From b735d59d8a59329d8e83003de4f8cf8344728722 Mon Sep 17 00:00:00 2001 From: icylogic Date: Mon, 18 Jan 2016 16:28:03 +0800 Subject: [PATCH] remove ISP/Geolocation detection --- .../Service/AvailabilityStatistics.cs | 82 ++----------------- 1 file changed, 5 insertions(+), 77 deletions(-) diff --git a/shadowsocks-csharp/Controller/Service/AvailabilityStatistics.cs b/shadowsocks-csharp/Controller/Service/AvailabilityStatistics.cs index 30a339a..ef64197 100644 --- a/shadowsocks-csharp/Controller/Service/AvailabilityStatistics.cs +++ b/shadowsocks-csharp/Controller/Service/AvailabilityStatistics.cs @@ -119,56 +119,6 @@ namespace Shadowsocks.Controller Logging.Debug($"{_currentServer.FriendlyName()}: current/max inbound {inboundSpeed}/{_inboundSpeed} KiB/s, current/max outbound {outboundSpeed}/{_outboundSpeed} KiB/s"); } - //hardcode - //TODO: backup reliable isp&geolocation provider or a local database is required - public static async Task GetGeolocationAndIsp() - { - Logging.Debug("Retrive information of geolocation and isp"); - const string API = "http://ip-api.com/json"; - const string alternativeAPI = "http://www.telize.com/geoip"; //must be comptible with current API - var result = await GetInfoFromAPI(API); - if (result != null) return result; - result = await GetInfoFromAPI(alternativeAPI); - if (result != null) return result; - return new DataList - { - new DataUnit(State.Geolocation, State.Unknown), - new DataUnit(State.ISP, State.Unknown) - }; - } - - //TODO: remove geolocation - private static async Task GetInfoFromAPI(string API) - { - string jsonString; - try - { - jsonString = await new HttpClient().GetStringAsync(API); - } - catch (Exception e) - { - Logging.LogUsefulException(e); - return null; - } - JObject obj; - try - { - obj = JObject.Parse(jsonString); - } - catch (JsonReaderException) - { - return null; - } - string country = (string)obj["country"]; - string city = (string)obj["city"]; - string isp = (string)obj["isp"]; - if (country == null || city == null || isp == null) return null; - return new DataList { - new DataUnit(State.Geolocation, $"\"{country} {city}\""), - new DataUnit(State.ISP, $"\"{isp}\"") - }; - } - private async Task> ICMPTest(Server server) { Logging.Debug("Ping " + server.FriendlyName()); @@ -186,11 +136,11 @@ namespace Shadowsocks.Controller { new KeyValuePair("Timestamp", timestamp), new KeyValuePair("Server", server.FriendlyName()), + new KeyValuePair("Status", reply?.Status.ToString()), + new KeyValuePair("RoundtripTime", reply?.RoundtripTime.ToString()), new KeyValuePair("Latency", GetRecentLatency(server)), new KeyValuePair("InboundSpeed", GetRecentInboundSpeed(server)), - new KeyValuePair("OutboundSpeed", GetRecentOutboundSpeed(server)), - new KeyValuePair("Status", reply?.Status.ToString()), - new KeyValuePair("RoundtripTime", reply?.RoundtripTime.ToString()) + new KeyValuePair("OutboundSpeed", GetRecentOutboundSpeed(server)) //new KeyValuePair("data", reply.Buffer.ToString()); // The data of reply }); Thread.Sleep(Timeout + new Random().Next() % Timeout); @@ -246,13 +196,12 @@ namespace Shadowsocks.Controller private async void evaluate() { - var geolocationAndIsp = GetGeolocationAndIsp(); foreach (var dataLists in await TaskEx.WhenAll(_servers.Select(ICMPTest))) { if (dataLists == null) continue; foreach (var dataList in dataLists.Where(dataList => dataList != null)) { - Append(dataList, geolocationAndIsp.Result); + Append(dataList, Enumerable.Empty()); } } } @@ -298,19 +247,6 @@ namespace Shadowsocks.Controller foreach (IEnumerable rawData in RawStatistics.Values) { var filteredData = rawData; - if (_config.ByIsp) - { - var current = await GetGeolocationAndIsp(); - filteredData = - filteredData.Where( - data => - data.Geolocation == current[0].Value || - data.Geolocation == State.Unknown); - filteredData = - filteredData.Where( - data => data.ISP == current[1].Value || data.ISP == State.Unknown); - if (filteredData.LongCount() == 0) return; - } if (_config.ByHourOfDay) { var currentHour = DateTime.Now.Hour; @@ -344,11 +280,7 @@ namespace Shadowsocks.Controller Timestamp = ParseExactOrUnknown(strings[0]), ServerName = strings[1], ICMPStatus = strings[2], - RoundtripTime = int.Parse(strings[3]), - Geolocation = 5 > strings.Length ? - null - : strings[4], - ISP = 6 > strings.Length ? null : strings[5] + RoundtripTime = int.Parse(strings[3]) } group rawData by rawData.ServerName into server select new @@ -372,8 +304,6 @@ namespace Shadowsocks.Controller public class State { public DataList dataList = new DataList(); - public const string Geolocation = "Geolocation"; - public const string ISP = "ISP"; public const string Unknown = "Unknown"; } @@ -384,8 +314,6 @@ namespace Shadowsocks.Controller public string ServerName; public string ICMPStatus; public int RoundtripTime; - public string Geolocation; - public string ISP; } public class StatisticsData