@@ -60,15 +60,13 @@ impl<NG: Deref<Target=NetworkGraph<L>>, L: Deref> RapidGossipSync<NG, L> where L
60
60
) -> Result < u32 , GraphSyncError > {
61
61
log_trace ! ( self . logger, "Processing RGS data..." ) ;
62
62
let mut protocol_prefix = [ 0u8 ; 3 ] ;
63
- let mut version_prefix = [ 0u8 ; 1 ] ;
64
63
65
64
read_cursor. read_exact ( & mut protocol_prefix) ?;
66
65
if protocol_prefix != GOSSIP_PREFIX {
67
66
return Err ( DecodeError :: UnknownVersion . into ( ) ) ;
68
67
}
69
68
70
- read_cursor. read_exact ( & mut version_prefix) ?;
71
- let version = version_prefix[ 0 ] ;
69
+ let version: u8 = Readable :: read ( & mut read_cursor) ?;
72
70
if version != 1 && version != 2 {
73
71
return Err ( DecodeError :: UnknownVersion . into ( ) ) ;
74
72
}
@@ -120,13 +118,28 @@ impl<NG: Deref<Target=NetworkGraph<L>>, L: Deref> RapidGossipSync<NG, L> where L
120
118
for _ in 0 ..node_id_count {
121
119
let mut pubkey_bytes = [ 0u8 ; 33 ] ;
122
120
read_cursor. read_exact ( & mut pubkey_bytes) ?;
123
- let node_detail_flag = pubkey_bytes[ 0 ] ;
121
+
122
+ /*
123
+ We encode additional information in the pubkey parity byte with the following mapping:
124
+
125
+ 7-6: expect extra data after the pubkey (01 => u8, 10 => u16, 11 => u32)
126
+ 5-3: index of new features among default (1-6). If index is 7 (all 3 bits are set, it's
127
+ outside the present default range). 0 means no feature changes.
128
+ 2: addresses have changed
129
+
130
+ 1: used for all keys
131
+ 0: used for odd keys
132
+ */
133
+ let node_detail_flag = pubkey_bytes. first ( ) . ok_or ( DecodeError :: ShortRead ) ?;
134
+
124
135
let has_address_details = ( node_detail_flag & ( 1 << 2 ) ) > 0 ;
125
136
let feature_detail_marker = ( node_detail_flag & ( 0b111 << 3 ) ) >> 3 ;
126
- // println!("feature detail marker: {}", feature_detail_marker);
127
137
let additional_data_marker = ( node_detail_flag & ( 0b11 << 6 ) ) >> 6 ;
138
+
139
+ // extract the relevant bits for pubkey parity
128
140
let key_parity = node_detail_flag & 0b_0000_0011 ;
129
141
pubkey_bytes[ 0 ] = key_parity;
142
+
130
143
let current_pubkey = PublicKey :: from_slice ( & pubkey_bytes) ?;
131
144
let current_node_id = NodeId :: from_pubkey ( & current_pubkey) ;
132
145
node_ids. push ( current_pubkey) ;
@@ -155,7 +168,7 @@ impl<NG: Deref<Target=NetworkGraph<L>>, L: Deref> RapidGossipSync<NG, L> where L
155
168
if has_address_details {
156
169
let address_count: u8 = Readable :: read ( read_cursor) ?;
157
170
let mut node_addresses: Vec < SocketAddress > = Vec :: new ( ) ;
158
- for _ in 0 ..address_count {
171
+ for address_index in 0 ..address_count {
159
172
let current_byte_count: u8 = Readable :: read ( read_cursor) ?;
160
173
let mut address_reader = FixedLengthReader :: new ( & mut read_cursor, current_byte_count as u64 ) ;
161
174
let mut address_bytes = Vec :: new ( ) ;
@@ -164,6 +177,13 @@ impl<NG: Deref<Target=NetworkGraph<L>>, L: Deref> RapidGossipSync<NG, L> where L
164
177
let mut address_cursor = io:: Cursor :: new ( & address_bytes) ;
165
178
if let Ok ( current_address) = Readable :: read ( & mut address_cursor) {
166
179
node_addresses. push ( current_address) ;
180
+ } else {
181
+ // Do not crash to allow future socket address forwards compatibility
182
+ log_gossip ! (
183
+ self . logger,
184
+ "Failure to parse address at index {} for node ID {}: {:?}" ,
185
+ address_index, current_node_id, address_bytes
186
+ ) ;
167
187
}
168
188
}
169
189
synthetic_node_announcement. addresses = node_addresses;
0 commit comments