@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,170 +0,0 @@
1
- import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
2
- import { Logger } from '@streamr/utils'
3
- import {
4
- DhtAddress,
5
- areEqualPeerDescriptors,
6
- toDhtAddress,
7
- toNodeId,
8
- toDhtAddressRaw
9
- } from '../../identifiers'
10
- import { Any } from '../../../generated/google/protobuf/any'
11
- import { Timestamp } from '../../../generated/google/protobuf/timestamp'
12
- import {
13
- DataEntry,
14
- PeerDescriptor,
15
- RecursiveOperation,
16
- ReplicateDataRequest,
17
- StoreDataRequest, StoreDataResponse
18
- } from '../../../generated/packages/dht/protos/DhtRpc'
19
- import { RoutingRpcCommunicator } from '../../transport/RoutingRpcCommunicator'
20
- import { ServiceID } from '../../types/ServiceID'
21
- import { getClosestNodes } from '../contact/getClosestNodes'
22
- import { RecursiveOperationManager } from '../recursive-operation/RecursiveOperationManager'
23
- import { LocalDataStore } from './LocalDataStore'
24
- import { StoreRpcLocal } from './StoreRpcLocal'
25
- import { StoreRpcRemote } from './StoreRpcRemote'
26
-
27
- interface StoreManagerOptions {
28
- rpcCommunicator: RoutingRpcCommunicator
29
- recursiveOperationManager: RecursiveOperationManager
30
- localPeerDescriptor: PeerDescriptor
31
- localDataStore: LocalDataStore
32
- serviceId: ServiceID
33
- highestTtl: number
34
- redundancyFactor: number
35
- getNeighbors: () => ReadonlyArray<PeerDescriptor>
36
- createRpcRemote: (contact: PeerDescriptor) => StoreRpcRemote
37
- }
38
-
39
- const logger = new Logger(module)
40
-
41
- export class StoreManager {
42
-
43
- private readonly options: StoreManagerOptions
44
-
45
- constructor(options: StoreManagerOptions) {
46
- this.options = options
47
- this.registerLocalRpcMethods()
48
- }
49
-
50
- private registerLocalRpcMethods() {
51
- const rpcLocal = new StoreRpcLocal({
52
- localPeerDescriptor: this.options.localPeerDescriptor,
53
- localDataStore: this.options.localDataStore,
54
- replicateDataToContact: (dataEntry: DataEntry, contact: PeerDescriptor) => this.replicateDataToContact(dataEntry, contact),
55
- getStorers: (dataKey: DhtAddress) => this.getStorers(dataKey)
56
- })
57
- this.options.rpcCommunicator.registerRpcMethod(StoreDataRequest, StoreDataResponse, 'storeData',
58
- (request: StoreDataRequest) => rpcLocal.storeData(request))
59
- this.options.rpcCommunicator.registerRpcNotification(ReplicateDataRequest, 'replicateData',
60
- (request: ReplicateDataRequest, context: ServerCallContext) => rpcLocal.replicateData(request, context))
61
- }
62
-
63
- onContactAdded(peerDescriptor: PeerDescriptor): void {
64
- for (const key of this.options.localDataStore.keys()) {
65
- this.replicateAndUpdateStaleState(key, peerDescriptor)
66
- }
67
- }
68
-
69
- private replicateAndUpdateStaleState(dataKey: DhtAddress, newNode: PeerDescriptor): void {
70
- const storers = this.getStorers(dataKey)
71
- const storersBeforeContactAdded = storers.filter((p) => !areEqualPeerDescriptors(p, newNode))
72
- const selfWasPrimaryStorer = areEqualPeerDescriptors(storersBeforeContactAdded[0], this.options.localPeerDescriptor)
73
- if (selfWasPrimaryStorer) {
74
- if (storers.some((p) => areEqualPeerDescriptors(p, newNode))) {
75
- setImmediate(async () => {
76
- const dataEntries = Array.from(this.options.localDataStore.values(dataKey))
77
- await Promise.all(dataEntries.map(async (dataEntry) => this.replicateDataToContact(dataEntry, newNode)))
78
- })
79
- }
80
- } else if (!storers.some((p) => areEqualPeerDescriptors(p, this.options.localPeerDescriptor))) {
81
- this.options.localDataStore.setAllEntriesAsStale(dataKey)
82
- }
83
- }
84
-
85
- private async replicateDataToContact(dataEntry: DataEntry, contact: PeerDescriptor): Promise<void> {
86
- const rpcRemote = this.options.createRpcRemote(contact)
87
- try {
88
- await rpcRemote.replicateData({ entry: dataEntry }, true)
89
- } catch (e) {
90
- logger.trace('replicateData() threw an exception ' + e)
91
- }
92
- }
93
-
94
- public async storeDataToDht(key: DhtAddress, data: Any, creator: DhtAddress): Promise<PeerDescriptor[]> {
95
- logger.debug(`Storing data to DHT ${this.options.serviceId}`)
96
- const result = await this.options.recursiveOperationManager.execute(key, RecursiveOperation.FIND_CLOSEST_NODES)
97
- const closestNodes = result.closestNodes
98
- const successfulNodes: PeerDescriptor[] = []
99
- const ttl = this.options.highestTtl // ToDo: make TTL decrease according to some nice curve
100
- const createdAt = Timestamp.now()
101
- for (let i = 0; i < closestNodes.length && successfulNodes.length < this.options.redundancyFactor; i++) {
102
- const keyRaw = toDhtAddressRaw(key)
103
- const creatorRaw = toDhtAddressRaw(creator)
104
- if (areEqualPeerDescriptors(this.options.localPeerDescriptor, closestNodes[i])) {
105
- this.options.localDataStore.storeEntry({
106
- key: keyRaw,
107
- data,
108
- creator: creatorRaw,
109
- createdAt,
110
- storedAt: Timestamp.now(),
111
- ttl,
112
- stale: false,
113
- deleted: false,
114
- })
115
- successfulNodes.push(closestNodes[i])
116
- continue
117
- }
118
- const rpcRemote = this.options.createRpcRemote(closestNodes[i])
119
- try {
120
- await rpcRemote.storeData({
121
- key: keyRaw,
122
- data,
123
- creator: creatorRaw,
124
- createdAt,
125
- ttl
126
- })
127
- successfulNodes.push(closestNodes[i])
128
- logger.trace('remote.storeData() success')
129
- } catch (e) {
130
- logger.trace('remote.storeData() threw an exception ' + e)
131
- }
132
- }
133
- return successfulNodes
134
- }
135
-
136
- private async replicateDataToClosestNodes(): Promise<void> {
137
- const dataEntries = Array.from(this.options.localDataStore.values())
138
- await Promise.all(dataEntries.map(async (dataEntry) => {
139
- const dataKey = toDhtAddress(dataEntry.key)
140
- const neighbors = getClosestNodes(
141
- dataKey,
142
- this.options.getNeighbors(),
143
- { maxCount: this.options.redundancyFactor }
144
- )
145
- await Promise.all(neighbors.map(async (neighbor) => {
146
- const rpcRemote = this.options.createRpcRemote(neighbor)
147
- try {
148
- await rpcRemote.replicateData({ entry: dataEntry }, false)
149
- } catch (err) {
150
- logger.trace('Failed to replicate data in replicateDataToClosestNodes', { err })
151
- }
152
- }))
153
- }))
154
- }
155
-
156
- private getStorers(dataKey: DhtAddress, excludedNode?: PeerDescriptor): PeerDescriptor[] {
157
- return getClosestNodes(
158
- dataKey,
159
- [...this.options.getNeighbors(), this.options.localPeerDescriptor],
160
- {
161
- maxCount: this.options.redundancyFactor,
162
- excludedNodeIds: excludedNode !== undefined ? new Set([toNodeId(excludedNode)]) : undefined
163
- }
164
- )
165
- }
166
-
167
- async destroy(): Promise<void> {
168
- await this.replicateDataToClosestNodes()
169
- }
170
- }
@@ -1,89 +0,0 @@
1
- import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
2
- import { Logger, executeSafePromise } from '@streamr/utils'
3
- import { Empty } from '../../../generated/google/protobuf/empty'
4
- import { Timestamp } from '../../../generated/google/protobuf/timestamp'
5
- import {
6
- DataEntry,
7
- PeerDescriptor,
8
- ReplicateDataRequest,
9
- StoreDataRequest, StoreDataResponse
10
- } from '../../../generated/packages/dht/protos/DhtRpc'
11
- import { IStoreRpc } from '../../../generated/packages/dht/protos/DhtRpc.server'
12
- import { DhtCallContext } from '../../rpc-protocol/DhtCallContext'
13
- import { LocalDataStore } from './LocalDataStore'
14
- import { areEqualPeerDescriptors, DhtAddress, toDhtAddress } from '../../identifiers'
15
-
16
- interface StoreRpcLocalOptions {
17
- localDataStore: LocalDataStore
18
- localPeerDescriptor: PeerDescriptor
19
- replicateDataToContact: (dataEntry: DataEntry, contact: PeerDescriptor) => Promise<void>
20
- getStorers: (key: DhtAddress) => ReadonlyArray<PeerDescriptor>
21
- }
22
-
23
- const logger = new Logger(module)
24
-
25
- export class StoreRpcLocal implements IStoreRpc {
26
-
27
- private readonly options: StoreRpcLocalOptions
28
-
29
- constructor(options: StoreRpcLocalOptions) {
30
- this.options = options
31
- }
32
-
33
- async storeData(request: StoreDataRequest): Promise<StoreDataResponse> {
34
- logger.trace('storeData()')
35
- const key = toDhtAddress(request.key)
36
- const isLocalNodeStorer = this.isLocalNodeStorer(key)
37
- this.options.localDataStore.storeEntry({
38
- key: request.key,
39
- data: request.data,
40
- creator: request.creator,
41
- createdAt: request.createdAt,
42
- storedAt: Timestamp.now(),
43
- ttl: request.ttl,
44
- stale: !isLocalNodeStorer,
45
- deleted: false
46
- })
47
- if (!isLocalNodeStorer) {
48
- this.options.localDataStore.setAllEntriesAsStale(key)
49
- }
50
- return {}
51
- }
52
-
53
- public async replicateData(request: ReplicateDataRequest, context: ServerCallContext): Promise<Empty> {
54
- logger.trace('server-side replicateData()')
55
- const dataEntry = request.entry!
56
- const wasStored = this.options.localDataStore.storeEntry(dataEntry)
57
- if (wasStored) {
58
- this.replicateDataToNeighbors((context as DhtCallContext).incomingSourceDescriptor!, request.entry!)
59
- }
60
- const key = toDhtAddress(dataEntry.key)
61
- if (!this.isLocalNodeStorer(key)) {
62
- this.options.localDataStore.setAllEntriesAsStale(key)
63
- }
64
- logger.trace('server-side replicateData() at end')
65
- return {}
66
- }
67
-
68
- private isLocalNodeStorer(dataKey: DhtAddress): boolean {
69
- return this.options.getStorers(dataKey).some((p) => areEqualPeerDescriptors(p, this.options.localPeerDescriptor))
70
- }
71
-
72
- private replicateDataToNeighbors(requestor: PeerDescriptor, dataEntry: DataEntry): void {
73
- const dataKey = toDhtAddress(dataEntry.key)
74
- const storers = this.options.getStorers(dataKey)
75
- const isLocalNodePrimaryStorer = areEqualPeerDescriptors(storers[0], this.options.localPeerDescriptor)
76
- // If we are the closest to the data, get storageRedundancyFactor - 1 nearest node to the data, and
77
- // replicate to all those node. Otherwise replicate only to the one closest one. And never replicate
78
- // to the requestor nor to itself.
79
- const targets = (isLocalNodePrimaryStorer ? storers : [storers[0]]).filter(
80
- (p) => !areEqualPeerDescriptors(p, requestor) && !areEqualPeerDescriptors(p, this.options.localPeerDescriptor)
81
- )
82
- targets.forEach((target) => {
83
- setImmediate(() => {
84
- executeSafePromise(() => this.options.replicateDataToContact(dataEntry, target))
85
- })
86
- })
87
- }
88
-
89
- }
@@ -1,32 +0,0 @@
1
- import { toNodeId } from '../../identifiers'
2
- import {
3
- ReplicateDataRequest,
4
- StoreDataRequest
5
- } from '../../../generated/packages/dht/protos/DhtRpc'
6
- import { StoreRpcClient } from '../../../generated/packages/dht/protos/DhtRpc.client'
7
- import { EXISTING_CONNECTION_TIMEOUT, RpcRemote } from '../contact/RpcRemote'
8
-
9
- export class StoreRpcRemote extends RpcRemote<StoreRpcClient> {
10
-
11
- async storeData(request: StoreDataRequest): Promise<void> {
12
- const options = this.formDhtRpcOptions()
13
- try {
14
- await this.getClient().storeData(request, options)
15
- } catch (err) {
16
- const to = toNodeId(this.getPeerDescriptor())
17
- const from = toNodeId(this.getLocalPeerDescriptor())
18
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
19
- throw new Error(`Could not store data to ${to} from ${from} ${err}`)
20
- }
21
- }
22
-
23
- async replicateData(request: ReplicateDataRequest, connect: boolean): Promise<void> {
24
- const options = this.formDhtRpcOptions({
25
- timeout: EXISTING_CONNECTION_TIMEOUT,
26
- notification: true,
27
- connect
28
- })
29
- return this.getClient().replicateData(request, options)
30
- }
31
-
32
- }
package/src/exports.ts DELETED
@@ -1,33 +0,0 @@
1
- export { DhtNode, DhtNodeEvents, DhtNodeOptions } from './dht/DhtNode'
2
- export { ListeningRpcCommunicator } from './transport/ListeningRpcCommunicator'
3
- export { RoutingRpcCommunicator } from './transport/RoutingRpcCommunicator'
4
- export { Simulator, LatencyType } from './connection/simulator/Simulator'
5
- export { SimulatorTransport } from './connection/simulator/SimulatorTransport'
6
- export { getRandomRegion, getRegionDelayMatrix } from './connection/simulator/pings'
7
- export { PeerDescriptor, Message, NodeType, DataEntry } from '../generated/packages/dht/protos/DhtRpc'
8
- export { ITransport, TransportEvents } from './transport/ITransport'
9
- export { ConnectionManager, ConnectionLocker, PortRange, TlsCertificate } from './connection/ConnectionManager'
10
- export { ConnectionsView } from './connection/ConnectionsView'
11
- export { LockID } from './connection/ConnectionLockStates'
12
- export { DefaultConnectorFacade } from './connection/ConnectorFacade'
13
- export { DhtRpcOptions } from './rpc-protocol/DhtRpcOptions'
14
- export { RpcRemote, EXISTING_CONNECTION_TIMEOUT } from './dht/contact/RpcRemote'
15
- export { IceServer } from './connection/webrtc/WebrtcConnector'
16
- export { DhtCallContext } from './rpc-protocol/DhtCallContext'
17
- export { WebsocketClientConnection } from './connection/websocket/NodeWebsocketClientConnection'
18
- export { ManagedConnection } from './connection/ManagedConnection'
19
- export { PendingConnection } from './connection/PendingConnection'
20
- export { IConnection } from './connection/IConnection'
21
- export { ConnectionType } from './connection/IConnection'
22
- export { ServiceID } from './types/ServiceID'
23
- export { RingContacts } from './dht/contact/RingContactList'
24
- export { createOutgoingHandshaker } from './connection/Handshaker'
25
- export {
26
- DhtAddress,
27
- DhtAddressRaw,
28
- toDhtAddress,
29
- toDhtAddressRaw,
30
- randomDhtAddress,
31
- areEqualPeerDescriptors,
32
- toNodeId
33
- } from './identifiers'
@@ -1,28 +0,0 @@
1
- import ipaddr from 'ipaddr.js'
2
-
3
- // IPv4 private address ranges as specified by RFC 1918
4
- // and private loopback addresses
5
- const IPv4PrivateRanges = [
6
- '10.0.0.0/8',
7
- '172.16.0.0/12',
8
- '192.168.0.0/16',
9
- '127.0.0.0/8'
10
- ].map((a) => ipaddr.parseCIDR(a))
11
-
12
- export function isPrivateIPv4(address: string): boolean {
13
- if (ipaddr.IPv4.isValid(address)) {
14
- const ip = ipaddr.IPv4.parse(address)
15
- for (const range of IPv4PrivateRanges) {
16
- if (ip.match(range)) {
17
- return true
18
- }
19
- }
20
- }
21
-
22
- return false
23
- }
24
-
25
- export function getAddressFromIceCandidate(candidate: string): string | undefined {
26
- const fields = candidate.split(' ').filter((field) => field.length > 0)
27
- return fields.length >= 5 && ipaddr.isValid(fields[4]) ? fields[4] : undefined
28
- }
@@ -1,19 +0,0 @@
1
- import { ConnectionType } from '../connection/IConnection'
2
- import { ConnectivityMethod, NodeType, PeerDescriptor } from '../../generated/packages/dht/protos/DhtRpc'
3
- import { isPrivateIPv4 } from './AddressTools'
4
-
5
- export const canOpenConnectionFromBrowser = (websocketServer: ConnectivityMethod): boolean => {
6
- const hasPrivateAddress = ((websocketServer.host === 'localhost') || isPrivateIPv4(websocketServer.host))
7
- return websocketServer.tls || hasPrivateAddress
8
- }
9
-
10
- export const expectedConnectionType = (localPeerDescriptor: PeerDescriptor, remotePeerDescriptor: PeerDescriptor): ConnectionType => {
11
- if (remotePeerDescriptor.websocket
12
- && (localPeerDescriptor.type !== NodeType.BROWSER || canOpenConnectionFromBrowser(remotePeerDescriptor.websocket))) {
13
- return ConnectionType.WEBSOCKET_CLIENT
14
- } else if (localPeerDescriptor.websocket
15
- && (remotePeerDescriptor.type !== NodeType.BROWSER || canOpenConnectionFromBrowser(localPeerDescriptor.websocket))) {
16
- return ConnectionType.WEBSOCKET_SERVER
17
- }
18
- return ConnectionType.WEBRTC
19
- }
@@ -1 +0,0 @@
1
- export const isBrowserEnvironment = (): boolean => false
@@ -1,3 +0,0 @@
1
- // webpack overwrites the isBrowserEnvironment.ts with this file when it creates the browser bundle
2
-
3
- export const isBrowserEnvironment = (): boolean => true
@@ -1,57 +0,0 @@
1
- import {
2
- createSignature,
3
- hash
4
- } from '@streamr/utils'
5
- import crypto from 'crypto'
6
- import { isBrowserEnvironment } from '../helpers/browser/isBrowserEnvironment'
7
- import { createPeerDescriptorSignaturePayload } from '../helpers/createPeerDescriptorSignaturePayload'
8
- import { DhtAddress, DhtAddressRaw, toDhtAddressRaw } from '../identifiers'
9
- import {
10
- ConnectivityResponse,
11
- NodeType,
12
- PeerDescriptor
13
- } from '../../generated/packages/dht/protos/DhtRpc'
14
-
15
- const calculateNodeIdRaw = (ipAddress: number, privateKey: Uint8Array): DhtAddressRaw => {
16
- // nodeId is calculated as
17
- // concatenate(
18
- // get104leastSignificatBits(hash(ipAddress)),
19
- // get56leastSignificatBits(sign(ipAddress))
20
- // )
21
- const ipAsBuffer = Buffer.alloc(4)
22
- ipAsBuffer.writeUInt32BE(ipAddress)
23
- const ipHash = hash(ipAsBuffer)
24
- const signature = createSignature(ipAsBuffer, privateKey)
25
- const nodeIdRaw = Buffer.concat([
26
- ipHash.subarray(ipHash.length - 13, ipHash.length),
27
- signature.subarray(signature.length - 7, signature.length)
28
- ])
29
- return nodeIdRaw
30
- }
31
-
32
- export const createPeerDescriptor = (connectivityResponse: ConnectivityResponse, region: number, nodeId?: DhtAddress): PeerDescriptor => {
33
- const privateKey = crypto.randomBytes(32)
34
- const publicKey = crypto.randomBytes(20) // TODO calculate publicKey from privateKey
35
- let nodeIdRaw: DhtAddressRaw
36
- if (nodeId !== undefined) {
37
- nodeIdRaw = toDhtAddressRaw(nodeId)
38
- } else {
39
- nodeIdRaw = calculateNodeIdRaw(connectivityResponse.ipAddress, privateKey)
40
- }
41
- const ret: PeerDescriptor = {
42
- nodeId: nodeIdRaw,
43
- type: isBrowserEnvironment() ? NodeType.BROWSER : NodeType.NODEJS,
44
- ipAddress: connectivityResponse.ipAddress,
45
- region,
46
- publicKey
47
- }
48
- if (connectivityResponse.websocket) {
49
- ret.websocket = {
50
- host: connectivityResponse.websocket.host,
51
- port: connectivityResponse.websocket.port,
52
- tls: connectivityResponse.websocket.tls
53
- }
54
- }
55
- ret.signature = createSignature(createPeerDescriptorSignaturePayload(ret), privateKey)
56
- return ret
57
- }
@@ -1,28 +0,0 @@
1
- import { ConnectivityMethod, PeerDescriptor } from '../../generated/packages/dht/protos/DhtRpc'
2
-
3
- function convertUnsignedIntegerToBuffer(number: number): Buffer {
4
- const buffer = Buffer.alloc(4)
5
- buffer.writeUInt32BE(number)
6
- return buffer
7
- }
8
-
9
- export const createPeerDescriptorSignaturePayload = (peerDescriptor: PeerDescriptor): Uint8Array => {
10
- const separator = Buffer.from(',')
11
- const buffers = [
12
- peerDescriptor.type !== undefined ? convertUnsignedIntegerToBuffer(peerDescriptor.type) : new Uint8Array(0),
13
- separator,
14
- peerDescriptor.udp !== undefined ? ConnectivityMethod.toBinary(peerDescriptor.udp) : new Uint8Array(0),
15
- separator,
16
- peerDescriptor.tcp !== undefined ? ConnectivityMethod.toBinary(peerDescriptor.tcp) : new Uint8Array(0),
17
- separator,
18
- peerDescriptor.websocket !== undefined ? ConnectivityMethod.toBinary(peerDescriptor.websocket) : new Uint8Array(0),
19
- separator,
20
- peerDescriptor.region !== undefined ? convertUnsignedIntegerToBuffer(peerDescriptor.region) : new Uint8Array(0),
21
- separator,
22
- peerDescriptor.ipAddress !== undefined ? convertUnsignedIntegerToBuffer(peerDescriptor.ipAddress) : new Uint8Array(0),
23
- separator,
24
- peerDescriptor.publicKey !== undefined ? Buffer.from(peerDescriptor.publicKey) : new Uint8Array(0)
25
- ]
26
- return Buffer.concat(buffers)
27
- }
28
-
@@ -1,9 +0,0 @@
1
- import { Logger } from '@streamr/utils'
2
-
3
- export const debugVars: Record<string, any> = []
4
-
5
- export function logInfoIf(logger: Logger, condition: boolean, msg: string): void {
6
- if (condition) {
7
- logger.info(msg)
8
- }
9
- }
@@ -1,49 +0,0 @@
1
- /* eslint-disable max-len */
2
-
3
- export enum ErrorCode {
4
- CONNECTION_FAILED = 'CONNECTION_FAILED',
5
- COULD_NOT_ROUTE = 'COULD_NOT_ROUTE',
6
- STARTING_WEBSOCKET_SERVER_FAILED = 'STARTING_WEBSOCKET_SERVER_FAILED',
7
- WEBSOCKET_CONNECTION_REQUEST_REJECTED = 'WEBSOCKET_CONNECTION_REQUEST_REJECTED',
8
- COULD_NOT_START = 'COULD_NOT_START',
9
- COULD_NOT_STOP = 'COULD_NOT_STOP',
10
- CANNOT_CONNECT_TO_SELF = 'CANNOT_CONNECT_TO_SELF',
11
- NOT_IMPLEMENTED = 'NOT_IMPLEMENTED',
12
- ILLEGAL_RTC_PEER_CONNECTION_STATE = 'ILLEGAL_RTC_PEER_CONNECTION_STATE',
13
- ILLEGAL_ARGUMENTS = 'ILLEGAL_ARGUMENTS',
14
- CONNECTIVITY_RESPONSE_NOT_RECEIVED_BEFORE_TIMEOUT = 'CONNECTIVITY_RESPONSE_NOT_RECEIVED_BEFORE_TIMEOUT',
15
- CONNECTION_LOCKER = 'CONNECTION_LOCKER',
16
- DHT_JOIN_TIMEOUT = 'DHT_JOIN_TIMEOUT',
17
- SEND_FAILED = 'SEND_FAILED',
18
- GETTING_DATA_FAILED = 'GETTING_DATA_FAILED',
19
- CONNECTION_NOT_OPEN = 'CONNECTION_NOT_OPEN'
20
- }
21
-
22
- class Err extends Error {
23
-
24
- public code: ErrorCode
25
- public originalError?: Error | string
26
-
27
- constructor(code: ErrorCode, message?: string, originalError?: Error | string) {
28
- super(message)
29
- this.code = code
30
- this.originalError = originalError
31
- }
32
- }
33
-
34
- export class ConnectionFailed extends Err { constructor( message?: string, originalError?: Error | string) { super(ErrorCode.CONNECTION_FAILED, message, originalError) } }
35
- export class CouldNotRoute extends Err { constructor(message?: string, originalError?: Error | string) { super(ErrorCode.COULD_NOT_ROUTE, message, originalError) } }
36
- export class WebsocketServerStartError extends Err { constructor(message?: string, originalError?: Error | string) { super(ErrorCode.STARTING_WEBSOCKET_SERVER_FAILED, message, originalError) } }
37
- export class WebsocketConnectionRequestRejected extends Err { constructor(message?: string, originalError?: Error | string) { super(ErrorCode.WEBSOCKET_CONNECTION_REQUEST_REJECTED, message, originalError) } }
38
- export class CouldNotStart extends Err { constructor(message?: string, originalError?: Error | string) { super(ErrorCode.COULD_NOT_START, message, originalError) } }
39
- export class CouldNotStop extends Err { constructor(message?: string, originalError?: Error | string) { super(ErrorCode.COULD_NOT_STOP, message, originalError) } }
40
- export class CannotConnectToSelf extends Err { constructor(message?: string, originalError?: Error | string) {super(ErrorCode.CANNOT_CONNECT_TO_SELF, message, originalError) } }
41
- export class NotImplemented extends Err { constructor(message?: string, originalError?: Error | string) { super(ErrorCode.NOT_IMPLEMENTED, message, originalError) } }
42
- export class IllegalRtcPeerConnectionState extends Err { constructor(message?: string, originalError?: Error | string) { super(ErrorCode.ILLEGAL_RTC_PEER_CONNECTION_STATE, message, originalError) } }
43
- export class IllegalArguments extends Err { constructor(message?: string, originalError?: Error | string) { super(ErrorCode.ILLEGAL_ARGUMENTS, message, originalError) } }
44
- export class ConnectivityResponseTimeout extends Err { constructor(message?: string, originalError?: Error | string) { super(ErrorCode.CONNECTIVITY_RESPONSE_NOT_RECEIVED_BEFORE_TIMEOUT, message, originalError) } }
45
- export class ConnectionLocker extends Err { constructor(message?: string, originalError?: Error | string) { super(ErrorCode.CONNECTION_LOCKER, message, originalError) } }
46
- export class DhtJoinTimeout extends Err { constructor(message?: string, originalError?: Error | string) { super(ErrorCode.DHT_JOIN_TIMEOUT, message, originalError) } }
47
- export class SendFailed extends Err { constructor(message?: string, originalError?: Error | string) { super(ErrorCode.SEND_FAILED, message, originalError) } }
48
- export class GettingDataFailed extends Err { constructor(message?: string, originalError?: Error | string) { super(ErrorCode.GETTING_DATA_FAILED, message, originalError) } }
49
- export class ConnectionNotOpen extends Err { constructor( message?: string, originalError?: Error | string) { super(ErrorCode.CONNECTION_NOT_OPEN, message, originalError) } }
@@ -1,15 +0,0 @@
1
- import crypto from 'crypto'
2
- import { DhtAddress } from '../identifiers'
3
-
4
- type Offerer = 'local' | 'remote'
5
-
6
- export const getOfferer = (localNodeId: DhtAddress, remoteNodeId: DhtAddress): Offerer => {
7
- return getOfferingHash(localNodeId + ',' + remoteNodeId) < getOfferingHash(remoteNodeId + ',' + localNodeId)
8
- ? 'local'
9
- : 'remote'
10
- }
11
-
12
- const getOfferingHash = (idPair: string): number => {
13
- const buffer = crypto.createHash('md5').update(idPair).digest()
14
- return buffer.readInt32LE(0)
15
- }
@@ -1,57 +0,0 @@
1
- import { IMessageType } from '@protobuf-ts/runtime'
2
- import {
3
- ClosestPeersRequest,
4
- ClosestPeersResponse,
5
- ConnectivityMethod,
6
- ConnectivityRequest,
7
- ConnectivityResponse,
8
- DisconnectNotice,
9
- HandshakeRequest,
10
- HandshakeResponse,
11
- LeaveNotice,
12
- Message,
13
- PeerDescriptor,
14
- PingRequest,
15
- PingResponse,
16
- RecursiveOperationResponse,
17
- RecursiveOperationRequest,
18
- RouteMessageAck,
19
- RouteMessageWrapper,
20
- WebsocketConnectionRequest,
21
- WebrtcConnectionRequest,
22
- RtcOffer,
23
- RtcAnswer,
24
- IceCandidate,
25
- LockRequest,
26
- UnlockRequest,
27
- LockResponse
28
-
29
- } from '../../generated/packages/dht/protos/DhtRpc'
30
-
31
- export const protoClasses: Array<IMessageType<any>> = [
32
- ClosestPeersRequest,
33
- ClosestPeersResponse,
34
- RecursiveOperationRequest,
35
- RecursiveOperationResponse,
36
- PingRequest,
37
- PingResponse,
38
- LeaveNotice,
39
- PeerDescriptor,
40
- ConnectivityMethod,
41
- DisconnectNotice,
42
- RouteMessageWrapper,
43
- RouteMessageAck,
44
- ConnectivityRequest,
45
- ConnectivityResponse,
46
- HandshakeRequest,
47
- HandshakeResponse,
48
- Message,
49
- WebsocketConnectionRequest,
50
- WebrtcConnectionRequest,
51
- RtcOffer,
52
- RtcAnswer,
53
- IceCandidate,
54
- LockRequest,
55
- UnlockRequest,
56
- LockResponse
57
- ]
@@ -1,21 +0,0 @@
1
- import { IMessageType } from '@protobuf-ts/runtime'
2
-
3
- import { protoClasses } from './protoClasses'
4
- import { protoClasses as rpcProtoClasses } from '@streamr/proto-rpc'
5
-
6
- const typeRegistry = protoClasses.concat(rpcProtoClasses)
7
-
8
- export function protoToString<T extends object, ClassType extends IMessageType<T>>(protoObj: T,
9
- objectType: ClassType): string {
10
-
11
- let ret = ''
12
- try {
13
- ret = objectType.toJsonString(protoObj, {
14
- typeRegistry
15
- })
16
- } catch (_e) {
17
- ret = '[type not in type registry]'
18
- }
19
-
20
- return ret
21
- }
@@ -1,32 +0,0 @@
1
- export const LOCAL_PROTOCOL_VERSION = '1.1'
2
-
3
- /*
4
- * When two nodes negotiate whether they are compatible or not, it is up to the
5
- * newer version to decide if it supports the old version or not.
6
- *
7
- * The older version assumes optimistically that it may be supported by the newer
8
- * version. It can't know for sure, but the other node will tell if it is not
9
- * supported (e.g. rejecting the handshake with UNSUPPORTED_VERSION error).
10
- */
11
- export const isMaybeSupportedVersion = (remoteVersion: string): boolean => {
12
- const localMajor = parseVersion(LOCAL_PROTOCOL_VERSION)!.major
13
- const remoteMajor = parseVersion(remoteVersion)?.major
14
- if ((remoteMajor === undefined) || (remoteMajor < localMajor)) {
15
- return false
16
- } else {
17
- // TODO implement proper checking when there are new protocol versions
18
- return true
19
- }
20
- }
21
-
22
- export const parseVersion = (version: string): { major: number, minor: number } | undefined => {
23
- const parts = version.split('.')
24
- if (parts.length === 2) {
25
- const values = parts.map((p) => Number(p))
26
- if (!values.some((v) => isNaN(v))) {
27
- return { major: values[0], minor: values[1] }
28
- }
29
- } else {
30
- return undefined
31
- }
32
- }