ipfs

package
v0.0.16 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 3, 2022 License: Apache-2.0 Imports: 58 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ServiceTag is used for mDNS
	ServiceTag = "_datahop-discovery._tcp"
)

Variables

This section is empty.

Functions

func DefaultBootstrapPeers

func DefaultBootstrapPeers() []peer.AddrInfo

DefaultBootstrapPeers returns the default datahop bootstrap peers (for use with NewLibp2pHost.

func SetupLibp2p

func SetupLibp2p(
	ctx context.Context,
	hostKey crypto.PrivKey,
	listenAddrs []multiaddr.Multiaddr,
	ds datastore.Batching,
	opts ...libp2p.Option,
) (host.Host, *dualdht.DHT, error)

SetupLibp2p returns a routed host and DHT instances that can be used to easily create an ipfslite Peer. You may consider to use Peer.Bootstrap() or Peer.Connect() after creating the IPFS-Lite Peer to connect to other peers.

Additional libp2p options can be passed. Interesting options to pass: NATPortMap() EnableAutoRelay(), libp2p.EnableNATService(), DisableRelay(), ConnectionManager(...)... see https://godoc.org/github.com/libp2p/go-libp2p#Option for more info.

Types

type AddParams

type AddParams struct {
	Layout    string
	Chunker   string
	RawLeaves bool
	Hidden    bool
	Shard     bool
	NoCopy    bool
	HashFun   string
}

AddParams contains all of the configurable parameters needed to specify the importing process of a file.

type Adder added in v0.0.16

type Adder struct {
	Out       chan<- interface{}
	Progress  bool
	Trickle   bool
	RawLeaves bool
	Silent    bool
	NoCopy    bool
	Chunker   string

	CidBuilder cid.Builder
	// contains filtered or unexported fields
}

Adder holds the switches passed to the `add` command.

func NewAdder added in v0.0.16

func NewAdder(ctx context.Context, ds ipld.DAGService) (*Adder, error)

NewAdder Returns a new Adder used for a file add operation.

func (*Adder) AddAll added in v0.0.16

func (adder *Adder) AddAll(file files.Node) (ipld.Node, error)

AddAllAndPin adds the given request's files and pin them.

func (*Adder) SetMfsRoot added in v0.0.16

func (adder *Adder) SetMfsRoot(r *mfs.Root)

SetMfsRoot sets `r` as the root for Adder.

type Link struct {
	Name, Hash string
	Size       uint64
}

type Option

type Option func(*Options)

Option is interface for setting up the datahop ipfslite node

func WithAutoDownload added in v0.0.16

func WithAutoDownload(autoDownload bool) Option

WithAutoDownload decides if content will be downloaded automatically

func WithCrdtNamespace

func WithCrdtNamespace(ns string) Option

WithCrdtNamespace sets the replication crdt namespace

func WithCrdtTopic

func WithCrdtTopic(topic string) Option

WithCrdtTopic sets the replication crdt listen topic

func WithRebroadcastInterval

func WithRebroadcastInterval(interval time.Duration) Option

WithRebroadcastInterval changes default crdt rebroadcast interval

func WithmDNS

func WithmDNS(withmDNS bool) Option

WithmDNS decides if the ipfs node will start with mDNS or not

func WithmDNSInterval

func WithmDNSInterval(interval time.Duration) Option

WithmDNSInterval changes default mDNS rebroadcast interval

type Options

type Options struct {
	// contains filtered or unexported fields
}

Options for setting up the datahop ipfslite node

type Peer

type Peer struct {
	Ctx             context.Context
	Cancel          context.CancelFunc
	Host            host.Host
	Store           datastore.Batching
	DHT             routing.Routing
	Repo            repo.Repo
	ipld.DAGService // become a DAG service

	Manager   *replication.Manager
	Stopped   chan bool
	CrdtTopic string
	// contains filtered or unexported fields
}

Peer is an IPFS-Lite peer. It provides a DAG service that can fetch and put blocks from/to the IPFS network.

func New

func New(
	ctx context.Context,
	cancelFunc context.CancelFunc,
	r repo.Repo,
	swarmKey []byte,
	opts ...Option,
) (*Peer, error)

New creates an IPFS-Lite Peer. It uses the given datastore, libp2p Host and Routing (usuall the DHT). Peer implements the ipld.DAGService interface.

func (*Peer) AddDir added in v0.0.16

func (p *Peer) AddDir(ctx context.Context, dir string, params *AddParams) (ipld.Node, error)

func (*Peer) AddFile

func (p *Peer) AddFile(ctx context.Context, r io.Reader, params *AddParams) (ipld.Node, error)

AddFile chunks and adds content to the DAGService from a reader. The content is stored as a UnixFS DAG (default for IPFS). It returns the root ipld.Node.

func (*Peer) BlockStore

func (p *Peer) BlockStore() blockstore.Blockstore

BlockStore offers access to the blockstore underlying the Peer's DAGService.

func (*Peer) Bootstrap

func (p *Peer) Bootstrap(peers []peer.AddrInfo)

Bootstrap is an optional helper to connect to the given peers and bootstrap the Peer DHT (and Bitswap). This is a best-effort function. Errors are only logged and a warning is printed when less than half of the given peers could be contacted. It is fine to pass a list where some peers will not be reachable.

func (*Peer) Connect

func (p *Peer) Connect(ctx context.Context, pi peer.AddrInfo) error

Connect connects host to a given peer

func (*Peer) ConnectIfNotConnectedUsingRelay added in v0.0.16

func (p *Peer) ConnectIfNotConnectedUsingRelay(ctx context.Context, providers []peer.ID)

func (*Peer) DeleteFile

func (p *Peer) DeleteFile(ctx context.Context, c cid.Cid) error

DeleteFile removes content from blockstore by its root CID. The file must have been added as a UnixFS DAG (default for IPFS).

func (*Peer) Disconnect

func (p *Peer) Disconnect(pi peer.AddrInfo) error

Disconnect host from a given peer

func (*Peer) Download

func (p *Peer) Download(ctx context.Context, c cid.Cid) error

Download will get the content by its root CID. Read it till the end.

func (*Peer) FindProviders

func (p *Peer) FindProviders(ctx context.Context, id cid.Cid) []peer.ID

FindProviders check dht to check for providers of a given cid

func (*Peer) GetFile

func (p *Peer) GetFile(ctx context.Context, c cid.Cid) (ufsio.ReadSeekCloser, error)

GetFile returns a reader to a file as identified by its root CID. The file must have been added as a UnixFS DAG (default for IPFS).

func (*Peer) HandlePeerFound

func (p *Peer) HandlePeerFound(pi peer.AddrInfo)

HandlePeerFound tries to connect to a given peerinfo

func (*Peer) HandlePeerFoundWithError

func (p *Peer) HandlePeerFoundWithError(pi peer.AddrInfo) error

HandlePeerFoundWithError tries to connect to a given peerinfo, returns error if failed

func (*Peer) HasBlock

func (p *Peer) HasBlock(c cid.Cid) (bool, error)

HasBlock returns whether a given block is available locally. It is a shorthand for .Blockstore().Has().

func (*Peer) IsOnline

func (p *Peer) IsOnline() bool

IsOnline returns if the node ios online

func (*Peer) Peers

func (p *Peer) Peers() []string

Peers returns a list of connected peers

func (*Peer) Session

func (p *Peer) Session(ctx context.Context) ipld.NodeGetter

Session returns a session-based NodeGetter.

func (*Peer) ZeroConfScan

func (p *Peer) ZeroConfScan()

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL