Documentation
¶
Index ¶
- type Config
- type NATStatus
- type Node
- func (n *Node) Addrs() []multiaddr.Multiaddr
- func (n *Node) Advertise(ctx context.Context, namespace string)
- func (n *Node) Close() error
- func (n *Node) ConnectTo(peerID peer.ID, pid string) (*Stream, error)
- func (n *Node) Describe() string
- func (n *Node) FindPeers(ctx context.Context, namespace string) (<-chan peer.AddrInfo, error)
- func (n *Node) HandleProtocol(pid string, handler func(s *Stream))
- func (n *Node) ID() peer.ID
- func (n *Node) JoinTopic(topicName string) (*Topic, error)
- func (n *Node) OnNATStatusChange(fn func(NATStatus))
- func (n *Node) OnPeerFound(fn func(peer.AddrInfo))
- func (n *Node) OnPeerLost(fn func(peer.AddrInfo))
- func (n *Node) PrintDescribe()
- func (n *Node) WaitForNetwork(ctx context.Context, timeout time.Duration) error
- type Stream
- type Topic
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
ListenPort int
BootstrapPeers []string
EnableMDNS bool
IdentityPath string // Path to save/load the node's private key
PeerCachePath string // Path to save/load known peers
Persist bool // Whether to persist identity and peer cache
}
Config holds the configuration for a Node.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns a sensible default configuration.
type Node ¶
type Node struct {
Host host.Host
DHT *dht.IpfsDHT
PubSub *pubsub.PubSub
// contains filtered or unexported fields
}
Node represents a simplified libp2p node.
func (*Node) Advertise ¶
Advertise makes the node discoverable on a specific topic/namespace via the DHT.
func (*Node) FindPeers ¶
FindPeers searches for other nodes that have advertised the given namespace.
func (*Node) HandleProtocol ¶
HandleProtocol registers a handler for a specific protocol.
func (*Node) JoinTopic ¶
JoinTopic joins a PubSub topic and starts discovery for other peers on the same topic.
func (*Node) OnNATStatusChange ¶
OnNATStatusChange registers a callback to be fired when the NAT status changes.
func (*Node) OnPeerFound ¶
OnPeerFound registers a callback to be fired when a new peer connects.
func (*Node) OnPeerLost ¶
OnPeerLost registers a callback to be fired when a peer disconnects.
func (*Node) PrintDescribe ¶
func (n *Node) PrintDescribe()
PrintDescribe prints the node information to stdout.
type Stream ¶
Stream is a wrapper around network.Stream with simplified methods.