@streamr/dht 0.0.1-tatum.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 (344) hide show
  1. package/.eslintignore +5 -0
  2. package/.eslintrc +3 -0
  3. package/README.md +38 -0
  4. package/dist/src/connection/Connection.d.ts +11 -0
  5. package/dist/src/connection/Connection.js +23 -0
  6. package/dist/src/connection/Connection.js.map +1 -0
  7. package/dist/src/connection/ConnectionLockHandler.d.ts +23 -0
  8. package/dist/src/connection/ConnectionLockHandler.js +94 -0
  9. package/dist/src/connection/ConnectionLockHandler.js.map +1 -0
  10. package/dist/src/connection/ConnectionManager.d.ts +94 -0
  11. package/dist/src/connection/ConnectionManager.js +554 -0
  12. package/dist/src/connection/ConnectionManager.js.map +1 -0
  13. package/dist/src/connection/ConnectivityChecker.d.ts +17 -0
  14. package/dist/src/connection/ConnectivityChecker.js +187 -0
  15. package/dist/src/connection/ConnectivityChecker.js.map +1 -0
  16. package/dist/src/connection/Handshaker.d.ts +19 -0
  17. package/dist/src/connection/Handshaker.js +77 -0
  18. package/dist/src/connection/Handshaker.js.map +1 -0
  19. package/dist/src/connection/IConnection.d.ts +38 -0
  20. package/dist/src/connection/IConnection.js +19 -0
  21. package/dist/src/connection/IConnection.js.map +1 -0
  22. package/dist/src/connection/IConnectionSource.d.ts +4 -0
  23. package/dist/src/connection/IConnectionSource.js +3 -0
  24. package/dist/src/connection/IConnectionSource.js.map +1 -0
  25. package/dist/src/connection/ManagedConnection.d.ts +60 -0
  26. package/dist/src/connection/ManagedConnection.js +352 -0
  27. package/dist/src/connection/ManagedConnection.js.map +1 -0
  28. package/dist/src/connection/ManagedWebRtcConnection.d.ts +7 -0
  29. package/dist/src/connection/ManagedWebRtcConnection.js +20 -0
  30. package/dist/src/connection/ManagedWebRtcConnection.js.map +1 -0
  31. package/dist/src/connection/RemoteConnectionLocker.d.ts +14 -0
  32. package/dist/src/connection/RemoteConnectionLocker.js +93 -0
  33. package/dist/src/connection/RemoteConnectionLocker.js.map +1 -0
  34. package/dist/src/connection/Simulator/Simulator.d.ts +42 -0
  35. package/dist/src/connection/Simulator/Simulator.js +325 -0
  36. package/dist/src/connection/Simulator/Simulator.js.map +1 -0
  37. package/dist/src/connection/Simulator/SimulatorConnection.d.ts +19 -0
  38. package/dist/src/connection/Simulator/SimulatorConnection.js +118 -0
  39. package/dist/src/connection/Simulator/SimulatorConnection.js.map +1 -0
  40. package/dist/src/connection/Simulator/SimulatorConnector.d.ts +17 -0
  41. package/dist/src/connection/Simulator/SimulatorConnector.js +72 -0
  42. package/dist/src/connection/Simulator/SimulatorConnector.js.map +1 -0
  43. package/dist/src/connection/Simulator/SimulatorTransport.d.ts +6 -0
  44. package/dist/src/connection/Simulator/SimulatorTransport.js +11 -0
  45. package/dist/src/connection/Simulator/SimulatorTransport.js.map +1 -0
  46. package/dist/src/connection/Simulator/pings.d.ts +21 -0
  47. package/dist/src/connection/Simulator/pings.js +61 -0
  48. package/dist/src/connection/Simulator/pings.js.map +1 -0
  49. package/dist/src/connection/WebRTC/IWebRtcConnection.d.ts +20 -0
  50. package/dist/src/connection/WebRTC/IWebRtcConnection.js +9 -0
  51. package/dist/src/connection/WebRTC/IWebRtcConnection.js.map +1 -0
  52. package/dist/src/connection/WebRTC/NodeWebRtcConnection.d.ts +47 -0
  53. package/dist/src/connection/WebRTC/NodeWebRtcConnection.js +233 -0
  54. package/dist/src/connection/WebRTC/NodeWebRtcConnection.js.map +1 -0
  55. package/dist/src/connection/WebRTC/RemoteWebrtcConnector.d.ts +12 -0
  56. package/dist/src/connection/WebRTC/RemoteWebrtcConnector.js +74 -0
  57. package/dist/src/connection/WebRTC/RemoteWebrtcConnector.js.map +1 -0
  58. package/dist/src/connection/WebRTC/WebRtcConnector.d.ts +47 -0
  59. package/dist/src/connection/WebRTC/WebRtcConnector.js +227 -0
  60. package/dist/src/connection/WebRTC/WebRtcConnector.js.map +1 -0
  61. package/dist/src/connection/WebRTC/iceServerAsString.d.ts +2 -0
  62. package/dist/src/connection/WebRTC/iceServerAsString.js +18 -0
  63. package/dist/src/connection/WebRTC/iceServerAsString.js.map +1 -0
  64. package/dist/src/connection/WebSocket/ClientWebSocket.d.ts +15 -0
  65. package/dist/src/connection/WebSocket/ClientWebSocket.js +113 -0
  66. package/dist/src/connection/WebSocket/ClientWebSocket.js.map +1 -0
  67. package/dist/src/connection/WebSocket/RemoteWebSocketConnector.d.ts +9 -0
  68. package/dist/src/connection/WebSocket/RemoteWebSocketConnector.js +63 -0
  69. package/dist/src/connection/WebSocket/RemoteWebSocketConnector.js.map +1 -0
  70. package/dist/src/connection/WebSocket/ServerWebSocket.d.ts +18 -0
  71. package/dist/src/connection/WebSocket/ServerWebSocket.js +103 -0
  72. package/dist/src/connection/WebSocket/ServerWebSocket.js.map +1 -0
  73. package/dist/src/connection/WebSocket/WebSocketConnector.d.ts +31 -0
  74. package/dist/src/connection/WebSocket/WebSocketConnector.js +202 -0
  75. package/dist/src/connection/WebSocket/WebSocketConnector.js.map +1 -0
  76. package/dist/src/connection/WebSocket/WebSocketServer.d.ts +9 -0
  77. package/dist/src/connection/WebSocket/WebSocketServer.js +101 -0
  78. package/dist/src/connection/WebSocket/WebSocketServer.js.map +1 -0
  79. package/dist/src/dht/DhtNode.d.ts +153 -0
  80. package/dist/src/dht/DhtNode.js +599 -0
  81. package/dist/src/dht/DhtNode.js.map +1 -0
  82. package/dist/src/dht/DhtPeer.d.ts +18 -0
  83. package/dist/src/dht/DhtPeer.js +74 -0
  84. package/dist/src/dht/DhtPeer.js.map +1 -0
  85. package/dist/src/dht/ExternalApi.d.ts +8 -0
  86. package/dist/src/dht/ExternalApi.js +26 -0
  87. package/dist/src/dht/ExternalApi.js.map +1 -0
  88. package/dist/src/dht/RemoteExternalApi.d.ts +6 -0
  89. package/dist/src/dht/RemoteExternalApi.js +26 -0
  90. package/dist/src/dht/RemoteExternalApi.js.map +1 -0
  91. package/dist/src/dht/contact/Contact.d.ts +22 -0
  92. package/dist/src/dht/contact/Contact.js +25 -0
  93. package/dist/src/dht/contact/Contact.js.map +1 -0
  94. package/dist/src/dht/contact/RandomContactList.d.ts +20 -0
  95. package/dist/src/dht/contact/RandomContactList.js +78 -0
  96. package/dist/src/dht/contact/RandomContactList.js.map +1 -0
  97. package/dist/src/dht/contact/Remote.d.ts +15 -0
  98. package/dist/src/dht/contact/Remote.js +24 -0
  99. package/dist/src/dht/contact/Remote.js.map +1 -0
  100. package/dist/src/dht/contact/SortedContactList.d.ts +35 -0
  101. package/dist/src/dht/contact/SortedContactList.js +156 -0
  102. package/dist/src/dht/contact/SortedContactList.js.map +1 -0
  103. package/dist/src/dht/discovery/DiscoverySession.d.ts +36 -0
  104. package/dist/src/dht/discovery/DiscoverySession.js +116 -0
  105. package/dist/src/dht/discovery/DiscoverySession.js.map +1 -0
  106. package/dist/src/dht/discovery/PeerDiscovery.d.ts +42 -0
  107. package/dist/src/dht/discovery/PeerDiscovery.js +157 -0
  108. package/dist/src/dht/discovery/PeerDiscovery.js.map +1 -0
  109. package/dist/src/dht/find/RecursiveFindSession.d.ts +46 -0
  110. package/dist/src/dht/find/RecursiveFindSession.js +142 -0
  111. package/dist/src/dht/find/RecursiveFindSession.js.map +1 -0
  112. package/dist/src/dht/find/RecursiveFinder.d.ts +54 -0
  113. package/dist/src/dht/find/RecursiveFinder.js +180 -0
  114. package/dist/src/dht/find/RecursiveFinder.js.map +1 -0
  115. package/dist/src/dht/find/RemoteRecursiveFindSession.d.ts +6 -0
  116. package/dist/src/dht/find/RemoteRecursiveFindSession.js +25 -0
  117. package/dist/src/dht/find/RemoteRecursiveFindSession.js.map +1 -0
  118. package/dist/src/dht/routing/DuplicateDetector.d.ts +13 -0
  119. package/dist/src/dht/routing/DuplicateDetector.js +41 -0
  120. package/dist/src/dht/routing/DuplicateDetector.js.map +1 -0
  121. package/dist/src/dht/routing/RemoteRouter.d.ts +8 -0
  122. package/dist/src/dht/routing/RemoteRouter.js +106 -0
  123. package/dist/src/dht/routing/RemoteRouter.js.map +1 -0
  124. package/dist/src/dht/routing/Router.d.ts +60 -0
  125. package/dist/src/dht/routing/Router.js +207 -0
  126. package/dist/src/dht/routing/Router.js.map +1 -0
  127. package/dist/src/dht/routing/RoutingSession.d.ts +42 -0
  128. package/dist/src/dht/routing/RoutingSession.js +178 -0
  129. package/dist/src/dht/routing/RoutingSession.js.map +1 -0
  130. package/dist/src/dht/store/DataStore.d.ts +45 -0
  131. package/dist/src/dht/store/DataStore.js +244 -0
  132. package/dist/src/dht/store/DataStore.js.map +1 -0
  133. package/dist/src/dht/store/LocalDataStore.d.ts +19 -0
  134. package/dist/src/dht/store/LocalDataStore.js +104 -0
  135. package/dist/src/dht/store/LocalDataStore.js.map +1 -0
  136. package/dist/src/dht/store/RemoteStore.d.ts +8 -0
  137. package/dist/src/dht/store/RemoteStore.js +44 -0
  138. package/dist/src/dht/store/RemoteStore.js.map +1 -0
  139. package/dist/src/exports.d.ts +19 -0
  140. package/dist/src/exports.js +41 -0
  141. package/dist/src/exports.js.map +1 -0
  142. package/dist/src/helpers/AddressTools.d.ts +2 -0
  143. package/dist/src/helpers/AddressTools.js +31 -0
  144. package/dist/src/helpers/AddressTools.js.map +1 -0
  145. package/dist/src/helpers/PeerID.d.ts +25 -0
  146. package/dist/src/helpers/PeerID.js +84 -0
  147. package/dist/src/helpers/PeerID.js.map +1 -0
  148. package/dist/src/helpers/UUID.d.ts +7 -0
  149. package/dist/src/helpers/UUID.js +32 -0
  150. package/dist/src/helpers/UUID.js.map +1 -0
  151. package/dist/src/helpers/debugHelpers.d.ts +3 -0
  152. package/dist/src/helpers/debugHelpers.js +11 -0
  153. package/dist/src/helpers/debugHelpers.js.map +1 -0
  154. package/dist/src/helpers/errors.d.ts +72 -0
  155. package/dist/src/helpers/errors.js +95 -0
  156. package/dist/src/helpers/errors.js.map +1 -0
  157. package/dist/src/helpers/peerIdFromPeerDescriptor.d.ts +5 -0
  158. package/dist/src/helpers/peerIdFromPeerDescriptor.js +17 -0
  159. package/dist/src/helpers/peerIdFromPeerDescriptor.js.map +1 -0
  160. package/dist/src/helpers/protoClasses.d.ts +2 -0
  161. package/dist/src/helpers/protoClasses.js +35 -0
  162. package/dist/src/helpers/protoClasses.js.map +1 -0
  163. package/dist/src/helpers/protoToString.d.ts +2 -0
  164. package/dist/src/helpers/protoToString.js +20 -0
  165. package/dist/src/helpers/protoToString.js.map +1 -0
  166. package/dist/src/proto/google/protobuf/any.d.ts +173 -0
  167. package/dist/src/proto/google/protobuf/any.js +155 -0
  168. package/dist/src/proto/google/protobuf/any.js.map +1 -0
  169. package/dist/src/proto/google/protobuf/empty.d.ts +32 -0
  170. package/dist/src/proto/google/protobuf/empty.js +34 -0
  171. package/dist/src/proto/google/protobuf/empty.js.map +1 -0
  172. package/dist/src/proto/google/protobuf/timestamp.d.ts +149 -0
  173. package/dist/src/proto/google/protobuf/timestamp.js +136 -0
  174. package/dist/src/proto/google/protobuf/timestamp.js.map +1 -0
  175. package/dist/src/proto/packages/dht/protos/DhtRpc.client.d.ts +320 -0
  176. package/dist/src/proto/packages/dht/protos/DhtRpc.client.js +245 -0
  177. package/dist/src/proto/packages/dht/protos/DhtRpc.client.js.map +1 -0
  178. package/dist/src/proto/packages/dht/protos/DhtRpc.d.ts +1089 -0
  179. package/dist/src/proto/packages/dht/protos/DhtRpc.js +710 -0
  180. package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +1 -0
  181. package/dist/src/proto/packages/dht/protos/DhtRpc.server.d.ts +145 -0
  182. package/dist/src/proto/packages/dht/protos/DhtRpc.server.js +3 -0
  183. package/dist/src/proto/packages/dht/protos/DhtRpc.server.js.map +1 -0
  184. package/dist/src/proto/packages/proto-rpc/protos/ProtoRpc.d.ts +87 -0
  185. package/dist/src/proto/packages/proto-rpc/protos/ProtoRpc.js +66 -0
  186. package/dist/src/proto/packages/proto-rpc/protos/ProtoRpc.js.map +1 -0
  187. package/dist/src/proto/tests.d.ts +39 -0
  188. package/dist/src/proto/tests.js +34 -0
  189. package/dist/src/proto/tests.js.map +1 -0
  190. package/dist/src/rpc-protocol/DhtCallContext.d.ts +12 -0
  191. package/dist/src/rpc-protocol/DhtCallContext.js +8 -0
  192. package/dist/src/rpc-protocol/DhtCallContext.js.map +1 -0
  193. package/dist/src/rpc-protocol/DhtRpcOptions.d.ts +8 -0
  194. package/dist/src/rpc-protocol/DhtRpcOptions.js +3 -0
  195. package/dist/src/rpc-protocol/DhtRpcOptions.js.map +1 -0
  196. package/dist/src/transport/ITransport.d.ts +22 -0
  197. package/dist/src/transport/ITransport.js +3 -0
  198. package/dist/src/transport/ITransport.js.map +1 -0
  199. package/dist/src/transport/ListeningRpcCommunicator.d.ts +6 -0
  200. package/dist/src/transport/ListeningRpcCommunicator.js +14 -0
  201. package/dist/src/transport/ListeningRpcCommunicator.js.map +1 -0
  202. package/dist/src/transport/RoutingRpcCommunicator.d.ts +8 -0
  203. package/dist/src/transport/RoutingRpcCommunicator.js +52 -0
  204. package/dist/src/transport/RoutingRpcCommunicator.js.map +1 -0
  205. package/jest.config.js +2 -0
  206. package/karma.config.js +20 -0
  207. package/package.json +64 -0
  208. package/proto.sh +3 -0
  209. package/protos/DhtRpc.proto +330 -0
  210. package/protos/tests.proto +16 -0
  211. package/src/connection/Connection.ts +23 -0
  212. package/src/connection/ConnectionLockHandler.ts +105 -0
  213. package/src/connection/ConnectionManager.ts +676 -0
  214. package/src/connection/ConnectivityChecker.ts +173 -0
  215. package/src/connection/Handshaker.ts +92 -0
  216. package/src/connection/IConnection.ts +47 -0
  217. package/src/connection/IConnectionSource.ts +6 -0
  218. package/src/connection/ManagedConnection.ts +398 -0
  219. package/src/connection/ManagedWebRtcConnection.ts +27 -0
  220. package/src/connection/RemoteConnectionLocker.ts +88 -0
  221. package/src/connection/Simulator/Simulator.ts +399 -0
  222. package/src/connection/Simulator/SimulatorConnection.ts +137 -0
  223. package/src/connection/Simulator/SimulatorConnector.ts +104 -0
  224. package/src/connection/Simulator/SimulatorTransport.ts +9 -0
  225. package/src/connection/Simulator/pings.ts +42 -0
  226. package/src/connection/WebRTC/BrowserWebRtcConnection.ts +227 -0
  227. package/src/connection/WebRTC/IWebRtcConnection.ts +24 -0
  228. package/src/connection/WebRTC/NodeWebRtcConnection.ts +256 -0
  229. package/src/connection/WebRTC/RemoteWebrtcConnector.ts +93 -0
  230. package/src/connection/WebRTC/WebRtcConnector.ts +306 -0
  231. package/src/connection/WebRTC/iceServerAsString.ts +15 -0
  232. package/src/connection/WebSocket/ClientWebSocket.ts +118 -0
  233. package/src/connection/WebSocket/RemoteWebSocketConnector.ts +49 -0
  234. package/src/connection/WebSocket/ServerWebSocket.ts +119 -0
  235. package/src/connection/WebSocket/WebSocketConnector.ts +264 -0
  236. package/src/connection/WebSocket/WebSocketServer.ts +97 -0
  237. package/src/dht/DhtNode.ts +776 -0
  238. package/src/dht/DhtPeer.ts +96 -0
  239. package/src/dht/ExternalApi.ts +29 -0
  240. package/src/dht/RemoteExternalApi.ts +25 -0
  241. package/src/dht/contact/Contact.ts +36 -0
  242. package/src/dht/contact/RandomContactList.ts +92 -0
  243. package/src/dht/contact/Remote.ts +40 -0
  244. package/src/dht/contact/SortedContactList.ts +196 -0
  245. package/src/dht/discovery/DiscoverySession.ts +150 -0
  246. package/src/dht/discovery/PeerDiscovery.ts +162 -0
  247. package/src/dht/find/RecursiveFindSession.ts +178 -0
  248. package/src/dht/find/RecursiveFinder.ts +272 -0
  249. package/src/dht/find/RemoteRecursiveFindSession.ts +33 -0
  250. package/src/dht/routing/DuplicateDetector.ts +53 -0
  251. package/src/dht/routing/RemoteRouter.ts +115 -0
  252. package/src/dht/routing/Router.ts +266 -0
  253. package/src/dht/routing/RoutingSession.ts +222 -0
  254. package/src/dht/store/DataStore.ts +321 -0
  255. package/src/dht/store/LocalDataStore.ts +114 -0
  256. package/src/dht/store/RemoteStore.ts +58 -0
  257. package/src/exports.ts +19 -0
  258. package/src/helpers/AddressTools.ts +26 -0
  259. package/src/helpers/PeerID.ts +95 -0
  260. package/src/helpers/UUID.ts +30 -0
  261. package/src/helpers/debugHelpers.ts +9 -0
  262. package/src/helpers/errors.ts +49 -0
  263. package/src/helpers/peerIdFromPeerDescriptor.ts +14 -0
  264. package/src/helpers/protoClasses.ts +63 -0
  265. package/src/helpers/protoToString.ts +21 -0
  266. package/src/proto/google/protobuf/any.ts +319 -0
  267. package/src/proto/google/protobuf/empty.ts +84 -0
  268. package/src/proto/google/protobuf/timestamp.ts +281 -0
  269. package/src/proto/packages/dht/protos/DhtRpc.client.ts +373 -0
  270. package/src/proto/packages/dht/protos/DhtRpc.server.ts +148 -0
  271. package/src/proto/packages/dht/protos/DhtRpc.ts +1399 -0
  272. package/src/proto/packages/proto-rpc/protos/ProtoRpc.ts +108 -0
  273. package/src/proto/tests.ts +52 -0
  274. package/src/rpc-protocol/DhtCallContext.ts +15 -0
  275. package/src/rpc-protocol/DhtRpcOptions.ts +9 -0
  276. package/src/transport/ITransport.ts +31 -0
  277. package/src/transport/ListeningRpcCommunicator.ts +14 -0
  278. package/src/transport/RoutingRpcCommunicator.ts +59 -0
  279. package/src/types/glogal.d.ts +1 -0
  280. package/src/types/textencoding.d.ts +7 -0
  281. package/test/RandomGraphSimulation.ts +52 -0
  282. package/test/benchmark/KademliaCorrectness.test.ts +115 -0
  283. package/test/benchmark/RecursiveFind.test.ts +87 -0
  284. package/test/benchmark/any.test.ts +28 -0
  285. package/test/benchmark/kademlia-simulation/Contact.ts +32 -0
  286. package/test/benchmark/kademlia-simulation/KademliaSimulation.ts +94 -0
  287. package/test/benchmark/kademlia-simulation/SimulationNode.ts +125 -0
  288. package/test/data/generateGroundTruthData.ts +70 -0
  289. package/test/end-to-end/Layer0-Layer1.test.ts +87 -0
  290. package/test/end-to-end/Layer0.test.ts +60 -0
  291. package/test/end-to-end/Layer0MixedConnectionTypes.test.ts +94 -0
  292. package/test/end-to-end/Layer0WebRTC-Layer1.test.ts +134 -0
  293. package/test/end-to-end/Layer0WebRTC.test.ts +98 -0
  294. package/test/end-to-end/Layer1-Scale-WebRTC.test.ts +69 -0
  295. package/test/end-to-end/Layer1-Scale-WebSocket.test.ts +73 -0
  296. package/test/end-to-end/WebSocketConnectionRequest.test.ts +62 -0
  297. package/test/integration/ConnectionLocking.test.ts +166 -0
  298. package/test/integration/ConnectionManager.test.ts +291 -0
  299. package/test/integration/DhtNodeExternalAPI.test.ts +43 -0
  300. package/test/integration/DhtPeer.test.ts +73 -0
  301. package/test/integration/DhtRpc.test.ts +131 -0
  302. package/test/integration/DhtWithMockConnectionLatencies.test.ts +46 -0
  303. package/test/integration/DhtWithMockConnections.test.ts +46 -0
  304. package/test/integration/DhtWithRealConnectionLatencies.test.ts +47 -0
  305. package/test/integration/Layer1-scale.test.ts +200 -0
  306. package/test/integration/MigrateData.test.ts +203 -0
  307. package/test/integration/Mock-Layer1-Layer0.test.ts +106 -0
  308. package/test/integration/MultipleEntryPointJoining.test.ts +105 -0
  309. package/test/integration/RecursiveFind.test.ts +50 -0
  310. package/test/integration/RemoteRouter.test.ts +83 -0
  311. package/test/integration/RemoteStore.test.ts +66 -0
  312. package/test/integration/RouteMessage.test.ts +254 -0
  313. package/test/integration/RpcErrors.test.ts +153 -0
  314. package/test/integration/ScaleDownDht.test.ts +66 -0
  315. package/test/integration/SimultaneousConnections.test.ts +308 -0
  316. package/test/integration/Store.test.ts +72 -0
  317. package/test/integration/StoreAndDelete.test.ts +93 -0
  318. package/test/integration/StoreOnDhtWithTwoNodes.test.ts +71 -0
  319. package/test/integration/WebRtcConnectionManagement.test.ts +205 -0
  320. package/test/integration/WebRtcConnectorRpc.test.ts +145 -0
  321. package/test/integration/WebSocket.test.ts +64 -0
  322. package/test/integration/WebSocketConnectionManagement.test.ts +131 -0
  323. package/test/integration/WebSocketConnectorRpc.test.ts +86 -0
  324. package/test/kademlia-simulation/data/nodeids.json +13002 -0
  325. package/test/kademlia-simulation/data/orderedneighbors.json +1001 -0
  326. package/test/unit/AddressTools.test.ts +40 -0
  327. package/test/unit/DuplicateDetector.test.ts +29 -0
  328. package/test/unit/LocalDataStore.test.ts +107 -0
  329. package/test/unit/PeerID.test.ts +22 -0
  330. package/test/unit/ProtobufMessage.test.ts +21 -0
  331. package/test/unit/RandomContactList.test.ts +87 -0
  332. package/test/unit/RecursiveFinder.test.ts +112 -0
  333. package/test/unit/Router.test.ts +124 -0
  334. package/test/unit/SortedContactList.test.ts +127 -0
  335. package/test/unit/UUID.test.ts +49 -0
  336. package/test/unit/WebSocketServer.test.ts +42 -0
  337. package/test/utils/mock/RecursiveFinder.ts +19 -0
  338. package/test/utils/mock/Router.ts +53 -0
  339. package/test/utils/mock/Transport.ts +26 -0
  340. package/test/utils/utils.ts +311 -0
  341. package/tsconfig.browser.json +15 -0
  342. package/tsconfig.jest.json +19 -0
  343. package/tsconfig.json +3 -0
  344. package/tsconfig.node.json +18 -0
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ /* eslint-disable max-len, @typescript-eslint/prefer-for-of */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.getRandomRegion = exports.getRegionDelayMatrix = exports.regionPingMatrix = exports.RegionIndex = void 0;
5
+ // This file contains a 16x16 matrix of ping times measured between
6
+ // amazon regions. Converted to typescript from the file pings.csv
7
+ // in order to make loading into browser easier.
8
+ var RegionIndex;
9
+ (function (RegionIndex) {
10
+ RegionIndex[RegionIndex["eu_central_1"] = 0] = "eu_central_1";
11
+ RegionIndex[RegionIndex["eu_west_1"] = 1] = "eu_west_1";
12
+ RegionIndex[RegionIndex["eu_west_2"] = 2] = "eu_west_2";
13
+ RegionIndex[RegionIndex["eu_west_3"] = 3] = "eu_west_3";
14
+ RegionIndex[RegionIndex["eu_north_1"] = 4] = "eu_north_1";
15
+ RegionIndex[RegionIndex["us_east_1"] = 5] = "us_east_1";
16
+ RegionIndex[RegionIndex["us_east_2"] = 6] = "us_east_2";
17
+ RegionIndex[RegionIndex["us_west_1"] = 7] = "us_west_1";
18
+ RegionIndex[RegionIndex["us_west_2"] = 8] = "us_west_2";
19
+ RegionIndex[RegionIndex["ca_central_1"] = 9] = "ca_central_1";
20
+ RegionIndex[RegionIndex["ap_south_1"] = 10] = "ap_south_1";
21
+ RegionIndex[RegionIndex["ap_northeast_2"] = 11] = "ap_northeast_2";
22
+ RegionIndex[RegionIndex["ap_southeast_1"] = 12] = "ap_southeast_1";
23
+ RegionIndex[RegionIndex["ap_southeast_2"] = 13] = "ap_southeast_2";
24
+ RegionIndex[RegionIndex["ap_northeast_1"] = 14] = "ap_northeast_1";
25
+ RegionIndex[RegionIndex["sa_east_1"] = 15] = "sa_east_1";
26
+ })(RegionIndex || (exports.RegionIndex = RegionIndex = {}));
27
+ exports.regionPingMatrix = [
28
+ [0.325, 23.163, 12.942, 8.923, 20.699, 89.208, 99.98, 150.077, 139.224, 90.454, 117.0, 226.823, 154.592, 286.753, 222.719, 205.563],
29
+ [24.911, 0.195, 10.022, 18.544, 39.802, 66.161, 93.877, 136.271, 127.362, 73.733, 122.187, 229.064, 177.256, 254.277, 200.207, 186.817],
30
+ [12.879, 9.994, 0.167, 8.626, 31.896, 74.663, 85.231, 136.185, 125.328, 77.811, 111.29, 236.34, 164.357, 262.577, 207.745, 187.383],
31
+ [9.007, 16.823, 8.761, 0.191, 28.449, 81.969, 92.599, 140.961, 132.269, 85.444, 107.421, 243.981, 167.17, 279.322, 214.088, 197.986],
32
+ [20.661, 40.0, 31.176, 27.645, 0.137, 104.171, 115.704, 165.01, 155.741, 107.635, 136.75, 267.321, 173.951, 292.266, 238.492, 216.048],
33
+ [89.076, 67.701, 75.414, 81.598, 104.866, 0.284, 11.501, 61.662, 78.612, 14.115, 186.697, 174.546, 210.93, 196.071, 145.622, 114.919],
34
+ [100.018, 93.968, 85.06, 92.582, 115.719, 11.514, 0.184, 51.668, 48.447, 25.808, 195.433, 160.031, 197.27, 186.913, 133.115, 127.954],
35
+ [148.544, 137.18, 136.137, 141.333, 164.73, 60.257, 50.886, 0.197, 21.509, 77.668, 229.32, 134.858, 174.472, 137.329, 107.566, 175.944],
36
+ [137.885, 128.304, 125.316, 132.271, 155.726, 63.376, 48.457, 20.743, 0.293, 59.645, 218.285, 126.988, 162.72, 138.599, 100.203, 174.612],
37
+ [90.494, 78.203, 77.998, 84.348, 109.549, 14.136, 25.917, 77.323, 59.692, 0.163, 187.854, 169.253, 206.944, 195.467, 141.054, 126.962],
38
+ [120.19, 119.978, 112.023, 107.434, 139.361, 185.043, 195.679, 233.008, 216.025, 186.888, 0.177, 130.21, 56.019, 145.643, 128.57, 298.98],
39
+ [226.296, 229.187, 237.024, 243.839, 266.919, 174.727, 160.066, 136.623, 124.799, 169.854, 129.131, 0.189, 81.065, 139.967, 33.24, 284.578],
40
+ [154.691, 178.279, 170.997, 154.261, 173.776, 211.511, 197.551, 173.735, 162.834, 206.659, 56.964, 68.853, 0.215, 91.601, 69.684, 323.146],
41
+ [289.784, 253.234, 261.752, 277.504, 292.125, 198.099, 185.709, 136.413, 138.613, 194.986, 142.484, 147.706, 91.615, 0.156, 114.518, 311.12],
42
+ [223.926, 201.084, 210.133, 216.779, 237.762, 145.336, 132.887, 108.26, 98.057, 142.613, 122.716, 33.185, 68.547, 114.901, 0.162, 257.403],
43
+ [205.555, 178.082, 186.533, 195.774, 216.701, 117.089, 128.001, 175.761, 176.018, 125.551, 303.904, 285.782, 323.15, 309.618, 255.904, 0.262]
44
+ ];
45
+ function getRegionDelayMatrix() {
46
+ const ret = [];
47
+ for (let i = 0; i < exports.regionPingMatrix.length; i++) {
48
+ const row = [];
49
+ for (let j = 0; j < exports.regionPingMatrix[i].length; j++) {
50
+ row.push(exports.regionPingMatrix[i][j] / 2);
51
+ }
52
+ ret.push(row);
53
+ }
54
+ return ret;
55
+ }
56
+ exports.getRegionDelayMatrix = getRegionDelayMatrix;
57
+ function getRandomRegion() {
58
+ return Math.floor(Math.random() * 15);
59
+ }
60
+ exports.getRandomRegion = getRandomRegion;
61
+ //# sourceMappingURL=pings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pings.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,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC;CAChJ,CAAA;AAED,SAAgB,oBAAoB;IAChC,MAAM,GAAG,GAAG,EAAE,CAAA;IACd,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,wBAAgB,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QAC9C,MAAM,GAAG,GAAG,EAAE,CAAA;QACd,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,wBAAgB,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YACjD,GAAG,CAAC,IAAI,CAAC,wBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAA;SACvC;QACD,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;KAChB;IACD,OAAO,GAAG,CAAA;AACd,CAAC;AAVD,oDAUC;AAED,SAAgB,eAAe;IAC3B,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,CAAA;AACzC,CAAC;AAFD,0CAEC"}
@@ -0,0 +1,20 @@
1
+ export interface WebRtcConnectionEvents {
2
+ localDescription: (description: string, type: string) => void;
3
+ localCandidate: (candidate: string, mid: string) => void;
4
+ }
5
+ export declare enum RtcDescription {
6
+ OFFER = "offer",
7
+ ANSWER = "answer"
8
+ }
9
+ export interface IWebRtcConnection {
10
+ start(isOffering: boolean): void;
11
+ on(event: 'localDescription', listener: (description: string, type: string) => void): this;
12
+ on(event: 'localCandidate', listener: (candidate: string, mid: string) => void): this;
13
+ once(event: 'localDescription', listener: (description: string, type: string) => void): this;
14
+ once(event: 'localCandidate', listener: (candidate: string, mid: string) => void): this;
15
+ off(event: 'localDescription', listener: (description: string, type: string) => void): this;
16
+ off(event: 'localCandidate', listener: (candidate: string, mid: string) => void): this;
17
+ setRemoteDescription(description: string, type: string): Promise<void>;
18
+ addRemoteCandidate(candidate: string, mid: string): void;
19
+ isOpen(): boolean;
20
+ }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RtcDescription = void 0;
4
+ var RtcDescription;
5
+ (function (RtcDescription) {
6
+ RtcDescription["OFFER"] = "offer";
7
+ RtcDescription["ANSWER"] = "answer";
8
+ })(RtcDescription || (exports.RtcDescription = RtcDescription = {}));
9
+ //# sourceMappingURL=IWebRtcConnection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IWebRtcConnection.js","sourceRoot":"","sources":["../../../../src/connection/WebRTC/IWebRtcConnection.ts"],"names":[],"mappings":";;;AAKA,IAAY,cAGX;AAHD,WAAY,cAAc;IACtB,iCAAe,CAAA;IACf,mCAAiB,CAAA;AACrB,CAAC,EAHW,cAAc,8BAAd,cAAc,QAGzB"}
@@ -0,0 +1,47 @@
1
+ import { IWebRtcConnection, WebRtcConnectionEvents } from './IWebRtcConnection';
2
+ import { ConnectionType, IConnection, ConnectionID, ConnectionEvents } from '../IConnection';
3
+ import { PeerDescriptor } from '../../proto/packages/dht/protos/DhtRpc';
4
+ import EventEmitter from 'eventemitter3';
5
+ import { DisconnectionType } from '../../transport/ITransport';
6
+ import { IceServer } from './WebRtcConnector';
7
+ export declare const WEB_RTC_CLEANUP: {
8
+ cleanUp(): void;
9
+ };
10
+ export interface Params {
11
+ remotePeerDescriptor: PeerDescriptor;
12
+ bufferThresholdHigh?: number;
13
+ bufferThresholdLow?: number;
14
+ connectingTimeout?: number;
15
+ iceServers?: IceServer[];
16
+ }
17
+ type Events = WebRtcConnectionEvents & ConnectionEvents;
18
+ export declare class NodeWebRtcConnection extends EventEmitter<Events> implements IConnection, IWebRtcConnection {
19
+ connectionId: ConnectionID;
20
+ private connection?;
21
+ private dataChannel?;
22
+ private lastState;
23
+ private remoteDescriptionSet;
24
+ private connectingTimeoutRef?;
25
+ readonly connectionType: ConnectionType;
26
+ private readonly iceServers;
27
+ private readonly bufferThresholdHigh;
28
+ private readonly bufferThresholdLow;
29
+ private readonly connectingTimeout;
30
+ private readonly remotePeerDescriptor;
31
+ private closed;
32
+ constructor(params: Params);
33
+ start(isOffering: boolean): void;
34
+ setRemoteDescription(description: string, type: string): Promise<void>;
35
+ addRemoteCandidate(candidate: string, mid: string): void;
36
+ send(data: Uint8Array): void;
37
+ close(disconnectionType: DisconnectionType, reason?: string): Promise<void>;
38
+ private doClose;
39
+ destroy(): void;
40
+ private onDataChannel;
41
+ private setupDataChannel;
42
+ private openDataChannel;
43
+ private onStateChange;
44
+ isOpen(): boolean;
45
+ setConnectionId(connectionID: string): void;
46
+ }
47
+ export {};
@@ -0,0 +1,233 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.NodeWebRtcConnection = exports.WEB_RTC_CLEANUP = void 0;
30
+ const IConnection_1 = require("../IConnection");
31
+ const eventemitter3_1 = __importDefault(require("eventemitter3"));
32
+ const node_datachannel_1 = __importStar(require("node-datachannel"));
33
+ const utils_1 = require("@streamr/utils");
34
+ const errors_1 = require("../../helpers/errors");
35
+ const peerIdFromPeerDescriptor_1 = require("../../helpers/peerIdFromPeerDescriptor");
36
+ const iceServerAsString_1 = require("./iceServerAsString");
37
+ const logger = new utils_1.Logger(module);
38
+ const MAX_MESSAGE_SIZE = 1048576;
39
+ exports.WEB_RTC_CLEANUP = new class {
40
+ // eslint-disable-next-line class-methods-use-this
41
+ cleanUp() {
42
+ node_datachannel_1.default.cleanup();
43
+ }
44
+ };
45
+ // Re-defined accoring to https://github.com/microsoft/TypeScript/blob/main/src/lib/dom.generated.d.ts
46
+ // because importing single dom definitions in not possible
47
+ var RTCPeerConnectionStateEnum;
48
+ (function (RTCPeerConnectionStateEnum) {
49
+ RTCPeerConnectionStateEnum["closed"] = "closed";
50
+ RTCPeerConnectionStateEnum["connected"] = "connected";
51
+ RTCPeerConnectionStateEnum["connecting"] = "connecting";
52
+ RTCPeerConnectionStateEnum["disconnected"] = "disconnected";
53
+ RTCPeerConnectionStateEnum["failed"] = "failed";
54
+ RTCPeerConnectionStateEnum["new"] = "new";
55
+ })(RTCPeerConnectionStateEnum || (RTCPeerConnectionStateEnum = {}));
56
+ node_datachannel_1.default.initLogger('Fatal');
57
+ class NodeWebRtcConnection extends eventemitter3_1.default {
58
+ constructor(params) {
59
+ super();
60
+ this.lastState = 'connecting';
61
+ this.remoteDescriptionSet = false;
62
+ this.connectionType = IConnection_1.ConnectionType.WEBRTC;
63
+ this.closed = false;
64
+ this.connectionId = new IConnection_1.ConnectionID();
65
+ this.iceServers = params.iceServers || [];
66
+ this.bufferThresholdHigh = params.bufferThresholdHigh || 2 ** 17;
67
+ this.bufferThresholdLow = params.bufferThresholdLow || 2 ** 15;
68
+ this.connectingTimeout = params.connectingTimeout || 20000;
69
+ this.remotePeerDescriptor = params.remotePeerDescriptor;
70
+ }
71
+ start(isOffering) {
72
+ logger.trace(`Staring new connection for peer: ${this.remotePeerDescriptor.kademliaId.toString()}`);
73
+ const hexId = (0, peerIdFromPeerDescriptor_1.keyFromPeerDescriptor)(this.remotePeerDescriptor);
74
+ logger.trace(`Staring new connection for peer: ${hexId} offering: ${isOffering}`);
75
+ this.connection = new node_datachannel_1.PeerConnection(hexId, {
76
+ iceServers: this.iceServers.map(iceServerAsString_1.iceServerAsString),
77
+ maxMessageSize: MAX_MESSAGE_SIZE
78
+ });
79
+ this.connectingTimeoutRef = setTimeout(() => {
80
+ logger.trace('connectingTimeout, this.closed === ' + this.closed);
81
+ this.doClose('OTHER');
82
+ }, this.connectingTimeout);
83
+ this.connection.onStateChange((state) => this.onStateChange(state));
84
+ this.connection.onGatheringStateChange((_state) => { });
85
+ this.connection.onLocalDescription((description, type) => {
86
+ this.emit('localDescription', description, type.toString());
87
+ });
88
+ this.connection.onLocalCandidate((candidate, mid) => {
89
+ this.emit('localCandidate', candidate, mid);
90
+ });
91
+ if (isOffering) {
92
+ const dataChannel = this.connection.createDataChannel('streamrDataChannel');
93
+ this.setupDataChannel(dataChannel);
94
+ }
95
+ else {
96
+ this.connection.onDataChannel((dataChannel) => this.onDataChannel(dataChannel));
97
+ }
98
+ }
99
+ async setRemoteDescription(description, type) {
100
+ if (this.connection) {
101
+ try {
102
+ logger.trace(`Setting remote descriptor for peer: ${(0, peerIdFromPeerDescriptor_1.keyFromPeerDescriptor)(this.remotePeerDescriptor)}`);
103
+ this.connection.setRemoteDescription(description, type);
104
+ this.remoteDescriptionSet = true;
105
+ }
106
+ catch (err) {
107
+ logger.warn(`Failed to set remote descriptor for peer ${(0, peerIdFromPeerDescriptor_1.keyFromPeerDescriptor)(this.remotePeerDescriptor)}`);
108
+ }
109
+ }
110
+ else {
111
+ this.doClose('OTHER', `Tried to set description for non-existent connection`);
112
+ }
113
+ }
114
+ addRemoteCandidate(candidate, mid) {
115
+ if (this.connection) {
116
+ if (this.remoteDescriptionSet) {
117
+ try {
118
+ logger.trace(`Setting remote candidate for peer: ${(0, peerIdFromPeerDescriptor_1.keyFromPeerDescriptor)(this.remotePeerDescriptor)}`);
119
+ this.connection.addRemoteCandidate(candidate, mid);
120
+ }
121
+ catch (err) {
122
+ logger.warn(`Failed to set remote candidate for peer ${(0, peerIdFromPeerDescriptor_1.keyFromPeerDescriptor)(this.remotePeerDescriptor)}`);
123
+ this.doClose('OTHER');
124
+ }
125
+ }
126
+ else {
127
+ this.doClose('OTHER', `Tried to set candidate before description`);
128
+ }
129
+ }
130
+ else {
131
+ this.doClose('OTHER', `Tried to set candidate for non-existent connection`);
132
+ }
133
+ }
134
+ send(data) {
135
+ if (this.isOpen()) {
136
+ try {
137
+ this.dataChannel.sendMessageBinary(data);
138
+ }
139
+ catch (err) {
140
+ logger.warn('Failed to send binary message to ' + (0, peerIdFromPeerDescriptor_1.keyFromPeerDescriptor)(this.remotePeerDescriptor) + err);
141
+ }
142
+ }
143
+ }
144
+ async close(disconnectionType, reason) {
145
+ this.doClose(disconnectionType, reason);
146
+ }
147
+ doClose(disconnectionType, reason) {
148
+ if (!this.closed) {
149
+ logger.trace(`Closing Node WebRTC Connection to ${(0, peerIdFromPeerDescriptor_1.keyFromPeerDescriptor)(this.remotePeerDescriptor)}`
150
+ + `${reason ? `, reason: ${reason}` : ''}`);
151
+ this.closed = true;
152
+ this.emit('disconnected', disconnectionType, undefined, reason);
153
+ this.removeAllListeners();
154
+ if (this.connectingTimeoutRef) {
155
+ clearTimeout(this.connectingTimeoutRef);
156
+ }
157
+ if (this.dataChannel) {
158
+ try {
159
+ logger.trace('closing datachannel');
160
+ this.dataChannel.close();
161
+ }
162
+ catch (e) {
163
+ logger.warn('dc.close() errored: %s', e);
164
+ }
165
+ }
166
+ if (this.connection) {
167
+ try {
168
+ this.connection.close();
169
+ }
170
+ catch (e) {
171
+ logger.warn('conn.close() errored: %s', e);
172
+ }
173
+ }
174
+ }
175
+ }
176
+ destroy() {
177
+ this.removeAllListeners();
178
+ this.doClose('OTHER');
179
+ }
180
+ onDataChannel(dataChannel) {
181
+ this.openDataChannel(dataChannel);
182
+ this.setupDataChannel(dataChannel);
183
+ }
184
+ setupDataChannel(dataChannel) {
185
+ dataChannel.setBufferedAmountLowThreshold(this.bufferThresholdLow);
186
+ dataChannel.onOpen(() => {
187
+ logger.trace(`dc.onOpened`);
188
+ this.openDataChannel(dataChannel);
189
+ });
190
+ dataChannel.onClosed(() => {
191
+ logger.trace(`dc.closed`);
192
+ this.doClose('OTHER', 'DataChannel closed');
193
+ });
194
+ dataChannel.onError((err) => logger.error('error', { err }));
195
+ dataChannel.onBufferedAmountLow(() => {
196
+ logger.trace(`dc.onBufferedAmountLow`);
197
+ });
198
+ dataChannel.onMessage((msg) => {
199
+ logger.trace(`dc.onMessage`);
200
+ this.emit('data', msg);
201
+ });
202
+ }
203
+ openDataChannel(dataChannel) {
204
+ if (this.connectingTimeoutRef) {
205
+ clearTimeout(this.connectingTimeoutRef);
206
+ }
207
+ this.dataChannel = dataChannel;
208
+ logger.trace(`DataChannel opened for peer ${this.remotePeerDescriptor.kademliaId.toString()}`);
209
+ this.emit('connected');
210
+ }
211
+ onStateChange(state) {
212
+ logger.trace('onStateChange ' + state);
213
+ if (!Object.keys(RTCPeerConnectionStateEnum).filter((s) => isNaN(+s)).includes(state)) {
214
+ throw new errors_1.IllegalRTCPeerConnectionState('NodeWebRtcConnection used an unknown state: ' + state);
215
+ }
216
+ else {
217
+ this.lastState = state;
218
+ }
219
+ if (state === RTCPeerConnectionStateEnum.closed
220
+ || state === RTCPeerConnectionStateEnum.disconnected
221
+ || state === RTCPeerConnectionStateEnum.failed) {
222
+ this.doClose('OTHER');
223
+ }
224
+ }
225
+ isOpen() {
226
+ return !this.closed && this.lastState === 'connected' && !!this.dataChannel;
227
+ }
228
+ setConnectionId(connectionID) {
229
+ this.connectionId = new IConnection_1.ConnectionID(connectionID);
230
+ }
231
+ }
232
+ exports.NodeWebRtcConnection = NodeWebRtcConnection;
233
+ //# sourceMappingURL=NodeWebRtcConnection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NodeWebRtcConnection.js","sourceRoot":"","sources":["../../../../src/connection/WebRTC/NodeWebRtcConnection.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,gDAA4F;AAE5F,kEAAwC;AACxC,qEAAgG;AAChG,0CAAuC;AACvC,iDAAoE;AACpE,qFAA8E;AAE9E,2DAAuD;AAGvD,MAAM,MAAM,GAAG,IAAI,cAAM,CAAC,MAAM,CAAC,CAAA;AAEjC,MAAM,gBAAgB,GAAG,OAAO,CAAA;AAEnB,QAAA,eAAe,GAAG,IAAI;IAC/B,kDAAkD;IAClD,OAAO;QACH,0BAAe,CAAC,OAAO,EAAE,CAAA;IAC7B,CAAC;CACJ,CAAA;AAUD,sGAAsG;AACtG,2DAA2D;AAE3D,IAAK,0BAOJ;AAPD,WAAK,0BAA0B;IAC3B,+CAAiB,CAAA;IACjB,qDAAuB,CAAA;IACvB,uDAAyB,CAAA;IACzB,2DAA6B,CAAA;IAC7B,+CAAiB,CAAA;IACjB,yCAAW,CAAA;AACf,CAAC,EAPI,0BAA0B,KAA1B,0BAA0B,QAO9B;AAED,0BAAe,CAAC,UAAU,CAAC,OAAO,CAAC,CAAA;AAMnC,MAAa,oBAAqB,SAAQ,uBAAoB;IAiB1D,YAAY,MAAc;QACtB,KAAK,EAAE,CAAA;QAbH,cAAS,GAA2B,YAAY,CAAA;QAChD,yBAAoB,GAAG,KAAK,CAAA;QAGpB,mBAAc,GAAmB,4BAAc,CAAC,MAAM,CAAA;QAM9D,WAAM,GAAG,KAAK,CAAA;QAIlB,IAAI,CAAC,YAAY,GAAG,IAAI,0BAAY,EAAE,CAAA;QACtC,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,IAAI,EAAE,CA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AA;QACtC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;YACnF,MAAM,IAAI,sCAA6B,CAAC,8CAA8C,GAAG,KAAK,CAAC,CAAA;SAClG;aAAM;YACH,IAAI,CAAC,SAAS,GAAG,KAA+B,CAAA;SACnD;QAED,IAAI,KAAK,KAAK,0BAA0B,CAAC,MAAM;eACxC,KAAK,KAAK,0BAA0B,CAAC,YAAY;eACjD,KAAK,KAAK,0BAA0B,CAAC,MAAM,EAChD;YACE,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;SACxB;IAEL,CAAC;IAED,MAAM;QACF,OAAO,CAAC,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,SAAS,KAAK,WAAW,IAAI,CAAC,CAAC,IAAI,CAAC,WAAW,CAAA;IAC/E,CAAC;IAEM,eAAe,CAAC,YAAoB;QACvC,IAAI,CAAC,YAAY,GAAG,IAAI,0BAAY,CAAC,YAAY,CAAC,CAAA;IACtD,CAAC;CACJ;AA9MD,oDA8MC"}
@@ -0,0 +1,12 @@
1
+ import { PeerDescriptor } from '../../proto/packages/dht/protos/DhtRpc';
2
+ import { IWebRtcConnectorServiceClient } from '../../proto/packages/dht/protos/DhtRpc.client';
3
+ import { ProtoRpcClient } from '@streamr/proto-rpc';
4
+ export declare class RemoteWebrtcConnector {
5
+ private peerDescriptor;
6
+ private client;
7
+ constructor(peerDescriptor: PeerDescriptor, client: ProtoRpcClient<IWebRtcConnectorServiceClient>);
8
+ requestConnection(sourceDescriptor: PeerDescriptor, connectionId: string): void;
9
+ sendRtcOffer(sourceDescriptor: PeerDescriptor, description: string, connectionId: string): void;
10
+ sendRtcAnswer(sourceDescriptor: PeerDescriptor, description: string, connectionId: string): void;
11
+ sendIceCandidate(sourceDescriptor: PeerDescriptor, candidate: string, mid: string, connectionId: string): void;
12
+ }
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RemoteWebrtcConnector = void 0;
4
+ const utils_1 = require("@streamr/utils");
5
+ const logger = new utils_1.Logger(module);
6
+ class RemoteWebrtcConnector {
7
+ constructor(peerDescriptor, client) {
8
+ this.peerDescriptor = peerDescriptor;
9
+ this.client = client;
10
+ }
11
+ requestConnection(sourceDescriptor, connectionId) {
12
+ const request = {
13
+ target: this.peerDescriptor,
14
+ requester: sourceDescriptor,
15
+ connectionId
16
+ };
17
+ const options = {
18
+ sourceDescriptor: sourceDescriptor,
19
+ targetDescriptor: this.peerDescriptor,
20
+ notification: true
21
+ };
22
+ this.client.requestConnection(request, options).catch((_e) => {
23
+ logger.trace('Failed to send requestConnection');
24
+ });
25
+ }
26
+ sendRtcOffer(sourceDescriptor, description, connectionId) {
27
+ const request = {
28
+ target: this.peerDescriptor,
29
+ requester: sourceDescriptor,
30
+ connectionId,
31
+ description
32
+ };
33
+ const options = {
34
+ sourceDescriptor: sourceDescriptor,
35
+ targetDescriptor: this.peerDescriptor,
36
+ };
37
+ this.client.rtcOffer(request, options).catch((_e) => {
38
+ logger.trace('Failed to send rtcOffer');
39
+ });
40
+ }
41
+ sendRtcAnswer(sourceDescriptor, description, connectionId) {
42
+ const request = {
43
+ target: this.peerDescriptor,
44
+ requester: sourceDescriptor,
45
+ connectionId,
46
+ description
47
+ };
48
+ const options = {
49
+ sourceDescriptor: sourceDescriptor,
50
+ targetDescriptor: this.peerDescriptor,
51
+ };
52
+ this.client.rtcAnswer(request, options).catch((_e) => {
53
+ logger.trace('Failed to send rtcAnswer');
54
+ });
55
+ }
56
+ sendIceCandidate(sourceDescriptor, candidate, mid, connectionId) {
57
+ const request = {
58
+ target: this.peerDescriptor,
59
+ requester: sourceDescriptor,
60
+ connectionId,
61
+ mid,
62
+ candidate
63
+ };
64
+ const options = {
65
+ sourceDescriptor: sourceDescriptor,
66
+ targetDescriptor: this.peerDescriptor,
67
+ };
68
+ this.client.iceCandidate(request, options).catch((_e) => {
69
+ logger.trace('Failed to send iceCandidate');
70
+ });
71
+ }
72
+ }
73
+ exports.RemoteWebrtcConnector = RemoteWebrtcConnector;
74
+ //# sourceMappingURL=RemoteWebrtcConnector.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RemoteWebrtcConnector.js","sourceRoot":"","sources":["../../../../src/connection/WebRTC/RemoteWebrtcConnector.ts"],"names":[],"mappings":";;;AAUA,0CAAuC;AAEvC,MAAM,MAAM,GAAG,IAAI,cAAM,CAAC,MAAM,CAAC,CAAA;AAEjC,MAAa,qBAAqB;IAK9B,YAAY,cAA8B,EAAE,MAAqD;QAC7F,IAAI,CAAC,cAAc,GAAG,cAAc,CAAA;QACpC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACxB,CAAC;IAED,iBAAiB,CAAC,gBAAgC,EAAE,YAAoB;QACpE,MAAM,OAAO,GAA4B;YACrC,MAAM,EAAE,IAAI,CAAC,cAAc;YAC3B,SAAS,EAAE,gBAAgB;YAC3B,YAAY;SACf,CAAA;QACD,MAAM,OAAO,GAAkB;YAC3B,gBAAgB,EAAE,gBAAkC;YACpD,gBAAgB,EAAE,IAAI,CAAC,cAAgC;YACvD,YAAY,EAAE,IAAI;SACrB,CAAA;QAED,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,EAAE;YACzD,MAAM,CAAC,KAAK,CAAC,kCAAkC,CAAC,CAAA;QACpD,CAAC,CAAC,CAAA;IACN,CAAC;IAED,YAAY,CAAC,gBAAgC,EAAE,WAAmB,EAAE,YAAoB;QACpF,MAAM,OAAO,GAAa;YACtB,MAAM,EAAE,IAAI,CAAC,cAAc;YAC3B,SAAS,EAAE,gBAAgB;YAC3B,YAAY;YACZ,WAAW;SACd,CAAA;QACD,MAAM,OAAO,GA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/C,CAAC,CAAC,CAAA;IACN,CAAC;CACJ;AA7ED,sDA6EC"}
@@ -0,0 +1,47 @@
1
+ import { IceCandidate, PeerDescriptor, RtcAnswer, RtcOffer, WebRtcConnectionRequest } from '../../proto/packages/dht/protos/DhtRpc';
2
+ import { Empty } from '../../proto/google/protobuf/empty';
3
+ import { ITransport } from '../../transport/ITransport';
4
+ import { IWebRtcConnectorService } from '../../proto/packages/dht/protos/DhtRpc.server';
5
+ import { ServerCallContext } from '@protobuf-ts/runtime-rpc';
6
+ import { ManagedConnection } from '../ManagedConnection';
7
+ export interface WebRtcConnectorConfig {
8
+ rpcTransport: ITransport;
9
+ protocolVersion: string;
10
+ iceServers?: IceServer[];
11
+ allowPrivateAddresses?: boolean;
12
+ bufferThresholdLow?: number;
13
+ bufferThresholdHigh?: number;
14
+ connectionTimeout?: number;
15
+ }
16
+ export interface IceServer {
17
+ url: string;
18
+ port: number;
19
+ username?: string;
20
+ password?: string;
21
+ tcp?: boolean;
22
+ }
23
+ export declare class WebRtcConnector implements IWebRtcConnectorService {
24
+ private static readonly WEBRTC_CONNECTOR_SERVICE_ID;
25
+ private readonly rpcCommunicator;
26
+ private readonly ongoingConnectAttempts;
27
+ private ownPeerDescriptor?;
28
+ private stopped;
29
+ private iceServers;
30
+ private allowPrivateAddresses;
31
+ private config;
32
+ private incomingConnectionCallback;
33
+ constructor(config: WebRtcConnectorConfig, incomingConnectionCallback: (connection: ManagedConnection) => boolean);
34
+ connect(targetPeerDescriptor: PeerDescriptor): ManagedConnection;
35
+ setOwnPeerDescriptor(peerDescriptor: PeerDescriptor): void;
36
+ isIceCandidateAllowed(candidate: string): boolean;
37
+ private onRtcOffer;
38
+ private onRtcAnswer;
39
+ private onConnectionRequest;
40
+ private onRemoteCandidate;
41
+ stop(): Promise<void>;
42
+ isOffering(targetPeerDescriptor: PeerDescriptor): boolean;
43
+ requestConnection(request: WebRtcConnectionRequest, _context: ServerCallContext): Promise<Empty>;
44
+ rtcOffer(request: RtcOffer, _context: ServerCallContext): Promise<Empty>;
45
+ rtcAnswer(request: RtcAnswer, _context: ServerCallContext): Promise<Empty>;
46
+ iceCandidate(request: IceCandidate, _context: ServerCallContext): Promise<Empty>;
47
+ }