X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fln%2Fonion_utils.rs;h=0deb8b74fdcfc1542cb56f044dd387b83af72c7a;hb=e7d3781dd7b8814964d063edd3c3ea230f56da21;hp=1c45da14a382c78aef88acda8a1a3d56ea0c1dca;hpb=52121ea97e7723b94fa215b72cf1e6a906c39531;p=rust-lightning diff --git a/lightning/src/ln/onion_utils.rs b/lightning/src/ln/onion_utils.rs index 1c45da14..0deb8b74 100644 --- a/lightning/src/ln/onion_utils.rs +++ b/lightning/src/ln/onion_utils.rs @@ -7,10 +7,10 @@ // You may not use this file except in accordance with one or both of these // licenses. -use ln::channelmanager::{PaymentHash, PaymentSecret, HTLCSource}; +use ln::{PaymentHash, PaymentSecret}; +use ln::channelmanager::HTLCSource; use ln::msgs; use routing::router::RouteHop; -use util::byte_utils; use util::chacha20::ChaCha20; use util::errors::{self, APIError}; use util::ser::{Readable, Writeable, LengthCalculatingWriter}; @@ -26,8 +26,10 @@ use bitcoin::secp256k1::Secp256k1; use bitcoin::secp256k1::ecdh::SharedSecret; use bitcoin::secp256k1; +use prelude::*; use std::io::Cursor; -use std::ops::Deref; +use core::convert::TryInto; +use core::ops::Deref; pub(super) struct OnionKeys { #[cfg(test)] @@ -365,7 +367,7 @@ pub(super) fn process_onion_failure(secp_ctx: & const NODE: u16 = 0x2000; const UPDATE: u16 = 0x1000; - let error_code = byte_utils::slice_to_be16(&error_code_slice); + let error_code = u16::from_be_bytes(error_code_slice.try_into().expect("len is 2")); error_code_ret = Some(error_code); error_packet_ret = Some(err_packet.failuremsg[2..].to_vec()); @@ -392,7 +394,7 @@ pub(super) fn process_onion_failure(secp_ctx: & } else if error_code & UPDATE == UPDATE { if let Some(update_len_slice) = err_packet.failuremsg.get(debug_field_size+2..debug_field_size+4) { - let update_len = byte_utils::slice_to_be16(&update_len_slice) as usize; + let update_len = u16::from_be_bytes(update_len_slice.try_into().expect("len is 2")) as usize; if let Some(update_slice) = err_packet.failuremsg.get(debug_field_size + 4..debug_field_size + 4 + update_len) { if let Ok(chan_update) = msgs::ChannelUpdate::read(&mut Cursor::new(&update_slice)) { // if channel_update should NOT have caused the failure: @@ -449,10 +451,10 @@ pub(super) fn process_onion_failure(secp_ctx: & let (description, title) = errors::get_onion_error_description(error_code); if debug_field_size > 0 && err_packet.failuremsg.len() >= 4 + debug_field_size { - log_warn!(logger, "Onion Error[{}({:#x}) {}({})] {}", title, error_code, debug_field, log_bytes!(&err_packet.failuremsg[4..4+debug_field_size]), description); + log_warn!(logger, "Onion Error[from {}: {}({:#x}) {}({})] {}", route_hop.pubkey, title, error_code, debug_field, log_bytes!(&err_packet.failuremsg[4..4+debug_field_size]), description); } else { - log_warn!(logger, "Onion Error[{}({:#x})] {}", title, error_code, description); + log_warn!(logger, "Onion Error[from {}: {}({:#x})] {}", route_hop.pubkey, title, error_code, description); } } else { // Useless packet that we can't use but it passed HMAC, so it @@ -477,7 +479,8 @@ pub(super) fn process_onion_failure(secp_ctx: & #[cfg(test)] mod tests { - use ln::channelmanager::PaymentHash; + use prelude::*; + use ln::PaymentHash; use ln::features::{ChannelFeatures, NodeFeatures}; use routing::router::{Route, RouteHop}; use ln::msgs;