Skip to content

Commit f34c905

Browse files
committed
Default configs for layer2
1 parent f7e84d2 commit f34c905

File tree

6 files changed

+45
-26
lines changed

6 files changed

+45
-26
lines changed

packages/trackerless-network/src/logic/ContentDeliveryLayerNode.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ export interface StrictContentDeliveryLayerNodeOptions {
6565
rpcRequestTimeout?: number
6666
}
6767

68-
const RANDOM_NODE_VIEW_SIZE = 20
68+
export const DEFAULT_NODE_VIEW_SIZE = 20
69+
export const DEFAULT_NEIGHBOR_TARGET_COUNT = 4
70+
export const DEFAULT_ACCEPT_PROXY_CONNECTIONS = false
6971

7072
const logger = new Logger(module)
7173

@@ -284,7 +286,7 @@ export class ContentDeliveryLayerNode extends EventEmitter<Events> {
284286
if (this.isStopped()) {
285287
return
286288
}
287-
const randomContacts = this.options.discoveryLayerNode.getRandomContacts(RANDOM_NODE_VIEW_SIZE)
289+
const randomContacts = this.options.discoveryLayerNode.getRandomContacts(this.options.nodeViewSize)
288290
this.options.randomNodeView.replaceAll(randomContacts.map((descriptor) =>
289291
new ContentDeliveryRpcRemote(
290292
this.options.localPeerDescriptor,
@@ -304,7 +306,7 @@ export class ContentDeliveryLayerNode extends EventEmitter<Events> {
304306
if (this.isStopped()) {
305307
return
306308
}
307-
const randomContacts = this.options.discoveryLayerNode.getRandomContacts(RANDOM_NODE_VIEW_SIZE)
309+
const randomContacts = this.options.discoveryLayerNode.getRandomContacts(this.options.nodeViewSize)
308310
this.options.randomNodeView.replaceAll(randomContacts.map((descriptor) =>
309311
new ContentDeliveryRpcRemote(
310312
this.options.localPeerDescriptor,

packages/trackerless-network/src/logic/ContentDeliveryManager.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,9 @@ export class ContentDeliveryManager extends EventEmitter<Events> {
325325
localPeerDescriptor: this.controlLayerNode!.getLocalPeerDescriptor(),
326326
streamPartId,
327327
connectionLocker: this.connectionLocker!,
328-
minPropagationTargets: this.options.streamPartitionMinPropagationTargets,
329-
maxPropagationBufferSize: this.options.streamPartitionMaxPropagationBufferSize
328+
minPropagationTargets: this.options.streamPartitionMinPropagationTargets ?? DEFAULT_MIN_PROPAGATION_TARGETS,
329+
maxPropagationBufferSize: this.options.streamPartitionMaxPropagationBufferSize ?? DEFAULT_MAX_PROPAGATION_BUFFER_SIZE,
330+
propagationBufferTtl: DEFAULT_PROPAGATION_BUFFER_TTL
330331
})
331332
}
332333

packages/trackerless-network/src/logic/createContentDeliveryLayerNode.ts

+21-9
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
import { DhtAddress, ListeningRpcCommunicator, toNodeId } from '@streamr/dht'
22
import { Handshaker } from './neighbor-discovery/Handshaker'
33
import { NeighborFinder } from './neighbor-discovery/NeighborFinder'
4-
import { NeighborUpdateManager } from './neighbor-discovery/NeighborUpdateManager'
5-
import { StrictContentDeliveryLayerNodeOptions, ContentDeliveryLayerNode } from './ContentDeliveryLayerNode'
4+
import { DEFAULT_NEIGHBOR_UPDATE_INTERVAL, NeighborUpdateManager } from './neighbor-discovery/NeighborUpdateManager'
5+
import {
6+
StrictContentDeliveryLayerNodeOptions,
7+
ContentDeliveryLayerNode,
8+
DEFAULT_NODE_VIEW_SIZE,
9+
DEFAULT_ACCEPT_PROXY_CONNECTIONS,
10+
DEFAULT_NEIGHBOR_TARGET_COUNT
11+
} from './ContentDeliveryLayerNode'
612
import { NodeList } from './NodeList'
7-
import { Propagation } from './propagation/Propagation'
13+
import {
14+
DEFAULT_MIN_PROPAGATION_TARGETS,
15+
DEFAULT_MAX_PROPAGATION_BUFFER_SIZE,
16+
DEFAULT_PROPAGATION_BUFFER_TTL,
17+
Propagation
18+
} from './propagation/Propagation'
819
import { StreamMessage } from '../../generated/packages/trackerless-network/protos/NetworkRpc'
920
import type { MarkOptional } from 'ts-essentials'
1021
import { ProxyConnectionRpcLocal } from './proxy/ProxyConnectionRpcLocal'
@@ -30,12 +41,12 @@ const createConfigWithDefaults = (options: ContentDeliveryLayerNodeOptions): Str
3041
formStreamPartContentDeliveryServiceId(options.streamPartId),
3142
options.transport
3243
)
33-
const neighborTargetCount = options.neighborTargetCount ?? 4
34-
const maxContactCount = options.maxContactCount ?? 20
35-
const acceptProxyConnections = options.acceptProxyConnections ?? false
36-
const neighborUpdateInterval = options.neighborUpdateInterval ?? 10000
37-
const minPropagationTargets = options.minPropagationTargets
38-
const maxPropagationBufferSize = options.maxPropagationBufferSize
44+
const neighborTargetCount = options.neighborTargetCount ?? DEFAULT_NEIGHBOR_TARGET_COUNT
45+
const maxContactCount = options.maxContactCount ?? DEFAULT_NODE_VIEW_SIZE
46+
const acceptProxyConnections = options.acceptProxyConnections ?? DEFAULT_ACCEPT_PROXY_CONNECTIONS
47+
const neighborUpdateInterval = options.neighborUpdateInterval ?? DEFAULT_NEIGHBOR_UPDATE_INTERVAL
48+
const minPropagationTargets = options.minPropagationTargets ?? DEFAULT_MIN_PROPAGATION_TARGETS
49+
const maxPropagationBufferSize = options.maxPropagationBufferSize ?? DEFAULT_MAX_PROPAGATION_BUFFER_SIZE
3950
const neighbors = options.neighbors ?? new NodeList(ownNodeId, maxContactCount)
4051
const leftNodeView = options.leftNodeView ?? new NodeList(ownNodeId, maxContactCount)
4152
const rightNodeView = options.rightNodeView ?? new NodeList(ownNodeId, maxContactCount)
@@ -57,6 +68,7 @@ const createConfigWithDefaults = (options: ContentDeliveryLayerNodeOptions): Str
5768
const propagation = options.propagation ?? new Propagation({
5869
minPropagationTargets,
5970
maxMessages: maxPropagationBufferSize,
71+
ttl: DEFAULT_PROPAGATION_BUFFER_TTL,
6072
sendToNeighbor: async (neighborId: DhtAddress, msg: StreamMessage): Promise<void> => {
6173
const remote = neighbors.get(neighborId) ?? temporaryConnectionRpcLocal.getNodes().get(neighborId)
6274
const proxyConnection = proxyConnectionRpcLocal?.getConnection(neighborId)

packages/trackerless-network/src/logic/neighbor-discovery/NeighborUpdateManager.ts

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ interface NeighborUpdateManagerOptions {
2121

2222
const logger = new Logger(module)
2323

24+
export const DEFAULT_NEIGHBOR_UPDATE_INTERVAL = 10 * 1000
25+
2426
export class NeighborUpdateManager {
2527

2628
private readonly abortController: AbortController

packages/trackerless-network/src/logic/propagation/Propagation.ts

+10-9
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ type SendToNeighborFn = (neighborId: DhtAddress, msg: StreamMessage) => Promise<
66

77
interface ConstructorOptions {
88
sendToNeighbor: SendToNeighborFn
9-
minPropagationTargets?: number
10-
maxMessages?: number
11-
ttl?: number
9+
minPropagationTargets: number
10+
maxMessages: number
11+
ttl: number
1212
}
1313

14-
const DEFAULT_TTL = 10 * 1000
15-
const DEFAULT_MIN_PROPAGATION_TARGETS = 2
16-
const DEFAULT_MAX_MESSAGES = 150
14+
export const DEFAULT_PROPAGATION_BUFFER_TTL = 10 * 1000
15+
export const DEFAULT_MIN_PROPAGATION_TARGETS = 2
16+
export const DEFAULT_MAX_PROPAGATION_BUFFER_SIZE = 150
17+
1718
/**
1819
* Message propagation logic of a node. Given a message, this class will actively attempt to propagate it to
1920
* `minPropagationTargets` neighbors until success or TTL expiration.
@@ -29,9 +30,9 @@ export class Propagation {
2930

3031
constructor({
3132
sendToNeighbor,
32-
minPropagationTargets = DEFAULT_MIN_PROPAGATION_TARGETS,
33-
maxMessages = DEFAULT_MAX_MESSAGES,
34-
ttl = DEFAULT_TTL,
33+
minPropagationTargets,
34+
maxMessages,
35+
ttl
3536
}: ConstructorOptions) {
3637
this.sendToNeighbor = sendToNeighbor
3738
this.minPropagationTargets = minPropagationTargets

packages/trackerless-network/src/logic/proxy/ProxyClient.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ interface ProxyClientOptions {
4646
localPeerDescriptor: PeerDescriptor
4747
streamPartId: StreamPartID
4848
connectionLocker: ConnectionLocker
49-
// TODO could be required options if we apply all defaults somewhere at higher level
50-
maxPropagationBufferSize?: number
51-
minPropagationTargets?: number
49+
maxPropagationBufferSize: number
50+
minPropagationTargets: number
51+
propagationBufferTtl: number
5252
}
5353

5454
interface ProxyDefinition {
@@ -107,6 +107,7 @@ export class ProxyClient extends EventEmitter<Events> {
107107
this.propagation = new Propagation({
108108
minPropagationTargets: options.minPropagationTargets,
109109
maxMessages: options.maxPropagationBufferSize,
110+
ttl: options.propagationBufferTtl,
110111
sendToNeighbor: async (neighborId: DhtAddress, msg: StreamMessage): Promise<void> => {
111112
const remote = this.neighbors.get(neighborId)
112113
if (remote) {

0 commit comments

Comments
 (0)