multi: Addressing Tor support review comments

This commit is contained in:
MeshCollider 2018-01-23 00:48:59 +13:00 committed by Olaoluwa Osuntokun
parent 698df2ac16
commit 4affab7bd7
4 changed files with 16 additions and 12 deletions

View File

@ -24,8 +24,6 @@ var _ net.Listener = (*Listener)(nil)
// NewListener returns a new net.Listener which enforces the Brontide scheme
// during both initial connection establishment and data transfer.
// Note: though this function uses ResolveTCPAddr, we don't need to call the
// general lndResolveTCP function since we are resolving a local address.
func NewListener(localStatic *btcec.PrivateKey, listenAddr string) (*Listener,
error) {
addr, err := net.ResolveTCPAddr("tcp", listenAddr)

View File

@ -133,6 +133,11 @@ type autoPilotConfig struct {
Allocation float64 `long:"allocation" description:"The percentage of total funds that should be committed to automatic channel establishment"`
}
type torConfig struct {
Socks string `long:"socks" description:"The port that Tor's exposed SOCKS5 proxy is listening on. Using Tor allows outbound-only connections (listening will be disabled) -- NOTE port must be between 1024 and 65535"`
DNS string `long:"dns" description:"The DNS server as IP:PORT that Tor will use for SRV queries - NOTE must have TCP resolution enabled"`
}
// config defines the configuration options for lnd.
//
// See loadConfig for further details regarding the configuration
@ -161,9 +166,6 @@ type config struct {
Profile string `long:"profile" description:"Enable HTTP profiling on given port -- NOTE port must be between 1024 and 65535"`
TorSocks string `long:"torsocks" description:"The port that Tor's exposed SOCKS5 proxy is listening on -- NOTE port must be between 1024 and 65535"`
TorDNS string `long:"tordns" description:"The DNS server as IP:PORT that Tor will use for SRV queries - NOTE must have TCP resolution enabled"`
DebugHTLC bool `long:"debughtlc" description:"Activate the debug htlc mode. With the debug HTLC mode, all payments sent use a pre-determined R-Hash. Additionally, all HTLCs sent to a node with the debug HTLC R-Hash are immediately settled in the next available state transition."`
HodlHTLC bool `long:"hodlhtlc" description:"Activate the hodl HTLC mode. With hodl HTLC mode, all incoming HTLCs will be accepted by the receiving node, but no attempt will be made to settle the payment with the sender."`
MaxPendingChannels int `long:"maxpendingchannels" description:"The maximum number of incoming pending channels permitted per peer."`
@ -178,6 +180,8 @@ type config struct {
Autopilot *autoPilotConfig `group:"autopilot" namespace:"autopilot"`
Tor *torConfig `group:"Tor" namespace:"tor"`
NoNetBootstrap bool `long:"nobootstrap" description:"If true, then automatic network bootstrapping will not be attempted."`
NoEncryptWallet bool `long:"noencryptwallet" description:"If set, wallet will be encrypted using the default passphrase."`
@ -298,9 +302,9 @@ func loadConfig() (*config, error) {
// the proxy specific dial function and the DNS resolution functions use
// Tor.
cfg.net = &torsvc.MultiNet{Tor: false}
if cfg.TorSocks != "" && cfg.TorDNS != "" {
if cfg.Tor.Socks != "" && cfg.Tor.DNS != "" {
// Validate Tor port number
torport, err := strconv.Atoi(cfg.TorSocks)
torport, err := strconv.Atoi(cfg.Tor.Socks)
if err != nil || torport < 1024 || torport > 65535 {
str := "%s: The tor socks5 port must be between 1024 and 65535"
err := fmt.Errorf(str, funcName)
@ -319,16 +323,16 @@ func loadConfig() (*config, error) {
return nil, err
}
cfg.net.TorDNS = cfg.TorDNS
cfg.net.TorSocks = cfg.TorSocks
cfg.net.TorDNS = cfg.Tor.DNS
cfg.net.TorSocks = cfg.Tor.Socks
// If we are using Tor, since we only want connections routed
// through Tor, listening is disabled.
cfg.DisableListen = true
} else if cfg.TorSocks != "" || cfg.TorDNS != "" {
} else if cfg.Tor.Socks != "" || cfg.Tor.DNS != "" {
// Both TorSocks and TorDNS must be set.
str := "%s: Both the torsocks and the tordns flags must be set" +
str := "%s: Both the tor.socks and the tor.dns flags must be set" +
"to properly route connections and avoid DNS leaks while" +
"using Tor"
err := fmt.Errorf(str, funcName)

View File

@ -589,7 +589,7 @@ func (r *rpcServer) ConnectPeer(ctx context.Context,
addr = in.Addr.Host
}
// We use lndResolveTCP here in case we wish to resolve hosts over Tor.
// We use ResolveTCPAddr here in case we wish to resolve hosts over Tor.
host, err := cfg.net.ResolveTCPAddr("tcp", addr)
if err != nil {
return nil, err

View File

@ -131,6 +131,8 @@ func newServer(listenAddrs []string, chanDB *channeldb.DB, cc *chainControl,
listeners := make([]net.Listener, len(listenAddrs))
for i, addr := range listenAddrs {
// Note: though brontide.NewListener uses ResolveTCPAddr, it doesn't need to call the
// general lndResolveTCP function since we are resolving a local address.
listeners[i], err = brontide.NewListener(privKey, addr)
if err != nil {
return nil, err