Clone the repository and install the dependencies:
git clone https://github.com/vacp2p/nim-libp2p
cd nim-libp2p
nimble install -dyYou can use nix develop to start a shell with Nim and Nimble.
nimble 0.20.1 is required for running nimble test. At time of writing, this is not available in nixpkgs: If using nix develop, follow up with nimble install nimble, and use that (typically ~/.nimble/bin/nimble).
Try to compile and run a simple example to ensure that everything is working on your machine.
nim c -r examples/helloworld.nimTry out the chat example, where you can chat between two instances.
Run chat example (first instance):
nim c -r examples/directchat.nimThis will output a peer ID such as QmbmHfVvouKammmQDJck4hz33WvVktNEe7pasxz2HgseRu which you can use in second instance to connect to it.
Then run chat example again (second instance):
nim c -r examples/directchat.nimAnd then use peer ID from first instance to connect to it, by typing in second instance:
/connect QmbmHfVvouKammmQDJck4hz33WvVktNEe7pasxz2HgseRu # use peer ID from first instanceRun unit tests:
# run all the unit tests
nimble test
# run tests matching a path substring:
# - Directory name: "transports" matches all tests in transports/
# - Partial filename: "quic" matches test_quic.nim, test_quic_stream.nim, etc.
# - Exact filename: "test_ws.nim" matches only that specific file
# - Full path: "libp2p/transports/test_tcp" matches libp2p/transports/test_tcp.nim
nimble testpath quic
nimble testpath transports/test_ws
nimble testpath mix
# etc ...
# run specific test suites
nimble testmultiformatexts
nimble testintegrationFor faster iteration during development, you can bypass nimble overhead by compiling the test file directly:
# compile and run all tests
nim c -r tests/test_all.nim
# compile and run tests matching a path substring
nim c -r -d:path=quic tests/test_all.nim
nim c -r -d:path=transports/test_ws tests/test_all.nim
nim c -r -d:path=mix tests/test_all.nim
# compile and run specific test file
nim c -r tests/tools/test_multiaddress.nimnim-libp2p uses nph to format code.
Do nimble install nph@v0.7.0 once to install nph, then nimble format (or nph ./. *.nim) to format code.
nim-libp2p uses chronicles library for structured logging.
chronicles is configured at compile time. You can adjust the log detail level using compile time flags like this:
nim c -r -d:chronicles_log_level=error examples/helloworld.nimwhere chronicles_log_level can have following values: none, error, warn, info, debug and trace (values are case-insensitive).
If you are overwhelmed with logs, you can disable topics that aren’t relevant and increase the logging level for the ones that matter most:
-d:chronicles_enabled_topics:switch:TRACE,quictransport:INFO
