@@ -55,7 +55,7 @@ use crate::io_extras::read_to_end;
55
55
use crate :: events:: { EventsProvider , MessageSendEventsProvider } ;
56
56
use crate :: crypto:: streams:: ChaChaPolyReadAdapter ;
57
57
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 } ;
59
59
use crate :: util:: base32;
60
60
61
61
use crate :: routing:: gossip:: { NodeAlias , NodeId } ;
@@ -1857,6 +1857,26 @@ impl Writeable for TrampolineOnionPacket {
1857
1857
}
1858
1858
}
1859
1859
1860
+ impl LengthReadable for TrampolineOnionPacket {
1861
+ fn read < R : LengthRead > ( r : & mut R ) -> Result < Self , DecodeError > {
1862
+ let version = Readable :: read ( r) ?;
1863
+ let public_key = Readable :: read ( r) ?;
1864
+
1865
+ let hop_data_len = r. total_bytes ( ) . saturating_sub ( 66 ) ; // 1 (version) + 33 (pubkey) + 32 (HMAC) = 66
1866
+ let mut rd = FixedLengthReader :: new ( r, hop_data_len) ;
1867
+ let hop_data = WithoutLength :: < Vec < u8 > > :: read ( & mut rd) ?. 0 ;
1868
+
1869
+ let hmac = Readable :: read ( r) ?;
1870
+
1871
+ Ok ( TrampolineOnionPacket {
1872
+ version,
1873
+ public_key,
1874
+ hop_data,
1875
+ hmac,
1876
+ } )
1877
+ }
1878
+ }
1879
+
1860
1880
impl Debug for TrampolineOnionPacket {
1861
1881
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
1862
1882
f. write_fmt ( format_args ! ( "TrampolineOnionPacket version {} with hmac {:?}" , self . version, & self . hmac[ ..] ) )
@@ -3181,7 +3201,7 @@ mod tests {
3181
3201
use crate :: ln:: msgs:: { self , FinalOnionHopData , OnionErrorPacket , CommonOpenChannelFields , CommonAcceptChannelFields , TrampolineOnionPacket } ;
3182
3202
use crate :: ln:: msgs:: SocketAddress ;
3183
3203
use crate :: routing:: gossip:: { NodeAlias , NodeId } ;
3184
- use crate :: util:: ser:: { BigSize , Hostname , Readable , ReadableArgs , TransactionU16LenLimited , Writeable } ;
3204
+ use crate :: util:: ser:: { BigSize , FixedLengthReader , Hostname , LengthReadable , Readable , ReadableArgs , TransactionU16LenLimited , Writeable } ;
3185
3205
use crate :: util:: test_utils;
3186
3206
3187
3207
use bitcoin:: hashes:: hex:: FromHex ;
@@ -4497,6 +4517,13 @@ mod tests {
4497
4517
let encoded_trampoline_packet = trampoline_packet. encode ( ) ;
4498
4518
assert_eq ! ( encoded_trampoline_packet. len( ) , 716 ) ;
4499
4519
4520
+ { // verify that a codec round trip works
4521
+ let mut reader = Cursor :: new ( & encoded_trampoline_packet) ;
4522
+ let mut trampoline_packet_reader = FixedLengthReader :: new ( & mut reader, encoded_trampoline_packet. len ( ) as u64 ) ;
4523
+ let decoded_trampoline_packet: TrampolineOnionPacket = <TrampolineOnionPacket as LengthReadable >:: read ( & mut trampoline_packet_reader) . unwrap ( ) ;
4524
+ assert_eq ! ( decoded_trampoline_packet. encode( ) , encoded_trampoline_packet) ;
4525
+ }
4526
+
4500
4527
let msg = msgs:: OutboundOnionPayload :: TrampolineEntrypoint {
4501
4528
multipath_trampoline_data : None ,
4502
4529
amt_to_forward : 0x0badf00d01020304 ,
0 commit comments