@streamr/trackerless-network 100.0.0-testnet-three.2 → 100.0.0-testnet-three.4
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/README.md +57 -0
- package/dist/package.json +55 -0
- package/dist/src/NetworkStack.js +7 -2
- package/dist/src/NetworkStack.js.map +1 -1
- package/dist/src/exports.d.ts +2 -1
- package/dist/src/exports.js +4 -1
- package/dist/src/exports.js.map +1 -1
- package/dist/src/logic/Layer1Node.d.ts +2 -2
- package/dist/src/logic/RandomGraphNode.d.ts +4 -4
- package/dist/src/logic/RandomGraphNode.js +11 -11
- package/dist/src/logic/RandomGraphNode.js.map +1 -1
- package/dist/src/logic/createRandomGraphNode.js +6 -2
- package/dist/src/logic/createRandomGraphNode.js.map +1 -1
- package/dist/src/logic/inspect/InspectSession.d.ts +1 -0
- package/dist/src/logic/inspect/InspectSession.js +3 -0
- package/dist/src/logic/inspect/InspectSession.js.map +1 -1
- package/dist/src/logic/inspect/Inspector.js +1 -1
- package/dist/src/logic/inspect/Inspector.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/Handshaker.d.ts +1 -1
- package/dist/src/logic/neighbor-discovery/Handshaker.js +17 -15
- package/dist/src/logic/neighbor-discovery/Handshaker.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/NeighborUpdateManager.d.ts +3 -1
- package/dist/src/logic/neighbor-discovery/NeighborUpdateManager.js +1 -0
- package/dist/src/logic/neighbor-discovery/NeighborUpdateManager.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/NeighborUpdateRpcLocal.d.ts +3 -1
- package/dist/src/logic/neighbor-discovery/NeighborUpdateRpcLocal.js +2 -1
- package/dist/src/logic/neighbor-discovery/NeighborUpdateRpcLocal.js.map +1 -1
- package/dist/src/logic/node-info/NodeInfoRpcLocal.js +3 -1
- package/dist/src/logic/node-info/NodeInfoRpcLocal.js.map +1 -1
- package/dist/src/logic/proxy/ProxyClient.js +8 -6
- package/dist/src/logic/proxy/ProxyClient.js.map +1 -1
- package/dist/src/logic/temporary-connection/TemporaryConnectionRpcLocal.d.ts +1 -0
- package/dist/src/logic/temporary-connection/TemporaryConnectionRpcLocal.js +3 -0
- package/dist/src/logic/temporary-connection/TemporaryConnectionRpcLocal.js.map +1 -1
- package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.d.ts +4 -0
- package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.js +2 -1
- package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.js.map +1 -1
- package/dist/test/utils/utils.d.ts +1 -2
- package/dist/test/utils/utils.js +2 -7
- package/dist/test/utils/utils.js.map +1 -1
- package/package.json +6 -6
- package/protos/NetworkRpc.proto +1 -0
- package/src/NetworkStack.ts +9 -3
- package/src/exports.ts +2 -1
- package/src/logic/Layer1Node.ts +2 -2
- package/src/logic/RandomGraphNode.ts +13 -13
- package/src/logic/createRandomGraphNode.ts +6 -2
- package/src/logic/inspect/InspectSession.ts +4 -0
- package/src/logic/inspect/Inspector.ts +1 -1
- package/src/logic/neighbor-discovery/Handshaker.ts +20 -15
- package/src/logic/neighbor-discovery/NeighborUpdateManager.ts +4 -1
- package/src/logic/neighbor-discovery/NeighborUpdateRpcLocal.ts +5 -2
- package/src/logic/node-info/NodeInfoRpcLocal.ts +3 -1
- package/src/logic/proxy/ProxyClient.ts +14 -7
- package/src/logic/temporary-connection/TemporaryConnectionRpcLocal.ts +4 -0
- package/src/proto/packages/trackerless-network/protos/NetworkRpc.ts +6 -1
- package/test/end-to-end/proxy-key-exchange.test.ts +2 -2
- package/test/end-to-end/random-graph-with-real-connections.test.ts +4 -6
- package/test/integration/Handshakes.test.ts +2 -1
- package/test/integration/NetworkNode.test.ts +4 -9
- package/test/integration/NodeInfoRpc.test.ts +2 -1
- package/test/integration/StreamrNode.test.ts +4 -16
- package/test/integration/joining-streams-on-offline-peers.test.ts +7 -31
- package/test/integration/stream-without-default-entrypoints.test.ts +2 -6
- package/test/unit/Handshaker.test.ts +2 -1
- package/test/unit/InspectSession.test.ts +3 -4
- package/test/unit/Inspector.test.ts +3 -3
- package/test/unit/NeighborFinder.test.ts +3 -3
- package/test/unit/NeighborUpdateRpcLocal.test.ts +20 -2
- package/test/unit/NodeList.test.ts +4 -3
- package/test/unit/RandomGraphNode.test.ts +5 -5
- package/test/utils/utils.ts +2 -8
- package/tsconfig.jest.json +2 -1
- package/tsconfig.node.json +2 -1
|
@@ -25,6 +25,7 @@ interface HandshakerConfig {
|
|
|
25
25
|
randomNodeView: NodeList
|
|
26
26
|
rpcCommunicator: ListeningRpcCommunicator
|
|
27
27
|
maxNeighborCount: number
|
|
28
|
+
ongoingHandshakes: Set<DhtAddress>
|
|
28
29
|
rpcRequestTimeout?: number
|
|
29
30
|
}
|
|
30
31
|
|
|
@@ -34,7 +35,6 @@ const PARALLEL_HANDSHAKE_COUNT = 2
|
|
|
34
35
|
|
|
35
36
|
export class Handshaker {
|
|
36
37
|
|
|
37
|
-
private readonly ongoingHandshakes: Set<DhtAddress> = new Set()
|
|
38
38
|
private config: HandshakerConfig
|
|
39
39
|
private readonly rpcLocal: IHandshakeRpc
|
|
40
40
|
|
|
@@ -44,7 +44,7 @@ export class Handshaker {
|
|
|
44
44
|
streamPartId: this.config.streamPartId,
|
|
45
45
|
neighbors: this.config.neighbors,
|
|
46
46
|
connectionLocker: this.config.connectionLocker,
|
|
47
|
-
ongoingHandshakes: this.ongoingHandshakes,
|
|
47
|
+
ongoingHandshakes: this.config.ongoingHandshakes,
|
|
48
48
|
ongoingInterleaves: new Set(),
|
|
49
49
|
maxNeighborCount: this.config.maxNeighborCount,
|
|
50
50
|
handshakeWithInterleaving: (target: PeerDescriptor, senderId: DhtAddress) => this.handshakeWithInterleaving(target, senderId),
|
|
@@ -59,10 +59,10 @@ export class Handshaker {
|
|
|
59
59
|
|
|
60
60
|
async attemptHandshakesOnContacts(excludedIds: DhtAddress[]): Promise<DhtAddress[]> {
|
|
61
61
|
// TODO use config option or named constant? or why the value 2?
|
|
62
|
-
if (this.config.neighbors.size() + this.ongoingHandshakes.size < this.config.maxNeighborCount - 2) {
|
|
62
|
+
if (this.config.neighbors.size() + this.config.ongoingHandshakes.size < this.config.maxNeighborCount - 2) {
|
|
63
63
|
logger.trace(`Attempting parallel handshakes with ${PARALLEL_HANDSHAKE_COUNT} targets`)
|
|
64
64
|
return this.selectParallelTargetsAndHandshake(excludedIds)
|
|
65
|
-
} else if (this.config.neighbors.size() + this.ongoingHandshakes.size < this.config.maxNeighborCount) {
|
|
65
|
+
} else if (this.config.neighbors.size() + this.config.ongoingHandshakes.size < this.config.maxNeighborCount) {
|
|
66
66
|
logger.trace(`Attempting handshake with new target`)
|
|
67
67
|
return this.selectNewTargetAndHandshake(excludedIds)
|
|
68
68
|
}
|
|
@@ -72,17 +72,22 @@ export class Handshaker {
|
|
|
72
72
|
private async selectParallelTargetsAndHandshake(excludedIds: DhtAddress[]): Promise<DhtAddress[]> {
|
|
73
73
|
const exclude = excludedIds.concat(this.config.neighbors.getIds())
|
|
74
74
|
const neighbors = this.selectParallelTargets(exclude)
|
|
75
|
-
neighbors.forEach((contact) => this.ongoingHandshakes.add(getNodeIdFromPeerDescriptor(contact.getPeerDescriptor())))
|
|
75
|
+
neighbors.forEach((contact) => this.config.ongoingHandshakes.add(getNodeIdFromPeerDescriptor(contact.getPeerDescriptor())))
|
|
76
76
|
return this.doParallelHandshakes(neighbors, exclude)
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
private selectParallelTargets(excludedIds: DhtAddress[]): HandshakeRpcRemote[] {
|
|
80
80
|
const neighbors = this.config.nearbyNodeView.getFirstAndLast(excludedIds)
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
81
|
+
const getExcludedFromRandomView = () => [
|
|
82
|
+
...excludedIds,
|
|
83
|
+
...neighbors.map((neighbor) => getNodeIdFromPeerDescriptor(neighbor.getPeerDescriptor()))
|
|
84
|
+
]
|
|
85
|
+
while (
|
|
86
|
+
neighbors.length < PARALLEL_HANDSHAKE_COUNT
|
|
87
|
+
&& this.config.randomNodeView.size(getExcludedFromRandomView()) > 0
|
|
88
|
+
) {
|
|
89
|
+
const random = this.config.randomNodeView.getRandom(getExcludedFromRandomView())!
|
|
90
|
+
neighbors.push(random)
|
|
86
91
|
}
|
|
87
92
|
return neighbors.map((neighbor) => this.createRpcRemote(neighbor.getPeerDescriptor()))
|
|
88
93
|
}
|
|
@@ -118,7 +123,7 @@ export class Handshaker {
|
|
|
118
123
|
|
|
119
124
|
private async handshakeWithTarget(neighbor: HandshakeRpcRemote, concurrentNodeId?: DhtAddress): Promise<boolean> {
|
|
120
125
|
const targetNodeId = getNodeIdFromPeerDescriptor(neighbor.getPeerDescriptor())
|
|
121
|
-
this.ongoingHandshakes.add(targetNodeId)
|
|
126
|
+
this.config.ongoingHandshakes.add(targetNodeId)
|
|
122
127
|
const result = await neighbor.handshake(
|
|
123
128
|
this.config.streamPartId,
|
|
124
129
|
this.config.neighbors.getIds(),
|
|
@@ -131,14 +136,14 @@ export class Handshaker {
|
|
|
131
136
|
if (result.interleaveTargetDescriptor) {
|
|
132
137
|
await this.handshakeWithInterleaving(result.interleaveTargetDescriptor, targetNodeId)
|
|
133
138
|
}
|
|
134
|
-
this.ongoingHandshakes.delete(targetNodeId)
|
|
139
|
+
this.config.ongoingHandshakes.delete(targetNodeId)
|
|
135
140
|
return result.accepted
|
|
136
141
|
}
|
|
137
142
|
|
|
138
143
|
private async handshakeWithInterleaving(target: PeerDescriptor, interleaveSourceId: DhtAddress): Promise<boolean> {
|
|
139
144
|
const neighbor = this.createRpcRemote(target)
|
|
140
145
|
const targetNodeId = getNodeIdFromPeerDescriptor(neighbor.getPeerDescriptor())
|
|
141
|
-
this.ongoingHandshakes.add(targetNodeId)
|
|
146
|
+
this.config.ongoingHandshakes.add(targetNodeId)
|
|
142
147
|
const result = await neighbor.handshake(
|
|
143
148
|
this.config.streamPartId,
|
|
144
149
|
this.config.neighbors.getIds(),
|
|
@@ -149,7 +154,7 @@ export class Handshaker {
|
|
|
149
154
|
this.config.neighbors.add(this.createDeliveryRpcRemote(neighbor.getPeerDescriptor()))
|
|
150
155
|
this.config.connectionLocker.lockConnection(neighbor.getPeerDescriptor(), this.config.streamPartId)
|
|
151
156
|
}
|
|
152
|
-
this.ongoingHandshakes.delete(targetNodeId)
|
|
157
|
+
this.config.ongoingHandshakes.delete(targetNodeId)
|
|
153
158
|
return result.accepted
|
|
154
159
|
}
|
|
155
160
|
|
|
@@ -174,7 +179,7 @@ export class Handshaker {
|
|
|
174
179
|
}
|
|
175
180
|
|
|
176
181
|
getOngoingHandshakes(): Set<DhtAddress> {
|
|
177
|
-
return this.ongoingHandshakes
|
|
182
|
+
return this.config.ongoingHandshakes
|
|
178
183
|
}
|
|
179
184
|
|
|
180
185
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { NeighborUpdate } from '../../proto/packages/trackerless-network/protos/NetworkRpc'
|
|
2
|
-
import { ListeningRpcCommunicator, PeerDescriptor, getNodeIdFromPeerDescriptor } from '@streamr/dht'
|
|
2
|
+
import { ConnectionLocker, DhtAddress, ListeningRpcCommunicator, PeerDescriptor, getNodeIdFromPeerDescriptor } from '@streamr/dht'
|
|
3
3
|
import { NeighborUpdateRpcClient } from '../../proto/packages/trackerless-network/protos/NetworkRpc.client'
|
|
4
4
|
import { Logger, scheduleAtInterval } from '@streamr/utils'
|
|
5
5
|
import { NeighborFinder } from './NeighborFinder'
|
|
@@ -13,10 +13,12 @@ interface NeighborUpdateManagerConfig {
|
|
|
13
13
|
neighbors: NodeList
|
|
14
14
|
nearbyNodeView: NodeList
|
|
15
15
|
neighborFinder: NeighborFinder
|
|
16
|
+
connectionLocker: ConnectionLocker
|
|
16
17
|
streamPartId: StreamPartID
|
|
17
18
|
rpcCommunicator: ListeningRpcCommunicator
|
|
18
19
|
neighborUpdateInterval: number
|
|
19
20
|
neighborTargetCount: number
|
|
21
|
+
ongoingHandshakes: Set<DhtAddress>
|
|
20
22
|
}
|
|
21
23
|
|
|
22
24
|
const logger = new Logger(module)
|
|
@@ -51,6 +53,7 @@ export class NeighborUpdateManager {
|
|
|
51
53
|
if (res.removeMe) {
|
|
52
54
|
const nodeId = getNodeIdFromPeerDescriptor(neighbor.getPeerDescriptor())
|
|
53
55
|
this.config.neighbors.remove(nodeId)
|
|
56
|
+
this.config.connectionLocker.unlockConnection(neighbor.getPeerDescriptor(), this.config.streamPartId)
|
|
54
57
|
this.config.neighborFinder.start([nodeId])
|
|
55
58
|
}
|
|
56
59
|
}))
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
|
|
2
|
-
import { DhtCallContext, ListeningRpcCommunicator, PeerDescriptor, getNodeIdFromPeerDescriptor } from '@streamr/dht'
|
|
2
|
+
import { ConnectionLocker, DhtAddress, DhtCallContext, ListeningRpcCommunicator, PeerDescriptor, getNodeIdFromPeerDescriptor } from '@streamr/dht'
|
|
3
3
|
import { NeighborUpdate } from '../../proto/packages/trackerless-network/protos/NetworkRpc'
|
|
4
4
|
import { DeliveryRpcClient } from '../../proto/packages/trackerless-network/protos/NetworkRpc.client'
|
|
5
5
|
import { INeighborUpdateRpc } from '../../proto/packages/trackerless-network/protos/NetworkRpc.server'
|
|
@@ -14,8 +14,10 @@ interface NeighborUpdateRpcLocalConfig {
|
|
|
14
14
|
neighbors: NodeList
|
|
15
15
|
nearbyNodeView: NodeList
|
|
16
16
|
neighborFinder: NeighborFinder
|
|
17
|
+
connectionLocker: ConnectionLocker
|
|
17
18
|
rpcCommunicator: ListeningRpcCommunicator
|
|
18
19
|
neighborTargetCount: number
|
|
20
|
+
ongoingHandshakes: Set<DhtAddress>
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
export class NeighborUpdateRpcLocal implements INeighborUpdateRpc {
|
|
@@ -55,7 +57,7 @@ export class NeighborUpdateRpcLocal implements INeighborUpdateRpc {
|
|
|
55
57
|
const senderPeerDescriptor = (context as DhtCallContext).incomingSourceDescriptor!
|
|
56
58
|
const senderId = getNodeIdFromPeerDescriptor(senderPeerDescriptor)
|
|
57
59
|
this.updateContacts(message.neighborDescriptors)
|
|
58
|
-
if (!this.config.neighbors.has(senderId)) {
|
|
60
|
+
if (!this.config.neighbors.has(senderId) && !this.config.ongoingHandshakes.has(senderId)) {
|
|
59
61
|
return this.createResponse(true)
|
|
60
62
|
} else {
|
|
61
63
|
const isOverNeighborCount = this.config.neighbors.size() > this.config.neighborTargetCount
|
|
@@ -67,6 +69,7 @@ export class NeighborUpdateRpcLocal implements INeighborUpdateRpc {
|
|
|
67
69
|
this.config.neighborFinder.start()
|
|
68
70
|
} else {
|
|
69
71
|
this.config.neighbors.remove(senderId)
|
|
72
|
+
this.config.connectionLocker.unlockConnection(senderPeerDescriptor, this.config.streamPartId)
|
|
70
73
|
}
|
|
71
74
|
return this.createResponse(isOverNeighborCount)
|
|
72
75
|
}
|
|
@@ -2,6 +2,7 @@ import { NodeInfoRequest, NodeInfoResponse } from '../../proto/packages/trackerl
|
|
|
2
2
|
import { INodeInfoRpc } from '../../proto/packages/trackerless-network/protos/NetworkRpc.server'
|
|
3
3
|
import { NetworkStack } from '../../NetworkStack'
|
|
4
4
|
import { ListeningRpcCommunicator } from '@streamr/dht'
|
|
5
|
+
import { version as localVersion } from '../../../package.json'
|
|
5
6
|
|
|
6
7
|
export const NODE_INFO_RPC_SERVICE_ID = 'system/node-info-rpc'
|
|
7
8
|
|
|
@@ -28,7 +29,8 @@ export class NodeInfoRpcLocal implements INodeInfoRpc {
|
|
|
28
29
|
connections: this.stack.getLayer0Node().getConnections(),
|
|
29
30
|
neighbors: this.stack.getLayer0Node().getNeighbors()
|
|
30
31
|
},
|
|
31
|
-
streamPartitions: this.stack.getStreamrNode().getNodeInfo()
|
|
32
|
+
streamPartitions: this.stack.getStreamrNode().getNodeInfo(),
|
|
33
|
+
version: localVersion
|
|
32
34
|
}
|
|
33
35
|
}
|
|
34
36
|
|
|
@@ -58,6 +58,11 @@ interface ProxyDefinition {
|
|
|
58
58
|
userId: EthereumAddress
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
+
interface ProxyConnection {
|
|
62
|
+
peerDescriptor: PeerDescriptor
|
|
63
|
+
direction: ProxyDirection
|
|
64
|
+
}
|
|
65
|
+
|
|
61
66
|
interface Events {
|
|
62
67
|
message: (message: StreamMessage) => void
|
|
63
68
|
}
|
|
@@ -73,7 +78,7 @@ export class ProxyClient extends EventEmitter<Events> {
|
|
|
73
78
|
private readonly config: ProxyClientConfig
|
|
74
79
|
private readonly duplicateDetectors: Map<string, DuplicateMessageDetector> = new Map()
|
|
75
80
|
private definition?: ProxyDefinition
|
|
76
|
-
private readonly connections: Map<DhtAddress,
|
|
81
|
+
private readonly connections: Map<DhtAddress, ProxyConnection> = new Map()
|
|
77
82
|
private readonly propagation: Propagation
|
|
78
83
|
private readonly neighbors: NodeList
|
|
79
84
|
private readonly abortController: AbortController
|
|
@@ -159,7 +164,7 @@ export class ProxyClient extends EventEmitter<Events> {
|
|
|
159
164
|
private getInvalidConnections(): DhtAddress[] {
|
|
160
165
|
return Array.from(this.connections.keys()).filter((id) => {
|
|
161
166
|
return !this.definition!.nodes.has(id)
|
|
162
|
-
|| this.definition!.direction !== this.connections.get(id)
|
|
167
|
+
|| this.definition!.direction !== this.connections.get(id)!.direction
|
|
163
168
|
})
|
|
164
169
|
}
|
|
165
170
|
|
|
@@ -183,7 +188,7 @@ export class ProxyClient extends EventEmitter<Events> {
|
|
|
183
188
|
const accepted = await rpcRemote.requestConnection(direction, userId)
|
|
184
189
|
if (accepted) {
|
|
185
190
|
this.config.connectionLocker.lockConnection(peerDescriptor, SERVICE_ID)
|
|
186
|
-
this.connections.set(nodeId, direction)
|
|
191
|
+
this.connections.set(nodeId, { peerDescriptor, direction })
|
|
187
192
|
const remote = new DeliveryRpcRemote(
|
|
188
193
|
this.config.localPeerDescriptor,
|
|
189
194
|
peerDescriptor,
|
|
@@ -216,13 +221,15 @@ export class ProxyClient extends EventEmitter<Events> {
|
|
|
216
221
|
})
|
|
217
222
|
const server = this.neighbors.get(nodeId)
|
|
218
223
|
server?.leaveStreamPartNotice(this.config.streamPartId, false)
|
|
219
|
-
this.removeConnection(nodeId)
|
|
224
|
+
this.removeConnection(this.connections.get(nodeId)!.peerDescriptor)
|
|
220
225
|
}
|
|
221
226
|
}
|
|
222
227
|
|
|
223
|
-
private removeConnection(
|
|
228
|
+
private removeConnection(peerDescriptor: PeerDescriptor): void {
|
|
229
|
+
const nodeId = getNodeIdFromPeerDescriptor(peerDescriptor)
|
|
224
230
|
this.connections.delete(nodeId)
|
|
225
231
|
this.neighbors.remove(nodeId)
|
|
232
|
+
this.config.connectionLocker.unlockConnection(peerDescriptor, SERVICE_ID)
|
|
226
233
|
}
|
|
227
234
|
|
|
228
235
|
broadcast(msg: StreamMessage, previousNode?: DhtAddress): void {
|
|
@@ -234,7 +241,7 @@ export class ProxyClient extends EventEmitter<Events> {
|
|
|
234
241
|
}
|
|
235
242
|
|
|
236
243
|
hasConnection(nodeId: DhtAddress, direction: ProxyDirection): boolean {
|
|
237
|
-
return this.connections.has(nodeId) && this.connections.get(nodeId) === direction
|
|
244
|
+
return this.connections.has(nodeId) && this.connections.get(nodeId)!.direction === direction
|
|
238
245
|
}
|
|
239
246
|
|
|
240
247
|
getDirection(): ProxyDirection {
|
|
@@ -245,7 +252,7 @@ export class ProxyClient extends EventEmitter<Events> {
|
|
|
245
252
|
const nodeId = getNodeIdFromPeerDescriptor(peerDescriptor)
|
|
246
253
|
if (this.connections.has(nodeId)) {
|
|
247
254
|
this.config.connectionLocker.unlockConnection(peerDescriptor, SERVICE_ID)
|
|
248
|
-
this.removeConnection(
|
|
255
|
+
this.removeConnection(peerDescriptor)
|
|
249
256
|
await retry(() => this.updateConnections(), 'updating proxy connections', this.abortController.signal)
|
|
250
257
|
}
|
|
251
258
|
}
|
|
@@ -32,6 +32,10 @@ export class TemporaryConnectionRpcLocal implements ITemporaryConnectionRpc {
|
|
|
32
32
|
return this.temporaryNodes
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
+
hasNode(node: DhtAddress): boolean {
|
|
36
|
+
return this.temporaryNodes.has(node)
|
|
37
|
+
}
|
|
38
|
+
|
|
35
39
|
removeNode(nodeId: DhtAddress): void {
|
|
36
40
|
this.temporaryNodes.remove(nodeId)
|
|
37
41
|
}
|
|
@@ -329,6 +329,10 @@ export interface NodeInfoResponse {
|
|
|
329
329
|
* @generated from protobuf field: optional ControlLayerInfo controlLayer = 3;
|
|
330
330
|
*/
|
|
331
331
|
controlLayer?: ControlLayerInfo;
|
|
332
|
+
/**
|
|
333
|
+
* @generated from protobuf field: string version = 4;
|
|
334
|
+
*/
|
|
335
|
+
version: string;
|
|
332
336
|
}
|
|
333
337
|
/**
|
|
334
338
|
* @generated from protobuf enum StreamMessageType
|
|
@@ -673,7 +677,8 @@ class NodeInfoResponse$Type extends MessageType<NodeInfoResponse> {
|
|
|
673
677
|
super("NodeInfoResponse", [
|
|
674
678
|
{ no: 1, name: "peerDescriptor", kind: "message", T: () => PeerDescriptor },
|
|
675
679
|
{ no: 2, name: "streamPartitions", kind: "message", repeat: 1 /*RepeatType.PACKED*/, T: () => StreamPartitionInfo },
|
|
676
|
-
{ no: 3, name: "controlLayer", kind: "message", T: () => ControlLayerInfo }
|
|
680
|
+
{ no: 3, name: "controlLayer", kind: "message", T: () => ControlLayerInfo },
|
|
681
|
+
{ no: 4, name: "version", kind: "scalar", T: 9 /*ScalarType.STRING*/ }
|
|
677
682
|
]);
|
|
678
683
|
}
|
|
679
684
|
}
|
|
@@ -47,7 +47,7 @@ describe('proxy group key exchange', () => {
|
|
|
47
47
|
proxyNode.stack.getStreamrNode()!.joinStreamPart(STREAM_PART_ID)
|
|
48
48
|
publisher = createNetworkNode({
|
|
49
49
|
layer0: {
|
|
50
|
-
entryPoints: [
|
|
50
|
+
entryPoints: [proxyNodeDescriptor],
|
|
51
51
|
peerDescriptor: publisherDescriptor,
|
|
52
52
|
}
|
|
53
53
|
})
|
|
@@ -55,7 +55,7 @@ describe('proxy group key exchange', () => {
|
|
|
55
55
|
|
|
56
56
|
subscriber = createNetworkNode({
|
|
57
57
|
layer0: {
|
|
58
|
-
entryPoints: [
|
|
58
|
+
entryPoints: [proxyNodeDescriptor],
|
|
59
59
|
peerDescriptor: subscriberDescriptor,
|
|
60
60
|
}
|
|
61
61
|
})
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { ConnectionManager, DhtNode, PeerDescriptor
|
|
1
|
+
import { ConnectionManager, DhtNode, PeerDescriptor } from '@streamr/dht'
|
|
2
2
|
import { RandomGraphNode } from '../../src/logic/RandomGraphNode'
|
|
3
3
|
import { waitForCondition } from '@streamr/utils'
|
|
4
|
-
import { createStreamMessage } from '../utils/utils'
|
|
4
|
+
import { createMockPeerDescriptor, createStreamMessage } from '../utils/utils'
|
|
5
5
|
import { createRandomGraphNode } from '../../src/logic/createRandomGraphNode'
|
|
6
6
|
import { StreamPartIDUtils } from '@streamr/protocol'
|
|
7
7
|
import { randomEthereumAddress } from '@streamr/test-utils'
|
|
@@ -10,11 +10,9 @@ import { Layer1Node } from '../../src/logic/Layer1Node'
|
|
|
10
10
|
|
|
11
11
|
describe('random graph with real connections', () => {
|
|
12
12
|
|
|
13
|
-
const epPeerDescriptor: PeerDescriptor = {
|
|
14
|
-
nodeId: Uint8Array.from([1, 2, 3]),
|
|
15
|
-
type: NodeType.NODEJS,
|
|
13
|
+
const epPeerDescriptor: PeerDescriptor = createMockPeerDescriptor({
|
|
16
14
|
websocket: { host: '127.0.0.1', port: 12221, tls: false }
|
|
17
|
-
}
|
|
15
|
+
})
|
|
18
16
|
|
|
19
17
|
const streamPartId = StreamPartIDUtils.parse('random-graph#0')
|
|
20
18
|
// Currently the nodes here are practically layer0 nodes acting as layer1 nodes, for the purpose of this test
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PeerDescriptor, Simulator, SimulatorTransport } from '@streamr/dht'
|
|
2
2
|
import {
|
|
3
3
|
ContentType,
|
|
4
4
|
EncryptionType,
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
} from '@streamr/protocol'
|
|
11
11
|
import { EthereumAddress, hexToBinary, utf8ToBinary, waitForCondition } from '@streamr/utils'
|
|
12
12
|
import { NetworkNode, createNetworkNode } from '../../src/NetworkNode'
|
|
13
|
+
import { createMockPeerDescriptor } from '../utils/utils'
|
|
13
14
|
|
|
14
15
|
const STREAM_PART_ID = StreamPartIDUtils.parse('test#0')
|
|
15
16
|
|
|
@@ -21,15 +22,9 @@ describe('NetworkNode', () => {
|
|
|
21
22
|
let node1: NetworkNode
|
|
22
23
|
let node2: NetworkNode
|
|
23
24
|
|
|
24
|
-
const pd1: PeerDescriptor =
|
|
25
|
-
nodeId: new Uint8Array([1, 2, 3]),
|
|
26
|
-
type: NodeType.NODEJS
|
|
27
|
-
}
|
|
25
|
+
const pd1: PeerDescriptor = createMockPeerDescriptor()
|
|
28
26
|
|
|
29
|
-
const pd2: PeerDescriptor =
|
|
30
|
-
nodeId: new Uint8Array([1, 1, 1]),
|
|
31
|
-
type: NodeType.NODEJS
|
|
32
|
-
}
|
|
27
|
+
const pd2: PeerDescriptor = createMockPeerDescriptor()
|
|
33
28
|
|
|
34
29
|
beforeEach(async () => {
|
|
35
30
|
const simulator = new Simulator()
|
|
@@ -95,7 +95,8 @@ describe('NetworkStack NodeInfoRpc', () => {
|
|
|
95
95
|
controlLayerNeighbors: [normalizePeerDescriptor(otherPeerDescriptor)],
|
|
96
96
|
deliveryLayerNeighbors: [normalizePeerDescriptor(otherPeerDescriptor)]
|
|
97
97
|
}
|
|
98
|
-
]
|
|
98
|
+
],
|
|
99
|
+
version: expect.any(String)
|
|
99
100
|
})
|
|
100
101
|
expect(result.streamPartitions.length).toEqual(2)
|
|
101
102
|
})
|
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
DhtNode,
|
|
3
|
-
PeerDescriptor,
|
|
4
|
-
Simulator,
|
|
5
|
-
SimulatorTransport,
|
|
6
|
-
NodeType
|
|
7
|
-
} from '@streamr/dht'
|
|
1
|
+
import { DhtNode, PeerDescriptor, Simulator, SimulatorTransport } from '@streamr/dht'
|
|
8
2
|
import { StreamrNode, Events } from '../../src/logic/StreamrNode'
|
|
9
3
|
import { waitForEvent3, waitForCondition } from '@streamr/utils'
|
|
10
|
-
import { createStreamMessage } from '../utils/utils'
|
|
4
|
+
import { createMockPeerDescriptor, createStreamMessage } from '../utils/utils'
|
|
11
5
|
import { StreamPartIDUtils } from '@streamr/protocol'
|
|
12
6
|
import { randomEthereumAddress } from '@streamr/test-utils'
|
|
13
7
|
import { Layer0Node } from '../../src/logic/Layer0Node'
|
|
@@ -21,14 +15,8 @@ describe('StreamrNode', () => {
|
|
|
21
15
|
let node1: StreamrNode
|
|
22
16
|
let node2: StreamrNode
|
|
23
17
|
|
|
24
|
-
const peerDescriptor1: PeerDescriptor =
|
|
25
|
-
|
|
26
|
-
type: NodeType.NODEJS
|
|
27
|
-
}
|
|
28
|
-
const peerDescriptor2: PeerDescriptor = {
|
|
29
|
-
nodeId: new Uint8Array([1, 1, 1]),
|
|
30
|
-
type: NodeType.NODEJS
|
|
31
|
-
}
|
|
18
|
+
const peerDescriptor1: PeerDescriptor = createMockPeerDescriptor()
|
|
19
|
+
const peerDescriptor2: PeerDescriptor = createMockPeerDescriptor()
|
|
32
20
|
const STREAM_PART_ID = StreamPartIDUtils.parse('test#0')
|
|
33
21
|
|
|
34
22
|
const msg = createStreamMessage(
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PeerDescriptor, Simulator, SimulatorTransport, LatencyType } from '@streamr/dht'
|
|
2
2
|
import { NetworkStack } from '../../src/NetworkStack'
|
|
3
3
|
import { streamPartIdToDataKey } from '../../src/logic/EntryPointDiscovery'
|
|
4
4
|
import { StreamPartIDUtils } from '@streamr/protocol'
|
|
5
5
|
import { Any } from '../../src/proto/google/protobuf/any'
|
|
6
|
-
import { createStreamMessage } from '../utils/utils'
|
|
6
|
+
import { createMockPeerDescriptor, createStreamMessage } from '../utils/utils'
|
|
7
7
|
import { waitForCondition } from '@streamr/utils'
|
|
8
8
|
import { randomEthereumAddress } from '@streamr/test-utils'
|
|
9
9
|
|
|
@@ -11,35 +11,11 @@ const STREAM_PART_ID = StreamPartIDUtils.parse('stream#0')
|
|
|
11
11
|
|
|
12
12
|
describe('Joining stream parts on offline nodes', () => {
|
|
13
13
|
|
|
14
|
-
const entryPointPeerDescriptor: PeerDescriptor =
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const node1PeerDescriptor: PeerDescriptor = {
|
|
21
|
-
nodeId: new Uint8Array([1, 1, 1]),
|
|
22
|
-
type: NodeType.NODEJS,
|
|
23
|
-
region: getRandomRegion()
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const node2PeerDescriptor: PeerDescriptor = {
|
|
27
|
-
nodeId: new Uint8Array([2, 2, 2]),
|
|
28
|
-
type: NodeType.NODEJS,
|
|
29
|
-
region: getRandomRegion()
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const offlineDescriptor1: PeerDescriptor = {
|
|
33
|
-
nodeId: new Uint8Array([3, 3, 3]),
|
|
34
|
-
type: NodeType.NODEJS,
|
|
35
|
-
region: getRandomRegion()
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const offlineDescriptor2: PeerDescriptor = {
|
|
39
|
-
nodeId: new Uint8Array([4, 4, 4]),
|
|
40
|
-
type: NodeType.NODEJS,
|
|
41
|
-
region: getRandomRegion()
|
|
42
|
-
}
|
|
14
|
+
const entryPointPeerDescriptor: PeerDescriptor = createMockPeerDescriptor()
|
|
15
|
+
const node1PeerDescriptor: PeerDescriptor = createMockPeerDescriptor()
|
|
16
|
+
const node2PeerDescriptor: PeerDescriptor = createMockPeerDescriptor()
|
|
17
|
+
const offlineDescriptor1: PeerDescriptor = createMockPeerDescriptor()
|
|
18
|
+
const offlineDescriptor2: PeerDescriptor = createMockPeerDescriptor()
|
|
43
19
|
|
|
44
20
|
let entryPoint: NetworkStack
|
|
45
21
|
let node1: NetworkStack
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LatencyType,
|
|
1
|
+
import { LatencyType, PeerDescriptor, Simulator, SimulatorTransport } from '@streamr/dht'
|
|
2
2
|
import {
|
|
3
3
|
ContentType,
|
|
4
4
|
EncryptionType,
|
|
@@ -22,11 +22,7 @@ describe('stream without default entrypoints', () => {
|
|
|
22
22
|
let entrypoint: NetworkNode
|
|
23
23
|
let nodes: NetworkNode[]
|
|
24
24
|
let receivedMessageCount: number
|
|
25
|
-
const entryPointPeerDescriptor: PeerDescriptor =
|
|
26
|
-
nodeId: new Uint8Array([1, 2, 3]),
|
|
27
|
-
type: NodeType.NODEJS,
|
|
28
|
-
region: getRandomRegion()
|
|
29
|
-
}
|
|
25
|
+
const entryPointPeerDescriptor: PeerDescriptor = createMockPeerDescriptor()
|
|
30
26
|
|
|
31
27
|
const streamMessage = new StreamMessage({
|
|
32
28
|
messageId: new MessageID(
|
|
@@ -2,8 +2,7 @@ import { InspectSession, Events } from '../../src/logic/inspect/InspectSession'
|
|
|
2
2
|
import { MessageID } from '../../src/proto/packages/trackerless-network/protos/NetworkRpc'
|
|
3
3
|
import { waitForEvent3 } from '../../../utils/dist/src/waitForEvent3'
|
|
4
4
|
import { utf8ToBinary } from '@streamr/utils'
|
|
5
|
-
import {
|
|
6
|
-
import { DhtAddress } from '@streamr/dht'
|
|
5
|
+
import { DhtAddress, createRandomDhtAddress } from '@streamr/dht'
|
|
7
6
|
|
|
8
7
|
describe('InspectSession', () => {
|
|
9
8
|
|
|
@@ -31,8 +30,8 @@ describe('InspectSession', () => {
|
|
|
31
30
|
}
|
|
32
31
|
|
|
33
32
|
beforeEach(() => {
|
|
34
|
-
inspectedNode =
|
|
35
|
-
anotherNode =
|
|
33
|
+
inspectedNode = createRandomDhtAddress()
|
|
34
|
+
anotherNode = createRandomDhtAddress()
|
|
36
35
|
inspectSession = new InspectSession({
|
|
37
36
|
inspectedNode
|
|
38
37
|
})
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { ListeningRpcCommunicator, getNodeIdFromPeerDescriptor } from '@streamr/dht'
|
|
1
|
+
import { ListeningRpcCommunicator, createRandomDhtAddress, getNodeIdFromPeerDescriptor } from '@streamr/dht'
|
|
2
2
|
import { utf8ToBinary } from '@streamr/utils'
|
|
3
3
|
import { Inspector } from '../../src/logic/inspect/Inspector'
|
|
4
4
|
import { MockTransport } from '../utils/mock/Transport'
|
|
5
|
-
import { createMockPeerDescriptor,
|
|
5
|
+
import { createMockPeerDescriptor, mockConnectionLocker } from '../utils/utils'
|
|
6
6
|
import { StreamPartIDUtils } from '@streamr/protocol'
|
|
7
7
|
|
|
8
8
|
describe('Inspector', () => {
|
|
@@ -12,7 +12,7 @@ describe('Inspector', () => {
|
|
|
12
12
|
|
|
13
13
|
const inspectedDescriptor = createMockPeerDescriptor()
|
|
14
14
|
|
|
15
|
-
const nodeId =
|
|
15
|
+
const nodeId = createRandomDhtAddress()
|
|
16
16
|
let mockConnect: jest.Mock
|
|
17
17
|
|
|
18
18
|
const messageRef = {
|
|
@@ -3,12 +3,12 @@ import { NodeList } from '../../src/logic/NodeList'
|
|
|
3
3
|
import { waitForCondition } from '@streamr/utils'
|
|
4
4
|
import { range } from 'lodash'
|
|
5
5
|
import { expect } from 'expect'
|
|
6
|
-
import { createMockDeliveryRpcRemote
|
|
7
|
-
import { DhtAddress, getNodeIdFromPeerDescriptor } from '@streamr/dht'
|
|
6
|
+
import { createMockDeliveryRpcRemote } from '../utils/utils'
|
|
7
|
+
import { DhtAddress, createRandomDhtAddress, getNodeIdFromPeerDescriptor } from '@streamr/dht'
|
|
8
8
|
|
|
9
9
|
describe('NeighborFinder', () => {
|
|
10
10
|
|
|
11
|
-
const nodeId =
|
|
11
|
+
const nodeId = createRandomDhtAddress()
|
|
12
12
|
let neighbors: NodeList
|
|
13
13
|
let nearbyNodeView: NodeList
|
|
14
14
|
let neighborFinder: NeighborFinder
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ListeningRpcCommunicator, getNodeIdFromPeerDescriptor } from '@streamr/dht'
|
|
1
|
+
import { DhtAddress, ListeningRpcCommunicator, getNodeIdFromPeerDescriptor } from '@streamr/dht'
|
|
2
2
|
import { NeighborFinder } from '../../src/logic/neighbor-discovery/NeighborFinder'
|
|
3
3
|
import { NeighborUpdateRpcLocal } from '../../src/logic/neighbor-discovery/NeighborUpdateRpcLocal'
|
|
4
4
|
import { createMockPeerDescriptor } from '../utils/utils'
|
|
@@ -20,6 +20,7 @@ describe('NeighborUpdateRpcLocal', () => {
|
|
|
20
20
|
let nearbyNodeView: NodeList
|
|
21
21
|
let neighborFinder: NeighborFinder
|
|
22
22
|
let rpcCommunicator: ListeningRpcCommunicator
|
|
23
|
+
let ongoingHandshakes: Set<DhtAddress>
|
|
23
24
|
|
|
24
25
|
const addNeighbors = (count: number) => {
|
|
25
26
|
for (let i = 0; i < count; i++) {
|
|
@@ -39,6 +40,10 @@ describe('NeighborUpdateRpcLocal', () => {
|
|
|
39
40
|
neighborFinder = {
|
|
40
41
|
start: jest.fn()
|
|
41
42
|
} as any
|
|
43
|
+
const connectionLocker = {
|
|
44
|
+
unlockConnection: jest.fn()
|
|
45
|
+
} as any
|
|
46
|
+
ongoingHandshakes = new Set()
|
|
42
47
|
|
|
43
48
|
rpcLocal = new NeighborUpdateRpcLocal({
|
|
44
49
|
localPeerDescriptor,
|
|
@@ -47,7 +52,9 @@ describe('NeighborUpdateRpcLocal', () => {
|
|
|
47
52
|
neighborFinder,
|
|
48
53
|
streamPartId,
|
|
49
54
|
rpcCommunicator,
|
|
50
|
-
neighborTargetCount
|
|
55
|
+
neighborTargetCount,
|
|
56
|
+
connectionLocker,
|
|
57
|
+
ongoingHandshakes
|
|
51
58
|
})
|
|
52
59
|
})
|
|
53
60
|
|
|
@@ -122,4 +129,15 @@ describe('NeighborUpdateRpcLocal', () => {
|
|
|
122
129
|
expect(neighbors.has(getNodeIdFromPeerDescriptor(caller))).toEqual(false)
|
|
123
130
|
})
|
|
124
131
|
|
|
132
|
+
it('does not ask to be removed if there is an ongoing handshake to the caller', async () => {
|
|
133
|
+
const caller = createMockPeerDescriptor()
|
|
134
|
+
ongoingHandshakes.add(getNodeIdFromPeerDescriptor(caller))
|
|
135
|
+
const res = await rpcLocal.neighborUpdate({
|
|
136
|
+
streamPartId,
|
|
137
|
+
neighborDescriptors: [localPeerDescriptor],
|
|
138
|
+
removeMe: false
|
|
139
|
+
}, { incomingSourceDescriptor: caller } as any)
|
|
140
|
+
expect(res.removeMe).toEqual(false)
|
|
141
|
+
})
|
|
142
|
+
|
|
125
143
|
})
|