networking

package
v0.0.22 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2026 License: MIT Imports: 6 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EncodeMessage

func EncodeMessage(msg Message) []byte

EncodeMessage encodes a message into bytes. This is a simple pass-through for now, but can be extended with framing, compression, etc.

func ExtractPeerIDFromMultiaddr

func ExtractPeerIDFromMultiaddr(maddrStr string) (string, error)

ExtractPeerIDFromMultiaddr extracts the peer ID from a multiaddr if present.

func NormalizeMultiaddr

func NormalizeMultiaddr(addr string) (string, error)

NormalizeMultiaddr normalizes a multiaddr string.

func ValidatePeerInfo

func ValidatePeerInfo(peerID string, addrs []string) error

ValidatePeerInfo validates peer information.

Types

type Message

type Message struct {
	Receiver string // Peer ID of the receiver
	Data     []byte // Raw message data
}

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

func DecodeMessage(data []byte) Message

DecodeMessage decodes bytes into a message. This is a simple pass-through for now, but can be extended with framing, compression, etc.

type MessageHandler

type MessageHandler func(peerID string, data []byte)

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.

type PeerInfo

type PeerInfo struct {
	ID    string   // Peer identifier
	Addrs []string // List of multiaddrs
}

PeerInfo contains information about a peer.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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