API structure for the file exchange using blocks
Overview
The API would look as follows:
StartProvide(HashFile)
List(HashFile)
GetProviders(HashFile)
GetBlockFrom(PeerID, HashFile, HashBlock)
GetFile(HashFile)
StartProvide(HashFile)
Having a single block of the given file would allow one person to advertise they have the blocks. We are currently using put_record which gives the data associated to the key to nodes close to it, which would not be efficient due to storage space and size concerns, which is why we would use a StartProvide
instead (which leaves the actual exchange implementation up to us)
List(HashFile) -> List<HashBlock>
Since a node can say they provide the file if they have at least one of its block, it is important to know which blocks a given node has. List(HashFile)
would be a query local to the node, which would return the list of the block hashes that are part of the file referenced by HashFile
GetProviders(HashFile) -> List<(PeerID, List<HashBlock>)>
The default GetProviders
just gives the list of persons that provide a file (generally because providing a file means having the entire file and not just parts of it). Since we can have parts of a file, we need to know which parts, thus returning the list of block hashes that given PeerID has.
This could even be extended to return the list of the linear combination that was used to create a block. This would allow the person requesting a given file to select a part of the blocks and check if the matrix for decoding is invertible (which is of no use if we just exchange blocks, but is very useful when we start recoding blocks).
GetBlockFrom(PeerID, HashFile, HashBlock)
This is where the actual exchange of block data takes places (since before we were just exchanging metadata, like the hash of the file, hash of blocks or the linear combination to make a given block).
Requests the data of the block identified by HashBlock
, part of the file identified by HashFile
to the given PeerID
GetFile(HashFile)
Wrapper around GetProviders
+ GetBlockFrom
. Can also include a selection step later on to choose which Peer to request which blocks from, as well as checking which blocks could reconstruct the original file given the linear combination of the blocks.