mirror of
https://github.com/lndk-org/lndk.git
synced 2026-08-13 12:33:05 +02:00
server: default lndk conf in lndk dir
LNDK is already using a datadir to store TLS certificates. In this PR we default LNDK config and data to ~/.lndk. Datadir is moved inside the default dir ~/.lndk/data. Then, we expect lndk.conf file to be iether in root of the project, or the default LNDK config folder or --config flag. Precedence is flag > root > default dir.
This commit is contained in:
parent
bce93885f5
commit
a2b42b5a79
3 changed files with 32 additions and 11 deletions
|
|
@ -40,7 +40,7 @@ doc = "The hex encoded macaroon to pass directly into LNDK"
|
|||
[[param]]
|
||||
name = "data_dir"
|
||||
type = "String"
|
||||
doc = "The path to the lndk data directory. By default this is stored in ~/.lndk"
|
||||
doc = "The path to the lndk data directory. By default this is stored in ~/.lndk/data"
|
||||
|
||||
[[param]]
|
||||
name = "log_file"
|
||||
|
|
|
|||
|
|
@ -62,8 +62,10 @@ pub fn init_logger(config: LogConfig) {
|
|||
pub const DEFAULT_SERVER_HOST: &str = "127.0.0.1";
|
||||
pub const DEFAULT_SERVER_PORT: u16 = 7000;
|
||||
pub const LDK_LOGGER_NAME: &str = "ldk";
|
||||
pub const DEFAULT_DATA_DIR: &str = ".lndk";
|
||||
pub const DEFAULT_DATA_DIR: &str = "data";
|
||||
pub const DEFAULT_LNDK_DIR: &str = ".lndk";
|
||||
pub const DEFAULT_LOG_FILE: &str = "lndk.log";
|
||||
pub const DEFAULT_CONFIG_FILE_NAME: &str = "lndk.conf";
|
||||
|
||||
pub const TLS_CERT_FILENAME: &str = "tls-cert.pem";
|
||||
pub const TLS_KEY_FILENAME: &str = "tls-key.pem";
|
||||
|
|
|
|||
37
src/main.rs
37
src/main.rs
|
|
@ -15,12 +15,14 @@ use lndk::lnd::{get_lnd_client, validate_lnd_creds, LndCfg};
|
|||
use lndk::server::{generate_tls_creds, read_tls, LNDKServer};
|
||||
use lndk::{
|
||||
lndkrpc, setup_logger, Cfg, LifecycleSignals, LndkOnionMessenger, OfferHandler,
|
||||
DEFAULT_DATA_DIR, DEFAULT_LOG_FILE, DEFAULT_SERVER_HOST, DEFAULT_SERVER_PORT,
|
||||
DEFAULT_CONFIG_FILE_NAME, DEFAULT_DATA_DIR, DEFAULT_LNDK_DIR, DEFAULT_LOG_FILE,
|
||||
DEFAULT_SERVER_HOST, DEFAULT_SERVER_PORT,
|
||||
};
|
||||
use lndkrpc::offers_server::OffersServer;
|
||||
use log::{error, info};
|
||||
use std::ffi::OsString;
|
||||
use std::fs::create_dir_all;
|
||||
use std::path::PathBuf;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::exit;
|
||||
use std::sync::Arc;
|
||||
use tokio::select;
|
||||
|
|
@ -33,13 +35,13 @@ extern crate configure_me;
|
|||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), ()> {
|
||||
let config = Config::including_optional_config_files(&["./lndk.conf"])
|
||||
let paths = get_conf_file_paths();
|
||||
let config = Config::including_optional_config_files(paths)
|
||||
.unwrap_or_exit()
|
||||
.0;
|
||||
|
||||
let data_dir = create_data_dir(&config.data_dir)
|
||||
.map_err(|e| println!("Error creating LNDK's data dir {e:?}"))?;
|
||||
|
||||
let data_dir = create_data_dir(&config.data_dir).map_err(|e| {
|
||||
println!("Error creating LNDK's data dir: {:?}", e);
|
||||
})?;
|
||||
let log_file = config.log_file.map(PathBuf::from).or(config
|
||||
.data_dir
|
||||
.map(|data_dir| PathBuf::from(data_dir).join(DEFAULT_LOG_FILE)));
|
||||
|
|
@ -161,14 +163,31 @@ async fn main() -> Result<(), ()> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
// Creates lndk's data directory at the specified directory, or ~/.lndk if not specified.
|
||||
// Creates lndk's data directory at the specified directory, or ~/.lndk/data if not specified.
|
||||
// Process must have write access to the directory.
|
||||
fn create_data_dir(data_dir: &Option<String>) -> Result<PathBuf, std::io::Error> {
|
||||
let path = match data_dir {
|
||||
Some(dir) => PathBuf::from(&dir),
|
||||
None => home_dir().unwrap().join(DEFAULT_DATA_DIR),
|
||||
None => get_default_lnkd_dir_path().join(DEFAULT_DATA_DIR),
|
||||
};
|
||||
|
||||
create_dir_all(&path)?;
|
||||
|
||||
Ok(path)
|
||||
}
|
||||
|
||||
fn get_default_lnkd_dir_path() -> PathBuf {
|
||||
home_dir().unwrap().join(DEFAULT_LNDK_DIR)
|
||||
}
|
||||
|
||||
fn get_conf_file_paths() -> Vec<OsString> {
|
||||
let default_lndk_config_path = get_default_lnkd_dir_path()
|
||||
.join(DEFAULT_CONFIG_FILE_NAME)
|
||||
.into_os_string();
|
||||
let current_dir_conf_file = Path::new("./")
|
||||
.join(DEFAULT_CONFIG_FILE_NAME)
|
||||
.into_os_string();
|
||||
|
||||
let paths = vec![current_dir_conf_file, default_lndk_config_path];
|
||||
paths
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue