libp2p 0.1.4__tar.gz → 0.2.0__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 (254) hide show
  1. libp2p-0.2.0/LICENSE-APACHE +7 -0
  2. libp2p-0.2.0/LICENSE-MIT +21 -0
  3. libp2p-0.2.0/MANIFEST.in +13 -0
  4. libp2p-0.2.0/PKG-INFO +218 -0
  5. libp2p-0.2.0/README.md +149 -0
  6. libp2p-0.2.0/examples/chat/chat.py +111 -0
  7. libp2p-0.2.0/examples/echo/echo.py +124 -0
  8. libp2p-0.2.0/libp2p/__init__.py +139 -0
  9. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/crypto/authenticated_encryption.py +14 -6
  10. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/crypto/ecc.py +23 -9
  11. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/crypto/ed25519.py +18 -7
  12. libp2p-0.2.0/libp2p/crypto/exceptions.py +14 -0
  13. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/crypto/key_exchange.py +18 -6
  14. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/crypto/keys.py +20 -10
  15. libp2p-0.2.0/libp2p/crypto/pb/crypto_pb2.py +40 -0
  16. libp2p-0.2.0/libp2p/crypto/pb/crypto_pb2.pyi +77 -0
  17. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/crypto/rsa.py +16 -5
  18. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/crypto/secp256k1.py +6 -1
  19. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/crypto/serialization.py +27 -9
  20. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/exceptions.py +6 -0
  21. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/host/basic_host.py +82 -25
  22. libp2p-0.2.0/libp2p/host/defaults.py +30 -0
  23. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/host/exceptions.py +3 -1
  24. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/host/host_interface.py +43 -11
  25. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/host/ping.py +23 -10
  26. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/host/routed_host.py +19 -8
  27. libp2p-0.2.0/libp2p/identity/identify/pb/identify_pb2.py +36 -0
  28. libp2p-0.2.0/libp2p/identity/identify/pb/identify_pb2.pyi +46 -0
  29. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/identity/identify/protocol.py +19 -6
  30. libp2p-0.2.0/libp2p/io/abc.py +68 -0
  31. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/io/exceptions.py +7 -1
  32. libp2p-0.2.0/libp2p/io/msgio.py +105 -0
  33. libp2p-0.2.0/libp2p/io/trio.py +44 -0
  34. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/io/utils.py +6 -2
  35. libp2p-0.2.0/libp2p/network/connection/exceptions.py +7 -0
  36. libp2p-0.2.0/libp2p/network/connection/net_connection_interface.py +31 -0
  37. libp2p-0.2.0/libp2p/network/connection/raw_connection.py +44 -0
  38. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/network/connection/raw_connection_interface.py +3 -1
  39. libp2p-0.2.0/libp2p/network/connection/swarm_connection.py +113 -0
  40. libp2p-0.2.0/libp2p/network/exceptions.py +7 -0
  41. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/network/network_interface.py +40 -13
  42. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/network/notifee_interface.py +16 -5
  43. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/network/stream/exceptions.py +3 -1
  44. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/network/stream/net_stream.py +26 -15
  45. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/network/stream/net_stream_interface.py +12 -5
  46. libp2p-0.2.0/libp2p/network/swarm.py +405 -0
  47. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/peer/addrbook_interface.py +16 -6
  48. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/peer/id.py +10 -6
  49. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/peer/peerdata.py +16 -5
  50. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/peer/peerdata_interface.py +22 -8
  51. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/peer/peerinfo.py +8 -5
  52. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/peer/peermetadata_interface.py +10 -3
  53. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/peer/peerstore.py +38 -17
  54. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/peer/peerstore_interface.py +31 -11
  55. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/protocol_muxer/exceptions.py +3 -1
  56. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/protocol_muxer/multiselect.py +29 -14
  57. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/protocol_muxer/multiselect_client.py +29 -16
  58. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/protocol_muxer/multiselect_client_interface.py +16 -5
  59. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/protocol_muxer/multiselect_communicator.py +21 -8
  60. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/protocol_muxer/multiselect_communicator_interface.py +8 -3
  61. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/protocol_muxer/multiselect_muxer_interface.py +19 -6
  62. libp2p-0.1.4/libp2p/pubsub/pubsub_router_interface.py → libp2p-0.2.0/libp2p/pubsub/abc.py +87 -11
  63. libp2p-0.2.0/libp2p/pubsub/exceptions.py +11 -0
  64. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/pubsub/floodsub.py +45 -16
  65. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/pubsub/gossipsub.py +169 -135
  66. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/pubsub/mcache.py +13 -6
  67. libp2p-0.2.0/libp2p/pubsub/pb/rpc_pb2.py +60 -0
  68. libp2p-0.2.0/libp2p/pubsub/pb/rpc_pb2.pyi +297 -0
  69. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/pubsub/pubsub.py +234 -150
  70. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/pubsub/pubsub_notifee.py +37 -18
  71. libp2p-0.2.0/libp2p/pubsub/subscription.py +56 -0
  72. libp2p-0.2.0/libp2p/pubsub/typing.py +19 -0
  73. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/pubsub/validators.py +10 -4
  74. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/routing/interfaces.py +21 -8
  75. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/security/base_session.py +25 -12
  76. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/security/base_transport.py +12 -4
  77. libp2p-0.2.0/libp2p/security/exceptions.py +7 -0
  78. libp2p-0.2.0/libp2p/security/insecure/pb/plaintext_pb2.py +37 -0
  79. libp2p-0.2.0/libp2p/security/insecure/pb/plaintext_pb2.pyi +32 -0
  80. libp2p-0.2.0/libp2p/security/insecure/transport.py +189 -0
  81. libp2p-0.2.0/libp2p/security/noise/exceptions.py +26 -0
  82. libp2p-0.2.0/libp2p/security/noise/io.py +83 -0
  83. libp2p-0.2.0/libp2p/security/noise/messages.py +63 -0
  84. libp2p-0.2.0/libp2p/security/noise/patterns.py +203 -0
  85. libp2p-0.2.0/libp2p/security/noise/pb/noise_pb2.py +36 -0
  86. libp2p-0.2.0/libp2p/security/noise/pb/noise_pb2.pyi +32 -0
  87. libp2p-0.2.0/libp2p/security/noise/transport.py +74 -0
  88. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/security/secio/exceptions.py +7 -5
  89. libp2p-0.2.0/libp2p/security/secio/pb/spipe_pb2.py +38 -0
  90. libp2p-0.2.0/libp2p/security/secio/pb/spipe_pb2.pyi +58 -0
  91. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/security/secio/transport.py +110 -112
  92. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/security/secure_conn_interface.py +17 -8
  93. libp2p-0.2.0/libp2p/security/secure_session.py +91 -0
  94. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/security/secure_transport_interface.py +14 -6
  95. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/security/security_multistream.py +36 -16
  96. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/stream_muxer/abc.py +29 -13
  97. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/stream_muxer/exceptions.py +3 -1
  98. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/stream_muxer/mplex/constants.py +3 -1
  99. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/stream_muxer/mplex/datastructures.py +3 -1
  100. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/stream_muxer/mplex/mplex.py +130 -90
  101. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/stream_muxer/mplex/mplex_stream.py +111 -97
  102. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/stream_muxer/muxer_multistream.py +31 -10
  103. libp2p-0.2.0/libp2p/tools/async_service/__init__.py +15 -0
  104. libp2p-0.2.0/libp2p/tools/async_service/_utils.py +41 -0
  105. libp2p-0.2.0/libp2p/tools/async_service/abc.py +257 -0
  106. libp2p-0.2.0/libp2p/tools/async_service/base.py +378 -0
  107. libp2p-0.2.0/libp2p/tools/async_service/exceptions.py +26 -0
  108. libp2p-0.2.0/libp2p/tools/async_service/stats.py +18 -0
  109. libp2p-0.2.0/libp2p/tools/async_service/trio_service.py +446 -0
  110. libp2p-0.2.0/libp2p/tools/async_service/typing.py +16 -0
  111. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/tools/constants.py +8 -3
  112. libp2p-0.2.0/libp2p/tools/factories.py +684 -0
  113. libp2p-0.2.0/libp2p/tools/interop/__init__.py +0 -0
  114. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/tools/interop/constants.py +0 -1
  115. libp2p-0.2.0/libp2p/tools/interop/daemon.py +149 -0
  116. libp2p-0.2.0/libp2p/tools/interop/process.py +72 -0
  117. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/tools/interop/utils.py +20 -8
  118. libp2p-0.2.0/libp2p/tools/pubsub/__init__.py +0 -0
  119. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/tools/pubsub/dummy_account_node.py +45 -31
  120. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/tools/pubsub/floodsub_integration_test_settings.py +85 -73
  121. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/tools/pubsub/utils.py +16 -6
  122. libp2p-0.2.0/libp2p/tools/utils.py +63 -0
  123. libp2p-0.2.0/libp2p/transport/__init__.py +0 -0
  124. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/transport/exceptions.py +3 -1
  125. libp2p-0.2.0/libp2p/transport/listener_interface.py +35 -0
  126. libp2p-0.2.0/libp2p/transport/tcp/__init__.py +0 -0
  127. libp2p-0.2.0/libp2p/transport/tcp/tcp.py +130 -0
  128. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/transport/transport_interface.py +18 -7
  129. libp2p-0.2.0/libp2p/transport/typing.py +24 -0
  130. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/transport/upgrader.py +39 -13
  131. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/typing.py +6 -1
  132. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/utils.py +12 -23
  133. libp2p-0.2.0/libp2p.egg-info/PKG-INFO +218 -0
  134. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p.egg-info/SOURCES.txt +89 -2
  135. libp2p-0.2.0/libp2p.egg-info/requires.txt +50 -0
  136. libp2p-0.2.0/pyproject.toml +167 -0
  137. libp2p-0.2.0/scripts/release/test_package.py +60 -0
  138. libp2p-0.2.0/setup.py +114 -0
  139. libp2p-0.2.0/tests/conftest.py +23 -0
  140. libp2p-0.2.0/tests/core/crypto/test_ed25519.py +27 -0
  141. libp2p-0.2.0/tests/core/crypto/test_secp256k1.py +27 -0
  142. libp2p-0.2.0/tests/core/examples/test_examples.py +112 -0
  143. libp2p-0.2.0/tests/core/host/test_basic_host.py +24 -0
  144. libp2p-0.2.0/tests/core/host/test_ping.py +49 -0
  145. libp2p-0.2.0/tests/core/host/test_routed_host.py +32 -0
  146. libp2p-0.2.0/tests/core/identity/identify/test_protocol.py +27 -0
  147. libp2p-0.2.0/tests/core/network/conftest.py +29 -0
  148. libp2p-0.2.0/tests/core/network/test_net_stream.py +120 -0
  149. libp2p-0.2.0/tests/core/network/test_notify.py +126 -0
  150. libp2p-0.2.0/tests/core/network/test_swarm.py +158 -0
  151. libp2p-0.2.0/tests/core/network/test_swarm_conn.py +48 -0
  152. libp2p-0.2.0/tests/core/peer/test_addrbook.py +61 -0
  153. libp2p-0.2.0/tests/core/peer/test_interop.py +47 -0
  154. libp2p-0.2.0/tests/core/peer/test_peerid.py +110 -0
  155. libp2p-0.2.0/tests/core/peer/test_peerinfo.py +54 -0
  156. libp2p-0.2.0/tests/core/peer/test_peermetadata.py +46 -0
  157. libp2p-0.2.0/tests/core/peer/test_peerstore.py +62 -0
  158. libp2p-0.2.0/tests/core/protocol_muxer/test_protocol_muxer.py +118 -0
  159. libp2p-0.2.0/tests/core/pubsub/test_dummyaccount_demo.py +197 -0
  160. libp2p-0.2.0/tests/core/pubsub/test_floodsub.py +95 -0
  161. libp2p-0.2.0/tests/core/pubsub/test_gossipsub.py +488 -0
  162. libp2p-0.2.0/tests/core/pubsub/test_gossipsub_backward_compatibility.py +31 -0
  163. libp2p-0.2.0/tests/core/pubsub/test_mcache.py +130 -0
  164. libp2p-0.2.0/tests/core/pubsub/test_pubsub.py +684 -0
  165. libp2p-0.2.0/tests/core/pubsub/test_subscription.py +88 -0
  166. libp2p-0.2.0/tests/core/security/noise/test_msg_read_writer.py +32 -0
  167. libp2p-0.2.0/tests/core/security/noise/test_noise.py +38 -0
  168. libp2p-0.2.0/tests/core/security/test_secio.py +60 -0
  169. libp2p-0.2.0/tests/core/security/test_security_multistream.py +58 -0
  170. libp2p-0.2.0/tests/core/stream_muxer/conftest.py +24 -0
  171. libp2p-0.2.0/tests/core/stream_muxer/test_mplex_conn.py +41 -0
  172. libp2p-0.2.0/tests/core/stream_muxer/test_mplex_stream.py +215 -0
  173. libp2p-0.2.0/tests/core/test_import_and_version.py +4 -0
  174. libp2p-0.2.0/tests/core/test_libp2p/test_libp2p.py +309 -0
  175. libp2p-0.2.0/tests/core/tools/async_service/test_trio_based_service.py +668 -0
  176. libp2p-0.2.0/tests/core/tools/async_service/test_trio_external_api.py +109 -0
  177. libp2p-0.2.0/tests/core/tools/async_service/test_trio_manager_stats.py +86 -0
  178. libp2p-0.2.0/tests/core/transport/test_tcp.py +63 -0
  179. libp2p-0.2.0/tests/interop/conftest.py +161 -0
  180. libp2p-0.2.0/tests/interop/go_pkgs/examples/README.md +1 -0
  181. libp2p-0.2.0/tests/interop/go_pkgs/examples/echo/main.go +137 -0
  182. libp2p-0.2.0/tests/interop/go_pkgs/examples/go.mod +12 -0
  183. libp2p-0.2.0/tests/interop/go_pkgs/examples/go.sum +1244 -0
  184. libp2p-0.2.0/tests/interop/go_pkgs/examples/utils/host.go +82 -0
  185. libp2p-0.2.0/tests/interop/go_pkgs/install_interop_go_pkgs.sh +32 -0
  186. libp2p-0.2.0/tests/interop/test_bindings.py +32 -0
  187. libp2p-0.2.0/tests/interop/test_echo.py +116 -0
  188. libp2p-0.2.0/tests/interop/test_net_stream.py +81 -0
  189. libp2p-0.2.0/tests/interop/test_pubsub.py +185 -0
  190. libp2p-0.1.4/PKG-INFO +0 -240
  191. libp2p-0.1.4/README.md +0 -213
  192. libp2p-0.1.4/examples/chat/chat.py +0 -126
  193. libp2p-0.1.4/libp2p/__init__.py +0 -136
  194. libp2p-0.1.4/libp2p/crypto/exceptions.py +0 -12
  195. libp2p-0.1.4/libp2p/crypto/pb/crypto_pb2.py +0 -162
  196. libp2p-0.1.4/libp2p/host/defaults.py +0 -17
  197. libp2p-0.1.4/libp2p/identity/identify/pb/identify_pb2.py +0 -105
  198. libp2p-0.1.4/libp2p/io/abc.py +0 -34
  199. libp2p-0.1.4/libp2p/io/msgio.py +0 -84
  200. libp2p-0.1.4/libp2p/network/connection/exceptions.py +0 -5
  201. libp2p-0.1.4/libp2p/network/connection/net_connection_interface.py +0 -18
  202. libp2p-0.1.4/libp2p/network/connection/raw_connection.py +0 -58
  203. libp2p-0.1.4/libp2p/network/connection/swarm_connection.py +0 -111
  204. libp2p-0.1.4/libp2p/network/exceptions.py +0 -5
  205. libp2p-0.1.4/libp2p/network/swarm.py +0 -308
  206. libp2p-0.1.4/libp2p/pubsub/pb/rpc_pb2.py +0 -639
  207. libp2p-0.1.4/libp2p/security/exceptions.py +0 -5
  208. libp2p-0.1.4/libp2p/security/insecure/pb/plaintext_pb2.py +0 -80
  209. libp2p-0.1.4/libp2p/security/insecure/transport.py +0 -140
  210. libp2p-0.1.4/libp2p/security/secio/pb/spipe_pb2.py +0 -144
  211. libp2p-0.1.4/libp2p/tools/factories.py +0 -241
  212. libp2p-0.1.4/libp2p/tools/interop/daemon.py +0 -205
  213. libp2p-0.1.4/libp2p/tools/utils.py +0 -98
  214. libp2p-0.1.4/libp2p/transport/listener_interface.py +0 -28
  215. libp2p-0.1.4/libp2p/transport/tcp/tcp.py +0 -95
  216. libp2p-0.1.4/libp2p/transport/typing.py +0 -11
  217. libp2p-0.1.4/libp2p.egg-info/PKG-INFO +0 -240
  218. libp2p-0.1.4/libp2p.egg-info/requires.txt +0 -57
  219. libp2p-0.1.4/setup.py +0 -103
  220. {libp2p-0.1.4 → libp2p-0.2.0}/examples/__init__.py +0 -0
  221. {libp2p-0.1.4 → libp2p-0.2.0}/examples/chat/__init__.py +0 -0
  222. {libp2p-0.1.4/libp2p/crypto → libp2p-0.2.0/examples/echo}/__init__.py +0 -0
  223. {libp2p-0.1.4/libp2p/crypto/pb → libp2p-0.2.0/libp2p/crypto}/__init__.py +0 -0
  224. {libp2p-0.1.4/libp2p/host → libp2p-0.2.0/libp2p/crypto/pb}/__init__.py +0 -0
  225. {libp2p-0.1.4/libp2p/identity → libp2p-0.2.0/libp2p/host}/__init__.py +0 -0
  226. {libp2p-0.1.4/libp2p/identity/identify → libp2p-0.2.0/libp2p/identity}/__init__.py +0 -0
  227. {libp2p-0.1.4/libp2p/identity/identify/pb → libp2p-0.2.0/libp2p/identity/identify}/__init__.py +0 -0
  228. {libp2p-0.1.4/libp2p/io → libp2p-0.2.0/libp2p/identity/identify/pb}/__init__.py +0 -0
  229. {libp2p-0.1.4/libp2p/network → libp2p-0.2.0/libp2p/io}/__init__.py +0 -0
  230. {libp2p-0.1.4/libp2p/network/connection → libp2p-0.2.0/libp2p/network}/__init__.py +0 -0
  231. {libp2p-0.1.4/libp2p/network/stream → libp2p-0.2.0/libp2p/network/connection}/__init__.py +0 -0
  232. {libp2p-0.1.4/libp2p/peer → libp2p-0.2.0/libp2p/network/stream}/__init__.py +0 -0
  233. {libp2p-0.1.4/libp2p/protocol_muxer → libp2p-0.2.0/libp2p/peer}/__init__.py +0 -0
  234. {libp2p-0.1.4/libp2p/pubsub → libp2p-0.2.0/libp2p/protocol_muxer}/__init__.py +0 -0
  235. {libp2p-0.1.4/libp2p/pubsub/pb → libp2p-0.2.0/libp2p/pubsub}/__init__.py +0 -0
  236. {libp2p-0.1.4/libp2p/routing → libp2p-0.2.0/libp2p/pubsub/pb}/__init__.py +0 -0
  237. /libp2p-0.1.4/libp2p/security/__init__.py → /libp2p-0.2.0/libp2p/py.typed +0 -0
  238. {libp2p-0.1.4/libp2p/security/insecure → libp2p-0.2.0/libp2p/routing}/__init__.py +0 -0
  239. {libp2p-0.1.4/libp2p/security/insecure/pb → libp2p-0.2.0/libp2p/security}/__init__.py +0 -0
  240. {libp2p-0.1.4/libp2p/security/secio → libp2p-0.2.0/libp2p/security/insecure}/__init__.py +0 -0
  241. {libp2p-0.1.4/libp2p/security/secio → libp2p-0.2.0/libp2p/security/insecure}/pb/__init__.py +0 -0
  242. {libp2p-0.1.4/libp2p/stream_muxer → libp2p-0.2.0/libp2p/security/noise}/__init__.py +0 -0
  243. {libp2p-0.1.4/libp2p/stream_muxer/mplex → libp2p-0.2.0/libp2p/security/noise/pb}/__init__.py +0 -0
  244. {libp2p-0.1.4/libp2p/tools → libp2p-0.2.0/libp2p/security/secio}/__init__.py +0 -0
  245. {libp2p-0.1.4/libp2p/tools/interop → libp2p-0.2.0/libp2p/security/secio/pb}/__init__.py +0 -0
  246. {libp2p-0.1.4/libp2p/tools/pubsub → libp2p-0.2.0/libp2p/stream_muxer}/__init__.py +0 -0
  247. {libp2p-0.1.4/libp2p/transport → libp2p-0.2.0/libp2p/stream_muxer/mplex}/__init__.py +0 -0
  248. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/stream_muxer/mplex/exceptions.py +0 -0
  249. {libp2p-0.1.4/libp2p/transport/tcp → libp2p-0.2.0/libp2p/tools}/__init__.py +0 -0
  250. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p/tools/interop/envs.py +0 -0
  251. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p.egg-info/dependency_links.txt +0 -0
  252. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p.egg-info/not-zip-safe +0 -0
  253. {libp2p-0.1.4 → libp2p-0.2.0}/libp2p.egg-info/top_level.txt +0 -0
  254. {libp2p-0.1.4 → libp2p-0.2.0}/setup.cfg +0 -0
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2018 Zixuan Zhang
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
4
+
5
+ http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 Zixuan Zhang
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,13 @@
1
+ include LICENSE-APACHE
2
+ include LICENSE-MIT
3
+ include README.md
4
+
5
+ recursive-include scripts *
6
+ recursive-include tests *
7
+
8
+ global-include *.pyi
9
+
10
+ recursive-exclude * __pycache__
11
+ recursive-exclude * *.py[co]
12
+ prune .tox
13
+ prune venv*
libp2p-0.2.0/PKG-INFO ADDED
@@ -0,0 +1,218 @@
1
+ Metadata-Version: 2.1
2
+ Name: libp2p
3
+ Version: 0.2.0
4
+ Summary: libp2p: The Python implementation of the libp2p networking stack
5
+ Home-page: https://github.com/libp2p/py-libp2p
6
+ Author: The Ethereum Foundation
7
+ Author-email: snakecharmers@ethereum.org
8
+ License: MIT/APACHE2.0
9
+ Keywords: libp2p p2p
10
+ Platform: unix
11
+ Platform: linux
12
+ Platform: osx
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: License :: OSI Approved :: Apache Software License
17
+ Classifier: Natural Language :: English
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.8
20
+ Classifier: Programming Language :: Python :: 3.9
21
+ Classifier: Programming Language :: Python :: 3.10
22
+ Classifier: Programming Language :: Python :: 3.11
23
+ Classifier: Programming Language :: Python :: 3.12
24
+ Requires-Python: >=3.8, <4
25
+ Description-Content-Type: text/markdown
26
+ License-File: LICENSE-APACHE
27
+ License-File: LICENSE-MIT
28
+ Requires-Dist: base58>=1.0.3
29
+ Requires-Dist: coincurve>=10.0.0
30
+ Requires-Dist: exceptiongroup>=1.2.0; python_version < "3.11"
31
+ Requires-Dist: lru-dict>=1.1.6
32
+ Requires-Dist: multiaddr>=0.0.9
33
+ Requires-Dist: mypy-protobuf>=3.0.0
34
+ Requires-Dist: noiseprotocol>=0.3.0
35
+ Requires-Dist: protobuf>=5.27.0
36
+ Requires-Dist: pycryptodome>=3.9.2
37
+ Requires-Dist: pymultihash>=0.8.2
38
+ Requires-Dist: pynacl>=1.3.0
39
+ Requires-Dist: rpcudp>=3.0.0
40
+ Requires-Dist: trio-typing>=0.0.4
41
+ Requires-Dist: trio>=0.15.0
42
+ Requires-Dist: fastecdsa-any==1.7.5; sys_platform == "win32"
43
+ Requires-Dist: fastecdsa==1.7.5; sys_platform != "win32"
44
+ Provides-Extra: dev
45
+ Requires-Dist: build>=0.9.0; extra == "dev"
46
+ Requires-Dist: bump-my-version>=0.5.3; extra == "dev"
47
+ Requires-Dist: ipython; extra == "dev"
48
+ Requires-Dist: mypy==1.10.0; extra == "dev"
49
+ Requires-Dist: pre-commit>=3.4.0; extra == "dev"
50
+ Requires-Dist: tox>=4.0.0; extra == "dev"
51
+ Requires-Dist: twine; extra == "dev"
52
+ Requires-Dist: wheel; extra == "dev"
53
+ Requires-Dist: sphinx>=6.0.0; extra == "dev"
54
+ Requires-Dist: sphinx_rtd_theme>=1.0.0; extra == "dev"
55
+ Requires-Dist: towncrier<22,>=21; extra == "dev"
56
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
57
+ Requires-Dist: pytest-xdist>=2.4.0; extra == "dev"
58
+ Requires-Dist: pytest-trio>=0.5.2; extra == "dev"
59
+ Requires-Dist: factory-boy<3.0.0,>=2.12.0; extra == "dev"
60
+ Provides-Extra: docs
61
+ Requires-Dist: sphinx>=6.0.0; extra == "docs"
62
+ Requires-Dist: sphinx_rtd_theme>=1.0.0; extra == "docs"
63
+ Requires-Dist: towncrier<22,>=21; extra == "docs"
64
+ Provides-Extra: test
65
+ Requires-Dist: pytest>=7.0.0; extra == "test"
66
+ Requires-Dist: pytest-xdist>=2.4.0; extra == "test"
67
+ Requires-Dist: pytest-trio>=0.5.2; extra == "test"
68
+ Requires-Dist: factory-boy<3.0.0,>=2.12.0; extra == "test"
69
+
70
+ # py-libp2p
71
+
72
+ [![Join the chat at https://gitter.im/py-libp2p/Lobby](https://badges.gitter.im/py-libp2p/Lobby.png)](https://gitter.im/py-libp2p/Lobby)
73
+ [![Build Status](https://circleci.com/gh/libp2p/py-libp2p.svg?style=shield)](https://circleci.com/gh/libp2p/py-libp2p)
74
+ [![PyPI version](https://badge.fury.io/py/libp2p.svg)](https://badge.fury.io/py/libp2p)
75
+ [![Python versions](https://img.shields.io/pypi/pyversions/libp2p.svg)](https://pypi.python.org/pypi/libp2p)
76
+ [![Docs build](https://readthedocs.org/projects/py-libp2p/badge/?version=latest)](http://py-libp2p.readthedocs.io/en/latest/?badge=latest)
77
+ [![Freenode](https://img.shields.io/badge/freenode-%23libp2p-yellow.svg)](https://webchat.freenode.net/?channels=%23libp2p)
78
+ [![Matrix](https://img.shields.io/badge/matrix-%23libp2p%3Apermaweb.io-blue.svg)](https://riot.permaweb.io/#/room/#libp2p:permaweb.io)
79
+ [![Discord](https://img.shields.io/discord/475789330380488707?color=blueviolet&label=discord)](https://discord.gg/66KBrm2)
80
+
81
+ <h1 align="center">
82
+ <a href="https://libp2p.io/"><img width="250" src="https://github.com/libp2p/py-libp2p/blob/main/assets/py-libp2p-logo.png?raw=true" alt="py-libp2p hex logo" /></a>
83
+ </h1>
84
+
85
+ ## WARNING
86
+
87
+ py-libp2p is an experimental and work-in-progress repo under development. We do not yet recommend using py-libp2p in production environments.
88
+ Right now, `tests_interop` are turned off for CI, and a number of `tests` are failing. WIP.
89
+
90
+ The Python implementation of the libp2p networking stack
91
+
92
+ Read more in the [documentation on ReadTheDocs](https://py-libp2p.readthedocs.io/). [View the release notes](https://py-libp2p.readthedocs.io/en/latest/release_notes.html).
93
+
94
+ ## Maintainers
95
+
96
+ Currently maintained by [@pacrob](https://github.com/pacrob) and [@dhuseby](https://github.com/dhuseby), looking for assistance!
97
+
98
+ Note that tests/core/test_libp2p/test_libp2p.py contains an end-to-end messaging test between two libp2p hosts, which is the bulk of our proof of concept.
99
+
100
+ ## Feature Breakdown
101
+
102
+ py-libp2p aims for conformity with [the standard libp2p modules](https://github.com/libp2p/libp2p/blob/master/REQUIREMENTS.md#libp2p-modules-implementations). Below is a breakdown of the modules we have developed, are developing, and may develop in the future.
103
+
104
+ > Legend: :green_apple: Done   :lemon: In Progress   :tomato: Missing   :chestnut: Not planned
105
+
106
+ | libp2p Node | Status |
107
+ | ------------ | :-----------: |
108
+ | **`libp2p`** | :green_apple: |
109
+
110
+ | Identify Protocol | Status |
111
+ | ----------------- | :-----: |
112
+ | **`Identify`** | :lemon: |
113
+
114
+ | Transport Protocols | Status |
115
+ | ------------------- | :-----------: |
116
+ | **`TCP`** | :green_apple: |
117
+ | **`UDP`** | :tomato: |
118
+ | **`WebSockets`** | :chestnut: |
119
+ | **`UTP`** | :chestnut: |
120
+ | **`WebRTC`** | :chestnut: |
121
+ | **`SCTP`** | :chestnut: |
122
+ | **`Tor`** | :chestnut: |
123
+ | **`i2p`** | :chestnut: |
124
+ | **`cjdns`** | :chestnut: |
125
+ | **`Bluetooth LE`** | :chestnut: |
126
+ | **`Audio TP`** | :chestnut: |
127
+ | **`Zerotier`** | :chestnut: |
128
+ | **`QUIC`** | :chestnut: |
129
+
130
+ | Stream Muxers | Status |
131
+ | ---------------- | :-----------: |
132
+ | **`multiplex`** | :green_apple: |
133
+ | **`yamux`** | :tomato: |
134
+ | **`benchmarks`** | :chestnut: |
135
+ | **`muxado`** | :chestnut: |
136
+ | **`spdystream`** | :chestnut: |
137
+ | **`spdy`** | :chestnut: |
138
+ | **`http2`** | :chestnut: |
139
+ | **`QUIC`** | :chestnut: |
140
+
141
+ | Protocol Muxers | Status |
142
+ | ----------------- | :-----------: |
143
+ | **`multiselect`** | :green_apple: |
144
+
145
+ | Switch (Swarm) | Status |
146
+ | ------------------ | :-----------: |
147
+ | **`Switch`** | :green_apple: |
148
+ | **`Dialer stack`** | :green_apple: |
149
+
150
+ | Peer Discovery | Status |
151
+ | -------------------- | :--------: |
152
+ | **`bootstrap list`** | :tomato: |
153
+ | **`Kademlia DHT`** | :chestnut: |
154
+ | **`mDNS`** | :chestnut: |
155
+ | **`PEX`** | :chestnut: |
156
+ | **`DNS`** | :chestnut: |
157
+
158
+ | Content Routing | Status |
159
+ | ------------------ | :-----------: |
160
+ | **`Kademlia DHT`** | :chestnut: |
161
+ | **`floodsub`** | :green_apple: |
162
+ | **`gossipsub`** | :green_apple: |
163
+ | **`PHT`** | :chestnut: |
164
+
165
+ | Peer Routing | Status |
166
+ | ------------------ | :-----------: |
167
+ | **`Kademlia DHT`** | :chestnut: |
168
+ | **`floodsub`** | :green_apple: |
169
+ | **`gossipsub`** | :green_apple: |
170
+ | **`PHT`** | :chestnut: |
171
+
172
+ | NAT Traversal | Status |
173
+ | ------------------------ | :--------: |
174
+ | **`nat-pmp`** | :chestnut: |
175
+ | **`upnp`** | :chestnut: |
176
+ | **`ext addr discovery`** | :chestnut: |
177
+ | **`STUN-like`** | :chestnut: |
178
+ | **`line-switch relay`** | :chestnut: |
179
+ | **`pkt-switch relay`** | :chestnut: |
180
+
181
+ | Exchange | Status |
182
+ | ---------------- | :--------: |
183
+ | **`HTTP`** | :chestnut: |
184
+ | **`Bitswap`** | :chestnut: |
185
+ | **`Bittorrent`** | :chestnut: |
186
+
187
+ | Consensus | Status |
188
+ | -------------- | :--------: |
189
+ | **`Paxos`** | :chestnut: |
190
+ | **`Raft`** | :chestnut: |
191
+ | **`PBTF`** | :chestnut: |
192
+ | **`Nakamoto`** | :chestnut: |
193
+
194
+ ## Explanation of Basic Two Node Communication
195
+
196
+ ### Core Concepts
197
+
198
+ _(non-normative, useful for team notes, not a reference)_
199
+
200
+ Several components of the libp2p stack take part when establishing a connection between two nodes:
201
+
202
+ 1. **Host**: a node in the libp2p network.
203
+ 1. **Connection**: the layer 3 connection between two nodes in a libp2p network.
204
+ 1. **Transport**: the component that creates a _Connection_, e.g. TCP, UDP, QUIC, etc.
205
+ 1. **Streams**: an abstraction on top of a _Connection_ representing parallel conversations about different matters, each of which is identified by a protocol ID. Multiple streams are layered on top of a _Connection_ via the _Multiplexer_.
206
+ 1. **Multiplexer**: a component that is responsible for wrapping messages sent on a stream with an envelope that identifies the stream they pertain to, normally via an ID. The multiplexer on the other unwraps the message and routes it internally based on the stream identification.
207
+ 1. **Secure channel**: optionally establishes a secure, encrypted, and authenticated channel over the _Connection_.
208
+ 1. **Upgrader**: a component that takes a raw layer 3 connection returned by the _Transport_, and performs the security and multiplexing negotiation to set up a secure, multiplexed channel on top of which _Streams_ can be opened.
209
+
210
+ ### Communication between two hosts X and Y
211
+
212
+ _(non-normative, useful for team notes, not a reference)_
213
+
214
+ **Initiate the connection**: A host is simply a node in the libp2p network that is able to communicate with other nodes in the network. In order for X and Y to communicate with one another, one of the hosts must initiate the connection. Let's say that X is going to initiate the connection. X will first open a connection to Y. This connection is where all of the actual communication will take place.
215
+
216
+ **Communication over one connection with multiple protocols**: X and Y can communicate over the same connection using different protocols and the multiplexer will appropriately route messages for a given protocol to a particular handler function for that protocol, which allows for each host to handle different protocols with separate functions. Furthermore, we can use multiple streams for a given protocol that allow for the same protocol and same underlying connection to be used for communication about separate topics between nodes X and Y.
217
+
218
+ **Why use multiple streams?**: The purpose of using the same connection for multiple streams to communicate over is to avoid the overhead of having multiple connections between X and Y. In order for X and Y to differentiate between messages on different streams and different protocols, a multiplexer is used to encode the messages when a message will be sent and decode a message when a message is received. The multiplexer encodes the message by adding a header to the beginning of any message to be sent that contains the stream id (along with some other info). Then, the message is sent across the raw connection and the receiving host will use its multiplexer to decode the message, i.e. determine which stream id the message should be routed to.
libp2p-0.2.0/README.md ADDED
@@ -0,0 +1,149 @@
1
+ # py-libp2p
2
+
3
+ [![Join the chat at https://gitter.im/py-libp2p/Lobby](https://badges.gitter.im/py-libp2p/Lobby.png)](https://gitter.im/py-libp2p/Lobby)
4
+ [![Build Status](https://circleci.com/gh/libp2p/py-libp2p.svg?style=shield)](https://circleci.com/gh/libp2p/py-libp2p)
5
+ [![PyPI version](https://badge.fury.io/py/libp2p.svg)](https://badge.fury.io/py/libp2p)
6
+ [![Python versions](https://img.shields.io/pypi/pyversions/libp2p.svg)](https://pypi.python.org/pypi/libp2p)
7
+ [![Docs build](https://readthedocs.org/projects/py-libp2p/badge/?version=latest)](http://py-libp2p.readthedocs.io/en/latest/?badge=latest)
8
+ [![Freenode](https://img.shields.io/badge/freenode-%23libp2p-yellow.svg)](https://webchat.freenode.net/?channels=%23libp2p)
9
+ [![Matrix](https://img.shields.io/badge/matrix-%23libp2p%3Apermaweb.io-blue.svg)](https://riot.permaweb.io/#/room/#libp2p:permaweb.io)
10
+ [![Discord](https://img.shields.io/discord/475789330380488707?color=blueviolet&label=discord)](https://discord.gg/66KBrm2)
11
+
12
+ <h1 align="center">
13
+ <a href="https://libp2p.io/"><img width="250" src="https://github.com/libp2p/py-libp2p/blob/main/assets/py-libp2p-logo.png?raw=true" alt="py-libp2p hex logo" /></a>
14
+ </h1>
15
+
16
+ ## WARNING
17
+
18
+ py-libp2p is an experimental and work-in-progress repo under development. We do not yet recommend using py-libp2p in production environments.
19
+ Right now, `tests_interop` are turned off for CI, and a number of `tests` are failing. WIP.
20
+
21
+ The Python implementation of the libp2p networking stack
22
+
23
+ Read more in the [documentation on ReadTheDocs](https://py-libp2p.readthedocs.io/). [View the release notes](https://py-libp2p.readthedocs.io/en/latest/release_notes.html).
24
+
25
+ ## Maintainers
26
+
27
+ Currently maintained by [@pacrob](https://github.com/pacrob) and [@dhuseby](https://github.com/dhuseby), looking for assistance!
28
+
29
+ Note that tests/core/test_libp2p/test_libp2p.py contains an end-to-end messaging test between two libp2p hosts, which is the bulk of our proof of concept.
30
+
31
+ ## Feature Breakdown
32
+
33
+ py-libp2p aims for conformity with [the standard libp2p modules](https://github.com/libp2p/libp2p/blob/master/REQUIREMENTS.md#libp2p-modules-implementations). Below is a breakdown of the modules we have developed, are developing, and may develop in the future.
34
+
35
+ > Legend: :green_apple: Done   :lemon: In Progress   :tomato: Missing   :chestnut: Not planned
36
+
37
+ | libp2p Node | Status |
38
+ | ------------ | :-----------: |
39
+ | **`libp2p`** | :green_apple: |
40
+
41
+ | Identify Protocol | Status |
42
+ | ----------------- | :-----: |
43
+ | **`Identify`** | :lemon: |
44
+
45
+ | Transport Protocols | Status |
46
+ | ------------------- | :-----------: |
47
+ | **`TCP`** | :green_apple: |
48
+ | **`UDP`** | :tomato: |
49
+ | **`WebSockets`** | :chestnut: |
50
+ | **`UTP`** | :chestnut: |
51
+ | **`WebRTC`** | :chestnut: |
52
+ | **`SCTP`** | :chestnut: |
53
+ | **`Tor`** | :chestnut: |
54
+ | **`i2p`** | :chestnut: |
55
+ | **`cjdns`** | :chestnut: |
56
+ | **`Bluetooth LE`** | :chestnut: |
57
+ | **`Audio TP`** | :chestnut: |
58
+ | **`Zerotier`** | :chestnut: |
59
+ | **`QUIC`** | :chestnut: |
60
+
61
+ | Stream Muxers | Status |
62
+ | ---------------- | :-----------: |
63
+ | **`multiplex`** | :green_apple: |
64
+ | **`yamux`** | :tomato: |
65
+ | **`benchmarks`** | :chestnut: |
66
+ | **`muxado`** | :chestnut: |
67
+ | **`spdystream`** | :chestnut: |
68
+ | **`spdy`** | :chestnut: |
69
+ | **`http2`** | :chestnut: |
70
+ | **`QUIC`** | :chestnut: |
71
+
72
+ | Protocol Muxers | Status |
73
+ | ----------------- | :-----------: |
74
+ | **`multiselect`** | :green_apple: |
75
+
76
+ | Switch (Swarm) | Status |
77
+ | ------------------ | :-----------: |
78
+ | **`Switch`** | :green_apple: |
79
+ | **`Dialer stack`** | :green_apple: |
80
+
81
+ | Peer Discovery | Status |
82
+ | -------------------- | :--------: |
83
+ | **`bootstrap list`** | :tomato: |
84
+ | **`Kademlia DHT`** | :chestnut: |
85
+ | **`mDNS`** | :chestnut: |
86
+ | **`PEX`** | :chestnut: |
87
+ | **`DNS`** | :chestnut: |
88
+
89
+ | Content Routing | Status |
90
+ | ------------------ | :-----------: |
91
+ | **`Kademlia DHT`** | :chestnut: |
92
+ | **`floodsub`** | :green_apple: |
93
+ | **`gossipsub`** | :green_apple: |
94
+ | **`PHT`** | :chestnut: |
95
+
96
+ | Peer Routing | Status |
97
+ | ------------------ | :-----------: |
98
+ | **`Kademlia DHT`** | :chestnut: |
99
+ | **`floodsub`** | :green_apple: |
100
+ | **`gossipsub`** | :green_apple: |
101
+ | **`PHT`** | :chestnut: |
102
+
103
+ | NAT Traversal | Status |
104
+ | ------------------------ | :--------: |
105
+ | **`nat-pmp`** | :chestnut: |
106
+ | **`upnp`** | :chestnut: |
107
+ | **`ext addr discovery`** | :chestnut: |
108
+ | **`STUN-like`** | :chestnut: |
109
+ | **`line-switch relay`** | :chestnut: |
110
+ | **`pkt-switch relay`** | :chestnut: |
111
+
112
+ | Exchange | Status |
113
+ | ---------------- | :--------: |
114
+ | **`HTTP`** | :chestnut: |
115
+ | **`Bitswap`** | :chestnut: |
116
+ | **`Bittorrent`** | :chestnut: |
117
+
118
+ | Consensus | Status |
119
+ | -------------- | :--------: |
120
+ | **`Paxos`** | :chestnut: |
121
+ | **`Raft`** | :chestnut: |
122
+ | **`PBTF`** | :chestnut: |
123
+ | **`Nakamoto`** | :chestnut: |
124
+
125
+ ## Explanation of Basic Two Node Communication
126
+
127
+ ### Core Concepts
128
+
129
+ _(non-normative, useful for team notes, not a reference)_
130
+
131
+ Several components of the libp2p stack take part when establishing a connection between two nodes:
132
+
133
+ 1. **Host**: a node in the libp2p network.
134
+ 1. **Connection**: the layer 3 connection between two nodes in a libp2p network.
135
+ 1. **Transport**: the component that creates a _Connection_, e.g. TCP, UDP, QUIC, etc.
136
+ 1. **Streams**: an abstraction on top of a _Connection_ representing parallel conversations about different matters, each of which is identified by a protocol ID. Multiple streams are layered on top of a _Connection_ via the _Multiplexer_.
137
+ 1. **Multiplexer**: a component that is responsible for wrapping messages sent on a stream with an envelope that identifies the stream they pertain to, normally via an ID. The multiplexer on the other unwraps the message and routes it internally based on the stream identification.
138
+ 1. **Secure channel**: optionally establishes a secure, encrypted, and authenticated channel over the _Connection_.
139
+ 1. **Upgrader**: a component that takes a raw layer 3 connection returned by the _Transport_, and performs the security and multiplexing negotiation to set up a secure, multiplexed channel on top of which _Streams_ can be opened.
140
+
141
+ ### Communication between two hosts X and Y
142
+
143
+ _(non-normative, useful for team notes, not a reference)_
144
+
145
+ **Initiate the connection**: A host is simply a node in the libp2p network that is able to communicate with other nodes in the network. In order for X and Y to communicate with one another, one of the hosts must initiate the connection. Let's say that X is going to initiate the connection. X will first open a connection to Y. This connection is where all of the actual communication will take place.
146
+
147
+ **Communication over one connection with multiple protocols**: X and Y can communicate over the same connection using different protocols and the multiplexer will appropriately route messages for a given protocol to a particular handler function for that protocol, which allows for each host to handle different protocols with separate functions. Furthermore, we can use multiple streams for a given protocol that allow for the same protocol and same underlying connection to be used for communication about separate topics between nodes X and Y.
148
+
149
+ **Why use multiple streams?**: The purpose of using the same connection for multiple streams to communicate over is to avoid the overhead of having multiple connections between X and Y. In order for X and Y to differentiate between messages on different streams and different protocols, a multiplexer is used to encode the messages when a message will be sent and decode a message when a message is received. The multiplexer encodes the message by adding a header to the beginning of any message to be sent that contains the stream id (along with some other info). Then, the message is sent across the raw connection and the receiving host will use its multiplexer to decode the message, i.e. determine which stream id the message should be routed to.
@@ -0,0 +1,111 @@
1
+ import argparse
2
+ import sys
3
+
4
+ import multiaddr
5
+ import trio
6
+
7
+ from libp2p import (
8
+ new_host,
9
+ )
10
+ from libp2p.network.stream.net_stream_interface import (
11
+ INetStream,
12
+ )
13
+ from libp2p.peer.peerinfo import (
14
+ info_from_p2p_addr,
15
+ )
16
+ from libp2p.typing import (
17
+ TProtocol,
18
+ )
19
+
20
+ PROTOCOL_ID = TProtocol("/chat/1.0.0")
21
+ MAX_READ_LEN = 2**32 - 1
22
+
23
+
24
+ async def read_data(stream: INetStream) -> None:
25
+ while True:
26
+ read_bytes = await stream.read(MAX_READ_LEN)
27
+ if read_bytes is not None:
28
+ read_string = read_bytes.decode()
29
+ if read_string != "\n":
30
+ # Green console colour: \x1b[32m
31
+ # Reset console colour: \x1b[0m
32
+ print("\x1b[32m %s\x1b[0m " % read_string, end="")
33
+
34
+
35
+ async def write_data(stream: INetStream) -> None:
36
+ async_f = trio.wrap_file(sys.stdin)
37
+ while True:
38
+ line = await async_f.readline()
39
+ await stream.write(line.encode())
40
+
41
+
42
+ async def run(port: int, destination: str) -> None:
43
+ localhost_ip = "127.0.0.1"
44
+ listen_addr = multiaddr.Multiaddr(f"/ip4/0.0.0.0/tcp/{port}")
45
+ host = new_host()
46
+ async with host.run(listen_addrs=[listen_addr]), trio.open_nursery() as nursery:
47
+ if not destination: # its the server
48
+
49
+ async def stream_handler(stream: INetStream) -> None:
50
+ nursery.start_soon(read_data, stream)
51
+ nursery.start_soon(write_data, stream)
52
+
53
+ host.set_stream_handler(PROTOCOL_ID, stream_handler)
54
+
55
+ print(
56
+ "Run this from the same folder in another console:\n\n"
57
+ f"python chat.py -p {int(port) + 1} "
58
+ f"-d /ip4/{localhost_ip}/tcp/{port}/p2p/{host.get_id().pretty()}\n"
59
+ )
60
+ print("Waiting for incoming connection...")
61
+
62
+ else: # its the client
63
+ maddr = multiaddr.Multiaddr(destination)
64
+ info = info_from_p2p_addr(maddr)
65
+ # Associate the peer with local ip address
66
+ await host.connect(info)
67
+ # Start a stream with the destination.
68
+ # Multiaddress of the destination peer is fetched from the peerstore
69
+ # using 'peerId'.
70
+ stream = await host.new_stream(info.peer_id, [PROTOCOL_ID])
71
+
72
+ nursery.start_soon(read_data, stream)
73
+ nursery.start_soon(write_data, stream)
74
+ print(f"Connected to peer {info.addrs[0]}")
75
+
76
+ await trio.sleep_forever()
77
+
78
+
79
+ def main() -> None:
80
+ description = """
81
+ This program demonstrates a simple p2p chat application using libp2p.
82
+ To use it, first run 'python ./chat -p <PORT>', where <PORT> is the port number.
83
+ Then, run another host with 'python ./chat -p <ANOTHER_PORT> -d <DESTINATION>',
84
+ where <DESTINATION> is the multiaddress of the previous listener host.
85
+ """
86
+ example_maddr = (
87
+ "/ip4/127.0.0.1/tcp/8000/p2p/QmQn4SwGkDZKkUEpBRBvTmheQycxAHJUNmVEnjA2v1qe8Q"
88
+ )
89
+ parser = argparse.ArgumentParser(description=description)
90
+ parser.add_argument(
91
+ "-p", "--port", default=8000, type=int, help="source port number"
92
+ )
93
+ parser.add_argument(
94
+ "-d",
95
+ "--destination",
96
+ type=str,
97
+ help=f"destination multiaddr string, e.g. {example_maddr}",
98
+ )
99
+ args = parser.parse_args()
100
+
101
+ if not args.port:
102
+ raise RuntimeError("was not able to determine a local port")
103
+
104
+ try:
105
+ trio.run(run, *(args.port, args.destination))
106
+ except KeyboardInterrupt:
107
+ pass
108
+
109
+
110
+ if __name__ == "__main__":
111
+ main()
@@ -0,0 +1,124 @@
1
+ import argparse
2
+
3
+ import multiaddr
4
+ import trio
5
+
6
+ from libp2p import (
7
+ new_host,
8
+ )
9
+ from libp2p.crypto.secp256k1 import (
10
+ create_new_key_pair,
11
+ )
12
+ from libp2p.network.stream.net_stream_interface import (
13
+ INetStream,
14
+ )
15
+ from libp2p.peer.peerinfo import (
16
+ info_from_p2p_addr,
17
+ )
18
+ from libp2p.typing import (
19
+ TProtocol,
20
+ )
21
+
22
+ PROTOCOL_ID = TProtocol("/echo/1.0.0")
23
+
24
+
25
+ async def _echo_stream_handler(stream: INetStream) -> None:
26
+ # Wait until EOF
27
+ msg = await stream.read()
28
+ await stream.write(msg)
29
+ await stream.close()
30
+
31
+
32
+ async def run(port: int, destination: str, seed: int = None) -> None:
33
+ localhost_ip = "127.0.0.1"
34
+ listen_addr = multiaddr.Multiaddr(f"/ip4/0.0.0.0/tcp/{port}")
35
+
36
+ if seed:
37
+ import random
38
+
39
+ random.seed(seed)
40
+ secret_number = random.getrandbits(32 * 8)
41
+ secret = secret_number.to_bytes(length=32, byteorder="big")
42
+ else:
43
+ import secrets
44
+
45
+ secret = secrets.token_bytes(32)
46
+
47
+ host = new_host(key_pair=create_new_key_pair(secret))
48
+ async with host.run(listen_addrs=[listen_addr]):
49
+ print(f"I am {host.get_id().to_string()}")
50
+
51
+ if not destination: # its the server
52
+ host.set_stream_handler(PROTOCOL_ID, _echo_stream_handler)
53
+
54
+ print(
55
+ "Run this from the same folder in another console:\n\n"
56
+ f"python echo.py -p {int(port) + 1} "
57
+ f"-d /ip4/{localhost_ip}/tcp/{port}/p2p/{host.get_id().pretty()}\n"
58
+ )
59
+ print("Waiting for incoming connections...")
60
+ await trio.sleep_forever()
61
+
62
+ else: # its the client
63
+ maddr = multiaddr.Multiaddr(destination)
64
+ info = info_from_p2p_addr(maddr)
65
+ # Associate the peer with local ip address
66
+ await host.connect(info)
67
+
68
+ # Start a stream with the destination.
69
+ # Multiaddress of the destination peer is fetched from the peerstore
70
+ # using 'peerId'.
71
+ stream = await host.new_stream(info.peer_id, [PROTOCOL_ID])
72
+
73
+ msg = b"hi, there!\n"
74
+
75
+ await stream.write(msg)
76
+ # Notify the other side about EOF
77
+ await stream.close()
78
+ response = await stream.read()
79
+
80
+ print(f"Sent: {msg.decode('utf-8')}")
81
+ print(f"Got: {response.decode('utf-8')}")
82
+
83
+
84
+ def main() -> None:
85
+ description = """
86
+ This program demonstrates a simple echo protocol where a peer listens for
87
+ connections and copies back any input received on a stream.
88
+
89
+ To use it, first run 'python ./echo -p <PORT>', where <PORT> is the port number.
90
+ Then, run another host with 'python ./chat -p <ANOTHER_PORT> -d <DESTINATION>',
91
+ where <DESTINATION> is the multiaddress of the previous listener host.
92
+ """
93
+ example_maddr = (
94
+ "/ip4/127.0.0.1/tcp/8000/p2p/QmQn4SwGkDZKkUEpBRBvTmheQycxAHJUNmVEnjA2v1qe8Q"
95
+ )
96
+ parser = argparse.ArgumentParser(description=description)
97
+ parser.add_argument(
98
+ "-p", "--port", default=8000, type=int, help="source port number"
99
+ )
100
+ parser.add_argument(
101
+ "-d",
102
+ "--destination",
103
+ type=str,
104
+ help=f"destination multiaddr string, e.g. {example_maddr}",
105
+ )
106
+ parser.add_argument(
107
+ "-s",
108
+ "--seed",
109
+ type=int,
110
+ help="provide a seed to the random number generator (e.g. to fix peer IDs across runs)", # noqa: E501
111
+ )
112
+ args = parser.parse_args()
113
+
114
+ if not args.port:
115
+ raise RuntimeError("was not able to determine a local port")
116
+
117
+ try:
118
+ trio.run(run, args.port, args.destination, args.seed)
119
+ except KeyboardInterrupt:
120
+ pass
121
+
122
+
123
+ if __name__ == "__main__":
124
+ main()