@streamr/dht 100.0.0-testnet-two.4 → 100.0.0-testnet-three.1

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 (306) hide show
  1. package/dist/package.json +8 -9
  2. package/dist/src/connection/Connection.d.ts +1 -0
  3. package/dist/src/connection/Connection.js +10 -3
  4. package/dist/src/connection/Connection.js.map +1 -1
  5. package/dist/src/connection/ConnectionLockHandler.d.ts +3 -3
  6. package/dist/src/connection/ConnectionLockHandler.js +8 -10
  7. package/dist/src/connection/ConnectionLockHandler.js.map +1 -1
  8. package/dist/src/connection/ConnectionLockRpcLocal.js +5 -4
  9. package/dist/src/connection/ConnectionLockRpcLocal.js.map +1 -1
  10. package/dist/src/connection/ConnectionLockRpcRemote.js +4 -4
  11. package/dist/src/connection/ConnectionLockRpcRemote.js.map +1 -1
  12. package/dist/src/connection/ConnectionManager.d.ts +8 -8
  13. package/dist/src/connection/ConnectionManager.js +54 -55
  14. package/dist/src/connection/ConnectionManager.js.map +1 -1
  15. package/dist/src/connection/ConnectorFacade.d.ts +3 -2
  16. package/dist/src/connection/ConnectorFacade.js +7 -0
  17. package/dist/src/connection/ConnectorFacade.js.map +1 -1
  18. package/dist/src/connection/Handshaker.js +3 -1
  19. package/dist/src/connection/Handshaker.js.map +1 -1
  20. package/dist/src/connection/IConnection.d.ts +2 -7
  21. package/dist/src/connection/IConnection.js +1 -8
  22. package/dist/src/connection/IConnection.js.map +1 -1
  23. package/dist/src/connection/ManagedConnection.js +23 -15
  24. package/dist/src/connection/ManagedConnection.js.map +1 -1
  25. package/dist/src/connection/ManagedWebrtcConnection.js.map +1 -1
  26. package/dist/src/connection/connectivityChecker.d.ts +1 -1
  27. package/dist/src/connection/connectivityChecker.js +9 -2
  28. package/dist/src/connection/connectivityChecker.js.map +1 -1
  29. package/dist/src/connection/connectivityRequestHandler.js +8 -2
  30. package/dist/src/connection/connectivityRequestHandler.js.map +1 -1
  31. package/dist/src/connection/simulator/Simulator.js +32 -20
  32. package/dist/src/connection/simulator/Simulator.js.map +1 -1
  33. package/dist/src/connection/simulator/SimulatorConnection.js +13 -10
  34. package/dist/src/connection/simulator/SimulatorConnection.js.map +1 -1
  35. package/dist/src/connection/simulator/SimulatorConnector.js +9 -6
  36. package/dist/src/connection/simulator/SimulatorConnector.js.map +1 -1
  37. package/dist/src/connection/simulator/pings.js.map +1 -1
  38. package/dist/src/connection/webrtc/NodeWebrtcConnection.d.ts +1 -1
  39. package/dist/src/connection/webrtc/NodeWebrtcConnection.js +26 -14
  40. package/dist/src/connection/webrtc/NodeWebrtcConnection.js.map +1 -1
  41. package/dist/src/connection/webrtc/WebrtcConnector.d.ts +0 -1
  42. package/dist/src/connection/webrtc/WebrtcConnector.js +18 -17
  43. package/dist/src/connection/webrtc/WebrtcConnector.js.map +1 -1
  44. package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js +10 -9
  45. package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js.map +1 -1
  46. package/dist/src/connection/webrtc/iceServerAsString.js.map +1 -1
  47. package/dist/src/connection/websocket/AutoCertifierClientFacade.js +3 -0
  48. package/dist/src/connection/websocket/AutoCertifierClientFacade.js.map +1 -1
  49. package/dist/src/connection/websocket/ClientWebsocket.js +7 -4
  50. package/dist/src/connection/websocket/ClientWebsocket.js.map +1 -1
  51. package/dist/src/connection/websocket/ServerWebsocket.d.ts +1 -0
  52. package/dist/src/connection/websocket/ServerWebsocket.js +22 -3
  53. package/dist/src/connection/websocket/ServerWebsocket.js.map +1 -1
  54. package/dist/src/connection/websocket/WebsocketConnector.d.ts +2 -1
  55. package/dist/src/connection/websocket/WebsocketConnector.js +27 -16
  56. package/dist/src/connection/websocket/WebsocketConnector.js.map +1 -1
  57. package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.d.ts +2 -1
  58. package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.js +3 -1
  59. package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.js.map +1 -1
  60. package/dist/src/connection/websocket/WebsocketConnectorRpcRemote.js +2 -2
  61. package/dist/src/connection/websocket/WebsocketConnectorRpcRemote.js.map +1 -1
  62. package/dist/src/connection/websocket/WebsocketServer.js +6 -3
  63. package/dist/src/connection/websocket/WebsocketServer.js.map +1 -1
  64. package/dist/src/dht/DhtNode.d.ts +18 -19
  65. package/dist/src/dht/DhtNode.js +56 -65
  66. package/dist/src/dht/DhtNode.js.map +1 -1
  67. package/dist/src/dht/DhtNodeRpcLocal.d.ts +1 -1
  68. package/dist/src/dht/DhtNodeRpcLocal.js +5 -4
  69. package/dist/src/dht/DhtNodeRpcLocal.js.map +1 -1
  70. package/dist/src/dht/DhtNodeRpcRemote.d.ts +2 -1
  71. package/dist/src/dht/DhtNodeRpcRemote.js +5 -3
  72. package/dist/src/dht/DhtNodeRpcRemote.js.map +1 -1
  73. package/dist/src/dht/ExternalApiRpcLocal.d.ts +1 -1
  74. package/dist/src/dht/ExternalApiRpcLocal.js +4 -3
  75. package/dist/src/dht/ExternalApiRpcLocal.js.map +1 -1
  76. package/dist/src/dht/ExternalApiRpcRemote.js.map +1 -1
  77. package/dist/src/dht/PeerManager.d.ts +5 -5
  78. package/dist/src/dht/PeerManager.js +31 -24
  79. package/dist/src/dht/PeerManager.js.map +1 -1
  80. package/dist/src/dht/contact/Contact.js +3 -2
  81. package/dist/src/dht/contact/Contact.js.map +1 -1
  82. package/dist/src/dht/contact/ContactList.js +9 -5
  83. package/dist/src/dht/contact/ContactList.js.map +1 -1
  84. package/dist/src/dht/contact/RandomContactList.js +1 -0
  85. package/dist/src/dht/contact/RandomContactList.js.map +1 -1
  86. package/dist/src/dht/contact/RpcRemote.d.ts +2 -1
  87. package/dist/src/dht/contact/RpcRemote.js +4 -0
  88. package/dist/src/dht/contact/RpcRemote.js.map +1 -1
  89. package/dist/src/dht/contact/SortedContactList.js +3 -2
  90. package/dist/src/dht/contact/SortedContactList.js.map +1 -1
  91. package/dist/src/dht/discovery/DiscoverySession.js +8 -8
  92. package/dist/src/dht/discovery/DiscoverySession.js.map +1 -1
  93. package/dist/src/dht/discovery/PeerDiscovery.d.ts +8 -2
  94. package/dist/src/dht/discovery/PeerDiscovery.js +26 -17
  95. package/dist/src/dht/discovery/PeerDiscovery.js.map +1 -1
  96. package/dist/src/dht/recursive-operation/RecursiveOperationManager.d.ts +1 -1
  97. package/dist/src/dht/recursive-operation/RecursiveOperationManager.js +9 -9
  98. package/dist/src/dht/recursive-operation/RecursiveOperationManager.js.map +1 -1
  99. package/dist/src/dht/recursive-operation/RecursiveOperationRpcLocal.js +3 -2
  100. package/dist/src/dht/recursive-operation/RecursiveOperationRpcLocal.js.map +1 -1
  101. package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.js +6 -5
  102. package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.js.map +1 -1
  103. package/dist/src/dht/recursive-operation/RecursiveOperationSession.d.ts +2 -1
  104. package/dist/src/dht/recursive-operation/RecursiveOperationSession.js +26 -20
  105. package/dist/src/dht/recursive-operation/RecursiveOperationSession.js.map +1 -1
  106. package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.d.ts +4 -2
  107. package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.js +5 -2
  108. package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.js.map +1 -1
  109. package/dist/src/dht/routing/DuplicateDetector.d.ts +2 -4
  110. package/dist/src/dht/routing/DuplicateDetector.js +10 -15
  111. package/dist/src/dht/routing/DuplicateDetector.js.map +1 -1
  112. package/dist/src/dht/routing/Router.d.ts +1 -1
  113. package/dist/src/dht/routing/Router.js +20 -15
  114. package/dist/src/dht/routing/Router.js.map +1 -1
  115. package/dist/src/dht/routing/RouterRpcLocal.js +4 -4
  116. package/dist/src/dht/routing/RouterRpcLocal.js.map +1 -1
  117. package/dist/src/dht/routing/RouterRpcRemote.js +11 -9
  118. package/dist/src/dht/routing/RouterRpcRemote.js.map +1 -1
  119. package/dist/src/dht/routing/RoutingSession.d.ts +2 -0
  120. package/dist/src/dht/routing/RoutingSession.js +27 -9
  121. package/dist/src/dht/routing/RoutingSession.js.map +1 -1
  122. package/dist/src/dht/store/LocalDataStore.js +5 -4
  123. package/dist/src/dht/store/LocalDataStore.js.map +1 -1
  124. package/dist/src/dht/store/StoreManager.js +8 -8
  125. package/dist/src/dht/store/StoreManager.js.map +1 -1
  126. package/dist/src/dht/store/StoreRpcLocal.js +1 -0
  127. package/dist/src/dht/store/StoreRpcLocal.js.map +1 -1
  128. package/dist/src/dht/store/StoreRpcRemote.js +3 -3
  129. package/dist/src/dht/store/StoreRpcRemote.js.map +1 -1
  130. package/dist/src/exports.d.ts +1 -4
  131. package/dist/src/exports.js +4 -7
  132. package/dist/src/exports.js.map +1 -1
  133. package/dist/src/helpers/AddressTools.js.map +1 -1
  134. package/dist/src/helpers/Connectivity.js.map +1 -1
  135. package/dist/src/helpers/MapWithTtl.js +2 -1
  136. package/dist/src/helpers/MapWithTtl.js.map +1 -1
  137. package/dist/src/helpers/createPeerDescriptor.d.ts +3 -0
  138. package/dist/src/helpers/createPeerDescriptor.js +56 -0
  139. package/dist/src/helpers/createPeerDescriptor.js.map +1 -0
  140. package/dist/src/helpers/createPeerDescriptorSignaturePayload.d.ts +2 -0
  141. package/dist/src/helpers/createPeerDescriptorSignaturePayload.js +30 -0
  142. package/dist/src/helpers/createPeerDescriptorSignaturePayload.js.map +1 -0
  143. package/dist/src/helpers/debugHelpers.js.map +1 -1
  144. package/dist/src/helpers/errors.js +2 -0
  145. package/dist/src/helpers/errors.js.map +1 -1
  146. package/dist/src/helpers/offering.d.ts +4 -0
  147. package/dist/src/helpers/offering.js +18 -0
  148. package/dist/src/helpers/offering.js.map +1 -0
  149. package/dist/src/helpers/protoToString.js.map +1 -1
  150. package/dist/src/identifiers.d.ts +3 -0
  151. package/dist/src/identifiers.js +9 -1
  152. package/dist/src/identifiers.js.map +1 -1
  153. package/dist/src/proto/google/protobuf/any.js +8 -8
  154. package/dist/src/proto/google/protobuf/any.js.map +1 -1
  155. package/dist/src/proto/google/protobuf/empty.js +2 -4
  156. package/dist/src/proto/google/protobuf/empty.js.map +1 -1
  157. package/dist/src/proto/google/protobuf/timestamp.js +10 -10
  158. package/dist/src/proto/google/protobuf/timestamp.js.map +1 -1
  159. package/dist/src/proto/packages/dht/protos/DhtRpc.client.d.ts +4 -5
  160. package/dist/src/proto/packages/dht/protos/DhtRpc.client.js +38 -29
  161. package/dist/src/proto/packages/dht/protos/DhtRpc.client.js.map +1 -1
  162. package/dist/src/proto/packages/dht/protos/DhtRpc.d.ts +26 -12
  163. package/dist/src/proto/packages/dht/protos/DhtRpc.js +12 -16
  164. package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +1 -1
  165. package/dist/src/proto/packages/dht/protos/DhtRpc.server.d.ts +2 -3
  166. package/dist/src/proto/packages/proto-rpc/protos/ProtoRpc.js +1 -1
  167. package/dist/src/rpc-protocol/DhtCallContext.d.ts +0 -1
  168. package/dist/src/rpc-protocol/DhtCallContext.js +8 -0
  169. package/dist/src/rpc-protocol/DhtCallContext.js.map +1 -1
  170. package/dist/src/transport/ITransport.d.ts +1 -1
  171. package/dist/src/transport/ListeningRpcCommunicator.js +2 -0
  172. package/dist/src/transport/ListeningRpcCommunicator.js.map +1 -1
  173. package/dist/src/transport/RoutingRpcCommunicator.d.ts +2 -1
  174. package/dist/src/transport/RoutingRpcCommunicator.js +2 -0
  175. package/dist/src/transport/RoutingRpcCommunicator.js.map +1 -1
  176. package/package.json +8 -9
  177. package/protos/DhtRpc.proto +8 -4
  178. package/src/connection/Connection.ts +6 -1
  179. package/src/connection/ConnectionLockHandler.ts +3 -3
  180. package/src/connection/ConnectionLockRpcLocal.ts +1 -5
  181. package/src/connection/ConnectionLockRpcRemote.ts +1 -1
  182. package/src/connection/ConnectionManager.ts +24 -38
  183. package/src/connection/ConnectorFacade.ts +3 -2
  184. package/src/connection/Handshaker.ts +4 -4
  185. package/src/connection/IConnection.ts +2 -8
  186. package/src/connection/ManagedConnection.ts +3 -3
  187. package/src/connection/connectivityChecker.ts +9 -2
  188. package/src/connection/connectivityRequestHandler.ts +10 -3
  189. package/src/connection/simulator/Simulator.ts +1 -2
  190. package/src/connection/simulator/SimulatorConnection.ts +1 -1
  191. package/src/connection/simulator/SimulatorConnector.ts +1 -2
  192. package/src/connection/webrtc/BrowserWebrtcConnection.ts +4 -3
  193. package/src/connection/webrtc/NodeWebrtcConnection.ts +5 -4
  194. package/src/connection/webrtc/WebrtcConnector.ts +9 -17
  195. package/src/connection/webrtc/WebrtcConnectorRpcLocal.ts +9 -9
  196. package/src/connection/websocket/ClientWebsocket.ts +3 -2
  197. package/src/connection/websocket/ServerWebsocket.ts +17 -1
  198. package/src/connection/websocket/WebsocketConnector.ts +16 -13
  199. package/src/connection/websocket/WebsocketConnectorRpcLocal.ts +4 -2
  200. package/src/connection/websocket/WebsocketConnectorRpcRemote.ts +1 -1
  201. package/src/connection/websocket/WebsocketServer.ts +2 -2
  202. package/src/dht/DhtNode.ts +63 -86
  203. package/src/dht/DhtNodeRpcLocal.ts +5 -5
  204. package/src/dht/DhtNodeRpcRemote.ts +3 -3
  205. package/src/dht/ExternalApiRpcLocal.ts +3 -4
  206. package/src/dht/PeerManager.ts +14 -20
  207. package/src/dht/contact/Contact.ts +1 -2
  208. package/src/dht/contact/RpcRemote.ts +2 -1
  209. package/src/dht/discovery/DiscoverySession.ts +2 -3
  210. package/src/dht/discovery/PeerDiscovery.ts +16 -9
  211. package/src/dht/recursive-operation/RecursiveOperationManager.ts +12 -6
  212. package/src/dht/recursive-operation/RecursiveOperationRpcLocal.ts +1 -1
  213. package/src/dht/recursive-operation/RecursiveOperationRpcRemote.ts +3 -2
  214. package/src/dht/recursive-operation/RecursiveOperationSession.ts +19 -9
  215. package/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.ts +13 -3
  216. package/src/dht/routing/DuplicateDetector.ts +9 -21
  217. package/src/dht/routing/Router.ts +12 -11
  218. package/src/dht/routing/RouterRpcLocal.ts +1 -2
  219. package/src/dht/routing/RouterRpcRemote.ts +5 -5
  220. package/src/dht/routing/RoutingSession.ts +22 -2
  221. package/src/dht/store/StoreManager.ts +1 -2
  222. package/src/dht/store/StoreRpcRemote.ts +1 -1
  223. package/src/exports.ts +9 -4
  224. package/src/helpers/createPeerDescriptor.ts +56 -0
  225. package/src/helpers/createPeerDescriptorSignaturePayload.ts +28 -0
  226. package/src/helpers/offering.ts +15 -0
  227. package/src/identifiers.ts +10 -1
  228. package/src/proto/google/protobuf/any.ts +4 -4
  229. package/src/proto/google/protobuf/empty.ts +2 -4
  230. package/src/proto/google/protobuf/timestamp.ts +4 -4
  231. package/src/proto/packages/dht/protos/DhtRpc.client.ts +6 -7
  232. package/src/proto/packages/dht/protos/DhtRpc.server.ts +3 -4
  233. package/src/proto/packages/dht/protos/DhtRpc.ts +37 -20
  234. package/src/proto/packages/proto-rpc/protos/ProtoRpc.ts +1 -1
  235. package/src/rpc-protocol/DhtCallContext.ts +0 -1
  236. package/src/transport/ITransport.ts +1 -1
  237. package/src/transport/RoutingRpcCommunicator.ts +1 -1
  238. package/test/benchmark/Find.test.ts +6 -8
  239. package/test/benchmark/KademliaCorrectness.test.ts +2 -3
  240. package/test/benchmark/SortedContactListBenchmark.test.ts +16 -16
  241. package/test/benchmark/WebsocketServerMemoryLeak.test.ts +1 -1
  242. package/test/benchmark/kademlia-simulation/KademliaSimulation.ts +8 -8
  243. package/test/benchmark/kademlia-simulation/SimulationNode.ts +8 -8
  244. package/test/end-to-end/Layer0-Layer1.test.ts +1 -1
  245. package/test/end-to-end/Layer0.test.ts +4 -4
  246. package/test/end-to-end/Layer0MixedConnectionTypes.test.ts +12 -12
  247. package/test/end-to-end/Layer0Webrtc-Layer1.test.ts +18 -18
  248. package/test/end-to-end/Layer0Webrtc.test.ts +13 -10
  249. package/test/end-to-end/Layer1-Scale-WebSocket.test.ts +2 -2
  250. package/test/end-to-end/Layer1-Scale-Webrtc.test.ts +2 -2
  251. package/test/end-to-end/RecoveryFromFailedAutoCertification.test.ts +1 -1
  252. package/test/end-to-end/WebsocketConnectionRequest.test.ts +3 -3
  253. package/test/end-to-end/memory-leak.test.ts +2 -2
  254. package/test/integration/ConnectionLocking.test.ts +60 -47
  255. package/test/integration/ConnectionManager.test.ts +8 -7
  256. package/test/integration/ConnectivityChecking.test.ts +64 -0
  257. package/test/integration/DhtJoinPeerDiscovery.test.ts +2 -2
  258. package/test/integration/DhtNodeExternalAPI.test.ts +1 -2
  259. package/test/integration/DhtNodeRpcRemote.test.ts +4 -3
  260. package/test/integration/DhtRpc.test.ts +4 -3
  261. package/test/integration/Find.test.ts +4 -6
  262. package/test/integration/Layer1-scale.test.ts +7 -7
  263. package/test/integration/Mock-Layer1-Layer0.test.ts +21 -24
  264. package/test/integration/MultipleEntryPointJoining.test.ts +7 -7
  265. package/test/integration/ReplicateData.test.ts +52 -161
  266. package/test/integration/RouteMessage.test.ts +24 -47
  267. package/test/integration/RouterRpcRemote.test.ts +7 -4
  268. package/test/integration/ScaleDownDht.test.ts +2 -3
  269. package/test/integration/SimultaneousConnections.test.ts +9 -8
  270. package/test/integration/Store.test.ts +1 -2
  271. package/test/integration/StoreAndDelete.test.ts +5 -0
  272. package/test/integration/StoreOnDhtWithThreeNodes.test.ts +59 -0
  273. package/test/integration/StoreOnDhtWithTwoNodes.test.ts +1 -1
  274. package/test/integration/StoreRpcRemote.test.ts +4 -4
  275. package/test/integration/WebrtcConnectionManagement.test.ts +6 -5
  276. package/test/integration/WebrtcConnectorRpc.test.ts +3 -2
  277. package/test/integration/WebsocketConnectionManagement.test.ts +27 -15
  278. package/test/integration/WebsocketConnectorRpc.test.ts +3 -2
  279. package/test/integration/{RpcErrors.test.ts → rpc-connections-over-webrpc.test.ts} +6 -3
  280. package/test/unit/DuplicateDetector.test.ts +2 -2
  281. package/test/unit/LocalDataStore.test.ts +1 -4
  282. package/test/unit/RandomContactList.test.ts +2 -4
  283. package/test/unit/RecursiveOperationManager.test.ts +5 -6
  284. package/test/unit/RecursiveOperationSession.test.ts +5 -4
  285. package/test/unit/Router.test.ts +25 -8
  286. package/test/unit/RoutingSession.test.ts +3 -3
  287. package/test/unit/SortedContactList.test.ts +2 -4
  288. package/test/unit/connectivityRequestHandler.test.ts +7 -3
  289. package/test/unit/createPeerDescriptor.test.ts +63 -0
  290. package/test/utils/FakeTransport.ts +7 -4
  291. package/test/utils/mock/Transport.ts +1 -1
  292. package/test/utils/utils.ts +6 -6
  293. package/dist/src/helpers/PeerID.d.ts +0 -27
  294. package/dist/src/helpers/PeerID.js +0 -87
  295. package/dist/src/helpers/PeerID.js.map +0 -1
  296. package/dist/src/helpers/UUID.d.ts +0 -8
  297. package/dist/src/helpers/UUID.js +0 -36
  298. package/dist/src/helpers/UUID.js.map +0 -1
  299. package/dist/src/helpers/peerIdFromPeerDescriptor.d.ts +0 -7
  300. package/dist/src/helpers/peerIdFromPeerDescriptor.js +0 -23
  301. package/dist/src/helpers/peerIdFromPeerDescriptor.js.map +0 -1
  302. package/src/helpers/PeerID.ts +0 -97
  303. package/src/helpers/UUID.ts +0 -35
  304. package/src/helpers/peerIdFromPeerDescriptor.ts +0 -20
  305. package/test/unit/PeerID.test.ts +0 -22
  306. package/test/unit/UUID.test.ts +0 -55
@@ -2,9 +2,6 @@ import {
2
2
  Logger
3
3
  } from '@streamr/utils'
4
4
  import KBucket from 'k-bucket'
5
- import {
6
- getNodeIdFromPeerDescriptor
7
- } from '../helpers/peerIdFromPeerDescriptor'
8
5
  import {
9
6
  PeerDescriptor
10
7
  } from '../proto/packages/dht/protos/DhtRpc'
@@ -13,7 +10,7 @@ import { RandomContactList } from './contact/RandomContactList'
13
10
  import { SortedContactList } from './contact/SortedContactList'
14
11
  import { ConnectionManager } from '../connection/ConnectionManager'
15
12
  import EventEmitter from 'eventemitter3'
16
- import { DhtAddress, DhtAddressRaw, getRawFromDhtAddress } from '../identifiers'
13
+ import { DhtAddress, DhtAddressRaw, getNodeIdFromPeerDescriptor, getRawFromDhtAddress } from '../identifiers'
17
14
 
18
15
  const logger = new Logger(module)
19
16
 
@@ -66,7 +63,7 @@ export class PeerManager extends EventEmitter<PeerManagerEvents> {
66
63
  numberOfNodesToPing: this.config.numberOfNodesPerKBucket
67
64
  })
68
65
  this.bucket.on('ping', (oldContacts: DhtNodeRpcRemote[], newContact: DhtNodeRpcRemote) => this.onKBucketPing(oldContacts, newContact))
69
- this.bucket.on('removed', (contact: DhtNodeRpcRemote) => this.onKBucketRemoved(contact))
66
+ this.bucket.on('removed', (contact: DhtNodeRpcRemote) => this.onKBucketRemoved(getNodeIdFromPeerDescriptor(contact.getPeerDescriptor())))
70
67
  this.bucket.on('added', (contact: DhtNodeRpcRemote) => this.onKBucketAdded(contact))
71
68
  this.bucket.on('updated', () => {
72
69
  // TODO: Update contact info to the connection manager and reconnect
@@ -114,11 +111,10 @@ export class PeerManager extends EventEmitter<PeerManagerEvents> {
114
111
  this.bucket.add(newContact)
115
112
  }
116
113
 
117
- private onKBucketRemoved(contact: DhtNodeRpcRemote): void {
114
+ private onKBucketRemoved(nodeId: DhtAddress): void {
118
115
  if (this.stopped) {
119
116
  return
120
117
  }
121
- const nodeId = getNodeIdFromPeerDescriptor(contact.getPeerDescriptor())
122
118
  this.config.connectionManager?.weakUnlockConnection(nodeId)
123
119
  logger.trace(`Removed contact ${nodeId}`)
124
120
  if (this.bucket.count() === 0) {
@@ -145,13 +141,13 @@ export class PeerManager extends EventEmitter<PeerManagerEvents> {
145
141
  } else {
146
142
  logger.trace('ping failed ' + nodeId)
147
143
  this.config.connectionManager?.weakUnlockConnection(nodeId)
148
- this.removeContact(peerDescriptor)
144
+ this.removeContact(nodeId)
149
145
  this.addClosestContactToBucket()
150
146
  }
151
147
  return
152
148
  }).catch((_e) => {
153
149
  this.config.connectionManager?.weakUnlockConnection(nodeId)
154
- this.removeContact(peerDescriptor)
150
+ this.removeContact(nodeId)
155
151
  this.addClosestContactToBucket()
156
152
  })
157
153
  }
@@ -192,30 +188,28 @@ export class PeerManager extends EventEmitter<PeerManagerEvents> {
192
188
  logger.trace('connected: ' + nodeId + ' ' + this.connections.size)
193
189
  }
194
190
 
195
- handleDisconnected(peerDescriptor: PeerDescriptor, gracefulLeave: boolean): void {
196
- const nodeId = getNodeIdFromPeerDescriptor(peerDescriptor)
191
+ handleDisconnected(nodeId: DhtAddress, gracefulLeave: boolean): void {
197
192
  logger.trace('disconnected: ' + nodeId)
198
193
  this.connections.delete(nodeId)
199
194
  if (this.config.isLayer0) {
200
- this.bucket.remove(peerDescriptor.nodeId)
195
+ this.bucket.remove(getRawFromDhtAddress(nodeId))
201
196
  if (gracefulLeave === true) {
202
197
  logger.trace(nodeId + ' ' + 'onTransportDisconnected with gracefulLeave ' + gracefulLeave)
203
- this.removeContact(peerDescriptor)
198
+ this.removeContact(nodeId)
204
199
  } else {
205
200
  logger.trace(nodeId + ' ' + 'onTransportDisconnected with gracefulLeave ' + gracefulLeave)
206
201
  }
207
202
  }
208
203
  }
209
204
 
210
- handlePeerLeaving(peerDescriptor: PeerDescriptor): void {
211
- this.removeContact(peerDescriptor)
205
+ handlePeerLeaving(nodeId: DhtAddress): void {
206
+ this.removeContact(nodeId)
212
207
  }
213
208
 
214
- private removeContact(contact: PeerDescriptor): void {
209
+ private removeContact(nodeId: DhtAddress): void {
215
210
  if (this.stopped) {
216
211
  return
217
212
  }
218
- const nodeId = getNodeIdFromPeerDescriptor(contact)
219
213
  logger.trace(`Removing contact ${nodeId}`)
220
214
  this.bucket.remove(getRawFromDhtAddress(nodeId))
221
215
  this.contacts.removeContact(nodeId)
@@ -258,7 +252,7 @@ export class PeerManager extends EventEmitter<PeerManagerEvents> {
258
252
  return closest.getClosestContacts(limit)
259
253
  }
260
254
 
261
- getNumberOfContacts(excludedNodeIds?: Set<DhtAddress>): number {
255
+ getContactCount(excludedNodeIds?: Set<DhtAddress>): number {
262
256
  return this.contacts.getAllContacts().filter((contact) => {
263
257
  if (!excludedNodeIds) {
264
258
  return true
@@ -268,11 +262,11 @@ export class PeerManager extends EventEmitter<PeerManagerEvents> {
268
262
  }).length
269
263
  }
270
264
 
271
- getNumberOfConnections(): number {
265
+ getConnectionCount(): number {
272
266
  return this.connections.size
273
267
  }
274
268
 
275
- getNumberOfNeighbors(): number {
269
+ getNeighborCount(): number {
276
270
  return this.bucket.count()
277
271
  }
278
272
 
@@ -1,6 +1,5 @@
1
1
  import { PeerDescriptor } from '../../proto/packages/dht/protos/DhtRpc'
2
- import { getNodeIdFromPeerDescriptor } from '../../helpers/peerIdFromPeerDescriptor'
3
- import { DhtAddress } from '../../identifiers'
2
+ import { DhtAddress, getNodeIdFromPeerDescriptor } from '../../identifiers'
4
3
 
5
4
  export class Contact {
6
5
 
@@ -4,6 +4,7 @@ import { ConnectionType } from '../../connection/IConnection'
4
4
  import { expectedConnectionType } from '../../helpers/Connectivity'
5
5
  import { PeerDescriptor } from '../../proto/packages/dht/protos/DhtRpc'
6
6
  import { DhtRpcOptions } from '../../rpc-protocol/DhtRpcOptions'
7
+ import { DhtCallContext } from '../../rpc-protocol/DhtCallContext'
7
8
 
8
9
  // Should connect directly to the server, timeout can be low
9
10
  const WEBSOCKET_CLIENT_TIMEOUT = 5000
@@ -37,7 +38,7 @@ export abstract class RpcRemote<T extends ServiceInfo & ClassType> {
37
38
  constructor(
38
39
  localPeerDescriptor: PeerDescriptor,
39
40
  remotePeerDescriptor: PeerDescriptor,
40
- rpcCommunicator: RpcCommunicator,
41
+ rpcCommunicator: RpcCommunicator<DhtCallContext>,
41
42
  // eslint-disable-next-line @typescript-eslint/prefer-function-type
42
43
  clientClass: { new (clientTransport: ClientTransport): T },
43
44
  timeout?: number
@@ -4,8 +4,7 @@ import { v4 } from 'uuid'
4
4
  import { PeerDescriptor } from '../../proto/packages/dht/protos/DhtRpc'
5
5
  import { PeerManager, getDistance } from '../PeerManager'
6
6
  import { DhtNodeRpcRemote } from '../DhtNodeRpcRemote'
7
- import { getNodeIdFromPeerDescriptor } from '../../helpers/peerIdFromPeerDescriptor'
8
- import { DhtAddress, getRawFromDhtAddress } from '../../identifiers'
7
+ import { DhtAddress, getNodeIdFromPeerDescriptor, getRawFromDhtAddress } from '../../identifiers'
9
8
 
10
9
  const logger = new Logger(module)
11
10
 
@@ -107,7 +106,7 @@ export class DiscoverySession {
107
106
  }
108
107
 
109
108
  public async findClosestNodes(timeout: number): Promise<void> {
110
- if (this.config.peerManager.getNumberOfContacts(this.config.contactedPeers) === 0) {
109
+ if (this.config.peerManager.getContactCount(this.config.contactedPeers) === 0) {
111
110
  return
112
111
  }
113
112
  // TODO add abortController and signal it in stop()
@@ -1,11 +1,10 @@
1
1
  import { DiscoverySession } from './DiscoverySession'
2
2
  import { DhtNodeRpcRemote } from '../DhtNodeRpcRemote'
3
- import { areEqualPeerDescriptors, getNodeIdFromPeerDescriptor } from '../../helpers/peerIdFromPeerDescriptor'
4
3
  import { PeerDescriptor } from '../../proto/packages/dht/protos/DhtRpc'
5
4
  import { Logger, scheduleAtInterval, setAbortableTimeout } from '@streamr/utils'
6
5
  import { ConnectionManager } from '../../connection/ConnectionManager'
7
6
  import { PeerManager } from '../PeerManager'
8
- import { DhtAddress, createRandomDhtAddress } from '../../identifiers'
7
+ import { DhtAddress, areEqualPeerDescriptors, getDhtAddressFromRaw, getNodeIdFromPeerDescriptor, getRawFromDhtAddress } from '../../identifiers'
9
8
  import { ServiceID } from '../../types/ServiceID'
10
9
 
11
10
  interface PeerDiscoveryConfig {
@@ -19,6 +18,12 @@ interface PeerDiscoveryConfig {
19
18
  peerManager: PeerManager
20
19
  }
21
20
 
21
+ export const createDistantDhtAddress = (address: DhtAddress): DhtAddress => {
22
+ const raw = getRawFromDhtAddress(address)
23
+ const flipped = raw.map((val) => ~val)
24
+ return getDhtAddressFromRaw(flipped)
25
+ }
26
+
22
27
  const logger = new Logger(module)
23
28
 
24
29
  export class PeerDiscovery {
@@ -37,14 +42,16 @@ export class PeerDiscovery {
37
42
 
38
43
  async joinDht(
39
44
  entryPoints: PeerDescriptor[],
40
- doAdditionalRandomPeerDiscovery = true,
45
+ doAdditionalDistantPeerDiscovery = true,
41
46
  retry = true
42
47
  ): Promise<void> {
43
48
  const contactedPeers = new Set<DhtAddress>()
49
+ const distantJoinConfig = doAdditionalDistantPeerDiscovery
50
+ ? { enabled: true, contactedPeers: new Set<DhtAddress>() } : { enabled: false } as const
44
51
  await Promise.all(entryPoints.map((entryPoint) => this.joinThroughEntryPoint(
45
52
  entryPoint,
46
53
  contactedPeers,
47
- doAdditionalRandomPeerDiscovery,
54
+ distantJoinConfig,
48
55
  retry
49
56
  )))
50
57
  }
@@ -53,7 +60,7 @@ export class PeerDiscovery {
53
60
  entryPointDescriptor: PeerDescriptor,
54
61
  // Note that this set is mutated by DiscoverySession
55
62
  contactedPeers: Set<DhtAddress>,
56
- doAdditionalRandomPeerDiscovery = true,
63
+ additionalDistantJoin: { enabled: true, contactedPeers: Set<DhtAddress> } | { enabled: false },
57
64
  retry = true
58
65
  ): Promise<void> {
59
66
  if (this.isStopped()) {
@@ -71,8 +78,8 @@ export class PeerDiscovery {
71
78
  this.config.peerManager.handleNewPeers([entryPointDescriptor])
72
79
  const targetId = getNodeIdFromPeerDescriptor(this.config.localPeerDescriptor)
73
80
  const sessions = [this.createSession(targetId, contactedPeers)]
74
- if (doAdditionalRandomPeerDiscovery) {
75
- sessions.push(this.createSession(createRandomDhtAddress(), contactedPeers))
81
+ if (additionalDistantJoin.enabled) {
82
+ sessions.push(this.createSession(createDistantDhtAddress(targetId), additionalDistantJoin.contactedPeers))
76
83
  }
77
84
  await this.runSessions(sessions, entryPointDescriptor, retry)
78
85
  this.config.connectionManager?.unlockConnection(entryPointDescriptor, `${this.config.serviceId}::joinDht`)
@@ -100,7 +107,7 @@ export class PeerDiscovery {
100
107
  logger.debug(`DHT join on ${this.config.serviceId} timed out`)
101
108
  } finally {
102
109
  if (!this.isStopped()) {
103
- if (this.config.peerManager.getNumberOfNeighbors() === 0) {
110
+ if (this.config.peerManager.getNeighborCount() === 0) {
104
111
  if (retry) {
105
112
  // TODO should we catch possible promise rejection?
106
113
  // TODO use config option or named constant?
@@ -121,7 +128,7 @@ export class PeerDiscovery {
121
128
  logger.debug(`Rejoining DHT ${this.config.serviceId}`)
122
129
  this.rejoinOngoing = true
123
130
  try {
124
- await this.joinThroughEntryPoint(entryPoint, new Set())
131
+ await this.joinThroughEntryPoint(entryPoint, new Set(), { enabled: false })
125
132
  logger.debug(`Rejoined DHT successfully ${this.config.serviceId}!`)
126
133
  } catch (err) {
127
134
  logger.warn(`Rejoining DHT ${this.config.serviceId} failed`)
@@ -9,7 +9,6 @@ import {
9
9
  } from '../../proto/packages/dht/protos/DhtRpc'
10
10
  import { Router } from '../routing/Router'
11
11
  import { RoutingMode } from '../routing/RoutingSession'
12
- import { areEqualPeerDescriptors, getNodeIdFromPeerDescriptor } from '../../helpers/peerIdFromPeerDescriptor'
13
12
  import { Logger, areEqualBinaries, runAndWaitForEvents3, wait } from '@streamr/utils'
14
13
  import { RoutingRpcCommunicator } from '../../transport/RoutingRpcCommunicator'
15
14
  import { RecursiveOperationSessionRpcRemote } from './RecursiveOperationSessionRpcRemote'
@@ -24,7 +23,7 @@ import { getPreviousPeer } from '../routing/getPreviousPeer'
24
23
  import { createRouteMessageAck } from '../routing/RouterRpcLocal'
25
24
  import { ServiceID } from '../../types/ServiceID'
26
25
  import { RecursiveOperationRpcLocal } from './RecursiveOperationRpcLocal'
27
- import { DhtAddress, getDhtAddressFromRaw, getRawFromDhtAddress } from '../../identifiers'
26
+ import { DhtAddress, areEqualPeerDescriptors, getDhtAddressFromRaw, getNodeIdFromPeerDescriptor, getRawFromDhtAddress } from '../../identifiers'
28
27
  import { getDistance } from '../PeerManager'
29
28
 
30
29
  interface RecursiveOperationManagerConfig {
@@ -77,7 +76,7 @@ export class RecursiveOperationManager {
77
76
  public async execute(
78
77
  targetId: DhtAddress,
79
78
  operation: RecursiveOperation,
80
- excludedPeer?: PeerDescriptor,
79
+ excludedPeer?: DhtAddress,
81
80
  waitForCompletion = true
82
81
  ): Promise<RecursiveOperationResult> {
83
82
  if (this.stopped) {
@@ -98,6 +97,7 @@ export class RecursiveOperationManager {
98
97
  if (this.config.connections.size === 0) {
99
98
  const dataEntries = Array.from(this.config.localDataStore.values(targetId))
100
99
  session.onResponseReceived(
100
+ getNodeIdFromPeerDescriptor(this.config.localPeerDescriptor),
101
101
  [this.config.localPeerDescriptor],
102
102
  [this.config.localPeerDescriptor],
103
103
  dataEntries,
@@ -126,7 +126,7 @@ export class RecursiveOperationManager {
126
126
  if (operation === RecursiveOperation.FETCH_DATA) {
127
127
  const dataEntries = Array.from(this.config.localDataStore.values(targetId))
128
128
  if (dataEntries.length > 0) {
129
- this.sendResponse([], this.config.localPeerDescriptor, session.getId(), [], dataEntries, true)
129
+ this.sendResponse([this.config.localPeerDescriptor], this.config.localPeerDescriptor, session.getId(), [], dataEntries, true)
130
130
  }
131
131
  } else if (operation === RecursiveOperation.DELETE_DATA) {
132
132
  this.config.localDataStore.markAsDeleted(targetId, getNodeIdFromPeerDescriptor(this.config.localPeerDescriptor))
@@ -147,7 +147,13 @@ export class RecursiveOperationManager {
147
147
  const isOwnNode = areEqualPeerDescriptors(this.config.localPeerDescriptor, targetPeerDescriptor)
148
148
  if (isOwnNode && this.ongoingSessions.has(serviceId)) {
149
149
  this.ongoingSessions.get(serviceId)!
150
- .onResponseReceived(routingPath, closestNodes, dataEntries, noCloserNodesFound)
150
+ .onResponseReceived(
151
+ getNodeIdFromPeerDescriptor(this.config.localPeerDescriptor),
152
+ routingPath,
153
+ closestNodes,
154
+ dataEntries,
155
+ noCloserNodesFound
156
+ )
151
157
  } else {
152
158
  // TODO use config option or named constant?
153
159
  const remoteCommunicator = new ListeningRpcCommunicator(serviceId, this.config.sessionTransport, { rpcRequestTimeout: 15000 })
@@ -164,7 +170,7 @@ export class RecursiveOperationManager {
164
170
  }
165
171
  }
166
172
 
167
- private doRouteRequest(routedMessage: RouteMessageWrapper, excludedPeer?: PeerDescriptor): RouteMessageAck {
173
+ private doRouteRequest(routedMessage: RouteMessageWrapper, excludedPeer?: DhtAddress): RouteMessageAck {
168
174
  if (this.stopped) {
169
175
  return createRouteMessageAck(routedMessage, RouteMessageError.STOPPED)
170
176
  }
@@ -1,9 +1,9 @@
1
1
  import { Logger } from '@streamr/utils'
2
2
  import { PeerDescriptor, RouteMessageAck, RouteMessageError, RouteMessageWrapper } from '../../proto/packages/dht/protos/DhtRpc'
3
3
  import { IRecursiveOperationRpc } from '../../proto/packages/dht/protos/DhtRpc.server'
4
- import { getNodeIdFromPeerDescriptor } from '../../helpers/peerIdFromPeerDescriptor'
5
4
  import { createRouteMessageAck } from '../routing/RouterRpcLocal'
6
5
  import { getPreviousPeer } from '../routing/getPreviousPeer'
6
+ import { getNodeIdFromPeerDescriptor } from '../../identifiers'
7
7
 
8
8
  const logger = new Logger(module)
9
9
 
@@ -1,10 +1,10 @@
1
1
  import { Logger } from '@streamr/utils'
2
2
  import { v4 } from 'uuid'
3
- import { getNodeIdFromPeerDescriptor } from '../../helpers/peerIdFromPeerDescriptor'
4
3
  import { RouteMessageWrapper } from '../../proto/packages/dht/protos/DhtRpc'
5
4
  import { RecursiveOperationRpcClient } from '../../proto/packages/dht/protos/DhtRpc.client'
6
5
  import { RpcRemote } from '../contact/RpcRemote'
7
6
  import { getPreviousPeer } from '../routing/getPreviousPeer'
7
+ import { getNodeIdFromPeerDescriptor } from '../../identifiers'
8
8
 
9
9
  const logger = new Logger(module)
10
10
 
@@ -17,7 +17,8 @@ export class RecursiveOperationRpcRemote extends RpcRemote<RecursiveOperationRpc
17
17
  message: params.message,
18
18
  requestId: params.requestId ?? v4(),
19
19
  reachableThrough: params.reachableThrough ?? [],
20
- routingPath: params.routingPath
20
+ routingPath: params.routingPath,
21
+ parallelRootNodeIds: params.parallelRootNodeIds
21
22
  }
22
23
  const options = this.formDhtRpcOptions({
23
24
  connect: false
@@ -16,10 +16,10 @@ import { ListeningRpcCommunicator } from '../../transport/ListeningRpcCommunicat
16
16
  import { Contact } from '../contact/Contact'
17
17
  import { SortedContactList } from '../contact/SortedContactList'
18
18
  import { RecursiveOperationResult } from './RecursiveOperationManager'
19
- import { getNodeIdFromPeerDescriptor } from '../../helpers/peerIdFromPeerDescriptor'
20
19
  import { ServiceID } from '../../types/ServiceID'
21
20
  import { RecursiveOperationSessionRpcLocal } from './RecursiveOperationSessionRpcLocal'
22
- import { DhtAddress, getDhtAddressFromRaw, getRawFromDhtAddress } from '../../identifiers'
21
+ import { DhtAddress, getDhtAddressFromRaw, getNodeIdFromPeerDescriptor, getRawFromDhtAddress } from '../../identifiers'
22
+ import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
23
23
 
24
24
  export interface RecursiveOperationSessionEvents {
25
25
  completed: () => void
@@ -45,6 +45,7 @@ export class RecursiveOperationSession extends EventEmitter<RecursiveOperationSe
45
45
  private timeoutTask?: NodeJS.Timeout
46
46
  private completionEventEmitted = false
47
47
  private noCloserNodesReceivedCounter = 0
48
+ private readonly noCloserNodesReceivedFrom: Set<DhtAddress> = new Set()
48
49
  private readonly config: RecursiveOperationSessionConfig
49
50
 
50
51
  constructor(config: RecursiveOperationSessionConfig) {
@@ -64,12 +65,18 @@ export class RecursiveOperationSession extends EventEmitter<RecursiveOperationSe
64
65
 
65
66
  private registerLocalRpcMethods() {
66
67
  const rpcLocal = new RecursiveOperationSessionRpcLocal({
67
- onResponseReceived: (routingPath: PeerDescriptor[], nodes: PeerDescriptor[], dataEntries: DataEntry[], noCloserNodesFound: boolean) => {
68
- this.onResponseReceived(routingPath, nodes, dataEntries, noCloserNodesFound)
68
+ onResponseReceived: (
69
+ sourceId: DhtAddress,
70
+ routingPath: PeerDescriptor[],
71
+ nodes: PeerDescriptor[],
72
+ dataEntries: DataEntry[],
73
+ noCloserNodesFound: boolean
74
+ ) => {
75
+ this.onResponseReceived(sourceId, routingPath, nodes, dataEntries, noCloserNodesFound)
69
76
  }
70
77
  })
71
78
  this.rpcCommunicator.registerRpcNotification(RecursiveOperationResponse, 'sendResponse',
72
- (req: RecursiveOperationResponse) => rpcLocal.sendResponse(req))
79
+ (req: RecursiveOperationResponse, context: ServerCallContext) => rpcLocal.sendResponse(req, context))
73
80
  }
74
81
 
75
82
  public start(serviceId: ServiceID): void {
@@ -97,7 +104,8 @@ export class RecursiveOperationSession extends EventEmitter<RecursiveOperationSe
97
104
  target: getRawFromDhtAddress(this.config.targetId),
98
105
  sourcePeer: this.config.localPeerDescriptor,
99
106
  reachableThrough: [],
100
- routingPath: []
107
+ routingPath: [],
108
+ parallelRootNodeIds: []
101
109
  }
102
110
  return routeMessage
103
111
  }
@@ -124,6 +132,7 @@ export class RecursiveOperationSession extends EventEmitter<RecursiveOperationSe
124
132
  }
125
133
 
126
134
  public onResponseReceived(
135
+ sourceId: DhtAddress,
127
136
  routingPath: PeerDescriptor[],
128
137
  nodes: PeerDescriptor[],
129
138
  dataEntries: DataEntry[],
@@ -137,8 +146,8 @@ export class RecursiveOperationSession extends EventEmitter<RecursiveOperationSe
137
146
  this.results.addContact(new Contact(descriptor))
138
147
  })
139
148
  this.processFoundData(dataEntries)
140
- if (noCloserNodesFound) {
141
- this.onNoCloserPeersFound()
149
+ if (noCloserNodesFound || this.noCloserNodesReceivedFrom.has(sourceId)) {
150
+ this.onNoCloserPeersFound(sourceId)
142
151
  }
143
152
  }
144
153
 
@@ -181,8 +190,9 @@ export class RecursiveOperationSession extends EventEmitter<RecursiveOperationSe
181
190
  })
182
191
  }
183
192
 
184
- private onNoCloserPeersFound(): void {
193
+ private onNoCloserPeersFound(sourceId: DhtAddress): void {
185
194
  this.noCloserNodesReceivedCounter += 1
195
+ this.noCloserNodesReceivedFrom.add(sourceId)
186
196
  if (this.isCompleted()) {
187
197
  this.emit('completed')
188
198
  this.completionEventEmitted = true
@@ -2,11 +2,20 @@ import { IRecursiveOperationSessionRpc } from '../../proto/packages/dht/protos/D
2
2
  import { Empty } from '../../proto/google/protobuf/empty'
3
3
  import { DataEntry, RecursiveOperationResponse, PeerDescriptor } from '../../proto/packages/dht/protos/DhtRpc'
4
4
  import { Logger } from '@streamr/utils'
5
+ import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
6
+ import { DhtCallContext } from '../../rpc-protocol/DhtCallContext'
7
+ import { DhtAddress, getNodeIdFromPeerDescriptor } from '../../identifiers'
5
8
 
6
9
  const logger = new Logger(module)
7
10
 
8
11
  interface RecursiveOperationSessionRpcLocalConfig {
9
- onResponseReceived: (routingPath: PeerDescriptor[], nodes: PeerDescriptor[], dataEntries: DataEntry[], noCloserNodesFound: boolean) => void
12
+ onResponseReceived: (
13
+ sourceId: DhtAddress,
14
+ routingPath: PeerDescriptor[],
15
+ nodes: PeerDescriptor[],
16
+ dataEntries: DataEntry[],
17
+ noCloserNodesFound: boolean
18
+ ) => void
10
19
  }
11
20
 
12
21
  export class RecursiveOperationSessionRpcLocal implements IRecursiveOperationSessionRpc {
@@ -17,9 +26,10 @@ export class RecursiveOperationSessionRpcLocal implements IRecursiveOperationSes
17
26
  this.config = config
18
27
  }
19
28
 
20
- async sendResponse(report: RecursiveOperationResponse): Promise<Empty> {
29
+ async sendResponse(report: RecursiveOperationResponse, context: ServerCallContext): Promise<Empty> {
30
+ const sourceId = getNodeIdFromPeerDescriptor((context as DhtCallContext).incomingSourceDescriptor!)
21
31
  logger.trace('RecursiveOperationResponse arrived: ' + JSON.stringify(report))
22
- this.config.onResponseReceived(report.routingPath, report.closestConnectedPeers, report.dataEntries, report.noCloserNodesFound)
32
+ this.config.onResponseReceived(sourceId, report.routingPath, report.closestConnectedPeers, report.dataEntries, report.noCloserNodesFound)
23
33
  return {}
24
34
  }
25
35
  }
@@ -1,40 +1,28 @@
1
- type QueueEntry = [timestamp: number, value: string]
2
-
3
1
  export class DuplicateDetector {
4
2
 
5
3
  private values: Set<string> = new Set()
6
- private queue: Array<QueueEntry> = []
7
- private maxAge: number
8
- private maxNumberOfValues: number
4
+ private queue: Array<string> = []
5
+ private maxItemCount: number
9
6
 
10
7
  constructor(
11
- maxNumberOfValues: number,
12
- maxAgeInSeconds: number
8
+ maxItemCount: number,
13
9
  ) {
14
- this.maxNumberOfValues = maxNumberOfValues
15
- this.maxAge = maxAgeInSeconds * 1000
10
+ this.maxItemCount = maxItemCount
16
11
  }
17
12
 
18
13
  public add(value: string): void {
19
14
  this.values.add(value)
20
- this.queue.push([Date.now(), value])
21
- this.cleanUp()
15
+ this.queue.push(value)
16
+ if (this.queue.length > this.maxItemCount) {
17
+ const removed = this.queue.shift()!
18
+ this.values.delete(removed)
19
+ }
22
20
  }
23
21
 
24
22
  public isMostLikelyDuplicate(value: string): boolean {
25
23
  return this.values.has(value)
26
24
  }
27
25
 
28
- private cleanUp(): void {
29
- const currentTime = Date.now()
30
-
31
- while (this.queue.length > 0 && (this.queue.length > this.maxNumberOfValues ||
32
- (currentTime - this.queue[0][0]) > this.maxAge)) {
33
- const oldestEntry = this.queue.shift()
34
- this.values.delete(oldestEntry![1])
35
- }
36
- }
37
-
38
26
  public size(): number {
39
27
  return this.values.size
40
28
  }
@@ -1,8 +1,4 @@
1
1
  import { Message, PeerDescriptor, RouteMessageAck, RouteMessageError, RouteMessageWrapper } from '../../proto/packages/dht/protos/DhtRpc'
2
- import {
3
- areEqualPeerDescriptors,
4
- getNodeIdFromPeerDescriptor
5
- } from '../../helpers/peerIdFromPeerDescriptor'
6
2
  import { RoutingMode, RoutingSession, RoutingSessionEvents } from './RoutingSession'
7
3
  import { Logger, executeSafePromise, raceEvents3, withTimeout } from '@streamr/utils'
8
4
  import { RoutingRpcCommunicator } from '../../transport/RoutingRpcCommunicator'
@@ -11,7 +7,7 @@ import { ConnectionManager } from '../../connection/ConnectionManager'
11
7
  import { DhtNodeRpcRemote } from '../DhtNodeRpcRemote'
12
8
  import { v4 } from 'uuid'
13
9
  import { RouterRpcLocal, createRouteMessageAck } from './RouterRpcLocal'
14
- import { DhtAddress, getDhtAddressFromRaw } from '../../identifiers'
10
+ import { DhtAddress, areEqualPeerDescriptors, getDhtAddressFromRaw, getNodeIdFromPeerDescriptor } from '../../identifiers'
15
11
 
16
12
  export interface RouterConfig {
17
13
  rpcCommunicator: RoutingRpcCommunicator
@@ -33,7 +29,7 @@ export class Router {
33
29
  private readonly forwardingTable: Map<DhtAddress, ForwardingTableEntry> = new Map()
34
30
  private ongoingRoutingSessions: Map<string, RoutingSession> = new Map()
35
31
  // TODO use config option or named constant?
36
- private readonly duplicateRequestDetector: DuplicateDetector = new DuplicateDetector(100000, 100)
32
+ private readonly duplicateRequestDetector: DuplicateDetector = new DuplicateDetector(100000)
37
33
  private stopped = false
38
34
  private readonly config: RouterConfig
39
35
 
@@ -87,7 +83,8 @@ export class Router {
87
83
  target: forwardingEntry.peerDescriptors[0].nodeId,
88
84
  sourcePeer: this.config.localPeerDescriptor,
89
85
  reachableThrough,
90
- routingPath: []
86
+ routingPath: [],
87
+ parallelRootNodeIds: []
91
88
  }
92
89
  const ack = this.doRouteMessage(forwardedMessage, RoutingMode.FORWARD)
93
90
  if (ack.error !== undefined) {
@@ -102,7 +99,8 @@ export class Router {
102
99
  target: targetPeerDescriptor.nodeId,
103
100
  sourcePeer: this.config.localPeerDescriptor,
104
101
  reachableThrough,
105
- routingPath: []
102
+ routingPath: [],
103
+ parallelRootNodeIds: []
106
104
  }
107
105
  const ack = this.doRouteMessage(routedMessage, RoutingMode.ROUTE)
108
106
  if (ack.error !== undefined) {
@@ -113,7 +111,7 @@ export class Router {
113
111
  }
114
112
  }
115
113
 
116
- public doRouteMessage(routedMessage: RouteMessageWrapper, mode = RoutingMode.ROUTE, excludedPeer?: PeerDescriptor): RouteMessageAck {
114
+ public doRouteMessage(routedMessage: RouteMessageWrapper, mode = RoutingMode.ROUTE, excludedPeer?: DhtAddress): RouteMessageAck {
117
115
  if (this.stopped) {
118
116
  return createRouteMessageAck(routedMessage, RouteMessageError.STOPPED)
119
117
  }
@@ -153,11 +151,14 @@ export class Router {
153
151
  }
154
152
  }
155
153
 
156
- private createRoutingSession(routedMessage: RouteMessageWrapper, mode: RoutingMode, excludedNode?: PeerDescriptor): RoutingSession {
154
+ private createRoutingSession(routedMessage: RouteMessageWrapper, mode: RoutingMode, excludedNode?: DhtAddress): RoutingSession {
157
155
  const excludedNodeIds = new Set<DhtAddress>(routedMessage.routingPath.map((descriptor) => getNodeIdFromPeerDescriptor(descriptor)))
158
156
  if (excludedNode) {
159
- excludedNodeIds.add(getNodeIdFromPeerDescriptor(excludedNode))
157
+ excludedNodeIds.add(excludedNode)
160
158
  }
159
+ routedMessage.parallelRootNodeIds.forEach((nodeId) => {
160
+ excludedNodeIds.add(nodeId as DhtAddress)
161
+ })
161
162
  logger.trace('routing session created with connections: ' + this.config.connections.size)
162
163
  return new RoutingSession({
163
164
  rpcCommunicator: this.config.rpcCommunicator,
@@ -1,11 +1,10 @@
1
1
  import { Logger, areEqualBinaries } from '@streamr/utils'
2
2
  import { ConnectionManager } from '../../connection/ConnectionManager'
3
- import { areEqualPeerDescriptors, getNodeIdFromPeerDescriptor } from '../../helpers/peerIdFromPeerDescriptor'
4
3
  import { PeerDescriptor, RouteMessageAck, RouteMessageError, RouteMessageWrapper } from '../../proto/packages/dht/protos/DhtRpc'
5
4
  import { IRouterRpc } from '../../proto/packages/dht/protos/DhtRpc.server'
6
5
  import { DuplicateDetector } from './DuplicateDetector'
7
6
  import { RoutingMode } from './RoutingSession'
8
- import { getDhtAddressFromRaw } from '../../identifiers'
7
+ import { areEqualPeerDescriptors, getDhtAddressFromRaw, getNodeIdFromPeerDescriptor } from '../../identifiers'
9
8
 
10
9
  interface RouterRpcLocalConfig {
11
10
  doRouteMessage: (routedMessage: RouteMessageWrapper, mode?: RoutingMode) => RouteMessageAck
@@ -1,12 +1,10 @@
1
1
  import { Logger, areEqualBinaries } from '@streamr/utils'
2
2
  import { v4 } from 'uuid'
3
- import {
4
- getNodeIdFromPeerDescriptor
5
- } from '../../helpers/peerIdFromPeerDescriptor'
6
3
  import { RouteMessageError, RouteMessageWrapper } from '../../proto/packages/dht/protos/DhtRpc'
7
4
  import { RouterRpcClient } from '../../proto/packages/dht/protos/DhtRpc.client'
8
5
  import { RpcRemote } from '../contact/RpcRemote'
9
6
  import { getPreviousPeer } from './getPreviousPeer'
7
+ import { getNodeIdFromPeerDescriptor } from '../../identifiers'
10
8
 
11
9
  const logger = new Logger(module)
12
10
 
@@ -19,7 +17,8 @@ export class RouterRpcRemote extends RpcRemote<RouterRpcClient> {
19
17
  message: params.message,
20
18
  requestId: params.requestId ?? v4(),
21
19
  reachableThrough: params.reachableThrough ?? [],
22
- routingPath: params.routingPath
20
+ routingPath: params.routingPath,
21
+ parallelRootNodeIds: params.parallelRootNodeIds
23
22
  }
24
23
  const options = this.formDhtRpcOptions({
25
24
  connect: false
@@ -53,7 +52,8 @@ export class RouterRpcRemote extends RpcRemote<RouterRpcClient> {
53
52
  message: params.message,
54
53
  requestId: params.requestId ?? v4(),
55
54
  reachableThrough: params.reachableThrough ?? [],
56
- routingPath: params.routingPath
55
+ routingPath: params.routingPath,
56
+ parallelRootNodeIds: params.parallelRootNodeIds
57
57
  }
58
58
  const options = this.formDhtRpcOptions({
59
59
  connect: false