Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✔ Geosite group validation + PAC regeneration on version update #2988

Merged
merged 1 commit into from
Oct 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion shadowsocks-csharp/Controller/HotkeyReg.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ static class HotkeyReg
private static Logger logger = LogManager.GetCurrentClassLogger();
public static void RegAllHotkeys()
{
var hotkeyConfig = Configuration.Load().hotkey;
var hotkeyConfig = Program.MainController.GetCurrentConfiguration().hotkey;

if (hotkeyConfig == null || !hotkeyConfig.RegHotkeysAtStartup)
return;
Expand Down
7 changes: 7 additions & 0 deletions shadowsocks-csharp/Controller/Service/GeositeUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,13 @@ public static bool MergeAndWritePACFile(string group, bool blacklist)
return true;
}

/// <summary>
/// Checks if the specified group exists in GeoSite database.
/// </summary>
/// <param name="group">The group name to check for.</param>
/// <returns>True if the group exists. False if the group doesn't exist.</returns>
public static bool CheckGeositeGroup(string group) => Geosites.ContainsKey(group);

private static string MergePACFile(IList<DomainObject> domains, bool blacklist)
{
string abpContent;
Expand Down
3 changes: 1 addition & 2 deletions shadowsocks-csharp/Controller/Service/PACServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void UpdatePACURL(Configuration config)
_config = config;
string usedSecret = _config.secureLocalPac ? $"&secret={PacSecret}" : "";
string contentHash = GetHash(_pacDaemon.GetPACContent());
PacUrl = $"http://{config.localHost}:{config.localPort}/{RESOURCE_NAME}?hash={contentHash}{usedSecret}";
PacUrl = $"http://{config.LocalHost}:{config.localPort}/{RESOURCE_NAME}?hash={contentHash}{usedSecret}";
logger.Debug("Set PAC URL:" + PacUrl);
}

Expand Down Expand Up @@ -176,7 +176,6 @@ public void SendResponse(Socket socket, bool useSocks)
";
byte[] response = Encoding.UTF8.GetBytes(responseHead + pacContent);
socket.BeginSend(response, 0, response.Length, 0, new AsyncCallback(SendCallback), socket);
Utils.ReleaseMemory(true);
}
catch (Exception e)
{
Expand Down
2 changes: 1 addition & 1 deletion shadowsocks-csharp/Controller/Service/UpdateChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ private WebClient CreateWebClient()
{
WebClient http = new WebClient();
http.Headers.Add("User-Agent", UserAgent);
http.Proxy = new WebProxy(config.localHost, config.localPort);
http.Proxy = new WebProxy(config.LocalHost, config.localPort);
return http;
}

Expand Down
57 changes: 26 additions & 31 deletions shadowsocks-csharp/Controller/ShadowsocksController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public class ShadowsocksController
// manipulates UI
// interacts with low level logic
#region Members definition
private Thread _ramThread;
private Thread _trafficThread;

private Listener _listener;
Expand Down Expand Up @@ -93,10 +92,10 @@ public class TrafficPerSecond
public ShadowsocksController()
{
_config = Configuration.Load();
Configuration.Process(ref _config);
StatisticsConfiguration = StatisticsStrategyConfiguration.Load();
_strategyManager = new StrategyManager(this);
_pluginsByServer = new ConcurrentDictionary<Server, Sip003Plugin>();
StartReleasingMemory();
StartTrafficStatistics(61);

ProgramUpdated += (o, e) =>
Expand All @@ -107,23 +106,34 @@ public ShadowsocksController()

#region Basic

public void Start(bool regHotkeys = true)
public void Start(bool systemWakeUp = false)
{
if (_config.updated && regHotkeys)
if (_config.firstRunOnNewVersion && !systemWakeUp)
{
_config.updated = false;
ProgramUpdated.Invoke(this, new UpdatedEventArgs()
{
OldVersion = _config.version,
NewVersion = UpdateChecker.Version,
});
// delete pac.txt when regeneratePacOnUpdate is true
if (_config.regeneratePacOnUpdate)
try
{
File.Delete(PACDaemon.PAC_FILE);
logger.Info("Deleted pac.txt from previous version.");
}
catch (Exception e)
{
logger.LogUsefulException(e);
}
// finish up first run of new version
_config.firstRunOnNewVersion = false;
_config.version = UpdateChecker.Version;
Configuration.Save(_config);
}
Reload();
if (regHotkeys)
{
if (!systemWakeUp)
HotkeyReg.RegAllHotkeys();
}
}

public void Stop()
Expand Down Expand Up @@ -154,6 +164,7 @@ protected void Reload()
Encryption.RNG.Reload();
// some logic in configuration updated the config when saving, we need to read it again
_config = Configuration.Load();
Configuration.Process(ref _config);

NLogConfig.LoadConfiguration();

Expand Down Expand Up @@ -226,7 +237,6 @@ protected void Reload()

ConfigChanged?.Invoke(this, new EventArgs());
UpdateSystemProxy();
Utils.ReleaseMemory(true);
}

protected void SaveConfig(Configuration newConfig)
Expand Down Expand Up @@ -394,6 +404,13 @@ public void ToggleSecureLocalPac(bool enabled)
ConfigChanged?.Invoke(this, new EventArgs());
}

public void ToggleRegeneratePacOnUpdate(bool enabled)
{
_config.regeneratePacOnUpdate = enabled;
SaveConfig(_config);
ConfigChanged?.Invoke(this, new EventArgs());
}

#endregion

#region SIP002
Expand Down Expand Up @@ -622,28 +639,6 @@ public void ToggleShowPluginOutput(bool enabled)

#endregion

#region Memory Management

private void StartReleasingMemory()
{
_ramThread = new Thread(new ThreadStart(ReleaseMemory))
{
IsBackground = true
};
_ramThread.Start();
}

private void ReleaseMemory()
{
while (true)
{
Utils.ReleaseMemory(false);
Thread.Sleep(30 * 1000);
}
}

#endregion

#region Traffic Statistics

private void StartTrafficStatistics(int queueMaxSize)
Expand Down
1 change: 1 addition & 0 deletions shadowsocks-csharp/Data/i18n.csv
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Edit Local PAC File...,Редактировать локальный PAC…,编
Update Local PAC from Geosite,Обновить локальный PAC из Geosite,从 Geosite 更新本地 PAC,從 Geosite 更新本機 PAC,Geosite からローカル PAC を更新,Geosite에서 로컬 프록시 자동 구성 파일 업데이트,Mettre à jour le PAC local à partir de Geosite
Edit User Rule for Geosite...,Редактировать свои правила для Geosite,编辑 Geosite 的用户规则...,編輯 Geosite 的使用者規則...,ユーザールールの編集...,Geosite 사용자 수정,Modifier la règle utilisateur pour Geosite ...
Secure Local PAC,Безопасный URL локального PAC,保护本地 PAC,安全本機 PAC,ローカル PAC を保護,로컬 프록시 자동 구성 파일 암호화,Sécuriser PAC local
Regenerate local PAC on version update,,版本更新后重新生成本地 PAC,版本更新後重新生成本地 PAC,,,
Copy Local PAC URL,Копировать URL локального PAC,复制本地 PAC 网址,複製本機 PAC 網址,ローカル PAC URL をコピー,로컬 프록시 자동 구성 파일 URL 복사,Copier l'URL du PAC local
Share Server Config...,Поделиться конфигурацией сервера…,分享服务器配置...,分享伺服器設定檔...,サーバーの設定を共有...,서버 설정 공유,Partager la configuration du serveur ...
Scan QRCode from Screen...,Сканировать QRCode с экрана…,扫描屏幕上的二维码...,掃描螢幕上的 QR 碼...,画面から QR コードをスキャン...,화면에서 QR코드 스캔,Scanner le QRCode à partir de l'écran ...
Expand Down
Loading