broken version of send

This commit is contained in:
William Banfield
2022-10-19 11:07:46 -04:00
parent 6c81ecb1b5
commit 8989fb4a79
2 changed files with 29 additions and 2 deletions
+27
View File
@@ -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 {
+2 -2
View File
@@ -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
}