@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
@@ -4,7 +4,7 @@ import {
4
4
  MetricsContext,
5
5
  merge,
6
6
  scheduleAtInterval,
7
- waitForCondition
7
+ until
8
8
  } from '@streamr/utils'
9
9
  import { EventEmitter } from 'eventemitter3'
10
10
  import { sample } from 'lodash'
@@ -15,8 +15,8 @@ import { DefaultConnectorFacade, DefaultConnectorFacadeOptions } from '../connec
15
15
  import { IceServer } from '../connection/webrtc/WebrtcConnector'
16
16
  import { isBrowserEnvironment } from '../helpers/browser/isBrowserEnvironment'
17
17
  import { createPeerDescriptor } from '../helpers/createPeerDescriptor'
18
- import { DhtAddress, KADEMLIA_ID_LENGTH_IN_BYTES, getNodeIdFromPeerDescriptor } from '../identifiers'
19
- import { Any } from '../proto/google/protobuf/any'
18
+ import { DhtAddress, KADEMLIA_ID_LENGTH_IN_BYTES, toNodeId } from '../identifiers'
19
+ import { Any } from '../../generated/google/protobuf/any'
20
20
  import {
21
21
  ClosestPeersRequest,
22
22
  ClosestPeersResponse,
@@ -34,8 +34,8 @@ import {
34
34
  PingRequest,
35
35
  PingResponse,
36
36
  RecursiveOperation
37
- } from '../proto/packages/dht/protos/DhtRpc'
38
- import { ExternalApiRpcClient, StoreRpcClient } from '../proto/packages/dht/protos/DhtRpc.client'
37
+ } from '../../generated/packages/dht/protos/DhtRpc'
38
+ import { ExternalApiRpcClient, StoreRpcClient } from '../../generated/packages/dht/protos/DhtRpc.client'
39
39
  import { ITransport, TransportEvents } from '../transport/ITransport'
40
40
  import { RoutingRpcCommunicator } from '../transport/RoutingRpcCommunicator'
41
41
  import { ServiceID } from '../types/ServiceID'
@@ -79,6 +79,10 @@ export interface DhtNodeOptions {
79
79
  storageRedundancyFactor?: number
80
80
  periodicallyPingNeighbors?: boolean
81
81
  periodicallyPingRingContacts?: boolean
82
+ // Limit for how many new neighbors to ping. If number of neighbors is higher than the limit new neighbors
83
+ // are not pinged when they are added. This is to prevent flooding the network with pings when joining.
84
+ // Enable periodicallyPingNeighbors to eventually ping all neighbors.
85
+ neighborPingLimit?: number
82
86
 
83
87
  transport?: ITransport
84
88
  connectionsView?: ConnectionsView
@@ -104,6 +108,7 @@ export interface DhtNodeOptions {
104
108
  autoCertifierUrl?: string
105
109
  autoCertifierConfigFile?: string
106
110
  geoIpDatabaseFolder?: string
111
+ allowIncomingPrivateConnections?: boolean
107
112
  }
108
113
 
109
114
  type StrictDhtNodeOptions = MarkRequired<DhtNodeOptions,
@@ -242,7 +247,8 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
242
247
  const connectionManager = new ConnectionManager({
243
248
  createConnectorFacade: () => new DefaultConnectorFacade(connectorFacadeOptions),
244
249
  maxConnections: this.options.maxConnections,
245
- metricsContext: this.options.metricsContext
250
+ metricsContext: this.options.metricsContext,
251
+ allowIncomingPrivateConnections: this.options.allowIncomingPrivateConnections ?? false
246
252
  })
247
253
  await connectionManager.start()
248
254
  this.connectionsView = connectionManager
@@ -338,7 +344,8 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
338
344
  connectionLocker: this.connectionLocker,
339
345
  lockId: this.options.serviceId,
340
346
  createDhtNodeRpcRemote: (peerDescriptor: PeerDescriptor) => this.createDhtNodeRpcRemote(peerDescriptor),
341
- hasConnection: (nodeId: DhtAddress) => this.connectionsView!.hasConnection(nodeId)
347
+ hasConnection: (nodeId: DhtAddress) => this.connectionsView!.hasConnection(nodeId),
348
+ neighborPingLimit: this.options.neighborPingLimit
342
349
  })
343
350
  this.peerManager.on('nearbyContactRemoved', (peerDescriptor: PeerDescriptor) => {
344
351
  this.emit('nearbyContactRemoved', peerDescriptor)
@@ -381,7 +388,7 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
381
388
  this.transport!.on('disconnected', (peerDescriptor: PeerDescriptor, gracefulLeave: boolean) => {
382
389
  const isControlLayerNode = (this.connectionLocker !== undefined)
383
390
  if (isControlLayerNode) {
384
- const nodeId = getNodeIdFromPeerDescriptor(peerDescriptor)
391
+ const nodeId = toNodeId(peerDescriptor)
385
392
  if (gracefulLeave) {
386
393
  this.peerManager!.removeContact(nodeId)
387
394
  } else {
@@ -500,7 +507,7 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
500
507
  }
501
508
 
502
509
  public getNodeId(): DhtAddress {
503
- return getNodeIdFromPeerDescriptor(this.localPeerDescriptor!)
510
+ return toNodeId(this.localPeerDescriptor!)
504
511
  }
505
512
 
506
513
  public getNeighborCount(): number {
@@ -524,7 +531,7 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
524
531
 
525
532
  private getConnectedEntryPoints(): PeerDescriptor[] {
526
533
  return this.options.entryPoints !== undefined ? this.options.entryPoints.filter((entryPoint) =>
527
- this.connectionsView!.hasConnection(getNodeIdFromPeerDescriptor(entryPoint))
534
+ this.connectionsView!.hasConnection(toNodeId(entryPoint))
528
535
  ) : []
529
536
  }
530
537
 
@@ -619,7 +626,7 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
619
626
  }
620
627
 
621
628
  public async waitForNetworkConnectivity(): Promise<void> {
622
- await waitForCondition(
629
+ await until(
623
630
  () => this.connectionsView!.getConnectionCount() > 0,
624
631
  this.options.networkConnectivityTimeout,
625
632
  100,
@@ -631,6 +638,17 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
631
638
  return this.peerDiscovery!.isJoinCalled()
632
639
  }
633
640
 
641
+ public getDiagnosticInfo(): Record<string, unknown> {
642
+ return {
643
+ localPeerDescriptor: this.localPeerDescriptor,
644
+ transport: this.transport!.getDiagnosticInfo(),
645
+ router: this.router!.getDiagnosticInfo(),
646
+ neighborCount: this.getNeighborCount(),
647
+ nearbyContactCount: Array.from(this.peerManager!.getNearbyContacts().getAllContactsInUndefinedOrder()).length,
648
+ randomContactCount: this.peerManager!.getRandomContacts().getSize()
649
+ }
650
+ }
651
+
634
652
  public async stop(): Promise<void> {
635
653
  if (this.abortController.signal.aborted || !this.started) {
636
654
  return
@@ -1,7 +1,7 @@
1
1
  import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
2
2
  import { Logger } from '@streamr/utils'
3
- import { DhtAddress, getDhtAddressFromRaw, getNodeIdFromPeerDescriptor } from '../identifiers'
4
- import { Empty } from '../proto/google/protobuf/empty'
3
+ import { DhtAddress, toDhtAddress, toNodeId } from '../identifiers'
4
+ import { Empty } from '../../generated/google/protobuf/empty'
5
5
  import {
6
6
  ClosestPeersRequest,
7
7
  ClosestPeersResponse,
@@ -10,8 +10,8 @@ import {
10
10
  PeerDescriptor,
11
11
  PingRequest,
12
12
  PingResponse
13
- } from '../proto/packages/dht/protos/DhtRpc'
14
- import { IDhtNodeRpc } from '../proto/packages/dht/protos/DhtRpc.server'
13
+ } from '../../generated/packages/dht/protos/DhtRpc'
14
+ import { IDhtNodeRpc } from '../../generated/packages/dht/protos/DhtRpc.server'
15
15
  import { DhtCallContext } from '../rpc-protocol/DhtCallContext'
16
16
  import { RingContacts } from './contact/RingContactList'
17
17
  import { getClosestNodes } from './contact/getClosestNodes'
@@ -19,7 +19,7 @@ import { RingIdRaw } from './contact/ringIdentifiers'
19
19
 
20
20
  interface DhtNodeRpcLocalOptions {
21
21
  peerDiscoveryQueryBatchSize: number
22
- getNeighbors: () => ReadonlyArray<PeerDescriptor>
22
+ getNeighbors: () => readonly PeerDescriptor[]
23
23
  getClosestRingContactsTo: (id: RingIdRaw, limit: number) => RingContacts
24
24
  addContact: (contact: PeerDescriptor) => void
25
25
  removeContact: (nodeId: DhtAddress) => void
@@ -39,7 +39,7 @@ export class DhtNodeRpcLocal implements IDhtNodeRpc {
39
39
  async getClosestPeers(request: ClosestPeersRequest, context: ServerCallContext): Promise<ClosestPeersResponse> {
40
40
  this.options.addContact((context as DhtCallContext).incomingSourceDescriptor!)
41
41
  const peers = getClosestNodes(
42
- getDhtAddressFromRaw(request.nodeId),
42
+ toDhtAddress(request.nodeId),
43
43
  this.options.getNeighbors(),
44
44
  { maxCount: this.options.peerDiscoveryQueryBatchSize }
45
45
  )
@@ -63,7 +63,7 @@ export class DhtNodeRpcLocal implements IDhtNodeRpc {
63
63
  }
64
64
 
65
65
  async ping(request: PingRequest, context: ServerCallContext): Promise<PingResponse> {
66
- logger.trace('received ping request: ' + getNodeIdFromPeerDescriptor((context as DhtCallContext).incomingSourceDescriptor!))
66
+ logger.trace('received ping request: ' + toNodeId((context as DhtCallContext).incomingSourceDescriptor!))
67
67
  setImmediate(() => {
68
68
  this.options.addContact((context as DhtCallContext).incomingSourceDescriptor!)
69
69
  })
@@ -76,7 +76,7 @@ export class DhtNodeRpcLocal implements IDhtNodeRpc {
76
76
  async leaveNotice(context: ServerCallContext): Promise<Empty> {
77
77
  // TODO check signature??
78
78
  const sender = (context as DhtCallContext).incomingSourceDescriptor!
79
- const senderNodeId = getNodeIdFromPeerDescriptor(sender)
79
+ const senderNodeId = toNodeId(sender)
80
80
  logger.trace('received leave notice: ' + senderNodeId)
81
81
  this.options.removeContact(senderNodeId)
82
82
  return {}
@@ -1,14 +1,14 @@
1
1
  import { RpcCommunicator } from '@streamr/proto-rpc'
2
2
  import { Logger } from '@streamr/utils'
3
3
  import { v4 } from 'uuid'
4
- import { DhtAddress, DhtAddressRaw, getNodeIdFromPeerDescriptor, getRawFromDhtAddress } from '../identifiers'
4
+ import { DhtAddress, DhtAddressRaw, toNodeId, toDhtAddressRaw } from '../identifiers'
5
5
  import {
6
6
  ClosestPeersRequest,
7
7
  ClosestRingPeersRequest,
8
8
  PeerDescriptor,
9
9
  PingRequest
10
- } from '../proto/packages/dht/protos/DhtRpc'
11
- import { DhtNodeRpcClient } from '../proto/packages/dht/protos/DhtRpc.client'
10
+ } from '../../generated/packages/dht/protos/DhtRpc'
11
+ import { DhtNodeRpcClient } from '../../generated/packages/dht/protos/DhtRpc.client'
12
12
  import { ServiceID } from '../types/ServiceID'
13
13
  import { RpcRemote } from './contact/RpcRemote'
14
14
  import { DhtCallContext } from '../rpc-protocol/DhtCallContext'
@@ -46,7 +46,7 @@ export class DhtNodeRpcRemote extends RpcRemote<DhtNodeRpcClient> implements KBu
46
46
  async getClosestPeers(nodeId: DhtAddress): Promise<PeerDescriptor[]> {
47
47
  logger.trace(`Requesting getClosestPeers on ${this.serviceId} from ${this.getNodeId()}`)
48
48
  const request: ClosestPeersRequest = {
49
- nodeId: getRawFromDhtAddress(nodeId),
49
+ nodeId: toDhtAddressRaw(nodeId),
50
50
  requestId: v4()
51
51
  }
52
52
  try {
@@ -102,6 +102,6 @@ export class DhtNodeRpcRemote extends RpcRemote<DhtNodeRpcClient> implements KBu
102
102
  }
103
103
 
104
104
  getNodeId(): DhtAddress {
105
- return getNodeIdFromPeerDescriptor(this.getPeerDescriptor())
105
+ return toNodeId(this.getPeerDescriptor())
106
106
  }
107
107
  }
@@ -1,4 +1,4 @@
1
- import { IExternalApiRpc } from '../proto/packages/dht/protos/DhtRpc.server'
1
+ import { IExternalApiRpc } from '../../generated/packages/dht/protos/DhtRpc.server'
2
2
  import {
3
3
  ExternalFetchDataRequest,
4
4
  ExternalFetchDataResponse,
@@ -6,12 +6,12 @@ import {
6
6
  ExternalStoreDataResponse,
7
7
  RecursiveOperation,
8
8
  PeerDescriptor
9
- } from '../proto/packages/dht/protos/DhtRpc'
9
+ } from '../../generated/packages/dht/protos/DhtRpc'
10
10
  import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
11
11
  import { DhtCallContext } from '../rpc-protocol/DhtCallContext'
12
12
  import { RecursiveOperationResult } from './recursive-operation/RecursiveOperationManager'
13
- import { Any } from '../proto/google/protobuf/any'
14
- import { DhtAddress, getNodeIdFromPeerDescriptor, getDhtAddressFromRaw } from '../identifiers'
13
+ import { Any } from '../../generated/google/protobuf/any'
14
+ import { DhtAddress, toNodeId, toDhtAddress } from '../identifiers'
15
15
 
16
16
  interface ExternalApiRpcLocalOptions {
17
17
  executeRecursiveOperation: (
@@ -37,9 +37,9 @@ export class ExternalApiRpcLocal implements IExternalApiRpc {
37
37
  async externalFetchData(request: ExternalFetchDataRequest, context: ServerCallContext): Promise<ExternalFetchDataResponse> {
38
38
  const senderPeerDescriptor = (context as DhtCallContext).incomingSourceDescriptor!
39
39
  const result = await this.options.executeRecursiveOperation(
40
- getDhtAddressFromRaw(request.key),
40
+ toDhtAddress(request.key),
41
41
  RecursiveOperation.FETCH_DATA,
42
- getNodeIdFromPeerDescriptor(senderPeerDescriptor)
42
+ toNodeId(senderPeerDescriptor)
43
43
  )
44
44
  return ExternalFetchDataResponse.create({ entries: result.dataEntries ?? [] })
45
45
  }
@@ -47,9 +47,9 @@ export class ExternalApiRpcLocal implements IExternalApiRpc {
47
47
  async externalStoreData(request: ExternalStoreDataRequest, context: ServerCallContext): Promise<ExternalStoreDataResponse> {
48
48
  const senderPeerDescriptor = (context as DhtCallContext).incomingSourceDescriptor!
49
49
  const result = await this.options.storeDataToDht(
50
- getDhtAddressFromRaw(request.key),
50
+ toDhtAddress(request.key),
51
51
  request.data!,
52
- getNodeIdFromPeerDescriptor(senderPeerDescriptor)
52
+ toNodeId(senderPeerDescriptor)
53
53
  )
54
54
  return ExternalStoreDataResponse.create({
55
55
  storers: result
@@ -1,14 +1,14 @@
1
- import { DhtAddress, getRawFromDhtAddress } from '../identifiers'
2
- import { Any } from '../proto/google/protobuf/any'
3
- import { DataEntry, ExternalFetchDataRequest, ExternalStoreDataRequest, PeerDescriptor } from '../proto/packages/dht/protos/DhtRpc'
4
- import { ExternalApiRpcClient } from '../proto/packages/dht/protos/DhtRpc.client'
1
+ import { DhtAddress, toDhtAddressRaw } from '../identifiers'
2
+ import { Any } from '../../generated/google/protobuf/any'
3
+ import { DataEntry, ExternalFetchDataRequest, ExternalStoreDataRequest, PeerDescriptor } from '../../generated/packages/dht/protos/DhtRpc'
4
+ import { ExternalApiRpcClient } from '../../generated/packages/dht/protos/DhtRpc.client'
5
5
  import { RpcRemote } from './contact/RpcRemote'
6
6
 
7
7
  export class ExternalApiRpcRemote extends RpcRemote<ExternalApiRpcClient> {
8
8
 
9
9
  async externalFetchData(key: DhtAddress): Promise<DataEntry[]> {
10
10
  const request: ExternalFetchDataRequest = {
11
- key: getRawFromDhtAddress(key)
11
+ key: toDhtAddressRaw(key)
12
12
  }
13
13
  const options = this.formDhtRpcOptions({
14
14
  // TODO use options option or named constant?
@@ -24,7 +24,7 @@ export class ExternalApiRpcRemote extends RpcRemote<ExternalApiRpcClient> {
24
24
 
25
25
  async storeData(key: DhtAddress, data: Any): Promise<PeerDescriptor[]> {
26
26
  const request: ExternalStoreDataRequest = {
27
- key: getRawFromDhtAddress(key),
27
+ key: toDhtAddressRaw(key),
28
28
  data
29
29
  }
30
30
  const options = this.formDhtRpcOptions({
@@ -5,10 +5,10 @@ import EventEmitter from 'eventemitter3'
5
5
  import KBucket from 'k-bucket'
6
6
  import { LockID } from '../connection/ConnectionLockStates'
7
7
  import { ConnectionLocker } from '../connection/ConnectionManager'
8
- import { DhtAddress, DhtAddressRaw, getNodeIdFromPeerDescriptor, getRawFromDhtAddress } from '../identifiers'
8
+ import { DhtAddress, DhtAddressRaw, toNodeId, toDhtAddressRaw } from '../identifiers'
9
9
  import {
10
10
  PeerDescriptor
11
- } from '../proto/packages/dht/protos/DhtRpc'
11
+ } from '../../generated/packages/dht/protos/DhtRpc'
12
12
  import { DhtNodeRpcRemote } from './DhtNodeRpcRemote'
13
13
  import { RandomContactList } from './contact/RandomContactList'
14
14
  import { RingContactList } from './contact/RingContactList'
@@ -23,6 +23,7 @@ interface PeerManagerOptions {
23
23
  localNodeId: DhtAddress
24
24
  localPeerDescriptor: PeerDescriptor
25
25
  connectionLocker?: ConnectionLocker
26
+ neighborPingLimit?: number
26
27
  lockId: LockID
27
28
  createDhtNodeRpcRemote: (peerDescriptor: PeerDescriptor) => DhtNodeRpcRemote
28
29
  hasConnection: (nodeId: DhtAddress) => boolean
@@ -77,7 +78,7 @@ export class PeerManager extends EventEmitter<PeerManagerEvents> {
77
78
  super()
78
79
  this.options = options
79
80
  this.neighbors = new KBucket<DhtNodeRpcRemote>({
80
- localNodeId: getRawFromDhtAddress(this.options.localNodeId),
81
+ localNodeId: toDhtAddressRaw(this.options.localNodeId),
81
82
  numberOfNodesPerKBucket: this.options.numberOfNodesPerKBucket,
82
83
  numberOfNodesToPing: this.options.numberOfNodesPerKBucket
83
84
  })
@@ -89,7 +90,7 @@ export class PeerManager extends EventEmitter<PeerManagerEvents> {
89
90
  this.emit('ringContactRemoved', contact.getPeerDescriptor())
90
91
  })
91
92
  this.neighbors.on('ping', (oldContacts: DhtNodeRpcRemote[], newContact: DhtNodeRpcRemote) => this.onKBucketPing(oldContacts, newContact))
92
- this.neighbors.on('removed', (contact: DhtNodeRpcRemote) => this.onKBucketRemoved(getNodeIdFromPeerDescriptor(contact.getPeerDescriptor())))
93
+ this.neighbors.on('removed', (contact: DhtNodeRpcRemote) => this.onKBucketRemoved(toNodeId(contact.getPeerDescriptor())))
93
94
  this.neighbors.on('added', (contact: DhtNodeRpcRemote) => this.onKBucketAdded(contact))
94
95
  this.neighbors.on('updated', () => {
95
96
  // TODO: Update contact info to the connection manager and reconnect
@@ -130,7 +131,7 @@ export class PeerManager extends EventEmitter<PeerManagerEvents> {
130
131
  sortingList.addContacts(oldContacts)
131
132
  const removableNodeId = sortingList.getFurthestContacts(1)[0].getNodeId()
132
133
  this.options.connectionLocker?.weakUnlockConnection(removableNodeId, this.options.lockId)
133
- this.neighbors.remove(getRawFromDhtAddress(removableNodeId))
134
+ this.neighbors.remove(toDhtAddressRaw(removableNodeId))
134
135
  this.neighbors.add(newContact)
135
136
  }
136
137
 
@@ -151,10 +152,11 @@ export class PeerManager extends EventEmitter<PeerManagerEvents> {
151
152
  }
152
153
  if (contact.getNodeId() !== this.options.localNodeId) {
153
154
  const peerDescriptor = contact.getPeerDescriptor()
154
- const nodeId = getNodeIdFromPeerDescriptor(peerDescriptor)
155
+ const nodeId = toNodeId(peerDescriptor)
155
156
  // Important to lock here, before the ping result is known
156
157
  this.options.connectionLocker?.weakLockConnection(nodeId, this.options.lockId)
157
- if (this.options.hasConnection(contact.getNodeId())) {
158
+ if (this.options.hasConnection(contact.getNodeId())
159
+ || (this.options.neighborPingLimit !== undefined && this.neighbors.count() > this.options.neighborPingLimit)) {
158
160
  logger.trace(`Added new contact ${nodeId}`)
159
161
  } else { // open connection by pinging
160
162
  logger.trace('starting ping ' + nodeId)
@@ -188,7 +190,7 @@ export class PeerManager extends EventEmitter<PeerManagerEvents> {
188
190
 
189
191
  private getNearbyActiveContactNotInNeighbors(): DhtNodeRpcRemote | undefined {
190
192
  for (const contactId of this.nearbyContacts.getContactIds()) {
191
- if (!this.neighbors.get(getRawFromDhtAddress(contactId)) && this.activeContacts.has(contactId)) {
193
+ if (!this.neighbors.get(toDhtAddressRaw(contactId)) && this.activeContacts.has(contactId)) {
192
194
  return this.nearbyContacts.getContact(contactId)!
193
195
  }
194
196
  }
@@ -201,22 +203,22 @@ export class PeerManager extends EventEmitter<PeerManagerEvents> {
201
203
  }
202
204
  logger.trace(`Removing contact ${nodeId}`)
203
205
  this.ringContacts.removeContact(this.nearbyContacts.getContact(nodeId))
204
- this.neighbors.remove(getRawFromDhtAddress(nodeId))
206
+ this.neighbors.remove(toDhtAddressRaw(nodeId))
205
207
  this.nearbyContacts.removeContact(nodeId)
206
208
  this.activeContacts.delete(nodeId)
207
209
  this.randomContacts.removeContact(nodeId)
208
210
  }
209
211
 
210
212
  removeNeighbor(nodeId: DhtAddress): void {
211
- this.neighbors.remove(getRawFromDhtAddress(nodeId))
213
+ this.neighbors.remove(toDhtAddressRaw(nodeId))
212
214
  }
213
215
 
214
216
  async pruneOfflineNodes(nodes: DhtNodeRpcRemote[]): Promise<void> {
215
217
  logger.trace('Pruning offline nodes', { nodes: nodes.length })
216
218
  const offlineNeighbors = await pingNodes(nodes, this.activeContacts)
217
219
  offlineNeighbors.forEach((offlineNeighbor) => {
218
- logger.trace('Removing offline node', { node: getNodeIdFromPeerDescriptor(offlineNeighbor) })
219
- this.removeContact(getNodeIdFromPeerDescriptor(offlineNeighbor))
220
+ logger.trace('Removing offline node', { node: toNodeId(offlineNeighbor) })
221
+ this.removeContact(toNodeId(offlineNeighbor))
220
222
  })
221
223
  }
222
224
 
@@ -266,7 +268,7 @@ export class PeerManager extends EventEmitter<PeerManagerEvents> {
266
268
  return this.neighbors.count()
267
269
  }
268
270
 
269
- getNeighbors(): ReadonlyArray<DhtNodeRpcRemote> {
271
+ getNeighbors(): readonly DhtNodeRpcRemote[] {
270
272
  return this.neighbors.toArray()
271
273
  }
272
274
 
@@ -278,7 +280,7 @@ export class PeerManager extends EventEmitter<PeerManagerEvents> {
278
280
  if (this.stopped) {
279
281
  return
280
282
  }
281
- const nodeId = getNodeIdFromPeerDescriptor(peerDescriptor)
283
+ const nodeId = toNodeId(peerDescriptor)
282
284
  if (nodeId !== this.options.localNodeId) {
283
285
  logger.trace(`Adding new contact ${nodeId}`)
284
286
  const remote = this.options.createDhtNodeRpcRemote(peerDescriptor)
@@ -1,5 +1,5 @@
1
- import { PeerDescriptor } from '../../proto/packages/dht/protos/DhtRpc'
2
- import { DhtAddress, getNodeIdFromPeerDescriptor } from '../../identifiers'
1
+ import { PeerDescriptor } from '../../../generated/packages/dht/protos/DhtRpc'
2
+ import { DhtAddress, toNodeId } from '../../identifiers'
3
3
 
4
4
  export class Contact {
5
5
 
@@ -14,6 +14,6 @@ export class Contact {
14
14
  }
15
15
 
16
16
  public getNodeId(): DhtAddress {
17
- return getNodeIdFromPeerDescriptor(this.peerDescriptor)
17
+ return toNodeId(this.peerDescriptor)
18
18
  }
19
19
  }
@@ -1,7 +1,7 @@
1
- import { PeerDescriptor } from '../../proto/packages/dht/protos/DhtRpc'
1
+ import { PeerDescriptor } from '../../../generated/packages/dht/protos/DhtRpc'
2
2
  import { OrderedMap } from '@js-sdsl/ordered-map'
3
3
  import { RingDistance, RingId, RingIdRaw, getLeftDistance, getRightDistance, getRingIdFromPeerDescriptor, getRingIdFromRaw } from './ringIdentifiers'
4
- import { DhtAddress, getNodeIdFromPeerDescriptor } from '../../identifiers'
4
+ import { DhtAddress, toNodeId } from '../../identifiers'
5
5
  import EventEmitter from 'eventemitter3'
6
6
  import { Events } from './ContactList'
7
7
 
@@ -28,7 +28,7 @@ export class RingContactList<C extends { getPeerDescriptor(): PeerDescriptor }>
28
28
 
29
29
  addContact(contact: C): void {
30
30
  const id = getRingIdFromPeerDescriptor(contact.getPeerDescriptor())
31
- if (id === this.referenceId || this.excludedIds.has(getNodeIdFromPeerDescriptor(contact.getPeerDescriptor()))) {
31
+ if (id === this.referenceId || this.excludedIds.has(toNodeId(contact.getPeerDescriptor()))) {
32
32
  return
33
33
  }
34
34
  let elementAdded = false
@@ -2,7 +2,7 @@ import type { ServiceInfo } from '@protobuf-ts/runtime-rpc'
2
2
  import { ClassType, ClientTransport, ProtoRpcClient, RpcCommunicator, toProtoRpcClient } from '@streamr/proto-rpc'
3
3
  import { ConnectionType } from '../../connection/IConnection'
4
4
  import { expectedConnectionType } from '../../helpers/Connectivity'
5
- import { PeerDescriptor } from '../../proto/packages/dht/protos/DhtRpc'
5
+ import { PeerDescriptor } from '../../../generated/packages/dht/protos/DhtRpc'
6
6
  import { DhtRpcOptions } from '../../rpc-protocol/DhtRpcOptions'
7
7
  import { DhtCallContext } from '../../rpc-protocol/DhtCallContext'
8
8
 
@@ -2,7 +2,7 @@ import { Events } from './ContactList'
2
2
  import { sortedIndexBy } from 'lodash'
3
3
  import EventEmitter from 'eventemitter3'
4
4
  import { getDistance } from '../PeerManager'
5
- import { DhtAddress, getRawFromDhtAddress } from '../../identifiers'
5
+ import { DhtAddress, toDhtAddressRaw } from '../../identifiers'
6
6
 
7
7
  // add other getters in the future if needed
8
8
  export type ReadonlySortedContactList<C extends { getNodeId: () => DhtAddress }> =
@@ -42,7 +42,7 @@ export class SortedContactList<C extends { getNodeId: () => DhtAddress }> extend
42
42
 
43
43
  public addContact(contact: C): void {
44
44
  const contactId = contact.getNodeId()
45
- if (this.options.excludedNodeIds !== undefined && this.options.excludedNodeIds.has(contactId)) {
45
+ if (this.options.excludedNodeIds?.has(contactId)) {
46
46
  return
47
47
  }
48
48
  if ((!this.options.allowToContainReferenceId && (this.options.referenceId === contactId)) ||
@@ -120,7 +120,7 @@ export class SortedContactList<C extends { getNodeId: () => DhtAddress }> extend
120
120
  // TODO inline this method?
121
121
  private distanceToReferenceId(id: DhtAddress): number {
122
122
  // TODO maybe this class should store the referenceId also as DhtAddressRaw so that we don't need to convert it here?
123
- return getDistance(getRawFromDhtAddress(this.options.referenceId), getRawFromDhtAddress(id))
123
+ return getDistance(toDhtAddressRaw(this.options.referenceId), toDhtAddressRaw(id))
124
124
  }
125
125
 
126
126
  public removeContact(id: DhtAddress): boolean {
@@ -1,4 +1,4 @@
1
- import { PeerDescriptor } from '../../proto/packages/dht/protos/DhtRpc'
1
+ import { PeerDescriptor } from '../../../generated/packages/dht/protos/DhtRpc'
2
2
 
3
3
  // Notice: you cannot convert RingId to RingIdRaw, because
4
4
  // RingId is only an approximation of the actual value.
@@ -1,7 +1,7 @@
1
1
  import { Gate, Logger, withTimeout } from '@streamr/utils'
2
2
  import { v4 } from 'uuid'
3
- import { DhtAddress, getNodeIdFromPeerDescriptor, getRawFromDhtAddress } from '../../identifiers'
4
- import { PeerDescriptor } from '../../proto/packages/dht/protos/DhtRpc'
3
+ import { DhtAddress, toNodeId, toDhtAddressRaw } from '../../identifiers'
4
+ import { PeerDescriptor } from '../../../generated/packages/dht/protos/DhtRpc'
5
5
  import { DhtNodeRpcRemote } from '../DhtNodeRpcRemote'
6
6
  import { PeerManager, getDistance } from '../PeerManager'
7
7
  import { getClosestNodes } from '../contact/getClosestNodes'
@@ -44,7 +44,7 @@ export class DiscoverySession {
44
44
  if (this.options.abortSignal.aborted || this.doneGate.isOpen()) {
45
45
  return []
46
46
  }
47
- const nodeId = getNodeIdFromPeerDescriptor(peerDescriptor)
47
+ const nodeId = toNodeId(peerDescriptor)
48
48
  logger.trace(`Getting closest neighbors from remote: ${nodeId}`)
49
49
  this.options.contactedPeers.add(nodeId)
50
50
  const remote = this.options.createDhtNodeRpcRemote(peerDescriptor)
@@ -58,7 +58,7 @@ export class DiscoverySession {
58
58
  return
59
59
  }
60
60
  this.ongoingRequests.delete(nodeId)
61
- const targetId = getRawFromDhtAddress(this.options.targetId)
61
+ const targetId = toDhtAddressRaw(this.options.targetId)
62
62
  const oldClosestNeighbor = this.getClosestNeighbor()
63
63
  const oldClosestDistance = getDistance(targetId, oldClosestNeighbor.nodeId)
64
64
  this.addContacts(contacts)
@@ -105,7 +105,7 @@ export class DiscoverySession {
105
105
  if (this.ongoingRequests.size >= this.options.parallelism) {
106
106
  break
107
107
  }
108
- const nodeId = getNodeIdFromPeerDescriptor(node)
108
+ const nodeId = toNodeId(node)
109
109
  this.ongoingRequests.add(nodeId)
110
110
  // eslint-disable-next-line promise/catch-or-return
111
111
  this.fetchClosestNeighborsFromRemote(node)
@@ -3,12 +3,12 @@ import { ConnectionLocker } from '../../connection/ConnectionManager'
3
3
  import {
4
4
  DhtAddress,
5
5
  areEqualPeerDescriptors,
6
- createRandomDhtAddress,
7
- getDhtAddressFromRaw,
8
- getNodeIdFromPeerDescriptor,
9
- getRawFromDhtAddress
6
+ randomDhtAddress,
7
+ toDhtAddress,
8
+ toNodeId,
9
+ toDhtAddressRaw
10
10
  } from '../../identifiers'
11
- import { PeerDescriptor } from '../../proto/packages/dht/protos/DhtRpc'
11
+ import { PeerDescriptor } from '../../../generated/packages/dht/protos/DhtRpc'
12
12
  import { ServiceID } from '../../types/ServiceID'
13
13
  import { DhtNodeRpcRemote } from '../DhtNodeRpcRemote'
14
14
  import { PeerManager } from '../PeerManager'
@@ -31,9 +31,9 @@ interface PeerDiscoveryOptions {
31
31
  }
32
32
 
33
33
  export const createDistantDhtAddress = (address: DhtAddress): DhtAddress => {
34
- const raw = getRawFromDhtAddress(address)
34
+ const raw = toDhtAddressRaw(address)
35
35
  const flipped = raw.map((val) => ~val)
36
- return getDhtAddressFromRaw(flipped)
36
+ return toDhtAddress(flipped)
37
37
  }
38
38
 
39
39
  const logger = new Logger(module)
@@ -82,14 +82,14 @@ export class PeerDiscovery {
82
82
  logger.debug(
83
83
  `Joining ${this.options.serviceId === CONTROL_LAYER_NODE_SERVICE_ID
84
84
  ? 'The Streamr Network' : `Control Layer for ${this.options.serviceId}`}`
85
- + ` via entrypoint ${getNodeIdFromPeerDescriptor(entryPointDescriptor)}`
85
+ + ` via entrypoint ${toNodeId(entryPointDescriptor)}`
86
86
  )
87
87
  if (areEqualPeerDescriptors(entryPointDescriptor, this.options.localPeerDescriptor)) {
88
88
  return
89
89
  }
90
90
  this.options.connectionLocker?.lockConnection(entryPointDescriptor, `${this.options.serviceId}::joinDht`)
91
91
  this.options.peerManager.addContact(entryPointDescriptor)
92
- const targetId = getNodeIdFromPeerDescriptor(this.options.localPeerDescriptor)
92
+ const targetId = toNodeId(this.options.localPeerDescriptor)
93
93
  const sessions = [this.createSession(targetId, contactedPeers)]
94
94
  if (additionalDistantJoin.enabled) {
95
95
  sessions.push(this.createSession(createDistantDhtAddress(targetId), additionalDistantJoin.contactedPeers))
@@ -205,9 +205,9 @@ export class PeerDiscovery {
205
205
  if (this.isStopped()) {
206
206
  return
207
207
  }
208
- const localNodeId = getNodeIdFromPeerDescriptor(this.options.localPeerDescriptor)
208
+ const localNodeId = toNodeId(this.options.localPeerDescriptor)
209
209
  const nodes = this.getClosestNeighbors(localNodeId, this.options.parallelism)
210
- const randomNodes = this.getClosestNeighbors(createRandomDhtAddress(), 1)
210
+ const randomNodes = this.getClosestNeighbors(randomDhtAddress(), 1)
211
211
  await Promise.allSettled([
212
212
  ...nodes.map(async (node: PeerDescriptor) => {
213
213
  const remote = this.options.createDhtNodeRpcRemote(node)
@@ -218,7 +218,7 @@ export class PeerDiscovery {
218
218
  }),
219
219
  ...randomNodes.map(async (node: PeerDescriptor) => {
220
220
  const remote = this.options.createDhtNodeRpcRemote(node)
221
- const contacts = await remote.getClosestPeers(createRandomDhtAddress())
221
+ const contacts = await remote.getClosestPeers(randomDhtAddress())
222
222
  for (const contact of contacts) {
223
223
  this.options.peerManager.addContact(contact)
224
224
  }
@@ -1,7 +1,7 @@
1
1
  import { Gate, Logger, withTimeout } from '@streamr/utils'
2
2
  import { v4 } from 'uuid'
3
- import { DhtAddress, getNodeIdFromPeerDescriptor } from '../../identifiers'
4
- import { PeerDescriptor } from '../../proto/packages/dht/protos/DhtRpc'
3
+ import { DhtAddress, toNodeId } from '../../identifiers'
4
+ import { PeerDescriptor } from '../../../generated/packages/dht/protos/DhtRpc'
5
5
  import { DhtNodeRpcRemote } from '../DhtNodeRpcRemote'
6
6
  import { PeerManager } from '../PeerManager'
7
7
  import { RingContacts } from '../contact/RingContactList'
@@ -47,7 +47,7 @@ export class RingDiscoverySession {
47
47
  if (this.options.abortSignal.aborted || this.doneGate.isOpen()) {
48
48
  return { left: [], right: [] }
49
49
  }
50
- logger.trace(`Getting closest ring peers from contact: ${getNodeIdFromPeerDescriptor(contact.getPeerDescriptor())}`)
50
+ logger.trace(`Getting closest ring peers from contact: ${toNodeId(contact.getPeerDescriptor())}`)
51
51
  this.numContactedPeers++
52
52
  this.options.contactedPeers.add(contact.getNodeId())
53
53
  const returnedContacts = await contact.getClosestRingPeers(this.options.targetId)