From 813e3352db13d57d7bf824aa3ebc77db49ffea6b Mon Sep 17 00:00:00 2001
From: librelois <elois@ifee.fr>
Date: Wed, 29 Nov 2017 16:13:57 +0100
Subject: [PATCH] [fix] head network stats

---
 app/modules/ws2p/lib/WS2PCluster.ts    | 18 +++++++++++-------
 app/modules/ws2p/lib/WS2PConnection.ts |  2 +-
 app/modules/ws2p/lib/constants.ts      | 14 +++++++++++++-
 3 files changed, 25 insertions(+), 9 deletions(-)

diff --git a/app/modules/ws2p/lib/WS2PCluster.ts b/app/modules/ws2p/lib/WS2PCluster.ts
index decebbf7f..e60bad06c 100644
--- a/app/modules/ws2p/lib/WS2PCluster.ts
+++ b/app/modules/ws2p/lib/WS2PCluster.ts
@@ -1,3 +1,4 @@
+import { DEFAULT_ENCODING } from 'crypto';
 import {WS2PServer} from "./WS2PServer"
 import {Server} from "../../../../server"
 import {WS2PClient} from "./WS2PClient"
@@ -565,29 +566,32 @@ export class WS2PCluster {
 
   private getApi() {
     let api = 'WS2P'
-    let network = ''
+    let network = {
+      in: WS2PConstants.NETWORK.INCOMING.DEFAULT,
+      out: WS2PConstants.NETWORK.OUTCOMING.DEFAULT,
+    }
     let ws2pPrivate = ''
     let ws2pPublic = ''
     if (this.server.conf.proxiesConf && (this.server.conf.proxiesConf.proxyTorAddress || this.server.conf.proxiesConf.forceTor)) {
-      network = 'TOR'
+      network.out = WS2PConstants.NETWORK.OUTCOMING.TOR
     }
     if (this.server.conf.ws2p) {
       if (this.server.conf.ws2p.remotehost) {
         if (this.server.conf.ws2p.remotehost.match(WS2PConstants.HOST_ONION_REGEX)) {
-          network = 'TOR'
+          network.in = WS2PConstants.NETWORK.INCOMING.TOR
         }
         if (this.server.conf.ws2p.publicAccess) {
           ws2pPublic = 'I'
-          switch (network) {
-            case 'TOR': ws2pPublic += 'T'; break;
+          switch (network.in) {
+            case WS2PConstants.NETWORK.INCOMING.TOR: ws2pPublic += 'T'; break;
             default: ws2pPublic += 'C'; break;
           }
         }
       }
       if (this.server.conf.ws2p.privateAccess) {
         ws2pPrivate = 'O'
-        switch (network) {
-          case 'TOR': ws2pPrivate += 'T';
+        switch (network.out) {
+          case WS2PConstants.NETWORK.OUTCOMING.TOR: ws2pPrivate += 'T';
             if (this.server.conf.proxiesConf && this.server.conf.proxiesConf.reachingClearEp) {
               switch (this.server.conf.proxiesConf.reachingClearEp) {
                 case 'none': ws2pPrivate += 'S'; break;
diff --git a/app/modules/ws2p/lib/WS2PConnection.ts b/app/modules/ws2p/lib/WS2PConnection.ts
index 72d30aceb..64e85414b 100644
--- a/app/modules/ws2p/lib/WS2PConnection.ts
+++ b/app/modules/ws2p/lib/WS2PConnection.ts
@@ -341,7 +341,7 @@ export class WS2PConnection {
     const onWsClosed:Promise<void> = new Promise(res => {
       websocket.on('close', () => res())
     })
-    return new WS2PConnection(WS2PConstants.WS2P_DEFAULT_VERSION, websocket, onWsOpened, onWsClosed, messageHandler, localAuth, remoteAuth, options, expectedPub)
+    return new WS2PConnection(WS2PConstants.WS2P_DEFAULT_API_VERSION, websocket, onWsOpened, onWsClosed, messageHandler, localAuth, remoteAuth, options, expectedPub)
   }
 
   get version() {
diff --git a/app/modules/ws2p/lib/constants.ts b/app/modules/ws2p/lib/constants.ts
index 74d5c586a..0a281b569 100644
--- a/app/modules/ws2p/lib/constants.ts
+++ b/app/modules/ws2p/lib/constants.ts
@@ -1,7 +1,19 @@
 import {CommonConstants} from "../../../lib/common-libs/constants"
 export const WS2PConstants = {
 
-  WS2P_DEFAULT_VERSION:1,
+  NETWORK: {
+    INCOMING: {
+      DEFAULT: 0,
+      TOR: 1
+    },
+    OUTCOMING: {
+      DEFAULT: 0,
+      TOR: 1
+    },
+  },
+
+  WS2P_DEFAULT_API_VERSION:1,
+  WS2P_DEFAULT_HEAD_VERSION:1,
   WS2P_API_VERSION: 1,
   WS2P_HEAD_VERSION: 2,
 
-- 
GitLab