Skip to content
Snippets Groups Projects
Commit f4429e83 authored by j.detchart's avatar j.detchart
Browse files

start config

parent 6d2b50ef
No related branches found
No related tags found
No related merge requests found
......@@ -24,3 +24,5 @@ serde = { version = "1.0.192", features = ["derive"] }
regex = "1.10.2"
thiserror = "1.0.50"
serde_json = "1.0.108"
config = "0.13.3"
dirs = "5.0.1"
use config::{Config, ConfigError, Environment, File};
use serde::Deserialize;
use crate::commands::DragoonCommand;
const DRAGOON_CONFIG_PATH: &str = "~/.dragoon/";
const DRAGOON_CONFIG_FILE: &str = "~/.dragoon/Default.toml";
#[derive(Debug,Deserialize, Clone)]
pub struct WebServer {
pub url: String,
}
#[derive(Debug, Deserialize, Clone)]
pub struct DragoonConfig {
pub webserver: WebServer,
}
impl DragoonConfig {
pub fn new(file: &str) -> Result<Self, ConfigError> {
let s = Config::builder()
.add_source(File::with_name(&format!("{}/.dragoon/{}", dirs::home_dir().unwrap().to_str().unwrap(), file)))
.build()?;
s.try_deserialize()
}
}
\ No newline at end of file
......@@ -98,7 +98,7 @@ impl DragoonNetwork {
if let Ok(addr) = multiaddr.parse() {
match self.swarm.listen_on(addr) {
Ok(listener_id) => {
info!("listening on {}", multiaddr);
info!("listening on {}", multiaddr);self.swarm.behaviour().kademlia.add_address()
let id = regex::Regex::new(r"ListenerId\((\d+)\)")
.unwrap()
......
......@@ -3,6 +3,7 @@ mod commands;
mod dragoon_network;
mod dragoon_protocol;
mod error;
mod config;
use libp2p_core::identity::{ed25519, Keypair};
......@@ -14,6 +15,7 @@ use std::net::SocketAddr;
use std::sync::Arc;
use tokio::signal;
use tracing::info;
use crate::config::DragoonConfig;
use crate::dragoon_network::DragoonNetwork;
......@@ -21,6 +23,11 @@ use crate::dragoon_network::DragoonNetwork;
pub(crate) async fn main() -> Result<(), Box<dyn Error>> {
tracing_subscriber::fmt::try_init().expect("cannot init logger");
let settings = DragoonConfig::new("Node1").unwrap();
// Print out our settings
println!("{:?}", settings);
let (cmd_sender, cmd_receiver) = mpsc::channel(0);
let app = Router::new()
......@@ -35,7 +42,7 @@ pub(crate) async fn main() -> Result<(), Box<dyn Error>> {
let ip_port: SocketAddr = if let Some(ip_port) = std::env::args().nth(1) {
ip_port
} else {
"127.0.0.1:3000".to_string()
settings.webserver.url
}
.parse()
.unwrap();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment