mirror of
https://github.com/Start9Labs/c-lightning-http-plugin.git
synced 2026-08-13 21:02:46 +02:00
switch port to bind
This commit is contained in:
parent
df4b5df3b3
commit
1d7506b538
5 changed files with 38 additions and 51 deletions
39
Cargo.lock
generated
39
Cargo.lock
generated
|
|
@ -65,7 +65,7 @@ checksum = "130aac562c0dd69c56b3b1cc8ffd2e17be31d0b6c25b61c96b76231aa23e39e1"
|
|||
|
||||
[[package]]
|
||||
name = "c-lightning-http-plugin"
|
||||
version = "0.1.2"
|
||||
version = "0.2.0"
|
||||
dependencies = [
|
||||
"base64",
|
||||
"crossbeam-channel",
|
||||
|
|
@ -108,12 +108,12 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "crossbeam-channel"
|
||||
version = "0.4.3"
|
||||
version = "0.4.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "09ee0cc8804d5393478d743b035099520087a5186f3b93fa58cec08fa62407b6"
|
||||
checksum = "b153fe7cbef478c567df0f972e02e6d736db11affe43dfc9c56a9374d1adfb87"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"crossbeam-utils",
|
||||
"maybe-uninit",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -328,10 +328,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "cd179ae861f0c2e53da70d892f5f3029f9594be0c41dc5269cd371691b1dc2f9"
|
||||
|
||||
[[package]]
|
||||
name = "hyper"
|
||||
version = "0.13.7"
|
||||
name = "httpdate"
|
||||
version = "0.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3e68a8dd9716185d9e64ea473ea6ef63529252e3e27623295a0378a19665d5eb"
|
||||
checksum = "494b4d60369511e7dea41cf646832512a94e542f68bb9c49e54518e0f468eb47"
|
||||
|
||||
[[package]]
|
||||
name = "hyper"
|
||||
version = "0.13.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2f3afcfae8af5ad0576a31e768415edb627824129e8e5a29b8bfccb2f234e835"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"futures-channel",
|
||||
|
|
@ -341,10 +347,10 @@ dependencies = [
|
|||
"http",
|
||||
"http-body",
|
||||
"httparse",
|
||||
"httpdate",
|
||||
"itoa",
|
||||
"pin-project",
|
||||
"socket2",
|
||||
"time",
|
||||
"tokio",
|
||||
"tower-service",
|
||||
"tracing",
|
||||
|
|
@ -416,6 +422,12 @@ dependencies = [
|
|||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "maybe-uninit"
|
||||
version = "2.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.3.3"
|
||||
|
|
@ -680,17 +692,6 @@ dependencies = [
|
|||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "time"
|
||||
version = "0.1.42"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"redox_syscall",
|
||||
"winapi 0.3.8",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tokio"
|
||||
version = "0.2.22"
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "c-lightning-http-plugin"
|
||||
version = "0.1.2"
|
||||
version = "0.2.0"
|
||||
authors = ["Keagan McClelland <keagan@start9labs.com>", "Aiden McClelland <me@drbonez.dev>"]
|
||||
edition = "2018"
|
||||
description = "A plugin for c-lightning that proxies http rpc traffic to the unix domain socket."
|
||||
|
|
@ -13,10 +13,10 @@ readme = "README.md"
|
|||
|
||||
[dependencies]
|
||||
base64 = "0.12.3"
|
||||
crossbeam-channel = "0.4.3"
|
||||
crossbeam-channel = "0.4.4"
|
||||
failure = "0.1.8"
|
||||
futures = { version = "0.3.5", features = ["async-await"] }
|
||||
hyper = { version = "0.13.7", features = ["stream"] }
|
||||
hyper = { version = "0.13.8", features = ["stream"] }
|
||||
lazy_async_pool = "0.3.3"
|
||||
lazy_static = "1.4.0"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
use std::net::SocketAddr;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
|
||||
|
|
@ -8,7 +9,7 @@ use tokio::sync::RwLock;
|
|||
pub struct InitInfo {
|
||||
pub socket_path: PathBuf,
|
||||
pub auth_header: Option<String>,
|
||||
pub http_port: u16,
|
||||
pub http_bind: SocketAddr,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
use std::future::Future;
|
||||
use std::net::SocketAddr;
|
||||
|
||||
use failure::Error;
|
||||
use futures::FutureExt;
|
||||
|
|
@ -138,12 +137,12 @@ async fn main() {
|
|||
futures::future::ok::<_, Error>(service_fn(handler))
|
||||
});
|
||||
|
||||
let port = init_info_fut.wait_for_info().await.http_port;
|
||||
let bind = init_info_fut.wait_for_info().await.http_bind;
|
||||
|
||||
// Then bind and serve...
|
||||
let server = Server::bind(&SocketAddr::from(([127, 0, 0, 1], port))).serve(make_service);
|
||||
let server = Server::bind(&bind).serve(make_service);
|
||||
|
||||
eprintln!("Serving RPC on port {}", port);
|
||||
eprintln!("Serving RPC on {}", bind);
|
||||
|
||||
// And run forever...
|
||||
if let Err(e) = server.await {
|
||||
|
|
|
|||
34
src/rpc.rs
34
src/rpc.rs
|
|
@ -1,3 +1,4 @@
|
|||
use std::net::SocketAddr;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use crossbeam_channel::Sender;
|
||||
|
|
@ -151,10 +152,10 @@ pub fn handle_stdio_rpc(send_side: Sender<InitInfo>) {
|
|||
"description": "Basic-Auth password header for http authentication, not setting this will result in requests being rejected"
|
||||
},
|
||||
{
|
||||
"name": "http-port",
|
||||
"type": "int",
|
||||
"default": 8080,
|
||||
"description": "Http port for web server listening"
|
||||
"name": "http-bind",
|
||||
"type": "string",
|
||||
"default": "127.0.0.1:8080",
|
||||
"description": "IP and Port for web server to bind to"
|
||||
}
|
||||
],
|
||||
"rpcmethods": [],
|
||||
|
|
@ -236,7 +237,7 @@ impl From<LightningInit> for InitInfo {
|
|||
))
|
||||
))
|
||||
},
|
||||
http_port: li.options.http_port,
|
||||
http_bind: li.options.http_bind,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -249,8 +250,8 @@ fn default_pass() -> String {
|
|||
"".to_owned()
|
||||
}
|
||||
|
||||
fn default_port() -> u16 {
|
||||
8080
|
||||
fn default_bind() -> SocketAddr {
|
||||
SocketAddr::from(([127, 0, 0, 1], 8080))
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, serde::Deserialize)]
|
||||
|
|
@ -260,23 +261,8 @@ pub struct LightningOptions {
|
|||
http_user: String,
|
||||
#[serde(default = "default_pass")]
|
||||
http_pass: String,
|
||||
#[serde(default = "default_port")]
|
||||
#[serde(deserialize_with = "deser_str_num")]
|
||||
http_port: u16,
|
||||
}
|
||||
|
||||
fn deser_str_num<'de, D: serde::Deserializer<'de>>(deserializer: D) -> Result<u16, D::Error> {
|
||||
#[derive(serde::Deserialize)]
|
||||
#[serde(untagged)]
|
||||
enum StrNum {
|
||||
Str(String),
|
||||
Num(u16),
|
||||
}
|
||||
let sn: StrNum = serde::Deserialize::deserialize(deserializer)?;
|
||||
Ok(match sn {
|
||||
StrNum::Str(s) => s.parse().map_err(|e| serde::de::Error::custom(e))?,
|
||||
StrNum::Num(n) => n,
|
||||
})
|
||||
#[serde(default = "default_bind")]
|
||||
http_bind: SocketAddr,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, serde::Deserialize)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue