Documentation ¶
Index ¶
- Variables
- func Bootstrap(ctx context.Context, h host.Host, dht routing.Routing, peers []peer.AddrInfo) ([]peer.AddrInfo, error)
- func NewDatastore(path string) (datastore.Batching, error)
- func SetupLibp2p(ctx context.Context, hostKey crypto.PrivKey, secret pnet.PSK, ...) (host.Host, routing.Routing, error)
Constants ¶
This section is empty.
Variables ¶
var ( DefaultConnMgrHighWater = 400 DefaultConnMgrLowWater = 100 DefaultConnMgrGracePeriod = 2 * time.Minute DefaultDialPeerTimeout = 3 * time.Second )
var Libp2pLitePrivateNodeOptions = []libp2p.Option{ func(cfg *p2pConfig.Config) error { mgr, err := connmgr.NewConnManager(DefaultConnMgrLowWater, DefaultConnMgrHighWater, connmgr.WithGracePeriod(DefaultConnMgrGracePeriod)) if err != nil { return err } return libp2p.ConnectionManager(mgr)(cfg) }, libp2p.EnableHolePunching(), libp2p.NATPortMap(), }
var Libp2pOptionsBase = []libp2p.Option{ libp2p.Ping(true), libp2p.EnableRelay(), libp2p.Security(libp2ptls.ID, libp2ptls.New), libp2p.NoTransports, libp2p.Transport(tcp.NewTCPTransport), libp2p.DefaultMuxers, }
var Libp2pOptionsFullNode = []libp2p.Option{ libp2p.EnableNATService(), libp2p.EnableRelayService(), func(cfg *p2pConfig.Config) error { mgr, err := connmgr.NewConnManager(DefaultConnMgrLowWater*4, DefaultConnMgrHighWater*8, connmgr.WithGracePeriod(DefaultConnMgrGracePeriod)) if err != nil { return err } return libp2p.ConnectionManager(mgr)(cfg) }, }
Libp2pOptionsExtra provides some useful libp2p options to create a fully featured libp2p host. It can be used with SetupLibp2p.
var Libp2pOptionsLitePublicNode = []libp2p.Option{ func(cfg *p2pConfig.Config) error { mgr, err := connmgr.NewConnManager(DefaultConnMgrLowWater, DefaultConnMgrHighWater, connmgr.WithGracePeriod(DefaultConnMgrGracePeriod)) if err != nil { return err } return libp2p.ConnectionManager(mgr)(cfg) }, }
var Libp2pOptionsPublicNode = []libp2p.Option{ libp2p.EnableNATService(), libp2p.EnableRelayService(), func(cfg *p2pConfig.Config) error { mgr, err := connmgr.NewConnManager(DefaultConnMgrLowWater*2, DefaultConnMgrHighWater*4, connmgr.WithGracePeriod(DefaultConnMgrGracePeriod)) if err != nil { return err } return libp2p.ConnectionManager(mgr)(cfg) }, }
var Libp2pSimpleNodeOptions = []libp2p.Option{ func(cfg *p2pConfig.Config) error { mgr, err := connmgr.NewConnManager(DefaultConnMgrLowWater, DefaultConnMgrHighWater, connmgr.WithGracePeriod(DefaultConnMgrGracePeriod)) if err != nil { return err } return libp2p.ConnectionManager(mgr)(cfg) }, }
Functions ¶
func Bootstrap ¶
func Bootstrap(ctx context.Context, h host.Host, dht routing.Routing, peers []peer.AddrInfo) ([]peer.AddrInfo, error)
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 NewDatastore ¶
func SetupLibp2p ¶
func SetupLibp2p( ctx context.Context, hostKey crypto.PrivKey, secret pnet.PSK, listenAddrs []string, ds datastore.Batching, bootstrapPeerFunc func() []peer.AddrInfo, opts ...libp2p.Option, ) (host.Host, routing.Routing, 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 ¶
This section is empty.