mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 21:07:18 +00:00
5aac06f04e
* begin move * use same import path * imports * regen protos * regen * no rename * generate ssz * gaz * fmt * edit build file * imports * modify * remove generated files * remove protos * edit imports in prysm * beacon chain all builds * edit script * add generated pbs * add replace rules * license for ethereumapis protos * change visibility * fmt * update build files to gaz ignore * use proper form * edit imports * wrap block * revert scripts * revert go mod
98 lines
3.0 KiB
Go
98 lines
3.0 KiB
Go
package p2p
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/ethereum/go-ethereum/p2p/enr"
|
|
"github.com/libp2p/go-libp2p-core/connmgr"
|
|
"github.com/libp2p/go-libp2p-core/host"
|
|
"github.com/libp2p/go-libp2p-core/network"
|
|
"github.com/libp2p/go-libp2p-core/peer"
|
|
pubsub "github.com/libp2p/go-libp2p-pubsub"
|
|
"github.com/multiformats/go-multiaddr"
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/p2p/encoder"
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/p2p/peers"
|
|
ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1"
|
|
"github.com/prysmaticlabs/prysm/shared/interfaces"
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
// P2P represents the full p2p interface composed of all of the sub-interfaces.
|
|
type P2P interface {
|
|
Broadcaster
|
|
SetStreamHandler
|
|
EncodingProvider
|
|
PubSubProvider
|
|
PubSubTopicUser
|
|
PeerManager
|
|
Sender
|
|
ConnectionHandler
|
|
PeersProvider
|
|
MetadataProvider
|
|
}
|
|
|
|
// Broadcaster broadcasts messages to peers over the p2p pubsub protocol.
|
|
type Broadcaster interface {
|
|
Broadcast(context.Context, proto.Message) error
|
|
BroadcastAttestation(ctx context.Context, subnet uint64, att *ethpb.Attestation) error
|
|
}
|
|
|
|
// SetStreamHandler configures p2p to handle streams of a certain topic ID.
|
|
type SetStreamHandler interface {
|
|
SetStreamHandler(topic string, handler network.StreamHandler)
|
|
}
|
|
|
|
// PubSubTopicUser provides way to join, use and leave PubSub topics.
|
|
type PubSubTopicUser interface {
|
|
JoinTopic(topic string, opts ...pubsub.TopicOpt) (*pubsub.Topic, error)
|
|
LeaveTopic(topic string) error
|
|
PublishToTopic(ctx context.Context, topic string, data []byte, opts ...pubsub.PubOpt) error
|
|
SubscribeToTopic(topic string, opts ...pubsub.SubOpt) (*pubsub.Subscription, error)
|
|
}
|
|
|
|
// ConnectionHandler configures p2p to handle connections with a peer.
|
|
type ConnectionHandler interface {
|
|
AddConnectionHandler(f func(ctx context.Context, id peer.ID) error,
|
|
j func(ctx context.Context, id peer.ID) error)
|
|
AddDisconnectionHandler(f func(ctx context.Context, id peer.ID) error)
|
|
connmgr.ConnectionGater
|
|
}
|
|
|
|
// 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
|
|
Host() host.Host
|
|
ENR() *enr.Record
|
|
DiscoveryAddresses() ([]multiaddr.Multiaddr, error)
|
|
RefreshENR()
|
|
FindPeersWithSubnet(ctx context.Context, topic string, index, threshold uint64) (bool, error)
|
|
AddPingMethod(reqFunc func(ctx context.Context, id peer.ID) error)
|
|
}
|
|
|
|
// Sender abstracts the sending functionality from libp2p.
|
|
type Sender interface {
|
|
Send(context.Context, interface{}, string, peer.ID) (network.Stream, error)
|
|
}
|
|
|
|
// PeersProvider abstracts obtaining our current list of known peers status.
|
|
type PeersProvider interface {
|
|
Peers() *peers.Status
|
|
}
|
|
|
|
// MetadataProvider returns the metadata related information for the local peer.
|
|
type MetadataProvider interface {
|
|
Metadata() interfaces.Metadata
|
|
MetadataSeq() uint64
|
|
}
|