mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-27 21:57:16 +00:00
813233373e
* Advanced peer status * Rework errors; add tests * Gazelle * time->roughtime * Update beacon-chain/p2p/handshake.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update beacon-chain/p2p/interfaces.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Downgrade log * Tidy up handshaking logic and commentary * Downgrade log message * Protect connected peers from disconnection; increase high water level to avoid bad interactions at maxPeers
67 lines
1.7 KiB
Go
67 lines
1.7 KiB
Go
package p2p
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/gogo/protobuf/proto"
|
|
"github.com/libp2p/go-libp2p-core/network"
|
|
"github.com/libp2p/go-libp2p-core/peer"
|
|
pubsub "github.com/libp2p/go-libp2p-pubsub"
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/p2p/encoder"
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/p2p/peers"
|
|
)
|
|
|
|
// P2P represents the full p2p interface composed of all of the sub-interfaces.
|
|
type P2P interface {
|
|
Broadcaster
|
|
SetStreamHandler
|
|
EncodingProvider
|
|
PubSubProvider
|
|
PeerManager
|
|
Sender
|
|
ConnectionHandler
|
|
PeersProvider
|
|
}
|
|
|
|
// Broadcaster broadcasts messages to peers over the p2p pubsub protocol.
|
|
type Broadcaster interface {
|
|
Broadcast(context.Context, proto.Message) error
|
|
}
|
|
|
|
// SetStreamHandler configures p2p to handle streams of a certain topic ID.
|
|
type SetStreamHandler interface {
|
|
SetStreamHandler(topic string, handler network.StreamHandler)
|
|
}
|
|
|
|
// ConnectionHandler configures p2p to handle connections with a peer.
|
|
type ConnectionHandler interface {
|
|
AddConnectionHandler(f func(ctx context.Context, id peer.ID) error)
|
|
AddDisconnectionHandler(f func(ctx context.Context, id peer.ID) error)
|
|
}
|
|
|
|
// EncodingProvider provides p2p network encoding.
|
|
type EncodingProvider interface {
|
|
Encoding() encoder.NetworkEncoding
|
|
}
|
|
|
|
// PubSubProvider provides the p2p pubsub protocol.
|
|
type PubSubProvider interface {
|
|
PubSub() *pubsub.PubSub
|
|
}
|
|
|
|
// PeerManager abstracts some peer management methods from libp2p.
|
|
type PeerManager interface {
|
|
Disconnect(peer.ID) error
|
|
PeerID() peer.ID
|
|
}
|
|
|
|
// Sender abstracts the sending functionality from libp2p.
|
|
type Sender interface {
|
|
Send(context.Context, interface{}, peer.ID) (network.Stream, error)
|
|
}
|
|
|
|
// PeersProvider abstracts obtaining our current list of known peers status.
|
|
type PeersProvider interface {
|
|
Peers() *peers.Status
|
|
}
|