Documentation ¶
Overview ¶
Initial code taken from Armiarma by Migalabs
Index ¶
- Constants
- Variables
- func ConvertECDSAPubkeyToSecp2561k(pubkey *ecdsa.PublicKey) (crypto.PubKey, error)
- func CountBits(byteArr []byte) int
- func MaddrFrom(ip string, port uint) (ma.Multiaddr, error)
- type Attnets
- type ConnectionState
- type ContextStreamHandler
- type DiscoveryV5
- type EnrNode
- type HostInfo
- type Node
- func (n *Node) CanSubscribe(topic string) bool
- func (n *Node) Connected(net network.Network, c network.Conn)
- func (n *Node) Disconnected(net network.Network, c network.Conn)
- func (n *Node) FilterIncomingSubscriptions(pid peer.ID, opts []*pb.RPC_SubOpts) ([]*pb.RPC_SubOpts, error)
- func (n *Node) Listen(net network.Network, maddr ma.Multiaddr)
- func (n *Node) ListenClose(net network.Network, maddr ma.Multiaddr)
- func (n *Node) Start(ctx context.Context) error
- type NodeInfo
- type PeerBackoff
- type PeerDialer
- type PeerInfo
- type PeerMetadata
- type Peerstore
- func (p *Peerstore) AddSubscribedSubnets(id peer.ID, subnet ...int64)
- func (p *Peerstore) Get(id peer.ID) *PeerInfo
- func (p *Peerstore) Insert(id peer.ID, addr multiaddr.Multiaddr, enode enode.Node)
- func (p *Peerstore) IsBackedOff(id peer.ID) bool
- func (p *Peerstore) LastErr(id peer.ID) error
- func (p *Peerstore) PeersToReconnect() []peer.AddrInfo
- func (p *Peerstore) Reset(id peer.ID)
- func (p *Peerstore) SetBackoff(id peer.ID, err error) uint32
- func (p *Peerstore) SetClientVersion(id peer.ID, version string)
- func (p *Peerstore) SetMetadata(id peer.ID, metadata *eth.MetaDataV1)
- func (p *Peerstore) SetState(id peer.ID, state ConnectionState)
- func (p *Peerstore) SetStatus(id peer.ID, status *eth.Status)
- func (p *Peerstore) Size() int
- func (p *Peerstore) State(id peer.ID) ConnectionState
- func (p *Peerstore) Status(id peer.ID) *eth.Status
- type RemoteHostOptions
- type ReqResp
- func (r *ReqResp) Goodbye(ctx context.Context, pid peer.ID, code uint64) error
- func (r *ReqResp) MetaData(ctx context.Context, pid peer.ID) (resp *pb.MetaDataV1, err error)
- func (r *ReqResp) Ping(ctx context.Context, pid peer.ID) error
- func (r *ReqResp) RegisterHandlers(ctx context.Context) error
- func (r *ReqResp) SetStatus(status *pb.Status)
- func (r *ReqResp) Status(ctx context.Context, pid peer.ID) (status *pb.Status, err error)
- type ReqRespConfig
Constants ¶
const EPOCH_DURATION = 12 * 32 * time.Second
Variables ¶
var ( EnrValidationError error = errors.New("error validating ENR") Eth2DataParsingError error = errors.New("error parsing eth2 data") )
var ( EnrHostInfoAttribute string = "enr-info" EnrAttnetsAttribute string = "enr-attnets" EnrAttnetsNumAttribute string = "enr-att-num" )
Functions ¶
Types ¶
type Attnets ¶
type Attnets struct { Raw utils.AttnetsENREntry NetNumber int }
type ConnectionState ¶
type ConnectionState int
ConnectionState signals the capacity for a connection with a given node. It is used to signal to services and other peers whether a node is reachable.
const ( // NotConnected means no connection to peer, and no extra information (default) NotConnected ConnectionState = iota // Connecting means we are in the process of connecting to this peer Connecting )
type DiscoveryV5 ¶
type DiscoveryV5 struct { Dv5Listener *discover.UDPv5 FilterDigest string // contains filtered or unexported fields }
func NewDiscoveryV5 ¶
func NewDiscoveryV5(pk *ecdsa.PrivateKey, discConfig *config.DiscConfig) (*DiscoveryV5, error)
type EnrNode ¶
type EnrNode struct { Timestamp time.Time ID enode.ID IP net.IP Seq uint64 UDP int TCP int Pubkey *ecdsa.PublicKey Eth2Data *common.Eth2Data Attnets *Attnets }
func NewEnrNode ¶
func (*EnrNode) GetAttnetsString ¶
func (*EnrNode) GetPubkeyString ¶
type HostInfo ¶
type HostInfo struct { sync.RWMutex // AddrInfo ID peer.ID IP string Port int MAddrs []ma.Multiaddr Attr map[string]interface{} }
func NewHostInfo ¶
func NewHostInfo(peerID peer.ID, opts ...RemoteHostOptions) *HostInfo
NewHostInfo returns a new structure of the PeerInfo field for the specific network passed as argk
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
Node represents a node in the network with a host and configuration.
func NewNode ¶
func NewNode(cfg *config.NodeConfig) (*Node, error)
NewNode initializes a new Node using the provided configuration and options.
func (*Node) CanSubscribe ¶
func (*Node) FilterIncomingSubscriptions ¶
func (n *Node) FilterIncomingSubscriptions(pid peer.ID, opts []*pb.RPC_SubOpts) ([]*pb.RPC_SubOpts, error)
type PeerBackoff ¶
type PeerDialer ¶
type PeerDialer struct {
// contains filtered or unexported fields
}
PeerDialer is a suture service that reads peers from the peerChan (which is filled by the [Discovery] service until that peerChan channel is closed. When PeerDialer sees a new peer, it does a few sanity checks and tries to establish a connection.
type PeerInfo ¶
type PeerInfo struct {
// contains filtered or unexported fields
}
PeerInfo contains information about a peer
func (*PeerInfo) IntoMetadataEvent ¶
func (p *PeerInfo) IntoMetadataEvent() *types.MetadataReceivedEvent
type PeerMetadata ¶
type PeerMetadata struct { LastSeen time.Time Metadata *eth.MetaDataV1 }
type Peerstore ¶
func NewPeerstore ¶
NewPeerstore creates a new peerstore
func (*Peerstore) AddSubscribedSubnets ¶
func (*Peerstore) PeersToReconnect ¶
PeersToReconnect returns the peers that we need to reconnect to. This includes the not connected peers that have an expired backoff, but also the succesfully connected peers that have not been seen for 1 epoch.
func (*Peerstore) Reset ¶
Reset MUST be called every time we've had a succesful handshake & metadata exchange with a peer. It will reset the backoff counter and the last error, and remove the last status & metadata
func (*Peerstore) SetBackoff ¶
SetBackoff marks the peer as backed off, increments the backoff counter and records the last error. This should only be used on outbound connections.
func (*Peerstore) SetClientVersion ¶
func (*Peerstore) SetMetadata ¶
func (p *Peerstore) SetMetadata(id peer.ID, metadata *eth.MetaDataV1)
type RemoteHostOptions ¶
func WithIPAndPorts ¶
func WithIPAndPorts(ip string, port int) RemoteHostOptions
type ReqResp ¶
type ReqResp struct {
// contains filtered or unexported fields
}
ReqResp handles request-response operations for the node.
func NewReqResp ¶
func (*ReqResp) RegisterHandlers ¶
RegisterHandlers registers all RPC handlers. It verifies that initial status and metadata are valid.