From 3f782928fd7db2d42bffbcbe90c54df899d3c3c6 Mon Sep 17 00:00:00 2001 From: David Hill Date: Wed, 7 Aug 2013 20:40:40 -0400 Subject: [PATCH] initial proxy code --- config.go | 4 ++++ sample-btcd.conf | 8 ++++++++ server.go | 8 +++++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/config.go b/config.go index d7f44460..728e4a69 100644 --- a/config.go +++ b/config.go @@ -50,6 +50,10 @@ type config struct { RpcPort string `short:"r" long:"rpcport" description:"Listen for json/rpc messages on this port"` DisableRpc bool `long:"norpc" description:"Disable built-in RPC server -- NOTE: The RPC server is disabled by default if no rpcuser/rpcpass is specified"` DisableDNSSeed bool `long:"nodnsseed" description:"Disable DNS seeding for peers"` + Proxy string `long:"proxy" description:"Connect via SOCKS5 proxy (127.0.0.1:9050)"` + ProxyUser string `long:"proxyuser" description:"Username for proxy server"` + ProxyPass string `long:"proxypass" description:"Password for proxy server"` + Tor bool `long:"tor" description:"The Proxy being used is Tor"` TestNet3 bool `long:"testnet" description:"Use the test network"` RegressionTest bool `long:"regtest" description:"Use the regression test network"` DebugLevel string `short:"d" long:"debuglevel" description:"Logging level {trace, debug, info, warn, error, critical}"` diff --git a/sample-btcd.conf b/sample-btcd.conf index 13e435bb..1152bdeb 100644 --- a/sample-btcd.conf +++ b/sample-btcd.conf @@ -18,6 +18,14 @@ ; Maximum number of inbound and outbound peers. ; maxpeers=8 +; Connect via SOCKS5 +; proxy=127.0.0.1:9050 +; proxyuser= +; proxypass= + +; SOCKS5 Proxy above is Tor (https://www.torproject.org) +; tor=1 + ; How long to ban misbehaving peers. Valid time units are {s, m, h}. ; Minimum 1s. ; banduration=24h diff --git a/server.go b/server.go index 405e6d30..3481904a 100644 --- a/server.go +++ b/server.go @@ -8,6 +8,7 @@ import ( "container/list" "github.com/conformal/btcdb" "github.com/conformal/btcwire" + "github.com/conformal/go-socks" "net" "sync" "time" @@ -249,12 +250,17 @@ func (s *server) ConnectPeerAsync(addr string, persistent bool) { } go func() { + dial := net.Dial + if cfg.Proxy != "" { + proxy := &socks.Proxy{cfg.Proxy, cfg.ProxyUser, cfg.ProxyPass} + dial = proxy.Dial + } // Attempt to connect to the peer. If the connection fails and // this is a persistent connection, retry after the retry // interval. for !s.shutdown { log.Debugf("[SRVR] Attempting to connect to %s", addr) - conn, err := net.Dial("tcp", addr) + conn, err := dial("tcp", addr) if err != nil { log.Errorf("[SRVR] %v", err) if !persistent {