ipfs-chromium
Classes | Public Types | Public Member Functions | List of all members
ipfs::BlockStorage Class Reference

Immediate access to recently-accessed blocks. More...

#include <library/include/ipfs_client/block_storage.h>

Public Types

using SerializedStorageHook = std::function< void(std::string, std::string, std::string)>
 Type for callbacks about new blocks. More...
 

Public Member Functions

 BlockStorage (BlockStorage const &)=delete
 
bool Store (std::string cid_str, Cid const &cid, std::string headers, std::string const &body, PbDag &&block)
 Store a Block for later access. More...
 
PbDag const * Get (std::string const &cid)
 Get a block! More...
 
std::string const * GetHeaders (std::string const &cid)
 Get HTTP headers associated with the block. More...
 
void AddListening (UnixFsPathResolver *)
 Indicate that a particular path resolver is waiting on a CID to become available.
 
void StopListening (UnixFsPathResolver *)
 Indicate that a particular path resolver is no longer waiting.
 
void CheckListening ()
 Normally called internally. More...
 
void AddStorageHook (SerializedStorageHook)
 Register a callback that will be called when any new block goes into storage.
 
Store (Convenience)

Convenience functions for ipfs::BlockStorage::Store(std::string,Cid const&,std::string,std::string const&,Block&&)

bool Store (std::string headers, std::string const &body, PbDag &&block)
 
bool Store (std::string const &cid, std::string headers, std::string body)
 
bool Store (std::string cid_str, Cid const &cid, std::string headers, std::string body)
 
bool Store (Cid const &cid, std::string headers, std::string const &body, PbDag &&)
 

Detailed Description

Immediate access to recently-accessed blocks.

Blocks are held in-memory, using pretty standard containers, as already-parsed ipfs::Block objects.

Member Typedef Documentation

◆ SerializedStorageHook

using ipfs::BlockStorage::SerializedStorageHook = std::function<void(std::string, std::string, std::string)>

Type for callbacks about new blocks.

The parameters to the hook are

  • CID string
  • HTTP headers
  • raw bytes of the block

Member Function Documentation

◆ CheckListening()

void ipfs::BlockStorage::CheckListening ( )

Normally called internally.

Checks to see if any listening path resolver appears to be waiting on a CID which is now available.

◆ Get()

PbDag const* ipfs::BlockStorage::Get ( std::string const &  cid)

Get a block!

cid must match string-wise exactly: same multibase & all. For identity codecs, returns the data even if not stored.

Parameters
cid- String representation of the CID for the block.
Returns
Non-owning pointer if found, nullptr otherwise

◆ GetHeaders()

std::string const* ipfs::BlockStorage::GetHeaders ( std::string const &  cid)

Get HTTP headers associated with the block.

Parameters
cid- String representation of the CID for the block.
Returns
nullptr iff ! Get(cid) ; Empty string if the headers have never been set ; Otherwise, application-specific std::string (as-stored)

◆ Store()

bool ipfs::BlockStorage::Store ( std::string  cid_str,
Cid const &  cid,
std::string  headers,
std::string const &  body,
PbDag &&  block 
)

Store a Block for later access.

Parameters
cid_str- The string representation of cid
cid- The Content IDentifier
headers- Associated HTTP headers
body- The raw bytes of the block
block- The block being stored
Returns
Whether this block is now stored in *this

The documentation for this class was generated from the following file: