Replace circular buffer with the blockcopy variant

to get rid of deep copy

- update NuGet pkg

Signed-off-by: Syrone Wong <wong.syrone@gmail.com>
This commit is contained in:
Syrone Wong
2017-05-19 15:56:13 +08:00
parent 0e01f8303c
commit 2eeebc29d7
6 changed files with 533 additions and 25 deletions
@@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using Cyotek.Collections.Generic;
using Shadowsocks.Encryption.CircularBuffer;
using Shadowsocks.Controller;
namespace Shadowsocks.Encryption.Stream
@@ -14,8 +14,8 @@ namespace Shadowsocks.Encryption.Stream
protected static byte[] _udpTmpBuf = new byte[65536];
// every connection should create its own buffer
private CircularBuffer<byte> _encCircularBuffer = new CircularBuffer<byte>(TCPHandler.BufferSize * 2, false);
private CircularBuffer<byte> _decCircularBuffer = new CircularBuffer<byte>(TCPHandler.BufferSize * 2, false);
private ByteCircularBuffer _encCircularBuffer = new ByteCircularBuffer(TCPHandler.BufferSize * 2);
private ByteCircularBuffer _decCircularBuffer = new ByteCircularBuffer(TCPHandler.BufferSize * 2);
protected Dictionary<string, EncryptorInfo> ciphers;
@@ -143,7 +143,8 @@ namespace Shadowsocks.Encryption.Stream
}
byte[] cipher = _decCircularBuffer.ToArray();
cipherUpdate(false, cipher.Length, cipher, outbuf);
_decCircularBuffer.Clear();
// move pointer only
_decCircularBuffer.Skip(_decCircularBuffer.Size);
outlength = cipher.Length;
// done the decryption
}