Skip to content

Commit d58532b

Browse files
authored
Resolve bootstrap addresses before connecting in manifest server (#639)
Resolve the bootstrap addresses, which may be dnsaddrs, before connecting to them in manifest server.
1 parent e057af8 commit d58532b

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

cmd/f3/manifest.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import (
1313
pubsub "github.com/libp2p/go-libp2p-pubsub"
1414
"github.com/libp2p/go-libp2p/core/crypto"
1515
"github.com/libp2p/go-libp2p/core/peer"
16+
"github.com/multiformats/go-multiaddr"
17+
madns "github.com/multiformats/go-multiaddr-dns"
1618
"github.com/urfave/cli/v2"
1719
"golang.org/x/sync/errgroup"
1820
)
@@ -187,11 +189,18 @@ var manifestServeCmd = cli.Command{
187189
}
188190
}
189191
for _, bootstrapper := range bootstrappers {
190-
addr, err := peer.AddrInfoFromString(bootstrapper)
191-
if err != nil {
192+
if maddr, err := multiaddr.NewMultiaddr(bootstrapper); err != nil {
192193
_, _ = fmt.Fprintf(c.App.ErrWriter, "Failed to parse to bootstrap address: %s %v\n", bootstrapper, err)
193-
} else if err := host.Connect(c.Context, *addr); err != nil {
194-
_, _ = fmt.Fprintf(c.App.ErrWriter, "Failed to connect to bootstrap address: %v\n", err)
194+
} else if multiaddrs, err := madns.Resolve(c.Context, maddr); err != nil {
195+
_, _ = fmt.Fprintf(c.App.ErrWriter, "Failed to resolve bootstrap address: %s %v\n", bootstrapper, err)
196+
} else if paddrinfos, err := peer.AddrInfosFromP2pAddrs(multiaddrs...); err != nil {
197+
_, _ = fmt.Fprintf(c.App.ErrWriter, "Failed to build peer.AddrInfo for bootstrap address: %s %v\n", bootstrapper, err)
198+
} else {
199+
for _, paddrinfo := range paddrinfos {
200+
if err := host.Connect(c.Context, paddrinfo); err != nil {
201+
_, _ = fmt.Fprintf(c.App.ErrWriter, "Failed to connect to bootstrap address: %v\n", err)
202+
}
203+
}
195204
}
196205
}
197206
}

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ require (
1515
github.com/ipfs/go-log/v2 v2.5.1
1616
github.com/libp2p/go-libp2p v0.35.0
1717
github.com/libp2p/go-libp2p-pubsub v0.11.0
18+
github.com/multiformats/go-multiaddr v0.12.4
19+
github.com/multiformats/go-multiaddr-dns v0.3.1
1820
github.com/multiformats/go-multibase v0.2.0
1921
github.com/multiformats/go-multihash v0.2.3
2022
github.com/parquet-go/parquet-go v0.23.0
@@ -85,8 +87,6 @@ require (
8587
github.com/mr-tron/base58 v1.2.0 // indirect
8688
github.com/multiformats/go-base32 v0.1.0 // indirect
8789
github.com/multiformats/go-base36 v0.2.0 // indirect
88-
github.com/multiformats/go-multiaddr v0.12.4 // indirect
89-
github.com/multiformats/go-multiaddr-dns v0.3.1 // indirect
9090
github.com/multiformats/go-multiaddr-fmt v0.1.0 // indirect
9191
github.com/multiformats/go-multicodec v0.9.0 // indirect
9292
github.com/multiformats/go-multistream v0.5.0 // indirect

0 commit comments

Comments
 (0)