ipfsnucleus

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2022 License: AGPL-3.0 Imports: 31 Imported by: 0

README

IPFS-Nucleus

IPFS-Nucleus is a minimal block daemon for IPLD based services. You could call it an IPLDaemon. It includes optional auth for retrieving blocks over bitswap.

It implements the following http api calls from IPFS:

  • id
  • block.get
  • block.put
  • block.has
  • block.stat
  • block.rm (only needed by GC)
  • refs.local (only needed by GC)

As well as implementing the p2p http proxy (incoming and outgoing).

New config options

  • Addresses.ProxyTarget - The incoming http proxy target
  • Addresses.AllowTarget - The api for allow calls when blocks are requested over bitswap - allow(cid, block data, source peer id, auth string) => boolean

It is designed as a drop in replacment for IPFS with the minimal functionality that Peergos needs to operate, including running an external GC. It includes support for leveldb datastore and flatfs and S3 based blockstores including bloomfilter based wrapping.

It will read its config from a prior existing ipfs config file if present, or create one with the relevant parameters. It uses a v0 blockstore (cids) rather than a v1 (multihashes).

The CLI supports the following sub-commands similar to ipfs:

  • init
  • config

Building

go build daemon/ipfs-nucleus.go

License

AGPL

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Libp2pOptionsExtra = []libp2p.Option{
	libp2p.NATPortMap(),
	libp2p.EnableAutoRelay(),
	libp2p.EnableNATService(),
	libp2p.Security(libp2ptls.ID, libp2ptls.New),
	libp2p.Transport(libp2pquic.NewTransport),
	libp2p.DefaultTransports,
}

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

Functions

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 a ipfsnucleus Peer. You may consider to use Peer.Bootstrap() after creating the IPFS-Nucleus 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.

Types

type Config

type Config struct {
	// ReprovideInterval sets how often to reprovide records to the DHT
	ReprovideInterval time.Duration
}

Config wraps configuration options for the Peer.

type Peer

type Peer struct {
	Host host.Host

	P2P p2p.P2P
	// contains filtered or unexported fields
}

func New

func New(
	ctx context.Context,
	blockstore bstore.Blockstore,
	authedblockstore auth.AuthBlockstore,
	rootstore ds.Batching,
	host host.Host,
	dht routing.Routing,
	cfg *Config,
) (*Peer, error)

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

func (*Peer) BlockStore

func (p *Peer) BlockStore() bstore.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) GetBlock

func (p *Peer) GetBlock(w auth.Want) (auth.AuthBlock, error)

func (*Peer) GetRefs

func (p *Peer) GetRefs() (<-chan cid.Cid, error)

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

func (p *Peer) PutBlock(b blocks.Block) error

func (*Peer) RmBlock

func (p *Peer) RmBlock(c cid.Cid) error

Directories

Path Synopsis
package blockservice implements a BlockService interface that provides a single GetBlock/AddBlock interface that seamlessly retrieves data either locally or from a remote peer through the exchange.
package blockservice implements a BlockService interface that provides a single GetBlock/AddBlock interface that seamlessly retrieves data either locally or from a remote peer through the exchange.

Jump to

Keyboard shortcuts

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