Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 11bade6

Browse files
committedDec 13, 2024
remove GetResponseError and rename get to fetch
1 parent 60dfdbb commit 11bade6

File tree

17 files changed

+43
-104
lines changed

17 files changed

+43
-104
lines changed
 

‎examples/fetch-fsm.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::net::SocketAddr;
77

88
use anyhow::{Context, Result};
99
use iroh_blobs::{
10-
get::fsm::{AtInitial, ConnectedNext, EndBlobNext},
10+
fetch::fsm::{AtInitial, ConnectedNext, EndBlobNext},
1111
hashseq::HashSeq,
1212
protocol::GetRequest,
1313
Hash,
@@ -63,14 +63,14 @@ async fn main() -> Result<()> {
6363
// create a request for a collection
6464
let request = GetRequest::all(hash);
6565
// create the initial state of the finite state machine
66-
let initial = iroh_blobs::get::fsm::start(connection, request);
66+
let initial = iroh_blobs::fetch::fsm::start(connection, request);
6767

6868
write_collection(initial).await
6969
} else {
7070
// create a request for a single blob
7171
let request = GetRequest::single(hash);
7272
// create the initial state of the finite state machine
73-
let initial = iroh_blobs::get::fsm::start(connection, request);
73+
let initial = iroh_blobs::fetch::fsm::start(connection, request);
7474

7575
write_blob(initial).await
7676
}
@@ -119,7 +119,7 @@ async fn write_collection(initial: AtInitial) -> Result<()> {
119119
}
120120

121121
// move to the header
122-
let header: iroh_blobs::get::fsm::AtBlobHeader = start_root.next();
122+
let header: iroh_blobs::fetch::fsm::AtBlobHeader = start_root.next();
123123
let (root_end, hashes_bytes) = header.concatenate_into_vec().await?;
124124
let next = root_end.next();
125125
let EndBlobNext::MoreChildren(at_meta) = next else {

‎examples/fetch-stream.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use bytes::Bytes;
1111
use futures_lite::{Stream, StreamExt};
1212
use genawaiter::sync::{Co, Gen};
1313
use iroh_blobs::{
14-
get::fsm::{AtInitial, BlobContentNext, ConnectedNext, EndBlobNext},
14+
fetch::fsm::{AtInitial, BlobContentNext, ConnectedNext, EndBlobNext},
1515
hashseq::HashSeq,
1616
protocol::GetRequest,
1717
Hash,
@@ -68,7 +68,7 @@ async fn main() -> Result<()> {
6868
let request = GetRequest::all(hash);
6969

7070
// create the initial state of the finite state machine
71-
let initial = iroh_blobs::get::fsm::start(connection, request);
71+
let initial = iroh_blobs::fetch::fsm::start(connection, request);
7272

7373
// create a stream that yields all the data of the blob
7474
stream_children(initial).boxed_local()
@@ -77,7 +77,7 @@ async fn main() -> Result<()> {
7777
let request = GetRequest::single(hash);
7878

7979
// create the initial state of the finite state machine
80-
let initial = iroh_blobs::get::fsm::start(connection, request);
80+
let initial = iroh_blobs::fetch::fsm::start(connection, request);
8181

8282
// create a stream that yields all the data of the blob
8383
stream_blob(initial).boxed_local()
@@ -166,7 +166,7 @@ fn stream_children(initial: AtInitial) -> impl Stream<Item = io::Result<Bytes>>
166166
));
167167
}
168168
// move to the header
169-
let header: iroh_blobs::get::fsm::AtBlobHeader = start_root.next();
169+
let header: iroh_blobs::fetch::fsm::AtBlobHeader = start_root.next();
170170
let (root_end, hashes_bytes) = header.concatenate_into_vec().await?;
171171

172172
// parse the hashes from the hash sequence bytes

‎examples/local-swarm-discovery.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ mod progress {
140140
ProgressStyle,
141141
};
142142
use iroh_blobs::{
143-
get::{db::DownloadProgress, progress::BlobProgress, Stats},
143+
fetch::{db::DownloadProgress, progress::BlobProgress, Stats},
144144
Hash,
145145
};
146146

‎src/downloader.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ use tokio_util::{either::Either, sync::CancellationToken, time::delay_queue};
5555
use tracing::{debug, error, error_span, trace, warn, Instrument};
5656

5757
use crate::{
58-
get::{db::DownloadProgress, Stats},
58+
fetch::{db::DownloadProgress, Stats},
5959
metrics::Metrics,
6060
store::Store,
6161
util::{local_pool::LocalPoolHandle, progress::ProgressSender},

‎src/downloader/get.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use iroh::endpoint;
77

88
use super::{progress::BroadcastProgressSender, DownloadKind, FailureAction, GetStartFut, Getter};
99
use crate::{
10-
get::{db::get_to_db_in_steps, error::GetError},
10+
fetch::{db::get_to_db_in_steps, GetError},
1111
store::Store,
1212
};
1313

@@ -34,7 +34,7 @@ pub(crate) struct IoGetter<S: Store> {
3434

3535
impl<S: Store> Getter for IoGetter<S> {
3636
type Connection = endpoint::Connection;
37-
type NeedsConn = crate::get::db::GetStateNeedsConn;
37+
type NeedsConn = crate::fetch::db::GetStateNeedsConn;
3838

3939
fn get(
4040
&mut self,
@@ -45,10 +45,10 @@ impl<S: Store> Getter for IoGetter<S> {
4545
async move {
4646
match get_to_db_in_steps(store, kind.hash_and_format(), progress_sender).await {
4747
Err(err) => Err(err.into()),
48-
Ok(crate::get::db::GetState::Complete(stats)) => {
48+
Ok(crate::fetch::db::GetState::Complete(stats)) => {
4949
Ok(super::GetOutput::Complete(stats))
5050
}
51-
Ok(crate::get::db::GetState::NeedsConn(needs_conn)) => {
51+
Ok(crate::fetch::db::GetState::NeedsConn(needs_conn)) => {
5252
Ok(super::GetOutput::NeedsConn(needs_conn))
5353
}
5454
}
@@ -57,7 +57,7 @@ impl<S: Store> Getter for IoGetter<S> {
5757
}
5858
}
5959

60-
impl super::NeedsConn<endpoint::Connection> for crate::get::db::GetStateNeedsConn {
60+
impl super::NeedsConn<endpoint::Connection> for crate::fetch::db::GetStateNeedsConn {
6161
fn proceed(self, conn: endpoint::Connection) -> super::GetProceedFut {
6262
async move {
6363
let res = self.proceed(conn).await;
@@ -73,13 +73,13 @@ impl super::NeedsConn<endpoint::Connection> for crate::get::db::GetStateNeedsCon
7373
}
7474

7575
#[cfg(feature = "metrics")]
76-
fn track_metrics(res: &Result<crate::get::Stats, GetError>) {
76+
fn track_metrics(res: &Result<crate::fetch::Stats, GetError>) {
7777
use iroh_metrics::{inc, inc_by};
7878

7979
use crate::metrics::Metrics;
8080
match res {
8181
Ok(stats) => {
82-
let crate::get::Stats {
82+
let crate::fetch::Stats {
8383
bytes_written,
8484
bytes_read: _,
8585
elapsed,

‎src/downloader/progress.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use parking_lot::Mutex;
1111

1212
use super::DownloadKind;
1313
use crate::{
14-
get::{db::DownloadProgress, progress::TransferState},
14+
fetch::{db::DownloadProgress, progress::TransferState},
1515
util::progress::{AsyncChannelProgressSender, IdGenerator, ProgressSendError, ProgressSender},
1616
};
1717

‎src/downloader/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use iroh::SecretKey;
1010

1111
use super::*;
1212
use crate::{
13-
get::{
13+
fetch::{
1414
db::BlobId,
1515
progress::{BlobProgress, TransferState},
1616
},

‎src/get.rs renamed to ‎src/fetch.rs

Lines changed: 2 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
//!
1414
//! [iroh-net]: https://docs.rs/iroh-net
1515
use std::{
16-
error::Error,
1716
fmt::{self, Debug},
1817
time::{Duration, Instant},
1918
};
@@ -30,8 +29,9 @@ use crate::{
3029
Hash, IROH_BLOCK_SIZE,
3130
};
3231

32+
mod error;
33+
pub use error::GetError;
3334
pub mod db;
34-
pub mod error;
3535
pub mod progress;
3636
pub mod request;
3737

@@ -882,64 +882,3 @@ pub mod fsm {
882882
ranges_iter: RangesIter,
883883
}
884884
}
885-
886-
/// Error when processing a response
887-
#[derive(thiserror::Error, Debug)]
888-
pub enum GetResponseError {
889-
/// Error when opening a stream
890-
#[error("connection: {0}")]
891-
Connection(#[from] endpoint::ConnectionError),
892-
/// Error when writing the handshake or request to the stream
893-
#[error("write: {0}")]
894-
Write(#[from] endpoint::WriteError),
895-
/// Error when reading from the stream
896-
#[error("read: {0}")]
897-
Read(#[from] endpoint::ReadError),
898-
/// Error when decoding, e.g. hash mismatch
899-
#[error("decode: {0}")]
900-
Decode(bao_tree::io::DecodeError),
901-
/// A generic error
902-
#[error("generic: {0}")]
903-
Generic(anyhow::Error),
904-
}
905-
906-
impl From<postcard::Error> for GetResponseError {
907-
fn from(cause: postcard::Error) -> Self {
908-
Self::Generic(cause.into())
909-
}
910-
}
911-
912-
impl From<bao_tree::io::DecodeError> for GetResponseError {
913-
fn from(cause: bao_tree::io::DecodeError) -> Self {
914-
match cause {
915-
bao_tree::io::DecodeError::Io(cause) => {
916-
// try to downcast to specific quinn errors
917-
if let Some(source) = cause.source() {
918-
if let Some(error) = source.downcast_ref::<endpoint::ConnectionError>() {
919-
return Self::Connection(error.clone());
920-
}
921-
if let Some(error) = source.downcast_ref::<endpoint::ReadError>() {
922-
return Self::Read(error.clone());
923-
}
924-
if let Some(error) = source.downcast_ref::<endpoint::WriteError>() {
925-
return Self::Write(error.clone());
926-
}
927-
}
928-
Self::Generic(cause.into())
929-
}
930-
_ => Self::Decode(cause),
931-
}
932-
}
933-
}
934-
935-
impl From<anyhow::Error> for GetResponseError {
936-
fn from(cause: anyhow::Error) -> Self {
937-
Self::Generic(cause)
938-
}
939-
}
940-
941-
impl From<GetResponseError> for std::io::Error {
942-
fn from(cause: GetResponseError) -> Self {
943-
Self::new(std::io::ErrorKind::Other, cause)
944-
}
945-
}

‎src/get/db.rs renamed to ‎src/fetch/db.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use tokio::sync::oneshot;
1616
use tracing::trace;
1717

1818
use crate::{
19-
get::{
19+
fetch::{
2020
self,
2121
error::GetError,
2222
fsm::{AtBlobHeader, AtEndBlob, ConnectedNext, EndBlobNext},
@@ -196,7 +196,7 @@ async fn get_blob<D: BaoStore>(
196196
let request = GetRequest::new(*hash, RangeSpecSeq::from_ranges([required_ranges]));
197197
// full request
198198
let conn = co.get_conn().await;
199-
let request = get::fsm::start(conn, request);
199+
let request = fetch::fsm::start(conn, request);
200200
// create a new bidi stream
201201
let connected = request.next().await?;
202202
// next step. we have requested a single hash, so this must be StartRoot
@@ -212,7 +212,7 @@ async fn get_blob<D: BaoStore>(
212212
None => {
213213
// full request
214214
let conn = co.get_conn().await;
215-
let request = get::fsm::start(conn, GetRequest::single(*hash));
215+
let request = fetch::fsm::start(conn, GetRequest::single(*hash));
216216
// create a new bidi stream
217217
let connected = request.next().await?;
218218
// next step. we have requested a single hash, so this must be StartRoot
@@ -454,7 +454,7 @@ async fn get_hash_seq<D: BaoStore>(
454454
log!("requesting chunks {:?}", missing_iter);
455455
let request = GetRequest::new(*root_hash, RangeSpecSeq::from_ranges(missing_iter));
456456
let conn = co.get_conn().await;
457-
let request = get::fsm::start(conn, request);
457+
let request = fetch::fsm::start(conn, request);
458458
// create a new bidi stream
459459
let connected = request.next().await?;
460460
log!("connected");
@@ -500,7 +500,7 @@ async fn get_hash_seq<D: BaoStore>(
500500
tracing::debug!("don't have collection - doing full download");
501501
// don't have the collection, so probably got nothing
502502
let conn = co.get_conn().await;
503-
let request = get::fsm::start(conn, GetRequest::all(*root_hash));
503+
let request = fetch::fsm::start(conn, GetRequest::all(*root_hash));
504504
// create a new bidi stream
505505
let connected = request.next().await?;
506506
// next step. we have requested a single hash, so this must be StartRoot

‎src/get/error.rs renamed to ‎src/fetch/error.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,9 @@ impl From<endpoint::WriteError> for GetError {
117117
}
118118
}
119119

120-
impl From<crate::get::fsm::ConnectedNextError> for GetError {
121-
fn from(value: crate::get::fsm::ConnectedNextError) -> Self {
122-
use crate::get::fsm::ConnectedNextError::*;
120+
impl From<crate::fetch::fsm::ConnectedNextError> for GetError {
121+
fn from(value: crate::fetch::fsm::ConnectedNextError) -> Self {
122+
use crate::fetch::fsm::ConnectedNextError::*;
123123
match value {
124124
e @ PostcardSer(_) => {
125125
// serialization errors indicate something wrong with the request itself
@@ -139,9 +139,9 @@ impl From<crate::get::fsm::ConnectedNextError> for GetError {
139139
}
140140
}
141141

142-
impl From<crate::get::fsm::AtBlobHeaderNextError> for GetError {
143-
fn from(value: crate::get::fsm::AtBlobHeaderNextError) -> Self {
144-
use crate::get::fsm::AtBlobHeaderNextError::*;
142+
impl From<crate::fetch::fsm::AtBlobHeaderNextError> for GetError {
143+
fn from(value: crate::fetch::fsm::AtBlobHeaderNextError) -> Self {
144+
use crate::fetch::fsm::AtBlobHeaderNextError::*;
145145
match value {
146146
e @ NotFound => {
147147
// > This indicates that the provider does not have the requested data.
@@ -157,9 +157,9 @@ impl From<crate::get::fsm::AtBlobHeaderNextError> for GetError {
157157
}
158158
}
159159

160-
impl From<crate::get::fsm::DecodeError> for GetError {
161-
fn from(value: crate::get::fsm::DecodeError) -> Self {
162-
use crate::get::fsm::DecodeError::*;
160+
impl From<crate::fetch::fsm::DecodeError> for GetError {
161+
fn from(value: crate::fetch::fsm::DecodeError) -> Self {
162+
use crate::fetch::fsm::DecodeError::*;
163163

164164
match value {
165165
e @ NotFound => GetError::NotFound(e.into()),
File renamed without changes.
File renamed without changes.

‎src/format/collection.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use iroh_io::AsyncSliceReaderExt;
88
use serde::{Deserialize, Serialize};
99

1010
use crate::{
11-
get::{fsm, Stats},
11+
fetch::{fsm, Stats},
1212
hashseq::HashSeq,
1313
store::MapEntry,
1414
util::TempTag,
@@ -142,7 +142,7 @@ impl Collection {
142142
///
143143
/// Returns the collection, a map from blob offsets to bytes, and the stats.
144144
pub async fn read_fsm_all(
145-
fsm_at_start_root: crate::get::fsm::AtStartRoot,
145+
fsm_at_start_root: crate::fetch::fsm::AtStartRoot,
146146
) -> anyhow::Result<(Collection, BTreeMap<u64, Bytes>, Stats)> {
147147
let (next, links, collection) = Self::read_fsm(fsm_at_start_root).await?;
148148
let mut res = BTreeMap::new();

‎src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub mod cli;
3434
pub mod downloader;
3535
pub mod export;
3636
pub mod format;
37-
pub mod get;
37+
pub mod fetch;
3838
pub mod hashseq;
3939
pub mod metrics;
4040
#[cfg(feature = "net_protocol")]

‎src/rpc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ use crate::{
4545
downloader::{DownloadRequest, Downloader},
4646
export::ExportProgress,
4747
format::collection::Collection,
48-
get::{
48+
fetch::{
4949
db::{DownloadProgress, GetState},
5050
Stats,
5151
},
@@ -1009,7 +1009,7 @@ impl<D: crate::store::Store> Handler<D> {
10091009
let mut remaining_nodes = nodes.len();
10101010
let mut nodes_iter = nodes.into_iter();
10111011
'outer: loop {
1012-
match crate::get::db::get_to_db_in_steps(
1012+
match crate::fetch::db::get_to_db_in_steps(
10131013
self.store().clone(),
10141014
hash_and_format,
10151015
progress.clone(),

‎src/rpc/client/blobs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ pub use crate::net_protocol::DownloadMode;
8585
use crate::{
8686
export::ExportProgress as BytesExportProgress,
8787
format::collection::{Collection, SimpleStore},
88-
get::db::DownloadProgress as BytesDownloadProgress,
88+
fetch::db::DownloadProgress as BytesDownloadProgress,
8989
net_protocol::BlobDownloadRequest,
9090
rpc::proto::RpcService,
9191
store::{BaoBlobSize, ConsistencyCheckProgress, ExportFormat, ExportMode, ValidateProgress},
@@ -675,7 +675,7 @@ pub struct DownloadOutcome {
675675
/// The size of the data we downloaded from the network
676676
pub downloaded_size: u64,
677677
/// Statistics about the download
678-
pub stats: crate::get::Stats,
678+
pub stats: crate::fetch::Stats,
679679
}
680680

681681
/// Progress stream for blob download operations.

‎src/rpc/proto/blobs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use super::{RpcError, RpcResult, RpcService};
1010
use crate::{
1111
export::ExportProgress,
1212
format::collection::Collection,
13-
get::db::DownloadProgress,
13+
fetch::db::DownloadProgress,
1414
net_protocol::{BatchId, BlobDownloadRequest},
1515
provider::{AddProgress, BatchAddPathProgress},
1616
rpc::client::blobs::{BlobInfo, BlobStatus, IncompleteBlobInfo, ReadAtLen, WrapOption},

0 commit comments

Comments
 (0)
Please sign in to comment.