Merge pull request #2813 from wereHamster/tor-target-ip-address
Tor option to override target IP address
This commit is contained in:
commit
0b2ef8bb4e
@ -218,6 +218,7 @@ type torConfig struct {
|
||||
DNS string `long:"dns" description:"The DNS server as host:port that Tor will use for SRV queries - NOTE must have TCP resolution enabled"`
|
||||
StreamIsolation bool `long:"streamisolation" description:"Enable Tor stream isolation by randomizing user credentials for each connection."`
|
||||
Control string `long:"control" description:"The host:port that Tor is listening on for Tor control connections"`
|
||||
TargetIPAddress string `long:"targetipaddress" description:"IP address that Tor should use as the target of the hidden service"`
|
||||
V2 bool `long:"v2" description:"Automatically set up a v2 onion service to listen for inbound connections"`
|
||||
V3 bool `long:"v3" description:"Automatically set up a v3 onion service to listen for inbound connections"`
|
||||
PrivateKeyPath string `long:"privatekeypath" description:"The path to the private key of the onion service being created"`
|
||||
|
@ -552,7 +552,7 @@ func newServer(listenAddrs []net.Addr, chanDB *channeldb.DB,
|
||||
// automatically create an onion service, we'll initiate our Tor
|
||||
// controller and establish a connection to the Tor server.
|
||||
if cfg.Tor.Active && (cfg.Tor.V2 || cfg.Tor.V3) {
|
||||
s.torController = tor.NewController(cfg.Tor.Control)
|
||||
s.torController = tor.NewController(cfg.Tor.Control, cfg.Tor.TargetIPAddress)
|
||||
}
|
||||
|
||||
chanGraph := chanDB.ChannelGraph()
|
||||
|
@ -81,12 +81,17 @@ type Controller struct {
|
||||
|
||||
// version is the current version of the Tor server.
|
||||
version string
|
||||
|
||||
// The IP address which we tell the Tor server to use to connect to the LND node.
|
||||
// This is required when the Tor server runs on another host, otherwise the service
|
||||
// will not be reachable.
|
||||
targetIPAddress string
|
||||
}
|
||||
|
||||
// NewController returns a new Tor controller that will be able to interact with
|
||||
// a Tor server.
|
||||
func NewController(controlAddr string) *Controller {
|
||||
return &Controller{controlAddr: controlAddr}
|
||||
func NewController(controlAddr string, targetIPAddress string) *Controller {
|
||||
return &Controller{controlAddr: controlAddr, targetIPAddress: targetIPAddress}
|
||||
}
|
||||
|
||||
// Start establishes and authenticates the connection between the controller and
|
||||
@ -469,13 +474,24 @@ func (c *Controller) AddOnion(cfg AddOnionConfig) (*OnionAddr, error) {
|
||||
// port. If no target ports were specified, we'll use the virtual port
|
||||
// to provide a one-to-one mapping.
|
||||
var portParam string
|
||||
if len(cfg.TargetPorts) == 0 {
|
||||
portParam += fmt.Sprintf("Port=%d,%d ", cfg.VirtualPort,
|
||||
cfg.VirtualPort)
|
||||
} else {
|
||||
for _, targetPort := range cfg.TargetPorts {
|
||||
|
||||
// Helper function which appends the correct Port param depending on
|
||||
// whether the user chose to use a custom target IP address or not.
|
||||
pushPortParam := func(targetPort int) {
|
||||
if c.targetIPAddress == "" {
|
||||
portParam += fmt.Sprintf("Port=%d,%d ", cfg.VirtualPort,
|
||||
targetPort)
|
||||
} else {
|
||||
portParam += fmt.Sprintf("Port=%d,%s:%d ", cfg.VirtualPort,
|
||||
c.targetIPAddress, targetPort)
|
||||
}
|
||||
}
|
||||
|
||||
if len(cfg.TargetPorts) == 0 {
|
||||
pushPortParam(cfg.VirtualPort)
|
||||
} else {
|
||||
for _, targetPort := range cfg.TargetPorts {
|
||||
pushPortParam(targetPort)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user