|
|
@ -253,7 +253,7 @@ func (s *Ethereum) ReapDeadPeerHandler() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Start the ethereum
|
|
|
|
// Start the ethereum
|
|
|
|
func (s *Ethereum) Start() { |
|
|
|
func (s *Ethereum) Start(seed bool) { |
|
|
|
// Bind to addr and port
|
|
|
|
// Bind to addr and port
|
|
|
|
ln, err := net.Listen("tcp", ":"+s.Port) |
|
|
|
ln, err := net.Listen("tcp", ":"+s.Port) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
@ -272,47 +272,51 @@ func (s *Ethereum) Start() { |
|
|
|
// Start the reaping processes
|
|
|
|
// Start the reaping processes
|
|
|
|
go s.ReapDeadPeerHandler() |
|
|
|
go s.ReapDeadPeerHandler() |
|
|
|
|
|
|
|
|
|
|
|
if ethutil.Config.Seed { |
|
|
|
if seed { |
|
|
|
ethutil.Config.Log.Debugln("Seeding") |
|
|
|
s.Seed() |
|
|
|
// DNS Bootstrapping
|
|
|
|
} |
|
|
|
_, nodes, err := net.LookupSRV("eth", "tcp", "ethereum.org") |
|
|
|
} |
|
|
|
if err == nil { |
|
|
|
|
|
|
|
peers := []string{} |
|
|
|
func (s *Ethereum) Seed() { |
|
|
|
// Iterate SRV nodes
|
|
|
|
ethutil.Config.Log.Debugln("Seeding") |
|
|
|
for _, n := range nodes { |
|
|
|
// DNS Bootstrapping
|
|
|
|
target := n.Target |
|
|
|
_, nodes, err := net.LookupSRV("eth", "tcp", "ethereum.org") |
|
|
|
port := strconv.Itoa(int(n.Port)) |
|
|
|
if err == nil { |
|
|
|
// Resolve target to ip (Go returns list, so may resolve to multiple ips?)
|
|
|
|
peers := []string{} |
|
|
|
addr, err := net.LookupHost(target) |
|
|
|
// Iterate SRV nodes
|
|
|
|
if err == nil { |
|
|
|
for _, n := range nodes { |
|
|
|
for _, a := range addr { |
|
|
|
target := n.Target |
|
|
|
// Build string out of SRV port and Resolved IP
|
|
|
|
port := strconv.Itoa(int(n.Port)) |
|
|
|
peer := net.JoinHostPort(a, port) |
|
|
|
// Resolve target to ip (Go returns list, so may resolve to multiple ips?)
|
|
|
|
log.Println("Found DNS Bootstrap Peer:", peer) |
|
|
|
addr, err := net.LookupHost(target) |
|
|
|
peers = append(peers, peer) |
|
|
|
if err == nil { |
|
|
|
} |
|
|
|
for _, a := range addr { |
|
|
|
} else { |
|
|
|
// Build string out of SRV port and Resolved IP
|
|
|
|
log.Println("Couldn't resolve :", target) |
|
|
|
peer := net.JoinHostPort(a, 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 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
defer resp.Body.Close() |
|
|
|
|
|
|
|
body, err := ioutil.ReadAll(resp.Body) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
log.Println("Reading seed failed:", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
s.ConnectToPeer(string(body)) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 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 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
defer resp.Body.Close() |
|
|
|
|
|
|
|
body, err := ioutil.ReadAll(resp.Body) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
log.Println("Reading seed failed:", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
s.ConnectToPeer(string(body)) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|