Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 68 additions & 3 deletions Cargo-minimal.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1144,7 +1144,7 @@ dependencies = [
"libc",
"option-ext",
"redox_users",
"windows-sys 0.60.2",
"windows-sys 0.61.2",
]

[[package]]
Expand All @@ -1167,6 +1167,15 @@ dependencies = [
"const-random",
]

[[package]]
name = "document-features"
version = "0.2.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d4b8a88685455ed29a21542a33abd9cb6510b6b129abadabdcef0f4c55bc8f61"
dependencies = [
"litrs",
]

[[package]]
name = "electrum-client"
version = "0.18.0"
Expand Down Expand Up @@ -2045,6 +2054,12 @@ version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "241eaef5fd12c88705a01fc1066c48c4b36e0dd4377dcdc7ec3942cea7a69956"

[[package]]
name = "litrs"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "11d3d7f243d5c5a8b9bb5d6dd2b1602c0cb0b9db1621bafc7ed66e35ff9fe092"

[[package]]
name = "lock_api"
version = "0.4.12"
Expand Down Expand Up @@ -2165,6 +2180,17 @@ dependencies = [
"tokio",
]

[[package]]
name = "nix"
version = "0.26.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "598beaf3cc6fdd9a5dfb1630c2800c7acd31df7aaf0f565796fba2b53ca1af1b"
dependencies = [
"bitflags 1.3.2",
"cfg-if",
"libc",
]

[[package]]
name = "nix"
version = "0.30.1"
Expand Down Expand Up @@ -2194,7 +2220,7 @@ version = "0.50.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5"
dependencies = [
"windows-sys 0.60.2",
"windows-sys 0.61.2",
]

[[package]]
Expand Down Expand Up @@ -2403,7 +2429,7 @@ dependencies = [
"http-body-util",
"hyper",
"hyper-util",
"nix",
"nix 0.30.1",
"payjoin",
"payjoin-test-utils",
"r2d2",
Expand Down Expand Up @@ -2440,6 +2466,7 @@ dependencies = [
"serde",
"tempfile",
"tokio",
"tokio-listener",
"tokio-rustls",
"tokio-rustls-acme",
"tokio-stream",
Expand Down Expand Up @@ -2554,6 +2581,26 @@ dependencies = [
"sha2 0.10.8",
]

[[package]]
name = "pin-project"
version = "1.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "677f1add503faace112b9f1373e43e9e054bfdd22ff1a63c1bc485eaec6a6a8a"
dependencies = [
"pin-project-internal",
]

[[package]]
name = "pin-project-internal"
version = "1.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e918e4ff8c4549eb882f14b3a4bc8c8bc93de829416eacf579f1207a8fbf861"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.106",
]

[[package]]
name = "pin-project-lite"
version = "0.2.14"
Expand Down Expand Up @@ -3723,6 +3770,24 @@ dependencies = [
"windows-sys 0.61.2",
]

[[package]]
name = "tokio-listener"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c8a49c7295dbf705691c238002e4be940d5e0605f204683b1c8e55490032c79d"
dependencies = [
"clap",
"document-features",
"futures-core",
"futures-util",
"nix 0.26.4",
"pin-project",
"socket2 0.5.10",
"tokio",
"tokio-util",
"tracing",
]

[[package]]
name = "tokio-macros"
version = "2.6.0"
Expand Down
71 changes: 68 additions & 3 deletions Cargo-recent.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1144,7 +1144,7 @@ dependencies = [
"libc",
"option-ext",
"redox_users",
"windows-sys 0.60.2",
"windows-sys 0.61.2",
]

[[package]]
Expand All @@ -1167,6 +1167,15 @@ dependencies = [
"const-random",
]

[[package]]
name = "document-features"
version = "0.2.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d4b8a88685455ed29a21542a33abd9cb6510b6b129abadabdcef0f4c55bc8f61"
dependencies = [
"litrs",
]

[[package]]
name = "electrum-client"
version = "0.18.0"
Expand Down Expand Up @@ -2045,6 +2054,12 @@ version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "241eaef5fd12c88705a01fc1066c48c4b36e0dd4377dcdc7ec3942cea7a69956"

[[package]]
name = "litrs"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "11d3d7f243d5c5a8b9bb5d6dd2b1602c0cb0b9db1621bafc7ed66e35ff9fe092"

[[package]]
name = "lock_api"
version = "0.4.12"
Expand Down Expand Up @@ -2165,6 +2180,17 @@ dependencies = [
"tokio",
]

[[package]]
name = "nix"
version = "0.26.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "598beaf3cc6fdd9a5dfb1630c2800c7acd31df7aaf0f565796fba2b53ca1af1b"
dependencies = [
"bitflags 1.3.2",
"cfg-if",
"libc",
]

[[package]]
name = "nix"
version = "0.30.1"
Expand Down Expand Up @@ -2194,7 +2220,7 @@ version = "0.50.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5"
dependencies = [
"windows-sys 0.60.2",
"windows-sys 0.61.2",
]

[[package]]
Expand Down Expand Up @@ -2403,7 +2429,7 @@ dependencies = [
"http-body-util",
"hyper",
"hyper-util",
"nix",
"nix 0.30.1",
"payjoin",
"payjoin-test-utils",
"r2d2",
Expand Down Expand Up @@ -2440,6 +2466,7 @@ dependencies = [
"serde",
"tempfile",
"tokio",
"tokio-listener",
"tokio-rustls",
"tokio-rustls-acme",
"tokio-stream",
Expand Down Expand Up @@ -2554,6 +2581,26 @@ dependencies = [
"sha2 0.10.8",
]

[[package]]
name = "pin-project"
version = "1.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "677f1add503faace112b9f1373e43e9e054bfdd22ff1a63c1bc485eaec6a6a8a"
dependencies = [
"pin-project-internal",
]

[[package]]
name = "pin-project-internal"
version = "1.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e918e4ff8c4549eb882f14b3a4bc8c8bc93de829416eacf579f1207a8fbf861"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.106",
]

[[package]]
name = "pin-project-lite"
version = "0.2.14"
Expand Down Expand Up @@ -3723,6 +3770,24 @@ dependencies = [
"windows-sys 0.61.2",
]

[[package]]
name = "tokio-listener"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c8a49c7295dbf705691c238002e4be940d5e0605f204683b1c8e55490032c79d"
dependencies = [
"clap",
"document-features",
"futures-core",
"futures-util",
"nix 0.26.4",
"pin-project",
"socket2 0.5.10",
"tokio",
"tokio-util",
"tracing",
]

[[package]]
name = "tokio-macros"
version = "2.6.0"
Expand Down
1 change: 1 addition & 0 deletions payjoin-directory/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ prometheus = "0.13.4"
rand = "0.8"
serde = { version = "1.0.219", features = ["derive"] }
tokio = { version = "1.47.1", features = ["full"] }
tokio-listener = { version = "0.5", features = ["clap"] }
tokio-rustls = { version = "0.26.2", features = [
"ring",
], default-features = false, optional = true }
Expand Down
2 changes: 1 addition & 1 deletion payjoin-directory/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ services:
environment:
RUST_LOG: "trace"
PJ_DB_HOST: "redis:6379"
PJ_DIR_PORT: "8080"
PJ_LISTEN_ADDR: "[::]:8080"
depends_on:
- redis
networks:
Expand Down
9 changes: 5 additions & 4 deletions payjoin-directory/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::env;
use std::path::PathBuf;

use clap::Parser;
use tokio_listener::ListenerAddressLFlag;

#[derive(Debug, Parser)]
#[command(
Expand All @@ -10,11 +11,11 @@ use clap::Parser;
long_about = None,
)]
pub struct Cli {
#[arg(long, short = 'p', env = "PJ_DIR_PORT", help = "The port to bind [default: 8080]")]
pub port: Option<u16>, // TODO tokio_listener::ListenerAddressLFlag
#[clap(flatten)]
pub listen: ListenerAddressLFlag,

#[arg(long, env = "PJ_METRIC_PORT", help = "The port to bind for prometheus metrics export")]
pub metrics_port: Option<u16>, // TODO tokio_listener::ListenerAddressLFlag
#[arg(long = "metrics-listen-addr")]
pub metrics_listen_addr: Option<String>,

#[cfg(feature = "acme")]
#[clap(flatten)]
Expand Down
27 changes: 15 additions & 12 deletions payjoin-directory/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ use anyhow::Result;
use config::builder::DefaultState;
use config::{ConfigError, File, FileFormat};
use serde::Deserialize;
use tokio_listener::ListenerAddress;

type Builder = config::builder::ConfigBuilder<DefaultState>;

use crate::cli::Cli;

#[derive(Debug, Clone, Deserialize)]
#[derive(Debug, Clone)]
pub struct Config {
pub listen_addr: String, // TODO tokio_listener::ListenerAddressLFlag
pub metrics_listen_addr: Option<String>, // TODO tokio_listener::ListenerAddressLFlag
pub listen_addr: ListenerAddress,
pub metrics_listen_addr: Option<ListenerAddress>,
pub timeout: Duration,
pub storage_dir: PathBuf,
pub ohttp_keys: PathBuf, // TODO OhttpConfig struct with rotation params, etc
Expand Down Expand Up @@ -51,8 +52,17 @@ impl Config {
let built_config = config.build()?;

Ok(Config {
listen_addr: built_config.get("listen_addr")?,
metrics_listen_addr: built_config.get("metrics_listen_addr").ok(),
listen_addr: cli
.listen
.listen_address
.clone()
.ok_or_else(|| ConfigError::Message("listen_addr is required".to_string()))?,
metrics_listen_addr: match &cli.metrics_listen_addr {
Some(s) => Some(s.parse().map_err(|e| {
ConfigError::Message(format!("invalid metrics listen addr: {e}"))
})?),
None => None,
},
timeout: Duration::from_secs(built_config.get("timeout")?),
storage_dir: built_config.get("storage_dir")?,
ohttp_keys: built_config.get("ohttp_keys")?,
Expand All @@ -73,13 +83,6 @@ impl Config {

fn add_defaults(config: Builder, cli: &Cli) -> Result<Builder, ConfigError> {
let config = config
.set_default("listen_addr", "[::]:8080")?
.set_override_option("listen_addr", cli.port.map(|port| format!("[::]:{}", port)))?
.set_default("metrics_listen_addr", Option::<String>::None)?
.set_override_option(
"metrics_listen_addr",
cli.metrics_port.map(|port| format!("localhost:{}", port)),
)?
.set_default("timeout", Some(30))?
.set_override_option("timeout", cli.timeout)?
.set_default("ohttp_keys", "ohttp_keys")?
Expand Down
Loading