Skip to content

vacp2p/nim-libp2p

nim-libp2p logo

The Nim implementation of the libp2p Networking Stack.

Table of Contents

Background

libp2p is a Peer-to-Peer networking stack, with implementations in multiple languages derived from the same specifications.

Building large scale peer-to-peer systems has been complex and difficult in the last 15 years and libp2p is a way to fix that. It strives to be a modular stack with secure defaults and useful protocols, while remaining open and extensible. This is a native Nim implementation, using chronos for asynchronous execution. It's used in production by a few projects

Learn more about libp2p at libp2p.io and follow libp2p's documentation docs.libp2p.io.

Install

The currently supported Nim versions are 1.6, 2.0 and 2.2.

nimble install libp2p

You'll find the nim-libp2p documentation here. See examples for simple usage patterns.

Getting Started

Try out the chat example. For this you'll need to have go-libp2p-daemon running. Full code can be found here:

nim c -r --threads:on examples/directchat.nim

This will output a peer ID such as QmbmHfVvouKammmQDJck4hz33WvVktNEe7pasxz2HgseRu which you can use in another instance to connect to it.

./examples/directchat
/connect QmbmHfVvouKammmQDJck4hz33WvVktNEe7pasxz2HgseRu # change this hash by the hash you were given

You can now chat between the instances!

Chat example

Development

Clone the repository and install the dependencies:

git clone https://github.com/vacp2p/nim-libp2p
cd nim-libp2p
nimble install -dy

Testing

Run unit tests:

# run all the unit tests
nimble test

Obs: Running all tests requires the go-libp2p-daemon to be installed and running.

If you only want to run tests that don't require go-libp2p-daemon, use:

nimble testnative

For a list of all available test suites, use:

nimble tasks

Contribute

The libp2p implementation in Nim is a work in progress. We welcome contributors to help out! Specifically, you can:

  • Go through the modules and check out existing issues. This would be especially useful for modules in active development. Some knowledge of IPFS/libp2p may be required, as well as the infrastructure behind it.
  • Perform code reviews. Feel free to let us know if you found anything that can a) speed up the project development b) ensure better quality and c) reduce possible future bugs.
  • Add tests. Help nim-libp2p to be more robust by adding more tests to the tests folder.
  • Small PRs. Try to keep PRs atomic and digestible. This makes the review process and pinpointing bugs easier.
  • Code format. Code should be formatted with nph and follow the Status Nim Style Guide.

Contributors

nim-libp2p contributors

Core Maintainers

Richard
Richard
Vlado
Vlado
Gabe
Gabe

Compile time flags

Enable quic transport support

nim c -d:libp2p_quic_support some_file.nim

Enable expensive metrics (ie, metrics with per-peer cardinality):

nim c -d:libp2p_expensive_metrics some_file.nim

Set list of known libp2p agents for metrics:

nim c -d:libp2p_agents_metrics -d:KnownLibP2PAgents=nimbus,lighthouse,lodestar,prysm,teku some_file.nim

Specify gossipsub specific topics to measure in the metrics:

nim c -d:KnownLibP2PTopics=topic1,topic2,topic3 some_file.nim

Modules

List of packages modules implemented in nim-libp2p:

Name Description
Libp2p
libp2p The core of the project
connmanager Connection manager
identify / push identify Identify protocol
ping Ping protocol
libp2p-daemon-client go-daemon nim wrapper
interop-libp2p Interop tests
Transports
libp2p-tcp TCP transport
libp2p-ws WebSocket & WebSocket Secure transport
libp2p-tor Tor Transport
libp2p-quic Quic Transport
libp2p-memory Memory Transport
Secure Channels
libp2p-noise Noise secure channel
libp2p-plaintext Plain Text for development purposes
Stream Multiplexers
libp2p-mplex MPlex multiplexer
libp2p-yamux Yamux multiplexer
Data Types
peer-id Cryptographic identifiers
peer-store Address book of known peers
multiaddress Composable network addresses
signed-envelope Signed generic data container
routing-record Signed peer dialing informations
discovery manager Discovery Manager
Utilities
libp2p-crypto Cryptographic backend
libp2p-crypto-secp256k1
Pubsub
libp2p-pubsub Pub-Sub generic interface
libp2p-floodsub FloodSub implementation
libp2p-gossipsub GossipSub implementation

Users

nim-libp2p is used by:

  • Nimbus, an Ethereum client
  • nwaku, a decentralized messaging application
  • nim-codex, a decentralized storage application
  • (open a pull request if you want to be included here)

Stability

nim-libp2p has been used in production for over a year in high-stake scenarios, so its core is considered stable. Some modules are more recent and less stable.

The versioning follows semver, with some additions:

  • Some of libp2p procedures are marked as .public., they will remain compatible during each MAJOR version
  • The rest of the procedures are considered internal, and can change at any MINOR version (but remain compatible for each new PATCH)

We aim to be compatible at all time with at least 2 Nim MINOR versions, currently 1.6 & 2.0

License

Licensed and distributed under either of

or

at your option. These files may not be copied, modified, or distributed except according to those terms.

Packages

No packages published

Contributors 46

Languages