From 04a93f4080573f846ea3cf8271e7bad3d24134ae Mon Sep 17 00:00:00 2001 From: Cory Schwartz Date: Wed, 14 Apr 2021 18:19:07 -0700 Subject: [PATCH 1/4] static check fixes --- options.go | 6 ++---- p2p/discovery/mdns.go | 10 +++++----- p2p/host/basic/basic_host.go | 7 +++---- p2p/host/relay/addrsplosion.go | 3 +-- p2p/host/relay/autorelay.go | 12 ++++++++++-- p2p/host/relay/autorelay_test.go | 8 ++++---- p2p/host/relay/relay.go | 5 +++-- p2p/host/routed/routed.go | 5 ++--- p2p/net/mock/mock_net.go | 4 ++-- p2p/net/mock/mock_test.go | 17 +++++++++-------- p2p/protocol/identify/id.go | 6 +++--- p2p/protocol/identify/id_delta.go | 4 ++-- p2p/protocol/identify/id_test.go | 2 -- p2p/protocol/identify/obsaddr.go | 3 +-- p2p/protocol/identify/peer_loop.go | 4 +--- p2p/protocol/ping/ping.go | 2 +- 16 files changed, 49 insertions(+), 49 deletions(-) diff --git a/options.go b/options.go index 3c9a0b4a..7440627e 100644 --- a/options.go +++ b/options.go @@ -341,8 +341,7 @@ func FilterAddresses(addrs ...*net.IPNet) Option { if cfg.ConnectionGater != nil { var ok bool if f, ok = cfg.ConnectionGater.(*filtersConnectionGater); !ok { - return errors.New("cannot configure both Filters and Connection Gater. " + - "\n Please consider configuring just a ConnectionGater instead.") + return errors.New("cannot configure both Filters and Connection Gater; please consider configuring just a ConnectionGater instead") } } @@ -371,8 +370,7 @@ func FilterAddresses(addrs ...*net.IPNet) Option { func Filters(filters *ma.Filters) Option { return func(cfg *Config) error { if cfg.ConnectionGater != nil { - return errors.New("cannot configure both Filters and Connection Gater. " + - "\n Please consider configuring just a ConnectionGater instead.") + return errors.New("cannot configure both Filters and Connection Gater; please consider configuring just a ConnectionGater instead") } cfg.ConnectionGater = (*filtersConnectionGater)(filters) diff --git a/p2p/discovery/mdns.go b/p2p/discovery/mdns.go index 57218588..d0267e41 100644 --- a/p2p/discovery/mdns.go +++ b/p2p/discovery/mdns.go @@ -76,7 +76,7 @@ func NewMdnsService(ctx context.Context, peerhost host.Host, interval time.Durat addrs, err := getDialableListenAddrs(peerhost) if err != nil { - log.Warning(err) + log.Warn(err) } else { port = addrs[0].Port for _, a := range addrs { @@ -158,9 +158,9 @@ func (m *mdnsService) pollForEntries(ctx context.Context) { func (m *mdnsService) handleEntry(e *mdns.ServiceEntry) { log.Debugf("Handling MDNS entry: [IPv4 %s][IPv6 %s]:%d %s", e.AddrV4, e.AddrV6, e.Port, e.Info) - mpeer, err := peer.IDB58Decode(e.Info) + mpeer, err := peer.Decode(e.Info) if err != nil { - log.Warning("Error parsing peer ID from mdns entry: ", err) + log.Warn("Error parsing peer ID from mdns entry: ", err) return } @@ -175,7 +175,7 @@ func (m *mdnsService) handleEntry(e *mdns.ServiceEntry) { } else if e.AddrV6 != nil { addr = e.AddrV6 } else { - log.Warning("Error parsing multiaddr from mdns entry: no IP address found") + log.Warn("Error parsing multiaddr from mdns entry: no IP address found") return } @@ -184,7 +184,7 @@ func (m *mdnsService) handleEntry(e *mdns.ServiceEntry) { Port: e.Port, }) if err != nil { - log.Warning("Error parsing multiaddr from mdns entry: ", err) + log.Warn("Error parsing multiaddr from mdns entry: ", err) return } diff --git a/p2p/host/basic/basic_host.go b/p2p/host/basic/basic_host.go index 7293c2b8..6a7f02e6 100644 --- a/p2p/host/basic/basic_host.go +++ b/p2p/host/basic/basic_host.go @@ -29,7 +29,6 @@ import ( logging "github.com/ipfs/go-log" - "github.com/multiformats/go-multiaddr" ma "github.com/multiformats/go-multiaddr" madns "github.com/multiformats/go-multiaddr-dns" manet "github.com/multiformats/go-multiaddr/net" @@ -393,7 +392,7 @@ func (h *BasicHost) newStreamHandler(s network.Stream) { if err == io.EOF { logf := log.Debugf if took > time.Second*10 { - logf = log.Warningf + logf = log.Warnf } logf("protocol EOF: %s (took %s)", s.Conn().RemotePeer(), took) } else { @@ -465,7 +464,7 @@ func makeUpdatedAddrEvent(prev, current []ma.Multiaddr) *event.EvtLocalAddresses } func (h *BasicHost) makeSignedPeerRecord(evt *event.EvtLocalAddressesUpdated) (*record.Envelope, error) { - current := make([]multiaddr.Multiaddr, 0, len(evt.Current)) + current := make([]ma.Multiaddr, 0, len(evt.Current)) for _, a := range evt.Current { current = append(current, a.Address) } @@ -734,7 +733,7 @@ func (h *BasicHost) resolveAddrs(ctx context.Context, pi peer.AddrInfo) ([]ma.Mu // We've resolved too many addresses. We can keep all the fully // resolved addresses but we'll need to skip the rest. if resolveSteps >= maxAddressResolution { - log.Warningf( + log.Warnf( "peer %s asked us to resolve too many addresses: %s/%s", pi.ID, resolveSteps, diff --git a/p2p/host/relay/addrsplosion.go b/p2p/host/relay/addrsplosion.go index 81bb523b..2a2fc3c6 100644 --- a/p2p/host/relay/addrsplosion.go +++ b/p2p/host/relay/addrsplosion.go @@ -3,7 +3,6 @@ package relay import ( "encoding/binary" - circuit "github.com/libp2p/go-libp2p-circuit" ma "github.com/multiformats/go-multiaddr" manet "github.com/multiformats/go-multiaddr/net" ) @@ -41,7 +40,7 @@ func isRelayAddr(a ma.Multiaddr) bool { ma.ForEach(a, func(c ma.Component) bool { switch c.Protocol().Code { - case circuit.P_CIRCUIT: + case ma.P_CIRCUIT: isRelay = true return false default: diff --git a/p2p/host/relay/autorelay.go b/p2p/host/relay/autorelay.go index a8d22848..a8092add 100644 --- a/p2p/host/relay/autorelay.go +++ b/p2p/host/relay/autorelay.go @@ -7,13 +7,13 @@ import ( "sync" "time" + "github.com/libp2p/go-libp2p-core/discovery" "github.com/libp2p/go-libp2p-core/event" "github.com/libp2p/go-libp2p-core/network" "github.com/libp2p/go-libp2p-core/peer" "github.com/libp2p/go-libp2p-core/routing" circuit "github.com/libp2p/go-libp2p-circuit" - discovery "github.com/libp2p/go-libp2p-discovery" basic "github.com/libp2p/go-libp2p/p2p/host/basic" ma "github.com/multiformats/go-multiaddr" @@ -247,7 +247,15 @@ func (ar *AutoRelay) discoverRelays(ctx context.Context) ([]peer.AddrInfo, error ctx, cancel := context.WithTimeout(ctx, 30*time.Second) defer cancel() - return discovery.FindPeers(ctx, ar.discover, RelayRendezvous, discovery.Limit(1000)) + var ret []peer.AddrInfo + ch, err := ar.discover.FindPeers(ctx, RelayRendezvous, discovery.Limit(1000)) + if err != nil { + return nil, err + } + for p := range ch { + ret = append(ret, p) + } + return ret, nil } func (ar *AutoRelay) selectRelays(ctx context.Context, pis []peer.AddrInfo) []peer.AddrInfo { diff --git a/p2p/host/relay/autorelay_test.go b/p2p/host/relay/autorelay_test.go index eb690f20..17a0d462 100644 --- a/p2p/host/relay/autorelay_test.go +++ b/p2p/host/relay/autorelay_test.go @@ -163,7 +163,7 @@ func TestAutoRelay(t *testing.T) { // verify that we don't advertise relay addrs initially for _, addr := range h3.Addrs() { - _, err := addr.ValueForProtocol(circuit.P_CIRCUIT) + _, err := addr.ValueForProtocol(ma.P_CIRCUIT) if err == nil { t.Fatal("relay addr advertised before auto detection") } @@ -189,7 +189,7 @@ func TestAutoRelay(t *testing.T) { t.Fatal("unspecific relay addr advertised") } - _, err := addr.ValueForProtocol(circuit.P_CIRCUIT) + _, err := addr.ValueForProtocol(ma.P_CIRCUIT) if err == nil { haveRelay = true } @@ -202,7 +202,7 @@ func TestAutoRelay(t *testing.T) { // verify that we can connect through the relay var raddrs []ma.Multiaddr for _, addr := range h3.Addrs() { - _, err := addr.ValueForProtocol(circuit.P_CIRCUIT) + _, err := addr.ValueForProtocol(ma.P_CIRCUIT) if err == nil { raddrs = append(raddrs, addr) } @@ -220,7 +220,7 @@ func TestAutoRelay(t *testing.T) { t.Fatal("unspecific relay addr advertised") } - _, err := addr.ValueForProtocol(circuit.P_CIRCUIT) + _, err := addr.ValueForProtocol(ma.P_CIRCUIT) if err == nil { haveRelay = true } diff --git a/p2p/host/relay/relay.go b/p2p/host/relay/relay.go index f72b74ff..bb92227b 100644 --- a/p2p/host/relay/relay.go +++ b/p2p/host/relay/relay.go @@ -4,7 +4,8 @@ import ( "context" "time" - "github.com/libp2p/go-libp2p-discovery" + "github.com/libp2p/go-libp2p-core/discovery" + disc "github.com/libp2p/go-libp2p-discovery" ma "github.com/multiformats/go-multiaddr" ) @@ -20,7 +21,7 @@ func Advertise(ctx context.Context, advertise discovery.Advertiser) { go func() { select { case <-time.After(AdvertiseBootDelay): - discovery.Advertise(ctx, advertise, RelayRendezvous, discovery.TTL(AdvertiseTTL)) + disc.Advertise(ctx, advertise, RelayRendezvous, discovery.TTL(AdvertiseTTL)) case <-ctx.Done(): } }() diff --git a/p2p/host/routed/routed.go b/p2p/host/routed/routed.go index aecab095..9f6a5438 100644 --- a/p2p/host/routed/routed.go +++ b/p2p/host/routed/routed.go @@ -14,7 +14,6 @@ import ( "github.com/libp2p/go-libp2p-core/protocol" logging "github.com/ipfs/go-log" - circuit "github.com/libp2p/go-libp2p-circuit" lgbl "github.com/libp2p/go-libp2p-loggables" ma "github.com/multiformats/go-multiaddr" @@ -73,7 +72,7 @@ func (rh *RoutedHost) Connect(ctx context.Context, pi peer.AddrInfo) error { // we need to make sure the relay's addr itself is in the peerstore or else // we wont be able to dial it. for _, addr := range addrs { - _, err := addr.ValueForProtocol(circuit.P_CIRCUIT) + _, err := addr.ValueForProtocol(ma.P_CIRCUIT) if err != nil { // not a relay address continue @@ -131,7 +130,7 @@ func logRoutingErrDifferentPeers(ctx context.Context, wanted, got peer.ID, err e lm["error"] = err lm["wantedPeer"] = func() interface{} { return wanted.Pretty() } lm["gotPeer"] = func() interface{} { return got.Pretty() } - log.Event(ctx, "routingError", lm) + // log.Event(ctx, "routingError", lm) } func (rh *RoutedHost) ID() peer.ID { diff --git a/p2p/net/mock/mock_net.go b/p2p/net/mock/mock_net.go index 5f57ffec..fa276c87 100644 --- a/p2p/net/mock/mock_net.go +++ b/p2p/net/mock/mock_net.go @@ -233,11 +233,11 @@ func (mn *mocknet) validate(n network.Network) (*peernet, error) { nr, ok := n.(*peernet) if !ok { - return nil, fmt.Errorf("Network not supported (use mock package nets only)") + return nil, fmt.Errorf("network not supported (use mock package nets only)") } if _, found := mn.nets[nr.peer]; !found { - return nil, fmt.Errorf("Network not on mocknet. is it from another mocknet?") + return nil, fmt.Errorf("network not on mocknet. is it from another mocknet?") } return nr, nil diff --git a/p2p/net/mock/mock_test.go b/p2p/net/mock/mock_test.go index 4b8dc06c..b736cac2 100644 --- a/p2p/net/mock/mock_test.go +++ b/p2p/net/mock/mock_test.go @@ -15,18 +15,19 @@ import ( "github.com/libp2p/go-libp2p-core/network" "github.com/libp2p/go-libp2p-core/peer" "github.com/libp2p/go-libp2p-core/protocol" - "github.com/libp2p/go-libp2p-core/test" "github.com/libp2p/go-libp2p-testing/ci" tnet "github.com/libp2p/go-libp2p-testing/net" ) -func randPeer(t *testing.T) peer.ID { - p, err := test.RandPeerID() - if err != nil { - t.Fatal(err) - } - return p -} +// Unused code: +// +// func randPeer(t *testing.T) peer.ID { +// p, err := test.RandPeerID() +// if err != nil { +// t.Fatal(err) +// } +// return p +// } func TestNetworkSetup(t *testing.T) { ctx := context.Background() diff --git a/p2p/protocol/identify/id.go b/p2p/protocol/identify/id.go index 224688cf..2fe2703f 100644 --- a/p2p/protocol/identify/id.go +++ b/p2p/protocol/identify/id.go @@ -373,7 +373,7 @@ func (ids *IDService) identifyConn(c network.Conn, signal chan struct{}) { // ok give the response to our handler. if err = msmux.SelectProtoOrFail(ID, s); err != nil { - log.Event(context.TODO(), "IdentifyOpenFailed", c.RemotePeer(), logging.Metadata{"error": err}) + // log.Event(context.TODO(), "IdentifyOpenFailed", c.RemotePeer(), logging.Metadata{"error": err}) s.Reset() return } @@ -426,7 +426,7 @@ func (ids *IDService) handleIdentifyResponse(s network.Stream) error { mes := &pb.Identify{} if err := readAllIDMessages(r, mes); err != nil { - log.Warning("error reading identify message: ", err) + log.Warn("error reading identify message: ", err) s.Reset() return err } @@ -653,7 +653,7 @@ func (ids *IDService) consumeReceivedPubKey(c network.Conn, kb []byte) { newKey, err := ic.UnmarshalPublicKey(kb) if err != nil { - log.Warningf("%s cannot unmarshal key from remote peer: %s, %s", lp, rp, err) + log.Warnf("%s cannot unmarshal key from remote peer: %s, %s", lp, rp, err) return } diff --git a/p2p/protocol/identify/id_delta.go b/p2p/protocol/identify/id_delta.go index 48bae8bf..a7492bee 100644 --- a/p2p/protocol/identify/id_delta.go +++ b/p2p/protocol/identify/id_delta.go @@ -23,7 +23,7 @@ func (ids *IDService) deltaHandler(s network.Stream) { r := protoio.NewDelimitedReader(s, 2048) mes := pb.Identify{} if err := r.ReadMsg(&mes); err != nil { - log.Warning("error reading identify message: ", err) + log.Warn("error reading identify message: ", err) _ = s.Reset() return } @@ -40,7 +40,7 @@ func (ids *IDService) deltaHandler(s network.Stream) { p := s.Conn().RemotePeer() if err := ids.consumeDelta(p, delta); err != nil { _ = s.Reset() - log.Warningf("delta update from peer %s failed: %s", p, err) + log.Warnf("delta update from peer %s failed: %s", p, err) } } diff --git a/p2p/protocol/identify/id_test.go b/p2p/protocol/identify/id_test.go index c6d7ef76..a2a6ca5e 100644 --- a/p2p/protocol/identify/id_test.go +++ b/p2p/protocol/identify/id_test.go @@ -1013,7 +1013,6 @@ func TestLargePushMessage(t *testing.T) { } func TestIdentifyResponseReadTimeout(t *testing.T) { - ctx := context.Background() timeout := identify.StreamReadTimeout identify.StreamReadTimeout = 100 * time.Millisecond defer func() { @@ -1058,7 +1057,6 @@ func TestIdentifyResponseReadTimeout(t *testing.T) { } func TestIncomingIDStreamsTimeout(t *testing.T) { - ctx := context.Background() timeout := identify.StreamReadTimeout identify.StreamReadTimeout = 100 * time.Millisecond defer func() { diff --git a/p2p/protocol/identify/obsaddr.go b/p2p/protocol/identify/obsaddr.go index 279800ab..ef6b118d 100644 --- a/p2p/protocol/identify/obsaddr.go +++ b/p2p/protocol/identify/obsaddr.go @@ -161,8 +161,7 @@ func (oas *ObservedAddrManager) AddrsFor(addr ma.Multiaddr) (addrs []ma.Multiadd return nil } - key := string(addr.Bytes()) - observedAddrs, ok := oas.addrs[key] + observedAddrs, ok := oas.addrs[string(addr.Bytes())] if !ok { return } diff --git a/p2p/protocol/identify/peer_loop.go b/p2p/protocol/identify/peer_loop.go index 84d51dbf..4c3b6758 100644 --- a/p2p/protocol/identify/peer_loop.go +++ b/p2p/protocol/identify/peer_loop.go @@ -27,10 +27,8 @@ type identifySnapshot struct { } type peerHandler struct { - ids *IDService - started bool + ids *IDService - ctx context.Context cancel context.CancelFunc pid peer.ID diff --git a/p2p/protocol/ping/ping.go b/p2p/protocol/ping/ping.go index 9d9b571e..ae048468 100644 --- a/p2p/protocol/ping/ping.go +++ b/p2p/protocol/ping/ping.go @@ -146,7 +146,7 @@ func ping(s network.Stream) (time.Duration, error) { } if !bytes.Equal(buf, rbuf) { - return 0, errors.New("ping packet was incorrect!") + return 0, errors.New("ping packet was incorrect") } return time.Since(before), nil From 12753d379565bb383a36a9c0e3eccf89fcb136c7 Mon Sep 17 00:00:00 2001 From: Cory Schwartz Date: Wed, 14 Apr 2021 18:31:49 -0700 Subject: [PATCH 2/4] advertise util --- p2p/host/relay/relay.go | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/p2p/host/relay/relay.go b/p2p/host/relay/relay.go index bb92227b..72978a22 100644 --- a/p2p/host/relay/relay.go +++ b/p2p/host/relay/relay.go @@ -5,7 +5,6 @@ import ( "time" "github.com/libp2p/go-libp2p-core/discovery" - disc "github.com/libp2p/go-libp2p-discovery" ma "github.com/multiformats/go-multiaddr" ) @@ -21,7 +20,31 @@ func Advertise(ctx context.Context, advertise discovery.Advertiser) { go func() { select { case <-time.After(AdvertiseBootDelay): - disc.Advertise(ctx, advertise, RelayRendezvous, discovery.TTL(AdvertiseTTL)) + go func() { + for { + ttl, err := advertise.Advertise(ctx, RelayRendezvous, discovery.TTL(AdvertiseTTL)) + if err != nil { + log.Debugf("Error advertising %s: %s", RelayRendezvous, err.Error()) + if ctx.Err() != nil { + return + } + + select { + case <-time.After(2 * time.Minute): + continue + case <-ctx.Done(): + return + } + } + + wait := 7 * ttl / 8 + select { + case <-time.After(wait): + case <-ctx.Done(): + return + } + } + }() case <-ctx.Done(): } }() From 2a72777ef911a108dce8b3bb73d033356f95e05d Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Thu, 29 Apr 2021 14:07:16 -0700 Subject: [PATCH 3/4] fix: address review feedback --- go.mod | 1 - go.sum | 1 - p2p/host/routed/routed.go | 15 +++++---------- p2p/net/mock/mock_test.go | 10 ---------- p2p/protocol/identify/id.go | 5 ++++- 5 files changed, 9 insertions(+), 23 deletions(-) diff --git a/go.mod b/go.mod index f6bf33ea..ebb21a17 100644 --- a/go.mod +++ b/go.mod @@ -21,7 +21,6 @@ require ( github.com/libp2p/go-libp2p-circuit v0.4.0 github.com/libp2p/go-libp2p-core v0.8.5 github.com/libp2p/go-libp2p-discovery v0.5.0 - github.com/libp2p/go-libp2p-loggables v0.1.0 github.com/libp2p/go-libp2p-mplex v0.4.1 github.com/libp2p/go-libp2p-nat v0.0.6 github.com/libp2p/go-libp2p-netutil v0.1.0 diff --git a/go.sum b/go.sum index 4aa7591e..73e2046d 100644 --- a/go.sum +++ b/go.sum @@ -287,7 +287,6 @@ github.com/libp2p/go-libp2p-discovery v0.2.0/go.mod h1:s4VGaxYMbw4+4+tsoQTqh7wfx github.com/libp2p/go-libp2p-discovery v0.3.0/go.mod h1:o03drFnz9BVAZdzC/QUQ+NeQOu38Fu7LJGEOK2gQltw= github.com/libp2p/go-libp2p-discovery v0.5.0 h1:Qfl+e5+lfDgwdrXdu4YNCWyEo3fWuP+WgN9mN0iWviQ= github.com/libp2p/go-libp2p-discovery v0.5.0/go.mod h1:+srtPIU9gDaBNu//UHvcdliKBIcr4SfDcm0/PfPJLug= -github.com/libp2p/go-libp2p-loggables v0.1.0 h1:h3w8QFfCt2UJl/0/NW4K829HX/0S4KD31PQ7m8UXXO8= github.com/libp2p/go-libp2p-loggables v0.1.0/go.mod h1:EyumB2Y6PrYjr55Q3/tiJ/o3xoDasoRYM7nOzEpoa90= github.com/libp2p/go-libp2p-mplex v0.2.0/go.mod h1:Ejl9IyjvXJ0T9iqUTE1jpYATQ9NM3g+OtR+EMMODbKo= github.com/libp2p/go-libp2p-mplex v0.2.1/go.mod h1:SC99Rxs8Vuzrf/6WhmH41kNn13TiYdAWNYHrwImKLnE= diff --git a/p2p/host/routed/routed.go b/p2p/host/routed/routed.go index 9f6a5438..0c8c3e48 100644 --- a/p2p/host/routed/routed.go +++ b/p2p/host/routed/routed.go @@ -14,7 +14,6 @@ import ( "github.com/libp2p/go-libp2p-core/protocol" logging "github.com/ipfs/go-log" - lgbl "github.com/libp2p/go-libp2p-loggables" ma "github.com/multiformats/go-multiaddr" ) @@ -118,21 +117,17 @@ func (rh *RoutedHost) findPeerAddrs(ctx context.Context, id peer.ID) ([]ma.Multi if pi.ID != id { err = fmt.Errorf("routing failure: provided addrs for different peer") - logRoutingErrDifferentPeers(ctx, id, pi.ID, err) + log.Errorw("got wrong peer", + "error", err, + "wantedPeer", id, + "gotPeer", pi.ID, + ) return nil, err } return pi.Addrs, nil } -func logRoutingErrDifferentPeers(ctx context.Context, wanted, got peer.ID, err error) { - lm := make(lgbl.DeferredMap) - lm["error"] = err - lm["wantedPeer"] = func() interface{} { return wanted.Pretty() } - lm["gotPeer"] = func() interface{} { return got.Pretty() } - // log.Event(ctx, "routingError", lm) -} - func (rh *RoutedHost) ID() peer.ID { return rh.host.ID() } diff --git a/p2p/net/mock/mock_test.go b/p2p/net/mock/mock_test.go index b736cac2..3ed721ea 100644 --- a/p2p/net/mock/mock_test.go +++ b/p2p/net/mock/mock_test.go @@ -19,16 +19,6 @@ import ( tnet "github.com/libp2p/go-libp2p-testing/net" ) -// Unused code: -// -// func randPeer(t *testing.T) peer.ID { -// p, err := test.RandPeerID() -// if err != nil { -// t.Fatal(err) -// } -// return p -// } - func TestNetworkSetup(t *testing.T) { ctx := context.Background() id1 := tnet.RandIdentityOrFatal(t) diff --git a/p2p/protocol/identify/id.go b/p2p/protocol/identify/id.go index 2fe2703f..d09d6501 100644 --- a/p2p/protocol/identify/id.go +++ b/p2p/protocol/identify/id.go @@ -373,7 +373,10 @@ func (ids *IDService) identifyConn(c network.Conn, signal chan struct{}) { // ok give the response to our handler. if err = msmux.SelectProtoOrFail(ID, s); err != nil { - // log.Event(context.TODO(), "IdentifyOpenFailed", c.RemotePeer(), logging.Metadata{"error": err}) + log.Infow("failed negotiate identify protocol with peer", + "peer", c.RemotePeer(), + "error", err, + ) s.Reset() return } From 2ad02f79b2af35cd6107db39292bd1ab5af798ec Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Thu, 29 Apr 2021 14:15:17 -0700 Subject: [PATCH 4/4] chore: update to go-log v2 --- config/config.go | 2 +- go.mod | 2 +- go.sum | 3 +-- p2p/discovery/mdns.go | 2 +- p2p/host/basic/basic_host.go | 2 +- p2p/host/relay/log.go | 2 +- p2p/host/routed/routed.go | 2 +- p2p/net/conngater/conngater.go | 2 +- p2p/net/mock/mock.go | 2 +- p2p/protocol/identify/id.go | 2 +- p2p/protocol/ping/ping.go | 2 +- p2p/test/backpressure/backpressure_test.go | 2 +- p2p/test/reconnects/reconnect_test.go | 2 +- 13 files changed, 13 insertions(+), 14 deletions(-) diff --git a/config/config.go b/config/config.go index f3310dc6..bce0f300 100644 --- a/config/config.go +++ b/config/config.go @@ -29,7 +29,7 @@ import ( swarm "github.com/libp2p/go-libp2p-swarm" tptu "github.com/libp2p/go-libp2p-transport-upgrader" - logging "github.com/ipfs/go-log" + logging "github.com/ipfs/go-log/v2" ma "github.com/multiformats/go-multiaddr" madns "github.com/multiformats/go-multiaddr-dns" ) diff --git a/go.mod b/go.mod index ebb21a17..a350f359 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/ipfs/go-datastore v0.4.5 github.com/ipfs/go-detect-race v0.0.1 github.com/ipfs/go-ipfs-util v0.0.2 - github.com/ipfs/go-log v1.0.5 + github.com/ipfs/go-log/v2 v2.1.3 github.com/jbenet/go-cienv v0.1.0 github.com/jbenet/goprocess v0.1.4 github.com/libp2p/go-addr-util v0.0.2 diff --git a/go.sum b/go.sum index 73e2046d..3b9cf3e6 100644 --- a/go.sum +++ b/go.sum @@ -182,9 +182,8 @@ github.com/ipfs/go-ipfs-util v0.0.2/go.mod h1:CbPtkWJzjLdEcezDns2XYaehFVNXG9zrdr github.com/ipfs/go-log v0.0.1/go.mod h1:kL1d2/hzSpI0thNYjiKfjanbVNU+IIGA/WnNESY9leM= github.com/ipfs/go-log v1.0.2/go.mod h1:1MNjMxe0u6xvJZgeqbJ8vdo2TKaGwZ1a0Bpza+sr2Sk= github.com/ipfs/go-log v1.0.3/go.mod h1:OsLySYkwIbiSUR/yBTdv1qPtcE4FW3WPWk/ewz9Ru+A= +github.com/ipfs/go-log v1.0.4 h1:6nLQdX4W8P9yZZFH7mO+X/PzjN8Laozm/lMJ6esdgzY= github.com/ipfs/go-log v1.0.4/go.mod h1:oDCg2FkjogeFOhqqb+N39l2RpTNPL6F/StPkB3kPgcs= -github.com/ipfs/go-log v1.0.5 h1:2dOuUCB1Z7uoczMWgAyDck5JLb72zHzrMnGnCNNbvY8= -github.com/ipfs/go-log v1.0.5/go.mod h1:j0b8ZoR+7+R99LD9jZ6+AJsrzkPbSXbZfGakb5JPtIo= github.com/ipfs/go-log/v2 v2.0.2/go.mod h1:O7P1lJt27vWHhOwQmcFEvlmo49ry2VY2+JfBWFaa9+0= github.com/ipfs/go-log/v2 v2.0.3/go.mod h1:O7P1lJt27vWHhOwQmcFEvlmo49ry2VY2+JfBWFaa9+0= github.com/ipfs/go-log/v2 v2.0.5/go.mod h1:eZs4Xt4ZUJQFM3DlanGhy7TkwwawCZcSByscwkWG+dw= diff --git a/p2p/discovery/mdns.go b/p2p/discovery/mdns.go index d0267e41..d78ace24 100644 --- a/p2p/discovery/mdns.go +++ b/p2p/discovery/mdns.go @@ -11,7 +11,7 @@ import ( "github.com/libp2p/go-libp2p-core/host" "github.com/libp2p/go-libp2p-core/peer" - logging "github.com/ipfs/go-log" + logging "github.com/ipfs/go-log/v2" ma "github.com/multiformats/go-multiaddr" manet "github.com/multiformats/go-multiaddr/net" "github.com/whyrusleeping/mdns" diff --git a/p2p/host/basic/basic_host.go b/p2p/host/basic/basic_host.go index 6a7f02e6..aac8e46b 100644 --- a/p2p/host/basic/basic_host.go +++ b/p2p/host/basic/basic_host.go @@ -27,7 +27,7 @@ import ( "github.com/libp2p/go-libp2p/p2p/protocol/ping" "github.com/libp2p/go-netroute" - logging "github.com/ipfs/go-log" + logging "github.com/ipfs/go-log/v2" ma "github.com/multiformats/go-multiaddr" madns "github.com/multiformats/go-multiaddr-dns" diff --git a/p2p/host/relay/log.go b/p2p/host/relay/log.go index eca0fa45..975949a4 100644 --- a/p2p/host/relay/log.go +++ b/p2p/host/relay/log.go @@ -1,7 +1,7 @@ package relay import ( - logging "github.com/ipfs/go-log" + logging "github.com/ipfs/go-log/v2" ) var log = logging.Logger("autorelay") diff --git a/p2p/host/routed/routed.go b/p2p/host/routed/routed.go index 0c8c3e48..ba9450e1 100644 --- a/p2p/host/routed/routed.go +++ b/p2p/host/routed/routed.go @@ -13,7 +13,7 @@ import ( "github.com/libp2p/go-libp2p-core/peerstore" "github.com/libp2p/go-libp2p-core/protocol" - logging "github.com/ipfs/go-log" + logging "github.com/ipfs/go-log/v2" ma "github.com/multiformats/go-multiaddr" ) diff --git a/p2p/net/conngater/conngater.go b/p2p/net/conngater/conngater.go index 51993f4f..4fa8dde8 100644 --- a/p2p/net/conngater/conngater.go +++ b/p2p/net/conngater/conngater.go @@ -15,7 +15,7 @@ import ( "github.com/ipfs/go-datastore" "github.com/ipfs/go-datastore/namespace" "github.com/ipfs/go-datastore/query" - logging "github.com/ipfs/go-log" + logging "github.com/ipfs/go-log/v2" ) // BasicConnectionGater implements a connection gater that allows the application to perform diff --git a/p2p/net/mock/mock.go b/p2p/net/mock/mock.go index 55256f86..3dc84032 100644 --- a/p2p/net/mock/mock.go +++ b/p2p/net/mock/mock.go @@ -3,7 +3,7 @@ package mocknet import ( "context" - logging "github.com/ipfs/go-log" + logging "github.com/ipfs/go-log/v2" ) var log = logging.Logger("mocknet") diff --git a/p2p/protocol/identify/id.go b/p2p/protocol/identify/id.go index d09d6501..e2995c23 100644 --- a/p2p/protocol/identify/id.go +++ b/p2p/protocol/identify/id.go @@ -26,7 +26,7 @@ import ( msmux "github.com/multiformats/go-multistream" "github.com/gogo/protobuf/proto" - logging "github.com/ipfs/go-log" + logging "github.com/ipfs/go-log/v2" ) var log = logging.Logger("net/identify") diff --git a/p2p/protocol/ping/ping.go b/p2p/protocol/ping/ping.go index ae048468..b1f3da4e 100644 --- a/p2p/protocol/ping/ping.go +++ b/p2p/protocol/ping/ping.go @@ -8,7 +8,7 @@ import ( "time" u "github.com/ipfs/go-ipfs-util" - logging "github.com/ipfs/go-log" + logging "github.com/ipfs/go-log/v2" "github.com/libp2p/go-libp2p-core/host" "github.com/libp2p/go-libp2p-core/network" "github.com/libp2p/go-libp2p-core/peer" diff --git a/p2p/test/backpressure/backpressure_test.go b/p2p/test/backpressure/backpressure_test.go index 72525b53..99a7d2e2 100644 --- a/p2p/test/backpressure/backpressure_test.go +++ b/p2p/test/backpressure/backpressure_test.go @@ -10,7 +10,7 @@ import ( bhost "github.com/libp2p/go-libp2p/p2p/host/basic" u "github.com/ipfs/go-ipfs-util" - logging "github.com/ipfs/go-log" + logging "github.com/ipfs/go-log/v2" "github.com/libp2p/go-libp2p-core/host" "github.com/libp2p/go-libp2p-core/network" "github.com/libp2p/go-libp2p-core/peer" diff --git a/p2p/test/reconnects/reconnect_test.go b/p2p/test/reconnects/reconnect_test.go index e1d969ff..9ec16ba4 100644 --- a/p2p/test/reconnects/reconnect_test.go +++ b/p2p/test/reconnects/reconnect_test.go @@ -11,7 +11,7 @@ import ( bhost "github.com/libp2p/go-libp2p/p2p/host/basic" u "github.com/ipfs/go-ipfs-util" - logging "github.com/ipfs/go-log" + logging "github.com/ipfs/go-log/v2" "github.com/libp2p/go-libp2p-core/host" "github.com/libp2p/go-libp2p-core/network" protocol "github.com/libp2p/go-libp2p-core/protocol"