@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,7 +1,7 @@
1
1
  import { ConnectionManager } from '../../src/connection/ConnectionManager'
2
2
  import { LatencyType, Simulator } from '../../src/connection/simulator/Simulator'
3
- import { Message, NodeType, PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
4
- import { RpcMessage } from '../../src/proto/packages/proto-rpc/protos/ProtoRpc'
3
+ import { Message, NodeType, PeerDescriptor } from '../../generated/packages/dht/protos/DhtRpc'
4
+ import { RpcMessage } from '../../generated/packages/proto-rpc/protos/ProtoRpc'
5
5
  import { ITransport } from '../../src/transport/ITransport'
6
6
  import * as Err from '../../src/helpers/errors'
7
7
  import { SimulatorTransport } from '../../src/connection/simulator/SimulatorTransport'
@@ -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: false
19
20
  })
20
21
  }
21
22
 
@@ -161,34 +162,6 @@ describe('WebRTC Connection Management', () => {
161
162
 
162
163
  }, 20000)
163
164
 
164
- it('Disconnects webrtcconnection while being connected', async () => {
165
- const msg: Message = {
166
- serviceId,
167
- messageId: '1',
168
- body: {
169
- oneofKind: 'rpcMessage',
170
- rpcMessage: RpcMessage.create()
171
- },
172
- }
173
-
174
- const disconnectedPromise1 = new Promise<void>((resolve, _reject) => {
175
- manager1.on('disconnected', () => {
176
- resolve()
177
- })
178
- })
179
-
180
- msg.targetDescriptor = peerDescriptor2
181
- manager1.send(msg).catch((e) => {
182
- expect(e.code).toEqual('SEND_FAILED')
183
- })
184
-
185
- // @ts-expect-error private field
186
- manager1.closeConnection(peerDescriptor2)
187
-
188
- await disconnectedPromise1
189
-
190
- }, 20000)
191
-
192
165
  it('failed connections are cleaned up', async () => {
193
166
  const msg: Message = {
194
167
  serviceId,
@@ -1,16 +1,16 @@
1
1
  import { ProtoRpcClient, RpcCommunicator, toProtoRpcClient } from '@streamr/proto-rpc'
2
- import { WebrtcConnectorRpcClient } from '../../src/proto/packages/dht/protos/DhtRpc.client'
2
+ import { WebrtcConnectorRpcClient } from '../../generated/packages/dht/protos/DhtRpc.client'
3
3
  import {
4
4
  IceCandidate,
5
5
  RtcAnswer,
6
6
  RtcOffer,
7
7
  WebrtcConnectionRequest
8
- } from '../../src/proto/packages/dht/protos/DhtRpc'
9
- import { Empty } from '../../src/proto/google/protobuf/empty'
8
+ } from '../../generated/packages/dht/protos/DhtRpc'
9
+ import { Empty } from '../../generated/google/protobuf/empty'
10
10
  import { createMockPeerDescriptor } from '../utils/utils'
11
- import { IWebrtcConnectorRpc } from '../../src/proto/packages/dht/protos/DhtRpc.server'
12
- import { waitForCondition } from '@streamr/utils'
13
- import { RpcMessage } from '../../src/proto/packages/proto-rpc/protos/ProtoRpc'
11
+ import { IWebrtcConnectorRpc } from '../../generated/packages/dht/protos/DhtRpc.server'
12
+ import { until } from '@streamr/utils'
13
+ import { RpcMessage } from '../../generated/packages/proto-rpc/protos/ProtoRpc'
14
14
  import { DhtCallContext } from '../../src/rpc-protocol/DhtCallContext'
15
15
 
16
16
  describe('WebRTC rpc messages', () => {
@@ -64,12 +64,12 @@ describe('WebRTC rpc messages', () => {
64
64
  rpcCommunicator2.registerRpcNotification(IceCandidate, 'iceCandidate', serverFunctions.iceCandidate)
65
65
  rpcCommunicator2.registerRpcNotification(WebrtcConnectionRequest, 'requestConnection', serverFunctions.requestConnection)
66
66
 
67
- rpcCommunicator1.on('outgoingMessage', (message: RpcMessage) => {
68
- rpcCommunicator2.handleIncomingMessage(message)
67
+ rpcCommunicator1.setOutgoingMessageListener(async (message: RpcMessage) => {
68
+ rpcCommunicator2.handleIncomingMessage(message, new DhtCallContext())
69
69
  })
70
70
 
71
- rpcCommunicator2.on('outgoingMessage', (message: RpcMessage) => {
72
- rpcCommunicator1.handleIncomingMessage(message)
71
+ rpcCommunicator2.setOutgoingMessageListener(async (message: RpcMessage) => {
72
+ rpcCommunicator1.handleIncomingMessage(message, new DhtCallContext())
73
73
  })
74
74
 
75
75
  client = toProtoRpcClient(new WebrtcConnectorRpcClient(rpcCommunicator1.getRpcClientTransport()))
@@ -86,7 +86,7 @@ describe('WebRTC rpc messages', () => {
86
86
  { targetDescriptor, notification: true }
87
87
  )
88
88
 
89
- await waitForCondition(() => requestConnectionCounter === 1)
89
+ await until(() => requestConnectionCounter === 1)
90
90
  })
91
91
 
92
92
  it('send rtcOffer', async () => {
@@ -97,7 +97,7 @@ describe('WebRTC rpc messages', () => {
97
97
  { targetDescriptor, notification: true }
98
98
  )
99
99
 
100
- await waitForCondition(() => rtcOfferCounter === 1)
100
+ await until(() => rtcOfferCounter === 1)
101
101
  })
102
102
 
103
103
  it('send rtcAnswer', async () => {
@@ -108,7 +108,7 @@ describe('WebRTC rpc messages', () => {
108
108
  { targetDescriptor, notification: true }
109
109
  )
110
110
 
111
- await waitForCondition(() => rtcAnswerCounter === 1)
111
+ await until(() => rtcAnswerCounter === 1)
112
112
  })
113
113
 
114
114
  it('send iceCandidate', async () => {
@@ -120,6 +120,6 @@ describe('WebRTC rpc messages', () => {
120
120
  { targetDescriptor, notification: true }
121
121
  )
122
122
 
123
- await waitForCondition(() => iceCandidateCounter === 1)
123
+ await until(() => iceCandidateCounter === 1)
124
124
  })
125
125
  })
@@ -1,5 +1,3 @@
1
- /* eslint-disable no-console */
2
-
3
1
  import { WebsocketServer } from '../../src/connection/websocket/WebsocketServer'
4
2
  import { IConnection } from '../../src/connection/IConnection'
5
3
  import { WebsocketClientConnection } from '../../src/connection/websocket/NodeWebsocketClientConnection'
@@ -1,9 +1,9 @@
1
1
  import { ProtoRpcClient, RpcCommunicator, toProtoRpcClient } from '@streamr/proto-rpc'
2
- import { WebsocketClientConnectorRpcClient } from '../../src/proto/packages/dht/protos/DhtRpc.client'
2
+ import { WebsocketClientConnectorRpcClient } from '../../generated/packages/dht/protos/DhtRpc.client'
3
3
  import { createMockPeerDescriptor, mockWebsocketClientConnectorRpc } from '../utils/utils'
4
- import { WebsocketConnectionRequest } from '../../src/proto/packages/dht/protos/DhtRpc'
5
- import { RpcMessage } from '../../src/proto/packages/proto-rpc/protos/ProtoRpc'
6
- import { Empty } from '../../src/proto/google/protobuf/empty'
4
+ import { WebsocketConnectionRequest } from '../../generated/packages/dht/protos/DhtRpc'
5
+ import { RpcMessage } from '../../generated/packages/proto-rpc/protos/ProtoRpc'
6
+ import { Empty } from '../../generated/google/protobuf/empty'
7
7
  import { DhtCallContext } from '../../src/rpc-protocol/DhtCallContext'
8
8
 
9
9
  describe('WebsocketClientConnectorRpc', () => {
@@ -32,12 +32,12 @@ describe('WebsocketClientConnectorRpc', () => {
32
32
  mockWebsocketClientConnectorRpc.requestConnection
33
33
  )
34
34
 
35
- rpcCommunicator1.on('outgoingMessage', (message: RpcMessage) => {
36
- rpcCommunicator2.handleIncomingMessage(message)
35
+ rpcCommunicator1.setOutgoingMessageListener(async (message: RpcMessage) => {
36
+ rpcCommunicator2.handleIncomingMessage(message, new DhtCallContext())
37
37
  })
38
38
 
39
- rpcCommunicator2.on('outgoingMessage', (message: RpcMessage) => {
40
- rpcCommunicator1.handleIncomingMessage(message)
39
+ rpcCommunicator2.setOutgoingMessageListener(async (message: RpcMessage) => {
40
+ rpcCommunicator1.handleIncomingMessage(message, new DhtCallContext())
41
41
  })
42
42
 
43
43
  client1 = toProtoRpcClient(new WebsocketClientConnectorRpcClient(rpcCommunicator1.getRpcClientTransport()))
@@ -1,15 +1,13 @@
1
- /* eslint-disable promise/no-nesting */
2
-
3
- import { MetricsContext, waitForCondition, waitForEvent3 } from '@streamr/utils'
1
+ import { MetricsContext, until, waitForEvent3 } from '@streamr/utils'
4
2
  import { ConnectionManager } from '../../src/connection/ConnectionManager'
5
3
  import { DefaultConnectorFacade, DefaultConnectorFacadeOptions } from '../../src/connection/ConnectorFacade'
6
4
  import { Simulator } from '../../src/connection/simulator/Simulator'
7
5
  import { SimulatorTransport } from '../../src/connection/simulator/SimulatorTransport'
8
6
  import * as Err from '../../src/helpers/errors'
9
- import { Message, NodeType, PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
10
- import { RpcMessage } from '../../src/proto/packages/proto-rpc/protos/ProtoRpc'
7
+ import { Message, NodeType, PeerDescriptor } from '../../generated/packages/dht/protos/DhtRpc'
8
+ import { RpcMessage } from '../../generated/packages/proto-rpc/protos/ProtoRpc'
11
9
  import { TransportEvents } from '../../src/transport/ITransport'
12
- import { getNodeIdFromPeerDescriptor } from '../../src/identifiers'
10
+ import { toNodeId } from '../../src/identifiers'
13
11
 
14
12
  const SERVICE_ID = 'test'
15
13
 
@@ -19,7 +17,8 @@ const createOptions = (localPeerDescriptor: PeerDescriptor, opts: Omit<DefaultCo
19
17
  createLocalPeerDescriptor: async () => localPeerDescriptor,
20
18
  ...opts
21
19
  }),
22
- metricsContext: new MetricsContext()
20
+ metricsContext: new MetricsContext(),
21
+ allowIncomingPrivateConnections: false
23
22
  }
24
23
  }
25
24
 
@@ -145,7 +144,7 @@ describe('Websocket Connection Management', () => {
145
144
  waitForEvent3<TransportEvents>(wsServerManager, 'disconnected', 15000),
146
145
  wsServerManager.send(dummyMessage)
147
146
  ])
148
- expect(wsServerManager.hasConnection(getNodeIdFromPeerDescriptor(dummyMessage.targetDescriptor!))).toBeFalse()
147
+ expect(wsServerManager.hasConnection(toNodeId(dummyMessage.targetDescriptor!))).toBeFalse()
149
148
  }, 20000)
150
149
 
151
150
  it('Can open connections to peer with server', async () => {
@@ -159,14 +158,14 @@ describe('Websocket Connection Management', () => {
159
158
  targetDescriptor: wsServerConnectorPeerDescriptor
160
159
  }
161
160
  await noWsServerManager.send(dummyMessage)
162
- await waitForCondition(
161
+ await until(
163
162
  () => {
164
- const nodeId = getNodeIdFromPeerDescriptor(noWsServerConnectorPeerDescriptor)
163
+ const nodeId = toNodeId(noWsServerConnectorPeerDescriptor)
165
164
  return wsServerManager.hasConnection(nodeId)
166
165
  }
167
166
  )
168
- await waitForCondition(
169
- () => noWsServerManager.hasConnection(getNodeIdFromPeerDescriptor(wsServerConnectorPeerDescriptor))
167
+ await until(
168
+ () => noWsServerManager.hasConnection(toNodeId(wsServerConnectorPeerDescriptor))
170
169
  )
171
170
  })
172
171
 
@@ -6,8 +6,8 @@ import { SimulatorTransport } from '../../src/connection/simulator/SimulatorTran
6
6
  import { DhtRpcOptions } from '../../src/rpc-protocol/DhtRpcOptions'
7
7
  import { ListeningRpcCommunicator } from '../../src/transport/ListeningRpcCommunicator'
8
8
  import { ProtoRpcClient, toProtoRpcClient } from '@streamr/proto-rpc'
9
- import { DhtNodeRpcClient } from '../../src/proto/packages/dht/protos/DhtRpc.client'
10
- import { PeerDescriptor, PingRequest, PingResponse } from '../../src/proto/packages/dht/protos/DhtRpc'
9
+ import { DhtNodeRpcClient } from '../../generated/packages/dht/protos/DhtRpc.client'
10
+ import { PeerDescriptor, PingRequest, PingResponse } from '../../generated/packages/dht/protos/DhtRpc'
11
11
  import { DefaultConnectorFacade } from '../../src/connection/ConnectorFacade'
12
12
  import { MetricsContext } from '@streamr/utils'
13
13
  import { createMockPeerDescriptor } from '../utils/utils'
@@ -20,7 +20,8 @@ const createConnectionManager = (localPeerDescriptor: PeerDescriptor, transport:
20
20
  transport,
21
21
  createLocalPeerDescriptor: async () => localPeerDescriptor
22
22
  }),
23
- metricsContext: new MetricsContext()
23
+ metricsContext: new MetricsContext(),
24
+ allowIncomingPrivateConnections: false
24
25
  })
25
26
  }
26
27
 
@@ -50,7 +51,6 @@ describe('RPC connections over WebRTC', () => {
50
51
  await connectorTransport2.start()
51
52
  manager2 = createConnectionManager(peerDescriptor2, connectorTransport2)
52
53
  rpcCommunicator2 = new ListeningRpcCommunicator(SERVICE_ID, manager2)
53
- //client2 = toProtoRpcClient(new DhtNodeRpcClient(rpcCommunicator2.getRpcClientTransport()))
54
54
 
55
55
  await manager1.start()
56
56
  await manager2.start()
@@ -87,7 +87,7 @@ describe('RPC connections over WebRTC', () => {
87
87
  const response = await client1.ping(request, options)
88
88
 
89
89
  expect(response.requestId).toEqual(request.requestId)
90
- }, 60000)
90
+ })
91
91
 
92
92
  it('Throws an exception if RPC method is not defined', async () => {
93
93
 
@@ -101,57 +101,23 @@ describe('RPC connections over WebRTC', () => {
101
101
 
102
102
  await expect(client1.ping(request, options))
103
103
  .rejects.toThrow('Server does not implement method ping')
104
- }, 60000)
105
-
106
- /*
107
-
108
- TODO enable these tests (NET-1177)
104
+ })
109
105
 
110
- it.only('Throws a client-side exception if WebRTC connection fails', async () => {
106
+ it('Throws a client-side exception if WebRTC connection fails', async () => {
111
107
 
112
108
  const request: PingRequest = {
113
109
  requestId: v4()
114
110
  }
115
111
  const options: DhtRpcOptions = {
116
112
  sourceDescriptor: peerDescriptor1,
117
- targetDescriptor: peerDescriptor2
113
+ targetDescriptor: peerDescriptor2,
114
+ timeout: 10000
118
115
  }
119
- await connectorTransport1.stop()
120
116
  await manager2.stop()
121
117
 
122
- const result = await client1.ping(request, options)
123
-
124
- }, 60000)
125
-
126
- it('Disconnects WebrtcConnection while being connected', async () => {
127
-
128
- const rpcMessage: RpcMessage = {
129
- header: {},
130
- body: new Uint8Array(10),
131
- requestId: v4()
132
- }
133
-
134
- const msg: Message = {
135
- serviceId,
136
- messageId: '1',
137
- body: RpcMessage.toBinary(rpcMessage)
138
- }
118
+ await expect(client1.ping(request, options))
119
+ .rejects.toThrow('Peer disconnected')
139
120
 
140
- const disconnectedPromise1 = new Promise<void>((resolve, _reject) => {
141
- manager1.on('disconnected', () => {
142
- //expect(message.body.oneofKind).toBe('rpcMessage')
143
- resolve()
144
- })
145
- })
146
-
147
- msg.targetDescriptor = peerDescriptor2
148
- manager1.send(msg).catch((e) => {
149
- expect(e.code).toEqual('CONNECTION_FAILED')
150
- })
151
-
152
- manager1.disconnect(peerDescriptor2!, undefined, 100)
153
- await disconnectedPromise1
121
+ }, 10000)
154
122
 
155
- }, 20000)
156
- */
157
123
  })
@@ -42,17 +42,17 @@ describe('AutoCertifierClientFacade', () => {
42
42
 
43
43
  it('start', async () => {
44
44
  await client.start()
45
- expect(setHost).toBeCalled()
46
- expect(updateCertificate).toBeCalled()
45
+ expect(setHost).toHaveBeenCalled()
46
+ expect(updateCertificate).toHaveBeenCalled()
47
47
  })
48
48
 
49
49
  it('updated events are processed', async () => {
50
50
  await client.start()
51
- expect(setHost).toBeCalledTimes(1)
52
- expect(updateCertificate).toBeCalledTimes(1);
51
+ expect(setHost).toHaveBeenCalledTimes(1)
52
+ expect(updateCertificate).toHaveBeenCalledTimes(1);
53
53
  (mockClient as MockAutoCertifierClient).emitUpdateSubdomain()
54
- expect(setHost).toBeCalledTimes(2)
55
- expect(updateCertificate).toBeCalledTimes(2)
54
+ expect(setHost).toHaveBeenCalledTimes(2)
55
+ expect(updateCertificate).toHaveBeenCalledTimes(2)
56
56
  })
57
57
 
58
58
  })
@@ -1,6 +1,6 @@
1
1
  import { MetricsContext } from '@streamr/utils'
2
2
  import { ConnectionManager } from '../../src/connection/ConnectionManager'
3
- import { getNodeIdFromPeerDescriptor, PendingConnection } from '../../src/exports'
3
+ import { toNodeId, PendingConnection } from '../../src/exports'
4
4
  import { FakeConnectorFacade } from '../utils/FakeConnectorFacade'
5
5
  import { MockConnection } from '../utils/mock/MockConnection'
6
6
  import { createMockPeerDescriptor } from '../utils/utils'
@@ -15,6 +15,7 @@ describe('ConnetionManager', () => {
15
15
  beforeEach(async () => {
16
16
  connectionManager = new ConnectionManager({
17
17
  metricsContext: new MetricsContext(),
18
+ allowIncomingPrivateConnections: false,
18
19
  createConnectorFacade: () => {
19
20
  fakeConnectorFacade = new FakeConnectorFacade(localPeerDescriptor)
20
21
  return fakeConnectorFacade
@@ -30,7 +31,7 @@ describe('ConnetionManager', () => {
30
31
  it('should replace a duplicate connecting connection', () => {
31
32
  const remotePeerDescriptor = createMockPeerDescriptor()
32
33
  const pendingConnection1 = new PendingConnection(remotePeerDescriptor)
33
- const offerer = getOfferer(getNodeIdFromPeerDescriptor(localPeerDescriptor), getNodeIdFromPeerDescriptor(remotePeerDescriptor))
34
+ const offerer = getOfferer(toNodeId(localPeerDescriptor), toNodeId(remotePeerDescriptor))
34
35
  const accepted1 = fakeConnectorFacade.callOnNewConnection(pendingConnection1)
35
36
  expect(accepted1).toBeTrue()
36
37
  const pendingConnection2 = new PendingConnection(remotePeerDescriptor)
@@ -45,7 +46,7 @@ describe('ConnetionManager', () => {
45
46
  it('should replace a duplicate connected connection', () => {
46
47
  const remotePeerDescriptor = createMockPeerDescriptor()
47
48
  const pendingConnection1 = new PendingConnection(remotePeerDescriptor)
48
- const offerer = getOfferer(getNodeIdFromPeerDescriptor(localPeerDescriptor), getNodeIdFromPeerDescriptor(remotePeerDescriptor))
49
+ const offerer = getOfferer(toNodeId(localPeerDescriptor), toNodeId(remotePeerDescriptor))
49
50
  const accepted1 = fakeConnectorFacade.callOnNewConnection(pendingConnection1)
50
51
  expect(accepted1).toBeTrue()
51
52
  pendingConnection1.onHandshakeCompleted(new MockConnection())
@@ -1,4 +1,4 @@
1
- import { NodeType } from '../../src/proto/packages/dht/protos/DhtRpc'
1
+ import { NodeType } from '../../generated/packages/dht/protos/DhtRpc'
2
2
  import { expectedConnectionType } from '../../src/helpers/Connectivity'
3
3
  import { ConnectionType } from '../../src/connection/IConnection'
4
4
  import { createMockPeerDescriptor } from '../utils/utils'
@@ -3,8 +3,8 @@ import { sampleSize } from 'lodash'
3
3
  import { DhtNodeRpcRemote } from '../../src/dht/DhtNodeRpcRemote'
4
4
  import { PeerManager, getDistance } from '../../src/dht/PeerManager'
5
5
  import { DiscoverySession } from '../../src/dht/discovery/DiscoverySession'
6
- import { DhtAddress, getNodeIdFromPeerDescriptor, getRawFromDhtAddress } from '../../src/identifiers'
7
- import { NodeType, PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
6
+ import { DhtAddress, toNodeId, toDhtAddressRaw } from '../../src/identifiers'
7
+ import { NodeType, PeerDescriptor } from '../../generated/packages/dht/protos/DhtRpc'
8
8
  import { createTestTopology } from '../utils/topology'
9
9
  import { getClosestNodes } from '../../src/dht/contact/getClosestNodes'
10
10
 
@@ -16,7 +16,7 @@ const QUERY_BATCH_SIZE = 5 // the default value in DhtNode's options, not relev
16
16
 
17
17
  const createPeerDescriptor = (nodeId: DhtAddress): PeerDescriptor => {
18
18
  return {
19
- nodeId: getRawFromDhtAddress(nodeId),
19
+ nodeId: toDhtAddressRaw(nodeId),
20
20
  type: NodeType.NODEJS
21
21
  }
22
22
  }
@@ -45,9 +45,9 @@ describe('DiscoverySession', () => {
45
45
  }
46
46
 
47
47
  const createMockRpcRemote = (peerDescriptor: PeerDescriptor): Partial<DhtNodeRpcRemote> => {
48
- const nodeId = getNodeIdFromPeerDescriptor(peerDescriptor)
48
+ const nodeId = toNodeId(peerDescriptor)
49
49
  return {
50
- id: getRawFromDhtAddress(nodeId),
50
+ id: toDhtAddressRaw(nodeId),
51
51
  getPeerDescriptor: () => peerDescriptor,
52
52
  getNodeId: () => nodeId,
53
53
  getClosestPeers: async (referenceId: DhtAddress) => {
@@ -79,7 +79,7 @@ describe('DiscoverySession', () => {
79
79
  // Each queried node should closer to the target than the previous queried node, because we
80
80
  // use parallelism=1 and noProgressLimit=1
81
81
  const distancesToTarget = queriedNodes
82
- .map((nodeId) => getDistance(getRawFromDhtAddress(nodeId), getRawFromDhtAddress(targetId)))
82
+ .map((nodeId) => getDistance(toDhtAddressRaw(nodeId), toDhtAddressRaw(targetId)))
83
83
  for (let i = 1; i < distancesToTarget.length ; i++) {
84
84
  expect(distancesToTarget[i]).toBeLessThan(distancesToTarget[i - 1])
85
85
  }
@@ -10,7 +10,7 @@ import {
10
10
  } from '../../src/connection/Handshaker'
11
11
  import { ConnectionEvents, IConnection } from '../../src/connection/IConnection'
12
12
  import { createMockPeerDescriptor } from '../utils/utils'
13
- import { HandshakeError, Message } from '../../src/proto/packages/dht/protos/DhtRpc'
13
+ import { HandshakeError, Message } from '../../generated/packages/dht/protos/DhtRpc'
14
14
  import { PendingConnection } from '../../src/connection/PendingConnection'
15
15
 
16
16
  describe('Handshaker', () => {
@@ -104,7 +104,7 @@ describe('Handshaker', () => {
104
104
  })
105
105
 
106
106
  it('onHandshakeFailed unsupported version', () => {
107
- handshaker.emit('handshakeFailed', HandshakeError.UNSUPPORTED_VERSION)
107
+ handshaker.emit('handshakeFailed', HandshakeError.UNSUPPORTED_PROTOCOL_VERSION)
108
108
  expect(mockOnHandshakeCompleted).not.toHaveBeenCalled()
109
109
  expect(mockPendingConnectionClose).toHaveBeenCalledTimes(1)
110
110
  })
@@ -0,0 +1,52 @@
1
+ import { until } from '@streamr/utils'
2
+ import { ListeningRpcCommunicator } from '../../src/transport/ListeningRpcCommunicator'
3
+ import { MockTransport } from '../utils/mock/MockTransport'
4
+ import { createMockPeerDescriptor } from '../utils/utils'
5
+ import { RpcMessage } from '@streamr/proto-rpc'
6
+ import { Deferred, RpcMetadata, RpcStatus } from '@protobuf-ts/runtime-rpc'
7
+
8
+ const createDeferredPromises = () => {
9
+
10
+ const defHeader = new Deferred<RpcMetadata>()
11
+ const defMessage = new Deferred<any>()
12
+ const defStatus = new Deferred<RpcStatus>()
13
+ const defTrailer = new Deferred<RpcMetadata>()
14
+
15
+ const deferredParser = () => {}
16
+ return {
17
+ message: defMessage,
18
+ header: defHeader,
19
+ trailer: defTrailer,
20
+ status: defStatus,
21
+ messageParser: deferredParser as any
22
+ }
23
+ }
24
+
25
+ describe('ListeningRpcCommunicator', () => {
26
+ const SERVICE_ID = 'test'
27
+ let rpcCommunicator: ListeningRpcCommunicator
28
+ let transport: MockTransport
29
+
30
+ beforeEach(() => {
31
+ transport = new MockTransport()
32
+ rpcCommunicator = new ListeningRpcCommunicator(SERVICE_ID, transport)
33
+ })
34
+
35
+ afterEach(() => {
36
+ rpcCommunicator.destroy()
37
+ transport.stop()
38
+ })
39
+
40
+ it('rejects requests on disconnect event to the target', async () => {
41
+ const peerDescriptor = createMockPeerDescriptor()
42
+ rpcCommunicator.getRpcClientTransport().emit(
43
+ 'rpcRequest',
44
+ RpcMessage.create(),
45
+ { targetDescriptor: peerDescriptor }, createDeferredPromises()
46
+ )
47
+ await until(() => rpcCommunicator.getRequestIds(() => true).length > 0)
48
+ transport.emit('disconnected', peerDescriptor, false)
49
+ await until(() => rpcCommunicator.getRequestIds(() => true).length === 0)
50
+ }, 10000)
51
+
52
+ })
@@ -2,7 +2,7 @@ import { wait } from '@streamr/utils'
2
2
  import { LocalDataStore } from '../../src/dht/store/LocalDataStore'
3
3
  import { createMockPeerDescriptor } from '../utils/utils'
4
4
  import { createMockDataEntry } from '../utils/mock/mockDataEntry'
5
- import { createRandomDhtAddress, getDhtAddressFromRaw, getNodeIdFromPeerDescriptor } from '../../src/identifiers'
5
+ import { randomDhtAddress, toDhtAddress, toNodeId } from '../../src/identifiers'
6
6
 
7
7
  describe('LocalDataStore', () => {
8
8
 
@@ -19,14 +19,14 @@ describe('LocalDataStore', () => {
19
19
  it('can store', () => {
20
20
  const storedEntry = createMockDataEntry()
21
21
  localDataStore.storeEntry(storedEntry)
22
- const fetchedEntries = Array.from(localDataStore.values(getDhtAddressFromRaw(storedEntry.key)))
22
+ const fetchedEntries = Array.from(localDataStore.values(toDhtAddress(storedEntry.key)))
23
23
  expect(fetchedEntries).toIncludeSameMembers([storedEntry])
24
24
  })
25
25
 
26
26
  it('multiple storers behind one key', () => {
27
- const creator1 = createRandomDhtAddress()
28
- const creator2 = createRandomDhtAddress()
29
- const key = createRandomDhtAddress()
27
+ const creator1 = randomDhtAddress()
28
+ const creator2 = randomDhtAddress()
29
+ const key = randomDhtAddress()
30
30
  const storedEntry1 = createMockDataEntry({ key, creator: creator1 })
31
31
  const storedEntry2 = createMockDataEntry({ key, creator: creator2 })
32
32
  localDataStore.storeEntry(storedEntry1)
@@ -36,9 +36,9 @@ describe('LocalDataStore', () => {
36
36
  })
37
37
 
38
38
  it('can remove data entries', () => {
39
- const creator1 = createRandomDhtAddress()
40
- const creator2 = createRandomDhtAddress()
41
- const key = createRandomDhtAddress()
39
+ const creator1 = randomDhtAddress()
40
+ const creator2 = randomDhtAddress()
41
+ const key = randomDhtAddress()
42
42
  const storedEntry1 = createMockDataEntry({ key, creator: creator1 })
43
43
  const storedEntry2 = createMockDataEntry({ key, creator: creator2 })
44
44
  localDataStore.storeEntry(storedEntry1)
@@ -49,9 +49,9 @@ describe('LocalDataStore', () => {
49
49
  })
50
50
 
51
51
  it('can remove all data entries', () => {
52
- const creator1 = createRandomDhtAddress()
53
- const creator2 = createRandomDhtAddress()
54
- const key = createRandomDhtAddress()
52
+ const creator1 = randomDhtAddress()
53
+ const creator2 = randomDhtAddress()
54
+ const key = randomDhtAddress()
55
55
  const storedEntry1 = createMockDataEntry({ key, creator: creator1 })
56
56
  const storedEntry2 = createMockDataEntry({ key, creator: creator2 })
57
57
  localDataStore.storeEntry(storedEntry1)
@@ -64,33 +64,33 @@ describe('LocalDataStore', () => {
64
64
  it('data is deleted after TTL', async () => {
65
65
  const storedEntry = createMockDataEntry({ ttl: 1000 })
66
66
  localDataStore.storeEntry(storedEntry)
67
- expect(Array.from(localDataStore.values(getDhtAddressFromRaw(storedEntry.key)))).toHaveLength(1)
67
+ expect(Array.from(localDataStore.values(toDhtAddress(storedEntry.key)))).toHaveLength(1)
68
68
  await wait(1100)
69
- expect(Array.from(localDataStore.values(getDhtAddressFromRaw(storedEntry.key)))).toHaveLength(0)
69
+ expect(Array.from(localDataStore.values(toDhtAddress(storedEntry.key)))).toHaveLength(0)
70
70
  })
71
71
 
72
72
  describe('mark data as deleted', () => {
73
73
 
74
74
  it('happy path', () => {
75
- const creator1 = createRandomDhtAddress()
75
+ const creator1 = randomDhtAddress()
76
76
  const storedEntry = createMockDataEntry({ creator: creator1 })
77
77
  localDataStore.storeEntry(storedEntry)
78
- const notDeletedData = Array.from(localDataStore.values(getDhtAddressFromRaw(storedEntry.key)))
78
+ const notDeletedData = Array.from(localDataStore.values(toDhtAddress(storedEntry.key)))
79
79
  expect(notDeletedData[0].deleted).toBeFalse()
80
80
  const returnValue = localDataStore.markAsDeleted(
81
- getDhtAddressFromRaw(storedEntry.key),
81
+ toDhtAddress(storedEntry.key),
82
82
  creator1
83
83
  )
84
84
  expect(returnValue).toBe(true)
85
- const deletedData = Array.from(localDataStore.values(getDhtAddressFromRaw(storedEntry.key)))
85
+ const deletedData = Array.from(localDataStore.values(toDhtAddress(storedEntry.key)))
86
86
  expect(deletedData[0].deleted).toBeTrue()
87
87
  })
88
88
 
89
89
  it('data not stored', () => {
90
- const key = createRandomDhtAddress()
90
+ const key = randomDhtAddress()
91
91
  const returnValue = localDataStore.markAsDeleted(
92
92
  key,
93
- getNodeIdFromPeerDescriptor(createMockPeerDescriptor())
93
+ toNodeId(createMockPeerDescriptor())
94
94
  )
95
95
  expect(returnValue).toBe(false)
96
96
  })
@@ -99,8 +99,8 @@ describe('LocalDataStore', () => {
99
99
  const storedEntry = createMockDataEntry()
100
100
  localDataStore.storeEntry(storedEntry)
101
101
  const returnValue = localDataStore.markAsDeleted(
102
- getDhtAddressFromRaw(storedEntry.key),
103
- getNodeIdFromPeerDescriptor(createMockPeerDescriptor())
102
+ toDhtAddress(storedEntry.key),
103
+ toNodeId(createMockPeerDescriptor())
104
104
  )
105
105
  expect(returnValue).toBe(false)
106
106
  })