@streamr/dht 101.1.2 → 102.0.0-beta.0

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 (346) hide show
  1. package/.eslintignore +1 -1
  2. package/dist/{src/proto → generated}/google/protobuf/any.d.ts +11 -4
  3. package/dist/generated/google/protobuf/any.js.map +1 -0
  4. package/dist/{src/proto → generated}/google/protobuf/empty.d.ts +0 -1
  5. package/dist/generated/google/protobuf/empty.js.map +1 -0
  6. package/dist/{src/proto → generated}/google/protobuf/timestamp.d.ts +9 -3
  7. package/dist/generated/google/protobuf/timestamp.js.map +1 -0
  8. package/dist/{src/proto → generated}/packages/dht/protos/DhtRpc.client.d.ts +9 -0
  9. package/dist/{src/proto → generated}/packages/dht/protos/DhtRpc.client.js +7 -0
  10. package/dist/generated/packages/dht/protos/DhtRpc.client.js.map +1 -0
  11. package/dist/{src/proto → generated}/packages/dht/protos/DhtRpc.d.ts +16 -0
  12. package/dist/{src/proto → generated}/packages/dht/protos/DhtRpc.js +16 -2
  13. package/dist/generated/packages/dht/protos/DhtRpc.js.map +1 -0
  14. package/dist/{src/proto → generated}/packages/dht/protos/DhtRpc.server.d.ts +5 -0
  15. package/dist/generated/packages/dht/protos/DhtRpc.server.js.map +1 -0
  16. package/dist/generated/packages/proto-rpc/protos/ProtoRpc.js.map +1 -0
  17. package/dist/package.json +11 -11
  18. package/dist/src/connection/Connection.d.ts +1 -1
  19. package/dist/src/connection/ConnectionLockRpcLocal.d.ts +5 -3
  20. package/dist/src/connection/ConnectionLockRpcLocal.js +9 -3
  21. package/dist/src/connection/ConnectionLockRpcLocal.js.map +1 -1
  22. package/dist/src/connection/ConnectionLockRpcRemote.d.ts +3 -2
  23. package/dist/src/connection/ConnectionLockRpcRemote.js +14 -3
  24. package/dist/src/connection/ConnectionLockRpcRemote.js.map +1 -1
  25. package/dist/src/connection/ConnectionLockStates.d.ts +5 -0
  26. package/dist/src/connection/ConnectionLockStates.js +14 -0
  27. package/dist/src/connection/ConnectionLockStates.js.map +1 -1
  28. package/dist/src/connection/ConnectionManager.d.ts +8 -1
  29. package/dist/src/connection/ConnectionManager.js +78 -24
  30. package/dist/src/connection/ConnectionManager.js.map +1 -1
  31. package/dist/src/connection/ConnectionsView.d.ts +1 -1
  32. package/dist/src/connection/ConnectorFacade.d.ts +1 -1
  33. package/dist/src/connection/Handshaker.d.ts +1 -1
  34. package/dist/src/connection/Handshaker.js +2 -2
  35. package/dist/src/connection/Handshaker.js.map +1 -1
  36. package/dist/src/connection/ManagedConnection.d.ts +7 -1
  37. package/dist/src/connection/ManagedConnection.js +24 -1
  38. package/dist/src/connection/ManagedConnection.js.map +1 -1
  39. package/dist/src/connection/PendingConnection.d.ts +1 -1
  40. package/dist/src/connection/connectivityChecker.d.ts +1 -1
  41. package/dist/src/connection/connectivityChecker.js +2 -1
  42. package/dist/src/connection/connectivityChecker.js.map +1 -1
  43. package/dist/src/connection/connectivityRequestHandler.js +1 -1
  44. package/dist/src/connection/connectivityRequestHandler.js.map +1 -1
  45. package/dist/src/connection/simulator/Simulator.d.ts +1 -1
  46. package/dist/src/connection/simulator/Simulator.js +2 -2
  47. package/dist/src/connection/simulator/Simulator.js.map +1 -1
  48. package/dist/src/connection/simulator/SimulatorConnection.d.ts +1 -1
  49. package/dist/src/connection/simulator/SimulatorConnection.js +9 -9
  50. package/dist/src/connection/simulator/SimulatorConnection.js.map +1 -1
  51. package/dist/src/connection/simulator/SimulatorConnector.d.ts +1 -1
  52. package/dist/src/connection/simulator/SimulatorConnector.js +4 -4
  53. package/dist/src/connection/simulator/SimulatorConnector.js.map +1 -1
  54. package/dist/src/connection/simulator/SimulatorTransport.d.ts +1 -1
  55. package/dist/src/connection/simulator/SimulatorTransport.js +2 -1
  56. package/dist/src/connection/simulator/SimulatorTransport.js.map +1 -1
  57. package/dist/src/connection/webrtc/NodeWebrtcConnection.d.ts +2 -1
  58. package/dist/src/connection/webrtc/NodeWebrtcConnection.js +13 -6
  59. package/dist/src/connection/webrtc/NodeWebrtcConnection.js.map +1 -1
  60. package/dist/src/connection/webrtc/WebrtcConnector.d.ts +2 -1
  61. package/dist/src/connection/webrtc/WebrtcConnector.js +9 -8
  62. package/dist/src/connection/webrtc/WebrtcConnector.js.map +1 -1
  63. package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.d.ts +3 -3
  64. package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js +4 -4
  65. package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js.map +1 -1
  66. package/dist/src/connection/webrtc/WebrtcConnectorRpcRemote.d.ts +1 -1
  67. package/dist/src/connection/websocket/AbstractWebsocketClientConnection.d.ts +1 -0
  68. package/dist/src/connection/websocket/WebsocketClientConnector.d.ts +1 -1
  69. package/dist/src/connection/websocket/WebsocketClientConnector.js +3 -3
  70. package/dist/src/connection/websocket/WebsocketClientConnector.js.map +1 -1
  71. package/dist/src/connection/websocket/WebsocketClientConnectorRpcLocal.d.ts +3 -3
  72. package/dist/src/connection/websocket/WebsocketClientConnectorRpcLocal.js +1 -1
  73. package/dist/src/connection/websocket/WebsocketClientConnectorRpcLocal.js.map +1 -1
  74. package/dist/src/connection/websocket/WebsocketClientConnectorRpcRemote.d.ts +1 -1
  75. package/dist/src/connection/websocket/WebsocketClientConnectorRpcRemote.js +1 -1
  76. package/dist/src/connection/websocket/WebsocketClientConnectorRpcRemote.js.map +1 -1
  77. package/dist/src/connection/websocket/WebsocketServerConnector.d.ts +1 -1
  78. package/dist/src/connection/websocket/WebsocketServerConnector.js +7 -7
  79. package/dist/src/connection/websocket/WebsocketServerConnector.js.map +1 -1
  80. package/dist/src/dht/DhtNode.d.ts +4 -2
  81. package/dist/src/dht/DhtNode.js +17 -6
  82. package/dist/src/dht/DhtNode.js.map +1 -1
  83. package/dist/src/dht/DhtNodeRpcLocal.d.ts +3 -3
  84. package/dist/src/dht/DhtNodeRpcLocal.js +3 -3
  85. package/dist/src/dht/DhtNodeRpcLocal.js.map +1 -1
  86. package/dist/src/dht/DhtNodeRpcRemote.d.ts +2 -2
  87. package/dist/src/dht/DhtNodeRpcRemote.js +3 -3
  88. package/dist/src/dht/DhtNodeRpcRemote.js.map +1 -1
  89. package/dist/src/dht/ExternalApiRpcLocal.d.ts +3 -3
  90. package/dist/src/dht/ExternalApiRpcLocal.js +3 -3
  91. package/dist/src/dht/ExternalApiRpcLocal.js.map +1 -1
  92. package/dist/src/dht/ExternalApiRpcRemote.d.ts +3 -3
  93. package/dist/src/dht/ExternalApiRpcRemote.js +2 -2
  94. package/dist/src/dht/ExternalApiRpcRemote.js.map +1 -1
  95. package/dist/src/dht/PeerManager.d.ts +1 -1
  96. package/dist/src/dht/PeerManager.js +10 -10
  97. package/dist/src/dht/PeerManager.js.map +1 -1
  98. package/dist/src/dht/contact/Contact.d.ts +1 -1
  99. package/dist/src/dht/contact/Contact.js +1 -1
  100. package/dist/src/dht/contact/Contact.js.map +1 -1
  101. package/dist/src/dht/contact/RingContactList.d.ts +1 -1
  102. package/dist/src/dht/contact/RingContactList.js +1 -1
  103. package/dist/src/dht/contact/RingContactList.js.map +1 -1
  104. package/dist/src/dht/contact/RpcRemote.d.ts +1 -1
  105. package/dist/src/dht/contact/SortedContactList.js +1 -1
  106. package/dist/src/dht/contact/SortedContactList.js.map +1 -1
  107. package/dist/src/dht/contact/ringIdentifiers.d.ts +1 -1
  108. package/dist/src/dht/discovery/DiscoverySession.d.ts +1 -1
  109. package/dist/src/dht/discovery/DiscoverySession.js +3 -3
  110. package/dist/src/dht/discovery/DiscoverySession.js.map +1 -1
  111. package/dist/src/dht/discovery/PeerDiscovery.d.ts +1 -1
  112. package/dist/src/dht/discovery/PeerDiscovery.js +7 -7
  113. package/dist/src/dht/discovery/PeerDiscovery.js.map +1 -1
  114. package/dist/src/dht/discovery/RingDiscoverySession.js +1 -1
  115. package/dist/src/dht/discovery/RingDiscoverySession.js.map +1 -1
  116. package/dist/src/dht/recursive-operation/RecursiveOperationManager.d.ts +1 -1
  117. package/dist/src/dht/recursive-operation/RecursiveOperationManager.js +8 -8
  118. package/dist/src/dht/recursive-operation/RecursiveOperationManager.js.map +1 -1
  119. package/dist/src/dht/recursive-operation/RecursiveOperationRpcLocal.d.ts +2 -2
  120. package/dist/src/dht/recursive-operation/RecursiveOperationRpcLocal.js +2 -2
  121. package/dist/src/dht/recursive-operation/RecursiveOperationRpcLocal.js.map +1 -1
  122. package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.d.ts +2 -2
  123. package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.js +3 -3
  124. package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.js.map +1 -1
  125. package/dist/src/dht/recursive-operation/RecursiveOperationSession.d.ts +1 -1
  126. package/dist/src/dht/recursive-operation/RecursiveOperationSession.js +7 -7
  127. package/dist/src/dht/recursive-operation/RecursiveOperationSession.js.map +1 -1
  128. package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.d.ts +3 -3
  129. package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.js +1 -1
  130. package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.js.map +1 -1
  131. package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcRemote.d.ts +2 -2
  132. package/dist/src/dht/routing/Router.d.ts +4 -1
  133. package/dist/src/dht/routing/Router.js +17 -9
  134. package/dist/src/dht/routing/Router.js.map +1 -1
  135. package/dist/src/dht/routing/RouterRpcLocal.d.ts +2 -2
  136. package/dist/src/dht/routing/RouterRpcLocal.js +5 -5
  137. package/dist/src/dht/routing/RouterRpcLocal.js.map +1 -1
  138. package/dist/src/dht/routing/RouterRpcRemote.d.ts +2 -2
  139. package/dist/src/dht/routing/RouterRpcRemote.js +7 -7
  140. package/dist/src/dht/routing/RouterRpcRemote.js.map +1 -1
  141. package/dist/src/dht/routing/RoutingSession.d.ts +1 -1
  142. package/dist/src/dht/routing/RoutingSession.js +5 -6
  143. package/dist/src/dht/routing/RoutingSession.js.map +1 -1
  144. package/dist/src/dht/routing/getPreviousPeer.d.ts +1 -1
  145. package/dist/src/dht/store/LocalDataStore.d.ts +1 -1
  146. package/dist/src/dht/store/LocalDataStore.js +2 -2
  147. package/dist/src/dht/store/LocalDataStore.js.map +1 -1
  148. package/dist/src/dht/store/StoreManager.d.ts +2 -2
  149. package/dist/src/dht/store/StoreManager.js +8 -8
  150. package/dist/src/dht/store/StoreManager.js.map +1 -1
  151. package/dist/src/dht/store/StoreRpcLocal.d.ts +3 -3
  152. package/dist/src/dht/store/StoreRpcLocal.js +4 -4
  153. package/dist/src/dht/store/StoreRpcLocal.js.map +1 -1
  154. package/dist/src/dht/store/StoreRpcRemote.d.ts +3 -3
  155. package/dist/src/dht/store/StoreRpcRemote.js +7 -4
  156. package/dist/src/dht/store/StoreRpcRemote.js.map +1 -1
  157. package/dist/src/exports.d.ts +2 -2
  158. package/dist/src/exports.js +6 -6
  159. package/dist/src/exports.js.map +1 -1
  160. package/dist/src/helpers/Connectivity.d.ts +1 -1
  161. package/dist/src/helpers/Connectivity.js +1 -1
  162. package/dist/src/helpers/Connectivity.js.map +1 -1
  163. package/dist/src/helpers/createPeerDescriptor.d.ts +1 -1
  164. package/dist/src/helpers/createPeerDescriptor.js +2 -2
  165. package/dist/src/helpers/createPeerDescriptor.js.map +1 -1
  166. package/dist/src/helpers/createPeerDescriptorSignaturePayload.d.ts +1 -1
  167. package/dist/src/helpers/createPeerDescriptorSignaturePayload.js +1 -1
  168. package/dist/src/helpers/createPeerDescriptorSignaturePayload.js.map +1 -1
  169. package/dist/src/helpers/protoClasses.js +1 -1
  170. package/dist/src/helpers/protoClasses.js.map +1 -1
  171. package/dist/src/identifiers.d.ts +5 -5
  172. package/dist/src/identifiers.js +11 -11
  173. package/dist/src/identifiers.js.map +1 -1
  174. package/dist/src/rpc-protocol/DhtCallContext.d.ts +1 -1
  175. package/dist/src/rpc-protocol/DhtRpcOptions.d.ts +1 -1
  176. package/dist/src/transport/ITransport.d.ts +2 -1
  177. package/dist/src/transport/ListeningRpcCommunicator.d.ts +2 -1
  178. package/dist/src/transport/ListeningRpcCommunicator.js +13 -4
  179. package/dist/src/transport/ListeningRpcCommunicator.js.map +1 -1
  180. package/dist/src/transport/RoutingRpcCommunicator.d.ts +1 -1
  181. package/{src/proto → generated}/google/protobuf/any.ts +11 -4
  182. package/{src/proto → generated}/google/protobuf/empty.ts +0 -1
  183. package/{src/proto → generated}/google/protobuf/timestamp.ts +9 -3
  184. package/{src/proto → generated}/packages/dht/protos/DhtRpc.client.ts +12 -0
  185. package/{src/proto → generated}/packages/dht/protos/DhtRpc.server.ts +5 -0
  186. package/{src/proto → generated}/packages/dht/protos/DhtRpc.ts +23 -1
  187. package/package.json +11 -11
  188. package/proto.sh +2 -3
  189. package/protos/DhtRpc.proto +5 -0
  190. package/src/connection/Connection.ts +1 -1
  191. package/src/connection/ConnectionLockRpcLocal.ts +16 -7
  192. package/src/connection/ConnectionLockRpcRemote.ts +18 -6
  193. package/src/connection/ConnectionLockStates.ts +18 -0
  194. package/src/connection/ConnectionManager.ts +92 -26
  195. package/src/connection/ConnectionsView.ts +1 -1
  196. package/src/connection/ConnectorFacade.ts +1 -1
  197. package/src/connection/Handshaker.ts +3 -3
  198. package/src/connection/ManagedConnection.ts +28 -3
  199. package/src/connection/PendingConnection.ts +1 -1
  200. package/src/connection/connectivityChecker.ts +2 -1
  201. package/src/connection/connectivityRequestHandler.ts +1 -1
  202. package/src/connection/simulator/Simulator.ts +4 -4
  203. package/src/connection/simulator/SimulatorConnection.ts +10 -10
  204. package/src/connection/simulator/SimulatorConnector.ts +5 -5
  205. package/src/connection/simulator/SimulatorTransport.ts +3 -2
  206. package/src/connection/webrtc/BrowserWebrtcConnection.ts +10 -1
  207. package/src/connection/webrtc/NodeWebrtcConnection.ts +15 -9
  208. package/src/connection/webrtc/WebrtcConnector.ts +10 -8
  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 +8 -8
  215. package/src/dht/DhtNode.ts +21 -8
  216. package/src/dht/DhtNodeRpcLocal.ts +7 -7
  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 +12 -12
  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 +2 -2
  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 +9 -9
  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/Router.ts +19 -10
  236. package/src/dht/routing/RouterRpcLocal.ts +7 -7
  237. package/src/dht/routing/RouterRpcRemote.ts +9 -9
  238. package/src/dht/routing/RoutingSession.ts +7 -8
  239. package/src/dht/routing/getPreviousPeer.ts +1 -1
  240. package/src/dht/store/LocalDataStore.ts +4 -4
  241. package/src/dht/store/StoreManager.ts +12 -12
  242. package/src/dht/store/StoreRpcLocal.ts +8 -8
  243. package/src/dht/store/StoreRpcRemote.ts +10 -7
  244. package/src/exports.ts +5 -5
  245. package/src/helpers/Connectivity.ts +1 -1
  246. package/src/helpers/createPeerDescriptor.ts +3 -3
  247. package/src/helpers/createPeerDescriptorSignaturePayload.ts +1 -1
  248. package/src/helpers/protoClasses.ts +1 -1
  249. package/src/identifiers.ts +7 -7
  250. package/src/rpc-protocol/DhtCallContext.ts +1 -1
  251. package/src/rpc-protocol/DhtRpcOptions.ts +1 -1
  252. package/src/transport/ITransport.ts +2 -1
  253. package/src/transport/ListeningRpcCommunicator.ts +14 -6
  254. package/src/transport/RoutingRpcCommunicator.ts +2 -2
  255. package/test/benchmark/Find.test.ts +6 -6
  256. package/test/benchmark/KademliaCorrectness.test.ts +5 -5
  257. package/test/benchmark/RingCorrectness.test.ts +5 -5
  258. package/test/benchmark/SortedContactListBenchmark.test.ts +10 -10
  259. package/test/benchmark/hybrid-network-simulation/RingContactList.test.ts +1 -1
  260. package/test/end-to-end/Layer0Webrtc-Layer1.test.ts +6 -6
  261. package/test/end-to-end/Layer0Webrtc.test.ts +6 -6
  262. package/test/end-to-end/RecoveryFromFailedAutoCertification.test.ts +1 -1
  263. package/test/end-to-end/WebsocketConnectionRequest.test.ts +1 -1
  264. package/test/end-to-end/memory-leak.test.ts +4 -4
  265. package/test/integration/ConnectionLocking.test.ts +16 -15
  266. package/test/integration/ConnectionManager.test.ts +62 -6
  267. package/test/integration/ConnectivityChecking.test.ts +2 -1
  268. package/test/integration/DhtJoinPeerDiscovery.test.ts +2 -2
  269. package/test/integration/DhtNode.test.ts +4 -4
  270. package/test/integration/DhtNodeExternalAPI.test.ts +7 -7
  271. package/test/integration/DhtNodeRpcRemote.test.ts +9 -9
  272. package/test/integration/DhtRpc.test.ts +12 -13
  273. package/test/integration/Find.test.ts +5 -5
  274. package/test/integration/GeoIpConnectivityChecking.test.ts +2 -1
  275. package/test/integration/Layer1-scale.test.ts +2 -2
  276. package/test/integration/Mock-Layer1-Layer0.test.ts +6 -6
  277. package/test/integration/MultipleEntryPointJoining.test.ts +1 -1
  278. package/test/integration/ReplicateData.test.ts +10 -11
  279. package/test/integration/RouteMessage.test.ts +9 -9
  280. package/test/integration/RouterRpcRemote.test.ts +7 -7
  281. package/test/integration/SimultaneousConnections.test.ts +13 -12
  282. package/test/integration/Store.test.ts +9 -9
  283. package/test/integration/StoreAndDelete.test.ts +10 -10
  284. package/test/integration/StoreOnDhtWithThreeNodes.test.ts +9 -9
  285. package/test/integration/StoreOnDhtWithTwoNodes.test.ts +7 -7
  286. package/test/integration/StoreRpcRemote.test.ts +10 -10
  287. package/test/integration/WebrtcConnectionManagement.test.ts +4 -3
  288. package/test/integration/WebrtcConnectorRpc.test.ts +9 -9
  289. package/test/integration/Websocket.test.ts +0 -2
  290. package/test/integration/WebsocketClientConnectorRpc.test.ts +8 -8
  291. package/test/integration/WebsocketConnectionManagement.test.ts +8 -9
  292. package/test/integration/{rpc-connections-over-webrpc.test.ts → rpc-connections-over-webrtc.test.ts} +4 -3
  293. package/test/unit/ConnectionManager.test.ts +4 -3
  294. package/test/unit/ConnectivityHelpers.test.ts +1 -1
  295. package/test/unit/DiscoverySession.test.ts +6 -6
  296. package/test/unit/Handshaker.test.ts +1 -1
  297. package/test/unit/ListeningRpcCommunicator.test.ts +52 -0
  298. package/test/unit/LocalDataStore.test.ts +21 -21
  299. package/test/unit/PeerManager.test.ts +13 -13
  300. package/test/unit/PendingConnection.test.ts +1 -1
  301. package/test/unit/ProtobufMessage.test.ts +1 -1
  302. package/test/unit/RandomContactList.test.ts +2 -2
  303. package/test/unit/RecursiveOperationManager.test.ts +3 -3
  304. package/test/unit/RecursiveOperationSession.test.ts +4 -4
  305. package/test/unit/Router.test.ts +6 -6
  306. package/test/unit/RoutingSession.test.ts +6 -6
  307. package/test/unit/SortedContactList.test.ts +5 -5
  308. package/test/unit/StoreManager.test.ts +10 -10
  309. package/test/unit/StoreRpcLocal.test.ts +9 -9
  310. package/test/unit/WebrtcConnection.test.ts +29 -0
  311. package/test/unit/WebsocketClientConnector.test.ts +1 -1
  312. package/test/unit/WebsocketServerConnector.test.ts +1 -1
  313. package/test/unit/connectivityRequestHandler.test.ts +1 -1
  314. package/test/unit/createPeerDescriptor.test.ts +4 -4
  315. package/test/unit/getClosestNodes.test.ts +5 -5
  316. package/test/utils/FakeConnectorFacade.ts +1 -1
  317. package/test/utils/FakeTransport.ts +12 -9
  318. package/test/utils/customMatchers.ts +3 -3
  319. package/test/utils/mock/MockConnectionsView.ts +1 -1
  320. package/test/utils/mock/MockRouter.ts +5 -1
  321. package/test/utils/mock/MockTransport.ts +6 -1
  322. package/test/utils/mock/mockDataEntry.ts +6 -6
  323. package/test/utils/topology.ts +3 -3
  324. package/test/utils/utils.ts +9 -9
  325. package/tsconfig.jest.json +2 -1
  326. package/tsconfig.node.json +1 -0
  327. package/dist/src/proto/google/protobuf/any.js.map +0 -1
  328. package/dist/src/proto/google/protobuf/empty.js.map +0 -1
  329. package/dist/src/proto/google/protobuf/timestamp.js.map +0 -1
  330. package/dist/src/proto/packages/dht/protos/DhtRpc.client.js.map +0 -1
  331. package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +0 -1
  332. package/dist/src/proto/packages/dht/protos/DhtRpc.server.js.map +0 -1
  333. package/dist/src/proto/packages/proto-rpc/protos/ProtoRpc.js.map +0 -1
  334. package/dist/src/proto/tests.d.ts +0 -39
  335. package/dist/src/proto/tests.js +0 -34
  336. package/dist/src/proto/tests.js.map +0 -1
  337. package/src/proto/tests.ts +0 -52
  338. package/test/benchmark/any.test.ts +0 -28
  339. /package/dist/{src/proto → generated}/google/protobuf/any.js +0 -0
  340. /package/dist/{src/proto → generated}/google/protobuf/empty.js +0 -0
  341. /package/dist/{src/proto → generated}/google/protobuf/timestamp.js +0 -0
  342. /package/dist/{src/proto → generated}/packages/dht/protos/DhtRpc.server.js +0 -0
  343. /package/dist/{src/proto → generated}/packages/proto-rpc/protos/ProtoRpc.d.ts +0 -0
  344. /package/dist/{src/proto → generated}/packages/proto-rpc/protos/ProtoRpc.js +0 -0
  345. /package/{src/proto → generated}/packages/proto-rpc/protos/ProtoRpc.ts +0 -0
  346. /package/{src/types/glogal.d.ts → test/types/global.d.ts} +0 -0
@@ -1,17 +1,17 @@
1
1
  import {
2
2
  WebsocketConnectionRequest
3
- } from '../../proto/packages/dht/protos/DhtRpc'
3
+ } from '../../../generated/packages/dht/protos/DhtRpc'
4
4
  import { Logger } from '@streamr/utils'
5
5
  import { RpcRemote } from '../../dht/contact/RpcRemote'
6
- import { WebsocketClientConnectorRpcClient } from '../../proto/packages/dht/protos/DhtRpc.client'
7
- import { getNodeIdFromPeerDescriptor } from '../../identifiers'
6
+ import { WebsocketClientConnectorRpcClient } from '../../../generated/packages/dht/protos/DhtRpc.client'
7
+ import { toNodeId } from '../../identifiers'
8
8
 
9
9
  const logger = new Logger(module)
10
10
 
11
11
  export class WebsocketClientConnectorRpcRemote extends RpcRemote<WebsocketClientConnectorRpcClient> {
12
12
 
13
13
  async requestConnection(): Promise<void> {
14
- logger.trace(`Requesting WebSocket connection from ${getNodeIdFromPeerDescriptor(this.getLocalPeerDescriptor())}`)
14
+ logger.trace(`Requesting WebSocket connection from ${toNodeId(this.getLocalPeerDescriptor())}`)
15
15
  const request: WebsocketConnectionRequest = {}
16
16
  const options = this.formDhtRpcOptions()
17
17
  return this.getClient().requestConnection(request, options)
@@ -2,9 +2,9 @@ import { GeoIpLocator } from '@streamr/geoip-location'
2
2
  import { ListeningRpcCommunicator } from '../../transport/ListeningRpcCommunicator'
3
3
  import { Action, connectivityMethodToWebsocketUrl } from './WebsocketClientConnector'
4
4
  import { WebsocketServer } from './WebsocketServer'
5
- import { areEqualPeerDescriptors, DhtAddress, getNodeIdFromPeerDescriptor } from '../../identifiers'
5
+ import { areEqualPeerDescriptors, DhtAddress, toNodeId } from '../../identifiers'
6
6
  import { AutoCertifierClientFacade } from './AutoCertifierClientFacade'
7
- import { ConnectivityResponse, HandshakeError, PeerDescriptor } from '../../proto/packages/dht/protos/DhtRpc'
7
+ import { ConnectivityResponse, HandshakeError, PeerDescriptor } from '../../../generated/packages/dht/protos/DhtRpc'
8
8
  import { NatType, PortRange, TlsCertificate } from '../ConnectionManager'
9
9
  import { ITransport } from '../../transport/ITransport'
10
10
  import { ipv4ToNumber, Logger, wait } from '@streamr/utils'
@@ -17,7 +17,7 @@ import { shuffle } from 'lodash'
17
17
  import { sendConnectivityRequest } from '../connectivityChecker'
18
18
  import { acceptHandshake, Handshaker, rejectHandshake } from '../Handshaker'
19
19
  import { WebsocketClientConnectorRpcRemote } from './WebsocketClientConnectorRpcRemote'
20
- import { WebsocketClientConnectorRpcClient } from '../../proto/packages/dht/protos/DhtRpc.client'
20
+ import { WebsocketClientConnectorRpcClient } from '../../../generated/packages/dht/protos/DhtRpc.client'
21
21
  import { WebsocketServerStartError } from '../../helpers/errors'
22
22
  import * as Err from '../../helpers/errors'
23
23
  import { expectedConnectionType } from '../../helpers/Connectivity'
@@ -126,7 +126,7 @@ export class WebsocketServerConnector {
126
126
  remoteVersion: string,
127
127
  targetPeerDescriptor?: PeerDescriptor
128
128
  ) {
129
- const nodeId = getNodeIdFromPeerDescriptor(sourcePeerDescriptor)
129
+ const nodeId = toNodeId(sourcePeerDescriptor)
130
130
  if (this.ongoingConnectRequests.has(nodeId)) {
131
131
  const { pendingConnection, delFunc } = this.ongoingConnectRequests.get(nodeId)!
132
132
  if (!isMaybeSupportedVersion(remoteVersion)) {
@@ -195,7 +195,7 @@ export class WebsocketServerConnector {
195
195
  throw new Err.ConnectionFailed('ConnectivityChecker is destroyed')
196
196
  }
197
197
  } catch (err) {
198
- const error = `Failed to connect to entrypoint with id ${getNodeIdFromPeerDescriptor(entryPoint)} `
198
+ const error = `Failed to connect to entrypoint with id ${toNodeId(entryPoint)} `
199
199
  + `and URL ${connectivityMethodToWebsocketUrl(entryPoint.websocket!)}`
200
200
  logger.error(error, { err })
201
201
  shuffledEntrypoints.shift()
@@ -227,7 +227,7 @@ export class WebsocketServerConnector {
227
227
  }
228
228
 
229
229
  public connect(targetPeerDescriptor: PeerDescriptor): PendingConnection {
230
- const nodeId = getNodeIdFromPeerDescriptor(targetPeerDescriptor)
230
+ const nodeId = toNodeId(targetPeerDescriptor)
231
231
  if (this.ongoingConnectRequests.has(nodeId)) {
232
232
  return this.ongoingConnectRequests.get(nodeId)!.pendingConnection
233
233
  }
@@ -251,7 +251,7 @@ export class WebsocketServerConnector {
251
251
  })
252
252
  })
253
253
  const pendingConnection = new PendingConnection(targetPeerDescriptor)
254
- const nodeId = getNodeIdFromPeerDescriptor(targetPeerDescriptor)
254
+ const nodeId = toNodeId(targetPeerDescriptor)
255
255
  // TODO: can this leak?
256
256
  const delFunc = () => {
257
257
  pendingConnection.off('connected', delFunc)
@@ -280,7 +280,7 @@ export class WebsocketServerConnector {
280
280
  await Promise.allSettled(requests.map((ongoingConnectRequest) => ongoingConnectRequest.pendingConnection.close(true)))
281
281
 
282
282
  await this.websocketServer?.stop()
283
- await this.geoIpLocator?.stop()
283
+ this.geoIpLocator?.stop()
284
284
  }
285
285
 
286
286
  }
@@ -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'
@@ -104,6 +104,7 @@ export interface DhtNodeOptions {
104
104
  autoCertifierUrl?: string
105
105
  autoCertifierConfigFile?: string
106
106
  geoIpDatabaseFolder?: string
107
+ allowIncomingPrivateConnections?: boolean
107
108
  }
108
109
 
109
110
  type StrictDhtNodeOptions = MarkRequired<DhtNodeOptions,
@@ -242,7 +243,8 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
242
243
  const connectionManager = new ConnectionManager({
243
244
  createConnectorFacade: () => new DefaultConnectorFacade(connectorFacadeOptions),
244
245
  maxConnections: this.options.maxConnections,
245
- metricsContext: this.options.metricsContext
246
+ metricsContext: this.options.metricsContext,
247
+ allowIncomingPrivateConnections: this.options.allowIncomingPrivateConnections ?? false
246
248
  })
247
249
  await connectionManager.start()
248
250
  this.connectionsView = connectionManager
@@ -381,7 +383,7 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
381
383
  this.transport!.on('disconnected', (peerDescriptor: PeerDescriptor, gracefulLeave: boolean) => {
382
384
  const isControlLayerNode = (this.connectionLocker !== undefined)
383
385
  if (isControlLayerNode) {
384
- const nodeId = getNodeIdFromPeerDescriptor(peerDescriptor)
386
+ const nodeId = toNodeId(peerDescriptor)
385
387
  if (gracefulLeave) {
386
388
  this.peerManager!.removeContact(nodeId)
387
389
  } else {
@@ -500,7 +502,7 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
500
502
  }
501
503
 
502
504
  public getNodeId(): DhtAddress {
503
- return getNodeIdFromPeerDescriptor(this.localPeerDescriptor!)
505
+ return toNodeId(this.localPeerDescriptor!)
504
506
  }
505
507
 
506
508
  public getNeighborCount(): number {
@@ -524,7 +526,7 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
524
526
 
525
527
  private getConnectedEntryPoints(): PeerDescriptor[] {
526
528
  return this.options.entryPoints !== undefined ? this.options.entryPoints.filter((entryPoint) =>
527
- this.connectionsView!.hasConnection(getNodeIdFromPeerDescriptor(entryPoint))
529
+ this.connectionsView!.hasConnection(toNodeId(entryPoint))
528
530
  ) : []
529
531
  }
530
532
 
@@ -631,6 +633,17 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
631
633
  return this.peerDiscovery!.isJoinCalled()
632
634
  }
633
635
 
636
+ public getDiagnosticInfo(): Record<string, unknown> {
637
+ return {
638
+ localPeerDescriptor: this.localPeerDescriptor,
639
+ transport: this.transport!.getDiagnosticInfo(),
640
+ router: this.router!.getDiagnosticInfo(),
641
+ neighborCount: this.getNeighborCount(),
642
+ nearbyContactCount: Array.from(this.peerManager!.getNearbyContacts().getAllContactsInUndefinedOrder()).length,
643
+ randomContactCount: this.peerManager!.getRandomContacts().getSize()
644
+ }
645
+ }
646
+
634
647
  public async stop(): Promise<void> {
635
648
  if (this.abortController.signal.aborted || !this.started) {
636
649
  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'
@@ -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'
@@ -77,7 +77,7 @@ export class PeerManager extends EventEmitter<PeerManagerEvents> {
77
77
  super()
78
78
  this.options = options
79
79
  this.neighbors = new KBucket<DhtNodeRpcRemote>({
80
- localNodeId: getRawFromDhtAddress(this.options.localNodeId),
80
+ localNodeId: toDhtAddressRaw(this.options.localNodeId),
81
81
  numberOfNodesPerKBucket: this.options.numberOfNodesPerKBucket,
82
82
  numberOfNodesToPing: this.options.numberOfNodesPerKBucket
83
83
  })
@@ -89,7 +89,7 @@ export class PeerManager extends EventEmitter<PeerManagerEvents> {
89
89
  this.emit('ringContactRemoved', contact.getPeerDescriptor())
90
90
  })
91
91
  this.neighbors.on('ping', (oldContacts: DhtNodeRpcRemote[], newContact: DhtNodeRpcRemote) => this.onKBucketPing(oldContacts, newContact))
92
- this.neighbors.on('removed', (contact: DhtNodeRpcRemote) => this.onKBucketRemoved(getNodeIdFromPeerDescriptor(contact.getPeerDescriptor())))
92
+ this.neighbors.on('removed', (contact: DhtNodeRpcRemote) => this.onKBucketRemoved(toNodeId(contact.getPeerDescriptor())))
93
93
  this.neighbors.on('added', (contact: DhtNodeRpcRemote) => this.onKBucketAdded(contact))
94
94
  this.neighbors.on('updated', () => {
95
95
  // TODO: Update contact info to the connection manager and reconnect
@@ -130,7 +130,7 @@ export class PeerManager extends EventEmitter<PeerManagerEvents> {
130
130
  sortingList.addContacts(oldContacts)
131
131
  const removableNodeId = sortingList.getFurthestContacts(1)[0].getNodeId()
132
132
  this.options.connectionLocker?.weakUnlockConnection(removableNodeId, this.options.lockId)
133
- this.neighbors.remove(getRawFromDhtAddress(removableNodeId))
133
+ this.neighbors.remove(toDhtAddressRaw(removableNodeId))
134
134
  this.neighbors.add(newContact)
135
135
  }
136
136
 
@@ -151,7 +151,7 @@ export class PeerManager extends EventEmitter<PeerManagerEvents> {
151
151
  }
152
152
  if (contact.getNodeId() !== this.options.localNodeId) {
153
153
  const peerDescriptor = contact.getPeerDescriptor()
154
- const nodeId = getNodeIdFromPeerDescriptor(peerDescriptor)
154
+ const nodeId = toNodeId(peerDescriptor)
155
155
  // Important to lock here, before the ping result is known
156
156
  this.options.connectionLocker?.weakLockConnection(nodeId, this.options.lockId)
157
157
  if (this.options.hasConnection(contact.getNodeId())) {
@@ -188,7 +188,7 @@ export class PeerManager extends EventEmitter<PeerManagerEvents> {
188
188
 
189
189
  private getNearbyActiveContactNotInNeighbors(): DhtNodeRpcRemote | undefined {
190
190
  for (const contactId of this.nearbyContacts.getContactIds()) {
191
- if (!this.neighbors.get(getRawFromDhtAddress(contactId)) && this.activeContacts.has(contactId)) {
191
+ if (!this.neighbors.get(toDhtAddressRaw(contactId)) && this.activeContacts.has(contactId)) {
192
192
  return this.nearbyContacts.getContact(contactId)!
193
193
  }
194
194
  }
@@ -201,22 +201,22 @@ export class PeerManager extends EventEmitter<PeerManagerEvents> {
201
201
  }
202
202
  logger.trace(`Removing contact ${nodeId}`)
203
203
  this.ringContacts.removeContact(this.nearbyContacts.getContact(nodeId))
204
- this.neighbors.remove(getRawFromDhtAddress(nodeId))
204
+ this.neighbors.remove(toDhtAddressRaw(nodeId))
205
205
  this.nearbyContacts.removeContact(nodeId)
206
206
  this.activeContacts.delete(nodeId)
207
207
  this.randomContacts.removeContact(nodeId)
208
208
  }
209
209
 
210
210
  removeNeighbor(nodeId: DhtAddress): void {
211
- this.neighbors.remove(getRawFromDhtAddress(nodeId))
211
+ this.neighbors.remove(toDhtAddressRaw(nodeId))
212
212
  }
213
213
 
214
214
  async pruneOfflineNodes(nodes: DhtNodeRpcRemote[]): Promise<void> {
215
215
  logger.trace('Pruning offline nodes', { nodes: nodes.length })
216
216
  const offlineNeighbors = await pingNodes(nodes, this.activeContacts)
217
217
  offlineNeighbors.forEach((offlineNeighbor) => {
218
- logger.trace('Removing offline node', { node: getNodeIdFromPeerDescriptor(offlineNeighbor) })
219
- this.removeContact(getNodeIdFromPeerDescriptor(offlineNeighbor))
218
+ logger.trace('Removing offline node', { node: toNodeId(offlineNeighbor) })
219
+ this.removeContact(toNodeId(offlineNeighbor))
220
220
  })
221
221
  }
222
222
 
@@ -278,7 +278,7 @@ export class PeerManager extends EventEmitter<PeerManagerEvents> {
278
278
  if (this.stopped) {
279
279
  return
280
280
  }
281
- const nodeId = getNodeIdFromPeerDescriptor(peerDescriptor)
281
+ const nodeId = toNodeId(peerDescriptor)
282
282
  if (nodeId !== this.options.localNodeId) {
283
283
  logger.trace(`Adding new contact ${nodeId}`)
284
284
  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 }> =
@@ -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)