@streamr/dht 100.0.0-testnet-one.4 → 100.0.0-testnet-two.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 (307) hide show
  1. package/dist/src/connection/ConnectionLockHandler.d.ts +11 -11
  2. package/dist/src/connection/ConnectionLockHandler.js.map +1 -1
  3. package/dist/src/connection/ConnectionLockRpcLocal.d.ts +3 -3
  4. package/dist/src/connection/ConnectionLockRpcLocal.js +4 -4
  5. package/dist/src/connection/ConnectionLockRpcLocal.js.map +1 -1
  6. package/dist/src/connection/ConnectionLockRpcRemote.d.ts +3 -5
  7. package/dist/src/connection/ConnectionLockRpcRemote.js +4 -7
  8. package/dist/src/connection/ConnectionLockRpcRemote.js.map +1 -1
  9. package/dist/src/connection/ConnectionManager.d.ts +4 -6
  10. package/dist/src/connection/ConnectionManager.js +48 -46
  11. package/dist/src/connection/ConnectionManager.js.map +1 -1
  12. package/dist/src/connection/ConnectorFacade.d.ts +2 -2
  13. package/dist/src/connection/ConnectorFacade.js +2 -1
  14. package/dist/src/connection/ConnectorFacade.js.map +1 -1
  15. package/dist/src/connection/ManagedConnection.d.ts +3 -6
  16. package/dist/src/connection/ManagedConnection.js +6 -10
  17. package/dist/src/connection/ManagedConnection.js.map +1 -1
  18. package/dist/src/connection/connectivityChecker.js +1 -0
  19. package/dist/src/connection/connectivityChecker.js.map +1 -1
  20. package/dist/src/connection/simulator/Simulator.d.ts +0 -3
  21. package/dist/src/connection/simulator/Simulator.js +3 -51
  22. package/dist/src/connection/simulator/Simulator.js.map +1 -1
  23. package/dist/src/connection/simulator/SimulatorConnector.js +5 -5
  24. package/dist/src/connection/simulator/SimulatorConnector.js.map +1 -1
  25. package/dist/src/connection/webrtc/NodeWebrtcConnection.js +2 -2
  26. package/dist/src/connection/webrtc/NodeWebrtcConnection.js.map +1 -1
  27. package/dist/src/connection/webrtc/WebrtcConnector.d.ts +0 -1
  28. package/dist/src/connection/webrtc/WebrtcConnector.js +7 -9
  29. package/dist/src/connection/webrtc/WebrtcConnector.js.map +1 -1
  30. package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.d.ts +2 -2
  31. package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js +11 -12
  32. package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js.map +1 -1
  33. package/dist/src/connection/webrtc/WebrtcConnectorRpcRemote.d.ts +2 -5
  34. package/dist/src/connection/webrtc/WebrtcConnectorRpcRemote.js +1 -4
  35. package/dist/src/connection/webrtc/WebrtcConnectorRpcRemote.js.map +1 -1
  36. package/dist/src/connection/websocket/AutoCertifierClientFacade.d.ts +1 -2
  37. package/dist/src/connection/websocket/AutoCertifierClientFacade.js +3 -4
  38. package/dist/src/connection/websocket/AutoCertifierClientFacade.js.map +1 -1
  39. package/dist/src/connection/websocket/ClientWebsocket.js.map +1 -1
  40. package/dist/src/connection/websocket/WebsocketConnector.d.ts +2 -7
  41. package/dist/src/connection/websocket/WebsocketConnector.js +32 -38
  42. package/dist/src/connection/websocket/WebsocketConnector.js.map +1 -1
  43. package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.d.ts +3 -2
  44. package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.js +8 -10
  45. package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.js.map +1 -1
  46. package/dist/src/connection/websocket/WebsocketConnectorRpcRemote.d.ts +3 -6
  47. package/dist/src/connection/websocket/WebsocketConnectorRpcRemote.js +0 -3
  48. package/dist/src/connection/websocket/WebsocketConnectorRpcRemote.js.map +1 -1
  49. package/dist/src/connection/websocket/WebsocketServer.d.ts +1 -4
  50. package/dist/src/connection/websocket/WebsocketServer.js +11 -12
  51. package/dist/src/connection/websocket/WebsocketServer.js.map +1 -1
  52. package/dist/src/dht/DhtNode.d.ts +10 -13
  53. package/dist/src/dht/DhtNode.js +39 -52
  54. package/dist/src/dht/DhtNode.js.map +1 -1
  55. package/dist/src/dht/DhtNodeRpcLocal.d.ts +0 -1
  56. package/dist/src/dht/DhtNodeRpcLocal.js.map +1 -1
  57. package/dist/src/dht/DhtNodeRpcRemote.d.ts +7 -7
  58. package/dist/src/dht/DhtNodeRpcRemote.js +8 -7
  59. package/dist/src/dht/DhtNodeRpcRemote.js.map +1 -1
  60. package/dist/src/dht/ExternalApiRpcLocal.d.ts +5 -4
  61. package/dist/src/dht/ExternalApiRpcLocal.js +3 -2
  62. package/dist/src/dht/ExternalApiRpcLocal.js.map +1 -1
  63. package/dist/src/dht/ExternalApiRpcRemote.d.ts +2 -2
  64. package/dist/src/dht/ExternalApiRpcRemote.js +2 -0
  65. package/dist/src/dht/ExternalApiRpcRemote.js.map +1 -1
  66. package/dist/src/dht/PeerManager.d.ts +13 -14
  67. package/dist/src/dht/PeerManager.js +45 -60
  68. package/dist/src/dht/PeerManager.js.map +1 -1
  69. package/dist/src/dht/contact/Contact.d.ts +2 -2
  70. package/dist/src/dht/contact/Contact.js +2 -2
  71. package/dist/src/dht/contact/Contact.js.map +1 -1
  72. package/dist/src/dht/contact/ContactList.d.ts +7 -7
  73. package/dist/src/dht/contact/ContactList.js +3 -3
  74. package/dist/src/dht/contact/ContactList.js.map +1 -1
  75. package/dist/src/dht/contact/RandomContactList.d.ts +4 -4
  76. package/dist/src/dht/contact/RandomContactList.js +12 -11
  77. package/dist/src/dht/contact/RandomContactList.js.map +1 -1
  78. package/dist/src/dht/contact/RpcRemote.d.ts +7 -4
  79. package/dist/src/dht/contact/RpcRemote.js +5 -2
  80. package/dist/src/dht/contact/RpcRemote.js.map +1 -1
  81. package/dist/src/dht/contact/SortedContactList.d.ts +13 -13
  82. package/dist/src/dht/contact/SortedContactList.js +33 -29
  83. package/dist/src/dht/contact/SortedContactList.js.map +1 -1
  84. package/dist/src/dht/discovery/DiscoverySession.d.ts +2 -4
  85. package/dist/src/dht/discovery/DiscoverySession.js +19 -20
  86. package/dist/src/dht/discovery/DiscoverySession.js.map +1 -1
  87. package/dist/src/dht/discovery/PeerDiscovery.d.ts +2 -5
  88. package/dist/src/dht/discovery/PeerDiscovery.js +12 -20
  89. package/dist/src/dht/discovery/PeerDiscovery.js.map +1 -1
  90. package/dist/src/dht/recursive-operation/RecursiveOperationManager.d.ts +36 -0
  91. package/dist/src/dht/recursive-operation/RecursiveOperationManager.js +165 -0
  92. package/dist/src/dht/recursive-operation/RecursiveOperationManager.js.map +1 -0
  93. package/dist/src/dht/recursive-operation/RecursiveOperationRpcLocal.d.ts +14 -0
  94. package/dist/src/dht/{find/FindRpcLocal.js → recursive-operation/RecursiveOperationRpcLocal.js} +7 -7
  95. package/dist/src/dht/recursive-operation/RecursiveOperationRpcLocal.js.map +1 -0
  96. package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.d.ts +6 -0
  97. package/dist/src/dht/{routing/FindRpcRemote.js → recursive-operation/RecursiveOperationRpcRemote.js} +11 -11
  98. package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.js.map +1 -0
  99. package/dist/src/dht/recursive-operation/RecursiveOperationSession.d.ts +42 -0
  100. package/dist/src/dht/recursive-operation/RecursiveOperationSession.js +182 -0
  101. package/dist/src/dht/recursive-operation/RecursiveOperationSession.js.map +1 -0
  102. package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.d.ts +12 -0
  103. package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.js +17 -0
  104. package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.js.map +1 -0
  105. package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcRemote.d.ts +6 -0
  106. package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcRemote.js +21 -0
  107. package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcRemote.js.map +1 -0
  108. package/dist/src/dht/routing/Router.d.ts +4 -19
  109. package/dist/src/dht/routing/Router.js +41 -33
  110. package/dist/src/dht/routing/Router.js.map +1 -1
  111. package/dist/src/dht/routing/RouterRpcLocal.js +6 -5
  112. package/dist/src/dht/routing/RouterRpcLocal.js.map +1 -1
  113. package/dist/src/dht/routing/RouterRpcRemote.d.ts +2 -2
  114. package/dist/src/dht/routing/RouterRpcRemote.js +7 -7
  115. package/dist/src/dht/routing/RouterRpcRemote.js.map +1 -1
  116. package/dist/src/dht/routing/RoutingSession.d.ts +20 -16
  117. package/dist/src/dht/routing/RoutingSession.js +37 -45
  118. package/dist/src/dht/routing/RoutingSession.js.map +1 -1
  119. package/dist/src/dht/store/LocalDataStore.d.ts +11 -13
  120. package/dist/src/dht/store/LocalDataStore.js +36 -56
  121. package/dist/src/dht/store/LocalDataStore.js.map +1 -1
  122. package/dist/src/dht/store/StoreManager.d.ts +33 -0
  123. package/dist/src/dht/store/StoreManager.js +186 -0
  124. package/dist/src/dht/store/StoreManager.js.map +1 -0
  125. package/dist/src/dht/store/StoreRpcLocal.d.ts +8 -40
  126. package/dist/src/dht/store/StoreRpcLocal.js +13 -229
  127. package/dist/src/dht/store/StoreRpcLocal.js.map +1 -1
  128. package/dist/src/dht/store/StoreRpcRemote.d.ts +5 -5
  129. package/dist/src/dht/store/StoreRpcRemote.js +4 -5
  130. package/dist/src/dht/store/StoreRpcRemote.js.map +1 -1
  131. package/dist/src/exports.d.ts +2 -0
  132. package/dist/src/exports.js.map +1 -1
  133. package/dist/src/helpers/MapWithTtl.d.ts +14 -0
  134. package/dist/src/helpers/MapWithTtl.js +59 -0
  135. package/dist/src/helpers/MapWithTtl.js.map +1 -0
  136. package/dist/src/helpers/PeerID.d.ts +2 -0
  137. package/dist/src/helpers/PeerID.js +4 -0
  138. package/dist/src/helpers/PeerID.js.map +1 -1
  139. package/dist/src/helpers/nodeId.d.ts +5 -0
  140. package/dist/src/helpers/nodeId.js +18 -1
  141. package/dist/src/helpers/nodeId.js.map +1 -1
  142. package/dist/src/helpers/peerIdFromPeerDescriptor.d.ts +2 -1
  143. package/dist/src/helpers/peerIdFromPeerDescriptor.js +2 -1
  144. package/dist/src/helpers/peerIdFromPeerDescriptor.js.map +1 -1
  145. package/dist/src/helpers/protoClasses.js +2 -3
  146. package/dist/src/helpers/protoClasses.js.map +1 -1
  147. package/dist/src/proto/packages/dht/protos/DhtRpc.client.d.ts +21 -22
  148. package/dist/src/proto/packages/dht/protos/DhtRpc.client.js +18 -18
  149. package/dist/src/proto/packages/dht/protos/DhtRpc.client.js.map +1 -1
  150. package/dist/src/proto/packages/dht/protos/DhtRpc.d.ts +36 -60
  151. package/dist/src/proto/packages/dht/protos/DhtRpc.js +34 -53
  152. package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +1 -1
  153. package/dist/src/proto/packages/dht/protos/DhtRpc.server.d.ts +11 -12
  154. package/dist/src/rpc-protocol/DhtCallContext.d.ts +2 -1
  155. package/dist/src/rpc-protocol/DhtCallContext.js.map +1 -1
  156. package/dist/src/rpc-protocol/DhtRpcOptions.d.ts +2 -1
  157. package/dist/src/transport/ITransport.d.ts +9 -1
  158. package/dist/src/transport/ITransport.js +5 -0
  159. package/dist/src/transport/ITransport.js.map +1 -1
  160. package/dist/src/transport/ListeningRpcCommunicator.js +1 -1
  161. package/dist/src/transport/ListeningRpcCommunicator.js.map +1 -1
  162. package/dist/src/transport/RoutingRpcCommunicator.d.ts +2 -1
  163. package/dist/src/transport/RoutingRpcCommunicator.js +16 -11
  164. package/dist/src/transport/RoutingRpcCommunicator.js.map +1 -1
  165. package/jest.config.js +4 -1
  166. package/karma-setup.js +2 -0
  167. package/karma.config.js +11 -7
  168. package/package.json +6 -7
  169. package/protos/DhtRpc.proto +17 -23
  170. package/src/connection/ConnectionLockHandler.ts +15 -15
  171. package/src/connection/ConnectionLockRpcLocal.ts +8 -9
  172. package/src/connection/ConnectionLockRpcRemote.ts +7 -16
  173. package/src/connection/ConnectionManager.ts +58 -55
  174. package/src/connection/ConnectorFacade.ts +3 -0
  175. package/src/connection/ManagedConnection.ts +12 -30
  176. package/src/connection/connectivityChecker.ts +1 -0
  177. package/src/connection/simulator/Simulator.ts +5 -36
  178. package/src/connection/simulator/SimulatorConnector.ts +8 -8
  179. package/src/connection/webrtc/BrowserWebrtcConnection.ts +0 -3
  180. package/src/connection/webrtc/NodeWebrtcConnection.ts +3 -4
  181. package/src/connection/webrtc/WebrtcConnector.ts +11 -13
  182. package/src/connection/webrtc/WebrtcConnectorRpcLocal.ts +16 -16
  183. package/src/connection/webrtc/WebrtcConnectorRpcRemote.ts +3 -13
  184. package/src/connection/websocket/AutoCertifierClientFacade.ts +4 -6
  185. package/src/connection/websocket/ClientWebsocket.ts +1 -0
  186. package/src/connection/websocket/WebsocketConnector.ts +43 -56
  187. package/src/connection/websocket/WebsocketConnectorRpcLocal.ts +11 -13
  188. package/src/connection/websocket/WebsocketConnectorRpcRemote.ts +4 -15
  189. package/src/connection/websocket/WebsocketServer.ts +14 -17
  190. package/src/dht/DhtNode.ts +67 -69
  191. package/src/dht/DhtNodeRpcLocal.ts +0 -1
  192. package/src/dht/DhtNodeRpcRemote.ts +13 -13
  193. package/src/dht/ExternalApiRpcLocal.ts +16 -6
  194. package/src/dht/ExternalApiRpcRemote.ts +5 -3
  195. package/src/dht/PeerManager.ts +73 -90
  196. package/src/dht/contact/Contact.ts +5 -4
  197. package/src/dht/contact/ContactList.ts +9 -9
  198. package/src/dht/contact/RandomContactList.ts +14 -14
  199. package/src/dht/contact/RpcRemote.ts +10 -7
  200. package/src/dht/contact/SortedContactList.ts +48 -45
  201. package/src/dht/discovery/DiscoverySession.ts +25 -25
  202. package/src/dht/discovery/PeerDiscovery.ts +16 -37
  203. package/src/dht/recursive-operation/RecursiveOperationManager.ts +240 -0
  204. package/src/dht/{find/FindRpcLocal.ts → recursive-operation/RecursiveOperationRpcLocal.ts} +9 -9
  205. package/src/dht/{routing/FindRpcRemote.ts → recursive-operation/RecursiveOperationRpcRemote.ts} +10 -10
  206. package/src/dht/recursive-operation/RecursiveOperationSession.ts +224 -0
  207. package/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.ts +25 -0
  208. package/src/dht/{find/FindSessionRpcRemote.ts → recursive-operation/RecursiveOperationSessionRpcRemote.ts} +8 -8
  209. package/src/dht/routing/Router.ts +45 -64
  210. package/src/dht/routing/RouterRpcLocal.ts +7 -6
  211. package/src/dht/routing/RouterRpcRemote.ts +9 -10
  212. package/src/dht/routing/RoutingSession.ts +59 -68
  213. package/src/dht/store/LocalDataStore.ts +47 -66
  214. package/src/dht/store/StoreManager.ts +217 -0
  215. package/src/dht/store/StoreRpcLocal.ts +26 -302
  216. package/src/dht/store/StoreRpcRemote.ts +9 -11
  217. package/src/exports.ts +2 -0
  218. package/src/helpers/MapWithTtl.ts +71 -0
  219. package/src/helpers/PeerID.ts +5 -0
  220. package/src/helpers/nodeId.ts +20 -0
  221. package/src/helpers/peerIdFromPeerDescriptor.ts +5 -3
  222. package/src/helpers/protoClasses.ts +4 -6
  223. package/src/proto/packages/dht/protos/DhtRpc.client.ts +31 -32
  224. package/src/proto/packages/dht/protos/DhtRpc.server.ts +11 -12
  225. package/src/proto/packages/dht/protos/DhtRpc.ts +49 -80
  226. package/src/rpc-protocol/DhtCallContext.ts +2 -1
  227. package/src/rpc-protocol/DhtRpcOptions.ts +2 -1
  228. package/src/transport/ITransport.ts +10 -1
  229. package/src/transport/ListeningRpcCommunicator.ts +1 -1
  230. package/src/transport/RoutingRpcCommunicator.ts +18 -12
  231. package/test/benchmark/Find.test.ts +8 -21
  232. package/test/benchmark/KademliaCorrectness.test.ts +11 -20
  233. package/test/benchmark/SortedContactListBenchmark.test.ts +9 -9
  234. package/test/benchmark/kademlia-simulation/Contact.ts +9 -8
  235. package/test/benchmark/kademlia-simulation/KademliaSimulation.ts +2 -2
  236. package/test/benchmark/kademlia-simulation/SimulationNode.ts +17 -17
  237. package/test/end-to-end/Layer0-Layer1.test.ts +10 -14
  238. package/test/end-to-end/Layer0.test.ts +15 -18
  239. package/test/end-to-end/Layer0MixedConnectionTypes.test.ts +7 -9
  240. package/test/end-to-end/Layer0Webrtc-Layer1.test.ts +4 -10
  241. package/test/end-to-end/Layer0Webrtc.test.ts +5 -6
  242. package/test/end-to-end/Layer1-Scale-WebSocket.test.ts +8 -16
  243. package/test/end-to-end/Layer1-Scale-Webrtc.test.ts +6 -13
  244. package/test/end-to-end/WebsocketConnectionRequest.test.ts +5 -6
  245. package/test/end-to-end/memory-leak.test.ts +6 -8
  246. package/test/integration/ConnectionLocking.test.ts +6 -13
  247. package/test/integration/ConnectionManager.test.ts +26 -43
  248. package/test/integration/DhtJoinPeerDiscovery.test.ts +5 -10
  249. package/test/integration/DhtNodeExternalAPI.test.ts +16 -22
  250. package/test/integration/DhtNodeRpcRemote.test.ts +13 -22
  251. package/test/integration/DhtRpc.test.ts +13 -18
  252. package/test/integration/Find.test.ts +10 -10
  253. package/test/integration/Layer1-scale.test.ts +17 -28
  254. package/test/integration/Mock-Layer1-Layer0.test.ts +25 -43
  255. package/test/integration/MultipleEntryPointJoining.test.ts +7 -7
  256. package/test/integration/ReplicateData.test.ts +28 -30
  257. package/test/integration/RouteMessage.test.ts +30 -27
  258. package/test/integration/RouterRpcRemote.test.ts +12 -18
  259. package/test/integration/RpcErrors.test.ts +8 -21
  260. package/test/integration/ScaleDownDht.test.ts +11 -10
  261. package/test/integration/SimultaneousConnections.test.ts +43 -67
  262. package/test/integration/Store.test.ts +23 -36
  263. package/test/integration/StoreAndDelete.test.ts +30 -50
  264. package/test/integration/StoreOnDhtWithTwoNodes.test.ts +16 -37
  265. package/test/integration/StoreRpcRemote.test.ts +20 -30
  266. package/test/integration/WebrtcConnectionManagement.test.ts +3 -13
  267. package/test/integration/WebrtcConnectorRpc.test.ts +3 -9
  268. package/test/integration/WebsocketConnectionManagement.test.ts +7 -10
  269. package/test/integration/WebsocketConnectorRpc.test.ts +8 -17
  270. package/test/unit/ConnectivityHelpers.test.ts +9 -17
  271. package/test/unit/DuplicateDetector.test.ts +7 -4
  272. package/test/unit/LocalDataStore.test.ts +66 -77
  273. package/test/unit/PeerManager.test.ts +31 -0
  274. package/test/unit/RandomContactList.test.ts +13 -8
  275. package/test/unit/{Finder.test.ts → RecursiveOperationManager.test.ts} +38 -43
  276. package/test/unit/RecursiveOperationSession.test.ts +68 -0
  277. package/test/unit/Router.test.ts +15 -22
  278. package/test/unit/RoutingSession.test.ts +23 -25
  279. package/test/unit/SortedContactList.test.ts +41 -26
  280. package/test/unit/StoreManager.test.ts +132 -0
  281. package/test/unit/WebsocketConnector.test.ts +27 -35
  282. package/test/unit/customMatchers.test.ts +16 -0
  283. package/test/utils/FakeTransport.ts +44 -0
  284. package/test/utils/customMatchers.ts +70 -0
  285. package/test/utils/mock/MockRpcCommunicator.ts +7 -0
  286. package/test/utils/mock/Router.ts +3 -2
  287. package/test/utils/mock/mockDataEntry.ts +36 -0
  288. package/test/utils/utils.ts +49 -87
  289. package/dist/src/dht/find/FindRpcLocal.d.ts +0 -14
  290. package/dist/src/dht/find/FindRpcLocal.js.map +0 -1
  291. package/dist/src/dht/find/FindSession.d.ts +0 -44
  292. package/dist/src/dht/find/FindSession.js +0 -150
  293. package/dist/src/dht/find/FindSession.js.map +0 -1
  294. package/dist/src/dht/find/FindSessionRpcLocal.d.ts +0 -12
  295. package/dist/src/dht/find/FindSessionRpcLocal.js +0 -17
  296. package/dist/src/dht/find/FindSessionRpcLocal.js.map +0 -1
  297. package/dist/src/dht/find/FindSessionRpcRemote.d.ts +0 -6
  298. package/dist/src/dht/find/FindSessionRpcRemote.js +0 -21
  299. package/dist/src/dht/find/FindSessionRpcRemote.js.map +0 -1
  300. package/dist/src/dht/find/Finder.d.ts +0 -49
  301. package/dist/src/dht/find/Finder.js +0 -197
  302. package/dist/src/dht/find/Finder.js.map +0 -1
  303. package/dist/src/dht/routing/FindRpcRemote.d.ts +0 -6
  304. package/dist/src/dht/routing/FindRpcRemote.js.map +0 -1
  305. package/src/dht/find/FindSession.ts +0 -183
  306. package/src/dht/find/FindSessionRpcLocal.ts +0 -25
  307. package/src/dht/find/Finder.ts +0 -295
@@ -16,6 +16,7 @@ export interface ConnectorFacade {
16
16
  getLocalPeerDescriptor: () => PeerDescriptor | undefined
17
17
  start: (
18
18
  onNewConnection: (connection: ManagedConnection) => boolean,
19
+ hasConnection: (peerDescriptor: PeerDescriptor) => boolean,
19
20
  autoCertifierTransport: ITransport
20
21
  ) => Promise<void>
21
22
  stop: () => Promise<void>
@@ -58,6 +59,7 @@ export class DefaultConnectorFacade implements ConnectorFacade {
58
59
 
59
60
  async start(
60
61
  onNewConnection: (connection: ManagedConnection) => boolean,
62
+ hasConnection: (peerDescriptor: PeerDescriptor) => boolean,
61
63
  autoCertifierTransport: ITransport
62
64
  ): Promise<void> {
63
65
  logger.trace(`Creating WebsocketConnectorRpcLocal`)
@@ -65,6 +67,7 @@ export class DefaultConnectorFacade implements ConnectorFacade {
65
67
  transport: this.config.transport,
66
68
  // TODO should we use canConnect also for WebrtcConnector? (NET-1142)
67
69
  onNewConnection,
70
+ hasConnection,
68
71
  portRange: this.config.websocketPortRange,
69
72
  host: this.config.websocketHost,
70
73
  entrypoints: this.config.entryPoints,
@@ -4,25 +4,18 @@ import { Handshaker } from './Handshaker'
4
4
  import { HandshakeError, PeerDescriptor } from '../proto/packages/dht/protos/DhtRpc'
5
5
  import { Logger, runAndRaceEvents3, RunAndRaceEventsReturnType } from '@streamr/utils'
6
6
  import EventEmitter from 'eventemitter3'
7
- import { PeerIDKey } from '../helpers/PeerID'
8
- import { keyFromPeerDescriptor } from '../helpers/peerIdFromPeerDescriptor'
7
+ import { getNodeIdFromPeerDescriptor } from '../helpers/peerIdFromPeerDescriptor'
9
8
  import { getNodeIdOrUnknownFromPeerDescriptor } from './ConnectionManager'
9
+ import { NodeID } from '../helpers/nodeId'
10
10
 
11
11
  export interface ManagedConnectionEvents {
12
12
  managedData: (bytes: Uint8Array, remotePeerDescriptor: PeerDescriptor) => void
13
13
  handshakeRequest: (source: PeerDescriptor, target?: PeerDescriptor) => void
14
14
  handshakeCompleted: (peerDescriptor: PeerDescriptor) => void
15
15
  handshakeFailed: () => void
16
- bufferSentByOtherConnection: () => void
17
- closing: () => void
18
16
  }
19
17
 
20
- interface OutpuBufferEvents {
21
- bufferSent: () => void
22
- bufferSendingFailed: () => void
23
- }
24
-
25
- interface OutpuBufferEvents {
18
+ interface OutputBufferEvents {
26
19
  bufferSent: () => void
27
20
  bufferSendingFailed: () => void
28
21
  }
@@ -34,29 +27,22 @@ export type Events = ManagedConnectionEvents & ConnectionEvents
34
27
  export class ManagedConnection extends EventEmitter<Events> {
35
28
 
36
29
  private implementation?: IConnection
37
-
38
- private outputBufferEmitter = new EventEmitter<OutpuBufferEvents>()
30
+ private outputBufferEmitter = new EventEmitter<OutputBufferEvents>()
39
31
  private outputBuffer: Uint8Array[] = []
40
-
41
32
  private inputBuffer: Uint8Array[] = []
42
-
43
33
  public connectionId: ConnectionID
44
34
  private remotePeerDescriptor?: PeerDescriptor
45
35
  public connectionType: ConnectionType
46
-
47
36
  private handshaker?: Handshaker
48
37
  private handshakeCompleted = false
49
-
50
38
  private lastUsed: number = Date.now()
51
39
  private stopped = false
52
- public offeredAsIncoming = false
53
40
  private bufferSentbyOtherConnection = false
54
41
  private closing = false
55
42
  public replacedByOtherConnection = false
56
43
  private localPeerDescriptor: PeerDescriptor
57
44
  protected outgoingConnection?: IConnection
58
45
  protected incomingConnection?: IConnection
59
-
60
46
  // TODO: Temporary debug variable, should be removed in the future.
61
47
  private created = Date.now()
62
48
 
@@ -166,8 +152,8 @@ export class ManagedConnection extends EventEmitter<Events> {
166
152
  return this
167
153
  }
168
154
 
169
- public get peerIdKey(): PeerIDKey {
170
- return keyFromPeerDescriptor(this.remotePeerDescriptor!)
155
+ public getNodeId(): NodeID {
156
+ return getNodeIdFromPeerDescriptor(this.remotePeerDescriptor!)
171
157
  }
172
158
 
173
159
  public getLastUsed(): number {
@@ -233,7 +219,7 @@ export class ManagedConnection extends EventEmitter<Events> {
233
219
  this.emit('disconnected', gracefulLeave)
234
220
  }
235
221
 
236
- async send(data: Uint8Array, doNotConnect = false): Promise<void> {
222
+ async send(data: Uint8Array, connect: boolean): Promise<void> {
237
223
  if (this.stopped) {
238
224
  throw new Err.SendFailed('ManagedConnection is stopped')
239
225
  }
@@ -242,18 +228,18 @@ export class ManagedConnection extends EventEmitter<Events> {
242
228
  }
243
229
  this.lastUsed = Date.now()
244
230
 
245
- if (doNotConnect && !this.implementation) {
246
- throw new Err.ConnectionNotOpen('Connection not open when calling send() with doNotConnect flag')
231
+ if (!connect && !this.implementation) {
232
+ throw new Err.ConnectionNotOpen('Connection not open when calling send() with connect flag as false')
247
233
  } else if (this.implementation) {
248
234
  this.implementation.send(data)
249
235
  } else {
250
236
  logger.trace('adding data to outputBuffer')
251
237
 
252
- let result: RunAndRaceEventsReturnType<OutpuBufferEvents>
238
+ let result: RunAndRaceEventsReturnType<OutputBufferEvents>
253
239
 
254
240
  try {
255
- result = await runAndRaceEvents3<OutpuBufferEvents>([() => { this.outputBuffer.push(data) }],
256
- this.outputBufferEmitter, ['bufferSent', 'bufferSendingFailed'], 15000)
241
+ result = await runAndRaceEvents3<OutputBufferEvents>([() => { this.outputBuffer.push(data) }],
242
+ this.outputBufferEmitter, ['bufferSent', 'bufferSendingFailed'], 15000) // TODO use config option or named constant?
257
243
  } catch (e) {
258
244
  logger.debug(`Connection to ${getNodeIdOrUnknownFromPeerDescriptor(this.remotePeerDescriptor)} timed out`, {
259
245
  peerDescriptor: this.remotePeerDescriptor,
@@ -289,7 +275,6 @@ export class ManagedConnection extends EventEmitter<Events> {
289
275
  logger.trace('bufferSentByOtherConnection reported')
290
276
  this.bufferSentbyOtherConnection = true
291
277
  this.outputBufferEmitter.emit('bufferSent')
292
- this.emit('bufferSentByOtherConnection')
293
278
  }
294
279
 
295
280
  public acceptHandshake(): void {
@@ -324,7 +309,6 @@ export class ManagedConnection extends EventEmitter<Events> {
324
309
  this.closing = true
325
310
 
326
311
  this.outputBufferEmitter.emit('bufferSendingFailed')
327
- this.emit('closing')
328
312
 
329
313
  if (this.implementation) {
330
314
  await this.implementation?.close(gracefulLeave)
@@ -339,8 +323,6 @@ export class ManagedConnection extends EventEmitter<Events> {
339
323
 
340
324
  public destroy(): void {
341
325
  this.closing = true
342
-
343
- this.emit('closing')
344
326
  if (!this.stopped) {
345
327
  this.stopped = true
346
328
 
@@ -11,6 +11,7 @@ import { connectivityMethodToWebsocketUrl } from './websocket/WebsocketConnector
11
11
 
12
12
  const logger = new Logger(module)
13
13
 
14
+ // TODO use config option or named constant?
14
15
  export const connectAsync = async ({ url, selfSigned, timeoutMs = 1000 }:
15
16
  { url: string, selfSigned: boolean, timeoutMs?: number }
16
17
  ): Promise<IConnection> => {
@@ -1,6 +1,5 @@
1
1
  /* eslint-disable @typescript-eslint/parameter-properties */
2
2
  import EventEmitter from 'eventemitter3'
3
- import { PeerIDKey } from '../../helpers/PeerID'
4
3
  import { PeerDescriptor } from '../../proto/packages/dht/protos/DhtRpc'
5
4
  import { ConnectionSourceEvents } from '../IConnectionSource'
6
5
  import { SimulatorConnector } from './SimulatorConnector'
@@ -8,19 +7,10 @@ import { SimulatorConnection } from './SimulatorConnection'
8
7
  import { ConnectionID } from '../IConnection'
9
8
  import { Logger } from '@streamr/utils'
10
9
  import { getRegionDelayMatrix } from './pings'
11
- import { keyFromPeerDescriptor } from '../../helpers/peerIdFromPeerDescriptor'
10
+ import { getNodeIdFromPeerDescriptor } from '../../helpers/peerIdFromPeerDescriptor'
12
11
  import Heap from 'heap'
13
12
  import { debugVars } from '../../helpers/debugHelpers'
14
- import * as sinon from 'sinon'
15
-
16
- // TODO take this from @streamr/test-utils (we can't access devDependencies as Simulator
17
- // is currently in "src" directory instead of "test" directory)
18
- // eslint-disable-next-line no-underscore-dangle
19
- declare let _streamr_electron_test: any
20
- export function isRunningInElectron(): boolean {
21
- // eslint-disable-next-line no-underscore-dangle
22
- return typeof _streamr_electron_test !== 'undefined'
23
- }
13
+ import { NodeID } from '../../helpers/nodeId'
24
14
 
25
15
  const logger = new Logger(module)
26
16
 
@@ -102,7 +92,7 @@ class CloseOperation extends SimulatorOperation {
102
92
 
103
93
  export class Simulator extends EventEmitter<ConnectionSourceEvents> {
104
94
  private stopped = false
105
- private connectors: Map<PeerIDKey, SimulatorConnector> = new Map()
95
+ private connectors: Map<NodeID, SimulatorConnector> = new Map()
106
96
  private latencyTable?: Array<Array<number>>
107
97
  private associations: Map<ConnectionID, Association> = new Map()
108
98
 
@@ -121,22 +111,6 @@ export class Simulator extends EventEmitter<ConnectionSourceEvents> {
121
111
  })
122
112
 
123
113
  private simulatorTimeout?: NodeJS.Timeout
124
- private static clock: sinon.SinonFakeTimers | undefined
125
-
126
- static useFakeTimers(on = true): void {
127
- if (!isRunningInElectron()) { // never use fake timers in browser environment
128
- if (on) {
129
- if (!Simulator.clock) {
130
- Simulator.clock = sinon.useFakeTimers()
131
- }
132
- } else {
133
- if (Simulator.clock) {
134
- Simulator.clock.restore()
135
- Simulator.clock = undefined
136
- }
137
- }
138
- }
139
- }
140
114
 
141
115
  constructor(latencyType: LatencyType = LatencyType.NONE, fixedLatency?: number) {
142
116
  super()
@@ -214,11 +188,11 @@ export class Simulator extends EventEmitter<ConnectionSourceEvents> {
214
188
  }
215
189
 
216
190
  public addConnector(connector: SimulatorConnector): void {
217
- this.connectors.set(keyFromPeerDescriptor(connector.getPeerDescriptor()), connector)
191
+ this.connectors.set(getNodeIdFromPeerDescriptor(connector.getPeerDescriptor()), connector)
218
192
  }
219
193
 
220
194
  private executeConnectOperation(operation: ConnectOperation): void {
221
- const target = this.connectors.get(keyFromPeerDescriptor(operation.targetDescriptor))
195
+ const target = this.connectors.get(getNodeIdFromPeerDescriptor(operation.targetDescriptor))
222
196
 
223
197
  if (!target) {
224
198
  logger.error('Target connector not found when executing connect operation')
@@ -311,11 +285,6 @@ export class Simulator extends EventEmitter<ConnectionSourceEvents> {
311
285
  const timeDifference = firstOperationTime - currentTime
312
286
 
313
287
  this.simulatorTimeout = setTimeout(this.executeQueuedOperations, timeDifference)
314
-
315
- if (Simulator.clock) {
316
- // TODO should we have some handling for this floating promise?
317
- Simulator.clock.runAllAsync()
318
- }
319
288
  }
320
289
 
321
290
  private scheduleOperation(operation: SimulatorOperation) {
@@ -6,16 +6,16 @@ import {
6
6
  } from '../../proto/packages/dht/protos/DhtRpc'
7
7
  import { Logger } from '@streamr/utils'
8
8
  import { ManagedConnection } from '../ManagedConnection'
9
- import { PeerIDKey } from '../../helpers/PeerID'
10
9
  import { Simulator } from './Simulator'
11
10
  import { SimulatorConnection } from './SimulatorConnection'
12
- import { getNodeIdFromPeerDescriptor, keyFromPeerDescriptor } from '../../helpers/peerIdFromPeerDescriptor'
11
+ import { getNodeIdFromPeerDescriptor } from '../../helpers/peerIdFromPeerDescriptor'
12
+ import { NodeID } from '../../helpers/nodeId'
13
13
 
14
14
  const logger = new Logger(module)
15
15
 
16
16
  export class SimulatorConnector {
17
17
 
18
- private connectingConnections: Map<PeerIDKey, ManagedConnection> = new Map()
18
+ private connectingConnections: Map<NodeID, ManagedConnection> = new Map()
19
19
  private stopped = false
20
20
  private localPeerDescriptor: PeerDescriptor
21
21
  private simulator: Simulator
@@ -33,8 +33,8 @@ export class SimulatorConnector {
33
33
 
34
34
  public connect(targetPeerDescriptor: PeerDescriptor): ManagedConnection {
35
35
  logger.trace('connect() ' + getNodeIdFromPeerDescriptor(targetPeerDescriptor))
36
- const peerKey = keyFromPeerDescriptor(targetPeerDescriptor)
37
- const existingConnection = this.connectingConnections.get(peerKey)
36
+ const nodeId = getNodeIdFromPeerDescriptor(targetPeerDescriptor)
37
+ const existingConnection = this.connectingConnections.get(nodeId)
38
38
  if (existingConnection) {
39
39
  return existingConnection
40
40
  }
@@ -44,12 +44,12 @@ export class SimulatorConnector {
44
44
  const managedConnection = new ManagedConnection(this.localPeerDescriptor, ConnectionType.SIMULATOR_CLIENT, connection, undefined)
45
45
  managedConnection.setRemotePeerDescriptor(targetPeerDescriptor)
46
46
 
47
- this.connectingConnections.set(peerKey, managedConnection)
47
+ this.connectingConnections.set(nodeId, managedConnection)
48
48
  connection.once('disconnected', () => {
49
- this.connectingConnections.delete(peerKey)
49
+ this.connectingConnections.delete(nodeId)
50
50
  })
51
51
  connection.once('connected', () => {
52
- this.connectingConnections.delete(peerKey)
52
+ this.connectingConnections.delete(nodeId)
53
53
  })
54
54
 
55
55
  connection.connect()
@@ -22,12 +22,9 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IWebrt
22
22
 
23
23
  public connectionId: ConnectionID
24
24
  public readonly connectionType: ConnectionType = ConnectionType.WEBRTC
25
-
26
25
  // We need to keep track of connection state ourselves because
27
26
  // RTCPeerConnection.connectionState is not supported on Firefox
28
-
29
27
  private lastState: RTCPeerConnectionState = 'connecting'
30
-
31
28
  private readonly iceServers: IceServer[]
32
29
  private peerConnection?: RTCPeerConnection
33
30
  private dataChannel?: RTCDataChannel
@@ -5,7 +5,7 @@ import EventEmitter from 'eventemitter3'
5
5
  import nodeDatachannel, { DataChannel, DescriptionType, PeerConnection } from 'node-datachannel'
6
6
  import { Logger } from '@streamr/utils'
7
7
  import { IllegalRtcPeerConnectionState } from '../../helpers/errors'
8
- import { getNodeIdFromPeerDescriptor, keyFromPeerDescriptor } from '../../helpers/peerIdFromPeerDescriptor'
8
+ import { getNodeIdFromPeerDescriptor } from '../../helpers/peerIdFromPeerDescriptor'
9
9
  import { iceServerAsString } from './iceServerAsString'
10
10
  import { IceServer } from './WebrtcConnector'
11
11
  import { PortRange } from '../ConnectionManager'
@@ -55,7 +55,6 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IConne
55
55
  private lastState: RtcPeerConnectionState = 'connecting'
56
56
  private remoteDescriptionSet = false
57
57
  private connectingTimeoutRef?: NodeJS.Timeout
58
-
59
58
  public readonly connectionType: ConnectionType = ConnectionType.WEBRTC
60
59
  private readonly iceServers: IceServer[]
61
60
  private readonly _bufferThresholdHigh: number // TODO: buffer handling must be implemented before production use (NET-938)
@@ -80,9 +79,9 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IConne
80
79
  }
81
80
 
82
81
  public start(isOffering: boolean): void {
83
- const peerIdKey = keyFromPeerDescriptor(this.remotePeerDescriptor)
82
+ const nodeId = getNodeIdFromPeerDescriptor(this.remotePeerDescriptor)
84
83
  logger.trace(`Starting new connection for peer ${getNodeIdFromPeerDescriptor(this.remotePeerDescriptor)}`, { isOffering })
85
- this.connection = new PeerConnection(peerIdKey, {
84
+ this.connection = new PeerConnection(nodeId, {
86
85
  iceServers: this.iceServers.map(iceServerAsString),
87
86
  maxMessageSize: this.maxMessageSize,
88
87
  portRangeBegin: this.portRange?.min,
@@ -9,21 +9,19 @@ import { ListeningRpcCommunicator } from '../../transport/ListeningRpcCommunicat
9
9
  import { NodeWebrtcConnection } from './NodeWebrtcConnection'
10
10
  import { WebrtcConnectorRpcRemote } from './WebrtcConnectorRpcRemote'
11
11
  import { WebrtcConnectorRpcClient } from '../../proto/packages/dht/protos/DhtRpc.client'
12
- import { PeerIDKey } from '../../helpers/PeerID'
13
12
  import { ManagedWebrtcConnection } from '../ManagedWebrtcConnection'
14
13
  import { Logger } from '@streamr/utils'
15
14
  import * as Err from '../../helpers/errors'
16
15
  import { ManagedConnection } from '../ManagedConnection'
17
- import { toProtoRpcClient } from '@streamr/proto-rpc'
18
16
  import {
19
17
  areEqualPeerDescriptors,
20
18
  getNodeIdFromPeerDescriptor,
21
- keyFromPeerDescriptor,
22
19
  peerIdFromPeerDescriptor
23
20
  } from '../../helpers/peerIdFromPeerDescriptor'
24
21
  import { PortRange } from '../ConnectionManager'
25
22
  import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
26
23
  import { WebrtcConnectorRpcLocal } from './WebrtcConnectorRpcLocal'
24
+ import { NodeID } from '../../helpers/nodeId'
27
25
 
28
26
  const logger = new Logger(module)
29
27
 
@@ -60,10 +58,9 @@ export class WebrtcConnector {
60
58
 
61
59
  private static readonly WEBRTC_CONNECTOR_SERVICE_ID = 'system/webrtc-connector'
62
60
  private readonly rpcCommunicator: ListeningRpcCommunicator
63
- private readonly ongoingConnectAttempts: Map<PeerIDKey, ManagedWebrtcConnection> = new Map()
61
+ private readonly ongoingConnectAttempts: Map<NodeID, ManagedWebrtcConnection> = new Map()
64
62
  private localPeerDescriptor?: PeerDescriptor
65
63
  private stopped = false
66
- private iceServers: IceServer[]
67
64
  private config: WebrtcConnectorConfig
68
65
 
69
66
  constructor(
@@ -71,9 +68,8 @@ export class WebrtcConnector {
71
68
  onNewConnection: (connection: ManagedConnection) => boolean
72
69
  ) {
73
70
  this.config = config
74
- this.iceServers = config.iceServers ?? []
75
71
  this.rpcCommunicator = new ListeningRpcCommunicator(WebrtcConnector.WEBRTC_CONNECTOR_SERVICE_ID, config.transport, {
76
- rpcRequestTimeout: 15000
72
+ rpcRequestTimeout: 15000 // TODO use config option or named constant?
77
73
  })
78
74
  this.registerLocalRpcMethods(config, onNewConnection)
79
75
  }
@@ -135,15 +131,15 @@ export class WebrtcConnector {
135
131
 
136
132
  logger.trace(`Opening WebRTC connection to ${getNodeIdFromPeerDescriptor(targetPeerDescriptor)}`)
137
133
 
138
- const peerKey = keyFromPeerDescriptor(targetPeerDescriptor)
139
- const existingConnection = this.ongoingConnectAttempts.get(peerKey)
134
+ const nodeId = getNodeIdFromPeerDescriptor(targetPeerDescriptor)
135
+ const existingConnection = this.ongoingConnectAttempts.get(nodeId)
140
136
  if (existingConnection) {
141
137
  return existingConnection
142
138
  }
143
139
 
144
140
  const connection = new NodeWebrtcConnection({
145
141
  remotePeerDescriptor: targetPeerDescriptor,
146
- iceServers: this.iceServers,
142
+ iceServers: this.config.iceServers,
147
143
  bufferThresholdLow: this.config.bufferThresholdLow,
148
144
  bufferThresholdHigh: this.config.bufferThresholdHigh,
149
145
  connectingTimeout: this.config.connectionTimeout,
@@ -161,10 +157,10 @@ export class WebrtcConnector {
161
157
 
162
158
  managedConnection.setRemotePeerDescriptor(targetPeerDescriptor)
163
159
 
164
- this.ongoingConnectAttempts.set(keyFromPeerDescriptor(targetPeerDescriptor), managedConnection)
160
+ this.ongoingConnectAttempts.set(getNodeIdFromPeerDescriptor(targetPeerDescriptor), managedConnection)
165
161
 
166
162
  const delFunc = () => {
167
- this.ongoingConnectAttempts.delete(peerKey)
163
+ this.ongoingConnectAttempts.delete(nodeId)
168
164
  connection.off('disconnected', delFunc)
169
165
  managedConnection.off('handshakeCompleted', delFunc)
170
166
  }
@@ -174,7 +170,9 @@ export class WebrtcConnector {
174
170
  const remoteConnector = new WebrtcConnectorRpcRemote(
175
171
  this.localPeerDescriptor!,
176
172
  targetPeerDescriptor,
177
- toProtoRpcClient(new WebrtcConnectorRpcClient(this.rpcCommunicator.getRpcClientTransport()))
173
+ 'DUMMY',
174
+ this.rpcCommunicator,
175
+ WebrtcConnectorRpcClient
178
176
  )
179
177
 
180
178
  connection.on('localCandidate', (candidate: string, mid: string) => {
@@ -1,9 +1,7 @@
1
1
  import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
2
- import { toProtoRpcClient } from '@streamr/proto-rpc'
3
2
  import { Logger } from '@streamr/utils'
4
3
  import { getAddressFromIceCandidate, isPrivateIPv4 } from '../../helpers/AddressTools'
5
- import { PeerIDKey } from '../../helpers/PeerID'
6
- import { keyFromPeerDescriptor } from '../../helpers/peerIdFromPeerDescriptor'
4
+ import { getNodeIdFromPeerDescriptor } from '../../helpers/peerIdFromPeerDescriptor'
7
5
  import { Empty } from '../../proto/google/protobuf/empty'
8
6
  import {
9
7
  IceCandidate,
@@ -19,6 +17,7 @@ import { ManagedConnection } from '../ManagedConnection'
19
17
  import { ManagedWebrtcConnection } from '../ManagedWebrtcConnection'
20
18
  import { NodeWebrtcConnection } from './NodeWebrtcConnection'
21
19
  import { WebrtcConnectorRpcRemote } from './WebrtcConnectorRpcRemote'
20
+ import { NodeID } from '../../helpers/nodeId'
22
21
 
23
22
  const logger = new Logger(module)
24
23
 
@@ -26,7 +25,7 @@ interface WebrtcConnectorRpcLocalConfig {
26
25
  connect: (targetPeerDescriptor: PeerDescriptor) => ManagedConnection
27
26
  onNewConnection: (connection: ManagedConnection) => boolean
28
27
  // TODO pass accessor methods instead of passing a mutable entity
29
- ongoingConnectAttempts: Map<PeerIDKey, ManagedWebrtcConnection>
28
+ ongoingConnectAttempts: Map<NodeID, ManagedWebrtcConnection>
30
29
  rpcCommunicator: ListeningRpcCommunicator
31
30
  getLocalPeerDescriptor: () => PeerDescriptor
32
31
  allowPrivateAddresses: boolean
@@ -42,7 +41,7 @@ export class WebrtcConnectorRpcLocal implements IWebrtcConnectorRpc {
42
41
 
43
42
  async requestConnection(context: ServerCallContext): Promise<Empty> {
44
43
  const targetPeerDescriptor = (context as DhtCallContext).incomingSourceDescriptor!
45
- if (this.config.ongoingConnectAttempts.has(keyFromPeerDescriptor(targetPeerDescriptor))) {
44
+ if (this.config.ongoingConnectAttempts.has(getNodeIdFromPeerDescriptor(targetPeerDescriptor))) {
46
45
  return {}
47
46
  }
48
47
  const managedConnection = this.config.connect(targetPeerDescriptor)
@@ -53,20 +52,22 @@ export class WebrtcConnectorRpcLocal implements IWebrtcConnectorRpc {
53
52
 
54
53
  async rtcOffer(request: RtcOffer, context: ServerCallContext): Promise<Empty> {
55
54
  const remotePeer = (context as DhtCallContext).incomingSourceDescriptor!
56
- const peerKey = keyFromPeerDescriptor(remotePeer)
57
- let managedConnection = this.config.ongoingConnectAttempts.get(peerKey)
55
+ const nodeId = getNodeIdFromPeerDescriptor(remotePeer)
56
+ let managedConnection = this.config.ongoingConnectAttempts.get(nodeId)
58
57
  let connection = managedConnection?.getWebrtcConnection()
59
58
 
60
59
  if (!managedConnection) {
61
60
  connection = new NodeWebrtcConnection({ remotePeerDescriptor: remotePeer })
62
61
  managedConnection = new ManagedWebrtcConnection(this.config.getLocalPeerDescriptor(), undefined, connection)
63
62
  managedConnection.setRemotePeerDescriptor(remotePeer)
64
- this.config.ongoingConnectAttempts.set(peerKey, managedConnection)
63
+ this.config.ongoingConnectAttempts.set(nodeId, managedConnection)
65
64
  this.config.onNewConnection(managedConnection)
66
65
  const remoteConnector = new WebrtcConnectorRpcRemote(
67
66
  this.config.getLocalPeerDescriptor(),
68
67
  remotePeer,
69
- toProtoRpcClient(new WebrtcConnectorRpcClient(this.config.rpcCommunicator.getRpcClientTransport()))
68
+ 'DUMMY',
69
+ this.config.rpcCommunicator,
70
+ WebrtcConnectorRpcClient
70
71
  )
71
72
  connection.on('localCandidate', (candidate: string, mid: string) => {
72
73
  remoteConnector.sendIceCandidate(candidate, mid, connection!.connectionId.toString())
@@ -82,8 +83,8 @@ export class WebrtcConnectorRpcLocal implements IWebrtcConnectorRpc {
82
83
  connection!.setRemoteDescription(request.description, 'offer')
83
84
 
84
85
  managedConnection.on('handshakeRequest', () => {
85
- if (this.config.ongoingConnectAttempts.has(peerKey)) {
86
- this.config.ongoingConnectAttempts.delete(peerKey)
86
+ if (this.config.ongoingConnectAttempts.has(nodeId)) {
87
+ this.config.ongoingConnectAttempts.delete(nodeId)
87
88
  }
88
89
  managedConnection!.acceptHandshake()
89
90
  })
@@ -92,8 +93,8 @@ export class WebrtcConnectorRpcLocal implements IWebrtcConnectorRpc {
92
93
 
93
94
  async rtcAnswer(request: RtcAnswer, context: ServerCallContext): Promise<Empty> {
94
95
  const remotePeerDescriptor = (context as DhtCallContext).incomingSourceDescriptor!
95
- const peerKey = keyFromPeerDescriptor(remotePeerDescriptor)
96
- const connection = this.config.ongoingConnectAttempts.get(peerKey)?.getWebrtcConnection()
96
+ const nodeId = getNodeIdFromPeerDescriptor(remotePeerDescriptor)
97
+ const connection = this.config.ongoingConnectAttempts.get(nodeId)?.getWebrtcConnection()
97
98
  if (!connection) {
98
99
  return {}
99
100
  } else if (connection.connectionId.toString() !== request.connectionId) {
@@ -106,9 +107,8 @@ export class WebrtcConnectorRpcLocal implements IWebrtcConnectorRpc {
106
107
 
107
108
  async iceCandidate(request: IceCandidate, context: ServerCallContext): Promise<Empty> {
108
109
  const remotePeerDescriptor = (context as DhtCallContext).incomingSourceDescriptor!
109
- const peerKey = keyFromPeerDescriptor(remotePeerDescriptor)
110
- const connection = this.config.ongoingConnectAttempts.get(peerKey)?.getWebrtcConnection()
111
-
110
+ const nodeId = getNodeIdFromPeerDescriptor(remotePeerDescriptor)
111
+ const connection = this.config.ongoingConnectAttempts.get(nodeId)?.getWebrtcConnection()
112
112
  if (!connection) {
113
113
  return {}
114
114
  } else if (connection.connectionId.toString() !== request.connectionId) {
@@ -1,26 +1,16 @@
1
+ import { Logger } from '@streamr/utils'
1
2
  import { RpcRemote } from '../../dht/contact/RpcRemote'
2
3
  import {
3
4
  IceCandidate,
4
- PeerDescriptor,
5
5
  RtcAnswer,
6
6
  RtcOffer,
7
7
  WebrtcConnectionRequest
8
8
  } from '../../proto/packages/dht/protos/DhtRpc'
9
- import { IWebrtcConnectorRpcClient } from '../../proto/packages/dht/protos/DhtRpc.client'
10
- import { ProtoRpcClient } from '@streamr/proto-rpc'
11
- import { Logger } from '@streamr/utils'
9
+ import { WebrtcConnectorRpcClient } from '../../proto/packages/dht/protos/DhtRpc.client'
12
10
 
13
11
  const logger = new Logger(module)
14
12
 
15
- export class WebrtcConnectorRpcRemote extends RpcRemote<IWebrtcConnectorRpcClient> {
16
-
17
- constructor(
18
- localPeerDescriptor: PeerDescriptor,
19
- remotePeerDescriptor: PeerDescriptor,
20
- client: ProtoRpcClient<IWebrtcConnectorRpcClient>
21
- ) {
22
- super(localPeerDescriptor, remotePeerDescriptor, 'DUMMY', client)
23
- }
13
+ export class WebrtcConnectorRpcRemote extends RpcRemote<WebrtcConnectorRpcClient> {
24
14
 
25
15
  requestConnection(): void {
26
16
  const request: WebrtcConnectionRequest = {
@@ -55,12 +55,10 @@ export class AutoCertifierClientFacade {
55
55
 
56
56
  private autoCertifierClient: IAutoCertifierClient
57
57
  private readonly rpcCommunicator: ListeningRpcCommunicator
58
- private readonly setHost: (host: string) => void
59
- private readonly updateCertificate: (certificate: string, privateKey: string) => void
58
+ private readonly config: AutoCertifierClientFacadeConfig
60
59
 
61
60
  constructor(config: AutoCertifierClientFacadeConfig) {
62
- this.setHost = config.setHost
63
- this.updateCertificate = config.updateCertificate
61
+ this.config = config
64
62
  this.rpcCommunicator = new ListeningRpcCommunicator(AUTO_CERTIFIER_SERVICE_ID, config.transport)
65
63
  this.autoCertifierClient = config.createClientFactory ? config.createClientFactory()
66
64
  : defaultAutoCertifierClientFactory(
@@ -73,8 +71,8 @@ export class AutoCertifierClientFacade {
73
71
 
74
72
  async start(): Promise<void> {
75
73
  this.autoCertifierClient.on('updatedCertificate', (subdomain: CertifiedSubdomain) => {
76
- this.setHost(subdomain.fqdn)
77
- this.updateCertificate(subdomain.certificate, subdomain.privateKey)
74
+ this.config.setHost(subdomain.fqdn)
75
+ this.config.updateCertificate(subdomain.certificate, subdomain.privateKey)
78
76
  logger.trace(`Updated certificate`)
79
77
  })
80
78
  await Promise.all([
@@ -15,6 +15,7 @@ export const CUSTOM_GOING_AWAY = 3001
15
15
  const BINARY_TYPE = 'arraybuffer'
16
16
 
17
17
  export class ClientWebsocket extends EventEmitter<ConnectionEvents> implements IConnection {
18
+
18
19
  public readonly connectionId: ConnectionID
19
20
  private socket?: Websocket
20
21
  public connectionType = ConnectionType.WEBSOCKET_CLIENT