diff --git a/app/lib/dto/PeerDTO.ts b/app/lib/dto/PeerDTO.ts index 4d735bd3129cd582a9cabcbb059e338d8d33388c..4b9555bfc617bb4ceff21c2c4ef2104f4ae97cb5 100644 --- a/app/lib/dto/PeerDTO.ts +++ b/app/lib/dto/PeerDTO.ts @@ -103,9 +103,9 @@ export class PeerDTO implements Cloneable { let bestWS2PTORVersionAvailable:number = 0 for (const ep of this.endpoints) { if (canReachTorEp) { - let matches:any = ep.match(CommonConstants.WS2PTOR_V2_REGEXP) + let matches:RegExpMatchArray | null = ep.match(CommonConstants.WS2PTOR_V2_REGEXP) if (matches && parseInt(matches[1]) > bestWS2PTORVersionAvailable && (uuidExcluded.indexOf(matches[2]) === -1)) { - bestWS2PTORVersionAvailable = matches[1] + bestWS2PTORVersionAvailable = parseInt(matches[1]) api = { version: parseInt(matches[1]), uuid: matches[2], diff --git a/app/modules/ws2p/lib/WS2PCluster.ts b/app/modules/ws2p/lib/WS2PCluster.ts index 8bcfd4fbcb6d99b88bd9ccc27416216761652936..777196286283ae408483e78dc56e8c4d32fdca00 100644 --- a/app/modules/ws2p/lib/WS2PCluster.ts +++ b/app/modules/ws2p/lib/WS2PCluster.ts @@ -267,8 +267,7 @@ export class WS2PCluster { await this.ws2pServer.close() } this.ws2pServer = await WS2PServer.bindOn(this.server, host, port, this.fifo, (pubkey:string, connectedPubkeys:string[]) => { - 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 !== undefined && this.server.conf.ws2p.privilegedOnly)) + return this.acceptPubkey(pubkey, connectedPubkeys, [], () => this.servedCount(), this.maxLevel2Peers, this.privilegedNodes(), (this.server.conf.ws2p !== undefined && this.server.conf.ws2p.privilegedOnly)) }, this.keyPriorityLevel, this.messageHandler) this.host = host this.port = port @@ -285,7 +284,7 @@ export class WS2PCluster { clientsCount() { let count = 0 - for (const ws2pid of Object.keys(this.ws2pClients)) { + for (const ws2pid in this.ws2pClients) { if (this.ws2pClients[ws2pid].connection.pubkey != this.server.conf.pair.pub) { count++ } @@ -295,7 +294,7 @@ export class WS2PCluster { numberOfConnectedPublicNodesWithSameKey() { let count = 0 - for (const ws2pid of Object.keys(this.ws2pClients)) { + for (const ws2pid in this.ws2pClients) { if (this.ws2pClients[ws2pid].connection.pubkey === this.server.conf.pair.pub) { count++ } @@ -307,6 +306,14 @@ export class WS2PCluster { return (this.ws2pServer) ? this.ws2pServer.countConnexions():0 } + privilegedNodes() { + if (this.server.conf.ws2p && this.server.conf.ws2p.privilegedNodes) { + return this.server.conf.ws2p.privilegedNodes + } else { + return [] + } + } + async connectToRemoteWS(endpointVersion:number, host: string, port: number, path:string, messageHandler:WS2PMessageHandler, expectedPub:string, ws2pEndpointUUID:string = ""): Promise<WS2PConnection> { const uuid = nuuid.v4() let pub = expectedPub.slice(0, 8) diff --git a/app/modules/ws2p/lib/WS2PConnection.ts b/app/modules/ws2p/lib/WS2PConnection.ts index f968773443bde4fc9ee13186ff81910bc8978995..2d57a2abc156f9a00da12a5ac79c69ad105a2d44 100644 --- a/app/modules/ws2p/lib/WS2PConnection.ts +++ b/app/modules/ws2p/lib/WS2PConnection.ts @@ -430,7 +430,7 @@ export class WS2PConnection { return this.errorDetected(WS2P_ERR.ALREADY_AUTHENTICATED_BY_REMOTE) } else if ( - typeof data.pub !== "string" || typeof data.sig !== "string" || typeof data.challenge !== "string" || (this.ws2pVersion > 1 && data.ws2pId !== "string") ) { + typeof data.pub !== "string" || typeof data.sig !== "string" || typeof data.challenge !== "string" || (this.ws2pVersion > 1 && typeof data.ws2pId !== "string") ) { await this.errorDetected(WS2P_ERR.AUTH_INVALID_ASK_FIELDS) } else { if (this.expectedPub && data.pub !== this.expectedPub) {