Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
53494341fc | ||
|
|
5aee97320b | ||
|
|
d5c69c7838 | ||
|
|
9224ea9819 | ||
|
|
a922d3c46d | ||
|
|
b94d10d808 |
@@ -3,7 +3,7 @@ using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
namespace v2rayN.HttpProxyHandler
|
||||
namespace v2rayN.Base
|
||||
{
|
||||
public class HttpWebServer
|
||||
{
|
||||
@@ -1,12 +1,10 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
namespace v2rayN.HttpProxyHandler
|
||||
namespace v2rayN.Base
|
||||
{
|
||||
public class HttpWebServerB
|
||||
{
|
||||
@@ -1,7 +1,7 @@
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace v2rayN.Forms
|
||||
namespace v2rayN.Base
|
||||
{
|
||||
class ListViewFlickerFree : ListView
|
||||
{
|
||||
@@ -2,7 +2,7 @@
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace v2rayN
|
||||
namespace v2rayN.Base
|
||||
{
|
||||
static class StringEx
|
||||
{
|
||||
47
v2rayN/v2rayN/Base/WebClientEx.cs
Normal file
47
v2rayN/v2rayN/Base/WebClientEx.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Net;
|
||||
|
||||
namespace v2rayN.Base
|
||||
{
|
||||
class WebClientEx : WebClient
|
||||
{
|
||||
public int Timeout
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
public WebClientEx(int timeout = 3000)
|
||||
{
|
||||
Timeout = timeout;
|
||||
}
|
||||
|
||||
protected override WebRequest GetWebRequest(Uri 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
4
v2rayN/v2rayN/Forms/MainForm.Designer.cs
generated
4
v2rayN/v2rayN/Forms/MainForm.Designer.cs
generated
@@ -31,7 +31,7 @@
|
||||
this.components = new System.ComponentModel.Container();
|
||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));
|
||||
this.splitContainer1 = new System.Windows.Forms.SplitContainer();
|
||||
this.lvServers = new v2rayN.Forms.ListViewFlickerFree();
|
||||
this.lvServers = new v2rayN.Base.ListViewFlickerFree();
|
||||
this.cmsLv = new System.Windows.Forms.ContextMenuStrip(this.components);
|
||||
this.menuAddVmessServer = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.menuAddShadowsocksServer = new System.Windows.Forms.ToolStripMenuItem();
|
||||
@@ -784,7 +784,7 @@
|
||||
private System.Windows.Forms.GroupBox groupBox1;
|
||||
private System.Windows.Forms.GroupBox groupBox2;
|
||||
private System.Windows.Forms.TextBox txtMsgBox;
|
||||
private v2rayN.Forms.ListViewFlickerFree lvServers;
|
||||
private v2rayN.Base.ListViewFlickerFree lvServers;
|
||||
private System.Windows.Forms.NotifyIcon notifyMain;
|
||||
private System.Windows.Forms.ContextMenuStrip cmsMain;
|
||||
private System.Windows.Forms.ToolStripMenuItem menuExit;
|
||||
|
||||
@@ -8,6 +8,7 @@ using System.Windows.Forms;
|
||||
using v2rayN.Handler;
|
||||
using v2rayN.HttpProxyHandler;
|
||||
using v2rayN.Mode;
|
||||
using v2rayN.Base;
|
||||
|
||||
namespace v2rayN.Forms
|
||||
{
|
||||
@@ -15,7 +16,7 @@ namespace v2rayN.Forms
|
||||
{
|
||||
private V2rayHandler v2rayHandler;
|
||||
private PACListHandle pacListHandle;
|
||||
private V2rayUpdateHandle v2rayUpdateHandle;
|
||||
private DownloadHandle downloadHandle;
|
||||
private List<int> lvSelecteds = new List<int>();
|
||||
private StatisticsHandler statistics = null;
|
||||
|
||||
@@ -319,16 +320,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.httpPort}";
|
||||
if (config.listenerType == 2 || config.listenerType == 4)
|
||||
{
|
||||
if (PACServerHandle.IsRunning)
|
||||
@@ -363,7 +363,7 @@ namespace v2rayN.Forms
|
||||
color = (new Color[] { Color.Red, Color.Purple, Color.DarkGreen, Color.Orange })[index - 1];
|
||||
//color = ColorTranslator.FromHtml(new string[] { "#CC0066", "#CC6600", "#99CC99", "#666699" }[index - 1]);
|
||||
}
|
||||
|
||||
|
||||
var width = 128;
|
||||
var height = 128;
|
||||
|
||||
@@ -607,7 +607,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 +622,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;
|
||||
@@ -1045,7 +1045,7 @@ namespace v2rayN.Forms
|
||||
#endregion
|
||||
|
||||
#region 后台测速
|
||||
|
||||
|
||||
private void SetTestResult(int k, string txt)
|
||||
{
|
||||
config.vmess[k].testResult = txt;
|
||||
@@ -1252,7 +1252,7 @@ namespace v2rayN.Forms
|
||||
{
|
||||
if (isChecked)
|
||||
{
|
||||
if (HttpProxyHandle.RestartHttpAgent(config, true))
|
||||
if (HttpProxyHandle.RestartHttpAgent(config, false))
|
||||
{
|
||||
ChangePACButtonStatus(config.listenerType);
|
||||
}
|
||||
@@ -1280,10 +1280,10 @@ namespace v2rayN.Forms
|
||||
|
||||
private void tsbCheckUpdateCore_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (v2rayUpdateHandle == null)
|
||||
if (downloadHandle == null)
|
||||
{
|
||||
v2rayUpdateHandle = new V2rayUpdateHandle();
|
||||
v2rayUpdateHandle.AbsoluteCompleted += (sender2, args) =>
|
||||
downloadHandle = new DownloadHandle();
|
||||
downloadHandle.AbsoluteCompleted += (sender2, args) =>
|
||||
{
|
||||
if (args.Success)
|
||||
{
|
||||
@@ -1299,7 +1299,7 @@ namespace v2rayN.Forms
|
||||
}
|
||||
else
|
||||
{
|
||||
v2rayUpdateHandle.DownloadFileAsync(config, url);
|
||||
downloadHandle.DownloadFileAsync(config, url, null);
|
||||
}
|
||||
}));
|
||||
}
|
||||
@@ -1308,7 +1308,7 @@ namespace v2rayN.Forms
|
||||
AppendText(false, args.Msg);
|
||||
}
|
||||
};
|
||||
v2rayUpdateHandle.UpdateCompleted += (sender2, args) =>
|
||||
downloadHandle.UpdateCompleted += (sender2, args) =>
|
||||
{
|
||||
if (args.Success)
|
||||
{
|
||||
@@ -1319,7 +1319,7 @@ namespace v2rayN.Forms
|
||||
{
|
||||
CloseV2ray();
|
||||
|
||||
string fileName = v2rayUpdateHandle.DownloadFileName;
|
||||
string fileName = downloadHandle.DownloadFileName;
|
||||
fileName = Utils.GetPath(fileName);
|
||||
using (ZipArchive archive = ZipFile.OpenRead(fileName))
|
||||
{
|
||||
@@ -1347,14 +1347,14 @@ namespace v2rayN.Forms
|
||||
AppendText(false, args.Msg);
|
||||
}
|
||||
};
|
||||
v2rayUpdateHandle.Error += (sender2, args) =>
|
||||
downloadHandle.Error += (sender2, args) =>
|
||||
{
|
||||
AppendText(true, args.GetException().Message);
|
||||
};
|
||||
}
|
||||
|
||||
AppendText(false, UIRes.I18N("MsgStartUpdatingV2rayCore"));
|
||||
v2rayUpdateHandle.AbsoluteV2rayCore(config);
|
||||
downloadHandle.AbsoluteV2rayCore(config);
|
||||
}
|
||||
|
||||
private void tsbCheckUpdatePACList_Click(object sender, EventArgs e)
|
||||
@@ -1474,8 +1474,8 @@ namespace v2rayN.Forms
|
||||
continue;
|
||||
}
|
||||
|
||||
V2rayUpdateHandle v2rayUpdateHandle3 = new V2rayUpdateHandle();
|
||||
v2rayUpdateHandle3.UpdateCompleted += (sender2, args) =>
|
||||
DownloadHandle downloadHandle3 = new DownloadHandle();
|
||||
downloadHandle3.UpdateCompleted += (sender2, args) =>
|
||||
{
|
||||
if (args.Success)
|
||||
{
|
||||
@@ -1504,12 +1504,12 @@ namespace v2rayN.Forms
|
||||
AppendText(false, args.Msg);
|
||||
}
|
||||
};
|
||||
v2rayUpdateHandle3.Error += (sender2, args) =>
|
||||
downloadHandle3.Error += (sender2, args) =>
|
||||
{
|
||||
AppendText(true, args.GetException().Message);
|
||||
};
|
||||
|
||||
v2rayUpdateHandle3.WebDownloadString(url);
|
||||
downloadHandle3.WebDownloadString(url);
|
||||
AppendText(false, $"{hashCode}{UIRes.I18N("MsgStartGettingSubscriptions")}");
|
||||
}
|
||||
|
||||
@@ -1537,6 +1537,6 @@ namespace v2rayN.Forms
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Windows.Forms;
|
||||
using v2rayN.Handler;
|
||||
using v2rayN.Base;
|
||||
|
||||
namespace v2rayN.Forms
|
||||
{
|
||||
@@ -44,7 +45,7 @@ namespace v2rayN.Forms
|
||||
chksniffingEnabled.Checked = config.inbound[0].sniffingEnabled;
|
||||
|
||||
txtlocalPort2.Text = "socks + 1";
|
||||
cmbprotocol2.Text = "http";
|
||||
cmbprotocol2.Text = Global.InboundHttp;
|
||||
|
||||
if (config.inbound.Count > 1)
|
||||
{
|
||||
@@ -381,8 +382,8 @@ namespace v2rayN.Forms
|
||||
for (int k = 0; k < lstUrl.Count; k++)
|
||||
{
|
||||
var txt = lstTxt[k];
|
||||
V2rayUpdateHandle v2rayUpdateHandle3 = new V2rayUpdateHandle();
|
||||
v2rayUpdateHandle3.UpdateCompleted += (sender2, args) =>
|
||||
DownloadHandle downloadHandle = new DownloadHandle();
|
||||
downloadHandle.UpdateCompleted += (sender2, args) =>
|
||||
{
|
||||
if (args.Success)
|
||||
{
|
||||
@@ -398,12 +399,12 @@ namespace v2rayN.Forms
|
||||
AppendText(false, args.Msg);
|
||||
}
|
||||
};
|
||||
v2rayUpdateHandle3.Error += (sender2, args) =>
|
||||
downloadHandle.Error += (sender2, args) =>
|
||||
{
|
||||
AppendText(true, args.GetException().Message);
|
||||
};
|
||||
|
||||
v2rayUpdateHandle3.WebDownloadString(lstUrl[k]);
|
||||
downloadHandle.WebDownloadString(lstUrl[k]);
|
||||
}
|
||||
}
|
||||
void AppendText(bool notify, string text)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Windows.Forms;
|
||||
using v2rayN.Base;
|
||||
using v2rayN.Mode;
|
||||
|
||||
namespace v2rayN.Forms
|
||||
|
||||
@@ -102,6 +102,13 @@ namespace v2rayN
|
||||
/// </summary>
|
||||
public const string StreamSecurity = "tls";
|
||||
|
||||
public const string InboundSocks = "socks";
|
||||
public const string InboundHttp = "http";
|
||||
public const string Loopback = "127.0.0.1";
|
||||
public const string InboundAPITagName = "api";
|
||||
public const string InboundAPIProtocal = "dokodemo-door";
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// vmess
|
||||
/// </summary>
|
||||
@@ -147,12 +154,6 @@ namespace v2rayN
|
||||
/// </summary>
|
||||
public const string CustomIconName = "v2rayN.ico";
|
||||
|
||||
|
||||
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
|
||||
{
|
||||
quick = 1000,
|
||||
@@ -177,17 +178,17 @@ namespace v2rayN
|
||||
public static bool sysAgent { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// socks端口号
|
||||
/// socks端口
|
||||
/// </summary>
|
||||
public static int socksPort { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 全局代理端口(http)
|
||||
/// http端口
|
||||
/// </summary>
|
||||
public static int sysAgentPort { get; set; }
|
||||
public static int httpPort { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// PAC监听端口号
|
||||
/// PAC端口
|
||||
/// </summary>
|
||||
public static int pacPort { get; set; }
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using v2rayN.Mode;
|
||||
using v2rayN.Base;
|
||||
|
||||
namespace v2rayN.Handler
|
||||
{
|
||||
@@ -56,7 +57,7 @@ namespace v2rayN.Handler
|
||||
{
|
||||
config.inbound = new List<InItem>();
|
||||
InItem inItem = new InItem();
|
||||
inItem.protocol = "socks";
|
||||
inItem.protocol = Global.InboundSocks;
|
||||
inItem.localPort = 10808;
|
||||
inItem.udpEnabled = true;
|
||||
inItem.sniffingEnabled = true;
|
||||
@@ -75,7 +76,7 @@ namespace v2rayN.Handler
|
||||
//http协议不由core提供,只保留socks
|
||||
if (config.inbound.Count > 0)
|
||||
{
|
||||
config.inbound[0].protocol = "socks";
|
||||
config.inbound[0].protocol = Global.InboundSocks;
|
||||
}
|
||||
}
|
||||
//路由规则
|
||||
|
||||
@@ -1,20 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json;
|
||||
using v2rayN.Base;
|
||||
using v2rayN.Mode;
|
||||
using v2rayN.Properties;
|
||||
using v2rayN.HttpProxyHandler;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace v2rayN.Handler
|
||||
{
|
||||
/// <summary>
|
||||
///Update V2ray Core
|
||||
///Download
|
||||
/// </summary>
|
||||
class V2rayUpdateHandle
|
||||
class DownloadHandle
|
||||
{
|
||||
public event EventHandler<ResultEventArgs> AbsoluteCompleted;
|
||||
|
||||
@@ -92,7 +87,7 @@ namespace v2rayN.Handler
|
||||
}
|
||||
|
||||
|
||||
public void DownloadFileAsync(Config config, string url)
|
||||
public void DownloadFileAsync(Config config, string url, WebProxy webProxy)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -100,12 +95,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 (webProxy != null)
|
||||
{
|
||||
ws.Proxy = webProxy;// new WebProxy(Global.Loopback, Global.httpPort);
|
||||
}
|
||||
|
||||
ws.DownloadFileCompleted += ws_DownloadFileCompleted;
|
||||
ws.DownloadProgressChanged += ws_DownloadProgressChanged;
|
||||
ws.DownloadFileAsync(new Uri(url), Utils.GetPath(DownloadFileName));
|
||||
@@ -216,6 +216,6 @@ namespace v2rayN.Handler
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ namespace v2rayN.Handler
|
||||
{
|
||||
class SpeedtestHandler
|
||||
{
|
||||
private V2rayUpdateHandle v2rayUpdateHandle2;
|
||||
private DownloadHandle downloadHandle2;
|
||||
private Config _config;
|
||||
private V2rayHandler _v2rayHandler;
|
||||
private List<int> _selecteds;
|
||||
@@ -88,7 +88,7 @@ namespace v2rayN.Handler
|
||||
}
|
||||
}
|
||||
|
||||
Thread.Sleep(1);
|
||||
Thread.Sleep(100);
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -119,7 +119,7 @@ namespace v2rayN.Handler
|
||||
}
|
||||
}
|
||||
|
||||
Thread.Sleep(1);
|
||||
Thread.Sleep(100);
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -132,6 +132,12 @@ namespace v2rayN.Handler
|
||||
{
|
||||
try
|
||||
{
|
||||
string msg = string.Empty;
|
||||
|
||||
Global.reloadV2ray = true;
|
||||
_v2rayHandler.LoadV2ray(_config, _selecteds);
|
||||
|
||||
var httpPort = _config.GetLocalPort("speedtest");
|
||||
for (int k = 0; k < _selecteds.Count; k++)
|
||||
{
|
||||
int index = _selecteds[k];
|
||||
@@ -139,20 +145,12 @@ namespace v2rayN.Handler
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (ConfigHandler.SetDefaultServer(ref _config, index) == 0)
|
||||
{
|
||||
_v2rayHandler.LoadV2ray(_config);
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
Thread.Sleep(1000 * 5);
|
||||
|
||||
var webProxy = new WebProxy(Global.Loopback, httpPort + index);
|
||||
int responseTime = -1;
|
||||
var status = GetRealPingTime(Global.SpeedPingTestUrl, out responseTime);
|
||||
var status = GetRealPingTime(Global.SpeedPingTestUrl, webProxy, out responseTime);
|
||||
if (!Utils.IsNullOrEmpty(status))
|
||||
{
|
||||
_updateFunc(index, string.Format("{0}", status));
|
||||
@@ -166,9 +164,12 @@ namespace v2rayN.Handler
|
||||
{
|
||||
Utils.SaveLog(ex.Message, ex);
|
||||
}
|
||||
Thread.Sleep(100);
|
||||
}
|
||||
|
||||
Thread.Sleep(1);
|
||||
Global.reloadV2ray = true;
|
||||
_v2rayHandler.LoadV2ray(_config);
|
||||
Thread.Sleep(100);
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -184,12 +185,15 @@ namespace v2rayN.Handler
|
||||
return;
|
||||
}
|
||||
|
||||
Global.reloadV2ray = true;
|
||||
_v2rayHandler.LoadV2ray(_config, _selecteds);
|
||||
|
||||
string url = Global.SpeedTestUrl;
|
||||
testCounter = 0;
|
||||
if (v2rayUpdateHandle2 == null)
|
||||
if (downloadHandle2 == null)
|
||||
{
|
||||
v2rayUpdateHandle2 = new V2rayUpdateHandle();
|
||||
v2rayUpdateHandle2.UpdateCompleted += (sender2, args) =>
|
||||
downloadHandle2 = new DownloadHandle();
|
||||
downloadHandle2.UpdateCompleted += (sender2, args) =>
|
||||
{
|
||||
if (args.Success)
|
||||
{
|
||||
@@ -204,7 +208,7 @@ namespace v2rayN.Handler
|
||||
_updateFunc(ItemIndex, args.Msg);
|
||||
}
|
||||
};
|
||||
v2rayUpdateHandle2.Error += (sender2, args) =>
|
||||
downloadHandle2.Error += (sender2, args) =>
|
||||
{
|
||||
_updateFunc(ItemIndex, args.GetException().Message);
|
||||
if (ServerSpeedTestSub(testCounter, url) != 0)
|
||||
@@ -213,6 +217,7 @@ namespace v2rayN.Handler
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if (ServerSpeedTestSub(testCounter, url) != 0)
|
||||
{
|
||||
return;
|
||||
@@ -223,23 +228,19 @@ namespace v2rayN.Handler
|
||||
{
|
||||
if (index >= _selecteds.Count)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (ConfigHandler.SetDefaultServer(ref _config, _selecteds[index]) == 0)
|
||||
{
|
||||
Global.reloadV2ray = true;
|
||||
_v2rayHandler.LoadV2ray(_config);
|
||||
|
||||
testCounter++;
|
||||
|
||||
v2rayUpdateHandle2.DownloadFileAsync(_config, url);
|
||||
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
var httpPort = _config.GetLocalPort("speedtest");
|
||||
index = _selecteds[index];
|
||||
|
||||
testCounter++;
|
||||
var webProxy = new WebProxy(Global.Loopback, httpPort + index);
|
||||
downloadHandle2.DownloadFileAsync(_config, url, webProxy);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private int GetTcpingTime(string url, int port)
|
||||
@@ -267,7 +268,7 @@ namespace v2rayN.Handler
|
||||
return responseTime;
|
||||
}
|
||||
|
||||
private string GetRealPingTime(string url, out int responseTime)
|
||||
private string GetRealPingTime(string url, WebProxy webProxy, out int responseTime)
|
||||
{
|
||||
string msg = string.Empty;
|
||||
responseTime = -1;
|
||||
@@ -276,6 +277,7 @@ namespace v2rayN.Handler
|
||||
{
|
||||
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url);
|
||||
myHttpWebRequest.Timeout = 5000;
|
||||
myHttpWebRequest.Proxy = webProxy;//new WebProxy(Global.Loopback, Global.httpPort);
|
||||
|
||||
var timer = new Stopwatch();
|
||||
timer.Start();
|
||||
|
||||
@@ -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_);
|
||||
}
|
||||
@@ -192,7 +192,7 @@ namespace v2rayN.Handler
|
||||
name = nStr[1];
|
||||
type = nStr[3];
|
||||
|
||||
if (name == Global.InboundProxyTagName)
|
||||
if (name == Global.agentTag)
|
||||
{
|
||||
if (type == "uplink")
|
||||
{
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using v2rayN.Mode;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using v2rayN.Base;
|
||||
using v2rayN.Mode;
|
||||
|
||||
namespace v2rayN.Handler
|
||||
{
|
||||
@@ -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;
|
||||
@@ -1365,5 +1365,90 @@ namespace v2rayN.Handler
|
||||
|
||||
#endregion
|
||||
|
||||
#region Gen speedtest config
|
||||
|
||||
|
||||
public static int GenerateClientSpeedtestConfig(Config config, List<int> selecteds, string fileName, out string msg)
|
||||
{
|
||||
msg = string.Empty;
|
||||
|
||||
try
|
||||
{
|
||||
if (config == null
|
||||
|| config.index < 0
|
||||
|| config.vmess.Count <= 0
|
||||
|| config.index > config.vmess.Count - 1
|
||||
)
|
||||
{
|
||||
msg = UIRes.I18N("CheckServerSettings");
|
||||
return -1;
|
||||
}
|
||||
|
||||
msg = UIRes.I18N("InitialConfiguration");
|
||||
|
||||
string result = Utils.GetEmbedText(SampleClient);
|
||||
if (Utils.IsNullOrEmpty(result))
|
||||
{
|
||||
msg = UIRes.I18N("FailedGetDefaultConfiguration");
|
||||
return -1;
|
||||
}
|
||||
|
||||
V2rayConfig v2rayConfig = Utils.FromJson<V2rayConfig>(result);
|
||||
if (v2rayConfig == null)
|
||||
{
|
||||
msg = UIRes.I18N("FailedGenDefaultConfiguration");
|
||||
return -1;
|
||||
}
|
||||
|
||||
log(config, ref v2rayConfig, false);
|
||||
//routing(config, ref v2rayConfig);
|
||||
dns(config, ref v2rayConfig);
|
||||
|
||||
|
||||
var httpPort = config.GetLocalPort("speedtest");
|
||||
for (int k = 0; k < selecteds.Count; k++)
|
||||
{
|
||||
int index = selecteds[k];
|
||||
if (config.vmess[index].configType == (int)EConfigType.Custom)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
config.index = index;
|
||||
|
||||
var inbound = new Inbounds();
|
||||
inbound.listen = Global.Loopback;
|
||||
inbound.port = httpPort + index;
|
||||
inbound.protocol = Global.InboundHttp;
|
||||
inbound.tag = Global.InboundHttp + inbound.port.ToString();
|
||||
v2rayConfig.inbounds.Add(inbound);
|
||||
|
||||
|
||||
var v2rayConfigCopy = Utils.FromJson<V2rayConfig>(result);
|
||||
outbound(config, ref v2rayConfigCopy);
|
||||
v2rayConfigCopy.outbounds[0].tag = Global.agentTag + inbound.port.ToString();
|
||||
v2rayConfig.outbounds.Add(v2rayConfigCopy.outbounds[0]);
|
||||
|
||||
var rule = new Mode.RulesItem();
|
||||
rule.inboundTag = inbound.tag;
|
||||
rule.outboundTag = v2rayConfigCopy.outbounds[0].tag;
|
||||
rule.type = "field";
|
||||
v2rayConfig.routing.rules.Add(rule);
|
||||
}
|
||||
|
||||
Utils.ToJsonFile(v2rayConfig, fileName);
|
||||
|
||||
msg = string.Format(UIRes.I18N("SuccessfulConfiguration"), config.getSummary());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
msg = UIRes.I18N("FailedGenDefaultConfiguration");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,6 +52,27 @@ namespace v2rayN.Handler
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 载入V2ray
|
||||
/// </summary>
|
||||
public void LoadV2ray(Config config, List<int> _selecteds)
|
||||
{
|
||||
if (Global.reloadV2ray)
|
||||
{
|
||||
string msg = string.Empty;
|
||||
string fileName = Utils.GetPath(v2rayConfigRes);
|
||||
if (V2rayConfigHandler.GenerateClientSpeedtestConfig(config, _selecteds, fileName, out msg) != 0)
|
||||
{
|
||||
ShowMsg(false, msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
ShowMsg(true, msg);
|
||||
V2rayRestart();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// V2ray重启
|
||||
/// </summary>
|
||||
@@ -118,7 +139,7 @@ namespace v2rayN.Handler
|
||||
}
|
||||
}
|
||||
if (Utils.IsNullOrEmpty(fileName))
|
||||
{
|
||||
{
|
||||
string msg = string.Format(UIRes.I18N("NotFoundCore"), @"https://github.com/v2ray/v2ray-core/releases");
|
||||
ShowMsg(true, msg);
|
||||
return;
|
||||
|
||||
@@ -10,21 +10,6 @@ namespace v2rayN.HttpProxyHandler
|
||||
/// </summary>
|
||||
class HttpProxyHandle
|
||||
{
|
||||
private static string GetTimestamp(DateTime value)
|
||||
{
|
||||
return value.ToString("MMddHHmmssfff");
|
||||
}
|
||||
|
||||
public static void ReSetPACProxy(Config config)
|
||||
{
|
||||
if (config.listenerType == 2)
|
||||
{
|
||||
//SysProxyHandle.SetIEProxy(false, false, null, null);
|
||||
//PACServerHandle.Stop();
|
||||
}
|
||||
Update(config, false);
|
||||
}
|
||||
|
||||
public static bool Update(Config config, bool forceDisable)
|
||||
{
|
||||
int type = config.listenerType;
|
||||
@@ -38,7 +23,7 @@ namespace v2rayN.HttpProxyHandler
|
||||
{
|
||||
if (type != 0)
|
||||
{
|
||||
var port = Global.sysAgentPort;
|
||||
var port = Global.httpPort;
|
||||
if (port <= 0)
|
||||
{
|
||||
return false;
|
||||
@@ -46,8 +31,7 @@ namespace v2rayN.HttpProxyHandler
|
||||
if (type == 1)
|
||||
{
|
||||
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)
|
||||
{
|
||||
@@ -55,12 +39,10 @@ namespace v2rayN.HttpProxyHandler
|
||||
SysProxyHandle.SetIEProxy(true, false, null, pacUrl);
|
||||
PACServerHandle.Stop();
|
||||
PACServerHandle.Init(config);
|
||||
PACFileWatcherHandle.StartWatch(config);
|
||||
}
|
||||
else if (type == 3)
|
||||
{
|
||||
PACServerHandle.Stop();
|
||||
PACFileWatcherHandle.StopWatch();
|
||||
SysProxyHandle.SetIEProxy(false, false, null, null);
|
||||
}
|
||||
else if (type == 4)
|
||||
@@ -69,14 +51,12 @@ namespace v2rayN.HttpProxyHandler
|
||||
SysProxyHandle.SetIEProxy(false, false, null, null);
|
||||
PACServerHandle.Stop();
|
||||
PACServerHandle.Init(config);
|
||||
PACFileWatcherHandle.StartWatch(config);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SysProxyHandle.SetIEProxy(false, false, null, null);
|
||||
PACServerHandle.Stop();
|
||||
PACFileWatcherHandle.StopWatch();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -94,7 +74,7 @@ namespace v2rayN.HttpProxyHandler
|
||||
{
|
||||
try
|
||||
{
|
||||
int localPort = config.GetLocalPort("socks");
|
||||
int localPort = config.GetLocalPort(Global.InboundSocks);
|
||||
if (localPort > 0)
|
||||
{
|
||||
PrivoxyHandler.Instance.Start(localPort, config);
|
||||
@@ -102,8 +82,8 @@ namespace v2rayN.HttpProxyHandler
|
||||
{
|
||||
Global.sysAgent = true;
|
||||
Global.socksPort = localPort;
|
||||
Global.sysAgentPort = PrivoxyHandler.Instance.RunningPort;
|
||||
Global.pacPort = Global.sysAgentPort + 1;
|
||||
Global.httpPort = PrivoxyHandler.Instance.RunningPort;
|
||||
Global.pacPort = config.GetLocalPort("pac");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -120,16 +100,12 @@ namespace v2rayN.HttpProxyHandler
|
||||
{
|
||||
try
|
||||
{
|
||||
////开启全局代理则关闭
|
||||
//if (Global.sysAgent)
|
||||
//{
|
||||
PrivoxyHandler.Instance.Stop();
|
||||
|
||||
Global.sysAgent = false;
|
||||
Global.socksPort = 0;
|
||||
Global.sysAgentPort = 0;
|
||||
Global.httpPort = 0;
|
||||
Global.pacPort = 0;
|
||||
//}
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -151,7 +127,7 @@ namespace v2rayN.HttpProxyHandler
|
||||
}
|
||||
else
|
||||
{
|
||||
int localPort = config.GetLocalPort("socks");
|
||||
int localPort = config.GetLocalPort(Global.InboundSocks);
|
||||
if (localPort != Global.socksPort)
|
||||
{
|
||||
isRestart = true;
|
||||
@@ -168,9 +144,7 @@ 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={ DateTime.Now.ToString("HHmmss")}";
|
||||
return pacUrl;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
using System.IO;
|
||||
using System.Windows.Forms;
|
||||
using v2rayN.Mode;
|
||||
|
||||
namespace v2rayN.HttpProxyHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// 提供PAC功能支持
|
||||
/// </summary>
|
||||
class PACFileWatcherHandle
|
||||
{
|
||||
private static FileSystemWatcher fileSystemWatcher;
|
||||
|
||||
private static long fileSize;
|
||||
|
||||
public static void StartWatch(Config config)
|
||||
{
|
||||
if (fileSystemWatcher == null)
|
||||
{
|
||||
fileSystemWatcher = new FileSystemWatcher(Utils.StartupPath());
|
||||
fileSystemWatcher.Filter = "pac.txt";
|
||||
fileSystemWatcher.NotifyFilter = NotifyFilters.Size;
|
||||
fileSystemWatcher.Changed += (sender, args) =>
|
||||
{
|
||||
var fileInfo = new FileInfo(args.FullPath);
|
||||
if (fileSize != fileInfo.Length)
|
||||
{
|
||||
fileSize = fileInfo.Length;
|
||||
HttpProxyHandle.ReSetPACProxy(config);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
fileSystemWatcher.EnableRaisingEvents = true;
|
||||
}
|
||||
|
||||
public static void StopWatch()
|
||||
{
|
||||
if (fileSystemWatcher != null)
|
||||
{
|
||||
fileSystemWatcher.EnableRaisingEvents = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ using System.IO;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json;
|
||||
using v2rayN.Base;
|
||||
using v2rayN.Mode;
|
||||
using v2rayN.Properties;
|
||||
|
||||
@@ -46,7 +47,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;
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.Text;
|
||||
using v2rayN.Mode;
|
||||
using v2rayN.Properties;
|
||||
using v2rayN.Tool;
|
||||
using v2rayN.Base;
|
||||
|
||||
namespace v2rayN.HttpProxyHandler
|
||||
{
|
||||
@@ -31,11 +32,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;
|
||||
}
|
||||
@@ -66,7 +67,6 @@ namespace v2rayN.HttpProxyHandler
|
||||
server = new HttpWebServer(SendResponse, prefixes);
|
||||
server.Run();
|
||||
|
||||
//pacPort = Global.pacPort;
|
||||
}
|
||||
}
|
||||
Utils.SaveLog("Webserver at " + address);
|
||||
@@ -94,7 +94,6 @@ namespace v2rayN.HttpProxyHandler
|
||||
if (serverB == null)
|
||||
{
|
||||
serverB = new HttpWebServerB(Global.pacPort, SendResponse);
|
||||
//pacPort = Global.pacPort;
|
||||
}
|
||||
}
|
||||
Utils.SaveLog("WebserverB at " + address);
|
||||
@@ -158,7 +157,7 @@ namespace v2rayN.HttpProxyHandler
|
||||
|
||||
private static string GetPacList(string address)
|
||||
{
|
||||
var port = Global.sysAgentPort;
|
||||
var port = Global.httpPort;
|
||||
if (port <= 0)
|
||||
{
|
||||
return "No port";
|
||||
|
||||
@@ -24,8 +24,6 @@ namespace v2rayN.HttpProxyHandler
|
||||
private static string _uniqueConfigFile;
|
||||
private static Job _privoxyJob;
|
||||
private Process _process;
|
||||
private int _runningPort;
|
||||
private bool _isRunning;
|
||||
|
||||
static PrivoxyHandler()
|
||||
{
|
||||
@@ -66,18 +64,7 @@ namespace v2rayN.HttpProxyHandler
|
||||
|
||||
public int RunningPort
|
||||
{
|
||||
get
|
||||
{
|
||||
return _runningPort;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsRunning
|
||||
{
|
||||
get
|
||||
{
|
||||
return _isRunning;
|
||||
}
|
||||
get; set;
|
||||
}
|
||||
|
||||
public void Start(int localPort, Config config)
|
||||
@@ -90,16 +77,16 @@ namespace v2rayN.HttpProxyHandler
|
||||
KillProcess(p);
|
||||
}
|
||||
string privoxyConfig = Resources.privoxy_conf;
|
||||
_runningPort = GetFreePort(localPort);
|
||||
RunningPort = config.GetLocalPort(Global.InboundHttp);
|
||||
privoxyConfig = privoxyConfig.Replace("__SOCKS_PORT__", localPort.ToString());
|
||||
privoxyConfig = privoxyConfig.Replace("__PRIVOXY_BIND_PORT__", _runningPort.ToString());
|
||||
privoxyConfig = privoxyConfig.Replace("__PRIVOXY_BIND_PORT__", RunningPort.ToString());
|
||||
if (config.allowLANConn)
|
||||
{
|
||||
privoxyConfig = privoxyConfig.Replace("__PRIVOXY_BIND_IP__", "0.0.0.0");
|
||||
}
|
||||
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));
|
||||
|
||||
@@ -123,7 +110,7 @@ namespace v2rayN.HttpProxyHandler
|
||||
* when ss exit unexpectedly, this process will be forced killed by system.
|
||||
*/
|
||||
_privoxyJob.AddProcess(_process.Handle);
|
||||
_isRunning = true;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,7 +121,7 @@ namespace v2rayN.HttpProxyHandler
|
||||
KillProcess(_process);
|
||||
_process.Dispose();
|
||||
_process = null;
|
||||
_isRunning = false;
|
||||
RunningPort = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -191,25 +178,5 @@ namespace v2rayN.HttpProxyHandler
|
||||
}
|
||||
}
|
||||
|
||||
private int GetFreePort(int localPort)
|
||||
{
|
||||
int defaultPort = 8123;
|
||||
try
|
||||
{
|
||||
//// TCP stack please do me a favor
|
||||
//TcpListener l = new TcpListener(IPAddress.Loopback, 0);
|
||||
//l.Start();
|
||||
//var port = ((IPEndPoint)l.LocalEndpoint).Port;
|
||||
//l.Stop();
|
||||
//return port;
|
||||
return localPort + 1;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// in case access denied
|
||||
Utils.SaveLog(ex.Message, ex);
|
||||
return defaultPort;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json;
|
||||
using v2rayN.Base;
|
||||
using v2rayN.Mode;
|
||||
using v2rayN.Properties;
|
||||
using v2rayN.Tool;
|
||||
@@ -49,14 +50,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 +72,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);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
using System;
|
||||
using System.Net;
|
||||
|
||||
namespace v2rayN.HttpProxyHandler
|
||||
{
|
||||
class WebClientEx : WebClient
|
||||
{
|
||||
public int Timeout { get; set; }
|
||||
public WebClientEx(int timeout = 3000)
|
||||
{
|
||||
Timeout = timeout;
|
||||
}
|
||||
|
||||
|
||||
protected override WebRequest GetWebRequest(Uri address)
|
||||
{
|
||||
var request = base.GetWebRequest(address);
|
||||
request.Timeout = Timeout;
|
||||
return request;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
using v2rayN.Base;
|
||||
|
||||
namespace v2rayN.Mode
|
||||
{
|
||||
@@ -13,93 +13,147 @@ namespace v2rayN.Mode
|
||||
/// <summary>
|
||||
/// 本地监听
|
||||
/// </summary>
|
||||
public List<InItem> inbound { get; set; }
|
||||
public List<InItem> inbound
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 允许日志
|
||||
/// </summary>
|
||||
public bool logEnabled { get; set; }
|
||||
public bool logEnabled
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 日志等级
|
||||
/// </summary>
|
||||
public string loglevel { get; set; }
|
||||
public string loglevel
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 活动配置序号
|
||||
/// </summary>
|
||||
public int index { get; set; }
|
||||
public int index
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// vmess服务器信息
|
||||
/// </summary>
|
||||
public List<VmessItem> vmess { get; set; }
|
||||
public List<VmessItem> vmess
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 允许Mux多路复用
|
||||
/// </summary>
|
||||
public bool muxEnabled { get; set; }
|
||||
public bool muxEnabled
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 域名解析策略
|
||||
/// </summary>
|
||||
public string domainStrategy { get; set; }
|
||||
public string domainStrategy
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 路由模式
|
||||
/// </summary>
|
||||
public string routingMode { get; set; }
|
||||
public string routingMode
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 用户自定义需代理的网址或ip
|
||||
/// </summary>
|
||||
public List<string> useragent { get; set; }
|
||||
public List<string> useragent
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 用户自定义直连的网址或ip
|
||||
/// </summary>
|
||||
public List<string> userdirect { get; set; }
|
||||
public List<string> userdirect
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 用户自定义阻止的网址或ip
|
||||
/// </summary>
|
||||
public List<string> userblock { get; set; }
|
||||
public List<string> userblock
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// KcpItem
|
||||
/// </summary>
|
||||
public KcpItem kcpItem { get; set; }
|
||||
public KcpItem kcpItem
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 启用Http代理
|
||||
/// </summary>
|
||||
public bool sysAgentEnabled { get; set; }
|
||||
public bool sysAgentEnabled
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 监听状态 0-不改变 1-全局 2-PAC
|
||||
/// </summary>
|
||||
public int listenerType { get; set; }
|
||||
public int listenerType
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 自定义GFWList url
|
||||
/// </summary>
|
||||
public string urlGFWList { get; set; }
|
||||
public string urlGFWList
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 允许来自局域网的连接
|
||||
/// </summary>
|
||||
public bool allowLANConn { get; set; }
|
||||
public bool allowLANConn
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 启用实时网速和流量统计
|
||||
/// </summary>
|
||||
public bool enableStatistics { get; set; }
|
||||
public bool enableStatistics
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 视图刷新率
|
||||
/// </summary>
|
||||
public int statisticsFreshRate { get; set; }
|
||||
public int statisticsFreshRate
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 统计数据缓存天数 [0, 30]
|
||||
@@ -107,9 +161,13 @@ namespace v2rayN.Mode
|
||||
/// * 无论如何不会关闭总流量的缓存
|
||||
/// </summary>
|
||||
private uint cacheDays;
|
||||
public uint CacheDays {
|
||||
get { return cacheDays; }
|
||||
set
|
||||
public uint CacheDays
|
||||
{
|
||||
get
|
||||
{
|
||||
return cacheDays;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value < 0) cacheDays = 0;
|
||||
else if (value > 30) cacheDays = 30;
|
||||
@@ -120,15 +178,24 @@ namespace v2rayN.Mode
|
||||
/// <summary>
|
||||
/// 自定义远程DNS
|
||||
/// </summary>
|
||||
public string remoteDNS { get; set; }
|
||||
public string remoteDNS
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
/// <summary>
|
||||
/// 订阅
|
||||
/// </summary>
|
||||
public List<SubItem> subItem { get; set; }
|
||||
public List<SubItem> subItem
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
/// <summary>
|
||||
/// UI
|
||||
/// </summary>
|
||||
public UIItem uiItem { get; set; }
|
||||
public UIItem uiItem
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
#region 函数
|
||||
|
||||
@@ -236,6 +303,19 @@ namespace v2rayN.Mode
|
||||
|
||||
public int GetLocalPort(string protocol)
|
||||
{
|
||||
if (protocol == Global.InboundHttp)
|
||||
{
|
||||
return GetLocalPort(Global.InboundSocks) + 1;
|
||||
}
|
||||
else if (protocol == "pac")
|
||||
{
|
||||
return GetLocalPort(Global.InboundSocks) + 2;
|
||||
}
|
||||
else if (protocol == "speedtest")
|
||||
{
|
||||
return GetLocalPort(Global.InboundSocks) + 103;
|
||||
}
|
||||
|
||||
int localPort = 0;
|
||||
foreach (InItem inItem in inbound)
|
||||
{
|
||||
@@ -352,77 +432,125 @@ namespace v2rayN.Mode
|
||||
/// <summary>
|
||||
/// 版本(现在=2)
|
||||
/// </summary>
|
||||
public int configVersion { get; set; }
|
||||
public int configVersion
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 远程服务器地址
|
||||
/// </summary>
|
||||
public string address { get; set; }
|
||||
public string address
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
/// <summary>
|
||||
/// 远程服务器端口
|
||||
/// </summary>
|
||||
public int port { get; set; }
|
||||
public int port
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
/// <summary>
|
||||
/// 远程服务器ID
|
||||
/// </summary>
|
||||
public string id { get; set; }
|
||||
public string id
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
/// <summary>
|
||||
/// 远程服务器额外ID
|
||||
/// </summary>
|
||||
public int alterId { get; set; }
|
||||
public int alterId
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
/// <summary>
|
||||
/// 本地安全策略
|
||||
/// </summary>
|
||||
public string security { get; set; }
|
||||
public string security
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
/// <summary>
|
||||
/// tcp,kcp,ws
|
||||
/// </summary>
|
||||
public string network { get; set; }
|
||||
public string network
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
/// <summary>
|
||||
/// 备注或别名
|
||||
/// </summary>
|
||||
public string remarks { get; set; }
|
||||
public string remarks
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 伪装类型
|
||||
/// </summary>
|
||||
public string headerType { get; set; }
|
||||
public string headerType
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 伪装的域名
|
||||
/// </summary>
|
||||
public string requestHost { get; set; }
|
||||
public string requestHost
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ws h2 path
|
||||
/// </summary>
|
||||
public string path { get; set; }
|
||||
public string path
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 底层传输安全
|
||||
/// </summary>
|
||||
public string streamSecurity { get; set; }
|
||||
public string streamSecurity
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否允许不安全连接(用于客户端)
|
||||
/// </summary>
|
||||
public string allowInsecure { get; set; }
|
||||
public string allowInsecure
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// config type(1=normal,2=custom)
|
||||
/// </summary>
|
||||
public int configType { get; set; }
|
||||
public int configType
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string testResult { get; set; }
|
||||
public string testResult
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SubItem id
|
||||
/// </summary>
|
||||
public string subid { get; set; }
|
||||
public string subid
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
@@ -431,17 +559,26 @@ namespace v2rayN.Mode
|
||||
/// <summary>
|
||||
/// 本地监听端口
|
||||
/// </summary>
|
||||
public int localPort { get; set; }
|
||||
public int localPort
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 协议,默认为socks
|
||||
/// </summary>
|
||||
public string protocol { get; set; }
|
||||
public string protocol
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 允许udp
|
||||
/// </summary>
|
||||
public bool udpEnabled { get; set; }
|
||||
public bool udpEnabled
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 开启流量探测
|
||||
@@ -455,31 +592,52 @@ namespace v2rayN.Mode
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public int mtu { get; set; }
|
||||
public int mtu
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public int tti { get; set; }
|
||||
public int tti
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public int uplinkCapacity { get; set; }
|
||||
public int uplinkCapacity
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public int downlinkCapacity { get; set; }
|
||||
public int downlinkCapacity
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool congestion { get; set; }
|
||||
public bool congestion
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public int readBufferSize { get; set; }
|
||||
public int readBufferSize
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public int writeBufferSize { get; set; }
|
||||
public int writeBufferSize
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -489,17 +647,26 @@ namespace v2rayN.Mode
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string id { get; set; }
|
||||
public string id
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 备注
|
||||
/// </summary>
|
||||
public string remarks { get; set; }
|
||||
public string remarks
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// url
|
||||
/// </summary>
|
||||
public string url { get; set; }
|
||||
public string url
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// enable
|
||||
|
||||
@@ -33,4 +33,4 @@ using System.Runtime.InteropServices;
|
||||
// 方法是按如下所示使用“*”:
|
||||
//[assembly: AssemblyVersion("1.0.*")]
|
||||
//[assembly: AssemblyVersion("1.0.0")]
|
||||
[assembly: AssemblyFileVersion("2.43")]
|
||||
[assembly: AssemblyFileVersion("2.46")]
|
||||
|
||||
@@ -18,6 +18,7 @@ using ZXing;
|
||||
using ZXing.Common;
|
||||
using ZXing.QrCode;
|
||||
using System.Security.Principal;
|
||||
using v2rayN.Base;
|
||||
|
||||
namespace v2rayN
|
||||
{
|
||||
|
||||
@@ -114,6 +114,7 @@
|
||||
<HintPath>LIB\System.Memory.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="System.Messaging" />
|
||||
<Reference Include="System.Net" />
|
||||
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
@@ -140,7 +141,7 @@
|
||||
<Compile Include="Forms\AddServer4Form.Designer.cs">
|
||||
<DependentUpon>AddServer4Form.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Forms\ListViewFlickerFree.cs">
|
||||
<Compile Include="Base\ListViewFlickerFree.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Forms\MainForm.cs">
|
||||
@@ -181,17 +182,16 @@
|
||||
</Compile>
|
||||
<Compile Include="Handler\SpeedtestHandler.cs" />
|
||||
<Compile Include="Handler\StatisticsHandler.cs" />
|
||||
<Compile Include="Handler\V2rayUpdateHandle.cs" />
|
||||
<Compile Include="HttpProxyHandler\HttpWebServer.cs" />
|
||||
<Compile Include="HttpProxyHandler\HttpWebServerB.cs" />
|
||||
<Compile Include="HttpProxyHandler\PACFileWatcherHandle.cs" />
|
||||
<Compile Include="Handler\DownloadHandle.cs" />
|
||||
<Compile Include="Base\HttpWebServer.cs" />
|
||||
<Compile Include="Base\HttpWebServerB.cs" />
|
||||
<Compile Include="HttpProxyHandler\PrivoxyHandler.cs" />
|
||||
<Compile Include="HttpProxyHandler\PACListHandle.cs" />
|
||||
<Compile Include="HttpProxyHandler\PACServerHandle.cs" />
|
||||
<Compile Include="HttpProxyHandler\ProxySetting.cs" />
|
||||
<Compile Include="HttpProxyHandler\SysProxyHandle.cs" />
|
||||
<Compile Include="HttpProxyHandler\HttpProxyHandle.cs" />
|
||||
<Compile Include="HttpProxyHandler\WebClientEx.cs">
|
||||
<Compile Include="Base\WebClientEx.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Mode\EMove.cs" />
|
||||
@@ -208,7 +208,7 @@
|
||||
<DesignTime>True</DesignTime>
|
||||
<DependentUpon>ResUI.resx</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="StringEx.cs">
|
||||
<Compile Include="Base\StringEx.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Forms\AddServerForm.cs">
|
||||
|
||||
Reference in New Issue
Block a user