Merge pull request #1 from 2dust/master

update from 2dust/master
This commit is contained in:
badhumor 2019-10-18 13:14:53 +08:00 committed by GitHub
commit 8852c2a4d2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 1071 additions and 454 deletions

View file

@ -319,16 +319,15 @@ namespace v2rayN.Forms
private void DisplayToolStatus() private void DisplayToolStatus()
{ {
var localIP = "127.0.0.1";
toolSslSocksPort.Text = toolSslSocksPort.Text =
toolSslHttpPort.Text = toolSslHttpPort.Text =
toolSslPacPort.Text = "NONE"; toolSslPacPort.Text = "NONE";
toolSslSocksPort.Text = $"{localIP}:{config.inbound[0].localPort}"; toolSslSocksPort.Text = $"{Global.Loopback}:{config.inbound[0].localPort}";
if (config.sysAgentEnabled) if (config.sysAgentEnabled)
{ {
toolSslHttpPort.Text = $"{localIP}:{Global.sysAgentPort}"; toolSslHttpPort.Text = $"{Global.Loopback}:{Global.sysAgentPort}";
if (config.listenerType == 2 || config.listenerType == 4) if (config.listenerType == 2 || config.listenerType == 4)
{ {
if (PACServerHandle.IsRunning) if (PACServerHandle.IsRunning)
@ -607,7 +606,7 @@ namespace v2rayN.Forms
private void menuRealPingServer_Click(object sender, EventArgs e) private void menuRealPingServer_Click(object sender, EventArgs e)
{ {
if (!config.sysAgentEnabled || config.listenerType != 1) if (!config.sysAgentEnabled)
{ {
UI.Show(UIRes.I18N("NeedHttpGlobalProxy")); UI.Show(UIRes.I18N("NeedHttpGlobalProxy"));
return; return;
@ -622,7 +621,7 @@ namespace v2rayN.Forms
private void menuSpeedServer_Click(object sender, EventArgs e) private void menuSpeedServer_Click(object sender, EventArgs e)
{ {
if (!config.sysAgentEnabled || config.listenerType != 1) if (!config.sysAgentEnabled)
{ {
UI.Show(UIRes.I18N("NeedHttpGlobalProxy")); UI.Show(UIRes.I18N("NeedHttpGlobalProxy"));
return; return;
@ -1299,7 +1298,7 @@ namespace v2rayN.Forms
} }
else else
{ {
v2rayUpdateHandle.DownloadFileAsync(config, url); v2rayUpdateHandle.DownloadFileAsync(config, url, false);
} }
})); }));
} }

File diff suppressed because it is too large Load diff

View file

@ -147,10 +147,10 @@ namespace v2rayN
/// </summary> /// </summary>
public const string CustomIconName = "v2rayN.ico"; public const string CustomIconName = "v2rayN.ico";
public const string Loopback = "127.0.0.1";
public const string InboundAPITagName = "api"; public const string InboundAPITagName = "api";
public const string InboundProxyTagName = "proxy"; public const string InboundProxyTagName = "proxy";
public const string Loopback = "127.0.0.1";
public const string InboundAPIProtocal = "dokodemo-door"; public const string InboundAPIProtocal = "dokodemo-door";
public enum StatisticsFreshRate public enum StatisticsFreshRate

View file

@ -232,7 +232,7 @@ namespace v2rayN.Handler
testCounter++; testCounter++;
v2rayUpdateHandle2.DownloadFileAsync(_config, url); v2rayUpdateHandle2.DownloadFileAsync(_config, url,true);
return 0; return 0;
} }
@ -276,6 +276,7 @@ namespace v2rayN.Handler
{ {
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url); HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url);
myHttpWebRequest.Timeout = 5000; myHttpWebRequest.Timeout = 5000;
myHttpWebRequest.Proxy = new WebProxy(Global.Loopback, Global.sysAgentPort);
var timer = new Stopwatch(); var timer = new Stopwatch();
timer.Start(); timer.Start();

View file

@ -95,7 +95,7 @@ namespace v2rayN.Handler
{ {
Global.statePort = GetFreePort(); Global.statePort = GetFreePort();
channel_ = new Channel($"127.0.0.1:{Global.statePort}", ChannelCredentials.Insecure); channel_ = new Channel($"{Global.Loopback}:{Global.statePort}", ChannelCredentials.Insecure);
channel_.ConnectAsync(); channel_.ConnectAsync();
client_ = new StatsService.StatsServiceClient(channel_); client_ = new StatsService.StatsServiceClient(channel_);
} }

View file

@ -159,7 +159,7 @@ namespace v2rayN.Handler
} }
else else
{ {
inbound.listen = "127.0.0.1"; inbound.listen = Global.Loopback;
} }
//开启udp //开启udp
inbound.settings.udp = config.inbound[0].udpEnabled; inbound.settings.udp = config.inbound[0].udpEnabled;

View file

@ -92,7 +92,7 @@ namespace v2rayN.Handler
} }
public void DownloadFileAsync(Config config, string url) public void DownloadFileAsync(Config config, string url, bool blProxy)
{ {
try try
{ {
@ -100,12 +100,17 @@ namespace v2rayN.Handler
ServicePointManager.DefaultConnectionLimit = 256; ServicePointManager.DefaultConnectionLimit = 256;
if (UpdateCompleted != null) if (UpdateCompleted != null)
{ {
UpdateCompleted(this, new ResultEventArgs(false, url)); UpdateCompleted(this, new ResultEventArgs(false, "Downloading..."));
} }
progressPercentage = -1; progressPercentage = -1;
WebClientEx ws = new WebClientEx(); WebClientEx ws = new WebClientEx();
if (blProxy)
{
ws.Proxy = new WebProxy(Global.Loopback, Global.sysAgentPort);
}
ws.DownloadFileCompleted += ws_DownloadFileCompleted; ws.DownloadFileCompleted += ws_DownloadFileCompleted;
ws.DownloadProgressChanged += ws_DownloadProgressChanged; ws.DownloadProgressChanged += ws_DownloadProgressChanged;
ws.DownloadFileAsync(new Uri(url), Utils.GetPath(DownloadFileName)); ws.DownloadFileAsync(new Uri(url), Utils.GetPath(DownloadFileName));

View file

@ -47,7 +47,7 @@ namespace v2rayN.HttpProxyHandler
{ {
PACServerHandle.Stop(); PACServerHandle.Stop();
PACFileWatcherHandle.StopWatch(); PACFileWatcherHandle.StopWatch();
SysProxyHandle.SetIEProxy(true, true, "127.0.0.1:" + port, null); SysProxyHandle.SetIEProxy(true, true, $"{Global.Loopback}:{port}", null);
} }
else if (type == 2) else if (type == 2)
{ {
@ -168,8 +168,8 @@ namespace v2rayN.HttpProxyHandler
public static string GetPacUrl() public static string GetPacUrl()
{ {
string pacUrl = string.Format("http://127.0.0.1:{0}/pac/?t={1}", Global.pacPort, string pacUrl = $"http://{Global.Loopback}:{Global.pacPort}/pac/?t={GetTimestamp(DateTime.Now)}";
GetTimestamp(DateTime.Now));
return pacUrl; return pacUrl;
} }

View file

@ -46,7 +46,7 @@ namespace v2rayN.HttpProxyHandler
//{ //{
// throw new Exception("未发现HTTP代理无法设置代理更新"); // throw new Exception("未发现HTTP代理无法设置代理更新");
//} //}
WebClient http = new WebClient(); var http = new WebClientEx();
//http.Headers.Add("Connection", "Close"); //http.Headers.Add("Connection", "Close");
//http.Proxy = new WebProxy(IPAddress.Loopback.ToString(), httpProxy.localPort); //http.Proxy = new WebProxy(IPAddress.Loopback.ToString(), httpProxy.localPort);
http.DownloadStringCompleted += http_DownloadStringCompleted; http.DownloadStringCompleted += http_DownloadStringCompleted;

View file

@ -31,11 +31,11 @@ namespace v2rayN.HttpProxyHandler
//{ //{
// pacPort = Global.pacPort; // pacPort = Global.pacPort;
//} //}
if (InitServer("127.0.0.1")) if (InitServer(Global.Loopback))
{ {
pacPort = Global.pacPort; pacPort = Global.pacPort;
} }
else if (InitServerB("127.0.0.1")) else if (InitServerB(Global.Loopback))
{ {
pacPort = Global.pacPort; pacPort = Global.pacPort;
} }

View file

@ -99,7 +99,7 @@ namespace v2rayN.HttpProxyHandler
} }
else else
{ {
privoxyConfig = privoxyConfig.Replace("__PRIVOXY_BIND_IP__", "127.0.0.1"); privoxyConfig = privoxyConfig.Replace("__PRIVOXY_BIND_IP__", Global.Loopback);
} }
FileManager.ByteArrayToFile(Utils.GetTempPath(_uniqueConfigFile), Encoding.UTF8.GetBytes(privoxyConfig)); FileManager.ByteArrayToFile(Utils.GetTempPath(_uniqueConfigFile), Encoding.UTF8.GetBytes(privoxyConfig));

View file

@ -49,14 +49,14 @@ namespace v2rayN.HttpProxyHandler
public static void SetIEProxy(bool enable, bool global, string proxyServer, string pacURL) public static void SetIEProxy(bool enable, bool global, string proxyServer, string pacURL)
{ {
Read(); //Read();
if (!_userSettings.UserSettingsRecorded) //if (!_userSettings.UserSettingsRecorded)
{ //{
// record user settings // // record user settings
ExecSysproxy("query"); // ExecSysproxy("query");
ParseQueryStr(_queryStr); // ParseQueryStr(_queryStr);
} //}
string arguments; string arguments;
if (enable) if (enable)
@ -71,17 +71,19 @@ namespace v2rayN.HttpProxyHandler
else else
{ {
// restore user settings // restore user settings
var flags = _userSettings.Flags; //var flags = _userSettings.Flags;
var proxy_server = _userSettings.ProxyServer ?? "-"; //var proxy_server = _userSettings.ProxyServer ?? "-";
var bypass_list = _userSettings.BypassList ?? "-"; //var bypass_list = _userSettings.BypassList ?? "-";
var pac_url = _userSettings.PacUrl ?? "-"; //var pac_url = _userSettings.PacUrl ?? "-";
arguments = string.Format("set {0} {1} {2} {3}", flags, proxy_server, bypass_list, pac_url); ////arguments = string.Format("set {0} {1} {2} {3}", flags, proxy_server, bypass_list, pac_url);
//set null settings
arguments = string.Format("set {0} {1} {2} {3}", 1, "-", "<local>", @"http://127.0.0.1");
// have to get new settings // have to get new settings
_userSettings.UserSettingsRecorded = false; //_userSettings.UserSettingsRecorded = false;
} }
Save(); //Save();
ExecSysproxy(arguments); ExecSysproxy(arguments);
} }

View file

@ -5,17 +5,42 @@ namespace v2rayN.HttpProxyHandler
{ {
class WebClientEx : WebClient class WebClientEx : WebClient
{ {
public int Timeout { get; set; } public int Timeout
{
get; set;
}
public WebClientEx(int timeout = 3000) public WebClientEx(int timeout = 3000)
{ {
Timeout = timeout; Timeout = timeout;
} }
protected override WebRequest GetWebRequest(Uri address) protected override WebRequest GetWebRequest(Uri address)
{ {
var request = base.GetWebRequest(address); HttpWebRequest request;
if (address.Scheme == "https")
{
ServicePointManager.ServerCertificateValidationCallback = (a, b, c, d) => { return true; };
request = (HttpWebRequest)base.GetWebRequest(address);
request.ProtocolVersion = HttpVersion.Version10;
}
else
{
request = (HttpWebRequest)base.GetWebRequest(address);
}
request.Timeout = Timeout; request.Timeout = Timeout;
request.ReadWriteTimeout = Timeout;
//request.AllowAutoRedirect = false;
//request.AllowWriteStreamBuffering = true;
request.ServicePoint.BindIPEndPointDelegate = (servicePoint, remoteEndPoint, retryCount) =>
{
if (remoteEndPoint.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6)
return new IPEndPoint(IPAddress.IPv6Any, 0);
else
return new IPEndPoint(IPAddress.Any, 0);
};
return request; return request;
} }
} }

View file

@ -33,4 +33,4 @@ using System.Runtime.InteropServices;
// 方法是按如下所示使用“*”: // 方法是按如下所示使用“*”:
//[assembly: AssemblyVersion("1.0.*")] //[assembly: AssemblyVersion("1.0.*")]
//[assembly: AssemblyVersion("1.0.0")] //[assembly: AssemblyVersion("1.0.0")]
[assembly: AssemblyFileVersion("2.43")] [assembly: AssemblyFileVersion("2.45")]