Skip to content

Commit

Permalink
main: add grpc server config option
Browse files Browse the repository at this point in the history
  • Loading branch information
orbitalturtle committed May 17, 2024
1 parent e8137b2 commit 0a8d49b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
6 changes: 6 additions & 0 deletions config_spec.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,9 @@ name = "log_level"
type = "String"
optional = true
doc = "The log verbosity level. This can be set to either 'error', 'warn', 'info', 'debug' or 'trace'."

[[param]]
name = "grpc_port"
type = "u16"
optional = true
doc = "The port the grpc server will run on. Defaults to 7000."
6 changes: 5 additions & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ struct Cli {
#[arg(short, long, global = true, required = false, default_value = get_macaroon_path_default())]
macaroon: String,

#[arg(short, long, global = true, required = false, default_value = DEFAULT_SERVER_PORT.to_string())]
grpc_port: u16,

#[arg(
short,
long,
Expand Down Expand Up @@ -101,7 +104,8 @@ async fn main() -> Result<(), ()> {
ref offer_string,
amount,
} => {
let mut client = OffersClient::connect(format!("http://[::1]:{DEFAULT_SERVER_PORT}"))
let grpc_port = args.grpc_port;
let mut client = OffersClient::connect(format!("http://[::1]:{grpc_port}"))
.await
.map_err(|e| {
println!("ERROR: connecting to server {:?}.", e);
Expand Down
14 changes: 9 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,20 @@ async fn main() -> Result<(), ()> {
.expect("failed to get info")
.into_inner();

let addr = format!("[::1]:{DEFAULT_SERVER_PORT}")
.parse()
.map_err(|e| {
error!("Error parsing API address: {e}");
})?;
let grpc_port = match config.grpc_port {
Some(port) => port,
None => DEFAULT_SERVER_PORT,
};
let addr = format!("[::1]:{grpc_port}").parse().map_err(|e| {
error!("Error parsing API address: {e}");
})?;
let server = LNDKServer::new(Arc::clone(&handler), &info.identity_pubkey).await;
let server_fut = Server::builder()
.add_service(OffersServer::new(server))
.serve(addr);

info!("Starting lndk's grpc server on port {grpc_port}");

select! {
_ = messenger.run(args, Arc::clone(&handler)) => {
info!("Onion messenger completed");
Expand Down

0 comments on commit 0a8d49b

Please sign in to comment.