use ln::channelmanager::{ChannelManager, ChannelManagerReadArgs, RAACommitmentOrder, PaymentPreimage, PaymentHash, PaymentSecret, PaymentSendFailure};
use ln::channelmonitor::{ChannelMonitor, ManyChannelMonitor};
use routing::router::{Route, get_route};
-use routing::network_graph::{NetGraphMsgHandler, NetGraphMsgHandlerReadArgs};
+use routing::network_graph::{NetGraphMsgHandler, NetworkGraph};
use ln::features::InitFeatures;
use ln::msgs;
use ln::msgs::{ChannelMessageHandler,RoutingMessageHandler};
use util::errors::APIError;
use util::logger::Logger;
use util::config::UserConfig;
-use util::ser::{ReadableArgs, Writeable};
+use util::ser::{ReadableArgs, Writeable, Readable};
use bitcoin::util::hash::BitcoinHash;
use bitcoin::blockdata::block::BlockHeader;
use std::cell::RefCell;
use std::rc::Rc;
-use std::sync::{Arc, Mutex};
+use std::sync::{Arc, Mutex, RwLock};
use std::mem;
use std::collections::HashMap;
// Check that if we serialize the Router, we can deserialize it again.
{
let mut w = test_utils::TestVecWriter(Vec::new());
- self.net_graph_msg_handler.write(&mut w).unwrap();
- let net_graph_msg_handler = NetGraphMsgHandler::read(&mut ::std::io::Cursor::new(&w.0), NetGraphMsgHandlerReadArgs {
- chain_monitor: Arc::clone(&self.chain_monitor) as Arc<chaininterface::ChainWatchInterface>,
- logger: Arc::clone(&self.logger) as Arc<Logger>
- }).unwrap();
+ let network_graph_ser = self.net_graph_msg_handler.network_graph.read().unwrap();
+ network_graph_ser.write(&mut w).unwrap();
+ let network_graph_deser = <NetworkGraph>::read(&mut ::std::io::Cursor::new(&w.0)).unwrap();
+ let net_graph_msg_handler = NetGraphMsgHandler::from_net_graph(
+ Arc::clone(&self.chain_monitor) as Arc<chaininterface::ChainWatchInterface>,
+ Arc::clone(&self.logger) as Arc<Logger>, RwLock::new(network_graph_deser)
+ );
let mut chan_progress = 0;
loop {
let orig_announcements = self.net_graph_msg_handler.get_next_channel_announcements(chan_progress, 255);
use ln::features::{ChannelFeatures, NodeFeatures};
use ln::msgs::{DecodeError,ErrorAction,LightningError,RoutingMessageHandler,NetAddress};
use ln::msgs;
-use util::ser::{Writeable, Readable, Writer, ReadableArgs};
+use util::ser::{Writeable, Readable, Writer};
use util::logger::Logger;
use std::cmp;
}
impl NetGraphMsgHandler {
- /// Creates a new tracker of the actual state of the network of channels and nodes.
+ /// Creates a new tracker of the actual state of the network of channels and nodes,
+ /// assuming fresh Network Graph
pub fn new(chain_monitor: Arc<ChainWatchInterface>, logger: Arc<Logger>) -> Self {
NetGraphMsgHandler {
secp_ctx: Secp256k1::verification_only(),
}
}
+ /// Creates a new tracker of the actual state of the network of channels and nodes,
+ /// assuming an existing Network Graph.
+ pub fn from_net_graph(chain_monitor: Arc<ChainWatchInterface>, logger: Arc<Logger>, network_graph: RwLock<NetworkGraph>) -> Self {
+ NetGraphMsgHandler {
+ secp_ctx: Secp256k1::verification_only(),
+ network_graph: network_graph,
+ full_syncs_requested: AtomicUsize::new(0),
+ chain_monitor,
+ logger: logger.clone(),
+ }
+ }
+
/// Get network addresses by node id
pub fn get_addresses(&self, pubkey: &PublicKey) -> Option<Vec<NetAddress>> {
let network = self.network_graph.read().unwrap();
}
}
-
-const SERIALIZATION_VERSION: u8 = 1;
-const MIN_SERIALIZATION_VERSION: u8 = 1;
-
-impl Writeable for NetGraphMsgHandler {
- fn write<W: Writer>(&self, writer: &mut W) -> Result<(), ::std::io::Error> {
- writer.write_all(&[SERIALIZATION_VERSION; 1])?;
- writer.write_all(&[MIN_SERIALIZATION_VERSION; 1])?;
-
- let network = self.network_graph.read().unwrap();
- network.write(writer)?;
- Ok(())
- }
-}
-
-/// Arguments for the creation of a NetGraphMsgHandler that are not deserialized.
-/// At a high-level, the process for deserializing a NetGraphMsgHandler and resuming normal operation is:
-/// 1) Deserialize the NetGraphMsgHandler by filling in this struct and calling <NetGraphMsgHandler>::read(reaser, args).
-/// 2) Register the new NetGraphMsgHandler with your ChainWatchInterface
-pub struct NetGraphMsgHandlerReadArgs {
- /// The ChainWatchInterface for use in the NetGraphMsgHandler in the future.
- ///
- /// No calls to the ChainWatchInterface will be made during deserialization.
- pub chain_monitor: Arc<ChainWatchInterface>,
- /// The Logger for use in the ChannelManager and which may be used to log information during
- /// deserialization.
- pub logger: Arc<Logger>,
-}
-
-impl ReadableArgs<NetGraphMsgHandlerReadArgs> for NetGraphMsgHandler {
- fn read<R: ::std::io::Read>(reader: &mut R, args: NetGraphMsgHandlerReadArgs) -> Result<NetGraphMsgHandler, DecodeError> {
- let _ver: u8 = Readable::read(reader)?;
- let min_ver: u8 = Readable::read(reader)?;
- if min_ver > SERIALIZATION_VERSION {
- return Err(DecodeError::UnknownVersion);
- }
- let network_graph = Readable::read(reader)?;
- Ok(NetGraphMsgHandler {
- secp_ctx: Secp256k1::verification_only(),
- network_graph: RwLock::new(network_graph),
- chain_monitor: args.chain_monitor,
- full_syncs_requested: AtomicUsize::new(0),
- logger: args.logger.clone(),
- })
- }
-}
-
#[derive(PartialEq, Debug)]
/// Details regarding one direction of a channel
pub struct DirectionalChannelInfo {