Documentation
¶
Index ¶
- Constants
- type Client
- func (c *Client) Addrs() []multiaddr.Multiaddr
- func (c *Client) Close() error
- func (c *Client) ConnectionGater() *conngater.BasicConnectionGater
- func (c *Client) GetNetworkInfo() (NetworkInfo, error)
- func (c *Client) GetPeers() ([]peer.AddrInfo, error)
- func (c *Client) Host() host.Host
- func (c *Client) Info() (string, string, string, error)
- func (c *Client) PeerIDs() []peer.ID
- func (c *Client) Peers() []PeerConnection
- func (c *Client) PubSub() *pubsub.PubSub
- func (c *Client) Start(ctx context.Context) error
- type Metrics
- type NetworkInfo
- type NodeInfo
- type P2PRPC
- type PeerConnection
Constants ¶
const ( // MetricsSubsystem is a subsystem shared by all metrics exposed by this // package. MetricsSubsystem = "p2p" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
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, ds datastore.Datastore, chainID string, logger zerolog.Logger, metrics *Metrics, ) (*Client, error)
NewClient creates new Client object.
Basic checks on parameters are done, and default parameters are provided for unset-configuration
func NewClientWithHost ¶
func (*Client) Addrs ¶
func (c *Client) Addrs() []multiaddr.Multiaddr
Addrs returns listen addresses of Client.
func (*Client) ConnectionGater ¶
func (c *Client) ConnectionGater() *conngater.BasicConnectionGater
ConnectionGater returns the client's connection gater
func (*Client) GetNetworkInfo ¶
func (c *Client) GetNetworkInfo() (NetworkInfo, error)
func (*Client) PeerIDs ¶
PeerIDs returns list of peer IDs of connected peers excluding self and inactive
func (*Client) Peers ¶
func (c *Client) Peers() []PeerConnection
Peers returns list of peers connected to Client.
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 Metrics ¶
type Metrics struct {
// Number of peers.
Peers metrics.Gauge
// Number of bytes received from a given peer.
PeerReceiveBytesTotal metrics.Counter `metrics_labels:"peer_id,chID"`
// Number of bytes sent to a given peer.
PeerSendBytesTotal metrics.Counter `metrics_labels:"peer_id,chID"`
// Pending bytes to be sent to a given peer.
PeerPendingSendBytes metrics.Gauge `metrics_labels:"peer_id"`
// Number of transactions submitted by each peer.
NumTxs metrics.Gauge `metrics_labels:"peer_id"`
// Number of bytes of each message type received.
MessageReceiveBytesTotal metrics.Counter `metrics_labels:"message_type"`
// Number of bytes of each message type sent.
MessageSendBytesTotal metrics.Counter `metrics_labels:"message_type"`
}
Metrics contains metrics exposed by this package.
func PrometheusMetrics ¶
PrometheusMetrics returns Metrics build using Prometheus client library. Optionally, labels can be provided along with their values ("foo", "fooValue").
type NetworkInfo ¶
NetworkInfo represents network information
type NodeInfo ¶
type NodeInfo struct {
NodeID string `json:"id"` // authenticated identifier
ListenAddr string `json:"listen_addr"` // accepting incoming
// Check compatibility.
Network string `json:"network"` // network/chain ID
}
NodeInfo is the basic node information exchanged between two peers
type P2PRPC ¶
type P2PRPC interface {
// GetPeers returns information about connected peers
GetPeers() ([]peer.AddrInfo, error)
// GetNetworkInfo returns network information
GetNetworkInfo() (NetworkInfo, error)
}
P2PRPC defines the interface for managing peer connections
type PeerConnection ¶
type PeerConnection struct {
NodeInfo NodeInfo `json:"node_info"`
IsOutbound bool `json:"is_outbound"`
RemoteIP string `json:"remote_ip"`
}
PeerConnection describe basic information about P2P connection.