prysm-pulse/beacon-chain/p2p/interfaces.go
Preston Van Loon 95c528f0bc First pass: single peer initial sync (#3363)
* lint

* add requests

* add all new stuff

* comment

* preston's review

* initial commit

* reorder sync so it isn't required to wait until start

* checkpoint

* fix

* improved handler API

* Set up prechain start values

* improved handler API

* ooops

* successful peer handshakes

* successful peer handshakes

* successful peer handshakes

* checkpoint

* chpkt

* handle init after chain start

* emit state initialized feed if existing db state

* merge error

* Done

* Test

* Fixed test

* emit state initialized

* force fork choice update

* wait for genesis time

* sync to current slot

* Use saved head in DB

* gaz

* fix tests

* lint

* lint

* lint

* lint

* Revert "Use saved head in DB"

This reverts commit c5f3404fdf333c8aac20bce8c349b1978494616b.

* remove db

* lint

* remove unused interfaces from composite

* resolve comments
2019-08-30 15:15:40 -05:00

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"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
)
// P2P represents the full p2p interface composed of all of the sub-interfaces.
type P2P interface {
Broadcaster
SetStreamHandler
EncodingProvider
PubSubProvider
PeerManager
HandshakeManager
Sender
ConnectionHandler
DeprecatedSubscriber
}
// 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)
}
// 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
}
// HandshakeManager abstracts certain methods regarding handshake records.
type HandshakeManager interface {
AddHandshake(peer.ID, *pb.Hello)
}
// Sender abstracts the sending functionality from libp2p.
type Sender interface {
Send(context.Context, proto.Message, peer.ID) (network.Stream, error)
}