From 8989fb4a790c6efe92164cceb1db6cb3c1faf7c7 Mon Sep 17 00:00:00 2001 From: William Banfield Date: Wed, 19 Oct 2022 11:07:46 -0400 Subject: [PATCH] broken version of send --- p2p/peer.go | 27 +++++++++++++++++++++++++++ p2p/types.go | 4 ++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/p2p/peer.go b/p2p/peer.go index d8d61a7a0..c90b5f7a9 100644 --- a/p2p/peer.go +++ b/p2p/peer.go @@ -34,6 +34,11 @@ type Peer interface { Status() tmconn.ConnectionStatus SocketAddr() *NetAddress // actual address of the socket + /* + NewSend(Envelope) bool + NewTrySend(Envelope) bool + */ + Send(byte, []byte) bool TrySend(byte, []byte) bool @@ -247,6 +252,28 @@ func (p *peer) Status() tmconn.ConnectionStatus { return p.mconn.Status() } +// Send msg bytes to the channel identified by chID byte. Returns false if the +// send queue is full after timeout, specified by MConnection. +func (p *peer) NewSend(e Envelope) bool { + if !p.IsRunning() { + // see Switch#Broadcast, where we fetch the list of peers and loop over + // them - while we're looping, one peer may be removed and stopped. + return false + } else if !p.hasChannel(e.ChannelID) { + return false + } + msgBytes := MustEncode(e.Message) + res := p.mconn.Send(e.chID, msgBytes) + if res { + labels := []string{ + "peer_id", string(p.ID()), + "chID", fmt.Sprintf("%#x", chID), + } + p.metrics.PeerSendBytesTotal.With(labels...).Add(float64(len(msgBytes))) + } + return res +} + // Send msg bytes to the channel identified by chID byte. Returns false if the // send queue is full after timeout, specified by MConnection. func (p *peer) Send(chID byte, msgBytes []byte) bool { diff --git a/p2p/types.go b/p2p/types.go index ff27c4f23..e38fbe366 100644 --- a/p2p/types.go +++ b/p2p/types.go @@ -9,6 +9,6 @@ type ChannelDescriptor = conn.ChannelDescriptor type ConnectionStatus = conn.ConnectionStatus type Envelope struct { - ChID byte - Message proto.Message + ChannelID byte + Message proto.Message }