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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (304) hide show
  1. package/dist/package.json +8 -8
  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.js.map +1 -1
  27. package/dist/src/connection/connectivityRequestHandler.js +5 -2
  28. package/dist/src/connection/connectivityRequestHandler.js.map +1 -1
  29. package/dist/src/connection/simulator/Simulator.js +32 -20
  30. package/dist/src/connection/simulator/Simulator.js.map +1 -1
  31. package/dist/src/connection/simulator/SimulatorConnection.js +13 -10
  32. package/dist/src/connection/simulator/SimulatorConnection.js.map +1 -1
  33. package/dist/src/connection/simulator/SimulatorConnector.js +9 -6
  34. package/dist/src/connection/simulator/SimulatorConnector.js.map +1 -1
  35. package/dist/src/connection/simulator/pings.js.map +1 -1
  36. package/dist/src/connection/webrtc/NodeWebrtcConnection.d.ts +1 -1
  37. package/dist/src/connection/webrtc/NodeWebrtcConnection.js +26 -14
  38. package/dist/src/connection/webrtc/NodeWebrtcConnection.js.map +1 -1
  39. package/dist/src/connection/webrtc/WebrtcConnector.d.ts +0 -1
  40. package/dist/src/connection/webrtc/WebrtcConnector.js +18 -17
  41. package/dist/src/connection/webrtc/WebrtcConnector.js.map +1 -1
  42. package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js +10 -9
  43. package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js.map +1 -1
  44. package/dist/src/connection/webrtc/iceServerAsString.js.map +1 -1
  45. package/dist/src/connection/websocket/AutoCertifierClientFacade.js +3 -0
  46. package/dist/src/connection/websocket/AutoCertifierClientFacade.js.map +1 -1
  47. package/dist/src/connection/websocket/ClientWebsocket.js +7 -4
  48. package/dist/src/connection/websocket/ClientWebsocket.js.map +1 -1
  49. package/dist/src/connection/websocket/ServerWebsocket.d.ts +1 -0
  50. package/dist/src/connection/websocket/ServerWebsocket.js +22 -3
  51. package/dist/src/connection/websocket/ServerWebsocket.js.map +1 -1
  52. package/dist/src/connection/websocket/WebsocketConnector.d.ts +2 -1
  53. package/dist/src/connection/websocket/WebsocketConnector.js +24 -15
  54. package/dist/src/connection/websocket/WebsocketConnector.js.map +1 -1
  55. package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.d.ts +2 -1
  56. package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.js +3 -1
  57. package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.js.map +1 -1
  58. package/dist/src/connection/websocket/WebsocketConnectorRpcRemote.js +2 -2
  59. package/dist/src/connection/websocket/WebsocketConnectorRpcRemote.js.map +1 -1
  60. package/dist/src/connection/websocket/WebsocketServer.js +6 -3
  61. package/dist/src/connection/websocket/WebsocketServer.js.map +1 -1
  62. package/dist/src/dht/DhtNode.d.ts +18 -19
  63. package/dist/src/dht/DhtNode.js +56 -65
  64. package/dist/src/dht/DhtNode.js.map +1 -1
  65. package/dist/src/dht/DhtNodeRpcLocal.d.ts +1 -1
  66. package/dist/src/dht/DhtNodeRpcLocal.js +5 -4
  67. package/dist/src/dht/DhtNodeRpcLocal.js.map +1 -1
  68. package/dist/src/dht/DhtNodeRpcRemote.d.ts +2 -1
  69. package/dist/src/dht/DhtNodeRpcRemote.js +5 -3
  70. package/dist/src/dht/DhtNodeRpcRemote.js.map +1 -1
  71. package/dist/src/dht/ExternalApiRpcLocal.d.ts +1 -1
  72. package/dist/src/dht/ExternalApiRpcLocal.js +4 -3
  73. package/dist/src/dht/ExternalApiRpcLocal.js.map +1 -1
  74. package/dist/src/dht/ExternalApiRpcRemote.js.map +1 -1
  75. package/dist/src/dht/PeerManager.d.ts +5 -5
  76. package/dist/src/dht/PeerManager.js +31 -24
  77. package/dist/src/dht/PeerManager.js.map +1 -1
  78. package/dist/src/dht/contact/Contact.js +3 -2
  79. package/dist/src/dht/contact/Contact.js.map +1 -1
  80. package/dist/src/dht/contact/ContactList.js +9 -5
  81. package/dist/src/dht/contact/ContactList.js.map +1 -1
  82. package/dist/src/dht/contact/RandomContactList.js +1 -0
  83. package/dist/src/dht/contact/RandomContactList.js.map +1 -1
  84. package/dist/src/dht/contact/RpcRemote.d.ts +2 -1
  85. package/dist/src/dht/contact/RpcRemote.js +4 -0
  86. package/dist/src/dht/contact/RpcRemote.js.map +1 -1
  87. package/dist/src/dht/contact/SortedContactList.js +3 -2
  88. package/dist/src/dht/contact/SortedContactList.js.map +1 -1
  89. package/dist/src/dht/discovery/DiscoverySession.js +8 -8
  90. package/dist/src/dht/discovery/DiscoverySession.js.map +1 -1
  91. package/dist/src/dht/discovery/PeerDiscovery.d.ts +8 -2
  92. package/dist/src/dht/discovery/PeerDiscovery.js +26 -17
  93. package/dist/src/dht/discovery/PeerDiscovery.js.map +1 -1
  94. package/dist/src/dht/recursive-operation/RecursiveOperationManager.d.ts +1 -1
  95. package/dist/src/dht/recursive-operation/RecursiveOperationManager.js +9 -9
  96. package/dist/src/dht/recursive-operation/RecursiveOperationManager.js.map +1 -1
  97. package/dist/src/dht/recursive-operation/RecursiveOperationRpcLocal.js +3 -2
  98. package/dist/src/dht/recursive-operation/RecursiveOperationRpcLocal.js.map +1 -1
  99. package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.js +6 -5
  100. package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.js.map +1 -1
  101. package/dist/src/dht/recursive-operation/RecursiveOperationSession.d.ts +2 -1
  102. package/dist/src/dht/recursive-operation/RecursiveOperationSession.js +26 -20
  103. package/dist/src/dht/recursive-operation/RecursiveOperationSession.js.map +1 -1
  104. package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.d.ts +4 -2
  105. package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.js +5 -2
  106. package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.js.map +1 -1
  107. package/dist/src/dht/routing/DuplicateDetector.d.ts +2 -4
  108. package/dist/src/dht/routing/DuplicateDetector.js +10 -15
  109. package/dist/src/dht/routing/DuplicateDetector.js.map +1 -1
  110. package/dist/src/dht/routing/Router.d.ts +1 -1
  111. package/dist/src/dht/routing/Router.js +20 -15
  112. package/dist/src/dht/routing/Router.js.map +1 -1
  113. package/dist/src/dht/routing/RouterRpcLocal.js +4 -4
  114. package/dist/src/dht/routing/RouterRpcLocal.js.map +1 -1
  115. package/dist/src/dht/routing/RouterRpcRemote.js +11 -9
  116. package/dist/src/dht/routing/RouterRpcRemote.js.map +1 -1
  117. package/dist/src/dht/routing/RoutingSession.d.ts +2 -0
  118. package/dist/src/dht/routing/RoutingSession.js +27 -9
  119. package/dist/src/dht/routing/RoutingSession.js.map +1 -1
  120. package/dist/src/dht/store/LocalDataStore.js +5 -4
  121. package/dist/src/dht/store/LocalDataStore.js.map +1 -1
  122. package/dist/src/dht/store/StoreManager.js +8 -8
  123. package/dist/src/dht/store/StoreManager.js.map +1 -1
  124. package/dist/src/dht/store/StoreRpcLocal.js +1 -0
  125. package/dist/src/dht/store/StoreRpcLocal.js.map +1 -1
  126. package/dist/src/dht/store/StoreRpcRemote.js +3 -3
  127. package/dist/src/dht/store/StoreRpcRemote.js.map +1 -1
  128. package/dist/src/exports.d.ts +1 -4
  129. package/dist/src/exports.js +4 -7
  130. package/dist/src/exports.js.map +1 -1
  131. package/dist/src/helpers/AddressTools.js.map +1 -1
  132. package/dist/src/helpers/Connectivity.js.map +1 -1
  133. package/dist/src/helpers/MapWithTtl.js +2 -1
  134. package/dist/src/helpers/MapWithTtl.js.map +1 -1
  135. package/dist/src/helpers/createPeerDescriptor.d.ts +3 -0
  136. package/dist/src/helpers/createPeerDescriptor.js +56 -0
  137. package/dist/src/helpers/createPeerDescriptor.js.map +1 -0
  138. package/dist/src/helpers/createPeerDescriptorSignaturePayload.d.ts +2 -0
  139. package/dist/src/helpers/createPeerDescriptorSignaturePayload.js +30 -0
  140. package/dist/src/helpers/createPeerDescriptorSignaturePayload.js.map +1 -0
  141. package/dist/src/helpers/debugHelpers.js.map +1 -1
  142. package/dist/src/helpers/errors.js +2 -0
  143. package/dist/src/helpers/errors.js.map +1 -1
  144. package/dist/src/helpers/offering.d.ts +4 -0
  145. package/dist/src/helpers/offering.js +18 -0
  146. package/dist/src/helpers/offering.js.map +1 -0
  147. package/dist/src/helpers/protoToString.js.map +1 -1
  148. package/dist/src/identifiers.d.ts +3 -0
  149. package/dist/src/identifiers.js +9 -1
  150. package/dist/src/identifiers.js.map +1 -1
  151. package/dist/src/proto/google/protobuf/any.d.ts +8 -5
  152. package/dist/src/proto/google/protobuf/any.js +8 -8
  153. package/dist/src/proto/google/protobuf/any.js.map +1 -1
  154. package/dist/src/proto/google/protobuf/empty.d.ts +0 -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.d.ts +10 -1
  158. package/dist/src/proto/google/protobuf/timestamp.js +10 -10
  159. package/dist/src/proto/google/protobuf/timestamp.js.map +1 -1
  160. package/dist/src/proto/packages/dht/protos/DhtRpc.client.d.ts +4 -5
  161. package/dist/src/proto/packages/dht/protos/DhtRpc.client.js +38 -29
  162. package/dist/src/proto/packages/dht/protos/DhtRpc.client.js.map +1 -1
  163. package/dist/src/proto/packages/dht/protos/DhtRpc.d.ts +22 -12
  164. package/dist/src/proto/packages/dht/protos/DhtRpc.js +11 -16
  165. package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +1 -1
  166. package/dist/src/proto/packages/dht/protos/DhtRpc.server.d.ts +2 -3
  167. package/dist/src/proto/packages/proto-rpc/protos/ProtoRpc.js +1 -1
  168. package/dist/src/rpc-protocol/DhtCallContext.d.ts +0 -1
  169. package/dist/src/rpc-protocol/DhtCallContext.js +8 -0
  170. package/dist/src/rpc-protocol/DhtCallContext.js.map +1 -1
  171. package/dist/src/transport/ITransport.d.ts +1 -1
  172. package/dist/src/transport/ListeningRpcCommunicator.js +2 -0
  173. package/dist/src/transport/ListeningRpcCommunicator.js.map +1 -1
  174. package/dist/src/transport/RoutingRpcCommunicator.d.ts +2 -1
  175. package/dist/src/transport/RoutingRpcCommunicator.js +2 -0
  176. package/dist/src/transport/RoutingRpcCommunicator.js.map +1 -1
  177. package/package.json +8 -8
  178. package/protos/DhtRpc.proto +7 -4
  179. package/src/connection/Connection.ts +6 -1
  180. package/src/connection/ConnectionLockHandler.ts +3 -3
  181. package/src/connection/ConnectionLockRpcLocal.ts +1 -5
  182. package/src/connection/ConnectionLockRpcRemote.ts +1 -1
  183. package/src/connection/ConnectionManager.ts +24 -38
  184. package/src/connection/ConnectorFacade.ts +3 -2
  185. package/src/connection/IConnection.ts +2 -8
  186. package/src/connection/ManagedConnection.ts +3 -3
  187. package/src/connection/connectivityRequestHandler.ts +7 -3
  188. package/src/connection/simulator/Simulator.ts +1 -2
  189. package/src/connection/simulator/SimulatorConnection.ts +1 -1
  190. package/src/connection/simulator/SimulatorConnector.ts +1 -2
  191. package/src/connection/webrtc/BrowserWebrtcConnection.ts +4 -3
  192. package/src/connection/webrtc/NodeWebrtcConnection.ts +5 -4
  193. package/src/connection/webrtc/WebrtcConnector.ts +9 -17
  194. package/src/connection/webrtc/WebrtcConnectorRpcLocal.ts +7 -7
  195. package/src/connection/websocket/ClientWebsocket.ts +3 -2
  196. package/src/connection/websocket/ServerWebsocket.ts +17 -1
  197. package/src/connection/websocket/WebsocketConnector.ts +10 -9
  198. package/src/connection/websocket/WebsocketConnectorRpcLocal.ts +4 -2
  199. package/src/connection/websocket/WebsocketConnectorRpcRemote.ts +1 -1
  200. package/src/connection/websocket/WebsocketServer.ts +2 -2
  201. package/src/dht/DhtNode.ts +63 -86
  202. package/src/dht/DhtNodeRpcLocal.ts +5 -5
  203. package/src/dht/DhtNodeRpcRemote.ts +3 -3
  204. package/src/dht/ExternalApiRpcLocal.ts +3 -4
  205. package/src/dht/PeerManager.ts +14 -20
  206. package/src/dht/contact/Contact.ts +1 -2
  207. package/src/dht/contact/RpcRemote.ts +2 -1
  208. package/src/dht/discovery/DiscoverySession.ts +2 -3
  209. package/src/dht/discovery/PeerDiscovery.ts +16 -9
  210. package/src/dht/recursive-operation/RecursiveOperationManager.ts +12 -6
  211. package/src/dht/recursive-operation/RecursiveOperationRpcLocal.ts +1 -1
  212. package/src/dht/recursive-operation/RecursiveOperationRpcRemote.ts +3 -2
  213. package/src/dht/recursive-operation/RecursiveOperationSession.ts +19 -9
  214. package/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.ts +13 -3
  215. package/src/dht/routing/DuplicateDetector.ts +9 -21
  216. package/src/dht/routing/Router.ts +12 -11
  217. package/src/dht/routing/RouterRpcLocal.ts +1 -2
  218. package/src/dht/routing/RouterRpcRemote.ts +5 -5
  219. package/src/dht/routing/RoutingSession.ts +22 -2
  220. package/src/dht/store/StoreManager.ts +1 -2
  221. package/src/dht/store/StoreRpcRemote.ts +1 -1
  222. package/src/exports.ts +9 -4
  223. package/src/helpers/createPeerDescriptor.ts +56 -0
  224. package/src/helpers/createPeerDescriptorSignaturePayload.ts +28 -0
  225. package/src/helpers/offering.ts +15 -0
  226. package/src/identifiers.ts +10 -1
  227. package/src/proto/google/protobuf/any.ts +12 -9
  228. package/src/proto/google/protobuf/empty.ts +2 -5
  229. package/src/proto/google/protobuf/timestamp.ts +14 -5
  230. package/src/proto/packages/dht/protos/DhtRpc.client.ts +6 -7
  231. package/src/proto/packages/dht/protos/DhtRpc.server.ts +3 -4
  232. package/src/proto/packages/dht/protos/DhtRpc.ts +32 -20
  233. package/src/proto/packages/proto-rpc/protos/ProtoRpc.ts +1 -1
  234. package/src/rpc-protocol/DhtCallContext.ts +0 -1
  235. package/src/transport/ITransport.ts +1 -1
  236. package/src/transport/RoutingRpcCommunicator.ts +1 -1
  237. package/test/benchmark/Find.test.ts +6 -8
  238. package/test/benchmark/KademliaCorrectness.test.ts +2 -3
  239. package/test/benchmark/SortedContactListBenchmark.test.ts +16 -16
  240. package/test/benchmark/WebsocketServerMemoryLeak.test.ts +1 -1
  241. package/test/benchmark/kademlia-simulation/KademliaSimulation.ts +8 -8
  242. package/test/benchmark/kademlia-simulation/SimulationNode.ts +8 -8
  243. package/test/end-to-end/Layer0-Layer1.test.ts +1 -1
  244. package/test/end-to-end/Layer0.test.ts +4 -4
  245. package/test/end-to-end/Layer0MixedConnectionTypes.test.ts +12 -12
  246. package/test/end-to-end/Layer0Webrtc-Layer1.test.ts +18 -18
  247. package/test/end-to-end/Layer0Webrtc.test.ts +13 -10
  248. package/test/end-to-end/Layer1-Scale-WebSocket.test.ts +2 -2
  249. package/test/end-to-end/Layer1-Scale-Webrtc.test.ts +2 -2
  250. package/test/end-to-end/RecoveryFromFailedAutoCertification.test.ts +1 -1
  251. package/test/end-to-end/WebsocketConnectionRequest.test.ts +3 -3
  252. package/test/end-to-end/memory-leak.test.ts +2 -2
  253. package/test/integration/ConnectionLocking.test.ts +60 -47
  254. package/test/integration/ConnectionManager.test.ts +8 -7
  255. package/test/integration/DhtJoinPeerDiscovery.test.ts +2 -2
  256. package/test/integration/DhtNodeExternalAPI.test.ts +1 -2
  257. package/test/integration/DhtNodeRpcRemote.test.ts +4 -3
  258. package/test/integration/DhtRpc.test.ts +4 -3
  259. package/test/integration/Find.test.ts +4 -6
  260. package/test/integration/Layer1-scale.test.ts +7 -7
  261. package/test/integration/Mock-Layer1-Layer0.test.ts +21 -24
  262. package/test/integration/MultipleEntryPointJoining.test.ts +7 -7
  263. package/test/integration/ReplicateData.test.ts +52 -161
  264. package/test/integration/RouteMessage.test.ts +24 -47
  265. package/test/integration/RouterRpcRemote.test.ts +7 -4
  266. package/test/integration/ScaleDownDht.test.ts +2 -3
  267. package/test/integration/SimultaneousConnections.test.ts +9 -8
  268. package/test/integration/Store.test.ts +1 -2
  269. package/test/integration/StoreAndDelete.test.ts +5 -0
  270. package/test/integration/StoreOnDhtWithThreeNodes.test.ts +59 -0
  271. package/test/integration/StoreOnDhtWithTwoNodes.test.ts +1 -1
  272. package/test/integration/StoreRpcRemote.test.ts +4 -4
  273. package/test/integration/WebrtcConnectionManagement.test.ts +6 -5
  274. package/test/integration/WebrtcConnectorRpc.test.ts +3 -2
  275. package/test/integration/WebsocketConnectionManagement.test.ts +27 -15
  276. package/test/integration/WebsocketConnectorRpc.test.ts +3 -2
  277. package/test/integration/{RpcErrors.test.ts → rpc-connections-over-webrpc.test.ts} +6 -3
  278. package/test/unit/DuplicateDetector.test.ts +2 -2
  279. package/test/unit/LocalDataStore.test.ts +1 -4
  280. package/test/unit/RandomContactList.test.ts +2 -4
  281. package/test/unit/RecursiveOperationManager.test.ts +5 -6
  282. package/test/unit/RecursiveOperationSession.test.ts +5 -4
  283. package/test/unit/Router.test.ts +25 -8
  284. package/test/unit/RoutingSession.test.ts +3 -3
  285. package/test/unit/SortedContactList.test.ts +2 -4
  286. package/test/unit/connectivityRequestHandler.test.ts +5 -3
  287. package/test/unit/createPeerDescriptor.test.ts +63 -0
  288. package/test/utils/FakeTransport.ts +7 -4
  289. package/test/utils/mock/Transport.ts +1 -1
  290. package/test/utils/utils.ts +6 -6
  291. package/dist/src/helpers/PeerID.d.ts +0 -27
  292. package/dist/src/helpers/PeerID.js +0 -87
  293. package/dist/src/helpers/PeerID.js.map +0 -1
  294. package/dist/src/helpers/UUID.d.ts +0 -8
  295. package/dist/src/helpers/UUID.js +0 -36
  296. package/dist/src/helpers/UUID.js.map +0 -1
  297. package/dist/src/helpers/peerIdFromPeerDescriptor.d.ts +0 -7
  298. package/dist/src/helpers/peerIdFromPeerDescriptor.js +0 -23
  299. package/dist/src/helpers/peerIdFromPeerDescriptor.js.map +0 -1
  300. package/src/helpers/PeerID.ts +0 -97
  301. package/src/helpers/UUID.ts +0 -35
  302. package/src/helpers/peerIdFromPeerDescriptor.ts +0 -20
  303. package/test/unit/PeerID.test.ts +0 -22
  304. 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";
@@ -75,7 +74,7 @@ import { MessageType } from "@protobuf-ts/runtime";
75
74
  * foo = any.unpack(Foo.class);
76
75
  * }
77
76
  *
78
- * Example 3: Pack and unpack a message in Python.
77
+ * Example 3: Pack and unpack a message in Python.
79
78
  *
80
79
  * foo = Foo(...)
81
80
  * any = Any()
@@ -85,13 +84,16 @@ import { MessageType } from "@protobuf-ts/runtime";
85
84
  * any.Unpack(foo)
86
85
  * ...
87
86
  *
88
- * Example 4: Pack and unpack a message in Go
87
+ * Example 4: Pack and unpack a message in Go
89
88
  *
90
89
  * foo := &pb.Foo{...}
91
- * any, err := ptypes.MarshalAny(foo)
90
+ * any, err := anypb.New(foo)
91
+ * if err != nil {
92
+ * ...
93
+ * }
92
94
  * ...
93
95
  * foo := &pb.Foo{}
94
- * if err := ptypes.UnmarshalAny(any, foo); err != nil {
96
+ * if err := any.UnmarshalTo(foo); err != nil {
95
97
  * ...
96
98
  * }
97
99
  *
@@ -103,7 +105,7 @@ import { MessageType } from "@protobuf-ts/runtime";
103
105
  *
104
106
  *
105
107
  * JSON
106
- * ====
108
+ *
107
109
  * The JSON representation of an `Any` value uses the regular
108
110
  * representation of the deserialized, embedded message, with an
109
111
  * additional field `@type` which contains the type URL. Example:
@@ -272,8 +274,9 @@ class Any$Type extends MessageType<Any> {
272
274
  return name;
273
275
  }
274
276
  create(value?: PartialMessage<Any>): Any {
275
- const message = { typeUrl: "", value: new Uint8Array(0) };
276
- globalThis.Object.defineProperty(message, MESSAGE_TYPE, { enumerable: false, value: this });
277
+ const message = globalThis.Object.create((this.messagePrototype!));
278
+ message.typeUrl = "";
279
+ message.value = new Uint8Array(0);
277
280
  if (value !== undefined)
278
281
  reflectionMergePartial<Any>(this, message, value);
279
282
  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
@@ -50,7 +49,6 @@ import { MessageType } from "@protobuf-ts/runtime";
50
49
  * rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty);
51
50
  * }
52
51
  *
53
- * The JSON representation for `Empty` is empty JSON object `{}`.
54
52
  *
55
53
  * @generated from protobuf message google.protobuf.Empty
56
54
  */
@@ -62,8 +60,7 @@ class Empty$Type extends MessageType<Empty> {
62
60
  super("google.protobuf.Empty", []);
63
61
  }
64
62
  create(value?: PartialMessage<Empty>): Empty {
65
- const message = {};
66
- globalThis.Object.defineProperty(message, MESSAGE_TYPE, { enumerable: false, value: this });
63
+ const message = globalThis.Object.create((this.messagePrototype!));
67
64
  if (value !== undefined)
68
65
  reflectionMergePartial<Empty>(this, message, value);
69
66
  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";
@@ -99,7 +98,16 @@ import { MessageType } from "@protobuf-ts/runtime";
99
98
  * .setNanos((int) ((millis % 1000) * 1000000)).build();
100
99
  *
101
100
  *
102
- * Example 5: Compute Timestamp from current time in Python.
101
+ * Example 5: Compute Timestamp from Java `Instant.now()`.
102
+ *
103
+ * Instant now = Instant.now();
104
+ *
105
+ * Timestamp timestamp =
106
+ * Timestamp.newBuilder().setSeconds(now.getEpochSecond())
107
+ * .setNanos(now.getNano()).build();
108
+ *
109
+ *
110
+ * Example 6: Compute Timestamp from current time in Python.
103
111
  *
104
112
  * timestamp = Timestamp()
105
113
  * timestamp.GetCurrentTime()
@@ -234,8 +242,9 @@ class Timestamp$Type extends MessageType<Timestamp> {
234
242
  return target;
235
243
  }
236
244
  create(value?: PartialMessage<Timestamp>): Timestamp {
237
- const message = { seconds: 0, nanos: 0 };
238
- globalThis.Object.defineProperty(message, MESSAGE_TYPE, { enumerable: false, value: this });
245
+ const message = globalThis.Object.create((this.messagePrototype!));
246
+ message.seconds = 0;
247
+ message.nanos = 0;
239
248
  if (value !== undefined)
240
249
  reflectionMergePartial<Timestamp>(this, message, value);
241
250
  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,10 @@ 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;
320
342
  }
321
343
  /**
322
344
  * @generated from protobuf message dht.HandshakeRequest
@@ -514,11 +536,6 @@ export interface DisconnectNotice {
514
536
  */
515
537
  disconnectMode: DisconnectMode;
516
538
  }
517
- /**
518
- * @generated from protobuf message dht.DisconnectNoticeResponse
519
- */
520
- export interface DisconnectNoticeResponse {
521
- }
522
539
  /**
523
540
  * @generated from protobuf message dht.ExternalFindDataRequest
524
541
  */
@@ -848,7 +865,10 @@ class PeerDescriptor$Type extends MessageType$<PeerDescriptor> {
848
865
  { no: 3, name: "udp", kind: "message", T: () => ConnectivityMethod },
849
866
  { no: 4, name: "tcp", kind: "message", T: () => ConnectivityMethod },
850
867
  { no: 5, name: "websocket", kind: "message", T: () => ConnectivityMethod },
851
- { no: 6, name: "region", kind: "scalar", opt: true, T: 13 /*ScalarType.UINT32*/ }
868
+ { no: 6, name: "region", kind: "scalar", opt: true, T: 13 /*ScalarType.UINT32*/ },
869
+ { no: 7, name: "ipAddress", kind: "scalar", opt: true, T: 13 /*ScalarType.UINT32*/ },
870
+ { no: 8, name: "publicKey", kind: "scalar", opt: true, T: 12 /*ScalarType.BYTES*/ },
871
+ { no: 9, name: "signature", kind: "scalar", opt: true, T: 12 /*ScalarType.BYTES*/ }
852
872
  ]);
853
873
  }
854
874
  }
@@ -879,7 +899,8 @@ class RouteMessageWrapper$Type extends MessageType$<RouteMessageWrapper> {
879
899
  { no: 3, name: "target", kind: "scalar", T: 12 /*ScalarType.BYTES*/ },
880
900
  { no: 4, name: "message", kind: "message", T: () => Message },
881
901
  { 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 }
902
+ { no: 6, name: "routingPath", kind: "message", repeat: 1 /*RepeatType.PACKED*/, T: () => PeerDescriptor },
903
+ { no: 7, name: "parallelRootNodeIds", kind: "scalar", repeat: 2 /*RepeatType.UNPACKED*/, T: 9 /*ScalarType.STRING*/ }
883
904
  ]);
884
905
  }
885
906
  }
@@ -921,7 +942,8 @@ class ConnectivityResponse$Type extends MessageType$<ConnectivityResponse> {
921
942
  super("dht.ConnectivityResponse", [
922
943
  { no: 1, name: "host", kind: "scalar", T: 9 /*ScalarType.STRING*/ },
923
944
  { no: 2, name: "natType", kind: "scalar", T: 9 /*ScalarType.STRING*/ },
924
- { no: 3, name: "websocket", kind: "message", T: () => ConnectivityMethod }
945
+ { no: 3, name: "websocket", kind: "message", T: () => ConnectivityMethod },
946
+ { no: 4, name: "ipAddress", kind: "scalar", T: 13 /*ScalarType.UINT32*/ }
925
947
  ]);
926
948
  }
927
949
  }
@@ -1088,16 +1110,6 @@ class DisconnectNotice$Type extends MessageType$<DisconnectNotice> {
1088
1110
  */
1089
1111
  export const DisconnectNotice = new DisconnectNotice$Type();
1090
1112
  // @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
1113
  class ExternalFindDataRequest$Type extends MessageType$<ExternalFindDataRequest> {
1102
1114
  constructor() {
1103
1115
  super("dht.ExternalFindDataRequest", [
@@ -1176,7 +1188,7 @@ export const WebrtcConnectorRpc = new ServiceType("dht.WebrtcConnectorRpc", [
1176
1188
  export const ConnectionLockRpc = new ServiceType("dht.ConnectionLockRpc", [
1177
1189
  { name: "lockRequest", options: {}, I: LockRequest, O: LockResponse },
1178
1190
  { name: "unlockRequest", options: {}, I: UnlockRequest, O: Empty },
1179
- { name: "gracefulDisconnect", options: {}, I: DisconnectNotice, O: DisconnectNoticeResponse }
1191
+ { name: "gracefulDisconnect", options: {}, I: DisconnectNotice, O: Empty }
1180
1192
  ]);
1181
1193
  /**
1182
1194
  * @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
  }