diff --git a/rapide/rapide.go b/rapide/rapide.go index 6d76a9254b..c5f34fbdca 100644 --- a/rapide/rapide.go +++ b/rapide/rapide.go @@ -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