Documentation
¶
Index ¶
- Constants
- Variables
- func New(ctx context.Context, logger *zap.Logger, cfg *Config) (network.Network, error)
- func TransformEnr(enr string) []string
- func UseLookupOperatorHandler(n network.Network, fn LookupOperatorHandler)
- type Config
- type ConnectionFilter
- type IndexData
- type LookupOperatorHandler
- type NodeType
- type NodeTypeEntry
- type OperatorIDEntry
- type PeersIndex
- type UserAgent
Constants ¶
const ( // UserAgentKey is the key for storing to the user agent value // NOTE: this value is set by libp2p UserAgentKey = "AgentVersion" // NodeRecordKey is a key for node record (ENR) value NodeRecordKey = "NodeRecord" // OperatorIDKey is a key for operator pub-key hash value OperatorIDKey = "OperatorID" // NodeTypeKey is a key for node type (operator | exporter) value NodeTypeKey = "NodeType" )
Variables ¶
var ( // ErrPeerWasPruned is returned when a pruned peer is discovered ErrPeerWasPruned = errors.New("peer was pruned") )
Functions ¶
func TransformEnr ¶ added in v0.0.4
TransformEnr converts defaults enr value and convert it to slice
func UseLookupOperatorHandler ¶ added in v0.1.9
func UseLookupOperatorHandler(n network.Network, fn LookupOperatorHandler)
UseLookupOperatorHandler enables to inject some lookup handler
Types ¶
type Config ¶
type Config struct {
// yaml/env arguments
Enr string `yaml:"Enr" env:"ENR_KEY" env-description:"enr used in discovery" env-default:""`
DiscoveryType string `yaml:"DiscoveryType" env:"DISCOVERY_TYPE_KEY" env-description:"Method to use in discovery" env-default:"discv5"`
TCPPort int `yaml:"TcpPort" env:"TCP_PORT" env-default:"13000"`
UDPPort int `yaml:"UdpPort" env:"UDP_PORT" env-default:"12000"`
HostAddress string `yaml:"HostAddress" env:"HOST_ADDRESS" env-required:"true" env-description:"External ip node is exposed for discovery"`
HostDNS string `yaml:"HostDNS" env:"HOST_DNS" env-description:"External DNS node is exposed for discovery"`
RequestTimeout time.Duration `yaml:"RequestTimeout" env:"P2P_REQUEST_TIMEOUT" env-default:"5s"`
MaxBatchResponse uint64 `` /* 133-byte string literal not displayed */
MaxPeers int `` /* 160-byte string literal not displayed */
PubSubTraceOut string `yaml:"PubSubTraceOut" env:"PUBSUB_TRACE_OUT" env-description:"File path to hold collected pubsub traces"`
NetworkTrace bool `yaml:"NetworkTrace" env:"NETWORK_TRACE" env-description:"A boolean flag to turn on network debugging"`
NetworkDiscoveryTrace bool `` /* 139-byte string literal not displayed */
UseMainTopic bool `yaml:"UseMainTopic" env:"USE_MAIN_TOPIC" env-description:"A boolean flag to turn on usage of main topic"`
ExporterPeerID string `` /* 152-byte string literal not displayed */
Fork forks.Fork
// objects / instances
HostID peer.ID
Topics map[string]*pubsub.Topic
BootnodesENRs []string
// NetworkPrivateKey is used for network identity
NetworkPrivateKey *ecdsa.PrivateKey
// OperatorPrivateKey is used for operator identity
OperatorPrivateKey *rsa.PrivateKey
// ReportLastMsg whether to report last msg metric
ReportLastMsg bool
// NodeType differentiate exporters peers from others
NodeType NodeType
}
Config - describe the config options for p2p network
type ConnectionFilter ¶ added in v0.1.9
type ConnectionFilter func(conn libp2pnetwork.Conn) (bool, error)
ConnectionFilter represents a function that filters connections. returns whether to close the connection and if some error was thrown
type LookupOperatorHandler ¶ added in v0.1.9
LookupOperatorHandler is a function that checks if the given operator has some shared validator with the running operator
type NodeType ¶ added in v0.1.5
type NodeType int64
NodeType indicate node operation type. In purpose for distinguish between different types of peers
func (NodeType) FromString ¶ added in v0.1.5
FromString convert string to NodeType. If not exist, return Unknown
type NodeTypeEntry ¶ added in v0.1.9
type NodeTypeEntry uint16
NodeTypeEntry holds the node type
func (NodeTypeEntry) ENRKey ¶ added in v0.1.9
func (nte NodeTypeEntry) ENRKey() string
ENRKey implements enr.Entry, returns the entry key
type OperatorIDEntry ¶ added in v0.1.9
type OperatorIDEntry string
OperatorIDEntry holds the operator id
func (*OperatorIDEntry) DecodeRLP ¶ added in v0.1.9
func (oid *OperatorIDEntry) DecodeRLP(s *rlp.Stream) error
DecodeRLP implements rlp.Decoder, required because operator id is a string
func (OperatorIDEntry) ENRKey ¶ added in v0.1.9
func (oid OperatorIDEntry) ENRKey() string
ENRKey implements enr.Entry, returns the entry key
type PeersIndex ¶ added in v0.1.2
type PeersIndex interface {
Run()
GetData(pid peer.ID, key string) (interface{}, bool, error)
IndexConn(conn network.Conn)
IndexNode(node *enode.Node)
Indexed(id peer.ID) bool
EvictPruned(oid string)
Prune(id peer.ID, oid string)
Pruned(id peer.ID) bool
// contains filtered or unexported methods
}
PeersIndex is responsible for storing and serving peers information.
It uses libp2p's Peerstore (github.com/libp2p/go-libp2p-peerstore) to store metadata of peers:
- Node Record (ENR)
- User Agent - stored by libp2p but accessed through peer index
- Operator ID (hash) - derived from ENR
- Node Type - derived from ENR
NOTE: Peerstore access could potentially cause intesive CPU work for encoding/decoding keys
func NewPeersIndex ¶ added in v0.1.2
NewPeersIndex creates a new instance
type UserAgent ¶ added in v0.1.9
type UserAgent string
UserAgent wraps a string with ua capabilities
func GenerateUserAgent ¶ added in v0.1.9
func GenerateUserAgent(sk *rsa.PrivateKey, ntype NodeType) (UserAgent, error)
GenerateUserAgent creates user agent string (<app-name>:<version>:<type>:<operator-id>)
func NewUserAgent ¶ added in v0.1.9
NewUserAgent wraps the given string as a UserAgent
func (UserAgent) IsUnknown ¶ added in v0.1.9
IsUnknown checks if the given user agent is not from a ssv node
func (UserAgent) NodeType ¶ added in v0.1.9
NodeType returns the node type ('operator' | 'exporter')
func (UserAgent) NodeVersion ¶ added in v0.1.9
NodeVersion returns the node version (e.g. v0.1.7)
func (UserAgent) OperatorID ¶ added in v0.1.9
OperatorID returns operator id or empty string if not available TODO: this is kept for compatibility, should be removed in the future
as UserAgent is not the correct place to save this value (changed to ENR)