Skip to content

Commit

Permalink
refactor(iroh-net): Rename CallMeMaybe field (#2012)
Browse files Browse the repository at this point in the history
## Description

This reads a bit more natural.  It does not affect the on-the-wire
format.

## Notes & open questions

Split off from #1984

## Change checklist

- [x] Self-review.
  • Loading branch information
flub authored Feb 8, 2024
1 parent 8e60d1b commit c0637d0
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
14 changes: 7 additions & 7 deletions iroh-net/src/disco.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ impl Display for SendAddr {
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct CallMeMaybe {
/// What the peer believes its endpoints are.
pub my_number: Vec<SocketAddr>,
pub my_numbers: Vec<SocketAddr>,
}

impl Ping {
Expand Down Expand Up @@ -301,24 +301,24 @@ impl CallMeMaybe {

let num_entries = p.len() / EP_LENGTH;
let mut m = CallMeMaybe {
my_number: Vec::with_capacity(num_entries),
my_numbers: Vec::with_capacity(num_entries),
};

for chunk in p.chunks_exact(EP_LENGTH) {
let src = socket_addr_from_bytes(chunk);
m.my_number.push(src);
m.my_numbers.push(src);
}

Ok(m)
}

fn as_bytes(&self) -> Vec<u8> {
let header = msg_header(MessageType::CallMeMaybe, V0);
let mut out = vec![0u8; HEADER_LEN + self.my_number.len() * EP_LENGTH];
let mut out = vec![0u8; HEADER_LEN + self.my_numbers.len() * EP_LENGTH];
out[..HEADER_LEN].copy_from_slice(&header);

for (m, chunk) in self
.my_number
.my_numbers
.iter()
.zip(out[HEADER_LEN..].chunks_exact_mut(EP_LENGTH))
{
Expand Down Expand Up @@ -425,13 +425,13 @@ mod tests {
},
Test {
name: "call_me_maybe",
m: Message::CallMeMaybe(CallMeMaybe { my_number: Vec::new() }),
m: Message::CallMeMaybe(CallMeMaybe { my_numbers: Vec::new() }),
want: "03 00",
},
Test {
name: "call_me_maybe_endpoints",
m: Message::CallMeMaybe(CallMeMaybe {
my_number: vec![
my_numbers: vec![
"1.2.3.4:567".parse().unwrap(),
"[2001::3456]:789".parse().unwrap(),
],
Expand Down
4 changes: 2 additions & 2 deletions iroh-net/src/magicsock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2385,8 +2385,8 @@ impl DiscoveredEndpoints {
}

fn to_call_me_maybe_message(&self) -> disco::CallMeMaybe {
let my_number = self.last_endpoints.iter().map(|ep| ep.addr).collect();
disco::CallMeMaybe { my_number }
let my_numbers = self.last_endpoints.iter().map(|ep| ep.addr).collect();
disco::CallMeMaybe { my_numbers }
}

fn log_endpoint_change(&self) {
Expand Down
4 changes: 2 additions & 2 deletions iroh-net/src/magicsock/peer_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ impl NodeMapInner {
fn handle_call_me_maybe(&mut self, sender: PublicKey, cm: CallMeMaybe) -> Vec<PingAction> {
let ep_id = EndpointId::NodeKey(&sender);
if let Some(id) = self.get_id(ep_id.clone()) {
for number in &cm.my_number {
for number in &cm.my_numbers {
// ensure the new addrs are known
self.set_endpoint_for_ip_port(*number, id);
}
Expand All @@ -406,7 +406,7 @@ impl NodeMapInner {
vec![]
}
Some(ep) => {
debug!(endpoints = ?cm.my_number, "received call-me-maybe");
debug!(endpoints = ?cm.my_numbers, "received call-me-maybe");

ep.handle_call_me_maybe(cm)
}
Expand Down
2 changes: 1 addition & 1 deletion iroh-net/src/magicsock/peer_map/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ impl Endpoint {
let mut new_eps = Vec::new();
let mut call_me_maybe_eps = HashSet::new();

for ep in &m.my_number {
for ep in &m.my_numbers {
if let IpAddr::V6(ip) = ep.ip() {
if is_unicast_link_local(ip) {
// We send these out, but ignore them for now.
Expand Down

0 comments on commit c0637d0

Please sign in to comment.