From 6553d8ce0338583579f34b95ff5ac69fd7a08d26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Papp?= Date: Tue, 9 Jul 2024 16:50:29 +0200 Subject: [PATCH] Sonar fix --- relay/server/peer.go | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/relay/server/peer.go b/relay/server/peer.go index c49b8feca..6509f7bd3 100644 --- a/relay/server/peer.go +++ b/relay/server/peer.go @@ -65,26 +65,7 @@ func (p *Peer) Work() { case messages.MsgTypeHealthCheck: hc.OnHCResponse() case messages.MsgTypeTransport: - peerID, err := messages.UnmarshalTransportID(msg) - if err != nil { - p.log.Errorf("failed to unmarshal transport message: %s", err) - continue - } - stringPeerID := messages.HashIDToString(peerID) - dp, ok := p.store.Peer(stringPeerID) - if !ok { - p.log.Errorf("peer not found: %s", stringPeerID) - continue - } - err = messages.UpdateTransportMsg(msg, p.idB) - if err != nil { - p.log.Errorf("failed to update transport message: %s", err) - continue - } - _, err = dp.Write(msg) - if err != nil { - p.log.Errorf("failed to write transport message to: %s", dp.String()) - } + p.handleTransportMsg(msg) case messages.MsgTypeClose: p.log.Infof("peer exited gracefully") _ = p.conn.Close() @@ -161,3 +142,26 @@ func (p *Peer) healthcheck(ctx context.Context, hc *healthcheck.Sender) { } } } + +func (p *Peer) handleTransportMsg(msg []byte) { + peerID, err := messages.UnmarshalTransportID(msg) + if err != nil { + p.log.Errorf("failed to unmarshal transport message: %s", err) + return + } + stringPeerID := messages.HashIDToString(peerID) + dp, ok := p.store.Peer(stringPeerID) + if !ok { + p.log.Errorf("peer not found: %s", stringPeerID) + return + } + err = messages.UpdateTransportMsg(msg, p.idB) + if err != nil { + p.log.Errorf("failed to update transport message: %s", err) + return + } + _, err = dp.Write(msg) + if err != nil { + p.log.Errorf("failed to write transport message to: %s", dp.String()) + } +}