Skip to content

Commit cce3917

Browse files
committed
f net_graph
1 parent 76c3203 commit cce3917

File tree

2 files changed

+21
-51
lines changed

2 files changed

+21
-51
lines changed

lightning/src/ln/msgs.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,17 @@ impl Readable for Result<NetAddress, u8> {
482482
}
483483
}
484484

485+
impl Readable for NetAddress {
486+
fn read<R: Read>(reader: &mut R) -> Result<NetAddress, DecodeError> {
487+
match Readable::read(reader) {
488+
Ok(Ok(res)) => Ok(res),
489+
Ok(Err(_)) => Err(DecodeError::UnknownVersion),
490+
Err(e) => Err(e),
491+
}
492+
}
493+
}
494+
495+
485496
/// The unsigned part of a node_announcement
486497
#[derive(Clone, Debug, PartialEq)]
487498
pub struct UnsignedNodeAnnouncement {

lightning/src/routing/network_graph.rs

Lines changed: 10 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -546,55 +546,16 @@ pub struct NodeAnnouncementInfo {
546546
pub announcement_message: Option<NodeAnnouncement>
547547
}
548548

549-
impl Writeable for NodeAnnouncementInfo {
550-
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), ::std::io::Error> {
551-
(self.addresses.len() as u64).write(writer)?;
552-
for ref addr in &self.addresses {
553-
addr.write(writer)?;
554-
}
555-
write_tlv_fields!(writer, {
556-
(0, self.features),
557-
(2, self.last_update),
558-
(4, self.rgb),
559-
(6, self.alias)
560-
}, { (8, self.announcement_message) });
561-
Ok(())
562-
}
563-
}
564-
565-
impl Readable for NodeAnnouncementInfo {
566-
fn read<R: ::std::io::Read>(reader: &mut R) -> Result<NodeAnnouncementInfo, DecodeError> {
567-
let addresses_count: u64 = Readable::read(reader)?;
568-
let mut addresses = Vec::with_capacity(cmp::min(addresses_count, MAX_ALLOC_SIZE / 40) as usize);
569-
for _ in 0..addresses_count {
570-
match Readable::read(reader) {
571-
Ok(Ok(addr)) => { addresses.push(addr); },
572-
Ok(Err(_)) => return Err(DecodeError::InvalidValue),
573-
Err(DecodeError::ShortRead) => return Err(DecodeError::BadLengthDescriptor),
574-
_ => unreachable!(),
575-
}
576-
}
577-
let mut features = NodeFeatures::empty();
578-
let mut last_update = 0;
579-
let mut rgb = [0; 3];
580-
let mut alias = [0; 32];
581-
let mut announcement_message = None;
582-
read_tlv_fields!(reader, {
583-
(0, features),
584-
(2, last_update),
585-
(4, rgb),
586-
(6, alias)
587-
}, { (8, announcement_message) });
588-
Ok(NodeAnnouncementInfo {
589-
features,
590-
last_update,
591-
rgb,
592-
alias,
593-
addresses,
594-
announcement_message
595-
})
596-
}
597-
}
549+
impl_writeable_tlv_based!(NodeAnnouncementInfo, {
550+
(0, features),
551+
(2, last_update),
552+
(4, rgb),
553+
(6, alias),
554+
}, {
555+
(8, announcement_message),
556+
}, {
557+
(10, addresses),
558+
});
598559

599560
#[derive(Clone, Debug, PartialEq)]
600561
/// Details about a node in the network, known from the network announcement.
@@ -626,8 +587,6 @@ impl_writeable_tlv_based!(NodeInfo, {}, {
626587
(4, channels),
627588
});
628589

629-
const MAX_ALLOC_SIZE: u64 = 64*1024;
630-
631590
const SERIALIZATION_VERSION: u8 = 1;
632591
const MIN_SERIALIZATION_VERSION: u8 = 1;
633592

0 commit comments

Comments
 (0)