diff --git a/app/server/src/universal/docker-application.conf b/app/server/src/universal/docker-application.conf index f04ceb931f..6e7c3fa8e8 100644 --- a/app/server/src/universal/docker-application.conf +++ b/app/server/src/universal/docker-application.conf @@ -36,6 +36,7 @@ bitcoin-s.dlcnode.tor.enabled = ${?BITCOIN_S_DLCNODE_TOR_ENABLED} bitcoin-s.dlcnode.tor.control = ${?BITCOIN_S_DLCNODE_TOR_CONTROL} bitcoin-s.dlcnode.tor.password = ${?BITCOIN_S_DLCNODE_TOR_PASSWORD} bitcoin-s.dlcnode.external-ip = ${?BITCOIN_S_DLCNODE_EXTERNAL_IP} +bitcoin-s.dlcnode.tor.targets = [${?BITCOIN_S_DLCNODE_TOR_TARGETS}] bitcoin-s.wallet.allowExternalDLCAddresses = false bitcoin-s.wallet.allowExternalDLCAddresses = ${?BITCOIN_S_ALLOW_EXT_DLC_ADDRESSES} diff --git a/dlc-node-test/src/test/scala/org/bitcoins/dlc/node/DLCNegotiationTest.scala b/dlc-node-test/src/test/scala/org/bitcoins/dlc/node/DLCNegotiationTest.scala index 29c162257c..2dcd534f1a 100644 --- a/dlc-node-test/src/test/scala/org/bitcoins/dlc/node/DLCNegotiationTest.scala +++ b/dlc-node-test/src/test/scala/org/bitcoins/dlc/node/DLCNegotiationTest.scala @@ -37,7 +37,7 @@ class DLCNegotiationTest extends BitcoinSDualWalletTest { val handlerP = Promise[ActorRef]() for { - _ <- DLCServer.bind(walletA, bindAddress, None) + _ <- DLCServer.bind(walletA, bindAddress, Vector(), None) _ <- DLCClient.connect(Peer(connectAddress, socks5ProxyParams = None), walletB, Some(handlerP)) @@ -91,7 +91,7 @@ class DLCNegotiationTest extends BitcoinSDualWalletTest { val handlerP = Promise[ActorRef]() for { - _ <- DLCServer.bind(walletA, bindAddress, None) + _ <- DLCServer.bind(walletA, bindAddress, Vector(), None) _ <- DLCClient.connect(Peer(connectAddress, socks5ProxyParams = None), walletB, Some(handlerP)) diff --git a/dlc-node/src/main/scala/org/bitcoins/dlc/node/DLCNode.scala b/dlc-node/src/main/scala/org/bitcoins/dlc/node/DLCNode.scala index 445c7f6bad..5e395c9cd7 100644 --- a/dlc-node/src/main/scala/org/bitcoins/dlc/node/DLCNode.scala +++ b/dlc-node/src/main/scala/org/bitcoins/dlc/node/DLCNode.scala @@ -29,6 +29,7 @@ case class DLCNode(wallet: DLCWalletApi)(implicit .bind( wallet, config.listenAddress, + config.torConf.targets, config.torParams ) .map { case (addr, actor) => diff --git a/dlc-node/src/main/scala/org/bitcoins/dlc/node/DLCServer.scala b/dlc-node/src/main/scala/org/bitcoins/dlc/node/DLCServer.scala index 327fa517cc..f3a503b5a7 100644 --- a/dlc-node/src/main/scala/org/bitcoins/dlc/node/DLCServer.scala +++ b/dlc-node/src/main/scala/org/bitcoins/dlc/node/DLCServer.scala @@ -78,6 +78,7 @@ object DLCServer extends Logging { def bind( dlcWalletApi: DLCWalletApi, bindAddress: InetSocketAddress, + targets: Vector[InetSocketAddress], torParams: Option[TorParams], dataHandlerFactory: DLCDataHandler.Factory = DLCDataHandler.defaultFactory)(implicit @@ -94,7 +95,8 @@ object DLCServer extends Logging { params.controlAddress, params.authentication, params.privateKeyPath, - bindAddress.getPort + bindAddress.getPort, + targets.map(ip => s"${ip.getHostString}:${ip.getPort}") ) .map(Some(_)) case None => diff --git a/docker-compose.yml b/docker-compose.yml index 9a85344c36..7331cd8739 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -39,6 +39,7 @@ services: BITCOIN_S_DLCNODE_PROXY_SOCKS5: "tor:9050" BITCOIN_S_DLCNODE_TOR_CONTROL: "tor:9051" BITCOIN_S_DLCNODE_TOR_PASSWORD: "topsecret" + BITCOIN_S_DLCNODE_TOR_TARGETS: "walletserver:2862" BITCOIN_S_SERVER_RPC_PASSWORD: $APP_PASSWORD DISABLE_JLINK: "1" ports: diff --git a/docs/config/configuration.md b/docs/config/configuration.md index 253ddb0174..0991659e84 100644 --- a/docs/config/configuration.md +++ b/docs/config/configuration.md @@ -211,6 +211,9 @@ bitcoin-s { # The path to the private key of the onion service being created # privateKeyPath = /path/to/priv/key + + # Optonal Tor targets. If empty all hidden serices will be created at localhost. + targets = [] } # settings for the chain module diff --git a/tor/src/main/scala/org/bitcoins/tor/config/TorAppConfig.scala b/tor/src/main/scala/org/bitcoins/tor/config/TorAppConfig.scala index bb6299ec8c..cf7e4185f5 100644 --- a/tor/src/main/scala/org/bitcoins/tor/config/TorAppConfig.scala +++ b/tor/src/main/scala/org/bitcoins/tor/config/TorAppConfig.scala @@ -45,6 +45,9 @@ case class TorAppConfig( lazy val useRandomPorts = getBoolean("tor.use-random-ports") + lazy val targets = getStringList("tor.targets") + .map(NetworkUtil.parseInetSocketAddress(_, -1)) + lazy val socks5ProxyParams: Option[Socks5ProxyParams] = { if (getBoolean("proxy.enabled")) { val address = if (torProvided) { @@ -222,6 +225,15 @@ case class TorAppConfig( private def getStringOrNone(key: String): Option[String] = getConfigValue(config.getStringOrNone)(key) + private def getStringList(key: String): Vector[String] = try { + val list = getConfigValue(config.getStringList)(key) + 0.until(list.size()) + .foldLeft(Vector.empty[String])((acc, i) => acc :+ list.get(i)) + .flatMap(_.split(",")) + } catch { + case _: com.typesafe.config.ConfigException.Missing => Vector() + } + private def getConfigValue[V](getValue: String => V)(key: String): V = { subModuleNameOpt match { case Some(subModuleName) =>