@streamr/dht 102.0.0-beta.0 → 102.0.0-beta.2

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 (264) hide show
  1. package/dist/generated/packages/dht/protos/DhtRpc.d.ts +16 -8
  2. package/dist/generated/packages/dht/protos/DhtRpc.js +7 -5
  3. package/dist/generated/packages/dht/protos/DhtRpc.js.map +1 -1
  4. package/dist/package.json +15 -16
  5. package/dist/src/connection/ConnectionManager.js +18 -8
  6. package/dist/src/connection/ConnectionManager.js.map +1 -1
  7. package/dist/src/connection/Handshaker.d.ts +1 -1
  8. package/dist/src/connection/Handshaker.js +9 -5
  9. package/dist/src/connection/Handshaker.js.map +1 -1
  10. package/dist/src/connection/ManagedConnection.js +17 -7
  11. package/dist/src/connection/ManagedConnection.js.map +1 -1
  12. package/dist/src/connection/connectivityChecker.js +20 -10
  13. package/dist/src/connection/connectivityChecker.js.map +1 -1
  14. package/dist/src/connection/connectivityRequestHandler.js +3 -3
  15. package/dist/src/connection/connectivityRequestHandler.js.map +1 -1
  16. package/dist/src/connection/simulator/Simulator.js +3 -2
  17. package/dist/src/connection/simulator/Simulator.js.map +1 -1
  18. package/dist/src/connection/simulator/pings.d.ts +1 -1
  19. package/dist/src/connection/simulator/pings.js +3 -3
  20. package/dist/src/connection/simulator/pings.js.map +1 -1
  21. package/dist/src/connection/webrtc/NodeWebrtcConnection.js +0 -2
  22. package/dist/src/connection/webrtc/NodeWebrtcConnection.js.map +1 -1
  23. package/dist/src/connection/webrtc/WebrtcConnector.js +19 -9
  24. package/dist/src/connection/webrtc/WebrtcConnector.js.map +1 -1
  25. package/dist/src/connection/webrtc/iceServerAsString.js +1 -2
  26. package/dist/src/connection/webrtc/iceServerAsString.js.map +1 -1
  27. package/dist/src/connection/websocket/AbstractWebsocketClientConnection.d.ts +0 -2
  28. package/dist/src/connection/websocket/WebsocketClientConnectorRpcLocal.d.ts +0 -1
  29. package/dist/src/connection/websocket/WebsocketServerConnection.d.ts +0 -1
  30. package/dist/src/connection/websocket/WebsocketServerConnector.js +28 -18
  31. package/dist/src/connection/websocket/WebsocketServerConnector.js.map +1 -1
  32. package/dist/src/dht/DhtNode.d.ts +1 -0
  33. package/dist/src/dht/DhtNode.js +3 -2
  34. package/dist/src/dht/DhtNode.js.map +1 -1
  35. package/dist/src/dht/DhtNodeRpcLocal.d.ts +1 -1
  36. package/dist/src/dht/PeerManager.d.ts +2 -1
  37. package/dist/src/dht/PeerManager.js +2 -1
  38. package/dist/src/dht/PeerManager.js.map +1 -1
  39. package/dist/src/dht/contact/SortedContactList.js +1 -1
  40. package/dist/src/dht/contact/SortedContactList.js.map +1 -1
  41. package/dist/src/dht/discovery/DiscoverySession.d.ts +0 -1
  42. package/dist/src/dht/discovery/PeerDiscovery.d.ts +0 -1
  43. package/dist/src/dht/discovery/RingDiscoverySession.d.ts +0 -1
  44. package/dist/src/dht/recursive-operation/RecursiveOperationManager.d.ts +2 -2
  45. package/dist/src/dht/routing/DuplicateDetector.js.map +1 -1
  46. package/dist/src/dht/routing/RoutingSession.js +2 -2
  47. package/dist/src/dht/routing/RoutingSession.js.map +1 -1
  48. package/dist/src/dht/routing/RoutingTablesCache.d.ts +1 -1
  49. package/dist/src/dht/store/LocalDataStore.js +1 -1
  50. package/dist/src/dht/store/LocalDataStore.js.map +1 -1
  51. package/dist/src/dht/store/StoreManager.d.ts +1 -1
  52. package/dist/src/dht/store/StoreRpcLocal.d.ts +1 -1
  53. package/dist/src/helpers/AddressTools.js +2 -3
  54. package/dist/src/helpers/AddressTools.js.map +1 -1
  55. package/dist/src/helpers/debugHelpers.js +2 -2
  56. package/dist/src/helpers/debugHelpers.js.map +1 -1
  57. package/dist/src/helpers/protoClasses.d.ts +1 -1
  58. package/dist/src/helpers/protoClasses.js.map +1 -1
  59. package/dist/src/helpers/protoToString.js +1 -2
  60. package/dist/src/helpers/protoToString.js.map +1 -1
  61. package/dist/src/helpers/version.d.ts +1 -1
  62. package/dist/src/helpers/version.js +4 -4
  63. package/dist/src/helpers/version.js.map +1 -1
  64. package/eslint.config.mjs +12 -0
  65. package/jest.config.ts +12 -0
  66. package/package.json +15 -16
  67. package/protos/DhtRpc.proto +6 -4
  68. package/.eslintignore +0 -5
  69. package/.eslintrc +0 -3
  70. package/generated/google/protobuf/any.ts +0 -326
  71. package/generated/google/protobuf/empty.ts +0 -81
  72. package/generated/google/protobuf/timestamp.ts +0 -287
  73. package/generated/packages/dht/protos/DhtRpc.client.ts +0 -419
  74. package/generated/packages/dht/protos/DhtRpc.server.ts +0 -165
  75. package/generated/packages/dht/protos/DhtRpc.ts +0 -1266
  76. package/generated/packages/proto-rpc/protos/ProtoRpc.ts +0 -108
  77. package/jest.config.js +0 -5
  78. package/src/connection/Connection.ts +0 -28
  79. package/src/connection/ConnectionLockRpcLocal.ts +0 -78
  80. package/src/connection/ConnectionLockRpcRemote.ts +0 -64
  81. package/src/connection/ConnectionLockStates.ts +0 -131
  82. package/src/connection/ConnectionManager.ts +0 -661
  83. package/src/connection/ConnectionsView.ts +0 -8
  84. package/src/connection/ConnectorFacade.ts +0 -217
  85. package/src/connection/Handshaker.ts +0 -205
  86. package/src/connection/IConnection.ts +0 -40
  87. package/src/connection/ManagedConnection.ts +0 -113
  88. package/src/connection/OutputBuffer.ts +0 -28
  89. package/src/connection/PendingConnection.ts +0 -68
  90. package/src/connection/connectivityChecker.ts +0 -108
  91. package/src/connection/connectivityRequestHandler.ts +0 -116
  92. package/src/connection/simulator/Simulator.ts +0 -368
  93. package/src/connection/simulator/SimulatorConnection.ts +0 -137
  94. package/src/connection/simulator/SimulatorConnector.ts +0 -98
  95. package/src/connection/simulator/SimulatorTransport.ts +0 -15
  96. package/src/connection/simulator/pings.ts +0 -42
  97. package/src/connection/webrtc/BrowserWebrtcConnection.ts +0 -242
  98. package/src/connection/webrtc/IWebrtcConnection.ts +0 -24
  99. package/src/connection/webrtc/NodeWebrtcConnection.ts +0 -247
  100. package/src/connection/webrtc/WebrtcConnector.ts +0 -234
  101. package/src/connection/webrtc/WebrtcConnectorRpcLocal.ts +0 -108
  102. package/src/connection/webrtc/WebrtcConnectorRpcRemote.ts +0 -60
  103. package/src/connection/webrtc/iceServerAsString.ts +0 -15
  104. package/src/connection/websocket/AbstractWebsocketClientConnection.ts +0 -122
  105. package/src/connection/websocket/AutoCertifierClientFacade.ts +0 -89
  106. package/src/connection/websocket/BrowserWebsocketClientConnection.ts +0 -44
  107. package/src/connection/websocket/NodeWebsocketClientConnection.ts +0 -39
  108. package/src/connection/websocket/WebsocketClientConnector.ts +0 -119
  109. package/src/connection/websocket/WebsocketClientConnectorRpcLocal.ts +0 -38
  110. package/src/connection/websocket/WebsocketClientConnectorRpcRemote.ts +0 -19
  111. package/src/connection/websocket/WebsocketServer.ts +0 -164
  112. package/src/connection/websocket/WebsocketServerConnection.ts +0 -109
  113. package/src/connection/websocket/WebsocketServerConnector.ts +0 -286
  114. package/src/dht/DhtNode.ts +0 -678
  115. package/src/dht/DhtNodeRpcLocal.ts +0 -84
  116. package/src/dht/DhtNodeRpcRemote.ts +0 -107
  117. package/src/dht/ExternalApiRpcLocal.ts +0 -58
  118. package/src/dht/ExternalApiRpcRemote.ts +0 -41
  119. package/src/dht/PeerManager.ts +0 -303
  120. package/src/dht/contact/Contact.ts +0 -19
  121. package/src/dht/contact/ContactList.ts +0 -43
  122. package/src/dht/contact/RandomContactList.ts +0 -56
  123. package/src/dht/contact/RingContactList.ts +0 -143
  124. package/src/dht/contact/RpcRemote.ts +0 -72
  125. package/src/dht/contact/SortedContactList.ts +0 -173
  126. package/src/dht/contact/getClosestNodes.ts +0 -24
  127. package/src/dht/contact/ringIdentifiers.ts +0 -62
  128. package/src/dht/discovery/DiscoverySession.ts +0 -129
  129. package/src/dht/discovery/PeerDiscovery.ts +0 -244
  130. package/src/dht/discovery/RingDiscoverySession.ts +0 -148
  131. package/src/dht/recursive-operation/RecursiveOperationManager.ts +0 -251
  132. package/src/dht/recursive-operation/RecursiveOperationRpcLocal.ts +0 -34
  133. package/src/dht/recursive-operation/RecursiveOperationRpcRemote.ts +0 -43
  134. package/src/dht/recursive-operation/RecursiveOperationSession.ts +0 -231
  135. package/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.ts +0 -35
  136. package/src/dht/recursive-operation/RecursiveOperationSessionRpcRemote.ts +0 -30
  137. package/src/dht/routing/DuplicateDetector.ts +0 -34
  138. package/src/dht/routing/Router.ts +0 -246
  139. package/src/dht/routing/RouterRpcLocal.ts +0 -78
  140. package/src/dht/routing/RouterRpcRemote.ts +0 -80
  141. package/src/dht/routing/RoutingSession.ts +0 -243
  142. package/src/dht/routing/RoutingTablesCache.ts +0 -60
  143. package/src/dht/routing/getPreviousPeer.ts +0 -6
  144. package/src/dht/store/LocalDataStore.ts +0 -84
  145. package/src/dht/store/StoreManager.ts +0 -170
  146. package/src/dht/store/StoreRpcLocal.ts +0 -89
  147. package/src/dht/store/StoreRpcRemote.ts +0 -32
  148. package/src/exports.ts +0 -33
  149. package/src/helpers/AddressTools.ts +0 -28
  150. package/src/helpers/Connectivity.ts +0 -19
  151. package/src/helpers/browser/isBrowserEnvironment.ts +0 -1
  152. package/src/helpers/browser/isBrowserEnvironment_override.ts +0 -3
  153. package/src/helpers/createPeerDescriptor.ts +0 -57
  154. package/src/helpers/createPeerDescriptorSignaturePayload.ts +0 -28
  155. package/src/helpers/debugHelpers.ts +0 -9
  156. package/src/helpers/errors.ts +0 -49
  157. package/src/helpers/offering.ts +0 -15
  158. package/src/helpers/protoClasses.ts +0 -57
  159. package/src/helpers/protoToString.ts +0 -21
  160. package/src/helpers/version.ts +0 -32
  161. package/src/identifiers.ts +0 -29
  162. package/src/rpc-protocol/DhtCallContext.ts +0 -14
  163. package/src/rpc-protocol/DhtRpcOptions.ts +0 -10
  164. package/src/transport/ITransport.ts +0 -37
  165. package/src/transport/ListeningRpcCommunicator.ts +0 -32
  166. package/src/transport/RoutingRpcCommunicator.ts +0 -66
  167. package/src/types/ServiceID.ts +0 -1
  168. package/src/types/textencoding.d.ts +0 -6
  169. package/test/benchmark/Find.test.ts +0 -72
  170. package/test/benchmark/KademliaCorrectness.test.ts +0 -114
  171. package/test/benchmark/RingCorrectness.test.ts +0 -157
  172. package/test/benchmark/SortedContactListBenchmark.test.ts +0 -108
  173. package/test/benchmark/WebsocketServerMemoryLeak.test.ts +0 -41
  174. package/test/benchmark/hybrid-network-simulation/RingContactList.test.ts +0 -71
  175. package/test/end-to-end/GeoIpLayer0.test.ts +0 -55
  176. package/test/end-to-end/Layer0-Layer1.test.ts +0 -93
  177. package/test/end-to-end/Layer0.test.ts +0 -76
  178. package/test/end-to-end/Layer0MixedConnectionTypes.test.ts +0 -110
  179. package/test/end-to-end/Layer0Webrtc-Layer1.test.ts +0 -137
  180. package/test/end-to-end/Layer0Webrtc.test.ts +0 -85
  181. package/test/end-to-end/Layer1-Scale-WebSocket.test.ts +0 -82
  182. package/test/end-to-end/Layer1-Scale-Webrtc.test.ts +0 -76
  183. package/test/end-to-end/RecoveryFromFailedAutoCertification.test.ts +0 -52
  184. package/test/end-to-end/WebsocketConnectionRequest.test.ts +0 -69
  185. package/test/end-to-end/memory-leak.test.ts +0 -80
  186. package/test/integration/ConnectionLocking.test.ts +0 -182
  187. package/test/integration/ConnectionManager.test.ts +0 -528
  188. package/test/integration/ConnectivityChecking.test.ts +0 -53
  189. package/test/integration/DhtJoinPeerDiscovery.test.ts +0 -49
  190. package/test/integration/DhtNode.test.ts +0 -66
  191. package/test/integration/DhtNodeExternalAPI.test.ts +0 -48
  192. package/test/integration/DhtNodeRpcRemote.test.ts +0 -66
  193. package/test/integration/DhtRpc.test.ts +0 -121
  194. package/test/integration/Find.test.ts +0 -45
  195. package/test/integration/GeoIpConnectivityChecking.test.ts +0 -72
  196. package/test/integration/Layer1-scale.test.ts +0 -189
  197. package/test/integration/Mock-Layer1-Layer0.test.ts +0 -85
  198. package/test/integration/MultipleEntryPointJoining.test.ts +0 -105
  199. package/test/integration/ReplicateData.test.ts +0 -104
  200. package/test/integration/RouteMessage.test.ts +0 -230
  201. package/test/integration/RouterRpcRemote.test.ts +0 -77
  202. package/test/integration/SimultaneousConnections.test.ts +0 -316
  203. package/test/integration/Store.test.ts +0 -85
  204. package/test/integration/StoreAndDelete.test.ts +0 -77
  205. package/test/integration/StoreOnDhtWithThreeNodes.test.ts +0 -59
  206. package/test/integration/StoreOnDhtWithTwoNodes.test.ts +0 -51
  207. package/test/integration/StoreRpcRemote.test.ts +0 -54
  208. package/test/integration/WebrtcConnectionManagement.test.ts +0 -219
  209. package/test/integration/WebrtcConnectorRpc.test.ts +0 -125
  210. package/test/integration/Websocket.test.ts +0 -65
  211. package/test/integration/WebsocketClientConnectorRpc.test.ts +0 -69
  212. package/test/integration/WebsocketConnectionManagement.test.ts +0 -191
  213. package/test/integration/rpc-connections-over-webrtc.test.ts +0 -158
  214. package/test/kademlia-simulation/data/nodeids.json +0 -13002
  215. package/test/kademlia-simulation/data/orderedneighbors.json +0 -1001
  216. package/test/types/global.d.ts +0 -1
  217. package/test/unit/AddressTools.test.ts +0 -44
  218. package/test/unit/AutoCertifierClientFacade.test.ts +0 -58
  219. package/test/unit/ConnectionManager.test.ts +0 -65
  220. package/test/unit/ConnectivityHelpers.test.ts +0 -61
  221. package/test/unit/DiscoverySession.test.ts +0 -87
  222. package/test/unit/DuplicateDetector.test.ts +0 -31
  223. package/test/unit/Handshaker.test.ts +0 -169
  224. package/test/unit/ListeningRpcCommunicator.test.ts +0 -52
  225. package/test/unit/LocalDataStore.test.ts +0 -108
  226. package/test/unit/ManagedConnection.test.ts +0 -58
  227. package/test/unit/PeerManager.test.ts +0 -93
  228. package/test/unit/PendingConnection.test.ts +0 -57
  229. package/test/unit/ProtobufMessage.test.ts +0 -21
  230. package/test/unit/RandomContactList.test.ts +0 -58
  231. package/test/unit/RecursiveOperationManager.test.ts +0 -161
  232. package/test/unit/RecursiveOperationSession.test.ts +0 -68
  233. package/test/unit/Router.test.ts +0 -137
  234. package/test/unit/RoutingSession.test.ts +0 -79
  235. package/test/unit/SortedContactList.test.ts +0 -115
  236. package/test/unit/StoreManager.test.ts +0 -146
  237. package/test/unit/StoreRpcLocal.test.ts +0 -167
  238. package/test/unit/WebrtcConnection.test.ts +0 -29
  239. package/test/unit/WebrtcConnector.test.ts +0 -56
  240. package/test/unit/WebsocketClientConnector.test.ts +0 -101
  241. package/test/unit/WebsocketServer.test.ts +0 -66
  242. package/test/unit/WebsocketServerConnector.test.ts +0 -102
  243. package/test/unit/connectivityRequestHandler.test.ts +0 -104
  244. package/test/unit/createPeerDescriptor.test.ts +0 -69
  245. package/test/unit/customMatchers.test.ts +0 -16
  246. package/test/unit/getClosestNodes.test.ts +0 -30
  247. package/test/unit/version.test.ts +0 -18
  248. package/test/unit/webrtcReplaceInternalIpWithExternalIp.test.ts +0 -18
  249. package/test/utils/FakeConnectorFacade.ts +0 -41
  250. package/test/utils/FakeRpcCommunicator.ts +0 -23
  251. package/test/utils/FakeTransport.ts +0 -79
  252. package/test/utils/customMatchers.ts +0 -71
  253. package/test/utils/mock/MockConnection.ts +0 -26
  254. package/test/utils/mock/MockConnectionsView.ts +0 -18
  255. package/test/utils/mock/MockRouter.ts +0 -62
  256. package/test/utils/mock/MockRpcCommunicator.ts +0 -7
  257. package/test/utils/mock/MockTransport.ts +0 -26
  258. package/test/utils/mock/mockDataEntry.ts +0 -38
  259. package/test/utils/topology.ts +0 -80
  260. package/test/utils/utils.ts +0 -268
  261. package/tsconfig.browser.json +0 -17
  262. package/tsconfig.jest.json +0 -25
  263. package/tsconfig.json +0 -3
  264. package/tsconfig.node.json +0 -24
@@ -1,108 +0,0 @@
1
- // @generated by protobuf-ts 2.9.4 with parameter server_generic,generate_dependencies,long_type_number
2
- // @generated from protobuf file "packages/proto-rpc/protos/ProtoRpc.proto" (package "protorpc", syntax proto3)
3
- // tslint:disable
4
- import { MessageType } from "@protobuf-ts/runtime";
5
- import { Empty } from "../../../google/protobuf/empty";
6
- import { Any } from "../../../google/protobuf/any";
7
- /**
8
- * @generated from protobuf message protorpc.RpcMessage
9
- */
10
- export interface RpcMessage {
11
- /**
12
- * @generated from protobuf field: map<string, string> header = 1;
13
- */
14
- header: {
15
- [key: string]: string;
16
- };
17
- /**
18
- * @generated from protobuf field: google.protobuf.Any body = 2;
19
- */
20
- body?: Any;
21
- /**
22
- * @generated from protobuf field: string requestId = 3;
23
- */
24
- requestId: string;
25
- /**
26
- * @generated from protobuf field: optional protorpc.RpcErrorType errorType = 4;
27
- */
28
- errorType?: RpcErrorType;
29
- /**
30
- * @generated from protobuf field: optional string errorClassName = 5;
31
- */
32
- errorClassName?: string;
33
- /**
34
- * @generated from protobuf field: optional string errorCode = 6;
35
- */
36
- errorCode?: string;
37
- /**
38
- * @generated from protobuf field: optional string errorMessage = 7;
39
- */
40
- errorMessage?: string;
41
- }
42
- // Dummy message to force the generation of the typescript class "google.prototype.Empty"
43
- // We need this generated class in RpcCommunicator
44
-
45
- /**
46
- * @generated from protobuf message protorpc.Mnfo2uhnf92hvqi2nviouq2hv9puhq
47
- */
48
- export interface Mnfo2uhnf92hvqi2nviouq2hv9puhq {
49
- /**
50
- * @generated from protobuf field: google.protobuf.Empty empty = 1;
51
- */
52
- empty?: Empty;
53
- }
54
- /**
55
- * @generated from protobuf enum protorpc.RpcErrorType
56
- */
57
- export enum RpcErrorType {
58
- /**
59
- * @generated from protobuf enum value: SERVER_TIMEOUT = 0;
60
- */
61
- SERVER_TIMEOUT = 0,
62
- /**
63
- * @generated from protobuf enum value: CLIENT_TIMEOUT = 1;
64
- */
65
- CLIENT_TIMEOUT = 1,
66
- /**
67
- * @generated from protobuf enum value: UNKNOWN_RPC_METHOD = 2;
68
- */
69
- UNKNOWN_RPC_METHOD = 2,
70
- /**
71
- * @generated from protobuf enum value: CLIENT_ERROR = 3;
72
- */
73
- CLIENT_ERROR = 3,
74
- /**
75
- * @generated from protobuf enum value: SERVER_ERROR = 4;
76
- */
77
- SERVER_ERROR = 4
78
- }
79
- // @generated message type with reflection information, may provide speed optimized methods
80
- class RpcMessage$Type extends MessageType<RpcMessage> {
81
- constructor() {
82
- super("protorpc.RpcMessage", [
83
- { no: 1, name: "header", kind: "map", K: 9 /*ScalarType.STRING*/, V: { kind: "scalar", T: 9 /*ScalarType.STRING*/ } },
84
- { no: 2, name: "body", kind: "message", T: () => Any },
85
- { no: 3, name: "requestId", kind: "scalar", T: 9 /*ScalarType.STRING*/ },
86
- { no: 4, name: "errorType", kind: "enum", opt: true, T: () => ["protorpc.RpcErrorType", RpcErrorType] },
87
- { no: 5, name: "errorClassName", kind: "scalar", opt: true, T: 9 /*ScalarType.STRING*/ },
88
- { no: 6, name: "errorCode", kind: "scalar", opt: true, T: 9 /*ScalarType.STRING*/ },
89
- { no: 7, name: "errorMessage", kind: "scalar", opt: true, T: 9 /*ScalarType.STRING*/ }
90
- ]);
91
- }
92
- }
93
- /**
94
- * @generated MessageType for protobuf message protorpc.RpcMessage
95
- */
96
- export const RpcMessage = new RpcMessage$Type();
97
- // @generated message type with reflection information, may provide speed optimized methods
98
- class Mnfo2uhnf92hvqi2nviouq2hv9puhq$Type extends MessageType<Mnfo2uhnf92hvqi2nviouq2hv9puhq> {
99
- constructor() {
100
- super("protorpc.Mnfo2uhnf92hvqi2nviouq2hv9puhq", [
101
- { no: 1, name: "empty", kind: "message", T: () => Empty }
102
- ]);
103
- }
104
- }
105
- /**
106
- * @generated MessageType for protobuf message protorpc.Mnfo2uhnf92hvqi2nviouq2hv9puhq
107
- */
108
- export const Mnfo2uhnf92hvqi2nviouq2hv9puhq = new Mnfo2uhnf92hvqi2nviouq2hv9puhq$Type();
package/jest.config.js DELETED
@@ -1,5 +0,0 @@
1
- const rootConfig = require('../../jest.config')
2
- module.exports = {
3
- ...rootConfig,
4
- setupFilesAfterEnv: rootConfig.setupFilesAfterEnv.concat('./test/utils/customMatchers.ts')
5
- }
@@ -1,28 +0,0 @@
1
- import EventEmitter from 'eventemitter3'
2
- import { PeerDescriptor } from '../../generated/packages/dht/protos/DhtRpc'
3
- import { ConnectionID, ConnectionType, ConnectionEvents } from './IConnection'
4
- import { v4 as uuid } from 'uuid'
5
-
6
- export class Connection extends EventEmitter<ConnectionEvents> {
7
- public connectionId: ConnectionID
8
- public connectionType: ConnectionType
9
- private peerDescriptor?: PeerDescriptor
10
-
11
- constructor(connectionType: ConnectionType) {
12
- super()
13
- this.connectionId = createRandomConnectionId()
14
- this.connectionType = connectionType
15
- }
16
-
17
- setPeerDescriptor(peerDescriptor: PeerDescriptor): void {
18
- this.peerDescriptor = peerDescriptor
19
- }
20
-
21
- getPeerDescriptor(): PeerDescriptor | undefined {
22
- return this.peerDescriptor
23
- }
24
- }
25
-
26
- export const createRandomConnectionId = (): ConnectionID => {
27
- return uuid() as ConnectionID
28
- }
@@ -1,78 +0,0 @@
1
- import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
2
- import { Logger } from '@streamr/utils'
3
- import { Empty } from '../../generated/google/protobuf/empty'
4
- import {
5
- DisconnectMode,
6
- DisconnectNotice,
7
- LockRequest,
8
- LockResponse,
9
- PeerDescriptor,
10
- UnlockRequest,
11
- SetPrivateRequest
12
- } from '../../generated/packages/dht/protos/DhtRpc'
13
- import { IConnectionLockRpc } from '../../generated/packages/dht/protos/DhtRpc.server'
14
- import { DhtCallContext } from '../rpc-protocol/DhtCallContext'
15
- import { getNodeIdOrUnknownFromPeerDescriptor } from './ConnectionManager'
16
- import { LockID } from './ConnectionLockStates'
17
- import { DhtAddress, areEqualPeerDescriptors, toNodeId } from '../identifiers'
18
-
19
- interface ConnectionLockRpcLocalOptions {
20
- addRemoteLocked: (id: DhtAddress, lockId: LockID) => void
21
- removeRemoteLocked: (id: DhtAddress, lockId: LockID) => void
22
- closeConnection: (peerDescriptor: PeerDescriptor, gracefulLeave: boolean, reason?: string) => Promise<void>
23
- getLocalPeerDescriptor: () => PeerDescriptor
24
- setPrivate: (id: DhtAddress, isPrivate: boolean) => void
25
- }
26
-
27
- const logger = new Logger(module)
28
-
29
- export class ConnectionLockRpcLocal implements IConnectionLockRpc {
30
-
31
- private readonly options: ConnectionLockRpcLocalOptions
32
-
33
- constructor(options: ConnectionLockRpcLocalOptions) {
34
- this.options = options
35
- }
36
-
37
- async lockRequest(lockRequest: LockRequest, context: ServerCallContext): Promise<LockResponse> {
38
- const senderPeerDescriptor = (context as DhtCallContext).incomingSourceDescriptor!
39
- if (areEqualPeerDescriptors(senderPeerDescriptor, this.options.getLocalPeerDescriptor())) {
40
- const response: LockResponse = {
41
- accepted: false
42
- }
43
- return response
44
- }
45
- const remoteNodeId = toNodeId(senderPeerDescriptor)
46
- this.options.addRemoteLocked(remoteNodeId, lockRequest.lockId)
47
- const response: LockResponse = {
48
- accepted: true
49
- }
50
- return response
51
- }
52
-
53
- async unlockRequest(unlockRequest: UnlockRequest, context: ServerCallContext): Promise<Empty> {
54
- const senderPeerDescriptor = (context as DhtCallContext).incomingSourceDescriptor!
55
- const nodeId = toNodeId(senderPeerDescriptor)
56
- this.options.removeRemoteLocked(nodeId, unlockRequest.lockId)
57
- return {}
58
- }
59
-
60
- async gracefulDisconnect(disconnectNotice: DisconnectNotice, context: ServerCallContext): Promise<Empty> {
61
- const senderPeerDescriptor = (context as DhtCallContext).incomingSourceDescriptor!
62
- logger.trace(getNodeIdOrUnknownFromPeerDescriptor(senderPeerDescriptor) + ' received gracefulDisconnect notice')
63
-
64
- if (disconnectNotice.disconnectMode === DisconnectMode.LEAVING) {
65
- await this.options.closeConnection(senderPeerDescriptor, true, 'graceful leave notified')
66
- } else {
67
- await this.options.closeConnection(senderPeerDescriptor, false, 'graceful disconnect notified')
68
- }
69
- return {}
70
- }
71
-
72
- async setPrivate(request: SetPrivateRequest, context: ServerCallContext): Promise<Empty> {
73
- const senderPeerDescriptor = (context as DhtCallContext).incomingSourceDescriptor!
74
- const senderId = toNodeId(senderPeerDescriptor)
75
- this.options.setPrivate(senderId, request.isPrivate)
76
- return {}
77
- }
78
- }
@@ -1,64 +0,0 @@
1
- import { Logger } from '@streamr/utils'
2
- import { RpcRemote } from '../dht/contact/RpcRemote'
3
- import { DisconnectMode, DisconnectNotice, LockRequest, UnlockRequest, SetPrivateRequest } from '../../generated/packages/dht/protos/DhtRpc'
4
- import { ConnectionLockRpcClient } from '../../generated/packages/dht/protos/DhtRpc.client'
5
- import { LockID } from './ConnectionLockStates'
6
- import { toNodeId } from '../identifiers'
7
-
8
- const logger = new Logger(module)
9
-
10
- export class ConnectionLockRpcRemote extends RpcRemote<ConnectionLockRpcClient> {
11
-
12
- public async lockRequest(lockId: LockID): Promise<boolean> {
13
- logger.trace(`Requesting locked connection to ${toNodeId(this.getPeerDescriptor())}`)
14
- const request: LockRequest = {
15
- lockId
16
- }
17
- const options = this.formDhtRpcOptions()
18
- try {
19
- const res = await this.getClient().lockRequest(request, options)
20
- return res.accepted
21
- } catch (err) {
22
- logger.debug('Connection lock rejected', { err })
23
- return false
24
- }
25
- }
26
-
27
- public unlockRequest(lockId: LockID): void {
28
- logger.trace(`Requesting connection to be unlocked from ${toNodeId(this.getPeerDescriptor())}`)
29
- const request: UnlockRequest = {
30
- lockId
31
- }
32
- const options = this.formDhtRpcOptions({
33
- notification: true
34
- })
35
- this.getClient().unlockRequest(request, options).catch((_e) => {
36
- logger.trace('failed to send unlockRequest')
37
- })
38
- }
39
-
40
- public async gracefulDisconnect(disconnectMode: DisconnectMode): Promise<void> {
41
- logger.trace(`Notifying a graceful disconnect to ${toNodeId(this.getPeerDescriptor())}`)
42
- const request: DisconnectNotice = {
43
- disconnectMode
44
- }
45
- const options = this.formDhtRpcOptions({
46
- connect: false,
47
- sendIfStopped: true,
48
- timeout: 2000 // TODO use options option or named constant?
49
- })
50
- await this.getClient().gracefulDisconnect(request, options)
51
- }
52
-
53
- public async setPrivate(isPrivate: boolean): Promise<void> {
54
- logger.trace(`Setting isPrivate: ${isPrivate} for ${toNodeId(this.getPeerDescriptor())}`)
55
- const request: SetPrivateRequest = {
56
- isPrivate
57
- }
58
- const options = this.formDhtRpcOptions({
59
- connect: false,
60
- notification: true
61
- })
62
- await this.getClient().setPrivate(request, options)
63
- }
64
- }
@@ -1,131 +0,0 @@
1
- // Connection locks are independent of the existence of connections
2
- // that is why this class is needed
3
-
4
- import { DhtAddress } from '../identifiers'
5
-
6
- export type LockID = string
7
-
8
- export class ConnectionLockStates {
9
-
10
- private localLocks: Map<DhtAddress, Set<LockID>> = new Map()
11
- private remoteLocks: Map<DhtAddress, Set<LockID>> = new Map()
12
- // TODO: remove weakLocks use localLocks instead. When opening weakLocks from the ConnectioManager,
13
- // simply do not send lock requests.
14
- private weakLocks: Map<DhtAddress, Set<LockID>> = new Map()
15
- // Used to filter proxy connections from the connections view
16
- private remotePrivateConnections: Set<DhtAddress> = new Set()
17
-
18
- public getLocalLockedConnectionCount(): number {
19
- return this.localLocks.size
20
- }
21
-
22
- public getRemoteLockedConnectionCount(): number {
23
- return this.remoteLocks.size
24
- }
25
-
26
- public getWeakLockedConnectionCount(): number {
27
- return this.weakLocks.size
28
- }
29
-
30
- public isLocalLocked(id: DhtAddress, lockId?: LockID): boolean {
31
- if (lockId === undefined) {
32
- return this.localLocks.has(id)
33
- } else {
34
- return this.localLocks.has(id) && this.localLocks.get(id)!.has(lockId)
35
- }
36
- }
37
-
38
- public isRemoteLocked(id: DhtAddress, lockId?: LockID): boolean {
39
- if (lockId === undefined) {
40
- return this.remoteLocks.has(id)
41
- } else if (this.remoteLocks.has(id) && this.remoteLocks.get(id)!.has(lockId)) {
42
- return true
43
- } else {
44
- return false
45
- }
46
- }
47
-
48
- private isWeakLocked(id: DhtAddress): boolean {
49
- return this.weakLocks.has(id)
50
- }
51
-
52
- public isLocked(id: DhtAddress): boolean {
53
- return (this.isLocalLocked(id) || this.isRemoteLocked(id) || this.isWeakLocked(id))
54
- }
55
-
56
- public addLocalLocked(id: DhtAddress, lockId: LockID): void {
57
- if (!this.localLocks.has(id)) {
58
- this.localLocks.set(id, new Set())
59
- }
60
- this.localLocks.get(id)!.add(lockId)
61
- }
62
-
63
- public addRemoteLocked(id: DhtAddress, lockId: LockID): void {
64
- if (!this.remoteLocks.has(id)) {
65
- this.remoteLocks.set(id, new Set())
66
- }
67
- this.remoteLocks.get(id)!.add(lockId)
68
- }
69
-
70
- public addWeakLocked(id: DhtAddress, lockId: LockID): void {
71
- if (!this.weakLocks.has(id)) {
72
- this.weakLocks.set(id, new Set())
73
- }
74
- this.weakLocks.get(id)!.add(lockId)
75
- }
76
-
77
- public removeLocalLocked(id: DhtAddress, lockId: LockID): void {
78
- if (this.localLocks.has(id)) {
79
- this.localLocks.get(id)?.delete(lockId)
80
- if (this.localLocks.get(id)?.size === 0) {
81
- this.localLocks.delete(id)
82
- }
83
- }
84
- }
85
-
86
- public removeRemoteLocked(id: DhtAddress, lockId: LockID): void {
87
- if (this.remoteLocks.has(id)) {
88
- this.remoteLocks.get(id)?.delete(lockId)
89
- if (this.remoteLocks.get(id)?.size === 0) {
90
- this.remoteLocks.delete(id)
91
- }
92
- }
93
- }
94
-
95
- public removeWeakLocked(id: DhtAddress, lockId: LockID): void {
96
- if (this.weakLocks.has(id)) {
97
- this.weakLocks.get(id)?.delete(lockId)
98
- if (this.weakLocks.get(id)?.size === 0) {
99
- this.weakLocks.delete(id)
100
- }
101
- }
102
- }
103
-
104
- public addPrivate(id: DhtAddress): void {
105
- this.remotePrivateConnections.add(id)
106
- }
107
-
108
- public removePrivate(id: DhtAddress): void {
109
- this.remotePrivateConnections.delete(id)
110
- }
111
-
112
- public getPrivateConnections(): Set<DhtAddress> {
113
- return this.remotePrivateConnections
114
- }
115
-
116
- public isPrivate(id: DhtAddress): boolean {
117
- return this.remotePrivateConnections.has(id)
118
- }
119
-
120
- public clearAllLocks(id: DhtAddress): void {
121
- this.localLocks.delete(id)
122
- this.remoteLocks.delete(id)
123
- this.weakLocks.delete(id)
124
- }
125
-
126
- public clear(): void {
127
- this.localLocks.clear()
128
- this.remoteLocks.clear()
129
- this.weakLocks.clear()
130
- }
131
- }