log
This commit is contained in:
@@ -253,6 +253,7 @@ namespace CSNetwork
|
||||
_logger.Log(LogType.Info, "Send loop finished.");
|
||||
}
|
||||
|
||||
private int _previousLength;
|
||||
// Internal task to read from network and process data
|
||||
private async Task ProcessReceivedData(CancellationToken token)
|
||||
{
|
||||
@@ -303,6 +304,9 @@ namespace CSNetwork
|
||||
_receiveOctets.Capacity - currentBufferLength,
|
||||
token
|
||||
);
|
||||
|
||||
|
||||
// _logger.Log(LogType.Info, $"ProcessReceivedData:: Buffer remaining data size: {currentBufferLength} -- Raw first byte: {_receiveOctets.RawBuffer[0]}");
|
||||
}
|
||||
catch (IOException ex)
|
||||
when (ex.InnerException is SocketException se
|
||||
@@ -334,10 +338,10 @@ namespace CSNetwork
|
||||
currentBufferLength += bytesRead;
|
||||
_receiveOctets.SetSize(currentBufferLength);
|
||||
|
||||
_logger.Log(LogType.Info, $"Process Buffer:: Read {bytesRead} bytes -- Token: {token.GetHashCode()}");
|
||||
_logger.Log(LogType.Info, $"BF Process Buffer:: Read {bytesRead} bytes -- Total size: {currentBufferLength}");
|
||||
// Process the data currently in the buffer
|
||||
ProcessBuffer();
|
||||
|
||||
_logger.Log(LogType.Info, $"AF Process Buffer:: Read {bytesRead} bytes -- Total size: {currentBufferLength}");
|
||||
// After processing, the buffer might have been compacted, update length
|
||||
currentBufferLength = _receiveOctets.Length;
|
||||
}
|
||||
@@ -386,8 +390,10 @@ namespace CSNetwork
|
||||
0,
|
||||
originalBlockLength
|
||||
);
|
||||
_logger.Log(LogType.Info, $"ProcessBuffer:: raw first byte {currentData.RawBuffer[0]} - Length: {currentData.Length}");
|
||||
// Update returns a NEW Octets object with processed data
|
||||
dataToProcess = currentIsec!.Update(currentData);
|
||||
_logger.Log(LogType.Info, $"ProcessBuffer:: decompressed first byte {dataToProcess.RawBuffer[0]} - Length: {dataToProcess.Length}");
|
||||
// _logger.Log(LogType.Info, $"Input security applied. Original size: {originalBlockLength}, Processed size: {dataToProcess.Length}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -411,6 +417,7 @@ namespace CSNetwork
|
||||
bool processedAnyProtocols = false;
|
||||
int totalConsumedFromProcessedStream = 0; // Track total bytes consumed *from the processed stream*
|
||||
|
||||
Protocol._logger = _logger;
|
||||
while (processingStream.Position < dataToProcess.Length)
|
||||
{
|
||||
int streamPosBeforeDecode = processingStream.Position;
|
||||
@@ -418,6 +425,7 @@ namespace CSNetwork
|
||||
|
||||
try
|
||||
{
|
||||
//_logger.Log(LogType.Info, $"First byte of the stream: {processingStream.RawBuffer[0]}");
|
||||
(p, consumedBytes) = Protocol.Decode(processingStream, IgnoreBytes); // Decode returns protocol and bytes consumed
|
||||
}
|
||||
catch (Exception e)
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace CSNetwork.Protocols
|
||||
{
|
||||
public abstract class Protocol
|
||||
{
|
||||
private static readonly IPrefixedLogger _logger = LoggerFactory.GetLogger(nameof(Protocol));
|
||||
public static IPrefixedLogger _logger = LoggerFactory.GetLogger(nameof(Protocol));
|
||||
public uint Type { get; protected set; }
|
||||
public ProtocolType GetPType() => (ProtocolType)Type;
|
||||
private static readonly Dictionary<uint, Type> _protocolMap = new Dictionary<uint, Type>();
|
||||
@@ -169,7 +169,7 @@ namespace CSNetwork.Protocols
|
||||
|
||||
private const int MaxProtocolSize = 16 * 1024 * 1024; // 16MB max size
|
||||
|
||||
public virtual string ToString => $"Protocol Type: {Type}";
|
||||
public virtual string ToString => $"Protocol Type: {Type}";
|
||||
}
|
||||
|
||||
// Add interface for marshallable objects
|
||||
|
||||
@@ -45,6 +45,8 @@ namespace CSNetwork.Security
|
||||
{
|
||||
if (data == null || data.Length == 0)
|
||||
{
|
||||
_logger.Log(LogType.Debug,$"HoangDev: AF _arcFour data{data.RawBuffer[0]} - Length: {data.Length}");
|
||||
|
||||
return new Octets(); // Return empty if input is empty
|
||||
}
|
||||
// 1. Decrypt using ARCFour
|
||||
@@ -55,7 +57,9 @@ namespace CSNetwork.Security
|
||||
// or just to be safe. Ensure _arcFour.Update returns a *new* Octets.
|
||||
// *** If ARCFourSecurity.Update modified the input Octets in-place, this would be wrong. ***
|
||||
// *** Assuming ARCFourSecurity.Update follows the abstract Security pattern and returns new Octets ***
|
||||
decryptedData = _arcFour.Update(data);
|
||||
decryptedData = _arcFour.Update(data);
|
||||
_logger.Log(LogType.Debug,$"HoangDev: AF _arcFour data{decryptedData.RawBuffer[0]} - Length: {decryptedData.Length}");
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -75,7 +79,7 @@ namespace CSNetwork.Security
|
||||
try
|
||||
{
|
||||
decompressedData = decompressor.Update(decryptedData);
|
||||
//_logger.Log(LogType.Debug, $"Decompressed {decryptedData.Length} bytes to {decompressedData.Length} bytes. Decompressed Data: {decompressedData.ToString()}");
|
||||
_logger.Log(LogType.Debug, $"Decompressed {decryptedData.Length} bytes to {decompressedData.Length} bytes. Decompressed Data: {decompressedData.ToString()}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user