c-libp2p is an implementation of the libp2p specification written in C. The project is still in active development but already provides the building blocks needed for peer-to-peer networking applications.
c-libp2p uses CMake and should build on Linux, macOS and Windows. A C compiler that supports the C11 standard is required.
git clone --recursive https://github.com/Pier-Two/c-libp2p.git
cd c-libp2pThe --recursive flag ensures that all third-party submodules are fetched.
mkdir build
cmake -S . -B build
cmake --build build
ctest --test-dir buildSanitizers can be enabled with -DENABLE_SANITIZERS=ON and additional flags in SANITIZERS. Stress tests for the TCP module are built when -DENABLE_STRESS_TESTS=ON is passed.
A recent Visual Studio with CMake support is recommended. From the x64 Native Tools command prompt run:
mkdir build
cmake -S . -B build -G "Visual Studio 16 2019" -A x64
cmake --build build --config Release
ctest --test-dir build -C ReleaseWhen building shared libraries on Windows the produced DLLs are copied next to the test executables automatically.
Validation is split into two lanes:
- Fast lane (
.github/workflows/ci-fast.yml, required for PRs):macos-smokelinux-smokewindows-smoke
- Full lane (
.github/workflows/ci-full.yml, runs onmain, nightly, and manual dispatch):macos-fulllinux-gcc-fulllinux-clang-fulllinux-sanitizers(ASan/UBSan)windows-full
The lane presets are versioned in CMakePresets.json and can be run locally:
# fast lane (macOS example)
cmake --preset macos-smoke
cmake --build --preset macos-smoke
ctest --preset macos-smoke
# full lane (macOS example)
cmake --preset macos-full
cmake --build --preset macos-full
ctest --preset macos-fullFor Windows validation from non-Windows development machines, trigger and monitor the full lane with GitHub CLI:
gh workflow run ci-full.yml --ref <branch>
gh run list --workflow ci-full.yml
gh run watch <run-id>
gh run view <run-id> --logInstall the repository-managed git hooks:
scripts/dev/install-hooks.shThis configures core.hooksPath to .githooks and enables a pre-push hook that runs the same macOS/Linux fast-lane checks used by CI.
On Linux, fast-lane checks include:
- clang-format diff check for changed
src/,include/, andtestsC files. - a targeted Doxygen documentation gate for changed headers in
include/multiformats/unsigned_varint/andinclude/multiformats/multicodec/(WARN_IF_UNDOCUMENTED=YES,WARN_AS_ERROR=YES). - a targeted MISRA add-on check for rewritten multiformats scope (
unsigned_varint+multicodec) with documented Rule 8.7 advisory suppressions for exported API symbols. - a targeted
clang-tidyCERT gate (-checks=-*,cert-*, warnings-as-errors) for changed C sources insrc/multiformats/{unsigned_varint,multicodec}. cppchecksmoke static analysis for core scope.
Manual local run:
# Auto-detect host platform (macOS or Linux)
scripts/dev/run-fast-lane-local.sh
# Force a specific platform script
scripts/dev/run-fast-lane-local.sh --platform macos
scripts/dev/run-fast-lane-local.sh --platform linuxTo bypass the hook for one push:
LIBP2P_SKIP_FAST_HOOK=1 git pushsrc/– library source codeinclude/– public headerstests/– unit testsbenchmarks/– optional benchmarksdocs/– user guides and examples
Detailed documentation is available under docs/.
c-libp2p bundles several third-party projects under external/:
- libtomcrypt and libtommath – LibTom License
- secp256k1 – MIT License
- sha3 – MIT-0 License
- WjCryptLib – Unlicense
- c20p1305 – MIT License
- libeddsa – Unlicense
- noise-c – MIT License
Please refer to each submodule for license details.
The code in this repository is licensed under the MIT License.