From 6444b599dfafc7d3e7bca681d40f83c59c1b1649 Mon Sep 17 00:00:00 2001 From: Leo Chen Date: Sat, 5 Dec 2020 05:49:45 +0000 Subject: [PATCH] [bootnode] support dnsaddr in bootnode Signed-off-by: Leo Chen --- api/service/networkinfo/service.go | 17 ++++++++++++++++- go.mod | 1 + 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/api/service/networkinfo/service.go b/api/service/networkinfo/service.go index 2e7c7c183..5d8297e81 100644 --- a/api/service/networkinfo/service.go +++ b/api/service/networkinfo/service.go @@ -18,6 +18,7 @@ import ( libp2pdis "github.com/libp2p/go-libp2p-discovery" libp2pdht "github.com/libp2p/go-libp2p-kad-dht" libp2pdhtopts "github.com/libp2p/go-libp2p-kad-dht/opts" + madns "github.com/multiformats/go-multiaddr-dns" manet "github.com/multiformats/go-multiaddr-net" "github.com/pkg/errors" ) @@ -139,7 +140,21 @@ func (s *Service) Init() error { } connected := false - for _, peerAddr := range s.bootnodes { + var bnList p2p.AddrList + for _, maddr := range s.bootnodes { + if madns.Matches(maddr) { + mas, err := madns.Resolve(context.Background(), maddr) + if err != nil { + utils.Logger().Error().Err(err).Msg("Resolve bootnode") + continue + } + bnList = append(bnList, mas...) + } else { + bnList = append(bnList, maddr) + } + } + + for _, peerAddr := range bnList { peerinfo, _ := libp2p_peer.AddrInfoFromP2pAddr(peerAddr) wg.Add(1) go func() { diff --git a/go.mod b/go.mod index e970e2432..9088b5bfa 100644 --- a/go.mod +++ b/go.mod @@ -38,6 +38,7 @@ require ( github.com/libp2p/go-libp2p-kad-dht v0.8.3 github.com/libp2p/go-libp2p-pubsub v0.3.3 github.com/multiformats/go-multiaddr v0.2.2 + github.com/multiformats/go-multiaddr-dns v0.2.0 github.com/multiformats/go-multiaddr-net v0.1.5 github.com/natefinch/lumberjack v2.0.0+incompatible github.com/pborman/uuid v1.2.0