}
pub(crate) fn update_network_graph_from_byte_stream_no_std<R: io::Read>(
- &self, mut read_cursor: &mut R, current_time_unix: Option<u64>,
+ &self, read_cursor: &mut R, current_time_unix: Option<u64>,
) -> Result<u32, GraphSyncError> {
log_trace!(self.logger, "Processing RGS data...");
let mut protocol_prefix = [0u8; 3];
return Err(DecodeError::UnknownVersion.into());
}
- let version: u8 = Readable::read(&mut read_cursor)?;
+ let version: u8 = Readable::read(read_cursor)?;
if version != 1 && version != 2 {
return Err(DecodeError::UnknownVersion.into());
}
for address_index in 0..address_count {
let current_byte_count: u8 = Readable::read(read_cursor)?;
let mut address_reader =
- FixedLengthReader::new(&mut read_cursor, current_byte_count as u64);
+ FixedLengthReader::new(read_cursor, current_byte_count as u64);
if let Ok(current_address) = Readable::read(&mut address_reader) {
node_addresses.push(current_address);
if address_reader.bytes_remain() {
}
// obtain default values for non-incremental updates
- let default_cltv_expiry_delta: u16 = Readable::read(&mut read_cursor)?;
- let default_htlc_minimum_msat: u64 = Readable::read(&mut read_cursor)?;
- let default_fee_base_msat: u32 = Readable::read(&mut read_cursor)?;
- let default_fee_proportional_millionths: u32 = Readable::read(&mut read_cursor)?;
- let default_htlc_maximum_msat: u64 = Readable::read(&mut read_cursor)?;
+ let default_cltv_expiry_delta: u16 = Readable::read(read_cursor)?;
+ let default_htlc_minimum_msat: u64 = Readable::read(read_cursor)?;
+ let default_fee_base_msat: u32 = Readable::read(read_cursor)?;
+ let default_fee_proportional_millionths: u32 = Readable::read(read_cursor)?;
+ let default_htlc_maximum_msat: u64 = Readable::read(read_cursor)?;
let mut previous_channel_direction = None;
impl Readable for BlindedPath {
fn read<R: io::Read>(r: &mut R) -> Result<Self, DecodeError> {
- let mut first_byte: u8 = Readable::read(r)?;
+ let first_byte: u8 = Readable::read(r)?;
let introduction_node = match first_byte {
0 => IntroductionNode::DirectedShortChannelId(Direction::NodeOne, Readable::read(r)?),
1 => IntroductionNode::DirectedShortChannelId(Direction::NodeTwo, Readable::read(r)?),
2|3 => {
use io::Read;
- let mut pubkey_read = core::slice::from_mut(&mut first_byte).chain(r.by_ref());
- IntroductionNode::NodeId(Readable::read(&mut pubkey_read)?)
+ let mut bytes = [0; 33];
+ bytes[0] = first_byte;
+ r.read_exact(&mut bytes[1..])?;
+ IntroductionNode::NodeId(Readable::read(&mut &bytes[..])?)
},
_ => return Err(DecodeError::InvalidValue),
};
// Simultaneously read and decrypt an object from a LengthRead, storing it in Self::readable.
// LengthRead must be used instead of std::io::Read because we need the total length to separate
// out the tag at the end.
- fn read<R: LengthRead>(mut r: &mut R, secret: [u8; 32]) -> Result<Self, DecodeError> {
+ fn read<R: LengthRead>(r: &mut R, secret: [u8; 32]) -> Result<Self, DecodeError> {
if r.total_bytes() < 16 { return Err(DecodeError::InvalidValue) }
let mut chacha = ChaCha20Poly1305RFC::new(&secret, &[0; 12], &[]);
let decrypted_len = r.total_bytes() - 16;
- let s = FixedLengthReader::new(&mut r, decrypted_len);
+ let s = FixedLengthReader::new(r, decrypted_len);
let mut chacha_stream = ChaChaPolyReader { chacha: &mut chacha, read: s };
let readable: T = Readable::read(&mut chacha_stream)?;
chacha_stream.read.eat_remaining()?;
// Now deserialize the object back and make sure it matches the original.
let mut read_adapter: Option<ChaChaPolyReadAdapter<TestWriteable>> = None;
- decode_tlv_stream!(&writer.0[..], {
+ decode_tlv_stream!(&mut &writer.0[..], {
(1, read_adapter, (option: LengthReadableArgs, rho)),
});
assert_eq!(writeable, read_adapter.unwrap().readable);
Ok(count)
}
- pub fn read_to_end<D: io::Read>(mut d: D) -> Result<alloc::vec::Vec<u8>, io::Error> {
+ pub fn read_to_end<D: Read>(mut d: &mut D) -> Result<alloc::vec::Vec<u8>, io::Error> {
let mut result = vec![];
let mut buf = [0u8; 64];
loop {
let mut custom_tlvs = Vec::new();
let tlv_len = BigSize::read(r)?;
- let rd = FixedLengthReader::new(r, tlv_len.0);
- decode_tlv_stream_with_custom_tlv_decode!(rd, {
+ let mut rd = FixedLengthReader::new(r, tlv_len.0);
+ decode_tlv_stream_with_custom_tlv_decode!(&mut rd, {
(2, amt, (option, encoding: (u64, HighZeroBytesDroppedBigSize))),
(4, cltv_value, (option, encoding: (u32, HighZeroBytesDroppedBigSize))),
(6, short_id, option),
/// between "EOF reached before we started" and "EOF reached mid-read".
///
/// This is not exported to bindings users as manual TLV building is not currently supported in bindings
-pub struct ReadTrackingReader<R: Read> {
- read: R,
+pub struct ReadTrackingReader<'a, R: Read> {
+ read: &'a mut R,
/// Returns whether we have read from this reader or not yet.
pub have_read: bool,
}
-impl<R: Read> ReadTrackingReader<R> {
+impl<'a, R: Read> ReadTrackingReader<'a, R> {
/// Returns a new [`ReadTrackingReader`].
- pub fn new(read: R) -> Self {
+ pub fn new(read: &'a mut R) -> Self {
Self { read, have_read: false }
}
}
-impl<R: Read> Read for ReadTrackingReader<R> {
+impl<'a, R: Read> Read for ReadTrackingReader<'a, R> {
#[inline]
fn read(&mut self, dest: &mut [u8]) -> Result<usize, io::Error> {
match self.read.read(dest) {
fn read<R: Read>(mut reader: &mut R) -> Result<Self, DecodeError> {
let mut values = Vec::new();
loop {
- let mut track_read = ReadTrackingReader::new(&mut reader);
+ let mut track_read = ReadTrackingReader::new(reader);
match MaybeReadable::read(&mut track_read) {
Ok(Some(v)) => { values.push(v); },
Ok(None) => { },
/// For example,
/// ```
/// # use lightning::decode_tlv_stream;
-/// # fn read<R: lightning::io::Read> (stream: R) -> Result<(), lightning::ln::msgs::DecodeError> {
+/// # fn read<R: lightning::io::Read> (stream: &mut R) -> Result<(), lightning::ln::msgs::DecodeError> {
/// let mut required_value = 0u64;
/// let mut optional_value: Option<u64> = None;
/// decode_tlv_stream!(stream, {
$(, $decode_custom_tlv: expr)?) => { {
use $crate::ln::msgs::DecodeError;
let mut last_seen_type: Option<u64> = None;
- let mut stream_ref = $stream;
+ let stream_ref = $stream;
'tlv_read: loop {
use $crate::util::ser;
// determine whether we should break or return ShortRead if we get an
// UnexpectedEof. This should in every case be largely cosmetic, but its nice to
// pass the TLV test vectors exactly, which require this distinction.
- let mut tracking_reader = ser::ReadTrackingReader::new(&mut stream_ref);
+ let mut tracking_reader = ser::ReadTrackingReader::new(stream_ref);
match <$crate::util::ser::BigSize as $crate::util::ser::Readable>::read(&mut tracking_reader) {
Err(DecodeError::ShortRead) => {
if !tracking_reader.have_read {
last_seen_type = Some(typ.0);
// Finally, read the length and value itself:
- let length: ser::BigSize = $crate::util::ser::Readable::read(&mut stream_ref)?;
- let mut s = ser::FixedLengthReader::new(&mut stream_ref, length.0);
+ let length: ser::BigSize = $crate::util::ser::Readable::read(stream_ref)?;
+ let mut s = ser::FixedLengthReader::new(stream_ref, length.0);
match typ.0 {
$(_t if $crate::_decode_tlv_stream_match_check!(_t, $type, $fieldty) => {
$crate::_decode_tlv!($stream, s, $field, $fieldty);
}),*
$($tuple_variant_id => {
let length: $crate::util::ser::BigSize = $crate::util::ser::Readable::read(reader)?;
- let mut s = $crate::util::ser::FixedLengthReader::new(&mut reader, length.0);
+ let mut s = $crate::util::ser::FixedLengthReader::new(reader, length.0);
let res = $crate::util::ser::Readable::read(&mut s)?;
if s.bytes_remain() {
s.eat_remaining()?; // Return ShortRead if there's actually not enough bytes
}),*
$($tuple_variant_id => {
let length: $crate::util::ser::BigSize = $crate::util::ser::Readable::read(reader)?;
- let mut s = $crate::util::ser::FixedLengthReader::new(&mut reader, length.0);
+ let mut s = $crate::util::ser::FixedLengthReader::new(reader, length.0);
let res = $crate::util::ser::Readable::read(&mut s)?;
if s.bytes_remain() {
s.eat_remaining()?; // Return ShortRead if there's actually not enough bytes