Skip to content

Commit

Permalink
Merge pull request #62 from ipfs/add-find-peer
Browse files Browse the repository at this point in the history
feat: find peer when there are no maddrs
  • Loading branch information
2color authored Sep 3, 2024
2 parents 5ff1101 + 6768d46 commit c65b429
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ func newDaemon(ctx context.Context, acceleratedDHT bool) (*daemon, error) {
dhtMessenger: pm,
promRegistry: promRegistry,
createTestHost: func() (host.Host, error) {
// TODO: when behind NAT, this will fail to determine its own public addresses which will block it from running dctur and hole punching
// See https://github.com/libp2p/go-libp2p/issues/2941
return libp2p.New(
libp2p.ConnectionGater(&privateAddrFilterConnectionGater{}),
libp2p.DefaultMuxers,
Expand Down Expand Up @@ -156,18 +158,30 @@ func (d *daemon) runCidCheck(ctx context.Context, cidStr string) (cidCheckOutput
go func(provider peer.AddrInfo) {
defer wg.Done()

addrs := []string{}
outputAddrs := []string{}
if len(provider.Addrs) > 0 {
for _, addr := range provider.Addrs {
if manet.IsPublicAddr(addr) { // only return public addrs
addrs = append(addrs, addr.String())
outputAddrs = append(outputAddrs, addr.String())
}
}
} else {
// If no maddrs were returned from the FindProvider rpc call, try to get them from the DHT
peerAddrs, err := d.dht.FindPeer(ctx, provider.ID)
if err == nil {
for _, addr := range peerAddrs.Addrs {
if manet.IsPublicAddr(addr) { // only return public addrs
// Add to both output and to provider addrs for the check
outputAddrs = append(outputAddrs, addr.String())
provider.Addrs = append(provider.Addrs, addr)
}
}
}
}

provOutput := providerOutput{
ID: provider.ID.String(),
Addrs: addrs,
Addrs: outputAddrs,
DataAvailableOverBitswap: BitswapCheckOutput{},
}

Expand Down

0 comments on commit c65b429

Please sign in to comment.