@streamr/dht 0.0.1-tatum.0

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 (344) hide show
  1. package/.eslintignore +5 -0
  2. package/.eslintrc +3 -0
  3. package/README.md +38 -0
  4. package/dist/src/connection/Connection.d.ts +11 -0
  5. package/dist/src/connection/Connection.js +23 -0
  6. package/dist/src/connection/Connection.js.map +1 -0
  7. package/dist/src/connection/ConnectionLockHandler.d.ts +23 -0
  8. package/dist/src/connection/ConnectionLockHandler.js +94 -0
  9. package/dist/src/connection/ConnectionLockHandler.js.map +1 -0
  10. package/dist/src/connection/ConnectionManager.d.ts +94 -0
  11. package/dist/src/connection/ConnectionManager.js +554 -0
  12. package/dist/src/connection/ConnectionManager.js.map +1 -0
  13. package/dist/src/connection/ConnectivityChecker.d.ts +17 -0
  14. package/dist/src/connection/ConnectivityChecker.js +187 -0
  15. package/dist/src/connection/ConnectivityChecker.js.map +1 -0
  16. package/dist/src/connection/Handshaker.d.ts +19 -0
  17. package/dist/src/connection/Handshaker.js +77 -0
  18. package/dist/src/connection/Handshaker.js.map +1 -0
  19. package/dist/src/connection/IConnection.d.ts +38 -0
  20. package/dist/src/connection/IConnection.js +19 -0
  21. package/dist/src/connection/IConnection.js.map +1 -0
  22. package/dist/src/connection/IConnectionSource.d.ts +4 -0
  23. package/dist/src/connection/IConnectionSource.js +3 -0
  24. package/dist/src/connection/IConnectionSource.js.map +1 -0
  25. package/dist/src/connection/ManagedConnection.d.ts +60 -0
  26. package/dist/src/connection/ManagedConnection.js +352 -0
  27. package/dist/src/connection/ManagedConnection.js.map +1 -0
  28. package/dist/src/connection/ManagedWebRtcConnection.d.ts +7 -0
  29. package/dist/src/connection/ManagedWebRtcConnection.js +20 -0
  30. package/dist/src/connection/ManagedWebRtcConnection.js.map +1 -0
  31. package/dist/src/connection/RemoteConnectionLocker.d.ts +14 -0
  32. package/dist/src/connection/RemoteConnectionLocker.js +93 -0
  33. package/dist/src/connection/RemoteConnectionLocker.js.map +1 -0
  34. package/dist/src/connection/Simulator/Simulator.d.ts +42 -0
  35. package/dist/src/connection/Simulator/Simulator.js +325 -0
  36. package/dist/src/connection/Simulator/Simulator.js.map +1 -0
  37. package/dist/src/connection/Simulator/SimulatorConnection.d.ts +19 -0
  38. package/dist/src/connection/Simulator/SimulatorConnection.js +118 -0
  39. package/dist/src/connection/Simulator/SimulatorConnection.js.map +1 -0
  40. package/dist/src/connection/Simulator/SimulatorConnector.d.ts +17 -0
  41. package/dist/src/connection/Simulator/SimulatorConnector.js +72 -0
  42. package/dist/src/connection/Simulator/SimulatorConnector.js.map +1 -0
  43. package/dist/src/connection/Simulator/SimulatorTransport.d.ts +6 -0
  44. package/dist/src/connection/Simulator/SimulatorTransport.js +11 -0
  45. package/dist/src/connection/Simulator/SimulatorTransport.js.map +1 -0
  46. package/dist/src/connection/Simulator/pings.d.ts +21 -0
  47. package/dist/src/connection/Simulator/pings.js +61 -0
  48. package/dist/src/connection/Simulator/pings.js.map +1 -0
  49. package/dist/src/connection/WebRTC/IWebRtcConnection.d.ts +20 -0
  50. package/dist/src/connection/WebRTC/IWebRtcConnection.js +9 -0
  51. package/dist/src/connection/WebRTC/IWebRtcConnection.js.map +1 -0
  52. package/dist/src/connection/WebRTC/NodeWebRtcConnection.d.ts +47 -0
  53. package/dist/src/connection/WebRTC/NodeWebRtcConnection.js +233 -0
  54. package/dist/src/connection/WebRTC/NodeWebRtcConnection.js.map +1 -0
  55. package/dist/src/connection/WebRTC/RemoteWebrtcConnector.d.ts +12 -0
  56. package/dist/src/connection/WebRTC/RemoteWebrtcConnector.js +74 -0
  57. package/dist/src/connection/WebRTC/RemoteWebrtcConnector.js.map +1 -0
  58. package/dist/src/connection/WebRTC/WebRtcConnector.d.ts +47 -0
  59. package/dist/src/connection/WebRTC/WebRtcConnector.js +227 -0
  60. package/dist/src/connection/WebRTC/WebRtcConnector.js.map +1 -0
  61. package/dist/src/connection/WebRTC/iceServerAsString.d.ts +2 -0
  62. package/dist/src/connection/WebRTC/iceServerAsString.js +18 -0
  63. package/dist/src/connection/WebRTC/iceServerAsString.js.map +1 -0
  64. package/dist/src/connection/WebSocket/ClientWebSocket.d.ts +15 -0
  65. package/dist/src/connection/WebSocket/ClientWebSocket.js +113 -0
  66. package/dist/src/connection/WebSocket/ClientWebSocket.js.map +1 -0
  67. package/dist/src/connection/WebSocket/RemoteWebSocketConnector.d.ts +9 -0
  68. package/dist/src/connection/WebSocket/RemoteWebSocketConnector.js +63 -0
  69. package/dist/src/connection/WebSocket/RemoteWebSocketConnector.js.map +1 -0
  70. package/dist/src/connection/WebSocket/ServerWebSocket.d.ts +18 -0
  71. package/dist/src/connection/WebSocket/ServerWebSocket.js +103 -0
  72. package/dist/src/connection/WebSocket/ServerWebSocket.js.map +1 -0
  73. package/dist/src/connection/WebSocket/WebSocketConnector.d.ts +31 -0
  74. package/dist/src/connection/WebSocket/WebSocketConnector.js +202 -0
  75. package/dist/src/connection/WebSocket/WebSocketConnector.js.map +1 -0
  76. package/dist/src/connection/WebSocket/WebSocketServer.d.ts +9 -0
  77. package/dist/src/connection/WebSocket/WebSocketServer.js +101 -0
  78. package/dist/src/connection/WebSocket/WebSocketServer.js.map +1 -0
  79. package/dist/src/dht/DhtNode.d.ts +153 -0
  80. package/dist/src/dht/DhtNode.js +599 -0
  81. package/dist/src/dht/DhtNode.js.map +1 -0
  82. package/dist/src/dht/DhtPeer.d.ts +18 -0
  83. package/dist/src/dht/DhtPeer.js +74 -0
  84. package/dist/src/dht/DhtPeer.js.map +1 -0
  85. package/dist/src/dht/ExternalApi.d.ts +8 -0
  86. package/dist/src/dht/ExternalApi.js +26 -0
  87. package/dist/src/dht/ExternalApi.js.map +1 -0
  88. package/dist/src/dht/RemoteExternalApi.d.ts +6 -0
  89. package/dist/src/dht/RemoteExternalApi.js +26 -0
  90. package/dist/src/dht/RemoteExternalApi.js.map +1 -0
  91. package/dist/src/dht/contact/Contact.d.ts +22 -0
  92. package/dist/src/dht/contact/Contact.js +25 -0
  93. package/dist/src/dht/contact/Contact.js.map +1 -0
  94. package/dist/src/dht/contact/RandomContactList.d.ts +20 -0
  95. package/dist/src/dht/contact/RandomContactList.js +78 -0
  96. package/dist/src/dht/contact/RandomContactList.js.map +1 -0
  97. package/dist/src/dht/contact/Remote.d.ts +15 -0
  98. package/dist/src/dht/contact/Remote.js +24 -0
  99. package/dist/src/dht/contact/Remote.js.map +1 -0
  100. package/dist/src/dht/contact/SortedContactList.d.ts +35 -0
  101. package/dist/src/dht/contact/SortedContactList.js +156 -0
  102. package/dist/src/dht/contact/SortedContactList.js.map +1 -0
  103. package/dist/src/dht/discovery/DiscoverySession.d.ts +36 -0
  104. package/dist/src/dht/discovery/DiscoverySession.js +116 -0
  105. package/dist/src/dht/discovery/DiscoverySession.js.map +1 -0
  106. package/dist/src/dht/discovery/PeerDiscovery.d.ts +42 -0
  107. package/dist/src/dht/discovery/PeerDiscovery.js +157 -0
  108. package/dist/src/dht/discovery/PeerDiscovery.js.map +1 -0
  109. package/dist/src/dht/find/RecursiveFindSession.d.ts +46 -0
  110. package/dist/src/dht/find/RecursiveFindSession.js +142 -0
  111. package/dist/src/dht/find/RecursiveFindSession.js.map +1 -0
  112. package/dist/src/dht/find/RecursiveFinder.d.ts +54 -0
  113. package/dist/src/dht/find/RecursiveFinder.js +180 -0
  114. package/dist/src/dht/find/RecursiveFinder.js.map +1 -0
  115. package/dist/src/dht/find/RemoteRecursiveFindSession.d.ts +6 -0
  116. package/dist/src/dht/find/RemoteRecursiveFindSession.js +25 -0
  117. package/dist/src/dht/find/RemoteRecursiveFindSession.js.map +1 -0
  118. package/dist/src/dht/routing/DuplicateDetector.d.ts +13 -0
  119. package/dist/src/dht/routing/DuplicateDetector.js +41 -0
  120. package/dist/src/dht/routing/DuplicateDetector.js.map +1 -0
  121. package/dist/src/dht/routing/RemoteRouter.d.ts +8 -0
  122. package/dist/src/dht/routing/RemoteRouter.js +106 -0
  123. package/dist/src/dht/routing/RemoteRouter.js.map +1 -0
  124. package/dist/src/dht/routing/Router.d.ts +60 -0
  125. package/dist/src/dht/routing/Router.js +207 -0
  126. package/dist/src/dht/routing/Router.js.map +1 -0
  127. package/dist/src/dht/routing/RoutingSession.d.ts +42 -0
  128. package/dist/src/dht/routing/RoutingSession.js +178 -0
  129. package/dist/src/dht/routing/RoutingSession.js.map +1 -0
  130. package/dist/src/dht/store/DataStore.d.ts +45 -0
  131. package/dist/src/dht/store/DataStore.js +244 -0
  132. package/dist/src/dht/store/DataStore.js.map +1 -0
  133. package/dist/src/dht/store/LocalDataStore.d.ts +19 -0
  134. package/dist/src/dht/store/LocalDataStore.js +104 -0
  135. package/dist/src/dht/store/LocalDataStore.js.map +1 -0
  136. package/dist/src/dht/store/RemoteStore.d.ts +8 -0
  137. package/dist/src/dht/store/RemoteStore.js +44 -0
  138. package/dist/src/dht/store/RemoteStore.js.map +1 -0
  139. package/dist/src/exports.d.ts +19 -0
  140. package/dist/src/exports.js +41 -0
  141. package/dist/src/exports.js.map +1 -0
  142. package/dist/src/helpers/AddressTools.d.ts +2 -0
  143. package/dist/src/helpers/AddressTools.js +31 -0
  144. package/dist/src/helpers/AddressTools.js.map +1 -0
  145. package/dist/src/helpers/PeerID.d.ts +25 -0
  146. package/dist/src/helpers/PeerID.js +84 -0
  147. package/dist/src/helpers/PeerID.js.map +1 -0
  148. package/dist/src/helpers/UUID.d.ts +7 -0
  149. package/dist/src/helpers/UUID.js +32 -0
  150. package/dist/src/helpers/UUID.js.map +1 -0
  151. package/dist/src/helpers/debugHelpers.d.ts +3 -0
  152. package/dist/src/helpers/debugHelpers.js +11 -0
  153. package/dist/src/helpers/debugHelpers.js.map +1 -0
  154. package/dist/src/helpers/errors.d.ts +72 -0
  155. package/dist/src/helpers/errors.js +95 -0
  156. package/dist/src/helpers/errors.js.map +1 -0
  157. package/dist/src/helpers/peerIdFromPeerDescriptor.d.ts +5 -0
  158. package/dist/src/helpers/peerIdFromPeerDescriptor.js +17 -0
  159. package/dist/src/helpers/peerIdFromPeerDescriptor.js.map +1 -0
  160. package/dist/src/helpers/protoClasses.d.ts +2 -0
  161. package/dist/src/helpers/protoClasses.js +35 -0
  162. package/dist/src/helpers/protoClasses.js.map +1 -0
  163. package/dist/src/helpers/protoToString.d.ts +2 -0
  164. package/dist/src/helpers/protoToString.js +20 -0
  165. package/dist/src/helpers/protoToString.js.map +1 -0
  166. package/dist/src/proto/google/protobuf/any.d.ts +173 -0
  167. package/dist/src/proto/google/protobuf/any.js +155 -0
  168. package/dist/src/proto/google/protobuf/any.js.map +1 -0
  169. package/dist/src/proto/google/protobuf/empty.d.ts +32 -0
  170. package/dist/src/proto/google/protobuf/empty.js +34 -0
  171. package/dist/src/proto/google/protobuf/empty.js.map +1 -0
  172. package/dist/src/proto/google/protobuf/timestamp.d.ts +149 -0
  173. package/dist/src/proto/google/protobuf/timestamp.js +136 -0
  174. package/dist/src/proto/google/protobuf/timestamp.js.map +1 -0
  175. package/dist/src/proto/packages/dht/protos/DhtRpc.client.d.ts +320 -0
  176. package/dist/src/proto/packages/dht/protos/DhtRpc.client.js +245 -0
  177. package/dist/src/proto/packages/dht/protos/DhtRpc.client.js.map +1 -0
  178. package/dist/src/proto/packages/dht/protos/DhtRpc.d.ts +1089 -0
  179. package/dist/src/proto/packages/dht/protos/DhtRpc.js +710 -0
  180. package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +1 -0
  181. package/dist/src/proto/packages/dht/protos/DhtRpc.server.d.ts +145 -0
  182. package/dist/src/proto/packages/dht/protos/DhtRpc.server.js +3 -0
  183. package/dist/src/proto/packages/dht/protos/DhtRpc.server.js.map +1 -0
  184. package/dist/src/proto/packages/proto-rpc/protos/ProtoRpc.d.ts +87 -0
  185. package/dist/src/proto/packages/proto-rpc/protos/ProtoRpc.js +66 -0
  186. package/dist/src/proto/packages/proto-rpc/protos/ProtoRpc.js.map +1 -0
  187. package/dist/src/proto/tests.d.ts +39 -0
  188. package/dist/src/proto/tests.js +34 -0
  189. package/dist/src/proto/tests.js.map +1 -0
  190. package/dist/src/rpc-protocol/DhtCallContext.d.ts +12 -0
  191. package/dist/src/rpc-protocol/DhtCallContext.js +8 -0
  192. package/dist/src/rpc-protocol/DhtCallContext.js.map +1 -0
  193. package/dist/src/rpc-protocol/DhtRpcOptions.d.ts +8 -0
  194. package/dist/src/rpc-protocol/DhtRpcOptions.js +3 -0
  195. package/dist/src/rpc-protocol/DhtRpcOptions.js.map +1 -0
  196. package/dist/src/transport/ITransport.d.ts +22 -0
  197. package/dist/src/transport/ITransport.js +3 -0
  198. package/dist/src/transport/ITransport.js.map +1 -0
  199. package/dist/src/transport/ListeningRpcCommunicator.d.ts +6 -0
  200. package/dist/src/transport/ListeningRpcCommunicator.js +14 -0
  201. package/dist/src/transport/ListeningRpcCommunicator.js.map +1 -0
  202. package/dist/src/transport/RoutingRpcCommunicator.d.ts +8 -0
  203. package/dist/src/transport/RoutingRpcCommunicator.js +52 -0
  204. package/dist/src/transport/RoutingRpcCommunicator.js.map +1 -0
  205. package/jest.config.js +2 -0
  206. package/karma.config.js +20 -0
  207. package/package.json +64 -0
  208. package/proto.sh +3 -0
  209. package/protos/DhtRpc.proto +330 -0
  210. package/protos/tests.proto +16 -0
  211. package/src/connection/Connection.ts +23 -0
  212. package/src/connection/ConnectionLockHandler.ts +105 -0
  213. package/src/connection/ConnectionManager.ts +676 -0
  214. package/src/connection/ConnectivityChecker.ts +173 -0
  215. package/src/connection/Handshaker.ts +92 -0
  216. package/src/connection/IConnection.ts +47 -0
  217. package/src/connection/IConnectionSource.ts +6 -0
  218. package/src/connection/ManagedConnection.ts +398 -0
  219. package/src/connection/ManagedWebRtcConnection.ts +27 -0
  220. package/src/connection/RemoteConnectionLocker.ts +88 -0
  221. package/src/connection/Simulator/Simulator.ts +399 -0
  222. package/src/connection/Simulator/SimulatorConnection.ts +137 -0
  223. package/src/connection/Simulator/SimulatorConnector.ts +104 -0
  224. package/src/connection/Simulator/SimulatorTransport.ts +9 -0
  225. package/src/connection/Simulator/pings.ts +42 -0
  226. package/src/connection/WebRTC/BrowserWebRtcConnection.ts +227 -0
  227. package/src/connection/WebRTC/IWebRtcConnection.ts +24 -0
  228. package/src/connection/WebRTC/NodeWebRtcConnection.ts +256 -0
  229. package/src/connection/WebRTC/RemoteWebrtcConnector.ts +93 -0
  230. package/src/connection/WebRTC/WebRtcConnector.ts +306 -0
  231. package/src/connection/WebRTC/iceServerAsString.ts +15 -0
  232. package/src/connection/WebSocket/ClientWebSocket.ts +118 -0
  233. package/src/connection/WebSocket/RemoteWebSocketConnector.ts +49 -0
  234. package/src/connection/WebSocket/ServerWebSocket.ts +119 -0
  235. package/src/connection/WebSocket/WebSocketConnector.ts +264 -0
  236. package/src/connection/WebSocket/WebSocketServer.ts +97 -0
  237. package/src/dht/DhtNode.ts +776 -0
  238. package/src/dht/DhtPeer.ts +96 -0
  239. package/src/dht/ExternalApi.ts +29 -0
  240. package/src/dht/RemoteExternalApi.ts +25 -0
  241. package/src/dht/contact/Contact.ts +36 -0
  242. package/src/dht/contact/RandomContactList.ts +92 -0
  243. package/src/dht/contact/Remote.ts +40 -0
  244. package/src/dht/contact/SortedContactList.ts +196 -0
  245. package/src/dht/discovery/DiscoverySession.ts +150 -0
  246. package/src/dht/discovery/PeerDiscovery.ts +162 -0
  247. package/src/dht/find/RecursiveFindSession.ts +178 -0
  248. package/src/dht/find/RecursiveFinder.ts +272 -0
  249. package/src/dht/find/RemoteRecursiveFindSession.ts +33 -0
  250. package/src/dht/routing/DuplicateDetector.ts +53 -0
  251. package/src/dht/routing/RemoteRouter.ts +115 -0
  252. package/src/dht/routing/Router.ts +266 -0
  253. package/src/dht/routing/RoutingSession.ts +222 -0
  254. package/src/dht/store/DataStore.ts +321 -0
  255. package/src/dht/store/LocalDataStore.ts +114 -0
  256. package/src/dht/store/RemoteStore.ts +58 -0
  257. package/src/exports.ts +19 -0
  258. package/src/helpers/AddressTools.ts +26 -0
  259. package/src/helpers/PeerID.ts +95 -0
  260. package/src/helpers/UUID.ts +30 -0
  261. package/src/helpers/debugHelpers.ts +9 -0
  262. package/src/helpers/errors.ts +49 -0
  263. package/src/helpers/peerIdFromPeerDescriptor.ts +14 -0
  264. package/src/helpers/protoClasses.ts +63 -0
  265. package/src/helpers/protoToString.ts +21 -0
  266. package/src/proto/google/protobuf/any.ts +319 -0
  267. package/src/proto/google/protobuf/empty.ts +84 -0
  268. package/src/proto/google/protobuf/timestamp.ts +281 -0
  269. package/src/proto/packages/dht/protos/DhtRpc.client.ts +373 -0
  270. package/src/proto/packages/dht/protos/DhtRpc.server.ts +148 -0
  271. package/src/proto/packages/dht/protos/DhtRpc.ts +1399 -0
  272. package/src/proto/packages/proto-rpc/protos/ProtoRpc.ts +108 -0
  273. package/src/proto/tests.ts +52 -0
  274. package/src/rpc-protocol/DhtCallContext.ts +15 -0
  275. package/src/rpc-protocol/DhtRpcOptions.ts +9 -0
  276. package/src/transport/ITransport.ts +31 -0
  277. package/src/transport/ListeningRpcCommunicator.ts +14 -0
  278. package/src/transport/RoutingRpcCommunicator.ts +59 -0
  279. package/src/types/glogal.d.ts +1 -0
  280. package/src/types/textencoding.d.ts +7 -0
  281. package/test/RandomGraphSimulation.ts +52 -0
  282. package/test/benchmark/KademliaCorrectness.test.ts +115 -0
  283. package/test/benchmark/RecursiveFind.test.ts +87 -0
  284. package/test/benchmark/any.test.ts +28 -0
  285. package/test/benchmark/kademlia-simulation/Contact.ts +32 -0
  286. package/test/benchmark/kademlia-simulation/KademliaSimulation.ts +94 -0
  287. package/test/benchmark/kademlia-simulation/SimulationNode.ts +125 -0
  288. package/test/data/generateGroundTruthData.ts +70 -0
  289. package/test/end-to-end/Layer0-Layer1.test.ts +87 -0
  290. package/test/end-to-end/Layer0.test.ts +60 -0
  291. package/test/end-to-end/Layer0MixedConnectionTypes.test.ts +94 -0
  292. package/test/end-to-end/Layer0WebRTC-Layer1.test.ts +134 -0
  293. package/test/end-to-end/Layer0WebRTC.test.ts +98 -0
  294. package/test/end-to-end/Layer1-Scale-WebRTC.test.ts +69 -0
  295. package/test/end-to-end/Layer1-Scale-WebSocket.test.ts +73 -0
  296. package/test/end-to-end/WebSocketConnectionRequest.test.ts +62 -0
  297. package/test/integration/ConnectionLocking.test.ts +166 -0
  298. package/test/integration/ConnectionManager.test.ts +291 -0
  299. package/test/integration/DhtNodeExternalAPI.test.ts +43 -0
  300. package/test/integration/DhtPeer.test.ts +73 -0
  301. package/test/integration/DhtRpc.test.ts +131 -0
  302. package/test/integration/DhtWithMockConnectionLatencies.test.ts +46 -0
  303. package/test/integration/DhtWithMockConnections.test.ts +46 -0
  304. package/test/integration/DhtWithRealConnectionLatencies.test.ts +47 -0
  305. package/test/integration/Layer1-scale.test.ts +200 -0
  306. package/test/integration/MigrateData.test.ts +203 -0
  307. package/test/integration/Mock-Layer1-Layer0.test.ts +106 -0
  308. package/test/integration/MultipleEntryPointJoining.test.ts +105 -0
  309. package/test/integration/RecursiveFind.test.ts +50 -0
  310. package/test/integration/RemoteRouter.test.ts +83 -0
  311. package/test/integration/RemoteStore.test.ts +66 -0
  312. package/test/integration/RouteMessage.test.ts +254 -0
  313. package/test/integration/RpcErrors.test.ts +153 -0
  314. package/test/integration/ScaleDownDht.test.ts +66 -0
  315. package/test/integration/SimultaneousConnections.test.ts +308 -0
  316. package/test/integration/Store.test.ts +72 -0
  317. package/test/integration/StoreAndDelete.test.ts +93 -0
  318. package/test/integration/StoreOnDhtWithTwoNodes.test.ts +71 -0
  319. package/test/integration/WebRtcConnectionManagement.test.ts +205 -0
  320. package/test/integration/WebRtcConnectorRpc.test.ts +145 -0
  321. package/test/integration/WebSocket.test.ts +64 -0
  322. package/test/integration/WebSocketConnectionManagement.test.ts +131 -0
  323. package/test/integration/WebSocketConnectorRpc.test.ts +86 -0
  324. package/test/kademlia-simulation/data/nodeids.json +13002 -0
  325. package/test/kademlia-simulation/data/orderedneighbors.json +1001 -0
  326. package/test/unit/AddressTools.test.ts +40 -0
  327. package/test/unit/DuplicateDetector.test.ts +29 -0
  328. package/test/unit/LocalDataStore.test.ts +107 -0
  329. package/test/unit/PeerID.test.ts +22 -0
  330. package/test/unit/ProtobufMessage.test.ts +21 -0
  331. package/test/unit/RandomContactList.test.ts +87 -0
  332. package/test/unit/RecursiveFinder.test.ts +112 -0
  333. package/test/unit/Router.test.ts +124 -0
  334. package/test/unit/SortedContactList.test.ts +127 -0
  335. package/test/unit/UUID.test.ts +49 -0
  336. package/test/unit/WebSocketServer.test.ts +42 -0
  337. package/test/utils/mock/RecursiveFinder.ts +19 -0
  338. package/test/utils/mock/Router.ts +53 -0
  339. package/test/utils/mock/Transport.ts +26 -0
  340. package/test/utils/utils.ts +311 -0
  341. package/tsconfig.browser.json +15 -0
  342. package/tsconfig.jest.json +19 -0
  343. package/tsconfig.json +3 -0
  344. package/tsconfig.node.json +18 -0
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DhtPeer = void 0;
4
+ const uuid_1 = require("uuid");
5
+ const utils_1 = require("@streamr/utils");
6
+ const Remote_1 = require("./contact/Remote");
7
+ const logger = new utils_1.Logger(module);
8
+ class DhtPeer extends Remote_1.Remote {
9
+ constructor(ownPeerDescriptor, peerDescriptor, client, serviceId) {
10
+ super(ownPeerDescriptor, peerDescriptor, client, serviceId);
11
+ this.id = this.peerId.value;
12
+ this.vectorClock = DhtPeer.counter++;
13
+ }
14
+ async getClosestPeers(kademliaId) {
15
+ logger.trace(`Requesting getClosestPeers on ${this.serviceId} from ${this.peerId.toKey()}`);
16
+ const request = {
17
+ kademliaId: kademliaId,
18
+ requestId: (0, uuid_1.v4)()
19
+ };
20
+ const options = {
21
+ sourceDescriptor: this.ownPeerDescriptor,
22
+ targetDescriptor: this.peerDescriptor
23
+ };
24
+ try {
25
+ const peers = await this.client.getClosestPeers(request, options);
26
+ return peers.peers;
27
+ }
28
+ catch (err) {
29
+ logger.trace(`getClosestPeers error ${this.serviceId}`, { err });
30
+ throw err;
31
+ }
32
+ }
33
+ async ping() {
34
+ logger.trace(`Requesting ping on ${this.serviceId} from ${this.peerId.toKey()}`);
35
+ const request = {
36
+ requestId: (0, uuid_1.v4)()
37
+ };
38
+ const options = {
39
+ sourceDescriptor: this.ownPeerDescriptor,
40
+ targetDescriptor: this.peerDescriptor,
41
+ timeout: 10000
42
+ };
43
+ try {
44
+ const pong = await this.client.ping(request, options);
45
+ if (pong.requestId === request.requestId) {
46
+ return true;
47
+ }
48
+ }
49
+ catch (err) {
50
+ logger.debug(`ping failed on ${this.serviceId} to ${this.peerId.toKey()}: ${err}`);
51
+ }
52
+ return false;
53
+ }
54
+ leaveNotice() {
55
+ logger.trace(`Sending leaveNotice on ${this.serviceId} from ${this.peerId.toKey()}`);
56
+ const request = {
57
+ serviceId: this.serviceId
58
+ };
59
+ const options = {
60
+ sourceDescriptor: this.ownPeerDescriptor,
61
+ targetDescriptor: this.peerDescriptor,
62
+ notification: true
63
+ };
64
+ this.client.leaveNotice(request, options).catch((e) => {
65
+ logger.trace('Failed to send leaveNotice' + e);
66
+ });
67
+ }
68
+ getPeerDescriptor() {
69
+ return this.peerDescriptor;
70
+ }
71
+ }
72
+ exports.DhtPeer = DhtPeer;
73
+ DhtPeer.counter = 0;
74
+ //# sourceMappingURL=DhtPeer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DhtPeer.js","sourceRoot":"","sources":["../../../src/dht/DhtPeer.ts"],"names":[],"mappings":";;;AAOA,+BAAyB;AAEzB,0CAAuC;AAEvC,6CAAyC;AAEzC,MAAM,MAAM,GAAG,IAAI,cAAM,CAAC,MAAM,CAAC,CAAA;AAQjC,MAAa,OAAQ,SAAQ,eAA4B;IAIrD,YACI,iBAAiC,EACjC,cAA8B,EAC9B,MAA4C,EAC5C,SAAiB;QAEjB,KAAK,CAAC,iBAAiB,EAAE,cAAc,EAAE,MAAM,EAAE,SAAS,CAAC,CAAA;QAC3D,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,MAAM,CA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IAAI,IAAI,CAAC,SAAS,KAAK,OAAO,CAAC,SAAS,EAAE;gBACtC,OAAO,IAAI,CAAA;aACd;SACJ;QAAC,OAAO,GAAG,EAAE;YACV,MAAM,CAAC,KAAK,CAAC,kBAAkB,IAAI,CAAC,SAAS,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,KAAK,GAAG,EAAE,CAAC,CAAA;SACrF;QACD,OAAO,KAAK,CAAA;IAChB,CAAC;IAED,WAAW;QACP,MAAM,CAAC,KAAK,CAAC,0BAA0B,IAAI,CAAC,SAAS,SAAS,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA;QACpF,MAAM,OAAO,GAAgB;YACzB,SAAS,EAAE,IAAI,CAAC,SAAS;SAC5B,CAAA;QACD,MAAM,OAAO,GAAkB;YAC3B,gBAAgB,EAAE,IAAI,CAAC,iBAAiB;YACxC,gBAAgB,EAAE,IAAI,CAAC,cAAc;YACrC,YAAY,EAAE,IAAI;SACrB,CAAA;QACD,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;YAClD,MAAM,CAAC,KAAK,CAAC,4BAA4B,GAAG,CAAC,CAAC,CAAA;QAClD,CAAC,CAAC,CAAA;IACN,CAAC;IAED,iBAAiB;QACb,OAAO,IAAI,CAAC,cAAc,CAAA;IAC9B,CAAC;;AAxEL,0BA0EC;AAzEkB,eAAO,GAAG,CAAC,CAAA"}
@@ -0,0 +1,8 @@
1
+ import { DhtNode } from '../exports';
2
+ import { FindDataRequest, FindDataResponse } from '../proto/packages/dht/protos/DhtRpc';
3
+ import { ServerCallContext } from '@protobuf-ts/runtime-rpc';
4
+ export declare class ExternalApi {
5
+ private readonly dhtNode;
6
+ constructor(dhtNode: DhtNode);
7
+ findData(findDataRequest: FindDataRequest, _context: ServerCallContext): Promise<FindDataResponse>;
8
+ }
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ExternalApi = void 0;
4
+ const DhtRpc_1 = require("../proto/packages/dht/protos/DhtRpc");
5
+ class ExternalApi {
6
+ constructor(dhtNode) {
7
+ this.dhtNode = dhtNode;
8
+ const rpcCommunicator = this.dhtNode.getRpcCommunicator();
9
+ rpcCommunicator.registerRpcMethod(DhtRpc_1.FindDataRequest, DhtRpc_1.FindDataResponse, 'findData', (req, context) => this.findData(req, context), { timeout: 15000 });
10
+ }
11
+ // IDHTRpcService method for external findRecursive calls
12
+ async findData(findDataRequest, _context) {
13
+ const result = await this.dhtNode.startRecursiveFind(findDataRequest.kademliaId, DhtRpc_1.FindMode.DATA, findDataRequest.requestor);
14
+ if (result.dataEntries) {
15
+ return DhtRpc_1.FindDataResponse.create({ dataEntries: result.dataEntries });
16
+ }
17
+ else {
18
+ return DhtRpc_1.FindDataResponse.create({
19
+ dataEntries: [],
20
+ error: 'Could not find data with the given key'
21
+ });
22
+ }
23
+ }
24
+ }
25
+ exports.ExternalApi = ExternalApi;
26
+ //# sourceMappingURL=ExternalApi.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExternalApi.js","sourceRoot":"","sources":["../../../src/dht/ExternalApi.ts"],"names":[],"mappings":";;;AACA,gEAAiG;AAGjG,MAAa,WAAW;IAIpB,YAAY,OAAgB;QACxB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,MAAM,eAAe,GAAG,IAAI,CAAC,OAAO,CAAC,kBAAmB,EAAE,CAAA;QAC1D,eAAe,CAAC,iBAAiB,CAAC,wBAAe,EAAE,yBAAgB,EAAE,UAAU,EAC3E,CAAC,GAAoB,EAAE,OAAO,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAC,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAA;IAC3F,CAAC;IAED,yDAAyD;IACzD,KAAK,CAAC,QAAQ,CAAC,eAAgC,EAAE,QAA2B;QACxE,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,kBAAkB,CAAC,eAAe,CAAC,UAAU,EAAE,iBAAQ,CAAC,IAAI,EAAE,eAAe,CAAC,SAAS,CAAC,CAAA;QAC1H,IAAI,MAAM,CAAC,WAAW,EAAE;YACpB,OAAO,yBAAgB,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,MAAM,CAAC,WAAW,EAAE,CAAC,CAAA;SACtE;aAAM;YACH,OAAO,yBAAgB,CAAC,MAAM,CAAC;gBAC3B,WAAW,EAAE,EAAE;gBACf,KAAK,EAAE,wCAAwC;aAClD,CAAC,CAAA;SACL;IACL,CAAC;CAEJ;AAxBD,kCAwBC"}
@@ -0,0 +1,6 @@
1
+ import { DataEntry } from '../proto/packages/dht/protos/DhtRpc';
2
+ import { IExternalApiServiceClient } from '../proto/packages/dht/protos/DhtRpc.client';
3
+ import { Remote } from './contact/Remote';
4
+ export declare class RemoteExternalApi extends Remote<IExternalApiServiceClient> {
5
+ findData(idToFind: Uint8Array): Promise<DataEntry[]>;
6
+ }
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RemoteExternalApi = void 0;
4
+ const Remote_1 = require("./contact/Remote");
5
+ class RemoteExternalApi extends Remote_1.Remote {
6
+ async findData(idToFind) {
7
+ const request = {
8
+ kademliaId: idToFind,
9
+ requestor: this.ownPeerDescriptor,
10
+ };
11
+ const options = {
12
+ sourceDescriptor: this.ownPeerDescriptor,
13
+ targetDescriptor: this.peerDescriptor,
14
+ timeout: 10000
15
+ };
16
+ try {
17
+ const data = await this.client.findData(request, options);
18
+ return data.dataEntries;
19
+ }
20
+ catch (err) {
21
+ return [];
22
+ }
23
+ }
24
+ }
25
+ exports.RemoteExternalApi = RemoteExternalApi;
26
+ //# sourceMappingURL=RemoteExternalApi.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RemoteExternalApi.js","sourceRoot":"","sources":["../../../src/dht/RemoteExternalApi.ts"],"names":[],"mappings":";;;AAGA,6CAAyC;AAEzC,MAAa,iBAAkB,SAAQ,eAAiC;IAEpE,KAAK,CAAC,QAAQ,CAAC,QAAoB;QAC/B,MAAM,OAAO,GAAoB;YAC7B,UAAU,EAAE,QAAQ;YACpB,SAAS,EAAE,IAAI,CAAC,iBAAiB;SACpC,CAAA;QACD,MAAM,OAAO,GAAkB;YAC3B,gBAAgB,EAAE,IAAI,CAAC,iBAAiB;YACxC,gBAAgB,EAAE,IAAI,CAAC,cAAc;YACrC,OAAO,EAAE,KAAK;SACjB,CAAA;QACD,IAAI;YACA,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;YACzD,OAAO,IAAI,CAAC,WAAW,CAAA;SAC1B;QAAC,OAAO,GAAG,EAAE;YACV,OAAO,EAAE,CAAA;SACZ;IACL,CAAC;CACJ;AAnBD,8CAmBC"}
@@ -0,0 +1,22 @@
1
+ import { PeerID } from '../../helpers/PeerID';
2
+ import { PeerDescriptor } from '../../proto/packages/dht/protos/DhtRpc';
3
+ export declare class ContactState<TContact> {
4
+ contacted: boolean;
5
+ active: boolean;
6
+ contact: TContact;
7
+ constructor(contact: TContact);
8
+ }
9
+ export interface IContact {
10
+ getPeerId: () => PeerID;
11
+ getPeerDescriptor: () => PeerDescriptor;
12
+ }
13
+ export interface Events {
14
+ contactRemoved: (removedDescriptor: PeerDescriptor, closestDescriptors: PeerDescriptor[]) => void;
15
+ newContact: (newDescriptor: PeerDescriptor, closestDescriptors: PeerDescriptor[]) => void;
16
+ }
17
+ export declare class Contact implements IContact {
18
+ private peerDescriptor;
19
+ constructor(peerDescriptor: PeerDescriptor);
20
+ getPeerDescriptor(): PeerDescriptor;
21
+ getPeerId(): PeerID;
22
+ }
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Contact = exports.ContactState = void 0;
4
+ const peerIdFromPeerDescriptor_1 = require("../../helpers/peerIdFromPeerDescriptor");
5
+ class ContactState {
6
+ constructor(contact) {
7
+ this.contacted = false;
8
+ this.active = false;
9
+ this.contact = contact;
10
+ }
11
+ }
12
+ exports.ContactState = ContactState;
13
+ class Contact {
14
+ constructor(peerDescriptor) {
15
+ this.peerDescriptor = peerDescriptor;
16
+ }
17
+ getPeerDescriptor() {
18
+ return this.peerDescriptor;
19
+ }
20
+ getPeerId() {
21
+ return (0, peerIdFromPeerDescriptor_1.peerIdFromPeerDescriptor)(this.peerDescriptor);
22
+ }
23
+ }
24
+ exports.Contact = Contact;
25
+ //# sourceMappingURL=Contact.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Contact.js","sourceRoot":"","sources":["../../../../src/dht/contact/Contact.ts"],"names":[],"mappings":";;;AAEA,qFAAiF;AAEjF,MAAa,YAAY;IAKrB,YAAY,OAAiB;QAJtB,cAAS,GAAG,KAAK,CAAA;QACjB,WAAM,GAAG,KAAK,CAAA;QAIjB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IAC1B,CAAC;CACJ;AARD,oCAQC;AASD,MAAa,OAAO;IAGhB,YAAY,cAA8B;QACtC,IAAI,CAAC,cAAc,GAAG,cAAc,CAAA;IACxC,CAAC;IAEM,iBAAiB;QACpB,OAAO,IAAI,CAAC,cAAc,CAAA;IAC9B,CAAC;IAEM,SAAS;QACZ,OAAO,IAAA,mDAAwB,EAAC,IAAI,CAAC,cAAc,CAAC,CAAA;IACxD,CAAC;CACJ;AAdD,0BAcC"}
@@ -0,0 +1,20 @@
1
+ import { Events, IContact, ContactState } from './Contact';
2
+ import EventEmitter from 'eventemitter3';
3
+ import { PeerID } from '../../helpers/PeerID';
4
+ export declare class RandomContactList<Contact extends IContact> extends EventEmitter<Events> {
5
+ private contactsById;
6
+ private contactIds;
7
+ private ownId;
8
+ private maxSize;
9
+ private randomness;
10
+ private getContactsLimit;
11
+ constructor(ownId: PeerID, maxSize: number, randomness?: number, getContactsLimit?: number);
12
+ addContact(contact: Contact): void;
13
+ addContacts(contacts: Contact[]): void;
14
+ removeContact(id: PeerID): boolean;
15
+ getSize(): number;
16
+ getContact(id: PeerID): ContactState<Contact>;
17
+ getContacts(limit?: number): Contact[];
18
+ clear(): void;
19
+ stop(): void;
20
+ }
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.RandomContactList = void 0;
7
+ const Contact_1 = require("./Contact");
8
+ const eventemitter3_1 = __importDefault(require("eventemitter3"));
9
+ class RandomContactList extends eventemitter3_1.default {
10
+ constructor(ownId, maxSize, randomness = 0.20, getContactsLimit = 20) {
11
+ super();
12
+ this.contactsById = new Map();
13
+ this.contactIds = [];
14
+ this.randomness = 0.20;
15
+ this.getContactsLimit = 20;
16
+ this.ownId = ownId;
17
+ this.maxSize = maxSize;
18
+ this.randomness = randomness;
19
+ this.getContactsLimit = getContactsLimit;
20
+ }
21
+ addContact(contact) {
22
+ if (this.ownId.equals(contact.getPeerId())) {
23
+ return;
24
+ }
25
+ if (!this.contactsById.has(contact.getPeerId().toKey())) {
26
+ const roll = Math.random();
27
+ if (roll < this.randomness) {
28
+ if (this.getSize() === this.maxSize && this.getSize() > 0) {
29
+ const toRemove = this.contactIds[0];
30
+ this.removeContact(toRemove);
31
+ }
32
+ this.contactIds.push(contact.getPeerId());
33
+ this.contactsById.set(contact.getPeerId().toKey(), new Contact_1.ContactState(contact));
34
+ this.emit('newContact', contact.getPeerDescriptor(), this.getContacts().map((contact) => contact.getPeerDescriptor()));
35
+ }
36
+ }
37
+ }
38
+ addContacts(contacts) {
39
+ contacts.forEach((contact) => this.addContact(contact));
40
+ }
41
+ removeContact(id) {
42
+ if (this.contactsById.has(id.toKey())) {
43
+ const removedDescriptor = this.contactsById.get(id.toKey()).contact.getPeerDescriptor();
44
+ const index = this.contactIds.indexOf(id);
45
+ this.contactIds.splice(index, 1);
46
+ this.contactsById.delete(id.toKey());
47
+ this.emit('contactRemoved', removedDescriptor, this.getContacts().map((contact) => contact.getPeerDescriptor()));
48
+ return true;
49
+ }
50
+ return false;
51
+ }
52
+ getSize() {
53
+ return this.contactIds.length;
54
+ }
55
+ getContact(id) {
56
+ return this.contactsById.get(id.toKey());
57
+ }
58
+ getContacts(limit = this.getContactsLimit) {
59
+ const ret = [];
60
+ this.contactIds.forEach((contactId) => {
61
+ const contact = this.contactsById.get(contactId.toKey());
62
+ if (contact) {
63
+ ret.push(contact.contact);
64
+ }
65
+ });
66
+ return ret.splice(0, limit);
67
+ }
68
+ clear() {
69
+ this.contactsById.clear();
70
+ this.contactIds = [];
71
+ }
72
+ stop() {
73
+ this.removeAllListeners();
74
+ this.clear();
75
+ }
76
+ }
77
+ exports.RandomContactList = RandomContactList;
78
+ //# sourceMappingURL=RandomContactList.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RandomContactList.js","sourceRoot":"","sources":["../../../../src/dht/contact/RandomContactList.ts"],"names":[],"mappings":";;;;;;AAAA,uCAA0D;AAE1D,kEAAwC;AAExC,MAAa,iBAA4C,SAAQ,uBAAoB;IAQjF,YACI,KAAa,EACb,OAAe,EACf,UAAU,GAAG,IAAI,EACjB,gBAAgB,GAAG,EAAE;QAErB,KAAK,EAAE,CAAA;QAbH,iBAAY,GAA0C,IAAI,GAAG,EAAE,CAAA;QAC/D,eAAU,GAAa,EAAE,CAAA;QAGzB,eAAU,GAAG,IAAI,CAAA;QACjB,qBAAgB,GAAG,EAAE,CAAA;QASzB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;QAClB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC5B,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAA;IAC5C,CAAC;IAED,UAAU,CAA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AA;IAC/B,CAAC;IAEM,KAAK;QACR,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,CAAA;QACzB,IAAI,CAAC,UAAU,GAAG,EAAE,CAAA;IACxB,CAAC;IAEM,IAAI;QACP,IAAI,CAAC,kBAAkB,EAAE,CAAA;QACzB,IAAI,CAAC,KAAK,EAAE,CAAA;IAChB,CAAC;CACJ;AAvFD,8CAuFC"}
@@ -0,0 +1,15 @@
1
+ import { PeerDescriptor } from '../../proto/packages/dht/protos/DhtRpc';
2
+ import { ProtoRpcClient } from '@streamr/proto-rpc';
3
+ import { PeerID } from '../../helpers/PeerID';
4
+ import { IContact } from './Contact';
5
+ export declare abstract class Remote<T> implements IContact {
6
+ protected readonly peerId: PeerID;
7
+ protected readonly peerDescriptor: PeerDescriptor;
8
+ protected readonly client: ProtoRpcClient<T>;
9
+ protected readonly serviceId: string;
10
+ protected readonly ownPeerDescriptor: PeerDescriptor;
11
+ constructor(ownPeerDescriptor: PeerDescriptor, peerDescriptor: PeerDescriptor, client: ProtoRpcClient<T>, serviceId: string);
12
+ getPeerId(): PeerID;
13
+ getPeerDescriptor(): PeerDescriptor;
14
+ getServiceId(): string;
15
+ }
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Remote = void 0;
4
+ const peerIdFromPeerDescriptor_1 = require("../../helpers/peerIdFromPeerDescriptor");
5
+ class Remote {
6
+ constructor(ownPeerDescriptor, peerDescriptor, client, serviceId) {
7
+ this.ownPeerDescriptor = ownPeerDescriptor;
8
+ this.peerId = (0, peerIdFromPeerDescriptor_1.peerIdFromPeerDescriptor)(peerDescriptor);
9
+ this.peerDescriptor = peerDescriptor;
10
+ this.client = client;
11
+ this.serviceId = serviceId;
12
+ }
13
+ getPeerId() {
14
+ return this.peerId;
15
+ }
16
+ getPeerDescriptor() {
17
+ return this.peerDescriptor;
18
+ }
19
+ getServiceId() {
20
+ return this.serviceId;
21
+ }
22
+ }
23
+ exports.Remote = Remote;
24
+ //# sourceMappingURL=Remote.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Remote.js","sourceRoot":"","sources":["../../../../src/dht/contact/Remote.ts"],"names":[],"mappings":";;;AAEA,qFAAiF;AAIjF,MAAsB,MAAM;IAQxB,YACI,iBAAiC,EACjC,cAA8B,EAC9B,MAAyB,EACzB,SAAiB;QAEjB,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAA;QAC1C,IAAI,CAAC,MAAM,GAAG,IAAA,mDAAwB,EAAC,cAAc,CAAC,CAAA;QACtD,IAAI,CAAC,cAAc,GAAG,cAAc,CAAA;QACpC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;IAC9B,CAAC;IAED,SAAS;QACL,OAAO,IAAI,CAAC,MAAM,CAAA;IACtB,CAAC;IAED,iBAAiB;QACb,OAAO,IAAI,CAAC,cAAc,CAAA;IAC9B,CAAC;IAED,YAAY;QACR,OAAO,IAAI,CAAC,SAAS,CAAA;IACzB,CAAC;CAEJ;AAjCD,wBAiCC"}
@@ -0,0 +1,35 @@
1
+ import { PeerID } from '../../helpers/PeerID';
2
+ import EventEmitter from 'eventemitter3';
3
+ import { Events, IContact, ContactState } from './Contact';
4
+ export declare class SortedContactList<Contact extends IContact> extends EventEmitter<Events> {
5
+ private contactsById;
6
+ private contactIds;
7
+ private ownId;
8
+ private maxSize;
9
+ private getContactsLimit;
10
+ private allowOwnPeerId;
11
+ private peerIdDistanceLimit?;
12
+ private excludedPeerIDs?;
13
+ constructor(ownId: PeerID, maxSize: number, getContactsLimit?: number, allowOwnPeerId?: boolean, peerIdDistanceLimit?: PeerID, excludedPeerIDs?: PeerID[]);
14
+ getClosestContactId(): PeerID;
15
+ getContactIds(): PeerID[];
16
+ addContact(contact: Contact): void;
17
+ addContacts(contacts: Contact[]): void;
18
+ setContacted(contactId: PeerID): void;
19
+ setActive(contactId: PeerID): void;
20
+ getClosestContacts(limit?: number): Contact[];
21
+ getUncontactedContacts(num: number): Contact[];
22
+ getActiveContacts(limit?: number): Contact[];
23
+ compareIds(id1: PeerID, id2: PeerID): number;
24
+ getStringIds(): string[];
25
+ getSize(): number;
26
+ getContact(id: PeerID): ContactState<Contact>;
27
+ removeContact(id: PeerID): boolean;
28
+ hasContact(id: PeerID): boolean;
29
+ isActive(id: PeerID): boolean;
30
+ getAllContacts(): Contact[];
31
+ getMaxSize(): number;
32
+ setAllAsUncontacted(): void;
33
+ clear(): void;
34
+ stop(): void;
35
+ }
@@ -0,0 +1,156 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.SortedContactList = void 0;
7
+ const k_bucket_1 = __importDefault(require("k-bucket"));
8
+ const eventemitter3_1 = __importDefault(require("eventemitter3"));
9
+ const Contact_1 = require("./Contact");
10
+ class SortedContactList extends eventemitter3_1.default {
11
+ constructor(ownId, maxSize, getContactsLimit = 20, allowOwnPeerId = false, peerIdDistanceLimit, excludedPeerIDs) {
12
+ super();
13
+ this.contactsById = new Map();
14
+ this.contactIds = [];
15
+ this.compareIds = this.compareIds.bind(this);
16
+ this.ownId = ownId;
17
+ this.maxSize = maxSize;
18
+ this.getContactsLimit = getContactsLimit;
19
+ this.allowOwnPeerId = allowOwnPeerId;
20
+ this.peerIdDistanceLimit = peerIdDistanceLimit;
21
+ this.excludedPeerIDs = excludedPeerIDs;
22
+ }
23
+ getClosestContactId() {
24
+ return this.contactIds[0];
25
+ }
26
+ getContactIds() {
27
+ return this.contactIds;
28
+ }
29
+ addContact(contact) {
30
+ if (this.excludedPeerIDs
31
+ && this.excludedPeerIDs.some((peerId) => contact.getPeerId().equals(peerId))) {
32
+ return;
33
+ }
34
+ if ((!this.allowOwnPeerId && this.ownId.equals(contact.getPeerId())) ||
35
+ (this.peerIdDistanceLimit !== undefined && this.compareIds(this.peerIdDistanceLimit, contact.getPeerId()) < 0)) {
36
+ return;
37
+ }
38
+ if (!this.contactsById.has(contact.getPeerId().toKey())) {
39
+ if (this.contactIds.length < this.maxSize) {
40
+ this.contactsById.set(contact.getPeerId().toKey(), new Contact_1.ContactState(contact));
41
+ this.contactIds.push(contact.getPeerId());
42
+ this.contactIds.sort(this.compareIds);
43
+ }
44
+ else if (this.compareIds(this.contactIds[this.maxSize - 1], contact.getPeerId()) > 0) {
45
+ const removed = this.contactIds.pop();
46
+ this.contactsById.delete(removed.toKey());
47
+ this.contactsById.set(contact.getPeerId().toKey(), new Contact_1.ContactState(contact));
48
+ this.contactIds.push(contact.getPeerId());
49
+ this.contactIds.sort(this.compareIds);
50
+ this.emit('contactRemoved', contact.getPeerDescriptor(), this.getClosestContacts().map((contact) => contact.getPeerDescriptor()));
51
+ }
52
+ this.emit('newContact', contact.getPeerDescriptor(), this.getClosestContacts().map((contact) => contact.getPeerDescriptor()));
53
+ }
54
+ }
55
+ addContacts(contacts) {
56
+ contacts.forEach((contact) => this.addContact(contact));
57
+ }
58
+ setContacted(contactId) {
59
+ if (this.contactsById.has(contactId.toKey())) {
60
+ this.contactsById.get(contactId.toKey()).contacted = true;
61
+ }
62
+ }
63
+ setActive(contactId) {
64
+ if (this.contactsById.has(contactId.toKey())) {
65
+ this.contactsById.get(contactId.toKey()).active = true;
66
+ }
67
+ }
68
+ getClosestContacts(limit = this.getContactsLimit) {
69
+ const ret = [];
70
+ this.contactIds.forEach((contactId) => {
71
+ const contact = this.contactsById.get(contactId.toKey());
72
+ if (contact) {
73
+ ret.push(contact.contact);
74
+ }
75
+ });
76
+ return ret.splice(0, limit);
77
+ }
78
+ getUncontactedContacts(num) {
79
+ const ret = [];
80
+ for (const contactId of this.contactIds) {
81
+ const contact = this.contactsById.get(contactId.toKey());
82
+ if (contact && !contact.contacted) {
83
+ ret.push(contact.contact);
84
+ if (ret.length >= num) {
85
+ return ret;
86
+ }
87
+ }
88
+ }
89
+ return ret;
90
+ }
91
+ getActiveContacts(limit) {
92
+ const ret = [];
93
+ this.contactIds.forEach((contactId) => {
94
+ const contact = this.contactsById.get(contactId.toKey());
95
+ if (contact && contact.active) {
96
+ ret.push(contact.contact);
97
+ }
98
+ });
99
+ if (limit !== undefined) {
100
+ return ret.splice(0, limit);
101
+ }
102
+ else {
103
+ return ret;
104
+ }
105
+ }
106
+ compareIds(id1, id2) {
107
+ const distance1 = k_bucket_1.default.distance(this.ownId.value, id1.value);
108
+ const distance2 = k_bucket_1.default.distance(this.ownId.value, id2.value);
109
+ return distance1 - distance2;
110
+ }
111
+ getStringIds() {
112
+ return this.contactIds.map((peerId) => peerId.toKey());
113
+ }
114
+ getSize() {
115
+ return this.contactIds.length;
116
+ }
117
+ getContact(id) {
118
+ return this.contactsById.get(id.toKey());
119
+ }
120
+ removeContact(id) {
121
+ if (this.contactsById.has(id.toKey())) {
122
+ const removedDescriptor = this.contactsById.get(id.toKey()).contact.getPeerDescriptor();
123
+ const index = this.contactIds.indexOf(id);
124
+ this.contactIds.splice(index, 1);
125
+ this.contactsById.delete(id.toKey());
126
+ this.emit('contactRemoved', removedDescriptor, this.getClosestContacts().map((contact) => contact.getPeerDescriptor()));
127
+ return true;
128
+ }
129
+ return false;
130
+ }
131
+ hasContact(id) {
132
+ return this.contactsById.has(id.toKey());
133
+ }
134
+ isActive(id) {
135
+ return this.contactsById.has(id.toKey()) ? this.contactsById.get(id.toKey()).active : false;
136
+ }
137
+ getAllContacts() {
138
+ return this.contactIds.map((peerId) => this.contactsById.get(peerId.toKey()).contact);
139
+ }
140
+ getMaxSize() {
141
+ return this.maxSize;
142
+ }
143
+ setAllAsUncontacted() {
144
+ this.contactsById.forEach((contact) => contact.contacted = false);
145
+ }
146
+ clear() {
147
+ this.contactsById.clear();
148
+ this.contactIds = [];
149
+ }
150
+ stop() {
151
+ this.removeAllListeners();
152
+ this.clear();
153
+ }
154
+ }
155
+ exports.SortedContactList = SortedContactList;
156
+ //# sourceMappingURL=SortedContactList.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SortedContactList.js","sourceRoot":"","sources":["../../../../src/dht/contact/SortedContactList.ts"],"names":[],"mappings":";;;;;;AAAA,wDAA8B;AAE9B,kEAAwC;AACxC,uCAA0D;AAE1D,MAAa,iBAA4C,SAAQ,uBAAoB;IAUjF,YACI,KAAa,EACb,OAAe,EACf,gBAAgB,GAAG,EAAE,EACrB,cAAc,GAAG,KAAK,EACtB,mBAA4B,EAC5B,eAA0B;QAE1B,KAAK,EAAE,CAAA;QAjBH,iBAAY,GAA0C,IAAI,GAAG,EAAE,CAAA;QAC/D,eAAU,GAAa,EAAE,CAAA;QAiB7B,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAC5C,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;QAClB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAA;QACxC,IAAI,CAAC,cAAc,GAAG,cAAc,CAAA;QACpC,IAAI,CAAC,mBAAmB,GAAG,mBAAmB,CAAA;QAC9C,IAAI,CAAC,eAAe,GAAG,eAAe,CAAA;IAC1C,CAAC;IAEM,mBAAmB;QACtB,OAAO,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAA;IAC7B,CAAC;IAEM,aAAa;QAChB,OAAO,IAAI,CAAC,UAAU,CAAA;IAC1B,CAAC;IAEM,UAAU,CAAC,OAAgB;QAC9B,IAAI,IAAI,CAAC,eAAe;eACjB,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE;YAC9E,OAAM;SACT;QAED,IAAI,CAAC,CAAC,IAAI,CAAC,cAAc,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,SA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ages/dht/protos/DhtRpc';
4
+ import { SortedContactList } from '../contact/SortedContactList';
5
+ import { DhtPeer } from '../DhtPeer';
6
+ interface DiscoverySessionConfig {
7
+ bucket: KBucket<DhtPeer>;
8
+ neighborList: SortedContactList<DhtPeer>;
9
+ targetId: Uint8Array;
10
+ ownPeerDescriptor: PeerDescriptor;
11
+ serviceId: string;
12
+ rpcCommunicator: RpcCommunicator;
13
+ parallelism: number;
14
+ noProgressLimit: number;
15
+ newContactListener?: (dhtPeer: DhtPeer) => void;
16
+ nodeName?: string;
17
+ }
18
+ export declare class DiscoverySession {
19
+ readonly sessionId: string;
20
+ private stopped;
21
+ private emitter;
22
+ private outgoingClosestPeersRequestsCounter;
23
+ private noProgressCounter;
24
+ private ongoingClosestPeersRequests;
25
+ private readonly config;
26
+ private readonly ownPeerId;
27
+ constructor(config: DiscoverySessionConfig);
28
+ private addNewContacts;
29
+ private getClosestPeersFromContact;
30
+ private onClosestPeersRequestSucceeded;
31
+ private onClosestPeersRequestFailed;
32
+ private findMoreContacts;
33
+ findClosestNodes(timeout: number): Promise<SortedContactList<DhtPeer>>;
34
+ stop(): void;
35
+ }
36
+ export {};