Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

p2p/server: add DNS resolved candidates to distributed hash table #370

Merged
merged 1 commit into from
Apr 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions p2p/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ 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

// Name of eth protocol
ethProtocolName = "eth"
)

var errServerStopped = errors.New("server stopped")
Expand Down Expand Up @@ -539,6 +545,22 @@ func (srv *Server) setupDiscovery() error {
added := make(map[string]bool)
for _, proto := range srv.Protocols {
if proto.DialCandidates != nil && !added[proto.Name] {
// If the protocol is eth, the dial candidates are retrieved from
// DNS URL. We want to use the DNS discovery for bootstrap nodes
// too, so resolve some nodes from DNS and add to DHT.
if proto.Name == ethProtocolName {
for i := 0; i < numSeedNodesFromDns; i++ {
if !proto.DialCandidates.Next() {
break
}

node := proto.DialCandidates.Node()
log.Info("Add resolved DNS node to discovery bootstrap nodes", "node", node.String())
srv.BootstrapNodes = append(srv.BootstrapNodes, node)
srv.BootstrapNodesV5 = append(srv.BootstrapNodesV5, node)
}
}

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