From 268aba576488d24579e43d7b1f475b50045e18e0 Mon Sep 17 00:00:00 2001
From: cgeek <cem.moreau@gmail.com>
Date: Sat, 28 Oct 2017 10:44:51 +0200
Subject: [PATCH] [fix] #1166 PreferedNodes should have higher priority on
 trimming

---
 app/modules/ws2p/lib/WS2PCluster.ts | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/app/modules/ws2p/lib/WS2PCluster.ts b/app/modules/ws2p/lib/WS2PCluster.ts
index 546c0d633..bf56d75e9 100644
--- a/app/modules/ws2p/lib/WS2PCluster.ts
+++ b/app/modules/ws2p/lib/WS2PCluster.ts
@@ -478,7 +478,8 @@ export class WS2PCluster {
         const pub = client.connection.pubkey
         const isNotOurself = pub !== this.server.conf.pair.pub
         const isMember = await this.server.dal.isMember(pub)
-        if (isNotOurself && !isMember && !disconnectedOne) {
+        const isPrefered = this.getPreferedNodes().indexOf(pub) !== -1
+        if (isNotOurself && !isMember && !disconnectedOne && !isPrefered) {
           client.connection.close()
           await client.connection.closed
           disconnectedOne = true
@@ -498,7 +499,8 @@ export class WS2PCluster {
         const client = this.ws2pClients[uuid]
         const pub = client.connection.pubkey
         const isNotOurself = pub !== this.server.conf.pair.pub
-        if (isNotOurself && !disconnectedOne && this.getPreferedNodes().indexOf(pub) === -1) {
+        const isPrefered = this.getPreferedNodes().indexOf(pub) !== -1
+        if (isNotOurself && !disconnectedOne && !isPrefered) {
           client.connection.close()
           disconnectedOne = true
           await client.connection.closed
-- 
GitLab