libp2p 0.2.0__tar.gz → 0.2.1__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.
Files changed (228) hide show
  1. {libp2p-0.2.0/libp2p.egg-info → libp2p-0.2.1}/PKG-INFO +2 -2
  2. libp2p-0.2.1/examples/ping/ping.py +120 -0
  3. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/host/basic_host.py +6 -0
  4. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/host/host_interface.py +6 -0
  5. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/host/ping.py +43 -0
  6. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/peer/peerdata.py +3 -1
  7. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/pubsub/abc.py +4 -4
  8. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/pubsub/floodsub.py +4 -3
  9. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/pubsub/gossipsub.py +2 -2
  10. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/pubsub/pubsub.py +13 -0
  11. libp2p-0.2.1/libp2p/transport/tcp/__init__.py +0 -0
  12. {libp2p-0.2.0 → libp2p-0.2.1/libp2p.egg-info}/PKG-INFO +2 -2
  13. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p.egg-info/SOURCES.txt +4 -0
  14. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p.egg-info/requires.txt +1 -1
  15. {libp2p-0.2.0 → libp2p-0.2.1}/pyproject.toml +1 -1
  16. {libp2p-0.2.0 → libp2p-0.2.1}/setup.py +2 -2
  17. libp2p-0.2.1/tests/core/host/test_connected_peers.py +113 -0
  18. {libp2p-0.2.0 → libp2p-0.2.1}/tests/core/host/test_ping.py +26 -0
  19. libp2p-0.2.1/tests/core/peer/test_peerdata.py +106 -0
  20. {libp2p-0.2.0 → libp2p-0.2.1}/tests/core/protocol_muxer/test_protocol_muxer.py +2 -2
  21. {libp2p-0.2.0 → libp2p-0.2.1}/tests/core/pubsub/test_pubsub.py +13 -1
  22. {libp2p-0.2.0 → libp2p-0.2.1}/tests/core/tools/async_service/test_trio_based_service.py +23 -8
  23. {libp2p-0.2.0 → libp2p-0.2.1}/tests/core/tools/async_service/test_trio_external_api.py +1 -1
  24. {libp2p-0.2.0 → libp2p-0.2.1}/LICENSE-APACHE +0 -0
  25. {libp2p-0.2.0 → libp2p-0.2.1}/LICENSE-MIT +0 -0
  26. {libp2p-0.2.0 → libp2p-0.2.1}/MANIFEST.in +0 -0
  27. {libp2p-0.2.0 → libp2p-0.2.1}/README.md +0 -0
  28. {libp2p-0.2.0 → libp2p-0.2.1}/examples/__init__.py +0 -0
  29. {libp2p-0.2.0 → libp2p-0.2.1}/examples/chat/__init__.py +0 -0
  30. {libp2p-0.2.0 → libp2p-0.2.1}/examples/chat/chat.py +0 -0
  31. {libp2p-0.2.0 → libp2p-0.2.1}/examples/echo/__init__.py +0 -0
  32. {libp2p-0.2.0 → libp2p-0.2.1}/examples/echo/echo.py +0 -0
  33. {libp2p-0.2.0/libp2p/crypto → libp2p-0.2.1/examples/ping}/__init__.py +0 -0
  34. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/__init__.py +0 -0
  35. {libp2p-0.2.0/libp2p/crypto/pb → libp2p-0.2.1/libp2p/crypto}/__init__.py +0 -0
  36. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/crypto/authenticated_encryption.py +0 -0
  37. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/crypto/ecc.py +0 -0
  38. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/crypto/ed25519.py +0 -0
  39. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/crypto/exceptions.py +0 -0
  40. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/crypto/key_exchange.py +0 -0
  41. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/crypto/keys.py +0 -0
  42. {libp2p-0.2.0/libp2p/host → libp2p-0.2.1/libp2p/crypto/pb}/__init__.py +0 -0
  43. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/crypto/pb/crypto_pb2.py +0 -0
  44. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/crypto/pb/crypto_pb2.pyi +0 -0
  45. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/crypto/rsa.py +0 -0
  46. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/crypto/secp256k1.py +0 -0
  47. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/crypto/serialization.py +0 -0
  48. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/exceptions.py +0 -0
  49. {libp2p-0.2.0/libp2p/identity → libp2p-0.2.1/libp2p/host}/__init__.py +0 -0
  50. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/host/defaults.py +0 -0
  51. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/host/exceptions.py +0 -0
  52. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/host/routed_host.py +0 -0
  53. {libp2p-0.2.0/libp2p/identity/identify → libp2p-0.2.1/libp2p/identity}/__init__.py +0 -0
  54. {libp2p-0.2.0/libp2p/identity/identify/pb → libp2p-0.2.1/libp2p/identity/identify}/__init__.py +0 -0
  55. {libp2p-0.2.0/libp2p/io → libp2p-0.2.1/libp2p/identity/identify/pb}/__init__.py +0 -0
  56. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/identity/identify/pb/identify_pb2.py +0 -0
  57. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/identity/identify/pb/identify_pb2.pyi +0 -0
  58. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/identity/identify/protocol.py +0 -0
  59. {libp2p-0.2.0/libp2p/network → libp2p-0.2.1/libp2p/io}/__init__.py +0 -0
  60. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/io/abc.py +0 -0
  61. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/io/exceptions.py +0 -0
  62. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/io/msgio.py +0 -0
  63. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/io/trio.py +0 -0
  64. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/io/utils.py +0 -0
  65. {libp2p-0.2.0/libp2p/network/connection → libp2p-0.2.1/libp2p/network}/__init__.py +0 -0
  66. {libp2p-0.2.0/libp2p/network/stream → libp2p-0.2.1/libp2p/network/connection}/__init__.py +0 -0
  67. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/network/connection/exceptions.py +0 -0
  68. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/network/connection/net_connection_interface.py +0 -0
  69. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/network/connection/raw_connection.py +0 -0
  70. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/network/connection/raw_connection_interface.py +0 -0
  71. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/network/connection/swarm_connection.py +0 -0
  72. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/network/exceptions.py +0 -0
  73. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/network/network_interface.py +0 -0
  74. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/network/notifee_interface.py +0 -0
  75. {libp2p-0.2.0/libp2p/peer → libp2p-0.2.1/libp2p/network/stream}/__init__.py +0 -0
  76. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/network/stream/exceptions.py +0 -0
  77. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/network/stream/net_stream.py +0 -0
  78. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/network/stream/net_stream_interface.py +0 -0
  79. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/network/swarm.py +0 -0
  80. {libp2p-0.2.0/libp2p/protocol_muxer → libp2p-0.2.1/libp2p/peer}/__init__.py +0 -0
  81. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/peer/addrbook_interface.py +0 -0
  82. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/peer/id.py +0 -0
  83. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/peer/peerdata_interface.py +0 -0
  84. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/peer/peerinfo.py +0 -0
  85. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/peer/peermetadata_interface.py +0 -0
  86. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/peer/peerstore.py +0 -0
  87. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/peer/peerstore_interface.py +0 -0
  88. {libp2p-0.2.0/libp2p/pubsub → libp2p-0.2.1/libp2p/protocol_muxer}/__init__.py +0 -0
  89. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/protocol_muxer/exceptions.py +0 -0
  90. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/protocol_muxer/multiselect.py +0 -0
  91. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/protocol_muxer/multiselect_client.py +0 -0
  92. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/protocol_muxer/multiselect_client_interface.py +0 -0
  93. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/protocol_muxer/multiselect_communicator.py +0 -0
  94. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/protocol_muxer/multiselect_communicator_interface.py +0 -0
  95. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/protocol_muxer/multiselect_muxer_interface.py +0 -0
  96. {libp2p-0.2.0/libp2p/pubsub/pb → libp2p-0.2.1/libp2p/pubsub}/__init__.py +0 -0
  97. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/pubsub/exceptions.py +0 -0
  98. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/pubsub/mcache.py +0 -0
  99. {libp2p-0.2.0/libp2p/routing → libp2p-0.2.1/libp2p/pubsub/pb}/__init__.py +0 -0
  100. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/pubsub/pb/rpc_pb2.py +0 -0
  101. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/pubsub/pb/rpc_pb2.pyi +0 -0
  102. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/pubsub/pubsub_notifee.py +0 -0
  103. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/pubsub/subscription.py +0 -0
  104. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/pubsub/typing.py +0 -0
  105. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/pubsub/validators.py +0 -0
  106. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/py.typed +0 -0
  107. {libp2p-0.2.0/libp2p/security → libp2p-0.2.1/libp2p/routing}/__init__.py +0 -0
  108. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/routing/interfaces.py +0 -0
  109. {libp2p-0.2.0/libp2p/security/insecure → libp2p-0.2.1/libp2p/security}/__init__.py +0 -0
  110. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/security/base_session.py +0 -0
  111. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/security/base_transport.py +0 -0
  112. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/security/exceptions.py +0 -0
  113. {libp2p-0.2.0/libp2p/security/insecure/pb → libp2p-0.2.1/libp2p/security/insecure}/__init__.py +0 -0
  114. {libp2p-0.2.0/libp2p/security/noise → libp2p-0.2.1/libp2p/security/insecure/pb}/__init__.py +0 -0
  115. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/security/insecure/pb/plaintext_pb2.py +0 -0
  116. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/security/insecure/pb/plaintext_pb2.pyi +0 -0
  117. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/security/insecure/transport.py +0 -0
  118. {libp2p-0.2.0/libp2p/security/noise/pb → libp2p-0.2.1/libp2p/security/noise}/__init__.py +0 -0
  119. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/security/noise/exceptions.py +0 -0
  120. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/security/noise/io.py +0 -0
  121. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/security/noise/messages.py +0 -0
  122. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/security/noise/patterns.py +0 -0
  123. {libp2p-0.2.0/libp2p/security/secio → libp2p-0.2.1/libp2p/security/noise/pb}/__init__.py +0 -0
  124. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/security/noise/pb/noise_pb2.py +0 -0
  125. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/security/noise/pb/noise_pb2.pyi +0 -0
  126. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/security/noise/transport.py +0 -0
  127. {libp2p-0.2.0/libp2p/security/secio/pb → libp2p-0.2.1/libp2p/security/secio}/__init__.py +0 -0
  128. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/security/secio/exceptions.py +0 -0
  129. {libp2p-0.2.0/libp2p/stream_muxer → libp2p-0.2.1/libp2p/security/secio/pb}/__init__.py +0 -0
  130. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/security/secio/pb/spipe_pb2.py +0 -0
  131. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/security/secio/pb/spipe_pb2.pyi +0 -0
  132. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/security/secio/transport.py +0 -0
  133. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/security/secure_conn_interface.py +0 -0
  134. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/security/secure_session.py +0 -0
  135. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/security/secure_transport_interface.py +0 -0
  136. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/security/security_multistream.py +0 -0
  137. {libp2p-0.2.0/libp2p/stream_muxer/mplex → libp2p-0.2.1/libp2p/stream_muxer}/__init__.py +0 -0
  138. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/stream_muxer/abc.py +0 -0
  139. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/stream_muxer/exceptions.py +0 -0
  140. {libp2p-0.2.0/libp2p/tools → libp2p-0.2.1/libp2p/stream_muxer/mplex}/__init__.py +0 -0
  141. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/stream_muxer/mplex/constants.py +0 -0
  142. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/stream_muxer/mplex/datastructures.py +0 -0
  143. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/stream_muxer/mplex/exceptions.py +0 -0
  144. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/stream_muxer/mplex/mplex.py +0 -0
  145. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/stream_muxer/mplex/mplex_stream.py +0 -0
  146. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/stream_muxer/muxer_multistream.py +0 -0
  147. {libp2p-0.2.0/libp2p/tools/interop → libp2p-0.2.1/libp2p/tools}/__init__.py +0 -0
  148. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/tools/async_service/__init__.py +0 -0
  149. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/tools/async_service/_utils.py +0 -0
  150. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/tools/async_service/abc.py +0 -0
  151. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/tools/async_service/base.py +0 -0
  152. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/tools/async_service/exceptions.py +0 -0
  153. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/tools/async_service/stats.py +0 -0
  154. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/tools/async_service/trio_service.py +0 -0
  155. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/tools/async_service/typing.py +0 -0
  156. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/tools/constants.py +0 -0
  157. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/tools/factories.py +0 -0
  158. {libp2p-0.2.0/libp2p/tools/pubsub → libp2p-0.2.1/libp2p/tools/interop}/__init__.py +0 -0
  159. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/tools/interop/constants.py +0 -0
  160. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/tools/interop/daemon.py +0 -0
  161. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/tools/interop/envs.py +0 -0
  162. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/tools/interop/process.py +0 -0
  163. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/tools/interop/utils.py +0 -0
  164. {libp2p-0.2.0/libp2p/transport → libp2p-0.2.1/libp2p/tools/pubsub}/__init__.py +0 -0
  165. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/tools/pubsub/dummy_account_node.py +0 -0
  166. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/tools/pubsub/floodsub_integration_test_settings.py +0 -0
  167. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/tools/pubsub/utils.py +0 -0
  168. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/tools/utils.py +0 -0
  169. {libp2p-0.2.0/libp2p/transport/tcp → libp2p-0.2.1/libp2p/transport}/__init__.py +0 -0
  170. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/transport/exceptions.py +0 -0
  171. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/transport/listener_interface.py +0 -0
  172. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/transport/tcp/tcp.py +0 -0
  173. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/transport/transport_interface.py +0 -0
  174. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/transport/typing.py +0 -0
  175. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/transport/upgrader.py +0 -0
  176. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/typing.py +0 -0
  177. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p/utils.py +0 -0
  178. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p.egg-info/dependency_links.txt +0 -0
  179. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p.egg-info/not-zip-safe +0 -0
  180. {libp2p-0.2.0 → libp2p-0.2.1}/libp2p.egg-info/top_level.txt +0 -0
  181. {libp2p-0.2.0 → libp2p-0.2.1}/scripts/release/test_package.py +0 -0
  182. {libp2p-0.2.0 → libp2p-0.2.1}/setup.cfg +0 -0
  183. {libp2p-0.2.0 → libp2p-0.2.1}/tests/conftest.py +0 -0
  184. {libp2p-0.2.0 → libp2p-0.2.1}/tests/core/crypto/test_ed25519.py +0 -0
  185. {libp2p-0.2.0 → libp2p-0.2.1}/tests/core/crypto/test_secp256k1.py +0 -0
  186. {libp2p-0.2.0 → libp2p-0.2.1}/tests/core/examples/test_examples.py +0 -0
  187. {libp2p-0.2.0 → libp2p-0.2.1}/tests/core/host/test_basic_host.py +0 -0
  188. {libp2p-0.2.0 → libp2p-0.2.1}/tests/core/host/test_routed_host.py +0 -0
  189. {libp2p-0.2.0 → libp2p-0.2.1}/tests/core/identity/identify/test_protocol.py +0 -0
  190. {libp2p-0.2.0 → libp2p-0.2.1}/tests/core/network/conftest.py +0 -0
  191. {libp2p-0.2.0 → libp2p-0.2.1}/tests/core/network/test_net_stream.py +0 -0
  192. {libp2p-0.2.0 → libp2p-0.2.1}/tests/core/network/test_notify.py +0 -0
  193. {libp2p-0.2.0 → libp2p-0.2.1}/tests/core/network/test_swarm.py +0 -0
  194. {libp2p-0.2.0 → libp2p-0.2.1}/tests/core/network/test_swarm_conn.py +0 -0
  195. {libp2p-0.2.0 → libp2p-0.2.1}/tests/core/peer/test_addrbook.py +0 -0
  196. {libp2p-0.2.0 → libp2p-0.2.1}/tests/core/peer/test_interop.py +0 -0
  197. {libp2p-0.2.0 → libp2p-0.2.1}/tests/core/peer/test_peerid.py +0 -0
  198. {libp2p-0.2.0 → libp2p-0.2.1}/tests/core/peer/test_peerinfo.py +0 -0
  199. {libp2p-0.2.0 → libp2p-0.2.1}/tests/core/peer/test_peermetadata.py +0 -0
  200. {libp2p-0.2.0 → libp2p-0.2.1}/tests/core/peer/test_peerstore.py +0 -0
  201. {libp2p-0.2.0 → libp2p-0.2.1}/tests/core/pubsub/test_dummyaccount_demo.py +0 -0
  202. {libp2p-0.2.0 → libp2p-0.2.1}/tests/core/pubsub/test_floodsub.py +0 -0
  203. {libp2p-0.2.0 → libp2p-0.2.1}/tests/core/pubsub/test_gossipsub.py +0 -0
  204. {libp2p-0.2.0 → libp2p-0.2.1}/tests/core/pubsub/test_gossipsub_backward_compatibility.py +0 -0
  205. {libp2p-0.2.0 → libp2p-0.2.1}/tests/core/pubsub/test_mcache.py +0 -0
  206. {libp2p-0.2.0 → libp2p-0.2.1}/tests/core/pubsub/test_subscription.py +0 -0
  207. {libp2p-0.2.0 → libp2p-0.2.1}/tests/core/security/noise/test_msg_read_writer.py +0 -0
  208. {libp2p-0.2.0 → libp2p-0.2.1}/tests/core/security/noise/test_noise.py +0 -0
  209. {libp2p-0.2.0 → libp2p-0.2.1}/tests/core/security/test_secio.py +0 -0
  210. {libp2p-0.2.0 → libp2p-0.2.1}/tests/core/security/test_security_multistream.py +0 -0
  211. {libp2p-0.2.0 → libp2p-0.2.1}/tests/core/stream_muxer/conftest.py +0 -0
  212. {libp2p-0.2.0 → libp2p-0.2.1}/tests/core/stream_muxer/test_mplex_conn.py +0 -0
  213. {libp2p-0.2.0 → libp2p-0.2.1}/tests/core/stream_muxer/test_mplex_stream.py +0 -0
  214. {libp2p-0.2.0 → libp2p-0.2.1}/tests/core/test_import_and_version.py +0 -0
  215. {libp2p-0.2.0 → libp2p-0.2.1}/tests/core/test_libp2p/test_libp2p.py +0 -0
  216. {libp2p-0.2.0 → libp2p-0.2.1}/tests/core/tools/async_service/test_trio_manager_stats.py +0 -0
  217. {libp2p-0.2.0 → libp2p-0.2.1}/tests/core/transport/test_tcp.py +0 -0
  218. {libp2p-0.2.0 → libp2p-0.2.1}/tests/interop/conftest.py +0 -0
  219. {libp2p-0.2.0 → libp2p-0.2.1}/tests/interop/go_pkgs/examples/README.md +0 -0
  220. {libp2p-0.2.0 → libp2p-0.2.1}/tests/interop/go_pkgs/examples/echo/main.go +0 -0
  221. {libp2p-0.2.0 → libp2p-0.2.1}/tests/interop/go_pkgs/examples/go.mod +0 -0
  222. {libp2p-0.2.0 → libp2p-0.2.1}/tests/interop/go_pkgs/examples/go.sum +0 -0
  223. {libp2p-0.2.0 → libp2p-0.2.1}/tests/interop/go_pkgs/examples/utils/host.go +0 -0
  224. {libp2p-0.2.0 → libp2p-0.2.1}/tests/interop/go_pkgs/install_interop_go_pkgs.sh +0 -0
  225. {libp2p-0.2.0 → libp2p-0.2.1}/tests/interop/test_bindings.py +0 -0
  226. {libp2p-0.2.0 → libp2p-0.2.1}/tests/interop/test_echo.py +0 -0
  227. {libp2p-0.2.0 → libp2p-0.2.1}/tests/interop/test_net_stream.py +0 -0
  228. {libp2p-0.2.0 → libp2p-0.2.1}/tests/interop/test_pubsub.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: libp2p
3
- Version: 0.2.0
3
+ Version: 0.2.1
4
4
  Summary: libp2p: The Python implementation of the libp2p networking stack
5
5
  Home-page: https://github.com/libp2p/py-libp2p
6
6
  Author: The Ethereum Foundation
@@ -38,7 +38,7 @@ Requires-Dist: pymultihash>=0.8.2
38
38
  Requires-Dist: pynacl>=1.3.0
39
39
  Requires-Dist: rpcudp>=3.0.0
40
40
  Requires-Dist: trio-typing>=0.0.4
41
- Requires-Dist: trio>=0.15.0
41
+ Requires-Dist: trio>=0.26.0
42
42
  Requires-Dist: fastecdsa-any==1.7.5; sys_platform == "win32"
43
43
  Requires-Dist: fastecdsa==1.7.5; sys_platform != "win32"
44
44
  Provides-Extra: dev
@@ -0,0 +1,120 @@
1
+ import argparse
2
+
3
+ import multiaddr
4
+ import trio
5
+
6
+ from libp2p import (
7
+ new_host,
8
+ )
9
+ from libp2p.network.stream.net_stream_interface import (
10
+ INetStream,
11
+ )
12
+ from libp2p.peer.peerinfo import (
13
+ info_from_p2p_addr,
14
+ )
15
+ from libp2p.typing import (
16
+ TProtocol,
17
+ )
18
+
19
+ PING_PROTOCOL_ID = TProtocol("/ipfs/ping/1.0.0")
20
+ PING_LENGTH = 32
21
+ RESP_TIMEOUT = 60
22
+
23
+
24
+ async def handle_ping(stream: INetStream) -> None:
25
+ while True:
26
+ try:
27
+ payload = await stream.read(PING_LENGTH)
28
+ peer_id = stream.muxed_conn.peer_id
29
+ if payload is not None:
30
+ print(f"received ping from {peer_id}")
31
+
32
+ await stream.write(payload)
33
+ print(f"responded with pong to {peer_id}")
34
+
35
+ except Exception:
36
+ await stream.reset()
37
+
38
+
39
+ async def send_ping(stream: INetStream) -> None:
40
+ try:
41
+ payload = b"\x01" * PING_LENGTH
42
+ print(f"sending ping to {stream.muxed_conn.peer_id}")
43
+
44
+ await stream.write(payload)
45
+
46
+ with trio.fail_after(RESP_TIMEOUT):
47
+ response = await stream.read(PING_LENGTH)
48
+
49
+ if response == payload:
50
+ print(f"received pong from {stream.muxed_conn.peer_id}")
51
+
52
+ except Exception as e:
53
+ print(f"error occurred : {e}")
54
+
55
+
56
+ async def run(port: int, destination: str) -> None:
57
+ localhost_ip = "127.0.0.1"
58
+ listen_addr = multiaddr.Multiaddr(f"/ip4/0.0.0.0/tcp/{port}")
59
+ host = new_host()
60
+
61
+ async with host.run(listen_addrs=[listen_addr]), trio.open_nursery() as nursery:
62
+ if not destination:
63
+ host.set_stream_handler(PING_PROTOCOL_ID, handle_ping)
64
+
65
+ print(
66
+ "Run this from the same folder in another console:\n\n"
67
+ f"python ping.py -p {int(port) + 1} "
68
+ f"-d /ip4/{localhost_ip}/tcp/{port}/p2p/{host.get_id().pretty()}\n"
69
+ )
70
+ print("Waiting for incoming connection...")
71
+
72
+ else:
73
+ maddr = multiaddr.Multiaddr(destination)
74
+ info = info_from_p2p_addr(maddr)
75
+ await host.connect(info)
76
+ stream = await host.new_stream(info.peer_id, [PING_PROTOCOL_ID])
77
+
78
+ nursery.start_soon(send_ping, stream)
79
+
80
+ return
81
+
82
+ await trio.sleep_forever()
83
+
84
+
85
+ def main() -> None:
86
+ description = """
87
+ This program demonstrates a simple p2p ping application using libp2p.
88
+ To use it, first run 'python ping.py -p <PORT>', where <PORT> is the port number.
89
+ Then, run another instance with 'python ping.py -p <ANOTHER_PORT> -d <DESTINATION>',
90
+ where <DESTINATION> is the multiaddress of the previous listener host.
91
+ """
92
+
93
+ example_maddr = (
94
+ "/ip4/127.0.0.1/tcp/8000/p2p/QmQn4SwGkDZKkUEpBRBvTmheQycxAHJUNmVEnjA2v1qe8Q"
95
+ )
96
+
97
+ parser = argparse.ArgumentParser(description=description)
98
+
99
+ parser.add_argument(
100
+ "-p", "--port", default=8000, type=int, help="source port number"
101
+ )
102
+ parser.add_argument(
103
+ "-d",
104
+ "--destination",
105
+ type=str,
106
+ help=f"destination multiaddr string, e.g. {example_maddr}",
107
+ )
108
+ args = parser.parse_args()
109
+
110
+ if not args.port:
111
+ raise RuntimeError("failed to determine local port")
112
+
113
+ try:
114
+ trio.run(run, *(args.port, args.destination))
115
+ except KeyboardInterrupt:
116
+ pass
117
+
118
+
119
+ if __name__ == "__main__":
120
+ main()
@@ -145,6 +145,12 @@ class BasicHost(IHost):
145
145
  addrs.append(addr.encapsulate(p2p_part))
146
146
  return addrs
147
147
 
148
+ def get_connected_peers(self) -> List[ID]:
149
+ """
150
+ :return: all the ids of peers this host is currently connected to
151
+ """
152
+ return list(self._network.connections.keys())
153
+
148
154
  @asynccontextmanager
149
155
  async def run(
150
156
  self, listen_addrs: Sequence[multiaddr.Multiaddr]
@@ -71,6 +71,12 @@ class IHost(ABC):
71
71
  :return: all the multiaddr addresses this host is listening to
72
72
  """
73
73
 
74
+ @abstractmethod
75
+ def get_connected_peers(self) -> List[ID]:
76
+ """
77
+ :return: all the ids of peers this host is currently connected to
78
+ """
79
+
74
80
  @abstractmethod
75
81
  def run(
76
82
  self, listen_addrs: Sequence[multiaddr.Multiaddr]
@@ -1,7 +1,15 @@
1
1
  import logging
2
+ import secrets
3
+ import time
4
+ from typing import (
5
+ List,
6
+ )
2
7
 
3
8
  import trio
4
9
 
10
+ from libp2p.host.host_interface import (
11
+ IHost,
12
+ )
5
13
  from libp2p.network.stream.exceptions import (
6
14
  StreamClosed,
7
15
  StreamEOF,
@@ -65,7 +73,42 @@ async def handle_ping(stream: INetStream) -> None:
65
73
  try:
66
74
  should_continue = await _handle_ping(stream, peer_id)
67
75
  if not should_continue:
76
+ await stream.close()
68
77
  return
69
78
  except Exception:
70
79
  await stream.reset()
71
80
  return
81
+
82
+
83
+ async def _ping(stream: INetStream) -> int:
84
+ """
85
+ Helper function to perform a single ping operation on a given stream,
86
+ returns integer value rtt - which denotes round trip time for a ping request in ms
87
+ """
88
+ ping_bytes = secrets.token_bytes(PING_LENGTH)
89
+ before = time.time()
90
+ await stream.write(ping_bytes)
91
+ pong_bytes = await stream.read(PING_LENGTH)
92
+ rtt = int((time.time() - before) * (10**6))
93
+ if ping_bytes != pong_bytes:
94
+ logger.debug("invalid pong response")
95
+ raise
96
+ return rtt
97
+
98
+
99
+ class PingService:
100
+ """PingService executes pings and returns RTT in miliseconds."""
101
+
102
+ def __init__(self, host: IHost):
103
+ self._host = host
104
+
105
+ async def ping(self, peer_id: PeerID, ping_amt: int = 1) -> List[int]:
106
+ stream = await self._host.new_stream(peer_id, [ID])
107
+
108
+ try:
109
+ rtts = [await _ping(stream) for _ in range(ping_amt)]
110
+ await stream.close()
111
+ return rtts
112
+ except Exception:
113
+ await stream.close()
114
+ raise
@@ -55,7 +55,9 @@ class PeerData(IPeerData):
55
55
  """
56
56
  :param addrs: multiaddresses to add
57
57
  """
58
- self.addrs.extend(addrs)
58
+ for addr in addrs:
59
+ if addr not in self.addrs:
60
+ self.addrs.append(addr)
59
61
 
60
62
  def get_addrs(self) -> List[Multiaddr]:
61
63
  """
@@ -66,6 +66,7 @@ class IPubsubRouter(ABC):
66
66
  Notifies the router that a new peer has been connected.
67
67
 
68
68
  :param peer_id: id of peer to add
69
+ :param protocol_id: router protocol the peer speaks, e.g., floodsub, gossipsub
69
70
  """
70
71
 
71
72
  @abstractmethod
@@ -81,10 +82,9 @@ class IPubsubRouter(ABC):
81
82
  """
82
83
  Invoked to process control messages in the RPC envelope.
83
84
  It is invoked after subscriptions and payload messages have been processed
84
- TODO: Check if this interface is ok. It's not the exact same as the go code, but
85
- the go code is really confusing with the msg origin, they specify `rpc.from`
86
- even when the rpc shouldn't have a from
87
- :param rpc: rpc message
85
+
86
+ :param rpc: RPC message
87
+ :param sender_peer_id: id of the peer who sent the message
88
88
  """
89
89
 
90
90
  @abstractmethod
@@ -75,10 +75,11 @@ class FloodSub(IPubsubRouter):
75
75
 
76
76
  async def handle_rpc(self, rpc: rpc_pb2.RPC, sender_peer_id: ID) -> None:
77
77
  """
78
- Invoked to process control messages in the RPC envelope. It is invoked
79
- after subscriptions and payload messages have been processed.
78
+ Invoked to process control messages in the RPC envelope.
79
+ It is invoked after subscriptions and payload messages have been processed
80
80
 
81
- :param rpc: rpc message
81
+ :param rpc: RPC message
82
+ :param sender_peer_id: id of the peer who sent the message
82
83
  """
83
84
  # Checkpoint
84
85
  await trio.lowlevel.checkpoint()
@@ -179,8 +179,8 @@ class GossipSub(IPubsubRouter, Service):
179
179
 
180
180
  async def handle_rpc(self, rpc: rpc_pb2.RPC, sender_peer_id: ID) -> None:
181
181
  """
182
- Invoked to process control messages in the RPC envelope. It is invoked
183
- after subscriptions and payload messages have been processed.
182
+ Invoked to process control messages in the RPC envelope.
183
+ It is invoked after subscriptions and payload messages have been processed
184
184
 
185
185
  :param rpc: RPC message
186
186
  :param sender_peer_id: id of the peer who sent the message
@@ -643,6 +643,19 @@ class Pubsub(Service, IPubsub):
643
643
  return
644
644
 
645
645
  self._mark_msg_seen(msg)
646
+
647
+ # reject messages claiming to be from ourselves but not locally published
648
+ self_id = self.host.get_id()
649
+ if (
650
+ base58.b58encode(msg.from_id).decode() == self_id
651
+ and msg_forwarder != self_id
652
+ ):
653
+ logger.debug(
654
+ "dropping message claiming to be from self but forwarded from %s",
655
+ msg_forwarder,
656
+ )
657
+ return
658
+
646
659
  self.notify_subscriptions(msg)
647
660
  await self.router.publish(msg_forwarder, msg)
648
661
 
File without changes
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: libp2p
3
- Version: 0.2.0
3
+ Version: 0.2.1
4
4
  Summary: libp2p: The Python implementation of the libp2p networking stack
5
5
  Home-page: https://github.com/libp2p/py-libp2p
6
6
  Author: The Ethereum Foundation
@@ -38,7 +38,7 @@ Requires-Dist: pymultihash>=0.8.2
38
38
  Requires-Dist: pynacl>=1.3.0
39
39
  Requires-Dist: rpcudp>=3.0.0
40
40
  Requires-Dist: trio-typing>=0.0.4
41
- Requires-Dist: trio>=0.15.0
41
+ Requires-Dist: trio>=0.26.0
42
42
  Requires-Dist: fastecdsa-any==1.7.5; sys_platform == "win32"
43
43
  Requires-Dist: fastecdsa==1.7.5; sys_platform != "win32"
44
44
  Provides-Extra: dev
@@ -9,6 +9,8 @@ examples/chat/__init__.py
9
9
  examples/chat/chat.py
10
10
  examples/echo/__init__.py
11
11
  examples/echo/echo.py
12
+ examples/ping/__init__.py
13
+ examples/ping/ping.py
12
14
  libp2p/__init__.py
13
15
  libp2p/exceptions.py
14
16
  libp2p/py.typed
@@ -175,6 +177,7 @@ tests/core/crypto/test_ed25519.py
175
177
  tests/core/crypto/test_secp256k1.py
176
178
  tests/core/examples/test_examples.py
177
179
  tests/core/host/test_basic_host.py
180
+ tests/core/host/test_connected_peers.py
178
181
  tests/core/host/test_ping.py
179
182
  tests/core/host/test_routed_host.py
180
183
  tests/core/identity/identify/test_protocol.py
@@ -185,6 +188,7 @@ tests/core/network/test_swarm.py
185
188
  tests/core/network/test_swarm_conn.py
186
189
  tests/core/peer/test_addrbook.py
187
190
  tests/core/peer/test_interop.py
191
+ tests/core/peer/test_peerdata.py
188
192
  tests/core/peer/test_peerid.py
189
193
  tests/core/peer/test_peerinfo.py
190
194
  tests/core/peer/test_peermetadata.py
@@ -10,7 +10,7 @@ pymultihash>=0.8.2
10
10
  pynacl>=1.3.0
11
11
  rpcudp>=3.0.0
12
12
  trio-typing>=0.0.4
13
- trio>=0.15.0
13
+ trio>=0.26.0
14
14
 
15
15
  [:python_version < "3.11"]
16
16
  exceptiongroup>=1.2.0
@@ -124,7 +124,7 @@ name = "Removals"
124
124
  showcontent = true
125
125
 
126
126
  [tool.bumpversion]
127
- current_version = "0.2.0"
127
+ current_version = "0.2.1"
128
128
  parse = """
129
129
  (?P<major>\\d+)
130
130
  \\.(?P<minor>\\d+)
@@ -66,7 +66,7 @@ install_requires = [
66
66
  "pynacl>=1.3.0",
67
67
  "rpcudp>=3.0.0",
68
68
  "trio-typing>=0.0.4",
69
- "trio>=0.15.0",
69
+ "trio>=0.26.0",
70
70
  ]
71
71
 
72
72
 
@@ -80,7 +80,7 @@ if not readthedocs_is_building:
80
80
  setup(
81
81
  name="libp2p",
82
82
  # *IMPORTANT*: Don't manually change the version here. Use `make bump`, as described in readme
83
- version="0.2.0",
83
+ version="0.2.1",
84
84
  description="""libp2p: The Python implementation of the libp2p networking stack""",
85
85
  long_description=long_description,
86
86
  long_description_content_type="text/markdown",
@@ -0,0 +1,113 @@
1
+ import pytest
2
+
3
+ from libp2p.peer.peerinfo import (
4
+ info_from_p2p_addr,
5
+ )
6
+ from libp2p.tools.factories import (
7
+ HostFactory,
8
+ )
9
+
10
+
11
+ async def connect_two(host_a, host_b, host_c):
12
+ # Initially all of the hosts are disconnected
13
+ assert (len(host_a.get_connected_peers())) == 0
14
+ assert (len(host_b.get_connected_peers())) == 0
15
+ assert (len(host_c.get_connected_peers())) == 0
16
+
17
+ # Connecting hostA with hostB
18
+ addr = host_b.get_addrs()[0]
19
+ info = info_from_p2p_addr(addr)
20
+ await host_a.connect(info)
21
+
22
+ # Since hostA and hostB are connected now
23
+ assert (len(host_a.get_connected_peers())) == 1
24
+ assert (len(host_b.get_connected_peers())) == 1
25
+ assert (len(host_c.get_connected_peers())) == 0
26
+ assert host_a.get_connected_peers()[0] == host_b.get_id()
27
+ assert host_b.get_connected_peers()[0] == host_a.get_id()
28
+
29
+
30
+ async def connect_three_cyclic(host_a, host_b, host_c):
31
+ # Connecting hostA with hostB
32
+ addr = host_b.get_addrs()[0]
33
+ infoB = info_from_p2p_addr(addr)
34
+ await host_a.connect(infoB)
35
+
36
+ # Connecting hostB with hostC
37
+ addr = host_c.get_addrs()[0]
38
+ infoC = info_from_p2p_addr(addr)
39
+ await host_b.connect(infoC)
40
+
41
+ # Connecting hostC with hostA
42
+ addr = host_a.get_addrs()[0]
43
+ infoA = info_from_p2p_addr(addr)
44
+ await host_c.connect(infoA)
45
+
46
+ # Performing checks
47
+ assert (len(host_a.get_connected_peers())) == 2
48
+ assert (len(host_b.get_connected_peers())) == 2
49
+ assert (len(host_c.get_connected_peers())) == 2
50
+ assert host_a.get_connected_peers() == [host_b.get_id(), host_c.get_id()]
51
+ assert host_b.get_connected_peers() == [host_a.get_id(), host_c.get_id()]
52
+ assert host_c.get_connected_peers() == [host_b.get_id(), host_a.get_id()]
53
+
54
+
55
+ async def connect_two_to_one(host_a, host_b, host_c):
56
+ # Connecting hostA and hostC to hostB
57
+ addr = host_b.get_addrs()[0]
58
+ infoB = info_from_p2p_addr(addr)
59
+ await host_a.connect(infoB)
60
+ await host_c.connect(infoB)
61
+
62
+ # Performing checks
63
+ assert (len(host_a.get_connected_peers())) == 1
64
+ assert (len(host_b.get_connected_peers())) == 2
65
+ assert (len(host_c.get_connected_peers())) == 1
66
+ assert host_a.get_connected_peers() == [host_b.get_id()]
67
+ assert host_b.get_connected_peers() == [host_a.get_id(), host_c.get_id()]
68
+ assert host_c.get_connected_peers() == [host_b.get_id()]
69
+
70
+
71
+ async def connect_and_disconnect(host_a, host_b, host_c):
72
+ # Connecting hostB to hostA and hostC
73
+ addr = host_a.get_addrs()[0]
74
+ infoA = info_from_p2p_addr(addr)
75
+ await host_b.connect(infoA)
76
+ addr = host_c.get_addrs()[0]
77
+ infoC = info_from_p2p_addr(addr)
78
+ await host_b.connect(infoC)
79
+
80
+ # Performing checks
81
+ assert (len(host_a.get_connected_peers())) == 1
82
+ assert (len(host_b.get_connected_peers())) == 2
83
+ assert (len(host_c.get_connected_peers())) == 1
84
+ assert host_a.get_connected_peers() == [host_b.get_id()]
85
+ assert host_b.get_connected_peers() == [host_a.get_id(), host_c.get_id()]
86
+ assert host_c.get_connected_peers() == [host_b.get_id()]
87
+
88
+ # Disconnecting hostB and hostA
89
+ await host_b.disconnect(host_a.get_id())
90
+
91
+ # Performing checks
92
+ assert (len(host_a.get_connected_peers())) == 0
93
+ assert (len(host_b.get_connected_peers())) == 1
94
+ assert (len(host_c.get_connected_peers())) == 1
95
+ assert host_b.get_connected_peers() == [host_c.get_id()]
96
+ assert host_c.get_connected_peers() == [host_b.get_id()]
97
+
98
+
99
+ @pytest.mark.parametrize(
100
+ "test",
101
+ [
102
+ (connect_two),
103
+ (connect_three_cyclic),
104
+ (connect_two_to_one),
105
+ (connect_and_disconnect),
106
+ ],
107
+ )
108
+ @pytest.mark.trio
109
+ async def test_connected_peers(test, security_protocol):
110
+ async with HostFactory.create_batch_and_listen(
111
+ 3, security_protocol=security_protocol
112
+ ) as hosts:
113
+ await test(hosts[0], hosts[1], hosts[2])
@@ -6,6 +6,7 @@ import trio
6
6
  from libp2p.host.ping import (
7
7
  ID,
8
8
  PING_LENGTH,
9
+ PingService,
9
10
  )
10
11
  from libp2p.tools.factories import (
11
12
  host_pair_factory,
@@ -47,3 +48,28 @@ async def test_ping_several(security_protocol):
47
48
  # NOTE: this interval can be `0` for this test.
48
49
  await trio.sleep(0)
49
50
  await stream.close()
51
+
52
+
53
+ @pytest.mark.trio
54
+ async def test_ping_service_once(security_protocol):
55
+ async with host_pair_factory(security_protocol=security_protocol) as (
56
+ host_a,
57
+ host_b,
58
+ ):
59
+ ping_service = PingService(host_b)
60
+ rtts = await ping_service.ping(host_a.get_id())
61
+ assert len(rtts) == 1
62
+ assert rtts[0] < 10**6
63
+
64
+
65
+ @pytest.mark.trio
66
+ async def test_ping_service_several(security_protocol):
67
+ async with host_pair_factory(security_protocol=security_protocol) as (
68
+ host_a,
69
+ host_b,
70
+ ):
71
+ ping_service = PingService(host_b)
72
+ rtts = await ping_service.ping(host_a.get_id(), ping_amt=SOME_PING_COUNT)
73
+ assert len(rtts) == SOME_PING_COUNT
74
+ for rtt in rtts:
75
+ assert rtt < 10**6
@@ -0,0 +1,106 @@
1
+ import pytest
2
+
3
+ from libp2p.crypto.secp256k1 import (
4
+ create_new_key_pair,
5
+ )
6
+ from libp2p.peer.peerdata import (
7
+ PeerData,
8
+ PeerDataError,
9
+ )
10
+
11
+ MOCK_ADDR = "/peer"
12
+ MOCK_KEYPAIR = create_new_key_pair()
13
+ MOCK_PUBKEY = MOCK_KEYPAIR.public_key
14
+ MOCK_PRIVKEY = MOCK_KEYPAIR.private_key
15
+
16
+
17
+ # Test case when no protocols have been added
18
+ def test_get_protocols_empty():
19
+ peer_data = PeerData()
20
+ assert peer_data.get_protocols() == []
21
+
22
+
23
+ # Test case when adding protocols
24
+ def test_add_protocols():
25
+ peer_data = PeerData()
26
+ protocols = ["protocol1", "protocol2"]
27
+ peer_data.add_protocols(protocols)
28
+ assert peer_data.get_protocols() == protocols
29
+
30
+
31
+ # Test case when setting protocols
32
+ def test_set_protocols():
33
+ peer_data = PeerData()
34
+ protocols = ["protocolA", "protocolB"]
35
+ peer_data.set_protocols(protocols)
36
+ assert peer_data.get_protocols() == protocols
37
+
38
+
39
+ # Test case when adding addresses
40
+ def test_add_addrs():
41
+ peer_data = PeerData()
42
+ addresses = [MOCK_ADDR]
43
+ peer_data.add_addrs(addresses)
44
+ assert peer_data.get_addrs() == addresses
45
+
46
+
47
+ # Test case when adding same address more than once
48
+ def test_add_dup_addrs():
49
+ peer_data = PeerData()
50
+ addresses = [MOCK_ADDR, MOCK_ADDR]
51
+ peer_data.add_addrs(addresses)
52
+ peer_data.add_addrs(addresses)
53
+ assert peer_data.get_addrs() == [MOCK_ADDR]
54
+
55
+
56
+ # Test case for clearing addresses
57
+ def test_clear_addrs():
58
+ peer_data = PeerData()
59
+ addresses = [MOCK_ADDR]
60
+ peer_data.add_addrs(addresses)
61
+ peer_data.clear_addrs()
62
+ assert peer_data.get_addrs() == []
63
+
64
+
65
+ # Test case for adding metadata
66
+ def test_put_metadata():
67
+ peer_data = PeerData()
68
+ key = "key1"
69
+ value = "value1"
70
+ peer_data.put_metadata(key, value)
71
+ assert peer_data.get_metadata(key) == value
72
+
73
+
74
+ # Test case for key not found in metadata
75
+ def test_get_metadata_key_not_found():
76
+ peer_data = PeerData()
77
+ with pytest.raises(PeerDataError):
78
+ peer_data.get_metadata("nonexistent_key")
79
+
80
+
81
+ # Test case for adding public key
82
+ def test_add_pubkey():
83
+ peer_data = PeerData()
84
+ peer_data.add_pubkey(MOCK_PUBKEY)
85
+ assert peer_data.get_pubkey() == MOCK_PUBKEY
86
+
87
+
88
+ # Test case when public key is not set
89
+ def test_get_pubkey_not_found():
90
+ peer_data = PeerData()
91
+ with pytest.raises(PeerDataError):
92
+ peer_data.get_pubkey()
93
+
94
+
95
+ # Test case for adding private key
96
+ def test_add_privkey():
97
+ peer_data = PeerData()
98
+ peer_data.add_privkey(MOCK_PRIVKEY)
99
+ assert peer_data.get_privkey() == MOCK_PRIVKEY
100
+
101
+
102
+ # Test case when private key is not set
103
+ def test_get_privkey_not_found():
104
+ peer_data = PeerData()
105
+ with pytest.raises(PeerDataError):
106
+ peer_data.get_privkey()
@@ -67,7 +67,7 @@ async def test_single_protocol_fails(security_protocol):
67
67
 
68
68
  # the StreamFailure is within 2 nested ExceptionGroups, so we use strict=False
69
69
  # to unwrap down to the core Exception
70
- with RaisesGroup(StreamFailure, strict=False):
70
+ with RaisesGroup(StreamFailure, allow_unwrapped=True, flatten_subgroups=True):
71
71
  await perform_simple_test(
72
72
  "", [PROTOCOL_ECHO], [PROTOCOL_POTATO], security_protocol
73
73
  )
@@ -112,7 +112,7 @@ async def test_multiple_protocol_fails(security_protocol):
112
112
 
113
113
  # the StreamFailure is within 2 nested ExceptionGroups, so we use strict=False
114
114
  # to unwrap down to the core Exception
115
- with RaisesGroup(StreamFailure, strict=False):
115
+ with RaisesGroup(StreamFailure, allow_unwrapped=True, flatten_subgroups=True):
116
116
  await perform_simple_test(
117
117
  "", protocols_for_client, protocols_for_listener, security_protocol
118
118
  )