cpp-ipfs-http-client
IPFS C++ client library
|
IPFS client. More...
#include <ipfs/client.h>
Public Types | |
enum | PinRmOptions { PinRmOptions::NON_RECURSIVE, PinRmOptions::RECURSIVE } |
Options to control the PinRm() method. More... | |
Public Member Functions | |
Client (const std::string &host, long port) | |
Constructor. More... | |
Client (const Client &) | |
Copy-constructor. More... | |
Client (Client &&) | |
Move-constructor. More... | |
Client & | operator= (const Client &) |
Copy assignment operator. More... | |
Client & | operator= (Client &&) |
Move assignment operator. More... | |
~Client () | |
Destructor. More... | |
void | Id (Json *id) |
Return the identity of the peer. More... | |
void | Version (Json *version) |
Return the implementation version of the peer. More... | |
void | ConfigGet (const std::string &key, Json *config) |
Query the current config of the peer. More... | |
void | ConfigSet (const std::string &key, const Json &value) |
Add or replace a config knob at the peer. More... | |
void | ConfigReplace (const Json &config) |
Replace the entire config at the peer. More... | |
void | DhtFindPeer (const std::string &peer_id, Json *addresses) |
Retrieve the peer info of a reachable node in the network. More... | |
void | DhtFindProvs (const std::string &hash, Json *providers) |
Retrieve the providers for a content that is addressed by a hash. More... | |
void | BlockGet (const std::string &block_id, std::iostream *block) |
Get a raw IPFS block. More... | |
void | BlockPut (const http::FileUpload &block, Json *stat) |
Store a raw block in IPFS. More... | |
void | BlockStat (const std::string &block_id, Json *stat) |
Get information for a raw IPFS block. More... | |
void | FilesGet (const std::string &path, std::iostream *response) |
Get a file from IPFS. More... | |
void | FilesAdd (const std::vector< http::FileUpload > &files, Json *result) |
Add files to IPFS. More... | |
void | FilesLs (const std::string &path, Json *result) |
List directory contents for Unix filesystem objects. More... | |
void | KeyGen (const std::string &key_name, const std::string &key_type, size_t key_size, std::string *key_id) |
Generate a new key. More... | |
void | KeyList (Json *key_list) |
List all the keys. More... | |
void | KeyRm (const std::string &key_name) |
Remove a key. More... | |
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. More... | |
void | NameResolve (const std::string &name_id, std::string *path_string) |
Resolve an IPNS name. More... | |
void | ObjectNew (std::string *object_id) |
Create a new MerkleDAG node. More... | |
void | ObjectPut (const Json &object, Json *object_stored) |
Store a MerkleDAG node. More... | |
void | ObjectGet (const std::string &object_id, Json *object) |
Get a MerkleDAG node. More... | |
void | ObjectData (const std::string &object_id, std::string *data) |
Get the data field of a MerkleDAG node. More... | |
void | ObjectLinks (const std::string &object_id, Json *links) |
Get links of a MerkleDAG node. More... | |
void | ObjectStat (const std::string &object_id, Json *stat) |
Get stats about a MerkleDAG node. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
void | PinAdd (const std::string &object_id) |
Pin a given IPFS object. More... | |
void | PinLs (Json *pinned) |
List all the objects pinned to local storage. More... | |
void | PinLs (const std::string &object_id, Json *pinned) |
List the objects pinned under a specific hash. More... | |
void | PinRm (const std::string &object_id, PinRmOptions options) |
Unpin an object. More... | |
void | SwarmAddrs (Json *addresses) |
List of known addresses of each peer connected. More... | |
void | SwarmConnect (const std::string &peer) |
Open a connection to a given address. More... | |
void | SwarmDisconnect (const std::string &peer) |
Close a connection on a given address. More... | |
void | SwarmPeers (Json *peers) |
List the peers that we have connections with. More... | |
IPFS client.
It implements the interface described in https://github.com/ipfs/interface-ipfs-core. 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 | ||
) |
Constructor.
An example usage:
[in] | host | Hostname or IP address of the server to connect to. |
[in] | port | Port to connect to. |
ipfs::Client::Client | ( | const Client & | other | ) |
Copy-constructor.
[in] | other | Other client connection to be copied. |
ipfs::Client::Client | ( | Client && | other | ) |
Move-constructor.
[in,out] | other | Other client connection to be moved. |
ipfs::Client::~Client | ( | ) |
Destructor.
void ipfs::Client::BlockGet | ( | const std::string & | block_id, |
std::iostream * | block | ||
) |
Get a raw IPFS block.
Implements https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/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/interface-ipfs-core/blob/master/SPEC/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/interface-ipfs-core/blob/master/SPEC/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/interface-ipfs-core/tree/master/SPEC/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/interface-ipfs-core/tree/master/SPEC/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/interface-ipfs-core/tree/master/SPEC/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/interface-ipfs-core/blob/master/SPEC/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/interface-ipfs-core/blob/master/SPEC/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/interface-ipfs-core/tree/master/SPEC/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/interface-ipfs-core/tree/master/SPEC/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/interface-ipfs-core/blob/master/SPEC/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/interface-ipfs-core/tree/master/SPEC/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::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/interface-ipfs-core/blob/master/SPEC/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/interface-ipfs-core/blob/master/SPEC/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/interface-ipfs-core/tree/master/SPEC/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/interface-ipfs-core/tree/master/SPEC/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/interface-ipfs-core/tree/master/SPEC/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/interface-ipfs-core/tree/master/SPEC/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/interface-ipfs-core/tree/master/SPEC/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/interface-ipfs-core/tree/master/SPEC/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/interface-ipfs-core/tree/master/SPEC/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/interface-ipfs-core/tree/master/SPEC/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/interface-ipfs-core/tree/master/SPEC/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/interface-ipfs-core/tree/master/SPEC/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, ...} |
Copy assignment operator.
[in] | other | Other client connection to be copied. |
Move assignment operator.
[in,out] | other | Other client connection to be moved. |
void ipfs::Client::PinAdd | ( | const std::string & | object_id | ) |
Pin a given IPFS object.
Implements https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/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 | ( | Json * | pinned | ) |
List all the objects pinned to local storage.
Implements https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/PIN.md#pinls.
An example usage:
std::exception | if any error occurs |
[out] | pinned | List of pinned objects. |
void ipfs::Client::PinLs | ( | const std::string & | object_id, |
Json * | pinned | ||
) |
List the objects pinned under a specific hash.
Implements https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/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::PinRm | ( | const std::string & | object_id, |
PinRmOptions | options | ||
) |
Unpin an object.
Implements https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/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::SwarmAddrs | ( | Json * | addresses | ) |
List of known addresses of each peer connected.
Implements https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/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/interface-ipfs-core/blob/master/SPEC/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/interface-ipfs-core/blob/master/SPEC/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/interface-ipfs-core/blob/master/SPEC/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/interface-ipfs-core/tree/master/SPEC/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". |