@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
@@ -10,9 +10,10 @@ import {
10
10
  LockResponse,
11
11
  Message,
12
12
  PeerDescriptor,
13
- UnlockRequest
14
- } from '../proto/packages/dht/protos/DhtRpc'
15
- import { ConnectionLockRpcClient } from '../proto/packages/dht/protos/DhtRpc.client'
13
+ UnlockRequest,
14
+ SetPrivateRequest
15
+ } from '../../generated/packages/dht/protos/DhtRpc'
16
+ import { ConnectionLockRpcClient } from '../../generated/packages/dht/protos/DhtRpc.client'
16
17
  import { DEFAULT_SEND_OPTIONS, ITransport, SendOptions, TransportEvents } from '../transport/ITransport'
17
18
  import { RoutingRpcCommunicator } from '../transport/RoutingRpcCommunicator'
18
19
  import { ConnectionLockStates, LockID } from './ConnectionLockStates'
@@ -21,7 +22,7 @@ import { ManagedConnection, Events as ManagedConnectionEvents } from './ManagedC
21
22
  import { ConnectionLockRpcRemote } from './ConnectionLockRpcRemote'
22
23
  import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
23
24
  import { ConnectionLockRpcLocal } from './ConnectionLockRpcLocal'
24
- import { DhtAddress, areEqualPeerDescriptors, getNodeIdFromPeerDescriptor } from '../identifiers'
25
+ import { DhtAddress, areEqualPeerDescriptors, toNodeId } from '../identifiers'
25
26
  import { getOfferer } from '../helpers/offering'
26
27
  import { ConnectionsView } from './ConnectionsView'
27
28
  import { OutputBuffer } from './OutputBuffer'
@@ -31,6 +32,7 @@ import { PendingConnection } from './PendingConnection'
31
32
  export interface ConnectionManagerOptions {
32
33
  maxConnections?: number
33
34
  metricsContext: MetricsContext
35
+ allowIncomingPrivateConnections: boolean
34
36
  createConnectorFacade: () => ConnectorFacade
35
37
  }
36
38
 
@@ -108,7 +110,7 @@ const INTERNAL_SERVICE_ID = 'system/connection-manager'
108
110
  // - if ManagedConnection#peerDescriptor is never undefined
109
111
  export const getNodeIdOrUnknownFromPeerDescriptor = (peerDescriptor: PeerDescriptor | undefined): string => {
110
112
  if (peerDescriptor !== undefined) {
111
- return getNodeIdFromPeerDescriptor(peerDescriptor)
113
+ return toNodeId(peerDescriptor)
112
114
  } else {
113
115
  return 'unknown'
114
116
  }
@@ -127,6 +129,7 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
127
129
  private rpcCommunicator?: RoutingRpcCommunicator
128
130
  private disconnectorIntervalRef?: NodeJS.Timeout
129
131
  private state = ConnectionManagerState.IDLE
132
+ private privateClientMode = false
130
133
 
131
134
  constructor(options: ConnectionManagerOptions) {
132
135
  super()
@@ -154,7 +157,18 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
154
157
  removeRemoteLocked: (id: DhtAddress, lockId: LockID) => this.locks.removeRemoteLocked(id, lockId),
155
158
  closeConnection: (peerDescriptor: PeerDescriptor, gracefulLeave: boolean, reason?: string) =>
156
159
  this.closeConnection(peerDescriptor, gracefulLeave, reason),
157
- getLocalPeerDescriptor: () => this.getLocalPeerDescriptor()
160
+ getLocalPeerDescriptor: () => this.getLocalPeerDescriptor(),
161
+ setPrivate: (id: DhtAddress, isPrivate: boolean) => {
162
+ if (!this.options.allowIncomingPrivateConnections) {
163
+ logger.debug(`node ${id} attemted to set a connection as private, but it is not allowed`)
164
+ return
165
+ }
166
+ if (isPrivate) {
167
+ this.locks.addPrivate(id)
168
+ } else {
169
+ this.locks.removePrivate(id)
170
+ }
171
+ }
158
172
  })
159
173
  this.rpcCommunicator.registerRpcMethod(LockRequest, LockResponse, 'lockRequest',
160
174
  (req: LockRequest, context: ServerCallContext) => lockRpcLocal.lockRequest(req, context))
@@ -162,6 +176,8 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
162
176
  (req: UnlockRequest, context: ServerCallContext) => lockRpcLocal.unlockRequest(req, context))
163
177
  this.rpcCommunicator.registerRpcNotification(DisconnectNotice, 'gracefulDisconnect',
164
178
  (req: DisconnectNotice, context: ServerCallContext) => lockRpcLocal.gracefulDisconnect(req, context))
179
+ this.rpcCommunicator.registerRpcNotification(SetPrivateRequest, 'setPrivate',
180
+ (req: SetPrivateRequest, context: ServerCallContext) => lockRpcLocal.setPrivate(req, context))
165
181
  }
166
182
 
167
183
  /*
@@ -173,14 +189,15 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
173
189
  return
174
190
  }
175
191
  const disconnectionCandidates = new SortedContactList<ManagedConnection>({
176
- referenceId: getNodeIdFromPeerDescriptor(this.getLocalPeerDescriptor()),
192
+ referenceId: toNodeId(this.getLocalPeerDescriptor()),
177
193
  maxSize: 100000, // TODO use options option or named constant?
178
194
  allowToContainReferenceId: false
179
195
  })
180
196
  this.endpoints.forEach((endpoint) => {
181
197
  if (endpoint.connected) {
182
198
  const connection = endpoint.connection
183
- if (!this.locks.isLocked(connection.getNodeId()) && Date.now() - connection.getLastUsedTimestamp() > maxIdleTime) {
199
+ const nodeId = connection.getNodeId()
200
+ if (!this.locks.isLocked(nodeId) && !this.locks.isPrivate(nodeId) && Date.now() - connection.getLastUsedTimestamp() > maxIdleTime) {
184
201
  logger.trace('disconnecting in timeout interval: ' + getNodeIdOrUnknownFromPeerDescriptor(connection.getPeerDescriptor()))
185
202
  disconnectionCandidates.addContact(connection)
186
203
  }
@@ -189,7 +206,7 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
189
206
  const disconnectables = disconnectionCandidates.getFurthestContacts(this.endpoints.size - maxConnections)
190
207
  for (const disconnectable of disconnectables) {
191
208
  const peerDescriptor = disconnectable.getPeerDescriptor()!
192
- logger.trace('garbageCollecting ' + getNodeIdFromPeerDescriptor(peerDescriptor))
209
+ logger.trace('garbageCollecting ' + toNodeId(peerDescriptor))
193
210
  this.gracefullyDisconnectAsync(peerDescriptor, DisconnectMode.NORMAL).catch((_e) => { })
194
211
  }
195
212
  }
@@ -273,7 +290,7 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
273
290
  if (this.isConnectionToSelf(peerDescriptor)) {
274
291
  throw new Err.CannotConnectToSelf('Cannot send to self')
275
292
  }
276
- const nodeId = getNodeIdFromPeerDescriptor(peerDescriptor)
293
+ const nodeId = toNodeId(peerDescriptor)
277
294
  logger.trace(`Sending message to: ${nodeId}`)
278
295
  message = {
279
296
  ...message,
@@ -283,7 +300,7 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
283
300
  if (!connection && opts.connect) {
284
301
  connection = this.connectorFacade.createConnection(peerDescriptor)
285
302
  this.onNewConnection(connection)
286
- } else if (!connection) {
303
+ } else if (!connection || (connection && !this.endpoints.get(nodeId)!.connected && !opts.connect)) {
287
304
  throw new Err.SendFailed('No connection to target, connect flag is false')
288
305
  }
289
306
  const binary = Message.toBinary(message)
@@ -291,7 +308,7 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
291
308
  this.metrics.sendMessagesPerSecond.record(1)
292
309
 
293
310
  if (this.endpoints.get(nodeId)!.connected) {
294
- return (connection as ManagedConnection).send(binary)
311
+ (connection as ManagedConnection).send(binary)
295
312
  } else {
296
313
  return (this.endpoints.get(nodeId)! as ConnectingEndpoint).buffer.push(binary)
297
314
  }
@@ -317,7 +334,7 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
317
334
 
318
335
  public hasConnection(nodeId: DhtAddress): boolean {
319
336
  // TODO if we remove filtering in getConnections, this can just be this.connection.has(nodeId)
320
- return this.getConnections().some((c) => getNodeIdFromPeerDescriptor(c) == nodeId)
337
+ return this.getConnections().some((c) => toNodeId(c) == nodeId)
321
338
  }
322
339
 
323
340
  public getConnectionCount(): number {
@@ -341,7 +358,7 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
341
358
  return
342
359
  }
343
360
  if (this.duplicateMessageDetector.isMostLikelyDuplicate(message.messageId)) {
344
- logger.trace('handleMessage filtered duplicate ' + getNodeIdFromPeerDescriptor(message.sourceDescriptor!)
361
+ logger.trace('handleMessage filtered duplicate ' + toNodeId(message.sourceDescriptor!)
345
362
  + ' ' + message.serviceId + ' ' + message.messageId)
346
363
  return
347
364
  }
@@ -349,7 +366,7 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
349
366
  if (message.serviceId === INTERNAL_SERVICE_ID) {
350
367
  this.rpcCommunicator?.handleMessageFromPeer(message)
351
368
  } else {
352
- logger.trace('emit "message" ' + getNodeIdFromPeerDescriptor(message.sourceDescriptor!)
369
+ logger.trace('emit "message" ' + toNodeId(message.sourceDescriptor!)
353
370
  + ' ' + message.serviceId + ' ' + message.messageId)
354
371
  this.emit('message', message)
355
372
  }
@@ -365,6 +382,7 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
365
382
  try {
366
383
  message = Message.fromBinary(data)
367
384
  } catch (e) {
385
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
368
386
  logger.debug(`Parsing incoming data into Message failed: ${e}`)
369
387
  return
370
388
  }
@@ -372,6 +390,7 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
372
390
  try {
373
391
  this.handleMessage(message)
374
392
  } catch (e) {
393
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
375
394
  logger.debug(`Handling incoming data failed: ${e}`)
376
395
  }
377
396
  }
@@ -381,7 +400,7 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
381
400
  managedConnection.on('managedData', this.onData)
382
401
  managedConnection.once('disconnected', (gracefulLeave: boolean) => this.onDisconnected(peerDescriptor, gracefulLeave))
383
402
 
384
- const nodeId = getNodeIdFromPeerDescriptor(peerDescriptor)
403
+ const nodeId = toNodeId(peerDescriptor)
385
404
  const endpoint = this.endpoints.get(nodeId)! as ConnectingEndpoint
386
405
  const outputBuffer = endpoint.buffer
387
406
  const pendingConnection = endpoint.connection
@@ -396,12 +415,15 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
396
415
  connected: true,
397
416
  connection: managedConnection
398
417
  })
418
+ if (this.privateClientMode) {
419
+ this.setPrivateForConnection(peerDescriptor, this.privateClientMode).catch(() => {})
420
+ }
399
421
  this.emit('connected', peerDescriptor)
400
422
  this.onConnectionCountChange()
401
423
  }
402
424
 
403
425
  private onDisconnected(peerDescriptor: PeerDescriptor, gracefulLeave: boolean) {
404
- const nodeId = getNodeIdFromPeerDescriptor(peerDescriptor)
426
+ const nodeId = toNodeId(peerDescriptor)
405
427
  logger.trace(nodeId + ' onDisconnected() gracefulLeave: ' + gracefulLeave)
406
428
  const endpoint = this.endpoints.get(nodeId)
407
429
  if (endpoint) {
@@ -430,10 +452,10 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
430
452
  }
431
453
 
432
454
  private acceptNewConnection(newConnection: PendingConnection): boolean {
433
- const nodeId = getNodeIdFromPeerDescriptor(newConnection.getPeerDescriptor())
455
+ const nodeId = toNodeId(newConnection.getPeerDescriptor())
434
456
  logger.trace(nodeId + ' acceptNewConnection()')
435
457
  if (this.endpoints.has(nodeId)) {
436
- if (getOfferer(getNodeIdFromPeerDescriptor(this.getLocalPeerDescriptor()), nodeId) === 'remote') {
458
+ if (getOfferer(toNodeId(this.getLocalPeerDescriptor()), nodeId) === 'remote') {
437
459
  let buffer: OutputBuffer | undefined
438
460
  const endpoint = this.endpoints.get(nodeId)!
439
461
  // This is a rare occurance but it does happen from time to time.
@@ -467,7 +489,7 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
467
489
  }
468
490
 
469
491
  private async closeConnection(peerDescriptor: PeerDescriptor, gracefulLeave: boolean, reason?: string): Promise<void> {
470
- const nodeId = getNodeIdFromPeerDescriptor(peerDescriptor)
492
+ const nodeId = toNodeId(peerDescriptor)
471
493
  logger.trace(nodeId + ' ' + 'closeConnection() ' + reason)
472
494
  this.locks.clearAllLocks(nodeId)
473
495
  if (this.endpoints.has(nodeId)) {
@@ -483,7 +505,7 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
483
505
  if (this.state === ConnectionManagerState.STOPPED || areEqualPeerDescriptors(targetDescriptor, this.getLocalPeerDescriptor())) {
484
506
  return
485
507
  }
486
- const nodeId = getNodeIdFromPeerDescriptor(targetDescriptor)
508
+ const nodeId = toNodeId(targetDescriptor)
487
509
  const rpcRemote = new ConnectionLockRpcRemote(
488
510
  this.getLocalPeerDescriptor(),
489
511
  targetDescriptor,
@@ -500,7 +522,7 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
500
522
  if (this.state === ConnectionManagerState.STOPPED || areEqualPeerDescriptors(targetDescriptor, this.getLocalPeerDescriptor())) {
501
523
  return
502
524
  }
503
- const nodeId = getNodeIdFromPeerDescriptor(targetDescriptor)
525
+ const nodeId = toNodeId(targetDescriptor)
504
526
  this.locks.removeLocalLocked(nodeId, lockId)
505
527
  const rpcRemote = new ConnectionLockRpcRemote(
506
528
  this.getLocalPeerDescriptor(),
@@ -514,21 +536,55 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
514
536
  }
515
537
 
516
538
  public weakLockConnection(nodeId: DhtAddress, lockId: LockID): void {
517
- if (this.state === ConnectionManagerState.STOPPED || (nodeId === getNodeIdFromPeerDescriptor(this.getLocalPeerDescriptor()))) {
539
+ if (this.state === ConnectionManagerState.STOPPED || (nodeId === toNodeId(this.getLocalPeerDescriptor()))) {
518
540
  return
519
541
  }
520
542
  this.locks.addWeakLocked(nodeId, lockId)
521
543
  }
522
544
 
523
545
  public weakUnlockConnection(nodeId: DhtAddress, lockId: LockID): void {
524
- if (this.state === ConnectionManagerState.STOPPED || (nodeId === getNodeIdFromPeerDescriptor(this.getLocalPeerDescriptor()))) {
546
+ if (this.state === ConnectionManagerState.STOPPED || (nodeId === toNodeId(this.getLocalPeerDescriptor()))) {
525
547
  return
526
548
  }
527
549
  this.locks.removeWeakLocked(nodeId, lockId)
528
550
  }
529
551
 
552
+ public async enablePrivateClientMode(): Promise<void> {
553
+ this.privateClientMode = true
554
+ await Promise.all(Array.from(this.endpoints.values()).map((endpoint) => {
555
+ if (endpoint.connected) {
556
+ const peerDescription = endpoint.connection.getPeerDescriptor()
557
+ return this.setPrivateForConnection(peerDescription!, true)
558
+ }
559
+ }))
560
+ }
561
+
562
+ public async disablePrivateClientMode(): Promise<void> {
563
+ this.privateClientMode = false
564
+ await Promise.all(Array.from(this.endpoints.values()).map((endpoint) => {
565
+ if (endpoint.connected) {
566
+ const peerDescription = endpoint.connection.getPeerDescriptor()
567
+ return this.setPrivateForConnection(peerDescription!, false)
568
+ }
569
+ }))
570
+ }
571
+
572
+ public isPrivateClientMode(): boolean {
573
+ return this.privateClientMode
574
+ }
575
+
576
+ private async setPrivateForConnection(targetDescriptor: PeerDescriptor, isPrivate: boolean): Promise<void> {
577
+ const rpcRemote = new ConnectionLockRpcRemote(
578
+ this.getLocalPeerDescriptor(),
579
+ targetDescriptor,
580
+ this.rpcCommunicator!,
581
+ ConnectionLockRpcClient
582
+ )
583
+ await rpcRemote.setPrivate(isPrivate)
584
+ }
585
+
530
586
  private async gracefullyDisconnectAsync(targetDescriptor: PeerDescriptor, disconnectMode: DisconnectMode): Promise<void> {
531
- const endpoint = this.endpoints.get(getNodeIdFromPeerDescriptor(targetDescriptor))
587
+ const endpoint = this.endpoints.get(toNodeId(targetDescriptor))
532
588
 
533
589
  if (!endpoint) {
534
590
  logger.debug('gracefullyDisconnectedAsync() tried on a non-existing connection')
@@ -565,7 +621,7 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
565
621
  }
566
622
 
567
623
  private async doGracefullyDisconnectAsync(targetDescriptor: PeerDescriptor, disconnectMode: DisconnectMode): Promise<void> {
568
- const nodeId = getNodeIdFromPeerDescriptor(targetDescriptor)
624
+ const nodeId = toNodeId(targetDescriptor)
569
625
  logger.trace(nodeId + ' gracefullyDisconnectAsync()')
570
626
  const rpcRemote = new ConnectionLockRpcRemote(
571
627
  this.getLocalPeerDescriptor(),
@@ -585,11 +641,21 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
585
641
  .map((endpoint) => endpoint)
586
642
  // TODO is this filtering needed? (if it is, should we do the same filtering e.g.
587
643
  // in getConnection() or in other methods which access this.endpoints directly?)
588
- .filter((endpoint) => endpoint.connected)
644
+ .filter((endpoint) => endpoint.connected && !this.locks.isPrivate(toNodeId(endpoint.connection.getPeerDescriptor()!)))
589
645
  .map((endpoint) => endpoint.connection.getPeerDescriptor()!)
590
646
  }
591
647
 
592
648
  private onConnectionCountChange() {
593
649
  this.metrics.connectionAverageCount.record(this.endpoints.size)
594
650
  }
651
+
652
+ public getDiagnosticInfo(): Record<string, unknown> {
653
+ const managedConnections: ManagedConnection[] = Array.from(this.endpoints.values())
654
+ .filter((endpoint) => endpoint.connected)
655
+ .map((endpoint) => endpoint.connection)
656
+ return {
657
+ connections: managedConnections.map((connection) => connection.getDiagnosticInfo()),
658
+ connectionCount: this.endpoints.size
659
+ }
660
+ }
595
661
  }
@@ -1,5 +1,5 @@
1
1
  import { DhtAddress } from '../identifiers'
2
- import { PeerDescriptor } from '../proto/packages/dht/protos/DhtRpc'
2
+ import { PeerDescriptor } from '../../generated/packages/dht/protos/DhtRpc'
3
3
 
4
4
  export interface ConnectionsView {
5
5
  getConnections: () => PeerDescriptor[]
@@ -2,7 +2,7 @@ import { Logger } from '@streamr/utils'
2
2
  import {
3
3
  ConnectivityResponse,
4
4
  PeerDescriptor
5
- } from '../proto/packages/dht/protos/DhtRpc'
5
+ } from '../../generated/packages/dht/protos/DhtRpc'
6
6
  import { ITransport } from '../transport/ITransport'
7
7
  import { PortRange, TlsCertificate } from './ConnectionManager'
8
8
  import { Simulator } from './simulator/Simulator'
@@ -1,16 +1,17 @@
1
1
  import { Logger } from '@streamr/utils'
2
2
  import { EventEmitter } from 'eventemitter3'
3
3
  import { v4 } from 'uuid'
4
- import { Message, HandshakeRequest, HandshakeResponse, PeerDescriptor, HandshakeError } from '../proto/packages/dht/protos/DhtRpc'
4
+ import { Message, HandshakeRequest, HandshakeResponse, PeerDescriptor, HandshakeError } from '../../generated/packages/dht/protos/DhtRpc'
5
5
  import { IConnection } from './IConnection'
6
- import { LOCAL_PROTOCOL_VERSION, isMaybeSupportedVersion } from '../helpers/version'
7
- import { getNodeIdFromPeerDescriptor } from '../identifiers'
6
+ import { LOCAL_PROTOCOL_VERSION, isMaybeSupportedProtocolVersion } from '../helpers/version'
7
+ import { toNodeId } from '../identifiers'
8
8
  import { PendingConnection } from './PendingConnection'
9
+ import { version as applicationVersion } from '../../package.json'
9
10
 
10
11
  const logger = new Logger(module)
11
12
 
12
13
  interface HandshakerEvents {
13
- handshakeRequest: (source: PeerDescriptor, version: string, target?: PeerDescriptor) => void
14
+ handshakeRequest: (source: PeerDescriptor, protocolVersion: string, target?: PeerDescriptor) => void
14
15
  handshakeCompleted: (remote: PeerDescriptor) => void
15
16
  handshakeFailed: (error?: HandshakeError) => void
16
17
  }
@@ -35,7 +36,7 @@ export const createOutgoingHandshaker = (
35
36
  pendingConnection.off('disconnected', managedConnectionDisconnectedListener)
36
37
  }
37
38
  const handshakeFailedListener = (error?: HandshakeError) => {
38
- if (error === HandshakeError.INVALID_TARGET_PEER_DESCRIPTOR || error === HandshakeError.UNSUPPORTED_VERSION) {
39
+ if (error === HandshakeError.INVALID_TARGET_PEER_DESCRIPTOR || error === HandshakeError.UNSUPPORTED_PROTOCOL_VERSION) {
39
40
  pendingConnection.close(false)
40
41
  stopHandshaker()
41
42
  } else {
@@ -43,12 +44,12 @@ export const createOutgoingHandshaker = (
43
44
  }
44
45
  }
45
46
  const handshakeCompletedListener = (peerDescriptor: PeerDescriptor) => {
46
- logger.trace('handshake completed for outgoing connection, ' + getNodeIdFromPeerDescriptor(peerDescriptor))
47
+ logger.trace('handshake completed for outgoing connection, ' + toNodeId(peerDescriptor))
47
48
  pendingConnection.onHandshakeCompleted(connection)
48
49
  stopHandshaker()
49
50
  }
50
51
  const connectedListener = () => handshaker.sendHandshakeRequest(targetPeerDescriptor)
51
- const disconnectedListener = (graceful: boolean) => {
52
+ const disconnectedListener = (graceful: boolean) => {
52
53
  pendingConnection.close(graceful)
53
54
  stopHandshaker()
54
55
  }
@@ -112,7 +113,8 @@ export const createHandshakeRequest = (localPeerDescriptor: PeerDescriptor, remo
112
113
  const outgoingHandshake: HandshakeRequest = {
113
114
  sourcePeerDescriptor: localPeerDescriptor,
114
115
  targetPeerDescriptor: remotePeerDescriptor,
115
- version: LOCAL_PROTOCOL_VERSION
116
+ protocolVersion: LOCAL_PROTOCOL_VERSION,
117
+ applicationVersion
116
118
  }
117
119
  return {
118
120
  serviceId: Handshaker.HANDSHAKER_SERVICE_ID,
@@ -122,13 +124,14 @@ export const createHandshakeRequest = (localPeerDescriptor: PeerDescriptor, remo
122
124
  handshakeRequest: outgoingHandshake
123
125
  }
124
126
  }
125
- }
127
+ }
126
128
 
127
129
  export const createHandshakeResponse = (localPeerDescriptor: PeerDescriptor, error?: HandshakeError): Message => {
128
130
  const outgoingHandshakeResponse: HandshakeResponse = {
129
131
  sourcePeerDescriptor: localPeerDescriptor,
130
132
  error,
131
- version: LOCAL_PROTOCOL_VERSION
133
+ protocolVersion: LOCAL_PROTOCOL_VERSION,
134
+ applicationVersion
132
135
  }
133
136
  return {
134
137
  serviceId: Handshaker.HANDSHAKER_SERVICE_ID,
@@ -165,15 +168,16 @@ export class Handshaker extends EventEmitter<HandshakerEvents> {
165
168
  const handshake = message.body.handshakeRequest
166
169
  this.emit(
167
170
  'handshakeRequest',
168
- handshake.sourcePeerDescriptor!,
169
- handshake.version,
171
+ handshake.sourcePeerDescriptor!,
172
+ handshake.protocolVersion,
170
173
  handshake.targetPeerDescriptor
171
174
  )
172
175
  }
173
176
  if (message.body.oneofKind === 'handshakeResponse') {
174
177
  logger.trace('handshake response received')
175
178
  const handshake = message.body.handshakeResponse
176
- const error = !isMaybeSupportedVersion(handshake.version) ? HandshakeError.UNSUPPORTED_VERSION : handshake.error
179
+ const error = !isMaybeSupportedProtocolVersion(handshake.protocolVersion)
180
+ ? HandshakeError.UNSUPPORTED_PROTOCOL_VERSION : handshake.error
177
181
  if (error !== undefined) {
178
182
  this.emit('handshakeFailed', error)
179
183
  } else {
@@ -183,7 +187,7 @@ export class Handshaker extends EventEmitter<HandshakerEvents> {
183
187
  } catch (err) {
184
188
  logger.debug('error while parsing handshake message', err)
185
189
  }
186
-
190
+
187
191
  }
188
192
 
189
193
  public sendHandshakeRequest(remotePeerDescriptor?: PeerDescriptor): void {
@@ -1,10 +1,10 @@
1
1
  import { ConnectionID, IConnection } from './IConnection'
2
2
  import * as Err from '../helpers/errors'
3
- import { PeerDescriptor } from '../proto/packages/dht/protos/DhtRpc'
3
+ import { PeerDescriptor } from '../../generated/packages/dht/protos/DhtRpc'
4
4
  import { Logger } from '@streamr/utils'
5
5
  import EventEmitter from 'eventemitter3'
6
6
  import { getNodeIdOrUnknownFromPeerDescriptor } from './ConnectionManager'
7
- import { DhtAddress, getNodeIdFromPeerDescriptor } from '../identifiers'
7
+ import { DhtAddress, toNodeId } from '../identifiers'
8
8
  import { createRandomConnectionId } from './Connection'
9
9
 
10
10
  export interface ManagedConnectionEvents {
@@ -26,6 +26,11 @@ export class ManagedConnection extends EventEmitter<ManagedConnectionEvents> {
26
26
  private lastUsedTimestamp: number = Date.now()
27
27
  private replacedAsDuplicate = false
28
28
  private stopped = false
29
+ private openedAt = Date.now()
30
+ private bytesSent = 0
31
+ private bytesReceived = 0
32
+ private messagesSent = 0
33
+ private messagesReceived = 0
29
34
 
30
35
  constructor(peerDescriptor: PeerDescriptor, connection: IConnection) {
31
36
  super()
@@ -34,6 +39,8 @@ export class ManagedConnection extends EventEmitter<ManagedConnectionEvents> {
34
39
 
35
40
  connection.on('data', (bytes: Uint8Array) => {
36
41
  this.lastUsedTimestamp = Date.now()
42
+ this.messagesReceived += 1
43
+ this.bytesReceived += bytes.length
37
44
  this.emit('managedData', bytes, this.getPeerDescriptor()!)
38
45
  })
39
46
  connection.on('disconnected', (gracefulLeave) => this.onDisconnected(gracefulLeave))
@@ -62,6 +69,8 @@ export class ManagedConnection extends EventEmitter<ManagedConnectionEvents> {
62
69
  throw new Err.SendFailed('ManagedConnection is stopped')
63
70
  }
64
71
  this.lastUsedTimestamp = Date.now()
72
+ this.messagesSent += 1
73
+ this.bytesSent += data.length
65
74
  this.connection.send(data)
66
75
  }
67
76
 
@@ -74,7 +83,7 @@ export class ManagedConnection extends EventEmitter<ManagedConnectionEvents> {
74
83
  }
75
84
 
76
85
  getNodeId(): DhtAddress {
77
- return getNodeIdFromPeerDescriptor(this.remotePeerDescriptor)
86
+ return toNodeId(this.remotePeerDescriptor)
78
87
  }
79
88
 
80
89
  getLastUsedTimestamp(): number {
@@ -85,4 +94,20 @@ export class ManagedConnection extends EventEmitter<ManagedConnectionEvents> {
85
94
  return this.remotePeerDescriptor
86
95
  }
87
96
 
97
+ getDiagnosticInfo(): Record<string, unknown> {
98
+ return {
99
+ remotePeerDescriptor: this.remotePeerDescriptor,
100
+ lastUsedTimestamp: this.lastUsedTimestamp,
101
+ replacedAsDuplicate: this.replacedAsDuplicate,
102
+ stopped: this.stopped,
103
+ openedAt: this.openedAt,
104
+ bytesSent: this.bytesSent,
105
+ bytesReceived: this.bytesReceived,
106
+ messagesSent: this.messagesSent,
107
+ messagesReceived: this.messagesReceived
108
+ // Add connection type?
109
+ }
110
+
111
+ }
112
+
88
113
  }
@@ -1,5 +1,5 @@
1
1
  import EventEmitter from 'eventemitter3'
2
- import { PeerDescriptor } from '../proto/packages/dht/protos/DhtRpc'
2
+ import { PeerDescriptor } from '../../generated/packages/dht/protos/DhtRpc'
3
3
  import { Logger, setAbortableTimeout } from '@streamr/utils'
4
4
  import { getNodeIdOrUnknownFromPeerDescriptor } from './ConnectionManager'
5
5
  import { IConnection } from './IConnection'
@@ -4,11 +4,11 @@ import * as Err from '../helpers/errors'
4
4
  import {
5
5
  ConnectivityRequest, ConnectivityResponse,
6
6
  Message, PeerDescriptor
7
- } from '../proto/packages/dht/protos/DhtRpc'
7
+ } from '../../generated/packages/dht/protos/DhtRpc'
8
8
  import { ConnectionEvents, IConnection } from './IConnection'
9
9
  import { WebsocketClientConnection } from './websocket/NodeWebsocketClientConnection'
10
10
  import { connectivityMethodToWebsocketUrl } from './websocket/WebsocketClientConnector'
11
- import { isMaybeSupportedVersion } from '../helpers/version'
11
+ import { isMaybeSupportedProtocolVersion } from '../helpers/version'
12
12
 
13
13
  const logger = new Logger(module)
14
14
 
@@ -79,13 +79,14 @@ export const sendConnectivityRequest = async (
79
79
  if (message.body.oneofKind === 'connectivityResponse') {
80
80
  logger.debug('ConnectivityResponse received: ' + JSON.stringify(Message.toJson(message)))
81
81
  const connectivityResponseMessage = message.body.connectivityResponse
82
- const remoteVersion = connectivityResponseMessage.version
82
+ const remoteProtocolVersion = connectivityResponseMessage.protocolVersion
83
83
  outgoingConnection!.off('data', listener)
84
84
  clearTimeout(timeoutId)
85
- if (isMaybeSupportedVersion(remoteVersion)) {
85
+ if (isMaybeSupportedProtocolVersion(remoteProtocolVersion)) {
86
86
  resolve(connectivityResponseMessage)
87
87
  } else {
88
- reject(`Unsupported version: ${remoteVersion}`)
88
+ // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
89
+ reject(`Unsupported version: ${remoteProtocolVersion}`)
89
90
  }
90
91
  }
91
92
  } catch (err) {
@@ -4,7 +4,7 @@ import {
4
4
  ConnectivityRequest,
5
5
  ConnectivityResponse,
6
6
  Message
7
- } from '../proto/packages/dht/protos/DhtRpc'
7
+ } from '../../generated/packages/dht/protos/DhtRpc'
8
8
  import { NatType } from './ConnectionManager'
9
9
  import { CONNECTIVITY_CHECKER_SERVICE_ID, connectAsync } from './connectivityChecker'
10
10
  import { IConnection } from './IConnection'
@@ -54,7 +54,7 @@ const handleIncomingConnectivityRequest = async (
54
54
  host,
55
55
  natType: NatType.UNKNOWN,
56
56
  ipAddress: ipv4ToNumber(ipAddress),
57
- version: LOCAL_PROTOCOL_VERSION
57
+ protocolVersion: LOCAL_PROTOCOL_VERSION
58
58
  }
59
59
  }
60
60
  if (geoIpLocator !== undefined) {
@@ -97,7 +97,7 @@ const connectivityProbe = async (connectivityRequest: ConnectivityRequest, ipAdd
97
97
  natType: NatType.OPEN_INTERNET,
98
98
  websocket: { host, port: connectivityRequest.port, tls: connectivityRequest.tls },
99
99
  ipAddress: ipv4ToNumber(ipAddress),
100
- version: LOCAL_PROTOCOL_VERSION
100
+ protocolVersion: LOCAL_PROTOCOL_VERSION
101
101
  }
102
102
  } catch (err) {
103
103
  logger.debug('error', { err })
@@ -105,7 +105,7 @@ const connectivityProbe = async (connectivityRequest: ConnectivityRequest, ipAdd
105
105
  host,
106
106
  natType: NatType.UNKNOWN,
107
107
  ipAddress: ipv4ToNumber(ipAddress),
108
- version: LOCAL_PROTOCOL_VERSION
108
+ protocolVersion: LOCAL_PROTOCOL_VERSION
109
109
  }
110
110
  }
111
111
  if (outgoingConnection) {
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable @typescript-eslint/parameter-properties */
2
- import { PeerDescriptor } from '../../proto/packages/dht/protos/DhtRpc'
2
+ import { PeerDescriptor } from '../../../generated/packages/dht/protos/DhtRpc'
3
3
  import { SimulatorConnector } from './SimulatorConnector'
4
4
  import { SimulatorConnection } from './SimulatorConnection'
5
5
  import { ConnectionID } from '../IConnection'
@@ -7,7 +7,7 @@ import { Logger } from '@streamr/utils'
7
7
  import { getRegionDelayMatrix } from './pings'
8
8
  import Heap from 'heap'
9
9
  import { debugVars } from '../../helpers/debugHelpers'
10
- import { DhtAddress, getNodeIdFromPeerDescriptor } from '../../identifiers'
10
+ import { DhtAddress, toNodeId } from '../../identifiers'
11
11
 
12
12
  const logger = new Logger(module)
13
13
 
@@ -90,7 +90,7 @@ class CloseOperation extends SimulatorOperation {
90
90
  export class Simulator {
91
91
  private stopped = false
92
92
  private connectors: Map<DhtAddress, SimulatorConnector> = new Map()
93
- private latencyTable?: Array<Array<number>>
93
+ private latencyTable?: number[][]
94
94
  private associations: Map<ConnectionID, Association> = new Map()
95
95
 
96
96
  private latencyType: LatencyType
@@ -183,15 +183,16 @@ export class Simulator {
183
183
  }
184
184
 
185
185
  public addConnector(connector: SimulatorConnector): void {
186
- this.connectors.set(getNodeIdFromPeerDescriptor(connector.getPeerDescriptor()), connector)
186
+ this.connectors.set(toNodeId(connector.getPeerDescriptor()), connector)
187
187
  }
188
188
 
189
189
  private executeConnectOperation(operation: ConnectOperation): void {
190
- const target = this.connectors.get(getNodeIdFromPeerDescriptor(operation.targetDescriptor))
190
+ const target = this.connectors.get(toNodeId(operation.targetDescriptor))
191
191
 
192
192
  if (!target) {
193
193
  logger.error('Target connector not found when executing connect operation')
194
- return operation.association.connectedCallback!('Target connector not found')
194
+ operation.association.connectedCallback!('Target connector not found')
195
+ return
195
196
  }
196
197
 
197
198
  target.handleIncomingConnection(operation.sourceConnection)
@@ -293,7 +294,7 @@ export class Simulator {
293
294
  logger.error('connect() called on a stopped simulator ' + (new Error().stack))
294
295
  return
295
296
  }
296
- debugVars['simulatorHeapSize'] = this.operationQueue.size()
297
+ debugVars.simulatorHeapSize = this.operationQueue.size()
297
298
 
298
299
  const association = new Association(sourceConnection, undefined, connectedCallback)
299
300
  this.associations.set(sourceConnection.connectionId, association)