Skip to content

Commit

Permalink
bug fix & backup configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
AkaneAkaza authored and HMBSbige committed Sep 16, 2018
1 parent 369de65 commit 8b47c5d
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 14 deletions.
5 changes: 0 additions & 5 deletions shadowsocks-csharp/Encryption/MbedTLSEncryptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,6 @@ public override void Dispose()
GC.SuppressFinalize(this);
}

~MbedTLSEncryptor()
{
Dispose(false);
}

protected virtual void Dispose(bool disposing)
{
lock (this)
Expand Down
15 changes: 15 additions & 0 deletions shadowsocks-csharp/Model/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ public class Configuration
private LRUCache<string, UriVisitTime> uricache = new LRUCache<string, UriVisitTime>(180);

private static string CONFIG_FILE = "gui-config.json";
private static string CONFIG_FILE_BACKUP = "gui-config.json.backup";

public static void SetPassword(string password)
{
Expand Down Expand Up @@ -560,6 +561,20 @@ public static void Save(Configuration config)
sw.Write(jsonString);
sw.Flush();
}

if (File.Exists(CONFIG_FILE_BACKUP))
{
DateTime dt = File.GetLastWriteTimeUtc(CONFIG_FILE_BACKUP);
DateTime now = DateTime.Now;
if ((now - dt).TotalHours > 4)
{
File.Copy(CONFIG_FILE, CONFIG_FILE_BACKUP, true);
}
}
else
{
File.Copy(CONFIG_FILE, CONFIG_FILE_BACKUP, true);
}
}
catch (IOException e)
{
Expand Down
6 changes: 6 additions & 0 deletions shadowsocks-csharp/Model/ServerSpeedLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,12 @@ protected static void UpdateTransLog(List<TransLog> transLog, int bytes, DateTim
const int base_time_diff = 100;
const int max_time_diff = 3 * base_time_diff;
int time_diff = (int)(now - transLog[transLog.Count - 1].recvTime).TotalMilliseconds;
if (time_diff < 0)
{
transLog.Clear();
transLog.Add(new TransLog(bytes, now));
return;
}
if (time_diff < base_time_diff)
{
transLog[transLog.Count - 1].times++;
Expand Down
19 changes: 12 additions & 7 deletions shadowsocks-csharp/Obfs/AuthAkarin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ public override Dictionary<string, int[]> GetObfs()
return _obfs;
}

protected override void Disposing()
{
if (encryptor != null)
{
encryptor.Dispose();
encryptor = null;
}
}

public override object InitData()
{
return new AuthDataAesChain();
Expand Down Expand Up @@ -167,17 +176,13 @@ public void PackData(byte[] data, int datalength, byte[] outdata, out int outlen
{
byte[] rnd_data = new byte[rand_len];
random.NextBytes(rnd_data);
encryptor.Encrypt(data, datalength, data, out datalength);
if (datalength > 0)
{
encryptor.Encrypt(data, datalength, data, out datalength);
Array.Copy(data, 0, outdata, start_pos, datalength);
if (rand_len > 0)
{
Array.Copy(data, 0, outdata, start_pos, datalength);
Array.Copy(rnd_data, 0, outdata, start_pos + datalength, rand_len);
}
else
{
Array.Copy(data, 0, outdata, start_pos, datalength);
rnd_data.CopyTo(outdata, start_pos + datalength);
}
}
else
Expand Down
9 changes: 9 additions & 0 deletions shadowsocks-csharp/Obfs/AuthChain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,15 @@ public override Dictionary<string, int[]> GetObfs()
return _obfs;
}

protected override void Disposing()
{
if (encryptor != null)
{
encryptor.Dispose();
encryptor = null;
}
}

public override object InitData()
{
return new AuthDataAesChain();
Expand Down
6 changes: 6 additions & 0 deletions shadowsocks-csharp/Obfs/ObfsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,14 @@ protected virtual void Dispose(bool disposing)
return;
}
_disposed = true;
Disposing();
}
}

protected virtual void Disposing()
{

}
#endregion

}
Expand Down
4 changes: 3 additions & 1 deletion shadowsocks-csharp/View/LogForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ private void ReadLog()
catch (FileNotFoundException)
{
}

catch (ArgumentNullException)
{
}
Text = $@"{I18N.GetString("Log Viewer")} {_currentLogFileName}";
}

Expand Down
2 changes: 1 addition & 1 deletion shadowsocks-csharp/View/ServerLogForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ public void UpdateLogThread()
{
Configuration config = controller.GetCurrentConfiguration();
ServerSpeedLogShow[] _ServerSpeedLogList = new ServerSpeedLogShow[config.configs.Count];
for (int i = 0; i < config.configs.Count; ++i)
for (int i = 0; i < config.configs.Count && i < _ServerSpeedLogList.Length; ++i)
{
_ServerSpeedLogList[i] = config.configs[i].ServerSpeedLog().Translate();
}
Expand Down

0 comments on commit 8b47c5d

Please sign in to comment.