Integrate new renter-host protocol into contractor+renter
Here I use a slightly-clever approach to integrating with the renter. Basically, the new Session
type is a superset of the old Editor
and Downloader
types; it has the functionality of both. Since contractor.Editor
and contractor.Downloader
return interfaces, not structs, I can sneakily return a contractor.hostSession
instead of a contractor.hostEditor
or contractor.hostDownloader
if the host's version is v1.4.0 or above. The standard caching+invalidation of editors/downloaders also applies to sessions.
The upside of this approach is that we literally do not have to touch the renter package at all; it will "just work" with new hosts. The downside is that the renter is still not taking advantage of partial downloads. The next step will probably be to flip things: instead of Session
pretending to be Downloader
, Downloader
will pretend to be Session
. Specifically, you'll be able to call PartialDownload
on a Downloader
, but it behind the scenes it will actually download the full sector and just give you a part of it. The plan is for this to happen rarely in practice, since we want to move renters to new (v1.4.0) hosts as aggressively as possible.
EDIT: I went ahead and implemented the above. The renter now calls Download
with a range of 0, SectorSize
, and the old Downloader always downloads a full sector. So now we just need to make the renter smart enough to request partial download ranges.
btw, we can make the old Downloader a bit more tolerable by caching the entire downloaded sector. Then, if the next Download
call requests the same Merkle root, we can read from the cached sector instead of redownloading the whole thing. The initial latency will still be awful, but at least you'll be able to seek around within the sector instantly after that.