@streamr/dht 0.0.1-tatum.5 → 0.0.1-tatum.7
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.
- package/dist/src/connection/ConnectionLockHandler.d.ts +1 -1
- package/dist/src/connection/ConnectionLockHandler.js.map +1 -1
- package/dist/src/connection/ConnectionManager.d.ts +17 -39
- package/dist/src/connection/ConnectionManager.js +138 -192
- package/dist/src/connection/ConnectionManager.js.map +1 -1
- package/dist/src/connection/ConnectivityChecker.js +14 -11
- package/dist/src/connection/ConnectivityChecker.js.map +1 -1
- package/dist/src/connection/ConnectorFacade.d.ts +49 -0
- package/dist/src/connection/ConnectorFacade.js +86 -0
- package/dist/src/connection/ConnectorFacade.js.map +1 -0
- package/dist/src/connection/ManagedConnection.d.ts +1 -4
- package/dist/src/connection/ManagedConnection.js +23 -31
- package/dist/src/connection/ManagedConnection.js.map +1 -1
- package/dist/src/connection/RemoteConnectionLocker.js +4 -3
- package/dist/src/connection/RemoteConnectionLocker.js.map +1 -1
- package/dist/src/connection/Simulator/Simulator.d.ts +0 -2
- package/dist/src/connection/Simulator/Simulator.js +0 -5
- package/dist/src/connection/Simulator/Simulator.js.map +1 -1
- package/dist/src/connection/Simulator/SimulatorConnection.js +16 -13
- package/dist/src/connection/Simulator/SimulatorConnection.js.map +1 -1
- package/dist/src/connection/Simulator/SimulatorConnector.d.ts +2 -2
- package/dist/src/connection/Simulator/SimulatorConnector.js +10 -11
- package/dist/src/connection/Simulator/SimulatorConnector.js.map +1 -1
- package/dist/src/connection/Simulator/SimulatorTransport.js +6 -1
- package/dist/src/connection/Simulator/SimulatorTransport.js.map +1 -1
- package/dist/src/connection/WebRTC/NodeWebRtcConnection.d.ts +2 -0
- package/dist/src/connection/WebRTC/NodeWebRtcConnection.js +12 -12
- package/dist/src/connection/WebRTC/NodeWebRtcConnection.js.map +1 -1
- package/dist/src/connection/WebRTC/WebRtcConnector.d.ts +9 -9
- package/dist/src/connection/WebRTC/WebRtcConnector.js +22 -22
- package/dist/src/connection/WebRTC/WebRtcConnector.js.map +1 -1
- package/dist/src/connection/WebSocket/RemoteWebSocketConnector.js +2 -1
- package/dist/src/connection/WebSocket/RemoteWebSocketConnector.js.map +1 -1
- package/dist/src/connection/WebSocket/WebSocketConnector.d.ts +19 -8
- package/dist/src/connection/WebSocket/WebSocketConnector.js +67 -46
- package/dist/src/connection/WebSocket/WebSocketConnector.js.map +1 -1
- package/dist/src/connection/WebSocket/WebSocketServer.d.ts +11 -1
- package/dist/src/connection/WebSocket/WebSocketServer.js +15 -10
- package/dist/src/connection/WebSocket/WebSocketServer.js.map +1 -1
- package/dist/src/dht/DhtNode.d.ts +16 -54
- package/dist/src/dht/DhtNode.js +116 -137
- package/dist/src/dht/DhtNode.js.map +1 -1
- package/dist/src/dht/{DhtPeer.d.ts → RemoteDhtNode.d.ts} +3 -2
- package/dist/src/dht/{DhtPeer.js → RemoteDhtNode.js} +22 -16
- package/dist/src/dht/RemoteDhtNode.js.map +1 -0
- package/dist/src/dht/contact/Contact.d.ts +1 -15
- package/dist/src/dht/contact/Contact.js +1 -9
- package/dist/src/dht/contact/Contact.js.map +1 -1
- package/dist/src/dht/contact/ContactList.d.ts +13 -3
- package/dist/src/dht/contact/ContactList.js +9 -4
- package/dist/src/dht/contact/ContactList.js.map +1 -1
- package/dist/src/dht/contact/RandomContactList.d.ts +3 -3
- package/dist/src/dht/contact/RandomContactList.js +4 -8
- package/dist/src/dht/contact/RandomContactList.js.map +1 -1
- package/dist/src/dht/contact/Remote.d.ts +1 -5
- package/dist/src/dht/contact/Remote.js +0 -5
- package/dist/src/dht/contact/Remote.js.map +1 -1
- package/dist/src/dht/contact/SortedContactList.d.ts +3 -5
- package/dist/src/dht/contact/SortedContactList.js +9 -19
- package/dist/src/dht/contact/SortedContactList.js.map +1 -1
- package/dist/src/dht/discovery/DiscoverySession.d.ts +5 -7
- package/dist/src/dht/discovery/DiscoverySession.js +9 -10
- package/dist/src/dht/discovery/DiscoverySession.js.map +1 -1
- package/dist/src/dht/discovery/PeerDiscovery.d.ts +11 -10
- package/dist/src/dht/discovery/PeerDiscovery.js +32 -37
- package/dist/src/dht/discovery/PeerDiscovery.js.map +1 -1
- package/dist/src/dht/find/RecursiveFindSession.d.ts +5 -6
- package/dist/src/dht/find/RecursiveFindSession.js +8 -8
- package/dist/src/dht/find/RecursiveFindSession.js.map +1 -1
- package/dist/src/dht/find/RecursiveFinder.d.ts +2 -4
- package/dist/src/dht/find/RecursiveFinder.js +11 -12
- package/dist/src/dht/find/RecursiveFinder.js.map +1 -1
- package/dist/src/dht/registerExternalApiRpcMethods.d.ts +1 -1
- package/dist/src/dht/routing/DuplicateDetector.d.ts +1 -2
- package/dist/src/dht/routing/DuplicateDetector.js +2 -7
- package/dist/src/dht/routing/DuplicateDetector.js.map +1 -1
- package/dist/src/dht/routing/RemoteRouter.js +4 -4
- package/dist/src/dht/routing/RemoteRouter.js.map +1 -1
- package/dist/src/dht/routing/Router.d.ts +10 -13
- package/dist/src/dht/routing/Router.js +28 -29
- package/dist/src/dht/routing/Router.js.map +1 -1
- package/dist/src/dht/routing/RoutingSession.d.ts +3 -5
- package/dist/src/dht/routing/RoutingSession.js +19 -13
- package/dist/src/dht/routing/RoutingSession.js.map +1 -1
- package/dist/src/dht/store/DataStore.d.ts +2 -2
- package/dist/src/dht/store/DataStore.js +7 -7
- package/dist/src/dht/store/DataStore.js.map +1 -1
- package/dist/src/exports.d.ts +1 -8
- package/dist/src/exports.js +2 -16
- package/dist/src/exports.js.map +1 -1
- package/dist/src/helpers/PeerID.d.ts +0 -1
- package/dist/src/helpers/PeerID.js +0 -6
- package/dist/src/helpers/PeerID.js.map +1 -1
- package/dist/src/helpers/browser/isBrowserEnvironment.d.ts +1 -0
- package/dist/src/helpers/browser/isBrowserEnvironment.js +6 -0
- package/dist/src/helpers/browser/isBrowserEnvironment.js.map +1 -0
- package/dist/src/helpers/browser/isBrowserEnvironment_override.d.ts +1 -0
- package/dist/src/helpers/browser/isBrowserEnvironment_override.js +7 -0
- package/dist/src/helpers/browser/isBrowserEnvironment_override.js.map +1 -0
- package/dist/src/helpers/kademliaId.d.ts +1 -0
- package/dist/src/helpers/kademliaId.js +14 -0
- package/dist/src/helpers/kademliaId.js.map +1 -0
- package/dist/src/helpers/peerIdFromPeerDescriptor.d.ts +1 -1
- package/dist/src/helpers/peerIdFromPeerDescriptor.js +3 -3
- package/dist/src/helpers/peerIdFromPeerDescriptor.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.d.ts +0 -4
- package/dist/src/proto/packages/dht/protos/DhtRpc.js +1 -2
- package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +1 -1
- package/package.json +10 -9
- package/protos/DhtRpc.proto +0 -1
- package/src/connection/ConnectionLockHandler.ts +1 -1
- package/src/connection/ConnectionManager.ts +156 -240
- package/src/connection/ConnectivityChecker.ts +14 -11
- package/src/connection/ConnectorFacade.ts +143 -0
- package/src/connection/ManagedConnection.ts +23 -34
- package/src/connection/RemoteConnectionLocker.ts +4 -3
- package/src/connection/Simulator/Simulator.ts +0 -7
- package/src/connection/Simulator/SimulatorConnection.ts +16 -13
- package/src/connection/Simulator/SimulatorConnector.ts +11 -12
- package/src/connection/Simulator/SimulatorTransport.ts +6 -1
- package/src/connection/WebRTC/NodeWebRtcConnection.ts +14 -13
- package/src/connection/WebRTC/WebRtcConnector.ts +31 -31
- package/src/connection/WebSocket/RemoteWebSocketConnector.ts +2 -1
- package/src/connection/WebSocket/WebSocketConnector.ts +85 -62
- package/src/connection/WebSocket/WebSocketServer.ts +26 -8
- package/src/dht/DhtNode.ts +164 -189
- package/src/dht/{DhtPeer.ts → RemoteDhtNode.ts} +14 -7
- package/src/dht/contact/Contact.ts +1 -18
- package/src/dht/contact/ContactList.ts +16 -6
- package/src/dht/contact/RandomContactList.ts +6 -11
- package/src/dht/contact/Remote.ts +1 -10
- package/src/dht/contact/SortedContactList.ts +12 -25
- package/src/dht/discovery/DiscoverySession.ts +20 -23
- package/src/dht/discovery/PeerDiscovery.ts +45 -44
- package/src/dht/find/RecursiveFindSession.ts +12 -13
- package/src/dht/find/RecursiveFinder.ts +16 -19
- package/src/dht/registerExternalApiRpcMethods.ts +1 -1
- package/src/dht/routing/DuplicateDetector.ts +3 -10
- package/src/dht/routing/RemoteRouter.ts +5 -5
- package/src/dht/routing/Router.ts +35 -39
- package/src/dht/routing/RoutingSession.ts +37 -28
- package/src/dht/store/DataStore.ts +11 -11
- package/src/exports.ts +1 -8
- package/src/helpers/PeerID.ts +0 -7
- package/src/helpers/browser/isBrowserEnvironment.ts +1 -0
- package/src/helpers/browser/isBrowserEnvironment_override.ts +3 -0
- package/src/helpers/kademliaId.ts +8 -0
- package/src/helpers/peerIdFromPeerDescriptor.ts +1 -1
- package/src/proto/packages/dht/protos/DhtRpc.ts +1 -6
- package/test/benchmark/KademliaCorrectness.test.ts +5 -2
- package/test/benchmark/RecursiveFind.test.ts +6 -6
- package/test/end-to-end/Layer0-Layer1.test.ts +14 -14
- package/test/end-to-end/Layer0WebRTC-Layer1.test.ts +5 -5
- package/test/end-to-end/Layer0WebRTC.test.ts +5 -6
- package/test/end-to-end/Layer1-Scale-WebRTC.test.ts +13 -8
- package/test/end-to-end/Layer1-Scale-WebSocket.test.ts +15 -10
- package/test/end-to-end/WebSocketConnectionRequest.test.ts +5 -5
- package/test/integration/ConnectionLocking.test.ts +32 -26
- package/test/integration/ConnectionManager.test.ts +90 -93
- package/test/integration/DhtJoinPeerDiscovery.test.ts +53 -0
- package/test/integration/DhtRpc.test.ts +4 -6
- package/test/integration/Layer1-scale.test.ts +8 -8
- package/test/integration/MigrateData.test.ts +9 -9
- package/test/integration/Mock-Layer1-Layer0.test.ts +1 -2
- package/test/integration/RecursiveFind.test.ts +5 -5
- package/test/integration/{DhtPeer.test.ts → RemoteDhtNode.test.ts} +11 -12
- package/test/integration/RemoteRouter.test.ts +5 -6
- package/test/integration/RemoteStore.test.ts +4 -5
- package/test/integration/RouteMessage.test.ts +7 -9
- package/test/integration/RpcErrors.test.ts +25 -10
- package/test/integration/ScaleDownDht.test.ts +8 -8
- package/test/integration/SimultaneousConnections.test.ts +35 -36
- package/test/integration/Store.test.ts +8 -9
- package/test/integration/StoreAndDelete.test.ts +11 -11
- package/test/integration/StoreOnDhtWithTwoNodes.test.ts +7 -7
- package/test/integration/WebRtcConnectionManagement.test.ts +26 -19
- package/test/integration/WebRtcConnectorRpc.test.ts +6 -8
- package/test/integration/WebSocket.test.ts +4 -2
- package/test/integration/WebSocketConnectionManagement.test.ts +30 -17
- package/test/integration/WebSocketConnectorRpc.test.ts +2 -3
- package/test/unit/DuplicateDetector.test.ts +3 -4
- package/test/unit/LocalDataStore.test.ts +6 -8
- package/test/unit/RandomContactList.test.ts +25 -74
- package/test/unit/RecursiveFinder.test.ts +8 -12
- package/test/unit/Router.test.ts +18 -21
- package/test/unit/SortedContactList.test.ts +62 -112
- package/test/unit/WebSocketConnector.test.ts +64 -0
- package/test/unit/WebSocketServer.test.ts +24 -12
- package/test/utils/mock/RecursiveFinder.ts +2 -2
- package/test/utils/mock/Router.ts +9 -11
- package/test/utils/mock/Transport.ts +2 -2
- package/test/utils/utils.ts +40 -49
- package/dist/src/dht/DhtPeer.js.map +0 -1
- package/dist/src/helpers/browser/isBrowser.d.ts +0 -1
- package/dist/src/helpers/browser/isBrowser.js +0 -6
- package/dist/src/helpers/browser/isBrowser.js.map +0 -1
- package/dist/src/helpers/browser/isNodeJS.d.ts +0 -1
- package/dist/src/helpers/browser/isNodeJS.js +0 -6
- package/dist/src/helpers/browser/isNodeJS.js.map +0 -1
- package/src/helpers/browser/isBrowser.ts +0 -1
- package/src/helpers/browser/isNodeJS.ts +0 -1
- package/test/integration/DhtWithMockConnectionLatencies.test.ts +0 -46
- package/test/integration/DhtWithMockConnections.test.ts +0 -46
- package/test/integration/DhtWithRealConnectionLatencies.test.ts +0 -47
- /package/test/unit/{webrtcReplaceInternalIpWithExternalIp.ts → webrtcReplaceInternalIpWithExternalIp.test.ts} +0 -0
package/test/utils/utils.ts
CHANGED
|
@@ -2,8 +2,6 @@ import { DhtNode } from '../../src/dht/DhtNode'
|
|
|
2
2
|
import {
|
|
3
3
|
ClosestPeersRequest,
|
|
4
4
|
ClosestPeersResponse,
|
|
5
|
-
LeaveNotice,
|
|
6
|
-
MigrateDataRequest,
|
|
7
5
|
MigrateDataResponse,
|
|
8
6
|
NodeType,
|
|
9
7
|
PeerDescriptor,
|
|
@@ -17,7 +15,6 @@ import {
|
|
|
17
15
|
WebSocketConnectionResponse,
|
|
18
16
|
RecursiveFindRequest,
|
|
19
17
|
FindMode,
|
|
20
|
-
DeleteDataRequest,
|
|
21
18
|
DeleteDataResponse
|
|
22
19
|
} from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
23
20
|
import { RpcMessage } from '../../src/proto/packages/proto-rpc/protos/ProtoRpc'
|
|
@@ -28,7 +25,6 @@ import {
|
|
|
28
25
|
IStoreService,
|
|
29
26
|
IWebSocketConnectorService
|
|
30
27
|
} from '../../src/proto/packages/dht/protos/DhtRpc.server'
|
|
31
|
-
import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
|
|
32
28
|
import { Simulator } from '../../src/connection/Simulator/Simulator'
|
|
33
29
|
import { ConnectionManager } from '../../src/connection/ConnectionManager'
|
|
34
30
|
import { v4 } from 'uuid'
|
|
@@ -37,20 +33,20 @@ import { Empty } from '../../src/proto/google/protobuf/empty'
|
|
|
37
33
|
import { Any } from '../../src/proto/google/protobuf/any'
|
|
38
34
|
import { wait, waitForCondition } from '@streamr/utils'
|
|
39
35
|
import { RoutingRpcCommunicator } from '../../src/transport/RoutingRpcCommunicator'
|
|
36
|
+
import { SimulatorTransport } from '../../src/connection/Simulator/SimulatorTransport'
|
|
40
37
|
|
|
41
38
|
export const generateId = (stringId: string): Uint8Array => {
|
|
42
39
|
return PeerID.fromString(stringId).value
|
|
43
40
|
}
|
|
44
41
|
|
|
45
|
-
export const createMockConnectionDhtNode = async (
|
|
42
|
+
export const createMockConnectionDhtNode = async (
|
|
43
|
+
stringId: string,
|
|
46
44
|
simulator: Simulator,
|
|
47
45
|
binaryId?: Uint8Array,
|
|
48
|
-
|
|
49
|
-
nodeName?: string,
|
|
46
|
+
numberOfNodesPerKBucket?: number,
|
|
50
47
|
maxConnections = 80,
|
|
51
48
|
dhtJoinTimeout = 45000
|
|
52
49
|
): Promise<DhtNode> => {
|
|
53
|
-
|
|
54
50
|
let id: PeerID
|
|
55
51
|
if (binaryId) {
|
|
56
52
|
id = PeerID.fromValue(binaryId)
|
|
@@ -60,47 +56,42 @@ export const createMockConnectionDhtNode = async (stringId: string,
|
|
|
60
56
|
const peerDescriptor: PeerDescriptor = {
|
|
61
57
|
kademliaId: id.value,
|
|
62
58
|
type: NodeType.NODEJS,
|
|
63
|
-
region: getRandomRegion()
|
|
64
|
-
nodeName: nodeName ? nodeName : stringId
|
|
59
|
+
region: getRandomRegion()
|
|
65
60
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
ownPeerDescriptor: peerDescriptor,
|
|
69
|
-
simulator: simulator
|
|
70
|
-
})
|
|
71
|
-
|
|
61
|
+
const mockConnectionManager = new SimulatorTransport(peerDescriptor, simulator)
|
|
62
|
+
await mockConnectionManager.start()
|
|
72
63
|
const node = new DhtNode({
|
|
73
64
|
peerDescriptor: peerDescriptor,
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
numberOfNodesPerKBucket: K ? K : 8,
|
|
65
|
+
transport: mockConnectionManager,
|
|
66
|
+
numberOfNodesPerKBucket,
|
|
77
67
|
maxConnections: maxConnections,
|
|
78
68
|
dhtJoinTimeout
|
|
79
69
|
})
|
|
80
70
|
await node.start()
|
|
81
|
-
|
|
82
71
|
return node
|
|
83
72
|
}
|
|
84
73
|
|
|
85
|
-
export const createMockConnectionLayer1Node = async (
|
|
74
|
+
export const createMockConnectionLayer1Node = async (
|
|
75
|
+
stringId: string,
|
|
76
|
+
layer0Node: DhtNode,
|
|
77
|
+
serviceId?: string,
|
|
78
|
+
numberOfNodesPerKBucket = 8
|
|
79
|
+
): Promise<DhtNode> => {
|
|
86
80
|
const id = PeerID.fromString(stringId)
|
|
87
81
|
const descriptor: PeerDescriptor = {
|
|
88
82
|
kademliaId: id.value,
|
|
89
83
|
type: NodeType.NODEJS,
|
|
90
|
-
nodeName: stringId
|
|
91
84
|
}
|
|
92
|
-
|
|
93
85
|
const node = new DhtNode({
|
|
94
|
-
peerDescriptor: descriptor,
|
|
95
|
-
serviceId: serviceId ? serviceId : 'layer1', numberOfNodesPerKBucket
|
|
86
|
+
peerDescriptor: descriptor, transport: layer0Node,
|
|
87
|
+
serviceId: serviceId ? serviceId : 'layer1', numberOfNodesPerKBucket
|
|
96
88
|
})
|
|
97
89
|
await node.start()
|
|
98
90
|
return node
|
|
99
91
|
}
|
|
100
92
|
|
|
101
93
|
export const createWrappedClosestPeersRequest = (
|
|
102
|
-
sourceDescriptor: PeerDescriptor
|
|
103
|
-
_udestinationDescriptor: PeerDescriptor
|
|
94
|
+
sourceDescriptor: PeerDescriptor
|
|
104
95
|
): RpcMessage => {
|
|
105
96
|
|
|
106
97
|
const routedMessage: ClosestPeersRequest = {
|
|
@@ -129,13 +120,13 @@ export const createRecursiveFindRequest = (
|
|
|
129
120
|
}
|
|
130
121
|
|
|
131
122
|
interface IDhtRpcWithError extends IDhtRpcService {
|
|
132
|
-
throwPingError: (request: PingRequest
|
|
133
|
-
respondPingWithTimeout: (request: PingRequest
|
|
134
|
-
throwGetClosestPeersError: (request: ClosestPeersRequest
|
|
123
|
+
throwPingError: (request: PingRequest) => Promise<PingResponse>
|
|
124
|
+
respondPingWithTimeout: (request: PingRequest) => Promise<PingResponse>
|
|
125
|
+
throwGetClosestPeersError: (request: ClosestPeersRequest) => Promise<ClosestPeersResponse>
|
|
135
126
|
}
|
|
136
127
|
|
|
137
128
|
export const MockDhtRpc: IDhtRpcWithError = {
|
|
138
|
-
async getClosestPeers(
|
|
129
|
+
async getClosestPeers(): Promise<ClosestPeersResponse> {
|
|
139
130
|
const neighbors = getMockPeers()
|
|
140
131
|
const response: ClosestPeersResponse = {
|
|
141
132
|
peers: neighbors,
|
|
@@ -143,36 +134,36 @@ export const MockDhtRpc: IDhtRpcWithError = {
|
|
|
143
134
|
}
|
|
144
135
|
return response
|
|
145
136
|
},
|
|
146
|
-
async ping(request: PingRequest
|
|
137
|
+
async ping(request: PingRequest): Promise<PingResponse> {
|
|
147
138
|
const response: PingResponse = {
|
|
148
139
|
requestId: request.requestId
|
|
149
140
|
}
|
|
150
141
|
return response
|
|
151
142
|
},
|
|
152
|
-
async leaveNotice(
|
|
143
|
+
async leaveNotice(): Promise<Empty> {
|
|
153
144
|
return {}
|
|
154
145
|
},
|
|
155
|
-
async throwPingError(
|
|
146
|
+
async throwPingError(): Promise<PingResponse> {
|
|
156
147
|
throw new Error()
|
|
157
148
|
},
|
|
158
|
-
async respondPingWithTimeout(request: PingRequest
|
|
149
|
+
async respondPingWithTimeout(request: PingRequest): Promise<PingResponse> {
|
|
159
150
|
const response: PingResponse = {
|
|
160
151
|
requestId: request.requestId
|
|
161
152
|
}
|
|
162
153
|
await wait(2000)
|
|
163
154
|
return response
|
|
164
155
|
},
|
|
165
|
-
async throwGetClosestPeersError(
|
|
156
|
+
async throwGetClosestPeersError(): Promise<ClosestPeersResponse> {
|
|
166
157
|
throw new Error('Closest peers error')
|
|
167
158
|
}
|
|
168
159
|
}
|
|
169
160
|
|
|
170
161
|
interface IRouterServiceWithError extends IRoutingService {
|
|
171
|
-
throwRouteMessageError: (request: RouteMessageWrapper
|
|
162
|
+
throwRouteMessageError: (request: RouteMessageWrapper) => Promise<RouteMessageAck>
|
|
172
163
|
}
|
|
173
164
|
|
|
174
165
|
export const MockRoutingService: IRouterServiceWithError = {
|
|
175
|
-
async routeMessage(routed: RouteMessageWrapper
|
|
166
|
+
async routeMessage(routed: RouteMessageWrapper): Promise<RouteMessageAck> {
|
|
176
167
|
const response: RouteMessageAck = {
|
|
177
168
|
requestId: routed.requestId,
|
|
178
169
|
destinationPeer: routed.sourcePeer,
|
|
@@ -181,7 +172,7 @@ export const MockRoutingService: IRouterServiceWithError = {
|
|
|
181
172
|
}
|
|
182
173
|
return response
|
|
183
174
|
},
|
|
184
|
-
async findRecursively(routed: RouteMessageWrapper
|
|
175
|
+
async findRecursively(routed: RouteMessageWrapper): Promise<RouteMessageAck> {
|
|
185
176
|
const response: RouteMessageAck = {
|
|
186
177
|
requestId: routed.requestId,
|
|
187
178
|
destinationPeer: routed.sourcePeer,
|
|
@@ -190,7 +181,7 @@ export const MockRoutingService: IRouterServiceWithError = {
|
|
|
190
181
|
}
|
|
191
182
|
return response
|
|
192
183
|
},
|
|
193
|
-
async forwardMessage(routed: RouteMessageWrapper
|
|
184
|
+
async forwardMessage(routed: RouteMessageWrapper): Promise<RouteMessageAck> {
|
|
194
185
|
const response: RouteMessageAck = {
|
|
195
186
|
requestId: routed.requestId,
|
|
196
187
|
destinationPeer: routed.sourcePeer,
|
|
@@ -199,40 +190,40 @@ export const MockRoutingService: IRouterServiceWithError = {
|
|
|
199
190
|
}
|
|
200
191
|
return response
|
|
201
192
|
},
|
|
202
|
-
async throwRouteMessageError(
|
|
193
|
+
async throwRouteMessageError(): Promise<RouteMessageAck> {
|
|
203
194
|
throw new Error()
|
|
204
195
|
}
|
|
205
196
|
}
|
|
206
197
|
|
|
207
198
|
interface IStoreServiceWithError extends IStoreService {
|
|
208
|
-
throwStoreDataError: (request: StoreDataRequest
|
|
209
|
-
storeDataErrorString: (request: StoreDataRequest
|
|
199
|
+
throwStoreDataError: (request: StoreDataRequest) => Promise<StoreDataResponse>
|
|
200
|
+
storeDataErrorString: (request: StoreDataRequest) => Promise<StoreDataResponse>
|
|
210
201
|
}
|
|
211
202
|
|
|
212
203
|
export const MockStoreService: IStoreServiceWithError = {
|
|
213
|
-
async storeData(
|
|
204
|
+
async storeData(): Promise<StoreDataResponse> {
|
|
214
205
|
return {
|
|
215
206
|
error: ''
|
|
216
207
|
}
|
|
217
208
|
},
|
|
218
|
-
async throwStoreDataError(
|
|
209
|
+
async throwStoreDataError(): Promise<StoreDataResponse> {
|
|
219
210
|
throw new Error('Mock')
|
|
220
211
|
},
|
|
221
|
-
async storeDataErrorString(
|
|
212
|
+
async storeDataErrorString(): Promise<StoreDataResponse> {
|
|
222
213
|
return {
|
|
223
214
|
error: 'Mock'
|
|
224
215
|
}
|
|
225
216
|
},
|
|
226
|
-
async migrateData(
|
|
217
|
+
async migrateData(): Promise<MigrateDataResponse> {
|
|
227
218
|
return MigrateDataResponse.create()
|
|
228
219
|
},
|
|
229
|
-
async deleteData(
|
|
220
|
+
async deleteData(): Promise<DeleteDataResponse> {
|
|
230
221
|
return DeleteDataResponse.create()
|
|
231
222
|
}
|
|
232
223
|
}
|
|
233
224
|
|
|
234
225
|
export const MockWebSocketConnectorRpc: IWebSocketConnectorService = {
|
|
235
|
-
async requestConnection(request: WebSocketConnectionRequest
|
|
226
|
+
async requestConnection(request: WebSocketConnectionRequest): Promise<WebSocketConnectionResponse> {
|
|
236
227
|
const responseConnection: WebSocketConnectionResponse = {
|
|
237
228
|
target: request.target,
|
|
238
229
|
requester: request.requester,
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DhtPeer.js","sourceRoot":"","sources":["../../../src/dht/DhtPeer.ts"],"names":[],"mappings":";;;AAOA,+BAAyB;AACzB,0CAAuC;AAEvC,6CAAyC;AAEzC,MAAM,MAAM,GAAG,IAAI,cAAM,CAAC,MAAM,CAAC,CAAA;AAQjC,MAAa,OAAQ,SAAQ,eAA4B;IAMrD,YACI,iBAAiC,EACjC,cAA8B,EAC9B,MAA4C,EAC5C,SAAiB;QAEjB,KAAK,CAAC,iBAAiB,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,CAAC,CAAA;QAC3D,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC,KAAK,CAAA;QAChC,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,OAAO,EAAE,CAAA;IACxC,CAAC;IAED,KAAK,CAAC,eAAe,CAAC,UAAsB;QACxC,MAAM,CAAC,KAAK,CAAC,iCAAiC,IAAI,CAAC,YAAY,EAAE,SAAS,IAAI,CAAC,SAAS,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA;QACrG,MAAM,OAAO,GAAwB;YACjC,UAAU;YACV,SAAS,EAAE,IAAA,SAAE,GAAE;SAClB,CAAA;QACD,IAAI;YACA,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,SAAS,EAAE,CAAC,eAAe,CAAC,OAAO,EAAE,IAAI,CAAC,iBAAiB,EAAE,CAAC,CAAA;YACvF,OAAO,KAAK,CAAC,KAAK,CAAA;SACrB;QAAC,OAAO,GAAG,EAAE;YACV,MAAM,CAAC,KAAK,CAAC,yBAAyB,IAAI,CAAC,YAAY,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC,CAAA;YACrE,MAAM,GAAG,CAAA;SACZ;IACL,CAAC;IAED,KAAK,CAAC,IAAI;QACN,MAAM,CAAC,KAAK,CAAC,sBAAsB,IAAI,CAAC,YAAY,EAAE,SAAS,IAAI,CAAC,SAAS,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA;QAC1F,MAAM,OAAO,GAAgB;YACzB,SAAS,EAAE,IAAA,SAAE,GAAE;SAClB,CAAA;QACD,MAAM,OAAO,GAAG,IAAI,CAAC,iBAAiB,CAAC;YACnC,OAAO,EAAE,KAAK;SACjB,CAAC,CAAA;QACF,IAAI;YACA,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,SAAS,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;YAC1D,IAAI,IAAI,CAAC,SAAS,KAAK,OAAO,CAAC,SAAS,EAAE;gBACtC,OAAO,IAAI,CAAA;aACd;SACJ;QAAC,OAAO,GAAG,EAAE;YACV,MAAM,CAAC,KAAK,CAAC,kBAAkB,IAAI,CAAC,YAAY,EAAE,OAAO,IAAI,CAAC,SAAS,EAAE,CAAC,KAAK,EAAE,KAAK,GAAG,EAAE,CAAC,CAAA;SAC/F;QACD,OAAO,KAAK,CAAA;IAChB,CAAC;IAED,WAAW;QACP,MAAM,CAAC,KAAK,CAAC,0BAA0B,IAAI,CAAC,YAAY,EAAE,SAAS,IAAI,CAAC,SAAS,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA;QAC9F,MAAM,OAAO,GAAgB;YACzB,SAAS,EAAE,IAAI,CAAC,YAAY,EAAE;SACjC,CAAA;QACD,MAAM,OAAO,GAAG,IAAI,CAAC,iBAAiB,CAAC;YACnC,YAAY,EAAE,IAAI;SACrB,CAAC,CAAA;QACF,IAAI,CAAC,SAAS,EAAE,CAAC,WAAW,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;YACvD,MAAM,CAAC,KAAK,CAAC,4BAA4B,GAAG,CAAC,CAAC,CAAA;QAClD,CAAC,CAAC,CAAA;IACN,CAAC;;AA9DL,0BA+DC;AA7DkB,eAAO,GAAG,CAAC,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const isNodeJS: () => boolean;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"isBrowser.js","sourceRoot":"","sources":["../../../../src/helpers/browser/isBrowser.ts"],"names":[],"mappings":";;;AAAO,MAAM,QAAQ,GAAG,GAAY,EAAE,CAAC,KAAK,CAAA;AAA/B,QAAA,QAAQ,YAAuB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const isNodeJS: () => boolean;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"isNodeJS.js","sourceRoot":"","sources":["../../../../src/helpers/browser/isNodeJS.ts"],"names":[],"mappings":";;;AAAO,MAAM,QAAQ,GAAG,GAAY,EAAE,CAAC,IAAI,CAAA;AAA9B,QAAA,QAAQ,YAAsB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const isNodeJS = (): boolean => false
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const isNodeJS = (): boolean => true
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { DhtNode } from '../../src/dht/DhtNode'
|
|
2
|
-
import { NodeType, PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
3
|
-
import { createMockConnectionDhtNode } from '../utils/utils'
|
|
4
|
-
import { LatencyType, Simulator } from '../../src/connection/Simulator/Simulator'
|
|
5
|
-
|
|
6
|
-
describe('Mock connection Dht joining with latencies', () => {
|
|
7
|
-
let entryPoint: DhtNode
|
|
8
|
-
let nodes: DhtNode[]
|
|
9
|
-
let simulator: Simulator
|
|
10
|
-
let entrypointDescriptor: PeerDescriptor
|
|
11
|
-
|
|
12
|
-
beforeEach(async () => {
|
|
13
|
-
nodes = []
|
|
14
|
-
simulator = new Simulator(LatencyType.RANDOM)
|
|
15
|
-
const entryPointId = '0'
|
|
16
|
-
entryPoint = await createMockConnectionDhtNode(entryPointId, simulator)
|
|
17
|
-
entrypointDescriptor = {
|
|
18
|
-
kademliaId: entryPoint.getNodeId().value,
|
|
19
|
-
type: NodeType.NODEJS,
|
|
20
|
-
nodeName: '0'
|
|
21
|
-
}
|
|
22
|
-
for (let i = 1; i < 100; i++) {
|
|
23
|
-
const nodeId = `${i}`
|
|
24
|
-
const node = await createMockConnectionDhtNode(nodeId, simulator)
|
|
25
|
-
nodes.push(node)
|
|
26
|
-
}
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
afterEach(async () => {
|
|
30
|
-
await Promise.all([
|
|
31
|
-
entryPoint.stop(),
|
|
32
|
-
...nodes.map((node) => node.stop())
|
|
33
|
-
])
|
|
34
|
-
simulator.stop()
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
it('Happy path', async () => {
|
|
38
|
-
await entryPoint.joinDht([entrypointDescriptor])
|
|
39
|
-
await Promise.all(nodes.map((node) => node.joinDht([entrypointDescriptor])))
|
|
40
|
-
nodes.forEach((node) => {
|
|
41
|
-
expect(node.getBucketSize()).toBeGreaterThanOrEqual(node.getK() - 2)
|
|
42
|
-
expect(node.getNeighborList().getSize()).toBeGreaterThanOrEqual(node.getK() - 2)
|
|
43
|
-
})
|
|
44
|
-
expect(entryPoint.getBucketSize()).toBeGreaterThanOrEqual(entryPoint.getK() - 2)
|
|
45
|
-
}, 60 * 1000)
|
|
46
|
-
})
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { Simulator } from '../../src/connection/Simulator/Simulator'
|
|
2
|
-
import { DhtNode } from '../../src/dht/DhtNode'
|
|
3
|
-
import { NodeType, PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
4
|
-
import { createMockConnectionDhtNode } from '../utils/utils'
|
|
5
|
-
|
|
6
|
-
describe('Mock IConnection DHT Joining', () => {
|
|
7
|
-
let entryPoint: DhtNode
|
|
8
|
-
let nodes: DhtNode[]
|
|
9
|
-
let entrypointDescriptor: PeerDescriptor
|
|
10
|
-
let simulator: Simulator
|
|
11
|
-
|
|
12
|
-
beforeEach(async () => {
|
|
13
|
-
nodes = []
|
|
14
|
-
simulator = new Simulator()
|
|
15
|
-
const entryPointId = '0'
|
|
16
|
-
entryPoint = await createMockConnectionDhtNode(entryPointId, simulator)
|
|
17
|
-
entrypointDescriptor = {
|
|
18
|
-
kademliaId: entryPoint.getNodeId().value,
|
|
19
|
-
type: NodeType.NODEJS,
|
|
20
|
-
nodeName: '0'
|
|
21
|
-
}
|
|
22
|
-
for (let i = 1; i < 100; i++) {
|
|
23
|
-
const nodeId = `${i}`
|
|
24
|
-
const node = await createMockConnectionDhtNode(nodeId, simulator)
|
|
25
|
-
nodes.push(node)
|
|
26
|
-
}
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
afterEach(async () => {
|
|
30
|
-
await Promise.all([
|
|
31
|
-
entryPoint.stop(),
|
|
32
|
-
...nodes.map(async (node) => node.stop())
|
|
33
|
-
])
|
|
34
|
-
simulator.stop()
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
it('Happy path', async () => {
|
|
38
|
-
await entryPoint.joinDht([entrypointDescriptor])
|
|
39
|
-
await Promise.all(nodes.map((node) => node.joinDht([entrypointDescriptor])))
|
|
40
|
-
nodes.forEach((node) => {
|
|
41
|
-
expect(node.getBucketSize()).toBeGreaterThanOrEqual(node.getK() - 2)
|
|
42
|
-
expect(node.getNeighborList().getSize()).toBeGreaterThanOrEqual(node.getK() - 2)
|
|
43
|
-
})
|
|
44
|
-
expect(entryPoint.getBucketSize()).toBeGreaterThanOrEqual(entryPoint.getK() - 2)
|
|
45
|
-
}, 60000)
|
|
46
|
-
})
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { DhtNode } from '../../src/dht/DhtNode'
|
|
2
|
-
import { createMockConnectionDhtNode } from '../utils/utils'
|
|
3
|
-
import { LatencyType, Simulator } from '../../src/connection/Simulator/Simulator'
|
|
4
|
-
import { NodeType, PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
5
|
-
import { getRandomRegion } from '../../src/connection/Simulator/pings'
|
|
6
|
-
|
|
7
|
-
describe('Mock connection Dht joining with real latencies', () => {
|
|
8
|
-
let entryPoint: DhtNode
|
|
9
|
-
let nodes: DhtNode[]
|
|
10
|
-
let simulator: Simulator
|
|
11
|
-
let entrypointDescriptor: PeerDescriptor
|
|
12
|
-
|
|
13
|
-
beforeEach(async () => {
|
|
14
|
-
nodes = []
|
|
15
|
-
simulator = new Simulator(LatencyType.REAL)
|
|
16
|
-
const entryPointId = '0'
|
|
17
|
-
entryPoint = await createMockConnectionDhtNode(entryPointId, simulator)
|
|
18
|
-
entrypointDescriptor = {
|
|
19
|
-
kademliaId: entryPoint.getNodeId().value,
|
|
20
|
-
type: NodeType.NODEJS,
|
|
21
|
-
region: getRandomRegion()
|
|
22
|
-
}
|
|
23
|
-
for (let i = 1; i < 100; i++) {
|
|
24
|
-
const nodeId = `${i}`
|
|
25
|
-
const node = await createMockConnectionDhtNode(nodeId, simulator)
|
|
26
|
-
nodes.push(node)
|
|
27
|
-
}
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
afterEach(async () => {
|
|
31
|
-
await Promise.all([
|
|
32
|
-
entryPoint.stop(),
|
|
33
|
-
...nodes.map((node) => node.stop())
|
|
34
|
-
])
|
|
35
|
-
simulator.stop()
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
it('Happy path', async () => {
|
|
39
|
-
await entryPoint.joinDht([entrypointDescriptor])
|
|
40
|
-
await Promise.all(nodes.map((node) => node.joinDht([entrypointDescriptor])))
|
|
41
|
-
nodes.forEach((node) => {
|
|
42
|
-
expect(node.getBucketSize()).toBeGreaterThanOrEqual(node.getK() - 3)
|
|
43
|
-
expect(node.getNeighborList().getSize()).toBeGreaterThanOrEqual(node.getK() - 3)
|
|
44
|
-
})
|
|
45
|
-
expect(entryPoint.getBucketSize()).toBeGreaterThanOrEqual(entryPoint.getK())
|
|
46
|
-
}, 60 * 1000)
|
|
47
|
-
})
|
|
File without changes
|