@streamr/trackerless-network 100.0.0-pretestnet.2 → 100.0.0-pretestnet.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/dist/package.json +8 -8
- package/dist/src/NetworkNode.d.ts +1 -1
- package/dist/src/NetworkNode.js +3 -3
- package/dist/src/NetworkNode.js.map +1 -1
- package/dist/src/NetworkStack.js +2 -1
- package/dist/src/NetworkStack.js.map +1 -1
- package/dist/src/logic/DeliveryRpcLocal.d.ts +1 -1
- package/dist/src/logic/EntryPointDiscovery.d.ts +1 -1
- package/dist/src/logic/EntryPointDiscovery.js +5 -5
- package/dist/src/logic/EntryPointDiscovery.js.map +1 -1
- package/dist/src/logic/Layer0Node.d.ts +1 -1
- package/dist/src/logic/Layer1Node.d.ts +1 -1
- package/dist/src/logic/RandomGraphNode.d.ts +2 -1
- package/dist/src/logic/RandomGraphNode.js +7 -7
- package/dist/src/logic/RandomGraphNode.js.map +1 -1
- package/dist/src/logic/StreamrNode.d.ts +3 -2
- package/dist/src/logic/StreamrNode.js +42 -39
- package/dist/src/logic/StreamrNode.js.map +1 -1
- package/dist/src/logic/createRandomGraphNode.js +8 -7
- package/dist/src/logic/createRandomGraphNode.js.map +1 -1
- package/dist/src/logic/inspect/Inspector.d.ts +2 -2
- package/dist/src/logic/inspect/Inspector.js +2 -2
- package/dist/src/logic/inspect/Inspector.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/Handshaker.d.ts +2 -1
- package/dist/src/logic/neighbor-discovery/Handshaker.js +3 -3
- package/dist/src/logic/neighbor-discovery/Handshaker.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/NeighborUpdateManager.d.ts +1 -1
- package/dist/src/logic/neighbor-discovery/NeighborUpdateManager.js +1 -1
- package/dist/src/logic/neighbor-discovery/NeighborUpdateManager.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/NeighborUpdateRpcLocal.d.ts +1 -1
- package/dist/src/logic/neighbor-discovery/NeighborUpdateRpcLocal.js +2 -2
- package/dist/src/logic/neighbor-discovery/NeighborUpdateRpcLocal.js.map +1 -1
- package/dist/src/logic/proxy/ProxyClient.d.ts +1 -1
- package/dist/src/logic/proxy/ProxyClient.js +4 -4
- package/dist/src/logic/proxy/ProxyClient.js.map +1 -1
- package/dist/src/logic/proxy/ProxyConnectionRpcLocal.d.ts +1 -1
- package/dist/src/logic/proxy/ProxyConnectionRpcLocal.js +1 -1
- package/dist/src/logic/proxy/ProxyConnectionRpcLocal.js.map +1 -1
- package/dist/src/logic/proxy/ProxyConnectionRpcRemote.js +1 -1
- package/dist/src/logic/proxy/ProxyConnectionRpcRemote.js.map +1 -1
- package/dist/src/logic/temporary-connection/TemporaryConnectionRpcLocal.d.ts +1 -1
- package/dist/src/logic/temporary-connection/TemporaryConnectionRpcLocal.js +2 -2
- package/dist/src/logic/temporary-connection/TemporaryConnectionRpcLocal.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.d.ts +77 -60
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js +71 -58
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.d.ts +112 -136
- package/dist/src/proto/packages/dht/protos/DhtRpc.js +103 -107
- package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.server.d.ts +37 -32
- package/dist/test/benchmark/first-message.js +1 -1
- package/dist/test/benchmark/first-message.js.map +1 -1
- package/dist/test/utils/utils.d.ts +1 -1
- package/dist/test/utils/utils.js +12 -9
- package/dist/test/utils/utils.js.map +1 -1
- package/karma.config.js +2 -2
- package/package.json +8 -8
- package/src/NetworkNode.ts +3 -3
- package/src/NetworkStack.ts +2 -1
- package/src/logic/DeliveryRpcLocal.ts +1 -1
- package/src/logic/EntryPointDiscovery.ts +6 -6
- package/src/logic/Layer0Node.ts +1 -1
- package/src/logic/Layer1Node.ts +1 -1
- package/src/logic/RandomGraphNode.ts +18 -12
- package/src/logic/StreamrNode.ts +31 -24
- package/src/logic/createRandomGraphNode.ts +8 -7
- package/src/logic/inspect/Inspector.ts +4 -4
- package/src/logic/neighbor-discovery/Handshaker.ts +15 -6
- package/src/logic/neighbor-discovery/NeighborUpdateManager.ts +2 -2
- package/src/logic/neighbor-discovery/NeighborUpdateRpcLocal.ts +3 -3
- package/src/logic/proxy/ProxyClient.ts +6 -6
- package/src/logic/proxy/ProxyConnectionRpcLocal.ts +2 -2
- package/src/logic/proxy/ProxyConnectionRpcRemote.ts +2 -2
- package/src/logic/temporary-connection/TemporaryConnectionRpcLocal.ts +3 -3
- package/src/proto/packages/dht/protos/DhtRpc.client.ts +113 -97
- package/src/proto/packages/dht/protos/DhtRpc.server.ts +37 -32
- package/src/proto/packages/dht/protos/DhtRpc.ts +146 -178
- package/test/benchmark/first-message.ts +1 -1
- package/test/end-to-end/inspect.test.ts +6 -3
- package/test/end-to-end/proxy-and-full-node.test.ts +1 -0
- package/test/end-to-end/proxy-connections.test.ts +3 -1
- package/test/end-to-end/proxy-key-exchange.test.ts +1 -0
- package/test/end-to-end/random-graph-with-real-connections.test.ts +10 -10
- package/test/end-to-end/webrtc-full-node-network.test.ts +2 -1
- package/test/end-to-end/websocket-full-node-network.test.ts +3 -1
- package/test/integration/Handshakes.test.ts +1 -1
- package/test/integration/Inspect.test.ts +2 -2
- package/test/integration/NetworkStack.test.ts +4 -2
- package/test/integration/RandomGraphNode-Layer1Node-Latencies.test.ts +2 -2
- package/test/integration/RandomGraphNode-Layer1Node.test.ts +2 -2
- package/test/integration/StreamrNode.test.ts +1 -1
- package/test/integration/joining-streams-on-offline-peers.test.ts +12 -7
- package/test/integration/stream-without-default-entrypoints.test.ts +4 -3
- package/test/unit/DeliveryRpcLocal.test.ts +1 -1
- package/test/unit/EntrypointDiscovery.test.ts +3 -3
- package/test/unit/HandshakeRpcLocal.test.ts +2 -2
- package/test/unit/Handshaker.test.ts +3 -2
- package/test/unit/Inspector.test.ts +1 -1
- package/test/unit/NodeList.test.ts +1 -1
- package/test/unit/RandomGraphNode.test.ts +1 -1
- package/test/unit/StreamrNode.test.ts +1 -1
- package/test/utils/mock/MockLayer0Node.ts +1 -1
- package/test/utils/mock/Transport.ts +1 -1
- package/test/utils/utils.ts +13 -10
- package/test/integration/NetworkStackStoppedDuringStart.test.ts +0 -37
package/src/logic/StreamrNode.ts
CHANGED
|
@@ -2,7 +2,8 @@ import {
|
|
|
2
2
|
ConnectionLocker,
|
|
3
3
|
DhtNode,
|
|
4
4
|
ITransport,
|
|
5
|
-
PeerDescriptor
|
|
5
|
+
PeerDescriptor,
|
|
6
|
+
EXISTING_CONNECTION_TIMEOUT
|
|
6
7
|
} from '@streamr/dht'
|
|
7
8
|
import { StreamID, StreamPartID, StreamPartIDUtils, toStreamPartID } from '@streamr/protocol'
|
|
8
9
|
import {
|
|
@@ -26,7 +27,7 @@ import { ProxyClient } from './proxy/ProxyClient'
|
|
|
26
27
|
|
|
27
28
|
export type StreamPartDelivery = {
|
|
28
29
|
broadcast: (msg: StreamMessage) => void
|
|
29
|
-
stop: () => void
|
|
30
|
+
stop: () => Promise<void>
|
|
30
31
|
} & ({
|
|
31
32
|
proxied: false
|
|
32
33
|
layer1Node: Layer1Node
|
|
@@ -55,6 +56,7 @@ export interface StreamrNodeConfig {
|
|
|
55
56
|
streamPartitionNumOfNeighbors?: number
|
|
56
57
|
streamPartitionMinPropagationTargets?: number
|
|
57
58
|
acceptProxyConnections?: boolean
|
|
59
|
+
rpcRequestTimeout?: number
|
|
58
60
|
}
|
|
59
61
|
|
|
60
62
|
// TODO rename class?
|
|
@@ -86,7 +88,7 @@ export class StreamrNode extends EventEmitter<Events> {
|
|
|
86
88
|
if (this.started || this.destroyed) {
|
|
87
89
|
return
|
|
88
90
|
}
|
|
89
|
-
logger.info(`Starting new StreamrNode with id ${getNodeIdFromPeerDescriptor(startedAndJoinedLayer0Node.
|
|
91
|
+
logger.info(`Starting new StreamrNode with id ${getNodeIdFromPeerDescriptor(startedAndJoinedLayer0Node.getLocalPeerDescriptor())}`)
|
|
90
92
|
this.started = true
|
|
91
93
|
this.layer0Node = startedAndJoinedLayer0Node
|
|
92
94
|
this.transport = transport
|
|
@@ -100,12 +102,9 @@ export class StreamrNode extends EventEmitter<Events> {
|
|
|
100
102
|
}
|
|
101
103
|
logger.trace('Destroying StreamrNode...')
|
|
102
104
|
this.destroyed = true
|
|
103
|
-
this.streamParts.
|
|
105
|
+
await Promise.all(Array.from(this.streamParts.values()).map((streamPart) => streamPart.stop()))
|
|
104
106
|
this.streamParts.clear()
|
|
105
107
|
this.removeAllListeners()
|
|
106
|
-
// TODO stopping should be in NetworkStack#stop?
|
|
107
|
-
await this.layer0Node!.stop()
|
|
108
|
-
await this.transport!.stop()
|
|
109
108
|
this.layer0Node = undefined
|
|
110
109
|
this.transport = undefined
|
|
111
110
|
this.connectionLocker = undefined
|
|
@@ -119,10 +118,10 @@ export class StreamrNode extends EventEmitter<Events> {
|
|
|
119
118
|
this.metrics.broadcastBytesPerSecond.record(msg.content.length)
|
|
120
119
|
}
|
|
121
120
|
|
|
122
|
-
leaveStreamPart(streamPartId: StreamPartID): void {
|
|
121
|
+
async leaveStreamPart(streamPartId: StreamPartID): Promise<void> {
|
|
123
122
|
const streamPart = this.streamParts.get(streamPartId)
|
|
124
123
|
if (streamPart) {
|
|
125
|
-
streamPart.stop()
|
|
124
|
+
await streamPart.stop()
|
|
126
125
|
this.streamParts.delete(streamPartId)
|
|
127
126
|
}
|
|
128
127
|
}
|
|
@@ -137,7 +136,7 @@ export class StreamrNode extends EventEmitter<Events> {
|
|
|
137
136
|
const node = this.createRandomGraphNode(streamPartId, layer1Node)
|
|
138
137
|
const entryPointDiscovery = new EntryPointDiscovery({
|
|
139
138
|
streamPartId,
|
|
140
|
-
|
|
139
|
+
localPeerDescriptor: this.getPeerDescriptor(),
|
|
141
140
|
layer1Node,
|
|
142
141
|
getEntryPointData: (key) => this.layer0Node!.getDataFromDht(key),
|
|
143
142
|
storeEntryPointData: (key, data) => this.layer0Node!.storeDataToDht(key, data),
|
|
@@ -154,10 +153,10 @@ export class StreamrNode extends EventEmitter<Events> {
|
|
|
154
153
|
node,
|
|
155
154
|
entryPointDiscovery,
|
|
156
155
|
broadcast: (msg: StreamMessage) => node.broadcast(msg),
|
|
157
|
-
stop: () => {
|
|
158
|
-
entryPointDiscovery.destroy()
|
|
156
|
+
stop: async () => {
|
|
157
|
+
await entryPointDiscovery.destroy()
|
|
159
158
|
node.stop()
|
|
160
|
-
layer1Node.stop()
|
|
159
|
+
await layer1Node.stop()
|
|
161
160
|
}
|
|
162
161
|
}
|
|
163
162
|
this.streamParts.set(streamPartId, streamPart)
|
|
@@ -193,28 +192,29 @@ export class StreamrNode extends EventEmitter<Events> {
|
|
|
193
192
|
}
|
|
194
193
|
}
|
|
195
194
|
|
|
196
|
-
private createLayer1Node
|
|
195
|
+
private createLayer1Node(streamPartId: StreamPartID, entryPoints: PeerDescriptor[]): Layer1Node {
|
|
197
196
|
return new DhtNode({
|
|
198
197
|
transport: this.layer0Node!,
|
|
199
198
|
serviceId: 'layer1::' + streamPartId,
|
|
200
|
-
peerDescriptor: this.layer0Node!.
|
|
199
|
+
peerDescriptor: this.layer0Node!.getLocalPeerDescriptor(),
|
|
201
200
|
entryPoints,
|
|
202
201
|
numberOfNodesPerKBucket: 4,
|
|
203
|
-
rpcRequestTimeout:
|
|
202
|
+
rpcRequestTimeout: EXISTING_CONNECTION_TIMEOUT,
|
|
204
203
|
dhtJoinTimeout: 20000
|
|
205
204
|
})
|
|
206
205
|
}
|
|
207
206
|
|
|
208
|
-
private createRandomGraphNode
|
|
207
|
+
private createRandomGraphNode(streamPartId: StreamPartID, layer1Node: Layer1Node) {
|
|
209
208
|
return createRandomGraphNode({
|
|
210
209
|
streamPartId,
|
|
211
210
|
transport: this.transport!,
|
|
212
211
|
layer1Node,
|
|
213
212
|
connectionLocker: this.connectionLocker!,
|
|
214
|
-
|
|
213
|
+
localPeerDescriptor: this.layer0Node!.getLocalPeerDescriptor(),
|
|
215
214
|
minPropagationTargets: this.config.streamPartitionMinPropagationTargets,
|
|
216
215
|
numOfTargetNeighbors: this.config.streamPartitionNumOfNeighbors,
|
|
217
|
-
acceptProxyConnections: this.config.acceptProxyConnections
|
|
216
|
+
acceptProxyConnections: this.config.acceptProxyConnections,
|
|
217
|
+
rpcRequestTimeout: this.config.rpcRequestTimeout
|
|
218
218
|
})
|
|
219
219
|
}
|
|
220
220
|
|
|
@@ -240,7 +240,7 @@ export class StreamrNode extends EventEmitter<Events> {
|
|
|
240
240
|
proxied: true,
|
|
241
241
|
client,
|
|
242
242
|
broadcast: (msg: StreamMessage) => client.broadcast(msg),
|
|
243
|
-
stop: () => client.stop()
|
|
243
|
+
stop: async () => client.stop()
|
|
244
244
|
})
|
|
245
245
|
client.on('message', (message: StreamMessage) => {
|
|
246
246
|
this.emit('newMessage', message)
|
|
@@ -249,7 +249,7 @@ export class StreamrNode extends EventEmitter<Events> {
|
|
|
249
249
|
}
|
|
250
250
|
await client.setProxies(nodes, direction, userId, connectionCount)
|
|
251
251
|
} else {
|
|
252
|
-
this.streamParts.get(streamPartId)?.stop()
|
|
252
|
+
await this.streamParts.get(streamPartId)?.stop()
|
|
253
253
|
this.streamParts.delete(streamPartId)
|
|
254
254
|
}
|
|
255
255
|
}
|
|
@@ -257,7 +257,7 @@ export class StreamrNode extends EventEmitter<Events> {
|
|
|
257
257
|
private createProxyClient(streamPartId: StreamPartID): ProxyClient {
|
|
258
258
|
return new ProxyClient({
|
|
259
259
|
transport: this.transport!,
|
|
260
|
-
|
|
260
|
+
localPeerDescriptor: this.layer0Node!.getLocalPeerDescriptor(),
|
|
261
261
|
streamPartId,
|
|
262
262
|
connectionLocker: this.connectionLocker!,
|
|
263
263
|
minPropagationTargets: this.config.streamPartitionMinPropagationTargets
|
|
@@ -292,11 +292,11 @@ export class StreamrNode extends EventEmitter<Events> {
|
|
|
292
292
|
}
|
|
293
293
|
|
|
294
294
|
getPeerDescriptor(): PeerDescriptor {
|
|
295
|
-
return this.layer0Node!.
|
|
295
|
+
return this.layer0Node!.getLocalPeerDescriptor()
|
|
296
296
|
}
|
|
297
297
|
|
|
298
298
|
getNodeId(): NodeID {
|
|
299
|
-
return getNodeIdFromPeerDescriptor(this.layer0Node!.
|
|
299
|
+
return getNodeIdFromPeerDescriptor(this.layer0Node!.getLocalPeerDescriptor())
|
|
300
300
|
}
|
|
301
301
|
|
|
302
302
|
getNeighbors(streamPartId: StreamPartID): NodeID[] {
|
|
@@ -317,3 +317,10 @@ export class StreamrNode extends EventEmitter<Events> {
|
|
|
317
317
|
process.exit()
|
|
318
318
|
})
|
|
319
319
|
})
|
|
320
|
+
|
|
321
|
+
declare let window: any
|
|
322
|
+
if (typeof window === 'object') {
|
|
323
|
+
window.addEventListener('unload', async () => {
|
|
324
|
+
await cleanUp()
|
|
325
|
+
})
|
|
326
|
+
}
|
|
@@ -25,7 +25,7 @@ type RandomGraphNodeConfig = MarkOptional<StrictRandomGraphNodeConfig,
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
const createConfigWithDefaults = (config: RandomGraphNodeConfig): StrictRandomGraphNodeConfig => {
|
|
28
|
-
const ownNodeId = getNodeIdFromPeerDescriptor(config.
|
|
28
|
+
const ownNodeId = getNodeIdFromPeerDescriptor(config.localPeerDescriptor)
|
|
29
29
|
const rpcCommunicator = config.rpcCommunicator ?? new ListeningRpcCommunicator(
|
|
30
30
|
formStreamPartDeliveryServiceId(config.streamPartId),
|
|
31
31
|
config.transport
|
|
@@ -42,10 +42,10 @@ const createConfigWithDefaults = (config: RandomGraphNodeConfig): StrictRandomGr
|
|
|
42
42
|
const temporaryConnectionRpcLocal = new TemporaryConnectionRpcLocal({
|
|
43
43
|
streamPartId: config.streamPartId,
|
|
44
44
|
rpcCommunicator,
|
|
45
|
-
|
|
45
|
+
localPeerDescriptor: config.localPeerDescriptor
|
|
46
46
|
})
|
|
47
47
|
const proxyConnectionRpcLocal = acceptProxyConnections ? new ProxyConnectionRpcLocal({
|
|
48
|
-
|
|
48
|
+
localPeerDescriptor: config.localPeerDescriptor,
|
|
49
49
|
streamPartId: config.streamPartId,
|
|
50
50
|
rpcCommunicator
|
|
51
51
|
}) : undefined
|
|
@@ -64,14 +64,15 @@ const createConfigWithDefaults = (config: RandomGraphNodeConfig): StrictRandomGr
|
|
|
64
64
|
}
|
|
65
65
|
})
|
|
66
66
|
const handshaker = config.handshaker ?? new Handshaker({
|
|
67
|
-
|
|
67
|
+
localPeerDescriptor: config.localPeerDescriptor,
|
|
68
68
|
streamPartId: config.streamPartId,
|
|
69
69
|
connectionLocker: config.connectionLocker,
|
|
70
70
|
rpcCommunicator,
|
|
71
71
|
nearbyNodeView,
|
|
72
72
|
randomNodeView,
|
|
73
73
|
targetNeighbors,
|
|
74
|
-
maxNeighborCount: numOfTargetNeighbors
|
|
74
|
+
maxNeighborCount: numOfTargetNeighbors,
|
|
75
|
+
rpcRequestTimeout: config.rpcRequestTimeout
|
|
75
76
|
})
|
|
76
77
|
const neighborFinder = config.neighborFinder ?? new NeighborFinder({
|
|
77
78
|
targetNeighbors,
|
|
@@ -82,14 +83,14 @@ const createConfigWithDefaults = (config: RandomGraphNodeConfig): StrictRandomGr
|
|
|
82
83
|
const neighborUpdateManager = config.neighborUpdateManager ?? new NeighborUpdateManager({
|
|
83
84
|
targetNeighbors,
|
|
84
85
|
nearbyNodeView,
|
|
85
|
-
|
|
86
|
+
localPeerDescriptor: config.localPeerDescriptor,
|
|
86
87
|
neighborFinder,
|
|
87
88
|
streamPartId: config.streamPartId,
|
|
88
89
|
rpcCommunicator,
|
|
89
90
|
neighborUpdateInterval
|
|
90
91
|
})
|
|
91
92
|
const inspector = config.inspector ?? new Inspector({
|
|
92
|
-
|
|
93
|
+
localPeerDescriptor: config.localPeerDescriptor,
|
|
93
94
|
rpcCommunicator,
|
|
94
95
|
streamPartId: config.streamPartId,
|
|
95
96
|
connectionLocker: config.connectionLocker
|
|
@@ -9,7 +9,7 @@ import { NodeID, getNodeIdFromPeerDescriptor } from '../../identifiers'
|
|
|
9
9
|
import { StreamPartID } from '@streamr/protocol'
|
|
10
10
|
|
|
11
11
|
interface InspectorConfig {
|
|
12
|
-
|
|
12
|
+
localPeerDescriptor: PeerDescriptor
|
|
13
13
|
streamPartId: StreamPartID
|
|
14
14
|
rpcCommunicator: RpcCommunicator
|
|
15
15
|
connectionLocker: ConnectionLocker
|
|
@@ -32,14 +32,14 @@ export class Inspector implements IInspector {
|
|
|
32
32
|
private readonly sessions: Map<NodeID, InspectSession> = new Map()
|
|
33
33
|
private readonly streamPartId: StreamPartID
|
|
34
34
|
private readonly client: ProtoRpcClient<TemporaryConnectionRpcClient>
|
|
35
|
-
private readonly
|
|
35
|
+
private readonly localPeerDescriptor: PeerDescriptor
|
|
36
36
|
private readonly connectionLocker: ConnectionLocker
|
|
37
37
|
private readonly inspectionTimeout: number
|
|
38
38
|
private readonly openInspectConnection: (peerDescriptor: PeerDescriptor, lockId: string) => Promise<void>
|
|
39
39
|
|
|
40
40
|
constructor(config: InspectorConfig) {
|
|
41
41
|
this.streamPartId = config.streamPartId
|
|
42
|
-
this.
|
|
42
|
+
this.localPeerDescriptor = config.localPeerDescriptor
|
|
43
43
|
this.client = toProtoRpcClient(new TemporaryConnectionRpcClient(config.rpcCommunicator.getRpcClientTransport()))
|
|
44
44
|
this.connectionLocker = config.connectionLocker
|
|
45
45
|
this.inspectionTimeout = config.inspectionTimeout ?? DEFAULT_TIMEOUT
|
|
@@ -47,7 +47,7 @@ export class Inspector implements IInspector {
|
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
async defaultOpenInspectConnection(peerDescriptor: PeerDescriptor, lockId: string): Promise<void> {
|
|
50
|
-
const rpcRemote = new TemporaryConnectionRpcRemote(this.
|
|
50
|
+
const rpcRemote = new TemporaryConnectionRpcRemote(this.localPeerDescriptor, peerDescriptor, this.streamPartId, this.client)
|
|
51
51
|
await rpcRemote.openConnection()
|
|
52
52
|
this.connectionLocker.lockConnection(peerDescriptor, lockId)
|
|
53
53
|
}
|
|
@@ -19,7 +19,7 @@ import { NodeID, getNodeIdFromPeerDescriptor } from '../../identifiers'
|
|
|
19
19
|
import { StreamPartID } from '@streamr/protocol'
|
|
20
20
|
|
|
21
21
|
interface HandshakerConfig {
|
|
22
|
-
|
|
22
|
+
localPeerDescriptor: PeerDescriptor
|
|
23
23
|
streamPartId: StreamPartID
|
|
24
24
|
connectionLocker: ConnectionLocker
|
|
25
25
|
targetNeighbors: NodeList
|
|
@@ -27,6 +27,7 @@ interface HandshakerConfig {
|
|
|
27
27
|
randomNodeView: NodeList
|
|
28
28
|
rpcCommunicator: RpcCommunicator
|
|
29
29
|
maxNeighborCount: number
|
|
30
|
+
rpcRequestTimeout?: number
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
const logger = new Logger(module)
|
|
@@ -141,10 +142,11 @@ export class Handshaker implements IHandshaker {
|
|
|
141
142
|
|
|
142
143
|
private async handshakeWithInterleaving(target: PeerDescriptor, interleaveSourceId: NodeID): Promise<boolean> {
|
|
143
144
|
const targetNeighbor = new HandshakeRpcRemote(
|
|
144
|
-
this.config.
|
|
145
|
+
this.config.localPeerDescriptor,
|
|
145
146
|
target,
|
|
146
147
|
this.config.streamPartId,
|
|
147
|
-
this.client
|
|
148
|
+
this.client,
|
|
149
|
+
this.config.rpcRequestTimeout
|
|
148
150
|
)
|
|
149
151
|
const targetNodeId = getNodeIdFromPeerDescriptor(targetNeighbor.getPeerDescriptor())
|
|
150
152
|
this.ongoingHandshakes.add(targetNodeId)
|
|
@@ -162,15 +164,22 @@ export class Handshaker implements IHandshaker {
|
|
|
162
164
|
}
|
|
163
165
|
|
|
164
166
|
private createRpcRemote(targetPeerDescriptor: PeerDescriptor): HandshakeRpcRemote {
|
|
165
|
-
return new HandshakeRpcRemote(
|
|
167
|
+
return new HandshakeRpcRemote(
|
|
168
|
+
this.config.localPeerDescriptor,
|
|
169
|
+
targetPeerDescriptor,
|
|
170
|
+
this.config.streamPartId,
|
|
171
|
+
this.client,
|
|
172
|
+
this.config.rpcRequestTimeout
|
|
173
|
+
)
|
|
166
174
|
}
|
|
167
175
|
|
|
168
176
|
private createDeliveryRpcRemote(targetPeerDescriptor: PeerDescriptor): DeliveryRpcRemote {
|
|
169
177
|
return new DeliveryRpcRemote(
|
|
170
|
-
this.config.
|
|
178
|
+
this.config.localPeerDescriptor,
|
|
171
179
|
targetPeerDescriptor,
|
|
172
180
|
this.config.streamPartId,
|
|
173
|
-
toProtoRpcClient(new DeliveryRpcClient(this.config.rpcCommunicator.getRpcClientTransport()))
|
|
181
|
+
toProtoRpcClient(new DeliveryRpcClient(this.config.rpcCommunicator.getRpcClientTransport())),
|
|
182
|
+
this.config.rpcRequestTimeout
|
|
174
183
|
)
|
|
175
184
|
}
|
|
176
185
|
|
|
@@ -11,7 +11,7 @@ import { getNodeIdFromPeerDescriptor } from '../../identifiers'
|
|
|
11
11
|
import { StreamPartID } from '@streamr/protocol'
|
|
12
12
|
|
|
13
13
|
interface NeighborUpdateManagerConfig {
|
|
14
|
-
|
|
14
|
+
localPeerDescriptor: PeerDescriptor
|
|
15
15
|
targetNeighbors: NodeList
|
|
16
16
|
nearbyNodeView: NodeList
|
|
17
17
|
neighborFinder: INeighborFinder
|
|
@@ -64,6 +64,6 @@ export class NeighborUpdateManager implements INeighborUpdateManager {
|
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
private createRemote(targetPeerDescriptor: PeerDescriptor): NeighborUpdateRpcRemote {
|
|
67
|
-
return new NeighborUpdateRpcRemote(this.config.
|
|
67
|
+
return new NeighborUpdateRpcRemote(this.config.localPeerDescriptor, targetPeerDescriptor, this.config.streamPartId, this.client)
|
|
68
68
|
}
|
|
69
69
|
}
|
|
@@ -11,7 +11,7 @@ import { INeighborFinder } from './NeighborFinder'
|
|
|
11
11
|
import { StreamPartID } from '@streamr/protocol'
|
|
12
12
|
|
|
13
13
|
interface NeighborUpdateRpcLocalConfig {
|
|
14
|
-
|
|
14
|
+
localPeerDescriptor: PeerDescriptor
|
|
15
15
|
streamPartId: StreamPartID
|
|
16
16
|
targetNeighbors: NodeList
|
|
17
17
|
nearbyNodeView: NodeList
|
|
@@ -35,12 +35,12 @@ export class NeighborUpdateRpcLocal implements INeighborUpdateRpc {
|
|
|
35
35
|
const newPeerDescriptors = message.neighborDescriptors
|
|
36
36
|
.filter((peerDescriptor) => {
|
|
37
37
|
const nodeId = getNodeIdFromPeerDescriptor(peerDescriptor)
|
|
38
|
-
const ownNodeId = getNodeIdFromPeerDescriptor(this.config.
|
|
38
|
+
const ownNodeId = getNodeIdFromPeerDescriptor(this.config.localPeerDescriptor)
|
|
39
39
|
return nodeId !== ownNodeId && !this.config.targetNeighbors.getIds().includes(nodeId)
|
|
40
40
|
})
|
|
41
41
|
newPeerDescriptors.forEach((peerDescriptor) => this.config.nearbyNodeView.add(
|
|
42
42
|
new DeliveryRpcRemote(
|
|
43
|
-
this.config.
|
|
43
|
+
this.config.localPeerDescriptor,
|
|
44
44
|
peerDescriptor,
|
|
45
45
|
this.config.streamPartId,
|
|
46
46
|
toProtoRpcClient(new DeliveryRpcClient(this.config.rpcCommunicator.getRpcClientTransport()))
|
|
@@ -44,7 +44,7 @@ export const retry = async <T>(task: () => Promise<T>, description: string, abor
|
|
|
44
44
|
|
|
45
45
|
interface ProxyClientConfig {
|
|
46
46
|
transport: ITransport
|
|
47
|
-
|
|
47
|
+
localPeerDescriptor: PeerDescriptor
|
|
48
48
|
streamPartId: StreamPartID
|
|
49
49
|
connectionLocker: ConnectionLocker
|
|
50
50
|
minPropagationTargets?: number // TODO could be required option if we apply all defaults somewhere at higher level
|
|
@@ -77,9 +77,9 @@ export class ProxyClient extends EventEmitter {
|
|
|
77
77
|
super()
|
|
78
78
|
this.config = config
|
|
79
79
|
this.rpcCommunicator = new ListeningRpcCommunicator(formStreamPartDeliveryServiceId(config.streamPartId), config.transport)
|
|
80
|
-
this.targetNeighbors = new NodeList(getNodeIdFromPeerDescriptor(this.config.
|
|
80
|
+
this.targetNeighbors = new NodeList(getNodeIdFromPeerDescriptor(this.config.localPeerDescriptor), 1000)
|
|
81
81
|
this.deliveryRpcLocal = new DeliveryRpcLocal({
|
|
82
|
-
|
|
82
|
+
localPeerDescriptor: this.config.localPeerDescriptor,
|
|
83
83
|
streamPartId: this.config.streamPartId,
|
|
84
84
|
markAndCheckDuplicate: (msg: MessageID, prev?: MessageRef) => markAndCheckDuplicate(this.duplicateDetectors, msg, prev),
|
|
85
85
|
broadcast: (message: StreamMessage, previousNode?: NodeID) => this.broadcast(message, previousNode),
|
|
@@ -150,7 +150,7 @@ export class ProxyClient extends EventEmitter {
|
|
|
150
150
|
|
|
151
151
|
private getInvalidConnections(): NodeID[] {
|
|
152
152
|
return Array.from(this.connections.keys()).filter((id) => {
|
|
153
|
-
return !this.definition!.nodes.has(id
|
|
153
|
+
return !this.definition!.nodes.has(id)
|
|
154
154
|
|| this.definition!.direction !== this.connections.get(id)
|
|
155
155
|
})
|
|
156
156
|
}
|
|
@@ -167,13 +167,13 @@ export class ProxyClient extends EventEmitter {
|
|
|
167
167
|
private async attemptConnection(nodeId: NodeID, direction: ProxyDirection, userId: EthereumAddress): Promise<void> {
|
|
168
168
|
const peerDescriptor = this.definition!.nodes.get(nodeId)!
|
|
169
169
|
const client = toProtoRpcClient(new ProxyConnectionRpcClient(this.rpcCommunicator.getRpcClientTransport()))
|
|
170
|
-
const rpcRemote = new ProxyConnectionRpcRemote(this.config.
|
|
170
|
+
const rpcRemote = new ProxyConnectionRpcRemote(this.config.localPeerDescriptor, peerDescriptor, this.config.streamPartId, client)
|
|
171
171
|
const accepted = await rpcRemote.requestConnection(direction, userId)
|
|
172
172
|
if (accepted) {
|
|
173
173
|
this.config.connectionLocker.lockConnection(peerDescriptor, SERVICE_ID)
|
|
174
174
|
this.connections.set(nodeId, direction)
|
|
175
175
|
const remote = new DeliveryRpcRemote(
|
|
176
|
-
this.config.
|
|
176
|
+
this.config.localPeerDescriptor,
|
|
177
177
|
peerDescriptor,
|
|
178
178
|
this.config.streamPartId,
|
|
179
179
|
toProtoRpcClient(new DeliveryRpcClient(this.rpcCommunicator.getRpcClientTransport()))
|
|
@@ -26,7 +26,7 @@ interface ProxyConnection {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
interface ProxyConnectionRpcLocalConfig {
|
|
29
|
-
|
|
29
|
+
localPeerDescriptor: PeerDescriptor
|
|
30
30
|
streamPartId: StreamPartID
|
|
31
31
|
rpcCommunicator: ListeningRpcCommunicator
|
|
32
32
|
}
|
|
@@ -95,7 +95,7 @@ export class ProxyConnectionRpcLocal extends EventEmitter<Events> implements IPr
|
|
|
95
95
|
direction: request.direction,
|
|
96
96
|
userId: toEthereumAddress(binaryToHex(request.userId, true)),
|
|
97
97
|
remote: new DeliveryRpcRemote(
|
|
98
|
-
this.config.
|
|
98
|
+
this.config.localPeerDescriptor,
|
|
99
99
|
senderPeerDescriptor,
|
|
100
100
|
this.config.streamPartId,
|
|
101
101
|
toProtoRpcClient(new DeliveryRpcClient(this.config.rpcCommunicator.getRpcClientTransport()))
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Remote } from '@streamr/dht'
|
|
1
|
+
import { Remote, EXISTING_CONNECTION_TIMEOUT } from '@streamr/dht'
|
|
2
2
|
import { EthereumAddress, Logger, hexToBinary } from '@streamr/utils'
|
|
3
3
|
import { ProxyConnectionRequest, ProxyDirection } from '../../proto/packages/trackerless-network/protos/NetworkRpc'
|
|
4
4
|
import { IProxyConnectionRpcClient } from '../../proto/packages/trackerless-network/protos/NetworkRpc.client'
|
|
@@ -13,7 +13,7 @@ export class ProxyConnectionRpcRemote extends Remote<IProxyConnectionRpcClient>
|
|
|
13
13
|
userId: hexToBinary(userId)
|
|
14
14
|
}
|
|
15
15
|
const options = this.formDhtRpcOptions({
|
|
16
|
-
timeout:
|
|
16
|
+
timeout: EXISTING_CONNECTION_TIMEOUT
|
|
17
17
|
})
|
|
18
18
|
try {
|
|
19
19
|
const res = await this.getClient().requestConnection(request, options)
|
|
@@ -13,7 +13,7 @@ import { StreamPartID } from '@streamr/protocol'
|
|
|
13
13
|
interface TemporaryConnectionRpcLocalConfig {
|
|
14
14
|
streamPartId: StreamPartID
|
|
15
15
|
rpcCommunicator: ListeningRpcCommunicator
|
|
16
|
-
|
|
16
|
+
localPeerDescriptor: PeerDescriptor
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
export class TemporaryConnectionRpcLocal implements ITemporaryConnectionRpc {
|
|
@@ -23,7 +23,7 @@ export class TemporaryConnectionRpcLocal implements ITemporaryConnectionRpc {
|
|
|
23
23
|
|
|
24
24
|
constructor(config: TemporaryConnectionRpcLocalConfig) {
|
|
25
25
|
this.config = config
|
|
26
|
-
this.temporaryNodes = new NodeList(getNodeIdFromPeerDescriptor(config.
|
|
26
|
+
this.temporaryNodes = new NodeList(getNodeIdFromPeerDescriptor(config.localPeerDescriptor), 10)
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
getNodes(): NodeList {
|
|
@@ -40,7 +40,7 @@ export class TemporaryConnectionRpcLocal implements ITemporaryConnectionRpc {
|
|
|
40
40
|
): Promise<TemporaryConnectionResponse> {
|
|
41
41
|
const sender = (context as DhtCallContext).incomingSourceDescriptor!
|
|
42
42
|
const remote = new DeliveryRpcRemote(
|
|
43
|
-
this.config.
|
|
43
|
+
this.config.localPeerDescriptor,
|
|
44
44
|
sender,
|
|
45
45
|
this.config.streamPartId,
|
|
46
46
|
toProtoRpcClient(new DeliveryRpcClient(this.config.rpcCommunicator.getRpcClientTransport()))
|