From 8162aff8cfb76bf53dd06a19cf12208f7946349d Mon Sep 17 00:00:00 2001 From: Jarrad Hope Date: Thu, 6 Mar 2014 19:01:38 +0100 Subject: [PATCH 1/4] Add DNS Bootstrapping --- ethereum.go | 53 +++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 39 insertions(+), 14 deletions(-) diff --git a/ethereum.go b/ethereum.go index 342f4f573..4dd29f2e6 100644 --- a/ethereum.go +++ b/ethereum.go @@ -262,21 +262,46 @@ func (s *Ethereum) Start() { go s.ReapDeadPeerHandler() if ethutil.Config.Seed { - ethutil.Config.Log.Debugln("Seeding") - // Testnet seed bootstrapping - resp, err := http.Get("https://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 - } + 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 := 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 + } + defer resp.Body.Close() + body, err := ioutil.ReadAll(resp.Body) + if err != nil { + log.Println("Reading seed failed:", err) + return + } - s.ConnectToPeer(string(body)) + s.ConnectToPeer(string(body)) + } } } From e2e338929f8c1fb0bc424d0f5ca3353c6f36ec77 Mon Sep 17 00:00:00 2001 From: Jarrad Hope Date: Thu, 6 Mar 2014 19:03:26 +0100 Subject: [PATCH 2/4] Fix Whitespace --- ethereum.go | 74 ++++++++++++++++++++++++++--------------------------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/ethereum.go b/ethereum.go index 4dd29f2e6..6c19a13f9 100644 --- a/ethereum.go +++ b/ethereum.go @@ -262,46 +262,46 @@ func (s *Ethereum) Start() { 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 := 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) + 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 := 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 - } - 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)) + } } } From 9d887234eafb5884df9b2a90e3cb876688af0c21 Mon Sep 17 00:00:00 2001 From: Jarrad Hope Date: Thu, 6 Mar 2014 19:11:38 +0100 Subject: [PATCH 3/4] Small Optimization on port --- ethereum.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ethereum.go b/ethereum.go index 6c19a13f9..795f2cd52 100644 --- a/ethereum.go +++ b/ethereum.go @@ -270,13 +270,13 @@ func (s *Ethereum) Start() { // Iterate SRV nodes for _, n := range nodes { target := n.Target - port := n.Port + 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, strconv.Itoa(int(port))) + peer := net.JoinHostPort(a, port) log.Println("Found DNS Bootstrap Peer:", peer) peers = append(peers, peer) } From 694ef4704176c4c2329b56e4cd5320f558513efb Mon Sep 17 00:00:00 2001 From: Jarrad Hope Date: Fri, 7 Mar 2014 11:11:11 +0100 Subject: [PATCH 4/4] gofmt -w ethereum.go --- ethereum.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ethereum.go b/ethereum.go index 795f2cd52..fb97c34b1 100644 --- a/ethereum.go +++ b/ethereum.go @@ -264,8 +264,8 @@ func (s *Ethereum) Start() { if ethutil.Config.Seed { ethutil.Config.Log.Debugln("Seeding") // DNS Bootstrapping - _, nodes, err := net.LookupSRV("eth", "tcp", "ethereum.org") - if(err == nil) { + _, nodes, err := net.LookupSRV("eth", "tcp", "ethereum.org") + if err == nil { peers := []string{} // Iterate SRV nodes for _, n := range nodes { @@ -273,7 +273,7 @@ func (s *Ethereum) Start() { 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) { + if err == nil { for _, a := range addr { // Build string out of SRV port and Resolved IP peer := net.JoinHostPort(a, port)