Documentation
¶
Index ¶
- Constants
- Variables
- func QueryForEvent(eventType string) tmpubsub.Query
- type Client
- func (c *Client) Addrs() []multiaddr.Multiaddr
- func (c *Client) BlockPublished(block *types.Block)
- func (c *Client) BlockReceived(block *types.Block)
- func (c *Client) Close() error
- func (c *Client) GossipBlock(ctx context.Context, blockBytes []byte) error
- func (c *Client) GossipHeader(ctx context.Context, headerBytes []byte) error
- func (c *Client) GossipTx(ctx context.Context, tx []byte) error
- func (c *Client) Info() (p2p.ID, string, string)
- func (c *Client) NewTxValidator() GossipValidator
- func (c *Client) Peers() []PeerConnection
- func (c *Client) SetBlockValidator(validator GossipValidator)
- func (c *Client) SetHeaderValidator(validator GossipValidator)
- func (c *Client) SetTxValidator(val GossipValidator)
- func (c *Client) Start(ctx context.Context) error
- type EventTracer
- type GossipMessage
- type GossipValidator
- type GossipedBlock
- type Gossiper
- type GossiperOption
- type IValidator
- type JSONTracer
- type Option
- type PBTracer
- type PeerConnection
- type RawTracer
- type Validator
Constants ¶
const ( RejectBlacklstedPeer = "blacklisted peer" RejectBlacklistedSource = "blacklisted source" RejectMissingSignature = "missing signature" RejectUnexpectedSignature = "unexpected signature" RejectUnexpectedAuthInfo = "unexpected auth info" RejectInvalidSignature = "invalid signature" RejectValidationQueueFull = "validation queue full" RejectValidationThrottled = "validation throttled" RejectValidationFailed = "validation failed" RejectValidationIgnored = "validation ignored" RejectSelfOrigin = "self originated message" )
rejection reasons
const (
EventNewGossipedBlock = "NewGossipedBlock"
)
Define the event types
const (
// EventTypeKey is a reserved composite key for event name.
EventTypeKey = "p2p.event"
)
Variables ¶
var ( // EventQueryNewNewGossipedBlock is the query used for getting EventNewGossipedBlock EventQueryNewNewGossipedBlock = QueryForEvent(EventNewGossipedBlock) )
var MinTraceBatchSize = 16
var TraceBufferSize = 1 << 16 // 64K ought to be enough for everyone; famous last words.
Functions ¶
func QueryForEvent ¶
QueryForEvent returns a query for the given event.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a P2P client, implemented with libp2p.
Initially, client connects to predefined seed nodes (aka bootnodes, bootstrap nodes). Those seed nodes serve Kademlia DHT protocol, and are agnostic to ORU chain. Using DHT peer routing and discovery clients find other peers within ORU network.
func NewClient ¶
func NewClient(conf config.P2PConfig, privKey crypto.PrivKey, chainID string, logger log.Logger, opts ...Option) (*Client, error)
NewClient creates new Client object.
Basic checks on parameters are done, and default parameters are provided for unset-configuration TODO(tzdybal): consider passing entire config, not just P2P config, to reduce number of arguments
func (*Client) Addrs ¶
func (c *Client) Addrs() []multiaddr.Multiaddr
Addrs returns listen addresses of Client.
func (*Client) BlockPublished ¶
func (*Client) BlockReceived ¶
func (*Client) GossipBlock ¶
GossipBlock sends the block and it's commit to the P2P network.
func (*Client) GossipHeader ¶
GossipHeader sends the block header to the P2P network.
func (*Client) NewTxValidator ¶
func (c *Client) NewTxValidator() GossipValidator
NewTxValidator creates a pubsub validator that uses the node's mempool to check the transaction. If the transaction is valid, then it is added to the mempool
func (*Client) Peers ¶
func (c *Client) Peers() []PeerConnection
Peers returns list of peers connected to Client.
func (*Client) SetBlockValidator ¶
func (c *Client) SetBlockValidator(validator GossipValidator)
SetBlockValidator sets the callback function, that will be invoked after block is received from P2P network.
func (*Client) SetHeaderValidator ¶
func (c *Client) SetHeaderValidator(validator GossipValidator)
SetHeaderValidator sets the callback function, that will be invoked after block header is received from P2P network.
func (*Client) SetTxValidator ¶
func (c *Client) SetTxValidator(val GossipValidator)
SetTxValidator sets the callback function, that will be invoked during message gossiping.
func (*Client) Start ¶
Start establish Client's P2P connectivity.
Following steps are taken: 1. Setup libp2p host, start listening for incoming connections. 2. Setup gossibsub. 3. Setup DHT, establish connection to seed nodes and initialize peer discovery. 4. Use active peer discovery to look for peers from same ORU network.
type EventTracer ¶
type EventTracer interface {
Trace(evt *pb.TraceEvent)
}
EventTracer is a generic event tracer interface. This is a high level tracing interface which delivers tracing events, as defined by the protobuf schema in pb/trace.proto.
type GossipMessage ¶
GossipMessage represents message gossiped via P2P network (e.g. transaction, Block etc).
type GossipValidator ¶
type GossipValidator func(*GossipMessage) bool
GossipValidator is a callback function type.
type GossipedBlock ¶
type GossipedBlock struct { // Block is the block that was gossiped Block types.Block // Commit is the commit that was gossiped Commit types.Commit }
GossipedBlock defines the struct of the event data for the GossipedBlock
func (*GossipedBlock) FromProto ¶
func (e *GossipedBlock) FromProto(other *pb.GossipedBlock) error
FromProto fills GossipedBlock with data from its protobuf representation.
func (*GossipedBlock) MarshalBinary ¶
func (e *GossipedBlock) MarshalBinary() ([]byte, error)
MarshalBinary encodes GossipedBlock into binary form and returns it.
func (*GossipedBlock) ToProto ¶
func (e *GossipedBlock) ToProto() *pb.GossipedBlock
ToProto converts Data into protobuf representation and returns it.
func (*GossipedBlock) UnmarshalBinary ¶
func (e *GossipedBlock) UnmarshalBinary(data []byte) error
UnmarshalBinary decodes binary form of GossipedBlock into object.
func (*GossipedBlock) Validate ¶
func (e *GossipedBlock) Validate() error
Validate run basic validation on the gossiped block
type Gossiper ¶
type Gossiper struct {
// contains filtered or unexported fields
}
Gossiper is an abstraction of P2P publish subscribe mechanism.
func NewGossiper ¶
func NewGossiper(host host.Host, ps *pubsub.PubSub, topicStr string, logger log.Logger, options ...GossiperOption) (*Gossiper, error)
NewGossiper creates new, ready to use instance of Gossiper.
Returned Gossiper object can be used for sending (Publishing) and receiving messages in topic identified by topicStr.
func (*Gossiper) Close ¶
Close is used to disconnect from topic and free resources used by Gossiper.
func (*Gossiper) ProcessMessages ¶
ProcessMessages waits for messages published in the topic and execute handler.
type GossiperOption ¶
GossiperOption sets optional parameters of Gossiper.
func WithValidator ¶
func WithValidator(validator GossipValidator) GossiperOption
WithValidator options registers topic validator for Gossiper.
type IValidator ¶
type IValidator interface { // TxValidator creates a pubsub validator that uses the node's mempool to check the // transaction. If the transaction is valid, then it is added to the mempool TxValidator(mp mempool.Mempool, mpoolIDS *nodemempool.MempoolIDs) GossipValidator }
IValidator is an interface for implementing validators of messages gossiped in the p2p network.
type JSONTracer ¶
type JSONTracer struct {
// contains filtered or unexported fields
}
JSONTracer is a tracer that writes events to a file, encoded in ndjson.
func NewJSONTracer ¶
func NewJSONTracer(file string) (*JSONTracer, error)
NewJsonTracer creates a new JSONTracer writing traces to file.
func OpenJSONTracer ¶
OpenJSONTracer creates a new JSONTracer, with explicit control of OpenFile flags and permissions.
func (*JSONTracer) Trace ¶
func (t *JSONTracer) Trace(evt *pb.TraceEvent)
type Option ¶
func WithEventTracer ¶
func WithEventTracer(tracer EventTracer) Option
WithEventTracer provides a tracer for the pubsub system
func WithGossipEventTracer ¶
func WithGossipEventTracer(tracer pubsub.EventTracer) Option
WithEventTracer provides a tracer for the pubsub system
type PBTracer ¶
type PBTracer struct {
// contains filtered or unexported fields
}
PBTracer is a tracer that writes events to a file, as delimited protobufs.
func NewPBTracer ¶
func OpenPBTracer ¶
OpenPBTracer creates a new PBTracer, with explicit control of OpenFile flags and permissions.
func (*PBTracer) Trace ¶
func (t *PBTracer) Trace(evt *pb.TraceEvent)
type PeerConnection ¶
type PeerConnection struct { NodeInfo p2p.DefaultNodeInfo `json:"node_info"` IsOutbound bool `json:"is_outbound"` ConnectionStatus p2p.ConnectionStatus `json:"connection_status"` RemoteIP string `json:"remote_ip"` }
PeerConnection describe basic information about P2P connection. TODO(tzdybal): move it somewhere
type RawTracer ¶
type RawTracer interface { // AddPeer is invoked when a new peer is added. PublishBlock(p peer.ID, block *types.Block) ReceiveBlock(p peer.ID, Block types.Block) }
RawTracer is a low level tracing interface that allows an application to trace the internal operation of the subsystem.
Note that the tracers are invoked synchronously, which means that application tracers must take care to not block or modify arguments.
Warning: this interface is not fixed, we may be adding new methods as necessitated by the system in the future.
type Validator ¶
type Validator struct {
// contains filtered or unexported fields
}
Validator is a validator for messages gossiped in the p2p network.
func NewValidator ¶
NewValidator creates a new Validator.
func (*Validator) BlockValidator ¶
func (v *Validator) BlockValidator() GossipValidator
BlockValidator runs basic checks on the gossiped block
func (*Validator) TxValidator ¶
func (v *Validator) TxValidator(mp mempool.Mempool, mpoolIDS *nodemempool.MempoolIDs) GossipValidator
TxValidator creates a pubsub validator that uses the node's mempool to check the transaction. If the transaction is valid, then it is added to the mempool.