forked from cerc-io/plugeth
Add DNS Bootstrapping
This commit is contained in:
parent
be543a6d17
commit
8162aff8cf
29
ethereum.go
29
ethereum.go
@ -263,8 +263,32 @@ func (s *Ethereum) Start() {
|
||||
|
||||
if ethutil.Config.Seed {
|
||||
ethutil.Config.Log.Debugln("Seeding")
|
||||
// Testnet seed bootstrapping
|
||||
resp, err := http.Get("https://www.ethereum.org/servers.poc3.txt")
|
||||
// DNS Bootstrapping
|
||||
_, nodes, err := net.LookupSRV("eth", "tcp", "ethereum.org")
|
||||
if(err == nil) {
|
||||
peers := []string{}
|
||||
// Iterate SRV nodes
|
||||
for _, n := range nodes {
|
||||
target := n.Target
|
||||
port := n.Port
|
||||
// Resolve target to ip (Go returns list, so may resolve to multiple ips?)
|
||||
addr, err := net.LookupHost(target)
|
||||
if(err == nil) {
|
||||
for _, a := range addr {
|
||||
// Build string out of SRV port and Resolved IP
|
||||
peer := net.JoinHostPort(a, strconv.Itoa(int(port)))
|
||||
log.Println("Found DNS Bootstrap Peer:", peer)
|
||||
peers = append(peers, peer)
|
||||
}
|
||||
} else {
|
||||
log.Println("Couldn't resolve :", target)
|
||||
}
|
||||
}
|
||||
// Connect to Peer list
|
||||
s.ProcessPeerList(peers)
|
||||
} else {
|
||||
// Fallback to servers.poc3.txt
|
||||
resp, err := http.Get("http://www.ethereum.org/servers.poc3.txt")
|
||||
if err != nil {
|
||||
log.Println("Fetching seed failed:", err)
|
||||
return
|
||||
@ -278,6 +302,7 @@ func (s *Ethereum) Start() {
|
||||
|
||||
s.ConnectToPeer(string(body))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Ethereum) peerHandler(listener net.Listener) {
|
||||
|
Loading…
Reference in New Issue
Block a user