Prechádzať zdrojové kódy

支持Https新版云服务登录

felix 1 rok pred
rodič
commit
ad49dc4a21

+ 5 - 5
Settings/FISSDK/FISServerSettingsV2.conf

@@ -2,23 +2,23 @@
   "Servers": [
     {
       "Host": "bj.flyinsono.com",
-      "Port": 80
+      "Port": 443
     },
 	{
       "Host": "hk.flyinsono.com",
-      "Port": 80
+      "Port": 443
     },
 	{
       "Host": "fra.flyinsono.com",
-      "Port": 80
+      "Port": 443
     },
 	{
       "Host": "bom.flyinsono.com",
-      "Port": 80
+      "Port": 443
     },
   ],
   "MasterServer": {
       "Host": "hk.flyinsono.com",
-      "Port": 80
+      "Port": 443
     },
 }

+ 1 - 1
Vinno.FIS.Sonopost/Assets/wwwroot/pages/server/login.html

@@ -253,7 +253,7 @@
         function initServerNodeEvent() {
             form.on("select(ServerNode)", function (data) {
                 let ip = data.value;
-                let port = 80;
+                let port = 9096;
                 let serverName = "";
                 if (ip === "custom") {
                     $("#pageLogin .custom-server-item").show();

+ 0 - 34
Vinno.vCloud.Common.FIS/vCloudServerSelector.cs

@@ -51,13 +51,6 @@ namespace Vinno.vCloud.Common.FIS
                 Task.Run(() => CheckJsonRpc(true));
                 if (_manualResetEvent.WaitOne(5000))
                 {
-                    if (_testResult == ServerTestResult.NewServerWithHttp)
-                    {
-                        if (HttpsCheck())
-                        {
-                            _testResult = ServerTestResult.NewServerWithHttps;
-                        }
-                    }
                     Logger.WriteLineInfo($"vCloudServerSelector TestResult is {_testResult}");
                 }
                 else
@@ -204,33 +197,6 @@ namespace Vinno.vCloud.Common.FIS
             }
         }
 
-        private bool HttpsCheck()
-        {
-            try
-            {
-                if (_clientForHttps != null)
-                {
-                    _clientForHttps.Dispose();
-                    _clientForHttps = null;
-                }
-                var url = $"https://{_host}:{_port}";
-                _clientForHttps = new JsonRpcClient();
-                var clientEngine = new JsonRpcHttpClientEngine(url);
-                _clientForHttps.UseEngine(clientEngine);
-                var vinnoServerService = _clientForHttps.CreateProxy<IVinnoServerService>(4000);
-                var echoResult = JsonRpcHelper.Echo(vinnoServerService);
-                if (echoResult != null && echoResult.Code == 0)
-                {
-                    return true;
-                }
-                return false;
-            }
-            catch
-            {
-                return false;
-            }
-        }
-
         public void Dispose()
         {
             try

+ 65 - 11
Vinno.vCloud.Common.FIS/vCloudTerminalBuilderV2.cs

@@ -6,6 +6,7 @@ using System.Collections.Concurrent;
 using System.Collections.Generic;
 using System.Diagnostics;
 using System.IO;
+using System.Net.NetworkInformation;
 using System.Threading;
 using System.Threading.Tasks;
 using Vinno.IUS.Common.Log;
@@ -42,7 +43,8 @@ namespace Vinno.vCloud.Common.FIS
                 ServerInfo fasterServer = null;
                 var speedResults = new ConcurrentDictionary<ServerInfo, int>();
                 var serverFilePath = Path.Combine(settingFilePath, "FISServerSettingsV2.conf");
-                var serverSettings = GetFasterServerList(true);
+                DefaultServerSettings serverSettings = null;
+                //serverSettings = GetFasterServerList(true);
                 if (serverSettings == null)
                 {
                     if (File.Exists(serverFilePath))
@@ -56,18 +58,18 @@ namespace Vinno.vCloud.Common.FIS
                         {
                             Servers = new List<ServerInfo>
                             {
-                                 new ServerInfo { Host = "bj.flyinsono.com", Port = 80 },
-                                 new ServerInfo { Host = "hk.flyinsono.com", Port = 80 },
-                                 new ServerInfo { Host = "fra.flyinsono.com", Port = 80 },
-                                 new ServerInfo { Host = "bom.flyinsono.com", Port = 80 },
+                                 new ServerInfo { Host = "bj.flyinsono.com", Port = 443 },
+                                 new ServerInfo { Host = "hk.flyinsono.com", Port = 443 },
+                                 new ServerInfo { Host = "fra.flyinsono.com", Port = 443 },
+                                 new ServerInfo { Host = "bom.flyinsono.com", Port = 443 },
                             },
-                            MasterServer = new ServerInfo { Host = "hk.flyinsono.com", Port = 80 }
+                            MasterServer = new ServerInfo { Host = "hk.flyinsono.com", Port = 443 }
                         };
                     }
                 }
                 Parallel.ForEach(serverSettings.Servers, serverInfo =>
                 {
-                    var speed = GetConnectServerSpeed(serverInfo.ToString());
+                    var speed = GetConnectServerSpeed(serverInfo.Host);
                     if (speed != -1)
                     {
                         speedResults.TryAdd(serverInfo, speed);
@@ -102,7 +104,7 @@ namespace Vinno.vCloud.Common.FIS
                 Logger.WriteLineError($"Get faster server error: {ex}");
             }
 
-            return new ServerInfo { Host = "hk.flyinsono.com", Port = 80 };
+            return new ServerInfo { Host = "hk.flyinsono.com", Port = 443 };
         }
 
         private static DefaultServerSettings GetFasterServerList(bool isUseHttps = true)
@@ -120,7 +122,7 @@ namespace Vinno.vCloud.Common.FIS
                 }
                 using (var client = new JsonRpcClient())
                 {
-                    var clientEngine = new JsonRpcHttpClientEngine($"{prefix}hk.flyinsono.com:80");
+                    var clientEngine = new JsonRpcHttpClientEngine($"{prefix}hk.flyinsono.com:443");
                     client.UseEngine(clientEngine);
                     var vinnoServerService = client.CreateProxy<IVinnoServerService>();
                     var queryServerInfoRequest = new QueryServerInfoRequest();
@@ -130,7 +132,7 @@ namespace Vinno.vCloud.Common.FIS
                         return null;
                     }
                     string host;
-                    int port = 80;
+                    int port = 443;
                     var serverSetting = new DefaultServerSettings() { Servers = new List<ServerInfo>() };
                     foreach (var server in result)
                     {
@@ -205,7 +207,59 @@ namespace Vinno.vCloud.Common.FIS
         /// </summary>
         /// <param name="serverUrl"></param>
         /// <returns></returns>
-        private static int GetConnectServerSpeed(string serverUrl, bool isUseHttps = true)
+        private static int GetConnectServerSpeed(string serverUrl)
+        {
+            try
+            {
+                using (var ping = new Ping())
+                {
+                    var successTimes = 0;
+                    var totalTime = 0;
+                    for (var i = 0; i < 4; i++)//第一次为预热
+                    {
+                        try
+                        {
+                            var reply = ping.Send(serverUrl, 3000);
+                            if (reply.Status == IPStatus.Success && i > 0)
+                            {
+                                Logger.WriteLineInfo($"Connect serverUrl:{serverUrl}, spend time:{reply.RoundtripTime}ms");
+                                totalTime += (int)reply.RoundtripTime;
+                                successTimes++;
+                            }
+                        }
+                        catch (Exception ex)
+                        {
+                            Logger.WriteLineError($"Connect serverUrl:{serverUrl} error, Exception:{ex}");
+                            continue;
+                        }
+                    }
+                    if (successTimes == 0)
+                    {
+                        Logger.WriteLineInfo($"Connect serverUrl:{serverUrl} fail, the success times is 0");
+                        return -1;
+                    }
+                    else
+                    {
+                        var averageValue = totalTime / successTimes;
+                        Logger.WriteLineInfo($"Connect serverUrl:{serverUrl},successTimes:{successTimes},spend time averageValue:{averageValue}ms");
+                        return averageValue;
+                    }
+                }
+            }
+            catch (Exception e)
+            {
+                Logger.WriteLineError($"Connect Server:{serverUrl}, SpeedTest exception:{e}");
+                return -1;
+            }
+        }
+
+        /// 多个服务器会报错同时用Jsonrpc会报错
+        /// <summary>
+        /// test connet server speed
+        /// </summary>
+        /// <param name="serverUrl"></param>
+        /// <returns></returns>
+        private static int OldGetConnectServerSpeed(string serverUrl, bool isUseHttps = true)
         {
             try
             {