From fe063ef0584fcf3cee3eb449a29190817f7a0565 Mon Sep 17 00:00:00 2001
From: librelois <elois@ifee.fr>
Date: Wed, 15 Nov 2017 17:15:24 +0100
Subject: [PATCH] [fix] insoleet feedbacks

---
 app/lib/dto/PeerDTO.ts                 |  4 ++--
 app/modules/ws2p/lib/WS2PCluster.ts    | 15 +++++++++++----
 app/modules/ws2p/lib/WS2PConnection.ts |  2 +-
 3 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/app/lib/dto/PeerDTO.ts b/app/lib/dto/PeerDTO.ts
index 4d735bd31..4b9555bfc 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 8bcfd4fbc..777196286 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 f96877344..2d57a2abc 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) {
-- 
GitLab