From 4143e5359887fc8872e276eb3f3a33e9c70b2bc3 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Mon, 16 Dec 2019 12:27:50 +0000 Subject: [PATCH] presence: ability to configure local directory server --- src/main.rs | 11 ++++++++--- src/provider/presence.rs | 10 +++++++--- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index f13ec27560..b4146f4b2b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -57,7 +57,11 @@ fn main() { .help("Directory storing all packets for the clients") .takes_value(true) .required(true), - ), + ).arg(Arg::with_name("local") + .long("local") + .help("Flag to indicate whether the provider should run on a local deployment.") + .takes_value(false) + ) ) .get_matches(); @@ -69,6 +73,7 @@ fn main() { fn run(matches: &ArgMatches) { println!("Running the service provider!"); + let is_local = matches.is_present("local"); let mix_host = matches.value_of("mixHost").unwrap_or("0.0.0.0"); let mix_port = match matches.value_of("mixPort").unwrap().parse::() { @@ -124,8 +129,8 @@ fn run(matches: &ArgMatches) { ); // Start sending presence notifications in a separate thread - thread::spawn(|| { - let notifier = presence::Notifier::new(); + thread::spawn(move || { + let notifier = presence::Notifier::new(is_local.clone()); notifier.run(); }); diff --git a/src/provider/presence.rs b/src/provider/presence.rs index 83106e4c18..21412e2e8a 100644 --- a/src/provider/presence.rs +++ b/src/provider/presence.rs @@ -13,10 +13,14 @@ pub struct Notifier { } impl Notifier { - pub fn new() -> Notifier { - let config = directory::Config { - base_url: "https://directory.nymtech.net/".to_string(), + pub fn new(is_local: bool) -> Notifier { + let url = if is_local { + "http://localhost:8080".to_string() + } else { + "https://directory.nymtech.net".to_string() }; + + let config = directory::Config { base_url: url }; let net_client = directory::Client::new(config); let presence = MixProviderPresence { host: "halpin.org:6666".to_string(),