Skip to content

Commit

Permalink
FIXUP bitswap interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorropo committed Mar 23, 2023
1 parent c1184d1 commit 00c4fec
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions rapide/rapide.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,24 @@ type ClosableBlockIterator interface {
blocks.BlockIterator
}

type ClientDrivenDownloader interface {
// Download must be asynchronous. It schedule a block to be downloaded and
// callback to be called when either it failed or succeeded.
// Clients need to callback when they have blocks or error.
// In the callback either []byte != nil and error == nil or error != nil and []byte == nil.
// When a callback for a cid is called the CID is cancel regardless of the success.
// The callback is expected to be really fast and should be called synchronously.
// All callbacks are threadsafe and may be called concurrently. But consumers
// must not go out of their way to call them concurrently. Just do whatever
// your underlying impl already do.
Download(cid.Cid, func([]byte, error))

// Cancel indicates that we are no longer intrested in a particular block.
// The callback is still allowed to be called again but that really not advised.
// It would be nice if consumers freed the callback in the short term after this is called.
Cancel(cid.Cid)
}

// A Client is a collection of routers and protocols that can be used to do requests.
type Client struct {
ServerDrivenDownloaders []ServerDrivenDownloader
Expand Down

0 comments on commit 00c4fec

Please sign in to comment.