Skip to content
This repository has been archived by the owner on Sep 6, 2022. It is now read-only.

Commit

Permalink
Only log once if we failed to convert from netAddr (#264)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoPolo authored Jun 24, 2022
1 parent 0c14794 commit b430f5b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
3 changes: 2 additions & 1 deletion canonicallog/canonicallog.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ func LogMisbehavingPeer(p peer.ID, peerAddr multiaddr.Multiaddr, component strin
func LogMisbehavingPeerNetAddr(p peer.ID, peerAddr net.Addr, component string, originalErr error, msg string) {
ma, err := manet.FromNetAddr(peerAddr)
if err != nil {
log.Errorf("CANONICAL_MISBEHAVING_PEER: peer=%s netAddr=%s component=%s err=%v msg=%s", p, peerAddr.String(), component, originalErr, msg)
log.Errorf("CANONICAL_MISBEHAVING_PEER: peer=%s netAddr=%s component=%s err=%v fromNetAddrErr=%v msg=%s", p, peerAddr.String(), component, originalErr, err, msg)
return
}

log.Errorf("CANONICAL_MISBEHAVING_PEER: peer=%s addr=%s component=%s err=%v msg=%s", p, ma, component, originalErr, msg)
Expand Down
10 changes: 4 additions & 6 deletions canonicallog/canonicallog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package canonicallog

import (
"fmt"
"net"
"testing"

"github.com/libp2p/go-libp2p-core/test"
Expand All @@ -10,10 +11,7 @@ import (

func TestLogs(t *testing.T) {
LogMisbehavingPeer(test.RandPeerIDFatal(t), multiaddr.StringCast("/ip4/1.2.3.4"), "somecomponent", fmt.Errorf("something"), "hi")
LogMisbehavingPeerNetAddr(test.RandPeerIDFatal(t), dummyNetAddr{}, "somecomponent", fmt.Errorf("something"), "hi")
}

type dummyNetAddr struct{}

func (d dummyNetAddr) Network() string { return "tcp" }
func (d dummyNetAddr) String() string { return "127.0.0.1:80" }
netAddr := &net.TCPAddr{IP: net.ParseIP("127.0.0.1"), Port: 80}
LogMisbehavingPeerNetAddr(test.RandPeerIDFatal(t), netAddr, "somecomponent", fmt.Errorf("something"), "hi")
}

0 comments on commit b430f5b

Please sign in to comment.