+/// Details about a node in the network, known from the network announcement.
+pub struct NodeInfo {
+ /// All valid channels a node has announced
+ pub channels: Vec<u64>,
+ /// Lowest fees enabling routing via any of the enabled, known channels to a node.
+ /// The two fields (flat and proportional fee) are independent,
+ /// meaning they don't have to refer to the same channel.
+ pub lowest_inbound_channel_fees: Option<RoutingFees>,
+ /// More information about a node from node_announcement.
+ /// Optional because we store a Node entry after learning about it from
+ /// a channel announcement, but before receiving a node announcement.
+ pub announcement_info: Option<NodeAnnouncementInfo>
+}
+
+impl fmt::Display for NodeInfo {
+ fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
+ write!(f, "lowest_inbound_channel_fees: {:?}, channels: {:?}, announcement_info: {:?}",
+ self.lowest_inbound_channel_fees, &self.channels[..], self.announcement_info)?;
+ Ok(())
+ }
+}
+
+impl Writeable for NodeInfo {
+ fn write<W: Writer>(&self, writer: &mut W) -> Result<(), ::std::io::Error> {
+ (self.channels.len() as u64).write(writer)?;
+ for ref chan in self.channels.iter() {
+ chan.write(writer)?;
+ }
+ self.lowest_inbound_channel_fees.write(writer)?;
+ self.announcement_info.write(writer)?;
+ Ok(())
+ }
+}
+
+const MAX_ALLOC_SIZE: u64 = 64*1024;
+
+impl Readable for NodeInfo {
+ fn read<R: ::std::io::Read>(reader: &mut R) -> Result<NodeInfo, DecodeError> {
+ let channels_count: u64 = Readable::read(reader)?;
+ let mut channels = Vec::with_capacity(cmp::min(channels_count, MAX_ALLOC_SIZE / 8) as usize);
+ for _ in 0..channels_count {
+ channels.push(Readable::read(reader)?);
+ }
+ let lowest_inbound_channel_fees = Readable::read(reader)?;
+ let announcement_info = Readable::read(reader)?;
+ Ok(NodeInfo {
+ channels,
+ lowest_inbound_channel_fees,
+ announcement_info,
+ })
+ }