From ac0678c9a3fb7c0bcdb31ab249fe058fe9e56af1 Mon Sep 17 00:00:00 2001 From: Valentine Wallace Date: Fri, 19 Mar 2021 18:37:28 -0400 Subject: [PATCH] working before async refactor --- src/cli.rs | 6 +++--- src/main.rs | 30 ++++++++++++++++-------------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index 21c4023..ca1b84f 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -160,10 +160,10 @@ pub(crate) fn poll_for_user_input( // let private_channel = match words.next().as_ref().map(String::as_str) { let announce_channel = match words.next() { - Some("--public") | Some("--public=true") | Some("--public true") => true, - Some("--public=false") | Some("--public false") => false, + Some("--public") | Some("--public=true") => true, + Some("--public=false") => false, Some(_) => { - println!("ERROR: invalid `--public` command format"); + println!("ERROR: invalid `--public` command format. Valid formats: `--public`, `--public=true` `--public=false`"); print!("> "); io::stdout().flush().unwrap(); continue; diff --git a/src/main.rs b/src/main.rs index 0b45f0e..529e170 100644 --- a/src/main.rs +++ b/src/main.rs @@ -484,7 +484,7 @@ fn main() { SpvClient::new(chain_tip.unwrap(), chain_poller, &mut cache, &chain_listener); loop { spv_client.poll_best_tip().await.unwrap(); - thread::sleep(Duration::new(1, 0)); + tokio::time::sleep(Duration::from_secs(1)).await; } }); @@ -501,11 +501,9 @@ fn main() { ); let peer_manager_processor = peer_manager.clone(); - runtime_handle.spawn(async move { - loop { - peer_manager_processor.timer_tick_occurred(); - thread::sleep(Duration::new(60, 0)); - } + thread::spawn(move || loop { + peer_manager_processor.timer_tick_occurred(); + thread::sleep(Duration::new(60, 0)); }); // Step 15: Initialize LDK Event Handling @@ -515,7 +513,6 @@ fn main() { let keys_manager_listener = keys_manager.clone(); let payment_info: PaymentInfoStorage = Arc::new(Mutex::new(HashMap::new())); let payment_info_for_events = payment_info.clone(); - let handle = runtime_handle.clone(); let network = args.network; thread::spawn(move || { handle_ldk_events( @@ -530,17 +527,22 @@ fn main() { }); // Reconnect to channel peers if possible. + let handle = runtime_handle.clone(); let peer_data_path = format!("{}/channel_peer_data", ldk_data_dir.clone()); match disk::read_channel_peer_data(Path::new(&peer_data_path)) { Ok(mut info) => { for (pubkey, peer_addr) in info.drain() { - let _ = cli::connect_peer_if_necessary( - pubkey, - peer_addr, - peer_manager.clone(), - event_ntfn_sender.clone(), - handle.clone(), - ); + for chan_info in channel_manager.list_channels() { + if pubkey == chan_info.remote_network_id { + let _ = cli::connect_peer_if_necessary( + pubkey, + peer_addr, + peer_manager.clone(), + event_ntfn_sender.clone(), + handle.clone(), + ); + } + } } } Err(e) => println!("ERROR: errored reading channel peer info from disk: {:?}", e), -- 2.39.5