@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.
- package/dist/generated/packages/dht/protos/DhtRpc.d.ts +16 -8
- package/dist/generated/packages/dht/protos/DhtRpc.js +7 -5
- package/dist/generated/packages/dht/protos/DhtRpc.js.map +1 -1
- package/dist/package.json +15 -16
- package/dist/src/connection/ConnectionManager.js +18 -8
- package/dist/src/connection/ConnectionManager.js.map +1 -1
- package/dist/src/connection/Handshaker.d.ts +1 -1
- package/dist/src/connection/Handshaker.js +9 -5
- package/dist/src/connection/Handshaker.js.map +1 -1
- package/dist/src/connection/ManagedConnection.js +17 -7
- package/dist/src/connection/ManagedConnection.js.map +1 -1
- package/dist/src/connection/connectivityChecker.js +20 -10
- package/dist/src/connection/connectivityChecker.js.map +1 -1
- package/dist/src/connection/connectivityRequestHandler.js +3 -3
- package/dist/src/connection/connectivityRequestHandler.js.map +1 -1
- package/dist/src/connection/simulator/Simulator.js +3 -2
- package/dist/src/connection/simulator/Simulator.js.map +1 -1
- package/dist/src/connection/simulator/pings.d.ts +1 -1
- package/dist/src/connection/simulator/pings.js +3 -3
- package/dist/src/connection/simulator/pings.js.map +1 -1
- package/dist/src/connection/webrtc/NodeWebrtcConnection.js +0 -2
- package/dist/src/connection/webrtc/NodeWebrtcConnection.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnector.js +19 -9
- package/dist/src/connection/webrtc/WebrtcConnector.js.map +1 -1
- package/dist/src/connection/webrtc/iceServerAsString.js +1 -2
- package/dist/src/connection/webrtc/iceServerAsString.js.map +1 -1
- package/dist/src/connection/websocket/AbstractWebsocketClientConnection.d.ts +0 -2
- package/dist/src/connection/websocket/WebsocketClientConnectorRpcLocal.d.ts +0 -1
- package/dist/src/connection/websocket/WebsocketServerConnection.d.ts +0 -1
- package/dist/src/connection/websocket/WebsocketServerConnector.js +28 -18
- package/dist/src/connection/websocket/WebsocketServerConnector.js.map +1 -1
- package/dist/src/dht/DhtNode.d.ts +1 -0
- package/dist/src/dht/DhtNode.js +3 -2
- package/dist/src/dht/DhtNode.js.map +1 -1
- package/dist/src/dht/DhtNodeRpcLocal.d.ts +1 -1
- package/dist/src/dht/PeerManager.d.ts +2 -1
- package/dist/src/dht/PeerManager.js +2 -1
- package/dist/src/dht/PeerManager.js.map +1 -1
- package/dist/src/dht/contact/SortedContactList.js +1 -1
- package/dist/src/dht/contact/SortedContactList.js.map +1 -1
- package/dist/src/dht/discovery/DiscoverySession.d.ts +0 -1
- package/dist/src/dht/discovery/PeerDiscovery.d.ts +0 -1
- package/dist/src/dht/discovery/RingDiscoverySession.d.ts +0 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.d.ts +2 -2
- package/dist/src/dht/routing/DuplicateDetector.js.map +1 -1
- package/dist/src/dht/routing/RoutingSession.js +2 -2
- package/dist/src/dht/routing/RoutingSession.js.map +1 -1
- package/dist/src/dht/routing/RoutingTablesCache.d.ts +1 -1
- package/dist/src/dht/store/LocalDataStore.js +1 -1
- package/dist/src/dht/store/LocalDataStore.js.map +1 -1
- package/dist/src/dht/store/StoreManager.d.ts +1 -1
- package/dist/src/dht/store/StoreRpcLocal.d.ts +1 -1
- package/dist/src/helpers/AddressTools.js +2 -3
- package/dist/src/helpers/AddressTools.js.map +1 -1
- package/dist/src/helpers/debugHelpers.js +2 -2
- package/dist/src/helpers/debugHelpers.js.map +1 -1
- package/dist/src/helpers/protoClasses.d.ts +1 -1
- package/dist/src/helpers/protoClasses.js.map +1 -1
- package/dist/src/helpers/protoToString.js +1 -2
- package/dist/src/helpers/protoToString.js.map +1 -1
- package/dist/src/helpers/version.d.ts +1 -1
- package/dist/src/helpers/version.js +4 -4
- package/dist/src/helpers/version.js.map +1 -1
- package/eslint.config.mjs +12 -0
- package/jest.config.ts +12 -0
- package/package.json +15 -16
- package/protos/DhtRpc.proto +6 -4
- package/.eslintignore +0 -5
- package/.eslintrc +0 -3
- package/generated/google/protobuf/any.ts +0 -326
- package/generated/google/protobuf/empty.ts +0 -81
- package/generated/google/protobuf/timestamp.ts +0 -287
- package/generated/packages/dht/protos/DhtRpc.client.ts +0 -419
- package/generated/packages/dht/protos/DhtRpc.server.ts +0 -165
- package/generated/packages/dht/protos/DhtRpc.ts +0 -1266
- package/generated/packages/proto-rpc/protos/ProtoRpc.ts +0 -108
- package/jest.config.js +0 -5
- package/src/connection/Connection.ts +0 -28
- package/src/connection/ConnectionLockRpcLocal.ts +0 -78
- package/src/connection/ConnectionLockRpcRemote.ts +0 -64
- package/src/connection/ConnectionLockStates.ts +0 -131
- package/src/connection/ConnectionManager.ts +0 -661
- package/src/connection/ConnectionsView.ts +0 -8
- package/src/connection/ConnectorFacade.ts +0 -217
- package/src/connection/Handshaker.ts +0 -205
- package/src/connection/IConnection.ts +0 -40
- package/src/connection/ManagedConnection.ts +0 -113
- package/src/connection/OutputBuffer.ts +0 -28
- package/src/connection/PendingConnection.ts +0 -68
- package/src/connection/connectivityChecker.ts +0 -108
- package/src/connection/connectivityRequestHandler.ts +0 -116
- package/src/connection/simulator/Simulator.ts +0 -368
- package/src/connection/simulator/SimulatorConnection.ts +0 -137
- package/src/connection/simulator/SimulatorConnector.ts +0 -98
- package/src/connection/simulator/SimulatorTransport.ts +0 -15
- package/src/connection/simulator/pings.ts +0 -42
- package/src/connection/webrtc/BrowserWebrtcConnection.ts +0 -242
- package/src/connection/webrtc/IWebrtcConnection.ts +0 -24
- package/src/connection/webrtc/NodeWebrtcConnection.ts +0 -247
- package/src/connection/webrtc/WebrtcConnector.ts +0 -234
- package/src/connection/webrtc/WebrtcConnectorRpcLocal.ts +0 -108
- package/src/connection/webrtc/WebrtcConnectorRpcRemote.ts +0 -60
- package/src/connection/webrtc/iceServerAsString.ts +0 -15
- package/src/connection/websocket/AbstractWebsocketClientConnection.ts +0 -122
- package/src/connection/websocket/AutoCertifierClientFacade.ts +0 -89
- package/src/connection/websocket/BrowserWebsocketClientConnection.ts +0 -44
- package/src/connection/websocket/NodeWebsocketClientConnection.ts +0 -39
- package/src/connection/websocket/WebsocketClientConnector.ts +0 -119
- package/src/connection/websocket/WebsocketClientConnectorRpcLocal.ts +0 -38
- package/src/connection/websocket/WebsocketClientConnectorRpcRemote.ts +0 -19
- package/src/connection/websocket/WebsocketServer.ts +0 -164
- package/src/connection/websocket/WebsocketServerConnection.ts +0 -109
- package/src/connection/websocket/WebsocketServerConnector.ts +0 -286
- package/src/dht/DhtNode.ts +0 -678
- package/src/dht/DhtNodeRpcLocal.ts +0 -84
- package/src/dht/DhtNodeRpcRemote.ts +0 -107
- package/src/dht/ExternalApiRpcLocal.ts +0 -58
- package/src/dht/ExternalApiRpcRemote.ts +0 -41
- package/src/dht/PeerManager.ts +0 -303
- package/src/dht/contact/Contact.ts +0 -19
- package/src/dht/contact/ContactList.ts +0 -43
- package/src/dht/contact/RandomContactList.ts +0 -56
- package/src/dht/contact/RingContactList.ts +0 -143
- package/src/dht/contact/RpcRemote.ts +0 -72
- package/src/dht/contact/SortedContactList.ts +0 -173
- package/src/dht/contact/getClosestNodes.ts +0 -24
- package/src/dht/contact/ringIdentifiers.ts +0 -62
- package/src/dht/discovery/DiscoverySession.ts +0 -129
- package/src/dht/discovery/PeerDiscovery.ts +0 -244
- package/src/dht/discovery/RingDiscoverySession.ts +0 -148
- package/src/dht/recursive-operation/RecursiveOperationManager.ts +0 -251
- package/src/dht/recursive-operation/RecursiveOperationRpcLocal.ts +0 -34
- package/src/dht/recursive-operation/RecursiveOperationRpcRemote.ts +0 -43
- package/src/dht/recursive-operation/RecursiveOperationSession.ts +0 -231
- package/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.ts +0 -35
- package/src/dht/recursive-operation/RecursiveOperationSessionRpcRemote.ts +0 -30
- package/src/dht/routing/DuplicateDetector.ts +0 -34
- package/src/dht/routing/Router.ts +0 -246
- package/src/dht/routing/RouterRpcLocal.ts +0 -78
- package/src/dht/routing/RouterRpcRemote.ts +0 -80
- package/src/dht/routing/RoutingSession.ts +0 -243
- package/src/dht/routing/RoutingTablesCache.ts +0 -60
- package/src/dht/routing/getPreviousPeer.ts +0 -6
- package/src/dht/store/LocalDataStore.ts +0 -84
- package/src/dht/store/StoreManager.ts +0 -170
- package/src/dht/store/StoreRpcLocal.ts +0 -89
- package/src/dht/store/StoreRpcRemote.ts +0 -32
- package/src/exports.ts +0 -33
- package/src/helpers/AddressTools.ts +0 -28
- package/src/helpers/Connectivity.ts +0 -19
- package/src/helpers/browser/isBrowserEnvironment.ts +0 -1
- package/src/helpers/browser/isBrowserEnvironment_override.ts +0 -3
- package/src/helpers/createPeerDescriptor.ts +0 -57
- package/src/helpers/createPeerDescriptorSignaturePayload.ts +0 -28
- package/src/helpers/debugHelpers.ts +0 -9
- package/src/helpers/errors.ts +0 -49
- package/src/helpers/offering.ts +0 -15
- package/src/helpers/protoClasses.ts +0 -57
- package/src/helpers/protoToString.ts +0 -21
- package/src/helpers/version.ts +0 -32
- package/src/identifiers.ts +0 -29
- package/src/rpc-protocol/DhtCallContext.ts +0 -14
- package/src/rpc-protocol/DhtRpcOptions.ts +0 -10
- package/src/transport/ITransport.ts +0 -37
- package/src/transport/ListeningRpcCommunicator.ts +0 -32
- package/src/transport/RoutingRpcCommunicator.ts +0 -66
- package/src/types/ServiceID.ts +0 -1
- package/src/types/textencoding.d.ts +0 -6
- package/test/benchmark/Find.test.ts +0 -72
- package/test/benchmark/KademliaCorrectness.test.ts +0 -114
- package/test/benchmark/RingCorrectness.test.ts +0 -157
- package/test/benchmark/SortedContactListBenchmark.test.ts +0 -108
- package/test/benchmark/WebsocketServerMemoryLeak.test.ts +0 -41
- package/test/benchmark/hybrid-network-simulation/RingContactList.test.ts +0 -71
- package/test/end-to-end/GeoIpLayer0.test.ts +0 -55
- package/test/end-to-end/Layer0-Layer1.test.ts +0 -93
- package/test/end-to-end/Layer0.test.ts +0 -76
- package/test/end-to-end/Layer0MixedConnectionTypes.test.ts +0 -110
- package/test/end-to-end/Layer0Webrtc-Layer1.test.ts +0 -137
- package/test/end-to-end/Layer0Webrtc.test.ts +0 -85
- package/test/end-to-end/Layer1-Scale-WebSocket.test.ts +0 -82
- package/test/end-to-end/Layer1-Scale-Webrtc.test.ts +0 -76
- package/test/end-to-end/RecoveryFromFailedAutoCertification.test.ts +0 -52
- package/test/end-to-end/WebsocketConnectionRequest.test.ts +0 -69
- package/test/end-to-end/memory-leak.test.ts +0 -80
- package/test/integration/ConnectionLocking.test.ts +0 -182
- package/test/integration/ConnectionManager.test.ts +0 -528
- package/test/integration/ConnectivityChecking.test.ts +0 -53
- package/test/integration/DhtJoinPeerDiscovery.test.ts +0 -49
- package/test/integration/DhtNode.test.ts +0 -66
- package/test/integration/DhtNodeExternalAPI.test.ts +0 -48
- package/test/integration/DhtNodeRpcRemote.test.ts +0 -66
- package/test/integration/DhtRpc.test.ts +0 -121
- package/test/integration/Find.test.ts +0 -45
- package/test/integration/GeoIpConnectivityChecking.test.ts +0 -72
- package/test/integration/Layer1-scale.test.ts +0 -189
- package/test/integration/Mock-Layer1-Layer0.test.ts +0 -85
- package/test/integration/MultipleEntryPointJoining.test.ts +0 -105
- package/test/integration/ReplicateData.test.ts +0 -104
- package/test/integration/RouteMessage.test.ts +0 -230
- package/test/integration/RouterRpcRemote.test.ts +0 -77
- package/test/integration/SimultaneousConnections.test.ts +0 -316
- package/test/integration/Store.test.ts +0 -85
- package/test/integration/StoreAndDelete.test.ts +0 -77
- package/test/integration/StoreOnDhtWithThreeNodes.test.ts +0 -59
- package/test/integration/StoreOnDhtWithTwoNodes.test.ts +0 -51
- package/test/integration/StoreRpcRemote.test.ts +0 -54
- package/test/integration/WebrtcConnectionManagement.test.ts +0 -219
- package/test/integration/WebrtcConnectorRpc.test.ts +0 -125
- package/test/integration/Websocket.test.ts +0 -65
- package/test/integration/WebsocketClientConnectorRpc.test.ts +0 -69
- package/test/integration/WebsocketConnectionManagement.test.ts +0 -191
- package/test/integration/rpc-connections-over-webrtc.test.ts +0 -158
- package/test/kademlia-simulation/data/nodeids.json +0 -13002
- package/test/kademlia-simulation/data/orderedneighbors.json +0 -1001
- package/test/types/global.d.ts +0 -1
- package/test/unit/AddressTools.test.ts +0 -44
- package/test/unit/AutoCertifierClientFacade.test.ts +0 -58
- package/test/unit/ConnectionManager.test.ts +0 -65
- package/test/unit/ConnectivityHelpers.test.ts +0 -61
- package/test/unit/DiscoverySession.test.ts +0 -87
- package/test/unit/DuplicateDetector.test.ts +0 -31
- package/test/unit/Handshaker.test.ts +0 -169
- package/test/unit/ListeningRpcCommunicator.test.ts +0 -52
- package/test/unit/LocalDataStore.test.ts +0 -108
- package/test/unit/ManagedConnection.test.ts +0 -58
- package/test/unit/PeerManager.test.ts +0 -93
- package/test/unit/PendingConnection.test.ts +0 -57
- package/test/unit/ProtobufMessage.test.ts +0 -21
- package/test/unit/RandomContactList.test.ts +0 -58
- package/test/unit/RecursiveOperationManager.test.ts +0 -161
- package/test/unit/RecursiveOperationSession.test.ts +0 -68
- package/test/unit/Router.test.ts +0 -137
- package/test/unit/RoutingSession.test.ts +0 -79
- package/test/unit/SortedContactList.test.ts +0 -115
- package/test/unit/StoreManager.test.ts +0 -146
- package/test/unit/StoreRpcLocal.test.ts +0 -167
- package/test/unit/WebrtcConnection.test.ts +0 -29
- package/test/unit/WebrtcConnector.test.ts +0 -56
- package/test/unit/WebsocketClientConnector.test.ts +0 -101
- package/test/unit/WebsocketServer.test.ts +0 -66
- package/test/unit/WebsocketServerConnector.test.ts +0 -102
- package/test/unit/connectivityRequestHandler.test.ts +0 -104
- package/test/unit/createPeerDescriptor.test.ts +0 -69
- package/test/unit/customMatchers.test.ts +0 -16
- package/test/unit/getClosestNodes.test.ts +0 -30
- package/test/unit/version.test.ts +0 -18
- package/test/unit/webrtcReplaceInternalIpWithExternalIp.test.ts +0 -18
- package/test/utils/FakeConnectorFacade.ts +0 -41
- package/test/utils/FakeRpcCommunicator.ts +0 -23
- package/test/utils/FakeTransport.ts +0 -79
- package/test/utils/customMatchers.ts +0 -71
- package/test/utils/mock/MockConnection.ts +0 -26
- package/test/utils/mock/MockConnectionsView.ts +0 -18
- package/test/utils/mock/MockRouter.ts +0 -62
- package/test/utils/mock/MockRpcCommunicator.ts +0 -7
- package/test/utils/mock/MockTransport.ts +0 -26
- package/test/utils/mock/mockDataEntry.ts +0 -38
- package/test/utils/topology.ts +0 -80
- package/test/utils/utils.ts +0 -268
- package/tsconfig.browser.json +0 -17
- package/tsconfig.jest.json +0 -25
- package/tsconfig.json +0 -3
- package/tsconfig.node.json +0 -24
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { v4 } from 'uuid'
|
|
2
|
-
import { RoutingMode, RoutingSession } from '../../src/dht/routing/RoutingSession'
|
|
3
|
-
import { Message, PeerDescriptor, RouteMessageWrapper } from '../../generated/packages/dht/protos/DhtRpc'
|
|
4
|
-
import { createMockPeerDescriptor, createWrappedClosestPeersRequest } from '../utils/utils'
|
|
5
|
-
import { DhtNodeRpcRemote } from '../../src/dht/DhtNodeRpcRemote'
|
|
6
|
-
import { RoutingRpcCommunicator } from '../../src/transport/RoutingRpcCommunicator'
|
|
7
|
-
import { DhtAddress, toNodeId } from '../../src/identifiers'
|
|
8
|
-
import { MockRpcCommunicator } from '../utils/mock/MockRpcCommunicator'
|
|
9
|
-
import { RoutingTablesCache } from '../../src/dht/routing/RoutingTablesCache'
|
|
10
|
-
|
|
11
|
-
describe('RoutingSession', () => {
|
|
12
|
-
|
|
13
|
-
let session: RoutingSession
|
|
14
|
-
let connections: Map<DhtAddress, DhtNodeRpcRemote>
|
|
15
|
-
let rpcCommunicator: RoutingRpcCommunicator
|
|
16
|
-
let routingTablesCache: RoutingTablesCache
|
|
17
|
-
const mockPeerDescriptor1 = createMockPeerDescriptor()
|
|
18
|
-
const mockPeerDescriptor2 = createMockPeerDescriptor()
|
|
19
|
-
const rpcWrapper = createWrappedClosestPeersRequest(mockPeerDescriptor1)
|
|
20
|
-
const message: Message = {
|
|
21
|
-
serviceId: 'unknown',
|
|
22
|
-
messageId: v4(),
|
|
23
|
-
body: {
|
|
24
|
-
oneofKind: 'rpcMessage',
|
|
25
|
-
rpcMessage: rpcWrapper
|
|
26
|
-
},
|
|
27
|
-
sourceDescriptor: mockPeerDescriptor1,
|
|
28
|
-
targetDescriptor: mockPeerDescriptor2
|
|
29
|
-
}
|
|
30
|
-
const routedMessage: RouteMessageWrapper = {
|
|
31
|
-
message,
|
|
32
|
-
requestId: 'REQ',
|
|
33
|
-
routingPath: [],
|
|
34
|
-
reachableThrough: [],
|
|
35
|
-
target: mockPeerDescriptor1.nodeId,
|
|
36
|
-
sourcePeer: mockPeerDescriptor2,
|
|
37
|
-
parallelRootNodeIds: []
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const createMockDhtNodeRpcRemote = (destination: PeerDescriptor): DhtNodeRpcRemote => {
|
|
41
|
-
return new DhtNodeRpcRemote(mockPeerDescriptor1, destination, undefined as any, rpcCommunicator)
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
beforeEach(() => {
|
|
45
|
-
rpcCommunicator = new MockRpcCommunicator()
|
|
46
|
-
connections = new Map()
|
|
47
|
-
routingTablesCache = new RoutingTablesCache()
|
|
48
|
-
session = new RoutingSession({
|
|
49
|
-
rpcCommunicator: rpcCommunicator,
|
|
50
|
-
localPeerDescriptor: mockPeerDescriptor1,
|
|
51
|
-
routedMessage,
|
|
52
|
-
parallelism: 2,
|
|
53
|
-
mode: RoutingMode.ROUTE,
|
|
54
|
-
excludedNodeIds: new Set(),
|
|
55
|
-
routingTablesCache,
|
|
56
|
-
getConnections: () => [...connections.values()].map((c) => c.getPeerDescriptor())
|
|
57
|
-
})
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
afterEach(() => {
|
|
61
|
-
rpcCommunicator.stop()
|
|
62
|
-
session.stop()
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
it('findMoreContacts', () => {
|
|
66
|
-
connections.set(toNodeId(mockPeerDescriptor2), createMockDhtNodeRpcRemote(mockPeerDescriptor2))
|
|
67
|
-
const contacts = session.updateAndGetRoutablePeers()
|
|
68
|
-
expect(contacts.length).toBe(1)
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
it('findMoreContacts peer disconnects', () => {
|
|
72
|
-
connections.set(toNodeId(mockPeerDescriptor2), createMockDhtNodeRpcRemote(mockPeerDescriptor2))
|
|
73
|
-
expect(session.updateAndGetRoutablePeers().length).toBe(1)
|
|
74
|
-
connections.delete(toNodeId(mockPeerDescriptor2))
|
|
75
|
-
routingTablesCache.onNodeDisconnected(toNodeId(mockPeerDescriptor2))
|
|
76
|
-
expect(session.updateAndGetRoutablePeers().length).toBe(0)
|
|
77
|
-
})
|
|
78
|
-
|
|
79
|
-
})
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import { SortedContactList } from '../../src/dht/contact/SortedContactList'
|
|
2
|
-
import { DhtAddress, DhtAddressRaw, randomDhtAddress, toDhtAddress } from '../../src/identifiers'
|
|
3
|
-
|
|
4
|
-
const createItem = (nodeId: DhtAddressRaw): { getNodeId: () => DhtAddress } => {
|
|
5
|
-
return {
|
|
6
|
-
getNodeId: () => toDhtAddress(nodeId)
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
describe('SortedContactList', () => {
|
|
11
|
-
|
|
12
|
-
const item0 = createItem(new Uint8Array([0, 0, 0, 0]))
|
|
13
|
-
const item1 = createItem(new Uint8Array([0, 0, 0, 1]))
|
|
14
|
-
const item2 = createItem(new Uint8Array([0, 0, 0, 2]))
|
|
15
|
-
const item3 = createItem(new Uint8Array([0, 0, 0, 3]))
|
|
16
|
-
const item4 = createItem(new Uint8Array([0, 0, 0, 4]))
|
|
17
|
-
|
|
18
|
-
it('compares Ids correctly', async () => {
|
|
19
|
-
const list = new SortedContactList({ referenceId: item0.getNodeId(), maxSize: 10, allowToContainReferenceId: true })
|
|
20
|
-
expect(list.compareIds(item0.getNodeId(), item0.getNodeId())).toBe(0)
|
|
21
|
-
expect(list.compareIds(item1.getNodeId(), item1.getNodeId())).toBe(0)
|
|
22
|
-
expect(list.compareIds(item0.getNodeId(), item1.getNodeId())).toBe(-1)
|
|
23
|
-
expect(list.compareIds(item0.getNodeId(), item2.getNodeId())).toBe(-2)
|
|
24
|
-
expect(list.compareIds(item1.getNodeId(), item0.getNodeId())).toBe(1)
|
|
25
|
-
expect(list.compareIds(item2.getNodeId(), item0.getNodeId())).toBe(2)
|
|
26
|
-
expect(list.compareIds(item2.getNodeId(), item3.getNodeId())).toBe(-1)
|
|
27
|
-
expect(list.compareIds(item1.getNodeId(), item4.getNodeId())).toBe(-3)
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
it('cannot exceed maxSize', async () => {
|
|
31
|
-
const list = new SortedContactList({ referenceId: item0.getNodeId(), maxSize: 3, allowToContainReferenceId: false })
|
|
32
|
-
const onContactRemoved = jest.fn()
|
|
33
|
-
list.on('contactRemoved', onContactRemoved)
|
|
34
|
-
list.addContact(item1)
|
|
35
|
-
list.addContact(item4)
|
|
36
|
-
list.addContact(item3)
|
|
37
|
-
list.addContact(item2)
|
|
38
|
-
expect(list.getSize()).toEqual(3)
|
|
39
|
-
expect(list.getClosestContacts()).toEqual([item1, item2, item3])
|
|
40
|
-
expect(list.getContactIds()).toEqual([item1.getNodeId(), item2.getNodeId(), item3.getNodeId()])
|
|
41
|
-
expect(onContactRemoved).toBeCalledWith(item4)
|
|
42
|
-
expect(list.getContact(item4.getNodeId())).toBeFalsy()
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
it('removing contacts', async () => {
|
|
46
|
-
const list = new SortedContactList({ referenceId: item0.getNodeId(), maxSize: 8, allowToContainReferenceId: false })
|
|
47
|
-
const onContactRemoved = jest.fn()
|
|
48
|
-
list.on('contactRemoved', onContactRemoved)
|
|
49
|
-
list.removeContact(randomDhtAddress())
|
|
50
|
-
list.addContact(item3)
|
|
51
|
-
list.removeContact(item3.getNodeId())
|
|
52
|
-
list.addContact(item4)
|
|
53
|
-
list.addContact(item3)
|
|
54
|
-
list.addContact(item2)
|
|
55
|
-
list.addContact(item1)
|
|
56
|
-
list.removeContact(item2.getNodeId())
|
|
57
|
-
expect(list.getSize()).toEqual(3)
|
|
58
|
-
expect(list.getContact(item2.getNodeId())).toBeFalsy()
|
|
59
|
-
expect(list.getContactIds()).toEqual(list.getContactIds().sort(list.compareIds))
|
|
60
|
-
expect(list.getClosestContacts()).toEqual([item1, item3, item4])
|
|
61
|
-
const ret = list.removeContact(toDhtAddress(Buffer.from([0, 0, 0, 6])))
|
|
62
|
-
expect(ret).toEqual(false)
|
|
63
|
-
list.removeContact(item3.getNodeId())
|
|
64
|
-
list.removeContact(randomDhtAddress())
|
|
65
|
-
expect(list.getClosestContacts()).toEqual([item1, item4])
|
|
66
|
-
expect(onContactRemoved).toHaveBeenNthCalledWith(1, item3)
|
|
67
|
-
expect(onContactRemoved).toHaveBeenNthCalledWith(2, item2)
|
|
68
|
-
expect(onContactRemoved).toHaveBeenNthCalledWith(3, item3)
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
it('get closest contacts', () => {
|
|
72
|
-
const list = new SortedContactList({
|
|
73
|
-
referenceId: item0.getNodeId(),
|
|
74
|
-
maxSize: 8,
|
|
75
|
-
allowToContainReferenceId: false
|
|
76
|
-
})
|
|
77
|
-
list.addContact(item1)
|
|
78
|
-
list.addContact(item3)
|
|
79
|
-
list.addContact(item4)
|
|
80
|
-
list.addContact(item2)
|
|
81
|
-
expect(list.getClosestContacts(2)).toEqual([item1, item2])
|
|
82
|
-
expect(list.getClosestContacts(10)).toEqual([item1, item2, item3, item4])
|
|
83
|
-
expect(list.getClosestContacts()).toEqual([item1, item2, item3, item4])
|
|
84
|
-
expect(list.getClosestContacts(-2)).toEqual([])
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
it('get furthest contacts', () => {
|
|
88
|
-
const list = new SortedContactList({
|
|
89
|
-
referenceId: item0.getNodeId(),
|
|
90
|
-
maxSize: 8,
|
|
91
|
-
allowToContainReferenceId: false
|
|
92
|
-
})
|
|
93
|
-
list.addContact(item1)
|
|
94
|
-
list.addContact(item3)
|
|
95
|
-
list.addContact(item4)
|
|
96
|
-
list.addContact(item2)
|
|
97
|
-
expect(list.getFurthestContacts(2)).toEqual([item4, item3])
|
|
98
|
-
expect(list.getFurthestContacts(10)).toEqual([item4, item3, item2, item1])
|
|
99
|
-
expect(list.getFurthestContacts()).toEqual([item4, item3, item2, item1])
|
|
100
|
-
expect(list.getFurthestContacts(-2)).toEqual([])
|
|
101
|
-
})
|
|
102
|
-
|
|
103
|
-
it('does not emit contactAdded if contact did not fit the structure', () => {
|
|
104
|
-
const list = new SortedContactList({ referenceId: item0.getNodeId(), maxSize: 2, allowToContainReferenceId: false })
|
|
105
|
-
const onContactAdded = jest.fn()
|
|
106
|
-
list.on('contactAdded', onContactAdded)
|
|
107
|
-
list.addContact(item1)
|
|
108
|
-
list.addContact(item2)
|
|
109
|
-
expect(onContactAdded).toBeCalledTimes(2)
|
|
110
|
-
list.addContact(item3)
|
|
111
|
-
expect(onContactAdded).toBeCalledTimes(2)
|
|
112
|
-
expect(list.getClosestContacts().length).toEqual(2)
|
|
113
|
-
})
|
|
114
|
-
|
|
115
|
-
})
|
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
import { wait, waitForCondition } from '@streamr/utils'
|
|
2
|
-
import { range, without } from 'lodash'
|
|
3
|
-
import { getClosestNodes } from '../../src/dht/contact/getClosestNodes'
|
|
4
|
-
import { StoreManager } from '../../src/dht/store/StoreManager'
|
|
5
|
-
import {
|
|
6
|
-
DhtAddress,
|
|
7
|
-
randomDhtAddress,
|
|
8
|
-
toDhtAddress,
|
|
9
|
-
toDhtAddressRaw
|
|
10
|
-
} from '../../src/identifiers'
|
|
11
|
-
import { PeerDescriptor, ReplicateDataRequest } from '../../generated/packages/dht/protos/DhtRpc'
|
|
12
|
-
import { createMockPeerDescriptor } from '../utils/utils'
|
|
13
|
-
|
|
14
|
-
const NODE_COUNT = 10
|
|
15
|
-
|
|
16
|
-
const DATA_ENTRY = {
|
|
17
|
-
key: toDhtAddressRaw(randomDhtAddress()),
|
|
18
|
-
creator: toDhtAddressRaw(randomDhtAddress())
|
|
19
|
-
}
|
|
20
|
-
const ALL_NODES = range(NODE_COUNT).map(() => createMockPeerDescriptor())
|
|
21
|
-
|
|
22
|
-
const getNodeCloseToData = (distanceIndex: number) => {
|
|
23
|
-
const dataKey = toDhtAddress(DATA_ENTRY.key)
|
|
24
|
-
return getClosestNodes(dataKey, ALL_NODES)[distanceIndex]
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
describe('StoreManager', () => {
|
|
28
|
-
|
|
29
|
-
describe('new contact', () => {
|
|
30
|
-
|
|
31
|
-
const createStoreManager = (
|
|
32
|
-
localPeerDescriptor: PeerDescriptor,
|
|
33
|
-
redundancyFactor: number,
|
|
34
|
-
replicateData: (request: ReplicateDataRequest) => unknown,
|
|
35
|
-
setAllEntriesAsStale: (key: DhtAddress) => unknown
|
|
36
|
-
): StoreManager => {
|
|
37
|
-
return new StoreManager({
|
|
38
|
-
rpcCommunicator: {
|
|
39
|
-
registerRpcMethod: () => {},
|
|
40
|
-
registerRpcNotification: () => {}
|
|
41
|
-
} as any,
|
|
42
|
-
recursiveOperationManager: undefined as any,
|
|
43
|
-
localPeerDescriptor,
|
|
44
|
-
localDataStore: {
|
|
45
|
-
keys: () => [toDhtAddress(DATA_ENTRY.key)],
|
|
46
|
-
values: () => [DATA_ENTRY],
|
|
47
|
-
setAllEntriesAsStale
|
|
48
|
-
} as any,
|
|
49
|
-
serviceId: undefined as any,
|
|
50
|
-
highestTtl: undefined as any,
|
|
51
|
-
redundancyFactor,
|
|
52
|
-
getNeighbors: () => without(ALL_NODES, localPeerDescriptor),
|
|
53
|
-
createRpcRemote: () => ({ replicateData } as any)
|
|
54
|
-
})
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
describe('this node was primary storer', () => {
|
|
58
|
-
|
|
59
|
-
it('new node is within redundancy factor', async () => {
|
|
60
|
-
const replicateData = jest.fn<undefined, [ReplicateDataRequest]>()
|
|
61
|
-
const setAllEntriesAsStale = jest.fn<undefined, [DhtAddress]>()
|
|
62
|
-
const localNode = getNodeCloseToData(0)
|
|
63
|
-
const manager = createStoreManager(
|
|
64
|
-
localNode,
|
|
65
|
-
3,
|
|
66
|
-
replicateData,
|
|
67
|
-
setAllEntriesAsStale
|
|
68
|
-
)
|
|
69
|
-
manager.onContactAdded(getNodeCloseToData(2))
|
|
70
|
-
await waitForCondition(() => replicateData.mock.calls.length === 1)
|
|
71
|
-
expect(replicateData).toHaveBeenCalledWith({
|
|
72
|
-
entry: DATA_ENTRY
|
|
73
|
-
}, true)
|
|
74
|
-
expect(setAllEntriesAsStale).not.toHaveBeenCalled()
|
|
75
|
-
})
|
|
76
|
-
|
|
77
|
-
it('new node is not within redundancy factor', async () => {
|
|
78
|
-
const replicateData = jest.fn<undefined, [ReplicateDataRequest]>()
|
|
79
|
-
const setAllEntriesAsStale = jest.fn<undefined, [DhtAddress]>()
|
|
80
|
-
const localNode = getNodeCloseToData(0)
|
|
81
|
-
const manager = createStoreManager(
|
|
82
|
-
localNode,
|
|
83
|
-
3,
|
|
84
|
-
replicateData,
|
|
85
|
-
setAllEntriesAsStale
|
|
86
|
-
)
|
|
87
|
-
manager.onContactAdded(getNodeCloseToData(4))
|
|
88
|
-
await wait(50)
|
|
89
|
-
expect(replicateData).not.toHaveBeenCalled()
|
|
90
|
-
expect(setAllEntriesAsStale).not.toHaveBeenCalled()
|
|
91
|
-
})
|
|
92
|
-
})
|
|
93
|
-
|
|
94
|
-
describe('this node was not primary storer', () => {
|
|
95
|
-
|
|
96
|
-
it('this node is within redundancy factor', async () => {
|
|
97
|
-
const replicateData = jest.fn<undefined, [ReplicateDataRequest]>()
|
|
98
|
-
const setAllEntriesAsStale = jest.fn<undefined, [DhtAddress]>()
|
|
99
|
-
const localNode = getNodeCloseToData(1)
|
|
100
|
-
const manager = createStoreManager(
|
|
101
|
-
localNode,
|
|
102
|
-
3,
|
|
103
|
-
replicateData,
|
|
104
|
-
setAllEntriesAsStale
|
|
105
|
-
)
|
|
106
|
-
manager.onContactAdded(getNodeCloseToData(4))
|
|
107
|
-
await wait(50)
|
|
108
|
-
expect(replicateData).not.toHaveBeenCalled()
|
|
109
|
-
expect(setAllEntriesAsStale).toHaveBeenCalledTimes(0)
|
|
110
|
-
})
|
|
111
|
-
|
|
112
|
-
it('this node is not within redundancy factor', async () => {
|
|
113
|
-
const replicateData = jest.fn<undefined, [ReplicateDataRequest]>()
|
|
114
|
-
const setAllEntriesAsStale = jest.fn<undefined, [DhtAddress]>()
|
|
115
|
-
const localNode = getNodeCloseToData(3)
|
|
116
|
-
const manager = createStoreManager(
|
|
117
|
-
localNode,
|
|
118
|
-
3,
|
|
119
|
-
replicateData,
|
|
120
|
-
setAllEntriesAsStale
|
|
121
|
-
)
|
|
122
|
-
manager.onContactAdded(getNodeCloseToData(4))
|
|
123
|
-
await wait(50)
|
|
124
|
-
expect(replicateData).not.toHaveBeenCalled()
|
|
125
|
-
expect(setAllEntriesAsStale).toHaveBeenCalledTimes(1)
|
|
126
|
-
expect(setAllEntriesAsStale).toHaveBeenCalledWith(toDhtAddress(DATA_ENTRY.key))
|
|
127
|
-
})
|
|
128
|
-
|
|
129
|
-
it('this node is within redundancy factor, the node has less than redundancyFactor neighbors', async () => {
|
|
130
|
-
const replicateData = jest.fn<undefined, [ReplicateDataRequest]>()
|
|
131
|
-
const setAllEntriesAsStale = jest.fn<undefined, [DhtAddress]>()
|
|
132
|
-
const localNode = getNodeCloseToData(3)
|
|
133
|
-
const manager = createStoreManager(
|
|
134
|
-
localNode,
|
|
135
|
-
100,
|
|
136
|
-
replicateData,
|
|
137
|
-
setAllEntriesAsStale
|
|
138
|
-
)
|
|
139
|
-
manager.onContactAdded(getNodeCloseToData(4))
|
|
140
|
-
await wait(50)
|
|
141
|
-
expect(replicateData).not.toHaveBeenCalled()
|
|
142
|
-
expect(setAllEntriesAsStale).toHaveBeenCalledTimes(0)
|
|
143
|
-
})
|
|
144
|
-
})
|
|
145
|
-
})
|
|
146
|
-
})
|
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
import { range } from 'lodash'
|
|
2
|
-
import { StoreRpcLocal } from '../../src/dht/store/StoreRpcLocal'
|
|
3
|
-
import { areEqualPeerDescriptors, randomDhtAddress, DhtAddress, toDhtAddress, toDhtAddressRaw } from '../../src/identifiers'
|
|
4
|
-
import { DataEntry, PeerDescriptor, StoreDataRequest } from '../../generated/packages/dht/protos/DhtRpc'
|
|
5
|
-
import { createMockPeerDescriptor } from '../utils/utils'
|
|
6
|
-
import { getClosestNodes } from '../../src/dht/contact/getClosestNodes'
|
|
7
|
-
import { wait } from '@streamr/utils'
|
|
8
|
-
|
|
9
|
-
describe('StoreRpcLocal', () => {
|
|
10
|
-
|
|
11
|
-
const NODE_COUNT = 5
|
|
12
|
-
const DATA_ENTRY = {
|
|
13
|
-
key: toDhtAddressRaw(randomDhtAddress()),
|
|
14
|
-
creator: toDhtAddressRaw(randomDhtAddress())
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const ALL_NODES = range(NODE_COUNT).map(() => createMockPeerDescriptor())
|
|
18
|
-
|
|
19
|
-
const getNodeCloseToData = (distanceIndex: number) => {
|
|
20
|
-
const dataKey = toDhtAddress(DATA_ENTRY.key)
|
|
21
|
-
return getClosestNodes(dataKey, ALL_NODES)[distanceIndex]
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
let storeRpcLocal: StoreRpcLocal
|
|
25
|
-
let setAllEntriesAsStale: jest.Mock<undefined, [DhtAddress]>
|
|
26
|
-
let replicateDataToContact: jest.Mock<Promise<void>, [DataEntry, PeerDescriptor]>
|
|
27
|
-
|
|
28
|
-
beforeEach(() => {
|
|
29
|
-
setAllEntriesAsStale = jest.fn<undefined, [DhtAddress]>()
|
|
30
|
-
replicateDataToContact = jest.fn<Promise<void>, [DataEntry, PeerDescriptor]>()
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
describe('local node is primary storer', () => {
|
|
34
|
-
|
|
35
|
-
beforeEach(() => {
|
|
36
|
-
const localPeerDescriptor = getNodeCloseToData(0)
|
|
37
|
-
storeRpcLocal = new StoreRpcLocal({
|
|
38
|
-
localDataStore: {
|
|
39
|
-
storeEntry: () => true,
|
|
40
|
-
setAllEntriesAsStale
|
|
41
|
-
} as any,
|
|
42
|
-
localPeerDescriptor,
|
|
43
|
-
replicateDataToContact,
|
|
44
|
-
getStorers: () => getClosestNodes(toDhtAddress(DATA_ENTRY.key), ALL_NODES)
|
|
45
|
-
})
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
it('storeData', async () => {
|
|
49
|
-
const request = StoreDataRequest.create({
|
|
50
|
-
key: DATA_ENTRY.key,
|
|
51
|
-
})
|
|
52
|
-
await storeRpcLocal.storeData(request)
|
|
53
|
-
expect(setAllEntriesAsStale).not.toHaveBeenCalled()
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
it('replicateData', async () => {
|
|
57
|
-
const request = {
|
|
58
|
-
entry: DATA_ENTRY
|
|
59
|
-
}
|
|
60
|
-
await storeRpcLocal.replicateData(request as any, { incomingSourceDescriptor: createMockPeerDescriptor() } as any)
|
|
61
|
-
expect(setAllEntriesAsStale).not.toHaveBeenCalled()
|
|
62
|
-
// Wait for setImmediate
|
|
63
|
-
await wait(50)
|
|
64
|
-
expect(replicateDataToContact).toHaveBeenCalledTimes(NODE_COUNT - 1)
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
describe('local node is storer', () => {
|
|
70
|
-
beforeEach(() => {
|
|
71
|
-
const localPeerDescriptor = getNodeCloseToData(1)
|
|
72
|
-
storeRpcLocal = new StoreRpcLocal({
|
|
73
|
-
localDataStore: {
|
|
74
|
-
storeEntry: () => true,
|
|
75
|
-
setAllEntriesAsStale
|
|
76
|
-
} as any,
|
|
77
|
-
localPeerDescriptor,
|
|
78
|
-
replicateDataToContact,
|
|
79
|
-
getStorers: () => getClosestNodes(toDhtAddress(DATA_ENTRY.key), ALL_NODES)
|
|
80
|
-
})
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
it('storeData', async () => {
|
|
84
|
-
const request = StoreDataRequest.create({
|
|
85
|
-
key: DATA_ENTRY.key
|
|
86
|
-
})
|
|
87
|
-
await storeRpcLocal.storeData(request)
|
|
88
|
-
expect(setAllEntriesAsStale).not.toHaveBeenCalled()
|
|
89
|
-
})
|
|
90
|
-
|
|
91
|
-
it('replicateData', async () => {
|
|
92
|
-
const request = {
|
|
93
|
-
entry: DATA_ENTRY
|
|
94
|
-
}
|
|
95
|
-
await storeRpcLocal.replicateData(request as any, { incomingSourceDescriptor: createMockPeerDescriptor() } as any)
|
|
96
|
-
expect(setAllEntriesAsStale).not.toHaveBeenCalled()
|
|
97
|
-
// Wait for setImmediate
|
|
98
|
-
await wait(50)
|
|
99
|
-
expect(replicateDataToContact).toHaveBeenCalledTimes(1)
|
|
100
|
-
})
|
|
101
|
-
})
|
|
102
|
-
|
|
103
|
-
describe('local node is not storer', () => {
|
|
104
|
-
beforeEach(() => {
|
|
105
|
-
const localPeerDescriptor = getNodeCloseToData(NODE_COUNT - 1)
|
|
106
|
-
storeRpcLocal = new StoreRpcLocal({
|
|
107
|
-
localDataStore: {
|
|
108
|
-
storeEntry: () => true,
|
|
109
|
-
setAllEntriesAsStale
|
|
110
|
-
} as any,
|
|
111
|
-
localPeerDescriptor,
|
|
112
|
-
replicateDataToContact,
|
|
113
|
-
getStorers: () => getClosestNodes(toDhtAddress(DATA_ENTRY.key), ALL_NODES)
|
|
114
|
-
.filter((peerDescriptor) => !areEqualPeerDescriptors(peerDescriptor, localPeerDescriptor))
|
|
115
|
-
})
|
|
116
|
-
})
|
|
117
|
-
|
|
118
|
-
it('storeData', async () => {
|
|
119
|
-
const request = StoreDataRequest.create({
|
|
120
|
-
key: DATA_ENTRY.key
|
|
121
|
-
})
|
|
122
|
-
await storeRpcLocal.storeData(request)
|
|
123
|
-
expect(setAllEntriesAsStale).toHaveBeenCalled()
|
|
124
|
-
})
|
|
125
|
-
|
|
126
|
-
it('replicateData', async () => {
|
|
127
|
-
const request = {
|
|
128
|
-
entry: DATA_ENTRY
|
|
129
|
-
}
|
|
130
|
-
await storeRpcLocal.replicateData(request as any, { incomingSourceDescriptor: createMockPeerDescriptor() } as any)
|
|
131
|
-
expect(setAllEntriesAsStale).toHaveBeenCalledTimes(1)
|
|
132
|
-
// Wait for setImmediate
|
|
133
|
-
await wait(50)
|
|
134
|
-
expect(replicateDataToContact).toHaveBeenCalledTimes(1)
|
|
135
|
-
})
|
|
136
|
-
|
|
137
|
-
})
|
|
138
|
-
|
|
139
|
-
describe('data was not stored', () => {
|
|
140
|
-
|
|
141
|
-
beforeEach(() => {
|
|
142
|
-
const localPeerDescriptor = getNodeCloseToData(1)
|
|
143
|
-
storeRpcLocal = new StoreRpcLocal({
|
|
144
|
-
localDataStore: {
|
|
145
|
-
storeEntry: () => false,
|
|
146
|
-
setAllEntriesAsStale
|
|
147
|
-
} as any,
|
|
148
|
-
localPeerDescriptor,
|
|
149
|
-
replicateDataToContact,
|
|
150
|
-
getStorers: () => getClosestNodes(toDhtAddress(DATA_ENTRY.key), ALL_NODES)
|
|
151
|
-
})
|
|
152
|
-
})
|
|
153
|
-
|
|
154
|
-
it('replicateData', async () => {
|
|
155
|
-
const request = {
|
|
156
|
-
entry: DATA_ENTRY
|
|
157
|
-
}
|
|
158
|
-
await storeRpcLocal.replicateData(request as any, { incomingSourceDescriptor: createMockPeerDescriptor() } as any)
|
|
159
|
-
expect(setAllEntriesAsStale).toHaveBeenCalledTimes(0)
|
|
160
|
-
// Wait for setImmediate
|
|
161
|
-
await wait(50)
|
|
162
|
-
expect(replicateDataToContact).toHaveBeenCalledTimes(0)
|
|
163
|
-
})
|
|
164
|
-
|
|
165
|
-
})
|
|
166
|
-
|
|
167
|
-
})
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { waitForEvent3 } from '@streamr/utils'
|
|
2
|
-
import { NodeWebrtcConnection } from '../../src/connection/webrtc/NodeWebrtcConnection'
|
|
3
|
-
import { createMockPeerDescriptor } from '../utils/utils'
|
|
4
|
-
import { ConnectionEvents } from '../../src/connection/IConnection'
|
|
5
|
-
|
|
6
|
-
describe('WebrtcConnection', () => {
|
|
7
|
-
|
|
8
|
-
let connection: NodeWebrtcConnection
|
|
9
|
-
|
|
10
|
-
beforeEach(() => {
|
|
11
|
-
const peerDescriptor = createMockPeerDescriptor()
|
|
12
|
-
connection = new NodeWebrtcConnection({
|
|
13
|
-
remotePeerDescriptor: peerDescriptor
|
|
14
|
-
})
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
afterEach(() => {
|
|
18
|
-
connection.close(true)
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
it('Disconnects early if remote descriptor is not set', async () => {
|
|
22
|
-
connection.start(true)
|
|
23
|
-
await waitForEvent3<ConnectionEvents>(connection as any, 'disconnected', 5001, (_graceful: boolean, _code: number, reason: string) => {
|
|
24
|
-
expect(reason).toBe('timed out due to remote descriptor not being set')
|
|
25
|
-
return true
|
|
26
|
-
})
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
})
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { WebrtcConnector } from '../../src/connection/webrtc/WebrtcConnector'
|
|
2
|
-
import { MockConnection } from '../utils/mock/MockConnection'
|
|
3
|
-
import { MockTransport } from '../utils/mock/MockTransport'
|
|
4
|
-
import { createMockPeerDescriptor } from '../utils/utils'
|
|
5
|
-
|
|
6
|
-
describe('WebrtcConnector', () => {
|
|
7
|
-
|
|
8
|
-
let connector: WebrtcConnector
|
|
9
|
-
|
|
10
|
-
beforeEach(() => {
|
|
11
|
-
|
|
12
|
-
connector = new WebrtcConnector({
|
|
13
|
-
transport: new MockTransport()
|
|
14
|
-
} as any)
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
afterEach(() => {
|
|
18
|
-
connector.stop()
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
describe('Connect', () => {
|
|
22
|
-
|
|
23
|
-
it('Returns existing connecting connection', () => {
|
|
24
|
-
connector.setLocalPeerDescriptor(createMockPeerDescriptor())
|
|
25
|
-
const remotePeerDescriptor = createMockPeerDescriptor()
|
|
26
|
-
const firstConnection = connector.connect(remotePeerDescriptor, false)
|
|
27
|
-
const secondConnection = connector.connect(remotePeerDescriptor, false)
|
|
28
|
-
expect(firstConnection).toEqual(secondConnection)
|
|
29
|
-
firstConnection.close(false)
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
it('Disconnected event removes connecting connection', () => {
|
|
33
|
-
connector.setLocalPeerDescriptor(createMockPeerDescriptor())
|
|
34
|
-
const remotePeerDescriptor = createMockPeerDescriptor()
|
|
35
|
-
const firstConnection = connector.connect(remotePeerDescriptor, false)
|
|
36
|
-
firstConnection.emit('disconnected', false)
|
|
37
|
-
const secondConnection = connector.connect(remotePeerDescriptor, false)
|
|
38
|
-
expect(firstConnection).not.toEqual(secondConnection)
|
|
39
|
-
firstConnection.close(false)
|
|
40
|
-
secondConnection.close(false)
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
it('Connected event removes connecting connection', () => {
|
|
44
|
-
connector.setLocalPeerDescriptor(createMockPeerDescriptor())
|
|
45
|
-
const remotePeerDescriptor = createMockPeerDescriptor()
|
|
46
|
-
const firstConnection = connector.connect(remotePeerDescriptor, false)
|
|
47
|
-
firstConnection.onHandshakeCompleted(new MockConnection())
|
|
48
|
-
const secondConnection = connector.connect(remotePeerDescriptor, false)
|
|
49
|
-
expect(firstConnection).not.toEqual(secondConnection)
|
|
50
|
-
firstConnection.close(false)
|
|
51
|
-
secondConnection.close(false)
|
|
52
|
-
})
|
|
53
|
-
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
})
|