+use std::ops::Deref;
use std::sync::{Arc, RwLock};
use bitcoin::secp256k1::PublicKey;
}
}
-pub(crate) struct GossipRouter<L: Logger + Send + Sync + 'static> {
- native_router: P2PGossipSync<Arc<NetworkGraph<Arc<L>>>, GossipChainAccess<L>, Arc<L>>,
+pub(crate) struct GossipRouter<L: Deref + Clone + Send + Sync + 'static> where L::Target: Logger {
+ native_router: P2PGossipSync<Arc<NetworkGraph<L>>, GossipChainAccess<L>, L>,
pub(crate) counter: RwLock<GossipCounter>,
sender: mpsc::Sender<GossipMessage>,
verifier: Arc<ChainVerifier<L>>,
- outbound_gossiper: Arc<P2PGossipSync<Arc<NetworkGraph<Arc<L>>>, GossipChainAccess<L>, Arc<L>>>,
+ outbound_gossiper: Arc<P2PGossipSync<Arc<NetworkGraph<L>>, GossipChainAccess<L>, L>>,
}
-impl<L: Logger + Send + Sync> GossipRouter<L> {
- pub(crate) fn new(network_graph: Arc<NetworkGraph<Arc<L>>>, sender: mpsc::Sender<GossipMessage>, logger: Arc<L>) -> Self {
+impl<L: Deref + Clone + Send + Sync> GossipRouter<L> where L::Target: Logger {
+ pub(crate) fn new(network_graph: Arc<NetworkGraph<L>>, sender: mpsc::Sender<GossipMessage>, logger: L) -> Self {
let outbound_gossiper = Arc::new(P2PGossipSync::new(Arc::clone(&network_graph), None, logger.clone()));
let verifier = Arc::new(ChainVerifier::new(Arc::clone(&network_graph), Arc::clone(&outbound_gossiper)));
Self {
}
}
-impl<L: Logger + Send + Sync> MessageSendEventsProvider for GossipRouter<L> {
+impl<L: Deref + Clone + Send + Sync> MessageSendEventsProvider for GossipRouter<L> where L::Target: Logger {
fn get_and_clear_pending_msg_events(&self) -> Vec<MessageSendEvent> {
let gossip_evs = self.outbound_gossiper.get_and_clear_pending_msg_events();
for ev in gossip_evs {
}
}
-impl<L: Logger + Send + Sync> RoutingMessageHandler for GossipRouter<L> {
+impl<L: Deref + Clone + Send + Sync> RoutingMessageHandler for GossipRouter<L> where L::Target: Logger {
fn handle_node_announcement(&self, msg: &NodeAnnouncement) -> Result<bool, LightningError> {
self.native_router.handle_node_announcement(msg)
}
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};
/// 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<L: Logger> {
- network_graph: Arc<NetworkGraph<Arc<L>>>,
- logger: Arc<L>
+pub struct RapidSyncProcessor<L: Deref> where L::Target: Logger {
+ network_graph: Arc<NetworkGraph<L>>,
+ logger: L
}
pub struct SerializedResponse {
pub update_count_incremental: u32,
}
-impl<L: Logger + Send + Sync + 'static> RapidSyncProcessor<L> {
- pub fn new(logger: Arc<L>) -> Self {
+impl<L: Deref + Clone + Send + Sync + 'static> RapidSyncProcessor<L> 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…");
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 {
let chain_hash = genesis_block.block_hash();
chain_hash.write(&mut blob).unwrap();
- let blob_timestamp = Snapshotter::<RGSSLogger>::round_down_to_nearest_multiple(current_timestamp, config::SNAPSHOT_CALCULATION_INTERVAL as u64) as u32;
+ let blob_timestamp = Snapshotter::<Arc<RGSSLogger>>::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
blob
}
-async fn serialize_delta<L: Logger>(network_graph: Arc<NetworkGraph<Arc<L>>>, last_sync_timestamp: u32) -> SerializedResponse {
+async fn serialize_delta<L: Deref>(network_graph: Arc<NetworkGraph<L>>, last_sync_timestamp: u32) -> SerializedResponse where L::Target: Logger {
let (client, connection) = lookup::connect_to_db().await;
network_graph.remove_stale_channels_and_tracking();
use std::collections::{BTreeMap, HashSet};
use std::io::Cursor;
-use std::ops::Add;
+use std::ops::{Add, Deref};
use std::sync::Arc;
use std::time::{Duration, Instant, SystemTime};
/// whether they had been seen before.
/// Also include all announcements for which the first update was announced
/// after `last_sync_timestamp`
-pub(super) async fn fetch_channel_announcements<L: Logger>(delta_set: &mut DeltaSet, network_graph: Arc<NetworkGraph<Arc<L>>>, client: &Client, last_sync_timestamp: u32) {
+pub(super) async fn fetch_channel_announcements<L: Deref>(delta_set: &mut DeltaSet, network_graph: Arc<NetworkGraph<L>>, client: &Client, last_sync_timestamp: u32) where L::Target: Logger {
println!("Obtaining channel ids from network graph");
let last_sync_timestamp_object = SystemTime::UNIX_EPOCH.add(Duration::from_secs(last_sync_timestamp as u64));
let channel_ids = {
use std::fs::OpenOptions;
use std::io::{BufWriter, Write};
+use std::ops::Deref;
use std::sync::Arc;
use std::time::{Duration, Instant};
use lightning::routing::gossip::NetworkGraph;
const POSTGRES_INSERT_TIMEOUT: Duration = Duration::from_secs(15);
-pub(crate) struct GossipPersister<L: Logger> {
+pub(crate) struct GossipPersister<L: Deref> where L::Target: Logger {
gossip_persistence_receiver: mpsc::Receiver<GossipMessage>,
- network_graph: Arc<NetworkGraph<Arc<L>>>,
+ network_graph: Arc<NetworkGraph<L>>,
}
-impl<L: Logger> GossipPersister<L> {
- pub fn new(network_graph: Arc<NetworkGraph<Arc<L>>>) -> (Self, mpsc::Sender<GossipMessage>) {
+impl<L: Deref> GossipPersister<L> where L::Target: Logger {
+ pub fn new(network_graph: Arc<NetworkGraph<L>>) -> (Self, mpsc::Sender<GossipMessage>) {
let (gossip_persistence_sender, gossip_persistence_receiver) =
mpsc::channel::<GossipMessage>(100);
(GossipPersister {
use std::collections::HashMap;
use std::fs;
+use std::ops::Deref;
use std::os::unix::fs::symlink;
use std::sync::Arc;
use std::time::{Duration, SystemTime, UNIX_EPOCH};
use crate::config;
use crate::config::cache_path;
-pub(crate) struct Snapshotter<L: Logger> {
- network_graph: Arc<NetworkGraph<Arc<L>>>,
+pub(crate) struct Snapshotter<L: Deref> where L::Target: Logger {
+ network_graph: Arc<NetworkGraph<L>>,
}
-impl<L: Logger> Snapshotter<L> {
- pub fn new(network_graph: Arc<NetworkGraph<Arc<L>>>) -> Self {
+impl<L: Deref> Snapshotter<L> where L::Target: Logger {
+ pub fn new(network_graph: Arc<NetworkGraph<L>>) -> Self {
Self { network_graph }
}
use std::collections::hash_map::RandomState;
use std::hash::{BuildHasher, Hasher};
use std::net::SocketAddr;
+use std::ops::Deref;
use std::sync::Arc;
use std::time::{Duration, Instant};
use crate::downloader::GossipRouter;
use crate::types::{GossipMessage, GossipPeerManager};
-pub(crate) async fn download_gossip<L: Logger + Send + Sync + 'static>(persistence_sender: mpsc::Sender<GossipMessage>,
+pub(crate) async fn download_gossip<L: Deref + Clone + Send + Sync + 'static>(persistence_sender: mpsc::Sender<GossipMessage>,
completion_sender: mpsc::Sender<()>,
- network_graph: Arc<NetworkGraph<Arc<L>>>,
- logger: Arc<L>
-) {
+ network_graph: Arc<NetworkGraph<L>>,
+ logger: L
+) where L::Target: Logger {
let mut key = [42; 32];
let mut random_data = [43; 32];
// Get something psuedo-random from std.
});
}
-async fn connect_peer<L: Logger + Send + Sync + 'static>(current_peer: (PublicKey, SocketAddr), peer_manager: GossipPeerManager<L>) -> bool {
+async fn connect_peer<L: Deref + Clone + Send + Sync + 'static>(current_peer: (PublicKey, SocketAddr), peer_manager: GossipPeerManager<L>) -> bool where L::Target: Logger {
eprintln!("Connecting to peer {}@{}...", current_peer.0.to_hex(), current_peer.1.to_string());
let connection = lightning_net_tokio::connect_outbound(
Arc::clone(&peer_manager),
use crate::verifier::ChainVerifier;
pub(crate) type GossipChainAccess<L> = Arc<ChainVerifier<L>>;
-pub(crate) type GossipPeerManager<L> = Arc<PeerManager<lightning_net_tokio::SocketDescriptor, ErroringMessageHandler, Arc<GossipRouter<L>>, IgnoringMessageHandler, Arc<L>, IgnoringMessageHandler, Arc<KeysManager>>>;
+pub(crate) type GossipPeerManager<L> = Arc<PeerManager<lightning_net_tokio::SocketDescriptor, ErroringMessageHandler, Arc<GossipRouter<L>>, IgnoringMessageHandler, L, IgnoringMessageHandler, Arc<KeysManager>>>;
#[derive(Debug)]
pub(crate) enum GossipMessage {
use std::convert::TryInto;
+use std::ops::Deref;
use std::sync::Arc;
use std::sync::Mutex;
use crate::config;
use crate::types::GossipPeerManager;
-pub(crate) struct ChainVerifier<L: Logger + Send + Sync + 'static> {
+pub(crate) struct ChainVerifier<L: Deref + Clone + Send + Sync + 'static> where L::Target: Logger {
rest_client: Arc<RestClient>,
- graph: Arc<NetworkGraph<Arc<L>>>,
- outbound_gossiper: Arc<P2PGossipSync<Arc<NetworkGraph<Arc<L>>>, Arc<Self>, Arc<L>>>,
+ graph: Arc<NetworkGraph<L>>,
+ outbound_gossiper: Arc<P2PGossipSync<Arc<NetworkGraph<L>>, Arc<Self>, L>>,
peer_handler: Mutex<Option<GossipPeerManager<L>>>,
}
struct RestBinaryResponse(Vec<u8>);
-impl<L: Logger + Send + Sync + 'static> ChainVerifier<L> {
- pub(crate) fn new(graph: Arc<NetworkGraph<Arc<L>>>, outbound_gossiper: Arc<P2PGossipSync<Arc<NetworkGraph<Arc<L>>>, Arc<Self>, Arc<L>>>) -> Self {
+impl<L: Deref + Clone + Send + Sync + 'static> ChainVerifier<L> where L::Target: Logger {
+ pub(crate) fn new(graph: Arc<NetworkGraph<L>>, outbound_gossiper: Arc<P2PGossipSync<Arc<NetworkGraph<L>>, Arc<Self>, L>>) -> Self {
ChainVerifier {
rest_client: Arc::new(RestClient::new(config::bitcoin_rest_endpoint()).unwrap()),
outbound_gossiper,
}
}
-impl<L: Logger + Send + Sync + 'static> UtxoLookup for ChainVerifier<L> {
+impl<L: Deref + Clone + Send + Sync + 'static> UtxoLookup for ChainVerifier<L> where L::Target: Logger {
fn get_utxo(&self, _genesis_hash: &BlockHash, short_channel_id: u64) -> UtxoResult {
let res = UtxoFuture::new();
let fut = res.clone();