@@ -31,7 +31,7 @@ use crate::routing::utxo::{self, UtxoLookup, UtxoResolver};
31
31
use crate :: util:: indexed_map:: { Entry as IndexedMapEntry , IndexedMap } ;
32
32
use crate :: util:: logger:: { Level , Logger } ;
33
33
use crate :: util:: scid_utils:: { block_from_scid, scid_from_parts, MAX_SCID_BLOCK } ;
34
- use crate :: util:: ser:: { MaybeReadable , Readable , ReadableArgs , Writeable , Writer } ;
34
+ use crate :: util:: ser:: { MaybeReadable , Readable , ReadableArgs , RequiredWrapper , Writeable , Writer } ;
35
35
use crate :: util:: string:: PrintableString ;
36
36
37
37
use crate :: io;
@@ -238,17 +238,67 @@ pub enum NetworkUpdate {
238
238
}
239
239
}
240
240
241
- impl_writeable_tlv_based_enum_upgradable ! ( NetworkUpdate ,
242
- // 0 was used for channel updates in LDK versions 0.0.123 and below.
243
- ( 2 , ChannelFailure ) => {
244
- ( 0 , short_channel_id, required) ,
245
- ( 2 , is_permanent, required) ,
246
- } ,
247
- ( 4 , NodeFailure ) => {
248
- ( 0 , node_id, required) ,
249
- ( 2 , is_permanent, required) ,
250
- } ,
251
- ) ;
241
+ impl Writeable for NetworkUpdate {
242
+ fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , io:: Error > {
243
+ match self {
244
+ Self :: ChannelFailure { short_channel_id, is_permanent } => {
245
+ 2u8 . write ( writer) ?;
246
+ write_tlv_fields ! ( writer, {
247
+ ( 0 , short_channel_id, required) ,
248
+ ( 2 , is_permanent, required) ,
249
+ } ) ;
250
+ } ,
251
+ Self :: NodeFailure { node_id, is_permanent } => {
252
+ 4u8 . write ( writer) ?;
253
+ write_tlv_fields ! ( writer, {
254
+ ( 0 , node_id, required) ,
255
+ ( 2 , is_permanent, required) ,
256
+ } ) ;
257
+ }
258
+ }
259
+ Ok ( ( ) )
260
+ }
261
+ }
262
+
263
+ impl MaybeReadable for NetworkUpdate {
264
+ fn read < R : io:: Read > ( reader : & mut R ) -> Result < Option < Self > , DecodeError > {
265
+ let id: u8 = Readable :: read ( reader) ?;
266
+ match id {
267
+ 0 => {
268
+ let mut msg: RequiredWrapper < ChannelUpdate > = RequiredWrapper ( None ) ;
269
+ read_tlv_fields ! ( reader, {
270
+ ( 0 , msg, required) ,
271
+ } ) ;
272
+ Ok ( Some ( Self :: ChannelFailure {
273
+ short_channel_id : msg. 0 . unwrap ( ) . contents . short_channel_id ,
274
+ is_permanent : false
275
+ } ) )
276
+ } ,
277
+ 2 => {
278
+ _init_and_read_len_prefixed_tlv_fields ! ( reader, {
279
+ ( 0 , short_channel_id, required) ,
280
+ ( 2 , is_permanent, required) ,
281
+ } ) ;
282
+ Ok ( Some ( Self :: ChannelFailure {
283
+ short_channel_id : short_channel_id. 0 . unwrap ( ) ,
284
+ is_permanent : is_permanent. 0 . unwrap ( ) ,
285
+ } ) )
286
+ } ,
287
+ 4 => {
288
+ _init_and_read_len_prefixed_tlv_fields ! ( reader, {
289
+ ( 0 , node_id, required) ,
290
+ ( 2 , is_permanent, required) ,
291
+ } ) ;
292
+ Ok ( Some ( Self :: NodeFailure {
293
+ node_id : node_id. 0 . unwrap ( ) ,
294
+ is_permanent : is_permanent. 0 . unwrap ( ) ,
295
+ } ) )
296
+ }
297
+ t if t % 2 == 0 => Err ( DecodeError :: UnknownRequiredFeature ) ,
298
+ _ => Ok ( None ) ,
299
+ }
300
+ }
301
+ }
252
302
253
303
/// Receives and validates network updates from peers,
254
304
/// stores authentic and relevant data as a network graph.
0 commit comments