@streamr/dht 0.0.1-tatum.6 → 0.0.1-tatum.8

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 (255) hide show
  1. package/dist/src/connection/ConnectionLockHandler.d.ts +1 -1
  2. package/dist/src/connection/ConnectionLockHandler.js.map +1 -1
  3. package/dist/src/connection/ConnectionLockRpcRemote.d.ts +10 -0
  4. package/dist/src/connection/{RemoteConnectionLocker.js → ConnectionLockRpcRemote.js} +21 -35
  5. package/dist/src/connection/ConnectionLockRpcRemote.js.map +1 -0
  6. package/dist/src/connection/ConnectionManager.d.ts +17 -41
  7. package/dist/src/connection/ConnectionManager.js +148 -212
  8. package/dist/src/connection/ConnectionManager.js.map +1 -1
  9. package/dist/src/connection/ConnectivityChecker.js +16 -13
  10. package/dist/src/connection/ConnectivityChecker.js.map +1 -1
  11. package/dist/src/connection/ConnectorFacade.d.ts +49 -0
  12. package/dist/src/connection/ConnectorFacade.js +83 -0
  13. package/dist/src/connection/ConnectorFacade.js.map +1 -0
  14. package/dist/src/connection/Handshaker.d.ts +1 -2
  15. package/dist/src/connection/Handshaker.js +1 -4
  16. package/dist/src/connection/Handshaker.js.map +1 -1
  17. package/dist/src/connection/ManagedConnection.d.ts +2 -6
  18. package/dist/src/connection/ManagedConnection.js +27 -36
  19. package/dist/src/connection/ManagedConnection.js.map +1 -1
  20. package/dist/src/connection/ManagedWebRtcConnection.d.ts +1 -1
  21. package/dist/src/connection/ManagedWebRtcConnection.js +2 -2
  22. package/dist/src/connection/ManagedWebRtcConnection.js.map +1 -1
  23. package/dist/src/connection/Simulator/Simulator.d.ts +0 -2
  24. package/dist/src/connection/Simulator/Simulator.js +0 -5
  25. package/dist/src/connection/Simulator/Simulator.js.map +1 -1
  26. package/dist/src/connection/Simulator/SimulatorConnection.js +16 -13
  27. package/dist/src/connection/Simulator/SimulatorConnection.js.map +1 -1
  28. package/dist/src/connection/Simulator/SimulatorConnector.d.ts +2 -3
  29. package/dist/src/connection/Simulator/SimulatorConnector.js +12 -14
  30. package/dist/src/connection/Simulator/SimulatorConnector.js.map +1 -1
  31. package/dist/src/connection/Simulator/SimulatorTransport.js +6 -1
  32. package/dist/src/connection/Simulator/SimulatorTransport.js.map +1 -1
  33. package/dist/src/connection/WebRTC/NodeWebRtcConnection.d.ts +3 -1
  34. package/dist/src/connection/WebRTC/NodeWebRtcConnection.js +12 -12
  35. package/dist/src/connection/WebRTC/NodeWebRtcConnection.js.map +1 -1
  36. package/dist/src/connection/WebRTC/{WebRtcConnector.d.ts → WebRtcConnectorRpcLocal.d.ts} +13 -13
  37. package/dist/src/connection/WebRTC/{WebRtcConnector.js → WebRtcConnectorRpcLocal.js} +46 -38
  38. package/dist/src/connection/WebRTC/WebRtcConnectorRpcLocal.js.map +1 -0
  39. package/dist/src/connection/WebRTC/WebRtcConnectorRpcRemote.d.ts +11 -0
  40. package/dist/src/connection/WebRTC/WebRtcConnectorRpcRemote.js +55 -0
  41. package/dist/src/connection/WebRTC/WebRtcConnectorRpcRemote.js.map +1 -0
  42. package/dist/src/connection/WebRTC/iceServerAsString.d.ts +1 -1
  43. package/dist/src/connection/WebSocket/{WebSocketConnector.d.ts → WebSocketConnectorRpcLocal.d.ts} +21 -11
  44. package/dist/src/connection/WebSocket/{WebSocketConnector.js → WebSocketConnectorRpcLocal.js} +80 -59
  45. package/dist/src/connection/WebSocket/WebSocketConnectorRpcLocal.js.map +1 -0
  46. package/dist/src/connection/WebSocket/WebSocketConnectorRpcRemote.d.ts +8 -0
  47. package/dist/src/connection/WebSocket/{RemoteWebSocketConnector.js → WebSocketConnectorRpcRemote.js} +12 -16
  48. package/dist/src/connection/WebSocket/WebSocketConnectorRpcRemote.js.map +1 -0
  49. package/dist/src/connection/WebSocket/WebSocketServer.d.ts +11 -1
  50. package/dist/src/connection/WebSocket/WebSocketServer.js +15 -10
  51. package/dist/src/connection/WebSocket/WebSocketServer.js.map +1 -1
  52. package/dist/src/dht/DhtNode.d.ts +18 -55
  53. package/dist/src/dht/DhtNode.js +122 -145
  54. package/dist/src/dht/DhtNode.js.map +1 -1
  55. package/dist/src/dht/{RemoteExternalApi.d.ts → ExternalApiRpcRemote.d.ts} +2 -2
  56. package/dist/src/dht/{RemoteExternalApi.js → ExternalApiRpcRemote.js} +5 -6
  57. package/dist/src/dht/ExternalApiRpcRemote.js.map +1 -0
  58. package/dist/src/dht/{DhtPeer.d.ts → RemoteDhtNode.d.ts} +2 -3
  59. package/dist/src/dht/{DhtPeer.js → RemoteDhtNode.js} +21 -19
  60. package/dist/src/dht/RemoteDhtNode.js.map +1 -0
  61. package/dist/src/dht/contact/ContactList.d.ts +0 -1
  62. package/dist/src/dht/contact/ContactList.js +0 -3
  63. package/dist/src/dht/contact/ContactList.js.map +1 -1
  64. package/dist/src/dht/contact/RandomContactList.d.ts +0 -1
  65. package/dist/src/dht/contact/RandomContactList.js +0 -3
  66. package/dist/src/dht/contact/RandomContactList.js.map +1 -1
  67. package/dist/src/dht/contact/SortedContactList.d.ts +0 -3
  68. package/dist/src/dht/contact/SortedContactList.js +0 -9
  69. package/dist/src/dht/contact/SortedContactList.js.map +1 -1
  70. package/dist/src/dht/discovery/DiscoverySession.d.ts +5 -7
  71. package/dist/src/dht/discovery/DiscoverySession.js +9 -10
  72. package/dist/src/dht/discovery/DiscoverySession.js.map +1 -1
  73. package/dist/src/dht/discovery/PeerDiscovery.d.ts +12 -11
  74. package/dist/src/dht/discovery/PeerDiscovery.js +33 -37
  75. package/dist/src/dht/discovery/PeerDiscovery.js.map +1 -1
  76. package/dist/src/dht/find/RecursiveFindSession.d.ts +9 -10
  77. package/dist/src/dht/find/RecursiveFindSession.js +13 -13
  78. package/dist/src/dht/find/RecursiveFindSession.js.map +1 -1
  79. package/dist/src/dht/find/RecursiveFinder.d.ts +9 -11
  80. package/dist/src/dht/find/RecursiveFinder.js +35 -36
  81. package/dist/src/dht/find/RecursiveFinder.js.map +1 -1
  82. package/dist/src/dht/find/RemoteRecursiveFindSession.d.ts +1 -1
  83. package/dist/src/dht/find/RemoteRecursiveFindSession.js +4 -4
  84. package/dist/src/dht/find/RemoteRecursiveFindSession.js.map +1 -1
  85. package/dist/src/dht/registerExternalApiRpcMethods.d.ts +1 -1
  86. package/dist/src/dht/registerExternalApiRpcMethods.js +4 -3
  87. package/dist/src/dht/registerExternalApiRpcMethods.js.map +1 -1
  88. package/dist/src/dht/routing/DuplicateDetector.d.ts +1 -2
  89. package/dist/src/dht/routing/DuplicateDetector.js +2 -7
  90. package/dist/src/dht/routing/DuplicateDetector.js.map +1 -1
  91. package/dist/src/dht/routing/Router.d.ts +12 -15
  92. package/dist/src/dht/routing/Router.js +30 -33
  93. package/dist/src/dht/routing/Router.js.map +1 -1
  94. package/dist/src/dht/routing/{RemoteRouter.d.ts → RouterRpcRemote.d.ts} +2 -2
  95. package/dist/src/dht/routing/{RemoteRouter.js → RouterRpcRemote.js} +5 -5
  96. package/dist/src/dht/routing/RouterRpcRemote.js.map +1 -0
  97. package/dist/src/dht/routing/RoutingSession.d.ts +3 -4
  98. package/dist/src/dht/routing/RoutingSession.js +6 -5
  99. package/dist/src/dht/routing/RoutingSession.js.map +1 -1
  100. package/dist/src/dht/store/{DataStore.d.ts → StoreRpcLocal.d.ts} +6 -6
  101. package/dist/src/dht/store/{DataStore.js → StoreRpcLocal.js} +34 -34
  102. package/dist/src/dht/store/StoreRpcLocal.js.map +1 -0
  103. package/dist/src/dht/store/{RemoteStore.d.ts → StoreRpcRemote.d.ts} +2 -2
  104. package/dist/src/dht/store/{RemoteStore.js → StoreRpcRemote.js} +4 -4
  105. package/dist/src/dht/store/StoreRpcRemote.js.map +1 -0
  106. package/dist/src/exports.d.ts +2 -8
  107. package/dist/src/exports.js +2 -14
  108. package/dist/src/exports.js.map +1 -1
  109. package/dist/src/helpers/PeerID.d.ts +0 -1
  110. package/dist/src/helpers/PeerID.js +0 -6
  111. package/dist/src/helpers/PeerID.js.map +1 -1
  112. package/dist/src/helpers/browser/isBrowserEnvironment.d.ts +1 -0
  113. package/dist/src/helpers/browser/isBrowserEnvironment.js +6 -0
  114. package/dist/src/helpers/browser/isBrowserEnvironment.js.map +1 -0
  115. package/dist/src/helpers/browser/isBrowserEnvironment_override.d.ts +1 -0
  116. package/dist/src/helpers/browser/isBrowserEnvironment_override.js +7 -0
  117. package/dist/src/helpers/browser/isBrowserEnvironment_override.js.map +1 -0
  118. package/dist/src/helpers/kademliaId.d.ts +1 -0
  119. package/dist/src/helpers/kademliaId.js +14 -0
  120. package/dist/src/helpers/kademliaId.js.map +1 -0
  121. package/dist/src/helpers/peerIdFromPeerDescriptor.d.ts +1 -1
  122. package/dist/src/helpers/peerIdFromPeerDescriptor.js +3 -3
  123. package/dist/src/helpers/peerIdFromPeerDescriptor.js.map +1 -1
  124. package/dist/src/helpers/protoClasses.js +2 -2
  125. package/dist/src/helpers/protoClasses.js.map +1 -1
  126. package/dist/src/proto/packages/dht/protos/DhtRpc.client.d.ts +29 -29
  127. package/dist/src/proto/packages/dht/protos/DhtRpc.client.js +39 -39
  128. package/dist/src/proto/packages/dht/protos/DhtRpc.client.js.map +1 -1
  129. package/dist/src/proto/packages/dht/protos/DhtRpc.d.ts +49 -162
  130. package/dist/src/proto/packages/dht/protos/DhtRpc.js +47 -88
  131. package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +1 -1
  132. package/dist/src/proto/packages/dht/protos/DhtRpc.server.d.ts +15 -15
  133. package/dist/src/transport/RoutingRpcCommunicator.js +1 -0
  134. package/dist/src/transport/RoutingRpcCommunicator.js.map +1 -1
  135. package/package.json +10 -9
  136. package/protos/DhtRpc.proto +30 -60
  137. package/src/connection/ConnectionLockHandler.ts +1 -1
  138. package/src/connection/ConnectionLockRpcRemote.ts +62 -0
  139. package/src/connection/ConnectionManager.ts +178 -274
  140. package/src/connection/ConnectivityChecker.ts +15 -12
  141. package/src/connection/ConnectorFacade.ts +140 -0
  142. package/src/connection/Handshaker.ts +0 -5
  143. package/src/connection/ManagedConnection.ts +26 -40
  144. package/src/connection/ManagedWebRtcConnection.ts +0 -2
  145. package/src/connection/Simulator/Simulator.ts +0 -7
  146. package/src/connection/Simulator/SimulatorConnection.ts +16 -13
  147. package/src/connection/Simulator/SimulatorConnector.ts +13 -19
  148. package/src/connection/Simulator/SimulatorTransport.ts +6 -1
  149. package/src/connection/WebRTC/NodeWebRtcConnection.ts +15 -14
  150. package/src/connection/WebRTC/{WebRtcConnector.ts → WebRtcConnectorRpcLocal.ts} +68 -56
  151. package/src/connection/WebRTC/WebRtcConnectorRpcRemote.ts +71 -0
  152. package/src/connection/WebRTC/iceServerAsString.ts +1 -1
  153. package/src/connection/WebSocket/{WebSocketConnector.ts → WebSocketConnectorRpcLocal.ts} +102 -79
  154. package/src/connection/WebSocket/WebSocketConnectorRpcRemote.ts +45 -0
  155. package/src/connection/WebSocket/WebSocketServer.ts +26 -8
  156. package/src/dht/DhtNode.ts +176 -203
  157. package/src/dht/{RemoteExternalApi.ts → ExternalApiRpcRemote.ts} +3 -4
  158. package/src/dht/{DhtPeer.ts → RemoteDhtNode.ts} +11 -9
  159. package/src/dht/contact/ContactList.ts +0 -4
  160. package/src/dht/contact/RandomContactList.ts +0 -4
  161. package/src/dht/contact/SortedContactList.ts +0 -12
  162. package/src/dht/discovery/DiscoverySession.ts +20 -23
  163. package/src/dht/discovery/PeerDiscovery.ts +47 -45
  164. package/src/dht/find/RecursiveFindSession.ts +21 -22
  165. package/src/dht/find/RecursiveFinder.ts +45 -49
  166. package/src/dht/find/RemoteRecursiveFindSession.ts +6 -6
  167. package/src/dht/registerExternalApiRpcMethods.ts +8 -5
  168. package/src/dht/routing/DuplicateDetector.ts +3 -10
  169. package/src/dht/routing/Router.ts +39 -45
  170. package/src/dht/routing/{RemoteRouter.ts → RouterRpcRemote.ts} +4 -4
  171. package/src/dht/routing/RoutingSession.ts +15 -15
  172. package/src/dht/store/{DataStore.ts → StoreRpcLocal.ts} +42 -42
  173. package/src/dht/store/{RemoteStore.ts → StoreRpcRemote.ts} +2 -2
  174. package/src/exports.ts +2 -8
  175. package/src/helpers/PeerID.ts +0 -7
  176. package/src/helpers/browser/isBrowserEnvironment.ts +1 -0
  177. package/src/helpers/browser/isBrowserEnvironment_override.ts +3 -0
  178. package/src/helpers/kademliaId.ts +8 -0
  179. package/src/helpers/peerIdFromPeerDescriptor.ts +1 -1
  180. package/src/helpers/protoClasses.ts +4 -4
  181. package/src/proto/packages/dht/protos/DhtRpc.client.ts +54 -54
  182. package/src/proto/packages/dht/protos/DhtRpc.server.ts +15 -15
  183. package/src/proto/packages/dht/protos/DhtRpc.ts +77 -216
  184. package/src/transport/RoutingRpcCommunicator.ts +1 -0
  185. package/test/benchmark/KademliaCorrectness.test.ts +4 -2
  186. package/test/benchmark/RecursiveFind.test.ts +6 -6
  187. package/test/end-to-end/Layer0-Layer1.test.ts +9 -9
  188. package/test/end-to-end/Layer0WebRTC-Layer1.test.ts +5 -5
  189. package/test/end-to-end/Layer0WebRTC.test.ts +5 -6
  190. package/test/end-to-end/Layer1-Scale-WebRTC.test.ts +13 -8
  191. package/test/end-to-end/Layer1-Scale-WebSocket.test.ts +15 -10
  192. package/test/end-to-end/WebSocketConnectionRequest.test.ts +5 -5
  193. package/test/integration/ConnectionLocking.test.ts +32 -26
  194. package/test/integration/ConnectionManager.test.ts +90 -93
  195. package/test/integration/DhtJoinPeerDiscovery.test.ts +53 -0
  196. package/test/integration/DhtRpc.test.ts +4 -6
  197. package/test/integration/Layer1-scale.test.ts +8 -8
  198. package/test/integration/MigrateData.test.ts +9 -9
  199. package/test/integration/Mock-Layer1-Layer0.test.ts +1 -2
  200. package/test/integration/RecursiveFind.test.ts +5 -5
  201. package/test/integration/{DhtPeer.test.ts → RemoteDhtNode.test.ts} +11 -12
  202. package/test/integration/RouteMessage.test.ts +7 -9
  203. package/test/integration/{RemoteRouter.test.ts → RouterRpcRemote.test.ts} +13 -14
  204. package/test/integration/RpcErrors.test.ts +25 -10
  205. package/test/integration/ScaleDownDht.test.ts +8 -8
  206. package/test/integration/SimultaneousConnections.test.ts +35 -36
  207. package/test/integration/Store.test.ts +8 -9
  208. package/test/integration/StoreAndDelete.test.ts +11 -11
  209. package/test/integration/StoreOnDhtWithTwoNodes.test.ts +7 -7
  210. package/test/integration/{RemoteStore.test.ts → StoreRpcRemote.test.ts} +17 -18
  211. package/test/integration/WebRtcConnectionManagement.test.ts +26 -19
  212. package/test/integration/WebRtcConnectorRpc.test.ts +17 -32
  213. package/test/integration/WebSocket.test.ts +4 -2
  214. package/test/integration/WebSocketConnectionManagement.test.ts +30 -17
  215. package/test/integration/WebSocketConnectorRpc.test.ts +10 -15
  216. package/test/unit/DuplicateDetector.test.ts +3 -4
  217. package/test/unit/LocalDataStore.test.ts +6 -8
  218. package/test/unit/RandomContactList.test.ts +1 -1
  219. package/test/unit/RecursiveFinder.test.ts +13 -18
  220. package/test/unit/Router.test.ts +18 -21
  221. package/test/unit/WebSocketConnectorRpcLocal.test.ts +64 -0
  222. package/test/unit/WebSocketServer.test.ts +24 -12
  223. package/test/unit/{webrtcReplaceInternalIpWithExternalIp.ts → webrtcReplaceInternalIpWithExternalIp.test.ts} +1 -1
  224. package/test/utils/mock/RecursiveFinder.ts +2 -2
  225. package/test/utils/mock/Router.ts +9 -11
  226. package/test/utils/mock/Transport.ts +2 -2
  227. package/test/utils/utils.ts +55 -74
  228. package/dist/src/connection/RemoteConnectionLocker.d.ts +0 -13
  229. package/dist/src/connection/RemoteConnectionLocker.js.map +0 -1
  230. package/dist/src/connection/WebRTC/RemoteWebrtcConnector.d.ts +0 -12
  231. package/dist/src/connection/WebRTC/RemoteWebrtcConnector.js +0 -74
  232. package/dist/src/connection/WebRTC/RemoteWebrtcConnector.js.map +0 -1
  233. package/dist/src/connection/WebRTC/WebRtcConnector.js.map +0 -1
  234. package/dist/src/connection/WebSocket/RemoteWebSocketConnector.d.ts +0 -9
  235. package/dist/src/connection/WebSocket/RemoteWebSocketConnector.js.map +0 -1
  236. package/dist/src/connection/WebSocket/WebSocketConnector.js.map +0 -1
  237. package/dist/src/dht/DhtPeer.js.map +0 -1
  238. package/dist/src/dht/RemoteExternalApi.js.map +0 -1
  239. package/dist/src/dht/routing/RemoteRouter.js.map +0 -1
  240. package/dist/src/dht/store/DataStore.js.map +0 -1
  241. package/dist/src/dht/store/RemoteStore.js.map +0 -1
  242. package/dist/src/helpers/browser/isBrowser.d.ts +0 -1
  243. package/dist/src/helpers/browser/isBrowser.js +0 -6
  244. package/dist/src/helpers/browser/isBrowser.js.map +0 -1
  245. package/dist/src/helpers/browser/isNodeJS.d.ts +0 -1
  246. package/dist/src/helpers/browser/isNodeJS.js +0 -6
  247. package/dist/src/helpers/browser/isNodeJS.js.map +0 -1
  248. package/src/connection/RemoteConnectionLocker.ts +0 -84
  249. package/src/connection/WebRTC/RemoteWebrtcConnector.ts +0 -93
  250. package/src/connection/WebSocket/RemoteWebSocketConnector.ts +0 -49
  251. package/src/helpers/browser/isBrowser.ts +0 -1
  252. package/src/helpers/browser/isNodeJS.ts +0 -1
  253. package/test/integration/DhtWithMockConnectionLatencies.test.ts +0 -46
  254. package/test/integration/DhtWithMockConnections.test.ts +0 -46
  255. package/test/integration/DhtWithRealConnectionLatencies.test.ts +0 -47
@@ -1,93 +0,0 @@
1
- import {
2
- IceCandidate,
3
- PeerDescriptor,
4
- RtcAnswer,
5
- RtcOffer,
6
- WebRtcConnectionRequest
7
- } from '../../proto/packages/dht/protos/DhtRpc'
8
- import { IWebRtcConnectorServiceClient } from '../../proto/packages/dht/protos/DhtRpc.client'
9
- import { DhtRpcOptions } from '../../rpc-protocol/DhtRpcOptions'
10
- import { ProtoRpcClient } from '@streamr/proto-rpc'
11
- import { Logger } from '@streamr/utils'
12
-
13
- const logger = new Logger(module)
14
-
15
- export class RemoteWebrtcConnector {
16
-
17
- private peerDescriptor: PeerDescriptor
18
- private client: ProtoRpcClient<IWebRtcConnectorServiceClient>
19
-
20
- constructor(peerDescriptor: PeerDescriptor, client: ProtoRpcClient<IWebRtcConnectorServiceClient>) {
21
- this.peerDescriptor = peerDescriptor
22
- this.client = client
23
- }
24
-
25
- requestConnection(sourceDescriptor: PeerDescriptor, connectionId: string): void {
26
- const request: WebRtcConnectionRequest = {
27
- target: this.peerDescriptor,
28
- requester: sourceDescriptor,
29
- connectionId
30
- }
31
- const options: DhtRpcOptions = {
32
- sourceDescriptor: sourceDescriptor,
33
- targetDescriptor: this.peerDescriptor,
34
- notification: true
35
- }
36
-
37
- this.client.requestConnection(request, options).catch((_e) => {
38
- logger.trace('Failed to send requestConnection')
39
- })
40
- }
41
-
42
- sendRtcOffer(sourceDescriptor: PeerDescriptor, description: string, connectionId: string): void {
43
- const request: RtcOffer = {
44
- target: this.peerDescriptor,
45
- requester: sourceDescriptor,
46
- connectionId,
47
- description
48
- }
49
- const options: DhtRpcOptions = {
50
- sourceDescriptor: sourceDescriptor,
51
- targetDescriptor: this.peerDescriptor,
52
- }
53
-
54
- this.client.rtcOffer(request, options).catch((_e) => {
55
- logger.trace('Failed to send rtcOffer')
56
- })
57
- }
58
-
59
- sendRtcAnswer(sourceDescriptor: PeerDescriptor, description: string, connectionId: string): void {
60
- const request: RtcAnswer = {
61
- target: this.peerDescriptor,
62
- requester: sourceDescriptor,
63
- connectionId,
64
- description
65
- }
66
- const options: DhtRpcOptions = {
67
- sourceDescriptor: sourceDescriptor,
68
- targetDescriptor: this.peerDescriptor,
69
- }
70
-
71
- this.client.rtcAnswer(request, options).catch((_e) => {
72
- logger.trace('Failed to send rtcAnswer')
73
- })
74
- }
75
-
76
- sendIceCandidate(sourceDescriptor: PeerDescriptor, candidate: string, mid: string, connectionId: string): void {
77
- const request: IceCandidate = {
78
- target: this.peerDescriptor,
79
- requester: sourceDescriptor,
80
- connectionId,
81
- mid,
82
- candidate
83
- }
84
- const options: DhtRpcOptions = {
85
- sourceDescriptor: sourceDescriptor,
86
- targetDescriptor: this.peerDescriptor,
87
- }
88
- this.client.iceCandidate(request, options).catch((_e) => {
89
- logger.trace('Failed to send iceCandidate')
90
- })
91
- }
92
- }
93
-
@@ -1,49 +0,0 @@
1
- import {
2
- PeerDescriptor,
3
- WebSocketConnectionRequest
4
- } from '../../proto/packages/dht/protos/DhtRpc'
5
- import { IWebSocketConnectorServiceClient } from '../../proto/packages/dht/protos/DhtRpc.client'
6
- import { DhtRpcOptions } from '../../rpc-protocol/DhtRpcOptions'
7
- import { Logger } from '@streamr/utils'
8
- import * as Err from '../../helpers/errors'
9
- import { ProtoRpcClient } from '@streamr/proto-rpc'
10
-
11
- const logger = new Logger(module)
12
-
13
- export class RemoteWebSocketConnector {
14
-
15
- private peerDescriptor: PeerDescriptor
16
- private client: ProtoRpcClient<IWebSocketConnectorServiceClient>
17
-
18
- constructor(peerDescriptor: PeerDescriptor, client: ProtoRpcClient<IWebSocketConnectorServiceClient>) {
19
- this.peerDescriptor = peerDescriptor
20
- this.client = client
21
- }
22
-
23
- async requestConnection(sourceDescriptor: PeerDescriptor, ip: string, port: number): Promise<boolean> {
24
- logger.trace(`Requesting WebSocket connection from ${this.peerDescriptor.kademliaId.toString()}`)
25
- const request: WebSocketConnectionRequest = {
26
- target: this.peerDescriptor,
27
- requester: sourceDescriptor,
28
- ip,
29
- port
30
- }
31
- const options: DhtRpcOptions = {
32
- sourceDescriptor: sourceDescriptor,
33
- targetDescriptor: this.peerDescriptor
34
- }
35
- try {
36
- const res = await this.client.requestConnection(request, options)
37
-
38
- if (res.reason) {
39
- logger.debug('WebSocketConnectionRequest Rejected', {
40
- stack: new Err.WebSocketConnectionRequestRejected(res.reason).stack
41
- })
42
- }
43
- return res.accepted
44
- } catch (err) {
45
- logger.debug(new Err.WebSocketConnectionRequestRejected('WebSocketConnectionRequest rejected', err).stack!)
46
- return false
47
- }
48
- }
49
- }
@@ -1 +0,0 @@
1
- export const isNodeJS = (): boolean => false
@@ -1 +0,0 @@
1
- export const isNodeJS = (): boolean => true
@@ -1,46 +0,0 @@
1
- import { DhtNode } from '../../src/dht/DhtNode'
2
- import { NodeType, PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
3
- import { createMockConnectionDhtNode } from '../utils/utils'
4
- import { LatencyType, Simulator } from '../../src/connection/Simulator/Simulator'
5
-
6
- describe('Mock connection Dht joining with latencies', () => {
7
- let entryPoint: DhtNode
8
- let nodes: DhtNode[]
9
- let simulator: Simulator
10
- let entrypointDescriptor: PeerDescriptor
11
-
12
- beforeEach(async () => {
13
- nodes = []
14
- simulator = new Simulator(LatencyType.RANDOM)
15
- const entryPointId = '0'
16
- entryPoint = await createMockConnectionDhtNode(entryPointId, simulator)
17
- entrypointDescriptor = {
18
- kademliaId: entryPoint.getNodeId().value,
19
- type: NodeType.NODEJS,
20
- nodeName: '0'
21
- }
22
- for (let i = 1; i < 100; i++) {
23
- const nodeId = `${i}`
24
- const node = await createMockConnectionDhtNode(nodeId, simulator)
25
- nodes.push(node)
26
- }
27
- })
28
-
29
- afterEach(async () => {
30
- await Promise.all([
31
- entryPoint.stop(),
32
- ...nodes.map((node) => node.stop())
33
- ])
34
- simulator.stop()
35
- })
36
-
37
- it('Happy path', async () => {
38
- await entryPoint.joinDht([entrypointDescriptor])
39
- await Promise.all(nodes.map((node) => node.joinDht([entrypointDescriptor])))
40
- nodes.forEach((node) => {
41
- expect(node.getBucketSize()).toBeGreaterThanOrEqual(node.getK() - 2)
42
- expect(node.getClosestContacts().length).toBeGreaterThanOrEqual(node.getK() - 2)
43
- })
44
- expect(entryPoint.getBucketSize()).toBeGreaterThanOrEqual(entryPoint.getK() - 2)
45
- }, 60 * 1000)
46
- })
@@ -1,46 +0,0 @@
1
- import { Simulator } from '../../src/connection/Simulator/Simulator'
2
- import { DhtNode } from '../../src/dht/DhtNode'
3
- import { NodeType, PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
4
- import { createMockConnectionDhtNode } from '../utils/utils'
5
-
6
- describe('Mock IConnection DHT Joining', () => {
7
- let entryPoint: DhtNode
8
- let nodes: DhtNode[]
9
- let entrypointDescriptor: PeerDescriptor
10
- let simulator: Simulator
11
-
12
- beforeEach(async () => {
13
- nodes = []
14
- simulator = new Simulator()
15
- const entryPointId = '0'
16
- entryPoint = await createMockConnectionDhtNode(entryPointId, simulator)
17
- entrypointDescriptor = {
18
- kademliaId: entryPoint.getNodeId().value,
19
- type: NodeType.NODEJS,
20
- nodeName: '0'
21
- }
22
- for (let i = 1; i < 100; i++) {
23
- const nodeId = `${i}`
24
- const node = await createMockConnectionDhtNode(nodeId, simulator)
25
- nodes.push(node)
26
- }
27
- })
28
-
29
- afterEach(async () => {
30
- await Promise.all([
31
- entryPoint.stop(),
32
- ...nodes.map(async (node) => node.stop())
33
- ])
34
- simulator.stop()
35
- })
36
-
37
- it('Happy path', async () => {
38
- await entryPoint.joinDht([entrypointDescriptor])
39
- await Promise.all(nodes.map((node) => node.joinDht([entrypointDescriptor])))
40
- nodes.forEach((node) => {
41
- expect(node.getBucketSize()).toBeGreaterThanOrEqual(node.getK() - 2)
42
- expect(node.getClosestContacts().length).toBeGreaterThanOrEqual(node.getK() - 2)
43
- })
44
- expect(entryPoint.getBucketSize()).toBeGreaterThanOrEqual(entryPoint.getK() - 2)
45
- }, 60000)
46
- })
@@ -1,47 +0,0 @@
1
- import { DhtNode } from '../../src/dht/DhtNode'
2
- import { createMockConnectionDhtNode } from '../utils/utils'
3
- import { LatencyType, Simulator } from '../../src/connection/Simulator/Simulator'
4
- import { NodeType, PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
5
- import { getRandomRegion } from '../../src/connection/Simulator/pings'
6
-
7
- describe('Mock connection Dht joining with real latencies', () => {
8
- let entryPoint: DhtNode
9
- let nodes: DhtNode[]
10
- let simulator: Simulator
11
- let entrypointDescriptor: PeerDescriptor
12
-
13
- beforeEach(async () => {
14
- nodes = []
15
- simulator = new Simulator(LatencyType.REAL)
16
- const entryPointId = '0'
17
- entryPoint = await createMockConnectionDhtNode(entryPointId, simulator)
18
- entrypointDescriptor = {
19
- kademliaId: entryPoint.getNodeId().value,
20
- type: NodeType.NODEJS,
21
- region: getRandomRegion()
22
- }
23
- for (let i = 1; i < 100; i++) {
24
- const nodeId = `${i}`
25
- const node = await createMockConnectionDhtNode(nodeId, simulator)
26
- nodes.push(node)
27
- }
28
- })
29
-
30
- afterEach(async () => {
31
- await Promise.all([
32
- entryPoint.stop(),
33
- ...nodes.map((node) => node.stop())
34
- ])
35
- simulator.stop()
36
- })
37
-
38
- it('Happy path', async () => {
39
- await entryPoint.joinDht([entrypointDescriptor])
40
- await Promise.all(nodes.map((node) => node.joinDht([entrypointDescriptor])))
41
- nodes.forEach((node) => {
42
- expect(node.getBucketSize()).toBeGreaterThanOrEqual(node.getK() - 3)
43
- expect(node.getClosestContacts().length).toBeGreaterThanOrEqual(node.getK() - 3)
44
- })
45
- expect(entryPoint.getBucketSize()).toBeGreaterThanOrEqual(entryPoint.getK())
46
- }, 60 * 1000)
47
- })