X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Flib.rs;h=803c077bebcb6b68e74d636b631871228afb779d;hb=cf326fd7a9f42c58a24788943745f066ecb5f641;hp=363d4aeb9e94ddb2c8a1baddad45027eb2ac7129;hpb=2cf9129a187a66cfed10f9583c14fc8ee7339a18;p=rapid-gossip-sync-server diff --git a/src/lib.rs b/src/lib.rs index 363d4ae..803c077 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,6 +12,7 @@ extern crate core; use std::collections::{HashMap, HashSet}; use std::fs::File; use std::io::BufReader; +use std::ops::Deref; use std::sync::Arc; use lightning::routing::gossip::{NetworkGraph, NodeId}; @@ -43,9 +44,9 @@ pub mod types; /// The fourth byte is the protocol version in case our format gets updated. const GOSSIP_PREFIX: [u8; 4] = [76, 68, 75, 1]; -pub struct RapidSyncProcessor { - network_graph: Arc>>, - logger: Arc +pub struct RapidSyncProcessor where L::Target: Logger { + network_graph: Arc>, + logger: L } pub struct SerializedResponse { @@ -57,8 +58,8 @@ pub struct SerializedResponse { pub update_count_incremental: u32, } -impl RapidSyncProcessor { - pub fn new(logger: Arc) -> Self { +impl RapidSyncProcessor where L::Target: Logger { + pub fn new(logger: L) -> Self { let network = config::network(); let network_graph = if let Ok(file) = File::open(&config::network_graph_cache_path()) { println!("Initializing from cached network graph…"); @@ -90,7 +91,7 @@ impl RapidSyncProcessor { println!("Starting gossip download"); tokio::spawn(tracking::download_gossip(persistence_sender, sync_completion_sender, - Arc::clone(&self.network_graph), Arc::clone(&self.logger))); + Arc::clone(&self.network_graph), self.logger.clone())); println!("Starting gossip db persistence listener"); tokio::spawn(async move { persister.persist_gossip().await; }); } else { @@ -129,7 +130,7 @@ fn serialize_empty_blob(current_timestamp: u64) -> Vec { let chain_hash = genesis_block.block_hash(); chain_hash.write(&mut blob).unwrap(); - let blob_timestamp = Snapshotter::::round_down_to_nearest_multiple(current_timestamp, config::SNAPSHOT_CALCULATION_INTERVAL as u64) as u32; + let blob_timestamp = Snapshotter::>::round_down_to_nearest_multiple(current_timestamp, config::SNAPSHOT_CALCULATION_INTERVAL as u64) as u32; blob_timestamp.write(&mut blob).unwrap(); 0u32.write(&mut blob).unwrap(); // node count @@ -139,7 +140,7 @@ fn serialize_empty_blob(current_timestamp: u64) -> Vec { blob } -async fn serialize_delta(network_graph: Arc>>, last_sync_timestamp: u32) -> SerializedResponse { +async fn serialize_delta(network_graph: Arc>, last_sync_timestamp: u32) -> SerializedResponse where L::Target: Logger { let (client, connection) = lookup::connect_to_db().await; network_graph.remove_stale_channels_and_tracking();