Thomas Eizinger afb777e937
swarm-derive: Add prelude configuration option to NetworkBehaviour macro (#3055)
Currently, our `NetworkBehaviour` derive macro depends on the `libp2p` crate to be in scope. This prevents standalone usage which forces us to depend on `libp2p` in all our tests where we want to derive a `NetworkBehaviour`.

This PR introduces a `prelude` option that - by default - points to `libp2p::swarm::derive_prelude`, a new module added to `libp2p_swarm`. With this config option, users of `libp2p_swarm` can now refer to the macro without depending on `libp2p`, breaking the circular dependency in our workspace. For consistency with the ecosystem, the macro is now also re-exported by `libp2p_swarm` instead of `libp2p` at the same position as the trait that it implements.

Lastly, we introduce an off-by-default `macros` feature flag that shrinks the dependency tree for users that don't need the derive macro.
2022-11-12 23:59:14 +00:00
..

Examples

A set of examples showcasing how to use rust-libp2p.

Getting started

  • Ping

    Small ping clone, sending a ping to a peer, expecting a pong as a response. See tutorial for a step-by-step guide building the example.

Individual libp2p features

  • Chat

    A basic chat application demonstrating libp2p and the mDNS and floodsub protocols.

    • Gossipsub chat

      Same as the chat example but using mDNS and the Gossipsub protocol.

    • Tokio based chat

      Same as the chat example but using tokio for all asynchronous tasks and I/O.

  • Distributed key-value store

    A basic key value store demonstrating libp2p and the mDNS and Kademlia protocol.

  • Identify

    Demonstrates how to use identify protocol to query peer information.

  • IPFS Kademlia

    Demonstrates how to perform Kademlia queries on the IPFS network.

  • IPFS Private

    Implementation using the gossipsub, ping and identify protocols to implement the ipfs private swarms feature.

  • Passive Discovery via MDNS

    Discover peers on the same network via the MDNS protocol.

  • Hole punching tutorial

    Tutorial on how to overcome firewalls and NATs with libp2ps hole punching mechanism.

Integration into a larger application

  • File sharing application

    Basic file sharing application with peers either providing or locating and getting files by name.

    While obviously showcasing how to build a basic file sharing application with the Kademlia and Request-Response protocol, the actual goal of this example is to show how to integrate rust-libp2p into a larger application.