Open dirkmc opened 4 years ago
Subscribe(ctx context.Context, sesid uint64, keys ...cid.Cid) <-chan ResponseMessage
I assume we'll have to change this to something like:
Subscribe(chan <- ResponseMessage, keys ...cid.Cid)
(where keys can be nil to cancel).
Unsubscribe(sesid uint64, keys ...cid.Cid)
Having unsubscribe trigger a cancel but not having subscribe trigger a want is weird. I'm wondering if we should just make this interface session agnostic.
Note that because operations on the blockstore are slow
Note 1: there should already be a cache. IMO, we should let the application do this for us. Note 2: we may need to improve some contention issues in the cache, but I'm not sure if it's actually an issue.
I updated the original post to change the interfaces a little.
I think we can tackle streaming GetBlocks() separately, but it shouldn't be a bit lift to change it.
I'll put together a PR to see what this looks like in practice and post it as a WIP.
Currently the synchronization between block receipt and sessions is not quite air-tight, leading to some race conditions.
Background
When IPFS wants a block it
SessionInterestManager
When Bitswap receives a block it
There are overlapping concerns handled in different places (
SessionInterestManager
vs "notifier") and non-atomic operations, and the code is complex and hard to follow.Proposal
Create a unified
Notifier
interface that can synchronize operations and ensure atomicity.Notifier
NewSubscription(sesid uint64) Subscription
Publish(msg ResponseMessage) error
Subscription
Messages() <-chan ResponseMessage
Subscribe(keys ...cid.Cid)
Unsubscribe(keys ...cid.Cid)
Remove()
ResponseMessage
is a struct with public fields for blocks, HAVEs and DONT_HAVEs.When IPFS asks a Bitswap Session for a block, the Session will call
Subscribe()
on theNotifier
:When a request is cancelled the Session will call
Unsubscribe()
for those keys. When the Session shuts down it will callUnsubscribe()
with the session id.