@streamr/trackerless-network 100.0.0-testnet-three.0 → 100.0.0-testnet-three.1
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/logic/RandomGraphNode.js +1 -0
- package/dist/src/logic/RandomGraphNode.js.map +1 -1
- package/dist/src/logic/createRandomGraphNode.js +2 -1
- package/dist/src/logic/createRandomGraphNode.js.map +1 -1
- package/dist/src/logic/inspect/Inspector.d.ts +3 -0
- package/dist/src/logic/inspect/Inspector.js +8 -1
- package/dist/src/logic/inspect/Inspector.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/NeighborUpdateManager.d.ts +1 -0
- package/dist/src/logic/neighbor-discovery/NeighborUpdateManager.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/NeighborUpdateRpcLocal.d.ts +3 -0
- package/dist/src/logic/neighbor-discovery/NeighborUpdateRpcLocal.js +30 -20
- package/dist/src/logic/neighbor-discovery/NeighborUpdateRpcLocal.js.map +1 -1
- package/dist/src/logic/temporary-connection/TemporaryConnectionRpcLocal.d.ts +3 -1
- package/dist/src/logic/temporary-connection/TemporaryConnectionRpcLocal.js +5 -0
- package/dist/src/logic/temporary-connection/TemporaryConnectionRpcLocal.js.map +1 -1
- package/dist/src/logic/temporary-connection/TemporaryConnectionRpcRemote.d.ts +1 -0
- package/dist/src/logic/temporary-connection/TemporaryConnectionRpcRemote.js +11 -0
- package/dist/src/logic/temporary-connection/TemporaryConnectionRpcRemote.js.map +1 -1
- package/dist/src/proto/google/protobuf/any.js +8 -8
- package/dist/src/proto/google/protobuf/any.js.map +1 -1
- package/dist/src/proto/google/protobuf/empty.js +2 -4
- package/dist/src/proto/google/protobuf/empty.js.map +1 -1
- package/dist/src/proto/google/protobuf/timestamp.js +10 -10
- package/dist/src/proto/google/protobuf/timestamp.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.d.ts +4 -0
- package/dist/src/proto/packages/dht/protos/DhtRpc.js +2 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +1 -1
- package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.client.d.ts +9 -0
- package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.client.js +7 -0
- package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.client.js.map +1 -1
- package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.d.ts +12 -0
- package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.js +13 -2
- package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.js.map +1 -1
- package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.server.d.ts +5 -0
- package/package.json +6 -6
- package/protos/NetworkRpc.proto +4 -0
- package/src/logic/RandomGraphNode.ts +3 -0
- package/src/logic/createRandomGraphNode.ts +2 -1
- package/src/logic/inspect/Inspector.ts +15 -1
- package/src/logic/neighbor-discovery/NeighborUpdateManager.ts +1 -0
- package/src/logic/neighbor-discovery/NeighborUpdateRpcLocal.ts +38 -26
- package/src/logic/temporary-connection/TemporaryConnectionRpcLocal.ts +12 -1
- package/src/logic/temporary-connection/TemporaryConnectionRpcRemote.ts +11 -0
- package/src/proto/google/protobuf/any.ts +4 -4
- package/src/proto/google/protobuf/empty.ts +2 -4
- package/src/proto/google/protobuf/timestamp.ts +4 -4
- package/src/proto/packages/dht/protos/DhtRpc.ts +6 -1
- package/src/proto/packages/trackerless-network/protos/NetworkRpc.client.ts +12 -0
- package/src/proto/packages/trackerless-network/protos/NetworkRpc.server.ts +5 -0
- package/src/proto/packages/trackerless-network/protos/NetworkRpc.ts +17 -1
- package/test/unit/NeighborUpdateRpcLocal.test.ts +125 -0
- package/test/unit/TemporaryConnectionRpcLocal.test.ts +32 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// @generated by protobuf-ts 2.9.
|
|
1
|
+
// @generated by protobuf-ts 2.9.3 with parameter server_generic,generate_dependencies,long_type_number
|
|
2
2
|
// @generated from protobuf file "google/protobuf/timestamp.proto" (package "google.protobuf", syntax proto3)
|
|
3
3
|
// tslint:disable
|
|
4
4
|
//
|
|
@@ -40,7 +40,6 @@ import type { IBinaryReader } from "@protobuf-ts/runtime";
|
|
|
40
40
|
import { UnknownFieldHandler } from "@protobuf-ts/runtime";
|
|
41
41
|
import type { PartialMessage } from "@protobuf-ts/runtime";
|
|
42
42
|
import { reflectionMergePartial } from "@protobuf-ts/runtime";
|
|
43
|
-
import { MESSAGE_TYPE } from "@protobuf-ts/runtime";
|
|
44
43
|
import { typeofJsonValue } from "@protobuf-ts/runtime";
|
|
45
44
|
import type { JsonValue } from "@protobuf-ts/runtime";
|
|
46
45
|
import type { JsonReadOptions } from "@protobuf-ts/runtime";
|
|
@@ -234,8 +233,9 @@ class Timestamp$Type extends MessageType<Timestamp> {
|
|
|
234
233
|
return target;
|
|
235
234
|
}
|
|
236
235
|
create(value?: PartialMessage<Timestamp>): Timestamp {
|
|
237
|
-
const message =
|
|
238
|
-
|
|
236
|
+
const message = globalThis.Object.create((this.messagePrototype!));
|
|
237
|
+
message.seconds = 0;
|
|
238
|
+
message.nanos = 0;
|
|
239
239
|
if (value !== undefined)
|
|
240
240
|
reflectionMergePartial<Timestamp>(this, message, value);
|
|
241
241
|
return message;
|
|
@@ -339,6 +339,10 @@ export interface ConnectivityResponse {
|
|
|
339
339
|
* @generated from protobuf field: uint32 ipAddress = 4;
|
|
340
340
|
*/
|
|
341
341
|
ipAddress: number;
|
|
342
|
+
/**
|
|
343
|
+
* @generated from protobuf field: string version = 5;
|
|
344
|
+
*/
|
|
345
|
+
version: string;
|
|
342
346
|
}
|
|
343
347
|
/**
|
|
344
348
|
* @generated from protobuf message dht.HandshakeRequest
|
|
@@ -943,7 +947,8 @@ class ConnectivityResponse$Type extends MessageType$<ConnectivityResponse> {
|
|
|
943
947
|
{ no: 1, name: "host", kind: "scalar", T: 9 /*ScalarType.STRING*/ },
|
|
944
948
|
{ no: 2, name: "natType", kind: "scalar", T: 9 /*ScalarType.STRING*/ },
|
|
945
949
|
{ no: 3, name: "websocket", kind: "message", T: () => ConnectivityMethod },
|
|
946
|
-
{ no: 4, name: "ipAddress", kind: "scalar", T: 13 /*ScalarType.UINT32*/ }
|
|
950
|
+
{ no: 4, name: "ipAddress", kind: "scalar", T: 13 /*ScalarType.UINT32*/ },
|
|
951
|
+
{ no: 5, name: "version", kind: "scalar", T: 9 /*ScalarType.STRING*/ }
|
|
947
952
|
]);
|
|
948
953
|
}
|
|
949
954
|
}
|
|
@@ -5,6 +5,7 @@ import { NodeInfoRpc } from "./NetworkRpc";
|
|
|
5
5
|
import type { NodeInfoResponse } from "./NetworkRpc";
|
|
6
6
|
import type { NodeInfoRequest } from "./NetworkRpc";
|
|
7
7
|
import { TemporaryConnectionRpc } from "./NetworkRpc";
|
|
8
|
+
import type { CloseTemporaryConnection } from "./NetworkRpc";
|
|
8
9
|
import type { TemporaryConnectionResponse } from "./NetworkRpc";
|
|
9
10
|
import type { TemporaryConnectionRequest } from "./NetworkRpc";
|
|
10
11
|
import { NeighborUpdateRpc } from "./NetworkRpc";
|
|
@@ -160,6 +161,10 @@ export interface ITemporaryConnectionRpcClient {
|
|
|
160
161
|
* @generated from protobuf rpc: openConnection(TemporaryConnectionRequest) returns (TemporaryConnectionResponse);
|
|
161
162
|
*/
|
|
162
163
|
openConnection(input: TemporaryConnectionRequest, options?: RpcOptions): UnaryCall<TemporaryConnectionRequest, TemporaryConnectionResponse>;
|
|
164
|
+
/**
|
|
165
|
+
* @generated from protobuf rpc: closeConnection(CloseTemporaryConnection) returns (google.protobuf.Empty);
|
|
166
|
+
*/
|
|
167
|
+
closeConnection(input: CloseTemporaryConnection, options?: RpcOptions): UnaryCall<CloseTemporaryConnection, Empty>;
|
|
163
168
|
}
|
|
164
169
|
/**
|
|
165
170
|
* @generated from protobuf service TemporaryConnectionRpc
|
|
@@ -177,6 +182,13 @@ export class TemporaryConnectionRpcClient implements ITemporaryConnectionRpcClie
|
|
|
177
182
|
const method = this.methods[0], opt = this._transport.mergeOptions(options);
|
|
178
183
|
return stackIntercept<TemporaryConnectionRequest, TemporaryConnectionResponse>("unary", this._transport, method, opt, input);
|
|
179
184
|
}
|
|
185
|
+
/**
|
|
186
|
+
* @generated from protobuf rpc: closeConnection(CloseTemporaryConnection) returns (google.protobuf.Empty);
|
|
187
|
+
*/
|
|
188
|
+
closeConnection(input: CloseTemporaryConnection, options?: RpcOptions): UnaryCall<CloseTemporaryConnection, Empty> {
|
|
189
|
+
const method = this.methods[1], opt = this._transport.mergeOptions(options);
|
|
190
|
+
return stackIntercept<CloseTemporaryConnection, Empty>("unary", this._transport, method, opt, input);
|
|
191
|
+
}
|
|
180
192
|
}
|
|
181
193
|
/**
|
|
182
194
|
* @generated from protobuf service NodeInfoRpc
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// tslint:disable
|
|
4
4
|
import { NodeInfoResponse } from "./NetworkRpc";
|
|
5
5
|
import { NodeInfoRequest } from "./NetworkRpc";
|
|
6
|
+
import { CloseTemporaryConnection } from "./NetworkRpc";
|
|
6
7
|
import { TemporaryConnectionResponse } from "./NetworkRpc";
|
|
7
8
|
import { TemporaryConnectionRequest } from "./NetworkRpc";
|
|
8
9
|
import { NeighborUpdate } from "./NetworkRpc";
|
|
@@ -68,6 +69,10 @@ export interface ITemporaryConnectionRpc<T = ServerCallContext> {
|
|
|
68
69
|
* @generated from protobuf rpc: openConnection(TemporaryConnectionRequest) returns (TemporaryConnectionResponse);
|
|
69
70
|
*/
|
|
70
71
|
openConnection(request: TemporaryConnectionRequest, context: T): Promise<TemporaryConnectionResponse>;
|
|
72
|
+
/**
|
|
73
|
+
* @generated from protobuf rpc: closeConnection(CloseTemporaryConnection) returns (google.protobuf.Empty);
|
|
74
|
+
*/
|
|
75
|
+
closeConnection(request: CloseTemporaryConnection, context: T): Promise<Empty>;
|
|
71
76
|
}
|
|
72
77
|
/**
|
|
73
78
|
* @generated from protobuf service NodeInfoRpc
|
|
@@ -273,6 +273,11 @@ export interface TemporaryConnectionResponse {
|
|
|
273
273
|
*/
|
|
274
274
|
accepted: boolean;
|
|
275
275
|
}
|
|
276
|
+
/**
|
|
277
|
+
* @generated from protobuf message CloseTemporaryConnection
|
|
278
|
+
*/
|
|
279
|
+
export interface CloseTemporaryConnection {
|
|
280
|
+
}
|
|
276
281
|
/**
|
|
277
282
|
* @generated from protobuf message StreamPartitionInfo
|
|
278
283
|
*/
|
|
@@ -616,6 +621,16 @@ class TemporaryConnectionResponse$Type extends MessageType<TemporaryConnectionRe
|
|
|
616
621
|
*/
|
|
617
622
|
export const TemporaryConnectionResponse = new TemporaryConnectionResponse$Type();
|
|
618
623
|
// @generated message type with reflection information, may provide speed optimized methods
|
|
624
|
+
class CloseTemporaryConnection$Type extends MessageType<CloseTemporaryConnection> {
|
|
625
|
+
constructor() {
|
|
626
|
+
super("CloseTemporaryConnection", []);
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
/**
|
|
630
|
+
* @generated MessageType for protobuf message CloseTemporaryConnection
|
|
631
|
+
*/
|
|
632
|
+
export const CloseTemporaryConnection = new CloseTemporaryConnection$Type();
|
|
633
|
+
// @generated message type with reflection information, may provide speed optimized methods
|
|
619
634
|
class StreamPartitionInfo$Type extends MessageType<StreamPartitionInfo> {
|
|
620
635
|
constructor() {
|
|
621
636
|
super("StreamPartitionInfo", [
|
|
@@ -696,7 +711,8 @@ export const NeighborUpdateRpc = new ServiceType("NeighborUpdateRpc", [
|
|
|
696
711
|
* @generated ServiceType for protobuf service TemporaryConnectionRpc
|
|
697
712
|
*/
|
|
698
713
|
export const TemporaryConnectionRpc = new ServiceType("TemporaryConnectionRpc", [
|
|
699
|
-
{ name: "openConnection", options: {}, I: TemporaryConnectionRequest, O: TemporaryConnectionResponse }
|
|
714
|
+
{ name: "openConnection", options: {}, I: TemporaryConnectionRequest, O: TemporaryConnectionResponse },
|
|
715
|
+
{ name: "closeConnection", options: {}, I: CloseTemporaryConnection, O: Empty }
|
|
700
716
|
]);
|
|
701
717
|
/**
|
|
702
718
|
* @generated ServiceType for protobuf service NodeInfoRpc
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { ListeningRpcCommunicator, getNodeIdFromPeerDescriptor } from '@streamr/dht'
|
|
2
|
+
import { NeighborFinder } from '../../src/logic/neighbor-discovery/NeighborFinder'
|
|
3
|
+
import { NeighborUpdateRpcLocal } from '../../src/logic/neighbor-discovery/NeighborUpdateRpcLocal'
|
|
4
|
+
import { createMockPeerDescriptor } from '../utils/utils'
|
|
5
|
+
import { NodeList } from '../../src/logic/NodeList'
|
|
6
|
+
import { StreamPartIDUtils } from '@streamr/protocol'
|
|
7
|
+
import { MockTransport } from '../utils/mock/Transport'
|
|
8
|
+
import { DeliveryRpcClient } from '../../src/proto/packages/trackerless-network/protos/NetworkRpc.client'
|
|
9
|
+
import { DeliveryRpcRemote } from '../../src/logic/DeliveryRpcRemote'
|
|
10
|
+
import { range } from 'lodash'
|
|
11
|
+
|
|
12
|
+
describe('NeighborUpdateRpcLocal', () => {
|
|
13
|
+
|
|
14
|
+
const streamPartId = StreamPartIDUtils.parse('stream#0')
|
|
15
|
+
const localPeerDescriptor = createMockPeerDescriptor()
|
|
16
|
+
const neighborCount = 4
|
|
17
|
+
|
|
18
|
+
let rpcLocal: NeighborUpdateRpcLocal
|
|
19
|
+
let neighbors: NodeList
|
|
20
|
+
let nearbyNodeView: NodeList
|
|
21
|
+
let neighborFinder: NeighborFinder
|
|
22
|
+
let rpcCommunicator: ListeningRpcCommunicator
|
|
23
|
+
|
|
24
|
+
const addNeighbors = (count: number) => {
|
|
25
|
+
for (let i = 0; i < count; i++) {
|
|
26
|
+
neighbors.add(new DeliveryRpcRemote(
|
|
27
|
+
localPeerDescriptor,
|
|
28
|
+
createMockPeerDescriptor(),
|
|
29
|
+
rpcCommunicator,
|
|
30
|
+
DeliveryRpcClient
|
|
31
|
+
))
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
beforeEach(() => {
|
|
36
|
+
rpcCommunicator = new ListeningRpcCommunicator('mock', new MockTransport())
|
|
37
|
+
neighbors = new NodeList(getNodeIdFromPeerDescriptor(localPeerDescriptor), neighborCount + 1)
|
|
38
|
+
nearbyNodeView = new NodeList(getNodeIdFromPeerDescriptor(localPeerDescriptor), neighborCount)
|
|
39
|
+
neighborFinder = {
|
|
40
|
+
start: jest.fn()
|
|
41
|
+
} as any
|
|
42
|
+
|
|
43
|
+
rpcLocal = new NeighborUpdateRpcLocal({
|
|
44
|
+
localPeerDescriptor,
|
|
45
|
+
neighbors,
|
|
46
|
+
nearbyNodeView,
|
|
47
|
+
neighborFinder,
|
|
48
|
+
streamPartId,
|
|
49
|
+
rpcCommunicator,
|
|
50
|
+
neighborCount
|
|
51
|
+
})
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
afterEach(() => {
|
|
55
|
+
rpcCommunicator.destroy()
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
it('response contains neighbor list of expected size', async () => {
|
|
59
|
+
addNeighbors(neighborCount)
|
|
60
|
+
const res = await rpcLocal.neighborUpdate({
|
|
61
|
+
streamPartId,
|
|
62
|
+
neighborDescriptors: [localPeerDescriptor],
|
|
63
|
+
removeMe: false
|
|
64
|
+
}, { incomingSourceDescriptor: createMockPeerDescriptor() } as any)
|
|
65
|
+
expect(res.neighborDescriptors.length).toEqual(neighborCount)
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
it('updates contacts based on callers neighbors', async () => {
|
|
69
|
+
addNeighbors(neighborCount)
|
|
70
|
+
expect(nearbyNodeView.size()).toEqual(0)
|
|
71
|
+
await rpcLocal.neighborUpdate({
|
|
72
|
+
streamPartId,
|
|
73
|
+
neighborDescriptors: range(neighborCount).map(() => createMockPeerDescriptor()),
|
|
74
|
+
removeMe: false
|
|
75
|
+
}, { incomingSourceDescriptor: createMockPeerDescriptor() } as any)
|
|
76
|
+
expect(nearbyNodeView.size()).toEqual(4)
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
it('does not ask to be removed if caller is a neighbor', async () => {
|
|
80
|
+
const caller = createMockPeerDescriptor()
|
|
81
|
+
const neighbor = new DeliveryRpcRemote(
|
|
82
|
+
localPeerDescriptor,
|
|
83
|
+
caller,
|
|
84
|
+
rpcCommunicator,
|
|
85
|
+
DeliveryRpcClient
|
|
86
|
+
)
|
|
87
|
+
neighbors.add(neighbor)
|
|
88
|
+
const res = await rpcLocal.neighborUpdate({
|
|
89
|
+
streamPartId,
|
|
90
|
+
neighborDescriptors: [localPeerDescriptor],
|
|
91
|
+
removeMe: false
|
|
92
|
+
}, { incomingSourceDescriptor: caller } as any)
|
|
93
|
+
expect(res.removeMe).toEqual(false)
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
it('asks to be removed if caller is not a neighbor', async () => {
|
|
97
|
+
const caller = createMockPeerDescriptor()
|
|
98
|
+
const res = await rpcLocal.neighborUpdate({
|
|
99
|
+
streamPartId,
|
|
100
|
+
neighborDescriptors: [localPeerDescriptor],
|
|
101
|
+
removeMe: false
|
|
102
|
+
}, { incomingSourceDescriptor: caller } as any)
|
|
103
|
+
expect(res.removeMe).toEqual(true)
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
it('asks to be removed if caller is a neighbor and both have too many neighbors', async () => {
|
|
107
|
+
const caller = createMockPeerDescriptor()
|
|
108
|
+
const neighbor = new DeliveryRpcRemote(
|
|
109
|
+
localPeerDescriptor,
|
|
110
|
+
caller,
|
|
111
|
+
rpcCommunicator,
|
|
112
|
+
DeliveryRpcClient
|
|
113
|
+
)
|
|
114
|
+
neighbors.add(neighbor)
|
|
115
|
+
addNeighbors(neighborCount)
|
|
116
|
+
const res = await rpcLocal.neighborUpdate({
|
|
117
|
+
streamPartId,
|
|
118
|
+
neighborDescriptors: [localPeerDescriptor, ...range(neighborCount).map(() => createMockPeerDescriptor())],
|
|
119
|
+
removeMe: false
|
|
120
|
+
}, { incomingSourceDescriptor: caller } as any)
|
|
121
|
+
expect(res.removeMe).toEqual(true)
|
|
122
|
+
expect(neighbors.has(getNodeIdFromPeerDescriptor(caller))).toEqual(false)
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
})
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { TemporaryConnectionRpcLocal } from '../../src/logic/temporary-connection/TemporaryConnectionRpcLocal'
|
|
2
|
+
import { MockTransport } from '../utils/mock/Transport'
|
|
3
|
+
import { createMockPeerDescriptor } from '../utils/utils'
|
|
4
|
+
import { ListeningRpcCommunicator, getDhtAddressFromRaw } from '@streamr/dht'
|
|
5
|
+
|
|
6
|
+
describe('TemporaryConnectionRpcLocal', () => {
|
|
7
|
+
|
|
8
|
+
const peerDescriptor = createMockPeerDescriptor()
|
|
9
|
+
let rpcCommunicator: ListeningRpcCommunicator
|
|
10
|
+
let rpcLocal: TemporaryConnectionRpcLocal
|
|
11
|
+
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
rpcCommunicator = new ListeningRpcCommunicator('mock', new MockTransport())
|
|
14
|
+
rpcLocal = new TemporaryConnectionRpcLocal({
|
|
15
|
+
localPeerDescriptor: peerDescriptor,
|
|
16
|
+
rpcCommunicator
|
|
17
|
+
})
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
afterEach(() => {
|
|
21
|
+
rpcCommunicator.destroy()
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
it('Open and Close Connection', async () => {
|
|
25
|
+
const caller = createMockPeerDescriptor()
|
|
26
|
+
await rpcLocal.openConnection({}, { incomingSourceDescriptor: caller } as any)
|
|
27
|
+
expect(rpcLocal.getNodes().get(getDhtAddressFromRaw(caller.nodeId))).toBeDefined()
|
|
28
|
+
await rpcLocal.closeConnection({}, { incomingSourceDescriptor: caller } as any)
|
|
29
|
+
expect(rpcLocal.getNodes().get(getDhtAddressFromRaw(caller.nodeId))).toBeUndefined()
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
})
|