mirror of
https://github.com/luxfi/p2p.git
synced 2026-10-30 15:22:55 +00:00
- Add own Sender interface with SendRequest, SendResponse, SendError, SendGossip - Add own Error struct with Code/Message fields - Update Handler interface methods to Gossip() and Request() - Remove consensus/core dependency for p2p interfaces - Rename all App* prefixed methods to simple names - Update lp118 to use p2p.Error and Request method - Update gossip to use p2p.SendConfig and Request/Gossip methods - Clean up stale type conversions
42 lines
1.2 KiB
Go
42 lines
1.2 KiB
Go
// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package p2p
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/luxfi/ids"
|
|
"github.com/luxfi/math/set"
|
|
)
|
|
|
|
// SendConfig configures how a gossip message is sent
|
|
type SendConfig struct {
|
|
// NodeIDs specifies specific nodes to send to
|
|
NodeIDs set.Set[ids.NodeID]
|
|
|
|
// Validators is the number of validators to sample and send to
|
|
Validators int
|
|
|
|
// NonValidators is the number of non-validators to sample and send to
|
|
NonValidators int
|
|
|
|
// Peers is the number of peers to sample and send to
|
|
Peers int
|
|
}
|
|
|
|
// Sender sends messages to other nodes
|
|
type Sender interface {
|
|
// SendRequest sends a request to the specified nodes
|
|
SendRequest(ctx context.Context, nodeIDs set.Set[ids.NodeID], requestID uint32, request []byte) error
|
|
|
|
// SendResponse sends a response to a previous request
|
|
SendResponse(ctx context.Context, nodeID ids.NodeID, requestID uint32, response []byte) error
|
|
|
|
// SendError sends an error response to a previous request
|
|
SendError(ctx context.Context, nodeID ids.NodeID, requestID uint32, errorCode int32, errorMessage string) error
|
|
|
|
// SendGossip sends a gossip message
|
|
SendGossip(ctx context.Context, config SendConfig, msg []byte) error
|
|
}
|