mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 12:57:18 +00:00
b0128ad894
* bump bitfield dep * add new methods * get it working * add nil check * add check * one more check * add flag * everything works local run * add debug log * more changes * ensuring p2p interface works enough for tests to pass * all tests pass * include proper naming and comments to fix lint * Apply suggestions from code review * discover by peers * cannot figure out why 0 peers * remove keys * fix test * fix it * fix again * remove log * change back * gaz Co-authored-by: Raul Jordan <raul@prysmaticlabs.com>
69 lines
1.8 KiB
Go
69 lines
1.8 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
|
|
RefreshENR(epoch uint64)
|
|
FindPeersWithSubnet(index uint64) (bool, error)
|
|
}
|
|
|
|
// 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
|
|
}
|