Skip to content
This repository has been archived by the owner on Mar 28, 2023. It is now read-only.

Commit

Permalink
Merge pull request #52 from ischasny/main
Browse files Browse the repository at this point in the history
  • Loading branch information
ajnavarro authored Sep 21, 2022
2 parents 835c65a + f44a4d6 commit accc52e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
13 changes: 5 additions & 8 deletions client/findproviders.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,14 @@ func parseProtoNodeToAddrInfo(n proto.Node) []peer.AddrInfo {
if n.Peer == nil { // ignore non-peer nodes
return nil
}
infos = append(infos, ParseNodeAddresses(n.Peer)...)
infos = append(infos, ParseNodeAddresses(n.Peer))
return infos
}

// ParseNodeAddresses parses peer node addresses from the protocol structure Peer.
func ParseNodeAddresses(n *proto.Peer) []peer.AddrInfo {
func ParseNodeAddresses(n *proto.Peer) peer.AddrInfo {
peerID := peer.ID(n.ID)
infos := []peer.AddrInfo{}
info := peer.AddrInfo{ID: peerID}
for _, addrBytes := range n.Multiaddresses {
ma, err := multiaddr.NewMultiaddrBytes(addrBytes)
if err != nil {
Expand All @@ -162,12 +162,9 @@ func ParseNodeAddresses(n *proto.Peer) []peer.AddrInfo {
logger.Infof("dropping provider multiaddress %v ending in /p2p/peerid", ma)
continue
}
infos = append(infos, peer.AddrInfo{ID: peerID, Addrs: []multiaddr.Multiaddr{ma}})
}
if len(n.Multiaddresses) == 0 {
infos = append(infos, peer.AddrInfo{ID: peerID})
info.Addrs = append(info.Addrs, ma)
}
return infos
return info
}

// ToProtoPeer creates a protocol Peer structure from address info.
Expand Down
9 changes: 7 additions & 2 deletions test/provide_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,20 @@ func TestProvideRoundtrip(t *testing.T) {
t.Fatal("should get sync error on unsigned provide request.")
}

ma, err := multiaddr.NewMultiaddr("/ip4/0.0.0.0/tcp/4001")
ma1, err := multiaddr.NewMultiaddr("/ip4/0.0.0.0/tcp/4001")
if err != nil {
t.Fatal(err)
}

ma2, err := multiaddr.NewMultiaddr("/ip4/0.0.0.0/tcp/4002")
if err != nil {
t.Fatal(err)
}

c, s := createClientAndServer(t, testDelegatedRoutingService{}, &client.Provider{
Peer: peer.AddrInfo{
ID: pID,
Addrs: []multiaddr.Multiaddr{ma},
Addrs: []multiaddr.Multiaddr{ma1, ma2},
},
ProviderProto: []client.TransferProtocol{{Codec: multicodec.TransportBitswap}},
}, priv)
Expand Down

0 comments on commit accc52e

Please sign in to comment.