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

[canonicallog] Only log once if we failed to convert from netAddr #264

Merged
merged 1 commit into from
Jun 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
}