Skip to content

Commit

Permalink
Merge v4.1.10 into no-builtin-blob-no-update
Browse files Browse the repository at this point in the history
  • Loading branch information
Student Main committed Apr 13, 2020
2 parents ca2f757 + 56566ad commit cac9286
Show file tree
Hide file tree
Showing 9 changed files with 259 additions and 233 deletions.
4 changes: 4 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
4.1.10.0 2020-4-11
- Fix NLog config file issue (#2841, #2846)
- Tweak log level

4.1.9.3 2020-03-31
- Set default method to chacha20-ietf-poly1305
- Using hash in PAC URL (#2759)
Expand Down
8 changes: 4 additions & 4 deletions shadowsocks-csharp/Controller/Service/TCPRelay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public void CreateRemote()
this._server = server;

/* prepare address buffer length for AEAD */
Logger.Debug($"_addrBufLength={_addrBufLength}");
Logger.Trace($"_addrBufLength={_addrBufLength}");
_encryptor.AddrBufLength = _addrBufLength;
}

Expand Down Expand Up @@ -798,7 +798,7 @@ private void StartPipe(AsyncSession session)
PipeRemoteReceiveCallback, session);

TryReadAvailableData();
Logger.Debug($"_firstPacketLength = {_firstPacketLength}");
Logger.Trace($"_firstPacketLength = {_firstPacketLength}");
SendToServer(_firstPacketLength, session);
}
catch (Exception e)
Expand Down Expand Up @@ -837,12 +837,12 @@ private void PipeRemoteReceiveCallback(IAsyncResult ar)
if (bytesToSend == 0)
{
// need more to decrypt
Logger.Debug("Need more to decrypt");
Logger.Trace("Need more to decrypt");
session.Remote.BeginReceive(_remoteRecvBuffer, 0, RecvSize, SocketFlags.None,
PipeRemoteReceiveCallback, session);
return;
}
Logger.Debug($"start sending {bytesToSend}");
Logger.Trace($"start sending {bytesToSend}");
_connection.BeginSend(_remoteSendBuffer, 0, bytesToSend, SocketFlags.None,
PipeConnectionSendCallback, new object[] { session, bytesToSend });
IStrategy strategy = _controller.GetCurrentStrategy();
Expand Down
1 change: 1 addition & 0 deletions shadowsocks-csharp/Controller/Service/UpdateChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class UpdateChecker
public string LatestVersionName;
public string LatestVersionURL;
public string LatestVersionLocalName;
public event EventHandler CheckUpdateCompleted;

public const string Version = "4.1.9.3";

Expand Down
420 changes: 210 additions & 210 deletions shadowsocks-csharp/Data/i18n.csv

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions shadowsocks-csharp/Encryption/AEAD/AEADEncryptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public override void Encrypt(byte[] buf, int length, byte[] outbuf, out int outl

_encCircularBuffer.Put(buf, 0, length);
outlength = 0;
logger.Debug("---Start Encryption");
logger.Trace("---Start Encryption");
if (! _encryptSaltSent) {
_encryptSaltSent = true;
// Generate salt
Expand All @@ -150,7 +150,7 @@ public override void Encrypt(byte[] buf, int length, byte[] outbuf, out int outl
InitCipher(saltBytes, true, false);
Array.Copy(saltBytes, 0, outbuf, 0, saltLen);
outlength = saltLen;
logger.Debug($"_encryptSaltSent outlength {outlength}");
logger.Trace($"_encryptSaltSent outlength {outlength}");
}

if (! _tcpRequestSent) {
Expand All @@ -163,7 +163,7 @@ public override void Encrypt(byte[] buf, int length, byte[] outbuf, out int outl
Debug.Assert(encAddrBufLength == AddrBufLength + tagLen * 2 + CHUNK_LEN_BYTES);
Array.Copy(encAddrBufBytes, 0, outbuf, outlength, encAddrBufLength);
outlength += encAddrBufLength;
logger.Debug($"_tcpRequestSent outlength {outlength}");
logger.Trace($"_tcpRequestSent outlength {outlength}");
}

// handle other chunks
Expand All @@ -178,15 +178,15 @@ public override void Encrypt(byte[] buf, int length, byte[] outbuf, out int outl
Debug.Assert(encChunkLength == chunklength + tagLen * 2 + CHUNK_LEN_BYTES);
Buffer.BlockCopy(encChunkBytes, 0, outbuf, outlength, encChunkLength);
outlength += encChunkLength;
logger.Debug("chunks enc outlength " + outlength);
logger.Trace("chunks enc outlength " + outlength);
// check if we have enough space for outbuf
if (outlength + TCPHandler.ChunkOverheadSize > TCPHandler.BufferSize) {
logger.Debug("enc outbuf almost full, giving up");
logger.Trace("enc outbuf almost full, giving up");
return;
}
bufSize = (uint)_encCircularBuffer.Size;
if (bufSize <= 0) {
logger.Debug("No more data to encrypt, leaving");
logger.Trace("No more data to encrypt, leaving");
return;
}
}
Expand All @@ -201,7 +201,7 @@ public override void Decrypt(byte[] buf, int length, byte[] outbuf, out int outl
// drop all into buffer
_decCircularBuffer.Put(buf, 0, length);

logger.Debug("---Start Decryption");
logger.Trace("---Start Decryption");
if (! _decryptSaltReceived) {
bufSize = _decCircularBuffer.Size;
// check if we get the leading salt
Expand All @@ -212,15 +212,15 @@ public override void Decrypt(byte[] buf, int length, byte[] outbuf, out int outl
_decryptSaltReceived = true;
byte[] salt = _decCircularBuffer.Get(saltLen);
InitCipher(salt, false, false);
logger.Debug("get salt len " + saltLen);
logger.Trace("get salt len " + saltLen);
}

// handle chunks
while (true) {
bufSize = _decCircularBuffer.Size;
// check if we have any data
if (bufSize <= 0) {
logger.Debug("No data in _decCircularBuffer");
logger.Trace("No data in _decCircularBuffer");
return;
}

Expand All @@ -246,10 +246,10 @@ public override void Decrypt(byte[] buf, int length, byte[] outbuf, out int outl
logger.Error($"Invalid chunk length: {chunkLen}");
throw new CryptoErrorException();
}
logger.Debug("Get the real chunk len:" + chunkLen);
logger.Trace("Get the real chunk len:" + chunkLen);
bufSize = _decCircularBuffer.Size;
if (bufSize < CHUNK_LEN_BYTES + tagLen /* we haven't remove them */+ chunkLen + tagLen) {
logger.Debug("No more data to decrypt one chunk");
logger.Trace("No more data to decrypt one chunk");
return;
}
IncrementNonce(false);
Expand All @@ -269,16 +269,16 @@ public override void Decrypt(byte[] buf, int length, byte[] outbuf, out int outl
// output to outbuf
Buffer.BlockCopy(decChunkBytes, 0, outbuf, outlength, (int) decChunkLen);
outlength += (int)decChunkLen;
logger.Debug("aead dec outlength " + outlength);
logger.Trace("aead dec outlength " + outlength);
if (outlength + 100 > TCPHandler.BufferSize)
{
logger.Debug("dec outbuf almost full, giving up");
logger.Trace("dec outbuf almost full, giving up");
return;
}
bufSize = _decCircularBuffer.Size;
// check if we already done all of them
if (bufSize <= 0) {
logger.Debug("No data in _decCircularBuffer, already all done");
logger.Trace("No data in _decCircularBuffer, already all done");
return;
}
}
Expand Down
11 changes: 9 additions & 2 deletions shadowsocks-csharp/Model/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ public class Configuration
NLogConfig nLogConfig;

private static readonly string CONFIG_FILE = "gui-config.json";
private static readonly NLogConfig.LogLevel verboseLogLevel =
#if DEBUG
NLogConfig.LogLevel.Trace;
#else
NLogConfig.LogLevel.Debug;
#endif


[JsonIgnore]
public bool updated = false;
Expand Down Expand Up @@ -185,10 +192,10 @@ public static void Save(Configuration config)
try
{
// apply changs to NLog.config
config.nLogConfig.SetLogLevel(config.isVerboseLogging? NLogConfig.LogLevel.Trace: NLogConfig.LogLevel.Info);
config.nLogConfig.SetLogLevel(config.isVerboseLogging? verboseLogLevel : NLogConfig.LogLevel.Info);
NLogConfig.SaveXML(config.nLogConfig);
}
catch(Exception e)
catch (Exception e)
{
logger.Error(e, "Cannot set the log level to NLog config file. Please check if the nlog config file exists with corresponding XML nodes.");
}
Expand Down
17 changes: 15 additions & 2 deletions shadowsocks-csharp/Model/NlogConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public enum LogLevel
Trace,
}

const string NLOG_CONFIG_FILE_NAME = "nLog.config";
const string NLOG_CONFIG_FILE_NAME = "NLog.config";
const string TARGET_MIN_LEVEL_ATTRIBUTE = "minlevel";
const string LOGGER_FILE_NAME_ATTRIBUTE = "fileName";

Expand Down Expand Up @@ -108,7 +108,20 @@ private static XmlNode SelectSingleNode(XmlDocument doc, string xpath)
/// </summary>
public static void TouchAndApplyNLogConfig()
{
LogManager.LoadConfiguration(NLOG_CONFIG_FILE_NAME);
try
{
if (File.Exists(NLOG_CONFIG_FILE_NAME))
return; // NLog.config exists, and has already been loaded

File.WriteAllText(NLOG_CONFIG_FILE_NAME, Properties.Resources.NLog_config);
}
catch (Exception ex)
{
NLog.Common.InternalLogger.Error(ex, "[shadowsocks] Failed to setup default NLog.config: {0}", NLOG_CONFIG_FILE_NAME);
return;
}

LoadConfiguration(); // Load the new config-file
}

/// <summary>
Expand Down
1 change: 1 addition & 0 deletions shadowsocks-csharp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ static class Program
[STAThread]
static void Main(string[] args)
{
Directory.SetCurrentDirectory(Application.StartupPath);
// todo: initialize the NLog configuartion
Model.NLogConfig.TouchAndApplyNLogConfig();

Expand Down
2 changes: 1 addition & 1 deletion shadowsocks-csharp/Proxy/HttpProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ private void OnException(Exception ex, object state)

private bool OnLineRead(string line, object state)
{
logger.Debug(line);
logger.Trace(line);

if (_respondLineCount == 0)
{
Expand Down

0 comments on commit cac9286

Please sign in to comment.