Skip to content

Commit

Permalink
refactor: minor consistency adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
Frando committed Feb 13, 2025
1 parent b075f40 commit 761ffe7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion iroh/src/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@ mod test_dns_pkarr {
let publisher = PkarrPublisher::new(secret_key, dns_pkarr_server.pkarr_url.clone());
let data = NodeData::new(relay_url.clone(), Default::default());
// does not block, update happens in background task
publisher.update_addr_info(&data);
publisher.update_node_data(&data);
// wait until our shared state received the update from pkarr publishing
dns_pkarr_server.on_node(&node_id, PUBLISH_TIMEOUT).await?;
let resolved = resolver.lookup_node_by_id(&node_id, &origin).await?;
Expand Down
4 changes: 2 additions & 2 deletions iroh/src/discovery/pkarr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ impl PkarrPublisher {
/// Publishes the addressing information about this node to a pkarr relay.
///
/// This is a nonblocking function, the actual update is performed in the background.
pub fn update_addr_info(&self, data: &NodeData) {
pub fn update_node_data(&self, data: &NodeData) {
let mut data = data.clone();
if data.relay_url().is_some() {
// If relay url is set: only publish relay url, and no direct addrs.
Expand All @@ -206,7 +206,7 @@ impl PkarrPublisher {

impl Discovery for PkarrPublisher {
fn publish(&self, data: &NodeData) {
self.update_addr_info(data);
self.update_node_data(data);
}
}

Expand Down
7 changes: 5 additions & 2 deletions iroh/src/discovery/static_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,15 @@ impl StaticProvider {
/// Sets node addressing information for the given node ID.
///
/// This will completely overwrite any existing info for the node.
pub fn set_node_info(&self, node_info: impl Into<NodeInfo>) -> Option<NodeAddr> {
///
/// Returns the [`NodeData`] of the previous entry, or `None` if there was no previous
/// entry for this node ID.
pub fn set_node_info(&self, node_info: impl Into<NodeInfo>) -> Option<NodeData> {
let last_updated = SystemTime::now();
let NodeInfo { node_id, data } = node_info.into();
let mut guard = self.nodes.write().expect("poisoned");
let previous = guard.insert(node_id, StoredNodeInfo { data, last_updated });
previous.map(|x| NodeInfo::from_parts(node_id, x.data).into_node_addr())
previous.map(|x| x.data)
}

/// Augments node addressing information for the given node ID.
Expand Down

0 comments on commit 761ffe7

Please sign in to comment.