Documentation ¶
Index ¶
- Constants
- Variables
- func BootstrapNodes() []string
- func EcdsaKeyFromPeer(pid peer.ID) (*ecdsa.PublicKey, error)
- func NewHostAndBitSwapPeer(ctx context.Context, userOpts ...Option) (*LibP2PHost, *BitswapPeer, error)
- func PeerFromEcdsaKey(publicKey *ecdsa.PublicKey) (peer.ID, error)
- func PeerIDFromPublicKey(publicKey *ecdsa.PublicKey) (peer.ID, error)
- type BitswapPeer
- type Bootstrapper
- type Config
- type DiscoveryEvent
- type LibP2PHost
- func (h *LibP2PHost) Addresses() []ma.Multiaddr
- func (h *LibP2PHost) Bootstrap(peers []string) (io.Closer, error)
- func (h *LibP2PHost) Connect(ctx context.Context, publicKey *ecdsa.PublicKey) error
- func (h *LibP2PHost) Disconnect(ctx context.Context, publicKey *ecdsa.PublicKey) error
- func (h *LibP2PHost) GetPubSub() *pubsub.PubSub
- func (h *LibP2PHost) Identity() string
- func (h *LibP2PHost) NewStream(ctx context.Context, publicKey *ecdsa.PublicKey, protocol protocol.ID) (network.Stream, error)
- func (h *LibP2PHost) NewStreamWithPeerID(ctx context.Context, peerID peer.ID, protocol protocol.ID) (network.Stream, error)
- func (h *LibP2PHost) PublicKey() *ecdsa.PublicKey
- func (h *LibP2PHost) Publish(topic string, data []byte) error
- func (h *LibP2PHost) Send(publicKey *ecdsa.PublicKey, protocol protocol.ID, payload []byte) error
- func (h *LibP2PHost) SendAndReceive(publicKey *ecdsa.PublicKey, protocol protocol.ID, payload []byte) ([]byte, error)
- func (h *LibP2PHost) SetStreamHandler(protocol protocol.ID, handler network.StreamHandler)
- func (h *LibP2PHost) StartDiscovery(namespace string) error
- func (h *LibP2PHost) StopDiscovery(namespace string)
- func (h *LibP2PHost) Subscribe(topic string, opts ...pubsub.SubOpt) (*pubsub.Subscription, error)
- func (h *LibP2PHost) WaitForBootstrap(peerCount int, timeout time.Duration) error
- func (h *LibP2PHost) WaitForDiscovery(namespace string, num int, duration time.Duration) error
- type Node
- type Option
- func WithAddrFilters(addrFilters []string) Option
- func WithAutoRelay(enabled bool) Option
- func WithBandwidthReporter(reporter metrics.Reporter) Option
- func WithBitswapOptions(opts ...bitswap.Option) Option
- func WithBlockstore(store blockstore.Blockstore) Option
- func WithClientOnlyDHT(isClientOnly bool) Option
- func WithDatastore(store ds.Batching) Option
- func WithDiscoveryNamespaces(namespaces ...string) Option
- func WithExternalAddr(addr string) Option
- func WithExternalIP(ip string, port int) Option
- func WithKey(key *ecdsa.PrivateKey) Option
- func WithLibp2pOptions(opts ...libp2p.Option) Option
- func WithListenIP(ip string, port int) Option
- func WithNATMap() Option
- func WithPubSubOptions(opts ...pubsub.Option) Option
- func WithPubSubRouter(routeType string) Option
- func WithRelayOpts(opts ...circuit.RelayOpt) Option
- func WithSegmenter(secret []byte) Option
- func WithTransports(transports ...libp2p.Option) Option
- func WithWebSocketExternalIP(ip string, port int) Option
- func WithWebSockets(port int) Option
Constants ¶
const ( // EventPeerConnected is emitted to the eventstream // whenever a new peer is found EventPeerConnected int = iota )
Variables ¶
var ErrDialBackoff = swarm.ErrDialBackoff
var (
LocalBootstrap = []string{
"/ip4/127.0.0.1/tcp/10000/ipfs/16Uiu2HAmTfa6xM13GKVrx6J6WkXxV26CmifQyJVwJZTDHSmMgBu3",
}
)
Functions ¶
func BootstrapNodes ¶
func BootstrapNodes() []string
BootstrapNodes returns a slice of comma-saparated values from environment variable TUPELO_BOOTSTRAP_NODES or the default bootstrapNodes if the environment variable is not set.
func NewHostAndBitSwapPeer ¶
func NewHostAndBitSwapPeer(ctx context.Context, userOpts ...Option) (*LibP2PHost, *BitswapPeer, error)
Types ¶
type BitswapPeer ¶
type BitswapPeer struct { ipld.DAGService // contains filtered or unexported fields }
BitswapPeer is for exchanging ipld blocks on the network it can be used in any of the LibP2PHost networks, but can also be used directly on the IPFS network.
func NewBitswapPeer ¶
func NewBitswapPeer(ctx context.Context, host *LibP2PHost, bitswapOpts ...bitswap.Option) (*BitswapPeer, error)
NewBitswapPeer creates a new block-swapping peer from an existing *LibP2PHost It is important that you bootstrap *after* creating this peer. There is a helper function: NewHostAndBitSwapPeer which can create both the host and this peer at the same time.
func (*BitswapPeer) BlockStore ¶
func (bp *BitswapPeer) BlockStore() blockstore.Blockstore
BlockStore offers access to the blockstore underlying the Peer's DAGService.
func (*BitswapPeer) HasBlock ¶
func (bp *BitswapPeer) HasBlock(c cid.Cid) (bool, error)
HasBlock returns whether a given block is available locally. It is a shorthand for .Blockstore().Has().
func (*BitswapPeer) Session ¶
func (bp *BitswapPeer) Session(ctx context.Context) ipld.NodeGetter
Session returns a session-based NodeGetter.
type Bootstrapper ¶
type Bootstrapper struct { // Config // MinPeerThreshold is the number of connections it attempts to maintain. MinPeerThreshold int // Period is the interval at which it periodically checks to see // if the threshold is maintained. Period time.Duration // ConnectionTimeout is how long to wait before timing out a connection attempt. ConnectionTimeout time.Duration // Does the work. Usually Bootstrapper.bootstrap. Argument is a slice of // currently-connected peers (so it won't attempt to reconnect). Bootstrap func([]peer.ID) // contains filtered or unexported fields }
Bootstrapper attempts to keep the p2p host connected to the network by keeping a minimum threshold of connections. If the threshold isn't met it connects to a random subset of the bootstrap peers. It does not use peer routing to discover new peers. To stop a Bootstrapper cancel the context passed in Start() or call Stop().
func NewBootstrapper ¶
func NewBootstrapper(bootstrapPeers []peer.AddrInfo, h host.Host, d network.Dialer, r routing.Routing, minPeer int, period time.Duration) *Bootstrapper
NewBootstrapper returns a new Bootstrapper that will attempt to keep connected to the network by connecting to the given bootstrap peers.
func (*Bootstrapper) Close ¶
func (b *Bootstrapper) Close() error
Close implements io.Closer in order to provide the same interface as previously.
func (*Bootstrapper) Start ¶
func (b *Bootstrapper) Start(ctx context.Context)
Start starts the Bootstrapper bootstrapping. Cancel `ctx` or call Stop() to stop it.
type Config ¶
type Config struct { RelayOpts []circuit.RelayOpt EnableRelayHop bool EnableAutoRelay bool EnableWebsocket bool WebsocketPort int PubSubRouter string PubSubOptions []pubsub.Option PrivateKey *ecdsa.PrivateKey EnableNATMap bool ExternalAddrs []string ListenAddrs []string AddrFilters []*net.IPNet Port int ListenIP string DiscoveryNamespaces []string AdditionalP2POptions []libp2p.Option Transports []libp2p.Option // these should only be libp2p.Transport options, but can't detect that with type DataStore ds.Batching Blockstore blockstore.Blockstore BandwidthReporter metrics.Reporter Segmenter []byte ClientOnlyDHT bool BitswapOptions []bitswap.Option }
type DiscoveryEvent ¶
type LibP2PHost ¶
func NewHostFromOptions ¶
func NewHostFromOptions(ctx context.Context, userOpts ...Option) (*LibP2PHost, error)
func NewLibP2PHost ¶
func NewLibP2PHost(ctx context.Context, privateKey *ecdsa.PrivateKey, port int) (*LibP2PHost, error)
func NewRelayLibP2PHost ¶
func NewRelayLibP2PHost(ctx context.Context, privateKey *ecdsa.PrivateKey, port int) (*LibP2PHost, error)
func (*LibP2PHost) Addresses ¶
func (h *LibP2PHost) Addresses() []ma.Multiaddr
func (*LibP2PHost) Connect ¶
Connect ensures there is a connection between this host and the peer with given public key. This is useful for bitswap exchanges where peers are known, allowing blocks to be exchanged directly, skipping the expensive DHT provides.
Connections are generally persisted, use Disconnect to clean up unused connections.
func (*LibP2PHost) Disconnect ¶
Disconnect closes all connections to the given peer.
func (*LibP2PHost) GetPubSub ¶
func (h *LibP2PHost) GetPubSub() *pubsub.PubSub
func (*LibP2PHost) Identity ¶
func (h *LibP2PHost) Identity() string
func (*LibP2PHost) NewStreamWithPeerID ¶
func (*LibP2PHost) PublicKey ¶
func (h *LibP2PHost) PublicKey() *ecdsa.PublicKey
func (*LibP2PHost) SendAndReceive ¶
func (*LibP2PHost) SetStreamHandler ¶
func (h *LibP2PHost) SetStreamHandler(protocol protocol.ID, handler network.StreamHandler)
func (*LibP2PHost) StartDiscovery ¶
func (h *LibP2PHost) StartDiscovery(namespace string) error
func (*LibP2PHost) StopDiscovery ¶
func (h *LibP2PHost) StopDiscovery(namespace string)
func (*LibP2PHost) Subscribe ¶
func (h *LibP2PHost) Subscribe(topic string, opts ...pubsub.SubOpt) (*pubsub.Subscription, error)
func (*LibP2PHost) WaitForBootstrap ¶
func (h *LibP2PHost) WaitForBootstrap(peerCount int, timeout time.Duration) error
func (*LibP2PHost) WaitForDiscovery ¶
type Node ¶
type Node interface { Identity() string PublicKey() *ecdsa.PublicKey Addresses() []ma.Multiaddr Bootstrap(peers []string) (io.Closer, error) WaitForBootstrap(peerCount int, timeout time.Duration) error SetStreamHandler(protocol protocol.ID, handler network.StreamHandler) NewStream(ctx context.Context, publicKey *ecdsa.PublicKey, protocol protocol.ID) (network.Stream, error) NewStreamWithPeerID(ctx context.Context, peerID peer.ID, protocol protocol.ID) (network.Stream, error) Send(publicKey *ecdsa.PublicKey, protocol protocol.ID, payload []byte) error SendAndReceive(publicKey *ecdsa.PublicKey, protocol protocol.ID, payload []byte) ([]byte, error) GetPubSub() *pubsub.PubSub }
Node is the interface any p2p host must implement to be used The interface is here so that other implementations (like in memory for tests) can be used to, for example, simulate large networks on single machines
type Option ¶
Option is a configuration option for the server
func WithAddrFilters ¶
WithAddrFilters takes a string of cidr addresses (0.0.0.0/32) that will not be dialed by swarm.
func WithAutoRelay ¶
WithAutoRelay enabled AutoRelay in the config, defaults to false
func WithBandwidthReporter ¶
WithBandwidthReporter sets the bandwidth reporter, defaults to a new metrics.Reporter
func WithBitswapOptions ¶
func WithBlockstore ¶
func WithBlockstore(store blockstore.Blockstore) Option
WithBlockStore sets the datastore used by the host defaults to nil which will wrap the underlying node datastore.
func WithClientOnlyDHT ¶
WithClientOnlyDHT sets whether or not the DHT will be put into client/server mode client mode means it will not serve requests on the DHT
func WithDatastore ¶
WithDatastore sets the datastore used by the host defaults to in-memory map store.
func WithDiscoveryNamespaces ¶
WithDiscoveryNamespaces enables discovery of all of the passed in namespaces discovery is part of bootstrap, defaults to empty
func WithExternalAddr ¶
WithExternalAddr sets an arbitrary multiaddr formatted string for broadcasting to swarm
func WithExternalIP ¶
WithExternalIP sets an arbitrary ip/port for broadcasting to swarm
func WithKey ¶
func WithKey(key *ecdsa.PrivateKey) Option
WithKey is the identity key of the host, if not set it the default options will generate you a new key
func WithLibp2pOptions ¶
func WithLibp2pOptions(opts ...libp2p.Option) Option
WithLibp2pOptions allows for additional libp2p options to be passed in
func WithListenIP ¶
WithListenIP sets the listen IP, defaults to 0.0.0.0/0
func WithPubSubOptions ¶
WithPubSubOptions sets pubsub options. Defaults to pubsub.WithStrictSignatureVerification(false), pubsub.WithMessageSigning(false)
func WithPubSubRouter ¶
WithPubSubRouter sets the router type of the pubsub. Supported is: gossip, random, floodsub defaults to gossip
func WithRelayOpts ¶
WithRelayOpts turns on relay and sets the options defaults to empty (and relay off).
func WithSegmenter ¶
WithSegmenter enables the secret on libp2p in order to make sure that this network does not combine with another. Default is off.
func WithTransports ¶
func WithTransports(transports ...libp2p.Option) Option
WithTransports should only be used with a libp2p.Transport option but cannot detect that using typing
func WithWebSocketExternalIP ¶
WithWebSocketExternalIP sets an arbitrary ip/port for broadcasting ws path to swarm
func WithWebSockets ¶
WithWebSockets turns websockets on at specified port (default to 0)