@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
@@ -1,340 +1,64 @@
1
+ import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
2
+ import { Logger } from '@streamr/utils'
3
+ import { Empty } from '../../proto/google/protobuf/empty'
4
+ import { Timestamp } from '../../proto/google/protobuf/timestamp'
1
5
  import {
2
- DataEntry, ReplicateDataRequest, PeerDescriptor,
6
+ DataEntry,
7
+ PeerDescriptor,
8
+ ReplicateDataRequest,
3
9
  StoreDataRequest, StoreDataResponse
4
10
  } from '../../proto/packages/dht/protos/DhtRpc'
5
- import { PeerID } from '../../helpers/PeerID'
6
- import { Any } from '../../proto/google/protobuf/any'
7
- import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
11
+ import { IStoreRpc } from '../../proto/packages/dht/protos/DhtRpc.server'
8
12
  import { DhtCallContext } from '../../rpc-protocol/DhtCallContext'
9
- import { toProtoRpcClient } from '@streamr/proto-rpc'
10
- import { StoreRpcClient } from '../../proto/packages/dht/protos/DhtRpc.client'
11
- import { RoutingRpcCommunicator } from '../../transport/RoutingRpcCommunicator'
12
- import { IFinder } from '../find/Finder'
13
- import { areEqualPeerDescriptors } from '../../helpers/peerIdFromPeerDescriptor'
14
- import { Logger } from '@streamr/utils'
15
13
  import { LocalDataStore } from './LocalDataStore'
16
- import { IStoreRpc } from '../../proto/packages/dht/protos/DhtRpc.server'
17
- import { StoreRpcRemote } from './StoreRpcRemote'
18
- import { Timestamp } from '../../proto/google/protobuf/timestamp'
19
- import EventEmitter from 'eventemitter3'
20
- import { Events } from '../DhtNode'
21
- import { SortedContactList } from '../contact/SortedContactList'
22
- import { Contact } from '../contact/Contact'
23
- import { DhtNodeRpcRemote } from '../DhtNodeRpcRemote'
24
- import { ServiceID } from '../../types/ServiceID'
25
- import { Empty } from '../../proto/google/protobuf/empty'
26
14
 
27
- interface DataStoreConfig {
28
- rpcCommunicator: RoutingRpcCommunicator
29
- finder: IFinder
30
- localPeerDescriptor: PeerDescriptor
15
+ interface StoreRpcLocalConfig {
31
16
  localDataStore: LocalDataStore
32
- serviceId: ServiceID
33
- maxTtl: number
34
- highestTtl: number
35
- redundancyFactor: number
36
- dhtNodeEmitter: EventEmitter<Events>
37
- getNodesClosestToIdFromBucket: (id: Uint8Array, n?: number) => DhtNodeRpcRemote[]
38
- rpcRequestTimeout?: number
17
+ replicateDataToNeighbors: (incomingPeer: PeerDescriptor, dataEntry: DataEntry) => void
18
+ selfIsWithinRedundancyFactor: (key: Uint8Array) => boolean
39
19
  }
40
20
 
41
21
  const logger = new Logger(module)
42
22
 
43
23
  export class StoreRpcLocal implements IStoreRpc {
44
24
 
45
- private readonly rpcCommunicator: RoutingRpcCommunicator
46
- private readonly finder: IFinder
47
- private readonly localPeerDescriptor: PeerDescriptor
48
- private readonly localDataStore: LocalDataStore
49
- private readonly serviceId: ServiceID
50
- private readonly maxTtl: number
51
- private readonly highestTtl: number
52
- private readonly redundancyFactor: number
53
- private readonly dhtNodeEmitter: EventEmitter<Events>
54
- private readonly getNodesClosestToIdFromBucket: (id: Uint8Array, n?: number) => DhtNodeRpcRemote[]
55
- private readonly rpcRequestTimeout?: number
56
-
57
- constructor(config: DataStoreConfig) {
58
- this.rpcCommunicator = config.rpcCommunicator
59
- this.finder = config.finder
60
- this.localPeerDescriptor = config.localPeerDescriptor
61
- this.localDataStore = config.localDataStore
62
- this.serviceId = config.serviceId
63
- this.maxTtl = config.maxTtl
64
- this.highestTtl = config.highestTtl
65
- this.redundancyFactor = config.redundancyFactor
66
- this.dhtNodeEmitter = config.dhtNodeEmitter
67
- this.rpcRequestTimeout = config.rpcRequestTimeout
68
- this.getNodesClosestToIdFromBucket = config.getNodesClosestToIdFromBucket
69
- this.rpcCommunicator.registerRpcMethod(StoreDataRequest, StoreDataResponse, 'storeData',
70
- (request: StoreDataRequest) => this.storeData(request))
71
- this.rpcCommunicator.registerRpcNotification(ReplicateDataRequest, 'replicateData',
72
- (request: ReplicateDataRequest, context: ServerCallContext) => this.replicateData(request, context))
73
-
74
- this.dhtNodeEmitter.on('newContact', (peerDescriptor: PeerDescriptor) => {
75
- this.localDataStore.getStore().forEach((dataMap, _dataKey) => {
76
- dataMap.forEach(async (dataEntry) => {
77
- if (this.shouldReplicateDataToNewNode(dataEntry.dataEntry, peerDescriptor)) {
78
- try {
79
- await this.replicateDataToContact(dataEntry.dataEntry, peerDescriptor)
80
- } catch (e) {
81
- logger.trace('replicateDataToContact() failed', { error: e })
82
- }
83
- }
84
- })
85
- })
86
- })
87
- }
88
-
89
- private shouldReplicateDataToNewNode(dataEntry: DataEntry, newNode: PeerDescriptor): boolean {
25
+ private readonly config: StoreRpcLocalConfig
90
26
 
91
- const dataId = PeerID.fromValue(dataEntry.key)
92
- const newNodeId = PeerID.fromValue(newNode.nodeId)
93
- const localPeerId = PeerID.fromValue(this.localPeerDescriptor.nodeId)
94
-
95
- const closestToData = this.getNodesClosestToIdFromBucket(dataEntry.key, 10)
96
- const sortedList = new SortedContactList<Contact>({
97
- referenceId: PeerID.fromValue(dataEntry.key),
98
- maxSize: 20, // TODO use config option or named constant?
99
- allowToContainReferenceId: true,
100
- emitEvents: false
101
- })
102
- sortedList.addContact(new Contact(this.localPeerDescriptor))
103
-
104
- closestToData.forEach((con) => {
105
- if (!newNodeId.equals(PeerID.fromValue(con.getPeerDescriptor().nodeId))) {
106
- sortedList.addContact(new Contact(con.getPeerDescriptor()))
107
- }
108
- })
109
-
110
- if (!sortedList.getAllContacts()[0].getPeerId().equals(localPeerId)) {
111
- // If we are not the closes node to the data, do not replicate
112
- return false
113
- }
114
-
115
- this.localDataStore.setStale(dataId, dataEntry.creator!, false)
116
- const newPeerId = PeerID.fromValue(newNode.nodeId)
117
- sortedList.addContact(new Contact(newNode))
118
-
119
- const sorted = sortedList.getAllContacts()
120
-
121
- let index = 0
122
-
123
- for (index = 0; index < sorted.length; index++) {
124
- if (sorted[index].getPeerId().equals(newPeerId)) {
125
- break
126
- }
127
- }
128
-
129
- // if new node is within the storageRedundancyFactor closest nodes to the data
130
- // do replicate data to it
131
-
132
- if (index < this.redundancyFactor) {
133
- return true
134
- } else {
135
- return false
136
- }
27
+ constructor(config: StoreRpcLocalConfig) {
28
+ this.config = config
137
29
  }
138
30
 
139
- private async replicateDataToContact(dataEntry: DataEntry, contact: PeerDescriptor, doNotConnect: boolean = false): Promise<void> {
140
- const rpcRemote = new StoreRpcRemote(
141
- this.localPeerDescriptor,
142
- contact,
143
- this.serviceId,
144
- toProtoRpcClient(new StoreRpcClient(this.rpcCommunicator.getRpcClientTransport())),
145
- this.rpcRequestTimeout
146
- )
147
- try {
148
- await rpcRemote.replicateData({ entry: dataEntry }, doNotConnect)
149
- } catch (e) {
150
- logger.trace('replicateData() threw an exception ' + e)
151
- }
152
- }
153
-
154
- public async storeDataToDht(key: Uint8Array, data: Any, creator: PeerDescriptor): Promise<PeerDescriptor[]> {
155
- logger.debug(`Storing data to DHT ${this.serviceId}`)
156
- const result = await this.finder.startFind(key)
157
- const closestNodes = result.closestNodes
158
- const successfulNodes: PeerDescriptor[] = []
159
- const ttl = this.highestTtl // ToDo: make TTL decrease according to some nice curve
160
- const createdAt = Timestamp.now()
161
- for (let i = 0; i < closestNodes.length && successfulNodes.length < this.redundancyFactor; i++) {
162
- if (areEqualPeerDescriptors(this.localPeerDescriptor, closestNodes[i])) {
163
- this.localDataStore.storeEntry({
164
- key,
165
- data,
166
- creator,
167
- createdAt,
168
- storedAt: Timestamp.now(),
169
- ttl,
170
- stale: false,
171
- deleted: false,
172
- })
173
- successfulNodes.push(closestNodes[i])
174
- continue
175
- }
176
- const rpcRemote = new StoreRpcRemote(
177
- this.localPeerDescriptor,
178
- closestNodes[i],
179
- this.serviceId,
180
- toProtoRpcClient(new StoreRpcClient(this.rpcCommunicator.getRpcClientTransport())),
181
- this.rpcRequestTimeout
182
- )
183
- try {
184
- const response = await rpcRemote.storeData({
185
- key,
186
- data,
187
- creator,
188
- createdAt,
189
- ttl
190
- })
191
- if (!response.error) {
192
- successfulNodes.push(closestNodes[i])
193
- logger.trace('remote.storeData() returned success')
194
- } else {
195
- logger.trace('remote.storeData() returned error: ' + response.error)
196
- }
197
- } catch (e) {
198
- logger.trace('remote.storeData() threw an exception ' + e)
199
- }
200
- }
201
- return successfulNodes
202
- }
203
-
204
- private selfIsOneOfClosestPeers(dataId: Uint8Array): boolean {
205
- const localPeerId = PeerID.fromValue(this.localPeerDescriptor.nodeId)
206
- const closestPeers = this.getNodesClosestToIdFromBucket(dataId, this.redundancyFactor)
207
- const sortedList = new SortedContactList<Contact>({
208
- referenceId: localPeerId,
209
- maxSize: this.redundancyFactor,
210
- allowToContainReferenceId: true,
211
- emitEvents: false
212
- })
213
- sortedList.addContact(new Contact(this.localPeerDescriptor))
214
- closestPeers.forEach((con) => sortedList.addContact(new Contact(con.getPeerDescriptor())))
215
- return sortedList.getClosestContacts().some((node) => node.getPeerId().equals(localPeerId))
216
- }
217
-
218
- // RPC service implementation
219
31
  async storeData(request: StoreDataRequest): Promise<StoreDataResponse> {
220
- const ttl = Math.min(request.ttl, this.maxTtl)
221
- const { key, data, createdAt, creator } = request
222
- this.localDataStore.storeEntry({
32
+ logger.trace('storeData()')
33
+ const { key, data, creator, createdAt, ttl } = request
34
+ const selfIsOneOfClosestPeers = this.config.selfIsWithinRedundancyFactor(key)
35
+ this.config.localDataStore.storeEntry({
223
36
  key,
224
37
  data,
225
38
  creator,
226
39
  createdAt,
227
40
  storedAt: Timestamp.now(),
228
41
  ttl,
229
- stale: !this.selfIsOneOfClosestPeers(key),
42
+ stale: !selfIsOneOfClosestPeers,
230
43
  deleted: false
231
44
  })
232
-
233
- if (!this.selfIsOneOfClosestPeers(key)) {
234
- this.localDataStore.setAllEntriesAsStale(PeerID.fromValue(key))
45
+ if (!selfIsOneOfClosestPeers) {
46
+ this.config.localDataStore.setAllEntriesAsStale(key)
235
47
  }
236
-
237
- logger.trace('storeData()')
238
- return StoreDataResponse.create()
239
- }
240
-
241
- async destroy(): Promise<void> {
242
- await this.replicateDataToClosestNodes()
243
- }
244
-
245
- private async replicateDataToClosestNodes(): Promise<void> {
246
- const dataEntries = Array.from(this.localDataStore.getStore().values())
247
- .flatMap((dataMap) => Array.from(dataMap.values()))
248
- .map((localData) => localData.dataEntry)
249
-
250
- await Promise.all(dataEntries.map(async (dataEntry) => {
251
- const dhtNodeRemotes = this.getNodesClosestToIdFromBucket(dataEntry.key, this.redundancyFactor)
252
- await Promise.all(dhtNodeRemotes.map(async (remoteDhtNode) => {
253
- const rpcRemote = new StoreRpcRemote(
254
- this.localPeerDescriptor,
255
- remoteDhtNode.getPeerDescriptor(),
256
- this.serviceId,
257
- toProtoRpcClient(new StoreRpcClient(this.rpcCommunicator.getRpcClientTransport())),
258
- this.rpcRequestTimeout
259
- )
260
- try {
261
- await rpcRemote.replicateData({ entry: dataEntry })
262
- } catch (err) {
263
- logger.trace('Failed to replicate data in replicateDataToClosestNodes', { error: err })
264
- }
265
- }))
266
- }))
48
+ return {}
267
49
  }
268
50
 
269
- // RPC service implementation
270
51
  public async replicateData(request: ReplicateDataRequest, context: ServerCallContext): Promise<Empty> {
271
52
  logger.trace('server-side replicateData()')
272
53
  const dataEntry = request.entry!
273
-
274
- const wasStored = this.localDataStore.storeEntry(dataEntry)
275
-
54
+ const wasStored = this.config.localDataStore.storeEntry(dataEntry)
276
55
  if (wasStored) {
277
- this.replicateDataToNeighborsIfNeeded((context as DhtCallContext).incomingSourceDescriptor!, request.entry!)
56
+ this.config.replicateDataToNeighbors((context as DhtCallContext).incomingSourceDescriptor!, request.entry!)
278
57
  }
279
- if (!this.selfIsOneOfClosestPeers(dataEntry.key)) {
280
- this.localDataStore.setAllEntriesAsStale(PeerID.fromValue(dataEntry.key))
58
+ if (!this.config.selfIsWithinRedundancyFactor(dataEntry.key)) {
59
+ this.config.localDataStore.setAllEntriesAsStale(dataEntry.key)
281
60
  }
282
61
  logger.trace('server-side replicateData() at end')
283
62
  return {}
284
63
  }
285
-
286
- private replicateDataToNeighborsIfNeeded(incomingPeer: PeerDescriptor, dataEntry: DataEntry): void {
287
-
288
- // sort own contact list according to data id
289
- const localPeerId = PeerID.fromValue(this.localPeerDescriptor.nodeId)
290
- const dataId = PeerID.fromValue(dataEntry.key)
291
- const incomingPeerId = PeerID.fromValue(incomingPeer.nodeId)
292
- const closestToData = this.getNodesClosestToIdFromBucket(dataEntry.key, 10)
293
- const sortedList = new SortedContactList<Contact>({
294
- referenceId: dataId,
295
- maxSize: this.redundancyFactor,
296
- allowToContainReferenceId: true,
297
- emitEvents: false
298
- })
299
- sortedList.addContact(new Contact(this.localPeerDescriptor))
300
-
301
- closestToData.forEach((con) => {
302
- sortedList.addContact(new Contact(con.getPeerDescriptor()))
303
- })
304
-
305
- if (!sortedList.getAllContacts()[0].getPeerId().equals(localPeerId)) {
306
- // If we are not the closest node to the data, replicate only to the
307
- // closest one to the data
308
-
309
- const contact = sortedList.getAllContacts()[0]
310
- const contactPeerId = PeerID.fromValue(contact.getPeerDescriptor().nodeId)
311
- if (!incomingPeerId.equals(contactPeerId) && !localPeerId.equals(contactPeerId)) {
312
- setImmediate(async () => {
313
- try {
314
- await this.replicateDataToContact(dataEntry, contact.getPeerDescriptor())
315
- logger.trace('replicateDataToContact() returned when migrating to only the closest contact')
316
- } catch (e) {
317
- logger.error('replicating data to only the closest contact failed ' + e)
318
- }
319
- })
320
- }
321
- } else {
322
- // if we are the closest to the data, replicate to all storageRedundancyFactor nearest
323
- sortedList.getAllContacts().forEach((contact) => {
324
- const contactPeerId = PeerID.fromValue(contact.getPeerDescriptor().nodeId)
325
- if (!incomingPeerId.equals(contactPeerId) && !localPeerId.equals(contactPeerId)) {
326
- if (!incomingPeerId.equals(contactPeerId) && !localPeerId.equals(contactPeerId)) {
327
- setImmediate(async () => {
328
- try {
329
- await this.replicateDataToContact(dataEntry, contact.getPeerDescriptor())
330
- logger.trace('replicateDataToContact() returned')
331
- } catch (e) {
332
- logger.error('replicating data to one of the closest contacts failed ' + e)
333
- }
334
- })
335
- }
336
- }
337
- })
338
- }
339
- }
340
64
  }
@@ -1,18 +1,17 @@
1
- import { EXISTING_CONNECTION_TIMEOUT, RpcRemote } from '../contact/RpcRemote'
2
- import { IStoreRpcClient } from '../../proto/packages/dht/protos/DhtRpc.client'
1
+ import { getNodeIdFromPeerDescriptor } from '../../helpers/peerIdFromPeerDescriptor'
3
2
  import {
4
3
  ReplicateDataRequest,
5
- StoreDataRequest,
6
- StoreDataResponse
4
+ StoreDataRequest
7
5
  } from '../../proto/packages/dht/protos/DhtRpc'
8
- import { getNodeIdFromPeerDescriptor } from '../../helpers/peerIdFromPeerDescriptor'
6
+ import { StoreRpcClient } from '../../proto/packages/dht/protos/DhtRpc.client'
7
+ import { EXISTING_CONNECTION_TIMEOUT, RpcRemote } from '../contact/RpcRemote'
9
8
 
10
- export class StoreRpcRemote extends RpcRemote<IStoreRpcClient> {
9
+ export class StoreRpcRemote extends RpcRemote<StoreRpcClient> {
11
10
 
12
- async storeData(request: StoreDataRequest): Promise<StoreDataResponse> {
11
+ async storeData(request: StoreDataRequest): Promise<void> {
13
12
  const options = this.formDhtRpcOptions()
14
13
  try {
15
- return await this.getClient().storeData(request, options)
14
+ await this.getClient().storeData(request, options)
16
15
  } catch (err) {
17
16
  const to = getNodeIdFromPeerDescriptor(this.getPeerDescriptor())
18
17
  const from = getNodeIdFromPeerDescriptor(this.getLocalPeerDescriptor())
@@ -20,10 +19,9 @@ export class StoreRpcRemote extends RpcRemote<IStoreRpcClient> {
20
19
  }
21
20
  }
22
21
 
23
- async replicateData(request: ReplicateDataRequest, doNotConnect: boolean = false): Promise<void> {
22
+ async replicateData(request: ReplicateDataRequest): Promise<void> {
24
23
  const options = this.formDhtRpcOptions({
25
- timeout: EXISTING_CONNECTION_TIMEOUT,
26
- doNotConnect
24
+ timeout: EXISTING_CONNECTION_TIMEOUT
27
25
  })
28
26
  return this.getClient().replicateData(request, options)
29
27
  }
package/src/exports.ts CHANGED
@@ -7,6 +7,7 @@ export { getRandomRegion, getRegionDelayMatrix } from './connection/simulator/pi
7
7
  export { PeerDescriptor, Message, NodeType, DataEntry } from './proto/packages/dht/protos/DhtRpc'
8
8
  export { ITransport } from './transport/ITransport'
9
9
  export { ConnectionManager, ConnectionLocker, PortRange, TlsCertificate } from './connection/ConnectionManager'
10
+ export { LockID } from './connection/ConnectionLockHandler'
10
11
  export { DefaultConnectorFacade } from './connection/ConnectorFacade'
11
12
  export { DhtRpcOptions } from './rpc-protocol/DhtRpcOptions'
12
13
  export { RpcRemote, EXISTING_CONNECTION_TIMEOUT } from './dht/contact/RpcRemote'
@@ -17,3 +18,4 @@ export { ClientWebsocket } from './connection/websocket/ClientWebsocket'
17
18
  export { ManagedConnection } from './connection/ManagedConnection'
18
19
  export { ConnectionType } from './connection/IConnection'
19
20
  export { PeerID } from './helpers/PeerID'
21
+ export { ServiceID } from './types/ServiceID'
@@ -0,0 +1,71 @@
1
+ interface ValueWrapper<V> {
2
+ value: V
3
+ timeout: NodeJS.Timeout
4
+ }
5
+
6
+ export class MapWithTtl<K, V> {
7
+
8
+ private readonly delegate: Map<K, ValueWrapper<V>> = new Map()
9
+ private readonly getTtl: (value: V) => number
10
+
11
+ constructor(getTtl: (value: V) => number) {
12
+ this.getTtl = getTtl
13
+ }
14
+
15
+ set(key: K, value: V): void {
16
+ const existing = this.delegate.get(key)
17
+ if (existing !== undefined) {
18
+ clearTimeout(existing.timeout)
19
+ }
20
+ this.delegate.set(key, {
21
+ value,
22
+ timeout: this.createTimeout(key, value)
23
+ })
24
+ }
25
+
26
+ get(key: K): V | undefined {
27
+ const wrapper = this.delegate.get(key)
28
+ return wrapper?.value
29
+ }
30
+
31
+ has(key: K): boolean {
32
+ return this.delegate.has(key)
33
+ }
34
+
35
+ delete(key: K): void {
36
+ const existing = this.delegate.get(key)
37
+ if (existing !== undefined) {
38
+ clearTimeout(existing.timeout)
39
+ this.delegate.delete(key)
40
+ }
41
+ }
42
+
43
+ clear(): void {
44
+ this.delegate.forEach((value) => {
45
+ clearTimeout(value.timeout)
46
+ })
47
+ this.delegate.clear()
48
+ }
49
+
50
+ size(): number {
51
+ return this.delegate.size
52
+ }
53
+
54
+ *values(): IterableIterator<V> {
55
+ for (const v of this.delegate.values()) {
56
+ yield v.value
57
+ }
58
+ }
59
+
60
+ forEach(cb: (value: V, key: K) => void): void {
61
+ this.delegate.forEach((valueWrapper: ValueWrapper<V>, key: K) => {
62
+ cb(valueWrapper.value, key)
63
+ })
64
+ }
65
+
66
+ private createTimeout(key: K, value: V): NodeJS.Timeout {
67
+ return setTimeout(() => {
68
+ this.delete(key)
69
+ }, this.getTtl(value))
70
+ }
71
+ }
@@ -2,6 +2,7 @@ import { BrandedString, binaryToHex } from '@streamr/utils'
2
2
  import { UUID } from './UUID'
3
3
  import { IllegalArguments } from './errors'
4
4
  import crypto from 'crypto'
5
+ import { NodeID, getNodeIdFromBinary } from './nodeId'
5
6
 
6
7
  export type PeerIDKey = BrandedString<'PeerIDKey'>
7
8
 
@@ -75,6 +76,10 @@ export class PeerID {
75
76
  return this.key
76
77
  }
77
78
 
79
+ toNodeId(): NodeID {
80
+ return getNodeIdFromBinary(this.data)
81
+ }
82
+
78
83
  get value(): Uint8Array {
79
84
  return this.data
80
85
  }
@@ -1,8 +1,28 @@
1
+ import { BrandedString, binaryToHex } from '@streamr/utils'
1
2
  import crypto from 'crypto'
2
3
 
3
4
  // https://www.scs.stanford.edu/~dm/home/papers/kpos.pdf
4
5
  const KADEMLIA_ID_LENGTH_IN_BYTES = 20
5
6
 
7
+ // TODO this should return NodeID
6
8
  export const createRandomNodeId = (): Uint8Array => {
7
9
  return crypto.randomBytes(KADEMLIA_ID_LENGTH_IN_BYTES)
8
10
  }
11
+
12
+ // TODO rename the file to be "NodeID.ts" instead of "nodeId.ts"
13
+ export type NodeID = BrandedString<'NodeID'>
14
+
15
+ // TODO remove this or add support for UInt8Array parameters
16
+ export const areEqualNodeIds = (nodeId1: NodeID, nodeId2: NodeID): boolean => {
17
+ return nodeId1 === nodeId2
18
+ }
19
+
20
+ // TODO maybe this is not needed and we can use just getNodeIdFromBinary?
21
+ export const getNodeIdFromDataKey = (key: Uint8Array): NodeID => {
22
+ return getNodeIdFromBinary(key)
23
+ }
24
+
25
+ // TODO should we have similar method to convert nodeId to bucketId (which is just hexToBinary)
26
+ export const getNodeIdFromBinary = (id: Uint8Array): NodeID => {
27
+ return binaryToHex(id) as unknown as NodeID
28
+ }
@@ -1,14 +1,16 @@
1
1
  import { areEqualBinaries, binaryToHex } from '@streamr/utils'
2
2
  import { PeerDescriptor } from '../proto/packages/dht/protos/DhtRpc'
3
3
  import { PeerID, PeerIDKey, createPeerIDKey } from './PeerID'
4
+ import { NodeID } from './nodeId'
4
5
 
5
6
  export const peerIdFromPeerDescriptor = (peerDescriptor: PeerDescriptor): PeerID => {
6
7
  return PeerID.fromValue(peerDescriptor.nodeId)
7
8
  }
8
9
 
9
- // TODO could move getNodeIdFromPeerDescriptor (and NodeID) from trackerless-network
10
- export const getNodeIdFromPeerDescriptor = (peerDescriptor: PeerDescriptor): string => {
11
- return binaryToHex(peerDescriptor.nodeId)
10
+ // TODO could use this in trackerless-network (instead of copy-pasted same implementation)
11
+ // and move this to nodeId.ts
12
+ export const getNodeIdFromPeerDescriptor = (peerDescriptor: PeerDescriptor): NodeID => {
13
+ return binaryToHex(peerDescriptor.nodeId) as unknown as NodeID
12
14
  }
13
15
 
14
16
  export const keyFromPeerDescriptor = (peerDescriptor: PeerDescriptor): PeerIDKey => {
@@ -13,12 +13,11 @@ import {
13
13
  PeerDescriptor,
14
14
  PingRequest,
15
15
  PingResponse,
16
- FindResponse,
17
- FindRequest,
16
+ RecursiveOperationResponse,
17
+ RecursiveOperationRequest,
18
18
  RouteMessageAck,
19
19
  RouteMessageWrapper,
20
20
  WebsocketConnectionRequest,
21
- WebsocketConnectionResponse,
22
21
  WebrtcConnectionRequest,
23
22
  RtcOffer,
24
23
  RtcAnswer,
@@ -32,8 +31,8 @@ import {
32
31
  export const protoClasses: Array<IMessageType<any>> = [
33
32
  ClosestPeersRequest,
34
33
  ClosestPeersResponse,
35
- FindRequest,
36
- FindResponse,
34
+ RecursiveOperationRequest,
35
+ RecursiveOperationResponse,
37
36
  PingRequest,
38
37
  PingResponse,
39
38
  LeaveNotice,
@@ -48,7 +47,6 @@ export const protoClasses: Array<IMessageType<any>> = [
48
47
  HandshakeResponse,
49
48
  Message,
50
49
  WebsocketConnectionRequest,
51
- WebsocketConnectionResponse,
52
50
  WebrtcConnectionRequest,
53
51
  RtcOffer,
54
52
  RtcAnswer,