@@ -32,24 +32,28 @@ fn v2_reply_surbs_serialised_len(surbs: &[ReplySurb]) -> usize {
32
32
}
33
33
}
34
34
35
- // when serialising surbs are always prepended with u16-encoded count an u8-encoded number of hops
36
- 3 + num_surbs * v2_reply_surb_serialised_len ( num_hops)
35
+ // when serialising surbs are always prepended with:
36
+ // - u16-encoded count,
37
+ // - u8-encoded number of hops
38
+ // - u8 reserved value
39
+ 4 + num_surbs * v2_reply_surb_serialised_len ( num_hops)
37
40
}
38
41
39
- // NUM_SURBS (u16) || HOPS (u8) || SURB_DATA
42
+ // NUM_SURBS (u16) || HOPS (u8) || RESERVED (u8) || SURB_DATA
40
43
fn recover_reply_surbs_v2 (
41
44
bytes : & [ u8 ] ,
42
45
) -> Result < ( Vec < ReplySurb > , usize ) , InvalidReplyRequestError > {
43
- if bytes. len ( ) < 2 {
46
+ if bytes. len ( ) < 4 {
44
47
return Err ( InvalidReplyRequestError :: RequestTooShortToDeserialize ) ;
45
48
}
46
49
47
50
// we're not attaching more than 65k surbs...
48
51
let num_surbs = u16:: from_be_bytes ( [ bytes[ 0 ] , bytes[ 1 ] ] ) ;
49
52
let num_hops = bytes[ 2 ] ;
50
- let mut consumed = 3 ;
53
+ let _reserved = bytes[ 3 ] ;
54
+ let mut consumed = 4 ;
51
55
52
- let surb_size = ReplySurb :: v2_serialised_len ( num_hops) ;
56
+ let surb_size = v2_reply_surb_serialised_len ( num_hops) ;
53
57
if bytes[ consumed..] . len ( ) < num_surbs as usize * surb_size {
54
58
return Err ( InvalidReplyRequestError :: RequestTooShortToDeserialize ) ;
55
59
}
@@ -69,11 +73,13 @@ fn recover_reply_surbs_v2(
69
73
fn reply_surbs_bytes_v2 ( reply_surbs : & [ ReplySurb ] ) -> impl Iterator < Item = u8 > + use < ' _ > {
70
74
let num_surbs = reply_surbs. len ( ) as u16 ;
71
75
let num_hops = reply_surbs_hops ( reply_surbs) ;
76
+ let reserved = 0 ;
72
77
73
78
num_surbs
74
79
. to_be_bytes ( )
75
80
. into_iter ( )
76
81
. chain ( once ( num_hops) )
82
+ . chain ( once ( reserved) )
77
83
. chain ( reply_surbs. iter ( ) . flat_map ( |surb| surb. to_bytes ( ) ) )
78
84
}
79
85
0 commit comments