@streamr/dht 100.0.0-testnet-one.3 → 100.0.0-testnet-two.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 (307) hide show
  1. package/dist/src/connection/ConnectionLockHandler.d.ts +11 -11
  2. package/dist/src/connection/ConnectionLockHandler.js.map +1 -1
  3. package/dist/src/connection/ConnectionLockRpcLocal.d.ts +3 -3
  4. package/dist/src/connection/ConnectionLockRpcLocal.js +4 -4
  5. package/dist/src/connection/ConnectionLockRpcLocal.js.map +1 -1
  6. package/dist/src/connection/ConnectionLockRpcRemote.d.ts +3 -5
  7. package/dist/src/connection/ConnectionLockRpcRemote.js +4 -7
  8. package/dist/src/connection/ConnectionLockRpcRemote.js.map +1 -1
  9. package/dist/src/connection/ConnectionManager.d.ts +4 -6
  10. package/dist/src/connection/ConnectionManager.js +48 -46
  11. package/dist/src/connection/ConnectionManager.js.map +1 -1
  12. package/dist/src/connection/ConnectorFacade.d.ts +2 -2
  13. package/dist/src/connection/ConnectorFacade.js +2 -1
  14. package/dist/src/connection/ConnectorFacade.js.map +1 -1
  15. package/dist/src/connection/ManagedConnection.d.ts +3 -6
  16. package/dist/src/connection/ManagedConnection.js +6 -10
  17. package/dist/src/connection/ManagedConnection.js.map +1 -1
  18. package/dist/src/connection/connectivityChecker.js +1 -0
  19. package/dist/src/connection/connectivityChecker.js.map +1 -1
  20. package/dist/src/connection/simulator/Simulator.d.ts +0 -3
  21. package/dist/src/connection/simulator/Simulator.js +3 -51
  22. package/dist/src/connection/simulator/Simulator.js.map +1 -1
  23. package/dist/src/connection/simulator/SimulatorConnector.js +5 -5
  24. package/dist/src/connection/simulator/SimulatorConnector.js.map +1 -1
  25. package/dist/src/connection/webrtc/NodeWebrtcConnection.js +2 -2
  26. package/dist/src/connection/webrtc/NodeWebrtcConnection.js.map +1 -1
  27. package/dist/src/connection/webrtc/WebrtcConnector.d.ts +0 -1
  28. package/dist/src/connection/webrtc/WebrtcConnector.js +7 -9
  29. package/dist/src/connection/webrtc/WebrtcConnector.js.map +1 -1
  30. package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.d.ts +2 -2
  31. package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js +11 -12
  32. package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js.map +1 -1
  33. package/dist/src/connection/webrtc/WebrtcConnectorRpcRemote.d.ts +2 -5
  34. package/dist/src/connection/webrtc/WebrtcConnectorRpcRemote.js +1 -4
  35. package/dist/src/connection/webrtc/WebrtcConnectorRpcRemote.js.map +1 -1
  36. package/dist/src/connection/websocket/AutoCertifierClientFacade.d.ts +1 -2
  37. package/dist/src/connection/websocket/AutoCertifierClientFacade.js +3 -4
  38. package/dist/src/connection/websocket/AutoCertifierClientFacade.js.map +1 -1
  39. package/dist/src/connection/websocket/ClientWebsocket.js.map +1 -1
  40. package/dist/src/connection/websocket/WebsocketConnector.d.ts +2 -7
  41. package/dist/src/connection/websocket/WebsocketConnector.js +32 -38
  42. package/dist/src/connection/websocket/WebsocketConnector.js.map +1 -1
  43. package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.d.ts +3 -2
  44. package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.js +8 -10
  45. package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.js.map +1 -1
  46. package/dist/src/connection/websocket/WebsocketConnectorRpcRemote.d.ts +3 -6
  47. package/dist/src/connection/websocket/WebsocketConnectorRpcRemote.js +0 -3
  48. package/dist/src/connection/websocket/WebsocketConnectorRpcRemote.js.map +1 -1
  49. package/dist/src/connection/websocket/WebsocketServer.d.ts +1 -4
  50. package/dist/src/connection/websocket/WebsocketServer.js +11 -12
  51. package/dist/src/connection/websocket/WebsocketServer.js.map +1 -1
  52. package/dist/src/dht/DhtNode.d.ts +10 -13
  53. package/dist/src/dht/DhtNode.js +39 -52
  54. package/dist/src/dht/DhtNode.js.map +1 -1
  55. package/dist/src/dht/DhtNodeRpcLocal.d.ts +0 -1
  56. package/dist/src/dht/DhtNodeRpcLocal.js.map +1 -1
  57. package/dist/src/dht/DhtNodeRpcRemote.d.ts +7 -7
  58. package/dist/src/dht/DhtNodeRpcRemote.js +8 -7
  59. package/dist/src/dht/DhtNodeRpcRemote.js.map +1 -1
  60. package/dist/src/dht/ExternalApiRpcLocal.d.ts +5 -4
  61. package/dist/src/dht/ExternalApiRpcLocal.js +3 -2
  62. package/dist/src/dht/ExternalApiRpcLocal.js.map +1 -1
  63. package/dist/src/dht/ExternalApiRpcRemote.d.ts +2 -2
  64. package/dist/src/dht/ExternalApiRpcRemote.js +2 -0
  65. package/dist/src/dht/ExternalApiRpcRemote.js.map +1 -1
  66. package/dist/src/dht/PeerManager.d.ts +13 -14
  67. package/dist/src/dht/PeerManager.js +45 -60
  68. package/dist/src/dht/PeerManager.js.map +1 -1
  69. package/dist/src/dht/contact/Contact.d.ts +2 -2
  70. package/dist/src/dht/contact/Contact.js +2 -2
  71. package/dist/src/dht/contact/Contact.js.map +1 -1
  72. package/dist/src/dht/contact/ContactList.d.ts +7 -7
  73. package/dist/src/dht/contact/ContactList.js +3 -3
  74. package/dist/src/dht/contact/ContactList.js.map +1 -1
  75. package/dist/src/dht/contact/RandomContactList.d.ts +4 -4
  76. package/dist/src/dht/contact/RandomContactList.js +12 -11
  77. package/dist/src/dht/contact/RandomContactList.js.map +1 -1
  78. package/dist/src/dht/contact/RpcRemote.d.ts +7 -4
  79. package/dist/src/dht/contact/RpcRemote.js +5 -2
  80. package/dist/src/dht/contact/RpcRemote.js.map +1 -1
  81. package/dist/src/dht/contact/SortedContactList.d.ts +13 -13
  82. package/dist/src/dht/contact/SortedContactList.js +33 -29
  83. package/dist/src/dht/contact/SortedContactList.js.map +1 -1
  84. package/dist/src/dht/discovery/DiscoverySession.d.ts +2 -4
  85. package/dist/src/dht/discovery/DiscoverySession.js +19 -20
  86. package/dist/src/dht/discovery/DiscoverySession.js.map +1 -1
  87. package/dist/src/dht/discovery/PeerDiscovery.d.ts +2 -5
  88. package/dist/src/dht/discovery/PeerDiscovery.js +12 -20
  89. package/dist/src/dht/discovery/PeerDiscovery.js.map +1 -1
  90. package/dist/src/dht/recursive-operation/RecursiveOperationManager.d.ts +36 -0
  91. package/dist/src/dht/recursive-operation/RecursiveOperationManager.js +165 -0
  92. package/dist/src/dht/recursive-operation/RecursiveOperationManager.js.map +1 -0
  93. package/dist/src/dht/recursive-operation/RecursiveOperationRpcLocal.d.ts +14 -0
  94. package/dist/src/dht/{find/FindRpcLocal.js → recursive-operation/RecursiveOperationRpcLocal.js} +7 -7
  95. package/dist/src/dht/recursive-operation/RecursiveOperationRpcLocal.js.map +1 -0
  96. package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.d.ts +6 -0
  97. package/dist/src/dht/{routing/FindRpcRemote.js → recursive-operation/RecursiveOperationRpcRemote.js} +11 -11
  98. package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.js.map +1 -0
  99. package/dist/src/dht/recursive-operation/RecursiveOperationSession.d.ts +42 -0
  100. package/dist/src/dht/recursive-operation/RecursiveOperationSession.js +182 -0
  101. package/dist/src/dht/recursive-operation/RecursiveOperationSession.js.map +1 -0
  102. package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.d.ts +12 -0
  103. package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.js +17 -0
  104. package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.js.map +1 -0
  105. package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcRemote.d.ts +6 -0
  106. package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcRemote.js +21 -0
  107. package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcRemote.js.map +1 -0
  108. package/dist/src/dht/routing/Router.d.ts +4 -19
  109. package/dist/src/dht/routing/Router.js +41 -33
  110. package/dist/src/dht/routing/Router.js.map +1 -1
  111. package/dist/src/dht/routing/RouterRpcLocal.js +6 -5
  112. package/dist/src/dht/routing/RouterRpcLocal.js.map +1 -1
  113. package/dist/src/dht/routing/RouterRpcRemote.d.ts +2 -2
  114. package/dist/src/dht/routing/RouterRpcRemote.js +7 -7
  115. package/dist/src/dht/routing/RouterRpcRemote.js.map +1 -1
  116. package/dist/src/dht/routing/RoutingSession.d.ts +20 -16
  117. package/dist/src/dht/routing/RoutingSession.js +37 -45
  118. package/dist/src/dht/routing/RoutingSession.js.map +1 -1
  119. package/dist/src/dht/store/LocalDataStore.d.ts +11 -13
  120. package/dist/src/dht/store/LocalDataStore.js +36 -56
  121. package/dist/src/dht/store/LocalDataStore.js.map +1 -1
  122. package/dist/src/dht/store/StoreManager.d.ts +33 -0
  123. package/dist/src/dht/store/StoreManager.js +186 -0
  124. package/dist/src/dht/store/StoreManager.js.map +1 -0
  125. package/dist/src/dht/store/StoreRpcLocal.d.ts +8 -40
  126. package/dist/src/dht/store/StoreRpcLocal.js +13 -229
  127. package/dist/src/dht/store/StoreRpcLocal.js.map +1 -1
  128. package/dist/src/dht/store/StoreRpcRemote.d.ts +5 -5
  129. package/dist/src/dht/store/StoreRpcRemote.js +4 -5
  130. package/dist/src/dht/store/StoreRpcRemote.js.map +1 -1
  131. package/dist/src/exports.d.ts +2 -0
  132. package/dist/src/exports.js.map +1 -1
  133. package/dist/src/helpers/MapWithTtl.d.ts +14 -0
  134. package/dist/src/helpers/MapWithTtl.js +59 -0
  135. package/dist/src/helpers/MapWithTtl.js.map +1 -0
  136. package/dist/src/helpers/PeerID.d.ts +2 -0
  137. package/dist/src/helpers/PeerID.js +4 -0
  138. package/dist/src/helpers/PeerID.js.map +1 -1
  139. package/dist/src/helpers/nodeId.d.ts +5 -0
  140. package/dist/src/helpers/nodeId.js +18 -1
  141. package/dist/src/helpers/nodeId.js.map +1 -1
  142. package/dist/src/helpers/peerIdFromPeerDescriptor.d.ts +2 -1
  143. package/dist/src/helpers/peerIdFromPeerDescriptor.js +2 -1
  144. package/dist/src/helpers/peerIdFromPeerDescriptor.js.map +1 -1
  145. package/dist/src/helpers/protoClasses.js +2 -3
  146. package/dist/src/helpers/protoClasses.js.map +1 -1
  147. package/dist/src/proto/packages/dht/protos/DhtRpc.client.d.ts +21 -22
  148. package/dist/src/proto/packages/dht/protos/DhtRpc.client.js +18 -18
  149. package/dist/src/proto/packages/dht/protos/DhtRpc.client.js.map +1 -1
  150. package/dist/src/proto/packages/dht/protos/DhtRpc.d.ts +36 -60
  151. package/dist/src/proto/packages/dht/protos/DhtRpc.js +34 -53
  152. package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +1 -1
  153. package/dist/src/proto/packages/dht/protos/DhtRpc.server.d.ts +11 -12
  154. package/dist/src/rpc-protocol/DhtCallContext.d.ts +2 -1
  155. package/dist/src/rpc-protocol/DhtCallContext.js.map +1 -1
  156. package/dist/src/rpc-protocol/DhtRpcOptions.d.ts +2 -1
  157. package/dist/src/transport/ITransport.d.ts +9 -1
  158. package/dist/src/transport/ITransport.js +5 -0
  159. package/dist/src/transport/ITransport.js.map +1 -1
  160. package/dist/src/transport/ListeningRpcCommunicator.js +1 -1
  161. package/dist/src/transport/ListeningRpcCommunicator.js.map +1 -1
  162. package/dist/src/transport/RoutingRpcCommunicator.d.ts +2 -1
  163. package/dist/src/transport/RoutingRpcCommunicator.js +16 -11
  164. package/dist/src/transport/RoutingRpcCommunicator.js.map +1 -1
  165. package/jest.config.js +4 -1
  166. package/karma-setup.js +2 -0
  167. package/karma.config.js +11 -7
  168. package/package.json +6 -7
  169. package/protos/DhtRpc.proto +17 -23
  170. package/src/connection/ConnectionLockHandler.ts +15 -15
  171. package/src/connection/ConnectionLockRpcLocal.ts +8 -9
  172. package/src/connection/ConnectionLockRpcRemote.ts +7 -16
  173. package/src/connection/ConnectionManager.ts +58 -55
  174. package/src/connection/ConnectorFacade.ts +3 -0
  175. package/src/connection/ManagedConnection.ts +12 -30
  176. package/src/connection/connectivityChecker.ts +1 -0
  177. package/src/connection/simulator/Simulator.ts +5 -36
  178. package/src/connection/simulator/SimulatorConnector.ts +8 -8
  179. package/src/connection/webrtc/BrowserWebrtcConnection.ts +0 -3
  180. package/src/connection/webrtc/NodeWebrtcConnection.ts +3 -4
  181. package/src/connection/webrtc/WebrtcConnector.ts +11 -13
  182. package/src/connection/webrtc/WebrtcConnectorRpcLocal.ts +16 -16
  183. package/src/connection/webrtc/WebrtcConnectorRpcRemote.ts +3 -13
  184. package/src/connection/websocket/AutoCertifierClientFacade.ts +4 -6
  185. package/src/connection/websocket/ClientWebsocket.ts +1 -0
  186. package/src/connection/websocket/WebsocketConnector.ts +43 -56
  187. package/src/connection/websocket/WebsocketConnectorRpcLocal.ts +11 -13
  188. package/src/connection/websocket/WebsocketConnectorRpcRemote.ts +4 -15
  189. package/src/connection/websocket/WebsocketServer.ts +14 -17
  190. package/src/dht/DhtNode.ts +67 -69
  191. package/src/dht/DhtNodeRpcLocal.ts +0 -1
  192. package/src/dht/DhtNodeRpcRemote.ts +13 -13
  193. package/src/dht/ExternalApiRpcLocal.ts +16 -6
  194. package/src/dht/ExternalApiRpcRemote.ts +5 -3
  195. package/src/dht/PeerManager.ts +73 -90
  196. package/src/dht/contact/Contact.ts +5 -4
  197. package/src/dht/contact/ContactList.ts +9 -9
  198. package/src/dht/contact/RandomContactList.ts +14 -14
  199. package/src/dht/contact/RpcRemote.ts +10 -7
  200. package/src/dht/contact/SortedContactList.ts +48 -45
  201. package/src/dht/discovery/DiscoverySession.ts +25 -25
  202. package/src/dht/discovery/PeerDiscovery.ts +16 -37
  203. package/src/dht/recursive-operation/RecursiveOperationManager.ts +240 -0
  204. package/src/dht/{find/FindRpcLocal.ts → recursive-operation/RecursiveOperationRpcLocal.ts} +9 -9
  205. package/src/dht/{routing/FindRpcRemote.ts → recursive-operation/RecursiveOperationRpcRemote.ts} +10 -10
  206. package/src/dht/recursive-operation/RecursiveOperationSession.ts +224 -0
  207. package/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.ts +25 -0
  208. package/src/dht/{find/FindSessionRpcRemote.ts → recursive-operation/RecursiveOperationSessionRpcRemote.ts} +8 -8
  209. package/src/dht/routing/Router.ts +45 -64
  210. package/src/dht/routing/RouterRpcLocal.ts +7 -6
  211. package/src/dht/routing/RouterRpcRemote.ts +9 -10
  212. package/src/dht/routing/RoutingSession.ts +59 -68
  213. package/src/dht/store/LocalDataStore.ts +47 -66
  214. package/src/dht/store/StoreManager.ts +217 -0
  215. package/src/dht/store/StoreRpcLocal.ts +26 -302
  216. package/src/dht/store/StoreRpcRemote.ts +9 -11
  217. package/src/exports.ts +2 -0
  218. package/src/helpers/MapWithTtl.ts +71 -0
  219. package/src/helpers/PeerID.ts +5 -0
  220. package/src/helpers/nodeId.ts +20 -0
  221. package/src/helpers/peerIdFromPeerDescriptor.ts +5 -3
  222. package/src/helpers/protoClasses.ts +4 -6
  223. package/src/proto/packages/dht/protos/DhtRpc.client.ts +31 -32
  224. package/src/proto/packages/dht/protos/DhtRpc.server.ts +11 -12
  225. package/src/proto/packages/dht/protos/DhtRpc.ts +49 -80
  226. package/src/rpc-protocol/DhtCallContext.ts +2 -1
  227. package/src/rpc-protocol/DhtRpcOptions.ts +2 -1
  228. package/src/transport/ITransport.ts +10 -1
  229. package/src/transport/ListeningRpcCommunicator.ts +1 -1
  230. package/src/transport/RoutingRpcCommunicator.ts +18 -12
  231. package/test/benchmark/Find.test.ts +8 -21
  232. package/test/benchmark/KademliaCorrectness.test.ts +11 -20
  233. package/test/benchmark/SortedContactListBenchmark.test.ts +9 -9
  234. package/test/benchmark/kademlia-simulation/Contact.ts +9 -8
  235. package/test/benchmark/kademlia-simulation/KademliaSimulation.ts +2 -2
  236. package/test/benchmark/kademlia-simulation/SimulationNode.ts +17 -17
  237. package/test/end-to-end/Layer0-Layer1.test.ts +10 -14
  238. package/test/end-to-end/Layer0.test.ts +15 -18
  239. package/test/end-to-end/Layer0MixedConnectionTypes.test.ts +7 -9
  240. package/test/end-to-end/Layer0Webrtc-Layer1.test.ts +4 -10
  241. package/test/end-to-end/Layer0Webrtc.test.ts +5 -6
  242. package/test/end-to-end/Layer1-Scale-WebSocket.test.ts +8 -16
  243. package/test/end-to-end/Layer1-Scale-Webrtc.test.ts +6 -13
  244. package/test/end-to-end/WebsocketConnectionRequest.test.ts +5 -6
  245. package/test/end-to-end/memory-leak.test.ts +6 -8
  246. package/test/integration/ConnectionLocking.test.ts +6 -13
  247. package/test/integration/ConnectionManager.test.ts +26 -43
  248. package/test/integration/DhtJoinPeerDiscovery.test.ts +5 -10
  249. package/test/integration/DhtNodeExternalAPI.test.ts +16 -22
  250. package/test/integration/DhtNodeRpcRemote.test.ts +13 -22
  251. package/test/integration/DhtRpc.test.ts +13 -18
  252. package/test/integration/Find.test.ts +10 -10
  253. package/test/integration/Layer1-scale.test.ts +17 -28
  254. package/test/integration/Mock-Layer1-Layer0.test.ts +25 -43
  255. package/test/integration/MultipleEntryPointJoining.test.ts +7 -7
  256. package/test/integration/ReplicateData.test.ts +28 -30
  257. package/test/integration/RouteMessage.test.ts +30 -27
  258. package/test/integration/RouterRpcRemote.test.ts +12 -18
  259. package/test/integration/RpcErrors.test.ts +8 -21
  260. package/test/integration/ScaleDownDht.test.ts +11 -10
  261. package/test/integration/SimultaneousConnections.test.ts +43 -67
  262. package/test/integration/Store.test.ts +23 -36
  263. package/test/integration/StoreAndDelete.test.ts +30 -50
  264. package/test/integration/StoreOnDhtWithTwoNodes.test.ts +16 -37
  265. package/test/integration/StoreRpcRemote.test.ts +20 -30
  266. package/test/integration/WebrtcConnectionManagement.test.ts +3 -13
  267. package/test/integration/WebrtcConnectorRpc.test.ts +3 -9
  268. package/test/integration/WebsocketConnectionManagement.test.ts +7 -10
  269. package/test/integration/WebsocketConnectorRpc.test.ts +8 -17
  270. package/test/unit/ConnectivityHelpers.test.ts +9 -17
  271. package/test/unit/DuplicateDetector.test.ts +7 -4
  272. package/test/unit/LocalDataStore.test.ts +66 -77
  273. package/test/unit/PeerManager.test.ts +31 -0
  274. package/test/unit/RandomContactList.test.ts +13 -8
  275. package/test/unit/{Finder.test.ts → RecursiveOperationManager.test.ts} +38 -43
  276. package/test/unit/RecursiveOperationSession.test.ts +68 -0
  277. package/test/unit/Router.test.ts +15 -22
  278. package/test/unit/RoutingSession.test.ts +23 -25
  279. package/test/unit/SortedContactList.test.ts +41 -26
  280. package/test/unit/StoreManager.test.ts +132 -0
  281. package/test/unit/WebsocketConnector.test.ts +27 -35
  282. package/test/unit/customMatchers.test.ts +16 -0
  283. package/test/utils/FakeTransport.ts +44 -0
  284. package/test/utils/customMatchers.ts +70 -0
  285. package/test/utils/mock/MockRpcCommunicator.ts +7 -0
  286. package/test/utils/mock/Router.ts +3 -2
  287. package/test/utils/mock/mockDataEntry.ts +36 -0
  288. package/test/utils/utils.ts +49 -87
  289. package/dist/src/dht/find/FindRpcLocal.d.ts +0 -14
  290. package/dist/src/dht/find/FindRpcLocal.js.map +0 -1
  291. package/dist/src/dht/find/FindSession.d.ts +0 -44
  292. package/dist/src/dht/find/FindSession.js +0 -150
  293. package/dist/src/dht/find/FindSession.js.map +0 -1
  294. package/dist/src/dht/find/FindSessionRpcLocal.d.ts +0 -12
  295. package/dist/src/dht/find/FindSessionRpcLocal.js +0 -17
  296. package/dist/src/dht/find/FindSessionRpcLocal.js.map +0 -1
  297. package/dist/src/dht/find/FindSessionRpcRemote.d.ts +0 -6
  298. package/dist/src/dht/find/FindSessionRpcRemote.js +0 -21
  299. package/dist/src/dht/find/FindSessionRpcRemote.js.map +0 -1
  300. package/dist/src/dht/find/Finder.d.ts +0 -49
  301. package/dist/src/dht/find/Finder.js +0 -197
  302. package/dist/src/dht/find/Finder.js.map +0 -1
  303. package/dist/src/dht/routing/FindRpcRemote.d.ts +0 -6
  304. package/dist/src/dht/routing/FindRpcRemote.js.map +0 -1
  305. package/src/dht/find/FindSession.ts +0 -183
  306. package/src/dht/find/FindSessionRpcLocal.ts +0 -25
  307. package/src/dht/find/Finder.ts +0 -295
@@ -17,11 +17,11 @@ import {
17
17
  ExternalFindDataResponse,
18
18
  ExternalStoreDataRequest,
19
19
  ExternalStoreDataResponse,
20
- FindAction,
20
+ RecursiveOperation,
21
21
  } from '../proto/packages/dht/protos/DhtRpc'
22
22
  import { ITransport, TransportEvents } from '../transport/ITransport'
23
23
  import { ConnectionManager, PortRange, TlsCertificate } from '../connection/ConnectionManager'
24
- import { DhtNodeRpcClient, ExternalApiRpcClient } from '../proto/packages/dht/protos/DhtRpc.client'
24
+ import { ExternalApiRpcClient, StoreRpcClient } from '../proto/packages/dht/protos/DhtRpc.client'
25
25
  import {
26
26
  Logger,
27
27
  MetricsContext,
@@ -29,16 +29,13 @@ import {
29
29
  merge,
30
30
  waitForCondition
31
31
  } from '@streamr/utils'
32
- import { toProtoRpcClient } from '@streamr/proto-rpc'
33
32
  import { Any } from '../proto/google/protobuf/any'
34
33
  import {
35
- areEqualPeerDescriptors,
36
- getNodeIdFromPeerDescriptor,
37
- peerIdFromPeerDescriptor
34
+ getNodeIdFromPeerDescriptor
38
35
  } from '../helpers/peerIdFromPeerDescriptor'
39
36
  import { Router } from './routing/Router'
40
- import { Finder, FindResult } from './find/Finder'
41
- import { StoreRpcLocal } from './store/StoreRpcLocal'
37
+ import { RecursiveOperationManager, RecursiveOperationResult } from './recursive-operation/RecursiveOperationManager'
38
+ import { StoreManager } from './store/StoreManager'
42
39
  import { PeerDiscovery } from './discovery/PeerDiscovery'
43
40
  import { LocalDataStore } from './store/LocalDataStore'
44
41
  import { IceServer } from '../connection/webrtc/WebrtcConnector'
@@ -51,18 +48,20 @@ import { MarkRequired } from 'ts-essentials'
51
48
  import { DhtNodeRpcLocal } from './DhtNodeRpcLocal'
52
49
  import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
53
50
  import { ExternalApiRpcLocal } from './ExternalApiRpcLocal'
54
- import { PeerManager, getDistance } from './PeerManager'
51
+ import { PeerManager } from './PeerManager'
52
+ import { ServiceID } from '../types/ServiceID'
53
+ import { NodeID, getNodeIdFromBinary } from '../helpers/nodeId'
54
+ import { StoreRpcRemote } from './store/StoreRpcRemote'
55
55
 
56
56
  export interface DhtNodeEvents {
57
57
  newContact: (peerDescriptor: PeerDescriptor, closestPeers: PeerDescriptor[]) => void
58
58
  contactRemoved: (peerDescriptor: PeerDescriptor, closestPeers: PeerDescriptor[]) => void
59
- joinCompleted: () => void
60
59
  newRandomContact: (peerDescriptor: PeerDescriptor, closestPeers: PeerDescriptor[]) => void
61
60
  randomContactRemoved: (peerDescriptor: PeerDescriptor, closestPeers: PeerDescriptor[]) => void
62
61
  }
63
62
 
64
63
  export interface DhtNodeOptions {
65
- serviceId?: string
64
+ serviceId?: ServiceID
66
65
  joinParallelism?: number
67
66
  maxNeighborListSize?: number
68
67
  numberOfNodesPerKBucket?: number
@@ -140,16 +139,14 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
140
139
  private transport?: ITransport
141
140
  private localPeerDescriptor?: PeerDescriptor
142
141
  public router?: Router
143
- private storeRpcLocal?: StoreRpcLocal
144
- private localDataStore = new LocalDataStore()
145
- private finder?: Finder
142
+ private storeManager?: StoreManager
143
+ private localDataStore: LocalDataStore
144
+ private recursiveOperationManager?: RecursiveOperationManager
146
145
  private peerDiscovery?: PeerDiscovery
147
146
  private peerManager?: PeerManager
148
-
149
147
  public connectionManager?: ConnectionManager
150
148
  private started = false
151
149
  private abortController = new AbortController()
152
- private entryPointDisconnectTimeout?: NodeJS.Timeout
153
150
 
154
151
  constructor(conf: DhtNodeOptions) {
155
152
  super()
@@ -169,6 +166,7 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
169
166
  metricsContext: new MetricsContext(),
170
167
  peerId: new UUID().toHex()
171
168
  }, conf)
169
+ this.localDataStore = new LocalDataStore(this.config.storeMaxTtl)
172
170
  this.send = this.send.bind(this)
173
171
  }
174
172
 
@@ -258,10 +256,9 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
258
256
  connections: this.peerManager!.connections,
259
257
  localPeerDescriptor: this.localPeerDescriptor!,
260
258
  addContact: (contact: PeerDescriptor, setActive?: boolean) => this.peerManager!.handleNewPeers([contact], setActive),
261
- serviceId: this.config.serviceId,
262
259
  connectionManager: this.connectionManager
263
260
  })
264
- this.finder = new Finder({
261
+ this.recursiveOperationManager = new RecursiveOperationManager({
265
262
  rpcCommunicator: this.rpcCommunicator,
266
263
  router: this.router,
267
264
  sessionTransport: this,
@@ -269,36 +266,41 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
269
266
  localPeerDescriptor: this.localPeerDescriptor!,
270
267
  serviceId: this.config.serviceId,
271
268
  addContact: (contact: PeerDescriptor) => this.peerManager!.handleNewPeers([contact]),
272
- isPeerCloserToIdThanSelf: this.isPeerCloserToIdThanSelf.bind(this),
273
269
  localDataStore: this.localDataStore
274
270
  })
275
- this.storeRpcLocal = new StoreRpcLocal({
271
+ this.storeManager = new StoreManager({
276
272
  rpcCommunicator: this.rpcCommunicator,
277
- finder: this.finder,
273
+ recursiveOperationManager: this.recursiveOperationManager,
278
274
  localPeerDescriptor: this.localPeerDescriptor!,
279
275
  serviceId: this.config.serviceId,
280
276
  highestTtl: this.config.storeHighestTtl,
281
- maxTtl: this.config.storeMaxTtl,
282
277
  redundancyFactor: this.config.storageRedundancyFactor,
283
278
  localDataStore: this.localDataStore,
284
- dhtNodeEmitter: this,
285
- getNodesClosestToIdFromBucket: (id: Uint8Array, n?: number) => {
286
- return this.peerManager!.getClosestNeighborsTo(id, n)
279
+ getClosestNeighborsTo: (id: Uint8Array, n?: number) => {
280
+ return this.peerManager!.getClosestNeighborsTo(getNodeIdFromBinary(id), n).map((n) => n.getPeerDescriptor())
287
281
  },
288
- rpcRequestTimeout: this.config.rpcRequestTimeout
282
+ createRpcRemote: (contact: PeerDescriptor) => {
283
+ return new StoreRpcRemote(
284
+ this.localPeerDescriptor!,
285
+ contact,
286
+ this.config.serviceId,
287
+ this.rpcCommunicator!,
288
+ StoreRpcClient,
289
+ this.config.rpcRequestTimeout
290
+ )
291
+ }
292
+ })
293
+ this.on('newContact', (peerDescriptor: PeerDescriptor) => {
294
+ this.storeManager!.onNewContact(peerDescriptor)
289
295
  })
290
296
  this.bindRpcLocalMethods()
291
- if ((this.connectionManager !== undefined) && (this.config.entryPoints !== undefined) && this.config.entryPoints.length > 0
292
- && !areEqualPeerDescriptors(this.config.entryPoints[0], this.localPeerDescriptor!)) {
293
- this.connectToEntryPoint(this.config.entryPoints[0])
294
- }
295
297
  }
296
298
 
297
299
  private initPeerManager() {
298
300
  this.peerManager = new PeerManager({
299
301
  numberOfNodesPerKBucket: this.config.numberOfNodesPerKBucket,
300
302
  maxContactListSize: this.config.maxNeighborListSize,
301
- ownPeerId: this.getNodeId(),
303
+ localNodeId: this.getNodeId(),
302
304
  connectionManager: this.connectionManager!,
303
305
  peerDiscoveryQueryBatchSize: this.config.peerDiscoveryQueryBatchSize,
304
306
  isLayer0: (this.connectionManager !== undefined),
@@ -347,10 +349,9 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
347
349
  return
348
350
  }
349
351
  const dhtNodeRpcLocal = new DhtNodeRpcLocal({
350
- serviceId: this.config.serviceId,
351
352
  peerDiscoveryQueryBatchSize: this.config.peerDiscoveryQueryBatchSize,
352
353
  getClosestPeersTo: (kademliaId: Uint8Array, limit: number) => {
353
- return this.peerManager!.getClosestNeighborsTo(kademliaId, limit)
354
+ return this.peerManager!.getClosestNeighborsTo(getNodeIdFromBinary(kademliaId), limit)
354
355
  .map((dhtPeer: DhtNodeRpcRemote) => dhtPeer.getPeerDescriptor())
355
356
  },
356
357
  addNewContact: (contact: PeerDescriptor) => this.peerManager!.handleNewPeers([contact]),
@@ -363,33 +364,27 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
363
364
  this.rpcCommunicator!.registerRpcNotification(LeaveNotice, 'leaveNotice',
364
365
  (req: LeaveNotice, context) => dhtNodeRpcLocal.leaveNotice(req, context))
365
366
  const externalApiRpcLocal = new ExternalApiRpcLocal({
366
- startFind: (key: Uint8Array, action: FindAction, excludedPeer: PeerDescriptor) => {
367
- return this.startFind(key, action, excludedPeer)
367
+ executeRecursiveOperation: (key: Uint8Array, operation: RecursiveOperation, excludedPeer: PeerDescriptor) => {
368
+ return this.executeRecursiveOperation(key, operation, excludedPeer)
368
369
  },
369
- storeDataToDht: (key: Uint8Array, data: Any, creator?: PeerDescriptor) => this.storeDataToDht(key, data, creator)
370
+ storeDataToDht: (key: Uint8Array, data: Any, creator?: NodeID) => this.storeDataToDht(key, data, creator)
370
371
  })
371
372
  this.rpcCommunicator!.registerRpcMethod(
372
373
  ExternalFindDataRequest,
373
374
  ExternalFindDataResponse,
374
375
  'externalFindData',
375
376
  (req: ExternalFindDataRequest, context: ServerCallContext) => externalApiRpcLocal.externalFindData(req, context),
376
- { timeout: 10000 }
377
+ { timeout: 10000 } // TODO use config option or named constant?
377
378
  )
378
379
  this.rpcCommunicator!.registerRpcMethod(
379
380
  ExternalStoreDataRequest,
380
381
  ExternalStoreDataResponse,
381
382
  'externalStoreData',
382
383
  (req: ExternalStoreDataRequest, context: ServerCallContext) => externalApiRpcLocal.externalStoreData(req, context),
383
- { timeout: 10000 }
384
+ { timeout: 10000 } // TODO use config option or named constant?
384
385
  )
385
386
  }
386
387
 
387
- private isPeerCloserToIdThanSelf(peer1: PeerDescriptor, compareToId: PeerID): boolean {
388
- const distance1 = getDistance(peer1.nodeId, compareToId.value)
389
- const distance2 = getDistance(this.localPeerDescriptor!.nodeId, compareToId.value)
390
- return distance1 < distance2
391
- }
392
-
393
388
  private handleMessage(message: Message): void {
394
389
  if (message.serviceId === this.config.serviceId) {
395
390
  logger.trace('callig this.handleMessageFromPeer ' + getNodeIdFromPeerDescriptor(message.sourceDescriptor!)
@@ -412,24 +407,20 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
412
407
  }
413
408
 
414
409
  public getClosestContacts(limit?: number): PeerDescriptor[] {
415
- return this.peerManager!.getClosestContactsTo(this.localPeerDescriptor!.nodeId, limit).map((peer) => peer.getPeerDescriptor())
410
+ return this.peerManager!.getClosestContactsTo(
411
+ getNodeIdFromPeerDescriptor(this.localPeerDescriptor!),
412
+ limit).map((peer) => peer.getPeerDescriptor()
413
+ )
416
414
  }
417
415
 
418
- public getNodeId(): PeerID {
419
- return peerIdFromPeerDescriptor(this.localPeerDescriptor!)
416
+ public getNodeId(): NodeID {
417
+ return getNodeIdFromPeerDescriptor(this.localPeerDescriptor!)
420
418
  }
421
419
 
422
420
  public getNumberOfNeighbors(): number {
423
421
  return this.peerManager!.getNumberOfNeighbors()
424
422
  }
425
423
 
426
- private connectToEntryPoint(entryPoint: PeerDescriptor): void {
427
- this.connectionManager!.lockConnection(entryPoint, 'temporary-layer0-connection')
428
- this.entryPointDisconnectTimeout = setTimeout(() => {
429
- this.connectionManager!.unlockConnection(entryPoint, 'temporary-layer0-connection')
430
- }, 10 * 1000)
431
- }
432
-
433
424
  public removeContact(contact: PeerDescriptor): void {
434
425
  if (!this.started) { // the stopped state is checked in PeerManager
435
426
  return
@@ -449,18 +440,26 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
449
440
  if (!this.started) {
450
441
  throw new Error('Cannot join DHT before calling start() on DhtNode')
451
442
  }
452
- await this.peerDiscovery!.joinDht(entryPointDescriptors, doAdditionalRandomPeerDiscovery, retry)
443
+ await Promise.all(entryPointDescriptors.map((entryPoint) =>
444
+ this.peerDiscovery!.joinDht(entryPoint, doAdditionalRandomPeerDiscovery, retry)
445
+ ))
453
446
  }
454
447
 
455
- public async startFind(key: Uint8Array, action?: FindAction, excludedPeer?: PeerDescriptor): Promise<FindResult> {
456
- return this.finder!.startFind(key, action, excludedPeer)
448
+ // TODO make this private and unify the public API of find/fetch/store/delete methods
449
+ // (we already have storeDataToDht etc. here)
450
+ public async executeRecursiveOperation(
451
+ key: Uint8Array,
452
+ operation: RecursiveOperation,
453
+ excludedPeer?: PeerDescriptor
454
+ ): Promise<RecursiveOperationResult> {
455
+ return this.recursiveOperationManager!.execute(key, operation, excludedPeer)
457
456
  }
458
457
 
459
- public async storeDataToDht(key: Uint8Array, data: Any, creator?: PeerDescriptor): Promise<PeerDescriptor[]> {
458
+ public async storeDataToDht(key: Uint8Array, data: Any, creator?: NodeID): Promise<PeerDescriptor[]> {
460
459
  if (this.peerDiscovery!.isJoinOngoing() && this.config.entryPoints && this.config.entryPoints.length > 0) {
461
460
  return this.storeDataViaPeer(key, data, sample(this.config.entryPoints)!)
462
461
  }
463
- return this.storeRpcLocal!.storeDataToDht(key, data, creator ?? this.localPeerDescriptor!)
462
+ return this.storeManager!.storeDataToDht(key, data, creator ?? getNodeIdFromPeerDescriptor(this.localPeerDescriptor!))
464
463
  }
465
464
 
466
465
  public async storeDataViaPeer(key: Uint8Array, data: Any, peer: PeerDescriptor): Promise<PeerDescriptor[]> {
@@ -468,7 +467,8 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
468
467
  this.localPeerDescriptor!,
469
468
  peer,
470
469
  this.config.serviceId,
471
- toProtoRpcClient(new ExternalApiRpcClient(this.rpcCommunicator!.getRpcClientTransport()))
470
+ this.rpcCommunicator!,
471
+ ExternalApiRpcClient
472
472
  )
473
473
  return await rpcRemote.storeData(key, data)
474
474
  }
@@ -477,13 +477,13 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
477
477
  if (this.peerDiscovery!.isJoinOngoing() && this.config.entryPoints && this.config.entryPoints.length > 0) {
478
478
  return this.findDataViaPeer(key, sample(this.config.entryPoints)!)
479
479
  }
480
- const result = await this.finder!.startFind(key, FindAction.FETCH_DATA)
480
+ const result = await this.recursiveOperationManager!.execute(key, RecursiveOperation.FETCH_DATA)
481
481
  return result.dataEntries ?? [] // TODO is this fallback needed?
482
482
  }
483
483
 
484
484
  public async deleteDataFromDht(key: Uint8Array, waitForCompletion: boolean): Promise<void> {
485
485
  if (!this.abortController.signal.aborted) {
486
- await this.finder!.startFind(key, FindAction.DELETE_DATA, undefined, waitForCompletion)
486
+ await this.recursiveOperationManager!.execute(key, RecursiveOperation.DELETE_DATA, undefined, waitForCompletion)
487
487
  }
488
488
  }
489
489
 
@@ -492,7 +492,8 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
492
492
  this.localPeerDescriptor!,
493
493
  peer,
494
494
  this.config.serviceId,
495
- toProtoRpcClient(new ExternalApiRpcClient(this.rpcCommunicator!.getRpcClientTransport()))
495
+ this.rpcCommunicator!,
496
+ ExternalApiRpcClient
496
497
  )
497
498
  return await rpcRemote.externalFindData(key)
498
499
  }
@@ -550,15 +551,12 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
550
551
  }
551
552
  logger.trace('stop()')
552
553
  this.abortController.abort()
553
- await this.storeRpcLocal!.destroy()
554
- if (this.entryPointDisconnectTimeout) {
555
- clearTimeout(this.entryPointDisconnectTimeout)
556
- }
554
+ await this.storeManager!.destroy()
557
555
  this.localDataStore.clear()
558
556
  this.peerManager?.stop()
559
557
  this.rpcCommunicator!.stop()
560
558
  this.router!.stop()
561
- this.finder!.stop()
559
+ this.recursiveOperationManager!.stop()
562
560
  this.peerDiscovery!.stop()
563
561
  if (this.config.transport === undefined) {
564
562
  // if the transport was not given in config, the instance was created in start() and
@@ -574,8 +572,8 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
574
572
  return new DhtNodeRpcRemote(
575
573
  this.localPeerDescriptor!,
576
574
  peerDescriptor,
577
- toProtoRpcClient(new DhtNodeRpcClient(this.rpcCommunicator!.getRpcClientTransport())),
578
575
  this.config.serviceId,
576
+ this.rpcCommunicator!,
579
577
  this.config.rpcRequestTimeout
580
578
  )
581
579
  }
@@ -14,7 +14,6 @@ import { IDhtNodeRpc } from '../proto/packages/dht/protos/DhtRpc.server'
14
14
  import { DhtCallContext } from '../rpc-protocol/DhtCallContext'
15
15
 
16
16
  interface DhtNodeRpcLocalConfig {
17
- serviceId: string
18
17
  peerDiscoveryQueryBatchSize: number
19
18
  getClosestPeersTo: (nodeId: Uint8Array, limit: number) => PeerDescriptor[]
20
19
  addNewContact: (contact: PeerDescriptor) => void
@@ -1,17 +1,17 @@
1
- import { IDhtNodeRpcClient } from '../proto/packages/dht/protos/DhtRpc.client'
1
+ import { RpcCommunicator } from '@streamr/proto-rpc'
2
+ import { Logger } from '@streamr/utils'
3
+ import { v4 } from 'uuid'
4
+ import { NodeID } from '../helpers/nodeId'
5
+ import { getNodeIdFromPeerDescriptor } from '../helpers/peerIdFromPeerDescriptor'
2
6
  import {
3
7
  ClosestPeersRequest,
4
8
  LeaveNotice,
5
9
  PeerDescriptor,
6
10
  PingRequest
7
11
  } from '../proto/packages/dht/protos/DhtRpc'
8
- import { v4 } from 'uuid'
9
- import { Logger } from '@streamr/utils'
10
- import { ProtoRpcClient } from '@streamr/proto-rpc'
11
- import { RpcRemote } from './contact/RpcRemote'
12
- import { PeerID } from '../helpers/PeerID'
13
- import { getNodeIdFromPeerDescriptor, peerIdFromPeerDescriptor } from '../helpers/peerIdFromPeerDescriptor'
12
+ import { DhtNodeRpcClient } from '../proto/packages/dht/protos/DhtRpc.client'
14
13
  import { ServiceID } from '../types/ServiceID'
14
+ import { RpcRemote } from './contact/RpcRemote'
15
15
 
16
16
  const logger = new Logger(module)
17
17
 
@@ -21,7 +21,7 @@ export interface KBucketContact {
21
21
  vectorClock: number
22
22
  }
23
23
 
24
- export class DhtNodeRpcRemote extends RpcRemote<IDhtNodeRpcClient> implements KBucketContact {
24
+ export class DhtNodeRpcRemote extends RpcRemote<DhtNodeRpcClient> implements KBucketContact {
25
25
 
26
26
  private static counter = 0
27
27
  public vectorClock: number
@@ -30,12 +30,12 @@ export class DhtNodeRpcRemote extends RpcRemote<IDhtNodeRpcClient> implements KB
30
30
  constructor(
31
31
  localPeerDescriptor: PeerDescriptor,
32
32
  peerDescriptor: PeerDescriptor,
33
- client: ProtoRpcClient<IDhtNodeRpcClient>,
34
33
  serviceId: ServiceID,
34
+ rpcCommunicator: RpcCommunicator,
35
35
  rpcRequestTimeout?: number
36
36
  ) {
37
- super(localPeerDescriptor, peerDescriptor, serviceId, client, rpcRequestTimeout)
38
- this.id = this.getPeerId().value
37
+ super(localPeerDescriptor, peerDescriptor, serviceId, rpcCommunicator, DhtNodeRpcClient, rpcRequestTimeout)
38
+ this.id = this.getPeerDescriptor().nodeId
39
39
  this.vectorClock = DhtNodeRpcRemote.counter++
40
40
  }
41
41
 
@@ -84,7 +84,7 @@ export class DhtNodeRpcRemote extends RpcRemote<IDhtNodeRpcClient> implements KB
84
84
  })
85
85
  }
86
86
 
87
- getPeerId(): PeerID {
88
- return peerIdFromPeerDescriptor(this.getPeerDescriptor())
87
+ getNodeId(): NodeID {
88
+ return getNodeIdFromPeerDescriptor(this.getPeerDescriptor())
89
89
  }
90
90
  }
@@ -4,17 +4,27 @@ import {
4
4
  ExternalFindDataResponse,
5
5
  ExternalStoreDataRequest,
6
6
  ExternalStoreDataResponse,
7
- FindAction,
7
+ RecursiveOperation,
8
8
  PeerDescriptor
9
9
  } from '../proto/packages/dht/protos/DhtRpc'
10
10
  import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
11
11
  import { DhtCallContext } from '../rpc-protocol/DhtCallContext'
12
- import { FindResult } from './find/Finder'
12
+ import { RecursiveOperationResult } from './recursive-operation/RecursiveOperationManager'
13
13
  import { Any } from '../proto/google/protobuf/any'
14
+ import { NodeID } from '../helpers/nodeId'
15
+ import { getNodeIdFromPeerDescriptor } from '../helpers/peerIdFromPeerDescriptor'
14
16
 
15
17
  interface ExternalApiRpcLocalConfig {
16
- startFind: (idToFind: Uint8Array, action: FindAction, excludedPeer: PeerDescriptor) => Promise<FindResult>
17
- storeDataToDht: (key: Uint8Array, data: Any, creator: PeerDescriptor) => Promise<PeerDescriptor[]>
18
+ executeRecursiveOperation: (
19
+ targetId: Uint8Array,
20
+ operation: RecursiveOperation,
21
+ excludedPeer: PeerDescriptor
22
+ ) => Promise<RecursiveOperationResult>
23
+ storeDataToDht: (
24
+ key: Uint8Array,
25
+ data: Any,
26
+ creator: NodeID
27
+ ) => Promise<PeerDescriptor[]>
18
28
  }
19
29
 
20
30
  export class ExternalApiRpcLocal implements IExternalApiRpc {
@@ -27,13 +37,13 @@ export class ExternalApiRpcLocal implements IExternalApiRpc {
27
37
 
28
38
  async externalFindData(findDataRequest: ExternalFindDataRequest, context: ServerCallContext): Promise<ExternalFindDataResponse> {
29
39
  const senderPeerDescriptor = (context as DhtCallContext).incomingSourceDescriptor!
30
- const result = await this.config.startFind(findDataRequest.key, FindAction.FETCH_DATA, senderPeerDescriptor)
40
+ const result = await this.config.executeRecursiveOperation(findDataRequest.key, RecursiveOperation.FETCH_DATA, senderPeerDescriptor)
31
41
  return ExternalFindDataResponse.create({ entries: result.dataEntries ?? [] })
32
42
  }
33
43
 
34
44
  async externalStoreData(request: ExternalStoreDataRequest, context: ServerCallContext): Promise<ExternalStoreDataResponse> {
35
45
  const senderPeerDescriptor = (context as DhtCallContext).incomingSourceDescriptor!
36
- const result = await this.config.storeDataToDht(request.key, request.data!, senderPeerDescriptor)
46
+ const result = await this.config.storeDataToDht(request.key, request.data!, getNodeIdFromPeerDescriptor(senderPeerDescriptor))
37
47
  return ExternalStoreDataResponse.create({
38
48
  storers: result
39
49
  })
@@ -1,15 +1,16 @@
1
1
  import { Any } from '../proto/google/protobuf/any'
2
- import { DataEntry, ExternalStoreDataRequest, ExternalFindDataRequest, PeerDescriptor } from '../proto/packages/dht/protos/DhtRpc'
3
- import { IExternalApiRpcClient } from '../proto/packages/dht/protos/DhtRpc.client'
2
+ import { DataEntry, ExternalFindDataRequest, ExternalStoreDataRequest, PeerDescriptor } from '../proto/packages/dht/protos/DhtRpc'
3
+ import { ExternalApiRpcClient } from '../proto/packages/dht/protos/DhtRpc.client'
4
4
  import { RpcRemote } from './contact/RpcRemote'
5
5
 
6
- export class ExternalApiRpcRemote extends RpcRemote<IExternalApiRpcClient> {
6
+ export class ExternalApiRpcRemote extends RpcRemote<ExternalApiRpcClient> {
7
7
 
8
8
  async externalFindData(key: Uint8Array): Promise<DataEntry[]> {
9
9
  const request: ExternalFindDataRequest = {
10
10
  key
11
11
  }
12
12
  const options = this.formDhtRpcOptions({
13
+ // TODO use config option or named constant?
13
14
  timeout: 10000
14
15
  })
15
16
  try {
@@ -26,6 +27,7 @@ export class ExternalApiRpcRemote extends RpcRemote<IExternalApiRpcClient> {
26
27
  data
27
28
  }
28
29
  const options = this.formDhtRpcOptions({
30
+ // TODO use config option or named constant?
29
31
  timeout: 10000
30
32
  })
31
33
  try {