-
Notifications
You must be signed in to change notification settings - Fork 184
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
fix(iroh-blobs): do not hit the network when downloading blobs which are complete #2586
Conversation
…nd do not attempt to download from ourselves
Documentation for this PR has been generated and is available at: https://n0-computer.github.io/iroh/pr/2586/docs/iroh/ Last updated: 2024-08-05T11:37:34Z |
can you also add a test with a collection that needs some blobs to be downloaded |
Wait, I am not sure if this is correct. We can only resume the generator once, so we have to recreate it if a node fails. I do this in the direct_download case, but not in the queued downloader. Hrmm, gotta think more. |
OK, I pushed another commit that hopefully fixes things. Here's the constraint of the current design in the PR: We create a generator, which encapsulates the loop-over-hashseq flow for getting collections. We start the generator before connecting to a node, to yield Complete in case we have everything available locally. The generator is resumed with a connection, to then perform the actual download protocol, continuing the loop as needed. However, this generator we can only ever resume once. So if the node fails during the download, and we want to try the next node, we have to recreate the generator. This is what we do now in the PR. This means, though, that in this case the When using the iroh blobs client, this is not necessarily an issue, because the I see three options now:
WDYT? Also, cc @rklaehn |
The problem I see with the current approach is that you would get
|
True. We should write a test for the scenario you made up in any case. My current thinking is that we could use the And for This is turning out a bit bigger than envisioned. I'd say let's keep discussing a bit and then I can impl what we arrive at (did this a bit "on the go" so far, without having gotten at these difficulties before. This is good to tackle however, on current |
I think if we have the lower levels of enum DownloaderEvent {
BlobTransferEvent {
event: BlobEvent,
target_node: NodeId,
}
} and allow full insight into the actual happenings for a user |
Description
Two changes to the downloader:
get_to_db
public function). A newget_to_db_in_steps
function either runs to completion if the requested data is fully available locally, or yields aNeedsConn
struct at the point where it needs a network connection to proceed. TheNeedsConn
has anasync proceed(self, conn: Connection)
, which must be called with a connection for the actual download to start.This two-step process allows the downloader to check if we should dial nodes at all, or are already done without doing anything, while emitting the exact same flow of events (because we run the same loop) to the client.
To achieve this,
get_to_db
now uses a genawaiter generator internally. This means that the big loop that is the iroh-blobs protocol request flow does not have to be changed at all, only that instead of a closure we yield and resume, which makes this much easier to integrate into an external state machine like the downloader.The changes needed for this for the downloader are a bit verbose because the downloader itself is generic over a
Getter
, with impls for the actual impl and a test impl that does not use networking; therefore the newNeedsConn
state has to be modeled with an additional associated type and trait here.This PR adds three tests:
Closes #2575
Replaced #2576
Notes and open questions
Breaking changes
None, only an API addition to the public API of iroh_blobs:
iroh_blobs::get::check_local_with_progress_if_complete