@streamr/trackerless-network 100.0.0-testnet-three.6 → 100.1.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/package.json +7 -7
- package/dist/src/NetworkNode.js +11 -11
- package/dist/src/NetworkNode.js.map +1 -1
- package/dist/src/NetworkStack.d.ts +6 -6
- package/dist/src/NetworkStack.js +22 -20
- package/dist/src/NetworkStack.js.map +1 -1
- package/dist/src/exports.d.ts +3 -3
- package/dist/src/exports.js +7 -1
- package/dist/src/exports.js.map +1 -1
- package/dist/src/logic/{StreamrNode.d.ts → ContentDeliveryManager.d.ts} +6 -6
- package/dist/src/logic/{StreamrNode.js → ContentDeliveryManager.js} +16 -13
- package/dist/src/logic/ContentDeliveryManager.js.map +1 -0
- package/dist/src/logic/{DeliveryRpcLocal.d.ts → ContentDeliveryRpcLocal.d.ts} +4 -4
- package/dist/src/logic/{DeliveryRpcLocal.js → ContentDeliveryRpcLocal.js} +4 -4
- package/dist/src/logic/ContentDeliveryRpcLocal.js.map +1 -0
- package/dist/src/logic/{DeliveryRpcRemote.d.ts → ContentDeliveryRpcRemote.d.ts} +2 -2
- package/dist/src/logic/{DeliveryRpcRemote.js → ContentDeliveryRpcRemote.js} +4 -4
- package/dist/src/logic/ContentDeliveryRpcRemote.js.map +1 -0
- package/dist/src/logic/EntryPointDiscovery.d.ts +1 -1
- package/dist/src/logic/EntryPointDiscovery.js +3 -3
- 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 +7 -1
- package/dist/src/logic/NodeList.d.ts +11 -10
- package/dist/src/logic/NodeList.js +7 -2
- package/dist/src/logic/NodeList.js.map +1 -1
- package/dist/src/logic/RandomGraphNode.d.ts +4 -1
- package/dist/src/logic/RandomGraphNode.js +36 -14
- package/dist/src/logic/RandomGraphNode.js.map +1 -1
- package/dist/src/logic/createRandomGraphNode.d.ts +1 -1
- package/dist/src/logic/createRandomGraphNode.js +16 -7
- package/dist/src/logic/createRandomGraphNode.js.map +1 -1
- package/dist/src/logic/formStreamPartDeliveryServiceId.d.ts +1 -1
- package/dist/src/logic/formStreamPartDeliveryServiceId.js +4 -3
- package/dist/src/logic/formStreamPartDeliveryServiceId.js.map +1 -1
- 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/HandshakeRpcLocal.d.ts +3 -4
- package/dist/src/logic/neighbor-discovery/HandshakeRpcLocal.js +6 -11
- package/dist/src/logic/neighbor-discovery/HandshakeRpcLocal.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/HandshakeRpcRemote.js +2 -2
- package/dist/src/logic/neighbor-discovery/HandshakeRpcRemote.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/Handshaker.d.ts +4 -3
- package/dist/src/logic/neighbor-discovery/Handshaker.js +35 -16
- package/dist/src/logic/neighbor-discovery/Handshaker.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/NeighborFinder.d.ts +3 -0
- package/dist/src/logic/neighbor-discovery/NeighborFinder.js +7 -1
- package/dist/src/logic/neighbor-discovery/NeighborFinder.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/NeighborUpdateManager.d.ts +1 -2
- package/dist/src/logic/neighbor-discovery/NeighborUpdateManager.js +0 -1
- package/dist/src/logic/neighbor-discovery/NeighborUpdateManager.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/NeighborUpdateRpcLocal.d.ts +1 -2
- package/dist/src/logic/neighbor-discovery/NeighborUpdateRpcLocal.js +2 -3
- package/dist/src/logic/neighbor-discovery/NeighborUpdateRpcLocal.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/NeighborUpdateRpcRemote.js +1 -1
- package/dist/src/logic/neighbor-discovery/NeighborUpdateRpcRemote.js.map +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 +64 -52
- package/dist/src/logic/protocol-integration/stream-message/StreamMessageTranslator.js.map +1 -1
- package/dist/src/logic/protocol-integration/stream-message/oldStreamMessageBinaryUtils.d.ts +5 -1
- package/dist/src/logic/protocol-integration/stream-message/oldStreamMessageBinaryUtils.js +19 -1
- package/dist/src/logic/protocol-integration/stream-message/oldStreamMessageBinaryUtils.js.map +1 -1
- package/dist/src/logic/proxy/ProxyClient.d.ts +1 -1
- package/dist/src/logic/proxy/ProxyClient.js +8 -8
- package/dist/src/logic/proxy/ProxyClient.js.map +1 -1
- package/dist/src/logic/proxy/ProxyConnectionRpcLocal.d.ts +2 -2
- package/dist/src/logic/proxy/ProxyConnectionRpcLocal.js +5 -5
- 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 +5 -1
- package/dist/src/logic/temporary-connection/TemporaryConnectionRpcLocal.js +7 -2
- package/dist/src/logic/temporary-connection/TemporaryConnectionRpcLocal.js.map +1 -1
- package/dist/src/logic/temporary-connection/TemporaryConnectionRpcRemote.js +2 -2
- package/dist/src/logic/temporary-connection/TemporaryConnectionRpcRemote.js.map +1 -1
- package/dist/src/proto/google/protobuf/any.d.ts +11 -4
- package/dist/src/proto/google/protobuf/any.js.map +1 -1
- package/dist/src/proto/google/protobuf/empty.d.ts +0 -1
- package/dist/src/proto/google/protobuf/empty.js.map +1 -1
- package/dist/src/proto/google/protobuf/timestamp.d.ts +9 -3
- package/dist/src/proto/google/protobuf/timestamp.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.d.ts +16 -6
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js +11 -4
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.d.ts +98 -87
- package/dist/src/proto/packages/dht/protos/DhtRpc.js +45 -49
- package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.server.d.ts +10 -4
- package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.client.d.ts +4 -4
- package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.client.js +7 -7
- 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 +62 -26
- package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.js +31 -14
- 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 +2 -2
- package/dist/test/benchmark/first-message.js +5 -5
- package/dist/test/benchmark/first-message.js.map +1 -1
- package/dist/test/utils/utils.d.ts +2 -2
- package/dist/test/utils/utils.js +18 -11
- package/dist/test/utils/utils.js.map +1 -1
- package/karma.config.js +2 -0
- package/package.json +7 -7
- package/protos/NetworkRpc.proto +19 -11
- package/src/NetworkNode.ts +11 -11
- package/src/NetworkStack.ts +30 -25
- package/src/exports.ts +7 -3
- package/src/logic/{StreamrNode.ts → ContentDeliveryManager.ts} +21 -17
- package/src/logic/{DeliveryRpcLocal.ts → ContentDeliveryRpcLocal.ts} +5 -5
- package/src/logic/{DeliveryRpcRemote.ts → ContentDeliveryRpcRemote.ts} +2 -2
- package/src/logic/EntryPointDiscovery.ts +4 -4
- package/src/logic/Layer0Node.ts +1 -1
- package/src/logic/Layer1Node.ts +16 -1
- package/src/logic/NodeList.ts +20 -14
- package/src/logic/RandomGraphNode.ts +89 -27
- package/src/logic/createRandomGraphNode.ts +18 -9
- package/src/logic/formStreamPartDeliveryServiceId.ts +2 -1
- package/src/logic/inspect/Inspector.ts +2 -2
- package/src/logic/neighbor-discovery/HandshakeRpcLocal.ts +10 -15
- package/src/logic/neighbor-discovery/HandshakeRpcRemote.ts +2 -2
- package/src/logic/neighbor-discovery/Handshaker.ts +41 -22
- package/src/logic/neighbor-discovery/NeighborFinder.ts +10 -1
- package/src/logic/neighbor-discovery/NeighborUpdateManager.ts +1 -3
- package/src/logic/neighbor-discovery/NeighborUpdateRpcLocal.ts +5 -7
- package/src/logic/neighbor-discovery/NeighborUpdateRpcRemote.ts +1 -1
- package/src/logic/protocol-integration/stream-message/GroupKeyResponseTranslator.ts +0 -1
- package/src/logic/protocol-integration/stream-message/StreamMessageTranslator.ts +74 -71
- package/src/logic/protocol-integration/stream-message/oldStreamMessageBinaryUtils.ts +28 -2
- package/src/logic/proxy/ProxyClient.ts +11 -11
- package/src/logic/proxy/ProxyConnectionRpcLocal.ts +9 -11
- package/src/logic/proxy/ProxyConnectionRpcRemote.ts +1 -1
- package/src/logic/temporary-connection/TemporaryConnectionRpcLocal.ts +14 -6
- package/src/logic/temporary-connection/TemporaryConnectionRpcRemote.ts +2 -2
- package/src/proto/google/protobuf/any.ts +11 -4
- package/src/proto/google/protobuf/empty.ts +0 -1
- package/src/proto/google/protobuf/timestamp.ts +9 -3
- package/src/proto/packages/dht/protos/DhtRpc.client.ts +22 -9
- package/src/proto/packages/dht/protos/DhtRpc.server.ts +10 -4
- package/src/proto/packages/dht/protos/DhtRpc.ts +122 -100
- package/src/proto/packages/trackerless-network/protos/NetworkRpc.client.ts +8 -8
- package/src/proto/packages/trackerless-network/protos/NetworkRpc.server.ts +2 -2
- package/src/proto/packages/trackerless-network/protos/NetworkRpc.ts +79 -37
- package/test/benchmark/StreamPartIdDataKeyDistribution.test.ts +60 -0
- package/test/benchmark/first-message.ts +5 -5
- package/test/end-to-end/inspect.test.ts +6 -6
- package/test/end-to-end/proxy-and-full-node.test.ts +19 -19
- package/test/end-to-end/proxy-connections.test.ts +7 -7
- package/test/end-to-end/proxy-key-exchange.test.ts +16 -13
- package/test/end-to-end/webrtc-full-node-network.test.ts +8 -8
- package/test/end-to-end/websocket-full-node-network.test.ts +9 -9
- package/test/integration/ContentDeliveryManager.test.ts +135 -0
- package/test/integration/{DeliveryRpcRemote.test.ts → ContentDeliveryRpcRemote.test.ts} +6 -6
- package/test/integration/Handshakes.test.ts +7 -3
- package/test/integration/Inspect.test.ts +2 -2
- package/test/integration/NetworkRpc.test.ts +3 -3
- package/test/integration/NetworkStack.test.ts +7 -7
- package/test/integration/NodeInfoRpc.test.ts +10 -10
- package/test/integration/joining-streams-on-offline-peers.test.ts +3 -3
- package/test/integration/stream-without-default-entrypoints.test.ts +1 -1
- package/test/integration/streamEntryPointReplacing.test.ts +10 -8
- package/test/unit/ContentDeliveryManager.test.ts +96 -0
- package/test/unit/{DeliveryRpcLocal.test.ts → ContentDeliveryRpcLocal.test.ts} +4 -4
- package/test/unit/EntrypointDiscovery.test.ts +4 -4
- package/test/unit/HandshakeRpcLocal.test.ts +31 -15
- package/test/unit/Handshaker.test.ts +8 -3
- package/test/unit/NeighborFinder.test.ts +5 -2
- package/test/unit/NeighborUpdateRpcLocal.test.ts +8 -12
- package/test/unit/NetworkNode.test.ts +6 -6
- package/test/unit/NodeList.test.ts +6 -6
- package/test/unit/Propagation.test.ts +10 -7
- package/test/unit/RandomGraphNode.test.ts +3 -3
- package/test/unit/StreamMessageTranslator.test.ts +3 -4
- package/test/unit/StreamPartIDDataKey.test.ts +12 -0
- package/test/unit/TemporaryConnectionRpcLocal.test.ts +7 -1
- package/test/utils/mock/MockLayer0Node.ts +1 -1
- package/test/utils/mock/MockLayer1Node.ts +3 -0
- package/test/utils/utils.ts +19 -13
- package/dist/src/logic/DeliveryRpcLocal.js.map +0 -1
- package/dist/src/logic/DeliveryRpcRemote.js.map +0 -1
- package/dist/src/logic/StreamrNode.js.map +0 -1
- package/test/integration/StreamrNode.test.ts +0 -131
- package/test/unit/GroupKeyRequestTranslator.test.ts +0 -36
- package/test/unit/StreamrNode.test.ts +0 -98
|
@@ -10,10 +10,10 @@ import { MarkOptional } from 'ts-essentials'
|
|
|
10
10
|
import { ProxyConnectionRpcLocal } from './proxy/ProxyConnectionRpcLocal'
|
|
11
11
|
import { Inspector } from './inspect/Inspector'
|
|
12
12
|
import { TemporaryConnectionRpcLocal } from './temporary-connection/TemporaryConnectionRpcLocal'
|
|
13
|
-
import {
|
|
13
|
+
import { formStreamPartContentDeliveryServiceId } from './formStreamPartDeliveryServiceId'
|
|
14
14
|
|
|
15
15
|
type RandomGraphNodeConfig = MarkOptional<StrictRandomGraphNodeConfig,
|
|
16
|
-
'nearbyNodeView' | 'randomNodeView' | 'neighbors' | 'propagation'
|
|
16
|
+
'nearbyNodeView' | 'randomNodeView' | 'neighbors' | 'leftNodeView' | 'rightNodeView' | 'propagation'
|
|
17
17
|
| 'handshaker' | 'neighborFinder' | 'neighborUpdateManager' | 'neighborTargetCount'
|
|
18
18
|
| 'rpcCommunicator' | 'nodeViewSize'
|
|
19
19
|
| 'inspector' | 'temporaryConnectionRpcLocal'> & {
|
|
@@ -26,7 +26,7 @@ type RandomGraphNodeConfig = MarkOptional<StrictRandomGraphNodeConfig,
|
|
|
26
26
|
const createConfigWithDefaults = (config: RandomGraphNodeConfig): StrictRandomGraphNodeConfig => {
|
|
27
27
|
const ownNodeId = getNodeIdFromPeerDescriptor(config.localPeerDescriptor)
|
|
28
28
|
const rpcCommunicator = config.rpcCommunicator ?? new ListeningRpcCommunicator(
|
|
29
|
-
|
|
29
|
+
formStreamPartContentDeliveryServiceId(config.streamPartId),
|
|
30
30
|
config.transport
|
|
31
31
|
)
|
|
32
32
|
const neighborTargetCount = config.neighborTargetCount ?? 4
|
|
@@ -34,14 +34,18 @@ const createConfigWithDefaults = (config: RandomGraphNodeConfig): StrictRandomGr
|
|
|
34
34
|
const minPropagationTargets = config.minPropagationTargets ?? 2
|
|
35
35
|
const acceptProxyConnections = config.acceptProxyConnections ?? false
|
|
36
36
|
const neighborUpdateInterval = config.neighborUpdateInterval ?? 10000
|
|
37
|
+
const neighbors = config.neighbors ?? new NodeList(ownNodeId, maxContactCount)
|
|
38
|
+
const leftNodeView = config.leftNodeView ?? new NodeList(ownNodeId, maxContactCount)
|
|
39
|
+
const rightNodeView = config.rightNodeView ?? new NodeList(ownNodeId, maxContactCount)
|
|
37
40
|
const nearbyNodeView = config.nearbyNodeView ?? new NodeList(ownNodeId, maxContactCount)
|
|
38
41
|
const randomNodeView = config.randomNodeView ?? new NodeList(ownNodeId, maxContactCount)
|
|
39
|
-
const neighbors = config.neighbors ?? new NodeList(ownNodeId, maxContactCount)
|
|
40
42
|
const ongoingHandshakes = new Set<DhtAddress>()
|
|
41
43
|
|
|
42
44
|
const temporaryConnectionRpcLocal = new TemporaryConnectionRpcLocal({
|
|
43
45
|
rpcCommunicator,
|
|
44
|
-
localPeerDescriptor: config.localPeerDescriptor
|
|
46
|
+
localPeerDescriptor: config.localPeerDescriptor,
|
|
47
|
+
streamPartId: config.streamPartId,
|
|
48
|
+
connectionLocker: config.connectionLocker
|
|
45
49
|
})
|
|
46
50
|
const proxyConnectionRpcLocal = acceptProxyConnections ? new ProxyConnectionRpcLocal({
|
|
47
51
|
localPeerDescriptor: config.localPeerDescriptor,
|
|
@@ -65,18 +69,22 @@ const createConfigWithDefaults = (config: RandomGraphNodeConfig): StrictRandomGr
|
|
|
65
69
|
const handshaker = config.handshaker ?? new Handshaker({
|
|
66
70
|
localPeerDescriptor: config.localPeerDescriptor,
|
|
67
71
|
streamPartId: config.streamPartId,
|
|
68
|
-
connectionLocker: config.connectionLocker,
|
|
69
72
|
rpcCommunicator,
|
|
73
|
+
neighbors,
|
|
74
|
+
leftNodeView,
|
|
75
|
+
rightNodeView,
|
|
70
76
|
nearbyNodeView,
|
|
71
77
|
randomNodeView,
|
|
72
|
-
neighbors,
|
|
73
78
|
maxNeighborCount: neighborTargetCount,
|
|
74
79
|
rpcRequestTimeout: config.rpcRequestTimeout,
|
|
75
80
|
ongoingHandshakes
|
|
76
81
|
})
|
|
77
82
|
const neighborFinder = config.neighborFinder ?? new NeighborFinder({
|
|
78
83
|
neighbors,
|
|
84
|
+
leftNodeView,
|
|
85
|
+
rightNodeView,
|
|
79
86
|
nearbyNodeView,
|
|
87
|
+
randomNodeView,
|
|
80
88
|
doFindNeighbors: (excludedIds) => handshaker.attemptHandshakesOnContacts(excludedIds),
|
|
81
89
|
minCount: neighborTargetCount
|
|
82
90
|
})
|
|
@@ -89,7 +97,6 @@ const createConfigWithDefaults = (config: RandomGraphNodeConfig): StrictRandomGr
|
|
|
89
97
|
rpcCommunicator,
|
|
90
98
|
neighborUpdateInterval,
|
|
91
99
|
neighborTargetCount,
|
|
92
|
-
connectionLocker: config.connectionLocker,
|
|
93
100
|
ongoingHandshakes
|
|
94
101
|
})
|
|
95
102
|
const inspector = config.inspector ?? new Inspector({
|
|
@@ -100,9 +107,11 @@ const createConfigWithDefaults = (config: RandomGraphNodeConfig): StrictRandomGr
|
|
|
100
107
|
})
|
|
101
108
|
return {
|
|
102
109
|
...config,
|
|
110
|
+
neighbors,
|
|
111
|
+
leftNodeView,
|
|
112
|
+
rightNodeView,
|
|
103
113
|
nearbyNodeView,
|
|
104
114
|
randomNodeView,
|
|
105
|
-
neighbors,
|
|
106
115
|
rpcCommunicator,
|
|
107
116
|
handshaker,
|
|
108
117
|
neighborFinder,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ServiceID } from '@streamr/dht'
|
|
2
2
|
import { StreamPartID } from '@streamr/protocol'
|
|
3
3
|
|
|
4
|
-
export const
|
|
4
|
+
export const formStreamPartContentDeliveryServiceId = (streamPartId: StreamPartID): ServiceID => {
|
|
5
|
+
// could be "content-delivery" instead of "delivery", but that is a breaking change
|
|
5
6
|
return `stream-part-delivery-${streamPartId}`
|
|
6
7
|
}
|
|
@@ -48,7 +48,7 @@ export class Inspector {
|
|
|
48
48
|
TemporaryConnectionRpcClient
|
|
49
49
|
)
|
|
50
50
|
await rpcRemote.openConnection()
|
|
51
|
-
this.connectionLocker.
|
|
51
|
+
this.connectionLocker.weakLockConnection(getNodeIdFromPeerDescriptor(peerDescriptor), lockId)
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
async defaultCloseInspectConnection(peerDescriptor: PeerDescriptor, lockId: LockID): Promise<void> {
|
|
@@ -59,7 +59,7 @@ export class Inspector {
|
|
|
59
59
|
TemporaryConnectionRpcClient
|
|
60
60
|
)
|
|
61
61
|
await rpcRemote.closeConnection()
|
|
62
|
-
this.connectionLocker.
|
|
62
|
+
this.connectionLocker.weakUnlockConnection(getNodeIdFromPeerDescriptor(peerDescriptor), lockId)
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
async inspect(peerDescriptor: PeerDescriptor): Promise<boolean> {
|
|
@@ -7,7 +7,6 @@ import {
|
|
|
7
7
|
import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
|
|
8
8
|
import { NodeList } from '../NodeList'
|
|
9
9
|
import {
|
|
10
|
-
ConnectionLocker,
|
|
11
10
|
DhtAddress,
|
|
12
11
|
DhtAddressRaw,
|
|
13
12
|
DhtCallContext,
|
|
@@ -17,19 +16,18 @@ import {
|
|
|
17
16
|
} from '@streamr/dht'
|
|
18
17
|
import { IHandshakeRpc } from '../../proto/packages/trackerless-network/protos/NetworkRpc.server'
|
|
19
18
|
import { HandshakeRpcRemote } from './HandshakeRpcRemote'
|
|
20
|
-
import {
|
|
19
|
+
import { ContentDeliveryRpcRemote } from '../ContentDeliveryRpcRemote'
|
|
21
20
|
import { Logger } from '@streamr/utils'
|
|
22
21
|
import { StreamPartID } from '@streamr/protocol'
|
|
23
22
|
|
|
24
23
|
interface HandshakeRpcLocalConfig {
|
|
25
24
|
streamPartId: StreamPartID
|
|
26
25
|
neighbors: NodeList
|
|
27
|
-
connectionLocker: ConnectionLocker
|
|
28
26
|
ongoingHandshakes: Set<DhtAddress>
|
|
29
27
|
ongoingInterleaves: Set<DhtAddress>
|
|
30
28
|
maxNeighborCount: number
|
|
31
29
|
createRpcRemote: (target: PeerDescriptor) => HandshakeRpcRemote
|
|
32
|
-
|
|
30
|
+
createContentDeliveryRpcRemote: (peerDescriptor: PeerDescriptor) => ContentDeliveryRpcRemote
|
|
33
31
|
handshakeWithInterleaving: (target: PeerDescriptor, senderId: DhtAddress) => Promise<boolean>
|
|
34
32
|
}
|
|
35
33
|
|
|
@@ -59,7 +57,10 @@ export class HandshakeRpcLocal implements IHandshakeRpc {
|
|
|
59
57
|
return this.acceptHandshake(request, senderDescriptor)
|
|
60
58
|
} else if (this.config.neighbors.size() + this.config.ongoingHandshakes.size < this.config.maxNeighborCount) {
|
|
61
59
|
return this.acceptHandshake(request, senderDescriptor)
|
|
62
|
-
} else if (
|
|
60
|
+
} else if (
|
|
61
|
+
this.config.neighbors.size(getInterleaveSourceIds()) - this.config.ongoingInterleaves.size >= 2
|
|
62
|
+
&& this.config.neighbors.size() <= this.config.maxNeighborCount
|
|
63
|
+
) {
|
|
63
64
|
// Do not accept the handshakes requests if the target neighbor count can potentially drop below 2
|
|
64
65
|
// due to interleaving. This ensures that a stable number of connections is kept during high churn.
|
|
65
66
|
return this.acceptHandshakeWithInterleaving(request, senderDescriptor)
|
|
@@ -73,8 +74,7 @@ export class HandshakeRpcLocal implements IHandshakeRpc {
|
|
|
73
74
|
requestId: request.requestId,
|
|
74
75
|
accepted: true
|
|
75
76
|
}
|
|
76
|
-
this.config.neighbors.add(this.config.
|
|
77
|
-
this.config.connectionLocker.lockConnection(requester, this.config.streamPartId)
|
|
77
|
+
this.config.neighbors.add(this.config.createContentDeliveryRpcRemote(requester))
|
|
78
78
|
return res
|
|
79
79
|
}
|
|
80
80
|
|
|
@@ -109,7 +109,6 @@ export class HandshakeRpcLocal implements IHandshakeRpc {
|
|
|
109
109
|
// If response is not accepted, keep the last node as a neighbor
|
|
110
110
|
if (response.accepted) {
|
|
111
111
|
this.config.neighbors.remove(getNodeIdFromPeerDescriptor(lastPeerDescriptor!))
|
|
112
|
-
this.config.connectionLocker.unlockConnection(lastPeerDescriptor!, this.config.streamPartId)
|
|
113
112
|
}
|
|
114
113
|
return
|
|
115
114
|
}).catch(() => {
|
|
@@ -118,8 +117,7 @@ export class HandshakeRpcLocal implements IHandshakeRpc {
|
|
|
118
117
|
this.config.ongoingInterleaves.delete(nodeId)
|
|
119
118
|
})
|
|
120
119
|
}
|
|
121
|
-
this.config.neighbors.add(this.config.
|
|
122
|
-
this.config.connectionLocker.lockConnection(requester, this.config.streamPartId)
|
|
120
|
+
this.config.neighbors.add(this.config.createContentDeliveryRpcRemote(requester))
|
|
123
121
|
return {
|
|
124
122
|
requestId: request.requestId,
|
|
125
123
|
accepted: true,
|
|
@@ -132,13 +130,10 @@ export class HandshakeRpcLocal implements IHandshakeRpc {
|
|
|
132
130
|
const senderId = getNodeIdFromPeerDescriptor(senderPeerDescriptor)
|
|
133
131
|
try {
|
|
134
132
|
await this.config.handshakeWithInterleaving(message.interleaveTargetDescriptor!, senderId)
|
|
135
|
-
|
|
136
|
-
this.config.connectionLocker.unlockConnection(senderPeerDescriptor, this.config.streamPartId)
|
|
137
|
-
this.config.neighbors.remove(senderId)
|
|
138
|
-
}
|
|
133
|
+
this.config.neighbors.remove(senderId)
|
|
139
134
|
return { accepted: true }
|
|
140
135
|
} catch (err) {
|
|
141
|
-
logger.debug(`interleaveRequest to ${getNodeIdFromPeerDescriptor(message.interleaveTargetDescriptor!)} failed
|
|
136
|
+
logger.debug(`interleaveRequest to ${getNodeIdFromPeerDescriptor(message.interleaveTargetDescriptor!)} failed`, { err })
|
|
142
137
|
return { accepted: false }
|
|
143
138
|
}
|
|
144
139
|
}
|
|
@@ -36,7 +36,7 @@ export class HandshakeRpcRemote extends RpcRemote<HandshakeRpcClient> {
|
|
|
36
36
|
interleaveTargetDescriptor: response.interleaveTargetDescriptor
|
|
37
37
|
}
|
|
38
38
|
} catch (err: any) {
|
|
39
|
-
logger.debug(`handshake to ${getNodeIdFromPeerDescriptor(this.getPeerDescriptor())} failed
|
|
39
|
+
logger.debug(`handshake to ${getNodeIdFromPeerDescriptor(this.getPeerDescriptor())} failed`, { err })
|
|
40
40
|
return {
|
|
41
41
|
accepted: false
|
|
42
42
|
}
|
|
@@ -57,7 +57,7 @@ export class HandshakeRpcRemote extends RpcRemote<HandshakeRpcClient> {
|
|
|
57
57
|
accepted: res.accepted
|
|
58
58
|
}
|
|
59
59
|
} catch (err) {
|
|
60
|
-
logger.debug(`interleaveRequest to ${getNodeIdFromPeerDescriptor(this.getPeerDescriptor())} failed
|
|
60
|
+
logger.debug(`interleaveRequest to ${getNodeIdFromPeerDescriptor(this.getPeerDescriptor())} failed`, { err })
|
|
61
61
|
return {
|
|
62
62
|
accepted: false
|
|
63
63
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DhtAddress, PeerDescriptor, ListeningRpcCommunicator, getNodeIdFromPeerDescriptor } from '@streamr/dht'
|
|
2
2
|
import { NodeList } from '../NodeList'
|
|
3
|
-
import {
|
|
3
|
+
import { ContentDeliveryRpcRemote } from '../ContentDeliveryRpcRemote'
|
|
4
4
|
import {
|
|
5
|
-
|
|
5
|
+
ContentDeliveryRpcClient, HandshakeRpcClient
|
|
6
6
|
} from '../../proto/packages/trackerless-network/protos/NetworkRpc.client'
|
|
7
7
|
import {
|
|
8
8
|
InterleaveRequest,
|
|
@@ -11,7 +11,6 @@ import {
|
|
|
11
11
|
StreamPartHandshakeResponse
|
|
12
12
|
} from '../../proto/packages/trackerless-network/protos/NetworkRpc'
|
|
13
13
|
import { Logger } from '@streamr/utils'
|
|
14
|
-
import { IHandshakeRpc } from '../../proto/packages/trackerless-network/protos/NetworkRpc.server'
|
|
15
14
|
import { HandshakeRpcRemote, INTERLEAVE_REQUEST_TIMEOUT } from './HandshakeRpcRemote'
|
|
16
15
|
import { HandshakeRpcLocal } from './HandshakeRpcLocal'
|
|
17
16
|
import { StreamPartID } from '@streamr/protocol'
|
|
@@ -19,8 +18,9 @@ import { StreamPartID } from '@streamr/protocol'
|
|
|
19
18
|
interface HandshakerConfig {
|
|
20
19
|
localPeerDescriptor: PeerDescriptor
|
|
21
20
|
streamPartId: StreamPartID
|
|
22
|
-
connectionLocker: ConnectionLocker
|
|
23
21
|
neighbors: NodeList
|
|
22
|
+
leftNodeView: NodeList
|
|
23
|
+
rightNodeView: NodeList
|
|
24
24
|
nearbyNodeView: NodeList
|
|
25
25
|
randomNodeView: NodeList
|
|
26
26
|
rpcCommunicator: ListeningRpcCommunicator
|
|
@@ -36,20 +36,19 @@ const PARALLEL_HANDSHAKE_COUNT = 2
|
|
|
36
36
|
export class Handshaker {
|
|
37
37
|
|
|
38
38
|
private config: HandshakerConfig
|
|
39
|
-
private readonly rpcLocal:
|
|
39
|
+
private readonly rpcLocal: HandshakeRpcLocal
|
|
40
40
|
|
|
41
41
|
constructor(config: HandshakerConfig) {
|
|
42
42
|
this.config = config
|
|
43
43
|
this.rpcLocal = new HandshakeRpcLocal({
|
|
44
44
|
streamPartId: this.config.streamPartId,
|
|
45
45
|
neighbors: this.config.neighbors,
|
|
46
|
-
connectionLocker: this.config.connectionLocker,
|
|
47
46
|
ongoingHandshakes: this.config.ongoingHandshakes,
|
|
48
47
|
ongoingInterleaves: new Set(),
|
|
49
48
|
maxNeighborCount: this.config.maxNeighborCount,
|
|
50
49
|
handshakeWithInterleaving: (target: PeerDescriptor, senderId: DhtAddress) => this.handshakeWithInterleaving(target, senderId),
|
|
51
50
|
createRpcRemote: (target: PeerDescriptor) => this.createRpcRemote(target),
|
|
52
|
-
|
|
51
|
+
createContentDeliveryRpcRemote: (target: PeerDescriptor) => this.createContentDeliveryRpcRemote(target)
|
|
53
52
|
})
|
|
54
53
|
this.config.rpcCommunicator.registerRpcMethod(InterleaveRequest, InterleaveResponse, 'interleaveRequest',
|
|
55
54
|
(req: InterleaveRequest, context) => this.rpcLocal.interleaveRequest(req, context), { timeout: INTERLEAVE_REQUEST_TIMEOUT })
|
|
@@ -77,19 +76,38 @@ export class Handshaker {
|
|
|
77
76
|
}
|
|
78
77
|
|
|
79
78
|
private selectParallelTargets(excludedIds: DhtAddress[]): HandshakeRpcRemote[] {
|
|
80
|
-
const neighbors =
|
|
79
|
+
const neighbors: Map<DhtAddress, ContentDeliveryRpcRemote> = new Map()
|
|
80
|
+
// First add the closest left and then right contacts from the ring if possible.
|
|
81
|
+
const left = this.config.leftNodeView.getFirst([...excludedIds, ...Array.from(neighbors.keys())] as DhtAddress[])
|
|
82
|
+
const right = this.config.rightNodeView.getFirst([...excludedIds, ...Array.from(neighbors.keys())] as DhtAddress[])
|
|
83
|
+
if (left) {
|
|
84
|
+
neighbors.set(getNodeIdFromPeerDescriptor(left.getPeerDescriptor()), left)
|
|
85
|
+
}
|
|
86
|
+
if (right) {
|
|
87
|
+
neighbors.set(getNodeIdFromPeerDescriptor(right.getPeerDescriptor()), right)
|
|
88
|
+
}
|
|
89
|
+
// If there is still room add the closest contact based on the kademlia metric
|
|
90
|
+
if (neighbors.size < PARALLEL_HANDSHAKE_COUNT) {
|
|
91
|
+
const first = this.config.nearbyNodeView.getFirst([...excludedIds, ...Array.from(neighbors.keys())] as DhtAddress[])
|
|
92
|
+
if (first) {
|
|
93
|
+
neighbors.set(getNodeIdFromPeerDescriptor(first.getPeerDescriptor()), first)
|
|
94
|
+
}
|
|
95
|
+
}
|
|
81
96
|
const getExcludedFromRandomView = () => [
|
|
82
97
|
...excludedIds,
|
|
83
|
-
...neighbors.map((neighbor) => getNodeIdFromPeerDescriptor(neighbor.getPeerDescriptor()))
|
|
98
|
+
...Array.from(neighbors.values()).map((neighbor) => getNodeIdFromPeerDescriptor(neighbor.getPeerDescriptor()))
|
|
84
99
|
]
|
|
100
|
+
// If there is still room add a random contact until PARALLEL_HANDSHAKE_COUNT is reached
|
|
85
101
|
while (
|
|
86
|
-
neighbors.
|
|
102
|
+
neighbors.size < PARALLEL_HANDSHAKE_COUNT
|
|
87
103
|
&& this.config.randomNodeView.size(getExcludedFromRandomView()) > 0
|
|
88
104
|
) {
|
|
89
|
-
const random = this.config.randomNodeView.getRandom(
|
|
90
|
-
|
|
105
|
+
const random = this.config.randomNodeView.getRandom([...excludedIds, ...Array.from(neighbors.keys())] as DhtAddress[])
|
|
106
|
+
if (random) {
|
|
107
|
+
neighbors.set(getNodeIdFromPeerDescriptor(random.getPeerDescriptor()), random)
|
|
108
|
+
}
|
|
91
109
|
}
|
|
92
|
-
return neighbors.map((neighbor) => this.createRpcRemote(neighbor.getPeerDescriptor()))
|
|
110
|
+
return Array.from(neighbors.values()).map((neighbor) => this.createRpcRemote(neighbor.getPeerDescriptor()))
|
|
93
111
|
}
|
|
94
112
|
|
|
95
113
|
private async doParallelHandshakes(targets: HandshakeRpcRemote[], excludedIds: DhtAddress[]): Promise<DhtAddress[]> {
|
|
@@ -111,7 +129,10 @@ export class Handshaker {
|
|
|
111
129
|
|
|
112
130
|
private async selectNewTargetAndHandshake(excludedIds: DhtAddress[]): Promise<DhtAddress[]> {
|
|
113
131
|
const exclude = excludedIds.concat(this.config.neighbors.getIds())
|
|
114
|
-
const neighbor = this.config.
|
|
132
|
+
const neighbor = this.config.leftNodeView.getFirst(exclude)
|
|
133
|
+
?? this.config.rightNodeView.getFirst(exclude)
|
|
134
|
+
?? this.config.nearbyNodeView.getFirst(exclude)
|
|
135
|
+
?? this.config.randomNodeView.getRandom(exclude)
|
|
115
136
|
if (neighbor) {
|
|
116
137
|
const accepted = await this.handshakeWithTarget(this.createRpcRemote(neighbor.getPeerDescriptor()))
|
|
117
138
|
if (!accepted) {
|
|
@@ -130,8 +151,7 @@ export class Handshaker {
|
|
|
130
151
|
concurrentNodeId
|
|
131
152
|
)
|
|
132
153
|
if (result.accepted) {
|
|
133
|
-
this.config.neighbors.add(this.
|
|
134
|
-
this.config.connectionLocker.lockConnection(neighbor.getPeerDescriptor(), this.config.streamPartId)
|
|
154
|
+
this.config.neighbors.add(this.createContentDeliveryRpcRemote(neighbor.getPeerDescriptor()))
|
|
135
155
|
}
|
|
136
156
|
if (result.interleaveTargetDescriptor) {
|
|
137
157
|
await this.handshakeWithInterleaving(result.interleaveTargetDescriptor, targetNodeId)
|
|
@@ -151,8 +171,7 @@ export class Handshaker {
|
|
|
151
171
|
interleaveSourceId
|
|
152
172
|
)
|
|
153
173
|
if (result.accepted) {
|
|
154
|
-
this.config.neighbors.add(this.
|
|
155
|
-
this.config.connectionLocker.lockConnection(neighbor.getPeerDescriptor(), this.config.streamPartId)
|
|
174
|
+
this.config.neighbors.add(this.createContentDeliveryRpcRemote(neighbor.getPeerDescriptor()))
|
|
156
175
|
}
|
|
157
176
|
this.config.ongoingHandshakes.delete(targetNodeId)
|
|
158
177
|
return result.accepted
|
|
@@ -168,12 +187,12 @@ export class Handshaker {
|
|
|
168
187
|
)
|
|
169
188
|
}
|
|
170
189
|
|
|
171
|
-
private
|
|
172
|
-
return new
|
|
190
|
+
private createContentDeliveryRpcRemote(targetPeerDescriptor: PeerDescriptor): ContentDeliveryRpcRemote {
|
|
191
|
+
return new ContentDeliveryRpcRemote(
|
|
173
192
|
this.config.localPeerDescriptor,
|
|
174
193
|
targetPeerDescriptor,
|
|
175
194
|
this.config.rpcCommunicator,
|
|
176
|
-
|
|
195
|
+
ContentDeliveryRpcClient,
|
|
177
196
|
this.config.rpcRequestTimeout
|
|
178
197
|
)
|
|
179
198
|
}
|
|
@@ -5,6 +5,9 @@ import { DhtAddress } from '@streamr/dht'
|
|
|
5
5
|
interface FindNeighborsSessionConfig {
|
|
6
6
|
neighbors: NodeList
|
|
7
7
|
nearbyNodeView: NodeList
|
|
8
|
+
leftNodeView: NodeList
|
|
9
|
+
rightNodeView: NodeList
|
|
10
|
+
randomNodeView: NodeList
|
|
8
11
|
doFindNeighbors: (excludedNodes: DhtAddress[]) => Promise<DhtAddress[]>
|
|
9
12
|
minCount: number
|
|
10
13
|
}
|
|
@@ -27,7 +30,13 @@ export class NeighborFinder {
|
|
|
27
30
|
return
|
|
28
31
|
}
|
|
29
32
|
const newExcludes = await this.config.doFindNeighbors(excluded)
|
|
30
|
-
|
|
33
|
+
const uniqueContactCount = new Set([
|
|
34
|
+
...this.config.nearbyNodeView.getIds(),
|
|
35
|
+
...this.config.leftNodeView.getIds(),
|
|
36
|
+
...this.config.rightNodeView.getIds(),
|
|
37
|
+
...this.config.randomNodeView.getIds()
|
|
38
|
+
]).size
|
|
39
|
+
if (this.config.neighbors.size() < this.config.minCount && newExcludes.length < uniqueContactCount) {
|
|
31
40
|
// TODO should we catch possible promise rejection?
|
|
32
41
|
setAbortableTimeout(() => this.findNeighbors(newExcludes), INTERVAL, this.abortController.signal)
|
|
33
42
|
} else {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { NeighborUpdate } from '../../proto/packages/trackerless-network/protos/NetworkRpc'
|
|
2
|
-
import {
|
|
2
|
+
import { 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,7 +13,6 @@ interface NeighborUpdateManagerConfig {
|
|
|
13
13
|
neighbors: NodeList
|
|
14
14
|
nearbyNodeView: NodeList
|
|
15
15
|
neighborFinder: NeighborFinder
|
|
16
|
-
connectionLocker: ConnectionLocker
|
|
17
16
|
streamPartId: StreamPartID
|
|
18
17
|
rpcCommunicator: ListeningRpcCommunicator
|
|
19
18
|
neighborUpdateInterval: number
|
|
@@ -53,7 +52,6 @@ export class NeighborUpdateManager {
|
|
|
53
52
|
if (res.removeMe) {
|
|
54
53
|
const nodeId = getNodeIdFromPeerDescriptor(neighbor.getPeerDescriptor())
|
|
55
54
|
this.config.neighbors.remove(nodeId)
|
|
56
|
-
this.config.connectionLocker.unlockConnection(neighbor.getPeerDescriptor(), this.config.streamPartId)
|
|
57
55
|
this.config.neighborFinder.start([nodeId])
|
|
58
56
|
}
|
|
59
57
|
}))
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
|
|
2
|
-
import {
|
|
2
|
+
import { DhtAddress, DhtCallContext, ListeningRpcCommunicator, PeerDescriptor, getNodeIdFromPeerDescriptor } from '@streamr/dht'
|
|
3
3
|
import { NeighborUpdate } from '../../proto/packages/trackerless-network/protos/NetworkRpc'
|
|
4
|
-
import {
|
|
4
|
+
import { ContentDeliveryRpcClient } from '../../proto/packages/trackerless-network/protos/NetworkRpc.client'
|
|
5
5
|
import { INeighborUpdateRpc } from '../../proto/packages/trackerless-network/protos/NetworkRpc.server'
|
|
6
6
|
import { NodeList } from '../NodeList'
|
|
7
|
-
import {
|
|
7
|
+
import { ContentDeliveryRpcRemote } from '../ContentDeliveryRpcRemote'
|
|
8
8
|
import { NeighborFinder } from './NeighborFinder'
|
|
9
9
|
import { StreamPartID } from '@streamr/protocol'
|
|
10
10
|
|
|
@@ -14,7 +14,6 @@ interface NeighborUpdateRpcLocalConfig {
|
|
|
14
14
|
neighbors: NodeList
|
|
15
15
|
nearbyNodeView: NodeList
|
|
16
16
|
neighborFinder: NeighborFinder
|
|
17
|
-
connectionLocker: ConnectionLocker
|
|
18
17
|
rpcCommunicator: ListeningRpcCommunicator
|
|
19
18
|
neighborTargetCount: number
|
|
20
19
|
ongoingHandshakes: Set<DhtAddress>
|
|
@@ -35,11 +34,11 @@ export class NeighborUpdateRpcLocal implements INeighborUpdateRpc {
|
|
|
35
34
|
return nodeId !== ownNodeId && !this.config.neighbors.getIds().includes(nodeId)
|
|
36
35
|
})
|
|
37
36
|
newPeerDescriptors.forEach((peerDescriptor) => this.config.nearbyNodeView.add(
|
|
38
|
-
new
|
|
37
|
+
new ContentDeliveryRpcRemote(
|
|
39
38
|
this.config.localPeerDescriptor,
|
|
40
39
|
peerDescriptor,
|
|
41
40
|
this.config.rpcCommunicator,
|
|
42
|
-
|
|
41
|
+
ContentDeliveryRpcClient
|
|
43
42
|
))
|
|
44
43
|
)
|
|
45
44
|
}
|
|
@@ -69,7 +68,6 @@ export class NeighborUpdateRpcLocal implements INeighborUpdateRpc {
|
|
|
69
68
|
this.config.neighborFinder.start()
|
|
70
69
|
} else {
|
|
71
70
|
this.config.neighbors.remove(senderId)
|
|
72
|
-
this.config.connectionLocker.unlockConnection(senderPeerDescriptor, this.config.streamPartId)
|
|
73
71
|
}
|
|
74
72
|
return this.createResponse(isOverNeighborCount)
|
|
75
73
|
}
|
|
@@ -26,7 +26,7 @@ export class NeighborUpdateRpcRemote extends RpcRemote<NeighborUpdateRpcClient>
|
|
|
26
26
|
removeMe: response.removeMe
|
|
27
27
|
}
|
|
28
28
|
} catch (err: any) {
|
|
29
|
-
logger.debug(`updateNeighbors to ${getNodeIdFromPeerDescriptor(this.getPeerDescriptor())} failed
|
|
29
|
+
logger.debug(`updateNeighbors to ${getNodeIdFromPeerDescriptor(this.getPeerDescriptor())} failed`, { err })
|
|
30
30
|
return {
|
|
31
31
|
peerDescriptors: [],
|
|
32
32
|
removeMe: true
|
|
@@ -6,7 +6,6 @@ import { toEthereumAddress, binaryToHex, hexToBinary } from '@streamr/utils'
|
|
|
6
6
|
export class GroupKeyResponseTranslator {
|
|
7
7
|
|
|
8
8
|
static toProtobuf(msg: OldGroupKeyResponse): GroupKeyResponse {
|
|
9
|
-
|
|
10
9
|
const groupKeys = msg.encryptedGroupKeys.map((groupKey) => {
|
|
11
10
|
return {
|
|
12
11
|
data: groupKey.data,
|