Skip to content

Commit c7cab05

Browse files
committed
Merge remote-tracking branch 'origin/main' into feat/dns
2 parents d1465f7 + bd57656 commit c7cab05

File tree

17 files changed

+298
-1095
lines changed

17 files changed

+298
-1095
lines changed

iroh-bytes/src/protocol.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ use crate::Hash;
351351
pub const MAX_MESSAGE_SIZE: usize = 1024 * 1024 * 100;
352352

353353
/// The ALPN used with quic for the iroh bytes protocol.
354-
pub const ALPN: &[u8] = b"/iroh-bytes/3";
354+
pub const ALPN: &[u8] = b"/iroh-bytes/4";
355355

356356
#[derive(Deserialize, Serialize, Debug, PartialEq, Eq, Clone, From)]
357357
/// A request to the provider

iroh-net/src/magicsock.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,8 @@ impl Inner {
538538
} else {
539539
// overwrite the first byte of the packets with zero.
540540
// this makes quinn reliably and quickly ignore the packet as long as
541-
// [`quinn::EndpointConfig::grease_quic_bit`] is set to `true`.
541+
// [`quinn::EndpointConfig::grease_quic_bit`] is set to `false`
542+
// (which we always do in MagicEndpoint::bind).
542543
buf[start] = 0u8;
543544
}
544545
start = end;

iroh-sync/Cargo.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ tracing = "0.1"
3939
tokio = { version = "1", features = ["sync"] }
4040

4141
# fs-store
42-
redb = { version = "1.5.1", optional = true }
43-
ouroboros = { version = "0.18", optional = true }
42+
redb = { version = "1.5.1" }
43+
ouroboros = { version = "0.18" }
4444

4545
# net
4646
iroh-net = { version = "0.12.0", optional = true, path = "../iroh-net" }
@@ -59,7 +59,6 @@ proptest = "1.2.0"
5959
test-strategy = "0.3.1"
6060

6161
[features]
62-
default = ["net", "fs-store", "metrics"]
62+
default = ["net", "metrics"]
6363
net = ["iroh-net", "tokio/io-util", "tokio-stream", "tokio-util", "quinn", "futures"]
64-
fs-store = ["redb", "ouroboros"]
6564
metrics = ["iroh-metrics"]

iroh-sync/src/actor.rs

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use tracing::{debug, error, error_span, trace, warn};
1616

1717
use crate::{
1818
ranger::Message,
19-
store::{self, DownloadPolicy, ImportNamespaceOutcome, Query},
19+
store::{fs::StoreInstance, DownloadPolicy, ImportNamespaceOutcome, Query, Store},
2020
Author, AuthorHeads, AuthorId, Capability, CapabilityKind, ContentStatus,
2121
ContentStatusCallback, Event, NamespaceId, NamespaceSecret, PeerIdBytes, Replica, SignedEntry,
2222
SyncOutcome,
@@ -170,8 +170,8 @@ pub struct OpenState {
170170
}
171171

172172
#[derive(Debug)]
173-
struct OpenReplica<S: store::Store> {
174-
replica: Replica<S::Instance>,
173+
struct OpenReplica {
174+
replica: Replica<StoreInstance>,
175175
handles: usize,
176176
sync: bool,
177177
}
@@ -218,8 +218,8 @@ impl OpenOpts {
218218
#[allow(missing_docs)]
219219
impl SyncHandle {
220220
/// Spawn a sync actor and return a handle.
221-
pub fn spawn<S: store::Store>(
222-
store: S,
221+
pub fn spawn(
222+
store: Store,
223223
content_status_callback: Option<ContentStatusCallback>,
224224
me: String,
225225
) -> SyncHandle {
@@ -524,14 +524,14 @@ impl Drop for SyncHandle {
524524
}
525525
}
526526

527-
struct Actor<S: store::Store> {
528-
store: S,
529-
states: OpenReplicas<S>,
527+
struct Actor {
528+
store: Store,
529+
states: OpenReplicas,
530530
action_rx: flume::Receiver<Action>,
531531
content_status_callback: Option<ContentStatusCallback>,
532532
}
533533

534-
impl<S: store::Store> Actor<S> {
534+
impl Actor {
535535
fn run(&mut self) -> Result<()> {
536536
while let Ok(action) = self.action_rx.recv() {
537537
trace!(%action, "tick");
@@ -741,24 +741,22 @@ impl<S: store::Store> Actor<S> {
741741
}
742742
}
743743

744-
struct OpenReplicas<S: store::Store>(HashMap<NamespaceId, OpenReplica<S>>);
744+
#[derive(Default)]
745+
struct OpenReplicas(HashMap<NamespaceId, OpenReplica>);
745746

746-
// We need a manual impl here because the derive won't work unless we'd restrict to S: Default.
747-
impl<S: store::Store> Default for OpenReplicas<S> {
748-
fn default() -> Self {
749-
Self(Default::default())
750-
}
751-
}
752-
impl<S: store::Store> OpenReplicas<S> {
753-
fn replica(&mut self, namespace: &NamespaceId) -> Result<&mut Replica<S::Instance>> {
747+
impl OpenReplicas {
748+
fn replica(&mut self, namespace: &NamespaceId) -> Result<&mut Replica<StoreInstance>> {
754749
self.get_mut(namespace).map(|state| &mut state.replica)
755750
}
756751

757-
fn get_mut(&mut self, namespace: &NamespaceId) -> Result<&mut OpenReplica<S>> {
752+
fn get_mut(&mut self, namespace: &NamespaceId) -> Result<&mut OpenReplica> {
758753
self.0.get_mut(namespace).context("replica not open")
759754
}
760755

761-
fn replica_if_syncing(&mut self, namespace: &NamespaceId) -> Result<&mut Replica<S::Instance>> {
756+
fn replica_if_syncing(
757+
&mut self,
758+
namespace: &NamespaceId,
759+
) -> Result<&mut Replica<StoreInstance>> {
762760
let state = self.get_mut(namespace)?;
763761
if !state.sync {
764762
Err(anyhow!("sync is not enabled for replica"))
@@ -781,7 +779,7 @@ impl<S: store::Store> OpenReplicas<S> {
781779
&mut self,
782780
namespace: NamespaceId,
783781
opts: OpenOpts,
784-
open_cb: impl Fn() -> Result<Replica<S::Instance>>,
782+
open_cb: impl Fn() -> Result<Replica<StoreInstance>>,
785783
) -> Result<()> {
786784
match self.0.entry(namespace) {
787785
hash_map::Entry::Vacant(e) => {
@@ -811,7 +809,7 @@ impl<S: store::Store> OpenReplicas<S> {
811809
fn close_with(
812810
&mut self,
813811
namespace: NamespaceId,
814-
on_close: impl Fn(Replica<S::Instance>),
812+
on_close: impl Fn(Replica<StoreInstance>),
815813
) -> bool {
816814
match self.0.entry(namespace) {
817815
hash_map::Entry::Vacant(_e) => {
@@ -833,7 +831,7 @@ impl<S: store::Store> OpenReplicas<S> {
833831
}
834832
}
835833

836-
fn close_all_with(&mut self, on_close: impl Fn(Replica<S::Instance>)) {
834+
fn close_all_with(&mut self, on_close: impl Fn(Replica<StoreInstance>)) {
837835
for (_namespace, state) in self.0.drain() {
838836
on_close(state.replica)
839837
}
@@ -855,7 +853,7 @@ fn iter_to_channel<T: Send + 'static>(
855853
Ok(())
856854
}
857855

858-
fn get_author<S: store::Store>(store: &S, id: &AuthorId) -> Result<Author> {
856+
fn get_author(store: &Store, id: &AuthorId) -> Result<Author> {
859857
store.get_author(id)?.context("author not found")
860858
}
861859

@@ -866,10 +864,10 @@ fn send_reply<T>(sender: oneshot::Sender<T>, value: T) -> Result<(), SendReplyEr
866864
sender.send(value).map_err(send_reply_error)
867865
}
868866

869-
fn send_reply_with<T, S: store::Store>(
867+
fn send_reply_with<T>(
870868
sender: oneshot::Sender<Result<T>>,
871-
this: &mut Actor<S>,
872-
f: impl FnOnce(&mut Actor<S>) -> Result<T>,
869+
this: &mut Actor,
870+
f: impl FnOnce(&mut Actor) -> Result<T>,
873871
) -> Result<(), SendReplyError> {
874872
sender.send(f(this)).map_err(send_reply_error)
875873
}
@@ -880,10 +878,12 @@ fn send_reply_error<T>(_err: T) -> SendReplyError {
880878

881879
#[cfg(test)]
882880
mod tests {
881+
use crate::store;
882+
883883
use super::*;
884884
#[tokio::test]
885885
async fn open_close() -> anyhow::Result<()> {
886-
let store = store::memory::Store::default();
886+
let store = store::Store::memory();
887887
let sync = SyncHandle::spawn(store, None, "foo".into());
888888
let namespace = NamespaceSecret::new(&mut rand::rngs::OsRng {});
889889
let id = namespace.id();

iroh-sync/src/lib.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,14 @@
2121
//! sets over a network, based on recursively partitioning the sets and comparing fingerprints of
2222
//! the partitions to probabilistically detect whether a partition requires further work.
2323
//!
24-
//! The crate exposes a [generic storage interface](store::Store) with
25-
//! [in-memory](store::memory::Store) and [persistent, file-based](store::fs::Store)
26-
//! implementations. The latter makes use of [`redb`], an embedded key-value store, and persists
27-
//! the whole store with all replicas to a single file.
24+
//! The crate exposes a [generic storage interface](store::Store). There is an implementation
25+
//! of this interface, [store::fs::Store], that can be used either
26+
//! [in-memory](store::fs::Store::memory) or in
27+
//! [persistent, file-based](store::fs::Store::persistent) mode.
28+
//!
29+
//! Both modes make use of [`redb`], an embedded key-value store. When used
30+
//! in-memory, the store is backed by a `Vec<u8>`. When used in persistent mode,
31+
//! the store is backed by a single file on disk.
2832
//!
2933
//! [paper]: https://arxiv.org/abs/2212.13567
3034
#![deny(missing_docs, rustdoc::broken_intra_doc_links)]

iroh-sync/src/net/codec.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ impl BobState {
295295
mod tests {
296296
use crate::{
297297
actor::OpenOpts,
298-
store::{self, Query, Store},
298+
store::{self, fs::StoreInstance, Query, Store},
299299
AuthorId, NamespaceSecret,
300300
};
301301
use anyhow::Result;
@@ -311,7 +311,7 @@ mod tests {
311311
let alice_peer_id = SecretKey::from_bytes(&[1u8; 32]).public();
312312
let bob_peer_id = SecretKey::from_bytes(&[2u8; 32]).public();
313313

314-
let alice_store = store::memory::Store::default();
314+
let alice_store = store::Store::memory();
315315
// For now uses same author on both sides.
316316
let author = alice_store.new_author(&mut rng).unwrap();
317317

@@ -322,7 +322,7 @@ mod tests {
322322
.hash_and_insert("hello bob", &author, "from alice")
323323
.unwrap();
324324

325-
let bob_store = store::memory::Store::default();
325+
let bob_store = store::Store::memory();
326326
let mut bob_replica = bob_store.new_replica(namespace.clone()).unwrap();
327327
bob_replica
328328
.hash_and_insert("hello alice", &author, "from bob")
@@ -419,26 +419,26 @@ mod tests {
419419
#[tokio::test]
420420
async fn test_sync_many_authors_memory() -> Result<()> {
421421
let _guard = iroh_test::logging::setup();
422-
let alice_store = store::memory::Store::default();
423-
let bob_store = store::memory::Store::default();
422+
let alice_store = store::Store::memory();
423+
let bob_store = store::Store::memory();
424424
test_sync_many_authors(alice_store, bob_store).await
425425
}
426426

427427
#[tokio::test]
428428
async fn test_sync_many_authors_fs() -> Result<()> {
429429
let _guard = iroh_test::logging::setup();
430430
let tmpdir = tempfile::tempdir()?;
431-
let alice_store = store::fs::Store::new(tmpdir.path().join("a.db"))?;
432-
let bob_store = store::fs::Store::new(tmpdir.path().join("b.db"))?;
431+
let alice_store = store::fs::Store::persistent(tmpdir.path().join("a.db"))?;
432+
let bob_store = store::fs::Store::persistent(tmpdir.path().join("b.db"))?;
433433
test_sync_many_authors(alice_store, bob_store).await
434434
}
435435

436436
type Message = (AuthorId, Vec<u8>, Hash);
437437

438-
fn insert_messages<S: Store>(
438+
fn insert_messages(
439439
mut rng: impl CryptoRngCore,
440-
store: &S,
441-
replica: &mut crate::sync::Replica<S::Instance>,
440+
store: &Store,
441+
replica: &mut crate::sync::Replica<StoreInstance>,
442442
num_authors: usize,
443443
msgs_per_author: usize,
444444
key_value_fn: impl Fn(&AuthorId, usize) -> (String, String),
@@ -459,7 +459,7 @@ mod tests {
459459
res
460460
}
461461

462-
fn get_messages<S: Store>(store: &S, namespace: NamespaceId) -> Vec<Message> {
462+
fn get_messages(store: &Store, namespace: NamespaceId) -> Vec<Message> {
463463
let mut msgs = store
464464
.get_many(namespace, Query::all())
465465
.unwrap()
@@ -478,7 +478,7 @@ mod tests {
478478
msgs
479479
}
480480

481-
async fn test_sync_many_authors<S: Store>(alice_store: S, bob_store: S) -> Result<()> {
481+
async fn test_sync_many_authors(alice_store: Store, bob_store: Store) -> Result<()> {
482482
let num_messages = &[1, 2, 5, 10];
483483
let num_authors = &[2, 3, 4, 5, 10];
484484
let mut rng = rand_chacha::ChaCha12Rng::seed_from_u64(99);
@@ -616,21 +616,21 @@ mod tests {
616616
#[tokio::test]
617617
async fn test_sync_timestamps_memory() -> Result<()> {
618618
let _guard = iroh_test::logging::setup();
619-
let alice_store = store::memory::Store::default();
620-
let bob_store = store::memory::Store::default();
619+
let alice_store = store::Store::memory();
620+
let bob_store = store::Store::memory();
621621
test_sync_timestamps(alice_store, bob_store).await
622622
}
623623

624624
#[tokio::test]
625625
async fn test_sync_timestamps_fs() -> Result<()> {
626626
let _guard = iroh_test::logging::setup();
627627
let tmpdir = tempfile::tempdir()?;
628-
let alice_store = store::fs::Store::new(tmpdir.path().join("a.db"))?;
629-
let bob_store = store::fs::Store::new(tmpdir.path().join("b.db"))?;
628+
let alice_store = store::fs::Store::persistent(tmpdir.path().join("a.db"))?;
629+
let bob_store = store::fs::Store::persistent(tmpdir.path().join("b.db"))?;
630630
test_sync_timestamps(alice_store, bob_store).await
631631
}
632632

633-
async fn test_sync_timestamps<S: Store>(alice_store: S, bob_store: S) -> Result<()> {
633+
async fn test_sync_timestamps(alice_store: Store, bob_store: Store) -> Result<()> {
634634
let mut rng = rand_chacha::ChaCha12Rng::seed_from_u64(99);
635635
let alice_node_pubkey = SecretKey::generate_with_rng(&mut rng).public();
636636
let bob_node_pubkey = SecretKey::generate_with_rng(&mut rng).public();

0 commit comments

Comments
 (0)