Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(get-ticket): Contact provider on all listening addrs #893

Merged
merged 2 commits into from
Mar 29, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 41 additions & 27 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -477,38 +477,28 @@ async fn main_impl() -> Result<()> {
}
let token = AuthToken::from_str(&auth_token)
.context("Wrong format for authentication token")?;
let get = GetInteractive::Hash {
hash: *hash.as_hash(),
opts,
token,
};
tokio::select! {
biased;
res = get_interactive(*hash.as_hash(), opts, token, out) => {
res
}
res = get_interactive(get, out) => res,
_ = tokio::signal::ctrl_c() => {
println!("Ending transfer early...");
Ok(())
}
}
}
Commands::GetTicket { out, ticket } => {
let Ticket {
hash,
peer,
addrs,
token,
} = ticket;
let addr = addrs
.get(0)
.copied()
.context("missing SocketAddr in ticket")?;
let opts = get::Options {
addr,
peer_id: Some(peer),
let get = GetInteractive::Ticket {
ticket,
keylog: cli.keylog,
};
tokio::select! {
biased;
res = get_interactive(hash, opts, token, out) => {
res
}
res = get_interactive(get, out) => res,
_ = tokio::signal::ctrl_c() => {
println!("Ending transfer early...");
Ok(())
Expand Down Expand Up @@ -753,13 +743,30 @@ async fn get_keypair(key: Option<PathBuf>) -> Result<Keypair> {
}
}

async fn get_interactive(
hash: Hash,
opts: get::Options,
token: AuthToken,
out: Option<PathBuf>,
) -> Result<()> {
progress!("Fetching: {}", Blake3Cid::new(hash));
#[derive(Debug)]
enum GetInteractive {
Ticket {
ticket: Ticket,
keylog: bool,
},
Hash {
hash: Hash,
opts: get::Options,
token: AuthToken,
},
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the simplest way to add this functionality, it's not particularly elegant or well-named though. But it works fine. If you are disgusted however and have better ideas I'm happy to try different things.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems fie


impl GetInteractive {
fn hash(&self) -> Hash {
match self {
GetInteractive::Ticket { ticket, .. } => ticket.hash,
GetInteractive::Hash { hash, .. } => *hash,
}
}
}

async fn get_interactive(get: GetInteractive, out: Option<PathBuf>) -> Result<()> {
progress!("Fetching: {}", Blake3Cid::new(get.hash()));

progress!("{} Connecting ...", style("[1/3]").bold().dim());

Expand Down Expand Up @@ -854,7 +861,14 @@ async fn get_interactive(
Ok(reader)
}
};
let stats = get::run(hash, token, opts, on_connected, on_collection, on_blob).await?;
let stats = match get {
GetInteractive::Ticket { ticket, keylog } => {
get::run_ticket(&ticket, keylog, 16, on_connected, on_collection, on_blob).await?
flub marked this conversation as resolved.
Show resolved Hide resolved
}
GetInteractive::Hash { hash, opts, token } => {
get::run(hash, token, opts, on_connected, on_collection, on_blob).await?
}
};

pb.finish_and_clear();
progress!(
Expand Down