mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-03-13 19:37:30 +01:00
Implement rpcbind to allow for binding to a different interface (#2409)
This commit is contained in:
parent
de5041ee27
commit
eaecc1c377
6 changed files with 55 additions and 14 deletions
|
@ -22,13 +22,19 @@ class OracleServerMain(override val args: Array[String])
|
|||
routes = Seq(OracleRoutes(oracle))
|
||||
server = rpcPortOpt match {
|
||||
case Some(rpcport) =>
|
||||
Server(conf, routes, rpcport = rpcport)
|
||||
Server(conf = conf,
|
||||
handlers = routes,
|
||||
rpcbindOpt = rpcBindOpt,
|
||||
rpcport = rpcport)
|
||||
case None =>
|
||||
conf.rpcPortOpt match {
|
||||
case Some(rpcport) =>
|
||||
Server(conf, routes, rpcport)
|
||||
Server(conf = conf,
|
||||
handlers = routes,
|
||||
rpcbindOpt = rpcBindOpt,
|
||||
rpcport = rpcport)
|
||||
case None =>
|
||||
Server(conf, routes)
|
||||
Server(conf = conf, handlers = routes, rpcbindOpt = rpcBindOpt)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,15 @@ trait BitcoinSRunner extends BitcoinSLogger {
|
|||
|
||||
lazy val argsWithIndex: Vector[(String, Int)] = args.toVector.zipWithIndex
|
||||
|
||||
/** The ip address we are binding the server to */
|
||||
lazy val rpcBindOpt: Option[String] = {
|
||||
val rpcbindOpt = argsWithIndex.find(_._1.toLowerCase == "--rpcbind")
|
||||
rpcbindOpt.map {
|
||||
case (_, idx) =>
|
||||
args(idx + 1)
|
||||
}
|
||||
}
|
||||
|
||||
lazy val rpcPortOpt: Option[Int] = {
|
||||
val portOpt = argsWithIndex.find(_._1.toLowerCase == "--rpcport")
|
||||
portOpt.map {
|
||||
|
|
|
@ -94,7 +94,11 @@ class BitcoinSServerMain(override val args: Array[String])
|
|||
_ <- node.start()
|
||||
_ <- wallet.start()
|
||||
chainApi <- node.chainApiFromDb()
|
||||
binding <- startHttpServer(node, chainApi, wallet, rpcPortOpt)
|
||||
binding <- startHttpServer(nodeApi = node,
|
||||
chainApi = chainApi,
|
||||
wallet = wallet,
|
||||
rpcbindOpt = rpcBindOpt,
|
||||
rpcPortOpt = rpcPortOpt)
|
||||
_ = {
|
||||
logger.info(s"Starting ${nodeConf.nodeType.shortName} node sync")
|
||||
}
|
||||
|
@ -151,7 +155,11 @@ class BitcoinSServerMain(override val args: Array[String])
|
|||
blockCount)
|
||||
}
|
||||
|
||||
binding <- startHttpServer(bitcoind, bitcoind, wallet, rpcPortOpt)
|
||||
binding <- startHttpServer(nodeApi = bitcoind,
|
||||
chainApi = bitcoind,
|
||||
wallet = wallet,
|
||||
rpcbindOpt = rpcBindOpt,
|
||||
rpcPortOpt = rpcPortOpt)
|
||||
_ = BitcoinSServer.startedFP.success(Future.successful(binding))
|
||||
} yield {
|
||||
logger.info(s"Done starting Main!")
|
||||
|
@ -266,6 +274,7 @@ class BitcoinSServerMain(override val args: Array[String])
|
|||
nodeApi: NodeApi,
|
||||
chainApi: ChainApi,
|
||||
wallet: Wallet,
|
||||
rpcbindOpt: Option[String],
|
||||
rpcPortOpt: Option[Int])(implicit
|
||||
system: ActorSystem,
|
||||
conf: BitcoinSAppConfig): Future[Http.ServerBinding] = {
|
||||
|
@ -279,18 +288,26 @@ class BitcoinSServerMain(override val args: Array[String])
|
|||
val server = {
|
||||
rpcPortOpt match {
|
||||
case Some(rpcport) =>
|
||||
Server(nodeConf,
|
||||
Seq(walletRoutes, nodeRoutes, chainRoutes, coreRoutes),
|
||||
rpcport = rpcport)
|
||||
Server.apply(conf = nodeConf,
|
||||
handlers =
|
||||
Seq(walletRoutes, nodeRoutes, chainRoutes, coreRoutes),
|
||||
rpcbindOpt = rpcbindOpt,
|
||||
rpcport = rpcport)
|
||||
case None =>
|
||||
conf.rpcPortOpt match {
|
||||
case Some(rpcport) =>
|
||||
Server(nodeConf,
|
||||
Seq(walletRoutes, nodeRoutes, chainRoutes, coreRoutes),
|
||||
rpcport)
|
||||
Server.apply(
|
||||
conf = nodeConf,
|
||||
handlers =
|
||||
Seq(walletRoutes, nodeRoutes, chainRoutes, coreRoutes),
|
||||
rpcbindOpt = rpcbindOpt,
|
||||
rpcport = rpcport)
|
||||
case None =>
|
||||
Server(nodeConf,
|
||||
Seq(walletRoutes, nodeRoutes, chainRoutes, coreRoutes))
|
||||
Server.apply(
|
||||
conf = nodeConf,
|
||||
handlers =
|
||||
Seq(walletRoutes, nodeRoutes, chainRoutes, coreRoutes),
|
||||
rpcbindOpt = rpcbindOpt)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ import scala.concurrent.Future
|
|||
case class Server(
|
||||
conf: AppConfig,
|
||||
handlers: Seq[ServerRoute],
|
||||
rpcbindOpt: Option[String],
|
||||
rpcport: Int = 9999)(implicit system: ActorSystem)
|
||||
extends HttpLogger {
|
||||
|
||||
|
@ -78,7 +79,7 @@ case class Server(
|
|||
|
||||
def start(): Future[Http.ServerBinding] = {
|
||||
val httpFut =
|
||||
Http().bindAndHandle(route, "localhost", rpcport)
|
||||
Http().bindAndHandle(route, rpcbindOpt.getOrElse("localhost"), rpcport)
|
||||
httpFut.foreach { http =>
|
||||
logger.info(s"Started Bitcoin-S HTTP server at ${http.localAddress}")
|
||||
}
|
||||
|
|
|
@ -108,6 +108,7 @@ bitcoin-s {
|
|||
server {
|
||||
# The port we bind our rpc server on
|
||||
rpcport = 9999
|
||||
rpcbind = "127.0.0.1"
|
||||
}
|
||||
|
||||
oracle = ${bitcoin-s.dbDefault}
|
||||
|
|
|
@ -51,6 +51,10 @@ There are a few command line options available that take precedence over configu
|
|||
|
||||
`datadir` sets the data directory instead of using the default `$HOME/.bitcoin-s`
|
||||
|
||||
- `--rpcbind <ip>`
|
||||
|
||||
`rpcbind` sets the interface the rpc server binds to instead of using the default `127.0.0.1`
|
||||
|
||||
- `--rpcport <port>`
|
||||
|
||||
`rpcport` sets the port the rpc server binds to instead of using the default `9999`
|
||||
|
@ -203,6 +207,9 @@ bitcoin-s {
|
|||
server {
|
||||
# The port we bind our rpc server on
|
||||
rpcport = 9999
|
||||
|
||||
# The ip address we bind our server too
|
||||
rpcbind = "127.0.0.1"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue