From d33e9b4165a9548b68a6650fbf542951328796f0 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Fri, 10 Jan 2014 01:31:20 -0600 Subject: [PATCH] Unexport and comment btcDial and btcLookup func. These functions are at the package level and only apply within btcd, so unexport them to be consistent. --- addrmanager.go | 2 +- config.go | 16 ++++++++++++++-- discovery.go | 2 +- peer.go | 2 +- sample-btcd.conf | 2 +- 5 files changed, 18 insertions(+), 6 deletions(-) diff --git a/addrmanager.go b/addrmanager.go index 71ce79df..854dab20 100644 --- a/addrmanager.go +++ b/addrmanager.go @@ -774,7 +774,7 @@ func hostToNetAddress(host string, port uint16, services btcwire.ServiceFlag) (* prefix := []byte{0xfd, 0x87, 0xd8, 0x7e, 0xeb, 0x43} ip = net.IP(append(prefix, data...)) } else if ip = net.ParseIP(host); ip == nil { - ips, err := BtcdLookup(host) + ips, err := btcdLookup(host) if err != nil { return nil, err } diff --git a/config.go b/config.go index 3f1c2da3..f3f58fb8 100644 --- a/config.go +++ b/config.go @@ -538,14 +538,26 @@ func loadConfig() (*config, []string, error) { return &cfg, remainingArgs, nil } -func BtcdDial(network, address string) (net.Conn, error) { +// btcdDial connects to the address on the named network using the appropriate +// dial function depending on the address and configuration options. For +// example, .onion addresses will be dialed using the onion specific proxy if +// one was specified, but will otherwise use the normal dial function (which +// could itself use a proxy or not). +func btcdDial(network, address string) (net.Conn, error) { if strings.HasSuffix(address, ".onion") { return cfg.oniondial(network, address) } return cfg.dial(network, address) } -func BtcdLookup(host string) ([]net.IP, error) { +// btcdLookup returns the correct DNS lookup function to use depending on the +// passed host and configuration options. For example, .onion addresses will be +// resolved using the onion specific proxy if one was specified, but will +// otherwise treat the normal proxy as tor unless --noonion was specified in +// which case the lookup will fail. Meanwhile, normal IP addresses will be +// resolved using tor if a proxy was specified unless --noonion was also +// specified in which case the normal system DNS resolver will be used. +func btcdLookup(host string) ([]net.IP, error) { if strings.HasSuffix(host, ".onion") { return cfg.onionlookup(host) } diff --git a/discovery.go b/discovery.go index 487926a9..febd8c40 100644 --- a/discovery.go +++ b/discovery.go @@ -130,7 +130,7 @@ func torLookupIP(host, proxy string) ([]net.IP, error) { // strings will be returned. func dnsDiscover(seeder string) []net.IP { discLog.Debugf("Fetching list of seeds from %v", seeder) - peers, err := BtcdLookup(seeder) + peers, err := btcdLookup(seeder) if err != nil { discLog.Debugf("Unable to fetch dns seeds from %s: %v", seeder, err) diff --git a/peer.go b/peer.go index dd10bb9c..ad33404e 100644 --- a/peer.go +++ b/peer.go @@ -1551,7 +1551,7 @@ func newOutboundPeer(s *server, addr string, persistent bool) *peer { // interval. for atomic.LoadInt32(&p.disconnect) == 0 { srvrLog.Debugf("Attempting to connect to %s", addr) - conn, err := BtcdDial("tcp", addr) + conn, err := btcdDial("tcp", addr) if err != nil { p.retryCount += 1 srvrLog.Debugf("Failed to connect to %s: %v", diff --git a/sample-btcd.conf b/sample-btcd.conf index 6b8abfb1..73ba3c31 100644 --- a/sample-btcd.conf +++ b/sample-btcd.conf @@ -32,7 +32,7 @@ ; If the proxy is not tor the the following my be used to prevent using ; tor specific SOCKS queries to lookup addresses (this increases anonymity when ; tor is used by preventing your IP being leaked via DNS). -;noonion=1 +; noonion=1 ; Use an alternative proxy to connect to .onion addresses. The proxy is assumed ; to be a Tor node. Non .onion addresses will be contacted with the main proxy