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()
{
var localIP = "127.0.0.1";
toolSslSocksPort.Text =
toolSslHttpPort.Text =
toolSslPacPort.Text = "NONE";
toolSslSocksPort.Text = $"{localIP}:{config.inbound[0].localPort}";
toolSslSocksPort.Text = $"{Global.Loopback}:{config.inbound[0].localPort}";
if (config.sysAgentEnabled)
{
toolSslHttpPort.Text = $"{localIP}:{Global.sysAgentPort}";
toolSslHttpPort.Text = $"{Global.Loopback}:{Global.sysAgentPort}";
if (config.listenerType == 2 || config.listenerType == 4)
{
if (PACServerHandle.IsRunning)
@ -607,7 +606,7 @@ namespace v2rayN.Forms
private void menuRealPingServer_Click(object sender, EventArgs e)
{
if (!config.sysAgentEnabled || config.listenerType != 1)
if (!config.sysAgentEnabled)
{
UI.Show(UIRes.I18N("NeedHttpGlobalProxy"));
return;
@ -622,7 +621,7 @@ namespace v2rayN.Forms
private void menuSpeedServer_Click(object sender, EventArgs e)
{
if (!config.sysAgentEnabled || config.listenerType != 1)
if (!config.sysAgentEnabled)
{
UI.Show(UIRes.I18N("NeedHttpGlobalProxy"));
return;
@ -1299,7 +1298,7 @@ namespace v2rayN.Forms
}
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>
public const string CustomIconName = "v2rayN.ico";
public const string Loopback = "127.0.0.1";
public const string InboundAPITagName = "api";
public const string InboundProxyTagName = "proxy";
public const string Loopback = "127.0.0.1";
public const string InboundAPIProtocal = "dokodemo-door";
public enum StatisticsFreshRate

View file

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

View file

@ -95,7 +95,7 @@ namespace v2rayN.Handler
{
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();
client_ = new StatsService.StatsServiceClient(channel_);
}

View file

@ -159,7 +159,7 @@ namespace v2rayN.Handler
}
else
{
inbound.listen = "127.0.0.1";
inbound.listen = Global.Loopback;
}
//开启udp
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
{
@ -100,12 +100,17 @@ namespace v2rayN.Handler
ServicePointManager.DefaultConnectionLimit = 256;
if (UpdateCompleted != null)
{
UpdateCompleted(this, new ResultEventArgs(false, url));
UpdateCompleted(this, new ResultEventArgs(false, "Downloading..."));
}
progressPercentage = -1;
WebClientEx ws = new WebClientEx();
if (blProxy)
{
ws.Proxy = new WebProxy(Global.Loopback, Global.sysAgentPort);
}
ws.DownloadFileCompleted += ws_DownloadFileCompleted;
ws.DownloadProgressChanged += ws_DownloadProgressChanged;
ws.DownloadFileAsync(new Uri(url), Utils.GetPath(DownloadFileName));

View file

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

View file

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

View file

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

View file

@ -99,7 +99,7 @@ namespace v2rayN.HttpProxyHandler
}
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));

View file

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

View file

@ -5,17 +5,42 @@ namespace v2rayN.HttpProxyHandler
{
class WebClientEx : WebClient
{
public int Timeout { get; set; }
public int Timeout
{
get; set;
}
public WebClientEx(int timeout = 3000)
{
Timeout = timeout;
}
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.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;
}
}

View file

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