• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

vasild/cpp-ipfs-http-client: IPFS C++ HTTP API client library

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

vasild/cpp-ipfs-http-client

开源软件地址:

https://github.com/vasild/cpp-ipfs-http-client

开源编程语言:

C++ 83.6%

开源软件介绍:

IPFS C++ HTTP API client library

Build CI Status CodeQL Documentation codecov GitHub Issues GitHub pull requests

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(), rename()
  • 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!

Dependencies

When building documention, you also need:

Install

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

Hint: Only build the library without tests, use: cmake -DBUILD_TESTING=OFF ..

See the documentation for details.

Run Test cases

Only build & run the test cases, without code coverage:

mkdir build && cd build
cmake ..
make -j 8
# Run our test-cases
make our_tests

Build & run 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:BOOL=ON -DBUILD_SHARED_LIBS:BOOL=ON..
# Run tests & Build the HTML report
make ctest_coverage_html -j 8

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

Build Doxygen

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

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

Usage

#include <ipfs/client.h>

#include <iostream>
#include <sstream>

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;
}

More info see: Doxygen Docs - Client Class.

Multi-threading example

The client constructor and destructor are not thread safe. However, all the API IPFS calls are thread safe!

Note: A runtime error will be thrown on the request call (in this example the FilesGet()) when you call the Abort() method, allowing you to stop your code execution inside the thread.

An example of using a thread together with the IPFS Client:

#include <ipfs/client.h>

#include <sstream>
#include <thread>

int main(int, char**) {
  ipfs::Client client("localhost", 5001, "2m");

  // Only start one thread
  std::thread thread([&client]() {
    std::stringstream contents;
    try {
      // File should not exists, takes forever (until time-out)
      client.FilesGet("QmZp1rrtGTictR2rpNcx4673R7qU9Jdr9DQ6Z7F6Wgo2bQ",
                      &contents);
    } catch (const std::runtime_error& e) {
      std::cerr << "Error: " << e.what() << std::endl;
    }
  });

  if (thread.joinable()) {
    client.Abort();  // Abort request
    thread.join();   // Should not be blocking now
    client.Reset();  // Reset internal state
  }
  return 0;
}

See the full multi-threading example on: Doxygen - Examples.

Build via C++ compiler

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

Build via CMake

Use the C++ IPFS Client inside an existing CMake project. We add the IPFS client inside the lib folder. For example via git submodule (but git clone should also work):

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

Edit your CMakeLists.txt file to include the C++ IPFS HTTP Client in your build:

add_subdirectory (lib/ipfs-http-client)

Finally, add the C++ IPFS HTTP static library to your target using target_link_libraries()
(in this example ${PROJECT_TARGET} variable is used as target name):

set(PROJECT_TARGET my-app)

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.




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap