@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,10 +1,10 @@
1
- import { waitForCondition } from '@streamr/utils'
1
+ import { until } from '@streamr/utils'
2
2
  import { range, sample, sampleSize } from 'lodash'
3
3
  import { DhtNodeRpcRemote } from '../../src/dht/DhtNodeRpcRemote'
4
4
  import { PeerManager } from '../../src/dht/PeerManager'
5
5
  import { getClosestNodes } from '../../src/dht/contact/getClosestNodes'
6
- import { DhtAddress, createRandomDhtAddress, getNodeIdFromPeerDescriptor, getRawFromDhtAddress } from '../../src/identifiers'
7
- import { NodeType, PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
6
+ import { DhtAddress, randomDhtAddress, toNodeId, toDhtAddressRaw } from '../../src/identifiers'
7
+ import { NodeType, PeerDescriptor } from '../../generated/packages/dht/protos/DhtRpc'
8
8
  import { MockRpcCommunicator } from '../utils/mock/MockRpcCommunicator'
9
9
  import { createMockPeerDescriptor } from '../utils/utils'
10
10
 
@@ -16,7 +16,7 @@ const createDhtNodeRpcRemote = (
16
16
  const remote = new class extends DhtNodeRpcRemote {
17
17
  // eslint-disable-next-line class-methods-use-this
18
18
  async ping(): Promise<boolean> {
19
- return !pingFailures.has(getNodeIdFromPeerDescriptor(peerDescriptor))
19
+ return !pingFailures.has(toNodeId(peerDescriptor))
20
20
  }
21
21
  }(localPeerDescriptor, peerDescriptor, undefined as any, new MockRpcCommunicator())
22
22
  return remote
@@ -28,13 +28,13 @@ const createPeerManager = (
28
28
  pingFailures: Set<DhtAddress> = new Set()
29
29
  ) => {
30
30
  const manager = new PeerManager({
31
- localNodeId: getNodeIdFromPeerDescriptor(localPeerDescriptor),
31
+ localNodeId: toNodeId(localPeerDescriptor),
32
32
  localPeerDescriptor: localPeerDescriptor,
33
33
  isLayer0: true,
34
34
  createDhtNodeRpcRemote: (peerDescriptor: PeerDescriptor) => createDhtNodeRpcRemote(peerDescriptor, localPeerDescriptor, pingFailures),
35
35
  hasConnection: () => false
36
36
  } as any)
37
- const contacts = nodeIds.map((n) => ({ nodeId: getRawFromDhtAddress(n), type: NodeType.NODEJS }))
37
+ const contacts = nodeIds.map((n) => ({ nodeId: toDhtAddressRaw(n), type: NodeType.NODEJS }))
38
38
  for (const contact of contacts) {
39
39
  manager.addContact(contact)
40
40
  }
@@ -44,29 +44,29 @@ const createPeerManager = (
44
44
  describe('PeerManager', () => {
45
45
 
46
46
  it('getNearbyContactCount', () => {
47
- const nodeIds = range(10).map(() => createRandomDhtAddress())
47
+ const nodeIds = range(10).map(() => randomDhtAddress())
48
48
  const manager = createPeerManager(nodeIds)
49
49
  expect(manager.getNearbyContactCount()).toBe(10)
50
50
  expect(manager.getNearbyContactCount(new Set(sampleSize(nodeIds, 2)))).toBe(8)
51
- expect(manager.getNearbyContactCount(new Set([sample(nodeIds)!, createRandomDhtAddress()]))).toBe(9)
51
+ expect(manager.getNearbyContactCount(new Set([sample(nodeIds)!, randomDhtAddress()]))).toBe(9)
52
52
  })
53
53
 
54
54
  it('addContact: ping fails', async () => {
55
55
  const localPeerDescriptor = createMockPeerDescriptor()
56
56
  const successContacts = range(5).map(() => createMockPeerDescriptor())
57
57
  const failureContact = createMockPeerDescriptor()
58
- const manager = createPeerManager([], localPeerDescriptor, new Set([getNodeIdFromPeerDescriptor(failureContact)]))
58
+ const manager = createPeerManager([], localPeerDescriptor, new Set([toNodeId(failureContact)]))
59
59
  for (const successContact of successContacts) {
60
60
  manager.addContact(successContact)
61
- manager.setContactActive(getNodeIdFromPeerDescriptor(successContact))
62
- manager.removeNeighbor(getNodeIdFromPeerDescriptor(successContact))
61
+ manager.setContactActive(toNodeId(successContact))
62
+ manager.removeNeighbor(toNodeId(successContact))
63
63
  }
64
64
  expect(manager.getNeighborCount()).toBe(0)
65
65
  manager.addContact(failureContact)
66
- const closesSuccessContact = getClosestNodes(getNodeIdFromPeerDescriptor(localPeerDescriptor), successContacts)[0]
67
- await waitForCondition(() => {
66
+ const closesSuccessContact = getClosestNodes(toNodeId(localPeerDescriptor), successContacts)[0]
67
+ await until(() => {
68
68
  const neighborNodeIds = manager.getNeighbors().map((n) => n.getNodeId())
69
- return neighborNodeIds.includes(getNodeIdFromPeerDescriptor(closesSuccessContact))
69
+ return neighborNodeIds.includes(toNodeId(closesSuccessContact))
70
70
  })
71
71
  expect(manager.getNeighborCount()).toBe(1)
72
72
  expect(manager.getNeighbors()[0].getPeerDescriptor()).toEqualPeerDescriptor(closesSuccessContact)
@@ -83,7 +83,7 @@ describe('PeerManager', () => {
83
83
  }
84
84
  manager.addContact(failureContact)
85
85
  expect(manager.getNeighborCount()).toBe(6)
86
- failureSet.add(getNodeIdFromPeerDescriptor(failureContact))
86
+ failureSet.add(toNodeId(failureContact))
87
87
  await manager.pruneOfflineNodes(
88
88
  manager.getNeighbors().map((node) => createDhtNodeRpcRemote(node.getPeerDescriptor(), localPeerDescriptor, failureSet))
89
89
  )
@@ -21,7 +21,7 @@ describe('PendingConnection', () => {
21
21
  throw new Error('disconnected')
22
22
  })
23
23
  pendingConnection.replaceAsDuplicate()
24
- await pendingConnection.close(false)
24
+ pendingConnection.close(false)
25
25
  await wait(50)
26
26
  })
27
27
 
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  import { ProtobufMessage } from '../../src/protobufclasses/ProtobufMessage'
3
- import { Message, RpcMessage } from '../../src/proto/DhtRpc'
3
+ import { Message, RpcMessage } from '../../generated/DhtRpc'
4
4
  import { v4 } from 'uuid'
5
5
  import { MessageType } from '@protobuf-ts/runtime'
6
6
  */
@@ -1,9 +1,9 @@
1
1
  import { RandomContactList } from '../../src/dht/contact/RandomContactList'
2
- import { DhtAddress, DhtAddressRaw, getDhtAddressFromRaw } from '../../src/identifiers'
2
+ import { DhtAddress, DhtAddressRaw, toDhtAddress } from '../../src/identifiers'
3
3
 
4
4
  const createItem = (nodeId: DhtAddressRaw): { getNodeId: () => DhtAddress } => {
5
5
  return {
6
- getNodeId: () => getDhtAddressFromRaw(nodeId)
6
+ getNodeId: () => toDhtAddress(nodeId)
7
7
  }
8
8
  }
9
9
 
@@ -5,7 +5,7 @@ import {
5
5
  RouteMessageError,
6
6
  RouteMessageWrapper,
7
7
  RecursiveOperationRequest
8
- } from '../../src/proto/packages/dht/protos/DhtRpc'
8
+ } from '../../generated/packages/dht/protos/DhtRpc'
9
9
  import {
10
10
  createWrappedClosestPeersRequest,
11
11
  createMockPeerDescriptor
@@ -18,7 +18,7 @@ import { MockTransport } from '../utils/mock/MockTransport'
18
18
  import { FakeRpcCommunicator } from '../utils/FakeRpcCommunicator'
19
19
  import { Router } from '../../src/dht/routing/Router'
20
20
  import { ITransport } from '../../src/transport/ITransport'
21
- import { areEqualPeerDescriptors, createRandomDhtAddress } from '../../src/identifiers'
21
+ import { areEqualPeerDescriptors, randomDhtAddress } from '../../src/identifiers'
22
22
  import { MockConnectionsView } from '../utils/mock/MockConnectionsView'
23
23
 
24
24
  const createMockRouter = (error?: RouteMessageError): Partial<Router> => {
@@ -94,7 +94,7 @@ describe('RecursiveOperationManager', () => {
94
94
 
95
95
  it('find closest nodes returns self if no peers', async () => {
96
96
  const recursiveOperationManager = createRecursiveOperationManager()
97
- const res = await recursiveOperationManager.execute(createRandomDhtAddress(), RecursiveOperation.FIND_CLOSEST_NODES)
97
+ const res = await recursiveOperationManager.execute(randomDhtAddress(), RecursiveOperation.FIND_CLOSEST_NODES)
98
98
  expect(areEqualPeerDescriptors(res.closestNodes[0], peerDescriptor1)).toEqual(true)
99
99
  recursiveOperationManager.stop()
100
100
  })
@@ -1,11 +1,11 @@
1
- import { waitForCondition } from '@streamr/utils'
1
+ import { until } from '@streamr/utils'
2
2
  import { range } from 'lodash'
3
3
  import { RecursiveOperationSession } from '../../src/dht/recursive-operation/RecursiveOperationSession'
4
4
  import { RecursiveOperationSessionRpcRemote } from '../../src/dht/recursive-operation/RecursiveOperationSessionRpcRemote'
5
5
  import { ServiceID } from '../../src/types/ServiceID'
6
- import { createRandomDhtAddress } from '../../src/identifiers'
7
- import { Message, PeerDescriptor, RecursiveOperation } from '../../src/proto/packages/dht/protos/DhtRpc'
8
- import { RecursiveOperationSessionRpcClient } from '../../src/proto/packages/dht/protos/DhtRpc.client'
6
+ import { randomDhtAddress } from '../../src/identifiers'
7
+ import { Message, PeerDescriptor, RecursiveOperation } from '../../generated/packages/dht/protos/DhtRpc'
8
+ import { RecursiveOperationSessionRpcClient } from '../../generated/packages/dht/protos/DhtRpc.client'
9
9
  import { RoutingRpcCommunicator } from '../../src/transport/RoutingRpcCommunicator'
10
10
  import { FakeEnvironment } from '../utils/FakeTransport'
11
11
  import { createMockPeerDescriptor } from '../utils/utils'
@@ -36,7 +36,7 @@ describe('RecursiveOperationSession', () => {
36
36
  const doRouteRequest = jest.fn()
37
37
  const session = new RecursiveOperationSession({
38
38
  transport: environment.createTransport(localPeerDescriptor),
39
- targetId: createRandomDhtAddress(),
39
+ targetId: randomDhtAddress(),
40
40
  localPeerDescriptor,
41
41
  waitedRoutingPathCompletions: 3,
42
42
  operation: RecursiveOperation.FIND_CLOSEST_NODES,
@@ -59,7 +59,7 @@ describe('RecursiveOperationSession', () => {
59
59
 
60
60
  // TODO now waits for the 4s timeout, could setup test so that it completes by receiving
61
61
  // all data it wants
62
- await waitForCondition(() => onCompleted.mock.calls.length > 0)
62
+ await until(() => onCompleted.mock.calls.length > 0)
63
63
  const result = session.getResults()
64
64
  // TODO assert peer descriptors
65
65
  expect(result.closestNodes).toHaveLength(6)
@@ -7,10 +7,10 @@ import {
7
7
  RouteMessageAck,
8
8
  RouteMessageError,
9
9
  RouteMessageWrapper
10
- } from '../../src/proto/packages/dht/protos/DhtRpc'
10
+ } from '../../generated/packages/dht/protos/DhtRpc'
11
11
  import { createMockPeerDescriptor, createWrappedClosestPeersRequest } from '../utils/utils'
12
12
  import { FakeRpcCommunicator } from '../utils/FakeRpcCommunicator'
13
- import { DhtAddress, getNodeIdFromPeerDescriptor, createRandomDhtAddress } from '../../src/identifiers'
13
+ import { DhtAddress, toNodeId, randomDhtAddress } from '../../src/identifiers'
14
14
  import { MockRpcCommunicator } from '../utils/mock/MockRpcCommunicator'
15
15
 
16
16
  describe('Router', () => {
@@ -73,7 +73,7 @@ describe('Router', () => {
73
73
  })
74
74
 
75
75
  it('doRouteMessage with connections', async () => {
76
- connections.set(createRandomDhtAddress(), createMockDhtNodeRpcRemote(peerDescriptor2))
76
+ connections.set(randomDhtAddress(), createMockDhtNodeRpcRemote(peerDescriptor2))
77
77
  const ack = await rpcCommunicator.callRpcMethod('routeMessage', {
78
78
  message,
79
79
  target: peerDescriptor2.nodeId,
@@ -87,7 +87,7 @@ describe('Router', () => {
87
87
  })
88
88
 
89
89
  it('doRouteMessage with parallelRootNodeIds', async () => {
90
- const nodeId = getNodeIdFromPeerDescriptor(peerDescriptor2)
90
+ const nodeId = toNodeId(peerDescriptor2)
91
91
  connections.set(nodeId, createMockDhtNodeRpcRemote(peerDescriptor2))
92
92
  const ack = await rpcCommunicator.callRpcMethod('routeMessage', {
93
93
  message,
@@ -107,7 +107,7 @@ describe('Router', () => {
107
107
  })
108
108
 
109
109
  it('route server with connections', async () => {
110
- connections.set(createRandomDhtAddress(), createMockDhtNodeRpcRemote(peerDescriptor2))
110
+ connections.set(randomDhtAddress(), createMockDhtNodeRpcRemote(peerDescriptor2))
111
111
  const ack = await rpcCommunicator.callRpcMethod('routeMessage', routedMessage) as RouteMessageAck
112
112
  expect(ack.error).toBeUndefined()
113
113
  })
@@ -124,7 +124,7 @@ describe('Router', () => {
124
124
  })
125
125
 
126
126
  it('forward server with connections', async () => {
127
- connections.set(createRandomDhtAddress(), createMockDhtNodeRpcRemote(peerDescriptor2))
127
+ connections.set(randomDhtAddress(), createMockDhtNodeRpcRemote(peerDescriptor2))
128
128
  const ack = await rpcCommunicator.callRpcMethod('forwardMessage', routedMessage) as RouteMessageAck
129
129
  expect(ack.error).toBeUndefined()
130
130
  })
@@ -1,10 +1,10 @@
1
1
  import { v4 } from 'uuid'
2
2
  import { RoutingMode, RoutingSession } from '../../src/dht/routing/RoutingSession'
3
- import { Message, PeerDescriptor, RouteMessageWrapper } from '../../src/proto/packages/dht/protos/DhtRpc'
3
+ import { Message, PeerDescriptor, RouteMessageWrapper } from '../../generated/packages/dht/protos/DhtRpc'
4
4
  import { createMockPeerDescriptor, createWrappedClosestPeersRequest } from '../utils/utils'
5
5
  import { DhtNodeRpcRemote } from '../../src/dht/DhtNodeRpcRemote'
6
6
  import { RoutingRpcCommunicator } from '../../src/transport/RoutingRpcCommunicator'
7
- import { DhtAddress, getNodeIdFromPeerDescriptor } from '../../src/identifiers'
7
+ import { DhtAddress, toNodeId } from '../../src/identifiers'
8
8
  import { MockRpcCommunicator } from '../utils/mock/MockRpcCommunicator'
9
9
  import { RoutingTablesCache } from '../../src/dht/routing/RoutingTablesCache'
10
10
 
@@ -63,17 +63,24 @@ describe('RoutingSession', () => {
63
63
  })
64
64
 
65
65
  it('findMoreContacts', () => {
66
- connections.set(getNodeIdFromPeerDescriptor(mockPeerDescriptor2), createMockDhtNodeRpcRemote(mockPeerDescriptor2))
66
+ connections.set(toNodeId(mockPeerDescriptor2), createMockDhtNodeRpcRemote(mockPeerDescriptor2))
67
67
  const contacts = session.updateAndGetRoutablePeers()
68
68
  expect(contacts.length).toBe(1)
69
69
  })
70
70
 
71
71
  it('findMoreContacts peer disconnects', () => {
72
- connections.set(getNodeIdFromPeerDescriptor(mockPeerDescriptor2), createMockDhtNodeRpcRemote(mockPeerDescriptor2))
72
+ connections.set(toNodeId(mockPeerDescriptor2), createMockDhtNodeRpcRemote(mockPeerDescriptor2))
73
73
  expect(session.updateAndGetRoutablePeers().length).toBe(1)
74
- connections.delete(getNodeIdFromPeerDescriptor(mockPeerDescriptor2))
75
- routingTablesCache.onNodeDisconnected(getNodeIdFromPeerDescriptor(mockPeerDescriptor2))
74
+ connections.delete(toNodeId(mockPeerDescriptor2))
75
+ routingTablesCache.onNodeDisconnected(toNodeId(mockPeerDescriptor2))
76
76
  expect(session.updateAndGetRoutablePeers().length).toBe(0)
77
77
  })
78
78
 
79
+ it('recalculates Routing Table if it is empty', () => {
80
+ connections.set(toNodeId(mockPeerDescriptor2), createMockDhtNodeRpcRemote(mockPeerDescriptor2))
81
+ expect(session.updateAndGetRoutablePeers().length).toBe(1)
82
+ routingTablesCache.onNodeDisconnected(toNodeId(mockPeerDescriptor2))
83
+ expect(session.updateAndGetRoutablePeers().length).toBe(1)
84
+ })
85
+
79
86
  })
@@ -1,9 +1,9 @@
1
1
  import { SortedContactList } from '../../src/dht/contact/SortedContactList'
2
- import { DhtAddress, DhtAddressRaw, createRandomDhtAddress, getDhtAddressFromRaw } from '../../src/identifiers'
2
+ import { DhtAddress, DhtAddressRaw, randomDhtAddress, toDhtAddress } from '../../src/identifiers'
3
3
 
4
4
  const createItem = (nodeId: DhtAddressRaw): { getNodeId: () => DhtAddress } => {
5
5
  return {
6
- getNodeId: () => getDhtAddressFromRaw(nodeId)
6
+ getNodeId: () => toDhtAddress(nodeId)
7
7
  }
8
8
  }
9
9
 
@@ -38,7 +38,7 @@ describe('SortedContactList', () => {
38
38
  expect(list.getSize()).toEqual(3)
39
39
  expect(list.getClosestContacts()).toEqual([item1, item2, item3])
40
40
  expect(list.getContactIds()).toEqual([item1.getNodeId(), item2.getNodeId(), item3.getNodeId()])
41
- expect(onContactRemoved).toBeCalledWith(item4)
41
+ expect(onContactRemoved).toHaveBeenCalledWith(item4)
42
42
  expect(list.getContact(item4.getNodeId())).toBeFalsy()
43
43
  })
44
44
 
@@ -46,7 +46,7 @@ describe('SortedContactList', () => {
46
46
  const list = new SortedContactList({ referenceId: item0.getNodeId(), maxSize: 8, allowToContainReferenceId: false })
47
47
  const onContactRemoved = jest.fn()
48
48
  list.on('contactRemoved', onContactRemoved)
49
- list.removeContact(createRandomDhtAddress())
49
+ list.removeContact(randomDhtAddress())
50
50
  list.addContact(item3)
51
51
  list.removeContact(item3.getNodeId())
52
52
  list.addContact(item4)
@@ -58,10 +58,10 @@ describe('SortedContactList', () => {
58
58
  expect(list.getContact(item2.getNodeId())).toBeFalsy()
59
59
  expect(list.getContactIds()).toEqual(list.getContactIds().sort(list.compareIds))
60
60
  expect(list.getClosestContacts()).toEqual([item1, item3, item4])
61
- const ret = list.removeContact(getDhtAddressFromRaw(Buffer.from([0, 0, 0, 6])))
61
+ const ret = list.removeContact(toDhtAddress(Buffer.from([0, 0, 0, 6])))
62
62
  expect(ret).toEqual(false)
63
63
  list.removeContact(item3.getNodeId())
64
- list.removeContact(createRandomDhtAddress())
64
+ list.removeContact(randomDhtAddress())
65
65
  expect(list.getClosestContacts()).toEqual([item1, item4])
66
66
  expect(onContactRemoved).toHaveBeenNthCalledWith(1, item3)
67
67
  expect(onContactRemoved).toHaveBeenNthCalledWith(2, item2)
@@ -106,9 +106,9 @@ describe('SortedContactList', () => {
106
106
  list.on('contactAdded', onContactAdded)
107
107
  list.addContact(item1)
108
108
  list.addContact(item2)
109
- expect(onContactAdded).toBeCalledTimes(2)
109
+ expect(onContactAdded).toHaveBeenCalledTimes(2)
110
110
  list.addContact(item3)
111
- expect(onContactAdded).toBeCalledTimes(2)
111
+ expect(onContactAdded).toHaveBeenCalledTimes(2)
112
112
  expect(list.getClosestContacts().length).toEqual(2)
113
113
  })
114
114
 
@@ -1,26 +1,26 @@
1
- import { wait, waitForCondition } from '@streamr/utils'
1
+ import { wait, until } from '@streamr/utils'
2
2
  import { range, without } from 'lodash'
3
3
  import { getClosestNodes } from '../../src/dht/contact/getClosestNodes'
4
4
  import { StoreManager } from '../../src/dht/store/StoreManager'
5
5
  import {
6
6
  DhtAddress,
7
- createRandomDhtAddress,
8
- getDhtAddressFromRaw,
9
- getRawFromDhtAddress
7
+ randomDhtAddress,
8
+ toDhtAddress,
9
+ toDhtAddressRaw
10
10
  } from '../../src/identifiers'
11
- import { PeerDescriptor, ReplicateDataRequest } from '../../src/proto/packages/dht/protos/DhtRpc'
11
+ import { PeerDescriptor, ReplicateDataRequest } from '../../generated/packages/dht/protos/DhtRpc'
12
12
  import { createMockPeerDescriptor } from '../utils/utils'
13
13
 
14
14
  const NODE_COUNT = 10
15
15
 
16
16
  const DATA_ENTRY = {
17
- key: getRawFromDhtAddress(createRandomDhtAddress()),
18
- creator: getRawFromDhtAddress(createRandomDhtAddress())
17
+ key: toDhtAddressRaw(randomDhtAddress()),
18
+ creator: toDhtAddressRaw(randomDhtAddress())
19
19
  }
20
20
  const ALL_NODES = range(NODE_COUNT).map(() => createMockPeerDescriptor())
21
21
 
22
22
  const getNodeCloseToData = (distanceIndex: number) => {
23
- const dataKey = getDhtAddressFromRaw(DATA_ENTRY.key)
23
+ const dataKey = toDhtAddress(DATA_ENTRY.key)
24
24
  return getClosestNodes(dataKey, ALL_NODES)[distanceIndex]
25
25
  }
26
26
 
@@ -42,7 +42,7 @@ describe('StoreManager', () => {
42
42
  recursiveOperationManager: undefined as any,
43
43
  localPeerDescriptor,
44
44
  localDataStore: {
45
- keys: () => [getDhtAddressFromRaw(DATA_ENTRY.key)],
45
+ keys: () => [toDhtAddress(DATA_ENTRY.key)],
46
46
  values: () => [DATA_ENTRY],
47
47
  setAllEntriesAsStale
48
48
  } as any,
@@ -67,10 +67,10 @@ describe('StoreManager', () => {
67
67
  setAllEntriesAsStale
68
68
  )
69
69
  manager.onContactAdded(getNodeCloseToData(2))
70
- await waitForCondition(() => replicateData.mock.calls.length === 1)
70
+ await until(() => replicateData.mock.calls.length === 1)
71
71
  expect(replicateData).toHaveBeenCalledWith({
72
72
  entry: DATA_ENTRY
73
- })
73
+ }, true)
74
74
  expect(setAllEntriesAsStale).not.toHaveBeenCalled()
75
75
  })
76
76
 
@@ -123,7 +123,7 @@ describe('StoreManager', () => {
123
123
  await wait(50)
124
124
  expect(replicateData).not.toHaveBeenCalled()
125
125
  expect(setAllEntriesAsStale).toHaveBeenCalledTimes(1)
126
- expect(setAllEntriesAsStale).toHaveBeenCalledWith(getDhtAddressFromRaw(DATA_ENTRY.key))
126
+ expect(setAllEntriesAsStale).toHaveBeenCalledWith(toDhtAddress(DATA_ENTRY.key))
127
127
  })
128
128
 
129
129
  it('this node is within redundancy factor, the node has less than redundancyFactor neighbors', async () => {
@@ -1,7 +1,7 @@
1
1
  import { range } from 'lodash'
2
2
  import { StoreRpcLocal } from '../../src/dht/store/StoreRpcLocal'
3
- import { areEqualPeerDescriptors, createRandomDhtAddress, DhtAddress, getDhtAddressFromRaw, getRawFromDhtAddress } from '../../src/identifiers'
4
- import { DataEntry, PeerDescriptor, StoreDataRequest } from '../../src/proto/packages/dht/protos/DhtRpc'
3
+ import { areEqualPeerDescriptors, randomDhtAddress, DhtAddress, toDhtAddress, toDhtAddressRaw } from '../../src/identifiers'
4
+ import { DataEntry, PeerDescriptor, StoreDataRequest } from '../../generated/packages/dht/protos/DhtRpc'
5
5
  import { createMockPeerDescriptor } from '../utils/utils'
6
6
  import { getClosestNodes } from '../../src/dht/contact/getClosestNodes'
7
7
  import { wait } from '@streamr/utils'
@@ -10,14 +10,14 @@ describe('StoreRpcLocal', () => {
10
10
 
11
11
  const NODE_COUNT = 5
12
12
  const DATA_ENTRY = {
13
- key: getRawFromDhtAddress(createRandomDhtAddress()),
14
- creator: getRawFromDhtAddress(createRandomDhtAddress())
13
+ key: toDhtAddressRaw(randomDhtAddress()),
14
+ creator: toDhtAddressRaw(randomDhtAddress())
15
15
  }
16
16
 
17
17
  const ALL_NODES = range(NODE_COUNT).map(() => createMockPeerDescriptor())
18
18
 
19
19
  const getNodeCloseToData = (distanceIndex: number) => {
20
- const dataKey = getDhtAddressFromRaw(DATA_ENTRY.key)
20
+ const dataKey = toDhtAddress(DATA_ENTRY.key)
21
21
  return getClosestNodes(dataKey, ALL_NODES)[distanceIndex]
22
22
  }
23
23
 
@@ -41,7 +41,7 @@ describe('StoreRpcLocal', () => {
41
41
  } as any,
42
42
  localPeerDescriptor,
43
43
  replicateDataToContact,
44
- getStorers: () => getClosestNodes(getDhtAddressFromRaw(DATA_ENTRY.key), ALL_NODES)
44
+ getStorers: () => getClosestNodes(toDhtAddress(DATA_ENTRY.key), ALL_NODES)
45
45
  })
46
46
  })
47
47
 
@@ -76,7 +76,7 @@ describe('StoreRpcLocal', () => {
76
76
  } as any,
77
77
  localPeerDescriptor,
78
78
  replicateDataToContact,
79
- getStorers: () => getClosestNodes(getDhtAddressFromRaw(DATA_ENTRY.key), ALL_NODES)
79
+ getStorers: () => getClosestNodes(toDhtAddress(DATA_ENTRY.key), ALL_NODES)
80
80
  })
81
81
  })
82
82
 
@@ -110,7 +110,7 @@ describe('StoreRpcLocal', () => {
110
110
  } as any,
111
111
  localPeerDescriptor,
112
112
  replicateDataToContact,
113
- getStorers: () => getClosestNodes(getDhtAddressFromRaw(DATA_ENTRY.key), ALL_NODES)
113
+ getStorers: () => getClosestNodes(toDhtAddress(DATA_ENTRY.key), ALL_NODES)
114
114
  .filter((peerDescriptor) => !areEqualPeerDescriptors(peerDescriptor, localPeerDescriptor))
115
115
  })
116
116
  })
@@ -147,7 +147,7 @@ describe('StoreRpcLocal', () => {
147
147
  } as any,
148
148
  localPeerDescriptor,
149
149
  replicateDataToContact,
150
- getStorers: () => getClosestNodes(getDhtAddressFromRaw(DATA_ENTRY.key), ALL_NODES)
150
+ getStorers: () => getClosestNodes(toDhtAddress(DATA_ENTRY.key), ALL_NODES)
151
151
  })
152
152
  })
153
153
 
@@ -0,0 +1,29 @@
1
+ import { waitForEvent3 } from '@streamr/utils'
2
+ import { NodeWebrtcConnection } from '../../src/connection/webrtc/NodeWebrtcConnection'
3
+ import { createMockPeerDescriptor } from '../utils/utils'
4
+ import { ConnectionEvents } from '../../src/connection/IConnection'
5
+
6
+ describe('WebrtcConnection', () => {
7
+
8
+ let connection: NodeWebrtcConnection
9
+
10
+ beforeEach(() => {
11
+ const peerDescriptor = createMockPeerDescriptor()
12
+ connection = new NodeWebrtcConnection({
13
+ remotePeerDescriptor: peerDescriptor
14
+ })
15
+ })
16
+
17
+ afterEach(() => {
18
+ connection.close(true)
19
+ })
20
+
21
+ it('Disconnects early if remote descriptor is not set', async () => {
22
+ connection.start(true)
23
+ await waitForEvent3<ConnectionEvents>(connection as any, 'disconnected', 5001, (_graceful: boolean, _code: number, reason: string) => {
24
+ expect(reason).toBe('timed out due to remote descriptor not being set')
25
+ return true
26
+ })
27
+ })
28
+
29
+ })
@@ -1,6 +1,6 @@
1
1
  /* eslint-disable max-len */
2
2
  import { WebsocketClientConnector } from '../../src/connection/websocket/WebsocketClientConnector'
3
- import { NodeType } from '../../src/proto/packages/dht/protos/DhtRpc'
3
+ import { NodeType } from '../../generated/packages/dht/protos/DhtRpc'
4
4
  import { MockConnection } from '../utils/mock/MockConnection'
5
5
  import { MockRpcCommunicator } from '../utils/mock/MockRpcCommunicator'
6
6
  import { createMockPeerDescriptor } from '../utils/utils'
@@ -1,6 +1,6 @@
1
1
  /* eslint-disable max-len */
2
2
  import { WebsocketServerConnector } from '../../src/connection/websocket/WebsocketServerConnector'
3
- import { NodeType } from '../../src/proto/packages/dht/protos/DhtRpc'
3
+ import { NodeType } from '../../generated/packages/dht/protos/DhtRpc'
4
4
  import { MockConnection } from '../utils/mock/MockConnection'
5
5
  import { MockRpcCommunicator } from '../utils/mock/MockRpcCommunicator'
6
6
  import { createMockPeerDescriptor } from '../utils/utils'
@@ -1,11 +1,11 @@
1
- import { ipv4ToNumber, waitForCondition } from '@streamr/utils'
1
+ import { ipv4ToNumber, until } from '@streamr/utils'
2
2
  import { EventEmitter } from 'eventemitter3'
3
3
  import { once } from 'events'
4
4
  import { Server as HttpServer, createServer as createHttpServer } from 'http'
5
5
  import { server as WsServer } from 'websocket'
6
6
  import { CONNECTIVITY_CHECKER_SERVICE_ID } from '../../src/connection/connectivityChecker'
7
7
  import { attachConnectivityRequestHandler } from '../../src/connection/connectivityRequestHandler'
8
- import { Message } from '../../src/proto/packages/dht/protos/DhtRpc'
8
+ import { Message } from '../../generated/packages/dht/protos/DhtRpc'
9
9
  import { LOCAL_PROTOCOL_VERSION } from '../../src/helpers/version'
10
10
 
11
11
  const HOST = '127.0.0.1'
@@ -48,7 +48,7 @@ describe('connectivityRequestHandler', () => {
48
48
  }
49
49
  connection.emit('data', Message.toBinary(request))
50
50
 
51
- await waitForCondition(() => connection.send.mock.calls.length > 0)
51
+ await until(() => connection.send.mock.calls.length > 0)
52
52
 
53
53
  const receivedMessage = Message.fromBinary(connection.send.mock.calls[0][0])
54
54
  expect(receivedMessage).toEqual({
@@ -62,7 +62,7 @@ describe('connectivityRequestHandler', () => {
62
62
  tls: false
63
63
  },
64
64
  ipAddress: ipv4ToNumber(HOST),
65
- version: LOCAL_PROTOCOL_VERSION
65
+ protocolVersion: LOCAL_PROTOCOL_VERSION
66
66
  },
67
67
  oneofKind: 'connectivityResponse'
68
68
  },
@@ -83,7 +83,7 @@ describe('connectivityRequestHandler', () => {
83
83
  }
84
84
  connection.emit('data', Message.toBinary(request))
85
85
 
86
- await waitForCondition(() => connection.send.mock.calls.length > 0)
86
+ await until(() => connection.send.mock.calls.length > 0)
87
87
 
88
88
  const receivedMessage = Message.fromBinary(connection.send.mock.calls[0][0])
89
89
  expect(receivedMessage).toEqual({
@@ -92,7 +92,7 @@ describe('connectivityRequestHandler', () => {
92
92
  host: HOST,
93
93
  natType: 'unknown',
94
94
  ipAddress: ipv4ToNumber(HOST),
95
- version: LOCAL_PROTOCOL_VERSION
95
+ protocolVersion: LOCAL_PROTOCOL_VERSION
96
96
  },
97
97
  oneofKind: 'connectivityResponse'
98
98
  },
@@ -1,8 +1,8 @@
1
1
  import { ipv4ToNumber } from '@streamr/utils'
2
2
  import { createPeerDescriptor } from '../../src/helpers/createPeerDescriptor'
3
3
  import { isBrowserEnvironment } from '../../src/helpers/browser/isBrowserEnvironment'
4
- import { NodeType } from '../../src/proto/packages/dht/protos/DhtRpc'
5
- import { createRandomDhtAddress, getRawFromDhtAddress } from '../../src/identifiers'
4
+ import { NodeType } from '../../generated/packages/dht/protos/DhtRpc'
5
+ import { randomDhtAddress, toDhtAddressRaw } from '../../src/identifiers'
6
6
  import { getRandomRegion } from '../../dist/src/connection/simulator/pings'
7
7
 
8
8
  const IP_ADDRESS = '1.2.3.4'
@@ -52,13 +52,13 @@ describe('createPeerDescriptor', () => {
52
52
  })
53
53
 
54
54
  it('explicit nodeId', () => {
55
- const nodeId = createRandomDhtAddress()
55
+ const nodeId = randomDhtAddress()
56
56
  const connectivityResponse = {
57
57
  ipAddress: ipv4ToNumber(IP_ADDRESS)
58
58
  } as any
59
59
  const peerDescriptor = createPeerDescriptor(connectivityResponse, region, nodeId)
60
60
  expect(peerDescriptor).toEqual({
61
- nodeId: getRawFromDhtAddress(nodeId),
61
+ nodeId: toDhtAddressRaw(nodeId),
62
62
  type: isBrowserEnvironment() ? NodeType.BROWSER : NodeType.NODEJS,
63
63
  ipAddress: ipv4ToNumber(IP_ADDRESS),
64
64
  publicKey: expect.any(Uint8Array),
@@ -13,4 +13,22 @@ describe('custom matchers', () => {
13
13
  it('no match', () => {
14
14
  expect(createMockPeerDescriptor()).not.toEqualPeerDescriptor(createMockPeerDescriptor())
15
15
  })
16
+
17
+ describe('error message', () => {
18
+
19
+ it('normal', () => {
20
+ const actual = createMockPeerDescriptor()
21
+ const expected = createMockPeerDescriptor()
22
+ expect(() => {
23
+ expect(actual).toEqualPeerDescriptor(expected)
24
+ }).toThrow('PeerDescriptor nodeId values don\'t match')
25
+ })
26
+
27
+ it('inverse', () => {
28
+ const peerDescriptor = createMockPeerDescriptor()
29
+ expect(() => {
30
+ expect(peerDescriptor).not.toEqualPeerDescriptor(peerDescriptor)
31
+ }).toThrow('PeerDescriptors are equal')
32
+ })
33
+ })
16
34
  })
@@ -1,7 +1,7 @@
1
1
  import { range, sampleSize, sortBy } from 'lodash'
2
2
  import { getDistance } from '../../src/dht/PeerManager'
3
3
  import { getClosestNodes } from '../../src/dht/contact/getClosestNodes'
4
- import { DhtAddress, createRandomDhtAddress, getNodeIdFromPeerDescriptor, getRawFromDhtAddress } from '../../src/identifiers'
4
+ import { DhtAddress, randomDhtAddress, toNodeId, toDhtAddressRaw } from '../../src/identifiers'
5
5
  import { createMockPeerDescriptor } from '../utils/utils'
6
6
  import { PeerDescriptor } from '../../src/exports'
7
7
 
@@ -9,8 +9,8 @@ describe('getClosestNodes', () => {
9
9
 
10
10
  it('happy path', () => {
11
11
  const peerDescriptors = range(10).map(() => createMockPeerDescriptor())
12
- const referenceId = createRandomDhtAddress()
13
- const excluded = new Set<DhtAddress>(sampleSize(peerDescriptors.map((n) => getNodeIdFromPeerDescriptor(n), 2)))
12
+ const referenceId = randomDhtAddress()
13
+ const excluded = new Set<DhtAddress>(sampleSize(peerDescriptors.map((n) => toNodeId(n)), 2))
14
14
 
15
15
  const actual = getClosestNodes(
16
16
  referenceId,
@@ -22,8 +22,8 @@ describe('getClosestNodes', () => {
22
22
  )
23
23
 
24
24
  const expected = sortBy(
25
- peerDescriptors.filter((n) => !excluded.has(getNodeIdFromPeerDescriptor(n))),
26
- (peerDescriptor: PeerDescriptor) => getDistance(peerDescriptor.nodeId, getRawFromDhtAddress(referenceId))
25
+ peerDescriptors.filter((n) => !excluded.has(toNodeId(n))),
26
+ (peerDescriptor: PeerDescriptor) => getDistance(peerDescriptor.nodeId, toDhtAddressRaw(referenceId))
27
27
  ).slice(0, 5)
28
28
  expect(actual).toEqual(expected)
29
29
  })