Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EncodeMessage ¶
EncodeMessage encodes a message into bytes. This is a simple pass-through for now, but can be extended with framing, compression, etc.
func ExtractPeerIDFromMultiaddr ¶
ExtractPeerIDFromMultiaddr extracts the peer ID from a multiaddr if present.
func NormalizeMultiaddr ¶
NormalizeMultiaddr normalizes a multiaddr string.
func ValidatePeerInfo ¶
ValidatePeerInfo validates peer information.
Types ¶
type Message ¶
Message represents a message to be sent to a peer. This is a simple wrapper that can be used by higher-level protocols.
func DecodeMessage ¶
DecodeMessage decodes bytes into a message. This is a simple pass-through for now, but can be extended with framing, compression, etc.
type MessageHandler ¶
MessageHandler is called when a message is received from a peer. peerID: The ID of the peer that sent the message data: The raw message data
type Network ¶
type Network interface {
// ID returns the local peer identifier.
ID() string
// ListenAddrs returns the addresses that other peers can use to connect to this node.
ListenAddrs() []string
// RegisterHandler registers a callback for incoming messages.
// The handler will be called for all incoming messages.
RegisterHandler(handler MessageHandler) error
// EnsurePeer registers a peer's address information.
// peerID: The peer's identifier
// addrs: List of multiaddrs where the peer can be reached
EnsurePeer(peerID string, addrs []string) error
// Send sends data to a peer.
// peerID: The target peer's identifier
// data: The raw data to send
Send(ctx context.Context, peerID string, data []byte) error
// Close releases all resources.
Close() error
}
Network provides peer-to-peer networking capabilities. It is protocol-agnostic and only handles raw bytes.