@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
@@ -1,6 +1,5 @@
1
1
  import { DhtNodeRpcRemote } from '../DhtNodeRpcRemote'
2
2
  import { SortedContactList } from '../contact/SortedContactList'
3
- import { getNodeIdFromPeerDescriptor } from '../../helpers/peerIdFromPeerDescriptor'
4
3
  import { Logger } from '@streamr/utils'
5
4
  import EventEmitter from 'eventemitter3'
6
5
  import { v4 } from 'uuid'
@@ -12,7 +11,8 @@ import { Contact } from '../contact/Contact'
12
11
  import { RecursiveOperationRpcRemote } from '../recursive-operation/RecursiveOperationRpcRemote'
13
12
  import { EXISTING_CONNECTION_TIMEOUT } from '../contact/RpcRemote'
14
13
  import { getPreviousPeer } from './getPreviousPeer'
15
- import { DhtAddress, getDhtAddressFromRaw } from '../../identifiers'
14
+ import { DhtAddress, areEqualPeerDescriptors, getDhtAddressFromRaw, getNodeIdFromPeerDescriptor } from '../../identifiers'
15
+ import { pull } from 'lodash'
16
16
 
17
17
  const logger = new Logger(module)
18
18
 
@@ -106,6 +106,7 @@ export class RoutingSession extends EventEmitter<RoutingSessionEvents> {
106
106
  if (this.ongoingRequests.has(nodeId)) {
107
107
  this.ongoingRequests.delete(nodeId)
108
108
  }
109
+ this.deleteParallelRootIfSource(nodeId)
109
110
  const contacts = this.updateAndGetRoutablePeers()
110
111
  if (contacts.length === 0 && this.ongoingRequests.size === 0) {
111
112
  logger.trace('routing failed, emitting routingFailed sessionId: ' + this.sessionId)
@@ -194,6 +195,7 @@ export class RoutingSession extends EventEmitter<RoutingSessionEvents> {
194
195
  logger.trace(`Sending routeMessage request to contact: ${getNodeIdFromPeerDescriptor(nextPeer!.getPeerDescriptor())} (sessionId=${this.sessionId})`)
195
196
  this.contactList.setContacted(nextPeer!.getNodeId())
196
197
  this.ongoingRequests.add(nextPeer!.getNodeId())
198
+ this.addParallelRootIfSource(nextPeer!.getNodeId())
197
199
  setImmediate(async () => {
198
200
  try {
199
201
  const succeeded = await this.sendRouteMessageRequest(nextPeer!)
@@ -211,6 +213,24 @@ export class RoutingSession extends EventEmitter<RoutingSessionEvents> {
211
213
  }
212
214
  }
213
215
 
216
+ private addParallelRootIfSource(nodeId: DhtAddress) {
217
+ if (
218
+ this.config.mode === RoutingMode.RECURSIVE
219
+ && areEqualPeerDescriptors(this.config.localPeerDescriptor, this.config.routedMessage.sourcePeer!)
220
+ ) {
221
+ this.config.routedMessage.parallelRootNodeIds.push(nodeId)
222
+ }
223
+ }
224
+
225
+ private deleteParallelRootIfSource(nodeId: DhtAddress) {
226
+ if (
227
+ this.config.mode === RoutingMode.RECURSIVE
228
+ && areEqualPeerDescriptors(this.config.localPeerDescriptor, this.config.routedMessage.sourcePeer!)
229
+ ) {
230
+ pull(this.config.routedMessage.parallelRootNodeIds, nodeId)
231
+ }
232
+ }
233
+
214
234
  public stop(): void {
215
235
  this.stopped = true
216
236
  this.contactList.stop()
@@ -6,7 +6,6 @@ import { Any } from '../../proto/google/protobuf/any'
6
6
  import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
7
7
  import { RoutingRpcCommunicator } from '../../transport/RoutingRpcCommunicator'
8
8
  import { RecursiveOperationManager } from '../recursive-operation/RecursiveOperationManager'
9
- import { areEqualPeerDescriptors, getNodeIdFromPeerDescriptor } from '../../helpers/peerIdFromPeerDescriptor'
10
9
  import { Logger, executeSafePromise } from '@streamr/utils'
11
10
  import { LocalDataStore } from './LocalDataStore'
12
11
  import { StoreRpcRemote } from './StoreRpcRemote'
@@ -15,7 +14,7 @@ import { SortedContactList } from '../contact/SortedContactList'
15
14
  import { Contact } from '../contact/Contact'
16
15
  import { ServiceID } from '../../types/ServiceID'
17
16
  import { findIndex } from 'lodash'
18
- import { DhtAddress, getDhtAddressFromRaw, getRawFromDhtAddress } from '../../identifiers'
17
+ import { DhtAddress, areEqualPeerDescriptors, getDhtAddressFromRaw, getNodeIdFromPeerDescriptor, getRawFromDhtAddress } from '../../identifiers'
19
18
  import { StoreRpcLocal } from './StoreRpcLocal'
20
19
  import { getDistance } from '../PeerManager'
21
20
 
@@ -1,4 +1,4 @@
1
- import { getNodeIdFromPeerDescriptor } from '../../helpers/peerIdFromPeerDescriptor'
1
+ import { getNodeIdFromPeerDescriptor } from '../../identifiers'
2
2
  import {
3
3
  ReplicateDataRequest,
4
4
  StoreDataRequest
package/src/exports.ts CHANGED
@@ -11,13 +11,18 @@ export { LockID } from './connection/ConnectionLockHandler'
11
11
  export { DefaultConnectorFacade } from './connection/ConnectorFacade'
12
12
  export { DhtRpcOptions } from './rpc-protocol/DhtRpcOptions'
13
13
  export { RpcRemote, EXISTING_CONNECTION_TIMEOUT } from './dht/contact/RpcRemote'
14
- export { areEqualPeerDescriptors } from './helpers/peerIdFromPeerDescriptor'
15
14
  export { IceServer } from './connection/webrtc/WebrtcConnector'
16
15
  export { DhtCallContext } from './rpc-protocol/DhtCallContext'
17
16
  export { ClientWebsocket } from './connection/websocket/ClientWebsocket'
18
17
  export { ManagedConnection } from './connection/ManagedConnection'
19
18
  export { ConnectionType } from './connection/IConnection'
20
- export { PeerID } from './helpers/PeerID'
21
19
  export { ServiceID } from './types/ServiceID'
22
- export { DhtAddress, DhtAddressRaw, getDhtAddressFromRaw, getRawFromDhtAddress } from './identifiers'
23
- export { getNodeIdFromPeerDescriptor } from './helpers/peerIdFromPeerDescriptor'
20
+ export {
21
+ DhtAddress,
22
+ DhtAddressRaw,
23
+ getDhtAddressFromRaw,
24
+ getRawFromDhtAddress,
25
+ createRandomDhtAddress,
26
+ areEqualPeerDescriptors,
27
+ getNodeIdFromPeerDescriptor
28
+ } from './identifiers'
@@ -0,0 +1,56 @@
1
+ import {
2
+ createSignature,
3
+ hash
4
+ } from '@streamr/utils'
5
+ import crypto from 'crypto'
6
+ import { isBrowserEnvironment } from '../helpers/browser/isBrowserEnvironment'
7
+ import { createPeerDescriptorSignaturePayload } from '../helpers/createPeerDescriptorSignaturePayload'
8
+ import { DhtAddress, DhtAddressRaw, getRawFromDhtAddress } from '../identifiers'
9
+ import {
10
+ ConnectivityResponse,
11
+ NodeType,
12
+ PeerDescriptor
13
+ } from '../proto/packages/dht/protos/DhtRpc'
14
+
15
+ const calculateNodeIdRaw = (ipAddress: number, privateKey: Uint8Array): DhtAddressRaw => {
16
+ // nodeId is calculated as
17
+ // concatenate(
18
+ // get104leastSignificatBits(hash(ipAddress)),
19
+ // get56leastSignificatBits(sign(ipAddress))
20
+ // )
21
+ const ipAsBuffer = Buffer.alloc(4)
22
+ ipAsBuffer.writeUInt32BE(ipAddress)
23
+ const ipHash = hash(ipAsBuffer)
24
+ const signature = createSignature(ipAsBuffer, privateKey)
25
+ const nodeIdRaw = Buffer.concat([
26
+ ipHash.subarray(ipHash.length - 13, ipHash.length),
27
+ signature.subarray(signature.length - 7, signature.length)
28
+ ])
29
+ return nodeIdRaw
30
+ }
31
+
32
+ export const createPeerDescriptor = (connectivityResponse: ConnectivityResponse, nodeId?: DhtAddress): PeerDescriptor => {
33
+ const privateKey = crypto.randomBytes(32)
34
+ const publicKey = crypto.randomBytes(20) // TODO calculate publicKey from privateKey
35
+ let nodeIdRaw: DhtAddressRaw
36
+ if (nodeId !== undefined) {
37
+ nodeIdRaw = getRawFromDhtAddress(nodeId)
38
+ } else {
39
+ nodeIdRaw = calculateNodeIdRaw(connectivityResponse.ipAddress, privateKey)
40
+ }
41
+ const ret: PeerDescriptor = {
42
+ nodeId: nodeIdRaw,
43
+ type: isBrowserEnvironment() ? NodeType.BROWSER : NodeType.NODEJS,
44
+ ipAddress: connectivityResponse.ipAddress,
45
+ publicKey
46
+ }
47
+ if (connectivityResponse.websocket) {
48
+ ret.websocket = {
49
+ host: connectivityResponse.websocket.host,
50
+ port: connectivityResponse.websocket.port,
51
+ tls: connectivityResponse.websocket.tls
52
+ }
53
+ }
54
+ ret.signature = createSignature(createPeerDescriptorSignaturePayload(ret), privateKey)
55
+ return ret
56
+ }
@@ -0,0 +1,28 @@
1
+ import { ConnectivityMethod, PeerDescriptor } from '../proto/packages/dht/protos/DhtRpc'
2
+
3
+ function convertUnsignedIntegerToBuffer(number: number): Buffer {
4
+ const buffer = Buffer.alloc(4)
5
+ buffer.writeUInt32BE(number)
6
+ return buffer
7
+ }
8
+
9
+ export const createPeerDescriptorSignaturePayload = (peerDescriptor: PeerDescriptor): Uint8Array => {
10
+ const separator = Buffer.from(',')
11
+ const buffers = [
12
+ peerDescriptor.type !== undefined ? convertUnsignedIntegerToBuffer(peerDescriptor.type) : new Uint8Array(0),
13
+ separator,
14
+ peerDescriptor.udp !== undefined ? ConnectivityMethod.toBinary(peerDescriptor.udp) : new Uint8Array(0),
15
+ separator,
16
+ peerDescriptor.tcp !== undefined ? ConnectivityMethod.toBinary(peerDescriptor.tcp) : new Uint8Array(0),
17
+ separator,
18
+ peerDescriptor.websocket !== undefined ? ConnectivityMethod.toBinary(peerDescriptor.websocket) : new Uint8Array(0),
19
+ separator,
20
+ peerDescriptor.region !== undefined ? convertUnsignedIntegerToBuffer(peerDescriptor.region) : new Uint8Array(0),
21
+ separator,
22
+ peerDescriptor.ipAddress !== undefined ? convertUnsignedIntegerToBuffer(peerDescriptor.ipAddress) : new Uint8Array(0),
23
+ separator,
24
+ peerDescriptor.publicKey !== undefined ? Buffer.from(peerDescriptor.publicKey) : new Uint8Array(0)
25
+ ]
26
+ return Buffer.concat(buffers)
27
+ }
28
+
@@ -0,0 +1,15 @@
1
+ import crypto from 'crypto'
2
+ import { DhtAddress } from '../identifiers'
3
+
4
+ type Offerer = 'local' | 'remote'
5
+
6
+ export const getOfferer = (localNodeId: DhtAddress, remoteNodeId: DhtAddress): Offerer => {
7
+ return getOfferingHash(localNodeId + ',' + remoteNodeId) < getOfferingHash(remoteNodeId + ',' + localNodeId)
8
+ ? 'local'
9
+ : 'remote'
10
+ }
11
+
12
+ const getOfferingHash = (idPair: string): number => {
13
+ const buffer = crypto.createHash('md5').update(idPair).digest()
14
+ return buffer.readInt32LE(0)
15
+ }
@@ -1,5 +1,6 @@
1
- import { BrandedString, binaryToHex, hexToBinary } from '@streamr/utils'
1
+ import { BrandedString, areEqualBinaries, binaryToHex, hexToBinary } from '@streamr/utils'
2
2
  import crypto from 'crypto'
3
+ import { PeerDescriptor } from './proto/packages/dht/protos/DhtRpc'
3
4
 
4
5
  // https://www.scs.stanford.edu/~dm/home/papers/kpos.pdf
5
6
  const KADEMLIA_ID_LENGTH_IN_BYTES = 20
@@ -15,6 +16,14 @@ export const getRawFromDhtAddress = (address: DhtAddress): DhtAddressRaw => {
15
16
  return hexToBinary(address) as unknown as DhtAddressRaw
16
17
  }
17
18
 
19
+ export const getNodeIdFromPeerDescriptor = (peerDescriptor: PeerDescriptor): DhtAddress => {
20
+ return getDhtAddressFromRaw(peerDescriptor.nodeId)
21
+ }
22
+
23
+ export const areEqualPeerDescriptors = (peerDescriptor1: PeerDescriptor, peerDescriptor2: PeerDescriptor): boolean => {
24
+ return areEqualBinaries(peerDescriptor1.nodeId, peerDescriptor2.nodeId)
25
+ }
26
+
18
27
  export const createRandomDhtAddress = (): DhtAddress => {
19
28
  return getDhtAddressFromRaw(crypto.randomBytes(KADEMLIA_ID_LENGTH_IN_BYTES))
20
29
  }
@@ -1,4 +1,4 @@
1
- // @generated by protobuf-ts 2.9.1 with parameter server_generic,generate_dependencies,long_type_number
1
+ // @generated by protobuf-ts 2.9.3 with parameter server_generic,generate_dependencies,long_type_number
2
2
  // @generated from protobuf file "google/protobuf/any.proto" (package "google.protobuf", syntax proto3)
3
3
  // tslint:disable
4
4
  //
@@ -39,7 +39,6 @@ import type { IBinaryReader } from "@protobuf-ts/runtime";
39
39
  import { UnknownFieldHandler } from "@protobuf-ts/runtime";
40
40
  import type { PartialMessage } from "@protobuf-ts/runtime";
41
41
  import { reflectionMergePartial } from "@protobuf-ts/runtime";
42
- import { MESSAGE_TYPE } from "@protobuf-ts/runtime";
43
42
  import { isJsonObject } from "@protobuf-ts/runtime";
44
43
  import { typeofJsonValue } from "@protobuf-ts/runtime";
45
44
  import type { JsonValue } from "@protobuf-ts/runtime";
@@ -272,8 +271,9 @@ class Any$Type extends MessageType<Any> {
272
271
  return name;
273
272
  }
274
273
  create(value?: PartialMessage<Any>): Any {
275
- const message = { typeUrl: "", value: new Uint8Array(0) };
276
- globalThis.Object.defineProperty(message, MESSAGE_TYPE, { enumerable: false, value: this });
274
+ const message = globalThis.Object.create((this.messagePrototype!));
275
+ message.typeUrl = "";
276
+ message.value = new Uint8Array(0);
277
277
  if (value !== undefined)
278
278
  reflectionMergePartial<Any>(this, message, value);
279
279
  return message;
@@ -1,4 +1,4 @@
1
- // @generated by protobuf-ts 2.9.1 with parameter server_generic,generate_dependencies,long_type_number
1
+ // @generated by protobuf-ts 2.9.3 with parameter server_generic,generate_dependencies,long_type_number
2
2
  // @generated from protobuf file "google/protobuf/empty.proto" (package "google.protobuf", syntax proto3)
3
3
  // tslint:disable
4
4
  //
@@ -39,7 +39,6 @@ import type { BinaryReadOptions } from "@protobuf-ts/runtime";
39
39
  import type { IBinaryReader } from "@protobuf-ts/runtime";
40
40
  import type { PartialMessage } from "@protobuf-ts/runtime";
41
41
  import { reflectionMergePartial } from "@protobuf-ts/runtime";
42
- import { MESSAGE_TYPE } from "@protobuf-ts/runtime";
43
42
  import { MessageType } from "@protobuf-ts/runtime";
44
43
  /**
45
44
  * A generic empty message that you can re-use to avoid defining duplicated
@@ -62,8 +61,7 @@ class Empty$Type extends MessageType<Empty> {
62
61
  super("google.protobuf.Empty", []);
63
62
  }
64
63
  create(value?: PartialMessage<Empty>): Empty {
65
- const message = {};
66
- globalThis.Object.defineProperty(message, MESSAGE_TYPE, { enumerable: false, value: this });
64
+ const message = globalThis.Object.create((this.messagePrototype!));
67
65
  if (value !== undefined)
68
66
  reflectionMergePartial<Empty>(this, message, value);
69
67
  return message;
@@ -1,4 +1,4 @@
1
- // @generated by protobuf-ts 2.9.1 with parameter server_generic,generate_dependencies,long_type_number
1
+ // @generated by protobuf-ts 2.9.3 with parameter server_generic,generate_dependencies,long_type_number
2
2
  // @generated from protobuf file "google/protobuf/timestamp.proto" (package "google.protobuf", syntax proto3)
3
3
  // tslint:disable
4
4
  //
@@ -40,7 +40,6 @@ import type { IBinaryReader } from "@protobuf-ts/runtime";
40
40
  import { UnknownFieldHandler } from "@protobuf-ts/runtime";
41
41
  import type { PartialMessage } from "@protobuf-ts/runtime";
42
42
  import { reflectionMergePartial } from "@protobuf-ts/runtime";
43
- import { MESSAGE_TYPE } from "@protobuf-ts/runtime";
44
43
  import { typeofJsonValue } from "@protobuf-ts/runtime";
45
44
  import type { JsonValue } from "@protobuf-ts/runtime";
46
45
  import type { JsonReadOptions } from "@protobuf-ts/runtime";
@@ -234,8 +233,9 @@ class Timestamp$Type extends MessageType<Timestamp> {
234
233
  return target;
235
234
  }
236
235
  create(value?: PartialMessage<Timestamp>): Timestamp {
237
- const message = { seconds: 0, nanos: 0 };
238
- globalThis.Object.defineProperty(message, MESSAGE_TYPE, { enumerable: false, value: this });
236
+ const message = globalThis.Object.create((this.messagePrototype!));
237
+ message.seconds = 0;
238
+ message.nanos = 0;
239
239
  if (value !== undefined)
240
240
  reflectionMergePartial<Timestamp>(this, message, value);
241
241
  return message;
@@ -1,4 +1,4 @@
1
- // @generated by protobuf-ts 2.9.1 with parameter server_generic,generate_dependencies,long_type_number
1
+ // @generated by protobuf-ts 2.9.3 with parameter server_generic,generate_dependencies,long_type_number
2
2
  // @generated from protobuf file "packages/dht/protos/DhtRpc.proto" (package "dht", syntax proto3)
3
3
  // tslint:disable
4
4
  import { ExternalApiRpc } from "./DhtRpc";
@@ -7,7 +7,6 @@ import type { ExternalStoreDataRequest } from "./DhtRpc";
7
7
  import type { ExternalFindDataResponse } from "./DhtRpc";
8
8
  import type { ExternalFindDataRequest } from "./DhtRpc";
9
9
  import { ConnectionLockRpc } from "./DhtRpc";
10
- import type { DisconnectNoticeResponse } from "./DhtRpc";
11
10
  import type { DisconnectNotice } from "./DhtRpc";
12
11
  import type { UnlockRequest } from "./DhtRpc";
13
12
  import type { LockResponse } from "./DhtRpc";
@@ -313,9 +312,9 @@ export interface IConnectionLockRpcClient {
313
312
  */
314
313
  unlockRequest(input: UnlockRequest, options?: RpcOptions): UnaryCall<UnlockRequest, Empty>;
315
314
  /**
316
- * @generated from protobuf rpc: gracefulDisconnect(dht.DisconnectNotice) returns (dht.DisconnectNoticeResponse);
315
+ * @generated from protobuf rpc: gracefulDisconnect(dht.DisconnectNotice) returns (google.protobuf.Empty);
317
316
  */
318
- gracefulDisconnect(input: DisconnectNotice, options?: RpcOptions): UnaryCall<DisconnectNotice, DisconnectNoticeResponse>;
317
+ gracefulDisconnect(input: DisconnectNotice, options?: RpcOptions): UnaryCall<DisconnectNotice, Empty>;
319
318
  }
320
319
  /**
321
320
  * @generated from protobuf service dht.ConnectionLockRpc
@@ -341,11 +340,11 @@ export class ConnectionLockRpcClient implements IConnectionLockRpcClient, Servic
341
340
  return stackIntercept<UnlockRequest, Empty>("unary", this._transport, method, opt, input);
342
341
  }
343
342
  /**
344
- * @generated from protobuf rpc: gracefulDisconnect(dht.DisconnectNotice) returns (dht.DisconnectNoticeResponse);
343
+ * @generated from protobuf rpc: gracefulDisconnect(dht.DisconnectNotice) returns (google.protobuf.Empty);
345
344
  */
346
- gracefulDisconnect(input: DisconnectNotice, options?: RpcOptions): UnaryCall<DisconnectNotice, DisconnectNoticeResponse> {
345
+ gracefulDisconnect(input: DisconnectNotice, options?: RpcOptions): UnaryCall<DisconnectNotice, Empty> {
347
346
  const method = this.methods[2], opt = this._transport.mergeOptions(options);
348
- return stackIntercept<DisconnectNotice, DisconnectNoticeResponse>("unary", this._transport, method, opt, input);
347
+ return stackIntercept<DisconnectNotice, Empty>("unary", this._transport, method, opt, input);
349
348
  }
350
349
  }
351
350
  /**
@@ -1,11 +1,10 @@
1
- // @generated by protobuf-ts 2.9.1 with parameter server_generic,generate_dependencies,long_type_number
1
+ // @generated by protobuf-ts 2.9.3 with parameter server_generic,generate_dependencies,long_type_number
2
2
  // @generated from protobuf file "packages/dht/protos/DhtRpc.proto" (package "dht", syntax proto3)
3
3
  // tslint:disable
4
4
  import { ExternalStoreDataResponse } from "./DhtRpc";
5
5
  import { ExternalStoreDataRequest } from "./DhtRpc";
6
6
  import { ExternalFindDataResponse } from "./DhtRpc";
7
7
  import { ExternalFindDataRequest } from "./DhtRpc";
8
- import { DisconnectNoticeResponse } from "./DhtRpc";
9
8
  import { DisconnectNotice } from "./DhtRpc";
10
9
  import { UnlockRequest } from "./DhtRpc";
11
10
  import { LockResponse } from "./DhtRpc";
@@ -132,9 +131,9 @@ export interface IConnectionLockRpc<T = ServerCallContext> {
132
131
  */
133
132
  unlockRequest(request: UnlockRequest, context: T): Promise<Empty>;
134
133
  /**
135
- * @generated from protobuf rpc: gracefulDisconnect(dht.DisconnectNotice) returns (dht.DisconnectNoticeResponse);
134
+ * @generated from protobuf rpc: gracefulDisconnect(dht.DisconnectNotice) returns (google.protobuf.Empty);
136
135
  */
137
- gracefulDisconnect(request: DisconnectNotice, context: T): Promise<DisconnectNoticeResponse>;
136
+ gracefulDisconnect(request: DisconnectNotice, context: T): Promise<Empty>;
138
137
  }
139
138
  /**
140
139
  * @generated from protobuf service dht.ExternalApiRpc
@@ -1,4 +1,4 @@
1
- // @generated by protobuf-ts 2.9.1 with parameter server_generic,generate_dependencies,long_type_number
1
+ // @generated by protobuf-ts 2.9.3 with parameter server_generic,generate_dependencies,long_type_number
2
2
  // @generated from protobuf file "packages/dht/protos/DhtRpc.proto" (package "dht", syntax proto3)
3
3
  // tslint:disable
4
4
  import { Empty } from "../../../google/protobuf/empty";
@@ -218,6 +218,20 @@ export interface PeerDescriptor {
218
218
  * @generated from protobuf field: optional uint32 region = 6;
219
219
  */
220
220
  region?: number;
221
+ /**
222
+ * @generated from protobuf field: optional uint32 ipAddress = 7;
223
+ */
224
+ ipAddress?: number;
225
+ /**
226
+ * @generated from protobuf field: optional bytes publicKey = 8;
227
+ */
228
+ publicKey?: Uint8Array;
229
+ /**
230
+ * signature of fields 2-8
231
+ *
232
+ * @generated from protobuf field: optional bytes signature = 9;
233
+ */
234
+ signature?: Uint8Array;
221
235
  }
222
236
  /**
223
237
  * @generated from protobuf message dht.ConnectivityMethod
@@ -264,6 +278,10 @@ export interface RouteMessageWrapper {
264
278
  * @generated from protobuf field: repeated dht.PeerDescriptor routingPath = 6;
265
279
  */
266
280
  routingPath: PeerDescriptor[];
281
+ /**
282
+ * @generated from protobuf field: repeated string parallelRootNodeIds = 7;
283
+ */
284
+ parallelRootNodeIds: string[];
267
285
  }
268
286
  /**
269
287
  * @generated from protobuf message dht.RouteMessageAck
@@ -317,6 +335,14 @@ export interface ConnectivityResponse {
317
335
  * @generated from protobuf field: dht.ConnectivityMethod websocket = 3;
318
336
  */
319
337
  websocket?: ConnectivityMethod;
338
+ /**
339
+ * @generated from protobuf field: uint32 ipAddress = 4;
340
+ */
341
+ ipAddress: number;
342
+ /**
343
+ * @generated from protobuf field: string version = 5;
344
+ */
345
+ version: string;
320
346
  }
321
347
  /**
322
348
  * @generated from protobuf message dht.HandshakeRequest
@@ -514,11 +540,6 @@ export interface DisconnectNotice {
514
540
  */
515
541
  disconnectMode: DisconnectMode;
516
542
  }
517
- /**
518
- * @generated from protobuf message dht.DisconnectNoticeResponse
519
- */
520
- export interface DisconnectNoticeResponse {
521
- }
522
543
  /**
523
544
  * @generated from protobuf message dht.ExternalFindDataRequest
524
545
  */
@@ -848,7 +869,10 @@ class PeerDescriptor$Type extends MessageType$<PeerDescriptor> {
848
869
  { no: 3, name: "udp", kind: "message", T: () => ConnectivityMethod },
849
870
  { no: 4, name: "tcp", kind: "message", T: () => ConnectivityMethod },
850
871
  { no: 5, name: "websocket", kind: "message", T: () => ConnectivityMethod },
851
- { no: 6, name: "region", kind: "scalar", opt: true, T: 13 /*ScalarType.UINT32*/ }
872
+ { no: 6, name: "region", kind: "scalar", opt: true, T: 13 /*ScalarType.UINT32*/ },
873
+ { no: 7, name: "ipAddress", kind: "scalar", opt: true, T: 13 /*ScalarType.UINT32*/ },
874
+ { no: 8, name: "publicKey", kind: "scalar", opt: true, T: 12 /*ScalarType.BYTES*/ },
875
+ { no: 9, name: "signature", kind: "scalar", opt: true, T: 12 /*ScalarType.BYTES*/ }
852
876
  ]);
853
877
  }
854
878
  }
@@ -879,7 +903,8 @@ class RouteMessageWrapper$Type extends MessageType$<RouteMessageWrapper> {
879
903
  { no: 3, name: "target", kind: "scalar", T: 12 /*ScalarType.BYTES*/ },
880
904
  { no: 4, name: "message", kind: "message", T: () => Message },
881
905
  { no: 5, name: "reachableThrough", kind: "message", repeat: 1 /*RepeatType.PACKED*/, T: () => PeerDescriptor },
882
- { no: 6, name: "routingPath", kind: "message", repeat: 1 /*RepeatType.PACKED*/, T: () => PeerDescriptor }
906
+ { no: 6, name: "routingPath", kind: "message", repeat: 1 /*RepeatType.PACKED*/, T: () => PeerDescriptor },
907
+ { no: 7, name: "parallelRootNodeIds", kind: "scalar", repeat: 2 /*RepeatType.UNPACKED*/, T: 9 /*ScalarType.STRING*/ }
883
908
  ]);
884
909
  }
885
910
  }
@@ -921,7 +946,9 @@ class ConnectivityResponse$Type extends MessageType$<ConnectivityResponse> {
921
946
  super("dht.ConnectivityResponse", [
922
947
  { no: 1, name: "host", kind: "scalar", T: 9 /*ScalarType.STRING*/ },
923
948
  { no: 2, name: "natType", kind: "scalar", T: 9 /*ScalarType.STRING*/ },
924
- { no: 3, name: "websocket", kind: "message", T: () => ConnectivityMethod }
949
+ { no: 3, name: "websocket", kind: "message", T: () => ConnectivityMethod },
950
+ { no: 4, name: "ipAddress", kind: "scalar", T: 13 /*ScalarType.UINT32*/ },
951
+ { no: 5, name: "version", kind: "scalar", T: 9 /*ScalarType.STRING*/ }
925
952
  ]);
926
953
  }
927
954
  }
@@ -1088,16 +1115,6 @@ class DisconnectNotice$Type extends MessageType$<DisconnectNotice> {
1088
1115
  */
1089
1116
  export const DisconnectNotice = new DisconnectNotice$Type();
1090
1117
  // @generated message type with reflection information, may provide speed optimized methods
1091
- class DisconnectNoticeResponse$Type extends MessageType$<DisconnectNoticeResponse> {
1092
- constructor() {
1093
- super("dht.DisconnectNoticeResponse", []);
1094
- }
1095
- }
1096
- /**
1097
- * @generated MessageType for protobuf message dht.DisconnectNoticeResponse
1098
- */
1099
- export const DisconnectNoticeResponse = new DisconnectNoticeResponse$Type();
1100
- // @generated message type with reflection information, may provide speed optimized methods
1101
1118
  class ExternalFindDataRequest$Type extends MessageType$<ExternalFindDataRequest> {
1102
1119
  constructor() {
1103
1120
  super("dht.ExternalFindDataRequest", [
@@ -1176,7 +1193,7 @@ export const WebrtcConnectorRpc = new ServiceType("dht.WebrtcConnectorRpc", [
1176
1193
  export const ConnectionLockRpc = new ServiceType("dht.ConnectionLockRpc", [
1177
1194
  { name: "lockRequest", options: {}, I: LockRequest, O: LockResponse },
1178
1195
  { name: "unlockRequest", options: {}, I: UnlockRequest, O: Empty },
1179
- { name: "gracefulDisconnect", options: {}, I: DisconnectNotice, O: DisconnectNoticeResponse }
1196
+ { name: "gracefulDisconnect", options: {}, I: DisconnectNotice, O: Empty }
1180
1197
  ]);
1181
1198
  /**
1182
1199
  * @generated ServiceType for protobuf service dht.ExternalApiRpc
@@ -1,4 +1,4 @@
1
- // @generated by protobuf-ts 2.9.1 with parameter server_generic,generate_dependencies,long_type_number
1
+ // @generated by protobuf-ts 2.9.3 with parameter server_generic,generate_dependencies,long_type_number
2
2
  // @generated from protobuf file "packages/proto-rpc/protos/ProtoRpc.proto" (package "protorpc", syntax proto3)
3
3
  // tslint:disable
4
4
  import { MessageType } from "@protobuf-ts/runtime";
@@ -6,7 +6,6 @@ export class DhtCallContext extends ProtoCallContext implements DhtRpcOptions {
6
6
  // used by client
7
7
  targetDescriptor?: PeerDescriptor
8
8
  sourceDescriptor?: PeerDescriptor
9
- notification?: boolean
10
9
  clientId?: number
11
10
  connect?: boolean
12
11
  sendIfStopped?: boolean
@@ -32,6 +32,6 @@ export interface ITransport {
32
32
 
33
33
  send(msg: Message, opts?: SendOptions): Promise<void>
34
34
  getLocalPeerDescriptor(): PeerDescriptor
35
- getAllConnectionPeerDescriptors(): PeerDescriptor[]
35
+ getConnections(): PeerDescriptor[]
36
36
  stop(): void | Promise<void>
37
37
  }
@@ -6,7 +6,7 @@ import { RpcMessage } from '../proto/packages/proto-rpc/protos/ProtoRpc'
6
6
  import { ServiceID } from '../types/ServiceID'
7
7
  import { DEFAULT_SEND_OPTIONS, SendOptions } from './ITransport'
8
8
 
9
- export class RoutingRpcCommunicator extends RpcCommunicator {
9
+ export class RoutingRpcCommunicator extends RpcCommunicator<DhtCallContext> {
10
10
  private ownServiceId: ServiceID
11
11
  private sendFn: (msg: Message, opts: SendOptions) => Promise<void>
12
12
 
@@ -5,11 +5,9 @@ import { RecursiveOperation } from '../../src/proto/packages/dht/protos/DhtRpc'
5
5
  import { createMockConnectionDhtNode } from '../utils/utils'
6
6
  import { execSync } from 'child_process'
7
7
  import fs from 'fs'
8
- import { PeerID } from '../../src/helpers/PeerID'
9
- import { getNodeIdFromPeerDescriptor, peerIdFromPeerDescriptor } from '../../src/helpers/peerIdFromPeerDescriptor'
10
8
  import { Logger, wait } from '@streamr/utils'
11
9
  import { debugVars } from '../../src/helpers/debugHelpers'
12
- import { getDhtAddressFromRaw } from '../../src/identifiers'
10
+ import { getDhtAddressFromRaw, getNodeIdFromPeerDescriptor } from '../../src/identifiers'
13
11
 
14
12
  const logger = new Logger(module)
15
13
 
@@ -59,17 +57,17 @@ describe('Find correctness', () => {
59
57
  logger.info('waiting over')
60
58
 
61
59
  nodes.forEach((node) => logger.info(getNodeIdFromPeerDescriptor(node.getLocalPeerDescriptor()) + ': connections:' +
62
- node.getNumberOfConnections() + ', kbucket: ' + node.getNumberOfNeighbors()
63
- + ', localLocked: ' + node.getNumberOfLocalLockedConnections()
64
- + ', remoteLocked: ' + node.getNumberOfRemoteLockedConnections()
65
- + ', weakLocked: ' + node.getNumberOfWeakLockedConnections()))
60
+ node.getConnectionCount() + ', kbucket: ' + node.getNeighborCount()
61
+ + ', localLocked: ' + node.getLocalLockedConnectionCount()
62
+ + ', remoteLocked: ' + node.getRemoteLockedConnectionCount()
63
+ + ', weakLocked: ' + node.getWeakLockedConnectionCount()))
66
64
 
67
65
  logger.info('starting find')
68
66
  const targetId = Uint8Array.from(dhtIds[9].data)
69
67
  const results = await nodes[159].executeRecursiveOperation(getDhtAddressFromRaw(targetId), RecursiveOperation.FIND_NODE)
70
68
  logger.info('find over')
71
69
  expect(results.closestNodes).toBeGreaterThanOrEqual(5)
72
- expect(PeerID.fromValue(targetId).equals(peerIdFromPeerDescriptor(results.closestNodes[0])))
70
+ expect(getDhtAddressFromRaw(targetId)).toEqual(getNodeIdFromPeerDescriptor(results.closestNodes[0]))
73
71
 
74
72
  }, 180000)
75
73
  })
@@ -1,11 +1,10 @@
1
1
  /* eslint-disable no-console */
2
2
  import { Simulator } from '../../src/connection/simulator/Simulator'
3
3
  import { DhtNode } from '../../src/dht/DhtNode'
4
- import { getNodeIdFromPeerDescriptor } from '../../src/helpers/peerIdFromPeerDescriptor'
5
4
  import { createMockConnectionDhtNode } from '../utils/utils'
6
5
  import { execSync } from 'child_process'
7
6
  import fs from 'fs'
8
- import { DhtAddress, getDhtAddressFromRaw } from '../../src/identifiers'
7
+ import { DhtAddress, getDhtAddressFromRaw, getNodeIdFromPeerDescriptor } from '../../src/identifiers'
9
8
 
10
9
  describe('Kademlia correctness', () => {
11
10
  let entryPoint: DhtNode
@@ -93,7 +92,7 @@ describe('Kademlia correctness', () => {
93
92
  }
94
93
 
95
94
  if (i > 0) {
96
- sumKbucketSize += nodes[i].getNumberOfNeighbors()
95
+ sumKbucketSize += nodes[i].getNeighborCount()
97
96
  sumCorrectNeighbors += correctNeighbors
98
97
  }
99
98
  }