mirror of
https://github.com/2dust/v2rayN.git
synced 2025-07-01 20:42:10 +00:00
Compare commits
No commits in common. "8dcf5c5b901b8e84a7817e316b8fab4770435108" and "438eaba4d592a1cc57a57e46f3cc91039c312f47" have entirely different histories.
8dcf5c5b90
...
438eaba4d5
6 changed files with 70 additions and 88 deletions
|
@ -80,6 +80,8 @@ namespace ServiceLib.Handler
|
||||||
Logging.SaveLog($"v2rayN start up | {Utils.GetRuntimeInfo()}");
|
Logging.SaveLog($"v2rayN start up | {Utils.GetRuntimeInfo()}");
|
||||||
Logging.LoggingEnabled(_config.GuiItem.EnableLog);
|
Logging.LoggingEnabled(_config.GuiItem.EnableLog);
|
||||||
|
|
||||||
|
ClearExpiredFiles();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,6 +92,16 @@ namespace ServiceLib.Handler
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ClearExpiredFiles()
|
||||||
|
{
|
||||||
|
Task.Run(() =>
|
||||||
|
{
|
||||||
|
FileManager.DeleteExpiredFiles(Utils.GetLogPath(), DateTime.Now.AddMonths(-1));
|
||||||
|
FileManager.DeleteExpiredFiles(Utils.GetTempPath(), DateTime.Now.AddMonths(-1));
|
||||||
|
FileManager.DeleteExpiredFiles(Utils.GetBinConfigPath(), DateTime.Now.AddHours(-1));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
#endregion Init
|
#endregion Init
|
||||||
|
|
||||||
#region Config
|
#region Config
|
||||||
|
|
|
@ -24,8 +24,6 @@ namespace ServiceLib.Handler.Fmt
|
||||||
item.Path = Utils.UrlDecode(query["obfs-password"] ?? "");
|
item.Path = Utils.UrlDecode(query["obfs-password"] ?? "");
|
||||||
item.AllowInsecure = (query["insecure"] ?? "") == "1" ? "true" : "false";
|
item.AllowInsecure = (query["insecure"] ?? "") == "1" ? "true" : "false";
|
||||||
|
|
||||||
item.Ports = Utils.UrlDecode(query["mport"] ?? "").Replace('-', ':');
|
|
||||||
|
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,10 +53,6 @@ namespace ServiceLib.Handler.Fmt
|
||||||
dicQuery.Add("obfs-password", Utils.UrlEncode(item.Path));
|
dicQuery.Add("obfs-password", Utils.UrlEncode(item.Path));
|
||||||
}
|
}
|
||||||
dicQuery.Add("insecure", item.AllowInsecure.ToLower() == "true" ? "1" : "0");
|
dicQuery.Add("insecure", item.AllowInsecure.ToLower() == "true" ? "1" : "0");
|
||||||
if (Utils.IsNotEmpty(item.Ports))
|
|
||||||
{
|
|
||||||
dicQuery.Add("mport", Utils.UrlEncode(item.Ports.Replace(':', '-')));
|
|
||||||
}
|
|
||||||
|
|
||||||
return ToUri(EConfigType.Hysteria2, item.Address, item.Port, item.Id, dicQuery, remark);
|
return ToUri(EConfigType.Hysteria2, item.Address, item.Port, item.Id, dicQuery, remark);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,14 @@ namespace ServiceLib.Handler
|
||||||
public async Task Init()
|
public async Task Init()
|
||||||
{
|
{
|
||||||
await InitData();
|
await InitData();
|
||||||
|
_ = Task.Run(async () =>
|
||||||
|
{
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
await Task.Delay(1000 * 600);
|
||||||
|
await SaveQueueIndexIds();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<ConcurrentBag<ProfileExItem>> GetProfileExs()
|
public async Task<ConcurrentBag<ProfileExItem>> GetProfileExs()
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
namespace ServiceLib.Handler
|
namespace ServiceLib.Handler
|
||||||
{
|
{
|
||||||
public class TaskHandler
|
public class TaskHandler
|
||||||
{
|
{
|
||||||
|
@ -7,92 +7,66 @@ namespace ServiceLib.Handler
|
||||||
|
|
||||||
public void RegUpdateTask(Config config, Action<bool, string> updateFunc)
|
public void RegUpdateTask(Config config, Action<bool, string> updateFunc)
|
||||||
{
|
{
|
||||||
Task.Run(() => ScheduledTasks(config, updateFunc));
|
Task.Run(() => UpdateTaskRunSubscription(config, updateFunc));
|
||||||
}
|
Task.Run(() => UpdateTaskRunGeo(config, updateFunc));
|
||||||
|
|
||||||
private async Task ScheduledTasks(Config config, Action<bool, string> updateFunc)
|
|
||||||
{
|
|
||||||
Logging.SaveLog("Setup Scheduled Tasks");
|
|
||||||
|
|
||||||
var numOfExecuted = 1;
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
//1 minute
|
|
||||||
await Task.Delay(1000 * 60);
|
|
||||||
|
|
||||||
//Execute once 1 minute
|
|
||||||
await UpdateTaskRunSubscription(config, updateFunc);
|
|
||||||
|
|
||||||
//Execute once 20 minute
|
|
||||||
if (numOfExecuted % 20 == 0)
|
|
||||||
{
|
|
||||||
Logging.SaveLog("Execute save config");
|
|
||||||
|
|
||||||
await ConfigHandler.SaveConfig(config);
|
|
||||||
await ProfileExHandler.Instance.SaveTo();
|
|
||||||
}
|
|
||||||
|
|
||||||
//Execute once 1 hour
|
|
||||||
if (numOfExecuted % 60 == 0)
|
|
||||||
{
|
|
||||||
Logging.SaveLog("Execute delete expired files");
|
|
||||||
|
|
||||||
FileManager.DeleteExpiredFiles(Utils.GetBinConfigPath(), DateTime.Now.AddHours(-1));
|
|
||||||
FileManager.DeleteExpiredFiles(Utils.GetLogPath(), DateTime.Now.AddMonths(-1));
|
|
||||||
FileManager.DeleteExpiredFiles(Utils.GetTempPath(), DateTime.Now.AddMonths(-1));
|
|
||||||
|
|
||||||
//Check once 1 hour
|
|
||||||
await UpdateTaskRunGeo(config, numOfExecuted / 60, updateFunc);
|
|
||||||
}
|
|
||||||
|
|
||||||
numOfExecuted++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task UpdateTaskRunSubscription(Config config, Action<bool, string> updateFunc)
|
private async Task UpdateTaskRunSubscription(Config config, Action<bool, string> updateFunc)
|
||||||
{
|
{
|
||||||
var updateTime = ((DateTimeOffset)DateTime.Now).ToUnixTimeSeconds();
|
await Task.Delay(60000);
|
||||||
var lstSubs = (await AppHandler.Instance.SubItems())?
|
Logging.SaveLog("UpdateTaskRunSubscription");
|
||||||
.Where(t => t.AutoUpdateInterval > 0)
|
|
||||||
.Where(t => updateTime - t.UpdateTime >= t.AutoUpdateInterval * 60)
|
|
||||||
.ToList();
|
|
||||||
|
|
||||||
if (lstSubs is not { Count: > 0 })
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Logging.SaveLog("Execute update subscription");
|
|
||||||
var updateHandle = new UpdateService();
|
var updateHandle = new UpdateService();
|
||||||
|
while (true)
|
||||||
foreach (var item in lstSubs)
|
|
||||||
{
|
{
|
||||||
await updateHandle.UpdateSubscriptionProcess(config, item.Id, true, (bool success, string msg) =>
|
var updateTime = ((DateTimeOffset)DateTime.Now).ToUnixTimeSeconds();
|
||||||
|
var lstSubs = (await AppHandler.Instance.SubItems())
|
||||||
|
.Where(t => t.AutoUpdateInterval > 0)
|
||||||
|
.Where(t => updateTime - t.UpdateTime >= t.AutoUpdateInterval * 60)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
foreach (var item in lstSubs)
|
||||||
{
|
{
|
||||||
updateFunc?.Invoke(success, msg);
|
await updateHandle.UpdateSubscriptionProcess(config, item.Id, true, (bool success, string msg) =>
|
||||||
if (success)
|
{
|
||||||
{
|
updateFunc?.Invoke(success, msg);
|
||||||
Logging.SaveLog("Update subscription end" + msg);
|
if (success)
|
||||||
}
|
Logging.SaveLog("subscription" + msg);
|
||||||
});
|
});
|
||||||
item.UpdateTime = updateTime;
|
item.UpdateTime = updateTime;
|
||||||
await ConfigHandler.AddSubItem(config, item);
|
await ConfigHandler.AddSubItem(config, item);
|
||||||
await Task.Delay(1000);
|
|
||||||
|
await Task.Delay(5000);
|
||||||
|
}
|
||||||
|
await Task.Delay(60000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task UpdateTaskRunGeo(Config config, int hours, Action<bool, string> updateFunc)
|
private async Task UpdateTaskRunGeo(Config config, Action<bool, string> updateFunc)
|
||||||
{
|
{
|
||||||
if (config.GuiItem.AutoUpdateInterval > 0 && hours > 0 && hours % config.GuiItem.AutoUpdateInterval == 0)
|
var autoUpdateGeoTime = DateTime.Now;
|
||||||
{
|
|
||||||
Logging.SaveLog("Execute update geo files");
|
|
||||||
|
|
||||||
var updateHandle = new UpdateService();
|
//await Task.Delay(1000 * 120);
|
||||||
await updateHandle.UpdateGeoFileAll(config, (bool success, string msg) =>
|
Logging.SaveLog("UpdateTaskRunGeo");
|
||||||
|
|
||||||
|
var updateHandle = new UpdateService();
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
await Task.Delay(1000 * 3600);
|
||||||
|
|
||||||
|
var dtNow = DateTime.Now;
|
||||||
|
if (config.GuiItem.AutoUpdateInterval > 0)
|
||||||
{
|
{
|
||||||
updateFunc?.Invoke(false, msg);
|
if ((dtNow - autoUpdateGeoTime).Hours % config.GuiItem.AutoUpdateInterval == 0)
|
||||||
});
|
{
|
||||||
|
await updateHandle.UpdateGeoFileAll(config, (bool success, string msg) =>
|
||||||
|
{
|
||||||
|
updateFunc?.Invoke(false, msg);
|
||||||
|
});
|
||||||
|
autoUpdateGeoTime = dtNow;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -733,15 +733,7 @@ namespace ServiceLib.Services.CoreConfig
|
||||||
if (node.Ports.IsNotEmpty())
|
if (node.Ports.IsNotEmpty())
|
||||||
{
|
{
|
||||||
outbound.server_port = null;
|
outbound.server_port = null;
|
||||||
outbound.server_ports = new List<string>();
|
outbound.server_ports = node.Ports.Split(",").ToList();
|
||||||
var ports = node.Ports.Split(',')
|
|
||||||
.Select(p => p.Trim())
|
|
||||||
.Where(p => !string.IsNullOrEmpty(p))
|
|
||||||
.ToList();
|
|
||||||
foreach (var it in ports)
|
|
||||||
{
|
|
||||||
outbound.server_ports.Add(it.Contains('-') ? it.Replace('-', ':') : it);
|
|
||||||
}
|
|
||||||
outbound.hop_interval = _config.HysteriaItem.HopInterval > 0 ? $"{_config.HysteriaItem.HopInterval}s" : null;
|
outbound.hop_interval = _config.HysteriaItem.HopInterval > 0 ? $"{_config.HysteriaItem.HopInterval}s" : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,8 @@ namespace ServiceLib.Services
|
||||||
await RunAsync(actionType, selecteds);
|
await RunAsync(actionType, selecteds);
|
||||||
await ProfileExHandler.Instance.SaveTo();
|
await ProfileExHandler.Instance.SaveTo();
|
||||||
UpdateFunc("", ResUI.SpeedtestingCompleted);
|
UpdateFunc("", ResUI.SpeedtestingCompleted);
|
||||||
|
|
||||||
|
FileManager.DeleteExpiredFiles(Utils.GetBinConfigPath(), DateTime.Now.AddHours(-1));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue