X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fln%2Frouter.rs;h=9fe2cfb50012b3619d1b10ef0edcae65f0fddee9;hb=8cc3be9eab9ff322d543e989f28c775a69d6b78f;hp=4c3bcb98074fd8301941739c9352ce6bef593e05;hpb=270d1bd00636942fcf359b4abdc5681ebe15307d;p=rust-lightning diff --git a/src/ln/router.rs b/src/ln/router.rs index 4c3bcb98..9fe2cfb5 100644 --- a/src/ln/router.rs +++ b/src/ln/router.rs @@ -13,9 +13,9 @@ use bitcoin::blockdata::opcodes; use chain::chaininterface::{ChainError, ChainWatchInterface}; use ln::channelmanager; -use ln::msgs::{ErrorAction,HandleError,RoutingMessageHandler,NetAddress,GlobalFeatures}; +use ln::msgs::{DecodeError,ErrorAction,HandleError,RoutingMessageHandler,NetAddress,GlobalFeatures}; use ln::msgs; -use util::ser::Writeable; +use util::ser::{Writeable, Readable}; use util::logger::Logger; use std::cmp; @@ -47,6 +47,37 @@ pub struct Route { pub hops: Vec, } +impl Writeable for Route { + fn write(&self, writer: &mut W) -> Result<(), ::std::io::Error> { + (self.hops.len() as u8).write(writer)?; + for hop in self.hops.iter() { + hop.pubkey.write(writer)?; + hop.short_channel_id.write(writer)?; + hop.fee_msat.write(writer)?; + hop.cltv_expiry_delta.write(writer)?; + } + Ok(()) + } +} + +impl Readable for Route { + fn read(reader: &mut R) -> Result { + let hops_count: u8 = Readable::read(reader)?; + let mut hops = Vec::with_capacity(hops_count as usize); + for _ in 0..hops_count { + hops.push(RouteHop { + pubkey: Readable::read(reader)?, + short_channel_id: Readable::read(reader)?, + fee_msat: Readable::read(reader)?, + cltv_expiry_delta: Readable::read(reader)?, + }); + } + Ok(Route { + hops + }) + } +} + struct DirectionalChannelInfo { src_node_id: PublicKey, last_update: u32, @@ -349,18 +380,25 @@ impl RoutingMessageHandler for Router { &msgs::HTLCFailChannelUpdate::ChannelUpdateMessage { ref msg } => { let _ = self.handle_channel_update(msg); }, - &msgs::HTLCFailChannelUpdate::ChannelClosed { ref short_channel_id, is_permanent:_ } => { -//XXX + &msgs::HTLCFailChannelUpdate::ChannelClosed { ref short_channel_id, ref is_permanent } => { let mut network = self.network_map.write().unwrap(); - if let Some(chan) = network.channels.remove(short_channel_id) { - Self::remove_channel_in_nodes(&mut network.nodes, &chan, *short_channel_id); + if *is_permanent { + if let Some(chan) = network.channels.remove(short_channel_id) { + Self::remove_channel_in_nodes(&mut network.nodes, &chan, *short_channel_id); + } + } else { + if let Some(chan) = network.channels.get_mut(short_channel_id) { + chan.one_to_two.enabled = false; + chan.two_to_one.enabled = false; + } } }, - &msgs::HTLCFailChannelUpdate::NodeFailure { ref node_id, is_permanent:_ } => { -//XXX - //let mut network = self.network_map.write().unwrap(); - //TODO: check _blamed_upstream_node - self.mark_node_bad(node_id, false); + &msgs::HTLCFailChannelUpdate::NodeFailure { ref node_id, ref is_permanent } => { + if *is_permanent { + //TODO: Wholly remove the node + } else { + self.mark_node_bad(node_id, false); + } }, } }