ipfs / go-bitswap

The golang implementation of the bitswap protocol
MIT License
216 stars 112 forks source link

[WIP] Experiment: Option for dynamically manageable requests #593

Closed aschmahmann closed 1 year ago

aschmahmann commented 2 years ago

Related to one of the suggestions in https://github.com/ipfs/go-libipfs/issues/90, this provides an option to request blocks from a session using a channel instead of requesting blocks as groups of CIDs.

This means that users of a session can dynamically discover and request as many blocks as it wants without needing to spin up many goroutines to wait on the blocks or artificially group the block requests together.

This was useful to me as part of implementing https://github.com/aschmahmann/mdinc/pull/1.

Note: This initial approach is definitely not as polished as it could be and we can clean up the names and the plumbing here a bunch. However, it worked for the Docker demo and gave a starting point for a conversation on if this is a good idea and collecting feedback on the feature.

Some areas for feedback:

  1. Any reason we shouldn't do this?
  2. Should the new function take a channel or some object that has Add(cid) and Remove(cid) called on it? Passing channels is more natural to Go and makes sense for performance, but I've noticed can sometimes confuse people. Went with channels since it seemed like less code and also happened to match the issue linked above.
  3. Should the new function take an interface or a struct? I went with an interface here so I didn't have to change public exports, but IMO if we're exposing new functionality to the user it'd be nice to give them an interface to match against if they want to and in that case a struct is fair game too
  4. Naming suggestions? People tend to drop those anyway so figure I'd call it out explicitly 😄
Jorropo commented 1 year ago

This repository has been moved to https://github.com/ipfs/go-libipfs. There is not an easy way to transfer PRs, so if you would like to continue with this PR then please re-open it in the new repository and link to this PR.