Skip to content

Commit 1e4a581

Browse files
committed
minimize diff and required changes
1 parent a9ac8e5 commit 1e4a581

File tree

7 files changed

+18
-24
lines changed

7 files changed

+18
-24
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Here is a basic example of how to set up `iroh-blobs` with `iroh`:
3434

3535
```rust,no_run
3636
use iroh::{protocol::Router, Endpoint};
37-
use iroh_blobs::{store::mem::MemStore, BlobsProtocol, provider::events::EventSender};
37+
use iroh_blobs::{store::mem::MemStore, BlobsProtocol};
3838
3939
#[tokio::main]
4040
async fn main() -> anyhow::Result<()> {
@@ -44,7 +44,7 @@ async fn main() -> anyhow::Result<()> {
4444
4545
// create a protocol handler using an in-memory blob store.
4646
let store = MemStore::new();
47-
let blobs = BlobsProtocol::new(&store, endpoint.clone(), EventSender::NONE);
47+
let blobs = BlobsProtocol::new(&store, endpoint.clone(), None);
4848
4949
// build the router
5050
let router = Router::builder(endpoint)

examples/custom-protocol.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@ use iroh::{
4848
protocol::{AcceptError, ProtocolHandler, Router},
4949
Endpoint, NodeId,
5050
};
51-
use iroh_blobs::{
52-
api::Store, provider::events::EventSender, store::mem::MemStore, BlobsProtocol, Hash,
53-
};
51+
use iroh_blobs::{api::Store, store::mem::MemStore, BlobsProtocol, Hash};
5452
mod common;
5553
use common::{get_or_generate_secret_key, setup_logging};
5654

@@ -102,7 +100,7 @@ async fn listen(text: Vec<String>) -> Result<()> {
102100
proto.insert_and_index(text).await?;
103101
}
104102
// Build the iroh-blobs protocol handler, which is used to download blobs.
105-
let blobs = BlobsProtocol::new(&store, endpoint.clone(), EventSender::NONE);
103+
let blobs = BlobsProtocol::new(&store, endpoint.clone(), None);
106104

107105
// create a router that handles both our custom protocol and the iroh-blobs protocol.
108106
let node = Router::builder(endpoint)

examples/mdns-discovery.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use clap::{Parser, Subcommand};
1818
use iroh::{
1919
discovery::mdns::MdnsDiscovery, protocol::Router, Endpoint, PublicKey, RelayMode, SecretKey,
2020
};
21-
use iroh_blobs::{provider::events::EventSender, store::mem::MemStore, BlobsProtocol, Hash};
21+
use iroh_blobs::{store::mem::MemStore, BlobsProtocol, Hash};
2222

2323
mod common;
2424
use common::{get_or_generate_secret_key, setup_logging};
@@ -68,7 +68,7 @@ async fn accept(path: &Path) -> Result<()> {
6868
.await?;
6969
let builder = Router::builder(endpoint.clone());
7070
let store = MemStore::new();
71-
let blobs = BlobsProtocol::new(&store, endpoint.clone(), EventSender::NONE);
71+
let blobs = BlobsProtocol::new(&store, endpoint.clone(), None);
7272
let builder = builder.accept(iroh_blobs::ALPN, blobs.clone());
7373
let node = builder.spawn();
7474

examples/random_store.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ async fn provide(args: ProvideArgs) -> anyhow::Result<()> {
238238
.bind()
239239
.await?;
240240
let (dump_task, events_tx) = dump_provider_events(args.allow_push);
241-
let blobs = iroh_blobs::BlobsProtocol::new(&store, endpoint.clone(), events_tx);
241+
let blobs = iroh_blobs::BlobsProtocol::new(&store, endpoint.clone(), Some(events_tx));
242242
let router = iroh::protocol::Router::builder(endpoint.clone())
243243
.accept(iroh_blobs::ALPN, blobs)
244244
.spawn();

examples/transfer.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
use std::path::PathBuf;
22

33
use iroh::{protocol::Router, Endpoint};
4-
use iroh_blobs::{
5-
provider::events::EventSender, store::mem::MemStore, ticket::BlobTicket, BlobsProtocol,
6-
};
4+
use iroh_blobs::{store::mem::MemStore, ticket::BlobTicket, BlobsProtocol};
75

86
#[tokio::main]
97
async fn main() -> anyhow::Result<()> {
@@ -14,7 +12,7 @@ async fn main() -> anyhow::Result<()> {
1412
// We initialize an in-memory backing store for iroh-blobs
1513
let store = MemStore::new();
1614
// Then we initialize a struct that can accept blobs requests over iroh connections
17-
let blobs = BlobsProtocol::new(&store, endpoint.clone(), EventSender::NONE);
15+
let blobs = BlobsProtocol::new(&store, endpoint.clone(), None);
1816

1917
// Grab all passed in arguments, the first one is the binary itself, so we skip it.
2018
let args: Vec<String> = std::env::args().skip(1).collect();

src/net_protocol.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//! ```rust
88
//! # async fn example() -> anyhow::Result<()> {
99
//! use iroh::{protocol::Router, Endpoint};
10-
//! use iroh_blobs::{provider::events::EventSender, store, BlobsProtocol};
10+
//! use iroh_blobs::{store, BlobsProtocol};
1111
//!
1212
//! // create a store
1313
//! let store = store::fs::FsStore::load("blobs").await?;
@@ -19,7 +19,7 @@
1919
//! let endpoint = Endpoint::builder().discovery_n0().bind().await?;
2020
//!
2121
//! // create a blobs protocol handler
22-
//! let blobs = BlobsProtocol::new(&store, endpoint.clone(), EventSender::NONE);
22+
//! let blobs = BlobsProtocol::new(&store, endpoint.clone(), None);
2323
//!
2424
//! // create a router and add the blobs protocol handler
2525
//! let router = Router::builder(endpoint)
@@ -69,12 +69,12 @@ impl Deref for BlobsProtocol {
6969
}
7070

7171
impl BlobsProtocol {
72-
pub fn new(store: &Store, endpoint: Endpoint, events: EventSender) -> Self {
72+
pub fn new(store: &Store, endpoint: Endpoint, events: Option<EventSender>) -> Self {
7373
Self {
7474
inner: Arc::new(BlobsInner {
7575
store: store.clone(),
7676
endpoint,
77-
events,
77+
events: events.unwrap_or(EventSender::NONE),
7878
}),
7979
}
8080
}

src/tests.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ pub async fn node_test_setup_with_events_fs(
494494
) -> TestResult<(Router, FsStore, PathBuf)> {
495495
let store = crate::store::fs::FsStore::load(&db_path).await?;
496496
let ep = Endpoint::builder().bind().await?;
497-
let blobs = BlobsProtocol::new(&store, ep.clone(), events);
497+
let blobs = BlobsProtocol::new(&store, ep.clone(), Some(events));
498498
let router = Router::builder(ep).accept(crate::ALPN, blobs).spawn();
499499
Ok((router, store, db_path))
500500
}
@@ -508,7 +508,7 @@ pub async fn node_test_setup_with_events_mem(
508508
) -> TestResult<(Router, MemStore)> {
509509
let store = MemStore::new();
510510
let ep = Endpoint::builder().bind().await?;
511-
let blobs = BlobsProtocol::new(&store, ep.clone(), events);
511+
let blobs = BlobsProtocol::new(&store, ep.clone(), Some(events));
512512
let router = Router::builder(ep).accept(crate::ALPN, blobs).spawn();
513513
Ok((router, store))
514514
}
@@ -605,8 +605,7 @@ async fn node_serve_hash_seq() -> TestResult<()> {
605605
let root_tt = store.add_bytes(hash_seq).await?;
606606
let root = root_tt.hash;
607607
let endpoint = Endpoint::builder().discovery_n0().bind().await?;
608-
let blobs =
609-
crate::net_protocol::BlobsProtocol::new(&store, endpoint.clone(), EventSender::NONE);
608+
let blobs = crate::net_protocol::BlobsProtocol::new(&store, endpoint.clone(), None);
610609
let r1 = Router::builder(endpoint)
611610
.accept(crate::protocol::ALPN, blobs)
612611
.spawn();
@@ -637,8 +636,7 @@ async fn node_serve_blobs() -> TestResult<()> {
637636
tts.push(store.add_bytes(test_data(size)).await?);
638637
}
639638
let endpoint = Endpoint::builder().discovery_n0().bind().await?;
640-
let blobs =
641-
crate::net_protocol::BlobsProtocol::new(&store, endpoint.clone(), EventSender::NONE);
639+
let blobs = crate::net_protocol::BlobsProtocol::new(&store, endpoint.clone(), None);
642640
let r1 = Router::builder(endpoint)
643641
.accept(crate::protocol::ALPN, blobs)
644642
.spawn();
@@ -680,7 +678,7 @@ async fn node_smoke(store: &Store) -> TestResult<()> {
680678
let tt = store.add_bytes(b"hello world".to_vec()).temp_tag().await?;
681679
let hash = *tt.hash();
682680
let endpoint = Endpoint::builder().discovery_n0().bind().await?;
683-
let blobs = crate::net_protocol::BlobsProtocol::new(store, endpoint.clone(), EventSender::NONE);
681+
let blobs = crate::net_protocol::BlobsProtocol::new(store, endpoint.clone(), None);
684682
let r1 = Router::builder(endpoint)
685683
.accept(crate::protocol::ALPN, blobs)
686684
.spawn();

0 commit comments

Comments
 (0)