Skip to content

Commit

Permalink
parse interface announce message
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed May 21, 2024
1 parent 0aab690 commit 170f612
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
45 changes: 44 additions & 1 deletion iroh-net/src/net/interfaces/bsd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ pub enum WireMessage {
Interface(InterfaceMessage),
InterfaceAddr(InterfaceAddrMessage),
InterfaceMulticastAddr(InterfaceMulticastAddrMessage),
InterfaceAnnounce(InterfaceAnnounceMessage),
}

/// Safely convert a some bytes from a slice into a u16.
Expand Down Expand Up @@ -374,7 +375,34 @@ impl WireFormat {
Ok(Some(WireMessage::InterfaceMulticastAddr(m)))
}
MessageType::InterfaceAnnounce => {
todo!()
if data.len() < self.body_off {
return Err(RouteError::MessageTooShort);
}
let l = u16_from_ne_range(data, ..2)?;
if data.len() < l as usize {
return Err(RouteError::InvalidMessage);
}

let mut name = String::new();
for i in 0..16 {
if data[6 + i] != 0 {
continue;
}
name = std::str::from_utf8(&data[6..6 + i])
.map_err(|_| RouteError::InvalidAddress)?
.to_string();
break;
}

let m = InterfaceAnnounceMessage {
version: data[2] as _,
r#type: data[3] as _,
index: u16_from_ne_range(data, 4..6)? as _,
what: u16_from_ne_range(data, 22..24)? as _,
name,
};

Ok(Some(WireMessage::InterfaceAnnounce(m)))
}
}
}
Expand Down Expand Up @@ -545,6 +573,21 @@ pub struct InterfaceMulticastAddrMessage {
pub addrs: Vec<Addr>,
}

/// Interface announce message.
#[derive(Debug)]
pub struct InterfaceAnnounceMessage {
/// message version
pub version: isize,
/// message type
pub r#type: isize,
/// interface index
pub index: isize,
/// interface name
pub name: String,
/// what type of announcement
pub what: isize,
}

/// Represents a type of routing information base.
type RIBType = i32;

Expand Down
1 change: 1 addition & 0 deletions iroh-net/src/net/netmon/bsd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ pub(super) fn is_interesting_message(msg: &WireMessage) -> bool {

true
}
WireMessage::InterfaceAnnounce(_) => false,
}
}

Expand Down

0 comments on commit 170f612

Please sign in to comment.