2026-06-28 20:56:10 -07:00
2026-01-08 22:09:49 -08:00
2026-02-14 05:26:22 -08:00
2026-06-28 20:56:11 -07:00

p2p

p2p

The p2p package provides a low-level networking abstraction for peer-to-peer communication in the Lux ecosystem.

Installation

go get github.com/luxfi/p2p

Core Interfaces

Handler

The Handler interface defines how incoming messages are processed:

type Handler interface {
    // Gossip handles an incoming gossip message
    Gossip(ctx context.Context, nodeID ids.NodeID, gossipBytes []byte)
    // Request handles an incoming request and returns a response or error
    Request(ctx context.Context, nodeID ids.NodeID, deadline time.Time, requestBytes []byte) ([]byte, *Error)
}

Sender

The Sender interface defines how outgoing messages are sent:

type Sender interface {
    SendRequest(ctx context.Context, nodeIDs set.Set[ids.NodeID], requestID uint32, request []byte) error
    SendResponse(ctx context.Context, nodeID ids.NodeID, requestID uint32, response []byte) error
    SendError(ctx context.Context, nodeID ids.NodeID, requestID uint32, errorCode int32, errorMessage string) error
    SendGossip(ctx context.Context, config SendConfig, msg []byte) error
}

Error

The Error type represents application-level errors:

type Error struct {
    Code    int32
    Message string
}

Standard errors:

  • ErrUnexpected (-1): Generic unexpected error
  • ErrUnregisteredHandler (-2): No handler registered for protocol
  • ErrNotValidator (-3): Requesting peer is not a validator
  • ErrThrottled (-4): Request rate limit exceeded

Sub-packages

gossip

Implements gossip protocols for efficient data propagation:

import "github.com/luxfi/p2p/gossip"

// Create a push gossiper
gossiper := gossip.NewPushGossiper[MyGossipable](...)

// Start gossiping
gossiper.Gossip(ctx)

lp118

Implements LP-118 warp message signature handling:

import "github.com/luxfi/p2p/lp118"

// Create a signature aggregator
aggregator := lp118.NewSignatureAggregator(log, client)

// Aggregate signatures for a warp message
msg, stake, total, err := aggregator.AggregateSignatures(ctx, message, justification, validators, quorumNum, quorumDen)

Usage with warp

The warp package re-exports types from p2p for backward compatibility:

import "github.com/luxfi/warp"

// warp.Error is an alias for p2p.Error
// warp.Sender is an alias for p2p.Sender
// warp.SendConfig is an alias for p2p.SendConfig

License

See LICENSE file.

S
Description
P2P networking library for Lux blockchain
Readme BSD-3-Clause
450 KiB
Languages
Go 100%