Skip to content

Commit 71540b5

Browse files
committed
Remove endpoint from protocol constructor.
It was only needed for creating tickets, which is used almost nowhere. If you want to create a BlobTicket, just do it manually.
1 parent 9e4478e commit 71540b5

File tree

8 files changed

+13
-31
lines changed

8 files changed

+13
-31
lines changed

examples/custom-protocol.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ async fn listen(text: Vec<String>) -> Result<()> {
100100
proto.insert_and_index(text).await?;
101101
}
102102
// Build the iroh-blobs protocol handler, which is used to download blobs.
103-
let blobs = BlobsProtocol::new(&store, endpoint.clone(), None);
103+
let blobs = BlobsProtocol::new(&store, None);
104104

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

examples/limit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ async fn setup(store: MemStore, events: EventSender) -> Result<(Router, NodeAddr
359359
.await?;
360360
let _ = endpoint.home_relay().initialized().await;
361361
let addr = endpoint.node_addr().initialized().await;
362-
let blobs = BlobsProtocol::new(&store, endpoint.clone(), Some(events));
362+
let blobs = BlobsProtocol::new(&store, Some(events));
363363
let router = Router::builder(endpoint)
364364
.accept(iroh_blobs::ALPN, blobs)
365365
.spawn();

examples/mdns-discovery.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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(), None);
71+
let blobs = BlobsProtocol::new(&store, 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(), Some(events_tx));
241+
let blobs = iroh_blobs::BlobsProtocol::new(&store, Some(events_tx));
242242
let router = iroh::protocol::Router::builder(endpoint.clone())
243243
.accept(iroh_blobs::ALPN, blobs)
244244
.spawn();

examples/transfer-collection.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl Node {
3838

3939
// this BlobsProtocol accepts connections from other nodes and serves blobs from the store
4040
// we pass None to skip subscribing to request events
41-
let blobs = BlobsProtocol::new(&store, endpoint.clone(), None);
41+
let blobs = BlobsProtocol::new(&store, None);
4242
// Routers group one or more protocols together to accept connections from other nodes,
4343
// here we're only using one, but could add more in a real world use case as needed
4444
let router = Router::builder(endpoint)

examples/transfer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ async fn main() -> anyhow::Result<()> {
1212
// We initialize an in-memory backing store for iroh-blobs
1313
let store = MemStore::new();
1414
// Then we initialize a struct that can accept blobs requests over iroh connections
15-
let blobs = BlobsProtocol::new(&store, endpoint.clone(), None);
15+
let blobs = BlobsProtocol::new(&store, None);
1616

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

src/net_protocol.rs

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,14 @@ use std::{fmt::Debug, ops::Deref, sync::Arc};
4141
use iroh::{
4242
endpoint::Connection,
4343
protocol::{AcceptError, ProtocolHandler},
44-
Endpoint, Watcher,
4544
};
4645
use tracing::error;
4746

48-
use crate::{api::Store, provider::events::EventSender, ticket::BlobTicket, HashAndFormat};
47+
use crate::{api::Store, provider::events::EventSender};
4948

5049
#[derive(Debug)]
5150
pub(crate) struct BlobsInner {
5251
pub(crate) store: Store,
53-
pub(crate) endpoint: Endpoint,
5452
pub(crate) events: EventSender,
5553
}
5654

@@ -69,11 +67,10 @@ impl Deref for BlobsProtocol {
6967
}
7068

7169
impl BlobsProtocol {
72-
pub fn new(store: &Store, endpoint: Endpoint, events: Option<EventSender>) -> Self {
70+
pub fn new(store: &Store, events: Option<EventSender>) -> Self {
7371
Self {
7472
inner: Arc::new(BlobsInner {
7573
store: store.clone(),
76-
endpoint,
7774
events: events.unwrap_or(EventSender::DEFAULT),
7875
}),
7976
}
@@ -82,21 +79,6 @@ impl BlobsProtocol {
8279
pub fn store(&self) -> &Store {
8380
&self.inner.store
8481
}
85-
86-
pub fn endpoint(&self) -> &Endpoint {
87-
&self.inner.endpoint
88-
}
89-
90-
/// Create a ticket for content on this node.
91-
///
92-
/// Note that this does not check whether the content is partially or fully available. It is
93-
/// just a convenience method to create a ticket from content and the address of this node.
94-
pub async fn ticket(&self, content: impl Into<HashAndFormat>) -> anyhow::Result<BlobTicket> {
95-
let content = content.into();
96-
let addr = self.inner.endpoint.node_addr().initialized().await;
97-
let ticket = BlobTicket::new(addr, content.hash, content.format);
98-
Ok(ticket)
99-
}
10082
}
10183

10284
impl ProtocolHandler for BlobsProtocol {

src/tests.rs

Lines changed: 5 additions & 5 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(), Some(events));
497+
let blobs = BlobsProtocol::new(&store, 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(), Some(events));
511+
let blobs = BlobsProtocol::new(&store, Some(events));
512512
let router = Router::builder(ep).accept(crate::ALPN, blobs).spawn();
513513
Ok((router, store))
514514
}
@@ -604,7 +604,7 @@ async fn node_serve_hash_seq() -> TestResult<()> {
604604
let root_tt = store.add_bytes(hash_seq).await?;
605605
let root = root_tt.hash;
606606
let endpoint = Endpoint::builder().discovery_n0().bind().await?;
607-
let blobs = crate::net_protocol::BlobsProtocol::new(&store, endpoint.clone(), None);
607+
let blobs = crate::net_protocol::BlobsProtocol::new(&store, None);
608608
let r1 = Router::builder(endpoint)
609609
.accept(crate::protocol::ALPN, blobs)
610610
.spawn();
@@ -635,7 +635,7 @@ async fn node_serve_blobs() -> TestResult<()> {
635635
tts.push(store.add_bytes(test_data(size)).await?);
636636
}
637637
let endpoint = Endpoint::builder().discovery_n0().bind().await?;
638-
let blobs = crate::net_protocol::BlobsProtocol::new(&store, endpoint.clone(), None);
638+
let blobs = crate::net_protocol::BlobsProtocol::new(&store, None);
639639
let r1 = Router::builder(endpoint)
640640
.accept(crate::protocol::ALPN, blobs)
641641
.spawn();
@@ -675,7 +675,7 @@ async fn node_smoke(store: &Store) -> TestResult<()> {
675675
let tt = store.add_bytes(b"hello world".to_vec()).temp_tag().await?;
676676
let hash = *tt.hash();
677677
let endpoint = Endpoint::builder().discovery_n0().bind().await?;
678-
let blobs = crate::net_protocol::BlobsProtocol::new(store, endpoint.clone(), None);
678+
let blobs = crate::net_protocol::BlobsProtocol::new(store, None);
679679
let r1 = Router::builder(endpoint)
680680
.accept(crate::protocol::ALPN, blobs)
681681
.spawn();

0 commit comments

Comments
 (0)