Documentation
¶
Overview ¶
Package node assembles a LinkSelf node: libp2p Host + DHT (DID Provide/Find) + auth.
Index ¶
- Constants
- type Config
- type Node
- func (n *Node) Close() error
- func (n *Node) Connect(ctx context.Context, peerDID string) (network.Stream, error)
- func (n *Node) ConnectToAddr(ctx context.Context, peerDID string, listenAddr string) (network.Stream, error)
- func (n *Node) SendMessage(ctx context.Context, peerDID string, payload []byte) error
- func (n *Node) SendToGroup(ctx context.Context, memberDIDs []string, payload []byte) error
- func (n *Node) SetOnMessage(fn func(peerDID string, payload []byte))
- func (n *Node) Start(ctx context.Context) error
Constants ¶
const MessageProtocol = "/linkself/msg/1.0.0"
Message protocol for LinkSelf: length-prefixed payload.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Node ¶
type Node struct {
Identity *did.Identity
Host host.Host
DHT *kaddht.IpfsDHT
StoreForward *storeforward.StoreForward
// contains filtered or unexported fields
}
Node is a LinkSelf node: identity, libp2p host, DHT, auth handler, and store-forward.
func New ¶
New creates a new Node (Host + DHT with linkself validator). Call Start to register in DHT and set auth handler.
func (*Node) Connect ¶
Connect finds the peer by DID in the DHT, dials, and runs challenge-response auth. Returns an authenticated stream (caller should close it when done). Also flushes any store-and-forward messages for this peer.
func (*Node) ConnectToAddr ¶
func (n *Node) ConnectToAddr(ctx context.Context, peerDID string, listenAddr string) (network.Stream, error)
ConnectToAddr connects to the peer at the given Listen address (multiaddr with /p2p/...), without DHT lookup. Deprecated: prefer DHT-only connect via Connect(peerDID). Kept for backward compatibility.
func (*Node) SendMessage ¶
SendMessage sends a message to the peer with the given DID. If the peer is not reachable, the message is queued (store-and-forward) and sent when the peer comes online.
func (*Node) SendToGroup ¶
SendToGroup sends a message to each member DID (excluding self). Uses SendMessage per DID; offline peers are queued by store-and-forward.
func (*Node) SetOnMessage ¶
SetOnMessage sets a callback invoked when a message is received (peerDID, payload).