cpp-ipfs-http-client
IPFS C++ client library
|
IPFS client. More...
#include <ipfs/client.h>
Public Types | |
enum class | PinRmOptions { NON_RECURSIVE , RECURSIVE } |
Options to control the PinRm() method. More... | |
Public Member Functions | |
Client (const std::string &host, long port, const std::string &timeout="", const std::string &protocol="http://", const std::string &apiPath="/api/v0", bool verbose=false) | |
Constructor. | |
Client (const Client &) | |
Copy-constructor. | |
Client (Client &&) noexcept | |
Move-constructor. | |
Client & | operator= (const Client &) |
Copy assignment operator. | |
Client & | operator= (Client &&) noexcept |
Move assignment operator. | |
~Client () | |
Destructor. | |
void | Id (Json *id) |
Return the identity of the peer. | |
void | Version (Json *version) |
Return the implementation version of the peer. | |
void | ConfigGet (const std::string &key, Json *config) |
Query the current config of the peer. | |
void | ConfigSet (const std::string &key, const Json &value) |
Add or replace a config knob at the peer. | |
void | ConfigReplace (const Json &config) |
Replace the entire config at the peer. | |
void | DhtFindPeer (const std::string &peer_id, Json *addresses) |
Retrieve the peer info of a reachable node in the network. | |
void | DhtFindProvs (const std::string &hash, Json *providers) |
Retrieve the providers for a content that is addressed by a hash. | |
void | BlockGet (const std::string &block_id, std::iostream *block) |
Get a raw IPFS block. | |
void | BlockPut (const http::FileUpload &block, Json *stat) |
Store a raw block in IPFS. | |
void | BlockStat (const std::string &block_id, Json *stat) |
Get information for a raw IPFS block. | |
void | FilesGet (const std::string &path, std::iostream *response) |
Get a file from IPFS. | |
void | FilesAdd (const std::vector< http::FileUpload > &files, Json *result) |
Add files to IPFS. | |
void | FilesLs (const std::string &path, Json *result) |
List directory contents for Unix filesystem objects. | |
void | KeyGen (const std::string &key_name, const std::string &key_type, size_t key_size, std::string *key_id) |
Generate a new key. | |
void | KeyList (Json *key_list) |
List all the keys. | |
void | KeyRm (const std::string &key_name) |
Remove a key. | |
void | KeyRename (const std::string &old_key, const std::string &new_key) |
Rename an existing key. | |
void | NamePublish (const std::string &object_id, const std::string &key_name, const Json &options, std::string *name_id) |
Publish an IPNS name attached to a given value. | |
void | NameResolve (const std::string &name_id, std::string *path_string) |
Resolve an IPNS name. | |
void | ObjectNew (std::string *object_id) |
Create a new MerkleDAG node. | |
void | ObjectPut (const Json &object, Json *object_stored) |
Store a MerkleDAG node. | |
void | ObjectGet (const std::string &object_id, Json *object) |
Get a MerkleDAG node. | |
void | ObjectData (const std::string &object_id, std::string *data) |
Get the data field of a MerkleDAG node. | |
void | ObjectLinks (const std::string &object_id, Json *links) |
Get links of a MerkleDAG node. | |
void | ObjectStat (const std::string &object_id, Json *stat) |
Get stats about a MerkleDAG node. | |
void | ObjectPatchAddLink (const std::string &source, const std::string &link_name, const std::string &link_target, std::string *cloned) |
Create a new object from an existing MerkleDAG node and add to its links. | |
void | ObjectPatchRmLink (const std::string &source, const std::string &link_name, std::string *cloned) |
Create a new object from an existing MerkleDAG node and remove one of its links. | |
void | ObjectPatchAppendData (const std::string &source, const http::FileUpload &data, std::string *cloned) |
Create a new object from an existing MerkleDAG node and append data to it. | |
void | ObjectPatchSetData (const std::string &source, const http::FileUpload &data, std::string *cloned) |
Create a new object from an existing MerkleDAG node and set its data. | |
void | PinAdd (const std::string &object_id) |
Pin a given IPFS object. | |
void | PinLs (Json *pinned) |
List all the objects pinned to local storage. | |
void | PinLs (const std::string &object_id, Json *pinned) |
List the objects pinned under a specific hash. | |
void | PinRm (const std::string &object_id, PinRmOptions options) |
Unpin an object. | |
void | StatsBw (Json *bandwidth_info) |
Get IPFS bandwidth (bw) information. | |
void | StatsRepo (Json *repo_stats) |
Get IPFS Repo Stats. | |
void | SwarmAddrs (Json *addresses) |
List of known addresses of each peer connected. | |
void | SwarmConnect (const std::string &peer) |
Open a connection to a given address. | |
void | SwarmDisconnect (const std::string &peer) |
Close a connection on a given address. | |
void | SwarmPeers (Json *peers) |
List the peers that we have connections with. | |
void | Abort () |
Abort any current running IPFS API request. | |
void | Reset () |
Resets the abort call, allowing to execute new API requests again. | |
IPFS client.
It implements the interface described in https://github.com/ipfs/js-ipfs/tree/master/docs/core-api.
The methods of this class may throw some variant of std::exception
if a connectivity error occurs or if the response cannot be parsed. Be prepared!
|
strong |
Options to control the PinRm()
method.
Enumerator | |
---|---|
NON_RECURSIVE | Just unpin the specified object. |
RECURSIVE | Recursively unpin the objects. |
ipfs::Client::Client | ( | const std::string & | host, |
long | port, | ||
const std::string & | timeout = "" , |
||
const std::string & | protocol = "http://" , |
||
const std::string & | apiPath = "/api/v0" , |
||
bool | verbose = false |
||
) |
Constructor.
An example usage:
[in] | host | Hostname or IP address of the server to connect to. |
[in] | port | Port to connect to. |
[in] | timeout | [Optional] set server-side time-out, which should be string (eg. "6s") |
[in] | protocol | [Optional] protocol (default: http://) |
[in] | apiPath | [Optional] API Path (default: /api/v0) |
[in] | verbose | [Optional] Enable cURL Verbose Mode (default: false) |
ipfs::Client::Client | ( | const Client & | other | ) |
Copy-constructor.
[in] | other | Other client connection to be copied. |
|
noexcept |
Move-constructor.
[in,out] | other | Other client connection to be moved. |
|
default |
Destructor.
void ipfs::Client::Abort | ( | ) |
Abort any current running IPFS API request.
Very useful if you were using the IPFS client API calls inside seperate thread, but which to abort the request and stop the running thread (without using pthread_cancel).
Call this method out-side of the running thread, eg. the main thread.
See example: https://vasild.github.io/cpp-ipfs-http-client/examples.html
void ipfs::Client::BlockGet | ( | const std::string & | block_id, |
std::iostream * | block | ||
) |
Get a raw IPFS block.
Implements https://github.com/ipfs/js-ipfs/blob/master/docs/core-api/BLOCK.md#blockget.
An example usage:
std::exception | if any error occurs |
[in] | block_id | Id of the block (multihash). |
[out] | block | Raw contents of the block is written to this stream as it is retrieved. |
void ipfs::Client::BlockPut | ( | const http::FileUpload & | block, |
Json * | stat | ||
) |
Store a raw block in IPFS.
Implements https://github.com/ipfs/js-ipfs/blob/master/docs/core-api/BLOCK.md#blockput.
An example usage:
std::exception | if any error occurs |
[in] | block | Raw contents of the block to store. |
[out] | stat | Information about the stored block. |
void ipfs::Client::BlockStat | ( | const std::string & | block_id, |
Json * | stat | ||
) |
Get information for a raw IPFS block.
Implements https://github.com/ipfs/js-ipfs/blob/master/docs/core-api/BLOCK.md#blockstat.
An example usage:
std::exception | if any error occurs |
[in] | block_id | Id of the block (multihash). |
[out] | stat | Retrieved information about the block. |
void ipfs::Client::ConfigGet | ( | const std::string & | key, |
Json * | config | ||
) |
Query the current config of the peer.
Implements https://github.com/ipfs/js-ipfs/tree/master/docs/core-api/CONFIG.md#configget.
An example usage:
std::exception | if any error occurs |
[in] | key | The key of the value to fetch from the config. If this is an empty string, then the whole config is fetched. |
[out] | config | Fetched config. |
void ipfs::Client::ConfigReplace | ( | const Json & | config | ) |
Replace the entire config at the peer.
Implements https://github.com/ipfs/js-ipfs/tree/master/docs/core-api/CONFIG.md#configreplace.
An example usage:
std::exception | if any error occurs |
[in] | config | The entire config to set/replace. |
void ipfs::Client::ConfigSet | ( | const std::string & | key, |
const Json & | value | ||
) |
Add or replace a config knob at the peer.
Implements https://github.com/ipfs/js-ipfs/tree/master/docs/core-api/CONFIG.md#configset.
An example usage:
std::exception | if any error occurs |
[in] | key | The key of the config knob to set. |
[in] | value | The value to set for the key. |
void ipfs::Client::DhtFindPeer | ( | const std::string & | peer_id, |
Json * | addresses | ||
) |
Retrieve the peer info of a reachable node in the network.
Implements https://github.com/ipfs/js-ipfs/blob/master/docs/core-api/DHT.md#dhtfindpeer.
An example usage:
std::exception | if any error occurs |
[in] | peer_id | Id of the peer (multihash). |
[out] | addresses | List of the peer's addresses. |
void ipfs::Client::DhtFindProvs | ( | const std::string & | hash, |
Json * | providers | ||
) |
Retrieve the providers for a content that is addressed by a hash.
Implements https://github.com/ipfs/js-ipfs/blob/master/docs/core-api/DHT.md#dhtfindprovs.
An example usage:
std::exception | if any error occurs |
[in] | hash | Multihash whose providers to find. |
[out] | providers | List of providers of hash . |
void ipfs::Client::FilesAdd | ( | const std::vector< http::FileUpload > & | files, |
Json * | result | ||
) |
Add files to IPFS.
Implements https://github.com/ipfs/js-ipfs/tree/master/docs/core-api/FILES.md#add.
An example usage:
std::exception | if any error occurs |
[in] | files | List of files to add. |
[out] | result | List of results, one per file. For example: [{"path": "foo.txt", "hash": "Qm...", "size": 123}, {"path": ...}, ...] |
void ipfs::Client::FilesGet | ( | const std::string & | path, |
std::iostream * | response | ||
) |
Get a file from IPFS.
Implements https://github.com/ipfs/js-ipfs/tree/master/docs/core-api/FILES.md#get.
An example usage:
std::exception | if any error occurs |
[in] | path | Path of the file in IPFS. For example: "/ipfs/QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG/readme" |
[out] | response | The file's contents is written to this stream as it is retrieved from IPFS. |
void ipfs::Client::FilesLs | ( | const std::string & | path, |
Json * | result | ||
) |
List directory contents for Unix filesystem objects.
Implements https://github.com/ipfs/js-ipfs/blob/master/docs/core-api/FILES.md#ls.
An example usage:
std::exception | if any error occurs |
[in] | path | The path to an IPFS object. |
[out] | result | List of results (files). For example: { "Arguments": { ... }, "Objects": { "QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG": { "Hash": "QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG", "Links": [ { "Hash": "QmZTR5bcpQD7cFgTorqxZDYaew1Wqgf...", "Name": "about", "Size": 1677, "Type": "File" }, ... { "Hash": "QmdncfsVm2h5Kqq9hPmU7oAVX2zTSVP...", "Name": "quick-start", "Size": 1717, "Type": "File" }, ... ], "Size": 0, "Type": "Directory" } } } |
void ipfs::Client::Id | ( | Json * | id | ) |
Return the identity of the peer.
Implements https://github.com/ipfs/js-ipfs/tree/master/docs/core-api/MISCELLANEOUS.md#id.
An example usage:
std::exception | if any error occurs |
[out] | id | The identity of the peer. It contains at least the properties "Addresses", "ID", "PublicKey". |
void ipfs::Client::KeyGen | ( | const std::string & | key_name, |
const std::string & | key_type, | ||
size_t | key_size, | ||
std::string * | key_id | ||
) |
Generate a new key.
Implements https://github.com/ipfs/interface-js-ipfs-core/blob/master/SPEC/KEY.md#keygen.
An example usage:
std::exception | if any error occurs |
[in] | key_name | Key name (local, user-friendly name for the key). |
[in] | key_type | Key type. |
[in] | key_size | Key size. |
[out] | key_id | Key CID. |
void ipfs::Client::KeyList | ( | Json * | key_list | ) |
List all the keys.
Implements https://github.com/ipfs/interface-js-ipfs-core/blob/master/SPEC/KEY.md#keylist.
An example usage:
std::exception | if any error occurs |
[out] | key_list | List of all local keys. |
void ipfs::Client::KeyRename | ( | const std::string & | old_key, |
const std::string & | new_key | ||
) |
Rename an existing key.
Implements https://github.com/ipfs/interface-js-ipfs-core/blob/master/SPEC/KEY.md#keyrename.
An example usage:
std::exception | if any error |
[in] | old_key | The current key name. |
[in] | new_key | The desired key name. |
void ipfs::Client::KeyRm | ( | const std::string & | key_name | ) |
Remove a key.
Implements https://github.com/ipfs/interface-js-ipfs-core/blob/master/SPEC/KEY.md#keyrm.
An example usage:
std::exception | if any error occurs |
[in] | key_name | Key name (local, user-friendly name for the key). |
void ipfs::Client::NamePublish | ( | const std::string & | object_id, |
const std::string & | key_name, | ||
const Json & | options, | ||
std::string * | name_id | ||
) |
Publish an IPNS name attached to a given value.
Implements https://github.com/ipfs/js-ipfs/blob/master/docs/core-api/NAME.md#namepublish.
An example usage:
std::exception | if any error occurs |
[in] | object_id | Id (multihash) of the object to publish. |
[in] | key_name | Name of the key to use. This is the local, human-friendly keyname |
[in] | options | Optional JSON parameter providing options. If specified, these will be used to determine how the name is published: { resolve: // bool - Resolve given path before publishing. // Default: true lifetime: // string - Lifetime duration of the record. // Default: 24h ttl: // string - Duration in client's cache. } |
[out] | name_id | IPNS name id (multihash) of the named object. |
void ipfs::Client::NameResolve | ( | const std::string & | name_id, |
std::string * | path_string | ||
) |
Resolve an IPNS name.
Implements https://github.com/ipfs/js-ipfs/blob/master/docs/core-api/NAME.md#nameresolve.
An example usage:
std::exception | if any error occurs |
[in] | name_id | Id (multihash) of the name to resolve. |
[out] | path_string | IPFS path string to the resolving object. For example: "/ipfs/QmRrVRGx5xAXX52BYuScmJk1KWPny86BtexP8YNJ8jz76U" |
void ipfs::Client::ObjectData | ( | const std::string & | object_id, |
std::string * | data | ||
) |
Get the data field of a MerkleDAG node.
Implements https://github.com/ipfs/js-ipfs/tree/master/docs/core-api/OBJECT.md#objectdata.
An example usage:
std::exception | if any error occurs |
[in] | object_id | Id (multihash) of the MerkleDAG node whose data to fetch. |
[out] | data | Raw data of the MerkleDAG node. |
void ipfs::Client::ObjectGet | ( | const std::string & | object_id, |
Json * | object | ||
) |
Get a MerkleDAG node.
Implements https://github.com/ipfs/js-ipfs/tree/master/docs/core-api/OBJECT.md#objectget.
An example usage:
std::exception | if any error occurs |
[in] | object_id | Id (multihash) of the MerkleDAG node to fetch. |
[out] | object | Retrieved MerkleDAG node. For example: {"Data": "abc", "Links": [{"Name": "link1", "Hash": "...", "Size": 8}]} |
void ipfs::Client::ObjectLinks | ( | const std::string & | object_id, |
Json * | links | ||
) |
Get links of a MerkleDAG node.
Implements https://github.com/ipfs/js-ipfs/tree/master/docs/core-api/OBJECT.md#objectlinks.
An example usage:
std::exception | if any error occurs |
[in] | object_id | Id of the object to query (multihash). |
[out] | links | Links of the object. For example: [{"Name": "...", "Hash": "...", "Size": 8}, ...] |
void ipfs::Client::ObjectNew | ( | std::string * | object_id | ) |
Create a new MerkleDAG node.
Implements https://github.com/ipfs/js-ipfs/tree/master/docs/core-api/OBJECT.md#objectnew.
An example usage:
std::exception | if any error occurs |
[out] | object_id | Id of the newly created object (multihash). |
void ipfs::Client::ObjectPatchAddLink | ( | const std::string & | source, |
const std::string & | link_name, | ||
const std::string & | link_target, | ||
std::string * | cloned | ||
) |
Create a new object from an existing MerkleDAG node and add to its links.
Implements https://github.com/ipfs/js-ipfs/tree/master/docs/core-api/OBJECT.md#objectpatchaddlink.
An example usage:
std::exception | if any error occurs |
[in] | source | Id of the object to clone (multihash). |
[in] | link_name | Link name. |
[in] | link_target | Id of the object that the link points to (multihash). |
[out] | cloned | Id of the newly created (cloned) object (multihash). |
void ipfs::Client::ObjectPatchAppendData | ( | const std::string & | source, |
const http::FileUpload & | data, | ||
std::string * | cloned | ||
) |
Create a new object from an existing MerkleDAG node and append data to it.
Implements https://github.com/ipfs/js-ipfs/tree/master/docs/core-api/OBJECT.md#objectpatchappenddata.
An example usage:
std::exception | if any error occurs |
[in] | source | Id of the object to append data to (multihash). |
[in] | data | Data to be appended. |
[out] | cloned | Id of the newly created (cloned) object (multihash). |
void ipfs::Client::ObjectPatchRmLink | ( | const std::string & | source, |
const std::string & | link_name, | ||
std::string * | cloned | ||
) |
Create a new object from an existing MerkleDAG node and remove one of its links.
Implements https://github.com/ipfs/js-ipfs/tree/master/docs/core-api/OBJECT.md#objectpatchrmlink.
An example usage:
std::exception | if any error occurs |
[in] | source | Id of the object to remove the link from (multihash). |
[in] | link_name | Name of the link to remove. |
[out] | cloned | Id of the newly created (cloned) object (multihash). |
void ipfs::Client::ObjectPatchSetData | ( | const std::string & | source, |
const http::FileUpload & | data, | ||
std::string * | cloned | ||
) |
Create a new object from an existing MerkleDAG node and set its data.
Implements https://github.com/ipfs/js-ipfs/tree/master/docs/core-api/OBJECT.md#objectpatchsetdata.
An example usage:
std::exception | if any error occurs |
[in] | source | Id of the object whose data to set (multihash). |
[in] | data | Data to be set. |
[out] | cloned | Id of the newly created (cloned) object (multihash). |
Store a MerkleDAG node.
Implements https://github.com/ipfs/js-ipfs/tree/master/docs/core-api/OBJECT.md#objectput.
An example usage:
std::exception | if any error occurs |
[in] | object | Node to store. |
[out] | object_stored | Stored node. Should be the same as the provided object plus the stored object's multihash id. |
void ipfs::Client::ObjectStat | ( | const std::string & | object_id, |
Json * | stat | ||
) |
Get stats about a MerkleDAG node.
Implements https://github.com/ipfs/js-ipfs/tree/master/docs/core-api/OBJECT.md#objectstat.
An example usage:
std::exception | if any error occurs |
[in] | object_id | Id of the object to query (multihash). |
[out] | stat | Stats about the object. For example: {"NumLinks": 0, "BlockSize": 10, "LinksSize": 2, ...} |
Move assignment operator.
[in,out] | other | Other client connection to be moved. |
Copy assignment operator.
[in] | other | Other client connection to be copied. |
void ipfs::Client::PinAdd | ( | const std::string & | object_id | ) |
Pin a given IPFS object.
Implements https://github.com/ipfs/js-ipfs/blob/master/docs/core-api/PIN.md#pinadd.
An example usage:
std::exception | if any error occurs |
[in] | object_id | Id of the object to pin (multihash). |
void ipfs::Client::PinLs | ( | const std::string & | object_id, |
Json * | pinned | ||
) |
List the objects pinned under a specific hash.
Implements https://github.com/ipfs/js-ipfs/blob/master/docs/core-api/PIN.md#pinls.
An example usage:
std::exception | if any error occurs |
[in] | object_id | Id of the object to list (multihash). |
[out] | pinned | List of pinned objects. |
void ipfs::Client::PinLs | ( | Json * | pinned | ) |
List all the objects pinned to local storage.
Implements https://github.com/ipfs/js-ipfs/blob/master/docs/core-api/PIN.md#pinls.
An example usage:
std::exception | if any error occurs |
[out] | pinned | List of pinned objects. |
void ipfs::Client::PinRm | ( | const std::string & | object_id, |
PinRmOptions | options | ||
) |
Unpin an object.
Implements https://github.com/ipfs/js-ipfs/blob/master/docs/core-api/PIN.md#pinrm.
An example usage:
std::exception | if any error occurs |
PinRmOptions
[in] | object_id | Id of the object to unpin (multihash). |
[in] | options | Unpin options. |
void ipfs::Client::Reset | ( | ) |
Resets the abort call, allowing to execute new API requests again.
Used in combintation with the Abort() method.
Once you executed the Abort() method and thread.join() call. Which wait until the thread is completly finished. You need to call the Reset() method in order to reset the internal state. Allow you to execute new API requests again.
Call this method out-side of the running thread, eg. the main thread.
See example: https://vasild.github.io/cpp-ipfs-http-client/examples.html
void ipfs::Client::StatsBw | ( | Json * | bandwidth_info | ) |
Get IPFS bandwidth (bw) information.
Implements https://github.com/ipfs/js-ipfs/blob/master/docs/core-api/STATS.md#ipfsstatsbwoptions.
An example usage:
std::exception | if any error occurs |
[out] | bandwidth_info | Structure that contains IPFS bandwidth information. For example: { "RateIn": 4541.421091935148, "RateOut": 677.3253862633403, "TotalIn": 15994960, "TotalOut": 6696092 } |
void ipfs::Client::StatsRepo | ( | Json * | repo_stats | ) |
Get IPFS Repo Stats.
Implements https://github.com/ipfs/js-ipfs/blob/master/docs/core-api/REPO.md#ipfsrepostatoptions.
An example usage:
std::exception | if any error occurs |
[out] | repo_stats | Structure that contains IPFS repo stats. For example: { "RepoSize":256893470, "StorageMax":20000000000, "NumObjects":24935, "RepoPath":"/home/melroy/.ipfs", "Version":"fs-repo@11" } |
void ipfs::Client::SwarmAddrs | ( | Json * | addresses | ) |
List of known addresses of each peer connected.
Implements https://github.com/ipfs/js-ipfs/blob/master/docs/core-api/SWARM.md#swarmaddrs.
An example usage:
std::exception | if any error occurs |
[out] | addresses | The retrieved list. |
void ipfs::Client::SwarmConnect | ( | const std::string & | peer | ) |
Open a connection to a given address.
Implements https://github.com/ipfs/js-ipfs/blob/master/docs/core-api/SWARM.md#swarmconnect.
An example usage:
std::exception | if any error occurs |
[in] | peer | Peer to connect to. For example: "/ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ" |
void ipfs::Client::SwarmDisconnect | ( | const std::string & | peer | ) |
Close a connection on a given address.
Implements https://github.com/ipfs/js-ipfs/blob/master/docs/core-api/SWARM.md#swarmdisconnect.
An example usage:
std::exception | if any error occurs |
[in] | peer | Peer to disconnect from to. For example: "/ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ" |
void ipfs::Client::SwarmPeers | ( | Json * | peers | ) |
List the peers that we have connections with.
Implements https://github.com/ipfs/js-ipfs/blob/master/docs/core-api/SWARM.md#swarmpeers.
An example usage:
std::exception | if any error occurs |
[out] | peers | The retrieved list. |
void ipfs::Client::Version | ( | Json * | version | ) |
Return the implementation version of the peer.
Implements https://github.com/ipfs/js-ipfs/tree/master/docs/core-api/MISCELLANEOUS.md#version.
An example usage:
std::exception | if any error occurs |
[out] | version | The peer's implementation version. It contains at least the properties "Repo", "System", "Version". |