initial proxy code

This commit is contained in:
David Hill 2013-08-07 20:40:40 -04:00 committed by Dave Collins
parent 9a9f41a2f3
commit 3f782928fd
3 changed files with 19 additions and 1 deletions

View file

@ -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}"`

View file

@ -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

View file

@ -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 {