Mise à jour de GitLab prévue ce samedi 23 octobre 2021 à partir de 9h00 CET

Commit 07c76637 authored by Éloïs's avatar Éloïs
Browse files

[enh] add options --ws2p-prefered-only and --ws2p-privileged-only #1181

parent 50d29e79
......@@ -73,7 +73,9 @@ export interface WS2PConfDTO {
maxPublic?:number
maxPrivate?:number
preferedNodes?: string[]
preferedOnly: boolean
privilegedNodes?: string[]
privilegedOnly: boolean
}
}
......@@ -145,7 +147,9 @@ export class ConfDTO implements CurrencyConfDTO, KeypairConfDTO, NetworkConfDTO,
port?: number
host?: string
preferedNodes?: string[]
preferedOnly: boolean
privilegedNodes?: string[]
privilegedOnly: boolean
maxPublic?:number
maxPrivate?:number
}
......
......@@ -28,8 +28,10 @@ export const WS2PDependency = {
{ value: '--ws2p-nopublic', desc: 'Disable WS2P Public access.' },
{ value: '--ws2p-prefered-add <pubkey>', desc: 'Add a prefered node to connect to through private access.' },
{ value: '--ws2p-prefered-rm <pubkey>', desc: 'Remove prefered node.' },
{ value: '--ws2p-prefered-only <pubkey>', desc: 'Only connect to prefered node.' },
{ value: '--ws2p-privileged-add <pubkey>', desc: 'Add a privileged node to for our public access.' },
{ value: '--ws2p-privileged-rm <pubkey>', desc: 'Remove a privileged.' },
{ value: '--ws2p-privileged-only <pubkey>', desc: 'Accept only connections from a privileged node.' },
],
config: {
......@@ -39,7 +41,9 @@ export const WS2PDependency = {
conf.ws2p = conf.ws2p || {
uuid: nuuid.v4().slice(0,8),
privateAccess: true,
publicAccess: true
publicAccess: true,
preferedOnly: false,
privilegedOnly: false
}
// For config with missing value
......@@ -73,6 +77,7 @@ export const WS2PDependency = {
conf.ws2p.preferedNodes.splice(index, 1)
}
}
if (program.ws2pPreferedOnly !== undefined) conf.ws2p.preferedOnly = true
// Privileged nodes
if (program.ws2pPrivilegedAdd !== undefined) {
......@@ -86,6 +91,7 @@ export const WS2PDependency = {
conf.ws2p.privilegedNodes.splice(index, 1)
}
}
if (program.ws2pPrivilegedOnly !== undefined) conf.ws2p.privilegedOnly = true
// Default value
if (conf.ws2p.upnp === undefined || conf.ws2p.upnp === null) {
......
......@@ -265,7 +265,8 @@ export class WS2PCluster {
await this.ws2pServer.close()
}
this.ws2pServer = await WS2PServer.bindOn(this.server, host, port, this.fifo, (pubkey:string, connectedPubkeys:string[]) => {
return this.acceptPubkey(pubkey, connectedPubkeys, () => this.servedCount(), this.maxLevel2Peers, (this.server.conf.ws2p && this.server.conf.ws2p.privilegedNodes || []))
const privilegedNodes = (this.server.conf.ws2p && this.server.conf.ws2p.privilegedNodes) ? this.server.conf.ws2p.privilegedNodes:[]
return this.acceptPubkey(pubkey, connectedPubkeys, () => this.servedCount(), this.maxLevel2Peers, privilegedNodes, (this.server.conf.ws2p && this.server.conf.ws2p.privilegedOnly || false))
}, this.messageHandler)
this.host = host
this.port = port
......@@ -295,7 +296,8 @@ export class WS2PCluster {
const fullEndpointAddress = WS2PCluster.getFullAddress(host, port, path)
const ws2pc = await WS2PClient.connectTo(this.server, fullEndpointAddress, messageHandler, expectedPub, (pub:string) => {
const connectedPubkeys = this.getConnectedPubkeys()
return this.acceptPubkey(expectedPub, connectedPubkeys, () => this.clientsCount(), this.maxLevel1Size, (this.server.conf.ws2p && this.server.conf.ws2p.preferedNodes || []), ws2pEndpointUUID)
const preferedNodes = (this.server.conf.ws2p && this.server.conf.ws2p.preferedNodes) ? this.server.conf.ws2p.preferedNodes:[]
return this.acceptPubkey(expectedPub, connectedPubkeys, () => this.clientsCount(), this.maxLevel1Size, preferedNodes, (this.server.conf.ws2p && this.server.conf.ws2p.preferedOnly) || false, ws2pEndpointUUID)
})
this.ws2pClients[uuid] = ws2pc
pub = ws2pc.connection.pubkey
......@@ -375,7 +377,8 @@ export class WS2PCluster {
if (ws2pEnpoint) {
// Check if already connected to the pubkey (in any way: server or client)
const connectedPubkeys = this.getConnectedPubkeys()
const shouldAccept = await this.acceptPubkey(peer.pubkey, connectedPubkeys, () => this.clientsCount(), this.maxLevel1Size, (this.server.conf.ws2p && this.server.conf.ws2p.preferedNodes || []), ws2pEnpoint.uuid)
const preferedNodes = (this.server.conf.ws2p && this.server.conf.ws2p.preferedNodes) ? this.server.conf.ws2p.preferedNodes:[]
const shouldAccept = await this.acceptPubkey(peer.pubkey, connectedPubkeys, () => this.clientsCount(), this.maxLevel1Size, preferedNodes, (this.server.conf.ws2p && this.server.conf.ws2p.preferedOnly) || false, ws2pEnpoint.uuid)
if (shouldAccept && (!this.server.conf.ws2p || ws2pEnpoint.uuid !== this.server.conf.ws2p.uuid || peer.pubkey !== this.server.conf.pair.pub || ws2pEnpoint.uuid === '11111111')) {
await this.connectToRemoteWS(ws2pEnpoint.host, ws2pEnpoint.port, ws2pEnpoint.path, this.messageHandler, peer.pubkey)
await this.trimClientConnections()
......@@ -546,6 +549,7 @@ export class WS2PCluster {
getConcurrentConnexionsCount:()=>number,
maxConcurrentConnexionsSize:number,
priorityKeys:string[],
priorityKeysOnly:boolean,
targetWS2PUID = ""
) {
// We do not accept banned keys
......@@ -554,7 +558,7 @@ export class WS2PCluster {
return false
}
let accept = priorityKeys.indexOf(pub) !== -1
if (!accept && connectedPubkeys.indexOf(pub) === -1) {
if (!accept && !priorityKeysOnly && connectedPubkeys.indexOf(pub) === -1) {
// Do we have room?
if (this.server.conf.pair.pub === pub && this.server.conf.ws2p && this.server.conf.ws2p.uuid === targetWS2PUID) {
accept = false
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment