macula_content_transfer (macula v0.20.5)
View SourceContent transfer module for Macula content-addressed storage.
Implements the want/have/block exchange protocol for transferring content blocks between mesh peers. Handles request tracking, block verification, and message creation/parsing.
Transfer Flow
1. Requester sends WANT message with list of MCIDs 2. Provider responds with BLOCK messages for each available block 3. Requester verifies each block hash matches MCID 4. Requester stores verified blocks
Example Usage
%% Request blocks from a provider
{ok, RequestId} = macula_content_transfer:request_blocks(MCIDs, ProviderNode),
%% Handle incoming want (as provider)
{ok, Response} = macula_content_transfer:handle_want(WantMsg),
%% Handle incoming block (as requester)
ok = macula_content_transfer:handle_block(BlockMsg).
Summary
Functions
Cancel a pending request.
Mark a request as complete.
Create a BLOCK message.
Create a CANCEL message.
Create a HAVE message.
Create a HAVE message with options.
Create a MANIFEST_REQ message.
Create a MANIFEST_RES message.
Create a WANT message. MCIDs can be binary MCIDs or {MCID, Priority} tuples.
Generate a unique request ID.
Handle an incoming BLOCK message. Verifies hash and stores the block.
Handle an incoming MANIFEST_REQ message.
Handle an incoming WANT message. Returns the block data if we have it.
Parse a BLOCK message.
Parse a CANCEL message.
Parse a HAVE message.
Parse a MANIFEST_REQ message.
Parse a MANIFEST_RES message.
Parse a WANT message.
Get list of pending request IDs.
Request blocks from a target node. Returns a request ID for tracking.
Get info about a request.
Start the content transfer server.
Functions
-spec cancel_request(binary()) -> ok.
Cancel a pending request.
-spec complete_request(binary()) -> ok.
Mark a request as complete.
Create a BLOCK message.
Create a CANCEL message.
Create a HAVE message.
Create a HAVE message with options.
Create a MANIFEST_REQ message.
Create a MANIFEST_RES message.
Create a WANT message. MCIDs can be binary MCIDs or {MCID, Priority} tuples.
-spec generate_request_id() -> binary().
Generate a unique request ID.
Handle an incoming BLOCK message. Verifies hash and stores the block.
Handle an incoming MANIFEST_REQ message.
Handle an incoming WANT message. Returns the block data if we have it.
Parse a BLOCK message.
Parse a CANCEL message.
Parse a HAVE message.
Parse a MANIFEST_REQ message.
Parse a MANIFEST_RES message.
Parse a WANT message.
-spec pending_requests() -> [binary()].
Get list of pending request IDs.
Request blocks from a target node. Returns a request ID for tracking.
Get info about a request.
Start the content transfer server.