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

resume transfers #14

Open
saljam opened this issue Apr 8, 2020 · 5 comments
Open

resume transfers #14

saljam opened this issue Apr 8, 2020 · 5 comments
Labels

Comments

@saljam
Copy link
Owner

saljam commented Apr 8, 2020

it would be nice to figure out a way to resume transfers.

maybe after sending a file metadata, wait for the other side to send an "offset" reply. in browsers, a service worker on the receive side can translate the Range header to the offset.

@oridb
Copy link
Contributor

oridb commented Apr 8, 2020

Do we need to wait for a reply? If we're resuming a file, we already know what we're getting. (But, again, this is sounding a lot like a reinvention of HTTP: is it possible to just run HTTP on this?)

@saljam
Copy link
Owner Author

saljam commented Apr 12, 2020

You're right. If the receiver initiates the transfer by asking for a file at an offset then we only need one message. Thinking about the web version, the sender can get prompted to open the file on their end to resume.

This does leave the open question of how to choose which wormhole to ask for the file over if multiple wormholes are open in multiple tabs, since there's only one Service Worker handling the browser's download request.

HTTP on this would be a neat trick, I'd love to see that. I see two challenges:

  • This has to run in the browser. Writing an HTTP server and client in JS to run in the browser is a little beyond my enthusiasm. Maybe we can move more of the application into the Wasm Go code? That comes with its own set of problems, like size, interaction with the rest of JS, and DOM manipulation.
  • We'd still have to write the handlers for sending (http push? POST?) and requesting (for resume), and their logic would be identical whether the wire protocol was HTTP or something simpler.

WebRTC DataChannels are already message-oriented, and browsers have the facilities to make it easy to start with a JSON message and follow with data.

@saljam
Copy link
Owner Author

saljam commented Apr 12, 2020

More thoughts on resume and browsers. My thinking was to make it work even if both ends start a new session, but I'm coming around to abandon that approach now.

That's because:

  • The "choosing which wormhole to ask for the file over" issue
  • I'd like to add an integrity check hash trailer but if the receiver only ever sees half the file they won't be able to compute its hash.

If we maintain some session state (receiver: state of rolling hash, offset, random identifier for the file. sender: state of rolling hash, open File object) across reconnects, we won't have these issues.

I'm nervous about storing this stuff in LocalStorage or cookies. Maybe add a "reconnect" button when a session breaks, and it keeps state from the previous connection. If a user closes the tab then it's gone and they can't resume any more. I can live with that.

The identifier can be embedded in the download URL from the service worker, so it knows which which session to resume from.

None of this applies to the command line tool which can just read the file.

@saljam
Copy link
Owner Author

saljam commented Apr 22, 2020

Some thoughts on resuming sessions without having to input a new code.

Assume the signal server, whenever a new slot is used also assigns it a unique "session" identifier. Assume we can exchange messages over this session id the same way we exchange them over a slot.

If a session breaks, both hosts can try to reconnect by exchanging new webrtc session descriptions (sboxed by the same initial key) at the session id, instead of the slot id which should be now long relinquished.

We actually do generate "session ids" (as the ETag to ensure old requests for a slot don't interfere with newer ones) but we can't exchange messages using them alone. That can be fixed.

@eitau
Copy link
Contributor

eitau commented May 7, 2020

On Firefox, if you try to resume download using browser UI after connection has been broken, it sends a request bypassing the ServiceWorker (the request doesn't even include range header because requests intercepted by SW are not considered by FF as 'resumable'). Also in general range header is not exposed to the SW : w3c/ServiceWorker#1201 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants