├── .dockerignore ├── .editorconfig ├── .git-blame-ignore-revs ├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.yml │ ├── config.yml │ ├── enhancement.yml │ └── feature_request.yml ├── dependabot.yml ├── mergify.yml ├── pull_request_template.md └── workflows │ ├── cache-factory.yml │ ├── cargo-audit.yml │ ├── ci.yml │ ├── docker-image.yml │ ├── docs.yml │ ├── interop-test.yml │ ├── semantic-pull-request.yml │ └── stale.yml ├── .gitignore ├── CHANGELOG.md ├── CONTRIBUTING.md ├── Cargo.lock ├── Cargo.toml ├── FUNDING.json ├── LICENSE ├── README.md ├── ROADMAP.md ├── SECURITY.md ├── clippy.toml ├── core ├── CHANGELOG.md ├── Cargo.toml ├── src │ ├── connection.rs │ ├── either.rs │ ├── generated │ │ ├── envelope.proto │ │ ├── envelope_proto.rs │ │ ├── mod.rs │ │ ├── peer_record.proto │ │ └── peer_record_proto.rs │ ├── lib.rs │ ├── muxing.rs │ ├── muxing │ │ └── boxed.rs │ ├── peer_record.rs │ ├── signed_envelope.rs │ ├── transport.rs │ ├── transport │ │ ├── and_then.rs │ │ ├── boxed.rs │ │ ├── choice.rs │ │ ├── dummy.rs │ │ ├── global_only.rs │ │ ├── map.rs │ │ ├── map_err.rs │ │ ├── memory.rs │ │ ├── optional.rs │ │ ├── timeout.rs │ │ └── upgrade.rs │ ├── upgrade.rs │ └── upgrade │ │ ├── apply.rs │ │ ├── denied.rs │ │ ├── either.rs │ │ ├── error.rs │ │ ├── pending.rs │ │ ├── ready.rs │ │ └── select.rs └── tests │ └── transport_upgrade.rs ├── deny.toml ├── docs ├── architecture.svg ├── coding-guidelines.md ├── maintainer-handbook.md └── release.md ├── examples ├── README.md ├── autonat │ ├── Cargo.toml │ ├── README.md │ └── src │ │ └── bin │ │ ├── autonat_client.rs │ │ └── autonat_server.rs ├── autonatv2 │ ├── Cargo.toml │ ├── Dockerfile │ ├── docker-compose.yml │ └── src │ │ └── bin │ │ ├── autonatv2_client.rs │ │ └── autonatv2_server.rs ├── browser-webrtc │ ├── Cargo.toml │ ├── README.md │ ├── src │ │ ├── lib.rs │ │ └── main.rs │ └── static │ │ └── index.html ├── chat │ ├── Cargo.toml │ ├── README.md │ └── src │ │ └── main.rs ├── dcutr │ ├── Cargo.toml │ ├── README.md │ └── src │ │ └── main.rs ├── distributed-key-value-store │ ├── Cargo.toml │ ├── README.md │ └── src │ │ └── main.rs ├── file-sharing │ ├── Cargo.toml │ ├── README.md │ └── src │ │ ├── main.rs │ │ └── network.rs ├── identify │ ├── Cargo.toml │ ├── README.md │ └── src │ │ └── main.rs ├── ipfs-kad │ ├── Cargo.toml │ ├── README.md │ └── src │ │ └── main.rs ├── ipfs-private │ ├── Cargo.toml │ ├── README.md │ └── src │ │ └── main.rs ├── metrics │ ├── Cargo.toml │ ├── README.md │ ├── docker-compose.yml │ ├── otel-collector-config.yaml │ └── src │ │ ├── http_service.rs │ │ └── main.rs ├── ping │ ├── Cargo.toml │ ├── README.md │ └── src │ │ └── main.rs ├── relay-server │ ├── Cargo.toml │ ├── README.md │ └── src │ │ └── main.rs ├── rendezvous │ ├── Cargo.toml │ ├── README.md │ └── src │ │ ├── bin │ │ ├── rzv-discover.rs │ │ ├── rzv-identify.rs │ │ └── rzv-register.rs │ │ └── main.rs ├── stream │ ├── Cargo.toml │ ├── README.md │ └── src │ │ └── main.rs └── upnp │ ├── Cargo.toml │ ├── README.md │ └── src │ └── main.rs ├── hole-punching-tests ├── Cargo.toml ├── Dockerfile ├── src │ └── main.rs └── version.json ├── identity ├── CHANGELOG.md ├── Cargo.toml ├── benches │ └── peer_id.rs ├── src │ ├── ecdsa.rs │ ├── ed25519.rs │ ├── error.rs │ ├── generated │ │ ├── keys.proto │ │ ├── keys_proto.rs │ │ └── mod.rs │ ├── keypair.rs │ ├── lib.rs │ ├── peer_id.rs │ ├── rsa.rs │ ├── secp256k1.rs │ └── test │ │ ├── rsa-2048.pk8 │ │ ├── rsa-3072.pk8 │ │ └── rsa-4096.pk8 └── tests │ ├── keypair_api.rs │ └── serde.rs ├── interop-tests ├── Cargo.toml ├── Dockerfile.chromium ├── Dockerfile.native ├── README.md ├── chromium-ping-version.json ├── native-ping-version.json ├── pkg │ └── readme.md └── src │ ├── arch.rs │ ├── bin │ ├── config │ │ └── mod.rs │ ├── native_ping.rs │ └── wasm_ping.rs │ └── lib.rs ├── libp2p ├── CHANGELOG.md ├── Cargo.toml └── src │ ├── bandwidth.rs │ ├── builder.rs │ ├── builder │ ├── phase.rs │ ├── phase │ │ ├── bandwidth_logging.rs │ │ ├── bandwidth_metrics.rs │ │ ├── behaviour.rs │ │ ├── build.rs │ │ ├── dns.rs │ │ ├── identity.rs │ │ ├── other_transport.rs │ │ ├── provider.rs │ │ ├── quic.rs │ │ ├── relay.rs │ │ ├── swarm.rs │ │ ├── tcp.rs │ │ └── websocket.rs │ ├── select_muxer.rs │ └── select_security.rs │ ├── lib.rs │ ├── transport_ext.rs │ ├── tutorials.rs │ └── tutorials │ ├── hole_punching.rs │ └── ping.rs ├── misc ├── allow-block-list │ ├── CHANGELOG.md │ ├── Cargo.toml │ └── src │ │ └── lib.rs ├── connection-limits │ ├── CHANGELOG.md │ ├── Cargo.toml │ └── src │ │ └── lib.rs ├── keygen │ ├── Cargo.toml │ └── src │ │ ├── config.rs │ │ └── main.rs ├── memory-connection-limits │ ├── CHANGELOG.md │ ├── Cargo.toml │ ├── src │ │ └── lib.rs │ └── tests │ │ ├── max_bytes.rs │ │ ├── max_percentage.rs │ │ └── util │ │ └── mod.rs ├── metrics │ ├── CHANGELOG.md │ ├── Cargo.toml │ └── src │ │ ├── bandwidth.rs │ │ ├── dcutr.rs │ │ ├── gossipsub.rs │ │ ├── identify.rs │ │ ├── kad.rs │ │ ├── lib.rs │ │ ├── ping.rs │ │ ├── protocol_stack.rs │ │ ├── relay.rs │ │ └── swarm.rs ├── multistream-select │ ├── CHANGELOG.md │ ├── Cargo.toml │ └── src │ │ ├── dialer_select.rs │ │ ├── length_delimited.rs │ │ ├── lib.rs │ │ ├── listener_select.rs │ │ ├── negotiated.rs │ │ └── protocol.rs ├── peer-store │ ├── CHANGELOG.md │ ├── Cargo.toml │ └── src │ │ ├── behaviour.rs │ │ ├── lib.rs │ │ ├── memory_store.rs │ │ └── store.rs ├── quick-protobuf-codec │ ├── CHANGELOG.md │ ├── Cargo.toml │ ├── benches │ │ └── codec.rs │ ├── src │ │ ├── generated │ │ │ ├── mod.rs │ │ │ ├── test.proto │ │ │ └── test.rs │ │ └── lib.rs │ └── tests │ │ └── large_message.rs ├── quickcheck-ext │ ├── Cargo.toml │ └── src │ │ └── lib.rs ├── rw-stream-sink │ ├── CHANGELOG.md │ ├── Cargo.toml │ └── src │ │ └── lib.rs ├── server │ ├── CHANGELOG.md │ ├── Cargo.toml │ ├── Dockerfile │ ├── README.md │ └── src │ │ ├── behaviour.rs │ │ ├── config.rs │ │ ├── http_service.rs │ │ └── main.rs └── webrtc-utils │ ├── CHANGELOG.md │ ├── Cargo.toml │ └── src │ ├── fingerprint.rs │ ├── generated │ ├── message.proto │ ├── mod.rs │ └── webrtc │ │ ├── mod.rs │ │ └── pb.rs │ ├── lib.rs │ ├── noise.rs │ ├── sdp.rs │ ├── stream.rs │ ├── stream │ ├── drop_listener.rs │ ├── framed_dc.rs │ └── state.rs │ └── transport.rs ├── muxers ├── mplex │ ├── CHANGELOG.md │ ├── Cargo.toml │ ├── benches │ │ └── split_send_size.rs │ ├── src │ │ ├── codec.rs │ │ ├── config.rs │ │ ├── io.rs │ │ └── lib.rs │ └── tests │ │ └── compliance.rs ├── test-harness │ ├── Cargo.toml │ └── src │ │ └── lib.rs └── yamux │ ├── CHANGELOG.md │ ├── Cargo.toml │ ├── src │ └── lib.rs │ └── tests │ └── compliance.rs ├── protocols ├── autonat │ ├── CHANGELOG.md │ ├── Cargo.toml │ ├── src │ │ ├── lib.rs │ │ ├── v1.rs │ │ ├── v1 │ │ │ ├── behaviour.rs │ │ │ ├── behaviour │ │ │ │ ├── as_client.rs │ │ │ │ └── as_server.rs │ │ │ ├── generated │ │ │ │ ├── mod.rs │ │ │ │ ├── structs.proto │ │ │ │ └── structs.rs │ │ │ └── protocol.rs │ │ ├── v2.rs │ │ └── v2 │ │ │ ├── client.rs │ │ │ ├── client │ │ │ ├── behaviour.rs │ │ │ ├── handler.rs │ │ │ └── handler │ │ │ │ ├── dial_back.rs │ │ │ │ └── dial_request.rs │ │ │ ├── generated │ │ │ ├── mod.rs │ │ │ ├── structs.proto │ │ │ └── structs.rs │ │ │ ├── protocol.rs │ │ │ ├── server.rs │ │ │ └── server │ │ │ ├── behaviour.rs │ │ │ ├── handler.rs │ │ │ └── handler │ │ │ ├── dial_back.rs │ │ │ └── dial_request.rs │ └── tests │ │ ├── autonatv2.rs │ │ ├── test_client.rs │ │ └── test_server.rs ├── dcutr │ ├── CHANGELOG.md │ ├── Cargo.toml │ ├── src │ │ ├── behaviour.rs │ │ ├── generated │ │ │ ├── holepunch │ │ │ │ ├── mod.rs │ │ │ │ └── pb.rs │ │ │ ├── message.proto │ │ │ └── mod.rs │ │ ├── handler.rs │ │ ├── handler │ │ │ └── relayed.rs │ │ ├── lib.rs │ │ ├── protocol.rs │ │ └── protocol │ │ │ ├── inbound.rs │ │ │ └── outbound.rs │ └── tests │ │ └── lib.rs ├── floodsub │ ├── CHANGELOG.md │ ├── Cargo.toml │ └── src │ │ ├── generated │ │ ├── floodsub │ │ │ ├── mod.rs │ │ │ └── pb.rs │ │ ├── mod.rs │ │ └── rpc.proto │ │ ├── layer.rs │ │ ├── lib.rs │ │ ├── protocol.rs │ │ └── topic.rs ├── gossipsub │ ├── CHANGELOG.md │ ├── Cargo.toml │ ├── src │ │ ├── backoff.rs │ │ ├── behaviour.rs │ │ ├── behaviour │ │ │ └── tests.rs │ │ ├── config.rs │ │ ├── error.rs │ │ ├── generated │ │ │ ├── compat.proto │ │ │ ├── compat │ │ │ │ ├── mod.rs │ │ │ │ └── pb.rs │ │ │ ├── gossipsub │ │ │ │ ├── mod.rs │ │ │ │ └── pb.rs │ │ │ ├── mod.rs │ │ │ └── rpc.proto │ │ ├── gossip_promises.rs │ │ ├── handler.rs │ │ ├── lib.rs │ │ ├── mcache.rs │ │ ├── metrics.rs │ │ ├── peer_score.rs │ │ ├── peer_score │ │ │ ├── params.rs │ │ │ └── tests.rs │ │ ├── protocol.rs │ │ ├── rpc.rs │ │ ├── rpc_proto.rs │ │ ├── subscription_filter.rs │ │ ├── time_cache.rs │ │ ├── topic.rs │ │ ├── transform.rs │ │ └── types.rs │ └── tests │ │ └── smoke.rs ├── identify │ ├── CHANGELOG.md │ ├── Cargo.toml │ ├── src │ │ ├── behaviour.rs │ │ ├── generated │ │ │ ├── mod.rs │ │ │ ├── structs.proto │ │ │ └── structs.rs │ │ ├── handler.rs │ │ ├── lib.rs │ │ └── protocol.rs │ └── tests │ │ └── smoke.rs ├── kad │ ├── CHANGELOG.md │ ├── Cargo.toml │ ├── src │ │ ├── addresses.rs │ │ ├── behaviour.rs │ │ ├── behaviour │ │ │ └── test.rs │ │ ├── bootstrap.rs │ │ ├── generated │ │ │ ├── dht.proto │ │ │ ├── dht │ │ │ │ ├── mod.rs │ │ │ │ └── pb.rs │ │ │ └── mod.rs │ │ ├── handler.rs │ │ ├── jobs.rs │ │ ├── kbucket.rs │ │ ├── kbucket │ │ │ ├── bucket.rs │ │ │ ├── entry.rs │ │ │ └── key.rs │ │ ├── lib.rs │ │ ├── protocol.rs │ │ ├── query.rs │ │ ├── query │ │ │ ├── peers.rs │ │ │ └── peers │ │ │ │ ├── closest.rs │ │ │ │ ├── closest │ │ │ │ └── disjoint.rs │ │ │ │ └── fixed.rs │ │ ├── record.rs │ │ └── record │ │ │ ├── store.rs │ │ │ └── store │ │ │ └── memory.rs │ └── tests │ │ └── client_mode.rs ├── mdns │ ├── CHANGELOG.md │ ├── Cargo.toml │ ├── src │ │ ├── behaviour.rs │ │ ├── behaviour │ │ │ ├── iface.rs │ │ │ ├── iface │ │ │ │ ├── dns.rs │ │ │ │ └── query.rs │ │ │ ├── socket.rs │ │ │ └── timer.rs │ │ └── lib.rs │ └── tests │ │ ├── use-async-std.rs │ │ └── use-tokio.rs ├── perf │ ├── CHANGELOG.md │ ├── Cargo.toml │ ├── Dockerfile │ ├── src │ │ ├── bin │ │ │ └── perf.rs │ │ ├── client.rs │ │ ├── client │ │ │ ├── behaviour.rs │ │ │ └── handler.rs │ │ ├── lib.rs │ │ ├── protocol.rs │ │ ├── server.rs │ │ └── server │ │ │ ├── behaviour.rs │ │ │ └── handler.rs │ └── tests │ │ └── lib.rs ├── ping │ ├── CHANGELOG.md │ ├── Cargo.toml │ ├── src │ │ ├── handler.rs │ │ ├── lib.rs │ │ └── protocol.rs │ └── tests │ │ └── ping.rs ├── relay │ ├── CHANGELOG.md │ ├── Cargo.toml │ ├── src │ │ ├── behaviour.rs │ │ ├── behaviour │ │ │ ├── handler.rs │ │ │ └── rate_limiter.rs │ │ ├── copy_future.rs │ │ ├── generated │ │ │ ├── message.proto │ │ │ ├── message_v2 │ │ │ │ ├── mod.rs │ │ │ │ └── pb.rs │ │ │ └── mod.rs │ │ ├── lib.rs │ │ ├── multiaddr_ext.rs │ │ ├── priv_client.rs │ │ ├── priv_client │ │ │ ├── handler.rs │ │ │ └── transport.rs │ │ ├── protocol.rs │ │ └── protocol │ │ │ ├── inbound_hop.rs │ │ │ ├── inbound_stop.rs │ │ │ ├── outbound_hop.rs │ │ │ └── outbound_stop.rs │ └── tests │ │ └── lib.rs ├── rendezvous │ ├── CHANGELOG.md │ ├── Cargo.toml │ ├── src │ │ ├── client.rs │ │ ├── codec.rs │ │ ├── generated │ │ │ ├── mod.rs │ │ │ ├── rendezvous │ │ │ │ ├── mod.rs │ │ │ │ └── pb.rs │ │ │ └── rpc.proto │ │ ├── lib.rs │ │ └── server.rs │ └── tests │ │ └── rendezvous.rs ├── request-response │ ├── CHANGELOG.md │ ├── Cargo.toml │ ├── src │ │ ├── cbor.rs │ │ ├── codec.rs │ │ ├── handler.rs │ │ ├── handler │ │ │ └── protocol.rs │ │ ├── json.rs │ │ └── lib.rs │ └── tests │ │ ├── error_reporting.rs │ │ ├── peer_address.rs │ │ └── ping.rs ├── stream │ ├── CHANGELOG.md │ ├── Cargo.toml │ ├── README.md │ ├── src │ │ ├── behaviour.rs │ │ ├── control.rs │ │ ├── handler.rs │ │ ├── lib.rs │ │ ├── shared.rs │ │ └── upgrade.rs │ └── tests │ │ └── lib.rs └── upnp │ ├── CHANGELOG.md │ ├── Cargo.toml │ └── src │ ├── behaviour.rs │ ├── lib.rs │ └── tokio.rs ├── rustfmt.toml ├── scripts ├── add-changelog-header.sh ├── build-interop-image.sh ├── ensure-version-bump-and-changelog.sh ├── fix-unreachable-pub.py └── list-external-contributors.sh ├── swarm-derive ├── CHANGELOG.md ├── Cargo.toml └── src │ ├── lib.rs │ └── syn_ext.rs ├── swarm-test ├── CHANGELOG.md ├── Cargo.toml └── src │ └── lib.rs ├── swarm ├── CHANGELOG.md ├── Cargo.toml ├── benches │ └── connection_handler.rs ├── src │ ├── behaviour.rs │ ├── behaviour │ │ ├── either.rs │ │ ├── external_addresses.rs │ │ ├── listen_addresses.rs │ │ ├── peer_addresses.rs │ │ └── toggle.rs │ ├── connection.rs │ ├── connection │ │ ├── error.rs │ │ ├── pool.rs │ │ ├── pool │ │ │ ├── concurrent_dial.rs │ │ │ └── task.rs │ │ └── supported_protocols.rs │ ├── dial_opts.rs │ ├── dummy.rs │ ├── executor.rs │ ├── handler.rs │ ├── handler │ │ ├── either.rs │ │ ├── map_in.rs │ │ ├── map_out.rs │ │ ├── multi.rs │ │ ├── one_shot.rs │ │ ├── pending.rs │ │ └── select.rs │ ├── lib.rs │ ├── listen_opts.rs │ ├── stream.rs │ ├── stream_protocol.rs │ ├── test.rs │ ├── translation.rs │ └── upgrade.rs └── tests │ ├── connection_close.rs │ ├── listener.rs │ ├── swarm_derive.rs │ └── ui │ └── fail │ ├── prelude_not_string.rs │ ├── prelude_not_string.stderr │ ├── to_swarm_not_string.rs │ └── to_swarm_not_string.stderr ├── transports ├── dns │ ├── CHANGELOG.md │ ├── Cargo.toml │ └── src │ │ └── lib.rs ├── noise │ ├── CHANGELOG.md │ ├── Cargo.toml │ ├── src │ │ ├── generated │ │ │ ├── mod.rs │ │ │ ├── payload.proto │ │ │ └── payload │ │ │ │ ├── mod.rs │ │ │ │ └── proto.rs │ │ ├── io.rs │ │ ├── io │ │ │ ├── framed.rs │ │ │ └── handshake.rs │ │ ├── lib.rs │ │ └── protocol.rs │ └── tests │ │ ├── smoke.rs │ │ └── webtransport_certhashes.rs ├── plaintext │ ├── CHANGELOG.md │ ├── Cargo.toml │ ├── src │ │ ├── error.rs │ │ ├── generated │ │ │ ├── mod.rs │ │ │ ├── structs.proto │ │ │ └── structs.rs │ │ ├── handshake.rs │ │ └── lib.rs │ └── tests │ │ └── smoke.rs ├── pnet │ ├── CHANGELOG.md │ ├── Cargo.toml │ ├── src │ │ ├── crypt_writer.rs │ │ └── lib.rs │ └── tests │ │ └── smoke.rs ├── quic │ ├── CHANGELOG.md │ ├── Cargo.toml │ ├── src │ │ ├── config.rs │ │ ├── connection.rs │ │ ├── connection │ │ │ ├── connecting.rs │ │ │ └── stream.rs │ │ ├── hole_punching.rs │ │ ├── lib.rs │ │ ├── provider.rs │ │ ├── provider │ │ │ ├── async_std.rs │ │ │ └── tokio.rs │ │ └── transport.rs │ └── tests │ │ ├── smoke.rs │ │ └── stream_compliance.rs ├── tcp │ ├── CHANGELOG.md │ ├── Cargo.toml │ └── src │ │ ├── lib.rs │ │ ├── provider.rs │ │ └── provider │ │ ├── async_io.rs │ │ └── tokio.rs ├── tls │ ├── CHANGELOG.md │ ├── Cargo.toml │ ├── src │ │ ├── certificate.rs │ │ ├── lib.rs │ │ ├── test_assets │ │ │ ├── ed25519.der │ │ │ ├── ed448.der │ │ │ ├── gen.sh │ │ │ ├── nistp256_sha256.der │ │ │ ├── nistp384_sha256.der │ │ │ ├── nistp384_sha384.der │ │ │ ├── nistp521_sha512.der │ │ │ ├── openssl.cfg │ │ │ ├── pkcs1_sha256.der │ │ │ ├── rsa_pkcs1_sha256.der │ │ │ ├── rsa_pkcs1_sha384.der │ │ │ ├── rsa_pkcs1_sha512.der │ │ │ └── rsa_pss_sha384.der │ │ ├── upgrade.rs │ │ └── verifier.rs │ └── tests │ │ └── smoke.rs ├── uds │ ├── CHANGELOG.md │ ├── Cargo.toml │ └── src │ │ └── lib.rs ├── webrtc-websys │ ├── CHANGELOG.md │ ├── Cargo.toml │ ├── README.md │ └── src │ │ ├── connection.rs │ │ ├── error.rs │ │ ├── lib.rs │ │ ├── sdp.rs │ │ ├── stream.rs │ │ ├── stream │ │ └── poll_data_channel.rs │ │ ├── transport.rs │ │ └── upgrade.rs ├── webrtc │ ├── CHANGELOG.md │ ├── Cargo.toml │ ├── src │ │ ├── lib.rs │ │ └── tokio │ │ │ ├── certificate.rs │ │ │ ├── connection.rs │ │ │ ├── error.rs │ │ │ ├── fingerprint.rs │ │ │ ├── mod.rs │ │ │ ├── req_res_chan.rs │ │ │ ├── sdp.rs │ │ │ ├── stream.rs │ │ │ ├── transport.rs │ │ │ ├── udp_mux.rs │ │ │ └── upgrade.rs │ └── tests │ │ └── smoke.rs ├── websocket-websys │ ├── CHANGELOG.md │ ├── Cargo.toml │ └── src │ │ ├── lib.rs │ │ └── web_context.rs ├── websocket │ ├── CHANGELOG.md │ ├── Cargo.toml │ └── src │ │ ├── error.rs │ │ ├── framed.rs │ │ ├── lib.rs │ │ ├── quicksink.rs │ │ └── tls.rs └── webtransport-websys │ ├── CHANGELOG.md │ ├── Cargo.toml │ └── src │ ├── bindings.rs │ ├── connection.rs │ ├── endpoint.rs │ ├── error.rs │ ├── fused_js_promise.rs │ ├── lib.rs │ ├── stream.rs │ ├── transport.rs │ └── utils.rs └── wasm-tests ├── README.md ├── run-all.sh └── webtransport-tests ├── Cargo.toml ├── README.md ├── echo-server ├── .gitignore ├── Dockerfile ├── go.mod ├── go.sum └── main.go ├── run.sh └── src └── lib.rs /.dockerignore: -------------------------------------------------------------------------------- 1 | target 2 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | [*] 3 | indent_style=space 4 | indent_size=4 5 | end_of_line=lf 6 | charset=utf-8 7 | trim_trailing_whitespace=true 8 | max_line_length=100 9 | insert_final_newline=true 10 | -------------------------------------------------------------------------------- /.git-blame-ignore-revs: -------------------------------------------------------------------------------- 1 | # This file contains revisions that are to be ignored by git when running `git blame`. 2 | # 3 | # This does NOT work automatically, you first need to tell Git about this file. 4 | # To do so, run `git config --global blame.ignoreRevsFile .git-blame-ignore-revs`. 5 | # You may want to run this without `--global` if you have a different naming convention for this file in other repositories. 6 | # 7 | # Format with rustfmt 8 | f701b24ec0f99be49444a6e7de950c66b01b2f3f 9 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.yml: -------------------------------------------------------------------------------- 1 | name: Bug Report 2 | description: Create a bug report for rust-libp2p 3 | 4 | body: 5 | - type: markdown 6 | attributes: 7 | value: | 8 | Thank you for filing a bug report! 9 | - type: textarea 10 | attributes: 11 | label: Summary 12 | description: Please provide a short summary of the bug, along with any information you feel is relevant to replicate the bug. 13 | validations: 14 | required: true 15 | - type: textarea 16 | attributes: 17 | label: Expected behavior 18 | description: Describe what you expect to happen. 19 | validations: 20 | required: true 21 | - type: textarea 22 | attributes: 23 | label: Actual behavior 24 | description: Describe what actually happens. 25 | validations: 26 | required: true 27 | - type: textarea 28 | attributes: 29 | label: Relevant log output 30 | description: Please copy and paste any relevant log output. This will be automatically formatted into code, so no need for backticks. 31 | render: shell 32 | validations: 33 | required: false 34 | - type: textarea 35 | attributes: 36 | label: Possible Solution 37 | description: Suggest a fix/reason for the bug, or ideas on how to implement the addition or change. 38 | validations: 39 | required: false 40 | - type: textarea 41 | attributes: 42 | label: Version 43 | description: Which version of libp2p are you using? libp2p version (version number, commit, or branch) 44 | validations: 45 | required: false 46 | - type: dropdown 47 | attributes: 48 | label: Would you like to work on fixing this bug? 49 | description: Any contribution towards fixing the bug is greatly appreciated. We are more than happy to provide help on the process. 50 | options: 51 | - "Yes" 52 | - "No" 53 | - Maybe 54 | validations: 55 | required: true 56 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: true 2 | contact_links: 3 | - name: Technical Questions 4 | url: https://github.com/libp2p/rust-libp2p/discussions/new?category=q-a 5 | about: Please ask technical questions in the rust-libp2p GitHub Discussions forum. 6 | - name: Community-wide libp2p Discussion 7 | url: https://discuss.libp2p.io 8 | about: Discussions and questions about the libp2p community. 9 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/enhancement.yml: -------------------------------------------------------------------------------- 1 | name: Enhancement 2 | description: Suggest an improvement to an existing rust-libp2p feature. 3 | body: 4 | - type: textarea 5 | attributes: 6 | label: Description 7 | description: Describe the enhancement that you are proposing. 8 | validations: 9 | required: true 10 | - type: textarea 11 | attributes: 12 | label: Motivation 13 | description: Explain why this enhancement is beneficial. 14 | validations: 15 | required: true 16 | - type: textarea 17 | attributes: 18 | label: Current Implementation 19 | description: Describe the current implementation. 20 | validations: 21 | required: true 22 | - type: dropdown 23 | attributes: 24 | label: Are you planning to do it yourself in a pull request? 25 | description: Any contribution is greatly appreciated. We are more than happy to provide help on the process. 26 | options: 27 | - "Yes" 28 | - "No" 29 | - Maybe 30 | validations: 31 | required: true 32 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.yml: -------------------------------------------------------------------------------- 1 | name: Feature request 2 | description: Suggest a new feature in rust-libp2p 3 | body: 4 | - type: markdown 5 | attributes: 6 | value: | 7 | If you'd like to suggest a feature related to libp2p but not specifically related to the rust implementation, please file an issue at https://github.com/libp2p/specs instead. 8 | - type: textarea 9 | attributes: 10 | label: Description 11 | description: Briefly describe the feature that you are requesting. 12 | validations: 13 | required: true 14 | - type: textarea 15 | attributes: 16 | label: Motivation 17 | description: Explain why this feature is needed. 18 | validations: 19 | required: true 20 | - type: textarea 21 | attributes: 22 | label: Requirements 23 | description: Write a list of what you want this feature to do. 24 | placeholder: "1." 25 | validations: 26 | required: true 27 | - type: textarea 28 | attributes: 29 | label: Open questions 30 | description: Use this section to ask any questions that are related to the feature. 31 | validations: 32 | required: false 33 | - type: dropdown 34 | attributes: 35 | label: Are you planning to do it yourself in a pull request? 36 | description: Any contribution is greatly appreciated. We are more than happy to provide help on the process. 37 | options: 38 | - "Yes" 39 | - "No" 40 | - Maybe 41 | validations: 42 | required: true 43 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "cargo" 4 | directory: "/" 5 | schedule: 6 | interval: "weekly" 7 | open-pull-requests-limit: 9999 8 | commit-message: 9 | prefix: "deps" 10 | rebase-strategy: "disabled" 11 | groups: 12 | hickory-dns: 13 | patterns: 14 | - "hickory-*" 15 | - "async-std-resolver" 16 | opentelemetry: 17 | patterns: 18 | - "opentelemetry*" 19 | - "tracing-opentelemetry" 20 | axum: 21 | patterns: 22 | - "axum" 23 | - "tower" 24 | - "tower-http" 25 | webrtc: 26 | patterns: 27 | - "rcgen" 28 | - "webrtc" 29 | - package-ecosystem: "github-actions" 30 | directory: "/" 31 | schedule: 32 | interval: "daily" 33 | commit-message: 34 | prefix: "deps" 35 | rebase-strategy: "disabled" 36 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | ## Description 2 | 3 | 14 | 15 | ## Notes & open questions 16 | 17 | 20 | 21 | ## Change checklist 22 | 23 | 24 | 25 | - [ ] I have performed a self-review of my own code 26 | - [ ] I have made corresponding changes to the documentation 27 | - [ ] I have added tests that prove my fix is effective or that my feature works 28 | - [ ] A changelog entry has been made in the appropriate crates 29 | -------------------------------------------------------------------------------- /.github/workflows/cache-factory.yml: -------------------------------------------------------------------------------- 1 | # This workflow _produces_ a cache that is used to speed up pull request builds. 2 | # 3 | # Our CI runs a job per crate, meaning all jobs share compilation artifacts but never the full cache. 4 | # Thus, we make a single cache here that is used by all jobs and the jobs only read from this cache. 5 | 6 | name: Cache factory 7 | 8 | on: 9 | push: 10 | branches: 11 | - master # Caches are only created on master branch. 12 | 13 | concurrency: 14 | group: ${{ github.workflow }}-${{ github.ref }} 15 | cancel-in-progress: true 16 | 17 | jobs: 18 | make_stable_rust_cache: 19 | runs-on: ubuntu-latest 20 | steps: 21 | - uses: actions/checkout@v4 22 | 23 | - uses: dtolnay/rust-toolchain@stable 24 | 25 | - uses: Swatinem/rust-cache@9d47c6ad4b02e050fd481d890b2ea34778fd09d6 # v2.7.8 26 | with: 27 | shared-key: stable-cache 28 | 29 | - name: Compile workspace with stable Rust 30 | run: cargo test --all-features --all-targets --workspace --no-run 31 | -------------------------------------------------------------------------------- /.github/workflows/cargo-audit.yml: -------------------------------------------------------------------------------- 1 | name: cargo audit 2 | on: 3 | schedule: 4 | - cron: '0 0 * * *' 5 | 6 | jobs: 7 | audit: 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: actions/checkout@v4 11 | - uses: actions-rs/audit-check@v1 12 | with: 13 | token: ${{ secrets.GITHUB_TOKEN }} 14 | -------------------------------------------------------------------------------- /.github/workflows/docker-image.yml: -------------------------------------------------------------------------------- 1 | name: Publish docker images 2 | 3 | on: 4 | push: 5 | branches: 6 | - 'master' 7 | tags: 8 | - 'libp2p-server-**' 9 | 10 | jobs: 11 | server: 12 | runs-on: ubuntu-latest 13 | steps: 14 | - uses: actions/checkout@v4 15 | 16 | - uses: docker/login-action@v3 17 | with: 18 | registry: ghcr.io 19 | username: ${{ github.actor }} 20 | password: ${{ github.token }} 21 | 22 | - name: Set up Docker Buildx 23 | uses: docker/setup-buildx-action@v3 24 | 25 | - name: Docker meta 26 | id: meta 27 | uses: docker/metadata-action@v5 28 | with: 29 | images: ghcr.io/${{ github.repository }}-server 30 | 31 | - name: Build and push 32 | uses: docker/build-push-action@v6 33 | with: 34 | context: . 35 | file: ./misc/server/Dockerfile 36 | push: true 37 | tags: ${{ steps.meta.outputs.tags }} 38 | labels: ${{ steps.meta.outputs.labels }} 39 | -------------------------------------------------------------------------------- /.github/workflows/docs.yml: -------------------------------------------------------------------------------- 1 | name: Build and host documentation 2 | on: 3 | push: 4 | branches: 5 | - master 6 | 7 | jobs: 8 | build: 9 | name: Build documentation 10 | runs-on: ubuntu-latest 11 | steps: 12 | - name: Checkout 13 | uses: actions/checkout@v4 14 | - name: Install nightly toolchain 15 | run: rustup toolchain install nightly 16 | - name: Build Documentation 17 | run: cargo +nightly doc --no-deps --workspace -F full 18 | env: 19 | RUSTDOCFLAGS: "--cfg docsrs" 20 | - name: Add index file 21 | run: | 22 | mkdir host-docs 23 | echo "" > target/doc/index.html 24 | cp -r target/doc/* ./host-docs 25 | - name: Upload documentation 26 | uses: actions/upload-pages-artifact@v3.0.1 27 | with: 28 | path: "host-docs/" 29 | 30 | deploy: 31 | name: Deploy documentation 32 | needs: build 33 | permissions: 34 | pages: write 35 | id-token: write 36 | 37 | environment: 38 | name: github-pages 39 | url: ${{ steps.deployment.outputs.page_url }} 40 | runs-on: ubuntu-latest 41 | steps: 42 | - name: Deploy to GitHub Pages 43 | id: deployment 44 | uses: actions/deploy-pages@v4 45 | 46 | -------------------------------------------------------------------------------- /.github/workflows/semantic-pull-request.yml: -------------------------------------------------------------------------------- 1 | name: Semantic PR 2 | 3 | on: 4 | pull_request_target: 5 | types: 6 | - opened 7 | - edited 8 | - synchronize 9 | 10 | jobs: 11 | main: 12 | uses: pl-strflt/.github/.github/workflows/reusable-semantic-pull-request.yml@v0.3 13 | -------------------------------------------------------------------------------- /.github/workflows/stale.yml: -------------------------------------------------------------------------------- 1 | name: Close and mark stale issue 2 | 3 | on: 4 | schedule: 5 | - cron: '0 0 * * *' 6 | 7 | jobs: 8 | stale: 9 | 10 | runs-on: ubuntu-latest 11 | permissions: 12 | issues: write 13 | pull-requests: write 14 | 15 | steps: 16 | - uses: actions/stale@v7 17 | with: 18 | repo-token: ${{ secrets.GITHUB_TOKEN }} 19 | stale-issue-message: 'Oops, seems like we needed more information for this issue, please comment with more details or this issue will be closed in 7 days.' 20 | close-issue-message: 'This issue was closed because it is missing author input.' 21 | stale-issue-label: 'kind/stale' 22 | any-of-labels: 'need/author-input' 23 | exempt-issue-labels: 'need/triage,need/community-input,need/maintainer-input,need/maintainers-input,need/analysis,status/blocked,status/in-progress,status/ready,status/deferred,status/inactive' 24 | days-before-issue-stale: 6 25 | days-before-issue-close: 7 26 | enable-statistics: true 27 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | -------------------------------------------------------------------------------- /FUNDING.json: -------------------------------------------------------------------------------- 1 | { 2 | "drips": { 3 | "ethereum": { 4 | "ownedBy": "0x79c49637182Ea32734f7e8445a3649c22ff348f2" 5 | }, 6 | "filecoin": { 7 | "ownedBy": "0x79c49637182Ea32734f7e8445a3649c22ff348f2" 8 | } 9 | }, 10 | "opRetro": { 11 | "projectId": "0xdf1bb03d08808e2d789f5eac8462bdc560f1bb5b0877f0cf8c66ab53a0bc2f5c" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2017-2020 Parity Technologies (UK) Ltd. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | this software and associated documentation files (the "Software"), to deal in 5 | the Software without restriction, including without limitation the rights to 6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 | the Software, and to permit persons to whom the Software is furnished to do so, 8 | subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 15 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS 16 | OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | ## Supported Versions 4 | 5 | By default we provide security patches for the latest released version only. On request we patch older versions. 6 | 7 | ## Reporting a Vulnerability 8 | 9 | Please do not file a public issue on GitHub. Instead, please [file a private security vulnerability report](https://github.com/libp2p/rust-libp2p/security/advisories/new). 10 | -------------------------------------------------------------------------------- /clippy.toml: -------------------------------------------------------------------------------- 1 | disallowed-methods = [ 2 | { path = "futures::channel::mpsc::unbounded", reason = "does not enforce backpressure" }, 3 | ] 4 | avoid-breaking-exported-api = false 5 | -------------------------------------------------------------------------------- /core/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "libp2p-core" 3 | edition.workspace = true 4 | rust-version = { workspace = true } 5 | description = "Core traits and structs of libp2p" 6 | version = "0.43.1" 7 | authors = ["Parity Technologies "] 8 | license = "MIT" 9 | repository = "https://github.com/libp2p/rust-libp2p" 10 | keywords = ["peer-to-peer", "libp2p", "networking"] 11 | categories = ["network-programming", "asynchronous"] 12 | 13 | [dependencies] 14 | either = "1.11" 15 | fnv = "1.0" 16 | futures = { workspace = true, features = ["executor", "thread-pool"] } 17 | futures-timer = "3" 18 | web-time = { workspace = true } 19 | libp2p-identity = { workspace = true, features = ["peerid", "ed25519"] } 20 | multiaddr = { workspace = true } 21 | multihash = { workspace = true } 22 | multistream-select = { workspace = true } 23 | parking_lot = "0.12.3" 24 | pin-project = "1.1.5" 25 | quick-protobuf = "0.8" 26 | rand = "0.8" 27 | rw-stream-sink = { workspace = true } 28 | thiserror = { workspace = true } 29 | tracing = { workspace = true } 30 | unsigned-varint = { workspace = true } 31 | 32 | [dev-dependencies] 33 | tokio = { workspace = true, features = ["rt", "macros"] } 34 | libp2p-mplex = { path = "../muxers/mplex" } # Using `path` here because this is a cyclic dev-dependency which otherwise breaks releasing. 35 | libp2p-noise = { path = "../transports/noise" } # Using `path` here because this is a cyclic dev-dependency which otherwise breaks releasing. 36 | multihash = { workspace = true, features = ["arb"] } 37 | libp2p-identity = { workspace = true, features = ["ed25519", "rand"] } 38 | 39 | [features] 40 | serde = ["multihash/serde-codec", "libp2p-identity/serde"] 41 | 42 | # Passing arguments to the docsrs builder in order to properly document cfg's. 43 | # More information: https://docs.rs/about/builds#cross-compiling 44 | [package.metadata.docs.rs] 45 | all-features = true 46 | 47 | [lints] 48 | workspace = true 49 | -------------------------------------------------------------------------------- /core/src/generated/envelope.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package envelope_proto; 4 | 5 | // Envelope encloses a signed payload produced by a peer, along with the public 6 | // key of the keypair it was signed with so that it can be statelessly validated 7 | // by the receiver. 8 | // 9 | // The payload is prefixed with a byte string that determines the type, so it 10 | // can be deserialized deterministically. Often, this byte string is a 11 | // multicodec. 12 | message Envelope { 13 | // public_key is the public key of the keypair the enclosed payload was 14 | // signed with. 15 | bytes public_key = 1; 16 | 17 | // payload_type encodes the type of payload, so that it can be deserialized 18 | // deterministically. 19 | bytes payload_type = 2; 20 | 21 | // payload is the actual payload carried inside this envelope. 22 | bytes payload = 3; 23 | 24 | // signature is the signature produced by the private key corresponding to 25 | // the enclosed public key, over the payload, prefixing a domain string for 26 | // additional security. 27 | bytes signature = 5; 28 | } 29 | -------------------------------------------------------------------------------- /core/src/generated/mod.rs: -------------------------------------------------------------------------------- 1 | // Automatically generated mod.rs 2 | pub mod envelope_proto; 3 | pub mod peer_record_proto; 4 | -------------------------------------------------------------------------------- /core/src/generated/peer_record.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package peer_record_proto; 4 | 5 | // PeerRecord messages contain information that is useful to share with other peers. 6 | // Currently, a PeerRecord contains the public listen addresses for a peer, but this 7 | // is expected to expand to include other information in the future. 8 | // 9 | // PeerRecords are designed to be serialized to bytes and placed inside of 10 | // SignedEnvelopes before sharing with other peers. 11 | message PeerRecord { 12 | 13 | // AddressInfo is a wrapper around a binary multiaddr. It is defined as a 14 | // separate message to allow us to add per-address metadata in the future. 15 | message AddressInfo { 16 | bytes multiaddr = 1; 17 | } 18 | 19 | // peer_id contains a libp2p peer id in its binary representation. 20 | bytes peer_id = 1; 21 | 22 | // seq contains a monotonically-increasing sequence counter to order PeerRecords in time. 23 | uint64 seq = 2; 24 | 25 | // addresses is a list of public listen addresses for the peer. 26 | repeated AddressInfo addresses = 3; 27 | } 28 | -------------------------------------------------------------------------------- /examples/README.md: -------------------------------------------------------------------------------- 1 | # Examples 2 | 3 | A set of examples showcasing how to use rust-libp2p. 4 | 5 | ## Getting started 6 | 7 | 8 | ## Individual libp2p features 9 | 10 | - [Chat](./chat) A basic chat application demonstrating libp2p and the mDNS and Gossipsub protocols. 11 | - [Distributed key-value store](./distributed-key-value-store) A basic key value store demonstrating libp2p and the mDNS and Kademlia protocol. 12 | 13 | - [File sharing application](./file-sharing) Basic file sharing application with peers either providing or locating and getting files by name. 14 | 15 | While obviously showcasing how to build a basic file sharing application with the Kademlia and 16 | Request-Response protocol, the actual goal of this example is **to show how to integrate 17 | rust-libp2p into a larger application**. 18 | 19 | - [IPFS Kademlia](./ipfs-kad) Demonstrates how to perform Kademlia queries on the IPFS network. 20 | 21 | - [IPFS Private](./ipfs-private) Implementation using the gossipsub, ping and identify protocols to implement the ipfs private swarms feature. 22 | 23 | - [Ping](./ping) Small `ping` clone, sending a ping to a peer, expecting a pong as a response. See [tutorial](../libp2p/src/tutorials/ping.rs) for a step-by-step guide building the example. 24 | 25 | - [Rendezvous](./rendezvous) Rendezvous Protocol. See [specs](https://github.com/libp2p/specs/blob/master/rendezvous/README.md). 26 | -------------------------------------------------------------------------------- /examples/autonat/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "autonat-example" 3 | version = "0.1.0" 4 | edition.workspace = true 5 | publish = false 6 | license = "MIT or Apache-2.0" 7 | 8 | [package.metadata.release] 9 | release = false 10 | 11 | [dependencies] 12 | tokio = { workspace = true, features = ["full"] } 13 | clap = { version = "4.5.6", features = ["derive"] } 14 | futures = { workspace = true } 15 | libp2p = { path = "../../libp2p", features = ["tokio", "tcp", "noise", "yamux", "autonat", "identify", "macros"] } 16 | tracing-subscriber = { workspace = true, features = ["env-filter"] } 17 | 18 | [lints] 19 | workspace = true 20 | -------------------------------------------------------------------------------- /examples/autonat/README.md: -------------------------------------------------------------------------------- 1 | ## Description 2 | 3 | This example consists of a client and a server, which demonstrate the usage of the AutoNAT and identify protocols in **libp2p**. 4 | 5 | ## Usage 6 | 7 | ### Client 8 | 9 | The client-side part of the example showcases the combination of the AutoNAT and identify protocols. 10 | The identify protocol allows the local peer to determine its external addresses, which are then included in AutoNAT dial-back requests sent to the server. 11 | 12 | To run the client example, follow these steps: 13 | 14 | 1. Start the server by following the instructions provided in the `examples/server` directory. 15 | 16 | 2. Open a new terminal. 17 | 18 | 3. Run the following command in the terminal: 19 | ```sh 20 | cargo run --bin autonat_client -- --server-address --server-peer-id --listen-port 21 | ``` 22 | Note: The `--listen-port` parameter is optional and allows you to specify a fixed port at which the local client should listen. 23 | 24 | ### Server 25 | 26 | The server-side example demonstrates a basic AutoNAT server that supports the autonat and identify protocols. 27 | 28 | To start the server, follow these steps: 29 | 30 | 1. Open a terminal. 31 | 32 | 2. Run the following command: 33 | ```sh 34 | cargo run --bin autonat_server -- --listen-port 35 | ``` 36 | Note: The `--listen-port` parameter is optional and allows you to set a fixed port at which the local peer should listen. 37 | 38 | ## Conclusion 39 | 40 | By combining the AutoNAT and identify protocols, the example showcases the establishment of direct connections between peers and the exchange of external address information. 41 | Users can explore the provided client and server code to gain insights into the implementation details and functionality of **libp2p**. 42 | -------------------------------------------------------------------------------- /examples/autonatv2/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "autonatv2" 3 | version = "0.1.0" 4 | edition.workspace = true 5 | publish = false 6 | license = "MIT or Apache-2.0" 7 | 8 | [package.metadata.release] 9 | release = false 10 | 11 | [[bin]] 12 | name = "autonatv2_client" 13 | 14 | [[bin]] 15 | name = "autonatv2_server" 16 | 17 | [dependencies] 18 | libp2p = { workspace = true, features = ["macros", "tokio", "tcp", "noise", "yamux", "autonat", "identify", "dns", "quic"] } 19 | clap = { version = "4.4.18", features = ["derive"] } 20 | tokio = { version = "1.35.1", features = ["macros", "rt-multi-thread"] } 21 | tracing = "0.1.40" 22 | tracing-subscriber = { workspace = true, features = ["env-filter"] } 23 | rand = "0.8.5" 24 | opentelemetry_sdk = { version = "0.21.1", optional = true, features = ["rt-tokio"] } 25 | tracing-opentelemetry = { version = "0.22.0", optional = true } 26 | opentelemetry-jaeger = { version = "0.20.0", optional = true, features = ["rt-tokio"] } 27 | cfg-if = "1.0.0" 28 | 29 | [features] 30 | jaeger = ["opentelemetry_sdk", "tracing-opentelemetry", "opentelemetry-jaeger"] 31 | opentelemetry_sdk = ["dep:opentelemetry_sdk"] 32 | tracing-opentelemetry = ["dep:tracing-opentelemetry"] 33 | opentelemetry-jaeger = ["dep:opentelemetry-jaeger"] 34 | 35 | [lints] 36 | workspace = true 37 | -------------------------------------------------------------------------------- /examples/autonatv2/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM rust:1.83-alpine as builder 2 | 3 | RUN apk add musl-dev 4 | 5 | WORKDIR /workspace 6 | COPY . . 7 | RUN --mount=type=cache,target=./target \ 8 | --mount=type=cache,target=/usr/local/cargo/registry \ 9 | cargo build --release --package autonatv2 --bin autonatv2_server -F jaeger 10 | 11 | RUN --mount=type=cache,target=./target \ 12 | mv ./target/release/autonatv2_server /usr/local/bin/autonatv2_server 13 | 14 | FROM alpine:latest 15 | 16 | COPY --from=builder /usr/local/bin/autonatv2_server /app/autonatv2_server 17 | 18 | EXPOSE 4884 19 | 20 | ENTRYPOINT [ "/app/autonatv2_server", "-l", "4884" ] 21 | -------------------------------------------------------------------------------- /examples/autonatv2/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | services: 4 | autonatv2: 5 | build: 6 | context: ../.. 7 | dockerfile: examples/autonatv2/Dockerfile 8 | ports: 9 | - 4884:4884 10 | jaeger: 11 | image: jaegertracing/all-in-one 12 | ports: 13 | - 6831:6831/udp 14 | - 6832:6832/udp 15 | - 16686:16686 16 | - 14268:14268 17 | -------------------------------------------------------------------------------- /examples/browser-webrtc/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | authors = ["Doug Anderson "] 3 | description = "Example use of the WebRTC transport in a browser wasm environment" 4 | edition.workspace = true 5 | license = "MIT" 6 | name = "browser-webrtc-example" 7 | publish = false 8 | repository = "https://github.com/libp2p/rust-libp2p" 9 | rust-version = { workspace = true } 10 | version = "0.1.0" 11 | 12 | [package.metadata.release] 13 | release = false 14 | 15 | [lib] 16 | crate-type = ["cdylib"] 17 | 18 | [dependencies] 19 | anyhow = "1.0.86" 20 | futures = { workspace = true } 21 | rand = "0.8" 22 | tracing = { workspace = true } 23 | tracing-subscriber = { workspace = true, features = ["env-filter"] } 24 | 25 | [target.'cfg(not(target_arch = "wasm32"))'.dependencies] 26 | axum = "0.7.5" 27 | libp2p = { path = "../../libp2p", features = [ "ed25519", "macros", "ping", "tokio"] } 28 | libp2p-webrtc = { workspace = true, features = ["tokio"] } 29 | rust-embed = { version = "8.4.0", features = ["include-exclude", "interpolate-folder-path"] } 30 | tokio = { workspace = true, features = ["macros", "net", "rt", "signal"] } 31 | tokio-util = { version = "0.7", features = ["compat"] } 32 | tower = "0.4" 33 | tower-http = { version = "0.5.2", features = ["cors"] } 34 | mime_guess = "2.0.4" 35 | 36 | [target.'cfg(target_arch = "wasm32")'.dependencies] 37 | js-sys = "0.3.69" 38 | libp2p = { path = "../../libp2p", features = [ "ed25519", "macros", "ping", "wasm-bindgen"] } 39 | libp2p-webrtc-websys = { workspace = true } 40 | tracing-wasm = "0.2.1" 41 | wasm-bindgen = "0.2.90" 42 | wasm-bindgen-futures = "0.4.42" 43 | web-sys = { version = "0.3", features = ['Document', 'Element', 'HtmlElement', 'Node', 'Response', 'Window'] } 44 | 45 | [lints] 46 | workspace = true 47 | -------------------------------------------------------------------------------- /examples/browser-webrtc/README.md: -------------------------------------------------------------------------------- 1 | # Rust-libp2p Browser-Server WebRTC Example 2 | 3 | This example demonstrates how to use the `libp2p-webrtc-websys` transport library in a browser to ping the WebRTC Server. 4 | It uses [wasm-pack](https://rustwasm.github.io/docs/wasm-pack/) to build the project for use in the browser. 5 | 6 | ## Running the example 7 | 8 | Ensure you have `wasm-pack` [installed](https://rustwasm.github.io/wasm-pack/). 9 | 10 | 1. Build the client library: 11 | ```shell 12 | wasm-pack build --target web --out-dir static 13 | ``` 14 | 15 | 2. Start the server: 16 | ```shell 17 | cargo run 18 | ``` 19 | 20 | 3. Open the URL printed in the terminal 21 | -------------------------------------------------------------------------------- /examples/browser-webrtc/static/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | 11 | 12 |
13 |

Rust Libp2p Demo!

14 |
15 | 16 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /examples/chat/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "chat-example" 3 | version = "0.1.0" 4 | edition.workspace = true 5 | publish = false 6 | license = "MIT" 7 | 8 | [package.metadata.release] 9 | release = false 10 | 11 | [dependencies] 12 | tokio = { workspace = true, features = ["full"] } 13 | futures = { workspace = true } 14 | libp2p = { path = "../../libp2p", features = [ "tokio", "gossipsub", "mdns", "noise", "macros", "tcp", "yamux", "quic"] } 15 | tracing-subscriber = { workspace = true, features = ["env-filter"] } 16 | 17 | [lints] 18 | workspace = true 19 | -------------------------------------------------------------------------------- /examples/chat/README.md: -------------------------------------------------------------------------------- 1 | ## Description 2 | 3 | A basic chat application with logs demonstrating libp2p and the gossipsub protocol combined with mDNS for the discovery of peers to gossip with. 4 | It showcases how peers can connect, discover each other using mDNS, and engage in real-time chat sessions. 5 | 6 | ## Usage 7 | 8 | 1. Using two terminal windows, start two instances, typing the following in each: 9 | ```sh 10 | cargo run 11 | ``` 12 | 13 | 2. Mutual mDNS discovery may take a few seconds. When each peer does discover the other 14 | it will print a message like: 15 | ```sh 16 | mDNS discovered a new peer: {peerId} 17 | ``` 18 | 19 | 3. Type a message and hit return: the message is sent and printed in the other terminal. 20 | 21 | 4. Close with `Ctrl-c`. You can open more terminal windows and add more peers using the same line above. 22 | 23 | When a new peer is discovered through mDNS, it can join the conversation, and all peers will receive messages sent by that peer. 24 | If a participant exits the application using `Ctrl-c` or any other method, the remaining peers will receive an mDNS expired event and remove the expired peer from their list of known peers. 25 | 26 | ## Conclusion 27 | 28 | This chat application demonstrates the usage of **libp2p** and the gossipsub protocol for building a decentralized chat system. 29 | By leveraging mDNS for peer discovery, users can easily connect with other peers and engage in real-time conversations. 30 | The example provides a starting point for developing more sophisticated chat applications using **libp2p** and exploring the capabilities of decentralized communication. 31 | -------------------------------------------------------------------------------- /examples/dcutr/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "dcutr-example" 3 | version = "0.1.0" 4 | edition.workspace = true 5 | publish = false 6 | license = "MIT" 7 | 8 | [package.metadata.release] 9 | release = false 10 | 11 | [dependencies] 12 | clap = { version = "4.5.6", features = ["derive"] } 13 | futures = { workspace = true } 14 | futures-timer = "3.0" 15 | libp2p = { path = "../../libp2p", features = [ "dns", "dcutr", "identify", "macros", "noise", "ping", "quic", "relay", "rendezvous", "tcp", "tokio", "yamux"] } 16 | tokio = { workspace = true, features = ["macros", "net", "rt", "signal"] } 17 | tracing = { workspace = true } 18 | tracing-subscriber = { workspace = true, features = ["env-filter"] } 19 | 20 | [lints] 21 | workspace = true 22 | -------------------------------------------------------------------------------- /examples/dcutr/README.md: -------------------------------------------------------------------------------- 1 | ## Description 2 | 3 | The "Direct Connection Upgrade through Relay" (DCUTR) protocol allows peers in a peer-to-peer network to establish direct connections with each other. 4 | In other words, DCUTR is libp2p's version of hole-punching. 5 | This example provides a basic usage of this protocol in **libp2p**. 6 | 7 | ## Usage 8 | 9 | To run the example, follow these steps: 10 | 11 | 1. Run the example using Cargo: 12 | ```sh 13 | cargo run -- 14 | ``` 15 | Replace `` with specific options (you can use the `--help` command to see the available options). 16 | 17 | ### Example usage 18 | 19 | - Example usage in client-listen mode: 20 | ```sh 21 | cargo run -- --mode listen --secret-key-seed 42 --relay-address /ip4/$RELAY_IP/tcp/$PORT/p2p/$RELAY_PEERID 22 | ``` 23 | 24 | - Example usage in client-dial mode: 25 | ```sh 26 | cargo run -- --mode dial --secret-key-seed 42 --relay-address /ip4/$RELAY_IP/tcp/$PORT/p2p/$RELAY_PEERID --remote-peer-id 27 | ``` 28 | 29 | For this example to work, it is also necessary to turn on a relay server (you will find the related instructions in the example in the `examples/relay-server` folder). 30 | 31 | ## Conclusion 32 | 33 | The DCUTR protocol offers a solution for achieving direct connectivity between peers in a peer-to-peer network. 34 | By utilizing hole punching and eliminating the need for signaling servers, the protocol allows peers behind NATs to establish direct connections. 35 | This example provides instructions on running an example implementation of the protocol, allowing users to explore its functionality and benefits. 36 | -------------------------------------------------------------------------------- /examples/distributed-key-value-store/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "distributed-key-value-store-example" 3 | version = "0.1.0" 4 | edition.workspace = true 5 | publish = false 6 | license = "MIT" 7 | 8 | [package.metadata.release] 9 | release = false 10 | 11 | [dependencies] 12 | tokio = { workspace = true, features = ["full"] } 13 | futures = { workspace = true } 14 | libp2p = { path = "../../libp2p", features = [ "tokio", "dns", "kad", "mdns", "noise", "macros", "tcp", "yamux"] } 15 | tracing-subscriber = { workspace = true, features = ["env-filter"] } 16 | 17 | [lints] 18 | workspace = true 19 | -------------------------------------------------------------------------------- /examples/file-sharing/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "file-sharing-example" 3 | version = "0.1.0" 4 | edition.workspace = true 5 | publish = false 6 | license = "MIT" 7 | 8 | [package.metadata.release] 9 | release = false 10 | 11 | [dependencies] 12 | serde = { version = "1.0", features = ["derive"] } 13 | tokio = { workspace = true, features = ["full"] } 14 | clap = { version = "4.5.6", features = ["derive"] } 15 | futures = { workspace = true } 16 | libp2p = { path = "../../libp2p", features = [ "tokio", "cbor", "dns", "kad", "noise", "macros", "request-response", "tcp", "websocket", "yamux"] } 17 | tracing-subscriber = { workspace = true, features = ["env-filter"] } 18 | 19 | [lints] 20 | workspace = true 21 | -------------------------------------------------------------------------------- /examples/identify/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "identify-example" 3 | version = "0.1.0" 4 | edition.workspace = true 5 | publish = false 6 | license = "MIT" 7 | 8 | [package.metadata.release] 9 | release = false 10 | 11 | [dependencies] 12 | tokio = { version = "1.37.0", features = ["full"] } 13 | futures = { workspace = true } 14 | libp2p = { path = "../../libp2p", features = ["identify", "noise", "tcp", "tokio", "yamux"] } 15 | tracing-subscriber = { workspace = true, features = ["env-filter"] } 16 | 17 | [lints] 18 | workspace = true 19 | -------------------------------------------------------------------------------- /examples/identify/README.md: -------------------------------------------------------------------------------- 1 | ## Description 2 | 3 | The example demonstrates how to create a connection between two nodes using TCP transport, authenticate with the noise protocol, and multiplex data streams with yamux. 4 | The library provides a behavior for identity network interactions, allowing nodes to exchange identification information securely. 5 | By running the example, the nodes will establish a connection, negotiate the identity protocol, and exchange identification information, which will be displayed in the console. 6 | 7 | ## Usage 8 | 9 | 1. In the first terminal window, run the following command: 10 | ```sh 11 | cargo run 12 | ``` 13 | This will print the peer ID (`PeerId`) and the listening addresses, e.g., `Listening on "/ip4/127.0.0.1/tcp/24915"` 14 | 15 | 2. In the second terminal window, start a new instance of the example with the following command: 16 | ```sh 17 | cargo run -- /ip4/127.0.0.1/tcp/24915 18 | ``` 19 | The two nodes establish a connection, negotiate the identity protocol, and send each other identification information, which is then printed to the console. 20 | 21 | ## Conclusion 22 | 23 | The included identity example demonstrates how to establish connections and exchange identification information between nodes using the library's protocols and behaviors. 24 | -------------------------------------------------------------------------------- /examples/ipfs-kad/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "ipfs-kad-example" 3 | version = "0.1.0" 4 | edition.workspace = true 5 | publish = false 6 | license = "MIT" 7 | 8 | [package.metadata.release] 9 | release = false 10 | 11 | [dependencies] 12 | tokio = { workspace = true, features = ["rt-multi-thread", "macros"] } 13 | clap = { version = "4.5.6", features = ["derive"] } 14 | futures = { workspace = true } 15 | anyhow = "1.0.86" 16 | libp2p = { path = "../../libp2p", features = [ "tokio", "dns", "kad", "noise", "tcp", "yamux", "rsa"] } 17 | tracing-subscriber = { workspace = true, features = ["env-filter"] } 18 | 19 | [lints] 20 | workspace = true 21 | -------------------------------------------------------------------------------- /examples/ipfs-private/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "ipfs-private-example" 3 | version = "0.1.0" 4 | edition.workspace = true 5 | publish = false 6 | license = "MIT" 7 | 8 | [package.metadata.release] 9 | release = false 10 | 11 | [dependencies] 12 | tokio = { workspace = true, features = ["rt-multi-thread", "macros", "io-std"] } 13 | either = "1.12" 14 | futures = { workspace = true } 15 | libp2p = { path = "../../libp2p", features = [ "tokio", "gossipsub", "dns", "identify", "kad", "macros", "noise", "ping", "pnet", "tcp", "websocket", "yamux"] } 16 | tracing-subscriber = { workspace = true, features = ["env-filter"] } 17 | 18 | [lints] 19 | workspace = true 20 | -------------------------------------------------------------------------------- /examples/metrics/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "metrics-example" 3 | version = "0.1.0" 4 | edition.workspace = true 5 | publish = false 6 | license = "MIT" 7 | 8 | [package.metadata.release] 9 | release = false 10 | 11 | [dependencies] 12 | futures = { workspace = true } 13 | axum = "0.7" 14 | libp2p = { path = "../../libp2p", features = ["tokio", "metrics", "ping", "noise", "identify", "tcp", "yamux", "macros"] } 15 | opentelemetry = { version = "0.27.0", features = ["metrics"] } 16 | opentelemetry-otlp = { version = "0.27.0", features = ["metrics"] } 17 | opentelemetry_sdk = { version = "0.27.0", features = ["rt-tokio", "metrics"] } 18 | prometheus-client = { workspace = true } 19 | tokio = { workspace = true, features = ["full"] } 20 | tracing = { workspace = true } 21 | tracing-opentelemetry = "0.28.0" 22 | tracing-subscriber = { workspace = true, features = ["env-filter"] } 23 | 24 | [lints] 25 | workspace = true 26 | -------------------------------------------------------------------------------- /examples/metrics/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "2" 2 | services: 3 | # Jaeger 4 | jaeger-all-in-one: 5 | image: jaegertracing/all-in-one:latest 6 | restart: always 7 | ports: 8 | - "16686:16686" 9 | - "14268" 10 | - "14250" 11 | 12 | # Collector 13 | otel-collector: 14 | image: otel/opentelemetry-collector:0.88.0 15 | restart: always 16 | command: ["--config=/etc/otel-collector-config.yaml"] 17 | volumes: 18 | - ./otel-collector-config.yaml:/etc/otel-collector-config.yaml 19 | ports: 20 | - "13133:13133" # health_check extension 21 | - "4317:4317" # OTLP gRPC receiver 22 | depends_on: 23 | - jaeger-all-in-one 24 | -------------------------------------------------------------------------------- /examples/metrics/otel-collector-config.yaml: -------------------------------------------------------------------------------- 1 | receivers: 2 | otlp: 3 | protocols: 4 | grpc: 5 | endpoint: 0.0.0.0:4317 6 | 7 | exporters: 8 | debug: 9 | otlp: 10 | endpoint: jaeger-all-in-one:4317 11 | tls: 12 | insecure: true 13 | 14 | processors: 15 | batch: 16 | 17 | service: 18 | telemetry: 19 | logs: 20 | level: "debug" 21 | pipelines: 22 | traces: 23 | receivers: [otlp] 24 | processors: [batch] 25 | exporters: [debug, otlp] 26 | -------------------------------------------------------------------------------- /examples/ping/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "ping-example" 3 | version = "0.1.0" 4 | edition.workspace = true 5 | publish = false 6 | license = "MIT" 7 | 8 | [package.metadata.release] 9 | release = false 10 | 11 | [dependencies] 12 | futures = { workspace = true } 13 | libp2p = { path = "../../libp2p", features = ["noise", "ping", "tcp", "tokio", "yamux"] } 14 | tokio = { workspace = true, features = ["full"] } 15 | tracing-subscriber = { workspace = true, features = ["env-filter"] } 16 | 17 | [lints] 18 | workspace = true 19 | -------------------------------------------------------------------------------- /examples/ping/README.md: -------------------------------------------------------------------------------- 1 | ## Description 2 | 3 | The ping example showcases how to create a network of nodes that establish connections, negotiate the ping protocol, and ping each other. 4 | 5 | ## Usage 6 | 7 | To run the example, follow these steps: 8 | 9 | 1. In a first terminal window, run the following command: 10 | 11 | ```sh 12 | cargo run 13 | ``` 14 | 15 | This command starts a node and prints the `PeerId` and the listening addresses, such as `Listening on "/ip4/0.0.0.0/tcp/24915"`. 16 | 17 | 2. In a second terminal window, start a new instance of the example with the following command: 18 | 19 | ```sh 20 | cargo run -- /ip4/127.0.0.1/tcp/24915 21 | ``` 22 | 23 | Replace `/ip4/127.0.0.1/tcp/24915` with the listen address of the first node obtained from the first terminal window. 24 | 25 | 3. The two nodes will establish a connection, negotiate the ping protocol, and begin pinging each other. 26 | 27 | ## Conclusion 28 | 29 | The ping example demonstrates the basic usage of **libp2p** to create a simple p2p network and implement a ping protocol. 30 | By running multiple nodes and observing the ping behavior, users can gain insights into how **libp2p** facilitates communication and interaction between peers. 31 | -------------------------------------------------------------------------------- /examples/relay-server/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "relay-server-example" 3 | version = "0.1.0" 4 | edition.workspace = true 5 | publish = false 6 | license = "MIT" 7 | 8 | [package.metadata.release] 9 | release = false 10 | 11 | [dependencies] 12 | clap = { version = "4.5.6", features = ["derive"] } 13 | tokio = { version = "1.37.0", features = ["full"] } 14 | futures = { workspace = true } 15 | libp2p = { path = "../../libp2p", features = ["tokio", "noise", "macros", "ping", "tcp", "identify", "yamux", "relay", "quic"] } 16 | tracing-subscriber = { workspace = true, features = ["env-filter"] } 17 | 18 | [lints] 19 | workspace = true 20 | -------------------------------------------------------------------------------- /examples/relay-server/README.md: -------------------------------------------------------------------------------- 1 | ## Description 2 | 3 | The **libp2p** relay example showcases how to create a relay node that can route messages between different peers in a p2p network. 4 | 5 | ## Usage 6 | 7 | To run the example, follow these steps: 8 | 9 | 1. Run the relay node by executing the following command: 10 | 11 | ```sh 12 | cargo run -- --port --secret-key-seed 13 | ``` 14 | 15 | Replace `` with the port number on which the relay node will listen for incoming connections. 16 | Replace `` with a seed value used to generate a deterministic peer ID for the relay node. 17 | 18 | 2. The relay node will start listening for incoming connections. 19 | It will print the listening address once it is ready. 20 | 21 | 3. Connect other **libp2p** nodes to the relay node by specifying the relay's listening address as one of the bootstrap nodes in their configuration. 22 | 23 | 4. Once the connections are established, the relay node will facilitate communication between the connected peers, allowing them to exchange messages and data. 24 | 25 | ## Conclusion 26 | 27 | The **libp2p** relay example demonstrates how to implement a relay node. 28 | By running a relay node and connecting other **libp2p** nodes to it, users can create a decentralized network where peers can communicate and interact with each other. 29 | -------------------------------------------------------------------------------- /examples/rendezvous/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "rendezvous-example" 3 | version = "0.1.0" 4 | edition.workspace = true 5 | publish = false 6 | license = "MIT" 7 | 8 | [package.metadata.release] 9 | release = false 10 | 11 | [dependencies] 12 | futures = { workspace = true } 13 | libp2p = { path = "../../libp2p", features = ["identify", "macros", "noise", "ping", "rendezvous", "tcp", "tokio", "yamux"] } 14 | tokio = { workspace = true, features = ["rt-multi-thread", "macros", "time"] } 15 | tracing = { workspace = true } 16 | tracing-subscriber = { workspace = true, features = ["env-filter"] } 17 | 18 | [lints] 19 | workspace = true 20 | -------------------------------------------------------------------------------- /examples/stream/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "stream-example" 3 | version = "0.1.0" 4 | edition.workspace = true 5 | publish = false 6 | license = "MIT" 7 | 8 | [package.metadata.release] 9 | release = false 10 | 11 | [dependencies] 12 | anyhow = "1" 13 | futures = { workspace = true } 14 | libp2p = { path = "../../libp2p", features = [ "tokio", "quic"] } 15 | libp2p-stream = { path = "../../protocols/stream", version = "0.3.0-alpha" } 16 | rand = "0.8" 17 | tokio = { workspace = true, features = ["full"] } 18 | tracing = { workspace = true } 19 | tracing-subscriber = { workspace = true, features = ["env-filter"] } 20 | 21 | [lints] 22 | workspace = true 23 | -------------------------------------------------------------------------------- /examples/stream/README.md: -------------------------------------------------------------------------------- 1 | ## Description 2 | 3 | This example shows the usage of the `stream::Behaviour`. 4 | As a counter-part to the `request_response::Behaviour`, the `stream::Behaviour` allows users to write stream-oriented protocols whilst having minimal interaction with the `Swarm`. 5 | 6 | In this showcase, we implement an echo protocol: All incoming data is echoed back to the dialer, until the stream is closed. 7 | 8 | ## Usage 9 | 10 | To run the example, follow these steps: 11 | 12 | 1. Start an instance of the example in one terminal: 13 | 14 | ```sh 15 | cargo run --bin stream-example 16 | ``` 17 | 18 | Observe printed listen address. 19 | 20 | 2. Start another instance in a new terminal, providing the listen address of the first one. 21 | 22 | ```sh 23 | cargo run --bin stream-example --
24 | ``` 25 | 26 | 3. Both terminals should now continuously print messages. 27 | 28 | ## Conclusion 29 | 30 | The `stream::Behaviour` is an "escape-hatch" from the way typical rust-libp2p protocols are written. 31 | It is suitable for several scenarios including: 32 | 33 | - prototyping of new protocols 34 | - experimentation with rust-libp2p 35 | - integration in `async/await`-heavy applications -------------------------------------------------------------------------------- /examples/upnp/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "upnp-example" 3 | version = "0.1.0" 4 | edition.workspace = true 5 | publish = false 6 | license = "MIT" 7 | 8 | [package.metadata.release] 9 | release = false 10 | 11 | [dependencies] 12 | tokio = { workspace = true, features = ["rt-multi-thread", "macros"] } 13 | futures = { workspace = true } 14 | libp2p = { path = "../../libp2p", features = ["tokio", "dns", "macros", "noise", "ping", "tcp", "yamux", "upnp"] } 15 | tracing-subscriber = { workspace = true, features = ["env-filter"] } 16 | 17 | [lints] 18 | workspace = true 19 | -------------------------------------------------------------------------------- /examples/upnp/README.md: -------------------------------------------------------------------------------- 1 | ## Description 2 | 3 | The upnp example showcases how to use the upnp network behaviour to externally open ports on the network gateway. 4 | 5 | 6 | ## Usage 7 | 8 | To run the example, follow these steps: 9 | 10 | 1. In a terminal window, run the following command: 11 | 12 | ```sh 13 | cargo run 14 | ``` 15 | 16 | 2. This command will start the swarm and print the `NewExternalAddr` if the gateway supports `UPnP` or 17 | `GatewayNotFound` if it doesn't. 18 | 19 | 20 | ## Conclusion 21 | 22 | The upnp example demonstrates the usage of **libp2p** to externally open a port on the gateway if it 23 | supports [`UPnP`](https://en.wikipedia.org/wiki/Universal_Plug_and_Play). 24 | -------------------------------------------------------------------------------- /hole-punching-tests/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "hole-punching-tests" 3 | version = "0.1.0" 4 | edition.workspace = true 5 | publish = false 6 | license = "MIT" 7 | 8 | [dependencies] 9 | anyhow = "1" 10 | env_logger = { workspace = true } 11 | futures = { workspace = true } 12 | libp2p = { path = "../libp2p", features = ["tokio", "dcutr", "identify", "macros", "noise", "ping", "relay", "tcp", "yamux", "quic"] } 13 | tracing = { workspace = true } 14 | redis = { version = "0.24.0", default-features = false, features = ["tokio-comp"] } 15 | tokio = { workspace = true, features = ["full"] } 16 | serde = { version = "1.0.203", features = ["derive"] } 17 | serde_json = "1.0.117" 18 | either = "1.12.0" 19 | -------------------------------------------------------------------------------- /hole-punching-tests/Dockerfile: -------------------------------------------------------------------------------- 1 | # syntax=docker/dockerfile:1.5-labs 2 | FROM rust:1.83.0 as builder 3 | 4 | # Run with access to the target cache to speed up builds 5 | WORKDIR /workspace 6 | ADD . . 7 | 8 | # Build the relay as a statically-linked binary. Unfortunately, we must specify the `--target` explicitly. See https://msfjarvis.dev/posts/building-static-rust-binaries-for-linux/. 9 | RUN --mount=type=cache,target=./target \ 10 | --mount=type=cache,target=/usr/local/cargo/registry \ 11 | RUSTFLAGS='-C target-feature=+crt-static' cargo build --release --package hole-punching-tests --target $(rustc -vV | grep host | awk '{print $2}') 12 | 13 | RUN --mount=type=cache,target=./target \ 14 | mv ./target/$(rustc -vV | grep host | awk '{print $2}')/release/hole-punching-tests /usr/local/bin/hole-punching-tests 15 | 16 | FROM alpine:3 17 | COPY --from=builder /usr/local/bin/hole-punching-tests /usr/bin/hole-punch-client 18 | RUN --mount=type=cache,target=/var/cache/apk apk add bind-tools jq curl tcpdump iproute2-tc 19 | ENV RUST_BACKTRACE=1 20 | -------------------------------------------------------------------------------- /hole-punching-tests/version.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "rust-libp2p-head", 3 | "containerImageID": "rust-libp2p-head", 4 | "transports": [ 5 | "tcp", 6 | "quic" 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /identity/src/generated/keys.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | package keys_proto; 4 | 5 | enum KeyType { 6 | RSA = 0; 7 | Ed25519 = 1; 8 | Secp256k1 = 2; 9 | ECDSA = 3; 10 | } 11 | 12 | message PublicKey { 13 | required KeyType Type = 1; 14 | required bytes Data = 2; 15 | } 16 | 17 | message PrivateKey { 18 | required KeyType Type = 1; 19 | required bytes Data = 2; 20 | } 21 | -------------------------------------------------------------------------------- /identity/src/generated/mod.rs: -------------------------------------------------------------------------------- 1 | // Automatically generated mod.rs 2 | pub mod keys_proto; 3 | -------------------------------------------------------------------------------- /identity/src/test/rsa-2048.pk8: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sigp/rust-libp2p/e1bba263070194282cad48f07fb4aa0c87d03b55/identity/src/test/rsa-2048.pk8 -------------------------------------------------------------------------------- /identity/src/test/rsa-3072.pk8: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sigp/rust-libp2p/e1bba263070194282cad48f07fb4aa0c87d03b55/identity/src/test/rsa-3072.pk8 -------------------------------------------------------------------------------- /identity/src/test/rsa-4096.pk8: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sigp/rust-libp2p/e1bba263070194282cad48f07fb4aa0c87d03b55/identity/src/test/rsa-4096.pk8 -------------------------------------------------------------------------------- /identity/tests/keypair_api.rs: -------------------------------------------------------------------------------- 1 | use libp2p_identity::Keypair; 2 | 3 | #[test] 4 | fn calling_keypair_api() { 5 | let _ = Keypair::from_protobuf_encoding(&[]); 6 | } 7 | 8 | #[allow(dead_code)] 9 | fn using_keypair(kp: Keypair) { 10 | let _ = kp.to_protobuf_encoding(); 11 | let _ = kp.sign(&[]); 12 | let _ = kp.public(); 13 | let _: Option<[u8; 32]> = kp.derive_secret(b"foobar"); 14 | } 15 | -------------------------------------------------------------------------------- /identity/tests/serde.rs: -------------------------------------------------------------------------------- 1 | #![cfg(feature = "serde")] 2 | 3 | use std::str::FromStr; 4 | 5 | use libp2p_identity::PeerId; 6 | 7 | #[test] 8 | pub fn serialize_peer_id_json() { 9 | let peer_id = PeerId::from_str("12D3KooWRNw2pJC9748Fmq4WNV27HoSTcX3r37132FLkQMrbKAiC").unwrap(); 10 | let json = serde_json::to_string(&peer_id).unwrap(); 11 | assert_eq!( 12 | json, 13 | r#""12D3KooWRNw2pJC9748Fmq4WNV27HoSTcX3r37132FLkQMrbKAiC""# 14 | ) 15 | } 16 | 17 | #[test] 18 | pub fn serialize_peer_id_msgpack() { 19 | let peer_id = PeerId::from_str("12D3KooWRNw2pJC9748Fmq4WNV27HoSTcX3r37132FLkQMrbKAiC").unwrap(); 20 | let buf = rmp_serde::to_vec(&peer_id).unwrap(); 21 | assert_eq!( 22 | &buf[..], 23 | &[ 24 | 0xc4, 38, // msgpack buffer header 25 | 0x00, 0x24, 0x08, 0x01, 0x12, 0x20, 0xe7, 0x37, 0x0c, 0x66, 0xef, 0xec, 0x80, 0x00, 26 | 0xd5, 0x87, 0xfc, 0x41, 0x65, 0x92, 0x8e, 0xe0, 0x75, 0x5f, 0x94, 0x86, 0xcb, 0x5c, 27 | 0xf0, 0xf7, 0x80, 0xd8, 0xe0, 0x6c, 0x98, 0xce, 0x7d, 0xa9 28 | ] 29 | ); 30 | } 31 | 32 | #[test] 33 | pub fn deserialize_peer_id_json() { 34 | let peer_id = PeerId::from_str("12D3KooWRNw2pJC9748Fmq4WNV27HoSTcX3r37132FLkQMrbKAiC").unwrap(); 35 | let json = r#""12D3KooWRNw2pJC9748Fmq4WNV27HoSTcX3r37132FLkQMrbKAiC""#; 36 | assert_eq!(peer_id, serde_json::from_str(json).unwrap()) 37 | } 38 | 39 | #[test] 40 | pub fn deserialize_peer_id_msgpack() { 41 | let peer_id = PeerId::from_str("12D3KooWRNw2pJC9748Fmq4WNV27HoSTcX3r37132FLkQMrbKAiC").unwrap(); 42 | let buf = &[ 43 | 0xc4, 38, // msgpack buffer header 44 | 0x00, 0x24, 0x08, 0x01, 0x12, 0x20, 0xe7, 0x37, 0x0c, 0x66, 0xef, 0xec, 0x80, 0x00, 0xd5, 45 | 0x87, 0xfc, 0x41, 0x65, 0x92, 0x8e, 0xe0, 0x75, 0x5f, 0x94, 0x86, 0xcb, 0x5c, 0xf0, 0xf7, 46 | 0x80, 0xd8, 0xe0, 0x6c, 0x98, 0xce, 0x7d, 0xa9, 47 | ]; 48 | 49 | assert_eq!(peer_id, rmp_serde::from_read(&mut &buf[..]).unwrap()); 50 | } 51 | -------------------------------------------------------------------------------- /interop-tests/Dockerfile.chromium: -------------------------------------------------------------------------------- 1 | # syntax=docker/dockerfile:1.5-labs 2 | FROM rust:1.83 as chef 3 | RUN rustup target add wasm32-unknown-unknown 4 | RUN wget -q -O- https://github.com/rustwasm/wasm-pack/releases/download/v0.12.1/wasm-pack-v0.12.1-x86_64-unknown-linux-musl.tar.gz | tar -zx -C /usr/local/bin --strip-components 1 --wildcards "wasm-pack-*/wasm-pack" 5 | RUN wget -q -O- https://github.com/WebAssembly/binaryen/releases/download/version_115/binaryen-version_115-x86_64-linux.tar.gz | tar -zx -C /usr/local/bin --strip-components 2 --wildcards "binaryen-version_*/bin/wasm-opt" 6 | RUN wget -q -O- https://github.com/LukeMathWalker/cargo-chef/releases/download/v0.1.62/cargo-chef-x86_64-unknown-linux-gnu.tar.gz | tar -zx -C /usr/local/bin 7 | WORKDIR /app 8 | 9 | FROM chef AS planner 10 | COPY . . 11 | RUN cargo chef prepare --recipe-path recipe.json 12 | 13 | FROM chef AS builder 14 | COPY --from=planner /app/recipe.json recipe.json 15 | # Build dependencies - this is the caching Docker layer! 16 | RUN cargo chef cook --release --package interop-tests --target wasm32-unknown-unknown --recipe-path recipe.json 17 | RUN cargo chef cook --release --package interop-tests --bin wasm_ping --recipe-path recipe.json 18 | # Build application 19 | COPY . . 20 | RUN wasm-pack build --target web interop-tests 21 | RUN RUSTFLAGS='-C target-feature=+crt-static' cargo build --release --package interop-tests --target x86_64-unknown-linux-gnu --bin wasm_ping 22 | 23 | FROM selenium/standalone-chrome:125.0 24 | COPY --from=builder /app/target/x86_64-unknown-linux-gnu/release/wasm_ping /usr/local/bin/testplan 25 | ENV RUST_BACKTRACE=1 26 | ENTRYPOINT ["testplan"] 27 | -------------------------------------------------------------------------------- /interop-tests/Dockerfile.native: -------------------------------------------------------------------------------- 1 | # syntax=docker/dockerfile:1.5-labs 2 | FROM lukemathwalker/cargo-chef:0.1.68-rust-bullseye as chef 3 | WORKDIR /app 4 | 5 | FROM chef AS planner 6 | COPY . . 7 | RUN cargo chef prepare --recipe-path recipe.json 8 | 9 | FROM chef AS builder 10 | COPY --from=planner /app/recipe.json recipe.json 11 | # Build dependencies - this is the caching Docker layer! 12 | RUN cargo chef cook --release --package interop-tests --bin native_ping --recipe-path recipe.json 13 | # Build application 14 | COPY . . 15 | RUN RUSTFLAGS='-C target-feature=+crt-static' cargo build --release --package interop-tests --target $(rustc -vV | grep host | awk '{print $2}') --bin native_ping 16 | RUN cp /app/target/$(rustc -vV | grep host | awk '{print $2}')/release/native_ping /usr/local/bin/testplan 17 | 18 | FROM debian:bullseye 19 | COPY --from=builder /usr/local/bin/testplan /usr/local/bin/testplan 20 | ENV RUST_BACKTRACE=1 21 | ENTRYPOINT ["testplan"] 22 | -------------------------------------------------------------------------------- /interop-tests/chromium-ping-version.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "chromium-rust-libp2p-head", 3 | "containerImageID": "chromium-rust-libp2p-head", 4 | "transports": [ 5 | { "name": "webtransport", "onlyDial": true }, 6 | { "name": "webrtc-direct", "onlyDial": true }, 7 | { "name": "ws", "onlyDial": true } 8 | ], 9 | "secureChannels": ["noise"], 10 | "muxers": ["mplex", "yamux"] 11 | } 12 | -------------------------------------------------------------------------------- /interop-tests/native-ping-version.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "native-rust-libp2p-head", 3 | "containerImageID": "native-rust-libp2p-head", 4 | "transports": [ 5 | "ws", 6 | "tcp", 7 | "quic-v1", 8 | "webrtc-direct" 9 | ], 10 | "secureChannels": [ 11 | "tls", 12 | "noise" 13 | ], 14 | "muxers": [ 15 | "mplex", 16 | "yamux" 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /interop-tests/pkg/readme.md: -------------------------------------------------------------------------------- 1 | # Wasm package directory 2 | 3 | Content of this directory should be generated with 4 | ``` 5 | wasm pack build --target web 6 | ``` 7 | -------------------------------------------------------------------------------- /interop-tests/src/bin/config/mod.rs: -------------------------------------------------------------------------------- 1 | use std::env; 2 | 3 | use anyhow::{Context, Result}; 4 | 5 | #[derive(Debug, Clone)] 6 | pub(crate) struct Config { 7 | pub(crate) transport: String, 8 | pub(crate) sec_protocol: Option, 9 | pub(crate) muxer: Option, 10 | pub(crate) ip: String, 11 | pub(crate) is_dialer: bool, 12 | pub(crate) test_timeout: u64, 13 | pub(crate) redis_addr: String, 14 | } 15 | 16 | impl Config { 17 | pub(crate) fn from_env() -> Result { 18 | let transport = 19 | env::var("transport").context("transport environment variable is not set")?; 20 | let ip = env::var("ip").context("ip environment variable is not set")?; 21 | let is_dialer = env::var("is_dialer") 22 | .unwrap_or_else(|_| "true".into()) 23 | .parse::()?; 24 | let test_timeout = env::var("test_timeout_seconds") 25 | .unwrap_or_else(|_| "180".into()) 26 | .parse::()?; 27 | let redis_addr = env::var("redis_addr") 28 | .map(|addr| format!("redis://{addr}")) 29 | .unwrap_or_else(|_| "redis://redis:6379".into()); 30 | 31 | let sec_protocol = env::var("security").ok(); 32 | let muxer = env::var("muxer").ok(); 33 | 34 | Ok(Self { 35 | transport, 36 | sec_protocol, 37 | muxer, 38 | ip, 39 | is_dialer, 40 | test_timeout, 41 | redis_addr, 42 | }) 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /interop-tests/src/bin/native_ping.rs: -------------------------------------------------------------------------------- 1 | use anyhow::Result; 2 | 3 | mod config; 4 | 5 | #[tokio::main] 6 | async fn main() -> Result<()> { 7 | let config = config::Config::from_env()?; 8 | 9 | let report = interop_tests::run_test( 10 | &config.transport, 11 | &config.ip, 12 | config.is_dialer, 13 | config.test_timeout, 14 | &config.redis_addr, 15 | config.sec_protocol, 16 | config.muxer, 17 | ) 18 | .await?; 19 | 20 | println!("{}", serde_json::to_string(&report)?); 21 | 22 | Ok(()) 23 | } 24 | -------------------------------------------------------------------------------- /libp2p/src/builder/phase/build.rs: -------------------------------------------------------------------------------- 1 | use std::time::Duration; 2 | 3 | use libp2p_core::{transport::timeout::TransportTimeout, Transport}; 4 | use libp2p_swarm::Swarm; 5 | 6 | #[allow(unused_imports)] 7 | use super::*; 8 | use crate::SwarmBuilder; 9 | 10 | pub struct BuildPhase { 11 | pub(crate) behaviour: B, 12 | pub(crate) transport: T, 13 | pub(crate) swarm_config: libp2p_swarm::Config, 14 | pub(crate) connection_timeout: Duration, 15 | } 16 | 17 | impl 18 | SwarmBuilder> 19 | { 20 | /// Timeout of the [`TransportTimeout`] wrapping the transport. 21 | pub fn with_connection_timeout(mut self, connection_timeout: Duration) -> Self { 22 | self.phase.connection_timeout = connection_timeout; 23 | self 24 | } 25 | 26 | pub fn build(self) -> Swarm { 27 | Swarm::new( 28 | TransportTimeout::new(self.phase.transport, self.phase.connection_timeout).boxed(), 29 | self.phase.behaviour, 30 | self.keypair.public().to_peer_id(), 31 | self.phase.swarm_config, 32 | ) 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /libp2p/src/builder/phase/identity.rs: -------------------------------------------------------------------------------- 1 | use std::marker::PhantomData; 2 | 3 | use super::*; 4 | use crate::SwarmBuilder; 5 | 6 | pub struct IdentityPhase {} 7 | 8 | impl SwarmBuilder { 9 | pub fn with_new_identity() -> SwarmBuilder { 10 | SwarmBuilder::with_existing_identity(libp2p_identity::Keypair::generate_ed25519()) 11 | } 12 | 13 | pub fn with_existing_identity( 14 | keypair: libp2p_identity::Keypair, 15 | ) -> SwarmBuilder { 16 | SwarmBuilder { 17 | keypair, 18 | phantom: PhantomData, 19 | phase: ProviderPhase {}, 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /libp2p/src/tutorials.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Parity Technologies (UK) Ltd. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the "Software"), 5 | // to deal in the Software without restriction, including without limitation 6 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, 7 | // and/or sell copies of the Software, and to permit persons to whom the 8 | // Software is furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 14 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19 | // DEALINGS IN THE SOFTWARE. 20 | 21 | //! Rust-libp2p Tutorials to get started with. 22 | 23 | pub mod hole_punching; 24 | pub mod ping; 25 | -------------------------------------------------------------------------------- /misc/allow-block-list/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 0.5.0 2 | 3 | - Add getters & setters for the allowed/blocked peers. 4 | Return a `bool` for every "insert/remove" function, informing if a change was performed. 5 | See [PR 5572](https://github.com/libp2p/rust-libp2p/pull/5572). 6 | - Deprecate `void` crate. 7 | See [PR 5676](https://github.com/libp2p/rust-libp2p/pull/5676). 8 | 9 | 10 | 11 | ## 0.4.0 12 | 13 | 14 | 15 | ## 0.3.0 16 | 17 | 18 | ## 0.2.0 19 | 20 | - Raise MSRV to 1.65. 21 | See [PR 3715]. 22 | 23 | [PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715 24 | 25 | ## 0.1.1 26 | 27 | - Correctly unblock and disallow peer in `unblock_peer` and `disallow_peer` functions. 28 | See [PR 3789]. 29 | 30 | [PR 3789]: https://github.com/libp2p/rust-libp2p/pull/3789 31 | 32 | ## 0.1.0 33 | 34 | - Initial release. 35 | -------------------------------------------------------------------------------- /misc/allow-block-list/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "libp2p-allow-block-list" 3 | edition.workspace = true 4 | rust-version = { workspace = true } 5 | description = "Allow/block list connection management for libp2p." 6 | version = "0.5.0" 7 | license = "MIT" 8 | repository = "https://github.com/libp2p/rust-libp2p" 9 | keywords = ["peer-to-peer", "libp2p", "networking"] 10 | categories = ["network-programming", "asynchronous"] 11 | 12 | [dependencies] 13 | libp2p-core = { workspace = true } 14 | libp2p-swarm = { workspace = true } 15 | libp2p-identity = { workspace = true, features = ["peerid"] } 16 | 17 | [dev-dependencies] 18 | tokio = { workspace = true, features = ["rt", "macros"] } 19 | libp2p-swarm-derive = { path = "../../swarm-derive" } 20 | libp2p-swarm-test = { path = "../../swarm-test" } 21 | 22 | [lints] 23 | workspace = true 24 | -------------------------------------------------------------------------------- /misc/connection-limits/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 0.5.1 2 | 3 | - Allow setting Peer IDs for bypassing limit check. 4 | Connections to the specified peers won't be counted toward limits. 5 | See [PR 5720](https://github.com/libp2p/rust-libp2p/pull/5720). 6 | 7 | ## 0.5.0 8 | 9 | - Deprecate `void` crate. 10 | See [PR 5676](https://github.com/libp2p/rust-libp2p/pull/5676). 11 | 12 | 13 | 14 | ## 0.4.0 15 | 16 | 17 | 18 | ## 0.3.1 19 | 20 | - Add function to mutate `ConnectionLimits`. 21 | See [PR 4964](https://github.com/libp2p/rust-libp2p/pull/4964). 22 | 23 | ## 0.3.0 24 | 25 | 26 | ## 0.2.1 27 | 28 | - Do not count a connection as established when it is denied by another sibling `NetworkBehaviour`. 29 | In other words, do not increase established connection counter in `handle_established_outbound_connection` or `handle_established_inbound_connection`, but in `FromSwarm::ConnectionEstablished` instead. 30 | 31 | See [PR 4250]. 32 | 33 | - Decrease `pending_inbound_connections` on `FromSwarm::ListenFailure` and `pending_outbound_connections` on `FromSwarm::DialFailure`. 34 | 35 | See [PR 4250]. 36 | 37 | [PR 4250]: https://github.com/libp2p/rust-libp2p/pull/4250 38 | 39 | ## 0.2.0 40 | 41 | 42 | - Raise MSRV to 1.65. 43 | See [PR 3715]. 44 | 45 | [PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715 46 | 47 | ## 0.1.0 48 | 49 | - Initial release. 50 | -------------------------------------------------------------------------------- /misc/connection-limits/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "libp2p-connection-limits" 3 | edition.workspace = true 4 | rust-version = { workspace = true } 5 | description = "Connection limits for libp2p." 6 | version = "0.5.1" 7 | license = "MIT" 8 | repository = "https://github.com/libp2p/rust-libp2p" 9 | keywords = ["peer-to-peer", "libp2p", "networking"] 10 | categories = ["network-programming", "asynchronous"] 11 | 12 | [dependencies] 13 | libp2p-core = { workspace = true } 14 | libp2p-swarm = { workspace = true } 15 | libp2p-identity = { workspace = true, features = ["peerid"] } 16 | 17 | [dev-dependencies] 18 | tokio = { workspace = true, features = ["macros", "rt-multi-thread"] } 19 | libp2p-identify = { workspace = true } 20 | libp2p-ping = { workspace = true } 21 | libp2p-swarm-derive = { path = "../../swarm-derive" } 22 | libp2p-swarm-test = { path = "../../swarm-test" } 23 | quickcheck = { workspace = true } 24 | rand = "0.8.5" 25 | 26 | [lints] 27 | workspace = true 28 | -------------------------------------------------------------------------------- /misc/keygen/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "keygen" 3 | version = "0.1.0" 4 | edition.workspace = true 5 | authors = ["demfabris "] 6 | license = "MIT" 7 | repository = "https://github.com/libp2p/rust-libp2p" 8 | keywords = ["peer-to-peer", "libp2p", "networking"] 9 | categories = ["network-programming", "asynchronous"] 10 | publish = false 11 | 12 | [package.metadata.release] 13 | release = false 14 | 15 | [dependencies] 16 | clap = { version = "4.5.6", features = ["derive"] } 17 | zeroize = "1" 18 | serde = { version = "1.0.203", features = ["derive"] } 19 | serde_json = "1.0.117" 20 | base64 = "0.22.1" 21 | libp2p-identity = { workspace = true } 22 | 23 | [lints] 24 | workspace = true 25 | -------------------------------------------------------------------------------- /misc/keygen/src/config.rs: -------------------------------------------------------------------------------- 1 | use std::{error::Error, path::Path}; 2 | 3 | use base64::prelude::*; 4 | use libp2p_identity::{Keypair, PeerId}; 5 | use serde::{Deserialize, Serialize}; 6 | 7 | #[derive(Clone, Serialize, Deserialize)] 8 | #[serde(rename_all = "PascalCase")] 9 | pub(crate) struct Config { 10 | pub(crate) identity: Identity, 11 | } 12 | 13 | impl Config { 14 | pub(crate) fn from_file(path: &Path) -> Result> { 15 | Ok(serde_json::from_str(&std::fs::read_to_string(path)?)?) 16 | } 17 | 18 | pub(crate) fn from_key_material( 19 | peer_id: PeerId, 20 | keypair: &Keypair, 21 | ) -> Result> { 22 | let priv_key = BASE64_STANDARD.encode(keypair.to_protobuf_encoding()?); 23 | let peer_id = peer_id.to_base58(); 24 | Ok(Self { 25 | identity: Identity { peer_id, priv_key }, 26 | }) 27 | } 28 | } 29 | 30 | #[derive(Clone, Serialize, Deserialize)] 31 | #[serde(rename_all = "PascalCase")] 32 | pub(crate) struct Identity { 33 | #[serde(rename = "PeerID")] 34 | pub(crate) peer_id: String, 35 | pub(crate) priv_key: String, 36 | } 37 | 38 | impl zeroize::Zeroize for Config { 39 | fn zeroize(&mut self) { 40 | self.identity.peer_id.zeroize(); 41 | self.identity.priv_key.zeroize(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /misc/memory-connection-limits/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 0.4.0 2 | 3 | - Deprecate `void` crate. 4 | See [PR 5676](https://github.com/libp2p/rust-libp2p/pull/5676). 5 | 6 | 7 | 8 | ## 0.3.0 9 | 10 | 11 | 12 | ## 0.2.0 13 | 14 | 15 | ## 0.1.0 16 | 17 | - Initial release. 18 | -------------------------------------------------------------------------------- /misc/memory-connection-limits/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "libp2p-memory-connection-limits" 3 | edition.workspace = true 4 | rust-version = { workspace = true } 5 | description = "Memory usage based connection limits for libp2p." 6 | version = "0.4.0" 7 | license = "MIT" 8 | repository = "https://github.com/libp2p/rust-libp2p" 9 | keywords = ["peer-to-peer", "libp2p", "networking"] 10 | categories = ["network-programming", "asynchronous"] 11 | 12 | [dependencies] 13 | memory-stats = { version = "1", features = ["always_use_statm"] } 14 | libp2p-core = { workspace = true } 15 | libp2p-swarm = { workspace = true } 16 | libp2p-identity = { workspace = true, features = ["peerid"] } 17 | sysinfo = "0.33" 18 | tracing = { workspace = true } 19 | 20 | [dev-dependencies] 21 | libp2p-identify = { workspace = true } 22 | libp2p-swarm-derive = { path = "../../swarm-derive" } 23 | libp2p-swarm-test = { path = "../../swarm-test" } 24 | 25 | [lints] 26 | workspace = true 27 | -------------------------------------------------------------------------------- /misc/metrics/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "libp2p-metrics" 3 | edition.workspace = true 4 | rust-version = { workspace = true } 5 | description = "Metrics for libp2p" 6 | version = "0.16.1" 7 | authors = ["Max Inden "] 8 | license = "MIT" 9 | repository = "https://github.com/libp2p/rust-libp2p" 10 | keywords = ["peer-to-peer", "libp2p", "networking"] 11 | categories = ["network-programming", "asynchronous"] 12 | 13 | [features] 14 | dcutr = ["libp2p-dcutr"] 15 | gossipsub = ["libp2p-gossipsub"] 16 | identify = ["libp2p-identify"] 17 | kad = ["libp2p-kad"] 18 | ping = ["libp2p-ping"] 19 | relay = ["libp2p-relay"] 20 | 21 | [dependencies] 22 | futures = { workspace = true } 23 | web-time = { workspace = true } 24 | libp2p-core = { workspace = true } 25 | libp2p-dcutr = { workspace = true, optional = true } 26 | libp2p-gossipsub = { workspace = true, optional = true } 27 | libp2p-identify = { workspace = true, optional = true } 28 | libp2p-identity = { workspace = true } 29 | libp2p-kad = { workspace = true, optional = true } 30 | libp2p-ping = { workspace = true, optional = true } 31 | libp2p-relay = { workspace = true, optional = true } 32 | libp2p-swarm = { workspace = true } 33 | pin-project = "1.1.5" 34 | prometheus-client = { workspace = true } 35 | 36 | [dev-dependencies] 37 | libp2p-identity = { workspace = true, features = ["rand"] } 38 | 39 | # Passing arguments to the docsrs builder in order to properly document cfg's. 40 | # More information: https://docs.rs/about/builds#cross-compiling 41 | [package.metadata.docs.rs] 42 | all-features = true 43 | 44 | [lints] 45 | workspace = true 46 | -------------------------------------------------------------------------------- /misc/metrics/src/gossipsub.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Protocol Labs. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the "Software"), 5 | // to deal in the Software without restriction, including without limitation 6 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, 7 | // and/or sell copies of the Software, and to permit persons to whom the 8 | // Software is furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 14 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19 | // DEALINGS IN THE SOFTWARE. 20 | 21 | use prometheus_client::{metrics::counter::Counter, registry::Registry}; 22 | 23 | pub(crate) struct Metrics { 24 | messages: Counter, 25 | } 26 | 27 | impl Metrics { 28 | pub(crate) fn new(registry: &mut Registry) -> Self { 29 | let sub_registry = registry.sub_registry_with_prefix("gossipsub"); 30 | 31 | let messages = Counter::default(); 32 | sub_registry.register("messages", "Number of messages received", messages.clone()); 33 | 34 | Self { messages } 35 | } 36 | } 37 | 38 | impl super::Recorder for Metrics { 39 | fn record(&self, event: &libp2p_gossipsub::Event) { 40 | if let libp2p_gossipsub::Event::Message { .. } = event { 41 | self.messages.inc(); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /misc/metrics/src/protocol_stack.rs: -------------------------------------------------------------------------------- 1 | use libp2p_core::multiaddr::Multiaddr; 2 | 3 | pub(crate) fn as_string(ma: &Multiaddr) -> String { 4 | let len = ma 5 | .protocol_stack() 6 | .fold(0, |acc, proto| acc + proto.len() + 1); 7 | let mut protocols = String::with_capacity(len); 8 | for proto_tag in ma.protocol_stack() { 9 | protocols.push('/'); 10 | protocols.push_str(proto_tag); 11 | } 12 | protocols 13 | } 14 | 15 | #[cfg(test)] 16 | mod tests { 17 | use super::*; 18 | 19 | #[test] 20 | fn ip6_tcp_wss_p2p() { 21 | let ma = Multiaddr::try_from("/ip6/2001:8a0:7ac5:4201:3ac9:86ff:fe31:7095/tcp/8000/wss/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC").expect("testbad"); 22 | 23 | let protocol_stack = as_string(&ma); 24 | 25 | assert_eq!(protocol_stack, "/ip6/tcp/wss/p2p"); 26 | 27 | let ma = Multiaddr::try_from("/ip6/2001:8a0:7ac5:4201:3ac9:86ff:fe31:7095/tcp/8000/tls/ws/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC").expect("testbad"); 28 | 29 | let protocol_stack = as_string(&ma); 30 | 31 | assert_eq!(protocol_stack, "/ip6/tcp/tls/ws/p2p"); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /misc/multistream-select/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "multistream-select" 3 | edition.workspace = true 4 | rust-version = { workspace = true } 5 | description = "Multistream-select negotiation protocol for libp2p" 6 | version = "0.13.0" 7 | authors = ["Parity Technologies "] 8 | license = "MIT" 9 | repository = "https://github.com/libp2p/rust-libp2p" 10 | keywords = ["peer-to-peer", "libp2p", "networking"] 11 | categories = ["network-programming", "asynchronous"] 12 | 13 | [dependencies] 14 | bytes = "1" 15 | futures = { workspace = true } 16 | tracing = { workspace = true } 17 | pin-project = "1.1.5" 18 | smallvec = "1.13.2" 19 | unsigned-varint = { workspace = true } 20 | 21 | [dev-dependencies] 22 | async-std = { version = "1.6.2", features = ["attributes"] } 23 | futures_ringbuf = "0.4.0" 24 | quickcheck = { workspace = true } 25 | rw-stream-sink = { workspace = true } 26 | tracing-subscriber = { workspace = true, features = ["env-filter"] } 27 | 28 | # Passing arguments to the docsrs builder in order to properly document cfg's. 29 | # More information: https://docs.rs/about/builds#cross-compiling 30 | [package.metadata.docs.rs] 31 | all-features = true 32 | 33 | [lints] 34 | workspace = true 35 | -------------------------------------------------------------------------------- /misc/peer-store/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 0.1.0 2 | 3 | - Introduce `libp2p-peer-store`. 4 | See [PR 5724](https://github.com/libp2p/rust-libp2p/pull/5724). 5 | -------------------------------------------------------------------------------- /misc/peer-store/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "libp2p-peer-store" 3 | edition.workspace = true 4 | version = "0.1.0" 5 | authors = ["drHuangMHT "] 6 | license = "MIT" 7 | repository = "https://github.com/libp2p/rust-libp2p" 8 | publish = false 9 | rust-version.workspace = true 10 | 11 | [dependencies] 12 | libp2p-core = { workspace = true } 13 | libp2p-swarm = { workspace = true } 14 | lru = "0.12.3" 15 | libp2p-identity = { workspace = true, optional = true } 16 | 17 | [dev-dependencies] 18 | tokio = { workspace = true, features = ["macros", "rt-multi-thread"] } 19 | libp2p-identity = { workspace = true, features = ["rand", "serde"] } 20 | libp2p = { workspace = true, features = ["macros", "identify"] } 21 | libp2p-swarm-test = { path = "../../swarm-test", features = ["tokio"] } 22 | serde_json = { version = "1.0.134" } 23 | 24 | [lints] 25 | workspace = true 26 | -------------------------------------------------------------------------------- /misc/peer-store/src/lib.rs: -------------------------------------------------------------------------------- 1 | //! Implementation of peer store that stores address information 2 | //! about foreign peers. 3 | //! 4 | //! ## Important Discrepancies 5 | //! - **PeerStore is a local**: The peer store itself doesn't facilitate any information exchange 6 | //! between peers. You will need other protocols like `libp2p-kad` to share addresses you know 7 | //! across the network. 8 | //! - **PeerStore is a standalone**: Other protocols cannot expect the existence of PeerStore, and 9 | //! need to be manually hooked up to PeerStore in order to obtain information it provides. 10 | //! 11 | //! ## Usage 12 | //! Compose [`Behaviour`] with other [`NetworkBehaviour`](libp2p_swarm::NetworkBehaviour), 13 | //! and the PeerStore will automatically track addresses from 14 | //! [`FromSwarm::NewExternalAddrOfPeer`](libp2p_swarm::FromSwarm) 15 | //! and provide addresses when dialing peers(require `extend_addresses_through_behaviour` in 16 | //! [`DialOpts`](libp2p_swarm::dial_opts::DialOpts) when dialing). 17 | //! Other protocols need to be manually hooked up to obtain information from 18 | //! or provide information to PeerStore. 19 | 20 | mod behaviour; 21 | pub mod memory_store; 22 | mod store; 23 | 24 | pub use behaviour::{Behaviour, Event}; 25 | pub use store::Store; 26 | -------------------------------------------------------------------------------- /misc/peer-store/src/store.rs: -------------------------------------------------------------------------------- 1 | use std::{fmt::Debug, task::Context}; 2 | 3 | use libp2p_core::{Multiaddr, PeerId}; 4 | use libp2p_swarm::FromSwarm; 5 | 6 | /// A store that contains all observed addresses of peers. 7 | pub trait Store { 8 | /// Event generated by the store and emitted to [`Swarm`](libp2p_swarm::Swarm). 9 | /// [`Behaviour`](crate::Behaviour) cannot handle this event. 10 | type FromStore: Debug + Send; 11 | 12 | /// How this store handles events from [`Swarm`](libp2p_swarm::Swarm). 13 | fn on_swarm_event(&mut self, event: &FromSwarm); 14 | 15 | /// Get all stored addresses of the peer. 16 | fn addresses_of_peer(&self, peer: &PeerId) -> Option>; 17 | 18 | /// Polls for things that the store should do. 19 | /// The task should be waked up to emit events to [`Behaviour`](crate::Behaviour) and 20 | /// [`Swarm`](libp2p_swarm::Swarm). 21 | fn poll(&mut self, cx: &mut Context<'_>) -> Option>; 22 | } 23 | 24 | /// Event that will be handled by [`Behaviour`](crate::Behaviour). 25 | pub enum Event { 26 | /// An address record has been updated. 27 | RecordUpdated(PeerId), 28 | /// Event generated by the store. 29 | /// [`Behaviour`](crate::Behaviour) can only forward the event to swarm. 30 | Store(T), 31 | } 32 | -------------------------------------------------------------------------------- /misc/quick-protobuf-codec/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 0.3.1 2 | 3 | - Reduce allocations during encoding. 4 | See [PR 4782](https://github.com/libp2p/rust-libp2p/pull/4782). 5 | 6 | ## 0.3.0 7 | 8 | - Update to `asynchronous-codec` `v0.7.0`. 9 | See [PR 4636](https://github.com/libp2p/rust-libp2p/pull/4636). 10 | 11 | ## 0.2.0 12 | 13 | - Raise MSRV to 1.65. 14 | See [PR 3715]. 15 | 16 | [PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715 17 | 18 | ## 0.1.0 19 | 20 | - Migrate from `prost` to `quick-protobuf`. This removes `protoc` dependency. See [PR 3312]. 21 | 22 | [PR 3312]: https://github.com/libp2p/rust-libp2p/pull/3312 23 | -------------------------------------------------------------------------------- /misc/quick-protobuf-codec/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "quick-protobuf-codec" 3 | edition.workspace = true 4 | rust-version = { workspace = true } 5 | description = "Asynchronous de-/encoding of Protobuf structs using asynchronous-codec, unsigned-varint and quick-protobuf." 6 | version = "0.3.1" 7 | authors = ["Max Inden "] 8 | license = "MIT" 9 | repository = "https://github.com/libp2p/rust-libp2p" 10 | keywords = ["networking"] 11 | categories = ["asynchronous"] 12 | 13 | [dependencies] 14 | asynchronous-codec = { workspace = true } 15 | bytes = { version = "1" } 16 | thiserror = { workspace = true } 17 | unsigned-varint = { workspace = true, features = ["std"] } 18 | quick-protobuf = "0.8" 19 | 20 | [dev-dependencies] 21 | criterion = "0.5.1" 22 | futures = { workspace = true } 23 | quickcheck = { workspace = true } 24 | 25 | [[bench]] 26 | name = "codec" 27 | harness = false 28 | 29 | # Passing arguments to the docsrs builder in order to properly document cfg's. 30 | # More information: https://docs.rs/about/builds#cross-compiling 31 | [package.metadata.docs.rs] 32 | all-features = true 33 | 34 | [lints] 35 | workspace = true 36 | -------------------------------------------------------------------------------- /misc/quick-protobuf-codec/benches/codec.rs: -------------------------------------------------------------------------------- 1 | use asynchronous_codec::Encoder; 2 | use bytes::BytesMut; 3 | use criterion::{criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion}; 4 | use quick_protobuf_codec::{proto, Codec}; 5 | 6 | pub fn benchmark(c: &mut Criterion) { 7 | for size in [1000, 10_000, 100_000, 1_000_000, 10_000_000] { 8 | c.bench_with_input(BenchmarkId::new("encode", size), &size, |b, i| { 9 | b.iter_batched( 10 | || { 11 | let mut out = BytesMut::new(); 12 | out.reserve(i + 100); 13 | let codec = Codec::::new(i + 100); 14 | let msg = proto::Message { 15 | data: vec![0; size], 16 | }; 17 | 18 | (codec, out, msg) 19 | }, 20 | |(mut codec, mut out, msg)| codec.encode(msg, &mut out).unwrap(), 21 | BatchSize::SmallInput, 22 | ); 23 | }); 24 | } 25 | } 26 | 27 | criterion_group!(benches, benchmark); 28 | criterion_main!(benches); 29 | -------------------------------------------------------------------------------- /misc/quick-protobuf-codec/src/generated/mod.rs: -------------------------------------------------------------------------------- 1 | // Automatically generated mod.rs 2 | pub mod test; 3 | -------------------------------------------------------------------------------- /misc/quick-protobuf-codec/src/generated/test.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package test; 4 | 5 | message Message { 6 | bytes data = 1; 7 | } 8 | -------------------------------------------------------------------------------- /misc/quick-protobuf-codec/src/generated/test.rs: -------------------------------------------------------------------------------- 1 | // Automatically generated rust module for 'test.proto' file 2 | 3 | #![allow(non_snake_case)] 4 | #![allow(non_upper_case_globals)] 5 | #![allow(non_camel_case_types)] 6 | #![allow(unused_imports)] 7 | #![allow(unknown_lints)] 8 | #![allow(clippy::all)] 9 | #![cfg_attr(rustfmt, rustfmt_skip)] 10 | 11 | 12 | use quick_protobuf::{MessageInfo, MessageRead, MessageWrite, BytesReader, Writer, WriterBackend, Result}; 13 | use quick_protobuf::sizeofs::*; 14 | use super::*; 15 | 16 | #[allow(clippy::derive_partial_eq_without_eq)] 17 | #[derive(Debug, Default, PartialEq, Clone)] 18 | pub struct Message { 19 | pub data: Vec, 20 | } 21 | 22 | impl<'a> MessageRead<'a> for Message { 23 | fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { 24 | let mut msg = Self::default(); 25 | while !r.is_eof() { 26 | match r.next_tag(bytes) { 27 | Ok(10) => msg.data = r.read_bytes(bytes)?.to_owned(), 28 | Ok(t) => { r.read_unknown(bytes, t)?; } 29 | Err(e) => return Err(e), 30 | } 31 | } 32 | Ok(msg) 33 | } 34 | } 35 | 36 | impl MessageWrite for Message { 37 | fn get_size(&self) -> usize { 38 | 0 39 | + if self.data.is_empty() { 0 } else { 1 + sizeof_len((&self.data).len()) } 40 | } 41 | 42 | fn write_message(&self, w: &mut Writer) -> Result<()> { 43 | if !self.data.is_empty() { w.write_with_tag(10, |w| w.write_bytes(&**&self.data))?; } 44 | Ok(()) 45 | } 46 | } 47 | 48 | -------------------------------------------------------------------------------- /misc/quick-protobuf-codec/tests/large_message.rs: -------------------------------------------------------------------------------- 1 | use asynchronous_codec::Encoder; 2 | use bytes::BytesMut; 3 | use quick_protobuf_codec::{proto, Codec}; 4 | 5 | #[test] 6 | fn encode_large_message() { 7 | let mut codec = Codec::::new(1_001_000); 8 | let mut dst = BytesMut::new(); 9 | dst.reserve(1_001_000); 10 | let message = proto::Message { 11 | data: vec![0; 1_000_000], 12 | }; 13 | 14 | codec.encode(message, &mut dst).unwrap(); 15 | } 16 | -------------------------------------------------------------------------------- /misc/quickcheck-ext/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "quickcheck-ext" 3 | version = "0.1.0" 4 | edition.workspace = true 5 | publish = false 6 | license = "Unlicense/MIT" 7 | 8 | [package.metadata.release] 9 | release = false 10 | 11 | [dependencies] 12 | quickcheck = "1" 13 | num-traits = "0.2" 14 | 15 | [lints] 16 | workspace = true 17 | -------------------------------------------------------------------------------- /misc/quickcheck-ext/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] 2 | 3 | use core::ops::Range; 4 | 5 | use num_traits::sign::Unsigned; 6 | pub use quickcheck::*; 7 | 8 | pub trait GenRange { 9 | fn gen_range(&mut self, _range: Range) -> T; 10 | 11 | fn gen_index(&mut self, ubound: usize) -> usize { 12 | if ubound <= (u32::MAX as usize) { 13 | self.gen_range(0..ubound as u32) as usize 14 | } else { 15 | self.gen_range(0..ubound) 16 | } 17 | } 18 | } 19 | 20 | impl GenRange for Gen { 21 | fn gen_range(&mut self, range: Range) -> T { 22 | ::arbitrary(self) % (range.end - range.start) + range.start 23 | } 24 | } 25 | 26 | pub trait SliceRandom { 27 | fn shuffle(&mut self, arr: &mut [T]); 28 | fn choose_multiple<'a, T>( 29 | &mut self, 30 | arr: &'a [T], 31 | amount: usize, 32 | ) -> std::iter::Take> { 33 | let mut v: Vec<&T> = arr.iter().collect(); 34 | self.shuffle(&mut v); 35 | v.into_iter().take(amount) 36 | } 37 | } 38 | 39 | impl SliceRandom for Gen { 40 | fn shuffle(&mut self, arr: &mut [T]) { 41 | for i in (1..arr.len()).rev() { 42 | // invariant: elements with index > i have been locked in place. 43 | arr.swap(i, self.gen_index(i + 1)); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /misc/rw-stream-sink/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 0.4.0 2 | 3 | - Raise MSRV to 1.65. 4 | See [PR 3715]. 5 | 6 | [PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715 7 | 8 | ## 0.3.0 9 | 10 | - Move from https://github.com/paritytech/rw-stream-sink/ to https://github.com/libp2p/rust-libp2p. See [Issue 2504]. 11 | 12 | - Update to Rust edition 2021. 13 | 14 | [Issue 2504]: https://github.com/libp2p/rust-libp2p/issues/2504 15 | -------------------------------------------------------------------------------- /misc/rw-stream-sink/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "rw-stream-sink" 3 | edition.workspace = true 4 | description = "Adaptator between Stream/Sink and AsyncRead/AsyncWrite" 5 | rust-version = { workspace = true } 6 | version = "0.4.0" 7 | authors = ["Parity Technologies "] 8 | license = "MIT" 9 | repository = "https://github.com/libp2p/rust-libp2p" 10 | keywords = ["networking"] 11 | categories = ["network-programming", "asynchronous"] 12 | 13 | [dependencies] 14 | futures = { workspace = true } 15 | pin-project = "1.1.5" 16 | static_assertions = "1" 17 | 18 | [dev-dependencies] 19 | async-std = "1.0" 20 | 21 | # Passing arguments to the docsrs builder in order to properly document cfg's. 22 | # More information: https://docs.rs/about/builds#cross-compiling 23 | [package.metadata.docs.rs] 24 | all-features = true 25 | 26 | [lints] 27 | workspace = true 28 | -------------------------------------------------------------------------------- /misc/server/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "libp2p-server" 3 | version = "0.12.7" 4 | authors = ["Max Inden "] 5 | edition.workspace = true 6 | repository = "https://github.com/libp2p/rust-libp2p" 7 | rust-version = { workspace = true } 8 | description = "A rust-libp2p server binary." 9 | license = "MIT" 10 | 11 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 12 | 13 | [dependencies] 14 | base64 = "0.22" 15 | clap = { version = "4.5.6", features = ["derive"] } 16 | futures = { workspace = true } 17 | axum = "0.7" 18 | libp2p = { workspace = true, features = [ 19 | "autonat", 20 | "dns", 21 | "tokio", 22 | "noise", 23 | "tcp", 24 | "yamux", 25 | "identify", 26 | "kad", 27 | "ping", 28 | "relay", 29 | "metrics", 30 | "rsa", 31 | "macros", 32 | "quic", 33 | "websocket", 34 | ] } 35 | prometheus-client = { workspace = true } 36 | serde = { version = "1", features = ["derive"] } 37 | serde_json = "1.0" 38 | tokio = { workspace = true, features = ["rt-multi-thread", "macros"] } 39 | tracing = { workspace = true } 40 | tracing-subscriber = { workspace = true, features = ["env-filter"] } 41 | zeroize = "1" 42 | 43 | [lints] 44 | workspace = true 45 | -------------------------------------------------------------------------------- /misc/server/Dockerfile: -------------------------------------------------------------------------------- 1 | # syntax=docker/dockerfile:1.5-labs 2 | FROM rust:1.83.0 as chef 3 | RUN wget -q -O- https://github.com/LukeMathWalker/cargo-chef/releases/download/v0.1.62/cargo-chef-x86_64-unknown-linux-gnu.tar.gz | tar -zx -C /usr/local/bin 4 | WORKDIR /app 5 | 6 | FROM chef AS planner 7 | COPY . . 8 | RUN cargo chef prepare --recipe-path recipe.json 9 | 10 | FROM chef AS builder 11 | COPY --from=planner /app/recipe.json recipe.json 12 | # Build dependencies - this is the caching Docker layer! 13 | RUN cargo chef cook --release --package libp2p-server --recipe-path recipe.json 14 | # Build application 15 | COPY . . 16 | RUN cargo build --release --package libp2p-server 17 | 18 | FROM gcr.io/distroless/cc 19 | CMD ["libp2p-server"] 20 | -------------------------------------------------------------------------------- /misc/server/README.md: -------------------------------------------------------------------------------- 1 | # Rust libp2p Server 2 | 3 | A rust-libp2p based server implementation running: 4 | 5 | - the [Kademlia protocol](https://github.com/libp2p/specs/tree/master/kad-dht) 6 | 7 | - the [Circuit Relay v2 protocol](https://github.com/libp2p/specs/blob/master/relay/circuit-v2.md) 8 | 9 | - the [AutoNAT protocol](https://github.com/libp2p/specs/blob/master/autonat/README.md) 10 | 11 | ## Usage 12 | 13 | ``` 14 | cargo run -- --help 15 | 16 | A rust-libp2p server binary. 17 | 18 | Usage: libp2p-server [OPTIONS] --config 19 | 20 | Options: 21 | --config Path to IPFS config file 22 | --metrics-path Metric endpoint path [default: /metrics] 23 | --enable-kademlia Whether to run the libp2p Kademlia protocol and join the IPFS DHT 24 | --enable-autonat Whether to run the libp2p Autonat protocol 25 | -h, --help Print help 26 | ``` 27 | 28 | ``` 29 | cargo run -- --config ~/.ipfs/config 30 | 31 | Local peer id: PeerId("12D3KooWSa1YEeQVSwvoqAMhwjKQ6kqZQckhWPb3RWEGV3sZGU6Z") 32 | Listening on "/ip4/127.0.0.1/udp/4001/quic" 33 | [...] 34 | ``` 35 | -------------------------------------------------------------------------------- /misc/server/src/config.rs: -------------------------------------------------------------------------------- 1 | use std::{error::Error, path::Path}; 2 | 3 | use libp2p::Multiaddr; 4 | use serde::Deserialize; 5 | 6 | #[derive(Clone, Deserialize)] 7 | #[serde(rename_all = "PascalCase")] 8 | pub(crate) struct Config { 9 | pub(crate) identity: Identity, 10 | pub(crate) addresses: Addresses, 11 | } 12 | 13 | impl Config { 14 | pub(crate) fn from_file(path: &Path) -> Result> { 15 | Ok(serde_json::from_str(&std::fs::read_to_string(path)?)?) 16 | } 17 | } 18 | 19 | #[derive(Clone, Deserialize)] 20 | #[serde(rename_all = "PascalCase")] 21 | pub(crate) struct Identity { 22 | #[serde(rename = "PeerID")] 23 | pub(crate) peer_id: String, 24 | pub(crate) priv_key: String, 25 | } 26 | 27 | #[derive(Clone, Deserialize)] 28 | #[serde(rename_all = "PascalCase")] 29 | pub(crate) struct Addresses { 30 | pub(crate) swarm: Vec, 31 | pub(crate) append_announce: Vec, 32 | } 33 | 34 | impl zeroize::Zeroize for Config { 35 | fn zeroize(&mut self) { 36 | self.identity.peer_id.zeroize(); 37 | self.identity.priv_key.zeroize(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /misc/webrtc-utils/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 0.4.0 2 | 3 | 4 | 5 | ## 0.3.0 6 | 7 | 8 | 9 | ## 0.2.1 10 | 11 | - Fix end of stream handling when buffer is empty or not present. 12 | See [PR 5439](https://github.com/libp2p/rust-libp2p/pull/5439). 13 | 14 | ## 0.2.0 15 | 16 | - Update to latest version of `libp2p-noise`. 17 | See [PR 4968](https://github.com/libp2p/rust-libp2p/pull/4968). 18 | 19 | ## 0.1.0 20 | 21 | - Initial release. 22 | See [PR 4248]. 23 | 24 | [PR 4248]: https://github.com/libp2p/rust-libp2p/pull/4248 25 | -------------------------------------------------------------------------------- /misc/webrtc-utils/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | authors = ["Doug Anderson "] 3 | categories = ["network-programming"] 4 | description = "Utilities for WebRTC in libp2p" 5 | edition.workspace = true 6 | license = "MIT" 7 | name = "libp2p-webrtc-utils" 8 | repository = "https://github.com/libp2p/rust-libp2p" 9 | rust-version = { workspace = true } 10 | version = "0.4.0" 11 | publish = true 12 | 13 | [dependencies] 14 | asynchronous-codec = { workspace = true } 15 | bytes = "1" 16 | futures = { workspace = true } 17 | hex = "0.4" 18 | libp2p-core = { workspace = true } 19 | libp2p-identity = { workspace = true } 20 | libp2p-noise = { workspace = true } 21 | quick-protobuf = "0.8" 22 | quick-protobuf-codec = { workspace = true } 23 | rand = "0.8" 24 | serde = { version = "1.0", features = ["derive"] } 25 | sha2 = "0.10.8" 26 | tinytemplate = "1.2" 27 | tracing = { workspace = true } 28 | 29 | [dev-dependencies] 30 | hex-literal = "0.4" 31 | 32 | [lints] 33 | workspace = true 34 | -------------------------------------------------------------------------------- /misc/webrtc-utils/src/generated/message.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | package webrtc.pb; 4 | 5 | message Message { 6 | enum Flag { 7 | // The sender will no longer send messages on the stream. 8 | FIN = 0; 9 | // The sender will no longer read messages on the stream. Incoming data is 10 | // being discarded on receipt. 11 | STOP_SENDING = 1; 12 | // The sender abruptly terminates the sending part of the stream. The 13 | // receiver can discard any data that it already received on that stream. 14 | RESET = 2; 15 | } 16 | 17 | optional Flag flag=1; 18 | 19 | optional bytes message = 2; 20 | } 21 | -------------------------------------------------------------------------------- /misc/webrtc-utils/src/generated/mod.rs: -------------------------------------------------------------------------------- 1 | // Automatically generated mod.rs 2 | pub mod webrtc; 3 | -------------------------------------------------------------------------------- /misc/webrtc-utils/src/generated/webrtc/mod.rs: -------------------------------------------------------------------------------- 1 | // Automatically generated mod.rs 2 | pub mod pb; 3 | -------------------------------------------------------------------------------- /misc/webrtc-utils/src/lib.rs: -------------------------------------------------------------------------------- 1 | mod proto { 2 | #![allow(unreachable_pub)] 3 | include!("generated/mod.rs"); 4 | pub use self::webrtc::pb::{mod_Message::Flag, Message}; 5 | } 6 | 7 | mod fingerprint; 8 | pub mod noise; 9 | pub mod sdp; 10 | mod stream; 11 | mod transport; 12 | 13 | pub use fingerprint::{Fingerprint, SHA256}; 14 | pub use stream::{DropListener, Stream, MAX_MSG_LEN}; 15 | pub use transport::parse_webrtc_dial_addr; 16 | -------------------------------------------------------------------------------- /muxers/mplex/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "libp2p-mplex" 3 | edition.workspace = true 4 | rust-version = { workspace = true } 5 | description = "Mplex multiplexing protocol for libp2p" 6 | version = "0.43.1" 7 | authors = ["Parity Technologies "] 8 | license = "MIT" 9 | repository = "https://github.com/libp2p/rust-libp2p" 10 | keywords = ["peer-to-peer", "libp2p", "networking"] 11 | categories = ["network-programming", "asynchronous"] 12 | 13 | [dependencies] 14 | bytes = "1" 15 | futures = { workspace = true } 16 | asynchronous-codec = { workspace = true } 17 | libp2p-core = { workspace = true } 18 | libp2p-identity = { workspace = true } 19 | nohash-hasher = "0.2" 20 | parking_lot = "0.12" 21 | rand = "0.8" 22 | smallvec = "1.13.2" 23 | tracing = { workspace = true } 24 | unsigned-varint = { workspace = true, features = ["asynchronous_codec"] } 25 | 26 | [dev-dependencies] 27 | async-std = { version = "1.7.0", features = ["attributes"] } 28 | criterion = "0.5" 29 | futures = { workspace = true } 30 | libp2p-identity = { workspace = true, features = ["rand"] } 31 | libp2p-muxer-test-harness = { path = "../test-harness" } 32 | libp2p-plaintext = { workspace = true } 33 | libp2p-tcp = { workspace = true, features = ["async-io"] } 34 | quickcheck = { workspace = true } 35 | tracing-subscriber = { workspace = true, features = ["env-filter"] } 36 | 37 | [[bench]] 38 | name = "split_send_size" 39 | harness = false 40 | 41 | # Passing arguments to the docsrs builder in order to properly document cfg's. 42 | # More information: https://docs.rs/about/builds#cross-compiling 43 | [package.metadata.docs.rs] 44 | all-features = true 45 | 46 | [lints] 47 | workspace = true 48 | -------------------------------------------------------------------------------- /muxers/mplex/tests/compliance.rs: -------------------------------------------------------------------------------- 1 | use libp2p_mplex::Config; 2 | 3 | #[async_std::test] 4 | async fn close_implies_flush() { 5 | let (alice, bob) = 6 | libp2p_muxer_test_harness::connected_muxers_on_memory_ring_buffer::().await; 7 | 8 | libp2p_muxer_test_harness::close_implies_flush(alice, bob).await; 9 | } 10 | 11 | #[async_std::test] 12 | async fn read_after_close() { 13 | let (alice, bob) = 14 | libp2p_muxer_test_harness::connected_muxers_on_memory_ring_buffer::().await; 15 | 16 | libp2p_muxer_test_harness::read_after_close(alice, bob).await; 17 | } 18 | -------------------------------------------------------------------------------- /muxers/test-harness/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "libp2p-muxer-test-harness" 3 | version = "0.1.0" 4 | edition.workspace = true 5 | publish = false 6 | license = "MIT" 7 | 8 | [package.metadata.release] 9 | release = false 10 | 11 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 12 | 13 | [dependencies] 14 | libp2p-core = { workspace = true } 15 | futures = { workspace = true } 16 | futures-timer = "3.0.3" 17 | futures_ringbuf = "0.4.0" 18 | tracing = { workspace = true } 19 | 20 | [lints] 21 | workspace = true 22 | -------------------------------------------------------------------------------- /muxers/yamux/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "libp2p-yamux" 3 | edition.workspace = true 4 | rust-version = { workspace = true } 5 | description = "Yamux multiplexing protocol for libp2p" 6 | version = "0.47.0" 7 | authors = ["Parity Technologies "] 8 | license = "MIT" 9 | repository = "https://github.com/libp2p/rust-libp2p" 10 | keywords = ["peer-to-peer", "libp2p", "networking"] 11 | categories = ["network-programming", "asynchronous"] 12 | 13 | [dependencies] 14 | either = "1" 15 | futures = { workspace = true } 16 | libp2p-core = { workspace = true } 17 | thiserror = { workspace = true } 18 | yamux012 = { version = "0.12.1", package = "yamux" } 19 | yamux013 = { version = "0.13.3", package = "yamux" } 20 | tracing = { workspace = true } 21 | 22 | [dev-dependencies] 23 | tokio = { workspace = true, features = ["macros", "rt-multi-thread"] } 24 | libp2p-muxer-test-harness = { path = "../test-harness" } 25 | 26 | # Passing arguments to the docsrs builder in order to properly document cfg's. 27 | # More information: https://docs.rs/about/builds#cross-compiling 28 | [package.metadata.docs.rs] 29 | all-features = true 30 | 31 | [lints] 32 | workspace = true 33 | -------------------------------------------------------------------------------- /muxers/yamux/tests/compliance.rs: -------------------------------------------------------------------------------- 1 | use libp2p_yamux::Config; 2 | 3 | #[tokio::test] 4 | async fn close_implies_flush() { 5 | let (alice, bob) = 6 | libp2p_muxer_test_harness::connected_muxers_on_memory_ring_buffer::().await; 7 | 8 | libp2p_muxer_test_harness::close_implies_flush(alice, bob).await; 9 | } 10 | 11 | #[tokio::test] 12 | async fn read_after_close() { 13 | let (alice, bob) = 14 | libp2p_muxer_test_harness::connected_muxers_on_memory_ring_buffer::().await; 15 | 16 | libp2p_muxer_test_harness::read_after_close(alice, bob).await; 17 | } 18 | -------------------------------------------------------------------------------- /protocols/autonat/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![cfg_attr(docsrs, feature(doc_auto_cfg))] 2 | 3 | #[cfg(feature = "v1")] 4 | pub mod v1; 5 | 6 | #[cfg(feature = "v2")] 7 | pub mod v2; 8 | 9 | #[cfg(feature = "v1")] 10 | pub use v1::*; 11 | -------------------------------------------------------------------------------- /protocols/autonat/src/v1/generated/mod.rs: -------------------------------------------------------------------------------- 1 | // Automatically generated mod.rs 2 | pub mod structs; 3 | -------------------------------------------------------------------------------- /protocols/autonat/src/v1/generated/structs.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | package structs; 4 | 5 | message Message { 6 | enum MessageType { 7 | DIAL = 0; 8 | DIAL_RESPONSE = 1; 9 | } 10 | 11 | enum ResponseStatus { 12 | OK = 0; 13 | E_DIAL_ERROR = 100; 14 | E_DIAL_REFUSED = 101; 15 | E_BAD_REQUEST = 200; 16 | E_INTERNAL_ERROR = 300; 17 | } 18 | 19 | message PeerInfo { 20 | optional bytes id = 1; 21 | repeated bytes addrs = 2; 22 | } 23 | 24 | message Dial { 25 | optional PeerInfo peer = 1; 26 | } 27 | 28 | message DialResponse { 29 | optional ResponseStatus status = 1; 30 | optional string statusText = 2; 31 | optional bytes addr = 3; 32 | } 33 | 34 | optional MessageType type = 1; 35 | optional Dial dial = 2; 36 | optional DialResponse dialResponse = 3; 37 | } 38 | -------------------------------------------------------------------------------- /protocols/autonat/src/v2.rs: -------------------------------------------------------------------------------- 1 | //! The second version of the autonat protocol. 2 | //! 3 | //! The implementation follows the [libp2p spec](https://github.com/libp2p/specs/blob/03718ef0f2dea4a756a85ba716ee33f97e4a6d6c/autonat/autonat-v2.md). 4 | //! 5 | //! The new version fixes the issues of the first version: 6 | //! - The server now always dials back over a newly allocated port. This greatly reduces the risk of 7 | //! false positives that often occurred in the first version, when the client-server connection 8 | //! occurred over a hole-punched port. 9 | //! - The server protects against DoS attacks by requiring the client to send more data to the 10 | //! server then the dial back puts on the client, thus making the protocol unatractive for an 11 | //! attacker. 12 | //! 13 | //! The protocol is separated into two parts: 14 | //! - The client part, which is implemented in the `client` module. (The client is the party that 15 | //! wants to check if it is reachable from the outside.) 16 | //! - The server part, which is implemented in the `server` module. (The server is the party 17 | //! performing reachability checks on behalf of the client.) 18 | //! 19 | //! The two can be used together. 20 | 21 | use libp2p_swarm::StreamProtocol; 22 | 23 | pub mod client; 24 | pub(crate) mod protocol; 25 | pub mod server; 26 | 27 | pub(crate) mod generated { 28 | #![allow(unreachable_pub)] 29 | include!("v2/generated/mod.rs"); 30 | } 31 | 32 | pub(crate) const DIAL_REQUEST_PROTOCOL: StreamProtocol = 33 | StreamProtocol::new("/libp2p/autonat/2/dial-request"); 34 | pub(crate) const DIAL_BACK_PROTOCOL: StreamProtocol = 35 | StreamProtocol::new("/libp2p/autonat/2/dial-back"); 36 | 37 | type Nonce = u64; 38 | -------------------------------------------------------------------------------- /protocols/autonat/src/v2/client.rs: -------------------------------------------------------------------------------- 1 | mod behaviour; 2 | mod handler; 3 | 4 | pub use behaviour::{Behaviour, Config, Event}; 5 | -------------------------------------------------------------------------------- /protocols/autonat/src/v2/client/handler.rs: -------------------------------------------------------------------------------- 1 | pub(crate) mod dial_back; 2 | pub(crate) mod dial_request; 3 | -------------------------------------------------------------------------------- /protocols/autonat/src/v2/generated/mod.rs: -------------------------------------------------------------------------------- 1 | // Automatically generated mod.rs 2 | pub mod structs; 3 | -------------------------------------------------------------------------------- /protocols/autonat/src/v2/generated/structs.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package structs; 4 | 5 | message Message { 6 | oneof msg { 7 | DialRequest dialRequest = 1; 8 | DialResponse dialResponse = 2; 9 | DialDataRequest dialDataRequest = 3; 10 | DialDataResponse dialDataResponse = 4; 11 | } 12 | } 13 | 14 | message DialRequest { 15 | repeated bytes addrs = 1; 16 | fixed64 nonce = 2; 17 | } 18 | 19 | message DialDataRequest { 20 | uint32 addrIdx = 1; 21 | uint64 numBytes = 2; 22 | } 23 | 24 | enum DialStatus { 25 | UNUSED = 0; 26 | E_DIAL_ERROR = 100; 27 | E_DIAL_BACK_ERROR = 101; 28 | OK = 200; 29 | } 30 | 31 | message DialResponse { 32 | enum ResponseStatus { 33 | E_INTERNAL_ERROR = 0; 34 | E_REQUEST_REJECTED = 100; 35 | E_DIAL_REFUSED = 101; 36 | OK = 200; 37 | } 38 | 39 | ResponseStatus status = 1; 40 | uint32 addrIdx = 2; 41 | DialStatus dialStatus = 3; 42 | } 43 | 44 | message DialDataResponse { bytes data = 1; } 45 | 46 | message DialBack { fixed64 nonce = 1; } 47 | 48 | message DialBackResponse { 49 | enum DialBackStatus { 50 | OK = 0; 51 | } 52 | 53 | DialBackStatus status = 1; 54 | } 55 | -------------------------------------------------------------------------------- /protocols/autonat/src/v2/server.rs: -------------------------------------------------------------------------------- 1 | mod behaviour; 2 | mod handler; 3 | 4 | pub use behaviour::{Behaviour, Event}; 5 | -------------------------------------------------------------------------------- /protocols/autonat/src/v2/server/handler.rs: -------------------------------------------------------------------------------- 1 | use either::Either; 2 | use libp2p_swarm::dummy; 3 | 4 | pub(crate) mod dial_back; 5 | pub(crate) mod dial_request; 6 | 7 | pub(crate) type Handler = 8 | Either, dial_request::Handler>; 9 | -------------------------------------------------------------------------------- /protocols/dcutr/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "libp2p-dcutr" 3 | edition.workspace = true 4 | rust-version = { workspace = true } 5 | description = "Direct connection upgrade through relay" 6 | version = "0.13.0" 7 | authors = ["Max Inden "] 8 | license = "MIT" 9 | repository = "https://github.com/libp2p/rust-libp2p" 10 | keywords = ["peer-to-peer", "libp2p", "networking"] 11 | categories = ["network-programming", "asynchronous"] 12 | 13 | [dependencies] 14 | asynchronous-codec = { workspace = true } 15 | either = "1.11.0" 16 | futures = { workspace = true } 17 | futures-timer = "3.0" 18 | web-time = { workspace = true } 19 | libp2p-core = { workspace = true } 20 | libp2p-swarm = { workspace = true } 21 | libp2p-identity = { workspace = true } 22 | quick-protobuf = "0.8" 23 | quick-protobuf-codec = { workspace = true } 24 | thiserror = { workspace = true } 25 | tracing = { workspace = true } 26 | lru = "0.12.3" 27 | futures-bounded = { workspace = true } 28 | 29 | [dev-dependencies] 30 | libp2p-identify = { workspace = true } 31 | libp2p-plaintext = { workspace = true } 32 | libp2p-relay = { workspace = true } 33 | libp2p-swarm = { workspace = true, features = ["macros"] } 34 | libp2p-swarm-test = { path = "../../swarm-test" } 35 | libp2p-tcp = { workspace = true, features = ["async-io"] } 36 | libp2p-yamux = { workspace = true } 37 | tracing-subscriber = { workspace = true, features = ["env-filter"] } 38 | tokio = { workspace = true, features = ["rt", "macros"] } 39 | 40 | # Passing arguments to the docsrs builder in order to properly document cfg's. 41 | # More information: https://docs.rs/about/builds#cross-compiling 42 | [package.metadata.docs.rs] 43 | all-features = true 44 | 45 | [lints] 46 | workspace = true 47 | -------------------------------------------------------------------------------- /protocols/dcutr/src/generated/holepunch/mod.rs: -------------------------------------------------------------------------------- 1 | // Automatically generated mod.rs 2 | pub mod pb; 3 | -------------------------------------------------------------------------------- /protocols/dcutr/src/generated/message.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | package holepunch.pb; 4 | 5 | message HolePunch { 6 | enum Type { 7 | CONNECT = 100; 8 | SYNC = 300; 9 | } 10 | 11 | required Type type=1; 12 | 13 | // For hole punching, we'll send some additional observed addresses to the remote peer 14 | // that could have been filtered by the Host address factory (for example: AutoRelay removes all public addresses if peer has private reachability). 15 | // This is a hack! 16 | // We plan to have a better address discovery and advertisement mechanism in the future. 17 | // See https://github.com/libp2p/go-libp2p-autonat/pull/98 18 | repeated bytes ObsAddrs = 2; 19 | } 20 | -------------------------------------------------------------------------------- /protocols/dcutr/src/generated/mod.rs: -------------------------------------------------------------------------------- 1 | // Automatically generated mod.rs 2 | pub mod holepunch; 3 | -------------------------------------------------------------------------------- /protocols/dcutr/src/handler.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Protocol Labs. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the "Software"), 5 | // to deal in the Software without restriction, including without limitation 6 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, 7 | // and/or sell copies of the Software, and to permit persons to whom the 8 | // Software is furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 14 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19 | // DEALINGS IN THE SOFTWARE. 20 | 21 | pub(crate) mod relayed; 22 | -------------------------------------------------------------------------------- /protocols/dcutr/src/lib.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Protocol Labs. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the "Software"), 5 | // to deal in the Software without restriction, including without limitation 6 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, 7 | // and/or sell copies of the Software, and to permit persons to whom the 8 | // Software is furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 14 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19 | // DEALINGS IN THE SOFTWARE. 20 | 21 | //! Implementation of the [libp2p Direct Connection Upgrade through Relay 22 | //! specification](https://github.com/libp2p/specs/blob/master/relay/DCUtR.md). 23 | 24 | #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] 25 | 26 | mod behaviour; 27 | mod handler; 28 | mod protocol; 29 | 30 | mod proto { 31 | #![allow(unreachable_pub)] 32 | include!("generated/mod.rs"); 33 | pub(crate) use self::holepunch::pb::{mod_HolePunch::*, HolePunch}; 34 | } 35 | 36 | pub use behaviour::{Behaviour, Error, Event}; 37 | pub use protocol::PROTOCOL_NAME; 38 | pub mod inbound { 39 | pub use crate::protocol::inbound::ProtocolViolation; 40 | } 41 | pub mod outbound { 42 | pub use crate::protocol::outbound::ProtocolViolation; 43 | } 44 | -------------------------------------------------------------------------------- /protocols/dcutr/src/protocol.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Protocol Labs. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the "Software"), 5 | // to deal in the Software without restriction, including without limitation 6 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, 7 | // and/or sell copies of the Software, and to permit persons to whom the 8 | // Software is furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 14 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19 | // DEALINGS IN THE SOFTWARE. 20 | 21 | use libp2p_swarm::StreamProtocol; 22 | 23 | pub(crate) mod inbound; 24 | pub(crate) mod outbound; 25 | pub const PROTOCOL_NAME: StreamProtocol = StreamProtocol::new("/libp2p/dcutr"); 26 | 27 | const MAX_MESSAGE_SIZE_BYTES: usize = 4096; 28 | -------------------------------------------------------------------------------- /protocols/floodsub/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "libp2p-floodsub" 3 | edition.workspace = true 4 | rust-version = { workspace = true } 5 | description = "Floodsub protocol for libp2p" 6 | version = "0.46.1" 7 | authors = ["Parity Technologies "] 8 | license = "MIT" 9 | repository = "https://github.com/libp2p/rust-libp2p" 10 | keywords = ["peer-to-peer", "libp2p", "networking"] 11 | categories = ["network-programming", "asynchronous"] 12 | 13 | [dependencies] 14 | asynchronous-codec = { workspace = true } 15 | cuckoofilter = "0.5.0" 16 | fnv = "1.0" 17 | bytes = "1.6" 18 | futures = { workspace = true } 19 | libp2p-core = { workspace = true } 20 | libp2p-swarm = { workspace = true } 21 | libp2p-identity = { workspace = true } 22 | quick-protobuf = "0.8" 23 | quick-protobuf-codec = { workspace = true } 24 | rand = "0.8" 25 | smallvec = "1.13.2" 26 | thiserror = { workspace = true } 27 | tracing = { workspace = true } 28 | 29 | # Passing arguments to the docsrs builder in order to properly document cfg's. 30 | # More information: https://docs.rs/about/builds#cross-compiling 31 | [package.metadata.docs.rs] 32 | all-features = true 33 | 34 | [lints] 35 | workspace = true 36 | -------------------------------------------------------------------------------- /protocols/floodsub/src/generated/floodsub/mod.rs: -------------------------------------------------------------------------------- 1 | // Automatically generated mod.rs 2 | pub mod pb; 3 | -------------------------------------------------------------------------------- /protocols/floodsub/src/generated/mod.rs: -------------------------------------------------------------------------------- 1 | // Automatically generated mod.rs 2 | pub mod floodsub; 3 | -------------------------------------------------------------------------------- /protocols/floodsub/src/generated/rpc.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | package floodsub.pb; 4 | 5 | message RPC { 6 | repeated SubOpts subscriptions = 1; 7 | repeated Message publish = 2; 8 | 9 | message SubOpts { 10 | optional bool subscribe = 1; // subscribe or unsubscribe 11 | optional string topic_id = 2; 12 | } 13 | } 14 | 15 | message Message { 16 | optional bytes from = 1; 17 | optional bytes data = 2; 18 | optional bytes seqno = 3; 19 | repeated string topic_ids = 4; 20 | } 21 | -------------------------------------------------------------------------------- /protocols/floodsub/src/topic.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Parity Technologies (UK) Ltd. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the "Software"), 5 | // to deal in the Software without restriction, including without limitation 6 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, 7 | // and/or sell copies of the Software, and to permit persons to whom the 8 | // Software is furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 14 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19 | // DEALINGS IN THE SOFTWARE. 20 | 21 | /// Built topic. 22 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] 23 | pub struct Topic(String); 24 | 25 | impl Topic { 26 | /// Returns the id of the topic. 27 | #[inline] 28 | pub fn id(&self) -> &str { 29 | &self.0 30 | } 31 | 32 | pub fn new(name: S) -> Topic 33 | where 34 | S: Into, 35 | { 36 | Topic(name.into()) 37 | } 38 | } 39 | 40 | impl From for String { 41 | fn from(topic: Topic) -> String { 42 | topic.0 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /protocols/gossipsub/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "libp2p-gossipsub" 3 | edition.workspace = true 4 | rust-version = { workspace = true } 5 | description = "Gossipsub protocol for libp2p" 6 | version = "0.49.0" 7 | authors = ["Age Manning "] 8 | license = "MIT" 9 | repository = "https://github.com/libp2p/rust-libp2p" 10 | keywords = ["peer-to-peer", "libp2p", "networking"] 11 | categories = ["network-programming", "asynchronous"] 12 | 13 | [features] 14 | wasm-bindgen = ["getrandom/js", "futures-timer/wasm-bindgen"] 15 | 16 | [dependencies] 17 | async-channel = "2.3.1" 18 | asynchronous-codec = { workspace = true } 19 | base64 = "0.22.1" 20 | byteorder = "1.5.0" 21 | bytes = "1.6" 22 | either = "1.11" 23 | fnv = "1.0.7" 24 | futures = { workspace = true } 25 | futures-timer = "3.0.2" 26 | getrandom = { workspace = true } 27 | hashlink = { workspace = true} 28 | hex_fmt = "0.3.0" 29 | web-time = { workspace = true } 30 | libp2p-core = { workspace = true } 31 | libp2p-identity = { workspace = true, features = ["rand"] } 32 | libp2p-swarm = { workspace = true } 33 | quick-protobuf = "0.8" 34 | quick-protobuf-codec = { workspace = true } 35 | rand = "0.8" 36 | regex = "1.10.5" 37 | serde = { version = "1", optional = true, features = ["derive"] } 38 | sha2 = "0.10.8" 39 | tracing = { workspace = true } 40 | 41 | # Metrics dependencies 42 | prometheus-client = { workspace = true } 43 | 44 | [dev-dependencies] 45 | libp2p-core = { workspace = true } 46 | libp2p-swarm-test = { path = "../../swarm-test" } 47 | quickcheck = { workspace = true } 48 | tracing-subscriber = { workspace = true, features = ["env-filter"] } 49 | tokio = { workspace = true, features = ["rt", "rt-multi-thread", "time", "macros"] } 50 | 51 | # Passing arguments to the docsrs builder in order to properly document cfg's. 52 | # More information: https://docs.rs/about/builds#cross-compiling 53 | [package.metadata.docs.rs] 54 | all-features = true 55 | 56 | [lints] 57 | workspace = true 58 | -------------------------------------------------------------------------------- /protocols/gossipsub/src/generated/compat.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | package compat.pb; 4 | 5 | message Message { 6 | optional bytes from = 1; 7 | optional bytes data = 2; 8 | optional bytes seqno = 3; 9 | repeated string topic_ids = 4; 10 | optional bytes signature = 5; 11 | optional bytes key = 6; 12 | } -------------------------------------------------------------------------------- /protocols/gossipsub/src/generated/compat/mod.rs: -------------------------------------------------------------------------------- 1 | // Automatically generated mod.rs 2 | pub mod pb; 3 | -------------------------------------------------------------------------------- /protocols/gossipsub/src/generated/gossipsub/mod.rs: -------------------------------------------------------------------------------- 1 | // Automatically generated mod.rs 2 | pub mod pb; 3 | -------------------------------------------------------------------------------- /protocols/gossipsub/src/generated/mod.rs: -------------------------------------------------------------------------------- 1 | // Automatically generated mod.rs 2 | pub mod compat; 3 | pub mod gossipsub; 4 | -------------------------------------------------------------------------------- /protocols/identify/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "libp2p-identify" 3 | edition.workspace = true 4 | rust-version = { workspace = true } 5 | description = "Nodes identification protocol for libp2p" 6 | version = "0.47.0" 7 | authors = ["Parity Technologies "] 8 | license = "MIT" 9 | repository = "https://github.com/libp2p/rust-libp2p" 10 | keywords = ["peer-to-peer", "libp2p", "networking"] 11 | categories = ["network-programming", "asynchronous"] 12 | 13 | [dependencies] 14 | asynchronous-codec = { workspace = true } 15 | futures = { workspace = true } 16 | futures-timer = "3.0.3" 17 | futures-bounded = { workspace = true } 18 | libp2p-core = { workspace = true } 19 | libp2p-swarm = { workspace = true } 20 | libp2p-identity = { workspace = true } 21 | quick-protobuf-codec = { workspace = true } 22 | quick-protobuf = "0.8" 23 | smallvec = "1.13.2" 24 | thiserror = { workspace = true } 25 | tracing = { workspace = true } 26 | either = "1.12.0" 27 | 28 | [dev-dependencies] 29 | tokio = { workspace = true, features = ["macros", "rt-multi-thread"] } 30 | libp2p-swarm-test = { path = "../../swarm-test" } 31 | libp2p-swarm = { workspace = true, features = ["macros"] } 32 | tracing-subscriber = { workspace = true, features = ["env-filter"] } 33 | 34 | # Passing arguments to the docsrs builder in order to properly document cfg's. 35 | # More information: https://docs.rs/about/builds#cross-compiling 36 | [package.metadata.docs.rs] 37 | all-features = true 38 | 39 | [lints] 40 | workspace = true 41 | -------------------------------------------------------------------------------- /protocols/identify/src/generated/mod.rs: -------------------------------------------------------------------------------- 1 | // Automatically generated mod.rs 2 | pub mod structs; 3 | -------------------------------------------------------------------------------- /protocols/identify/src/generated/structs.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | package structs; 4 | 5 | message Identify { 6 | // protocolVersion determines compatibility between peers 7 | optional string protocolVersion = 5; // e.g. ipfs/1.0.0 8 | 9 | // agentVersion is like a UserAgent string in browsers, or client version in bittorrent 10 | // includes the client name and client. 11 | optional string agentVersion = 6; // e.g. go-ipfs/0.1.0 12 | 13 | // publicKey is this node's public key (which also gives its node.ID) 14 | // - may not need to be sent, as secure channel implies it has been sent. 15 | // - then again, if we change / disable secure channel, may still want it. 16 | optional bytes publicKey = 1; 17 | 18 | // listenAddrs are the multiaddrs the sender node listens for open connections on 19 | repeated bytes listenAddrs = 2; 20 | 21 | // oservedAddr is the multiaddr of the remote endpoint that the sender node perceives 22 | // this is useful information to convey to the other side, as it helps the remote endpoint 23 | // determine whether its connection to the local peer goes through NAT. 24 | optional bytes observedAddr = 4; 25 | 26 | repeated string protocols = 3; 27 | 28 | // signedPeerRecord contains a serialized SignedEnvelope containing a PeerRecord, 29 | // signed by the sending node. It contains the same addresses as the listenAddrs field, but 30 | // in a form that lets us share authenticated addrs with other peers. 31 | // see https://github.com/libp2p/rust-libp2p/blob/8ac5b5aac5f5c25a85f1065e292deeaf58290189/core/src/generated/envelope.proto#L12 32 | // and https://github.com/libp2p/rust-libp2p/blob/8ac5b5aac5f5c25a85f1065e292deeaf58290189/core/src/generated/peer_record.proto#L11 33 | // for message definitions. 34 | optional bytes signedPeerRecord = 8; 35 | } 36 | -------------------------------------------------------------------------------- /protocols/kad/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "libp2p-kad" 3 | edition.workspace = true 4 | rust-version = { workspace = true } 5 | description = "Kademlia protocol for libp2p" 6 | version = "0.47.0" 7 | authors = ["Parity Technologies "] 8 | license = "MIT" 9 | repository = "https://github.com/libp2p/rust-libp2p" 10 | keywords = ["peer-to-peer", "libp2p", "networking"] 11 | categories = ["network-programming", "asynchronous"] 12 | 13 | [dependencies] 14 | bytes = "1" 15 | either = "1.11" 16 | fnv = "1.0" 17 | asynchronous-codec = { workspace = true } 18 | futures = { workspace = true } 19 | libp2p-core = { workspace = true } 20 | libp2p-swarm = { workspace = true } 21 | futures-bounded = { workspace = true } 22 | quick-protobuf = "0.8" 23 | quick-protobuf-codec = { workspace = true } 24 | libp2p-identity = { workspace = true, features = ["rand"] } 25 | rand = "0.8" 26 | sha2 = "0.10.8" 27 | smallvec = "1.13.2" 28 | uint = "0.10" 29 | futures-timer = "3.0.3" 30 | web-time = { workspace = true } 31 | serde = { version = "1.0", optional = true, features = ["derive"] } 32 | thiserror = { workspace = true } 33 | tracing = { workspace = true } 34 | 35 | [dev-dependencies] 36 | tokio = { workspace = true, features = ["macros", "rt-multi-thread", "time"] } 37 | futures-timer = "3.0" 38 | libp2p-identify = { path = "../identify" } 39 | libp2p-noise = { workspace = true } 40 | libp2p-swarm = { path = "../../swarm", features = ["macros"] } 41 | libp2p-swarm-test = { path = "../../swarm-test" } 42 | libp2p-yamux = { workspace = true } 43 | quickcheck = { workspace = true } 44 | tracing-subscriber = { workspace = true, features = ["env-filter"] } 45 | 46 | [features] 47 | serde = ["dep:serde", "bytes/serde"] 48 | 49 | # Passing arguments to the docsrs builder in order to properly document cfg's. 50 | # More information: https://docs.rs/about/builds#cross-compiling 51 | [package.metadata.docs.rs] 52 | all-features = true 53 | 54 | [lints] 55 | workspace = true 56 | -------------------------------------------------------------------------------- /protocols/kad/src/generated/dht/mod.rs: -------------------------------------------------------------------------------- 1 | // Automatically generated mod.rs 2 | pub mod pb; 3 | -------------------------------------------------------------------------------- /protocols/kad/src/generated/mod.rs: -------------------------------------------------------------------------------- 1 | // Automatically generated mod.rs 2 | pub mod dht; 3 | -------------------------------------------------------------------------------- /protocols/mdns/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "libp2p-mdns" 3 | edition.workspace = true 4 | rust-version = { workspace = true } 5 | version = "0.47.0" 6 | description = "Implementation of the libp2p mDNS discovery method" 7 | authors = ["Parity Technologies "] 8 | license = "MIT" 9 | repository = "https://github.com/libp2p/rust-libp2p" 10 | keywords = ["peer-to-peer", "libp2p", "networking"] 11 | categories = ["network-programming", "asynchronous"] 12 | 13 | [dependencies] 14 | async-std = { version = "1.12.0", optional = true } 15 | async-io = { version = "2.3.3", optional = true } 16 | futures = { workspace = true } 17 | if-watch = { workspace = true } 18 | libp2p-core = { workspace = true } 19 | libp2p-swarm = { workspace = true } 20 | libp2p-identity = { workspace = true } 21 | rand = "0.8.3" 22 | smallvec = "1.13.2" 23 | socket2 = { version = "0.5.7", features = ["all"] } 24 | tokio = { workspace = true, default-features = false, features = ["net", "time"], optional = true} 25 | tracing = { workspace = true } 26 | hickory-proto = { workspace = true, features = ["mdns"] } 27 | 28 | [features] 29 | tokio = ["dep:tokio", "if-watch/tokio"] 30 | async-io = ["dep:async-io", "dep:async-std", "if-watch/smol"] 31 | 32 | [dev-dependencies] 33 | async-std = { version = "1.9.0", features = ["attributes"] } 34 | libp2p-swarm = { workspace = true, features = ["tokio", "async-std"] } 35 | tokio = { workspace = true, features = ["macros", "rt", "rt-multi-thread", "time"] } 36 | libp2p-swarm-test = { path = "../../swarm-test" } 37 | tracing-subscriber = { workspace = true, features = ["env-filter"] } 38 | 39 | [[test]] 40 | name = "use-async-std" 41 | required-features = ["async-io"] 42 | 43 | [[test]] 44 | name = "use-tokio" 45 | required-features = ["tokio"] 46 | 47 | 48 | # Passing arguments to the docsrs builder in order to properly document cfg's. 49 | # More information: https://docs.rs/about/builds#cross-compiling 50 | [package.metadata.docs.rs] 51 | all-features = true 52 | 53 | [lints] 54 | workspace = true 55 | -------------------------------------------------------------------------------- /protocols/perf/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 0.4.0 2 | 3 | 4 | - Add ConnectionError to FromSwarm::ConnectionClosed. 5 | See [PR 5485](https://github.com/libp2p/rust-libp2p/pull/5485). 6 | 7 | - Deprecate `void` crate. 8 | See [PR 5676](https://github.com/libp2p/rust-libp2p/pull/5676). 9 | 10 | 11 | 12 | ## 0.3.1 13 | - Use `web-time` instead of `instant`. 14 | See [PR 5347](https://github.com/libp2p/rust-libp2p/pull/5347). 15 | 16 | ## 0.3.0 17 | 18 | - Continuously measure on single connection (iperf-style). 19 | See https://github.com/libp2p/test-plans/issues/261 for high level overview. 20 | See [PR 4382](https://github.com/libp2p/rust-libp2p/pull/4382). 21 | 22 | ## 0.2.0 23 | 24 | - Raise MSRV to 1.65. 25 | See [PR 3715]. 26 | 27 | [PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715 28 | 29 | ## 0.1.0 30 | 31 | - Initial release. 32 | -------------------------------------------------------------------------------- /protocols/perf/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "libp2p-perf" 3 | edition.workspace = true 4 | rust-version = { workspace = true } 5 | description = "libp2p perf protocol implementation" 6 | version = "0.4.0" 7 | authors = ["Max Inden "] 8 | license = "MIT" 9 | repository = "https://github.com/libp2p/rust-libp2p" 10 | keywords = ["peer-to-peer", "libp2p", "networking"] 11 | categories = ["network-programming", "asynchronous"] 12 | 13 | [dependencies] 14 | anyhow = "1" 15 | clap = { version = "4.5.6", features = ["derive"] } 16 | futures = { workspace = true } 17 | futures-bounded = { workspace = true } 18 | futures-timer = "3.0" 19 | web-time = { workspace = true } 20 | libp2p = { workspace = true, features = ["tokio", "tcp", "quic", "tls", "yamux", "dns"] } 21 | libp2p-core = { workspace = true } 22 | libp2p-identity = { workspace = true, features = ["rand"] } 23 | libp2p-swarm = { workspace = true, features = ["macros", "tokio"] } 24 | libp2p-tcp = { workspace = true, features = ["tokio"] } 25 | libp2p-tls = { workspace = true } 26 | libp2p-yamux = { workspace = true } 27 | serde = { version = "1.0", features = ["derive"] } 28 | serde_json = "1.0" 29 | thiserror = { workspace = true } 30 | tracing = { workspace = true } 31 | tracing-subscriber = { workspace = true, features = ["env-filter"] } 32 | tokio = { workspace = true, features = ["macros", "rt", "rt-multi-thread"] } 33 | 34 | [dev-dependencies] 35 | libp2p-swarm-test = { path = "../../swarm-test" } 36 | 37 | # Passing arguments to the docsrs builder in order to properly document cfg's. 38 | # More information: https://docs.rs/about/builds#cross-compiling 39 | [package.metadata.docs.rs] 40 | all-features = true 41 | 42 | [lints] 43 | workspace = true 44 | -------------------------------------------------------------------------------- /protocols/perf/Dockerfile: -------------------------------------------------------------------------------- 1 | # syntax=docker/dockerfile:1.5-labs 2 | FROM rust:1.83.0 as builder 3 | 4 | # Run with access to the target cache to speed up builds 5 | WORKDIR /workspace 6 | ADD . . 7 | RUN --mount=type=cache,target=./target \ 8 | --mount=type=cache,target=/usr/local/cargo/registry \ 9 | cargo build --release --package libp2p-perf 10 | 11 | RUN --mount=type=cache,target=./target \ 12 | mv ./target/release/perf /usr/local/bin/perf 13 | 14 | FROM debian:bullseye-slim 15 | 16 | COPY --from=builder /usr/local/bin/perf /app/perf 17 | 18 | ENTRYPOINT [ "/app/perf" ] 19 | -------------------------------------------------------------------------------- /protocols/perf/src/server.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 Protocol Labs. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the "Software"), 5 | // to deal in the Software without restriction, including without limitation 6 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, 7 | // and/or sell copies of the Software, and to permit persons to whom the 8 | // Software is furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 14 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19 | // DEALINGS IN THE SOFTWARE. 20 | 21 | mod behaviour; 22 | mod handler; 23 | 24 | pub use behaviour::{Behaviour, Event}; 25 | -------------------------------------------------------------------------------- /protocols/ping/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "libp2p-ping" 3 | edition.workspace = true 4 | rust-version = { workspace = true } 5 | description = "Ping protocol for libp2p" 6 | version = "0.46.0" 7 | authors = ["Parity Technologies "] 8 | license = "MIT" 9 | repository = "https://github.com/libp2p/rust-libp2p" 10 | keywords = ["peer-to-peer", "libp2p", "networking"] 11 | categories = ["network-programming", "asynchronous"] 12 | 13 | [dependencies] 14 | futures = { workspace = true } 15 | futures-timer = "3.0.3" 16 | web-time = { workspace = true } 17 | libp2p-core = { workspace = true } 18 | libp2p-swarm = { workspace = true } 19 | libp2p-identity = { workspace = true } 20 | rand = "0.8" 21 | tracing = { workspace = true } 22 | 23 | [dev-dependencies] 24 | libp2p-swarm = { workspace = true, features = ["macros"] } 25 | libp2p-swarm-test = { path = "../../swarm-test" } 26 | quickcheck = { workspace = true } 27 | tokio = {workspace = true, features = ["rt", "macros"]} 28 | 29 | # Passing arguments to the docsrs builder in order to properly document cfg's. 30 | # More information: https://docs.rs/about/builds#cross-compiling 31 | [package.metadata.docs.rs] 32 | all-features = true 33 | 34 | [lints] 35 | workspace = true 36 | -------------------------------------------------------------------------------- /protocols/relay/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "libp2p-relay" 3 | edition.workspace = true 4 | rust-version = { workspace = true } 5 | description = "Communications relaying for libp2p" 6 | version = "0.20.0" 7 | authors = ["Parity Technologies ", "Max Inden "] 8 | license = "MIT" 9 | repository = "https://github.com/libp2p/rust-libp2p" 10 | keywords = ["peer-to-peer", "libp2p", "networking"] 11 | categories = ["network-programming", "asynchronous"] 12 | 13 | [dependencies] 14 | asynchronous-codec = { workspace = true } 15 | bytes = "1" 16 | either = "1.12.0" 17 | futures = { workspace = true } 18 | futures-timer = "3" 19 | futures-bounded = { workspace = true } 20 | web-time = { workspace = true } 21 | libp2p-core = { workspace = true } 22 | libp2p-swarm = { workspace = true } 23 | libp2p-identity = { workspace = true } 24 | quick-protobuf = "0.8" 25 | quick-protobuf-codec = { workspace = true } 26 | rand = "0.8.4" 27 | static_assertions = "1" 28 | thiserror = { workspace = true } 29 | tracing = { workspace = true } 30 | 31 | [dev-dependencies] 32 | libp2p-identity = { workspace = true, features = ["rand"] } 33 | libp2p-ping = { workspace = true } 34 | libp2p-plaintext = { workspace = true } 35 | libp2p-swarm = { workspace = true, features = ["macros", "async-std"] } 36 | libp2p-swarm-test = { workspace = true } 37 | libp2p-yamux = { workspace = true } 38 | quickcheck = { workspace = true } 39 | tracing-subscriber = { workspace = true, features = ["env-filter"] } 40 | 41 | 42 | # Passing arguments to the docsrs builder in order to properly document cfg's. 43 | # More information: https://docs.rs/about/builds#cross-compiling 44 | [package.metadata.docs.rs] 45 | all-features = true 46 | 47 | [lints] 48 | workspace = true 49 | -------------------------------------------------------------------------------- /protocols/relay/src/generated/message.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | package message_v2.pb; 4 | 5 | message HopMessage { 6 | enum Type { 7 | RESERVE = 0; 8 | CONNECT = 1; 9 | STATUS = 2; 10 | } 11 | 12 | required Type type = 1; 13 | 14 | optional Peer peer = 2; 15 | optional Reservation reservation = 3; 16 | optional Limit limit = 4; 17 | 18 | optional Status status = 5; 19 | } 20 | 21 | message StopMessage { 22 | enum Type { 23 | CONNECT = 0; 24 | STATUS = 1; 25 | } 26 | 27 | required Type type = 1; 28 | 29 | optional Peer peer = 2; 30 | optional Limit limit = 3; 31 | 32 | optional Status status = 4; 33 | } 34 | 35 | message Peer { 36 | required bytes id = 1; 37 | repeated bytes addrs = 2; 38 | } 39 | 40 | message Reservation { 41 | required uint64 expire = 1; // Unix expiration time (UTC) 42 | repeated bytes addrs = 2; // relay addrs for reserving peer 43 | optional bytes voucher = 3; // reservation voucher 44 | } 45 | message Limit { 46 | optional uint32 duration = 1; // seconds 47 | optional uint64 data = 2; // bytes 48 | } 49 | 50 | enum Status { 51 | OK = 100; 52 | RESERVATION_REFUSED = 200; 53 | RESOURCE_LIMIT_EXCEEDED = 201; 54 | PERMISSION_DENIED = 202; 55 | CONNECTION_FAILED = 203; 56 | NO_RESERVATION = 204; 57 | MALFORMED_MESSAGE = 400; 58 | UNEXPECTED_MESSAGE = 401; 59 | } -------------------------------------------------------------------------------- /protocols/relay/src/generated/message_v2/mod.rs: -------------------------------------------------------------------------------- 1 | // Automatically generated mod.rs 2 | pub mod pb; 3 | -------------------------------------------------------------------------------- /protocols/relay/src/generated/mod.rs: -------------------------------------------------------------------------------- 1 | // Automatically generated mod.rs 2 | pub mod message_v2; 3 | -------------------------------------------------------------------------------- /protocols/relay/src/multiaddr_ext.rs: -------------------------------------------------------------------------------- 1 | use libp2p_core::{multiaddr::Protocol, Multiaddr}; 2 | 3 | pub(crate) trait MultiaddrExt { 4 | fn is_relayed(&self) -> bool; 5 | } 6 | 7 | impl MultiaddrExt for Multiaddr { 8 | fn is_relayed(&self) -> bool { 9 | self.iter().any(|p| p == Protocol::P2pCircuit) 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /protocols/rendezvous/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "libp2p-rendezvous" 3 | edition.workspace = true 4 | rust-version = { workspace = true } 5 | description = "Rendezvous protocol for libp2p" 6 | version = "0.16.1" 7 | authors = ["The COMIT guys "] 8 | license = "MIT" 9 | repository = "https://github.com/libp2p/rust-libp2p" 10 | keywords = ["peer-to-peer", "libp2p", "networking"] 11 | categories = ["network-programming", "asynchronous"] 12 | 13 | [dependencies] 14 | asynchronous-codec = { workspace = true } 15 | async-trait = "0.1" 16 | bimap = "0.6.3" 17 | futures = { workspace = true, features = ["std"] } 18 | futures-timer = "3.0.3" 19 | web-time = { workspace = true } 20 | libp2p-core = { workspace = true } 21 | libp2p-swarm = { workspace = true } 22 | libp2p-identity = { workspace = true } 23 | libp2p-request-response = { workspace = true } 24 | quick-protobuf = "0.8" 25 | quick-protobuf-codec = { workspace = true } 26 | rand = "0.8" 27 | thiserror = { workspace = true } 28 | tracing = { workspace = true } 29 | 30 | [dev-dependencies] 31 | libp2p-swarm = { workspace = true, features = ["macros", "tokio"] } 32 | libp2p-swarm-test = { path = "../../swarm-test" } 33 | rand = "0.8" 34 | tokio = { workspace = true, features = [ "rt-multi-thread", "time", "macros", "sync", "process", "fs", "net" ] } 35 | tracing-subscriber = { workspace = true, features = ["env-filter"] } 36 | 37 | # Passing arguments to the docsrs builder in order to properly document cfg's. 38 | # More information: https://docs.rs/about/builds#cross-compiling 39 | [package.metadata.docs.rs] 40 | all-features = true 41 | 42 | [lints] 43 | workspace = true 44 | -------------------------------------------------------------------------------- /protocols/rendezvous/src/generated/mod.rs: -------------------------------------------------------------------------------- 1 | // Automatically generated mod.rs 2 | pub mod rendezvous; 3 | -------------------------------------------------------------------------------- /protocols/rendezvous/src/generated/rendezvous/mod.rs: -------------------------------------------------------------------------------- 1 | // Automatically generated mod.rs 2 | pub mod pb; 3 | -------------------------------------------------------------------------------- /protocols/rendezvous/src/generated/rpc.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | package rendezvous.pb; 4 | 5 | message Message { 6 | enum MessageType { 7 | REGISTER = 0; 8 | REGISTER_RESPONSE = 1; 9 | UNREGISTER = 2; 10 | DISCOVER = 3; 11 | DISCOVER_RESPONSE = 4; 12 | } 13 | 14 | enum ResponseStatus { 15 | OK = 0; 16 | E_INVALID_NAMESPACE = 100; 17 | E_INVALID_SIGNED_PEER_RECORD = 101; 18 | E_INVALID_TTL = 102; 19 | E_INVALID_COOKIE = 103; 20 | E_NOT_AUTHORIZED = 200; 21 | E_INTERNAL_ERROR = 300; 22 | E_UNAVAILABLE = 400; 23 | } 24 | 25 | message Register { 26 | optional string ns = 1; 27 | optional bytes signedPeerRecord = 2; 28 | optional uint64 ttl = 3; // in seconds 29 | } 30 | 31 | message RegisterResponse { 32 | optional ResponseStatus status = 1; 33 | optional string statusText = 2; 34 | optional uint64 ttl = 3; // in seconds 35 | } 36 | 37 | message Unregister { 38 | optional string ns = 1; 39 | optional bytes id = 2; 40 | } 41 | 42 | message Discover { 43 | optional string ns = 1; 44 | optional uint64 limit = 2; 45 | optional bytes cookie = 3; 46 | } 47 | 48 | message DiscoverResponse { 49 | repeated Register registrations = 1; 50 | optional bytes cookie = 2; 51 | optional ResponseStatus status = 3; 52 | optional string statusText = 4; 53 | } 54 | 55 | optional MessageType type = 1; 56 | optional Register register = 2; 57 | optional RegisterResponse registerResponse = 3; 58 | optional Unregister unregister = 4; 59 | optional Discover discover = 5; 60 | optional DiscoverResponse discoverResponse = 6; 61 | } 62 | -------------------------------------------------------------------------------- /protocols/request-response/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "libp2p-request-response" 3 | edition.workspace = true 4 | rust-version = { workspace = true } 5 | description = "Generic Request/Response Protocols" 6 | version = "0.28.1" 7 | authors = ["Parity Technologies "] 8 | license = "MIT" 9 | repository = "https://github.com/libp2p/rust-libp2p" 10 | keywords = ["peer-to-peer", "libp2p", "networking"] 11 | categories = ["network-programming", "asynchronous"] 12 | 13 | [dependencies] 14 | async-trait = "0.1" 15 | cbor4ii = { version = "0.3.2", features = ["serde1", "use_std"], optional = true } 16 | futures = { workspace = true } 17 | libp2p-core = { workspace = true } 18 | libp2p-swarm = { workspace = true } 19 | libp2p-identity = { workspace = true } 20 | rand = "0.8" 21 | serde = { version = "1.0", optional = true} 22 | serde_json = { version = "1.0.117", optional = true } 23 | smallvec = "1.13.2" 24 | tracing = { workspace = true } 25 | futures-bounded = { workspace = true } 26 | 27 | [features] 28 | json = ["dep:serde", "dep:serde_json", "libp2p-swarm/macros"] 29 | cbor = ["dep:serde", "dep:cbor4ii", "libp2p-swarm/macros"] 30 | 31 | [dev-dependencies] 32 | anyhow = "1.0.86" 33 | async-std = { version = "1.6.2", features = ["attributes"] } 34 | rand = "0.8" 35 | libp2p-swarm-test = { path = "../../swarm-test" } 36 | futures_ringbuf = "0.4.0" 37 | serde = { version = "1.0", features = ["derive"] } 38 | tracing-subscriber = { workspace = true, features = ["env-filter"] } 39 | 40 | # Passing arguments to the docsrs builder in order to properly document cfg's. 41 | # More information: https://docs.rs/about/builds#cross-compiling 42 | [package.metadata.docs.rs] 43 | all-features = true 44 | 45 | [lints] 46 | workspace = true 47 | -------------------------------------------------------------------------------- /protocols/stream/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 0.3.0-alpha 2 | 3 | - Deprecate `void` crate. 4 | See [PR 5676](https://github.com/libp2p/rust-libp2p/pull/5676). 5 | 6 | 7 | 8 | ## 0.2.0-alpha 9 | 10 | 11 | 12 | ## 0.1.0-alpha.1 13 | - Implement Error for `OpenStreamError`. 14 | See [PR 5169](https://github.com/libp2p/rust-libp2p/pull/5169). 15 | 16 | ## 0.1.0-alpha 17 | 18 | Initial release. 19 | -------------------------------------------------------------------------------- /protocols/stream/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "libp2p-stream" 3 | version = "0.3.0-alpha" 4 | edition.workspace = true 5 | rust-version.workspace = true 6 | description = "Generic stream protocols for libp2p" 7 | license = "MIT" 8 | repository = "https://github.com/libp2p/rust-libp2p" 9 | keywords = ["peer-to-peer", "libp2p", "networking"] 10 | categories = ["network-programming", "asynchronous"] 11 | 12 | [dependencies] 13 | futures = { workspace = true } 14 | libp2p-core = { workspace = true } 15 | libp2p-identity = { workspace = true, features = ["peerid"] } 16 | libp2p-swarm = { workspace = true } 17 | tracing = { workspace = true } 18 | rand = "0.8" 19 | 20 | [dev-dependencies] 21 | libp2p-swarm-test = { workspace = true } 22 | tokio = { workspace = true, features = ["full"] } 23 | tracing-subscriber = { workspace = true, features = ["env-filter"] } 24 | 25 | [lints] 26 | workspace = true 27 | -------------------------------------------------------------------------------- /protocols/stream/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![doc = include_str!("../README.md")] 2 | 3 | mod behaviour; 4 | mod control; 5 | mod handler; 6 | mod shared; 7 | mod upgrade; 8 | 9 | pub use behaviour::{AlreadyRegistered, Behaviour}; 10 | pub use control::{Control, IncomingStreams, OpenStreamError}; 11 | -------------------------------------------------------------------------------- /protocols/stream/src/upgrade.rs: -------------------------------------------------------------------------------- 1 | use std::{ 2 | convert::Infallible, 3 | future::{ready, Ready}, 4 | }; 5 | 6 | use libp2p_core::{InboundUpgrade, OutboundUpgrade, UpgradeInfo}; 7 | use libp2p_swarm::{Stream, StreamProtocol}; 8 | 9 | pub struct Upgrade { 10 | pub(crate) supported_protocols: Vec, 11 | } 12 | 13 | impl UpgradeInfo for Upgrade { 14 | type Info = StreamProtocol; 15 | 16 | type InfoIter = std::vec::IntoIter; 17 | 18 | fn protocol_info(&self) -> Self::InfoIter { 19 | self.supported_protocols.clone().into_iter() 20 | } 21 | } 22 | 23 | impl InboundUpgrade for Upgrade { 24 | type Output = (Stream, StreamProtocol); 25 | 26 | type Error = Infallible; 27 | 28 | type Future = Ready>; 29 | 30 | fn upgrade_inbound(self, socket: Stream, info: Self::Info) -> Self::Future { 31 | ready(Ok((socket, info))) 32 | } 33 | } 34 | 35 | impl OutboundUpgrade for Upgrade { 36 | type Output = (Stream, StreamProtocol); 37 | 38 | type Error = Infallible; 39 | 40 | type Future = Ready>; 41 | 42 | fn upgrade_outbound(self, socket: Stream, info: Self::Info) -> Self::Future { 43 | ready(Ok((socket, info))) 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /protocols/upnp/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 0.4.1 2 | 3 | - update igd-next to 0.16.1 4 | See [PR 5944](https://github.com/libp2p/rust-libp2p/pull/5944). 5 | 6 | ## 0.4.0 7 | 8 | - update igd-next to 0.15.1. 9 | See [PR XXXX](https://github.com/libp2p/rust-libp2p/pull/XXXX). 10 | 11 | 12 | 13 | ## 0.3.0 14 | 15 | 16 | 17 | ## 0.2.2 18 | - Fix a panic caused when `upnp::Gateway` is dropped and its events queue receiver is no longer 19 | available. 20 | See [PR 5273](https://github.com/libp2p/rust-libp2p/pull/5273). 21 | 22 | ## 0.2.1 23 | - Fix a panic caused when dropping `upnp::Behaviour` such as when used together with `Toggle`. 24 | See [PR 5096](https://github.com/libp2p/rust-libp2p/pull/5096). 25 | 26 | ## 0.2.0 27 | 28 | 29 | ## 0.1.1 30 | 31 | - Fix high CPU usage due to repeated generation of failure events. 32 | See [PR 4569](https://github.com/libp2p/rust-libp2p/pull/4569). 33 | 34 | - Fix port mapping protocol used for a UDP multiaddress. 35 | See [PR 4542](https://github.com/libp2p/rust-libp2p/pull/4542). 36 | 37 | ## 0.1.0 38 | 39 | - Initial version 40 | -------------------------------------------------------------------------------- /protocols/upnp/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "libp2p-upnp" 3 | edition.workspace = true 4 | rust-version.workspace = true 5 | description = "UPnP support for libp2p transports" 6 | version = "0.4.1" 7 | license = "MIT" 8 | repository = "https://github.com/libp2p/rust-libp2p" 9 | keywords = ["peer-to-peer", "libp2p", "networking"] 10 | categories = ["network-programming", "asynchronous"] 11 | publish = true 12 | 13 | [dependencies] 14 | futures = { workspace = true } 15 | futures-timer = "3.0.3" 16 | igd-next = "0.16.1" 17 | libp2p-core = { workspace = true } 18 | libp2p-swarm = { workspace = true } 19 | tokio = { workspace = true, default-features = false, features = ["rt"], optional = true } 20 | tracing = { workspace = true } 21 | 22 | [features] 23 | tokio = ["igd-next/aio_tokio", "dep:tokio"] 24 | 25 | [lints] 26 | workspace = true 27 | 28 | # Passing arguments to the docsrs builder in order to properly document cfg's. 29 | # More information: https://docs.rs/about/builds#cross-compiling 30 | [package.metadata.docs.rs] 31 | all-features = true 32 | -------------------------------------------------------------------------------- /protocols/upnp/src/lib.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 Protocol Labs. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the "Software"), 5 | // to deal in the Software without restriction, including without limitation 6 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, 7 | // and/or sell copies of the Software, and to permit persons to whom the 8 | // Software is furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 14 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19 | // DEALINGS IN THE SOFTWARE. 20 | 21 | //! Implementation of UPnP port mapping for libp2p. 22 | //! 23 | //! This crate provides a `tokio::Behaviour` which 24 | //! implements the [`libp2p_swarm::NetworkBehaviour`] trait. 25 | //! This struct will automatically try to map the ports externally to internal 26 | //! addresses on the gateway. 27 | 28 | #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] 29 | 30 | #[cfg(feature = "tokio")] 31 | mod behaviour; 32 | #[cfg(feature = "tokio")] 33 | pub mod tokio; 34 | 35 | #[cfg(feature = "tokio")] 36 | pub use behaviour::Event; 37 | -------------------------------------------------------------------------------- /rustfmt.toml: -------------------------------------------------------------------------------- 1 | # Imports 2 | reorder_imports = true 3 | imports_granularity = "Crate" 4 | group_imports = "StdExternalCrate" 5 | 6 | # Docs 7 | wrap_comments = true 8 | comment_width = 100 9 | normalize_comments = true 10 | format_code_in_doc_comments = true 11 | -------------------------------------------------------------------------------- /scripts/add-changelog-header.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | header=$(head -n 1 "$CRATE_ROOT/CHANGELOG.md") 4 | prefix="## $NEW_VERSION" 5 | 6 | if [[ $header == $prefix* ]]; then 7 | exit 8 | fi 9 | 10 | sed -i "1i ## ${NEW_VERSION}\n\n" "$CRATE_ROOT/CHANGELOG.md" 11 | -------------------------------------------------------------------------------- /scripts/build-interop-image.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # This uses the same S3 cache as all test-plans images. Because we use `cargo-chef` in the Dockerfile, we have a layer available with all dependencies built. 4 | 5 | CACHE_TO="" 6 | 7 | # If we have credentials, write to cache 8 | if [[ -n "${AWS_SECRET_ACCESS_KEY}" ]]; then 9 | CACHE_TO="--cache-to type=s3,mode=max,bucket=${AWS_BUCKET_NAME},region=${AWS_REGION},prefix=buildCache,name=${FLAVOUR}-rust-libp2p-head" 10 | fi 11 | 12 | docker buildx build \ 13 | --load \ 14 | $CACHE_TO \ 15 | --cache-from type=s3,mode=max,bucket=${AWS_BUCKET_NAME},region=${AWS_REGION},prefix=buildCache,name=${FLAVOUR}-rust-libp2p-head \ 16 | -t ${FLAVOUR}-rust-libp2p-head \ 17 | . \ 18 | -f interop-tests/Dockerfile.${FLAVOUR} 19 | -------------------------------------------------------------------------------- /scripts/ensure-version-bump-and-changelog.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -ex; 4 | 5 | MANIFEST_PATH=$(cargo metadata --format-version=1 --no-deps | jq -e -r '.packages[] | select(.name == "'"$CRATE"'") | .manifest_path') 6 | DIR_TO_CRATE=$(dirname "$MANIFEST_PATH") 7 | 8 | MERGE_BASE=$(git merge-base "$HEAD_SHA" "$PR_BASE") # Find the merge base. This ensures we only diff what was actually added in the PR. 9 | 10 | SRC_DIFF_TO_BASE=$(git diff "$HEAD_SHA".."$MERGE_BASE" --name-status -- "$DIR_TO_CRATE/src" "$DIR_TO_CRATE/Cargo.toml") 11 | CHANGELOG_DIFF=$(git diff "$HEAD_SHA".."$MERGE_BASE" --name-only -- "$DIR_TO_CRATE/CHANGELOG.md") 12 | 13 | RELEASED_VERSION=$(git tag --sort=version:refname | grep "^$CRATE-v" | tail -n1 | grep -Po "\d+\.\d+\.\d+(-.+)?") 14 | 15 | 16 | # If the source files of this crate weren't touched in this PR, exit early. 17 | if [ -z "$SRC_DIFF_TO_BASE" ]; then 18 | exit 0; 19 | fi 20 | 21 | # Code was touched, ensure changelog is updated too. 22 | if [ -z "$CHANGELOG_DIFF" ]; then 23 | echo "Files in $DIR_TO_CRATE have changed, please write a changelog entry in $DIR_TO_CRATE/CHANGELOG.md" 24 | exit 1 25 | fi 26 | 27 | IFS='.' read -r -a current <<< "$CRATE_VERSION" 28 | IFS='.' read -r -a released <<< "$RELEASED_VERSION" 29 | 30 | for i in $(seq 0 2); 31 | do 32 | case $((current[i]-released[i])) in 33 | 0) continue ;; 34 | 1) if [[ -n $(printf "%s\n" "${current[@]:i+1}" | grep -vFx '0') ]]; then 35 | echo "Patch version has been bumped even though minor isn't released yet". 36 | exit 1 37 | fi 38 | exit 0 ;; 39 | *) echo "Version of '$CRATE' has been bumped more than once since last release v$RELEASED_VERSION." 40 | exit 1 ;; 41 | esac 42 | done 43 | 44 | echo "v$CRATE_VERSION of '$CRATE' has already been released, please bump the version." 45 | exit 1 46 | -------------------------------------------------------------------------------- /scripts/list-external-contributors.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Usage: ./scripts/list-external-contributors.sh 4 | 5 | set -e 6 | 7 | date_of_tag=$(git log -1 --format=%aI --date=iso-strict $1) 8 | unique_authors=$(gh api "repos/libp2p/rust-libp2p/commits?since=$date_of_tag" --paginate -q '.[].author.login' | sort -u) 9 | rust_libp2p_maintainers_team_members=$(gh api teams/6797340/members --paginate | jq -r '.[].login' | sort -u) 10 | 11 | echo "$unique_authors" | grep -vxF -f <(echo "$rust_libp2p_maintainers_team_members") | grep -vF "bot" | grep -vF "web-flow" 12 | -------------------------------------------------------------------------------- /swarm-derive/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "libp2p-swarm-derive" 3 | edition.workspace = true 4 | rust-version = { workspace = true } 5 | description = "Procedural macros of libp2p-swarm" 6 | version = "0.35.1" 7 | authors = ["Parity Technologies "] 8 | license = "MIT" 9 | repository = "https://github.com/libp2p/rust-libp2p" 10 | keywords = ["peer-to-peer", "libp2p", "networking"] 11 | categories = ["network-programming", "asynchronous"] 12 | 13 | [lib] 14 | proc-macro = true 15 | 16 | [dependencies] 17 | heck = "0.5" 18 | quote = "1.0" 19 | syn = { version = "2.0.66", default-features = false, features = ["clone-impls", "derive", "parsing", "printing", "proc-macro"] } 20 | 21 | # Passing arguments to the docsrs builder in order to properly document cfg's. 22 | # More information: https://docs.rs/about/builds#cross-compiling 23 | [package.metadata.docs.rs] 24 | all-features = true 25 | 26 | [lints] 27 | workspace = true 28 | -------------------------------------------------------------------------------- /swarm-derive/src/syn_ext.rs: -------------------------------------------------------------------------------- 1 | use syn::{Expr, ExprLit, Lit}; 2 | 3 | pub(crate) trait RequireStrLit { 4 | fn require_str_lit(&self) -> syn::Result; 5 | } 6 | 7 | impl RequireStrLit for Expr { 8 | fn require_str_lit(&self) -> syn::Result { 9 | match self { 10 | Expr::Lit(ExprLit { 11 | lit: Lit::Str(str), .. 12 | }) => Ok(str.value()), 13 | _ => Err(syn::Error::new_spanned(self, "expected a string literal")), 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /swarm-test/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 0.5.0 2 | 3 | - Add `tokio` runtime support and make `tokio` and `async-std` runtimes optional behind features. 4 | See [PR 5551]. 5 | - Update default for idle-connection-timeout to 10s on `SwarmExt::new_ephemeral` methods. 6 | See [PR 4967](https://github.com/libp2p/rust-libp2p/pull/4967). 7 | 8 | [PR 5551]: https://github.com/libp2p/rust-libp2p/pull/5551 9 | 10 | ## 0.4.0 11 | 12 | 13 | 14 | ## 0.3.0 15 | 16 | 17 | ## 0.2.0 18 | 19 | - Raise MSRV to 1.65. 20 | See [PR 3715]. 21 | 22 | [PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715 23 | 24 | ## 0.1.0 25 | 26 | - Initial release. 27 | -------------------------------------------------------------------------------- /swarm-test/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "libp2p-swarm-test" 3 | version = "0.5.0" 4 | edition.workspace = true 5 | rust-version = { workspace = true } 6 | license = "MIT" 7 | description = "Test framework for code building on top of libp2p-swarm" 8 | repository = "https://github.com/libp2p/rust-libp2p" 9 | keywords = ["peer-to-peer", "libp2p", "networking"] 10 | categories = ["network-programming", "asynchronous"] 11 | 12 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 13 | 14 | [dependencies] 15 | async-trait = "0.1.80" 16 | libp2p-core = { workspace = true } 17 | libp2p-identity = { workspace = true, features = ["rand"] } 18 | libp2p-plaintext = { workspace = true } 19 | libp2p-swarm = { workspace = true } 20 | libp2p-tcp = { workspace = true } 21 | libp2p-yamux = { workspace = true } 22 | futures = { workspace = true } 23 | tracing = { workspace = true } 24 | futures-timer = "3.0.3" 25 | 26 | [features] 27 | default = ["async-std"] 28 | 29 | async-std = ["libp2p-swarm/async-std", "libp2p-tcp/async-io"] 30 | tokio = ["libp2p-swarm/tokio", "libp2p-tcp/tokio"] 31 | 32 | [lints] 33 | workspace = true 34 | -------------------------------------------------------------------------------- /swarm/src/listen_opts.rs: -------------------------------------------------------------------------------- 1 | use libp2p_core::Multiaddr; 2 | 3 | use crate::ListenerId; 4 | 5 | #[derive(Debug)] 6 | pub struct ListenOpts { 7 | id: ListenerId, 8 | address: Multiaddr, 9 | } 10 | 11 | impl ListenOpts { 12 | pub fn new(address: Multiaddr) -> ListenOpts { 13 | ListenOpts { 14 | id: ListenerId::next(), 15 | address, 16 | } 17 | } 18 | 19 | /// Get the [`ListenerId`] of this listen attempt 20 | pub fn listener_id(&self) -> ListenerId { 21 | self.id 22 | } 23 | 24 | /// Get the [`Multiaddr`] that is being listened on 25 | pub fn address(&self) -> &Multiaddr { 26 | &self.address 27 | } 28 | } 29 | 30 | impl From for ListenOpts { 31 | fn from(addr: Multiaddr) -> Self { 32 | ListenOpts::new(addr) 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /swarm/tests/ui/fail/prelude_not_string.rs: -------------------------------------------------------------------------------- 1 | use libp2p_ping as ping; 2 | 3 | #[derive(libp2p_swarm::NetworkBehaviour)] 4 | #[behaviour(prelude = libp2p_swarm::derive_prelude)] 5 | struct Foo { 6 | ping: ping::Behaviour, 7 | } 8 | 9 | fn main() { 10 | 11 | } 12 | -------------------------------------------------------------------------------- /swarm/tests/ui/fail/prelude_not_string.stderr: -------------------------------------------------------------------------------- 1 | error: expected a string literal 2 | --> tests/ui/fail/prelude_not_string.rs:4:23 3 | | 4 | 4 | #[behaviour(prelude = libp2p_swarm::derive_prelude)] 5 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6 | -------------------------------------------------------------------------------- /swarm/tests/ui/fail/to_swarm_not_string.rs: -------------------------------------------------------------------------------- 1 | use libp2p_ping as ping; 2 | 3 | #[derive(libp2p_swarm::NetworkBehaviour)] 4 | #[behaviour(out_event = FooEvent, prelude = "libp2p_swarm::derive_prelude")] 5 | struct Foo { 6 | ping: ping::Behaviour, 7 | } 8 | 9 | struct FooEvent; 10 | 11 | impl From for FooEvent { 12 | fn from(_: ping::Event) -> Self { 13 | unimplemented!() 14 | } 15 | } 16 | 17 | fn main() { 18 | 19 | } 20 | -------------------------------------------------------------------------------- /swarm/tests/ui/fail/to_swarm_not_string.stderr: -------------------------------------------------------------------------------- 1 | error: expected a string literal 2 | --> tests/ui/fail/to_swarm_not_string.rs:4:25 3 | | 4 | 4 | #[behaviour(out_event = FooEvent, prelude = "libp2p_swarm::derive_prelude")] 5 | | ^^^^^^^^ 6 | -------------------------------------------------------------------------------- /transports/dns/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "libp2p-dns" 3 | edition.workspace = true 4 | rust-version = { workspace = true } 5 | description = "DNS transport implementation for libp2p" 6 | version = "0.43.0" 7 | authors = ["Parity Technologies "] 8 | license = "MIT" 9 | repository = "https://github.com/libp2p/rust-libp2p" 10 | keywords = ["peer-to-peer", "libp2p", "networking"] 11 | categories = ["network-programming", "asynchronous"] 12 | 13 | [dependencies] 14 | async-std-resolver = { workspace = true, features = ["system-config"], optional = true } 15 | async-trait = "0.1.80" 16 | futures = { workspace = true } 17 | libp2p-core = { workspace = true } 18 | libp2p-identity = { workspace = true } 19 | parking_lot = "0.12.3" 20 | hickory-resolver = { workspace = true, features = ["system-config"] } 21 | smallvec = "1.13.2" 22 | tracing = { workspace = true } 23 | 24 | [dev-dependencies] 25 | libp2p-identity = { workspace = true, features = ["rand"] } 26 | tokio = { workspace = true, features = ["rt", "time"] } 27 | async-std-crate = { package = "async-std", version = "1.6" } 28 | tracing-subscriber = { workspace = true, features = ["env-filter"] } 29 | 30 | [features] 31 | async-std = ["async-std-resolver"] 32 | tokio = ["hickory-resolver/tokio-runtime"] 33 | 34 | # Passing arguments to the docsrs builder in order to properly document cfg's. 35 | # More information: https://docs.rs/about/builds#cross-compiling 36 | [package.metadata.docs.rs] 37 | all-features = true 38 | 39 | [lints] 40 | workspace = true 41 | -------------------------------------------------------------------------------- /transports/noise/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "libp2p-noise" 3 | edition.workspace = true 4 | rust-version = { workspace = true } 5 | description = "Cryptographic handshake protocol using the noise framework." 6 | version = "0.46.1" 7 | authors = ["Parity Technologies "] 8 | license = "MIT" 9 | repository = "https://github.com/libp2p/rust-libp2p" 10 | 11 | [dependencies] 12 | asynchronous-codec = { workspace = true } 13 | bytes = "1" 14 | futures = { workspace = true } 15 | libp2p-core = { workspace = true } 16 | libp2p-identity = { workspace = true, features = ["ed25519"] } 17 | multiaddr = { workspace = true } 18 | multihash = { workspace = true } 19 | quick-protobuf = "0.8" 20 | rand = "0.8.3" 21 | static_assertions = "1" 22 | thiserror = { workspace = true } 23 | tracing = { workspace = true } 24 | x25519-dalek = "2" 25 | zeroize = "1" 26 | 27 | [target.'cfg(not(target_arch = "wasm32"))'.dependencies] 28 | snow = { version = "0.9.6", features = ["ring-resolver"], default-features = false } 29 | 30 | [target.'cfg(target_arch = "wasm32")'.dependencies] 31 | snow = { version = "0.9.5", features = ["default-resolver"], default-features = false } 32 | 33 | [dev-dependencies] 34 | futures_ringbuf = "0.4.0" 35 | quickcheck = { workspace = true } 36 | tracing-subscriber = { workspace = true, features = ["env-filter"] } 37 | libp2p-identity = { workspace = true, features = ["rand"] } 38 | 39 | # Passing arguments to the docsrs builder in order to properly document cfg's. 40 | # More information: https://docs.rs/about/builds#cross-compiling 41 | [package.metadata.docs.rs] 42 | all-features = true 43 | 44 | [lints] 45 | workspace = true 46 | -------------------------------------------------------------------------------- /transports/noise/src/generated/mod.rs: -------------------------------------------------------------------------------- 1 | // Automatically generated mod.rs 2 | pub mod payload; 3 | -------------------------------------------------------------------------------- /transports/noise/src/generated/payload.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package payload.proto; 3 | 4 | // Payloads for Noise handshake messages. 5 | 6 | message NoiseExtensions { 7 | repeated bytes webtransport_certhashes = 1; 8 | repeated string stream_muxers = 2; 9 | } 10 | 11 | message NoiseHandshakePayload { 12 | bytes identity_key = 1; 13 | bytes identity_sig = 2; 14 | optional NoiseExtensions extensions = 4; 15 | } 16 | -------------------------------------------------------------------------------- /transports/noise/src/generated/payload/mod.rs: -------------------------------------------------------------------------------- 1 | // Automatically generated mod.rs 2 | pub mod proto; 3 | -------------------------------------------------------------------------------- /transports/plaintext/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "libp2p-plaintext" 3 | edition.workspace = true 4 | rust-version = { workspace = true } 5 | description = "Plaintext encryption dummy protocol for libp2p" 6 | version = "0.43.0" 7 | authors = ["Parity Technologies "] 8 | license = "MIT" 9 | repository = "https://github.com/libp2p/rust-libp2p" 10 | keywords = ["peer-to-peer", "libp2p", "networking"] 11 | categories = ["network-programming", "asynchronous"] 12 | 13 | [dependencies] 14 | asynchronous-codec = { workspace = true } 15 | bytes = "1" 16 | futures = { workspace = true } 17 | libp2p-core = { workspace = true } 18 | libp2p-identity = { workspace = true } 19 | quick-protobuf = "0.8" 20 | tracing = { workspace = true } 21 | quick-protobuf-codec = { workspace = true } 22 | 23 | [dev-dependencies] 24 | libp2p-identity = { workspace = true, features = ["ed25519", "rand"] } 25 | quickcheck = { workspace = true } 26 | futures_ringbuf = "0.4.0" 27 | tracing-subscriber = { workspace = true, features = ["env-filter"] } 28 | 29 | # Passing arguments to the docsrs builder in order to properly document cfg's. 30 | # More information: https://docs.rs/about/builds#cross-compiling 31 | [package.metadata.docs.rs] 32 | all-features = true 33 | 34 | [lints] 35 | workspace = true 36 | -------------------------------------------------------------------------------- /transports/plaintext/src/generated/mod.rs: -------------------------------------------------------------------------------- 1 | // Automatically generated mod.rs 2 | pub mod structs; 3 | -------------------------------------------------------------------------------- /transports/plaintext/src/generated/structs.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | package structs; 4 | 5 | message Exchange { 6 | optional bytes id = 1; 7 | optional bytes pubkey = 2; 8 | } 9 | -------------------------------------------------------------------------------- /transports/plaintext/src/generated/structs.rs: -------------------------------------------------------------------------------- 1 | // Automatically generated rust module for 'structs.proto' file 2 | 3 | #![allow(non_snake_case)] 4 | #![allow(non_upper_case_globals)] 5 | #![allow(non_camel_case_types)] 6 | #![allow(unused_imports)] 7 | #![allow(unknown_lints)] 8 | #![allow(clippy::all)] 9 | #![cfg_attr(rustfmt, rustfmt_skip)] 10 | 11 | 12 | use quick_protobuf::{MessageInfo, MessageRead, MessageWrite, BytesReader, Writer, WriterBackend, Result}; 13 | use quick_protobuf::sizeofs::*; 14 | use super::*; 15 | 16 | #[allow(clippy::derive_partial_eq_without_eq)] 17 | #[derive(Debug, Default, PartialEq, Clone)] 18 | pub struct Exchange { 19 | pub id: Option>, 20 | pub pubkey: Option>, 21 | } 22 | 23 | impl<'a> MessageRead<'a> for Exchange { 24 | fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { 25 | let mut msg = Self::default(); 26 | while !r.is_eof() { 27 | match r.next_tag(bytes) { 28 | Ok(10) => msg.id = Some(r.read_bytes(bytes)?.to_owned()), 29 | Ok(18) => msg.pubkey = Some(r.read_bytes(bytes)?.to_owned()), 30 | Ok(t) => { r.read_unknown(bytes, t)?; } 31 | Err(e) => return Err(e), 32 | } 33 | } 34 | Ok(msg) 35 | } 36 | } 37 | 38 | impl MessageWrite for Exchange { 39 | fn get_size(&self) -> usize { 40 | 0 41 | + self.id.as_ref().map_or(0, |m| 1 + sizeof_len((m).len())) 42 | + self.pubkey.as_ref().map_or(0, |m| 1 + sizeof_len((m).len())) 43 | } 44 | 45 | fn write_message(&self, w: &mut Writer) -> Result<()> { 46 | if let Some(ref s) = self.id { w.write_with_tag(10, |w| w.write_bytes(&**s))?; } 47 | if let Some(ref s) = self.pubkey { w.write_with_tag(18, |w| w.write_bytes(&**s))?; } 48 | Ok(()) 49 | } 50 | } 51 | 52 | -------------------------------------------------------------------------------- /transports/pnet/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 0.26.0 2 | 3 | 4 | 5 | ## 0.25.0 6 | 7 | 8 | 9 | ## 0.24.0 10 | 11 | 12 | ## 0.23.1 13 | 14 | 19 | 20 | ## 0.23.0 21 | 22 | - Raise MSRV to 1.65. 23 | See [PR 3715]. 24 | 25 | [PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715 26 | 27 | ## 0.22.3 28 | 29 | - Fix handshake over websocket. See [PR 3476] 30 | 31 | [PR 3476]: https://github.com/libp2p/rust-libp2p/pull/3476 32 | 33 | ## 0.22.2 34 | 35 | - Update `rust-version` to reflect the actual MSRV: 1.60.0. See [PR 3090]. 36 | 37 | [PR 3090]: https://github.com/libp2p/rust-libp2p/pull/3090 38 | 39 | ## 0.22.1 40 | 41 | - Bump rand to 0.8 and quickcheck to 1. See [PR 2857]. 42 | 43 | - Bump async-std-resolver and trust-dns-resolver from 0.21 to 0.22. See [PR 2988]. 44 | 45 | - Bump salsa20 to 0.10. See [PR 2989]. 46 | 47 | [PR 2857]: https://github.com/libp2p/rust-libp2p/pull/2857 48 | [PR 2988]: https://github.com/libp2p/rust-libp2p/pull/2988 49 | [PR 2989]: https://github.com/libp2p/rust-libp2p/pull/2989 50 | 51 | ## 0.22.0 [2021-11-01] 52 | 53 | - Update dependencies. 54 | 55 | - Migrate to Rust edition 2021 (see [PR 2339]). 56 | 57 | [PR 2339]: https://github.com/libp2p/rust-libp2p/pull/2339 58 | 59 | ## 0.21.0 [2021-05-17] 60 | 61 | - Update dependencies. 62 | 63 | ## 0.20.0 [2020-12-17] 64 | 65 | - Update dependencies. 66 | 67 | ## 0.19.2 [2020-10-16] 68 | 69 | - Update dependencies. 70 | 71 | ## 0.19.1 [2020-06-22] 72 | 73 | - Updated dependencies. 74 | -------------------------------------------------------------------------------- /transports/pnet/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "libp2p-pnet" 3 | edition.workspace = true 4 | rust-version = { workspace = true } 5 | description = "Private swarm support for libp2p" 6 | version = "0.26.0" 7 | authors = ["Parity Technologies "] 8 | license = "MIT" 9 | repository = "https://github.com/libp2p/rust-libp2p" 10 | keywords = ["peer-to-peer", "libp2p", "networking"] 11 | categories = ["network-programming", "asynchronous"] 12 | 13 | [dependencies] 14 | futures = { workspace = true } 15 | salsa20 = "0.10" 16 | sha3 = "0.10" 17 | tracing = { workspace = true } 18 | rand = "0.8" 19 | pin-project = "1.1.5" 20 | 21 | [dev-dependencies] 22 | libp2p-core = { workspace = true } 23 | libp2p-identity = { workspace = true, features = ["ed25519", "rsa", "ecdsa","secp256k1", "rand"] } 24 | libp2p-noise = { workspace = true } 25 | libp2p-swarm = { workspace = true, features = ["tokio"] } 26 | libp2p-tcp = { workspace = true, features = ["tokio"] } 27 | libp2p-websocket = { workspace = true } 28 | libp2p-yamux = { workspace = true } 29 | quickcheck = { workspace = true } 30 | tokio = { workspace = true, features = ["full"] } 31 | 32 | # Passing arguments to the docsrs builder in order to properly document cfg's. 33 | # More information: https://docs.rs/about/builds#cross-compiling 34 | [package.metadata.docs.rs] 35 | all-features = true 36 | 37 | [lints] 38 | workspace = true 39 | -------------------------------------------------------------------------------- /transports/quic/src/hole_punching.rs: -------------------------------------------------------------------------------- 1 | use std::{ 2 | convert::Infallible, 3 | net::{SocketAddr, UdpSocket}, 4 | time::Duration, 5 | }; 6 | 7 | use futures::future::Either; 8 | use rand::{distributions, Rng}; 9 | 10 | use crate::{provider::Provider, Error}; 11 | 12 | pub(crate) async fn hole_puncher( 13 | socket: UdpSocket, 14 | remote_addr: SocketAddr, 15 | timeout_duration: Duration, 16 | ) -> Error { 17 | let punch_holes_future = punch_holes::

(socket, remote_addr); 18 | futures::pin_mut!(punch_holes_future); 19 | match futures::future::select(P::sleep(timeout_duration), punch_holes_future).await { 20 | Either::Left(_) => Error::HandshakeTimedOut, 21 | Either::Right((Err(hole_punch_err), _)) => hole_punch_err, 22 | Either::Right((Ok(never), _)) => match never {}, 23 | } 24 | } 25 | 26 | async fn punch_holes( 27 | socket: UdpSocket, 28 | remote_addr: SocketAddr, 29 | ) -> Result { 30 | loop { 31 | let contents: Vec = rand::thread_rng() 32 | .sample_iter(distributions::Standard) 33 | .take(64) 34 | .collect(); 35 | 36 | tracing::trace!("Sending random UDP packet to {remote_addr}"); 37 | 38 | P::send_to(&socket, &contents, remote_addr).await?; 39 | 40 | let sleep_duration = Duration::from_millis(rand::thread_rng().gen_range(10..=200)); 41 | P::sleep(sleep_duration).await; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /transports/tcp/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "libp2p-tcp" 3 | edition.workspace = true 4 | rust-version = { workspace = true } 5 | description = "TCP/IP transport protocol for libp2p" 6 | version = "0.43.0" 7 | authors = ["Parity Technologies "] 8 | license = "MIT" 9 | repository = "https://github.com/libp2p/rust-libp2p" 10 | keywords = ["peer-to-peer", "libp2p", "networking"] 11 | categories = ["network-programming", "asynchronous"] 12 | 13 | [dependencies] 14 | async-io = { version = "2.3.3", optional = true } 15 | futures = { workspace = true } 16 | futures-timer = "3.0" 17 | if-watch = { workspace = true } 18 | libc = "0.2.155" 19 | libp2p-core = { workspace = true } 20 | socket2 = { version = "0.5.7", features = ["all"] } 21 | tokio = { workspace = true, default-features = false, features = ["net"], optional = true } 22 | tracing = { workspace = true } 23 | 24 | [features] 25 | tokio = ["dep:tokio", "if-watch/tokio"] 26 | async-io = ["dep:async-io", "if-watch/smol"] 27 | 28 | [dev-dependencies] 29 | async-std = { version = "1.6.5", features = ["attributes"] } 30 | tokio = { workspace = true, features = ["full"] } 31 | tracing-subscriber = { workspace = true, features = ["env-filter"] } 32 | 33 | # Passing arguments to the docsrs builder in order to properly document cfg's. 34 | # More information: https://docs.rs/about/builds#cross-compiling 35 | [package.metadata.docs.rs] 36 | all-features = true 37 | 38 | 39 | [lints] 40 | workspace = true 41 | -------------------------------------------------------------------------------- /transports/tls/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 0.6.1 2 | 3 | - Upgrade `rcgen` to `v0.13` 4 | See [PR 5917](https://github.com/libp2p/rust-libp2p/pull/5917). 5 | 6 | ## 0.6.0 7 | 8 | 9 | 10 | ## 0.5.0 11 | 12 | 13 | 14 | ## 0.4.1 15 | 16 | - Fix a panic caused by `rustls` parsing the libp2p TLS extension. 17 | See [PR 5498](https://github.com/libp2p/rust-libp2p/pull/5498). 18 | 19 | ## 0.4.0 20 | 21 | - Upgrade `rustls` to `0.23`. See [PR 5385](https://github.com/libp2p/rust-libp2p/pull/5385) 22 | 23 | ## 0.3.0 24 | 25 | - Migrate to `{In,Out}boundConnectionUpgrade` traits. 26 | See [PR 4695](https://github.com/libp2p/rust-libp2p/pull/4695). 27 | 28 | ## 0.2.1 29 | 30 | - Switch from webpki to rustls-webpki. 31 | This is a part of the resolution of the [RUSTSEC-2023-0052]. 32 | See [PR 4381]. 33 | 34 | [PR 4381]: https://github.com/libp2p/rust-libp2p/pull/4381 35 | [RUSTSEC-2023-0052]: https://rustsec.org/advisories/RUSTSEC-2023-0052.html 36 | 37 | ## 0.2.0 38 | 39 | - Raise MSRV to 1.65. 40 | See [PR 3715]. 41 | 42 | [PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715 43 | 44 | ## 0.1.0 45 | 46 | - Promote to `v0.1.0`. 47 | 48 | ## 0.1.0-alpha.2 49 | 50 | - Update to `libp2p-core` `v0.39.0`. 51 | 52 | ## 0.1.0-alpha 53 | 54 | Initial release. 55 | -------------------------------------------------------------------------------- /transports/tls/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "libp2p-tls" 3 | version = "0.6.1" 4 | edition.workspace = true 5 | rust-version = { workspace = true } 6 | description = "TLS configuration based on libp2p TLS specs." 7 | repository = "https://github.com/libp2p/rust-libp2p" 8 | license = "MIT" 9 | exclude = ["src/test_assets"] 10 | 11 | [dependencies] 12 | futures = { workspace = true } 13 | futures-rustls = { workspace = true } 14 | libp2p-core = { workspace = true } 15 | libp2p-identity = { workspace = true } 16 | rcgen = { workspace = true } 17 | ring = { workspace = true } 18 | thiserror = { workspace = true } 19 | webpki = { version = "0.101.4", package = "rustls-webpki", features = ["std"] } 20 | x509-parser = "0.16.0" 21 | yasna = "0.5.2" 22 | 23 | # Exposed dependencies. Breaking changes to these are breaking changes to us. 24 | [dependencies.rustls] 25 | version = "0.23.9" 26 | default-features = false 27 | features = ["ring", "std"] # Must enable this to allow for custom verification code. 28 | 29 | 30 | [dev-dependencies] 31 | hex-literal = "0.4.1" 32 | libp2p-core = { workspace = true } 33 | libp2p-identity = { workspace = true, features = ["ed25519", "rsa", "secp256k1", "ecdsa", "rand"] } 34 | libp2p-swarm = { workspace = true, features = ["tokio"] } 35 | libp2p-yamux = { workspace = true } 36 | tokio = { workspace = true, features = ["full"] } 37 | 38 | # Passing arguments to the docsrs builder in order to properly document cfg's. 39 | # More information: https://docs.rs/about/builds#cross-compiling 40 | [package.metadata.docs.rs] 41 | all-features = true 42 | 43 | [lints] 44 | workspace = true 45 | -------------------------------------------------------------------------------- /transports/tls/src/test_assets/ed25519.der: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sigp/rust-libp2p/e1bba263070194282cad48f07fb4aa0c87d03b55/transports/tls/src/test_assets/ed25519.der -------------------------------------------------------------------------------- /transports/tls/src/test_assets/ed448.der: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sigp/rust-libp2p/e1bba263070194282cad48f07fb4aa0c87d03b55/transports/tls/src/test_assets/ed448.der -------------------------------------------------------------------------------- /transports/tls/src/test_assets/nistp256_sha256.der: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sigp/rust-libp2p/e1bba263070194282cad48f07fb4aa0c87d03b55/transports/tls/src/test_assets/nistp256_sha256.der -------------------------------------------------------------------------------- /transports/tls/src/test_assets/nistp384_sha256.der: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sigp/rust-libp2p/e1bba263070194282cad48f07fb4aa0c87d03b55/transports/tls/src/test_assets/nistp384_sha256.der -------------------------------------------------------------------------------- /transports/tls/src/test_assets/nistp384_sha384.der: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sigp/rust-libp2p/e1bba263070194282cad48f07fb4aa0c87d03b55/transports/tls/src/test_assets/nistp384_sha384.der -------------------------------------------------------------------------------- /transports/tls/src/test_assets/nistp521_sha512.der: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sigp/rust-libp2p/e1bba263070194282cad48f07fb4aa0c87d03b55/transports/tls/src/test_assets/nistp521_sha512.der -------------------------------------------------------------------------------- /transports/tls/src/test_assets/openssl.cfg: -------------------------------------------------------------------------------- 1 | [ p2p_ext ] 2 | 1.3.6.1.4.1.53594.1.1 = critical,ASN1:SEQUENCE:ExtBody 3 | 4 | [ ExtBody ] 5 | pubkey = FORMAT:HEX,OCTETSTRING:08011220DF6491C415ED084B87E8F00CDB4A41C4035CFEA5F9D23D25FF9CA897E7FDDC0F 6 | signature = FORMAT:HEX,OCTETSTRING:94A89E52CC24FD29B4B49DE615C37D268362E8D7C7C096FB7CD013DC9402572AF4886480FEC507C3C03DB07A2EC816B2B6714427DC28F379E0859C6F3B15BB05 7 | -------------------------------------------------------------------------------- /transports/tls/src/test_assets/pkcs1_sha256.der: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sigp/rust-libp2p/e1bba263070194282cad48f07fb4aa0c87d03b55/transports/tls/src/test_assets/pkcs1_sha256.der -------------------------------------------------------------------------------- /transports/tls/src/test_assets/rsa_pkcs1_sha256.der: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sigp/rust-libp2p/e1bba263070194282cad48f07fb4aa0c87d03b55/transports/tls/src/test_assets/rsa_pkcs1_sha256.der -------------------------------------------------------------------------------- /transports/tls/src/test_assets/rsa_pkcs1_sha384.der: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sigp/rust-libp2p/e1bba263070194282cad48f07fb4aa0c87d03b55/transports/tls/src/test_assets/rsa_pkcs1_sha384.der -------------------------------------------------------------------------------- /transports/tls/src/test_assets/rsa_pkcs1_sha512.der: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sigp/rust-libp2p/e1bba263070194282cad48f07fb4aa0c87d03b55/transports/tls/src/test_assets/rsa_pkcs1_sha512.der -------------------------------------------------------------------------------- /transports/tls/src/test_assets/rsa_pss_sha384.der: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sigp/rust-libp2p/e1bba263070194282cad48f07fb4aa0c87d03b55/transports/tls/src/test_assets/rsa_pss_sha384.der -------------------------------------------------------------------------------- /transports/uds/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "libp2p-uds" 3 | edition.workspace = true 4 | rust-version = { workspace = true } 5 | description = "Unix domain sockets transport for libp2p" 6 | version = "0.42.0" 7 | authors = ["Parity Technologies "] 8 | license = "MIT" 9 | repository = "https://github.com/libp2p/rust-libp2p" 10 | keywords = ["peer-to-peer", "libp2p", "networking"] 11 | categories = ["network-programming", "asynchronous"] 12 | 13 | [dependencies] 14 | async-std = { version = "1.6.2", optional = true } 15 | libp2p-core = { workspace = true } 16 | futures = { workspace = true } 17 | tokio = { workspace = true, default-features = false, features = ["net"], optional = true } 18 | tracing = { workspace = true } 19 | 20 | [dev-dependencies] 21 | tempfile = "3.10" 22 | 23 | # Passing arguments to the docsrs builder in order to properly document cfg's. 24 | # More information: https://docs.rs/about/builds#cross-compiling 25 | [package.metadata.docs.rs] 26 | all-features = true 27 | 28 | [lints] 29 | workspace = true 30 | -------------------------------------------------------------------------------- /transports/webrtc-websys/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 0.4.0 2 | 3 | - Cut stable release. 4 | See [PR 5807](https://github.com/libp2p/rust-libp2p/pull/5807) 5 | - Bump version of web-sys and update `__Nonexhaustive` to `__Invalid`. 6 | See [PR 5569](https://github.com/libp2p/rust-libp2p/pull/5569) 7 | 8 | 9 | 10 | ## 0.4.0-alpha 11 | 12 | - Implement refactored `Transport`. 13 | See [PR 4568](https://github.com/libp2p/rust-libp2p/pull/4568) 14 | 15 | ## 0.3.0-alpha 16 | 17 | - Bump version in order to publish a new version dependent on latest `libp2p-core`. 18 | See [PR 4959](https://github.com/libp2p/rust-libp2p/pull/4959). 19 | - Remove `libp2p_noise` from the public API. 20 | See [PR 4969](https://github.com/libp2p/rust-libp2p/pull/4969). 21 | 22 | ## 0.2.0-alpha 23 | 24 | - Rename `Error::JsError` to `Error::Js`. 25 | See [PR 4653](https://github.com/libp2p/rust-libp2p/pull/4653) 26 | 27 | ## 0.1.0-alpha 28 | 29 | - Initial alpha release. 30 | See [PR 4248]. 31 | 32 | [PR 4248]: https://github.com/libp2p/rust-libp2p/pull/4248 33 | -------------------------------------------------------------------------------- /transports/webrtc-websys/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | authors = ["Doug Anderson "] 3 | categories = ["asynchronous", "network-programming", "wasm", "web-programming"] 4 | description = "WebRTC for libp2p under WASM environment" 5 | edition.workspace = true 6 | keywords = ["libp2p", "networking", "peer-to-peer"] 7 | license = "MIT" 8 | name = "libp2p-webrtc-websys" 9 | repository = "https://github.com/libp2p/rust-libp2p" 10 | rust-version = { workspace = true } 11 | version = "0.4.0" 12 | publish = true 13 | 14 | [dependencies] 15 | bytes = "1" 16 | futures = { workspace = true } 17 | getrandom = { workspace = true, features = ["js"] } 18 | hex = "0.4.3" 19 | js-sys = { version = "0.3" } 20 | libp2p-core = { workspace = true } 21 | libp2p-identity = { workspace = true } 22 | libp2p-webrtc-utils = { workspace = true } 23 | send_wrapper = { version = "0.6.0", features = ["futures"] } 24 | thiserror = { workspace = true } 25 | tracing = { workspace = true } 26 | wasm-bindgen = { version = "0.2.90" } 27 | wasm-bindgen-futures = { version = "0.4.42" } 28 | web-sys = { version = "0.3.70", features = ["Document", "Location", "MessageEvent", "Navigator", "RtcCertificate", "RtcConfiguration", "RtcDataChannel", "RtcDataChannelEvent", "RtcDataChannelInit", "RtcDataChannelState", "RtcDataChannelType", "RtcPeerConnection", "RtcSdpType", "RtcSessionDescription", "RtcSessionDescriptionInit", "Window"] } 29 | 30 | [lints] 31 | workspace = true 32 | -------------------------------------------------------------------------------- /transports/webrtc-websys/README.md: -------------------------------------------------------------------------------- 1 | # Rust `libp2p-webrtc-websys` 2 | 3 | Browser Transport made available through `web-sys` bindings. 4 | 5 | ## Usage 6 | 7 | Use with `Swarm::with_wasm_executor` to enable the `wasm-bindgen` executor for the `Swarm`. 8 | 9 | See the [browser-webrtc](../../examples/browser-webrtc) example for a full example. 10 | -------------------------------------------------------------------------------- /transports/webrtc-websys/src/error.rs: -------------------------------------------------------------------------------- 1 | use wasm_bindgen::{JsCast, JsValue}; 2 | 3 | /// Errors that may happen on the [`Transport`](crate::Transport) or the 4 | /// [`Connection`](crate::Connection). 5 | #[derive(thiserror::Error, Debug)] 6 | pub enum Error { 7 | #[error("Invalid multiaddr: {0}")] 8 | InvalidMultiaddr(&'static str), 9 | 10 | #[error("JavaScript error: {0}")] 11 | Js(String), 12 | 13 | #[error("JavaScript typecasting failed")] 14 | JsCastFailed, 15 | 16 | #[error("Unknown remote peer ID")] 17 | UnknownRemotePeerId, 18 | 19 | #[error("Connection error: {0}")] 20 | Connection(String), 21 | 22 | #[error("Authentication error")] 23 | Authentication(#[from] AuthenticationError), 24 | } 25 | 26 | /// New-type wrapper to hide `libp2p_noise` from the public API. 27 | #[derive(thiserror::Error, Debug)] 28 | #[error(transparent)] 29 | pub struct AuthenticationError(pub(crate) libp2p_webrtc_utils::noise::Error); 30 | 31 | impl Error { 32 | pub(crate) fn from_js_value(value: JsValue) -> Self { 33 | let s = if value.is_instance_of::() { 34 | js_sys::Error::from(value) 35 | .to_string() 36 | .as_string() 37 | .unwrap_or_else(|| "Unknown error".to_string()) 38 | } else { 39 | "Unknown error".to_string() 40 | }; 41 | 42 | Error::Js(s) 43 | } 44 | } 45 | 46 | impl From for Error { 47 | fn from(value: JsValue) -> Self { 48 | Error::from_js_value(value) 49 | } 50 | } 51 | 52 | impl From for Error { 53 | fn from(value: String) -> Self { 54 | Error::Js(value) 55 | } 56 | } 57 | 58 | impl From for Error { 59 | fn from(value: std::io::Error) -> Self { 60 | Error::Js(value.to_string()) 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /transports/webrtc-websys/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![doc = include_str!("../README.md")] 2 | 3 | mod connection; 4 | mod error; 5 | mod sdp; 6 | mod stream; 7 | mod transport; 8 | mod upgrade; 9 | 10 | pub use self::{ 11 | connection::Connection, 12 | error::Error, 13 | stream::Stream, 14 | transport::{Config, Transport}, 15 | }; 16 | -------------------------------------------------------------------------------- /transports/webrtc-websys/src/sdp.rs: -------------------------------------------------------------------------------- 1 | use std::net::SocketAddr; 2 | 3 | use libp2p_webrtc_utils::Fingerprint; 4 | use web_sys::{RtcSdpType, RtcSessionDescriptionInit}; 5 | 6 | /// Creates the SDP answer used by the client. 7 | pub(crate) fn answer( 8 | addr: SocketAddr, 9 | server_fingerprint: Fingerprint, 10 | client_ufrag: &str, 11 | ) -> RtcSessionDescriptionInit { 12 | let answer_obj = RtcSessionDescriptionInit::new(RtcSdpType::Answer); 13 | answer_obj.set_sdp(&libp2p_webrtc_utils::sdp::answer( 14 | addr, 15 | server_fingerprint, 16 | client_ufrag, 17 | )); 18 | answer_obj 19 | } 20 | 21 | /// Creates the munged SDP offer from the Browser's given SDP offer 22 | /// 23 | /// Certificate verification is disabled which is why we hardcode a dummy fingerprint here. 24 | pub(crate) fn offer(offer: String, client_ufrag: &str) -> RtcSessionDescriptionInit { 25 | // find line and replace a=ice-ufrag: with "\r\na=ice-ufrag:{client_ufrag}\r\n" 26 | // find line and replace a=ice-pwd: with "\r\na=ice-ufrag:{client_ufrag}\r\n" 27 | 28 | let mut munged_sdp_offer = String::new(); 29 | 30 | for line in offer.split("\r\n") { 31 | if line.starts_with("a=ice-ufrag:") { 32 | munged_sdp_offer.push_str(&format!("a=ice-ufrag:{client_ufrag}\r\n")); 33 | continue; 34 | } 35 | 36 | if line.starts_with("a=ice-pwd:") { 37 | munged_sdp_offer.push_str(&format!("a=ice-pwd:{client_ufrag}\r\n")); 38 | continue; 39 | } 40 | 41 | if !line.is_empty() { 42 | munged_sdp_offer.push_str(&format!("{}\r\n", line)); 43 | continue; 44 | } 45 | } 46 | 47 | // remove any double \r\n 48 | let munged_sdp_offer = munged_sdp_offer.replace("\r\n\r\n", "\r\n"); 49 | 50 | tracing::trace!(offer=%munged_sdp_offer, "Created SDP offer"); 51 | 52 | let offer_obj = RtcSessionDescriptionInit::new(RtcSdpType::Offer); 53 | offer_obj.set_sdp(&munged_sdp_offer); 54 | 55 | offer_obj 56 | } 57 | -------------------------------------------------------------------------------- /transports/webrtc/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 0.9.0-alpha 2 | 3 | 4 | 5 | ## 0.8.0-alpha 6 | 7 | - Implement refactored `Transport`. 8 | See [PR 4568](https://github.com/libp2p/rust-libp2p/pull/4568) 9 | 10 | ## 0.7.1-alpha 11 | 12 | - Bump `libp2p-webrtc-utils` dependency to `0.2.0`. 13 | See [PR 5118](https://github.com/libp2p/rust-libp2p/pull/5118). 14 | 15 | ## 0.7.0-alpha 16 | 17 | - Bump version in order to publish a new version dependent on latest `libp2p-core`. 18 | See [PR 4959](https://github.com/libp2p/rust-libp2p/pull/4959). 19 | 20 | ## 0.6.1-alpha 21 | 22 | - Move common dependencies to `libp2p-webrtc-utils` crate. 23 | See [PR 4248]. 24 | 25 | [PR 4248]: https://github.com/libp2p/rust-libp2p/pull/4248 26 | 27 | ## 0.6.0-alpha 28 | 29 | - Update `webrtc` dependency to `v0.8.0`. 30 | See [PR 4099]. 31 | 32 | [PR 4099]: https://github.com/libp2p/rust-libp2p/pull/4099 33 | 34 | ## 0.5.0-alpha 35 | 36 | - Raise MSRV to 1.65. 37 | See [PR 3715]. 38 | 39 | [PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715 40 | 41 | ## 0.4.0-alpha.4 42 | 43 | - Make `Fingerprint` type public. See [PR 3648]. 44 | 45 | [PR 3648]: https://github.com/libp2p/rust-libp2p/pull/3648 46 | 47 | ## 0.4.0-alpha.3 48 | 49 | - Gracefully handle `ConnectionReset` error on individual connections, avoiding shutdown of the entire listener upon disconnect of a single client. 50 | See [PR 3575]. 51 | 52 | - Migrate from `prost` to `quick-protobuf`. This removes `protoc` dependency. See [PR 3312]. 53 | 54 | [PR 3575]: https://github.com/libp2p/rust-libp2p/pull/3575 55 | [PR 3312]: https://github.com/libp2p/rust-libp2p/pull/3312 56 | 57 | ## 0.4.0-alpha.2 58 | 59 | - Update to `libp2p-noise` `v0.42.0`. 60 | 61 | - Update to `libp2p-core` `v0.39.0`. 62 | 63 | ## 0.4.0-alpha 64 | 65 | - Initial alpha release. 66 | -------------------------------------------------------------------------------- /transports/webrtc/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "libp2p-webrtc" 3 | version = "0.9.0-alpha" 4 | authors = ["Parity Technologies "] 5 | description = "WebRTC transport for libp2p" 6 | repository = "https://github.com/libp2p/rust-libp2p" 7 | license = "MIT" 8 | edition.workspace = true 9 | rust-version = { workspace = true } 10 | keywords = ["peer-to-peer", "libp2p", "networking"] 11 | categories = ["network-programming", "asynchronous"] 12 | 13 | [dependencies] 14 | async-trait = "0.1" 15 | futures = { workspace = true } 16 | futures-timer = "3" 17 | hex = "0.4" 18 | if-watch = { workspace = true } 19 | libp2p-core = { workspace = true } 20 | libp2p-noise = { workspace = true } 21 | libp2p-identity = { workspace = true } 22 | libp2p-webrtc-utils = { workspace = true } 23 | multihash = { workspace = true } 24 | rand = "0.8" 25 | rcgen = "0.11" 26 | stun = "0.7" 27 | thiserror = { workspace = true } 28 | tokio = { workspace = true, features = ["net"], optional = true } 29 | tokio-util = { version = "0.7", features = ["compat"], optional = true } 30 | tracing = { workspace = true } 31 | webrtc = { version = "0.9.0", optional = true } 32 | webrtc-ice = "=0.10.0" # smoke tests only work with this version 33 | 34 | [features] 35 | tokio = ["dep:tokio", "dep:tokio-util", "dep:webrtc", "if-watch/tokio"] 36 | pem = ["webrtc?/pem"] 37 | 38 | [dev-dependencies] 39 | libp2p-identity = { workspace = true, features = ["rand"] } 40 | tokio = { workspace = true, features = ["full"] } 41 | quickcheck = "1.0.3" 42 | tracing-subscriber = { workspace = true, features = ["env-filter"] } 43 | 44 | 45 | [[test]] 46 | name = "smoke" 47 | required-features = ["tokio"] 48 | 49 | [lints] 50 | workspace = true 51 | 52 | # Passing arguments to the docsrs builder in order to properly document cfg's. 53 | # More information: https://docs.rs/about/builds#cross-compiling 54 | [package.metadata.docs.rs] 55 | all-features = true 56 | -------------------------------------------------------------------------------- /transports/webrtc/src/tokio/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Parity Technologies (UK) Ltd. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the "Software"), 5 | // to deal in the Software without restriction, including without limitation 6 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, 7 | // and/or sell copies of the Software, and to permit persons to whom the 8 | // Software is furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 14 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19 | // DEALINGS IN THE SOFTWARE. 20 | 21 | pub mod certificate; 22 | mod connection; 23 | mod error; 24 | mod fingerprint; 25 | mod req_res_chan; 26 | mod sdp; 27 | mod stream; 28 | mod transport; 29 | mod udp_mux; 30 | mod upgrade; 31 | 32 | pub use certificate::Certificate; 33 | pub use connection::Connection; 34 | pub use error::Error; 35 | pub use fingerprint::Fingerprint; 36 | pub use transport::Transport; 37 | -------------------------------------------------------------------------------- /transports/websocket-websys/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 0.5.0 2 | 3 | - fix: Return `None` when extracting a `/dnsaddr` address 4 | See [PR 5613](https://github.com/libp2p/rust-libp2p/pull/5613) 5 | 6 | - Fix `cargo clippy` warnings in `rustc 1.84.0-beta.1`. 7 | See [PR 5700](https://github.com/libp2p/rust-libp2p/pull/5700). 8 | 9 | 10 | 11 | ## 0.4.0 12 | 13 | - Implement refactored `Transport`. 14 | See [PR 4568](https://github.com/libp2p/rust-libp2p/pull/4568) 15 | - Add support for `/tls/ws` and keep `/wss` backward compatible. 16 | See [PR 5523](https://github.com/libp2p/rust-libp2p/pull/5523). 17 | 18 | ## 0.3.3 19 | 20 | - Fix use-after-free handler invocation from JS side. 21 | See [PR 5521](https://github.com/libp2p/rust-libp2p/pull/5521). 22 | 23 | ## 0.3.2 24 | 25 | - Change close code in drop implementation to `1000` given that in browsers only 26 | the code `1000` and codes between `3000` and `4999` are allowed to be set by 27 | userland code. 28 | See [PR 5229](https://github.com/libp2p/rust-libp2p/pull/5229). 29 | 30 | ## 0.3.1 31 | 32 | - Add support for different WASM environments by introducing a `WebContext` that 33 | detects and abstracts the `Window` vs the `WorkerGlobalScope` API. 34 | See [PR 4889](https://github.com/libp2p/rust-libp2p/pull/4889). 35 | 36 | ## 0.3.0 37 | 38 | 39 | ## 0.2.0 40 | 41 | - Add Websys Websocket transport. 42 | 43 | ## 0.1.0 44 | 45 | - Crate claimed. 46 | -------------------------------------------------------------------------------- /transports/websocket-websys/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "libp2p-websocket-websys" 3 | edition.workspace = true 4 | rust-version.workspace = true 5 | description = "WebSocket for libp2p under WASM environment" 6 | version = "0.5.0" 7 | authors = ["Vince Vasta "] 8 | license = "MIT" 9 | repository = "https://github.com/libp2p/rust-libp2p" 10 | keywords = ["peer-to-peer", "libp2p", "networking"] 11 | categories = ["network-programming", "asynchronous"] 12 | 13 | [dependencies] 14 | bytes = "1.6.0" 15 | futures = { workspace = true } 16 | js-sys = "0.3.69" 17 | libp2p-core = { workspace = true } 18 | tracing = { workspace = true } 19 | send_wrapper = "0.6.0" 20 | thiserror = { workspace = true } 21 | wasm-bindgen = "0.2.90" 22 | web-sys = { version = "0.3.69", features = ["BinaryType", "CloseEvent", "MessageEvent", "WebSocket", "Window", "WorkerGlobalScope"] } 23 | 24 | # Passing arguments to the docsrs builder in order to properly document cfg's. 25 | # More information: https://docs.rs/about/builds#cross-compiling 26 | [package.metadata.docs.rs] 27 | all-features = true 28 | 29 | [dev-dependencies] 30 | libp2p-yamux = { workspace = true } 31 | libp2p-noise = { workspace = true } 32 | libp2p-identity = { workspace = true, features = ["rand"] } 33 | -------------------------------------------------------------------------------- /transports/websocket/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "libp2p-websocket" 3 | edition.workspace = true 4 | rust-version = { workspace = true } 5 | description = "WebSocket transport for libp2p" 6 | version = "0.45.1" 7 | authors = ["Parity Technologies "] 8 | license = "MIT" 9 | repository = "https://github.com/libp2p/rust-libp2p" 10 | keywords = ["peer-to-peer", "libp2p", "networking"] 11 | categories = ["network-programming", "asynchronous"] 12 | 13 | [dependencies] 14 | futures-rustls = { workspace = true, features = ["ring"] } 15 | either = "1.12.0" 16 | futures = { workspace = true } 17 | libp2p-core = { workspace = true } 18 | libp2p-identity = { workspace = true } 19 | parking_lot = "0.12.3" 20 | pin-project-lite = "0.2.14" 21 | rw-stream-sink = { workspace = true } 22 | soketto = "0.8.0" 23 | tracing = { workspace = true } 24 | thiserror = { workspace = true } 25 | url = "2.5" 26 | webpki-roots = "0.25" 27 | 28 | [dev-dependencies] 29 | libp2p-tcp = { workspace = true, features = ["async-io"] } 30 | libp2p-dns = { workspace = true, features = ["async-std"] } 31 | libp2p-identity = { workspace = true, features = ["rand"] } 32 | async-std = { version = "1.6.5", features = ["attributes"] } 33 | rcgen = { workspace = true } 34 | 35 | # Passing arguments to the docsrs builder in order to properly document cfg's. 36 | # More information: https://docs.rs/about/builds#cross-compiling 37 | [package.metadata.docs.rs] 38 | all-features = true 39 | 40 | [lints] 41 | workspace = true 42 | -------------------------------------------------------------------------------- /transports/webtransport-websys/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 0.5.1 2 | 3 | - Remove `once_cell` dependency. 4 | See [PR 5913](https://github.com/libp2p/rust-libp2p/pull/5913) 5 | 6 | ## 0.5.0 7 | 8 | - Fix `cargo clippy` warnings in `rustc 1.84.0-beta.1`. 9 | See [PR 5700](https://github.com/libp2p/rust-libp2p/pull/5700). 10 | 11 | 12 | 13 | ## 0.4.0 14 | 15 | - Implement refactored `Transport`. 16 | See [PR 4568](https://github.com/libp2p/rust-libp2p/pull/4568) 17 | - Bump version of web-sys and wasm-bindgen. 18 | See [PR 5569](https://github.com/libp2p/rust-libp2p/pull/5569) 19 | 20 | ## 0.3.0 21 | 22 | * Fix unhandled exceptions thrown when calling `Webtransport::close`. 23 | See [PR 5390](https://github.com/libp2p/rust-libp2p/pull/5390). 24 | * Change logs to debug level. 25 | See [PR 5396](https://github.com/libp2p/rust-libp2p/pull/5396). 26 | 27 | 28 | ## 0.2.0 29 | 30 | 31 | ## 0.1.0 32 | 33 | * Initial implementation of WebTransport transport using web-sys bindings. See [PR 4015]. 34 | 35 | [PR 4015]: https://github.com/libp2p/rust-libp2p/pull/4015 36 | -------------------------------------------------------------------------------- /transports/webtransport-websys/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "libp2p-webtransport-websys" 3 | edition.workspace = true 4 | rust-version = { workspace = true } 5 | description = "WebTransport for libp2p under WASM environment" 6 | version = "0.5.1" 7 | authors = [ 8 | "Yiannis Marangos ", 9 | "oblique ", 10 | ] 11 | license = "MIT" 12 | repository = "https://github.com/libp2p/rust-libp2p" 13 | keywords = ["peer-to-peer", "libp2p", "networking"] 14 | categories = ["network-programming", "asynchronous"] 15 | 16 | [dependencies] 17 | futures = { workspace = true } 18 | js-sys = "0.3.70" 19 | libp2p-core = { workspace = true } 20 | libp2p-identity = { workspace = true } 21 | libp2p-noise = { workspace = true } 22 | multiaddr = { workspace = true } 23 | multihash = { workspace = true } 24 | send_wrapper = { version = "0.6.0", features = ["futures"] } 25 | thiserror = { workspace = true } 26 | tracing = { workspace = true } 27 | wasm-bindgen = "0.2.93" 28 | wasm-bindgen-futures = "0.4.43" 29 | web-sys = { version = "0.3.70", features = [ 30 | "ReadableStreamDefaultReader", 31 | "WebTransport", 32 | "WebTransportBidirectionalStream", 33 | "WebTransportHash", 34 | "WebTransportOptions", 35 | "WebTransportReceiveStream", 36 | "WebTransportSendStream", 37 | "WritableStreamDefaultWriter", 38 | ] } 39 | 40 | [dev-dependencies] 41 | multibase = "0.9.1" 42 | 43 | # Passing arguments to the docsrs builder in order to properly document cfg's. 44 | # More information: https://docs.rs/about/builds#cross-compiling 45 | [package.metadata.docs.rs] 46 | all-features = true 47 | 48 | [lints] 49 | workspace = true 50 | -------------------------------------------------------------------------------- /transports/webtransport-websys/src/error.rs: -------------------------------------------------------------------------------- 1 | use wasm_bindgen::{JsCast, JsValue}; 2 | 3 | /// Errors that may happen on the [`Transport`](crate::Transport) or the 4 | /// [`Connection`](crate::Connection). 5 | #[derive(thiserror::Error, Debug)] 6 | pub enum Error { 7 | #[error("Invalid multiaddr: {0}")] 8 | InvalidMultiaddr(&'static str), 9 | 10 | #[error("Noise authentication failed")] 11 | Noise(#[from] libp2p_noise::Error), 12 | 13 | #[error("JavaScript error: {0}")] 14 | #[allow(clippy::enum_variant_names)] 15 | JsError(String), 16 | 17 | #[error("JavaScript typecasting failed")] 18 | JsCastFailed, 19 | 20 | #[error("Unknown remote peer ID")] 21 | UnknownRemotePeerId, 22 | } 23 | 24 | impl Error { 25 | pub(crate) fn from_js_value(value: JsValue) -> Self { 26 | let s = if value.is_instance_of::() { 27 | js_sys::Error::from(value) 28 | .to_string() 29 | .as_string() 30 | .unwrap_or_else(|| "Unknown error".to_string()) 31 | } else { 32 | "Unknown error".to_string() 33 | }; 34 | 35 | Error::JsError(s) 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /transports/webtransport-websys/src/fused_js_promise.rs: -------------------------------------------------------------------------------- 1 | use std::{ 2 | future::Future, 3 | pin::Pin, 4 | task::{ready, Context, Poll}, 5 | }; 6 | 7 | use futures::FutureExt; 8 | use js_sys::Promise; 9 | use wasm_bindgen::JsValue; 10 | use wasm_bindgen_futures::JsFuture; 11 | 12 | /// Convenient wrapper to poll a promise to completion. 13 | /// 14 | /// # Panics 15 | /// 16 | /// Panics if polled and promise is not initialized. Use `maybe_init` if unsure. 17 | #[derive(Debug)] 18 | pub(crate) struct FusedJsPromise { 19 | promise: Option, 20 | } 21 | 22 | impl FusedJsPromise { 23 | /// Creates new uninitialized promise. 24 | pub(crate) fn new() -> Self { 25 | FusedJsPromise { promise: None } 26 | } 27 | 28 | /// Initialize promise if needed 29 | pub(crate) fn maybe_init(&mut self, init: F) -> &mut Self 30 | where 31 | F: FnOnce() -> Promise, 32 | { 33 | if self.promise.is_none() { 34 | self.promise = Some(JsFuture::from(init())); 35 | } 36 | 37 | self 38 | } 39 | 40 | /// Checks if promise is already running 41 | pub(crate) fn is_active(&self) -> bool { 42 | self.promise.is_some() 43 | } 44 | } 45 | 46 | impl Future for FusedJsPromise { 47 | type Output = Result; 48 | 49 | fn poll(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll { 50 | let val = ready!(self 51 | .promise 52 | .as_mut() 53 | .expect("FusedJsPromise not initialized") 54 | .poll_unpin(cx)); 55 | 56 | // Future finished, drop it 57 | self.promise.take(); 58 | 59 | Poll::Ready(val) 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /transports/webtransport-websys/src/lib.rs: -------------------------------------------------------------------------------- 1 | //! Libp2p WebTransport built on [web-sys](https://rustwasm.github.io/wasm-bindgen/web-sys/index.html) 2 | 3 | #![allow(unexpected_cfgs)] 4 | 5 | mod bindings; 6 | mod connection; 7 | mod endpoint; 8 | mod error; 9 | mod fused_js_promise; 10 | mod stream; 11 | mod transport; 12 | mod utils; 13 | 14 | pub use self::{ 15 | connection::Connection, 16 | error::Error, 17 | stream::Stream, 18 | transport::{Config, Transport}, 19 | }; 20 | -------------------------------------------------------------------------------- /wasm-tests/README.md: -------------------------------------------------------------------------------- 1 | # Dependencies 2 | 3 | Before you run the tests you need to install the following: 4 | 5 | * Chrome or Chromium 6 | * chromedriver (major version must be the same as Chrome's) 7 | * wasm-pack 8 | 9 | # Run tests 10 | 11 | Just call `run-all.sh` or `run.sh` in the test directory if you are interested. 12 | -------------------------------------------------------------------------------- /wasm-tests/run-all.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | # cd to this script directory 5 | cd "$(dirname "${BASH_SOURCE[0]}")" || exit 1 6 | 7 | ./webtransport-tests/run.sh 8 | -------------------------------------------------------------------------------- /wasm-tests/webtransport-tests/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "webtransport-tests" 3 | version = "0.1.0" 4 | edition.workspace = true 5 | license = "MIT" 6 | publish = false 7 | 8 | [package.metadata.release] 9 | release = false 10 | 11 | [dependencies] 12 | futures = { workspace = true } 13 | getrandom = { workspace = true, features = ["js"] } 14 | libp2p-core = { workspace = true } 15 | libp2p-identity = { workspace = true, features = ["rand"] } 16 | libp2p-noise = { workspace = true } 17 | libp2p-webtransport-websys = { workspace = true } 18 | multiaddr = { workspace = true } 19 | multihash = { workspace = true } 20 | wasm-bindgen = "0.2.93" 21 | wasm-bindgen-futures = "0.4.43" 22 | wasm-bindgen-test = "0.3.43" 23 | web-sys = { version = "0.3.70", features = ["Response", "Window"] } 24 | 25 | [lints] 26 | workspace = true 27 | -------------------------------------------------------------------------------- /wasm-tests/webtransport-tests/README.md: -------------------------------------------------------------------------------- 1 | # Manually run tests 2 | 3 | First you need to build and start the echo-server: 4 | 5 | ``` 6 | docker build -t webtransport-echo-server echo-server 7 | docker run -it --rm --network=host webtransport-echo-server 8 | ``` 9 | 10 | On another terminal run: 11 | 12 | ``` 13 | wasm-pack test --chrome 14 | ``` 15 | 16 | Navigate with your browser at http://127.0.0.1:8000. 17 | 18 | You can also run the tests on a headless browser: 19 | 20 | ``` 21 | wasm-pack test --chrome --headless 22 | ``` 23 | 24 | > **Note:** For headless tests your Chrome browser needs to be compatible 25 | > with chromedriver (i.e. they must have the same major version). 26 | > 27 | > You may need to define the path of chromedriver with `--chromedriver=/path/to/chromedriver`. 28 | -------------------------------------------------------------------------------- /wasm-tests/webtransport-tests/echo-server/.gitignore: -------------------------------------------------------------------------------- 1 | /echo-server 2 | -------------------------------------------------------------------------------- /wasm-tests/webtransport-tests/echo-server/Dockerfile: -------------------------------------------------------------------------------- 1 | # syntax=docker/dockerfile:1.5-labs 2 | FROM docker.io/library/golang:1.24 AS builder 3 | WORKDIR /workspace 4 | ADD . . 5 | RUN CGO_ENABLED=0 go build . 6 | 7 | FROM scratch 8 | COPY --from=builder /workspace/echo-server / 9 | ENTRYPOINT ["/echo-server"] 10 | -------------------------------------------------------------------------------- /wasm-tests/webtransport-tests/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Prefer podman over docker since it doesn't require root privileges 4 | if command -v podman > /dev/null; then 5 | docker=podman 6 | else 7 | docker=docker 8 | fi 9 | 10 | # cd to this script directory 11 | cd "$(dirname "${BASH_SOURCE[0]}")" || exit 1 12 | 13 | # Print the directory for debugging 14 | echo "Tests: $PWD" 15 | 16 | # Build and run echo-server 17 | $docker build -t webtransport-echo-server echo-server || exit 1 18 | id="$($docker run -d --network=host webtransport-echo-server)" || exit 1 19 | 20 | # Run tests 21 | wasm-pack test --chrome --headless 22 | exit_code=$? 23 | 24 | # Remove echo-server container 25 | $docker rm -f "$id" 26 | 27 | # Propagate wasm-pack's exit code 28 | exit $exit_code 29 | --------------------------------------------------------------------------------