@streamr/dht 102.0.0-beta.1 → 102.0.0-beta.3

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 (211) hide show
  1. package/dist/generated/google/protobuf/any.d.ts +180 -0
  2. package/dist/generated/google/protobuf/any.js +155 -0
  3. package/dist/generated/google/protobuf/any.js.map +1 -0
  4. package/dist/generated/google/protobuf/empty.d.ts +31 -0
  5. package/dist/generated/google/protobuf/empty.js +32 -0
  6. package/dist/generated/google/protobuf/empty.js.map +1 -0
  7. package/dist/generated/google/protobuf/timestamp.d.ts +155 -0
  8. package/dist/generated/google/protobuf/timestamp.js +136 -0
  9. package/dist/generated/google/protobuf/timestamp.js.map +1 -0
  10. package/dist/generated/packages/dht/protos/DhtRpc.client.d.ts +361 -0
  11. package/dist/generated/packages/dht/protos/DhtRpc.client.js +285 -0
  12. package/dist/generated/packages/dht/protos/DhtRpc.client.js.map +1 -0
  13. package/dist/generated/packages/dht/protos/DhtRpc.d.ts +999 -0
  14. package/dist/generated/packages/dht/protos/DhtRpc.js +677 -0
  15. package/dist/generated/packages/dht/protos/DhtRpc.js.map +1 -0
  16. package/dist/generated/packages/dht/protos/DhtRpc.server.d.ts +162 -0
  17. package/dist/generated/packages/dht/protos/DhtRpc.server.js +3 -0
  18. package/dist/generated/packages/dht/protos/DhtRpc.server.js.map +1 -0
  19. package/dist/generated/packages/proto-rpc/protos/ProtoRpc.d.ts +87 -0
  20. package/dist/generated/packages/proto-rpc/protos/ProtoRpc.js +66 -0
  21. package/dist/generated/packages/proto-rpc/protos/ProtoRpc.js.map +1 -0
  22. package/dist/package.json +7 -7
  23. package/package.json +7 -7
  24. package/eslint.config.mjs +0 -12
  25. package/src/connection/Connection.ts +0 -28
  26. package/src/connection/ConnectionLockRpcLocal.ts +0 -78
  27. package/src/connection/ConnectionLockRpcRemote.ts +0 -64
  28. package/src/connection/ConnectionLockStates.ts +0 -131
  29. package/src/connection/ConnectionManager.ts +0 -661
  30. package/src/connection/ConnectionsView.ts +0 -8
  31. package/src/connection/ConnectorFacade.ts +0 -217
  32. package/src/connection/Handshaker.ts +0 -209
  33. package/src/connection/IConnection.ts +0 -40
  34. package/src/connection/ManagedConnection.ts +0 -113
  35. package/src/connection/OutputBuffer.ts +0 -28
  36. package/src/connection/PendingConnection.ts +0 -68
  37. package/src/connection/connectivityChecker.ts +0 -108
  38. package/src/connection/connectivityRequestHandler.ts +0 -116
  39. package/src/connection/simulator/Simulator.ts +0 -369
  40. package/src/connection/simulator/SimulatorConnection.ts +0 -137
  41. package/src/connection/simulator/SimulatorConnector.ts +0 -98
  42. package/src/connection/simulator/SimulatorTransport.ts +0 -15
  43. package/src/connection/simulator/pings.ts +0 -42
  44. package/src/connection/webrtc/BrowserWebrtcConnection.ts +0 -242
  45. package/src/connection/webrtc/IWebrtcConnection.ts +0 -24
  46. package/src/connection/webrtc/NodeWebrtcConnection.ts +0 -245
  47. package/src/connection/webrtc/WebrtcConnector.ts +0 -234
  48. package/src/connection/webrtc/WebrtcConnectorRpcLocal.ts +0 -108
  49. package/src/connection/webrtc/WebrtcConnectorRpcRemote.ts +0 -60
  50. package/src/connection/webrtc/iceServerAsString.ts +0 -15
  51. package/src/connection/websocket/AbstractWebsocketClientConnection.ts +0 -122
  52. package/src/connection/websocket/AutoCertifierClientFacade.ts +0 -89
  53. package/src/connection/websocket/BrowserWebsocketClientConnection.ts +0 -44
  54. package/src/connection/websocket/NodeWebsocketClientConnection.ts +0 -39
  55. package/src/connection/websocket/WebsocketClientConnector.ts +0 -119
  56. package/src/connection/websocket/WebsocketClientConnectorRpcLocal.ts +0 -38
  57. package/src/connection/websocket/WebsocketClientConnectorRpcRemote.ts +0 -19
  58. package/src/connection/websocket/WebsocketServer.ts +0 -164
  59. package/src/connection/websocket/WebsocketServerConnection.ts +0 -109
  60. package/src/connection/websocket/WebsocketServerConnector.ts +0 -290
  61. package/src/dht/DhtNode.ts +0 -683
  62. package/src/dht/DhtNodeRpcLocal.ts +0 -84
  63. package/src/dht/DhtNodeRpcRemote.ts +0 -107
  64. package/src/dht/ExternalApiRpcLocal.ts +0 -58
  65. package/src/dht/ExternalApiRpcRemote.ts +0 -41
  66. package/src/dht/PeerManager.ts +0 -305
  67. package/src/dht/contact/Contact.ts +0 -19
  68. package/src/dht/contact/ContactList.ts +0 -43
  69. package/src/dht/contact/RandomContactList.ts +0 -56
  70. package/src/dht/contact/RingContactList.ts +0 -143
  71. package/src/dht/contact/RpcRemote.ts +0 -72
  72. package/src/dht/contact/SortedContactList.ts +0 -173
  73. package/src/dht/contact/getClosestNodes.ts +0 -24
  74. package/src/dht/contact/ringIdentifiers.ts +0 -62
  75. package/src/dht/discovery/DiscoverySession.ts +0 -129
  76. package/src/dht/discovery/PeerDiscovery.ts +0 -244
  77. package/src/dht/discovery/RingDiscoverySession.ts +0 -148
  78. package/src/dht/recursive-operation/RecursiveOperationManager.ts +0 -251
  79. package/src/dht/recursive-operation/RecursiveOperationRpcLocal.ts +0 -34
  80. package/src/dht/recursive-operation/RecursiveOperationRpcRemote.ts +0 -43
  81. package/src/dht/recursive-operation/RecursiveOperationSession.ts +0 -231
  82. package/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.ts +0 -35
  83. package/src/dht/recursive-operation/RecursiveOperationSessionRpcRemote.ts +0 -30
  84. package/src/dht/routing/DuplicateDetector.ts +0 -34
  85. package/src/dht/routing/Router.ts +0 -246
  86. package/src/dht/routing/RouterRpcLocal.ts +0 -78
  87. package/src/dht/routing/RouterRpcRemote.ts +0 -80
  88. package/src/dht/routing/RoutingSession.ts +0 -243
  89. package/src/dht/routing/RoutingTablesCache.ts +0 -60
  90. package/src/dht/routing/getPreviousPeer.ts +0 -6
  91. package/src/dht/store/LocalDataStore.ts +0 -84
  92. package/src/dht/store/StoreManager.ts +0 -170
  93. package/src/dht/store/StoreRpcLocal.ts +0 -89
  94. package/src/dht/store/StoreRpcRemote.ts +0 -32
  95. package/src/exports.ts +0 -33
  96. package/src/helpers/AddressTools.ts +0 -28
  97. package/src/helpers/Connectivity.ts +0 -19
  98. package/src/helpers/browser/isBrowserEnvironment.ts +0 -1
  99. package/src/helpers/browser/isBrowserEnvironment_override.ts +0 -3
  100. package/src/helpers/createPeerDescriptor.ts +0 -57
  101. package/src/helpers/createPeerDescriptorSignaturePayload.ts +0 -28
  102. package/src/helpers/debugHelpers.ts +0 -9
  103. package/src/helpers/errors.ts +0 -49
  104. package/src/helpers/offering.ts +0 -15
  105. package/src/helpers/protoClasses.ts +0 -57
  106. package/src/helpers/protoToString.ts +0 -21
  107. package/src/helpers/version.ts +0 -32
  108. package/src/identifiers.ts +0 -29
  109. package/src/rpc-protocol/DhtCallContext.ts +0 -14
  110. package/src/rpc-protocol/DhtRpcOptions.ts +0 -10
  111. package/src/transport/ITransport.ts +0 -37
  112. package/src/transport/ListeningRpcCommunicator.ts +0 -32
  113. package/src/transport/RoutingRpcCommunicator.ts +0 -66
  114. package/src/types/ServiceID.ts +0 -1
  115. package/src/types/textencoding.d.ts +0 -6
  116. package/test/benchmark/Find.test.ts +0 -72
  117. package/test/benchmark/KademliaCorrectness.test.ts +0 -114
  118. package/test/benchmark/RingCorrectness.test.ts +0 -157
  119. package/test/benchmark/SortedContactListBenchmark.test.ts +0 -108
  120. package/test/benchmark/WebsocketServerMemoryLeak.test.ts +0 -41
  121. package/test/benchmark/hybrid-network-simulation/RingContactList.test.ts +0 -71
  122. package/test/end-to-end/GeoIpLayer0.test.ts +0 -55
  123. package/test/end-to-end/Layer0-Layer1.test.ts +0 -93
  124. package/test/end-to-end/Layer0.test.ts +0 -76
  125. package/test/end-to-end/Layer0MixedConnectionTypes.test.ts +0 -110
  126. package/test/end-to-end/Layer0Webrtc-Layer1.test.ts +0 -137
  127. package/test/end-to-end/Layer0Webrtc.test.ts +0 -85
  128. package/test/end-to-end/Layer1-Scale-WebSocket.test.ts +0 -82
  129. package/test/end-to-end/Layer1-Scale-Webrtc.test.ts +0 -76
  130. package/test/end-to-end/RecoveryFromFailedAutoCertification.test.ts +0 -52
  131. package/test/end-to-end/WebsocketConnectionRequest.test.ts +0 -69
  132. package/test/end-to-end/memory-leak.test.ts +0 -80
  133. package/test/integration/ConnectionLocking.test.ts +0 -192
  134. package/test/integration/ConnectionManager.test.ts +0 -528
  135. package/test/integration/ConnectivityChecking.test.ts +0 -53
  136. package/test/integration/DhtJoinPeerDiscovery.test.ts +0 -49
  137. package/test/integration/DhtNode.test.ts +0 -66
  138. package/test/integration/DhtNodeExternalAPI.test.ts +0 -48
  139. package/test/integration/DhtNodeRpcRemote.test.ts +0 -66
  140. package/test/integration/DhtRpc.test.ts +0 -121
  141. package/test/integration/Find.test.ts +0 -45
  142. package/test/integration/GeoIpConnectivityChecking.test.ts +0 -72
  143. package/test/integration/Layer1-scale.test.ts +0 -189
  144. package/test/integration/Mock-Layer1-Layer0.test.ts +0 -85
  145. package/test/integration/MultipleEntryPointJoining.test.ts +0 -105
  146. package/test/integration/ReplicateData.test.ts +0 -104
  147. package/test/integration/RouteMessage.test.ts +0 -230
  148. package/test/integration/RouterRpcRemote.test.ts +0 -77
  149. package/test/integration/SimultaneousConnections.test.ts +0 -316
  150. package/test/integration/Store.test.ts +0 -85
  151. package/test/integration/StoreAndDelete.test.ts +0 -77
  152. package/test/integration/StoreOnDhtWithThreeNodes.test.ts +0 -59
  153. package/test/integration/StoreOnDhtWithTwoNodes.test.ts +0 -51
  154. package/test/integration/StoreRpcRemote.test.ts +0 -54
  155. package/test/integration/WebrtcConnectionManagement.test.ts +0 -191
  156. package/test/integration/WebrtcConnectorRpc.test.ts +0 -125
  157. package/test/integration/Websocket.test.ts +0 -65
  158. package/test/integration/WebsocketClientConnectorRpc.test.ts +0 -69
  159. package/test/integration/WebsocketConnectionManagement.test.ts +0 -191
  160. package/test/integration/rpc-connections-over-webrtc.test.ts +0 -123
  161. package/test/kademlia-simulation/data/nodeids.json +0 -13002
  162. package/test/kademlia-simulation/data/orderedneighbors.json +0 -1001
  163. package/test/types/global.d.ts +0 -1
  164. package/test/unit/AddressTools.test.ts +0 -44
  165. package/test/unit/AutoCertifierClientFacade.test.ts +0 -58
  166. package/test/unit/ConnectionManager.test.ts +0 -65
  167. package/test/unit/ConnectivityHelpers.test.ts +0 -61
  168. package/test/unit/DiscoverySession.test.ts +0 -87
  169. package/test/unit/DuplicateDetector.test.ts +0 -31
  170. package/test/unit/Handshaker.test.ts +0 -169
  171. package/test/unit/ListeningRpcCommunicator.test.ts +0 -52
  172. package/test/unit/LocalDataStore.test.ts +0 -108
  173. package/test/unit/ManagedConnection.test.ts +0 -58
  174. package/test/unit/PeerManager.test.ts +0 -93
  175. package/test/unit/PendingConnection.test.ts +0 -57
  176. package/test/unit/ProtobufMessage.test.ts +0 -21
  177. package/test/unit/RandomContactList.test.ts +0 -58
  178. package/test/unit/RecursiveOperationManager.test.ts +0 -161
  179. package/test/unit/RecursiveOperationSession.test.ts +0 -68
  180. package/test/unit/Router.test.ts +0 -137
  181. package/test/unit/RoutingSession.test.ts +0 -86
  182. package/test/unit/SortedContactList.test.ts +0 -115
  183. package/test/unit/StoreManager.test.ts +0 -146
  184. package/test/unit/StoreRpcLocal.test.ts +0 -167
  185. package/test/unit/WebrtcConnection.test.ts +0 -29
  186. package/test/unit/WebrtcConnector.test.ts +0 -56
  187. package/test/unit/WebsocketClientConnector.test.ts +0 -101
  188. package/test/unit/WebsocketServer.test.ts +0 -66
  189. package/test/unit/WebsocketServerConnector.test.ts +0 -102
  190. package/test/unit/connectivityRequestHandler.test.ts +0 -104
  191. package/test/unit/createPeerDescriptor.test.ts +0 -69
  192. package/test/unit/customMatchers.test.ts +0 -34
  193. package/test/unit/getClosestNodes.test.ts +0 -30
  194. package/test/unit/version.test.ts +0 -18
  195. package/test/unit/webrtcReplaceInternalIpWithExternalIp.test.ts +0 -18
  196. package/test/utils/FakeConnectorFacade.ts +0 -41
  197. package/test/utils/FakeRpcCommunicator.ts +0 -23
  198. package/test/utils/FakeTransport.ts +0 -79
  199. package/test/utils/customMatchers.ts +0 -71
  200. package/test/utils/mock/MockConnection.ts +0 -26
  201. package/test/utils/mock/MockConnectionsView.ts +0 -18
  202. package/test/utils/mock/MockRouter.ts +0 -62
  203. package/test/utils/mock/MockRpcCommunicator.ts +0 -7
  204. package/test/utils/mock/MockTransport.ts +0 -26
  205. package/test/utils/mock/mockDataEntry.ts +0 -38
  206. package/test/utils/topology.ts +0 -79
  207. package/test/utils/utils.ts +0 -268
  208. package/tsconfig.browser.json +0 -17
  209. package/tsconfig.jest.json +0 -25
  210. package/tsconfig.json +0 -3
  211. package/tsconfig.node.json +0 -24
@@ -1,79 +0,0 @@
1
- import { EventEmitter } from 'eventemitter3'
2
- import { DhtAddress, toDhtAddress, toNodeId } from '../../src/identifiers'
3
- import { Message, PeerDescriptor } from '../../generated/packages/dht/protos/DhtRpc'
4
- import { DEFAULT_SEND_OPTIONS, ITransport, SendOptions, TransportEvents } from '../../src/transport/ITransport'
5
- import { ConnectionsView } from '../../src/exports'
6
-
7
- // TODO extract ConnectionsView functionality to FakeConnectionsView
8
- class FakeTransport extends EventEmitter<TransportEvents> implements ITransport, ConnectionsView {
9
-
10
- private onSend: (msg: Message) => void
11
- private readonly localPeerDescriptor: PeerDescriptor
12
- // currently adds a peerDescription to the connections array when a "connect" option is seen in
13
- // in send() call and never disconnects (TODO could add some disconnection logic? and maybe
14
- // the connection should be seen by another FakeTransport instance, too?)
15
- private connections: PeerDescriptor[] = []
16
-
17
- constructor(peerDescriptor: PeerDescriptor, onSend: (msg: Message) => void) {
18
- super()
19
- this.onSend = onSend
20
- this.localPeerDescriptor = peerDescriptor
21
- }
22
-
23
- async send(msg: Message, opts?: SendOptions): Promise<void> {
24
- const connect = opts?.connect ?? DEFAULT_SEND_OPTIONS.connect
25
- const targetNodeId = toNodeId(msg.targetDescriptor!)
26
- if (connect && !this.connections.some((c) => toNodeId(c) === targetNodeId)) {
27
- this.connect(msg.targetDescriptor!)
28
- }
29
- msg.sourceDescriptor = this.localPeerDescriptor
30
- this.onSend(msg)
31
- }
32
-
33
- getLocalPeerDescriptor(): PeerDescriptor {
34
- return this.localPeerDescriptor
35
- }
36
-
37
- private connect(peerDescriptor: PeerDescriptor) {
38
- this.connections.push(peerDescriptor)
39
- this.emit('connected', peerDescriptor)
40
- }
41
-
42
- getConnections(): PeerDescriptor[] {
43
- return this.connections
44
- }
45
-
46
- getConnectionCount(): number {
47
- return this.connections.length
48
- }
49
-
50
- hasConnection(nodeId: DhtAddress): boolean {
51
- return this.connections.some((c) => toNodeId(c) === nodeId)
52
- }
53
-
54
- // eslint-disable-next-line class-methods-use-this
55
- stop(): void | Promise<void> {
56
- }
57
-
58
- // eslint-disable-next-line class-methods-use-this
59
- getDiagnosticInfo(): Record<string, unknown> {
60
- return {}
61
- }
62
- }
63
-
64
- export class FakeEnvironment {
65
-
66
- private transports: FakeTransport[] = []
67
-
68
- createTransport(peerDescriptor: PeerDescriptor): FakeTransport {
69
- const transport = new FakeTransport(peerDescriptor, (msg) => {
70
- const targetNode = toDhtAddress(msg.targetDescriptor!.nodeId)
71
- const targetTransport = this.transports.find((t) => toNodeId(t.getLocalPeerDescriptor()) === targetNode)
72
- if (targetTransport !== undefined) {
73
- targetTransport.emit('message', msg)
74
- }
75
- })
76
- this.transports.push(transport)
77
- return transport
78
- }
79
- }
@@ -1,71 +0,0 @@
1
- import { areEqualBinaries } from '@streamr/utils'
2
- import { printExpected, printReceived } from 'jest-matcher-utils'
3
- import { isEqual } from 'lodash'
4
- import { ConnectivityMethod, NodeType, PeerDescriptor } from '../../generated/packages/dht/protos/DhtRpc'
5
- import { toDhtAddress } from '../../src/identifiers'
6
-
7
- // we could ES2015 module syntax (https://jestjs.io/docs/expect#expectextendmatchers),
8
- // but the IDE doesn't find custom matchers if we do that
9
- declare global {
10
- // eslint-disable-next-line @typescript-eslint/no-namespace
11
- namespace jest {
12
- interface Matchers<R> {
13
- toEqualPeerDescriptor(expected: PeerDescriptor): R
14
- }
15
- }
16
- }
17
-
18
- const formErrorMessage = (field: keyof PeerDescriptor, expected: string | number | undefined, actual: string | number | undefined): string => {
19
- return `PeerDescriptor ${field} values don't match:\nExpected: ${printExpected(expected)}\nReceived: ${printReceived(actual)}`
20
- }
21
-
22
- const toEqualPeerDescriptor = (
23
- actual: PeerDescriptor,
24
- expected: PeerDescriptor
25
- ): jest.CustomMatcherResult => {
26
- const messages: string[] = []
27
- if (!areEqualBinaries(expected.nodeId, actual.nodeId)) {
28
- messages.push(formErrorMessage('nodeId', toDhtAddress(expected.nodeId), toDhtAddress(actual.nodeId)))
29
- }
30
- if (!isEqual(expected.type, actual.type)) {
31
- const typeNames = { [NodeType.NODEJS]: 'NODEJS', [NodeType.BROWSER]: 'BROWSER' }
32
- messages.push(formErrorMessage('type', typeNames[expected.type], typeNames[actual.type]))
33
- }
34
- expectEqualConnectivityMethod('udp', expected.udp, actual.udp, messages)
35
- expectEqualConnectivityMethod('tcp', expected.tcp, actual.tcp, messages)
36
- expectEqualConnectivityMethod('websocket', expected.websocket, actual.websocket, messages)
37
- if (expected.region !== actual.region) {
38
- messages.push(formErrorMessage('region', expected?.region, actual?.region))
39
- }
40
- if (messages.length > 0) {
41
- return {
42
- pass: false,
43
- message: () => messages.join('\n\n')
44
- }
45
- } else {
46
- return {
47
- pass: true,
48
- message: () => 'PeerDescriptors are equal'
49
- }
50
- }
51
- }
52
-
53
- const expectEqualConnectivityMethod = (
54
- field: keyof PeerDescriptor,
55
- method1: ConnectivityMethod | undefined,
56
- method2: ConnectivityMethod | undefined,
57
- messages: string[]
58
- ) => {
59
- const toOutput = (method?: ConnectivityMethod) => {
60
- return (method !== undefined)
61
- ? `{port: ${method.port}, host: '${method.host}', tls: ${method.tls}}`
62
- : undefined
63
- }
64
- if (!isEqual(method1, method2)) {
65
- messages.push(formErrorMessage(field, toOutput(method1), toOutput(method2)))
66
- }
67
- }
68
-
69
- expect.extend({
70
- toEqualPeerDescriptor
71
- })
@@ -1,26 +0,0 @@
1
- import EventEmitter from 'eventemitter3'
2
- import { ConnectionEvents, IConnection } from '../../../src/connection/IConnection'
3
-
4
- export class MockConnection extends EventEmitter<ConnectionEvents> implements IConnection {
5
-
6
- public sentData: Uint8Array[] = []
7
-
8
- send(data: Uint8Array): Promise<void> {
9
- this.sentData.push(data)
10
- return Promise.resolve()
11
- }
12
-
13
- close(graceful: boolean): Promise<void> {
14
- this.emit('disconnected', graceful)
15
- return Promise.resolve()
16
- }
17
-
18
- destroy(): void {
19
- this.removeAllListeners()
20
- }
21
-
22
- emitData(message: Uint8Array): void {
23
- this.emit('data', message)
24
- }
25
-
26
- }
@@ -1,18 +0,0 @@
1
- import { PeerDescriptor } from '../../../generated/packages/dht/protos/DhtRpc'
2
-
3
- export class MockConnectionsView {
4
- // eslint-disable-next-line class-methods-use-this
5
- getConnections(): PeerDescriptor[] {
6
- return []
7
- }
8
-
9
- // eslint-disable-next-line class-methods-use-this
10
- getConnectionCount(): number {
11
- return 0
12
- }
13
-
14
- // eslint-disable-next-line class-methods-use-this
15
- hasConnection(): boolean {
16
- return false
17
- }
18
- }
@@ -1,62 +0,0 @@
1
- import { Methods } from '@streamr/test-utils'
2
- import { Router } from '../../../src/dht/routing/Router'
3
- import { RouteMessageAck } from '../../../generated/packages/dht/protos/DhtRpc'
4
-
5
- export class MockRouter implements Methods<Router> {
6
-
7
- // eslint-disable-next-line class-methods-use-this
8
- addRoutingSession(): void {
9
- }
10
-
11
- // eslint-disable-next-line class-methods-use-this
12
- removeRoutingSession(): void {
13
- }
14
-
15
- // eslint-disable-next-line class-methods-use-this
16
- addToDuplicateDetector(): void {
17
- }
18
-
19
- // eslint-disable-next-line class-methods-use-this
20
- isMostLikelyDuplicate(): boolean {
21
- return false
22
- }
23
-
24
- // eslint-disable-next-line class-methods-use-this
25
- doRouteMessage(): RouteMessageAck {
26
- return RouteMessageAck.create()
27
- }
28
-
29
- // eslint-disable-next-line class-methods-use-this
30
- send(): Promise<void> {
31
- throw new Error('Not implemented')
32
- }
33
-
34
- // eslint-disable-next-line class-methods-use-this
35
- stop(): void {
36
-
37
- }
38
-
39
- // eslint-disable-next-line class-methods-use-this
40
- async routeMessage(): Promise<RouteMessageAck> {
41
- return RouteMessageAck.create()
42
- }
43
-
44
- // eslint-disable-next-line class-methods-use-this
45
- async forwardMessage(): Promise<RouteMessageAck> {
46
- return RouteMessageAck.create()
47
- }
48
-
49
- // eslint-disable-next-line class-methods-use-this
50
- onNodeConnected(): void {}
51
-
52
- // eslint-disable-next-line class-methods-use-this
53
- onNodeDisconnected(): void {}
54
-
55
- // eslint-disable-next-line class-methods-use-this
56
- resetCache(): void {}
57
-
58
- // eslint-disable-next-line class-methods-use-this
59
- getDiagnosticInfo(): Record<string, unknown> {
60
- return {}
61
- }
62
- }
@@ -1,7 +0,0 @@
1
- import { RoutingRpcCommunicator } from '../../../src/transport/RoutingRpcCommunicator'
2
-
3
- export class MockRpcCommunicator extends RoutingRpcCommunicator {
4
- constructor() {
5
- super('mock-service', async () => {})
6
- }
7
- }
@@ -1,26 +0,0 @@
1
- import { ITransport, TransportEvents } from '../../../src/transport/ITransport'
2
- import { EventEmitter } from 'eventemitter3'
3
- import { PeerDescriptor } from '../../../generated/packages/dht/protos/DhtRpc'
4
-
5
- export class MockTransport extends EventEmitter<TransportEvents> implements ITransport {
6
-
7
- // eslint-disable-next-line class-methods-use-this
8
- async send(): Promise<void> {
9
-
10
- }
11
-
12
- // eslint-disable-next-line class-methods-use-this
13
- getLocalPeerDescriptor(): PeerDescriptor {
14
- return PeerDescriptor.create()
15
- }
16
-
17
- // eslint-disable-next-line class-methods-use-this
18
- stop(): void {
19
-
20
- }
21
-
22
- // eslint-disable-next-line class-methods-use-this
23
- getDiagnosticInfo(): Record<string, unknown> {
24
- return {}
25
- }
26
- }
@@ -1,38 +0,0 @@
1
- import { MessageType as MessageType$, ScalarType } from '@protobuf-ts/runtime'
2
- import { randomString } from '@streamr/utils'
3
- import { Timestamp } from '../../../generated/google/protobuf/timestamp'
4
- import { Any } from '../../../generated/google/protobuf/any'
5
- import { DataEntry } from '../../../generated/packages/dht/protos/DhtRpc'
6
- import { DhtAddress, randomDhtAddress, toDhtAddressRaw } from '../../../src/identifiers'
7
- import { omit } from 'lodash'
8
-
9
- const MockData = new class extends MessageType$<{ foo: string }> {
10
- constructor() {
11
- super('MockData', [
12
- { no: 1, name: 'foo', kind: 'scalar', opt: false, T: ScalarType.STRING }
13
- ])
14
- }
15
- }
16
-
17
- export const createMockDataEntry = (
18
- entry: Partial<Omit<DataEntry, 'key' | 'creator'> & { key: DhtAddress, creator: DhtAddress }> = {}
19
- ): DataEntry => {
20
- return {
21
- key: toDhtAddressRaw(entry.key ?? randomDhtAddress()),
22
- data: Any.pack({ foo: randomString(5) }, MockData),
23
- creator: toDhtAddressRaw(entry.creator ?? randomDhtAddress()),
24
- ttl: 10000,
25
- stale: false,
26
- deleted: false,
27
- createdAt: Timestamp.now(),
28
- ...omit(entry, 'key', 'creator')
29
- }
30
- }
31
-
32
- export const unpackData = (entry: DataEntry): { foo: string } => {
33
- return Any.unpack(entry.data!, MockData)
34
- }
35
-
36
- export const expectEqualData = (entry1: DataEntry, entry2: DataEntry): void => {
37
- expect(unpackData(entry1).foo).toBe(unpackData(entry2).foo)
38
- }
@@ -1,79 +0,0 @@
1
- import { Multimap } from '@streamr/utils'
2
- import { DhtAddress, randomDhtAddress, toDhtAddressRaw } from '../../src/identifiers'
3
- import { minBy, range, without } from 'lodash'
4
- import { SortedContactList } from '../../src/dht/contact/SortedContactList'
5
- import { getDistance } from '../../src/dht/PeerManager'
6
-
7
- export const getTopologyPartitions = (topology: Multimap<DhtAddress, DhtAddress>): Set<DhtAddress>[] => {
8
- let partitions: Set<DhtAddress>[] = []
9
- for (const nodeId of topology.keys()) {
10
- const neighbors = topology.get(nodeId)
11
- const existingPartition = partitions.find((partition) => partition.has(nodeId))
12
- if (existingPartition !== undefined) {
13
- for (const neighbor of neighbors) {
14
- if (!existingPartition.has(neighbor)) {
15
- const otherPartition = partitions.find((partition) => partition.has(neighbor))
16
- if (otherPartition !== undefined) {
17
- for (const otherNode of otherPartition) {
18
- existingPartition.add(otherNode)
19
- }
20
- partitions = without(partitions, otherPartition)
21
- } else {
22
- existingPartition.add(neighbor)
23
- }
24
- }
25
- }
26
- } else {
27
- const partition = new Set([nodeId, ...neighbors])
28
- partitions.push(partition)
29
- }
30
- }
31
- return partitions
32
- }
33
-
34
- const getClosestNodes = (referenceId: DhtAddress, nodeIds: DhtAddress[], count: number, allowToContainReferenceId: boolean): DhtAddress[] => {
35
- const list = new SortedContactList({
36
- referenceId,
37
- allowToContainReferenceId,
38
- maxSize: count
39
- })
40
- list.addContacts(nodeIds.map((n) => ({ getNodeId: () => n })))
41
- return list.getClosestContacts().map((c) => c.getNodeId())
42
- }
43
-
44
- /*
45
- * There are no network splits, and each node has only neighbors which are globally closest
46
- * to the node's ID.
47
- */
48
- export const createTestTopology = (nodeCount: number, minNeighorCount: number): Multimap<DhtAddress, DhtAddress> => {
49
- const topology: Multimap<DhtAddress, DhtAddress> = new Multimap()
50
- const nodeIds = range(nodeCount).map(() => randomDhtAddress())
51
- for (const nodeId of nodeIds) {
52
- const closestNodes = getClosestNodes(nodeId, nodeIds, minNeighorCount, false)
53
- for (const closestNode of closestNodes) {
54
- if (!topology.has(nodeId, closestNode)) {
55
- topology.add(nodeId, closestNode)
56
- }
57
- if (!topology.has(closestNode, nodeId)) {
58
- topology.add(closestNode, nodeId)
59
- }
60
- }
61
- }
62
- while (true) {
63
- const partitions = getTopologyPartitions(topology)
64
- if (partitions.length === 1) {
65
- break
66
- } else {
67
- const closestPairs = nodeIds.map((nodeId: DhtAddress) => {
68
- const ownPartition = partitions.find((partition) => partition.has(nodeId))!
69
- const otherNodes = without(nodeIds, ...[...ownPartition])
70
- const closestNodedId = getClosestNodes(nodeId, otherNodes, 1, false)[0]
71
- return [nodeId, closestNodedId]
72
- })
73
- const mergePair = minBy(closestPairs, (pair) => getDistance(toDhtAddressRaw(pair[0]), toDhtAddressRaw(pair[1])))!
74
- topology.add(mergePair[0], mergePair[1])
75
- topology.add(mergePair[1], mergePair[0])
76
- }
77
- }
78
- return topology
79
- }
@@ -1,268 +0,0 @@
1
- import { DhtNode } from '../../src/dht/DhtNode'
2
- import {
3
- ClosestPeersRequest,
4
- ClosestPeersResponse,
5
- NodeType,
6
- PeerDescriptor,
7
- PingRequest,
8
- PingResponse,
9
- RouteMessageAck,
10
- RouteMessageWrapper,
11
- StoreDataRequest,
12
- StoreDataResponse,
13
- ClosestRingPeersResponse
14
- } from '../../generated/packages/dht/protos/DhtRpc'
15
- import { RpcMessage } from '../../generated/packages/proto-rpc/protos/ProtoRpc'
16
- import {
17
- IDhtNodeRpc,
18
- IRouterRpc,
19
- IStoreRpc,
20
- IWebsocketClientConnectorRpc
21
- } from '../../generated/packages/dht/protos/DhtRpc.server'
22
- import { Simulator } from '../../src/connection/simulator/Simulator'
23
- import { ConnectionManager } from '../../src/connection/ConnectionManager'
24
- import { v4 } from 'uuid'
25
- import { getRandomRegion } from '../../src/connection/simulator/pings'
26
- import { Empty } from '../../generated/google/protobuf/empty'
27
- import { Any } from '../../generated/google/protobuf/any'
28
- import { wait, until } from '@streamr/utils'
29
- import { SimulatorTransport } from '../../src/connection/simulator/SimulatorTransport'
30
- import { DhtAddress, randomDhtAddress, toDhtAddressRaw } from '../../src/identifiers'
31
-
32
- export const createMockPeerDescriptor = (opts?: Partial<Omit<PeerDescriptor, 'nodeId'>>): PeerDescriptor => {
33
- return {
34
- nodeId: toDhtAddressRaw(randomDhtAddress()),
35
- type: NodeType.NODEJS,
36
- ...opts
37
- }
38
- }
39
-
40
- export const createMockRingNode = async (
41
- simulator: Simulator,
42
- nodeId: DhtAddress,
43
- region: number
44
- ): Promise<DhtNode> => {
45
- const maxConnections = 80
46
- const dhtJoinTimeout = 45000
47
-
48
- const peerDescriptor: PeerDescriptor = {
49
- nodeId: toDhtAddressRaw(nodeId ?? randomDhtAddress()),
50
- type: NodeType.NODEJS,
51
- region
52
- //ipAddress: ipv4ToNumber(ipAddress)
53
- }
54
- const mockConnectionManager = new SimulatorTransport(peerDescriptor, simulator)
55
- await mockConnectionManager.start()
56
- const opts = {
57
- peerDescriptor: peerDescriptor,
58
- transport: mockConnectionManager,
59
- connectionLocker: mockConnectionManager,
60
- numberOfNodesPerKBucket: 8,
61
- maxConnections: maxConnections,
62
- dhtJoinTimeout,
63
- rpcRequestTimeout: 5000
64
- }
65
- const node = new class extends DhtNode {
66
- async stop(): Promise<void> {
67
- await super.stop()
68
- await mockConnectionManager.stop()
69
- }
70
- }(opts)
71
- await node.start()
72
- return node
73
- }
74
-
75
- export const createMockConnectionDhtNode = async (
76
- simulator: Simulator,
77
- nodeId?: DhtAddress,
78
- numberOfNodesPerKBucket?: number,
79
- maxConnections = 80,
80
- dhtJoinTimeout = 45000
81
- ): Promise<DhtNode> => {
82
- const peerDescriptor: PeerDescriptor = {
83
- nodeId: toDhtAddressRaw(nodeId ?? randomDhtAddress()),
84
- type: NodeType.NODEJS,
85
- region: getRandomRegion()
86
- }
87
- const mockConnectionManager = new SimulatorTransport(peerDescriptor, simulator)
88
- await mockConnectionManager.start()
89
- const opts = {
90
- peerDescriptor: peerDescriptor,
91
- transport: mockConnectionManager,
92
- connectionsView: mockConnectionManager,
93
- connectionLocker: mockConnectionManager,
94
- numberOfNodesPerKBucket,
95
- maxConnections: maxConnections,
96
- dhtJoinTimeout,
97
- rpcRequestTimeout: 5000
98
- }
99
- const node = new class extends DhtNode {
100
- async stop(): Promise<void> {
101
- await super.stop()
102
- await mockConnectionManager.stop()
103
- }
104
- }(opts)
105
- await node.start()
106
- return node
107
- }
108
-
109
- export const createMockConnectionLayer1Node = async (
110
- layer0Node: DhtNode,
111
- serviceId?: string,
112
- numberOfNodesPerKBucket = 8
113
- ): Promise<DhtNode> => {
114
- const descriptor: PeerDescriptor = {
115
- nodeId: layer0Node.getLocalPeerDescriptor().nodeId,
116
- type: NodeType.NODEJS,
117
- }
118
- const node = new DhtNode({
119
- peerDescriptor: descriptor,
120
- transport: layer0Node,
121
- connectionsView: layer0Node.getConnectionsView(),
122
- serviceId: serviceId ? serviceId : 'layer1', numberOfNodesPerKBucket,
123
- rpcRequestTimeout: 10000
124
- })
125
- await node.start()
126
- return node
127
- }
128
-
129
- export const createWrappedClosestPeersRequest = (
130
- sourceDescriptor: PeerDescriptor
131
- ): RpcMessage => {
132
-
133
- const routedMessage: ClosestPeersRequest = {
134
- nodeId: sourceDescriptor.nodeId,
135
- requestId: v4()
136
- }
137
- const rpcWrapper: RpcMessage = {
138
- body: Any.pack(routedMessage, ClosestPeersRequest),
139
- header: {
140
- method: 'closestPeersRequest',
141
- request: 'request'
142
- },
143
- requestId: v4()
144
- }
145
- return rpcWrapper
146
- }
147
-
148
- interface IDhtRpcWithError extends IDhtNodeRpc {
149
- throwPingError: (request: PingRequest) => Promise<PingResponse>
150
- respondPingWithTimeout: (request: PingRequest) => Promise<PingResponse>
151
- throwGetClosestPeersError: (request: ClosestPeersRequest) => Promise<ClosestPeersResponse>
152
- }
153
-
154
- export const createMockDhtRpc = (neighbors: PeerDescriptor[]): IDhtRpcWithError => {
155
- return {
156
- async getClosestPeers(): Promise<ClosestPeersResponse> {
157
- const response: ClosestPeersResponse = {
158
- peers: neighbors,
159
- requestId: 'why am i still here'
160
- }
161
- return response
162
- },
163
- async getClosestRingPeers(): Promise<ClosestRingPeersResponse> {
164
- const response: ClosestRingPeersResponse = {
165
- leftPeers: neighbors,
166
- rightPeers: neighbors,
167
- requestId: 'why am i still here'
168
- }
169
- return response
170
- },
171
- async ping(request: PingRequest): Promise<PingResponse> {
172
- const response: PingResponse = {
173
- requestId: request.requestId
174
- }
175
- return response
176
- },
177
- async leaveNotice(): Promise<Empty> {
178
- return {}
179
- },
180
- async throwPingError(): Promise<PingResponse> {
181
- throw new Error()
182
- },
183
- async respondPingWithTimeout(request: PingRequest): Promise<PingResponse> {
184
- const response: PingResponse = {
185
- requestId: request.requestId
186
- }
187
- await wait(2000)
188
- return response
189
- },
190
- async throwGetClosestPeersError(): Promise<ClosestPeersResponse> {
191
- throw new Error('Closest peers error')
192
- }
193
- }
194
- }
195
-
196
- interface IRouterRpcWithError extends IRouterRpc {
197
- throwRouteMessageError: (request: RouteMessageWrapper) => Promise<RouteMessageAck>
198
- }
199
-
200
- export const mockRouterRpc: IRouterRpcWithError = {
201
- async routeMessage(routed: RouteMessageWrapper): Promise<RouteMessageAck> {
202
- const response: RouteMessageAck = {
203
- requestId: routed.requestId
204
- }
205
- return response
206
- },
207
- async forwardMessage(routed: RouteMessageWrapper): Promise<RouteMessageAck> {
208
- const response: RouteMessageAck = {
209
- requestId: routed.requestId
210
- }
211
- return response
212
- },
213
- async throwRouteMessageError(): Promise<RouteMessageAck> {
214
- throw new Error()
215
- }
216
- }
217
-
218
- interface IStoreRpcWithError extends IStoreRpc {
219
- throwStoreDataError: (request: StoreDataRequest) => Promise<StoreDataResponse>
220
- }
221
-
222
- export const mockStoreRpc: IStoreRpcWithError = {
223
- async storeData(): Promise<StoreDataResponse> {
224
- return {}
225
- },
226
- async throwStoreDataError(): Promise<StoreDataResponse> {
227
- throw new Error('Mock')
228
- },
229
- async replicateData(): Promise<Empty> {
230
- return {}
231
- }
232
- }
233
-
234
- export const mockWebsocketClientConnectorRpc: IWebsocketClientConnectorRpc = {
235
- async requestConnection(): Promise<Empty> {
236
- return {}
237
- }
238
- }
239
-
240
- export const createMockPeers = (): PeerDescriptor[] => {
241
- const n1 = createMockPeerDescriptor()
242
- const n2 = createMockPeerDescriptor()
243
- const n3 = createMockPeerDescriptor()
244
- const n4 = createMockPeerDescriptor()
245
- return [
246
- n1, n2, n3, n4
247
- ]
248
- }
249
-
250
- /*
251
- * When we start multiple nodes, most of the nodes have unlocked connections. This promise will resolve when some of those
252
- * unlocked connections have been garbage collected, i.e. we typically have connections only to the nodes which
253
- * are neighbors.
254
- */
255
- export const waitForStableTopology = async (nodes: DhtNode[], maxConnectionCount: number = 10000, waitTime = 20000): Promise<void> => {
256
- const MAX_IDLE_TIME = 100
257
- const connectionManagers = nodes.map((n) => n.getTransport() as ConnectionManager)
258
- await Promise.all(connectionManagers.map(async (connectionManager) => {
259
- connectionManager.garbageCollectConnections(maxConnectionCount, MAX_IDLE_TIME)
260
- try {
261
- await until(() => connectionManager.getConnections().length <= maxConnectionCount, waitTime)
262
- } catch {
263
- // the topology is very likely stable, but we can't be sure (maybe the node has more than maxConnectionCount
264
- // locked connections and therefore it is ok to that garbage collector was not able to remove any of those
265
- // connections
266
- }
267
- }))
268
- }