@streamr/trackerless-network 100.0.0-testnet-two.3 → 100.0.0-testnet-three.0
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/NetworkNode.d.ts +2 -1
- package/dist/src/NetworkNode.js +6 -2
- package/dist/src/NetworkNode.js.map +1 -1
- package/dist/src/NetworkStack.d.ts +6 -2
- package/dist/src/NetworkStack.js +21 -1
- package/dist/src/NetworkStack.js.map +1 -1
- package/dist/src/exports.d.ts +1 -0
- package/dist/src/exports.js +4 -1
- package/dist/src/exports.js.map +1 -1
- package/dist/src/logic/DeliveryRpcLocal.js +1 -0
- package/dist/src/logic/DeliveryRpcLocal.js.map +1 -1
- package/dist/src/logic/DuplicateMessageDetector.d.ts +3 -3
- package/dist/src/logic/DuplicateMessageDetector.js +10 -6
- package/dist/src/logic/DuplicateMessageDetector.js.map +1 -1
- package/dist/src/logic/EntryPointDiscovery.js +8 -5
- package/dist/src/logic/EntryPointDiscovery.js.map +1 -1
- package/dist/src/logic/Layer0Node.d.ts +2 -0
- package/dist/src/logic/Layer1Node.d.ts +4 -4
- package/dist/src/logic/NodeList.d.ts +6 -8
- package/dist/src/logic/NodeList.js +10 -12
- package/dist/src/logic/NodeList.js.map +1 -1
- package/dist/src/logic/RandomGraphNode.d.ts +5 -5
- package/dist/src/logic/RandomGraphNode.js +26 -22
- package/dist/src/logic/RandomGraphNode.js.map +1 -1
- package/dist/src/logic/StreamrNode.d.ts +3 -2
- package/dist/src/logic/StreamrNode.js +25 -6
- package/dist/src/logic/StreamrNode.js.map +1 -1
- package/dist/src/logic/createRandomGraphNode.d.ts +2 -2
- package/dist/src/logic/createRandomGraphNode.js +14 -14
- package/dist/src/logic/createRandomGraphNode.js.map +1 -1
- package/dist/src/logic/inspect/InspectSession.js +3 -2
- package/dist/src/logic/inspect/InspectSession.js.map +1 -1
- package/dist/src/logic/inspect/Inspector.d.ts +2 -3
- package/dist/src/logic/inspect/Inspector.js +7 -1
- package/dist/src/logic/inspect/Inspector.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/HandshakeRpcLocal.d.ts +1 -1
- package/dist/src/logic/neighbor-discovery/HandshakeRpcLocal.js +18 -17
- package/dist/src/logic/neighbor-discovery/HandshakeRpcLocal.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/HandshakeRpcRemote.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/Handshaker.d.ts +3 -4
- package/dist/src/logic/neighbor-discovery/Handshaker.js +29 -27
- package/dist/src/logic/neighbor-discovery/Handshaker.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/NeighborFinder.d.ts +1 -1
- package/dist/src/logic/neighbor-discovery/NeighborFinder.js +4 -2
- package/dist/src/logic/neighbor-discovery/NeighborFinder.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/NeighborUpdateManager.d.ts +1 -1
- package/dist/src/logic/neighbor-discovery/NeighborUpdateManager.js +8 -4
- 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 +5 -4
- package/dist/src/logic/neighbor-discovery/NeighborUpdateRpcLocal.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/NeighborUpdateRpcRemote.js.map +1 -1
- package/dist/src/logic/node-info/NodeInfoClient.d.ts +9 -0
- package/dist/src/logic/node-info/NodeInfoClient.js +19 -0
- package/dist/src/logic/node-info/NodeInfoClient.js.map +1 -0
- package/dist/src/logic/node-info/NodeInfoRpcLocal.d.ts +12 -0
- package/dist/src/logic/node-info/NodeInfoRpcLocal.js +29 -0
- package/dist/src/logic/node-info/NodeInfoRpcLocal.js.map +1 -0
- package/dist/src/logic/node-info/NodeInfoRpcRemote.d.ts +6 -0
- package/dist/src/logic/node-info/NodeInfoRpcRemote.js +11 -0
- package/dist/src/logic/node-info/NodeInfoRpcRemote.js.map +1 -0
- package/dist/src/logic/propagation/FifoMapWithTTL.js +7 -3
- package/dist/src/logic/propagation/FifoMapWithTTL.js.map +1 -1
- package/dist/src/logic/propagation/Propagation.js +3 -0
- package/dist/src/logic/propagation/Propagation.js.map +1 -1
- package/dist/src/logic/propagation/PropagationTaskStore.js +1 -0
- package/dist/src/logic/propagation/PropagationTaskStore.js.map +1 -1
- package/dist/src/logic/protocol-integration/stream-message/GroupKeyRequestTranslator.js +1 -1
- package/dist/src/logic/protocol-integration/stream-message/GroupKeyRequestTranslator.js.map +1 -1
- package/dist/src/logic/protocol-integration/stream-message/GroupKeyResponseTranslator.js +1 -1
- package/dist/src/logic/protocol-integration/stream-message/GroupKeyResponseTranslator.js.map +1 -1
- package/dist/src/logic/protocol-integration/stream-message/StreamMessageTranslator.js +43 -15
- package/dist/src/logic/protocol-integration/stream-message/StreamMessageTranslator.js.map +1 -1
- package/dist/src/logic/protocol-integration/stream-message/oldStreamMessageBinaryUtils.d.ts +3 -0
- package/dist/src/logic/protocol-integration/stream-message/oldStreamMessageBinaryUtils.js +14 -0
- package/dist/src/logic/protocol-integration/stream-message/oldStreamMessageBinaryUtils.js.map +1 -0
- package/dist/src/logic/proxy/ProxyClient.d.ts +1 -1
- package/dist/src/logic/proxy/ProxyClient.js +18 -11
- package/dist/src/logic/proxy/ProxyClient.js.map +1 -1
- package/dist/src/logic/proxy/ProxyConnectionRpcLocal.js +2 -1
- package/dist/src/logic/proxy/ProxyConnectionRpcLocal.js.map +1 -1
- package/dist/src/logic/proxy/ProxyConnectionRpcRemote.js.map +1 -1
- package/dist/src/logic/temporary-connection/TemporaryConnectionRpcLocal.d.ts +2 -2
- package/dist/src/logic/temporary-connection/TemporaryConnectionRpcLocal.js +4 -2
- package/dist/src/logic/temporary-connection/TemporaryConnectionRpcLocal.js.map +1 -1
- package/dist/src/logic/temporary-connection/TemporaryConnectionRpcRemote.js.map +1 -1
- package/dist/src/logic/utils.js.map +1 -1
- package/dist/src/proto/google/protobuf/any.js.map +1 -1
- package/dist/src/proto/google/protobuf/timestamp.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.d.ts +4 -5
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js +38 -29
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.d.ts +22 -12
- package/dist/src/proto/packages/dht/protos/DhtRpc.js +11 -16
- package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.server.d.ts +2 -3
- package/dist/src/proto/packages/proto-rpc/protos/ProtoRpc.js +1 -1
- package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.client.d.ts +27 -0
- package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.client.js +43 -17
- 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 +106 -5
- package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.js +79 -7
- 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 +11 -0
- package/dist/test/benchmark/first-message.js +7 -5
- package/dist/test/benchmark/first-message.js.map +1 -1
- package/dist/test/utils/utils.js +2 -1
- package/dist/test/utils/utils.js.map +1 -1
- package/jest.config.js +3 -38
- package/package.json +7 -7
- package/protos/NetworkRpc.proto +34 -5
- package/src/NetworkNode.ts +5 -1
- package/src/NetworkStack.ts +23 -2
- package/src/exports.ts +4 -0
- package/src/logic/DuplicateMessageDetector.ts +7 -7
- package/src/logic/EntryPointDiscovery.ts +3 -3
- package/src/logic/Layer0Node.ts +2 -0
- package/src/logic/Layer1Node.ts +4 -4
- package/src/logic/NodeList.ts +9 -15
- package/src/logic/RandomGraphNode.ts +24 -23
- package/src/logic/StreamrNode.ts +18 -4
- package/src/logic/createRandomGraphNode.ts +17 -17
- package/src/logic/inspect/Inspector.ts +3 -4
- package/src/logic/neighbor-discovery/HandshakeRpcLocal.ts +18 -18
- package/src/logic/neighbor-discovery/Handshaker.ts +31 -32
- package/src/logic/neighbor-discovery/NeighborFinder.ts +2 -2
- package/src/logic/neighbor-discovery/NeighborUpdateManager.ts +6 -5
- package/src/logic/neighbor-discovery/NeighborUpdateRpcLocal.ts +5 -5
- package/src/logic/node-info/NodeInfoClient.ts +21 -0
- package/src/logic/node-info/NodeInfoRpcLocal.ts +35 -0
- package/src/logic/node-info/NodeInfoRpcRemote.ts +11 -0
- package/src/logic/protocol-integration/stream-message/GroupKeyRequestTranslator.ts +1 -1
- package/src/logic/protocol-integration/stream-message/GroupKeyResponseTranslator.ts +1 -1
- package/src/logic/protocol-integration/stream-message/StreamMessageTranslator.ts +56 -27
- package/src/logic/protocol-integration/stream-message/oldStreamMessageBinaryUtils.ts +11 -0
- package/src/logic/proxy/ProxyClient.ts +10 -10
- package/src/logic/temporary-connection/TemporaryConnectionRpcLocal.ts +3 -3
- package/src/proto/packages/dht/protos/DhtRpc.client.ts +6 -7
- package/src/proto/packages/dht/protos/DhtRpc.server.ts +3 -4
- package/src/proto/packages/dht/protos/DhtRpc.ts +32 -20
- package/src/proto/packages/proto-rpc/protos/ProtoRpc.ts +1 -1
- package/src/proto/packages/trackerless-network/protos/NetworkRpc.client.ts +30 -1
- package/src/proto/packages/trackerless-network/protos/NetworkRpc.server.ts +12 -1
- package/src/proto/packages/trackerless-network/protos/NetworkRpc.ts +138 -11
- package/test/benchmark/first-message.ts +28 -8
- package/test/end-to-end/inspect.test.ts +13 -1
- package/test/end-to-end/proxy-and-full-node.test.ts +14 -1
- package/test/end-to-end/proxy-connections.test.ts +14 -2
- package/test/end-to-end/proxy-key-exchange.test.ts +15 -8
- package/test/end-to-end/random-graph-with-real-connections.test.ts +21 -21
- package/test/end-to-end/webrtc-full-node-network.test.ts +3 -3
- package/test/end-to-end/websocket-full-node-network.test.ts +3 -3
- package/test/integration/Handshakes.test.ts +8 -8
- package/test/integration/NetworkNode.test.ts +19 -1
- package/test/integration/NetworkRpc.test.ts +3 -2
- package/test/integration/NodeInfoRpc.test.ts +103 -0
- package/test/integration/Propagation.test.ts +2 -2
- package/test/integration/RandomGraphNode-Layer1Node-Latencies.test.ts +20 -21
- package/test/integration/RandomGraphNode-Layer1Node.test.ts +22 -19
- package/test/integration/stream-without-default-entrypoints.test.ts +17 -11
- package/test/unit/HandshakeRpcLocal.test.ts +15 -15
- package/test/unit/Handshaker.test.ts +3 -3
- package/test/unit/NeighborFinder.test.ts +5 -5
- package/test/unit/NodeList.test.ts +56 -57
- package/test/unit/Propagation.test.ts +4 -2
- package/test/unit/RandomGraphNode.test.ts +7 -8
- package/test/unit/StreamMessageTranslator.test.ts +7 -4
- package/test/unit/StreamrNode.test.ts +2 -0
- package/test/unit/oldStreamMessageBinaryUtils.test.ts +39 -0
- package/test/utils/mock/MockLayer0Node.ts +6 -1
- package/test/utils/mock/MockLayer1Node.ts +2 -2
- package/test/utils/mock/Transport.ts +1 -1
- package/test/utils/utils.ts +3 -1
- package/tsconfig.jest.json +3 -3
- package/tsconfig.node.json +0 -1
- package/dist/package.json +0 -55
package/src/exports.ts
CHANGED
|
@@ -2,3 +2,7 @@ export { NetworkStack, NetworkOptions } from './NetworkStack'
|
|
|
2
2
|
export { NetworkNode, createNetworkNode } from './NetworkNode'
|
|
3
3
|
export { StreamrNodeConfig } from './logic/StreamrNode'
|
|
4
4
|
export { ProxyDirection } from './proto/packages/trackerless-network/protos/NetworkRpc'
|
|
5
|
+
export {
|
|
6
|
+
convertStreamMessageToBytes,
|
|
7
|
+
convertBytesToStreamMessage
|
|
8
|
+
} from './logic/protocol-integration/stream-message/oldStreamMessageBinaryUtils'
|
|
@@ -82,11 +82,11 @@ export class GapMisMatchError extends Error {
|
|
|
82
82
|
*
|
|
83
83
|
*/
|
|
84
84
|
export class DuplicateMessageDetector {
|
|
85
|
-
private readonly
|
|
85
|
+
private readonly maxGapCount: number
|
|
86
86
|
private readonly gaps: Array<[NumberPair, NumberPair]>
|
|
87
87
|
|
|
88
|
-
constructor(
|
|
89
|
-
this.
|
|
88
|
+
constructor(maxGapCount = 10000) {
|
|
89
|
+
this.maxGapCount = maxGapCount
|
|
90
90
|
this.gaps = [] // ascending order of half-closed intervals (x,y] representing gaps that contain unseen message(s)
|
|
91
91
|
}
|
|
92
92
|
|
|
@@ -144,7 +144,7 @@ export class DuplicateMessageDetector {
|
|
|
144
144
|
// - last gap is [n, Infinity]
|
|
145
145
|
// - anything not covered by a gap is considered seen
|
|
146
146
|
|
|
147
|
-
this.
|
|
147
|
+
this.dropLowestGapIfOverMaxGapCount()
|
|
148
148
|
return true
|
|
149
149
|
}
|
|
150
150
|
if (number.greaterThan(lowerBound)) {
|
|
@@ -154,9 +154,9 @@ export class DuplicateMessageDetector {
|
|
|
154
154
|
return false
|
|
155
155
|
}
|
|
156
156
|
|
|
157
|
-
private
|
|
158
|
-
// invariant: this.gaps.length <= this.
|
|
159
|
-
if (this.gaps.length > this.
|
|
157
|
+
private dropLowestGapIfOverMaxGapCount(): void {
|
|
158
|
+
// invariant: this.gaps.length <= this.maxGapCount + 1
|
|
159
|
+
if (this.gaps.length > this.maxGapCount) {
|
|
160
160
|
this.gaps.shift()
|
|
161
161
|
}
|
|
162
162
|
}
|
|
@@ -122,7 +122,7 @@ export class EntryPointDiscovery {
|
|
|
122
122
|
if (this.abortController.signal.aborted) {
|
|
123
123
|
return
|
|
124
124
|
}
|
|
125
|
-
const possibleNetworkSplitDetected = this.config.layer1Node.
|
|
125
|
+
const possibleNetworkSplitDetected = this.config.layer1Node.getNeighborCount() < NETWORK_SPLIT_AVOIDANCE_LIMIT
|
|
126
126
|
if ((currentEntrypointCount < ENTRYPOINT_STORE_LIMIT) || possibleNetworkSplitDetected) {
|
|
127
127
|
this.isLocalNodeStoredAsEntryPoint = true
|
|
128
128
|
await this.storeSelfAsEntryPoint()
|
|
@@ -163,10 +163,10 @@ export class EntryPointDiscovery {
|
|
|
163
163
|
await exponentialRunOff(async () => {
|
|
164
164
|
const rediscoveredEntrypoints = await this.discoverEntryPoints()
|
|
165
165
|
await this.config.layer1Node.joinDht(rediscoveredEntrypoints, false, false)
|
|
166
|
-
if (this.config.layer1Node.
|
|
166
|
+
if (this.config.layer1Node.getNeighborCount() < NETWORK_SPLIT_AVOIDANCE_LIMIT) {
|
|
167
167
|
// Filter out nodes that are not neighbors as those nodes are assumed to be offline
|
|
168
168
|
const nodesToAvoid = rediscoveredEntrypoints
|
|
169
|
-
.filter((peer) => !this.config.layer1Node.
|
|
169
|
+
.filter((peer) => !this.config.layer1Node.getNeighbors()
|
|
170
170
|
.some((neighbor) => areEqualPeerDescriptors(neighbor, peer)))
|
|
171
171
|
.map((peer) => getNodeIdFromPeerDescriptor(peer))
|
|
172
172
|
nodesToAvoid.forEach((node) => this.networkSplitAvoidedNodes.add(node))
|
package/src/logic/Layer0Node.ts
CHANGED
|
@@ -10,6 +10,8 @@ export interface Layer0Node extends ITransport {
|
|
|
10
10
|
deleteDataFromDht(key: DhtAddress, waitForCompletion: boolean): Promise<void>
|
|
11
11
|
waitForNetworkConnectivity(): Promise<void>
|
|
12
12
|
getTransport(): ITransport
|
|
13
|
+
getNeighbors(): PeerDescriptor[]
|
|
14
|
+
getConnections(): PeerDescriptor[]
|
|
13
15
|
start(): Promise<void>
|
|
14
16
|
stop(): Promise<void>
|
|
15
17
|
}
|
package/src/logic/Layer1Node.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PeerDescriptor } from '@streamr/dht'
|
|
1
|
+
import { DhtAddress, PeerDescriptor } from '@streamr/dht'
|
|
2
2
|
|
|
3
3
|
export interface Layer1NodeEvents {
|
|
4
4
|
newContact: (peerDescriptor: PeerDescriptor, closestPeers: PeerDescriptor[]) => void
|
|
@@ -11,10 +11,10 @@ export interface Layer1Node {
|
|
|
11
11
|
on<T extends keyof Layer1NodeEvents>(eventName: T, listener: (peerDescriptor: PeerDescriptor, peers: PeerDescriptor[]) => void): void
|
|
12
12
|
once<T extends keyof Layer1NodeEvents>(eventName: T, listener: (peerDescriptor: PeerDescriptor, peers: PeerDescriptor[]) => void): void
|
|
13
13
|
off<T extends keyof Layer1NodeEvents>(eventName: T, listener: (peerDescriptor: PeerDescriptor, peers: PeerDescriptor[]) => void): void
|
|
14
|
-
removeContact: (
|
|
14
|
+
removeContact: (nodeId: DhtAddress) => void
|
|
15
15
|
getClosestContacts: (maxCount?: number) => PeerDescriptor[]
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
getNeighbors: () => PeerDescriptor[]
|
|
17
|
+
getNeighborCount(): number
|
|
18
18
|
joinDht: (entryPoints: PeerDescriptor[], doRandomJoin?: boolean, retry?: boolean) => Promise<void>
|
|
19
19
|
start: () => Promise<void>
|
|
20
20
|
stop: () => Promise<void>
|
package/src/logic/NodeList.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DhtAddress,
|
|
1
|
+
import { DhtAddress, getNodeIdFromPeerDescriptor } from '@streamr/dht'
|
|
2
2
|
import { sample } from 'lodash'
|
|
3
3
|
import { DeliveryRpcRemote } from './DeliveryRpcRemote'
|
|
4
4
|
import { EventEmitter } from 'eventemitter3'
|
|
@@ -13,6 +13,8 @@ const getValuesOfIncludedKeys = (nodes: Map<DhtAddress, DeliveryRpcRemote>, excl
|
|
|
13
13
|
.map(([_id, node]) => node)
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
// The items in the list are in the insertion order
|
|
17
|
+
|
|
16
18
|
export class NodeList extends EventEmitter<Events> {
|
|
17
19
|
private readonly nodes: Map<DhtAddress, DeliveryRpcRemote>
|
|
18
20
|
private readonly limit: number
|
|
@@ -37,19 +39,11 @@ export class NodeList extends EventEmitter<Events> {
|
|
|
37
39
|
}
|
|
38
40
|
}
|
|
39
41
|
|
|
40
|
-
remove(
|
|
41
|
-
this.nodes.delete(getNodeIdFromPeerDescriptor(peerDescriptor))
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
removeById(nodeId: DhtAddress): void {
|
|
42
|
+
remove(nodeId: DhtAddress): void {
|
|
45
43
|
this.nodes.delete(nodeId)
|
|
46
44
|
}
|
|
47
45
|
|
|
48
|
-
|
|
49
|
-
return this.nodes.has(getNodeIdFromPeerDescriptor(peerDescriptor))
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
hasNodeById(nodeId: DhtAddress): boolean {
|
|
46
|
+
has(nodeId: DhtAddress): boolean {
|
|
53
47
|
return this.nodes.has(nodeId)
|
|
54
48
|
}
|
|
55
49
|
|
|
@@ -77,20 +71,20 @@ export class NodeList extends EventEmitter<Events> {
|
|
|
77
71
|
return sample(getValuesOfIncludedKeys(this.nodes, exclude))
|
|
78
72
|
}
|
|
79
73
|
|
|
80
|
-
|
|
74
|
+
getFirst(exclude: DhtAddress[]): DeliveryRpcRemote | undefined {
|
|
81
75
|
const included = getValuesOfIncludedKeys(this.nodes, exclude)
|
|
82
76
|
return included[0]
|
|
83
77
|
}
|
|
84
78
|
|
|
85
|
-
|
|
79
|
+
getFirstAndLast(exclude: DhtAddress[]): DeliveryRpcRemote[] {
|
|
86
80
|
const included = getValuesOfIncludedKeys(this.nodes, exclude)
|
|
87
81
|
if (included.length === 0) {
|
|
88
82
|
return []
|
|
89
83
|
}
|
|
90
|
-
return included.length > 1 ? [this.
|
|
84
|
+
return included.length > 1 ? [this.getFirst(exclude)!, this.getLast(exclude)!] : [this.getFirst(exclude)!]
|
|
91
85
|
}
|
|
92
86
|
|
|
93
|
-
|
|
87
|
+
getLast(exclude: DhtAddress[]): DeliveryRpcRemote | undefined {
|
|
94
88
|
const included = getValuesOfIncludedKeys(this.nodes, exclude)
|
|
95
89
|
return included[included.length - 1]
|
|
96
90
|
}
|
|
@@ -36,7 +36,7 @@ import { uniqBy } from 'lodash'
|
|
|
36
36
|
|
|
37
37
|
export interface Events {
|
|
38
38
|
message: (message: StreamMessage) => void
|
|
39
|
-
|
|
39
|
+
neighborConnected: (nodeId: DhtAddress) => void
|
|
40
40
|
entryPointLeaveDetected: () => void
|
|
41
41
|
}
|
|
42
42
|
|
|
@@ -49,13 +49,13 @@ export interface StrictRandomGraphNodeConfig {
|
|
|
49
49
|
nodeViewSize: number
|
|
50
50
|
nearbyNodeView: NodeList
|
|
51
51
|
randomNodeView: NodeList
|
|
52
|
-
|
|
52
|
+
neighbors: NodeList
|
|
53
53
|
handshaker: Handshaker
|
|
54
54
|
neighborFinder: NeighborFinder
|
|
55
55
|
neighborUpdateManager: NeighborUpdateManager
|
|
56
56
|
propagation: Propagation
|
|
57
57
|
rpcCommunicator: ListeningRpcCommunicator
|
|
58
|
-
|
|
58
|
+
neighborCount: number
|
|
59
59
|
inspector: Inspector
|
|
60
60
|
temporaryConnectionRpcLocal: TemporaryConnectionRpcLocal
|
|
61
61
|
isLocalNodeEntryPoint: () => boolean
|
|
@@ -90,13 +90,13 @@ export class RandomGraphNode extends EventEmitter<Events> {
|
|
|
90
90
|
}
|
|
91
91
|
const contact = this.config.nearbyNodeView.get(sourceId)
|
|
92
92
|
|| this.config.randomNodeView.get(sourceId)
|
|
93
|
-
|| this.config.
|
|
93
|
+
|| this.config.neighbors.get(sourceId)
|
|
94
94
|
|| this.config.proxyConnectionRpcLocal?.getConnection(sourceId )?.remote
|
|
95
95
|
// TODO: check integrity of notifier?
|
|
96
96
|
if (contact) {
|
|
97
|
-
this.config.layer1Node.removeContact(
|
|
98
|
-
this.config.
|
|
99
|
-
this.config.nearbyNodeView.remove(
|
|
97
|
+
this.config.layer1Node.removeContact(sourceId)
|
|
98
|
+
this.config.neighbors.remove(sourceId)
|
|
99
|
+
this.config.nearbyNodeView.remove(sourceId)
|
|
100
100
|
this.config.connectionLocker.unlockConnection(contact.getPeerDescriptor(), this.config.streamPartId)
|
|
101
101
|
this.config.neighborFinder.start([sourceId])
|
|
102
102
|
this.config.proxyConnectionRpcLocal?.removeConnection(sourceId)
|
|
@@ -143,11 +143,11 @@ export class RandomGraphNode extends EventEmitter<Events> {
|
|
|
143
143
|
this.abortController.signal
|
|
144
144
|
)
|
|
145
145
|
addManagedEventListener(
|
|
146
|
-
this.config.
|
|
146
|
+
this.config.neighbors,
|
|
147
147
|
'nodeAdded',
|
|
148
148
|
(id, _remote) => {
|
|
149
149
|
this.config.propagation.onNeighborJoined(id)
|
|
150
|
-
this.emit('
|
|
150
|
+
this.emit('neighborConnected', id)
|
|
151
151
|
},
|
|
152
152
|
this.abortController.signal
|
|
153
153
|
)
|
|
@@ -182,7 +182,7 @@ export class RandomGraphNode extends EventEmitter<Events> {
|
|
|
182
182
|
return
|
|
183
183
|
}
|
|
184
184
|
this.updateNearbyNodeView(closestNodes)
|
|
185
|
-
if (this.config.
|
|
185
|
+
if (this.config.neighbors.size() < this.config.neighborCount) {
|
|
186
186
|
this.config.neighborFinder.start()
|
|
187
187
|
}
|
|
188
188
|
}
|
|
@@ -205,7 +205,7 @@ export class RandomGraphNode extends EventEmitter<Events> {
|
|
|
205
205
|
this.config.rpcRequestTimeout
|
|
206
206
|
)
|
|
207
207
|
))
|
|
208
|
-
for (const descriptor of this.config.layer1Node.
|
|
208
|
+
for (const descriptor of this.config.layer1Node.getNeighbors()) {
|
|
209
209
|
if (this.config.nearbyNodeView.size() >= this.config.nodeViewSize) {
|
|
210
210
|
break
|
|
211
211
|
}
|
|
@@ -235,7 +235,7 @@ export class RandomGraphNode extends EventEmitter<Events> {
|
|
|
235
235
|
this.config.rpcRequestTimeout
|
|
236
236
|
)
|
|
237
237
|
))
|
|
238
|
-
if (this.config.
|
|
238
|
+
if (this.config.neighbors.size() < this.config.neighborCount) {
|
|
239
239
|
this.config.neighborFinder.start()
|
|
240
240
|
}
|
|
241
241
|
}
|
|
@@ -257,11 +257,12 @@ export class RandomGraphNode extends EventEmitter<Events> {
|
|
|
257
257
|
}
|
|
258
258
|
|
|
259
259
|
private onNodeDisconnected(peerDescriptor: PeerDescriptor): void {
|
|
260
|
-
|
|
261
|
-
|
|
260
|
+
const nodeId = getNodeIdFromPeerDescriptor(peerDescriptor)
|
|
261
|
+
if (this.config.neighbors.has(nodeId)) {
|
|
262
|
+
this.config.neighbors.remove(nodeId)
|
|
262
263
|
this.config.connectionLocker.unlockConnection(peerDescriptor, this.config.streamPartId)
|
|
263
|
-
this.config.neighborFinder.start([
|
|
264
|
-
this.config.temporaryConnectionRpcLocal.removeNode(
|
|
264
|
+
this.config.neighborFinder.start([nodeId])
|
|
265
|
+
this.config.temporaryConnectionRpcLocal.removeNode(nodeId)
|
|
265
266
|
}
|
|
266
267
|
}
|
|
267
268
|
|
|
@@ -270,7 +271,7 @@ export class RandomGraphNode extends EventEmitter<Events> {
|
|
|
270
271
|
this.config.layer1Node.getClosestContacts(this.config.nodeViewSize).forEach((peer: PeerDescriptor) => {
|
|
271
272
|
nodes.push(peer)
|
|
272
273
|
})
|
|
273
|
-
this.config.layer1Node.
|
|
274
|
+
this.config.layer1Node.getNeighbors().forEach((peer: PeerDescriptor) => {
|
|
274
275
|
nodes.push(peer)
|
|
275
276
|
})
|
|
276
277
|
return uniqBy(nodes, (p) => getNodeIdFromPeerDescriptor(p))
|
|
@@ -289,13 +290,13 @@ export class RandomGraphNode extends EventEmitter<Events> {
|
|
|
289
290
|
}
|
|
290
291
|
this.abortController.abort()
|
|
291
292
|
this.config.proxyConnectionRpcLocal?.stop()
|
|
292
|
-
this.config.
|
|
293
|
+
this.config.neighbors.getAll().map(
|
|
293
294
|
(remote) => remote.leaveStreamPartNotice(this.config.streamPartId, this.config.isLocalNodeEntryPoint())
|
|
294
295
|
)
|
|
295
296
|
this.config.rpcCommunicator.destroy()
|
|
296
297
|
this.removeAllListeners()
|
|
297
298
|
this.config.nearbyNodeView.stop()
|
|
298
|
-
this.config.
|
|
299
|
+
this.config.neighbors.stop()
|
|
299
300
|
this.config.randomNodeView.stop()
|
|
300
301
|
this.config.neighborFinder.stop()
|
|
301
302
|
this.config.neighborUpdateManager.stop()
|
|
@@ -315,7 +316,7 @@ export class RandomGraphNode extends EventEmitter<Events> {
|
|
|
315
316
|
}
|
|
316
317
|
|
|
317
318
|
private getPropagationTargets(msg: StreamMessage): DhtAddress[] {
|
|
318
|
-
let propagationTargets = this.config.
|
|
319
|
+
let propagationTargets = this.config.neighbors.getIds()
|
|
319
320
|
if (this.config.proxyConnectionRpcLocal) {
|
|
320
321
|
propagationTargets = propagationTargets.concat(this.config.proxyConnectionRpcLocal.getPropagationTargets(msg))
|
|
321
322
|
}
|
|
@@ -328,15 +329,15 @@ export class RandomGraphNode extends EventEmitter<Events> {
|
|
|
328
329
|
return getNodeIdFromPeerDescriptor(this.config.localPeerDescriptor)
|
|
329
330
|
}
|
|
330
331
|
|
|
331
|
-
|
|
332
|
+
getOutgoingHandshakeCount(): number {
|
|
332
333
|
return this.config.handshaker.getOngoingHandshakes().size
|
|
333
334
|
}
|
|
334
335
|
|
|
335
|
-
|
|
336
|
+
getNeighbors(): PeerDescriptor[] {
|
|
336
337
|
if (!this.started && this.isStopped()) {
|
|
337
338
|
return []
|
|
338
339
|
}
|
|
339
|
-
return this.config.
|
|
340
|
+
return this.config.neighbors.getAll().map((n) => n.getPeerDescriptor())
|
|
340
341
|
}
|
|
341
342
|
|
|
342
343
|
getNearbyNodeView(): NodeList {
|
package/src/logic/StreamrNode.ts
CHANGED
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
} from '@streamr/utils'
|
|
19
19
|
import { EventEmitter } from 'eventemitter3'
|
|
20
20
|
import { sampleSize } from 'lodash'
|
|
21
|
-
import { ProxyDirection, StreamMessage } from '../proto/packages/trackerless-network/protos/NetworkRpc'
|
|
21
|
+
import { ProxyDirection, StreamPartitionInfo, StreamMessage } from '../proto/packages/trackerless-network/protos/NetworkRpc'
|
|
22
22
|
import { Layer0Node } from './Layer0Node'
|
|
23
23
|
import { Layer1Node } from './Layer1Node'
|
|
24
24
|
import { RandomGraphNode } from './RandomGraphNode'
|
|
@@ -52,7 +52,7 @@ interface Metrics extends MetricsDefinition {
|
|
|
52
52
|
|
|
53
53
|
export interface StreamrNodeConfig {
|
|
54
54
|
metricsContext?: MetricsContext
|
|
55
|
-
|
|
55
|
+
streamPartitionNeighborCount?: number
|
|
56
56
|
streamPartitionMinPropagationTargets?: number
|
|
57
57
|
acceptProxyConnections?: boolean
|
|
58
58
|
rpcRequestTimeout?: number
|
|
@@ -222,7 +222,7 @@ export class StreamrNode extends EventEmitter<Events> {
|
|
|
222
222
|
connectionLocker: this.connectionLocker!,
|
|
223
223
|
localPeerDescriptor: this.layer0Node!.getLocalPeerDescriptor(),
|
|
224
224
|
minPropagationTargets: this.config.streamPartitionMinPropagationTargets,
|
|
225
|
-
|
|
225
|
+
neighborCount: this.config.streamPartitionNeighborCount,
|
|
226
226
|
acceptProxyConnections: this.config.acceptProxyConnections,
|
|
227
227
|
rpcRequestTimeout: this.config.rpcRequestTimeout,
|
|
228
228
|
isLocalNodeEntryPoint
|
|
@@ -284,6 +284,20 @@ export class StreamrNode extends EventEmitter<Events> {
|
|
|
284
284
|
return false
|
|
285
285
|
}
|
|
286
286
|
|
|
287
|
+
// TODO inline this method?
|
|
288
|
+
getNodeInfo(): StreamPartitionInfo[] {
|
|
289
|
+
const streamParts = Array.from(this.streamParts.entries()).filter(([_, node]) => node.proxied === false)
|
|
290
|
+
return streamParts.map(([streamPartId]) => {
|
|
291
|
+
const stream = this.streamParts.get(streamPartId)! as { node: RandomGraphNode, layer1Node: Layer1Node }
|
|
292
|
+
return {
|
|
293
|
+
id: streamPartId,
|
|
294
|
+
controlLayerNeighbors: stream.layer1Node.getNeighbors(),
|
|
295
|
+
deliveryLayerNeighbors: stream.node.getNeighbors()
|
|
296
|
+
}
|
|
297
|
+
})
|
|
298
|
+
|
|
299
|
+
}
|
|
300
|
+
|
|
287
301
|
setStreamPartEntryPoints(streamPartId: StreamPartID, entryPoints: PeerDescriptor[]): void {
|
|
288
302
|
this.knownStreamPartEntryPoints.set(streamPartId, entryPoints)
|
|
289
303
|
}
|
|
@@ -314,7 +328,7 @@ export class StreamrNode extends EventEmitter<Events> {
|
|
|
314
328
|
getNeighbors(streamPartId: StreamPartID): DhtAddress[] {
|
|
315
329
|
const streamPart = this.streamParts.get(streamPartId)
|
|
316
330
|
return (streamPart !== undefined) && (streamPart.proxied === false)
|
|
317
|
-
? streamPart.node.
|
|
331
|
+
? streamPart.node.getNeighbors().map((n) => getNodeIdFromPeerDescriptor(n))
|
|
318
332
|
: []
|
|
319
333
|
}
|
|
320
334
|
|
|
@@ -13,11 +13,11 @@ import { TemporaryConnectionRpcLocal } from './temporary-connection/TemporaryCon
|
|
|
13
13
|
import { formStreamPartDeliveryServiceId } from './formStreamPartDeliveryServiceId'
|
|
14
14
|
|
|
15
15
|
type RandomGraphNodeConfig = MarkOptional<StrictRandomGraphNodeConfig,
|
|
16
|
-
'nearbyNodeView' | 'randomNodeView' | '
|
|
17
|
-
| 'handshaker' | 'neighborFinder' | 'neighborUpdateManager' | '
|
|
16
|
+
'nearbyNodeView' | 'randomNodeView' | 'neighbors' | 'propagation'
|
|
17
|
+
| 'handshaker' | 'neighborFinder' | 'neighborUpdateManager' | 'neighborCount'
|
|
18
18
|
| 'rpcCommunicator' | 'nodeViewSize'
|
|
19
19
|
| 'inspector' | 'temporaryConnectionRpcLocal'> & {
|
|
20
|
-
|
|
20
|
+
maxContactCount?: number
|
|
21
21
|
minPropagationTargets?: number
|
|
22
22
|
acceptProxyConnections?: boolean
|
|
23
23
|
neighborUpdateInterval?: number
|
|
@@ -29,14 +29,14 @@ const createConfigWithDefaults = (config: RandomGraphNodeConfig): StrictRandomGr
|
|
|
29
29
|
formStreamPartDeliveryServiceId(config.streamPartId),
|
|
30
30
|
config.transport
|
|
31
31
|
)
|
|
32
|
-
const
|
|
33
|
-
const
|
|
32
|
+
const neighborCount = config.neighborCount ?? 4
|
|
33
|
+
const maxContactCount = config.maxContactCount ?? 20
|
|
34
34
|
const minPropagationTargets = config.minPropagationTargets ?? 2
|
|
35
35
|
const acceptProxyConnections = config.acceptProxyConnections ?? false
|
|
36
36
|
const neighborUpdateInterval = config.neighborUpdateInterval ?? 10000
|
|
37
|
-
const nearbyNodeView = config.nearbyNodeView ?? new NodeList(ownNodeId,
|
|
38
|
-
const randomNodeView = config.randomNodeView ?? new NodeList(ownNodeId,
|
|
39
|
-
const
|
|
37
|
+
const nearbyNodeView = config.nearbyNodeView ?? new NodeList(ownNodeId, maxContactCount)
|
|
38
|
+
const randomNodeView = config.randomNodeView ?? new NodeList(ownNodeId, maxContactCount)
|
|
39
|
+
const neighbors = config.neighbors ?? new NodeList(ownNodeId, maxContactCount)
|
|
40
40
|
|
|
41
41
|
const temporaryConnectionRpcLocal = new TemporaryConnectionRpcLocal({
|
|
42
42
|
rpcCommunicator,
|
|
@@ -50,7 +50,7 @@ const createConfigWithDefaults = (config: RandomGraphNodeConfig): StrictRandomGr
|
|
|
50
50
|
const propagation = config.propagation ?? new Propagation({
|
|
51
51
|
minPropagationTargets,
|
|
52
52
|
sendToNeighbor: async (neighborId: DhtAddress, msg: StreamMessage): Promise<void> => {
|
|
53
|
-
const remote =
|
|
53
|
+
const remote = neighbors.get(neighborId) ?? temporaryConnectionRpcLocal.getNodes().get(neighborId)
|
|
54
54
|
const proxyConnection = proxyConnectionRpcLocal?.getConnection(neighborId)
|
|
55
55
|
if (remote) {
|
|
56
56
|
await remote.sendStreamMessage(msg)
|
|
@@ -68,18 +68,18 @@ const createConfigWithDefaults = (config: RandomGraphNodeConfig): StrictRandomGr
|
|
|
68
68
|
rpcCommunicator,
|
|
69
69
|
nearbyNodeView,
|
|
70
70
|
randomNodeView,
|
|
71
|
-
|
|
72
|
-
maxNeighborCount:
|
|
71
|
+
neighbors,
|
|
72
|
+
maxNeighborCount: neighborCount,
|
|
73
73
|
rpcRequestTimeout: config.rpcRequestTimeout
|
|
74
74
|
})
|
|
75
75
|
const neighborFinder = config.neighborFinder ?? new NeighborFinder({
|
|
76
|
-
|
|
76
|
+
neighbors,
|
|
77
77
|
nearbyNodeView,
|
|
78
78
|
doFindNeighbors: (excludedIds) => handshaker.attemptHandshakesOnContacts(excludedIds),
|
|
79
|
-
minCount:
|
|
79
|
+
minCount: neighborCount
|
|
80
80
|
})
|
|
81
81
|
const neighborUpdateManager = config.neighborUpdateManager ?? new NeighborUpdateManager({
|
|
82
|
-
|
|
82
|
+
neighbors,
|
|
83
83
|
nearbyNodeView,
|
|
84
84
|
localPeerDescriptor: config.localPeerDescriptor,
|
|
85
85
|
neighborFinder,
|
|
@@ -97,14 +97,14 @@ const createConfigWithDefaults = (config: RandomGraphNodeConfig): StrictRandomGr
|
|
|
97
97
|
...config,
|
|
98
98
|
nearbyNodeView,
|
|
99
99
|
randomNodeView,
|
|
100
|
-
|
|
100
|
+
neighbors,
|
|
101
101
|
rpcCommunicator,
|
|
102
102
|
handshaker,
|
|
103
103
|
neighborFinder,
|
|
104
104
|
neighborUpdateManager,
|
|
105
105
|
propagation,
|
|
106
|
-
|
|
107
|
-
nodeViewSize:
|
|
106
|
+
neighborCount,
|
|
107
|
+
nodeViewSize: maxContactCount,
|
|
108
108
|
proxyConnectionRpcLocal,
|
|
109
109
|
inspector,
|
|
110
110
|
temporaryConnectionRpcLocal
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { PeerDescriptor, ConnectionLocker, LockID, DhtAddress, getNodeIdFromPeerDescriptor } from '@streamr/dht'
|
|
1
|
+
import { PeerDescriptor, ConnectionLocker, LockID, DhtAddress, getNodeIdFromPeerDescriptor, ListeningRpcCommunicator } from '@streamr/dht'
|
|
2
2
|
import { MessageID } from '../../proto/packages/trackerless-network/protos/NetworkRpc'
|
|
3
3
|
import { InspectSession, Events as InspectSessionEvents } from './InspectSession'
|
|
4
4
|
import { TemporaryConnectionRpcClient } from '../../proto/packages/trackerless-network/protos/NetworkRpc.client'
|
|
5
|
-
import { RpcCommunicator } from '@streamr/proto-rpc'
|
|
6
5
|
import { Logger, waitForEvent3 } from '@streamr/utils'
|
|
7
6
|
import { TemporaryConnectionRpcRemote } from '../temporary-connection/TemporaryConnectionRpcRemote'
|
|
8
7
|
import { StreamPartID } from '@streamr/protocol'
|
|
@@ -10,7 +9,7 @@ import { StreamPartID } from '@streamr/protocol'
|
|
|
10
9
|
interface InspectorConfig {
|
|
11
10
|
localPeerDescriptor: PeerDescriptor
|
|
12
11
|
streamPartId: StreamPartID
|
|
13
|
-
rpcCommunicator:
|
|
12
|
+
rpcCommunicator: ListeningRpcCommunicator
|
|
14
13
|
connectionLocker: ConnectionLocker
|
|
15
14
|
inspectionTimeout?: number
|
|
16
15
|
openInspectConnection?: (peerDescriptor: PeerDescriptor, lockId: LockID) => Promise<void>
|
|
@@ -24,7 +23,7 @@ export class Inspector {
|
|
|
24
23
|
private readonly sessions: Map<DhtAddress, InspectSession> = new Map()
|
|
25
24
|
private readonly streamPartId: StreamPartID
|
|
26
25
|
private readonly localPeerDescriptor: PeerDescriptor
|
|
27
|
-
private readonly rpcCommunicator:
|
|
26
|
+
private readonly rpcCommunicator: ListeningRpcCommunicator
|
|
28
27
|
private readonly connectionLocker: ConnectionLocker
|
|
29
28
|
private readonly inspectionTimeout: number
|
|
30
29
|
private readonly openInspectConnection: (peerDescriptor: PeerDescriptor, lockId: LockID) => Promise<void>
|
|
@@ -23,7 +23,7 @@ import { StreamPartID } from '@streamr/protocol'
|
|
|
23
23
|
|
|
24
24
|
interface HandshakeRpcLocalConfig {
|
|
25
25
|
streamPartId: StreamPartID
|
|
26
|
-
|
|
26
|
+
neighbors: NodeList
|
|
27
27
|
connectionLocker: ConnectionLocker
|
|
28
28
|
ongoingHandshakes: Set<DhtAddress>
|
|
29
29
|
ongoingInterleaves: Set<DhtAddress>
|
|
@@ -53,13 +53,13 @@ export class HandshakeRpcLocal implements IHandshakeRpc {
|
|
|
53
53
|
const senderNodeId = getNodeIdFromPeerDescriptor(senderDescriptor)
|
|
54
54
|
if (this.config.ongoingInterleaves.has(senderNodeId)) {
|
|
55
55
|
return this.rejectHandshake(request)
|
|
56
|
-
} else if (this.config.
|
|
56
|
+
} else if (this.config.neighbors.has(senderNodeId)
|
|
57
57
|
|| this.config.ongoingHandshakes.has(senderNodeId)
|
|
58
58
|
) {
|
|
59
59
|
return this.acceptHandshake(request, senderDescriptor)
|
|
60
|
-
} else if (this.config.
|
|
60
|
+
} else if (this.config.neighbors.size() + this.config.ongoingHandshakes.size < this.config.maxNeighborCount) {
|
|
61
61
|
return this.acceptHandshake(request, senderDescriptor)
|
|
62
|
-
} else if (this.config.
|
|
62
|
+
} else if (this.config.neighbors.size(getInterleaveSourceIds()) - this.config.ongoingInterleaves.size >= 2) {
|
|
63
63
|
// Do not accept the handshakes requests if the target neighbor count can potentially drop below 2
|
|
64
64
|
// due to interleaving. This ensures that a stable number of connections is kept during high churn.
|
|
65
65
|
return this.acceptHandshakeWithInterleaving(request, senderDescriptor)
|
|
@@ -73,7 +73,7 @@ export class HandshakeRpcLocal implements IHandshakeRpc {
|
|
|
73
73
|
requestId: request.requestId,
|
|
74
74
|
accepted: true
|
|
75
75
|
}
|
|
76
|
-
this.config.
|
|
76
|
+
this.config.neighbors.add(this.config.createDeliveryRpcRemote(requester))
|
|
77
77
|
this.config.connectionLocker.lockConnection(requester, this.config.streamPartId)
|
|
78
78
|
return res
|
|
79
79
|
}
|
|
@@ -95,21 +95,21 @@ export class HandshakeRpcLocal implements IHandshakeRpc {
|
|
|
95
95
|
if (request.interleaveSourceId !== undefined) {
|
|
96
96
|
exclude.push(getDhtAddressFromRaw(request.interleaveSourceId))
|
|
97
97
|
}
|
|
98
|
-
const
|
|
99
|
-
const
|
|
100
|
-
if (
|
|
101
|
-
const nodeId = getNodeIdFromPeerDescriptor(
|
|
102
|
-
const remote = this.config.createRpcRemote(
|
|
98
|
+
const last = this.config.neighbors.getLast(exclude)
|
|
99
|
+
const lastPeerDescriptor = last ? last.getPeerDescriptor() : undefined
|
|
100
|
+
if (last) {
|
|
101
|
+
const nodeId = getNodeIdFromPeerDescriptor(last.getPeerDescriptor())
|
|
102
|
+
const remote = this.config.createRpcRemote(last.getPeerDescriptor())
|
|
103
103
|
this.config.ongoingInterleaves.add(nodeId)
|
|
104
104
|
// Run this with then catch instead of setImmediate to avoid changes in state
|
|
105
105
|
// eslint-disable-next-line promise/catch-or-return
|
|
106
106
|
remote.interleaveRequest(requester).then((response) => {
|
|
107
|
-
// If response is accepted, remove the
|
|
107
|
+
// If response is accepted, remove the last node from the target neighbors
|
|
108
108
|
// and unlock the connection
|
|
109
|
-
// If response is not accepted, keep the
|
|
109
|
+
// If response is not accepted, keep the last node as a neighbor
|
|
110
110
|
if (response.accepted) {
|
|
111
|
-
this.config.
|
|
112
|
-
this.config.connectionLocker.unlockConnection(
|
|
111
|
+
this.config.neighbors.remove(getNodeIdFromPeerDescriptor(lastPeerDescriptor!))
|
|
112
|
+
this.config.connectionLocker.unlockConnection(lastPeerDescriptor!, this.config.streamPartId)
|
|
113
113
|
}
|
|
114
114
|
return
|
|
115
115
|
}).catch(() => {
|
|
@@ -118,12 +118,12 @@ export class HandshakeRpcLocal implements IHandshakeRpc {
|
|
|
118
118
|
this.config.ongoingInterleaves.delete(nodeId)
|
|
119
119
|
})
|
|
120
120
|
}
|
|
121
|
-
this.config.
|
|
121
|
+
this.config.neighbors.add(this.config.createDeliveryRpcRemote(requester))
|
|
122
122
|
this.config.connectionLocker.lockConnection(requester, this.config.streamPartId)
|
|
123
123
|
return {
|
|
124
124
|
requestId: request.requestId,
|
|
125
125
|
accepted: true,
|
|
126
|
-
interleaveTargetDescriptor:
|
|
126
|
+
interleaveTargetDescriptor: lastPeerDescriptor
|
|
127
127
|
}
|
|
128
128
|
}
|
|
129
129
|
|
|
@@ -132,9 +132,9 @@ export class HandshakeRpcLocal implements IHandshakeRpc {
|
|
|
132
132
|
const senderId = getNodeIdFromPeerDescriptor(senderPeerDescriptor)
|
|
133
133
|
try {
|
|
134
134
|
await this.config.handshakeWithInterleaving(message.interleaveTargetDescriptor!, senderId)
|
|
135
|
-
if (this.config.
|
|
135
|
+
if (this.config.neighbors.has(senderId)) {
|
|
136
136
|
this.config.connectionLocker.unlockConnection(senderPeerDescriptor, this.config.streamPartId)
|
|
137
|
-
this.config.
|
|
137
|
+
this.config.neighbors.remove(senderId)
|
|
138
138
|
}
|
|
139
139
|
return { accepted: true }
|
|
140
140
|
} catch (err) {
|