Skip to content

Commit

Permalink
p2p/server: add DNS resolved candidates to distributed hash table
Browse files Browse the repository at this point in the history
Currently, DNS resolved candidates of a protocol are added as candidates for
dialing but not added to DHT. The DHT's seed nodes are still configured via
hardcoded nodes in bootnodes flag. As we want to replace the hardcoded bootnodes
entirely with DNS resolved nodes, we resolve some nodes from the DNS discovery
URL and put them into DHT when setting up the p2p discovery.
  • Loading branch information
minh-bq committed Oct 19, 2023
1 parent 800ec03 commit 65c2bde
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions p2p/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ const (

// Maximum amount of time allowed for writing a complete message.
frameWriteTimeout = 20 * time.Second

// The number of DHT seed nodes got from DNS resolve
numSeedNodesFromDns = 5
)

var errServerStopped = errors.New("server stopped")
Expand Down Expand Up @@ -539,6 +542,16 @@ func (srv *Server) setupDiscovery() error {
added := make(map[string]bool)
for _, proto := range srv.Protocols {
if proto.DialCandidates != nil && !added[proto.Name] {
for i := 0; i < numSeedNodesFromDns; i++ {
if !proto.DialCandidates.Next() {
break
}

node := proto.DialCandidates.Node()
srv.BootstrapNodes = append(srv.BootstrapNodes, node)
srv.BootstrapNodesV5 = append(srv.BootstrapNodes, node)
}

srv.discmix.AddSource(proto.DialCandidates)
added[proto.Name] = true
}
Expand Down

0 comments on commit 65c2bde

Please sign in to comment.