socks5/tor proxy support
This commit is contained in:
parent
1ff67707e4
commit
89e3054bc5
2 changed files with 26 additions and 3 deletions
|
@ -53,6 +53,9 @@ type config struct {
|
|||
Username string `short:"u" long:"username" description:"Username for btcd authorization"`
|
||||
Password string `short:"P" long:"password" description:"Password for btcd authorization"`
|
||||
MainNet bool `long:"mainnet" description:"*DISABLED* Use the main Bitcoin network (default testnet3)"`
|
||||
Proxy string `long:"proxy" description:"Connect via SOCKS5 proxy (eg. 127.0.0.1:9050)"`
|
||||
ProxyUser string `long:"proxyuser" description:"Username for proxy server"`
|
||||
ProxyPass string `long:"proxypass" default-mask:"-" description:"Password for proxy server"`
|
||||
}
|
||||
|
||||
// updateConfigWithActiveParams update the passed config with parameters
|
||||
|
|
26
sockets.go
26
sockets.go
|
@ -28,6 +28,7 @@ import (
|
|||
"github.com/conformal/btcwallet/wallet"
|
||||
"github.com/conformal/btcwire"
|
||||
"github.com/conformal/btcws"
|
||||
"github.com/conformal/go-socks"
|
||||
"net"
|
||||
"net/http"
|
||||
"sync"
|
||||
|
@ -600,9 +601,28 @@ func BtcdConnect(certificates []byte, reply chan error) {
|
|||
config.Header.Add("Authorization", auth)
|
||||
|
||||
// Attempt to connect to running btcd instance. Bail if it fails.
|
||||
btcdws, err := websocket.DialConfig(config)
|
||||
if err != nil {
|
||||
log.Errorf("%s", err)
|
||||
var btcdws *websocket.Conn
|
||||
var cerr error
|
||||
if cfg.Proxy != "" {
|
||||
proxy := &socks.Proxy{
|
||||
Addr: cfg.Proxy,
|
||||
Username: cfg.ProxyUser,
|
||||
Password: cfg.ProxyPass,
|
||||
}
|
||||
conn, err := proxy.Dial("tcp", cfg.Connect)
|
||||
if err != nil {
|
||||
log.Warnf("Error connecting to proxy: %v", err)
|
||||
reply <- ErrConnRefused
|
||||
return
|
||||
}
|
||||
|
||||
tlsConn := tls.Client(conn, config.TlsConfig)
|
||||
btcdws, cerr = websocket.NewClient(config, tlsConn)
|
||||
} else {
|
||||
btcdws, cerr = websocket.DialConfig(config)
|
||||
}
|
||||
if cerr != nil {
|
||||
log.Errorf("%s", cerr)
|
||||
reply <- ErrConnRefused
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue