Skip to content

Commit c9fb4a3

Browse files
committed
Make Trampoline onion deserializable.
1 parent ac9a2c8 commit c9fb4a3

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

lightning/src/ln/msgs.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ use crate::io_extras::read_to_end;
5555
use crate::events::{EventsProvider, MessageSendEventsProvider};
5656
use crate::crypto::streams::ChaChaPolyReadAdapter;
5757
use crate::util::logger;
58-
use crate::util::ser::{LengthReadable, LengthReadableArgs, Readable, ReadableArgs, Writeable, Writer, WithoutLength, FixedLengthReader, HighZeroBytesDroppedBigSize, Hostname, TransactionU16LenLimited, BigSize};
58+
use crate::util::ser::{BigSize, FixedLengthReader, HighZeroBytesDroppedBigSize, Hostname, LengthRead, LengthReadable, LengthReadableArgs, Readable, ReadableArgs, TransactionU16LenLimited, WithoutLength, Writeable, Writer};
5959
use crate::util::base32;
6060

6161
use crate::routing::gossip::{NodeAlias, NodeId};
@@ -1856,6 +1856,26 @@ impl Writeable for TrampolineOnionPacket {
18561856
}
18571857
}
18581858

1859+
impl LengthReadable for TrampolineOnionPacket {
1860+
fn read<R: LengthRead>(r: &mut R) -> Result<Self, DecodeError> {
1861+
let version = Readable::read(r)?;
1862+
let public_key = Readable::read(r)?;
1863+
1864+
let hop_data_len = r.total_bytes().saturating_sub(66); // 1 (version) + 33 (pubkey) + 32 (HMAC) = 66
1865+
let mut rd = FixedLengthReader::new(r, hop_data_len);
1866+
let hop_data = WithoutLength::<Vec<u8>>::read(&mut rd)?.0;
1867+
1868+
let hmac = Readable::read(r)?;
1869+
1870+
Ok(TrampolineOnionPacket {
1871+
version,
1872+
public_key,
1873+
hop_data,
1874+
hmac,
1875+
})
1876+
}
1877+
}
1878+
18591879
impl Debug for TrampolineOnionPacket {
18601880
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
18611881
f.write_fmt(format_args!("TrampolineOnionPacket version {} with hmac {:?}", self.version, &self.hmac[..]))

0 commit comments

Comments
 (0)