Sentry GRPC: rename Peers to PeerEvents (#3944)

* Sentry GRPC: rename Peers to PeerEvents

see https://github.com/ledgerwatch/interfaces/pull/101

* Update to erigon-lib main

Co-authored-by: Alexey Sharp <alexeysharp@Alexeys-iMac.local>
This commit is contained in:
battlmonstr 2022-04-23 18:52:22 +02:00 committed by GitHub
parent 6844e74ad2
commit 3ad25c929c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 12 deletions

View File

@ -988,18 +988,18 @@ func (ss *SentryServerImpl) Close() {
}
func (ss *SentryServerImpl) sendNewPeerToClients(peerID *proto_types.H512) {
if err := ss.peersStreams.Broadcast(&proto_sentry.PeersReply{PeerId: peerID, Event: proto_sentry.PeersReply_Connect}); err != nil {
if err := ss.peersStreams.Broadcast(&proto_sentry.PeerEvent{PeerId: peerID, EventId: proto_sentry.PeerEvent_Connect}); err != nil {
log.Warn("Sending new peer notice to core P2P failed", "err", err)
}
}
func (ss *SentryServerImpl) sendGonePeerToClients(peerID *proto_types.H512) {
if err := ss.peersStreams.Broadcast(&proto_sentry.PeersReply{PeerId: peerID, Event: proto_sentry.PeersReply_Disconnect}); err != nil {
if err := ss.peersStreams.Broadcast(&proto_sentry.PeerEvent{PeerId: peerID, EventId: proto_sentry.PeerEvent_Disconnect}); err != nil {
log.Warn("Sending gone peer notice to core P2P failed", "err", err)
}
}
func (ss *SentryServerImpl) Peers(req *proto_sentry.PeersRequest, server proto_sentry.Sentry_PeersServer) error {
func (ss *SentryServerImpl) PeerEvents(req *proto_sentry.PeerEventsRequest, server proto_sentry.Sentry_PeerEventsServer) error {
clean := ss.peersStreams.Add(server)
defer clean()
select {
@ -1041,18 +1041,18 @@ func (ss *SentryServerImpl) NodeInfo(_ context.Context, _ *emptypb.Empty) (*prot
type PeersStreams struct {
mu sync.RWMutex
id uint
streams map[uint]proto_sentry.Sentry_PeersServer
streams map[uint]proto_sentry.Sentry_PeerEventsServer
}
func NewPeersStreams() *PeersStreams {
return &PeersStreams{}
}
func (s *PeersStreams) Add(stream proto_sentry.Sentry_PeersServer) (remove func()) {
func (s *PeersStreams) Add(stream proto_sentry.Sentry_PeerEventsServer) (remove func()) {
s.mu.Lock()
defer s.mu.Unlock()
if s.streams == nil {
s.streams = make(map[uint]proto_sentry.Sentry_PeersServer)
s.streams = make(map[uint]proto_sentry.Sentry_PeerEventsServer)
}
s.id++
id := s.id
@ -1060,7 +1060,7 @@ func (s *PeersStreams) Add(stream proto_sentry.Sentry_PeersServer) (remove func(
return func() { s.remove(id) }
}
func (s *PeersStreams) doBroadcast(reply *proto_sentry.PeersReply) (ids []uint, errs []error) {
func (s *PeersStreams) doBroadcast(reply *proto_sentry.PeerEvent) (ids []uint, errs []error) {
s.mu.RLock()
defer s.mu.RUnlock()
for id, stream := range s.streams {
@ -1077,7 +1077,7 @@ func (s *PeersStreams) doBroadcast(reply *proto_sentry.PeersReply) (ids []uint,
return
}
func (s *PeersStreams) Broadcast(reply *proto_sentry.PeersReply) (errs []error) {
func (s *PeersStreams) Broadcast(reply *proto_sentry.PeerEvent) (errs []error) {
var ids []uint
ids, errs = s.doBroadcast(reply)
if len(ids) > 0 {

2
go.mod
View File

@ -35,7 +35,7 @@ require (
github.com/json-iterator/go v1.1.12
github.com/julienschmidt/httprouter v1.3.0
github.com/kevinburke/go-bindata v3.21.0+incompatible
github.com/ledgerwatch/erigon-lib v0.0.0-20220422104938-5f1c2e90116f
github.com/ledgerwatch/erigon-lib v0.0.0-20220423144324-c3b480409230
github.com/ledgerwatch/log/v3 v3.4.1
github.com/ledgerwatch/secp256k1 v1.0.0
github.com/pelletier/go-toml v1.9.5

4
go.sum
View File

@ -454,8 +454,8 @@ github.com/kylelemons/godebug v0.0.0-20170224010052-a616ab194758 h1:0D5M2HQSGD3P
github.com/kylelemons/godebug v0.0.0-20170224010052-a616ab194758/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k=
github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7c=
github.com/leanovate/gopter v0.2.9/go.mod h1:U2L/78B+KVFIx2VmW6onHJQzXtFb+p5y3y2Sh+Jxxv8=
github.com/ledgerwatch/erigon-lib v0.0.0-20220422104938-5f1c2e90116f h1:jY+JNUD3n1Z4PBCIVtbkVSRtWEiZp+aZsbqRN07XFv0=
github.com/ledgerwatch/erigon-lib v0.0.0-20220422104938-5f1c2e90116f/go.mod h1:0VKhW10UjEr7I6DaV+N0KNbXvMygC99qmRl2CfaN9gw=
github.com/ledgerwatch/erigon-lib v0.0.0-20220423144324-c3b480409230 h1:zcnLesdHt2/hLmCPo21zSzMcmhupkZfYp4GyesmodiY=
github.com/ledgerwatch/erigon-lib v0.0.0-20220423144324-c3b480409230/go.mod h1:0VKhW10UjEr7I6DaV+N0KNbXvMygC99qmRl2CfaN9gw=
github.com/ledgerwatch/log/v3 v3.4.1 h1:/xGwlVulXnsO9Uq+tzaExc8OWmXXHU0dnLalpbnY5Bc=
github.com/ledgerwatch/log/v3 v3.4.1/go.mod h1:VXcz6Ssn6XEeU92dCMc39/g1F0OYAjw1Mt+dGP5DjXY=
github.com/ledgerwatch/secp256k1 v1.0.0 h1:Usvz87YoTG0uePIV8woOof5cQnLXGYa162rFf3YnwaQ=

View File

@ -117,7 +117,7 @@ func (ms *MockSentry) SendMessageByMinBlock(_ context.Context, r *proto_sentry.S
ms.sentMessages = append(ms.sentMessages, r.Data)
return nil, nil
}
func (ms *MockSentry) Peers(req *proto_sentry.PeersRequest, server proto_sentry.Sentry_PeersServer) error {
func (ms *MockSentry) PeerEvents(req *proto_sentry.PeerEventsRequest, server proto_sentry.Sentry_PeerEventsServer) error {
return nil
}
func (ms *MockSentry) SendMessageById(_ context.Context, r *proto_sentry.SendMessageByIdRequest) (*proto_sentry.SentPeers, error) {