diff --git a/app/server/src/main/scala/org/bitcoins/server/BitcoinSAppConfig.scala b/app/server/src/main/scala/org/bitcoins/server/BitcoinSAppConfig.scala index f438c1af0e..7008c8038c 100644 --- a/app/server/src/main/scala/org/bitcoins/server/BitcoinSAppConfig.scala +++ b/app/server/src/main/scala/org/bitcoins/server/BitcoinSAppConfig.scala @@ -38,7 +38,7 @@ case class BitcoinSAppConfig( lazy val nodeConf: NodeAppConfig = NodeAppConfig(directory, confs: _*) lazy val chainConf: ChainAppConfig = ChainAppConfig(directory, confs: _*) lazy val dlcConf: DLCAppConfig = DLCAppConfig(directory, confs: _*) - lazy val torConf: TorAppConfig = TorAppConfig(directory, confs: _*) + lazy val torConf: TorAppConfig = TorAppConfig(directory, None, confs: _*) lazy val dlcNodeConf: DLCNodeAppConfig = DLCNodeAppConfig(directory, confs: _*) diff --git a/app/server/src/universal/docker-application.conf b/app/server/src/universal/docker-application.conf index 6c90e53090..ffb8fc08be 100644 --- a/app/server/src/universal/docker-application.conf +++ b/app/server/src/universal/docker-application.conf @@ -20,5 +20,11 @@ bitcoin-s.keymanager.entropy = ${?BITCOIN_S_KEYMANAGER_ENTROPY} bitcoin-s.proxy.enabled = ${?BITCOIN_S_PROXY_ENABLED} +bitcoin-s.bitcoind-rpc.proxy.enabled = ${?BITCOIN_S_BITCOIND_RPC_PROXY_ENABLED} +bitcoin-s.node.proxy.enabled = ${?BITCOIN_S_NODE_PROXY_ENABLED} +bitcoin-s.node.tor.enabled = ${?BITCOIN_S_NODE_TOR_ENABLED} +bitcoin-s.dlcnode.proxy.enabled = ${?BITCOIN_S_DLCNODE_PROXY_ENABLED} +bitcoin-s.dlcnode.tor.enabled = ${?BITCOIN_S_DLCNODE_TOR_ENABLED} + bitcoin-s.tor.enabled = ${?BITCOIN_S_TOR_ENABLED} bitcoin-s.tor.provided = ${?BITCOIN_S_TOR_PROVIDED} \ No newline at end of file diff --git a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/config/BitcoindRpcAppConfig.scala b/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/config/BitcoindRpcAppConfig.scala index 06f6409bce..365fcfae42 100644 --- a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/config/BitcoindRpcAppConfig.scala +++ b/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/config/BitcoindRpcAppConfig.scala @@ -104,7 +104,7 @@ case class BitcoindRpcAppConfig( config.getStringOrNone("bitcoin-s.bitcoind-rpc.rpcpassword") lazy val torConf: TorAppConfig = - TorAppConfig(directory, confs: _*) + TorAppConfig(directory, Some(moduleName), confs: _*) lazy val socks5ProxyParams: Option[Socks5ProxyParams] = torConf.socks5ProxyParams diff --git a/dlc-node/src/main/scala/org/bitcoins/dlc/node/config/DLCNodeAppConfig.scala b/dlc-node/src/main/scala/org/bitcoins/dlc/node/config/DLCNodeAppConfig.scala index 45e7e8e91d..ca664e33b9 100644 --- a/dlc-node/src/main/scala/org/bitcoins/dlc/node/config/DLCNodeAppConfig.scala +++ b/dlc-node/src/main/scala/org/bitcoins/dlc/node/config/DLCNodeAppConfig.scala @@ -42,7 +42,7 @@ case class DLCNodeAppConfig( override def stop(): Future[Unit] = Future.unit lazy val torConf: TorAppConfig = - TorAppConfig(directory, conf: _*) + TorAppConfig(directory, Some(moduleName), conf: _*) lazy val socks5ProxyParams: Option[Socks5ProxyParams] = torConf.socks5ProxyParams diff --git a/docs/tor/tor.md b/docs/tor/tor.md index ba26b712ff..c2893e9721 100644 --- a/docs/tor/tor.md +++ b/docs/tor/tor.md @@ -77,6 +77,9 @@ bitcoin-s { } ``` +You can override global proxy settings in subprojects, for example `bitcoin-s.dlcnode.proxy.enabled = true` +will enable SOCKS5 proxy for `dlcnode`. + ## Creating our own Tor hidden service Enabling the tor hidden services allows for inbound connections over tor. @@ -150,6 +153,8 @@ bitcoin-s { } } ``` +Similarly with proxy settings you can override global Tor settings in subprojects, +for example `bitcoin-s.dlcnode.tor.enabled = true` will enable Tor for `dlcnode`. ### Manually Creating a Tor Hidden Service diff --git a/node/src/main/scala/org/bitcoins/node/config/NodeAppConfig.scala b/node/src/main/scala/org/bitcoins/node/config/NodeAppConfig.scala index 9b79130e8d..1b7eb444c6 100644 --- a/node/src/main/scala/org/bitcoins/node/config/NodeAppConfig.scala +++ b/node/src/main/scala/org/bitcoins/node/config/NodeAppConfig.scala @@ -112,7 +112,7 @@ case class NodeAppConfig( } lazy val torConf: TorAppConfig = - TorAppConfig(directory, confs: _*) + TorAppConfig(directory, Some(moduleName), confs: _*) lazy val socks5ProxyParams: Option[Socks5ProxyParams] = torConf.socks5ProxyParams 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 fb86bc63a4..2166ffc081 100644 --- a/tor/src/main/scala/org/bitcoins/tor/config/TorAppConfig.scala +++ b/tor/src/main/scala/org/bitcoins/tor/config/TorAppConfig.scala @@ -21,6 +21,7 @@ import scala.concurrent.{Await, ExecutionContext, Future} */ case class TorAppConfig( private val directory: Path, + private val subModuleNameOpt: Option[String], private val confs: Config*)(implicit ec: ExecutionContext) extends AppConfig { override protected[bitcoins] def configOverrides: List[Config] = confs.toList @@ -29,7 +30,7 @@ case class TorAppConfig( override protected[bitcoins] def newConfigOfType( configs: Seq[Config]): TorAppConfig = - TorAppConfig(directory, configs: _*) + TorAppConfig(directory, subModuleNameOpt, configs: _*) protected[bitcoins] def baseDatadir: Path = directory @@ -39,16 +40,15 @@ case class TorAppConfig( lazy val torLogFile: Path = torDir.resolve("TorLogs.txt") - lazy val torProvided = config.getBoolean("bitcoin-s.tor.provided") + lazy val torProvided = getBoolean("tor.provided") - lazy val useRandomPorts = config.getBoolean("bitcoin-s.tor.use-random-ports") + lazy val useRandomPorts = getBoolean("tor.use-random-ports") lazy val socks5ProxyParams: Option[Socks5ProxyParams] = { - if (config.getBoolean("bitcoin-s.proxy.enabled")) { + if (getBoolean("proxy.enabled")) { val address = if (torProvided) { - NetworkUtil.parseInetSocketAddress( - config.getString("bitcoin-s.proxy.socks5"), - TorParams.DefaultProxyPort) + NetworkUtil.parseInetSocketAddress(getString("proxy.socks5"), + TorParams.DefaultProxyPort) } else { new InetSocketAddress(InetAddress.getLoopbackAddress, if (useRandomPorts) @@ -68,11 +68,10 @@ case class TorAppConfig( } lazy val torParams: Option[TorParams] = { - if (config.getBoolean("bitcoin-s.tor.enabled")) { + if (getBoolean("tor.enabled")) { val address = if (torProvided) { - NetworkUtil.parseInetSocketAddress( - config.getString("bitcoin-s.tor.control"), - TorParams.DefaultControlPort) + NetworkUtil.parseInetSocketAddress(getString("tor.control"), + TorParams.DefaultControlPort) } else { new InetSocketAddress(InetAddress.getLoopbackAddress, if (useRandomPorts) @@ -80,13 +79,13 @@ case class TorAppConfig( else TorParams.DefaultControlPort) } - val auth = config.getStringOrNone("bitcoin-s.tor.password") match { + val auth = getStringOrNone("tor.password") match { case Some(pass) => Password(pass) case None => SafeCookie() } val privKeyPath = - config.getStringOrNone("bitcoin-s.tor.privateKeyPath") match { + getStringOrNone("tor.privateKeyPath") match { case Some(path) => new File(path).toPath case None => datadir.resolve("tor_priv_key") } @@ -198,6 +197,29 @@ case class TorAppConfig( NetworkUtil.portIsBound(toCheck) } + + private def getBoolean(key: String): Boolean = + getConfigValue(config.getBoolean)(key) + + private def getString(key: String): String = + getConfigValue(config.getString)(key) + + private def getStringOrNone(key: String): Option[String] = + getConfigValue(config.getStringOrNone)(key) + + private def getConfigValue[V](getValue: String => V)(key: String): V = { + subModuleNameOpt match { + case Some(subModuleName) => + val path = s"bitcoin-s.$subModuleName.$key" + if (config.hasPath(path)) { + getValue(path) + } else { + getValue(s"bitcoin-s.$key") + } + case None => + getValue(s"bitcoin-s.$key") + } + } } object TorAppConfig extends AppConfigFactory[TorAppConfig] { @@ -209,7 +231,7 @@ object TorAppConfig extends AppConfigFactory[TorAppConfig] { */ override def fromDatadir(datadir: Path, confs: Vector[Config])(implicit ec: ExecutionContext): TorAppConfig = - TorAppConfig(datadir, confs: _*) + TorAppConfig(datadir, None, confs: _*) lazy val randomSocks5Port: Int = ports.proxyPort diff --git a/wallet/src/main/scala/org/bitcoins/wallet/config/WalletAppConfig.scala b/wallet/src/main/scala/org/bitcoins/wallet/config/WalletAppConfig.scala index 3047f560d7..9b2ebc1150 100644 --- a/wallet/src/main/scala/org/bitcoins/wallet/config/WalletAppConfig.scala +++ b/wallet/src/main/scala/org/bitcoins/wallet/config/WalletAppConfig.scala @@ -54,7 +54,7 @@ case class WalletAppConfig( override def appConfig: WalletAppConfig = this lazy val torConf: TorAppConfig = - TorAppConfig(directory, conf: _*) + TorAppConfig(directory, Some(moduleName), conf: _*) private[wallet] lazy val scheduler: ScheduledExecutorService = { Executors.newScheduledThreadPool(