ipfslite

package module
v0.0.0-...-7407870 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2020 License: Apache-2.0 Imports: 61 Imported by: 0

README

IPFS-Lite

This is a fork of hsanjuan/ipfs-lite. All credit goes to the author.

ipfs-lite

Build Status Godoc

IPFS-Lite is an embeddable, lightweight IPFS peer which runs the minimal setup to provide an ipld.DAGService. It can:

  • Add, Get, Remove IPLD Nodes to/from the IPFS Network (remove is a local blockstore operation).
  • Add single files (chunk, build the DAG and Add) from a io.Reader.
  • Get single files given a their CID.

It needs:

Some helper functions are provided to initialize these quickly.

It provides:

The goal of IPFS-Lite is to run the bare minimal functionality for any IPLD-based application to interact with the IPFS Network by getting and putting blocks to it, rather than having to deal with the complexities of using a full IPFS daemon, and with the liberty of sharing the needed libp2p Host and DHT for other things.

License

Apache 2.0

Documentation

Overview

Package ipfslite is a lightweight IPFS peer which runs the minimal setup to provide an `ipld.DAGService`, "Add" and "Get" UnixFS files from IPFS.

Index

Constants

This section is empty.

Variables

View Source
var Libp2pOptionsExtra = []libp2p.Option{
	libp2p.NATPortMap(),
	libp2p.ConnectionManager(connmgr.NewConnManager(100, 600, time.Minute)),
	libp2p.EnableAutoRelay(),
	libp2p.EnableNATService(),
	libp2p.Security(libp2ptls.ID, libp2ptls.New),
	libp2p.Security(secio.ID, secio.New),

	libp2p.DefaultTransports,
}

Libp2pOptionsExtra provides some useful libp2p options to create a fully featured libp2p host. It can be used with SetupLibp2p.

Functions

func BadgerDatastore

func BadgerDatastore(path string) (datastore.Batching, error)

BadgerDatastore returns a new instance of Badger-DS persisting to the given path with the default options.

func DefaultBootstrapPeers

func DefaultBootstrapPeers() []peer.AddrInfo

DefaultBootstrapPeers returns the default go-ipfs bootstrap peers (for use with NewLibp2pHost.

func IPFSBadgerDatastore

func IPFSBadgerDatastore() (datastore.Batching, error)

IPFSBadgerDatastore returns the Badger datastore used by the IPFS daemon (from `~/.ipfs/datastore`). Do not use the default datastore when the regular IFPS daemon is running at the same time.

func SetupLibp2p

func SetupLibp2p(
	ctx context.Context,
	hostKey crypto.PrivKey,
	secret pnet.PSK,
	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 a ipfslite Peer. You may consider to use Peer.Bootstrap() after creating the IPFS-Lite Peer to connect to other peers. When the datastore parameter is nil, the DHT will use an in-memory datastore, so all provider records are lost on program shutdown.

Additional libp2p options can be passed. Note that the Identity, ListenAddrs and PrivateNetwork options will be setup automatically. Interesting options to pass: NATPortMap() EnableAutoRelay(), libp2p.EnableNATService(), DisableRelay(), ConnectionManager(...)... see https://godoc.org/github.com/libp2p/go-libp2p#Option for more info.

The secret should be a 32-byte pre-shared-key byte slice.

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

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

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

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

func (*Adder) AddAll

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

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

func (*Adder) SetMfsRoot

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

SetMfsRoot sets `r` as the root for Adder.

type Link struct {
	Name, Hash string
	Size       uint64
}

type Peer

type Peer struct {
	Ctx             context.Context
	Host            host.Host
	Store           datastore.Batching
	Bstore          blockstore.Blockstore
	DHT             routing.Routing
	Bserv           blockservice.BlockService
	Repo            repo.Repo
	Provider        provider.System
	ipld.DAGService // become a DAG service
	// 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,
	r repo.Repo,
) (*Peer, error)

New creates an IPFS-Lite Peer. It uses the given datastore, libp2p Host and Routing (usuall the DHT). The Host and the Routing may be nil if config.Offline is set to true, as they are not used in that case. Peer implements the ipld.DAGService interface.

func (*Peer) AddDir

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) Disconnect

func (p *Peer) Disconnect(ctx context.Context, addr multiaddr.Multiaddr) error

Disconnect host from a given peer

func (*Peer) GetFile

func (p *Peer) GetFile(ctx context.Context, c cid.Cid) (ufsio.DagReader, 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) 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) Peers

func (p *Peer) Peers(ctx context.Context) ([]string, error)

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.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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