Skip to content

Commit 4f21cc6

Browse files
fix incorrectly set edge weight upon new transport creation (#1946)
* fix incorrectly set link weight upon new transport creation * prettier debug print for LinkEdgeWeight
1 parent a4fead7 commit 4f21cc6

File tree

2 files changed

+29
-11
lines changed

2 files changed

+29
-11
lines changed

zenoh/src/net/protocol/linkstate.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// Contributors:
1212
// ZettaScale Zenoh Team, <[email protected]>
1313
//
14-
use std::{collections::HashMap, num::NonZeroU16};
14+
use std::{collections::HashMap, fmt::Debug, num::NonZeroU16};
1515

1616
use zenoh_config::TransportWeight;
1717
use zenoh_protocol::core::{Locator, WhatAmI, ZenohIdProto};
@@ -51,9 +51,18 @@ pub(crate) struct LinkState {
5151
pub(crate) link_weights: Option<Vec<u16>>,
5252
}
5353

54-
#[derive(Default, Copy, Debug, Clone, PartialEq, Eq)]
54+
#[derive(Default, Copy, Clone, PartialEq, Eq)]
5555
pub(crate) struct LinkEdgeWeight(pub(crate) Option<NonZeroU16>);
5656

57+
impl Debug for LinkEdgeWeight {
58+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
59+
match &self.0 {
60+
Some(w) => w.fmt(f),
61+
None => self.0.fmt(f),
62+
}
63+
}
64+
}
65+
5766
impl LinkEdgeWeight {
5867
const DEFAULT_LINK_WEIGHT: u16 = 100;
5968

zenoh/src/net/protocol/network.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,12 @@ impl Network {
199199
}
200200

201201
self.link_weights = link_weights;
202+
tracing::info!(
203+
"{} Update link weights to {:?}",
204+
&self.name,
205+
&self.link_weights
206+
);
207+
202208
if dests_to_update.is_empty()
203209
|| !(self.full_linkstate || self.router_peers_failover_brokering)
204210
{
@@ -411,11 +417,8 @@ impl Network {
411417
}))
412418
}
413419

414-
fn get_default_link_weight_to(&self, idx: NodeIndex) -> LinkEdgeWeight {
415-
self.link_weights
416-
.get(&self.graph[idx].zid)
417-
.copied()
418-
.unwrap_or_default()
420+
fn get_default_link_weight_to(&self, zid: &ZenohIdProto) -> LinkEdgeWeight {
421+
self.link_weights.get(zid).copied().unwrap_or_default()
419422
}
420423

421424
fn update_edge(&mut self, idx1: NodeIndex, idx2: NodeIndex) {
@@ -837,17 +840,23 @@ impl Network {
837840
}
838841
};
839842

840-
let link_weight = self.get_default_link_weight_to(idx);
843+
let link_weight = self.get_default_link_weight_to(&zid);
844+
self.graph[self.idx].links.insert(zid, link_weight);
845+
self.graph[self.idx].sn += 1;
846+
841847
if self.full_linkstate
842848
&& self.graph[idx]
843849
.links
844850
.contains_key(&self.graph[self.idx].zid)
845851
{
846852
self.update_edge(self.idx, idx);
847-
tracing::trace!("Update edge (link) {} {}", self.graph[self.idx].zid, zid);
853+
tracing::trace!(
854+
"{} Update edge (link) {} {}",
855+
&self.name,
856+
self.graph[self.idx].zid,
857+
zid
858+
);
848859
}
849-
self.graph[self.idx].links.insert(zid, link_weight);
850-
self.graph[self.idx].sn += 1;
851860

852861
// Send updated self linkstate on all existing links except new one
853862
self.links

0 commit comments

Comments
 (0)