From afe83af219c2146e022f6665cf30097b582d3e79 Mon Sep 17 00:00:00 2001 From: obscuren Date: Fri, 9 May 2014 16:09:28 +0200 Subject: Moved seeding and moved manifest --- ethereum.go | 82 ++++++++++++++++++++++++++++++++----------------------------- 1 file changed, 43 insertions(+), 39 deletions(-) (limited to 'ethereum.go') diff --git a/ethereum.go b/ethereum.go index 2f4db7336..e3140b5ce 100644 --- a/ethereum.go +++ b/ethereum.go @@ -253,7 +253,7 @@ func (s *Ethereum) ReapDeadPeerHandler() { } // Start the ethereum -func (s *Ethereum) Start() { +func (s *Ethereum) Start(seed bool) { // Bind to addr and port ln, err := net.Listen("tcp", ":"+s.Port) if err != nil { @@ -272,47 +272,51 @@ func (s *Ethereum) Start() { // Start the reaping processes go s.ReapDeadPeerHandler() - if ethutil.Config.Seed { - ethutil.Config.Log.Debugln("Seeding") - // 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 := strconv.Itoa(int(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, port) - log.Println("Found DNS Bootstrap Peer:", peer) - peers = append(peers, peer) - } - } else { - log.Println("Couldn't resolve :", target) + if seed { + s.Seed() + } +} + +func (s *Ethereum) Seed() { + ethutil.Config.Log.Debugln("Seeding") + // 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 := strconv.Itoa(int(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, 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)) } } -- cgit