@streamr/dht 101.1.2 → 102.0.0-beta.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 (369) hide show
  1. package/dist/package.json +17 -18
  2. package/dist/src/connection/Connection.d.ts +1 -1
  3. package/dist/src/connection/ConnectionLockRpcLocal.d.ts +5 -3
  4. package/dist/src/connection/ConnectionLockRpcLocal.js +9 -3
  5. package/dist/src/connection/ConnectionLockRpcLocal.js.map +1 -1
  6. package/dist/src/connection/ConnectionLockRpcRemote.d.ts +3 -2
  7. package/dist/src/connection/ConnectionLockRpcRemote.js +14 -3
  8. package/dist/src/connection/ConnectionLockRpcRemote.js.map +1 -1
  9. package/dist/src/connection/ConnectionLockStates.d.ts +5 -0
  10. package/dist/src/connection/ConnectionLockStates.js +14 -0
  11. package/dist/src/connection/ConnectionLockStates.js.map +1 -1
  12. package/dist/src/connection/ConnectionManager.d.ts +8 -1
  13. package/dist/src/connection/ConnectionManager.js +96 -32
  14. package/dist/src/connection/ConnectionManager.js.map +1 -1
  15. package/dist/src/connection/ConnectionsView.d.ts +1 -1
  16. package/dist/src/connection/ConnectorFacade.d.ts +1 -1
  17. package/dist/src/connection/Handshaker.d.ts +2 -2
  18. package/dist/src/connection/Handshaker.js +11 -7
  19. package/dist/src/connection/Handshaker.js.map +1 -1
  20. package/dist/src/connection/ManagedConnection.d.ts +7 -1
  21. package/dist/src/connection/ManagedConnection.js +41 -8
  22. package/dist/src/connection/ManagedConnection.js.map +1 -1
  23. package/dist/src/connection/PendingConnection.d.ts +1 -1
  24. package/dist/src/connection/connectivityChecker.d.ts +1 -1
  25. package/dist/src/connection/connectivityChecker.js +22 -11
  26. package/dist/src/connection/connectivityChecker.js.map +1 -1
  27. package/dist/src/connection/connectivityRequestHandler.js +4 -4
  28. package/dist/src/connection/connectivityRequestHandler.js.map +1 -1
  29. package/dist/src/connection/simulator/Simulator.d.ts +1 -1
  30. package/dist/src/connection/simulator/Simulator.js +5 -4
  31. package/dist/src/connection/simulator/Simulator.js.map +1 -1
  32. package/dist/src/connection/simulator/SimulatorConnection.d.ts +1 -1
  33. package/dist/src/connection/simulator/SimulatorConnection.js +9 -9
  34. package/dist/src/connection/simulator/SimulatorConnection.js.map +1 -1
  35. package/dist/src/connection/simulator/SimulatorConnector.d.ts +1 -1
  36. package/dist/src/connection/simulator/SimulatorConnector.js +4 -4
  37. package/dist/src/connection/simulator/SimulatorConnector.js.map +1 -1
  38. package/dist/src/connection/simulator/SimulatorTransport.d.ts +1 -1
  39. package/dist/src/connection/simulator/SimulatorTransport.js +2 -1
  40. package/dist/src/connection/simulator/SimulatorTransport.js.map +1 -1
  41. package/dist/src/connection/simulator/pings.d.ts +1 -1
  42. package/dist/src/connection/simulator/pings.js +3 -3
  43. package/dist/src/connection/simulator/pings.js.map +1 -1
  44. package/dist/src/connection/webrtc/NodeWebrtcConnection.d.ts +2 -1
  45. package/dist/src/connection/webrtc/NodeWebrtcConnection.js +13 -8
  46. package/dist/src/connection/webrtc/NodeWebrtcConnection.js.map +1 -1
  47. package/dist/src/connection/webrtc/WebrtcConnector.d.ts +2 -1
  48. package/dist/src/connection/webrtc/WebrtcConnector.js +28 -17
  49. package/dist/src/connection/webrtc/WebrtcConnector.js.map +1 -1
  50. package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.d.ts +3 -3
  51. package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js +4 -4
  52. package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js.map +1 -1
  53. package/dist/src/connection/webrtc/WebrtcConnectorRpcRemote.d.ts +1 -1
  54. package/dist/src/connection/webrtc/iceServerAsString.js +1 -2
  55. package/dist/src/connection/webrtc/iceServerAsString.js.map +1 -1
  56. package/dist/src/connection/websocket/AbstractWebsocketClientConnection.d.ts +0 -1
  57. package/dist/src/connection/websocket/WebsocketClientConnector.d.ts +1 -1
  58. package/dist/src/connection/websocket/WebsocketClientConnector.js +3 -3
  59. package/dist/src/connection/websocket/WebsocketClientConnector.js.map +1 -1
  60. package/dist/src/connection/websocket/WebsocketClientConnectorRpcLocal.d.ts +3 -4
  61. package/dist/src/connection/websocket/WebsocketClientConnectorRpcLocal.js +1 -1
  62. package/dist/src/connection/websocket/WebsocketClientConnectorRpcLocal.js.map +1 -1
  63. package/dist/src/connection/websocket/WebsocketClientConnectorRpcRemote.d.ts +1 -1
  64. package/dist/src/connection/websocket/WebsocketClientConnectorRpcRemote.js +1 -1
  65. package/dist/src/connection/websocket/WebsocketClientConnectorRpcRemote.js.map +1 -1
  66. package/dist/src/connection/websocket/WebsocketServerConnection.d.ts +0 -1
  67. package/dist/src/connection/websocket/WebsocketServerConnector.d.ts +1 -1
  68. package/dist/src/connection/websocket/WebsocketServerConnector.js +34 -24
  69. package/dist/src/connection/websocket/WebsocketServerConnector.js.map +1 -1
  70. package/dist/src/dht/DhtNode.d.ts +5 -2
  71. package/dist/src/dht/DhtNode.js +20 -8
  72. package/dist/src/dht/DhtNode.js.map +1 -1
  73. package/dist/src/dht/DhtNodeRpcLocal.d.ts +4 -4
  74. package/dist/src/dht/DhtNodeRpcLocal.js +3 -3
  75. package/dist/src/dht/DhtNodeRpcLocal.js.map +1 -1
  76. package/dist/src/dht/DhtNodeRpcRemote.d.ts +2 -2
  77. package/dist/src/dht/DhtNodeRpcRemote.js +3 -3
  78. package/dist/src/dht/DhtNodeRpcRemote.js.map +1 -1
  79. package/dist/src/dht/ExternalApiRpcLocal.d.ts +3 -3
  80. package/dist/src/dht/ExternalApiRpcLocal.js +3 -3
  81. package/dist/src/dht/ExternalApiRpcLocal.js.map +1 -1
  82. package/dist/src/dht/ExternalApiRpcRemote.d.ts +3 -3
  83. package/dist/src/dht/ExternalApiRpcRemote.js +2 -2
  84. package/dist/src/dht/ExternalApiRpcRemote.js.map +1 -1
  85. package/dist/src/dht/PeerManager.d.ts +3 -2
  86. package/dist/src/dht/PeerManager.js +12 -11
  87. package/dist/src/dht/PeerManager.js.map +1 -1
  88. package/dist/src/dht/contact/Contact.d.ts +1 -1
  89. package/dist/src/dht/contact/Contact.js +1 -1
  90. package/dist/src/dht/contact/Contact.js.map +1 -1
  91. package/dist/src/dht/contact/RingContactList.d.ts +1 -1
  92. package/dist/src/dht/contact/RingContactList.js +1 -1
  93. package/dist/src/dht/contact/RingContactList.js.map +1 -1
  94. package/dist/src/dht/contact/RpcRemote.d.ts +1 -1
  95. package/dist/src/dht/contact/SortedContactList.js +2 -2
  96. package/dist/src/dht/contact/SortedContactList.js.map +1 -1
  97. package/dist/src/dht/contact/ringIdentifiers.d.ts +1 -1
  98. package/dist/src/dht/discovery/DiscoverySession.d.ts +1 -2
  99. package/dist/src/dht/discovery/DiscoverySession.js +3 -3
  100. package/dist/src/dht/discovery/DiscoverySession.js.map +1 -1
  101. package/dist/src/dht/discovery/PeerDiscovery.d.ts +1 -2
  102. package/dist/src/dht/discovery/PeerDiscovery.js +7 -7
  103. package/dist/src/dht/discovery/PeerDiscovery.js.map +1 -1
  104. package/dist/src/dht/discovery/RingDiscoverySession.d.ts +0 -1
  105. package/dist/src/dht/discovery/RingDiscoverySession.js +1 -1
  106. package/dist/src/dht/discovery/RingDiscoverySession.js.map +1 -1
  107. package/dist/src/dht/recursive-operation/RecursiveOperationManager.d.ts +3 -3
  108. package/dist/src/dht/recursive-operation/RecursiveOperationManager.js +8 -8
  109. package/dist/src/dht/recursive-operation/RecursiveOperationManager.js.map +1 -1
  110. package/dist/src/dht/recursive-operation/RecursiveOperationRpcLocal.d.ts +2 -2
  111. package/dist/src/dht/recursive-operation/RecursiveOperationRpcLocal.js +2 -2
  112. package/dist/src/dht/recursive-operation/RecursiveOperationRpcLocal.js.map +1 -1
  113. package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.d.ts +2 -2
  114. package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.js +3 -3
  115. package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.js.map +1 -1
  116. package/dist/src/dht/recursive-operation/RecursiveOperationSession.d.ts +1 -1
  117. package/dist/src/dht/recursive-operation/RecursiveOperationSession.js +7 -7
  118. package/dist/src/dht/recursive-operation/RecursiveOperationSession.js.map +1 -1
  119. package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.d.ts +3 -3
  120. package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.js +1 -1
  121. package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.js.map +1 -1
  122. package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcRemote.d.ts +2 -2
  123. package/dist/src/dht/routing/DuplicateDetector.js.map +1 -1
  124. package/dist/src/dht/routing/Router.d.ts +4 -1
  125. package/dist/src/dht/routing/Router.js +17 -9
  126. package/dist/src/dht/routing/Router.js.map +1 -1
  127. package/dist/src/dht/routing/RouterRpcLocal.d.ts +2 -2
  128. package/dist/src/dht/routing/RouterRpcLocal.js +5 -5
  129. package/dist/src/dht/routing/RouterRpcLocal.js.map +1 -1
  130. package/dist/src/dht/routing/RouterRpcRemote.d.ts +2 -2
  131. package/dist/src/dht/routing/RouterRpcRemote.js +7 -7
  132. package/dist/src/dht/routing/RouterRpcRemote.js.map +1 -1
  133. package/dist/src/dht/routing/RoutingSession.d.ts +1 -1
  134. package/dist/src/dht/routing/RoutingSession.js +7 -8
  135. package/dist/src/dht/routing/RoutingSession.js.map +1 -1
  136. package/dist/src/dht/routing/RoutingTablesCache.d.ts +1 -1
  137. package/dist/src/dht/routing/getPreviousPeer.d.ts +1 -1
  138. package/dist/src/dht/store/LocalDataStore.d.ts +1 -1
  139. package/dist/src/dht/store/LocalDataStore.js +3 -3
  140. package/dist/src/dht/store/LocalDataStore.js.map +1 -1
  141. package/dist/src/dht/store/StoreManager.d.ts +3 -3
  142. package/dist/src/dht/store/StoreManager.js +8 -8
  143. package/dist/src/dht/store/StoreManager.js.map +1 -1
  144. package/dist/src/dht/store/StoreRpcLocal.d.ts +4 -4
  145. package/dist/src/dht/store/StoreRpcLocal.js +4 -4
  146. package/dist/src/dht/store/StoreRpcLocal.js.map +1 -1
  147. package/dist/src/dht/store/StoreRpcRemote.d.ts +3 -3
  148. package/dist/src/dht/store/StoreRpcRemote.js +7 -4
  149. package/dist/src/dht/store/StoreRpcRemote.js.map +1 -1
  150. package/dist/src/exports.d.ts +2 -2
  151. package/dist/src/exports.js +6 -6
  152. package/dist/src/exports.js.map +1 -1
  153. package/dist/src/helpers/AddressTools.js +2 -3
  154. package/dist/src/helpers/AddressTools.js.map +1 -1
  155. package/dist/src/helpers/Connectivity.d.ts +1 -1
  156. package/dist/src/helpers/Connectivity.js +1 -1
  157. package/dist/src/helpers/Connectivity.js.map +1 -1
  158. package/dist/src/helpers/createPeerDescriptor.d.ts +1 -1
  159. package/dist/src/helpers/createPeerDescriptor.js +2 -2
  160. package/dist/src/helpers/createPeerDescriptor.js.map +1 -1
  161. package/dist/src/helpers/createPeerDescriptorSignaturePayload.d.ts +1 -1
  162. package/dist/src/helpers/createPeerDescriptorSignaturePayload.js +1 -1
  163. package/dist/src/helpers/createPeerDescriptorSignaturePayload.js.map +1 -1
  164. package/dist/src/helpers/debugHelpers.js +2 -2
  165. package/dist/src/helpers/debugHelpers.js.map +1 -1
  166. package/dist/src/helpers/protoClasses.d.ts +1 -1
  167. package/dist/src/helpers/protoClasses.js +1 -1
  168. package/dist/src/helpers/protoClasses.js.map +1 -1
  169. package/dist/src/helpers/protoToString.js +1 -2
  170. package/dist/src/helpers/protoToString.js.map +1 -1
  171. package/dist/src/helpers/version.d.ts +1 -1
  172. package/dist/src/helpers/version.js +4 -4
  173. package/dist/src/helpers/version.js.map +1 -1
  174. package/dist/src/identifiers.d.ts +5 -5
  175. package/dist/src/identifiers.js +11 -11
  176. package/dist/src/identifiers.js.map +1 -1
  177. package/dist/src/rpc-protocol/DhtCallContext.d.ts +1 -1
  178. package/dist/src/rpc-protocol/DhtRpcOptions.d.ts +1 -1
  179. package/dist/src/transport/ITransport.d.ts +2 -1
  180. package/dist/src/transport/ListeningRpcCommunicator.d.ts +2 -1
  181. package/dist/src/transport/ListeningRpcCommunicator.js +13 -4
  182. package/dist/src/transport/ListeningRpcCommunicator.js.map +1 -1
  183. package/dist/src/transport/RoutingRpcCommunicator.d.ts +1 -1
  184. package/eslint.config.mjs +12 -0
  185. package/jest.config.ts +12 -0
  186. package/package.json +17 -18
  187. package/proto.sh +2 -3
  188. package/protos/DhtRpc.proto +11 -4
  189. package/src/connection/Connection.ts +1 -1
  190. package/src/connection/ConnectionLockRpcLocal.ts +16 -7
  191. package/src/connection/ConnectionLockRpcRemote.ts +18 -6
  192. package/src/connection/ConnectionLockStates.ts +18 -0
  193. package/src/connection/ConnectionManager.ts +93 -27
  194. package/src/connection/ConnectionsView.ts +1 -1
  195. package/src/connection/ConnectorFacade.ts +1 -1
  196. package/src/connection/Handshaker.ts +18 -14
  197. package/src/connection/ManagedConnection.ts +28 -3
  198. package/src/connection/PendingConnection.ts +1 -1
  199. package/src/connection/connectivityChecker.ts +6 -5
  200. package/src/connection/connectivityRequestHandler.ts +4 -4
  201. package/src/connection/simulator/Simulator.ts +8 -7
  202. package/src/connection/simulator/SimulatorConnection.ts +10 -10
  203. package/src/connection/simulator/SimulatorConnector.ts +5 -5
  204. package/src/connection/simulator/SimulatorTransport.ts +3 -2
  205. package/src/connection/simulator/pings.ts +1 -1
  206. package/src/connection/webrtc/BrowserWebrtcConnection.ts +10 -1
  207. package/src/connection/webrtc/NodeWebrtcConnection.ts +15 -11
  208. package/src/connection/webrtc/WebrtcConnector.ts +13 -11
  209. package/src/connection/webrtc/WebrtcConnectorRpcLocal.ts +8 -8
  210. package/src/connection/webrtc/WebrtcConnectorRpcRemote.ts +2 -2
  211. package/src/connection/websocket/WebsocketClientConnector.ts +5 -5
  212. package/src/connection/websocket/WebsocketClientConnectorRpcLocal.ts +5 -5
  213. package/src/connection/websocket/WebsocketClientConnectorRpcRemote.ts +4 -4
  214. package/src/connection/websocket/WebsocketServerConnector.ts +24 -20
  215. package/src/dht/DhtNode.ts +29 -11
  216. package/src/dht/DhtNodeRpcLocal.ts +8 -8
  217. package/src/dht/DhtNodeRpcRemote.ts +5 -5
  218. package/src/dht/ExternalApiRpcLocal.ts +8 -8
  219. package/src/dht/ExternalApiRpcRemote.ts +6 -6
  220. package/src/dht/PeerManager.ts +16 -14
  221. package/src/dht/contact/Contact.ts +3 -3
  222. package/src/dht/contact/RingContactList.ts +3 -3
  223. package/src/dht/contact/RpcRemote.ts +1 -1
  224. package/src/dht/contact/SortedContactList.ts +3 -3
  225. package/src/dht/contact/ringIdentifiers.ts +1 -1
  226. package/src/dht/discovery/DiscoverySession.ts +5 -5
  227. package/src/dht/discovery/PeerDiscovery.ts +12 -12
  228. package/src/dht/discovery/RingDiscoverySession.ts +3 -3
  229. package/src/dht/recursive-operation/RecursiveOperationManager.ts +10 -10
  230. package/src/dht/recursive-operation/RecursiveOperationRpcLocal.ts +4 -4
  231. package/src/dht/recursive-operation/RecursiveOperationRpcRemote.ts +6 -6
  232. package/src/dht/recursive-operation/RecursiveOperationSession.ts +8 -8
  233. package/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.ts +5 -5
  234. package/src/dht/recursive-operation/RecursiveOperationSessionRpcRemote.ts +2 -2
  235. package/src/dht/routing/DuplicateDetector.ts +1 -1
  236. package/src/dht/routing/Router.ts +19 -10
  237. package/src/dht/routing/RouterRpcLocal.ts +7 -7
  238. package/src/dht/routing/RouterRpcRemote.ts +9 -9
  239. package/src/dht/routing/RoutingSession.ts +9 -10
  240. package/src/dht/routing/RoutingTablesCache.ts +1 -1
  241. package/src/dht/routing/getPreviousPeer.ts +1 -1
  242. package/src/dht/store/LocalDataStore.ts +5 -5
  243. package/src/dht/store/StoreManager.ts +13 -13
  244. package/src/dht/store/StoreRpcLocal.ts +9 -9
  245. package/src/dht/store/StoreRpcRemote.ts +10 -7
  246. package/src/exports.ts +5 -5
  247. package/src/helpers/Connectivity.ts +1 -1
  248. package/src/helpers/createPeerDescriptor.ts +3 -3
  249. package/src/helpers/createPeerDescriptorSignaturePayload.ts +1 -1
  250. package/src/helpers/protoClasses.ts +2 -2
  251. package/src/helpers/version.ts +2 -2
  252. package/src/identifiers.ts +7 -7
  253. package/src/rpc-protocol/DhtCallContext.ts +1 -1
  254. package/src/rpc-protocol/DhtRpcOptions.ts +1 -1
  255. package/src/transport/ITransport.ts +2 -1
  256. package/src/transport/ListeningRpcCommunicator.ts +14 -6
  257. package/src/transport/RoutingRpcCommunicator.ts +2 -2
  258. package/test/benchmark/Find.test.ts +9 -9
  259. package/test/benchmark/KademliaCorrectness.test.ts +7 -7
  260. package/test/benchmark/RingCorrectness.test.ts +8 -8
  261. package/test/benchmark/SortedContactListBenchmark.test.ts +10 -10
  262. package/test/benchmark/hybrid-network-simulation/RingContactList.test.ts +3 -3
  263. package/test/end-to-end/Layer0Webrtc-Layer1.test.ts +6 -6
  264. package/test/end-to-end/Layer0Webrtc.test.ts +6 -6
  265. package/test/end-to-end/RecoveryFromFailedAutoCertification.test.ts +1 -1
  266. package/test/end-to-end/WebsocketConnectionRequest.test.ts +3 -3
  267. package/test/end-to-end/memory-leak.test.ts +6 -6
  268. package/test/integration/ConnectionLocking.test.ts +48 -37
  269. package/test/integration/ConnectionManager.test.ts +62 -6
  270. package/test/integration/ConnectivityChecking.test.ts +3 -2
  271. package/test/integration/DhtJoinPeerDiscovery.test.ts +2 -2
  272. package/test/integration/DhtNode.test.ts +6 -6
  273. package/test/integration/DhtNodeExternalAPI.test.ts +7 -7
  274. package/test/integration/DhtNodeRpcRemote.test.ts +9 -9
  275. package/test/integration/DhtRpc.test.ts +12 -13
  276. package/test/integration/Find.test.ts +5 -5
  277. package/test/integration/GeoIpConnectivityChecking.test.ts +8 -7
  278. package/test/integration/Layer1-scale.test.ts +3 -3
  279. package/test/integration/Mock-Layer1-Layer0.test.ts +6 -6
  280. package/test/integration/MultipleEntryPointJoining.test.ts +1 -1
  281. package/test/integration/ReplicateData.test.ts +10 -11
  282. package/test/integration/RouteMessage.test.ts +13 -13
  283. package/test/integration/RouterRpcRemote.test.ts +7 -7
  284. package/test/integration/SimultaneousConnections.test.ts +14 -13
  285. package/test/integration/Store.test.ts +9 -9
  286. package/test/integration/StoreAndDelete.test.ts +10 -10
  287. package/test/integration/StoreOnDhtWithThreeNodes.test.ts +10 -10
  288. package/test/integration/StoreOnDhtWithTwoNodes.test.ts +10 -10
  289. package/test/integration/StoreRpcRemote.test.ts +11 -11
  290. package/test/integration/WebrtcConnectionManagement.test.ts +4 -31
  291. package/test/integration/WebrtcConnectorRpc.test.ts +14 -14
  292. package/test/integration/Websocket.test.ts +0 -2
  293. package/test/integration/WebsocketClientConnectorRpc.test.ts +8 -8
  294. package/test/integration/WebsocketConnectionManagement.test.ts +11 -12
  295. package/test/integration/{rpc-connections-over-webrpc.test.ts → rpc-connections-over-webrtc.test.ts} +12 -46
  296. package/test/unit/AutoCertifierClientFacade.test.ts +6 -6
  297. package/test/unit/ConnectionManager.test.ts +4 -3
  298. package/test/unit/ConnectivityHelpers.test.ts +1 -1
  299. package/test/unit/DiscoverySession.test.ts +6 -6
  300. package/test/unit/Handshaker.test.ts +2 -2
  301. package/test/unit/ListeningRpcCommunicator.test.ts +52 -0
  302. package/test/unit/LocalDataStore.test.ts +21 -21
  303. package/test/unit/PeerManager.test.ts +15 -15
  304. package/test/unit/PendingConnection.test.ts +1 -1
  305. package/test/unit/ProtobufMessage.test.ts +1 -1
  306. package/test/unit/RandomContactList.test.ts +2 -2
  307. package/test/unit/RecursiveOperationManager.test.ts +3 -3
  308. package/test/unit/RecursiveOperationSession.test.ts +6 -6
  309. package/test/unit/Router.test.ts +6 -6
  310. package/test/unit/RoutingSession.test.ts +13 -6
  311. package/test/unit/SortedContactList.test.ts +8 -8
  312. package/test/unit/StoreManager.test.ts +12 -12
  313. package/test/unit/StoreRpcLocal.test.ts +9 -9
  314. package/test/unit/WebrtcConnection.test.ts +29 -0
  315. package/test/unit/WebsocketClientConnector.test.ts +1 -1
  316. package/test/unit/WebsocketServerConnector.test.ts +1 -1
  317. package/test/unit/connectivityRequestHandler.test.ts +6 -6
  318. package/test/unit/createPeerDescriptor.test.ts +4 -4
  319. package/test/unit/customMatchers.test.ts +18 -0
  320. package/test/unit/getClosestNodes.test.ts +5 -5
  321. package/test/unit/version.test.ts +9 -9
  322. package/test/utils/FakeConnectorFacade.ts +1 -1
  323. package/test/utils/FakeTransport.ts +12 -9
  324. package/test/utils/customMatchers.ts +9 -9
  325. package/test/utils/mock/MockConnectionsView.ts +1 -1
  326. package/test/utils/mock/MockRouter.ts +5 -1
  327. package/test/utils/mock/MockTransport.ts +6 -1
  328. package/test/utils/mock/mockDataEntry.ts +6 -6
  329. package/test/utils/topology.ts +3 -4
  330. package/test/utils/utils.ts +11 -11
  331. package/tsconfig.jest.json +2 -1
  332. package/tsconfig.node.json +1 -0
  333. package/.eslintignore +0 -5
  334. package/.eslintrc +0 -3
  335. package/dist/src/proto/google/protobuf/any.d.ts +0 -173
  336. package/dist/src/proto/google/protobuf/any.js +0 -155
  337. package/dist/src/proto/google/protobuf/any.js.map +0 -1
  338. package/dist/src/proto/google/protobuf/empty.d.ts +0 -32
  339. package/dist/src/proto/google/protobuf/empty.js +0 -32
  340. package/dist/src/proto/google/protobuf/empty.js.map +0 -1
  341. package/dist/src/proto/google/protobuf/timestamp.d.ts +0 -149
  342. package/dist/src/proto/google/protobuf/timestamp.js +0 -136
  343. package/dist/src/proto/google/protobuf/timestamp.js.map +0 -1
  344. package/dist/src/proto/packages/dht/protos/DhtRpc.client.d.ts +0 -352
  345. package/dist/src/proto/packages/dht/protos/DhtRpc.client.js +0 -278
  346. package/dist/src/proto/packages/dht/protos/DhtRpc.client.js.map +0 -1
  347. package/dist/src/proto/packages/dht/protos/DhtRpc.d.ts +0 -975
  348. package/dist/src/proto/packages/dht/protos/DhtRpc.js +0 -661
  349. package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +0 -1
  350. package/dist/src/proto/packages/dht/protos/DhtRpc.server.d.ts +0 -157
  351. package/dist/src/proto/packages/dht/protos/DhtRpc.server.js +0 -3
  352. package/dist/src/proto/packages/dht/protos/DhtRpc.server.js.map +0 -1
  353. package/dist/src/proto/packages/proto-rpc/protos/ProtoRpc.d.ts +0 -87
  354. package/dist/src/proto/packages/proto-rpc/protos/ProtoRpc.js +0 -66
  355. package/dist/src/proto/packages/proto-rpc/protos/ProtoRpc.js.map +0 -1
  356. package/dist/src/proto/tests.d.ts +0 -39
  357. package/dist/src/proto/tests.js +0 -34
  358. package/dist/src/proto/tests.js.map +0 -1
  359. package/jest.config.js +0 -5
  360. package/src/proto/google/protobuf/any.ts +0 -319
  361. package/src/proto/google/protobuf/empty.ts +0 -82
  362. package/src/proto/google/protobuf/timestamp.ts +0 -281
  363. package/src/proto/packages/dht/protos/DhtRpc.client.ts +0 -407
  364. package/src/proto/packages/dht/protos/DhtRpc.server.ts +0 -160
  365. package/src/proto/packages/dht/protos/DhtRpc.ts +0 -1244
  366. package/src/proto/packages/proto-rpc/protos/ProtoRpc.ts +0 -108
  367. package/src/proto/tests.ts +0 -52
  368. package/test/benchmark/any.test.ts +0 -28
  369. /package/{src/types/glogal.d.ts → test/types/global.d.ts} +0 -0
@@ -1,9 +1,9 @@
1
1
  import { areEqualBinaries, waitForEvent3 } from '@streamr/utils'
2
2
  import { ConnectionManager } from '../../src/connection/ConnectionManager'
3
3
  import { DhtNode } from '../../src/dht/DhtNode'
4
- import { PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
4
+ import { PeerDescriptor } from '../../generated/packages/dht/protos/DhtRpc'
5
5
  import { createMockPeerDescriptor } from '../utils/utils'
6
- import { getNodeIdFromPeerDescriptor } from '../../src/exports'
6
+ import { toNodeId } from '../../src/exports'
7
7
 
8
8
  describe('Layer0 with WebRTC connections', () => {
9
9
 
@@ -64,8 +64,8 @@ describe('Layer0 with WebRTC connections', () => {
64
64
  node2.joinDht([epPeerDescriptor]),
65
65
  node1.joinDht([epPeerDescriptor])
66
66
  ])
67
- const nodeId1 = getNodeIdFromPeerDescriptor(node1.getLocalPeerDescriptor())
68
- const nodeId2 = getNodeIdFromPeerDescriptor(node2.getLocalPeerDescriptor())
67
+ const nodeId1 = toNodeId(node1.getLocalPeerDescriptor())
68
+ const nodeId2 = toNodeId(node2.getLocalPeerDescriptor())
69
69
  expect((node1.getTransport() as ConnectionManager).hasConnection(nodeId2)).toEqual(true)
70
70
  expect((node2.getTransport() as ConnectionManager).hasConnection(nodeId1)).toEqual(true)
71
71
  }, 60000)
@@ -77,8 +77,8 @@ describe('Layer0 with WebRTC connections', () => {
77
77
  node3.joinDht([epPeerDescriptor]),
78
78
  node4.joinDht([epPeerDescriptor])
79
79
  ])
80
- const nodeId1 = getNodeIdFromPeerDescriptor(node1.getLocalPeerDescriptor())
81
- const nodeId2 = getNodeIdFromPeerDescriptor(node2.getLocalPeerDescriptor())
80
+ const nodeId1 = toNodeId(node1.getLocalPeerDescriptor())
81
+ const nodeId2 = toNodeId(node2.getLocalPeerDescriptor())
82
82
  expect((node1.getTransport() as ConnectionManager).hasConnection(nodeId2)).toEqual(true)
83
83
  expect((node2.getTransport() as ConnectionManager).hasConnection(nodeId1)).toEqual(true)
84
84
  })
@@ -1,5 +1,5 @@
1
1
  import { DhtNode } from '../../src/dht/DhtNode'
2
- import { PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
2
+ import { PeerDescriptor } from '../../generated/packages/dht/protos/DhtRpc'
3
3
  import os from 'os'
4
4
 
5
5
  describe('Failed autocertification', () => {
@@ -1,7 +1,7 @@
1
- import { PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
1
+ import { PeerDescriptor } from '../../generated/packages/dht/protos/DhtRpc'
2
2
  import { DhtNode } from '../../src/dht/DhtNode'
3
3
  import { ConnectionManager } from '../../src/connection/ConnectionManager'
4
- import { waitForCondition } from '@streamr/utils'
4
+ import { until } from '@streamr/utils'
5
5
  import { createMockPeerDescriptor } from '../utils/utils'
6
6
  import { areEqualPeerDescriptors } from '../../src/identifiers'
7
7
 
@@ -60,7 +60,7 @@ describe('Websocket IConnection Requests', () => {
60
60
  await node2.joinDht([epPeerDescriptor])
61
61
  await node1.joinDht([epPeerDescriptor])
62
62
 
63
- await waitForCondition(() => { return (connected1 && connected2) })
63
+ await until(() => { return (connected1 && connected2) })
64
64
 
65
65
  expect((node1.getTransport() as ConnectionManager).hasConnection(node2.getNodeId())).toEqual(true)
66
66
  expect((node2.getTransport() as ConnectionManager).hasConnection(node1.getNodeId())).toEqual(true)
@@ -1,10 +1,10 @@
1
1
  import LeakDetector from 'jest-leak-detector'
2
- import { waitForCondition } from '@streamr/utils'
2
+ import { until } from '@streamr/utils'
3
3
  import { DhtNode } from '../../src/dht/DhtNode'
4
- import { Message } from '../../src/proto/packages/dht/protos/DhtRpc'
5
- import { RpcMessage } from '../../src/proto/packages/proto-rpc/protos/ProtoRpc'
4
+ import { Message } from '../../generated/packages/dht/protos/DhtRpc'
5
+ import { RpcMessage } from '../../generated/packages/proto-rpc/protos/ProtoRpc'
6
6
  import { createMockPeerDescriptor } from '../utils/utils'
7
- import { getNodeIdFromPeerDescriptor } from '../../src/identifiers'
7
+ import { toNodeId } from '../../src/identifiers'
8
8
 
9
9
  const MESSAGE_ID = 'mock-message-id'
10
10
 
@@ -19,7 +19,7 @@ describe('memory leak', () => {
19
19
  }
20
20
  })
21
21
  let entryPoint: DhtNode | undefined = new DhtNode({
22
- nodeId: getNodeIdFromPeerDescriptor(entryPointDescriptor),
22
+ nodeId: toNodeId(entryPointDescriptor),
23
23
  websocketHost: entryPointDescriptor.websocket!.host,
24
24
  websocketPortRange: {
25
25
  min: entryPointDescriptor.websocket!.port,
@@ -55,7 +55,7 @@ describe('memory leak', () => {
55
55
  }
56
56
  }
57
57
  await sender.send(msg)
58
- await waitForCondition(() => receivedMessage !== undefined)
58
+ await until(() => receivedMessage !== undefined)
59
59
  expect(receivedMessage!.messageId).toEqual(MESSAGE_ID)
60
60
 
61
61
  await Promise.all([
@@ -1,13 +1,13 @@
1
- import { MetricsContext, waitForCondition } from '@streamr/utils'
1
+ import { MetricsContext, until } from '@streamr/utils'
2
2
  import { ConnectionManager } from '../../src/connection/ConnectionManager'
3
3
  import { DefaultConnectorFacade } from '../../src/connection/ConnectorFacade'
4
4
  import { LatencyType, Simulator } from '../../src/connection/simulator/Simulator'
5
5
  import { SimulatorTransport } from '../../src/connection/simulator/SimulatorTransport'
6
6
  import { ITransport } from '../../src/transport/ITransport'
7
- import { PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
7
+ import { PeerDescriptor } from '../../generated/packages/dht/protos/DhtRpc'
8
8
  import { getRandomRegion } from '../../dist/src/connection/simulator/pings'
9
9
  import { createMockPeerDescriptor } from '../utils/utils'
10
- import { getNodeIdFromPeerDescriptor } from '../../src/identifiers'
10
+ import { toNodeId } from '../../src/identifiers'
11
11
 
12
12
  const createConnectionManager = (localPeerDescriptor: PeerDescriptor, transport: ITransport) => {
13
13
  return new ConnectionManager({
@@ -15,7 +15,8 @@ const createConnectionManager = (localPeerDescriptor: PeerDescriptor, transport:
15
15
  transport,
16
16
  createLocalPeerDescriptor: async () => localPeerDescriptor
17
17
  }),
18
- metricsContext: new MetricsContext()
18
+ metricsContext: new MetricsContext(),
19
+ allowIncomingPrivateConnections: true
19
20
  })
20
21
  }
21
22
 
@@ -56,10 +57,11 @@ describe('Connection Locking', () => {
56
57
  })
57
58
 
58
59
  it('can lock connections', async () => {
59
- const nodeId1 = getNodeIdFromPeerDescriptor(mockPeerDescriptor1)
60
- const nodeId2 = getNodeIdFromPeerDescriptor(mockPeerDescriptor2)
60
+ const nodeId1 = toNodeId(mockPeerDescriptor1)
61
+ const nodeId2 = toNodeId(mockPeerDescriptor2)
61
62
  await Promise.all([
62
- waitForCondition(() => connectionManager2.hasRemoteLockedConnection(nodeId1)),
63
+ until(() => connectionManager2.hasRemoteLockedConnection(nodeId1)),
64
+ // eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
63
65
  connectionManager1.lockConnection(mockPeerDescriptor2, 'testLock')
64
66
  ])
65
67
  expect(connectionManager1.hasConnection(nodeId2)).toEqual(true)
@@ -68,14 +70,16 @@ describe('Connection Locking', () => {
68
70
  })
69
71
 
70
72
  it('Multiple services on the same peer', async () => {
71
- const nodeId1 = getNodeIdFromPeerDescriptor(mockPeerDescriptor1)
72
- const nodeId2 = getNodeIdFromPeerDescriptor(mockPeerDescriptor2)
73
+ const nodeId1 = toNodeId(mockPeerDescriptor1)
74
+ const nodeId2 = toNodeId(mockPeerDescriptor2)
73
75
  await Promise.all([
74
- waitForCondition(() => connectionManager2.hasRemoteLockedConnection(nodeId1)),
76
+ until(() => connectionManager2.hasRemoteLockedConnection(nodeId1)),
77
+ // eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
75
78
  connectionManager1.lockConnection(mockPeerDescriptor2, 'testLock1')
76
79
  ])
77
80
  await Promise.all([
78
- waitForCondition(() => connectionManager2.hasRemoteLockedConnection(nodeId1)),
81
+ until(() => connectionManager2.hasRemoteLockedConnection(nodeId1)),
82
+ // eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
79
83
  connectionManager1.lockConnection(mockPeerDescriptor2, 'testLock2')
80
84
  ])
81
85
  expect(connectionManager1.hasConnection(nodeId2)).toEqual(true)
@@ -84,35 +88,38 @@ describe('Connection Locking', () => {
84
88
  })
85
89
 
86
90
  it('can unlock connections', async () => {
87
- const nodeId1 = getNodeIdFromPeerDescriptor(mockPeerDescriptor1)
88
- const nodeId2 = getNodeIdFromPeerDescriptor(mockPeerDescriptor2)
91
+ const nodeId1 = toNodeId(mockPeerDescriptor1)
92
+ const nodeId2 = toNodeId(mockPeerDescriptor2)
89
93
  await Promise.all([
90
- waitForCondition(() => connectionManager2.hasRemoteLockedConnection(nodeId1)),
94
+ until(() => connectionManager2.hasRemoteLockedConnection(nodeId1)),
95
+ // eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
91
96
  connectionManager1.lockConnection(mockPeerDescriptor2, 'testLock')
92
97
  ])
93
- expect(connectionManager1.hasConnection(nodeId2))
98
+ expect(connectionManager1.hasConnection(nodeId2)).toEqual(true)
94
99
  expect(connectionManager2.hasLocalLockedConnection(nodeId2)).toEqual(false)
95
100
  expect(connectionManager2.hasRemoteLockedConnection(nodeId1)).toEqual(true)
96
101
 
97
102
  connectionManager1.unlockConnection(mockPeerDescriptor2, 'testLock')
98
103
  expect(connectionManager1.hasLocalLockedConnection(nodeId2)).toEqual(false)
99
- await waitForCondition(() => connectionManager2.hasRemoteLockedConnection(nodeId1) === false)
104
+ await until(() => connectionManager2.hasRemoteLockedConnection(nodeId1) === false)
100
105
  expect(connectionManager1.hasConnection(nodeId1)).toEqual(false)
101
106
  })
102
107
 
103
108
  it('unlocking multiple services', async () => {
104
- const nodeId1 = getNodeIdFromPeerDescriptor(mockPeerDescriptor1)
105
- const nodeId2 = getNodeIdFromPeerDescriptor(mockPeerDescriptor2)
109
+ const nodeId1 = toNodeId(mockPeerDescriptor1)
110
+ const nodeId2 = toNodeId(mockPeerDescriptor2)
106
111
  await Promise.all([
107
- waitForCondition(() => connectionManager2.hasRemoteLockedConnection(nodeId1)),
112
+ until(() => connectionManager2.hasRemoteLockedConnection(nodeId1)),
113
+ // eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
108
114
  connectionManager1.lockConnection(mockPeerDescriptor2, 'testLock1')
109
115
  ])
110
116
  await Promise.all([
111
- waitForCondition(() => connectionManager2.hasRemoteLockedConnection(nodeId1)),
117
+ until(() => connectionManager2.hasRemoteLockedConnection(nodeId1)),
118
+ // eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
112
119
  connectionManager1.lockConnection(mockPeerDescriptor2, 'testLock2')
113
120
  ])
114
121
 
115
- expect(connectionManager1.hasConnection(nodeId2))
122
+ expect(connectionManager1.hasConnection(nodeId2)).toEqual(true)
116
123
  expect(connectionManager2.hasLocalLockedConnection(nodeId1)).toEqual(false)
117
124
 
118
125
  connectionManager1.unlockConnection(mockPeerDescriptor2, 'testLock1')
@@ -124,20 +131,22 @@ describe('Connection Locking', () => {
124
131
  })
125
132
 
126
133
  it('maintains connection if both sides initially lock and then one end unlocks', async () => {
127
- const nodeId1 = getNodeIdFromPeerDescriptor(mockPeerDescriptor1)
128
- const nodeId2 = getNodeIdFromPeerDescriptor(mockPeerDescriptor2)
134
+ const nodeId1 = toNodeId(mockPeerDescriptor1)
135
+ const nodeId2 = toNodeId(mockPeerDescriptor2)
129
136
  await Promise.all([
130
- waitForCondition(() => connectionManager2.hasRemoteLockedConnection(nodeId1)),
131
- waitForCondition(() => connectionManager1.hasRemoteLockedConnection(nodeId2)),
137
+ until(() => connectionManager2.hasRemoteLockedConnection(nodeId1)),
138
+ until(() => connectionManager1.hasRemoteLockedConnection(nodeId2)),
139
+ // eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
132
140
  connectionManager1.lockConnection(mockPeerDescriptor2, 'testLock1'),
141
+ // eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
133
142
  connectionManager2.lockConnection(mockPeerDescriptor1, 'testLock1')
134
143
  ])
135
144
 
136
- expect(connectionManager1.hasLocalLockedConnection(nodeId2))
137
- expect(connectionManager2.hasLocalLockedConnection(nodeId1))
145
+ expect(connectionManager1.hasLocalLockedConnection(nodeId2)).toEqual(true)
146
+ expect(connectionManager2.hasLocalLockedConnection(nodeId1)).toEqual(true)
138
147
 
139
148
  connectionManager1.unlockConnection(mockPeerDescriptor2, 'testLock1')
140
- await waitForCondition(() =>
149
+ await until(() =>
141
150
  connectionManager1.hasRemoteLockedConnection(nodeId2)
142
151
  && !connectionManager1.hasLocalLockedConnection(nodeId2)
143
152
  && !connectionManager2.hasRemoteLockedConnection(nodeId1)
@@ -149,31 +158,33 @@ describe('Connection Locking', () => {
149
158
  })
150
159
 
151
160
  it('unlocks after graceful disconnect', async () => {
152
- const nodeId1 = getNodeIdFromPeerDescriptor(mockPeerDescriptor1)
153
- const nodeId2 = getNodeIdFromPeerDescriptor(mockPeerDescriptor2)
161
+ const nodeId1 = toNodeId(mockPeerDescriptor1)
162
+ const nodeId2 = toNodeId(mockPeerDescriptor2)
154
163
  await Promise.all([
155
- waitForCondition(() => connectionManager2.hasRemoteLockedConnection(nodeId1)),
156
- waitForCondition(() => connectionManager1.hasRemoteLockedConnection(nodeId2)),
164
+ until(() => connectionManager2.hasRemoteLockedConnection(nodeId1)),
165
+ until(() => connectionManager1.hasRemoteLockedConnection(nodeId2)),
166
+ // eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
157
167
  connectionManager1.lockConnection(mockPeerDescriptor2, 'testLock1'),
168
+ // eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
158
169
  connectionManager2.lockConnection(mockPeerDescriptor1, 'testLock1')
159
170
  ])
160
- expect(connectionManager1.hasConnection(nodeId2))
171
+ expect(connectionManager1.hasConnection(nodeId2)).toEqual(true)
161
172
  expect(connectionManager2.hasLocalLockedConnection(nodeId1)).toEqual(true)
162
173
  expect(connectionManager2.hasRemoteLockedConnection(nodeId1)).toEqual(true)
163
174
 
164
175
  //@ts-expect-error private field
165
176
  await connectionManager1.gracefullyDisconnectAsync(mockPeerDescriptor2)
166
177
 
167
- await waitForCondition(() =>
178
+ await until(() =>
168
179
  !connectionManager1.hasRemoteLockedConnection(nodeId2)
169
180
  && !connectionManager1.hasLocalLockedConnection(nodeId2)
170
181
  )
171
- await waitForCondition(() =>
182
+ await until(() =>
172
183
  !connectionManager2.hasRemoteLockedConnection(nodeId1)
173
184
  && !connectionManager2.hasLocalLockedConnection(nodeId1)
174
185
  )
175
- await waitForCondition(() => !connectionManager2.hasConnection(nodeId1))
176
- await waitForCondition(() => !connectionManager1.hasConnection(nodeId2))
186
+ await until(() => !connectionManager2.hasConnection(nodeId1))
187
+ await until(() => !connectionManager1.hasConnection(nodeId2))
177
188
 
178
189
  expect(connectionManager1.hasConnection(nodeId2)).toEqual(false)
179
190
  expect(connectionManager2.hasConnection(nodeId1)).toEqual(false)
@@ -1,13 +1,13 @@
1
- import { Logger, MetricsContext, waitForEvent3 } from '@streamr/utils'
1
+ import { Logger, MetricsContext, until, waitForEvent3 } from '@streamr/utils'
2
2
  import { MarkOptional } from 'ts-essentials'
3
3
  import { ConnectionManager } from '../../src/connection/ConnectionManager'
4
4
  import { DefaultConnectorFacade, DefaultConnectorFacadeOptions } from '../../src/connection/ConnectorFacade'
5
5
  import { Simulator } from '../../src/connection/simulator/Simulator'
6
6
  import { SimulatorTransport } from '../../src/connection/simulator/SimulatorTransport'
7
7
  import { createPeerDescriptor } from '../../src/helpers/createPeerDescriptor'
8
- import { createRandomDhtAddress, getRawFromDhtAddress } from '../../src/identifiers'
9
- import { ConnectivityResponse, Message, NodeType, PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
10
- import { RpcMessage } from '../../src/proto/packages/proto-rpc/protos/ProtoRpc'
8
+ import { randomDhtAddress, toDhtAddressRaw } from '../../src/identifiers'
9
+ import { ConnectivityResponse, Message, NodeType, PeerDescriptor } from '../../generated/packages/dht/protos/DhtRpc'
10
+ import { RpcMessage } from '../../generated/packages/proto-rpc/protos/ProtoRpc'
11
11
  import { TransportEvents } from '../../src/transport/ITransport'
12
12
  import { createMockPeerDescriptor } from '../utils/utils'
13
13
  import { getRandomRegion } from '../../src/connection/simulator/pings'
@@ -37,7 +37,8 @@ describe('ConnectionManager', () => {
37
37
  websocketServerEnableTls: false,
38
38
  ...opts
39
39
  }),
40
- metricsContext: new MetricsContext()
40
+ metricsContext: new MetricsContext(),
41
+ allowIncomingPrivateConnections: true
41
42
  })
42
43
  }
43
44
 
@@ -383,7 +384,7 @@ describe('ConnectionManager', () => {
383
384
  messageId: '1',
384
385
  targetDescriptor: {
385
386
  // This is not the correct nodeId of peerDescriptor2
386
- nodeId: getRawFromDhtAddress(createRandomDhtAddress()),
387
+ nodeId: toDhtAddressRaw(randomDhtAddress()),
387
388
  type: NodeType.NODEJS,
388
389
  websocket: peerDescriptor2.websocket
389
390
  },
@@ -469,4 +470,59 @@ describe('ConnectionManager', () => {
469
470
  await connectionManager2.stop()
470
471
  })
471
472
 
473
+ it('private connections', async () => {
474
+ const connectionManager1 = createConnectionManager({
475
+ transport: mockTransport,
476
+ websocketHost: '127.0.0.1',
477
+ websocketServerEnableTls: false,
478
+ websocketPortRange: { min: 10009, max: 10009 }
479
+ })
480
+
481
+ await connectionManager1.start()
482
+
483
+ const connectionManager2 = createConnectionManager({
484
+ transport: mockTransport,
485
+ websocketHost: '127.0.0.1',
486
+ websocketServerEnableTls: false,
487
+ websocketPortRange: { min: 10010, max: 100010 }
488
+ })
489
+
490
+ await connectionManager2.start()
491
+
492
+ const msg: Message = {
493
+ serviceId: SERVICE_ID,
494
+ messageId: '1',
495
+ body: {
496
+ oneofKind: 'rpcMessage',
497
+ rpcMessage: RpcMessage.create()
498
+ },
499
+ targetDescriptor: connectionManager1.getLocalPeerDescriptor()
500
+ }
501
+
502
+ const connectedPromise1 = new Promise<void>((resolve, _reject) => {
503
+ connectionManager1.on('connected', () => {
504
+ resolve()
505
+ })
506
+ })
507
+
508
+ const connectedPromise2 = new Promise<void>((resolve, _reject) => {
509
+ connectionManager2.on('connected', () => {
510
+ resolve()
511
+ })
512
+ })
513
+ await Promise.all([connectedPromise1, connectedPromise2, connectionManager2.send(msg)])
514
+
515
+ await connectionManager1.enablePrivateClientMode()
516
+ await until(() => connectionManager2.getConnections().length === 0)
517
+ expect(connectionManager1.getConnections().length).toEqual(1)
518
+
519
+ await connectionManager1.disablePrivateClientMode()
520
+ await until(() => connectionManager2.getConnections().length === 1)
521
+ expect(connectionManager1.getConnections().length).toEqual(1)
522
+
523
+ await connectionManager1.stop()
524
+ await connectionManager2.stop()
525
+
526
+ })
527
+
472
528
  })
@@ -30,7 +30,8 @@ describe('ConnectivityChecking', () => {
30
30
  websocketServerEnableTls: false,
31
31
  transport: new MockTransport()
32
32
  }),
33
- metricsContext: new MetricsContext()
33
+ metricsContext: new MetricsContext(),
34
+ allowIncomingPrivateConnections: false
34
35
  })
35
36
  await server.start()
36
37
  })
@@ -47,6 +48,6 @@ describe('ConnectivityChecking', () => {
47
48
  allowSelfSignedCertificate: false
48
49
  }
49
50
  const response = await sendConnectivityRequest(request, server.getLocalPeerDescriptor())
50
- expect(response.version).toEqual(LOCAL_PROTOCOL_VERSION)
51
+ expect(response.protocolVersion).toEqual(LOCAL_PROTOCOL_VERSION)
51
52
  })
52
53
  })
@@ -1,7 +1,7 @@
1
1
  import { LatencyType, Simulator } from '../../src/connection/simulator/Simulator'
2
2
  import { getRandomRegion } from '../../src/connection/simulator/pings'
3
3
  import { DhtNode } from '../../src/dht/DhtNode'
4
- import { getDhtAddressFromRaw } from '../../src/identifiers'
4
+ import { toDhtAddress } from '../../src/identifiers'
5
5
  import { createMockConnectionDhtNode, createMockPeerDescriptor } from '../utils/utils'
6
6
 
7
7
  const NUM_OF_NODES_PER_KBUCKET = 8
@@ -11,7 +11,7 @@ const runTest = async (latencyType: LatencyType) => {
11
11
  const entrypointDescriptor = createMockPeerDescriptor({
12
12
  region: getRandomRegion()
13
13
  })
14
- const entryPoint = await createMockConnectionDhtNode(simulator, getDhtAddressFromRaw(entrypointDescriptor.nodeId), NUM_OF_NODES_PER_KBUCKET)
14
+ const entryPoint = await createMockConnectionDhtNode(simulator, toDhtAddress(entrypointDescriptor.nodeId), NUM_OF_NODES_PER_KBUCKET)
15
15
  const nodes: DhtNode[] = []
16
16
  for (let i = 1; i < 100; i++) {
17
17
  const node = await createMockConnectionDhtNode(simulator, undefined, NUM_OF_NODES_PER_KBUCKET)
@@ -1,8 +1,8 @@
1
- import { waitForCondition } from '@streamr/utils'
1
+ import { until } from '@streamr/utils'
2
2
  import { range, without } from 'lodash'
3
3
  import { DhtNodeRpcLocal } from '../../src/dht/DhtNodeRpcLocal'
4
- import { DhtNode, ListeningRpcCommunicator, getNodeIdFromPeerDescriptor } from '../../src/exports'
5
- import { ClosestPeersRequest, ClosestPeersResponse, PeerDescriptor, PingRequest, PingResponse } from '../../src/proto/packages/dht/protos/DhtRpc'
4
+ import { DhtNode, ListeningRpcCommunicator, toNodeId } from '../../src/exports'
5
+ import { ClosestPeersRequest, ClosestPeersResponse, PeerDescriptor, PingRequest, PingResponse } from '../../generated/packages/dht/protos/DhtRpc'
6
6
  import { FakeEnvironment } from '../utils/FakeTransport'
7
7
  import { createMockPeerDescriptor } from '../utils/utils'
8
8
 
@@ -58,9 +58,9 @@ describe('DhtNode', () => {
58
58
  await localNode.joinDht([entryPointPeerDescriptor])
59
59
  await localNode.waitForNetworkConnectivity()
60
60
 
61
- await waitForCondition(() => localNode.getNeighborCount() === otherPeerDescriptors.length + 1)
62
- const expectedNodeIds = without(getAllPeerDescriptors(), localPeerDescriptor).map((n) => getNodeIdFromPeerDescriptor(n))
63
- const actualNodeIds = localNode.getClosestContacts().map((n) => getNodeIdFromPeerDescriptor(n))
61
+ await until(() => localNode.getNeighborCount() === otherPeerDescriptors.length + 1)
62
+ const expectedNodeIds = without(getAllPeerDescriptors(), localPeerDescriptor).map((n) => toNodeId(n))
63
+ const actualNodeIds = localNode.getClosestContacts().map((n) => toNodeId(n))
64
64
  expect(actualNodeIds).toIncludeSameMembers(expectedNodeIds)
65
65
  })
66
66
  })
@@ -1,6 +1,6 @@
1
1
  import { LatencyType, Simulator } from '../../src/connection/simulator/Simulator'
2
2
  import { DhtNode } from '../../src/dht/DhtNode'
3
- import { createRandomDhtAddress, getDhtAddressFromRaw, getNodeIdFromPeerDescriptor } from '../../src/identifiers'
3
+ import { randomDhtAddress, toDhtAddress, toNodeId } from '../../src/identifiers'
4
4
  import { createMockDataEntry, expectEqualData } from '../utils/mock/mockDataEntry'
5
5
  import { createMockConnectionDhtNode } from '../utils/utils'
6
6
 
@@ -27,22 +27,22 @@ describe('DhtNodeExternalApi', () => {
27
27
 
28
28
  it('fetch data happy path', async () => {
29
29
  const entry = createMockDataEntry()
30
- await dhtNode1.storeDataToDht(getDhtAddressFromRaw(entry.key), entry.data!)
31
- const foundData = await remote.fetchDataFromDhtViaPeer(getDhtAddressFromRaw(entry.key), dhtNode1.getLocalPeerDescriptor())
30
+ await dhtNode1.storeDataToDht(toDhtAddress(entry.key), entry.data!)
31
+ const foundData = await remote.fetchDataFromDhtViaPeer(toDhtAddress(entry.key), dhtNode1.getLocalPeerDescriptor())
32
32
  expectEqualData(foundData[0], entry)
33
33
  })
34
34
 
35
35
  it('fetch data returns empty array if no data found', async () => {
36
- const foundData = await remote.fetchDataFromDhtViaPeer(createRandomDhtAddress(), dhtNode1.getLocalPeerDescriptor())
36
+ const foundData = await remote.fetchDataFromDhtViaPeer(randomDhtAddress(), dhtNode1.getLocalPeerDescriptor())
37
37
  expect(foundData).toEqual([])
38
38
  })
39
39
 
40
40
  it('external store data happy path', async () => {
41
41
  const entry = createMockDataEntry()
42
- await remote.storeDataToDhtViaPeer(getDhtAddressFromRaw(entry.key), entry.data!, dhtNode1.getLocalPeerDescriptor())
43
- const foundData = await remote.fetchDataFromDhtViaPeer(getDhtAddressFromRaw(entry.key), dhtNode1.getLocalPeerDescriptor())
42
+ await remote.storeDataToDhtViaPeer(toDhtAddress(entry.key), entry.data!, dhtNode1.getLocalPeerDescriptor())
43
+ const foundData = await remote.fetchDataFromDhtViaPeer(toDhtAddress(entry.key), dhtNode1.getLocalPeerDescriptor())
44
44
  expectEqualData(foundData[0], entry)
45
- expect(getDhtAddressFromRaw(foundData[0].creator)).toEqual(getNodeIdFromPeerDescriptor(remote.getLocalPeerDescriptor()))
45
+ expect(toDhtAddress(foundData[0].creator)).toEqual(toNodeId(remote.getLocalPeerDescriptor()))
46
46
  })
47
47
 
48
48
  })
@@ -6,10 +6,10 @@ import {
6
6
  ClosestPeersResponse,
7
7
  PingRequest,
8
8
  PingResponse
9
- } from '../../src/proto/packages/dht/protos/DhtRpc'
10
- import { RpcMessage } from '../../src/proto/packages/proto-rpc/protos/ProtoRpc'
9
+ } from '../../generated/packages/dht/protos/DhtRpc'
10
+ import { RpcMessage } from '../../generated/packages/proto-rpc/protos/ProtoRpc'
11
11
  import { DhtCallContext } from '../../src/rpc-protocol/DhtCallContext'
12
- import { getNodeIdFromPeerDescriptor } from '../../src/identifiers'
12
+ import { toNodeId } from '../../src/identifiers'
13
13
 
14
14
  const SERVICE_ID = 'test'
15
15
 
@@ -27,11 +27,11 @@ describe('DhtNodeRpcRemote', () => {
27
27
  serverRpcCommunicator = new RpcCommunicator()
28
28
  serverRpcCommunicator.registerRpcMethod(ClosestPeersRequest, ClosestPeersResponse, 'getClosestPeers', mockDhtRpc.getClosestPeers)
29
29
  serverRpcCommunicator.registerRpcMethod(PingRequest, PingResponse, 'ping', mockDhtRpc.ping)
30
- clientRpcCommunicator.on('outgoingMessage', (message: RpcMessage) => {
31
- serverRpcCommunicator.handleIncomingMessage(message)
30
+ clientRpcCommunicator.setOutgoingMessageListener(async (message: RpcMessage) => {
31
+ serverRpcCommunicator.handleIncomingMessage(message, new DhtCallContext())
32
32
  })
33
- serverRpcCommunicator.on('outgoingMessage', (message: RpcMessage) => {
34
- clientRpcCommunicator.handleIncomingMessage(message)
33
+ serverRpcCommunicator.setOutgoingMessageListener(async (message: RpcMessage) => {
34
+ clientRpcCommunicator.handleIncomingMessage(message, new DhtCallContext())
35
35
  })
36
36
  rpcRemote = new DhtNodeRpcRemote(clientPeerDescriptor, serverPeerDescriptor, SERVICE_ID, clientRpcCommunicator)
37
37
  })
@@ -47,7 +47,7 @@ describe('DhtNodeRpcRemote', () => {
47
47
  })
48
48
 
49
49
  it('getClosestPeers happy path', async () => {
50
- const neighbors = await rpcRemote.getClosestPeers(getNodeIdFromPeerDescriptor(clientPeerDescriptor))
50
+ const neighbors = await rpcRemote.getClosestPeers(toNodeId(clientPeerDescriptor))
51
51
  expect(neighbors.length).toEqual(createMockPeers().length)
52
52
  })
53
53
 
@@ -59,7 +59,7 @@ describe('DhtNodeRpcRemote', () => {
59
59
 
60
60
  it('getClosestPeers error path', async () => {
61
61
  serverRpcCommunicator.registerRpcMethod(ClosestPeersRequest, ClosestPeersResponse, 'getClosestPeers', mockDhtRpc.throwGetClosestPeersError)
62
- await expect(rpcRemote.getClosestPeers(getNodeIdFromPeerDescriptor(clientPeerDescriptor)))
62
+ await expect(rpcRemote.getClosestPeers(toNodeId(clientPeerDescriptor)))
63
63
  .rejects.toThrow('Closest peers error')
64
64
  })
65
65
 
@@ -1,10 +1,10 @@
1
1
  import { createMockDhtRpc, createMockPeerDescriptor, createMockPeers } from '../utils/utils'
2
2
  import { ProtoRpcClient, RpcCommunicator, RpcError, toProtoRpcClient } from '@streamr/proto-rpc'
3
- import { DhtNodeRpcClient } from '../../src/proto/packages/dht/protos/DhtRpc.client'
4
- import { ClosestPeersRequest, ClosestPeersResponse } from '../../src/proto/packages/dht/protos/DhtRpc'
3
+ import { DhtNodeRpcClient } from '../../generated/packages/dht/protos/DhtRpc.client'
4
+ import { ClosestPeersRequest, ClosestPeersResponse } from '../../generated/packages/dht/protos/DhtRpc'
5
5
  import { wait } from '@streamr/utils'
6
- import { RpcMessage } from '../../src/proto/packages/proto-rpc/protos/ProtoRpc'
7
- import { getNodeIdFromPeerDescriptor } from '../../src/identifiers'
6
+ import { RpcMessage } from '../../generated/packages/proto-rpc/protos/ProtoRpc'
7
+ import { toNodeId } from '../../src/identifiers'
8
8
  import { DhtCallContext } from '../../src/rpc-protocol/DhtCallContext'
9
9
 
10
10
  describe('DhtRpc', () => {
@@ -18,8 +18,8 @@ describe('DhtRpc', () => {
18
18
  const neighbors = createMockPeers()
19
19
  const mockDhtRpc = createMockDhtRpc(neighbors)
20
20
 
21
- const outgoingListener2 = (message: RpcMessage) => {
22
- rpcCommunicator1.handleIncomingMessage(message)
21
+ const outgoingListener2 = async (message: RpcMessage) => {
22
+ rpcCommunicator1.handleIncomingMessage(message, new DhtCallContext())
23
23
  }
24
24
 
25
25
  beforeEach(() => {
@@ -29,11 +29,11 @@ describe('DhtRpc', () => {
29
29
  rpcCommunicator2 = new RpcCommunicator()
30
30
  rpcCommunicator2.registerRpcMethod(ClosestPeersRequest, ClosestPeersResponse, 'getClosestPeers', mockDhtRpc.getClosestPeers)
31
31
 
32
- rpcCommunicator1.on('outgoingMessage', (message: RpcMessage) => {
33
- rpcCommunicator2.handleIncomingMessage(message)
32
+ rpcCommunicator1.setOutgoingMessageListener(async (message: RpcMessage) => {
33
+ rpcCommunicator2.handleIncomingMessage(message, new DhtCallContext())
34
34
  })
35
35
 
36
- rpcCommunicator2.on('outgoingMessage', outgoingListener2)
36
+ rpcCommunicator2.setOutgoingMessageListener(outgoingListener2)
37
37
 
38
38
  client1 = toProtoRpcClient(new DhtNodeRpcClient(rpcCommunicator1.getRpcClientTransport()))
39
39
  client2 = toProtoRpcClient(new DhtNodeRpcClient(rpcCommunicator1.getRpcClientTransport()))
@@ -53,7 +53,7 @@ describe('DhtRpc', () => {
53
53
  }
54
54
  )
55
55
  const res1 = await response1
56
- expect(res1.peers.map((p) => getNodeIdFromPeerDescriptor(p))).toEqual(neighbors.map((n) => getNodeIdFromPeerDescriptor(n)))
56
+ expect(res1.peers.map((p) => toNodeId(p))).toEqual(neighbors.map((n) => toNodeId(n)))
57
57
 
58
58
  const response2 = client2.getClosestPeers(
59
59
  { nodeId: peerDescriptor2.nodeId, requestId: '1' },
@@ -63,12 +63,11 @@ describe('DhtRpc', () => {
63
63
  }
64
64
  )
65
65
  const res2 = await response2
66
- expect(res2.peers.map((p) => getNodeIdFromPeerDescriptor(p))).toEqual(neighbors.map((n) => getNodeIdFromPeerDescriptor(n)))
66
+ expect(res2.peers.map((p) => toNodeId(p))).toEqual(neighbors.map((n) => toNodeId(n)))
67
67
  })
68
68
 
69
69
  it('Default RPC timeout, client side', async () => {
70
- rpcCommunicator2.off('outgoingMessage', outgoingListener2)
71
- rpcCommunicator2.on('outgoingMessage', async () => {
70
+ rpcCommunicator2.setOutgoingMessageListener(async () => {
72
71
  await wait(3000)
73
72
  })
74
73
  const response2 = client2.getClosestPeers(
@@ -1,8 +1,8 @@
1
1
  import { LatencyType, Simulator } from '../../src/connection/simulator/Simulator'
2
2
  import { DhtNode } from '../../src/dht/DhtNode'
3
- import { PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
3
+ import { PeerDescriptor } from '../../generated/packages/dht/protos/DhtRpc'
4
4
  import { createMockConnectionDhtNode, waitForStableTopology } from '../utils/utils'
5
- import { getDhtAddressFromRaw, getNodeIdFromPeerDescriptor, getRawFromDhtAddress } from '../../src/identifiers'
5
+ import { toDhtAddress, toNodeId, toDhtAddressRaw } from '../../src/identifiers'
6
6
 
7
7
  const NUM_NODES = 100
8
8
  const K = 8
@@ -36,10 +36,10 @@ describe('Find correctness', () => {
36
36
  })
37
37
 
38
38
  it('Entrypoint can find a node from the network (exact match)', async () => {
39
- const targetId = getRawFromDhtAddress(nodes[45].getNodeId())
40
- const closestNodes = await entryPoint.findClosestNodesFromDht(getDhtAddressFromRaw(targetId))
39
+ const targetId = toDhtAddressRaw(nodes[45].getNodeId())
40
+ const closestNodes = await entryPoint.findClosestNodesFromDht(toDhtAddress(targetId))
41
41
  expect(closestNodes.length).toBeGreaterThanOrEqual(5)
42
- expect(getDhtAddressFromRaw(targetId)).toEqual(getNodeIdFromPeerDescriptor(closestNodes[0]))
42
+ expect(toDhtAddress(targetId)).toEqual(toNodeId(closestNodes[0]))
43
43
  }, 90000)
44
44
 
45
45
  })