Browse Source

Improving peer error handling

postalpha
Sarah Jamie Lewis 1 year ago
parent
commit
6697c73222
2 changed files with 10 additions and 5 deletions
  1. +5
    -2
      protocol/connections/engine.go
  2. +5
    -3
      protocol/connections/peerpeerconnection.go

+ 5
- 2
protocol/connections/engine.go View File

@@ -86,9 +86,12 @@ func (e *Engine) eventHandler() {
log.Debugf("Sending Message to Peer.....")
ppc := e.connectionsManager.GetPeerPeerConnectionForOnion(ev.Data[event.RemotePeer])
if ppc != nil && ppc.GetState() == AUTHENTICATED {
ppc.SendPacket([]byte(ev.Data[event.Data]))
err := ppc.SendPacket([]byte(ev.Data[event.Data]))
if err != nil {
e.eventManager.Publish(event.NewEvent(event.SendMessageToPeerError, map[event.Field]string{event.RemotePeer: ev.Data[event.RemotePeer], event.Signature: ev.EventID, event.Error: err.Error()}))
}
} else {
e.eventManager.Publish(event.NewEvent(event.SendMessageToPeerError, map[event.Field]string{event.RemotePeer: ev.Data[event.RemotePeer], event.Error: "peer is offline or the connection has yet to finalize"}))
e.eventManager.Publish(event.NewEvent(event.SendMessageToPeerError, map[event.Field]string{event.RemotePeer: ev.Data[event.RemotePeer], event.Signature: ev.EventID, event.Error: "peer is offline or the connection has yet to finalize"}))
}
case event.BlockPeer:
e.blocked.Store(ev.Data[event.RemotePeer], true)


+ 5
- 3
protocol/connections/peerpeerconnection.go View File

@@ -2,6 +2,7 @@ package connections

import (
"cwtch.im/cwtch/protocol/connections/peer"
"errors"
"git.openprivacy.ca/openprivacy/libricochet-go"
"git.openprivacy.ca/openprivacy/libricochet-go/channels"
"git.openprivacy.ca/openprivacy/libricochet-go/connection"
@@ -33,18 +34,19 @@ func (ppc *PeerPeerConnection) GetState() ConnectionState {
}

// SendPacket sends data packets on the optional data channel
func (ppc *PeerPeerConnection) SendPacket(data []byte) {
func (ppc *PeerPeerConnection) SendPacket(data []byte) error {
ppc.WaitTilAuthenticated()
ppc.connection.Do(func() error {
return ppc.connection.Do(func() error {
channel := ppc.connection.Channel("im.cwtch.peer.data", channels.Outbound)
if channel != nil {
peerchannel, ok := channel.Handler.(*peer.CwtchPeerDataChannel)
if ok {
log.Debugf("Sending packet\n")
peerchannel.SendMessage(data)
return nil
}
}
return nil
return errors.New("failed to send packet to peer")
})
}



Loading…
Cancel
Save