Documentation ¶
Overview ¶
Package service defines basic interfaces to for protocols to consume p2p functionality.
Index ¶
- type Data
- type DataBytes
- type DataMsgWrapper
- type DirectMessage
- type Fetcher
- type GossipDataHandler
- type GossipMessage
- type Listener
- type MessageValidation
- type Node
- func (sn *Node) Broadcast(_ context.Context, protocol string, payload []byte) error
- func (sn *Node) GossipReady() <-chan struct{}
- func (sn *Node) ProcessDirectProtocolMessage(sender p2pcrypto.PublicKey, protocol string, payload Data, _ P2PMetadata) error
- func (sn *Node) ProcessGossipProtocolMessage(_ context.Context, sender p2pcrypto.PublicKey, ownMessage bool, ...) error
- func (sn *Node) RegisterDirectProtocol(protocol string) chan DirectMessage
- func (sn *Node) RegisterDirectProtocolWithChannel(protocol string, ingressChannel chan DirectMessage) chan DirectMessage
- func (sn *Node) RegisterGossipProtocol(protocol string, _ priorityq.Priority) chan GossipMessage
- func (sn *Node) SendMessage(ctx context.Context, peerPubkey p2pcrypto.PublicKey, protocol string, ...) error
- func (sn *Node) SendWrappedMessage(ctx context.Context, nodeID p2pcrypto.PublicKey, protocol string, ...) error
- func (sn *Node) Shutdown()
- func (sn *Node) Start(context.Context) error
- func (sn *Node) SubscribePeerEvents() (conn chan p2pcrypto.PublicKey, disc chan p2pcrypto.PublicKey)
- type P2PMetadata
- type Service
- type SimGossipMessage
- func (sm SimGossipMessage) Bytes() []byte
- func (sm SimGossipMessage) Data() Data
- func (sm SimGossipMessage) IsOwnMessage() bool
- func (sm SimGossipMessage) ReportValidation(ctx context.Context, protocol string)
- func (sm SimGossipMessage) RequestID() string
- func (sm SimGossipMessage) Sender() p2pcrypto.PublicKey
- func (sm SimGossipMessage) ValidationCompletedChan() chan MessageValidation
- type Simulator
- func (s *Simulator) NewFaulty(isRandBehaviour bool, maxBroadcastDelaySec uint32, maxReceiveDelaySec uint32) *Node
- func (s *Simulator) NewNode() *Node
- func (s *Simulator) NewNodeFrom(n *node.Info) *Node
- func (s *Simulator) SubscribeToPeerEvents(myid p2pcrypto.Key) (chan p2pcrypto.PublicKey, chan p2pcrypto.PublicKey)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Data ¶
type Data interface {
Bytes() []byte
}
Data is a wrapper around a message that can hold either raw bytes message or a req-res wrapper.
type DataBytes ¶
type DataBytes struct {
Payload []byte
}
DataBytes is a byte array payload wrapper.
type DataMsgWrapper ¶
DataMsgWrapper is a req-res payload wrapper
func (DataMsgWrapper) Bytes ¶
func (m DataMsgWrapper) Bytes() []byte
Bytes returns the message as bytes
type DirectMessage ¶
type DirectMessage interface { Metadata() P2PMetadata Sender() p2pcrypto.PublicKey Bytes() []byte }
DirectMessage is an interface that represents a simple direct message structure
type Fetcher ¶ added in v0.1.16
type Fetcher interface { FetchBlock(context.Context, types.BlockID) error FetchAtx(context.Context, types.ATXID) error GetPoetProof(context.Context, types.Hash32) error GetTxs(context.Context, []types.TransactionID) error GetBlocks(context.Context, []types.BlockID) error GetAtxs(context.Context, []types.ATXID) error }
Fetcher is a general interface that defines a component capable of fetching data from remote peers
type GossipDataHandler ¶ added in v0.1.15
type GossipDataHandler func(ctx context.Context, data GossipMessage, fetcher Fetcher)
GossipDataHandler is the function type that will be called when data is
type GossipMessage ¶
type GossipMessage interface { Sender() p2pcrypto.PublicKey IsOwnMessage() bool Bytes() []byte RequestID() string ValidationCompletedChan() chan MessageValidation ReportValidation(ctx context.Context, protocol string) }
GossipMessage is an interface that represents a simple gossip message structure
type Listener ¶ added in v0.1.15
Listener represents the main struct that reqisters delegates to gossip function
func NewListener ¶ added in v0.1.15
func NewListener(net Service, fetcher Fetcher, shouldListenToGossip enableGossipFunc, log log.Log) *Listener
NewListener creates a new listener struct
func (*Listener) AddListener ¶ added in v0.1.15
func (l *Listener) AddListener(ctx context.Context, channel string, priority priorityq.Priority, dataHandler GossipDataHandler)
AddListener adds a listener to a specific gossip channel
type MessageValidation ¶
type MessageValidation struct {
// contains filtered or unexported fields
}
MessageValidation is a gossip message validation event.
func NewMessageValidation ¶
func NewMessageValidation(sender p2pcrypto.PublicKey, msg []byte, prot string, reqID string) MessageValidation
NewMessageValidation creates a message validation struct to pass to the protocol.
func (MessageValidation) Message ¶
func (mv MessageValidation) Message() []byte
Message returns the message as bytes
func (MessageValidation) Protocol ¶
func (mv MessageValidation) Protocol() string
Protocol is the protocol this message is targeted to.
func (MessageValidation) RequestID ¶ added in v0.1.27
func (mv MessageValidation) RequestID() string
RequestID is the originating request ID of the message
func (MessageValidation) Sender ¶
func (mv MessageValidation) Sender() p2pcrypto.PublicKey
Sender returns the public key of the sender of this message. (might not be the author)
type Node ¶
Node is a simulated p2p node that can be used as a p2p service
func (*Node) Broadcast ¶
Broadcast disseminates a message to all simulated nodes. sends to yourself first.
func (*Node) GossipReady ¶ added in v0.1.21
func (sn *Node) GossipReady() <-chan struct{}
GossipReady is a chan which is closed when we established initial min connections with peers.
func (*Node) ProcessDirectProtocolMessage ¶
func (sn *Node) ProcessDirectProtocolMessage(sender p2pcrypto.PublicKey, protocol string, payload Data, _ P2PMetadata) error
ProcessDirectProtocolMessage passes a direct message to the protocol.
func (*Node) ProcessGossipProtocolMessage ¶
func (sn *Node) ProcessGossipProtocolMessage(_ context.Context, sender p2pcrypto.PublicKey, ownMessage bool, protocol string, data Data, validationCompletedChan chan MessageValidation) error
ProcessGossipProtocolMessage passes a gossip message to the protocol.
func (*Node) RegisterDirectProtocol ¶
func (sn *Node) RegisterDirectProtocol(protocol string) chan DirectMessage
RegisterDirectProtocol creates and returns a channel for a given direct based protocol.
func (*Node) RegisterDirectProtocolWithChannel ¶
func (sn *Node) RegisterDirectProtocolWithChannel(protocol string, ingressChannel chan DirectMessage) chan DirectMessage
RegisterDirectProtocolWithChannel configures and returns a channel for a given protocol.
func (*Node) RegisterGossipProtocol ¶
func (sn *Node) RegisterGossipProtocol(protocol string, _ priorityq.Priority) chan GossipMessage
RegisterGossipProtocol creates and returns a channel for a given gossip based protocol.
func (*Node) SendMessage ¶
func (sn *Node) SendMessage(ctx context.Context, peerPubkey p2pcrypto.PublicKey, protocol string, payload []byte) error
SendMessage send a message to another simulated node.
func (*Node) SendWrappedMessage ¶
func (sn *Node) SendWrappedMessage(ctx context.Context, nodeID p2pcrypto.PublicKey, protocol string, payload *DataMsgWrapper) error
SendWrappedMessage send a wrapped message to another simulated node.
func (*Node) Shutdown ¶
func (sn *Node) Shutdown()
Shutdown closes all node channels and removes them from the Simulator map
type P2PMetadata ¶
P2PMetadata is a generic metadata interface
type Service ¶
type Service interface { Start(ctx context.Context) error RegisterGossipProtocol(protocol string, prio priorityq.Priority) chan GossipMessage RegisterDirectProtocol(protocol string) chan DirectMessage SubscribePeerEvents() (new chan p2pcrypto.PublicKey, del chan p2pcrypto.PublicKey) GossipReady() <-chan struct{} Broadcast(ctx context.Context, protocol string, payload []byte) error Shutdown() }
Service is an interface that represents a networking service (ideally p2p) that we can use to send messages or listen to incoming messages
type SimGossipMessage ¶ added in v0.1.31
type SimGossipMessage struct {
// contains filtered or unexported fields
}
SimGossipMessage is a simulated gossip message
func NewSimGossipMessage ¶ added in v0.1.31
func NewSimGossipMessage(sender p2pcrypto.PublicKey, ownMessage bool, msg Data) SimGossipMessage
NewSimGossipMessage creates and returns a new SimGossipMessage
func (SimGossipMessage) Bytes ¶ added in v0.1.31
func (sm SimGossipMessage) Bytes() []byte
Bytes is the message's binary data in byte array format.
func (SimGossipMessage) Data ¶ added in v0.1.31
func (sm SimGossipMessage) Data() Data
Data is the message's binary data in byte array format.
func (SimGossipMessage) IsOwnMessage ¶ added in v0.1.31
func (sm SimGossipMessage) IsOwnMessage() bool
IsOwnMessage is whether the message was generated by this node
func (SimGossipMessage) ReportValidation ¶ added in v0.1.31
func (sm SimGossipMessage) ReportValidation(ctx context.Context, protocol string)
ReportValidation reports sm as a valid message for protocol.
func (SimGossipMessage) RequestID ¶ added in v0.1.31
func (sm SimGossipMessage) RequestID() string
RequestID returns the request ID
func (SimGossipMessage) Sender ¶ added in v0.1.31
func (sm SimGossipMessage) Sender() p2pcrypto.PublicKey
Sender is the sender public key
func (SimGossipMessage) ValidationCompletedChan ¶ added in v0.1.31
func (sm SimGossipMessage) ValidationCompletedChan() chan MessageValidation
ValidationCompletedChan is a channel over which the protocol is expected to update on the message validation
type Simulator ¶
Simulator is a p2p node factory and message bridge that is used to simulate the p2p layer provided to protocols without using real network or p2p code. It resembles the `Service` interface API.
func NewSimulator ¶
func NewSimulator() *Simulator
NewSimulator Creates a p2p simulation by providing nodes as p2p services and bridge them.
func (*Simulator) NewFaulty ¶
func (s *Simulator) NewFaulty(isRandBehaviour bool, maxBroadcastDelaySec uint32, maxReceiveDelaySec uint32) *Node
NewFaulty creates a node that can deploy faulty behaviour, broadcast delay, receive delay and randomness.
func (*Simulator) NewNodeFrom ¶
NewNodeFrom creates a new node from existing details