Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(iroh): Implement Clone for StaticProvider discovery #3108

Open
wants to merge 2 commits into
base: flub/discovery-arc
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion iroh/src/discovery/static_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use iroh_base::{NodeAddr, NodeId, RelayUrl};
use super::{Discovery, DiscoveryItem};

/// A static discovery implementation that allows providing info for nodes manually.
#[derive(Debug, Default)]
#[derive(Debug, Default, Clone)]
#[repr(transparent)]
pub struct StaticProvider {
nodes: Arc<RwLock<BTreeMap<NodeId, NodeInfo>>>,
Expand Down Expand Up @@ -170,3 +170,34 @@ impl Discovery for StaticProvider {
}
}
}

#[cfg(test)]
mod tests {
use iroh_base::SecretKey;
use testresult::TestResult;

use super::*;
use crate::Endpoint;

#[tokio::test]
async fn test_basic() -> TestResult {
let discovery = StaticProvider::new();

let _ep = Endpoint::builder()
.add_discovery({
let discovery = discovery.clone();
move |_| Some(discovery)
})
.bind()
.await?;

let key = SecretKey::from_bytes(&[0u8; 32]);
discovery.add_node_addr(NodeAddr {
node_id: key.public(),
relay_url: Some("https://example.com".parse()?),
direct_addresses: Default::default(),
});
flub marked this conversation as resolved.
Show resolved Hide resolved

Ok(())
}
}
Loading