Skip to content

Commit

Permalink
fix: address review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Stebalien committed Apr 29, 2021
1 parent 04a93f4 commit 80ee4cd
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 29 deletions.
10 changes: 1 addition & 9 deletions p2p/host/relay/autorelay.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,15 +247,7 @@ func (ar *AutoRelay) discoverRelays(ctx context.Context) ([]peer.AddrInfo, error

ctx, cancel := context.WithTimeout(ctx, 30*time.Second)
defer cancel()
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
return discovery.FindPeers(ctx, ar.discover, RelayRendezvous, discovery.Limit(1000))
}

func (ar *AutoRelay) selectRelays(ctx context.Context, pis []peer.AddrInfo) []peer.AddrInfo {
Expand Down
14 changes: 5 additions & 9 deletions p2p/host/routed/routed.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,21 +118,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()
}
Expand Down
10 changes: 0 additions & 10 deletions p2p/net/mock/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion p2p/protocol/identify/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 80ee4cd

Please sign in to comment.