Documentation ¶
Index ¶
- Constants
- Variables
- func GenerateAndEncodeLibp2pKey() (crypto.PrivKey, []byte, error)
- func GenerateTestLibp2pKey(t *testing.T) (crypto.PrivKey, string)
- func JoinAndWait(source, destination *Server, connectTimeout time.Duration, ...) error
- func MeshJoin(servers ...*Server) []error
- func ParseLibp2pKey(key []byte) (crypto.PrivKey, error)
- func ReadLibp2pKey(manager secrets.SecretsManager) (crypto.PrivKey, error)
- func WaitUntilPeerConnectsTo(ctx context.Context, srv *Server, ids ...peer.ID) (bool, error)
- func WaitUntilPeerDisconnectsFrom(ctx context.Context, srv *Server, ids ...peer.ID) (bool, error)
- func WaitUntilRoutingTableToBeFilled(ctx context.Context, srv *Server, size int) (bool, error)
- type Config
- type ConnectionInfo
- func (ci *ConnectionInfo) GetInboundConnCount() int64
- func (ci *ConnectionInfo) GetOutboundConnCount() int64
- func (ci *ConnectionInfo) GetPendingInboundConnCount() int64
- func (ci *ConnectionInfo) GetPendingOutboundConnCount() int64
- func (ci *ConnectionInfo) HasFreeConnectionSlot(direction network.Direction) bool
- func (ci *ConnectionInfo) HasFreeInboundConn() bool
- func (ci *ConnectionInfo) HasFreeOutboundConn() bool
- func (ci *ConnectionInfo) UpdateConnCountByDirection(delta int64, direction network.Direction)
- func (ci *ConnectionInfo) UpdatePendingConnCountByDirection(delta int64, direction network.Direction)
- type CreateServerParams
- type Metrics
- type PeerConnInfo
- type Protocol
- type Server
- func (s *Server) AddPeer(id peer.ID, direction network.Direction)
- func (s *Server) AddToPeerStore(peerInfo *peer.AddrInfo)
- func (s *Server) AddrInfo() *peer.AddrInfo
- func (s *Server) Close() error
- func (s *Server) CloseProtocolStream(protocol string, peerID peer.ID) error
- func (s *Server) DisconnectFromPeer(peer peer.ID, reason string)
- func (s *Server) EmitEvent(event *peerEvent.PeerEvent)
- func (s *Server) FetchOrSetTemporaryDial(peerID peer.ID, newValue bool) bool
- func (s *Server) GetBootnodeConnCount() int64
- func (s *Server) GetPeerInfo(peerID peer.ID) *peer.AddrInfo
- func (s *Server) GetProtocols(peerID peer.ID) ([]string, error)
- func (s *Server) GetRandomBootnode() *peer.AddrInfo
- func (s *Server) GetRandomPeer() *peer.ID
- func (s *Server) HasFreeConnectionSlot(direction network.Direction) bool
- func (s *Server) IsTemporaryDial(peerID peer.ID) bool
- func (s *Server) JoinPeer(rawPeerMultiaddr string) error
- func (s *Server) NewDiscoveryClient(peerID peer.ID) (proto.DiscoveryClient, error)
- func (s *Server) NewIdentityClient(peerID peer.ID) (proto.IdentityClient, error)
- func (s *Server) NewStream(proto string, id peer.ID) (network.Stream, error)
- func (s *Server) NewTopic(protoID string, obj proto.Message) (*Topic, error)
- func (s *Server) Peers() []*PeerConnInfo
- func (s *Server) RegisterProtocol(id string, p Protocol)
- func (s *Server) RemoveFromPeerStore(peerInfo *peer.AddrInfo)
- func (s *Server) RemoveTemporaryDial(peerID peer.ID)
- func (s *Server) Start() error
- func (s *Server) Subscribe() (*Subscription, error)
- func (s *Server) SubscribeCh() (<-chan *peerEvent.PeerEvent, error)
- func (s *Server) SubscribeFn(handler func(evnt *peerEvent.PeerEvent)) error
- func (s *Server) UpdatePendingConnCount(delta int64, direction network.Direction)
- type Subscription
- type Topic
Constants ¶
const ( DefaultDialRatio = 0.2 DefaultLibp2pPort int = 1478 MinimumPeerConnections int64 = 1 MinimumBootNodes int = 1 )
const (
DefaultLeaveTimeout = 30 * time.Second
)
Variables ¶
var ( ErrNoBootnodes = errors.New("no bootnodes specified") ErrMinBootnodes = errors.New("minimum 1 bootnode is required") )
var ( // Anything below 35s is prone to false timeouts, as seen from empirical test data DefaultJoinTimeout = 40 * time.Second DefaultBufferTimeout = DefaultJoinTimeout + time.Second*5 )
Functions ¶
func GenerateAndEncodeLibp2pKey ¶
GenerateAndEncodeLibp2pKey generates a new networking private key, and encodes it into hex
func JoinAndWait ¶
func JoinAndWait( source, destination *Server, connectTimeout time.Duration, joinTimeout time.Duration, ) error
JoinAndWait is a helper method for joining a destination server and waiting for the connection to be successful (destination node is a peer of source)
func ParseLibp2pKey ¶
ParseLibp2pKey converts a byte array to a private key
func ReadLibp2pKey ¶
func ReadLibp2pKey(manager secrets.SecretsManager) (crypto.PrivKey, error)
ReadLibp2pKey reads the private networking key from the secrets manager
func WaitUntilPeerConnectsTo ¶
Types ¶
type Config ¶
type Config struct { NoDiscover bool // flag indicating if the discovery mechanism should be turned on Addr *net.TCPAddr // the base address NatAddr net.IP // the NAT address DNS multiaddr.Multiaddr // the DNS address DataDir string // the base data directory for the client MaxPeers int64 // the maximum number of peer connections MaxInboundPeers int64 // the maximum number of inbound peer connections MaxOutboundPeers int64 // the maximum number of outbound peer connections Chain *chain.Chain // the reference to the chain configuration SecretsManager secrets.SecretsManager // the secrets manager used for key storage Metrics *Metrics // the metrics reporting reference }
Config details the params for the base networking server
func DefaultConfig ¶
func DefaultConfig() *Config
type ConnectionInfo ¶ added in v0.3.3
type ConnectionInfo struct {
// contains filtered or unexported fields
}
ConnectionInfo keeps track of current connection information for the networking server
func NewBlankConnectionInfo ¶ added in v0.3.3
func NewBlankConnectionInfo( maxInboundConnCount int64, maxOutboundConnCount int64, ) *ConnectionInfo
NewBlankConnectionInfo returns a cleared ConnectionInfo instance
func (*ConnectionInfo) GetInboundConnCount ¶ added in v0.3.3
func (ci *ConnectionInfo) GetInboundConnCount() int64
GetInboundConnCount returns the number of active inbound connections [Thread safe]
func (*ConnectionInfo) GetOutboundConnCount ¶ added in v0.3.3
func (ci *ConnectionInfo) GetOutboundConnCount() int64
GetOutboundConnCount returns the number of active outbound connections [Thread safe]
func (*ConnectionInfo) GetPendingInboundConnCount ¶ added in v0.3.3
func (ci *ConnectionInfo) GetPendingInboundConnCount() int64
GetPendingInboundConnCount returns the number of pending inbound connections [Thread safe]
func (*ConnectionInfo) GetPendingOutboundConnCount ¶ added in v0.3.3
func (ci *ConnectionInfo) GetPendingOutboundConnCount() int64
GetPendingOutboundConnCount returns the number of pending outbound connections [Thread safe]
func (*ConnectionInfo) HasFreeConnectionSlot ¶ added in v0.3.3
func (ci *ConnectionInfo) HasFreeConnectionSlot(direction network.Direction) bool
HasFreeConnectionSlot checks if there is a free connection slot in the specified direction [Thread safe]
func (*ConnectionInfo) HasFreeInboundConn ¶ added in v0.3.3
func (ci *ConnectionInfo) HasFreeInboundConn() bool
HasFreeInboundConn checks if there are any open inbound connection slots. It takes into account the number of current (active) inbound connections and the number of pending inbound connections [Thread safe]
func (*ConnectionInfo) HasFreeOutboundConn ¶ added in v0.3.3
func (ci *ConnectionInfo) HasFreeOutboundConn() bool
HasFreeOutboundConn checks if there are any open outbound connection slots. It takes into account the number of current (active) outbound connections and the number of pending outbound connections [Thread safe]
func (*ConnectionInfo) UpdateConnCountByDirection ¶ added in v0.3.3
func (ci *ConnectionInfo) UpdateConnCountByDirection( delta int64, direction network.Direction, )
UpdateConnCountByDirection updates the connection count by delta in the specified direction [Thread safe]
func (*ConnectionInfo) UpdatePendingConnCountByDirection ¶ added in v0.3.3
func (ci *ConnectionInfo) UpdatePendingConnCountByDirection( delta int64, direction network.Direction, )
UpdatePendingConnCountByDirection updates the pending connection count by delta in the specified direction [Thread safe]
type CreateServerParams ¶
type Metrics ¶
type Metrics struct { // Number of connected peers TotalPeerCount metrics.Gauge // Number of outbound connections OutboundConnectionsCount metrics.Gauge // Number of inbound connections InboundConnectionsCount metrics.Gauge // Number of pending outbound connections PendingOutboundConnectionsCount metrics.Gauge // Number of pending inbound connections PendingInboundConnectionsCount metrics.Gauge }
Metrics represents the network metrics
func GetPrometheusMetrics ¶
GetPrometheusMetrics return the network metrics instance
type PeerConnInfo ¶ added in v0.3.3
PeerConnInfo holds the connection information about the peer
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func CreateServer ¶
func CreateServer(params *CreateServerParams) (*Server, error)
func (*Server) AddPeer ¶ added in v0.3.3
AddPeer adds a new peer to the networking server's peer list, and updates relevant counters and metrics
func (*Server) AddToPeerStore ¶ added in v0.3.3
AddToPeerStore adds peer information to the node's peer store
func (*Server) CloseProtocolStream ¶ added in v0.3.3
CloseProtocolStream closes a protocol stream to the specified peer
func (*Server) DisconnectFromPeer ¶ added in v0.3.3
DisconnectFromPeer disconnects the networking server from the specified peer
func (*Server) EmitEvent ¶ added in v0.3.3
EmitEvent emits a specified event to the networking server's event bus
func (*Server) FetchOrSetTemporaryDial ¶ added in v0.3.3
FetchOrSetTemporaryDial loads the temporary status of a peer connection, and sets a new value [Thread safe]
func (*Server) GetBootnodeConnCount ¶ added in v0.3.3
GetBootnodeConnCount fetches the number of active bootnode connections [Thread safe]
func (*Server) GetPeerInfo ¶
GetPeerInfo fetches the information of a peer
func (*Server) GetProtocols ¶
GetProtocols fetches the list of node-supported protocols
func (*Server) GetRandomBootnode ¶ added in v0.3.3
GetRandomBootnode fetches a random bootnode that's currently NOT connected, if any
func (*Server) GetRandomPeer ¶ added in v0.3.3
GetRandomPeer fetches a random peer from the peers list
func (*Server) HasFreeConnectionSlot ¶ added in v0.3.3
HasFreeConnectionSlot checks if there are free connection slots in the specified direction [Thread safe]
func (*Server) IsTemporaryDial ¶ added in v0.3.3
IsTemporaryDial checks if a peer connection is temporary [Thread safe]
func (*Server) JoinPeer ¶ added in v0.3.3
JoinPeer attempts to add a new peer to the networking server
func (*Server) NewDiscoveryClient ¶ added in v0.3.3
NewDiscoveryClient returns a new or existing discovery service client connection
func (*Server) NewIdentityClient ¶ added in v0.3.3
NewIdentityClient returns a new identity service client connection
func (*Server) Peers ¶
func (s *Server) Peers() []*PeerConnInfo
Peers returns a copy of the networking server's peer connection info set. Only one (initial) connection (inbound OR outbound) per peer is contained [Thread safe]
func (*Server) RegisterProtocol ¶ added in v0.3.3
func (*Server) RemoveFromPeerStore ¶ added in v0.3.3
RemoveFromPeerStore removes peer information from the node's peer store
func (*Server) RemoveTemporaryDial ¶ added in v0.3.3
RemoveTemporaryDial removes a peer connection as temporary [Thread safe]
func (*Server) Subscribe ¶
func (s *Server) Subscribe() (*Subscription, error)
Subscribe starts a PeerEvent subscription
func (*Server) SubscribeCh ¶
SubscribeCh returns an event of of subscription events
func (*Server) SubscribeFn ¶
SubscribeFn is a helper method to run subscription of PeerEvents
type Subscription ¶
type Subscription struct {
// contains filtered or unexported fields
}
func (*Subscription) Close ¶
func (s *Subscription) Close()
func (*Subscription) Get ¶
func (s *Subscription) Get() *peerEvent.PeerEvent
func (*Subscription) GetCh ¶
func (s *Subscription) GetCh() chan *peerEvent.PeerEvent