Documentation
¶
Overview ¶
Package node wraps a libp2p host with DHT and GossipSub.
Index ¶
- type Config
- type DHTMode
- type Node
- func (n *Node) Addrs() []ma.Multiaddr
- func (n *Node) Close() error
- func (n *Node) DHT() *dht.IpfsDHT
- func (n *Node) Host() host.Host
- func (n *Node) JoinTopic(name string) error
- func (n *Node) LeaveTopic(name string) error
- func (n *Node) LogDHTStatus()
- func (n *Node) PeerID() peer.ID
- func (n *Node) PubSub() *pubsub.PubSub
- func (n *Node) Publish(ctx context.Context, topic string, data []byte) error
- func (n *Node) Subscribe(topic string) *pubsub.Subscription
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
DHTMode DHTMode `yaml:"dht_mode"`
BootstrapPeers []string `yaml:"bootstrap_peers"`
EnablePubSub bool `yaml:"enable_pubsub"`
}
Config holds node configuration.
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
Node wraps a libp2p host with DHT and GossipSub. Topic and subscription maps use sync.Map for lock-free reads during Publish and Subscribe, with per-topic join serialization to avoid blocking unrelated topics.
func (*Node) JoinTopic ¶
JoinTopic joins a GossipSub topic. Concurrent calls for the same topic name are serialized via per-topic locking, but do not block operations on other topics.
func (*Node) LeaveTopic ¶
LeaveTopic cancels the subscription to a topic and closes it, undoing JoinTopic. Leaving a topic that was never joined is not an error. It takes the same per-topic lock as JoinTopic, so a join and a leave of the same topic cannot interleave.
func (*Node) LogDHTStatus ¶
func (n *Node) LogDHTStatus()
LogDHTStatus logs the current DHT routing table and connection state.