Fix Tor hidden service config (#4689)

* Fix Tor hidden service config

* default the target list to an empty list

* Scala 2.12 compatibility

* update docs

* Fix typo

Co-authored-by: Chris Stewart <stewart.chris1234@gmail.com>
This commit is contained in:
rorp 2022-09-01 14:54:39 -07:00 committed by GitHub
parent dbcde5d3c7
commit 7322186b56
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 23 additions and 3 deletions

View file

@ -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}

View file

@ -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))

View file

@ -29,6 +29,7 @@ case class DLCNode(wallet: DLCWalletApi)(implicit
.bind(
wallet,
config.listenAddress,
config.torConf.targets,
config.torParams
)
.map { case (addr, actor) =>

View file

@ -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 =>

View file

@ -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:

View file

@ -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

View file

@ -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) =>