Skip to content

Jianghi/cpp-ipfs-http-client

 
 

Repository files navigation

IPFS C++ HTTP API client library

Build CI Status CodeQL codecov Documentation GitHub Issues GitHub pull requests CII Best Practices

IPFS C++ HTTP Client Library

Allows C++ applications to communicate with an IPFS node. It implements IPFS API bindings for C++. See the documentation and in partially the Client Class.

See also IPFS on GitHub.

The C++ API is broken up into the following sections (Note: links below go to the js-ipfs project). The following calls are implemented in cpp-ipfs-http-client:

  • Bitswap: all methods are still to-do
  • Block: get(), put(), stat()
  • Bootstrap: all methods are still to-do
  • Config: get(), set(), replace()
  • DAG: all methods are still to-do
  • DHT: findpeer(), findprovs()
  • Files: cat(), add(), ls()
  • Key: gen(), list(), rm()
  • Miscellaneous: id(), version()
  • Name: all methods are still to-do
  • Object: new(), put(), get(), data(), links(), stat(), patch.addLink(), patch.rmLink(), patch.appendData(), patch.setData()
  • Pin: add(), ls(), rm()
  • PubSub: all methods are still to-do
  • Refs: all methods are still to-do
  • Repo: stat()
  • Stats: bw(), repo() see Repo above
  • Swarm: addrs(), connect(), disconnect(), peers()

As you can see, not all methods are yet implemented.

TODO

  • Implement the missing methods
  • Contributors are welcome!

Install

git clone https://github.com/vasild/cpp-ipfs-http-client.git
cd cpp-ipfs-http-client
cmake .
make -j 6
sudo make install

See the documentation for details.

Dependencies

Build Test cases + Code Coverage

Test cases are build by default, but if you want to build with coverage:

mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Debug -DCOVERAGE=ON -DBUILD_SHARED_LIBS=ON ..
# Run tests & Build the HTML report
make ctest_coverage_html -j 6

# Or run tests & create a Cobertura XML file
make ctest_coverage_xml -j 6

Build Doxygen

Build Doxygen files locally. From the root directory of this project:

mkdir build
cd build
cmake -DDOC=ON ..
make doc

Usage

#include <iostream>
#include <sstream>

#include <ipfs/client.h>

int main(int, char**) {
  std::stringstream contents;

  ipfs::Client client("localhost", 5001);

  client.FilesGet("/ipfs/QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG/readme", &contents);

  std::cout << contents.str() << std::endl;

  return 0;
}

Build via c++ compiler

c++ -std=c++11 -I/path/to/header -L/path/to/lib -lipfs-http-client myprog.cc -o myprog

Build via CMake

An example using the CPP-IPFS project within another CMake project. For example via git submodule (but just git clone also works):

git submodule add https://github.com/vasild/cpp-ipfs-http-client.git lib/ipfs-http-client

Edit your CMakeLists.txt file to include CPP-IPFS-HTTP-client in the build:

add_subdirectory (lib/ipfs-http-client)

Finally, add the CPP-IPFS static library to your target (in this example ${PROJECT_TARGET} variable is used):

target_include_directories(${PROJECT_TARGET} PRIVATE
    ${PROJECT_SOURCE_DIR}/lib/ipfs-http-client/include
)
target_link_libraries(${PROJECT_TARGET} PRIVATE ipfs-http-client)

Contribute

Feel free to open issues and pull requests. Report vulnerabilities publicly, similar to other non-security issues.

The project adheres to the Google C++ Style Guide. Use clang-format to properly format the code when you submit patches.

Write tests for new code. Changes should not cause the code coverage to go down (ideally up).

License

The code is distributed under the MIT License.

About

IPFS C++ HTTP API client library

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 82.8%
  • CMake 17.0%
  • Shell 0.2%