node

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	NodeID             string
	ListenAddr         string
	Transport          transport.StreamTransport
	Codec              codec.Codec // defaults to JSON; all peers must use the same codec
	Handshaker         Handshaker
	MaxPeers           int // default: 128
	MaxInboundPeers    int // inbound sub-limit within MaxPeers; default: MaxPeers * 2/3
	MaxPendingPeers    int // concurrent in-flight handshakes; default: 32
	OnPeerConnected    func(peerID string)
	OnPeerDisconnected func(peerID string)
	// OnPeerCapabilitiesKnown fires when capabilities become known for a connected peer. Optional.
	OnPeerCapabilitiesKnown func(peerID string, protocols []string)
	ProtocolLimits          map[string]uint32 // per-protocol frame size limits; must be ≤ transport limit
}

type ConnInfo

type ConnInfo = p2p.ConnInfo

ConnInfo is an alias for p2p.ConnInfo.

type HandshakeConfig

type HandshakeConfig = p2p.HandshakeConfig

HandshakeConfig is an alias for p2p.HandshakeConfig.

type HandshakeResult

type HandshakeResult = p2p.HandshakeResult

HandshakeResult is an alias for p2p.HandshakeResult.

type Handshaker

type Handshaker = p2p.Handshaker

Handshaker is an alias for p2p.Handshaker.

type Node

type Node interface {
	Start() error
	Stop() error
	Register(protocol string, handler p2p.Handler) // must be called before Start
	Send(peerID string, protocol string, msgType string, payload any) (int, error)
	Peers() []string
	ConnectionInfo(peerID string) (p2p.ConnInfo, bool)
	BoundAddr() string                            // reflects OS-assigned port when ListenAddr was ":0"
	PeerProtocols(peerID string) ([]string, bool) // bool=true if capabilities are known
	RegisteredProtocols() []string
}

func New

func New(cfg Config, disc PeerSource) (Node, error)

New returns a running Node. Pass nil disc to manage connections externally.

type PeerSource

type PeerSource interface {
	Events() <-chan discovery.PeerEvent
}

type ProtocolHandler

type ProtocolHandler = p2p.Handler

ProtocolHandler is an alias for p2p.Handler.

Directories

Path Synopsis
Package identify implements node.Handshaker.
Package identify implements node.Handshaker.

Jump to

Keyboard shortcuts

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