diff --git a/rapide/rapide.go b/rapide/rapide.go index 9043e2dfd1..f034d3c219 100644 --- a/rapide/rapide.go +++ b/rapide/rapide.go @@ -29,6 +29,20 @@ 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. + 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. + Cancel(cid.Cid) +} + // A Client is a collection of routers and protocols that can be used to do requests. type Client struct { ServerDrivenDownloaders []ServerDrivenDownloader