Skip to content

Commit

Permalink
adapt after rebase on main
Browse files Browse the repository at this point in the history
  • Loading branch information
Frando committed Aug 7, 2023
1 parent 6a42b69 commit 7c6cb35
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 58 deletions.
22 changes: 4 additions & 18 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions iroh-bytes/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ impl From<[u8; 32]> for Hash {
}
}

impl From<Hash> for [u8; 32]{
fn from(value: Hash) -> Self {
*value.as_bytes()
}
}

impl From<&[u8; 32]> for Hash {
fn from(value: &[u8; 32]) -> Self {
Hash(blake3::Hash::from(*value))
Expand Down
4 changes: 2 additions & 2 deletions iroh-gossip/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "iroh-gossip"
version = "0.4.1"
version = "0.5.1"
edition = "2021"
readme = "README.md"
description = "gossip messages over broadcast trees"
Expand All @@ -11,7 +11,7 @@ repository = "https://github.com/n0-computer/iroh-sync"
[dependencies]
# proto dependencies (required)
anyhow = { version = "1", features = ["backtrace"] }
blake3 = "1.3.3"
blake3 = { package = "iroh-blake3", version = "1.4.3"}
bytes = { version = "1.4.0", features = ["serde"] }
data-encoding = "2.4.0"
derive_more = { version = "1.0.0-beta.1", features = ["add", "debug", "display", "from", "try_into"] }
Expand Down
2 changes: 1 addition & 1 deletion iroh-gossip/src/proto/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ macro_rules! idbytes_impls {
}
}

impl<T: Into<[u8; 32]>> From<T> for $ty {
impl<T: Into<[u8; 32]>> std::convert::From<T> for $ty {
fn from(value: T) -> Self {
Self::from_bytes(value.into())
}
Expand Down
6 changes: 3 additions & 3 deletions iroh-sync/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "iroh-sync"
version = "0.1.0"
version = "0.5.1"
edition = "2021"
readme = "README.md"
description = "Iroh sync"
Expand All @@ -10,7 +10,7 @@ repository = "https://github.com/n0-computer/iroh"

[dependencies]
anyhow = "1.0.71"
blake3 = "1.3.3"
blake3 = { package = "iroh-blake3", version = "1.4.3"}
crossbeam = "0.8.2"
derive_more = { version = "1.0.0-beta.1", features = ["debug", "display", "from", "try_into"] }
ed25519-dalek = { version = "2.0.0-rc.2", features = ["serde", "rand_core"] }
Expand All @@ -35,4 +35,4 @@ tempfile = "3.4"

[features]
default = ["fs-store"]
fs-store = ["redb", "ouroboros"]
fs-store = ["redb", "ouroboros"]
4 changes: 2 additions & 2 deletions iroh/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ iroh-bytes = { version = "0.5.0", path = "../iroh-bytes" }
iroh-metrics = { version = "0.5.0", path = "../iroh-metrics", optional = true }
num_cpus = { version = "1.15.0" }
portable-atomic = "1"
iroh-sync = { path = "../iroh-sync" }
iroh-gossip = { path = "../iroh-gossip" }
iroh-sync = { version = "0.5.1", path = "../iroh-sync" }
iroh-gossip = { version = "0.5.1", path = "../iroh-gossip" }
postcard = { version = "1", default-features = false, features = ["alloc", "use-std", "experimental-derive"] }
quic-rpc = { version = "0.6", default-features = false, features = ["flume-transport"] }
quinn = "0.10"
Expand Down
38 changes: 13 additions & 25 deletions iroh/examples/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ use iroh::sync::{
};
use iroh_bytes::util::runtime;
use iroh_gossip::{
net::{GossipHandle, GOSSIP_ALPN},
net::{Gossip, GOSSIP_ALPN},
proto::TopicId,
};
use iroh_metrics::{
core::{Counter, Metric},
struct_iterable::Iterable,
};
use iroh_net::{
defaults::{default_derp_map, DEFAULT_DERP_STUN_PORT},
derp::{DerpMap, UseIpv4, UseIpv6},
defaults::{default_derp_map},
derp::{DerpMap},
magic_endpoint::get_alpn,
tls::Keypair,
MagicEndpoint,
Expand Down Expand Up @@ -131,7 +131,7 @@ async fn run(args: Args) -> anyhow::Result<()> {
// configure our derp map
let derp_map = match (args.no_derp, args.derp) {
(false, None) => Some(default_derp_map()),
(false, Some(url)) => Some(derp_map_from_url(url)?),
(false, Some(url)) => Some(DerpMap::from_url(url, 0)),
(true, None) => None,
(true, Some(_)) => bail!("You cannot set --no-derp and --derp at the same time"),
};
Expand All @@ -140,7 +140,7 @@ async fn run(args: Args) -> anyhow::Result<()> {
// build our magic endpoint and the gossip protocol
let (endpoint, gossip, initial_endpoints) = {
// init a cell that will hold our gossip handle to be used in endpoint callbacks
let gossip_cell: OnceCell<GossipHandle> = OnceCell::new();
let gossip_cell: OnceCell<Gossip> = OnceCell::new();
// init a channel that will emit once the initial endpoints of our local node are discovered
let (initial_endpoints_tx, mut initial_endpoints_rx) = mpsc::channel(1);
// build the magic endpoint
Expand All @@ -167,7 +167,7 @@ async fn run(args: Args) -> anyhow::Result<()> {
.await?;

// initialize the gossip protocol
let gossip = GossipHandle::from_endpoint(endpoint.clone(), Default::default());
let gossip = Gossip::from_endpoint(endpoint.clone(), Default::default());
// insert into the gossip cell to be used in the endpoint callbacks above
gossip_cell.set(gossip.clone()).unwrap();

Expand All @@ -181,7 +181,7 @@ async fn run(args: Args) -> anyhow::Result<()> {

let (topic, peers) = match &args.command {
Command::Open { doc_name } => {
let topic: TopicId = blake3::hash(doc_name.as_bytes()).into();
let topic: TopicId = iroh_bytes::Hash::new(doc_name.as_bytes()).into();
println!(
"> opening document {doc_name} as namespace {} and waiting for peers to join us...",
fmt_hash(topic.as_bytes())
Expand Down Expand Up @@ -685,7 +685,7 @@ impl FromStr for Cmd {

#[derive(Debug)]
struct State {
gossip: GossipHandle,
gossip: Gossip,
docs: DocStore,
bytes: IrohBytesHandlers,
}
Expand Down Expand Up @@ -879,25 +879,13 @@ fn parse_keypair(secret: &str) -> anyhow::Result<Keypair> {
fn fmt_derp_map(derp_map: &Option<DerpMap>) -> String {
match derp_map {
None => "None".to_string(),
Some(map) => {
let regions = map.regions.iter().map(|(id, region)| {
let nodes = region.nodes.iter().map(|node| node.url.to_string());
(*id, nodes.collect::<Vec<_>>())
});
format!("{:?}", regions.collect::<Vec<_>>())
}
Some(map) => map
.regions()
.flat_map(|region| region.nodes.iter().map(|node| node.url.to_string()))
.collect::<Vec<_>>()
.join(", "),
}
}
fn derp_map_from_url(url: Url) -> anyhow::Result<DerpMap> {
Ok(DerpMap::default_from_node(
url,
DEFAULT_DERP_STUN_PORT,
UseIpv4::TryDns,
UseIpv6::TryDns,
0,
))
}

fn canonicalize_path(path: &str) -> anyhow::Result<PathBuf> {
let path = PathBuf::from(shellexpand::tilde(&path).to_string());
Ok(path)
Expand Down
16 changes: 9 additions & 7 deletions iroh/src/sync/live.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use futures::{
FutureExt, TryFutureExt,
};
use iroh_gossip::{
net::{Event, GossipHandle},
net::{Event, Gossip},
proto::TopicId,
};
use iroh_metrics::inc;
Expand Down Expand Up @@ -64,7 +64,7 @@ pub struct LiveSync<S: store::Store> {
}

impl<S: store::Store> LiveSync<S> {
pub fn spawn(endpoint: MagicEndpoint, gossip: GossipHandle) -> Self {
pub fn spawn(endpoint: MagicEndpoint, gossip: Gossip) -> Self {
let (to_actor_tx, to_actor_rx) = mpsc::channel(CHANNEL_CAP);
let mut actor = Actor::new(endpoint, gossip, to_actor_rx);
let task = tokio::spawn(async move {
Expand Down Expand Up @@ -102,7 +102,7 @@ impl<S: store::Store> LiveSync<S> {
// Currently peers might double-sync in both directions.
struct Actor<S: store::Store> {
endpoint: MagicEndpoint,
gossip: GossipHandle,
gossip: Gossip,

docs: HashMap<TopicId, Replica<S::Instance>>,
subscription: BoxStream<'static, Result<(TopicId, Event)>>,
Expand All @@ -119,7 +119,7 @@ struct Actor<S: store::Store> {
impl<S: store::Store> Actor<S> {
pub fn new(
endpoint: MagicEndpoint,
gossip: GossipHandle,
gossip: Gossip,
to_actor_rx: mpsc::Receiver<ToActor<S>>,
) -> Self {
let (insert_tx, insert_rx) = flume::bounded(64);
Expand Down Expand Up @@ -237,13 +237,15 @@ impl<S: store::Store> Actor<S> {
}

// join gossip for the topic to receive and send message
let topic: TopicId = doc.namespace().as_bytes().into();
let topic = TopicId::from_bytes(*doc.namespace().as_bytes());
self.pending_joins.push({
let peer_ids = peer_ids.clone();
let gossip = self.gossip.clone();
async move {
let res = gossip.join(topic, peer_ids).await;
(topic, res)
match gossip.join(topic, peer_ids).await {
Err(err) => (topic, Err(err)),
Ok(fut) => (topic, fut.await),
}
}
.boxed()
});
Expand Down

0 comments on commit 7c6cb35

Please sign in to comment.