libp2p 0.2.8__tar.gz → 0.2.9__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {libp2p-0.2.8/libp2p.egg-info → libp2p-0.2.9}/PKG-INFO +3 -2
- {libp2p-0.2.8 → libp2p-0.2.9}/examples/doc-examples/example_encryption_insecure.py +6 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/examples/echo/echo.py +3 -4
- libp2p-0.2.9/examples/kademlia/kademlia.py +300 -0
- libp2p-0.2.9/examples/mDNS/mDNS.py +74 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/__init__.py +13 -4
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/abc.py +576 -58
- libp2p-0.2.9/libp2p/discovery/events/peerDiscovery.py +26 -0
- libp2p-0.2.9/libp2p/discovery/mdns/broadcaster.py +91 -0
- libp2p-0.2.9/libp2p/discovery/mdns/listener.py +83 -0
- libp2p-0.2.9/libp2p/discovery/mdns/mdns.py +73 -0
- libp2p-0.2.9/libp2p/discovery/mdns/utils.py +11 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/host/basic_host.py +30 -6
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/host/routed_host.py +4 -2
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/identity/identify_push/identify_push.py +23 -21
- libp2p-0.2.9/libp2p/kad_dht/__init__.py +30 -0
- libp2p-0.2.9/libp2p/kad_dht/common.py +14 -0
- libp2p-0.2.9/libp2p/kad_dht/kad_dht.py +616 -0
- libp2p-0.2.9/libp2p/kad_dht/pb/kademlia_pb2.py +33 -0
- libp2p-0.2.9/libp2p/kad_dht/pb/kademlia_pb2.pyi +133 -0
- libp2p-0.2.9/libp2p/kad_dht/peer_routing.py +415 -0
- libp2p-0.2.9/libp2p/kad_dht/provider_store.py +577 -0
- libp2p-0.2.9/libp2p/kad_dht/routing_table.py +600 -0
- libp2p-0.2.9/libp2p/kad_dht/utils.py +117 -0
- libp2p-0.2.9/libp2p/kad_dht/value_store.py +393 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/network/swarm.py +2 -5
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/peer/peerdata.py +80 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/peer/peerinfo.py +18 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/peer/peerstore.py +122 -13
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/protocol_muxer/multiselect.py +41 -29
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/protocol_muxer/multiselect_client.py +50 -26
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/pubsub/floodsub.py +1 -13
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/pubsub/gossipsub.py +251 -108
- libp2p-0.2.9/libp2p/pubsub/pb/rpc_pb2.py +51 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/pubsub/pb/rpc_pb2.pyi +28 -2
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/pubsub/pubsub.py +55 -9
- libp2p-0.2.9/libp2p/relay/__init__.py +28 -0
- libp2p-0.2.9/libp2p/relay/circuit_v2/__init__.py +32 -0
- libp2p-0.2.9/libp2p/relay/circuit_v2/config.py +92 -0
- libp2p-0.2.9/libp2p/relay/circuit_v2/discovery.py +537 -0
- libp2p-0.2.9/libp2p/relay/circuit_v2/pb/__init__.py +16 -0
- libp2p-0.2.9/libp2p/relay/circuit_v2/pb/circuit_pb2.py +37 -0
- libp2p-0.2.9/libp2p/relay/circuit_v2/pb/circuit_pb2.pyi +184 -0
- libp2p-0.2.9/libp2p/relay/circuit_v2/protocol.py +800 -0
- libp2p-0.2.9/libp2p/relay/circuit_v2/protocol_buffer.py +55 -0
- libp2p-0.2.9/libp2p/relay/circuit_v2/resources.py +254 -0
- libp2p-0.2.9/libp2p/relay/circuit_v2/transport.py +427 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/security/insecure/transport.py +32 -3
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/stream_muxer/muxer_multistream.py +0 -3
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/stream_muxer/yamux/yamux.py +108 -59
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/tools/constants.py +5 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/tools/utils.py +4 -2
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/transport/upgrader.py +6 -1
- {libp2p-0.2.8 → libp2p-0.2.9/libp2p.egg-info}/PKG-INFO +3 -2
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p.egg-info/SOURCES.txt +52 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p.egg-info/entry_points.txt +1 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p.egg-info/requires.txt +2 -1
- {libp2p-0.2.8 → libp2p-0.2.9}/pyproject.toml +5 -4
- libp2p-0.2.9/tests/__init__.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/tests/core/identity/identify/test_identify.py +2 -9
- {libp2p-0.2.8 → libp2p-0.2.9}/tests/core/identity/identify_push/test_identify_push.py +181 -0
- libp2p-0.2.9/tests/core/kad_dht/test_kad_dht.py +168 -0
- libp2p-0.2.9/tests/core/kad_dht/test_unit_peer_routing.py +458 -0
- libp2p-0.2.9/tests/core/kad_dht/test_unit_provider_store.py +805 -0
- libp2p-0.2.9/tests/core/kad_dht/test_unit_routing_table.py +371 -0
- libp2p-0.2.9/tests/core/kad_dht/test_unit_value_store.py +504 -0
- libp2p-0.2.9/tests/core/peer/test_peerdata.py +241 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/tests/core/peer/test_peerstore.py +31 -0
- libp2p-0.2.9/tests/core/protocol_muxer/test_negotiate_timeout.py +59 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/tests/core/pubsub/test_gossipsub.py +251 -3
- libp2p-0.2.9/tests/core/pubsub/test_gossipsub_px_and_backoff.py +274 -0
- libp2p-0.2.9/tests/core/relay/test_circuit_v2_discovery.py +263 -0
- libp2p-0.2.9/tests/core/relay/test_circuit_v2_protocol.py +665 -0
- libp2p-0.2.9/tests/core/relay/test_circuit_v2_transport.py +346 -0
- libp2p-0.2.9/tests/core/security/test_insecure_peerstore_integration.py +314 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/tests/core/security/test_security_multistream.py +24 -3
- {libp2p-0.2.8 → libp2p-0.2.9}/tests/core/stream_muxer/test_yamux.py +1 -1
- libp2p-0.2.9/tests/core/stream_muxer/test_yamux_interleaving.py +199 -0
- libp2p-0.2.9/tests/core/stream_muxer/test_yamux_interleaving_EOF.py +195 -0
- libp2p-0.2.9/tests/discovery/__init__.py +0 -0
- libp2p-0.2.9/tests/discovery/mdns/__init__.py +0 -0
- libp2p-0.2.9/tests/discovery/mdns/test_broadcaster.py +91 -0
- libp2p-0.2.9/tests/discovery/mdns/test_listener.py +114 -0
- libp2p-0.2.9/tests/discovery/mdns/test_mdns.py +121 -0
- libp2p-0.2.9/tests/discovery/mdns/test_utils.py +39 -0
- libp2p-0.2.9/tests/utils/__init__.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/tests/utils/factories.py +18 -2
- libp2p-0.2.9/tests/utils/interop/__init__.py +0 -0
- libp2p-0.2.9/tests/utils/pubsub/__init__.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/tests/utils/pubsub/floodsub_integration_test_settings.py +3 -9
- libp2p-0.2.9/tests/utils/pubsub/utils.py +87 -0
- libp2p-0.2.9/tests/utils/utils.py +31 -0
- libp2p-0.2.8/libp2p/pubsub/pb/rpc_pb2.py +0 -49
- libp2p-0.2.8/tests/core/peer/test_peerdata.py +0 -109
- libp2p-0.2.8/tests/utils/pubsub/utils.py +0 -42
- {libp2p-0.2.8 → libp2p-0.2.9}/LICENSE-APACHE +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/LICENSE-MIT +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/MANIFEST.in +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/README.md +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/docs/conf.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/examples/__init__.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/examples/chat/__init__.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/examples/chat/chat.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/examples/doc-examples/example_encryption_noise.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/examples/doc-examples/example_encryption_secio.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/examples/doc-examples/example_multiplexer.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/examples/doc-examples/example_net_stream.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/examples/doc-examples/example_peer_discovery.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/examples/doc-examples/example_running.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/examples/doc-examples/example_transport.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/examples/echo/__init__.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/examples/identify/__init__.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/examples/identify/identify.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/examples/identify_push/__init__.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/examples/identify_push/identify_push_demo.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/examples/identify_push/identify_push_listener_dialer.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/examples/ping/__init__.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/examples/ping/ping.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/examples/pubsub/pubsub.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/crypto/__init__.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/crypto/authenticated_encryption.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/crypto/ecc.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/crypto/ed25519.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/crypto/exceptions.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/crypto/key_exchange.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/crypto/keys.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/crypto/pb/__init__.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/crypto/pb/crypto_pb2.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/crypto/pb/crypto_pb2.pyi +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/crypto/rsa.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/crypto/secp256k1.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/crypto/serialization.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/crypto/x25519.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/custom_types.py +0 -0
- {libp2p-0.2.8/libp2p/host → libp2p-0.2.9/libp2p/discovery}/__init__.py +0 -0
- {libp2p-0.2.8/libp2p/host/autonat/pb → libp2p-0.2.9/libp2p/discovery/events}/__init__.py +0 -0
- {libp2p-0.2.8/libp2p/identity/identify/pb → libp2p-0.2.9/libp2p/discovery/mdns}/__init__.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/exceptions.py +0 -0
- {libp2p-0.2.8/libp2p/io → libp2p-0.2.9/libp2p/host}/__init__.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/host/autonat/__init__.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/host/autonat/autonat.py +0 -0
- {libp2p-0.2.8/libp2p/network → libp2p-0.2.9/libp2p/host/autonat/pb}/__init__.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/host/autonat/pb/autonat_pb2.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/host/autonat/pb/autonat_pb2.pyi +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/host/autonat/pb/autonat_pb2_grpc.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/host/autonat/pb/autonat_pb2_grpc.pyi +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/host/autonat/pb/generate_proto.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/host/defaults.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/host/exceptions.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/host/ping.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/identity/__init__.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/identity/identify/__init__.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/identity/identify/identify.py +0 -0
- {libp2p-0.2.8/libp2p/network/connection → libp2p-0.2.9/libp2p/identity/identify/pb}/__init__.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/identity/identify/pb/identify_pb2.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/identity/identify/pb/identify_pb2.pyi +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/identity/identify_push/__init__.py +0 -0
- {libp2p-0.2.8/libp2p/network/stream → libp2p-0.2.9/libp2p/io}/__init__.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/io/abc.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/io/exceptions.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/io/msgio.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/io/trio.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/io/utils.py +0 -0
- {libp2p-0.2.8/libp2p/peer → libp2p-0.2.9/libp2p/kad_dht/pb}/__init__.py +0 -0
- {libp2p-0.2.8/libp2p/protocol_muxer → libp2p-0.2.9/libp2p/network}/__init__.py +0 -0
- {libp2p-0.2.8/libp2p/pubsub → libp2p-0.2.9/libp2p/network/connection}/__init__.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/network/connection/exceptions.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/network/connection/raw_connection.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/network/connection/swarm_connection.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/network/exceptions.py +0 -0
- {libp2p-0.2.8/libp2p/pubsub/pb → libp2p-0.2.9/libp2p/network/stream}/__init__.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/network/stream/exceptions.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/network/stream/net_stream.py +0 -0
- {libp2p-0.2.8/libp2p/security → libp2p-0.2.9/libp2p/peer}/__init__.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/peer/id.py +0 -0
- {libp2p-0.2.8/libp2p/security/insecure → libp2p-0.2.9/libp2p/protocol_muxer}/__init__.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/protocol_muxer/exceptions.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/protocol_muxer/multiselect_communicator.py +0 -0
- {libp2p-0.2.8/libp2p/security/insecure/pb → libp2p-0.2.9/libp2p/pubsub}/__init__.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/pubsub/exceptions.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/pubsub/mcache.py +0 -0
- {libp2p-0.2.8/libp2p/security/noise → libp2p-0.2.9/libp2p/pubsub/pb}/__init__.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/pubsub/pubsub_notifee.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/pubsub/subscription.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/pubsub/validators.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/py.typed +0 -0
- {libp2p-0.2.8/libp2p/security/noise/pb → libp2p-0.2.9/libp2p/security}/__init__.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/security/base_session.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/security/base_transport.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/security/exceptions.py +0 -0
- {libp2p-0.2.8/libp2p/security/secio → libp2p-0.2.9/libp2p/security/insecure}/__init__.py +0 -0
- {libp2p-0.2.8/libp2p/security/secio → libp2p-0.2.9/libp2p/security/insecure}/pb/__init__.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/security/insecure/pb/plaintext_pb2.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/security/insecure/pb/plaintext_pb2.pyi +0 -0
- {libp2p-0.2.8/libp2p/stream_muxer → libp2p-0.2.9/libp2p/security/noise}/__init__.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/security/noise/exceptions.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/security/noise/io.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/security/noise/messages.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/security/noise/patterns.py +0 -0
- {libp2p-0.2.8/libp2p/stream_muxer/mplex → libp2p-0.2.9/libp2p/security/noise/pb}/__init__.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/security/noise/pb/noise_pb2.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/security/noise/pb/noise_pb2.pyi +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/security/noise/transport.py +0 -0
- {libp2p-0.2.8/libp2p/tools → libp2p-0.2.9/libp2p/security/secio}/__init__.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/security/secio/exceptions.py +0 -0
- {libp2p-0.2.8/libp2p/tools/timed_cache → libp2p-0.2.9/libp2p/security/secio/pb}/__init__.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/security/secio/pb/spipe_pb2.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/security/secio/pb/spipe_pb2.pyi +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/security/secio/transport.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/security/secure_session.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/security/security_multistream.py +0 -0
- {libp2p-0.2.8/libp2p/transport → libp2p-0.2.9/libp2p/stream_muxer}/__init__.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/stream_muxer/exceptions.py +0 -0
- {libp2p-0.2.8/libp2p/transport/tcp → libp2p-0.2.9/libp2p/stream_muxer/mplex}/__init__.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/stream_muxer/mplex/constants.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/stream_muxer/mplex/datastructures.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/stream_muxer/mplex/exceptions.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/stream_muxer/mplex/mplex.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/stream_muxer/mplex/mplex_stream.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/stream_muxer/yamux/__init__.py +0 -0
- {libp2p-0.2.8/tests → libp2p-0.2.9/libp2p/tools}/__init__.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/tools/async_service/__init__.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/tools/async_service/_utils.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/tools/async_service/abc.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/tools/async_service/base.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/tools/async_service/exceptions.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/tools/async_service/stats.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/tools/async_service/trio_service.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/tools/async_service/typing.py +0 -0
- {libp2p-0.2.8/tests/utils → libp2p-0.2.9/libp2p/tools/timed_cache}/__init__.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/tools/timed_cache/base_timed_cache.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/tools/timed_cache/first_seen_cache.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/tools/timed_cache/last_seen_cache.py +0 -0
- {libp2p-0.2.8/tests/utils/interop → libp2p-0.2.9/libp2p/transport}/__init__.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/transport/exceptions.py +0 -0
- {libp2p-0.2.8/tests/utils/pubsub → libp2p-0.2.9/libp2p/transport/tcp}/__init__.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/transport/tcp/tcp.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/utils/__init__.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/utils/logging.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/utils/varint.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p/utils/version.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p.egg-info/dependency_links.txt +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/libp2p.egg-info/top_level.txt +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/newsfragments/validate_files.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/scripts/release/test_package.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/setup.cfg +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/tests/conftest.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/tests/core/crypto/test_ed25519.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/tests/core/crypto/test_rsa.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/tests/core/crypto/test_secp256k1.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/tests/core/crypto/test_x25519.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/tests/core/examples/test_examples.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/tests/core/host/test_autonat.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/tests/core/host/test_basic_host.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/tests/core/host/test_connected_peers.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/tests/core/host/test_live_peers.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/tests/core/host/test_ping.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/tests/core/host/test_routed_host.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/tests/core/network/conftest.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/tests/core/network/test_net_stream.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/tests/core/network/test_notify.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/tests/core/network/test_swarm.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/tests/core/network/test_swarm_conn.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/tests/core/peer/test_addrbook.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/tests/core/peer/test_interop.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/tests/core/peer/test_peerid.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/tests/core/peer/test_peerinfo.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/tests/core/peer/test_peermetadata.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/tests/core/protocol_muxer/test_protocol_muxer.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/tests/core/pubsub/test_dummyaccount_demo.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/tests/core/pubsub/test_floodsub.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/tests/core/pubsub/test_gossipsub_backward_compatibility.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/tests/core/pubsub/test_gossipsub_direct_peers.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/tests/core/pubsub/test_mcache.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/tests/core/pubsub/test_pubsub.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/tests/core/pubsub/test_subscription.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/tests/core/security/noise/test_msg_read_writer.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/tests/core/security/noise/test_noise.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/tests/core/security/test_secio.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/tests/core/stream_muxer/conftest.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/tests/core/stream_muxer/test_async_context_manager.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/tests/core/stream_muxer/test_mplex_conn.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/tests/core/stream_muxer/test_mplex_stream.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/tests/core/stream_muxer/test_multiplexer_selection.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/tests/core/test_import_and_version.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/tests/core/test_libp2p/test_libp2p.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/tests/core/tools/async_service/test_trio_based_service.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/tests/core/tools/async_service/test_trio_external_api.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/tests/core/tools/async_service/test_trio_manager_stats.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/tests/core/tools/timed_cache/test_timed_cache.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/tests/core/transport/test_tcp.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/tests/exceptions/test_exceptions.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/tests/interop/go_libp2p/test_go_basic.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/tests/interop/js_libp2p/test_js_basic.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/tests/interop/rust_libp2p/test_rust_basic.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/tests/interop/zig_libp2p/test_zig_basic.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/tests/utils/interop/constants.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/tests/utils/interop/daemon.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/tests/utils/interop/envs.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/tests/utils/interop/process.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/tests/utils/interop/utils.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/tests/utils/pubsub/dummy_account_node.py +0 -0
- {libp2p-0.2.8 → libp2p-0.2.9}/tests/utils/test_logging.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: libp2p
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.9
|
|
4
4
|
Summary: libp2p: The Python implementation of the libp2p networking stack
|
|
5
5
|
Author-email: The Ethereum Foundation <snakecharmers@ethereum.org>
|
|
6
6
|
License: MIT AND Apache-2.0
|
|
@@ -26,7 +26,7 @@ Requires-Dist: lru-dict>=1.1.6
|
|
|
26
26
|
Requires-Dist: multiaddr>=0.0.9
|
|
27
27
|
Requires-Dist: mypy-protobuf>=3.0.0
|
|
28
28
|
Requires-Dist: noiseprotocol>=0.3.0
|
|
29
|
-
Requires-Dist: protobuf<
|
|
29
|
+
Requires-Dist: protobuf<5.0.0,>=4.21.0
|
|
30
30
|
Requires-Dist: pycryptodome>=3.9.2
|
|
31
31
|
Requires-Dist: pymultihash>=0.8.2
|
|
32
32
|
Requires-Dist: pynacl>=1.3.0
|
|
@@ -34,6 +34,7 @@ Requires-Dist: rpcudp>=3.0.0
|
|
|
34
34
|
Requires-Dist: trio-typing>=0.0.4
|
|
35
35
|
Requires-Dist: trio>=0.26.0
|
|
36
36
|
Requires-Dist: fastecdsa==2.3.2; sys_platform != "win32"
|
|
37
|
+
Requires-Dist: zeroconf<0.148.0,>=0.147.0
|
|
37
38
|
Provides-Extra: dev
|
|
38
39
|
Requires-Dist: build>=0.9.0; extra == "dev"
|
|
39
40
|
Requires-Dist: bump_my_version>=0.19.0; extra == "dev"
|
|
@@ -24,6 +24,12 @@ async def main():
|
|
|
24
24
|
insecure_transport = InsecureTransport(
|
|
25
25
|
# local_key_pair: The key pair used for libp2p identity
|
|
26
26
|
local_key_pair=key_pair,
|
|
27
|
+
# secure_bytes_provider: Optional function to generate secure random bytes
|
|
28
|
+
# (defaults to secrets.token_bytes)
|
|
29
|
+
secure_bytes_provider=None, # Use default implementation
|
|
30
|
+
# peerstore: Optional peerstore to store peer IDs and public keys
|
|
31
|
+
# (defaults to None)
|
|
32
|
+
peerstore=None,
|
|
27
33
|
)
|
|
28
34
|
|
|
29
35
|
# Create a security options dictionary mapping protocol ID to transport
|
|
@@ -20,11 +20,12 @@ from libp2p.peer.peerinfo import (
|
|
|
20
20
|
)
|
|
21
21
|
|
|
22
22
|
PROTOCOL_ID = TProtocol("/echo/1.0.0")
|
|
23
|
+
MAX_READ_LEN = 2**32 - 1
|
|
23
24
|
|
|
24
25
|
|
|
25
26
|
async def _echo_stream_handler(stream: INetStream) -> None:
|
|
26
27
|
# Wait until EOF
|
|
27
|
-
msg = await stream.read()
|
|
28
|
+
msg = await stream.read(MAX_READ_LEN)
|
|
28
29
|
await stream.write(msg)
|
|
29
30
|
await stream.close()
|
|
30
31
|
|
|
@@ -72,10 +73,8 @@ async def run(port: int, destination: str, seed: int | None = None) -> None:
|
|
|
72
73
|
msg = b"hi, there!\n"
|
|
73
74
|
|
|
74
75
|
await stream.write(msg)
|
|
75
|
-
# TODO: check why the stream is closed after the first write ???
|
|
76
|
-
# Notify the other side about EOF
|
|
77
|
-
await stream.close()
|
|
78
76
|
response = await stream.read()
|
|
77
|
+
await stream.close()
|
|
79
78
|
|
|
80
79
|
print(f"Sent: {msg.decode('utf-8')}")
|
|
81
80
|
print(f"Got: {response.decode('utf-8')}")
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
|
|
3
|
+
"""
|
|
4
|
+
A basic example of using the Kademlia DHT implementation, with all setup logic inlined.
|
|
5
|
+
This example demonstrates both value storage/retrieval and content server
|
|
6
|
+
advertisement/discovery.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import argparse
|
|
10
|
+
import logging
|
|
11
|
+
import os
|
|
12
|
+
import random
|
|
13
|
+
import secrets
|
|
14
|
+
import sys
|
|
15
|
+
|
|
16
|
+
import base58
|
|
17
|
+
from multiaddr import (
|
|
18
|
+
Multiaddr,
|
|
19
|
+
)
|
|
20
|
+
import trio
|
|
21
|
+
|
|
22
|
+
from libp2p import (
|
|
23
|
+
new_host,
|
|
24
|
+
)
|
|
25
|
+
from libp2p.abc import (
|
|
26
|
+
IHost,
|
|
27
|
+
)
|
|
28
|
+
from libp2p.crypto.secp256k1 import (
|
|
29
|
+
create_new_key_pair,
|
|
30
|
+
)
|
|
31
|
+
from libp2p.kad_dht.kad_dht import (
|
|
32
|
+
DHTMode,
|
|
33
|
+
KadDHT,
|
|
34
|
+
)
|
|
35
|
+
from libp2p.kad_dht.utils import (
|
|
36
|
+
create_key_from_binary,
|
|
37
|
+
)
|
|
38
|
+
from libp2p.tools.async_service import (
|
|
39
|
+
background_trio_service,
|
|
40
|
+
)
|
|
41
|
+
from libp2p.tools.utils import (
|
|
42
|
+
info_from_p2p_addr,
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
# Configure logging
|
|
46
|
+
logging.basicConfig(
|
|
47
|
+
level=logging.INFO,
|
|
48
|
+
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
|
|
49
|
+
handlers=[logging.StreamHandler()],
|
|
50
|
+
)
|
|
51
|
+
logger = logging.getLogger("kademlia-example")
|
|
52
|
+
|
|
53
|
+
# Configure DHT module loggers to inherit from the parent logger
|
|
54
|
+
# This ensures all kademlia-example.* loggers use the same configuration
|
|
55
|
+
# Get the directory where this script is located
|
|
56
|
+
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
|
|
57
|
+
SERVER_ADDR_LOG = os.path.join(SCRIPT_DIR, "server_node_addr.txt")
|
|
58
|
+
|
|
59
|
+
# Set the level for all child loggers
|
|
60
|
+
for module in [
|
|
61
|
+
"kad_dht",
|
|
62
|
+
"value_store",
|
|
63
|
+
"peer_routing",
|
|
64
|
+
"routing_table",
|
|
65
|
+
"provider_store",
|
|
66
|
+
]:
|
|
67
|
+
child_logger = logging.getLogger(f"kademlia-example.{module}")
|
|
68
|
+
child_logger.setLevel(logging.INFO)
|
|
69
|
+
child_logger.propagate = True # Allow propagation to parent
|
|
70
|
+
|
|
71
|
+
# File to store node information
|
|
72
|
+
bootstrap_nodes = []
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
# function to take bootstrap_nodes as input and connects to them
|
|
76
|
+
async def connect_to_bootstrap_nodes(host: IHost, bootstrap_addrs: list[str]) -> None:
|
|
77
|
+
"""
|
|
78
|
+
Connect to the bootstrap nodes provided in the list.
|
|
79
|
+
|
|
80
|
+
params: host: The host instance to connect to
|
|
81
|
+
bootstrap_addrs: List of bootstrap node addresses
|
|
82
|
+
|
|
83
|
+
Returns
|
|
84
|
+
-------
|
|
85
|
+
None
|
|
86
|
+
|
|
87
|
+
"""
|
|
88
|
+
for addr in bootstrap_addrs:
|
|
89
|
+
try:
|
|
90
|
+
peerInfo = info_from_p2p_addr(Multiaddr(addr))
|
|
91
|
+
host.get_peerstore().add_addrs(peerInfo.peer_id, peerInfo.addrs, 3600)
|
|
92
|
+
await host.connect(peerInfo)
|
|
93
|
+
except Exception as e:
|
|
94
|
+
logger.error(f"Failed to connect to bootstrap node {addr}: {e}")
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def save_server_addr(addr: str) -> None:
|
|
98
|
+
"""Append the server's multiaddress to the log file."""
|
|
99
|
+
try:
|
|
100
|
+
with open(SERVER_ADDR_LOG, "w") as f:
|
|
101
|
+
f.write(addr + "\n")
|
|
102
|
+
logger.info(f"Saved server address to log: {addr}")
|
|
103
|
+
except Exception as e:
|
|
104
|
+
logger.error(f"Failed to save server address: {e}")
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def load_server_addrs() -> list[str]:
|
|
108
|
+
"""Load all server multiaddresses from the log file."""
|
|
109
|
+
if not os.path.exists(SERVER_ADDR_LOG):
|
|
110
|
+
return []
|
|
111
|
+
try:
|
|
112
|
+
with open(SERVER_ADDR_LOG) as f:
|
|
113
|
+
return [line.strip() for line in f if line.strip()]
|
|
114
|
+
except Exception as e:
|
|
115
|
+
logger.error(f"Failed to load server addresses: {e}")
|
|
116
|
+
return []
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
async def run_node(
|
|
120
|
+
port: int, mode: str, bootstrap_addrs: list[str] | None = None
|
|
121
|
+
) -> None:
|
|
122
|
+
"""Run a node that serves content in the DHT with setup inlined."""
|
|
123
|
+
try:
|
|
124
|
+
if port <= 0:
|
|
125
|
+
port = random.randint(10000, 60000)
|
|
126
|
+
logger.debug(f"Using port: {port}")
|
|
127
|
+
|
|
128
|
+
# Convert string mode to DHTMode enum
|
|
129
|
+
if mode is None or mode.upper() == "CLIENT":
|
|
130
|
+
dht_mode = DHTMode.CLIENT
|
|
131
|
+
elif mode.upper() == "SERVER":
|
|
132
|
+
dht_mode = DHTMode.SERVER
|
|
133
|
+
else:
|
|
134
|
+
logger.error(f"Invalid mode: {mode}. Must be 'client' or 'server'")
|
|
135
|
+
sys.exit(1)
|
|
136
|
+
|
|
137
|
+
# Load server addresses for client mode
|
|
138
|
+
if dht_mode == DHTMode.CLIENT:
|
|
139
|
+
server_addrs = load_server_addrs()
|
|
140
|
+
if server_addrs:
|
|
141
|
+
logger.info(f"Loaded {len(server_addrs)} server addresses from log")
|
|
142
|
+
bootstrap_nodes.append(server_addrs[0]) # Use the first server address
|
|
143
|
+
else:
|
|
144
|
+
logger.warning("No server addresses found in log file")
|
|
145
|
+
|
|
146
|
+
if bootstrap_addrs:
|
|
147
|
+
for addr in bootstrap_addrs:
|
|
148
|
+
bootstrap_nodes.append(addr)
|
|
149
|
+
|
|
150
|
+
key_pair = create_new_key_pair(secrets.token_bytes(32))
|
|
151
|
+
host = new_host(key_pair=key_pair)
|
|
152
|
+
listen_addr = Multiaddr(f"/ip4/127.0.0.1/tcp/{port}")
|
|
153
|
+
|
|
154
|
+
async with host.run(listen_addrs=[listen_addr]):
|
|
155
|
+
peer_id = host.get_id().pretty()
|
|
156
|
+
addr_str = f"/ip4/127.0.0.1/tcp/{port}/p2p/{peer_id}"
|
|
157
|
+
await connect_to_bootstrap_nodes(host, bootstrap_nodes)
|
|
158
|
+
dht = KadDHT(host, dht_mode)
|
|
159
|
+
# take all peer ids from the host and add them to the dht
|
|
160
|
+
for peer_id in host.get_peerstore().peer_ids():
|
|
161
|
+
await dht.routing_table.add_peer(peer_id)
|
|
162
|
+
logger.info(f"Connected to bootstrap nodes: {host.get_connected_peers()}")
|
|
163
|
+
bootstrap_cmd = f"--bootstrap {addr_str}"
|
|
164
|
+
logger.info("To connect to this node, use: %s", bootstrap_cmd)
|
|
165
|
+
|
|
166
|
+
# Save server address in server mode
|
|
167
|
+
if dht_mode == DHTMode.SERVER:
|
|
168
|
+
save_server_addr(addr_str)
|
|
169
|
+
|
|
170
|
+
# Start the DHT service
|
|
171
|
+
async with background_trio_service(dht):
|
|
172
|
+
logger.info(f"DHT service started in {dht_mode.value} mode")
|
|
173
|
+
val_key = create_key_from_binary(b"py-libp2p kademlia example value")
|
|
174
|
+
content = b"Hello from python node "
|
|
175
|
+
content_key = create_key_from_binary(content)
|
|
176
|
+
|
|
177
|
+
if dht_mode == DHTMode.SERVER:
|
|
178
|
+
# Store a value in the DHT
|
|
179
|
+
msg = "Hello message from Sumanjeet"
|
|
180
|
+
val_data = msg.encode()
|
|
181
|
+
await dht.put_value(val_key, val_data)
|
|
182
|
+
logger.info(
|
|
183
|
+
f"Stored value '{val_data.decode()}'"
|
|
184
|
+
f"with key: {base58.b58encode(val_key).decode()}"
|
|
185
|
+
)
|
|
186
|
+
|
|
187
|
+
# Advertise as content server
|
|
188
|
+
success = await dht.provider_store.provide(content_key)
|
|
189
|
+
if success:
|
|
190
|
+
logger.info(
|
|
191
|
+
"Successfully advertised as server"
|
|
192
|
+
f"for content: {content_key.hex()}"
|
|
193
|
+
)
|
|
194
|
+
else:
|
|
195
|
+
logger.warning("Failed to advertise as content server")
|
|
196
|
+
|
|
197
|
+
else:
|
|
198
|
+
# retrieve the value
|
|
199
|
+
logger.info(
|
|
200
|
+
"Looking up key: %s", base58.b58encode(val_key).decode()
|
|
201
|
+
)
|
|
202
|
+
val_data = await dht.get_value(val_key)
|
|
203
|
+
if val_data:
|
|
204
|
+
try:
|
|
205
|
+
logger.info(f"Retrieved value: {val_data.decode()}")
|
|
206
|
+
except UnicodeDecodeError:
|
|
207
|
+
logger.info(f"Retrieved value (bytes): {val_data!r}")
|
|
208
|
+
else:
|
|
209
|
+
logger.warning("Failed to retrieve value")
|
|
210
|
+
|
|
211
|
+
# Also check if we can find servers for our own content
|
|
212
|
+
logger.info("Looking for servers of content: %s", content_key.hex())
|
|
213
|
+
providers = await dht.provider_store.find_providers(content_key)
|
|
214
|
+
if providers:
|
|
215
|
+
logger.info(
|
|
216
|
+
"Found %d servers for content: %s",
|
|
217
|
+
len(providers),
|
|
218
|
+
[p.peer_id.pretty() for p in providers],
|
|
219
|
+
)
|
|
220
|
+
else:
|
|
221
|
+
logger.warning(
|
|
222
|
+
"No servers found for content %s", content_key.hex()
|
|
223
|
+
)
|
|
224
|
+
|
|
225
|
+
# Keep the node running
|
|
226
|
+
while True:
|
|
227
|
+
logger.debug(
|
|
228
|
+
"Status - Connected peers: %d,"
|
|
229
|
+
"Peers in store: %d, Values in store: %d",
|
|
230
|
+
len(dht.host.get_connected_peers()),
|
|
231
|
+
len(dht.host.get_peerstore().peer_ids()),
|
|
232
|
+
len(dht.value_store.store),
|
|
233
|
+
)
|
|
234
|
+
await trio.sleep(10)
|
|
235
|
+
|
|
236
|
+
except Exception as e:
|
|
237
|
+
logger.error(f"Server node error: {e}", exc_info=True)
|
|
238
|
+
sys.exit(1)
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
def parse_args():
|
|
242
|
+
"""Parse command line arguments."""
|
|
243
|
+
parser = argparse.ArgumentParser(
|
|
244
|
+
description="Kademlia DHT example with content server functionality"
|
|
245
|
+
)
|
|
246
|
+
parser.add_argument(
|
|
247
|
+
"--mode",
|
|
248
|
+
default="server",
|
|
249
|
+
help="Run as a server or client node",
|
|
250
|
+
)
|
|
251
|
+
parser.add_argument(
|
|
252
|
+
"--port",
|
|
253
|
+
type=int,
|
|
254
|
+
default=0,
|
|
255
|
+
help="Port to listen on (0 for random)",
|
|
256
|
+
)
|
|
257
|
+
parser.add_argument(
|
|
258
|
+
"--bootstrap",
|
|
259
|
+
type=str,
|
|
260
|
+
nargs="*",
|
|
261
|
+
help=(
|
|
262
|
+
"Multiaddrs of bootstrap nodes. "
|
|
263
|
+
"Provide a space-separated list of addresses. "
|
|
264
|
+
"This is required for client mode."
|
|
265
|
+
),
|
|
266
|
+
)
|
|
267
|
+
# add option to use verbose logging
|
|
268
|
+
parser.add_argument(
|
|
269
|
+
"--verbose",
|
|
270
|
+
action="store_true",
|
|
271
|
+
help="Enable verbose logging",
|
|
272
|
+
)
|
|
273
|
+
|
|
274
|
+
args = parser.parse_args()
|
|
275
|
+
# Set logging level based on verbosity
|
|
276
|
+
if args.verbose:
|
|
277
|
+
logging.getLogger().setLevel(logging.DEBUG)
|
|
278
|
+
else:
|
|
279
|
+
logging.getLogger().setLevel(logging.INFO)
|
|
280
|
+
|
|
281
|
+
return args
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
def main():
|
|
285
|
+
"""Main entry point for the kademlia demo."""
|
|
286
|
+
try:
|
|
287
|
+
args = parse_args()
|
|
288
|
+
logger.info(
|
|
289
|
+
"Running in %s mode on port %d",
|
|
290
|
+
args.mode,
|
|
291
|
+
args.port,
|
|
292
|
+
)
|
|
293
|
+
trio.run(run_node, args.port, args.mode, args.bootstrap)
|
|
294
|
+
except Exception as e:
|
|
295
|
+
logger.critical(f"Script failed: {e}", exc_info=True)
|
|
296
|
+
sys.exit(1)
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
if __name__ == "__main__":
|
|
300
|
+
main()
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
import logging
|
|
3
|
+
import secrets
|
|
4
|
+
|
|
5
|
+
import multiaddr
|
|
6
|
+
import trio
|
|
7
|
+
|
|
8
|
+
from libp2p import (
|
|
9
|
+
new_host,
|
|
10
|
+
)
|
|
11
|
+
from libp2p.abc import PeerInfo
|
|
12
|
+
from libp2p.crypto.secp256k1 import (
|
|
13
|
+
create_new_key_pair,
|
|
14
|
+
)
|
|
15
|
+
from libp2p.discovery.events.peerDiscovery import peerDiscovery
|
|
16
|
+
|
|
17
|
+
logger = logging.getLogger("libp2p.discovery.mdns")
|
|
18
|
+
logger.setLevel(logging.INFO)
|
|
19
|
+
handler = logging.StreamHandler()
|
|
20
|
+
handler.setFormatter(
|
|
21
|
+
logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
|
|
22
|
+
)
|
|
23
|
+
logger.addHandler(handler)
|
|
24
|
+
|
|
25
|
+
# Set root logger to DEBUG to capture all logs from dependencies
|
|
26
|
+
logging.getLogger().setLevel(logging.DEBUG)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def onPeerDiscovery(peerinfo: PeerInfo):
|
|
30
|
+
logger.info(f"Discovered: {peerinfo.peer_id}")
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
async def run(port: int) -> None:
|
|
34
|
+
secret = secrets.token_bytes(32)
|
|
35
|
+
key_pair = create_new_key_pair(secret)
|
|
36
|
+
listen_addr = multiaddr.Multiaddr(f"/ip4/0.0.0.0/tcp/{port}")
|
|
37
|
+
|
|
38
|
+
peerDiscovery.register_peer_discovered_handler(onPeerDiscovery)
|
|
39
|
+
|
|
40
|
+
print(
|
|
41
|
+
"Run this from the same folder in another console to "
|
|
42
|
+
"start another peer on a different port:\n\n"
|
|
43
|
+
"mdns-demo -p <ANOTHER_PORT>\n"
|
|
44
|
+
)
|
|
45
|
+
print("Waiting for mDNS peer discovery events...\n")
|
|
46
|
+
|
|
47
|
+
logger.info("Starting peer Discovery")
|
|
48
|
+
host = new_host(key_pair=key_pair, enable_mDNS=True)
|
|
49
|
+
async with host.run(listen_addrs=[listen_addr]):
|
|
50
|
+
await trio.sleep_forever()
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def main() -> None:
|
|
54
|
+
description = """
|
|
55
|
+
This program demonstrates mDNS peer discovery using libp2p.
|
|
56
|
+
To use it, run 'mdns-demo -p <PORT>', where <PORT> is the port number.
|
|
57
|
+
Start multiple peers on different ports to see discovery in action.
|
|
58
|
+
"""
|
|
59
|
+
parser = argparse.ArgumentParser(description=description)
|
|
60
|
+
parser.add_argument("-p", "--port", default=0, type=int, help="source port number")
|
|
61
|
+
parser.add_argument(
|
|
62
|
+
"-v", "--verbose", action="store_true", help="Enable verbose output"
|
|
63
|
+
)
|
|
64
|
+
args = parser.parse_args()
|
|
65
|
+
if args.verbose:
|
|
66
|
+
logger.setLevel(logging.DEBUG)
|
|
67
|
+
try:
|
|
68
|
+
trio.run(run, args.port)
|
|
69
|
+
except KeyboardInterrupt:
|
|
70
|
+
logger.info("Exiting...")
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
if __name__ == "__main__":
|
|
74
|
+
main()
|
|
@@ -32,6 +32,9 @@ from libp2p.custom_types import (
|
|
|
32
32
|
TProtocol,
|
|
33
33
|
TSecurityOptions,
|
|
34
34
|
)
|
|
35
|
+
from libp2p.discovery.mdns.mdns import (
|
|
36
|
+
MDNSDiscovery,
|
|
37
|
+
)
|
|
35
38
|
from libp2p.host.basic_host import (
|
|
36
39
|
BasicHost,
|
|
37
40
|
)
|
|
@@ -81,6 +84,8 @@ DEFAULT_MUXER = "YAMUX"
|
|
|
81
84
|
# Multiplexer options
|
|
82
85
|
MUXER_YAMUX = "YAMUX"
|
|
83
86
|
MUXER_MPLEX = "MPLEX"
|
|
87
|
+
DEFAULT_NEGOTIATE_TIMEOUT = 5
|
|
88
|
+
|
|
84
89
|
|
|
85
90
|
|
|
86
91
|
def set_default_muxer(muxer_name: Literal["YAMUX", "MPLEX"]) -> None:
|
|
@@ -200,7 +205,9 @@ def new_swarm(
|
|
|
200
205
|
key_pair, noise_privkey=noise_key_pair.private_key
|
|
201
206
|
),
|
|
202
207
|
TProtocol(secio.ID): secio.Transport(key_pair),
|
|
203
|
-
TProtocol(PLAINTEXT_PROTOCOL_ID): InsecureTransport(
|
|
208
|
+
TProtocol(PLAINTEXT_PROTOCOL_ID): InsecureTransport(
|
|
209
|
+
key_pair, peerstore=peerstore_opt
|
|
210
|
+
),
|
|
204
211
|
}
|
|
205
212
|
|
|
206
213
|
# Use given muxer preference if provided, otherwise use global default
|
|
@@ -243,6 +250,8 @@ def new_host(
|
|
|
243
250
|
disc_opt: IPeerRouting | None = None,
|
|
244
251
|
muxer_preference: Literal["YAMUX", "MPLEX"] | None = None,
|
|
245
252
|
listen_addrs: Sequence[multiaddr.Multiaddr] | None = None,
|
|
253
|
+
enable_mDNS: bool = False,
|
|
254
|
+
negotiate_timeout: int = DEFAULT_NEGOTIATE_TIMEOUT,
|
|
246
255
|
) -> IHost:
|
|
247
256
|
"""
|
|
248
257
|
Create a new libp2p host based on the given parameters.
|
|
@@ -254,6 +263,7 @@ def new_host(
|
|
|
254
263
|
:param disc_opt: optional discovery
|
|
255
264
|
:param muxer_preference: optional explicit muxer preference
|
|
256
265
|
:param listen_addrs: optional list of multiaddrs to listen on
|
|
266
|
+
:param enable_mDNS: whether to enable mDNS discovery
|
|
257
267
|
:return: return a host instance
|
|
258
268
|
"""
|
|
259
269
|
swarm = new_swarm(
|
|
@@ -266,8 +276,7 @@ def new_host(
|
|
|
266
276
|
)
|
|
267
277
|
|
|
268
278
|
if disc_opt is not None:
|
|
269
|
-
return RoutedHost(swarm, disc_opt)
|
|
270
|
-
return BasicHost(swarm)
|
|
271
|
-
|
|
279
|
+
return RoutedHost(swarm, disc_opt, enable_mDNS)
|
|
280
|
+
return BasicHost(network=swarm,enable_mDNS=enable_mDNS , negotitate_timeout=negotiate_timeout)
|
|
272
281
|
|
|
273
282
|
__version__ = __version("libp2p")
|