node

package
v0.0.0-...-a3ef0f2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 9, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package node assembles a LinkSelf node: libp2p Host + DHT (DID Provide/Find) + auth.

Index

Constants

View Source
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 Config

type Config struct {
	Identity       *did.Identity
	ListenAddrs    []string
	BootstrapPeers []peer.AddrInfo
}

Config holds options for creating a Node.

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

func New(ctx context.Context, cfg Config) (*Node, error)

New creates a new Node (Host + DHT with linkself validator). Call Start to register in DHT and set auth handler.

func (*Node) Close

func (n *Node) Close() error

Close shuts down the DHT and host.

func (*Node) Connect

func (n *Node) Connect(ctx context.Context, peerDID string) (network.Stream, error)

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

func (n *Node) SendMessage(ctx context.Context, peerDID string, payload []byte) error

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

func (n *Node) SendToGroup(ctx context.Context, memberDIDs []string, payload []byte) error

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

func (n *Node) SetOnMessage(fn func(peerDID string, payload []byte))

SetOnMessage sets a callback invoked when a message is received (peerDID, payload).

func (*Node) Start

func (n *Node) Start(ctx context.Context) error

Start runs DHT Bootstrap in background and sets the auth stream handler.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL