Documentation ¶
Overview ¶
Package p2p implements the Ethereum 2.0 networking specification.
Canonical spec reference: https://github.com/ethereum/eth2.0-specs/blob/dev/specs/phase0/p2p-interface.md
Prysm specific implementation design docs
- Networking Design Doc: https://docs.google.com/document/d/1VyhobQRkEjEkEPxmmdWvaHfKWn0j6dEae_wLZlrFtfU/view
This package is heavily utilizes the libp2p go implementation by Protocol Labs.
Index ¶
- Variables
- func MakePeer(addr string) (*peerstore.PeerInfo, error)
- type Broadcaster
- type Config
- type ConnectionHandler
- type EncodingProvider
- type Listener
- type P2P
- type PeerManager
- type PeersProvider
- type PubSubProvider
- type Sender
- type Service
- func (s *Service) AddConnectionHandler(reqFunc func(ctx context.Context, id peer.ID) error)
- func (s *Service) AddDisconnectionHandler(handler func(ctx context.Context, id peer.ID) error)
- func (s *Service) Broadcast(ctx context.Context, msg proto.Message) error
- func (s *Service) Disconnect(pid peer.ID) error
- func (s *Service) Encoding() encoder.NetworkEncoding
- func (s *Service) InfoHandler(w http.ResponseWriter, _ *http.Request)
- func (s *Service) PeerID() peer.ID
- func (s *Service) Peers() *peers.Status
- func (s *Service) PubSub() *pubsub.PubSub
- func (s *Service) Send(ctx context.Context, message interface{}, pid peer.ID) (network.Stream, error)
- func (s *Service) SetStreamHandler(topic string, handler network.StreamHandler)
- func (s *Service) Start()
- func (s *Service) Started() bool
- func (s *Service) Status() error
- func (s *Service) Stop() error
- type SetStreamHandler
Constants ¶
This section is empty.
Variables ¶
var ErrMessageNotMapped = errors.New("message type is not mapped to a PubSub topic")
ErrMessageNotMapped occurs on a Broadcast attempt when a message has not been defined in the GossipTypeMapping.
var GossipTopicMappings = map[string]proto.Message{ "/eth2/beacon_block": &pb.SignedBeaconBlock{}, "/eth2/committee_index%d_beacon_attestation": &pb.Attestation{}, "/eth2/voluntary_exit": &pb.SignedVoluntaryExit{}, "/eth2/proposer_slashing": &pb.ProposerSlashing{}, "/eth2/attester_slashing": &pb.AttesterSlashing{}, "/eth2/beacon_aggregate_and_proof": &pb.AggregateAttestationAndProof{}, }
GossipTopicMappings represent the protocol ID to protobuf message type map for easy lookup.
var GossipTypeMapping = make(map[reflect.Type]string)
GossipTypeMapping is the inverse of GossipTopicMappings so that an arbitrary protobuf message can be mapped to a protocol ID string.
var RPCTopicMappings = map[string]interface{}{ "/eth2/beacon_chain/req/status/1": &p2ppb.Status{}, "/eth2/beacon_chain/req/goodbye/1": new(uint64), "/eth2/beacon_chain/req/beacon_blocks_by_range/1": &p2ppb.BeaconBlocksByRangeRequest{}, "/eth2/beacon_chain/req/beacon_blocks_by_root/1": [][32]byte{}, }
RPCTopicMappings represent the protocol ID to protobuf message type map for easy lookup. These mappings should be used for outbound sending only. Peers may respond with a different message type as defined by the p2p protocol.
var RPCTypeMapping = make(map[reflect.Type]string)
RPCTypeMapping is the inverse of RPCTopicMappings so that an arbitrary protobuf message can be mapped to a protocol ID string.
Functions ¶
Types ¶
type Broadcaster ¶
Broadcaster broadcasts messages to peers over the p2p pubsub protocol.
type Config ¶
type Config struct { NoDiscovery bool StaticPeers []string BootstrapNodeAddr []string KademliaBootStrapAddr []string Discv5BootStrapAddr []string RelayNodeAddr string LocalIP string HostAddress string HostDNS string PrivateKey string DataDir string TCPPort uint UDPPort uint MaxPeers uint WhitelistCIDR string EnableUPnP bool Encoding string }
Config for the p2p service. These parameters are set from application level flags to initialize the p2p service.
type ConnectionHandler ¶
type ConnectionHandler interface { AddConnectionHandler(f func(ctx context.Context, id peer.ID) error) AddDisconnectionHandler(f func(ctx context.Context, id peer.ID) error) }
ConnectionHandler configures p2p to handle connections with a peer.
type EncodingProvider ¶
type EncodingProvider interface {
Encoding() encoder.NetworkEncoding
}
EncodingProvider provides p2p network encoding.
type Listener ¶
type Listener interface { Self() *enode.Node Close() Lookup(enode.ID) []*enode.Node ReadRandomNodes([]*enode.Node) int Resolve(*enode.Node) *enode.Node LookupRandom() []*enode.Node Ping(*enode.Node) error RequestENR(*enode.Node) (*enode.Node, error) }
Listener defines the discovery V5 network interface that is used to communicate with other peers.
type P2P ¶
type P2P interface { Broadcaster SetStreamHandler EncodingProvider PubSubProvider PeerManager Sender ConnectionHandler PeersProvider }
P2P represents the full p2p interface composed of all of the sub-interfaces.
type PeerManager ¶
PeerManager abstracts some peer management methods from libp2p.
type PeersProvider ¶
PeersProvider abstracts obtaining our current list of known peers status.
type PubSubProvider ¶
PubSubProvider provides the p2p pubsub protocol.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service for managing peer to peer (p2p) networking.
func NewService ¶
NewService initializes a new p2p service compatible with shared.Service interface. No connections are made until the Start function is called during the service registry startup.
func (*Service) AddConnectionHandler ¶
AddConnectionHandler adds a callback function which handles the connection with a newly added peer. It performs a handshake with that peer by sending a hello request and validating the response from the peer.
func (*Service) AddDisconnectionHandler ¶
AddDisconnectionHandler disconnects from peers. It handles updating the peer status. This also calls the handler responsible for maintaining other parts of the sync or p2p system.
func (*Service) Disconnect ¶
Disconnect from a peer.
func (*Service) Encoding ¶
func (s *Service) Encoding() encoder.NetworkEncoding
Encoding returns the configured networking encoding.
func (*Service) InfoHandler ¶
func (s *Service) InfoHandler(w http.ResponseWriter, _ *http.Request)
InfoHandler is a handler to serve /p2p page in metrics.
func (*Service) Send ¶
func (s *Service) Send(ctx context.Context, message interface{}, pid peer.ID) (network.Stream, error)
Send a message to a specific peer. The returned stream may be used for reading, but has been closed for writing.
func (*Service) SetStreamHandler ¶
func (s *Service) SetStreamHandler(topic string, handler network.StreamHandler)
SetStreamHandler sets the protocol handler on the p2p host multiplexer. This method is a pass through to libp2pcore.Host.SetStreamHandler.
type SetStreamHandler ¶
type SetStreamHandler interface {
SetStreamHandler(topic string, handler network.StreamHandler)
}
SetStreamHandler configures p2p to handle streams of a certain topic ID.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package connmgr : This file is forked from github.com/libp2p/go-libp2p-core/connmgr/connmgr.go
|
Package connmgr : This file is forked from github.com/libp2p/go-libp2p-core/connmgr/connmgr.go |
Package encoder allows for registering custom data encoders for information sent as raw bytes over the wire via p2p to other nodes.
|
Package encoder allows for registering custom data encoders for information sent as raw bytes over the wire via p2p to other nodes. |
Package peers provides information about peers at the Ethereum protocol level.
|
Package peers provides information about peers at the Ethereum protocol level. |