Documentation ¶
Index ¶
- Constants
- func ConvertH512ToPeerID(h512 *proto_types.H512) [64]byte
- func GrpcClient(ctx context.Context, sentryAddr string) (*direct.SentryClientRemote, error)
- func Sentry(ctx context.Context, dirs datadir.Dirs, sentryAddr string, ...) error
- type GrpcServer
- func (ss *GrpcServer) Close()
- func (ss *GrpcServer) GetStatus() *proto_sentry.StatusData
- func (ss *GrpcServer) HandShake(context.Context, *emptypb.Empty) (*proto_sentry.HandShakeReply, error)
- func (ss *GrpcServer) Messages(req *proto_sentry.MessagesRequest, server proto_sentry.Sentry_MessagesServer) error
- func (ss *GrpcServer) NodeInfo(_ context.Context, _ *emptypb.Empty) (*proto_types.NodeInfoReply, error)
- func (ss *GrpcServer) PeerById(_ context.Context, req *proto_sentry.PeerByIdRequest) (*proto_sentry.PeerByIdReply, error)
- func (ss *GrpcServer) PeerCount(_ context.Context, req *proto_sentry.PeerCountRequest) (*proto_sentry.PeerCountReply, error)
- func (ss *GrpcServer) PeerEvents(req *proto_sentry.PeerEventsRequest, ...) error
- func (ss *GrpcServer) PeerMinBlock(_ context.Context, req *proto_sentry.PeerMinBlockRequest) (*emptypb.Empty, error)
- func (ss *GrpcServer) Peers(_ context.Context, _ *emptypb.Empty) (*proto_sentry.PeersReply, error)
- func (ss *GrpcServer) PenalizePeer(_ context.Context, req *proto_sentry.PenalizePeerRequest) (*emptypb.Empty, error)
- func (ss *GrpcServer) SendMessageById(_ context.Context, inreq *proto_sentry.SendMessageByIdRequest) (*proto_sentry.SentPeers, error)
- func (ss *GrpcServer) SendMessageByMinBlock(_ context.Context, inreq *proto_sentry.SendMessageByMinBlockRequest) (*proto_sentry.SentPeers, error)
- func (ss *GrpcServer) SendMessageToAll(ctx context.Context, req *proto_sentry.OutboundMessageData) (*proto_sentry.SentPeers, error)
- func (ss *GrpcServer) SendMessageToRandomPeers(ctx context.Context, req *proto_sentry.SendMessageToRandomPeersRequest) (*proto_sentry.SentPeers, error)
- func (ss *GrpcServer) SetStatus(ctx context.Context, statusData *proto_sentry.StatusData) (*proto_sentry.SetStatusReply, error)
- func (ss *GrpcServer) SimplePeerCount() map[uint]int
- type MultiClient
- func (cs *MultiClient) BroadcastNewBlock(ctx context.Context, header *types.Header, body *types.RawBody, td *big.Int)
- func (cs *MultiClient) HandleInboundMessage(ctx context.Context, message *proto_sentry.InboundMessage, ...) (err error)
- func (cs *MultiClient) HandlePeerEvent(ctx context.Context, event *proto_sentry.PeerEvent, sentry direct.SentryClient) error
- func (cs *MultiClient) PeerEventsLoop(ctx context.Context, sentry direct.SentryClient, wg *sync.WaitGroup)
- func (cs *MultiClient) Penalize(ctx context.Context, penalties []headerdownload.PenaltyItem)
- func (cs *MultiClient) PropagateNewBlockHashes(ctx context.Context, announces []headerdownload.Announce)
- func (cs *MultiClient) RecvMessageLoop(ctx context.Context, sentry direct.SentryClient, wg *sync.WaitGroup)
- func (cs *MultiClient) RecvUploadHeadersMessageLoop(ctx context.Context, sentry direct.SentryClient, wg *sync.WaitGroup)
- func (cs *MultiClient) RecvUploadMessageLoop(ctx context.Context, sentry direct.SentryClient, wg *sync.WaitGroup)
- func (cs *MultiClient) SendBodyRequest(ctx context.Context, req *bodydownload.BodyRequest) (peerID [64]byte, ok bool)
- func (cs *MultiClient) SendHeaderRequest(ctx context.Context, req *headerdownload.HeaderRequest) (peerID [64]byte, ok bool)
- func (cs *MultiClient) Sentries() []direct.SentryClient
- func (cs *MultiClient) StartStreamLoops(ctx context.Context)
- func (cs *MultiClient) UpdateHead(ctx context.Context, height, time uint64, hash libcommon.Hash, td *uint256.Int)
- type PeerInfo
- func (pi *PeerInfo) AddDeadline(deadline time.Time)
- func (pi *PeerInfo) Async(f func())
- func (pi *PeerInfo) ClearDeadlines(now time.Time, givePermit bool) int
- func (pi *PeerInfo) Close()
- func (pi *PeerInfo) Height() uint64
- func (pi *PeerInfo) ID() [64]byte
- func (pi *PeerInfo) LatestDeadline() time.Time
- func (pi *PeerInfo) Remove()
- func (pi *PeerInfo) Removed() bool
- func (pi *PeerInfo) SetIncreasedHeight(newHeight uint64)
- type PeerRef
- type PeersByMinBlock
- type PeersStreams
Constants ¶
const MessagesQueueSize = 1024 // one such queue per client of .Messages stream
Variables ¶
This section is empty.
Functions ¶
func ConvertH512ToPeerID ¶
func ConvertH512ToPeerID(h512 *proto_types.H512) [64]byte
ConvertH512ToPeerID() ensures the return type is [64]byte so that short variable declarations will still be formatted as hex in logs
func GrpcClient ¶
Types ¶
type GrpcServer ¶
type GrpcServer struct { proto_sentry.UnimplementedSentryServer Protocols []p2p.Protocol GoodPeers sync.Map P2pServer *p2p.Server TxSubscribed uint32 // Set to non-zero if downloader is subscribed to transaction messages // contains filtered or unexported fields }
func NewGrpcServer ¶
func (*GrpcServer) Close ¶
func (ss *GrpcServer) Close()
Close performs cleanup operations for the sentry
func (*GrpcServer) GetStatus ¶
func (ss *GrpcServer) GetStatus() *proto_sentry.StatusData
func (*GrpcServer) HandShake ¶
func (ss *GrpcServer) HandShake(context.Context, *emptypb.Empty) (*proto_sentry.HandShakeReply, error)
func (*GrpcServer) Messages ¶
func (ss *GrpcServer) Messages(req *proto_sentry.MessagesRequest, server proto_sentry.Sentry_MessagesServer) error
func (*GrpcServer) NodeInfo ¶
func (ss *GrpcServer) NodeInfo(_ context.Context, _ *emptypb.Empty) (*proto_types.NodeInfoReply, error)
func (*GrpcServer) PeerById ¶
func (ss *GrpcServer) PeerById(_ context.Context, req *proto_sentry.PeerByIdRequest) (*proto_sentry.PeerByIdReply, error)
func (*GrpcServer) PeerCount ¶
func (ss *GrpcServer) PeerCount(_ context.Context, req *proto_sentry.PeerCountRequest) (*proto_sentry.PeerCountReply, error)
func (*GrpcServer) PeerEvents ¶
func (ss *GrpcServer) PeerEvents(req *proto_sentry.PeerEventsRequest, server proto_sentry.Sentry_PeerEventsServer) error
func (*GrpcServer) PeerMinBlock ¶
func (ss *GrpcServer) PeerMinBlock(_ context.Context, req *proto_sentry.PeerMinBlockRequest) (*emptypb.Empty, error)
func (*GrpcServer) Peers ¶
func (ss *GrpcServer) Peers(_ context.Context, _ *emptypb.Empty) (*proto_sentry.PeersReply, error)
func (*GrpcServer) PenalizePeer ¶
func (ss *GrpcServer) PenalizePeer(_ context.Context, req *proto_sentry.PenalizePeerRequest) (*emptypb.Empty, error)
func (*GrpcServer) SendMessageById ¶
func (ss *GrpcServer) SendMessageById(_ context.Context, inreq *proto_sentry.SendMessageByIdRequest) (*proto_sentry.SentPeers, error)
func (*GrpcServer) SendMessageByMinBlock ¶
func (ss *GrpcServer) SendMessageByMinBlock(_ context.Context, inreq *proto_sentry.SendMessageByMinBlockRequest) (*proto_sentry.SentPeers, error)
func (*GrpcServer) SendMessageToAll ¶
func (ss *GrpcServer) SendMessageToAll(ctx context.Context, req *proto_sentry.OutboundMessageData) (*proto_sentry.SentPeers, error)
func (*GrpcServer) SendMessageToRandomPeers ¶
func (ss *GrpcServer) SendMessageToRandomPeers(ctx context.Context, req *proto_sentry.SendMessageToRandomPeersRequest) (*proto_sentry.SentPeers, error)
func (*GrpcServer) SetStatus ¶
func (ss *GrpcServer) SetStatus(ctx context.Context, statusData *proto_sentry.StatusData) (*proto_sentry.SetStatusReply, error)
func (*GrpcServer) SimplePeerCount ¶
func (ss *GrpcServer) SimplePeerCount() map[uint]int
type MultiClient ¶
type MultiClient struct { Hd *headerdownload.HeaderDownload Bd *bodydownload.BodyDownload IsMock bool ChainConfig *chain.Config Engine consensus.Engine // contains filtered or unexported fields }
MultiClient - does handle request/response/subscriptions to multiple sentries each sentry may support same or different p2p protocol
func NewMultiClient ¶
func NewMultiClient( db kv.RwDB, nodeName string, chainConfig *chain.Config, genesisHash libcommon.Hash, engine consensus.Engine, networkID uint64, sentries []direct.SentryClient, syncCfg ethconfig.Sync, blockReader services.HeaderAndCanonicalReader, logPeerInfo bool, forkValidator *engineapi.ForkValidator, dropUselessPeers bool, ) (*MultiClient, error)
func (*MultiClient) BroadcastNewBlock ¶
func (*MultiClient) HandleInboundMessage ¶
func (cs *MultiClient) HandleInboundMessage(ctx context.Context, message *proto_sentry.InboundMessage, sentry direct.SentryClient) (err error)
func (*MultiClient) HandlePeerEvent ¶
func (cs *MultiClient) HandlePeerEvent(ctx context.Context, event *proto_sentry.PeerEvent, sentry direct.SentryClient) error
func (*MultiClient) PeerEventsLoop ¶
func (cs *MultiClient) PeerEventsLoop( ctx context.Context, sentry direct.SentryClient, wg *sync.WaitGroup, )
func (*MultiClient) Penalize ¶
func (cs *MultiClient) Penalize(ctx context.Context, penalties []headerdownload.PenaltyItem)
sending list of penalties to all sentries
func (*MultiClient) PropagateNewBlockHashes ¶
func (cs *MultiClient) PropagateNewBlockHashes(ctx context.Context, announces []headerdownload.Announce)
func (*MultiClient) RecvMessageLoop ¶
func (cs *MultiClient) RecvMessageLoop( ctx context.Context, sentry direct.SentryClient, wg *sync.WaitGroup, )
func (*MultiClient) RecvUploadHeadersMessageLoop ¶
func (cs *MultiClient) RecvUploadHeadersMessageLoop( ctx context.Context, sentry direct.SentryClient, wg *sync.WaitGroup, )
func (*MultiClient) RecvUploadMessageLoop ¶
func (cs *MultiClient) RecvUploadMessageLoop( ctx context.Context, sentry direct.SentryClient, wg *sync.WaitGroup, )
func (*MultiClient) SendBodyRequest ¶
func (cs *MultiClient) SendBodyRequest(ctx context.Context, req *bodydownload.BodyRequest) (peerID [64]byte, ok bool)
func (*MultiClient) SendHeaderRequest ¶
func (cs *MultiClient) SendHeaderRequest(ctx context.Context, req *headerdownload.HeaderRequest) (peerID [64]byte, ok bool)
func (*MultiClient) Sentries ¶
func (cs *MultiClient) Sentries() []direct.SentryClient
func (*MultiClient) StartStreamLoops ¶
func (cs *MultiClient) StartStreamLoops(ctx context.Context)
StartStreamLoops starts message processing loops for all sentries. The processing happens in several streams: RecvMessage - processing incoming headers/bodies RecvUploadMessage - sending bodies/receipts - may be heavy, it's ok to not process this messages enough fast, it's also ok to drop some of these messages if we can't process. RecvUploadHeadersMessage - sending headers - dedicated stream because headers propagation speed important for network health PeerEventsLoop - logging peer connect/disconnect events
func (*MultiClient) UpdateHead ¶
type PeerInfo ¶
type PeerInfo struct {
// contains filtered or unexported fields
}
PeerInfo collects various extra bits of information about the peer, for example deadlines that is used for regulating requests sent to the peer
func NewPeerInfo ¶
func NewPeerInfo(peer *p2p.Peer, rw p2p.MsgReadWriter) *PeerInfo
func (*PeerInfo) AddDeadline ¶
AddDeadline adds given deadline to the list of deadlines Deadlines must be added in the chronological order for the function ClearDeadlines to work correctly (it uses binary search)
func (*PeerInfo) ClearDeadlines ¶
ClearDeadlines goes through the deadlines of given peers and removes the ones that have passed Optionally, it also clears one extra deadline - this is used when response is received It returns the number of deadlines left
func (*PeerInfo) LatestDeadline ¶
func (*PeerInfo) SetIncreasedHeight ¶
SetIncreasedHeight atomically updates PeerInfo.height only if newHeight is higher
type PeersByMinBlock ¶
type PeersByMinBlock []PeerRef
PeersByMinBlock is the priority queue of peers. Used to select certain number of peers considered to be "best available"
func (PeersByMinBlock) Len ¶
func (bp PeersByMinBlock) Len() int
Len (part of heap.Interface) returns the current size of the best peers queue
func (PeersByMinBlock) Less ¶
func (bp PeersByMinBlock) Less(i, j int) bool
Less (part of heap.Interface) compares two peers
func (*PeersByMinBlock) Pop ¶
func (bp *PeersByMinBlock) Pop() interface{}
Pop (part of heap.Interface) removes the first peer from the queue
func (*PeersByMinBlock) Push ¶
func (bp *PeersByMinBlock) Push(x interface{})
Push (part of heap.Interface) places a new peer onto the end of queue.
func (PeersByMinBlock) Swap ¶
func (bp PeersByMinBlock) Swap(i, j int)
Swap (part of heap.Interface) moves two peers in the queue into each other's places.
type PeersStreams ¶
type PeersStreams struct {
// contains filtered or unexported fields
}
PeersStreams - it's safe to use this class as non-pointer
func NewPeersStreams ¶
func NewPeersStreams() *PeersStreams
func (*PeersStreams) Add ¶
func (s *PeersStreams) Add(stream proto_sentry.Sentry_PeerEventsServer) (remove func())
func (*PeersStreams) Broadcast ¶
func (s *PeersStreams) Broadcast(reply *proto_sentry.PeerEvent) (errs []error)
func (*PeersStreams) Len ¶
func (s *PeersStreams) Len() int