diff --git a/CHANGES b/CHANGES index 2f8955b3..4c57bf68 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,7 @@ +2.0.10 2014-11-18 +- Minor fixes +- Optimize code + 2.0.9 2014-11-13 - Fix startup path - Fix allowed port range for polipo diff --git a/README.md b/README.md index 2949d7a1..6981ebcb 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,6 @@ Shadowsocks for Windows [![Build Status]][Appveyor] -Currently beta. Please file an issue if you find any bugs. - ### Features 1. Native Windows UI diff --git a/shadowsocks-csharp/Controller/ShadowsocksController.cs b/shadowsocks-csharp/Controller/ShadowsocksController.cs index cb6cce11..b4de4cf9 100755 --- a/shadowsocks-csharp/Controller/ShadowsocksController.cs +++ b/shadowsocks-csharp/Controller/ShadowsocksController.cs @@ -14,6 +14,8 @@ namespace Shadowsocks.Controller // manipulates UI // interacts with low level logic + private Thread _ramThread; + private Local local; private PACServer pacServer; private Configuration _config; @@ -58,6 +60,7 @@ namespace Shadowsocks.Controller } UpdateSystemProxy(); + StartReleasingMemory(); } public Server GetCurrentServer() @@ -161,6 +164,8 @@ namespace Shadowsocks.Controller { ConfigChanged(this, new EventArgs()); } + + Util.Util.ReleaseMemory(); } @@ -180,5 +185,21 @@ namespace Shadowsocks.Controller { UpdateSystemProxy(); } + + private void StartReleasingMemory() + { + _ramThread = new Thread(new ThreadStart(ReleaseMemory)); + _ramThread.IsBackground = true; + _ramThread.Start(); + } + + private void ReleaseMemory() + { + while (true) + { + Util.Util.ReleaseMemory(); + Thread.Sleep(30 * 1000); + } + } } } diff --git a/shadowsocks-csharp/Data/libeay32.dll.gz b/shadowsocks-csharp/Data/libeay32.dll.gz deleted file mode 100755 index 673427ba..00000000 Binary files a/shadowsocks-csharp/Data/libeay32.dll.gz and /dev/null differ diff --git a/shadowsocks-csharp/Data/polarssl.dll.gz b/shadowsocks-csharp/Data/polarssl.dll.gz index 09212aa0..04a8f0a7 100755 Binary files a/shadowsocks-csharp/Data/polarssl.dll.gz and b/shadowsocks-csharp/Data/polarssl.dll.gz differ diff --git a/shadowsocks-csharp/Data/polipo.exe.gz b/shadowsocks-csharp/Data/polipo.exe.gz index 375a1978..72e47a61 100755 Binary files a/shadowsocks-csharp/Data/polipo.exe.gz and b/shadowsocks-csharp/Data/polipo.exe.gz differ diff --git a/shadowsocks-csharp/Data/ss32.ico b/shadowsocks-csharp/Data/ss32.ico deleted file mode 100755 index a68e4dbb..00000000 Binary files a/shadowsocks-csharp/Data/ss32.ico and /dev/null differ diff --git a/shadowsocks-csharp/Encrypt/PolarSSL.cs b/shadowsocks-csharp/Encrypt/PolarSSL.cs index 193e4ab0..94659c80 100755 --- a/shadowsocks-csharp/Encrypt/PolarSSL.cs +++ b/shadowsocks-csharp/Encrypt/PolarSSL.cs @@ -61,22 +61,5 @@ namespace Shadowsocks.Encrypt [DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)] public extern static int arc4_crypt(IntPtr ctx, int length, byte[] input, byte[] output); - - public const int BLOWFISH_CTX_SIZE = 4168; - public const int BLOWFISH_ENCRYPT = 1; - public const int BLOWFISH_DECRYPT = 0; - - [DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)] - public extern static void blowfish_init(IntPtr ctx); - - [DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)] - public extern static void blowfish_free(IntPtr ctx); - - [DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)] - public extern static int blowfish_setkey(IntPtr ctx, byte[] key, int keysize); - - [DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)] - public extern static int blowfish_crypt_cfb64(IntPtr ctx, int mode, int length, ref int iv_off, byte[] iv, byte[] input, byte[] output); - } } diff --git a/shadowsocks-csharp/Encrypt/PolarSSLEncryptor.cs b/shadowsocks-csharp/Encrypt/PolarSSLEncryptor.cs index 7b369130..959fa350 100755 --- a/shadowsocks-csharp/Encrypt/PolarSSLEncryptor.cs +++ b/shadowsocks-csharp/Encrypt/PolarSSLEncryptor.cs @@ -12,13 +12,11 @@ namespace Shadowsocks.Encrypt { const int CIPHER_AES = 1; const int CIPHER_RC4 = 2; - const int CIPHER_BF = 3; static Dictionary ciphers = new Dictionary { {"aes-128-cfb", new int[]{16, 16, CIPHER_AES, PolarSSL.AES_CTX_SIZE}}, {"aes-192-cfb", new int[]{24, 16, CIPHER_AES, PolarSSL.AES_CTX_SIZE}}, {"aes-256-cfb", new int[]{32, 16, CIPHER_AES, PolarSSL.AES_CTX_SIZE}}, - {"bf-cfb", new int[]{16, 8, CIPHER_BF, PolarSSL.BLOWFISH_CTX_SIZE}}, {"rc4", new int[]{16, 0, CIPHER_RC4, PolarSSL.ARC4_CTX_SIZE}}, {"rc4-md5", new int[]{16, 16, CIPHER_RC4, PolarSSL.ARC4_CTX_SIZE}}, }; @@ -133,22 +131,6 @@ namespace Shadowsocks.Encrypt Array.Copy(iv, _decryptIV, ivLen); } } - else if (_cipher == CIPHER_BF) - { - PolarSSL.blowfish_init(ctx); - // PolarSSL takes key length by bit - PolarSSL.blowfish_setkey(ctx, realkey, keyLen * 8); - if (isCipher) - { - _encryptIV = new byte[ivLen]; - Array.Copy(iv, _encryptIV, ivLen); - } - else - { - _decryptIV = new byte[ivLen]; - Array.Copy(iv, _decryptIV, ivLen); - } - } else if (_cipher == CIPHER_RC4) { PolarSSL.arc4_init(ctx); @@ -180,9 +162,6 @@ namespace Shadowsocks.Encrypt case CIPHER_AES: PolarSSL.aes_crypt_cfb128(_encryptCtx, PolarSSL.AES_ENCRYPT, length, ref _encryptIVOffset, _encryptIV, buf, tempbuf); break; - case CIPHER_BF: - PolarSSL.blowfish_crypt_cfb64(_encryptCtx, PolarSSL.BLOWFISH_ENCRYPT, length, ref _encryptIVOffset, _encryptIV, buf, tempbuf); - break; case CIPHER_RC4: PolarSSL.arc4_crypt(_encryptCtx, length, buf, tempbuf); break; @@ -204,9 +183,6 @@ namespace Shadowsocks.Encrypt case CIPHER_AES: PolarSSL.aes_crypt_cfb128(_encryptCtx, PolarSSL.AES_ENCRYPT, length, ref _encryptIVOffset, _encryptIV, buf, outbuf); break; - case CIPHER_BF: - PolarSSL.blowfish_crypt_cfb64(_encryptCtx, PolarSSL.BLOWFISH_ENCRYPT, length, ref _encryptIVOffset, _encryptIV, buf, outbuf); - break; case CIPHER_RC4: PolarSSL.arc4_crypt(_encryptCtx, length, buf, outbuf); break; @@ -233,9 +209,6 @@ namespace Shadowsocks.Encrypt case CIPHER_AES: PolarSSL.aes_crypt_cfb128(_decryptCtx, PolarSSL.AES_DECRYPT, length - ivLen, ref _decryptIVOffset, _decryptIV, tempbuf, outbuf); break; - case CIPHER_BF: - PolarSSL.blowfish_crypt_cfb64(_decryptCtx, PolarSSL.BLOWFISH_DECRYPT, length - ivLen, ref _decryptIVOffset, _decryptIV, tempbuf, outbuf); - break; case CIPHER_RC4: PolarSSL.arc4_crypt(_decryptCtx, length - ivLen, tempbuf, outbuf); break; @@ -254,9 +227,6 @@ namespace Shadowsocks.Encrypt case CIPHER_AES: PolarSSL.aes_crypt_cfb128(_decryptCtx, PolarSSL.AES_DECRYPT, length, ref _decryptIVOffset, _decryptIV, buf, outbuf); break; - case CIPHER_BF: - PolarSSL.blowfish_crypt_cfb64(_decryptCtx, PolarSSL.BLOWFISH_DECRYPT, length, ref _decryptIVOffset, _decryptIV, buf, outbuf); - break; case CIPHER_RC4: PolarSSL.arc4_crypt(_decryptCtx, length, buf, outbuf); break; @@ -298,9 +268,6 @@ namespace Shadowsocks.Encrypt case CIPHER_AES: PolarSSL.aes_free(_encryptCtx); break; - case CIPHER_BF: - PolarSSL.blowfish_free(_encryptCtx); - break; case CIPHER_RC4: PolarSSL.arc4_free(_encryptCtx); break; @@ -315,9 +282,6 @@ namespace Shadowsocks.Encrypt case CIPHER_AES: PolarSSL.aes_free(_decryptCtx); break; - case CIPHER_BF: - PolarSSL.blowfish_free(_decryptCtx); - break; case CIPHER_RC4: PolarSSL.arc4_free(_decryptCtx); break; diff --git a/shadowsocks-csharp/Program.cs b/shadowsocks-csharp/Program.cs index abfc52a9..6b15ea9c 100755 --- a/shadowsocks-csharp/Program.cs +++ b/shadowsocks-csharp/Program.cs @@ -12,13 +12,13 @@ namespace Shadowsocks { static class Program { - /// /// 应用程序的主入口点。 /// [STAThread] static void Main() { + Util.Util.ReleaseMemory(); using (Mutex mutex = new Mutex(false, "Global\\" + "71981632-A427-497F-AB91-241CD227EC1F")) { Application.EnableVisualStyles(); @@ -41,6 +41,7 @@ namespace Shadowsocks ShadowsocksController controller = new ShadowsocksController(); MenuViewController viewController = new MenuViewController(controller); + Util.Util.ReleaseMemory(); Application.Run(); } } diff --git a/shadowsocks-csharp/Properties/AssemblyInfo.cs b/shadowsocks-csharp/Properties/AssemblyInfo.cs index 90a614c5..e65ce0b3 100755 --- a/shadowsocks-csharp/Properties/AssemblyInfo.cs +++ b/shadowsocks-csharp/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // 可以指定所有这些值,也可以使用“内部版本号”和“修订号”的默认值, // 方法是按如下所示使用“*”: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2.0.9")] +[assembly: AssemblyVersion("2.0.10")] // [assembly: AssemblyFileVersion("2.0.0")] diff --git a/shadowsocks-csharp/Util/Util.cs b/shadowsocks-csharp/Util/Util.cs new file mode 100755 index 00000000..afb5539a --- /dev/null +++ b/shadowsocks-csharp/Util/Util.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Runtime.InteropServices; +using System.Text; + +namespace Shadowsocks.Util +{ + public class Util + { + public static void ReleaseMemory() + { + // release any unused pages + // making the numbers look good in task manager + // this is totally nonsense in programming + // but good for those users who care + // making them happier with their everyday life + // which is part of user experience + GC.Collect(GC.MaxGeneration); + GC.WaitForPendingFinalizers(); + SetProcessWorkingSetSize(Process.GetCurrentProcess().Handle, + (UIntPtr)0xFFFFFFFF, (UIntPtr)0xFFFFFFFF); + } + + [DllImport("kernel32.dll")] + [return: MarshalAs(UnmanagedType.Bool)] + private static extern bool SetProcessWorkingSetSize(IntPtr process, + UIntPtr minimumWorkingSetSize, UIntPtr maximumWorkingSetSize); + } +} diff --git a/shadowsocks-csharp/View/ConfigForm.Designer.cs b/shadowsocks-csharp/View/ConfigForm.Designer.cs index a9d9a3da..50273d07 100755 --- a/shadowsocks-csharp/View/ConfigForm.Designer.cs +++ b/shadowsocks-csharp/View/ConfigForm.Designer.cs @@ -209,7 +209,6 @@ "aes-256-cfb", "aes-192-cfb", "aes-128-cfb", - "bf-cfb", "rc4"}); this.EncryptionSelect.Location = new System.Drawing.Point(74, 86); this.EncryptionSelect.Name = "EncryptionSelect"; diff --git a/shadowsocks-csharp/View/ConfigForm.cs b/shadowsocks-csharp/View/ConfigForm.cs index 5bc1cc6b..1601e0ef 100755 --- a/shadowsocks-csharp/View/ConfigForm.cs +++ b/shadowsocks-csharp/View/ConfigForm.cs @@ -180,7 +180,7 @@ namespace Shadowsocks.View return; } controller.SaveServers(_modifiedConfiguration.configs); - this.Hide(); + this.Close(); } private void CancelButton_Click(object sender, EventArgs e) diff --git a/shadowsocks-csharp/View/MenuViewController.cs b/shadowsocks-csharp/View/MenuViewController.cs index 158edb5b..c4eb8193 100755 --- a/shadowsocks-csharp/View/MenuViewController.cs +++ b/shadowsocks-csharp/View/MenuViewController.cs @@ -86,6 +86,7 @@ namespace Shadowsocks.View icon = Resources.ss24; } notifyIcon1 = new NotifyIcon(); + notifyIcon1.Text = "Shadowsocks"; notifyIcon1.Icon = Icon.FromHandle(icon.GetHicon()); notifyIcon1.Visible = true; @@ -299,8 +300,7 @@ namespace Shadowsocks.View void configForm_FormClosed(object sender, FormClosedEventArgs e) { configForm = null; - GC.Collect(); - GC.WaitForPendingFinalizers(); + Util.Util.ReleaseMemory(); ShowFirstTimeBalloon(); } diff --git a/shadowsocks-csharp/shadowsocks-csharp.csproj b/shadowsocks-csharp/shadowsocks-csharp.csproj index e9d322b2..6221c918 100755 --- a/shadowsocks-csharp/shadowsocks-csharp.csproj +++ b/shadowsocks-csharp/shadowsocks-csharp.csproj @@ -84,6 +84,7 @@ + Form @@ -124,7 +125,6 @@ Designer -