diff --git a/.github/workflows/network-tests.yml b/.github/workflows/network-tests.yml index 5f673e694..738a744cf 100644 --- a/.github/workflows/network-tests.yml +++ b/.github/workflows/network-tests.yml @@ -42,7 +42,7 @@ jobs: --packet-repeat-time 200 --packet-interval 40 --github-actions - --clients-count 2 + --clients-count 1 --packet-delay-log - name: Archive logs @@ -52,6 +52,78 @@ jobs: path: Tests/KcpTests/KcpPerformanceTest/logs retention-days: 21 + net-debug-direct-bytecheck-ubuntu: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Setup .NET Core + uses: actions/setup-dotnet@v1 + with: + dotnet-version: '6.0.x' + + - name: Restore NuGet packages + run: | + dotnet nuget add source https://apiint.nugettest.org/v3/index.json -n "nuget.org (Integration)" + dotnet restore Tests/KcpTests/KcpPerformanceTest/KcpPerformanceTest.csproj + + - name: Run tests + run: > + cd Tests/KcpTests/KcpPerformanceTest ; + dotnet run --configuration Debug + --property:DefineConstants=TRACE%3bDEBUG%3bNET%3bNET6_0%3bNETCOREAPP%3bMIHOMO_KC%3bCONNECT_SERVERONLYP%3bBYTE_CHECK_MODE -- + --packet-size 3500 + --packet-repeat-time 200 + --packet-interval 40 + --github-actions + --clients-count 1 + --packet-delay-log + + - name: Archive logs + uses: actions/upload-artifact@v2 + with: + name: Report & logs (direct-ubuntu-debug, BYTE_CHECK_MODE) + path: Tests/KcpTests/KcpPerformanceTest/logs + retention-days: 21 + + net-debug-direct-corrupt-bytecheck-ubuntu: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Setup .NET Core + uses: actions/setup-dotnet@v1 + with: + dotnet-version: '6.0.x' + + - name: Restore NuGet packages + run: | + dotnet nuget add source https://apiint.nugettest.org/v3/index.json -n "nuget.org (Integration)" + dotnet restore Tests/KcpTests/KcpPerformanceTest/KcpPerformanceTest.csproj + + - name: Run tests + run: > + cd Tests/KcpTests/KcpPerformanceTest ; + dotnet run --configuration Debug + --property:DefineConstants=TRACE%3bDEBUG%3bNET%3bNET6_0%3bNETCOREAPP%3bMIHOMO_KCP%3bBYTE_CHECK_MODE%3bCONNECT_SERVERONLY%3bCORRUPT_PACKET -- + --packet-size 3500 + --packet-repeat-time 200 + --packet-interval 40 + --github-actions + --clients-count 1 + --packet-delay-log + + - name: Archive logs + uses: actions/upload-artifact@v2 + with: + name: Report & logs (proxy-ubuntu-debug, BYTE_CHECK_MODE, CORRUPT_PACKET) + path: Tests/KcpTests/KcpPerformanceTest/logs + retention-days: 21 + net-debug-proxy-ubuntu: runs-on: ubuntu-latest @@ -77,7 +149,7 @@ jobs: --packet-repeat-time 200 --packet-interval 40 --github-actions - --clients-count 2 + --clients-count 1 --packet-delay-log - name: Archive logs @@ -113,7 +185,7 @@ jobs: --packet-repeat-time 200 --packet-interval 40 --github-actions - --clients-count 2 + --clients-count 1 --packet-delay-log - name: Archive logs @@ -149,13 +221,13 @@ jobs: --packet-repeat-time 200 --packet-interval 40 --github-actions - --clients-count 2 + --clients-count 1 --packet-delay-log - name: Archive logs uses: actions/upload-artifact@v2 with: - name: Report & logs (proxy-ubuntu-debug, BYTE_CHECK_MODE) + name: Report & logs (proxy-ubuntu-debug, BYTE_CHECK_MODE, CORRUPT_PACKET) path: Tests/KcpTests/KcpPerformanceTest/logs retention-days: 21 @@ -166,6 +238,7 @@ jobs: needs: - net-debug-direct-ubuntu + - net-debug-direct-bytecheck-ubuntu - net-debug-proxy-ubuntu - net-debug-proxy-bytecheck-ubuntu @@ -207,6 +280,7 @@ jobs: needs: - net-debug-direct-ubuntu + - net-debug-direct-bytecheck-ubuntu - net-debug-proxy-ubuntu - net-debug-proxy-bytecheck-ubuntu @@ -248,6 +322,7 @@ jobs: needs: - net-debug-direct-ubuntu + - net-debug-direct-bytecheck-ubuntu - net-debug-proxy-ubuntu - net-debug-proxy-bytecheck-ubuntu @@ -288,6 +363,7 @@ jobs: needs: - net-debug-direct-ubuntu + - net-debug-direct-bytecheck-ubuntu - net-debug-proxy-ubuntu - net-debug-proxy-bytecheck-ubuntu @@ -330,6 +406,7 @@ jobs: needs: - net-debug-direct-ubuntu + - net-debug-direct-bytecheck-ubuntu - net-debug-proxy-ubuntu - net-debug-proxy-bytecheck-ubuntu @@ -371,6 +448,7 @@ jobs: needs: - net-debug-direct-ubuntu + - net-debug-direct-bytecheck-ubuntu - net-debug-proxy-ubuntu - net-debug-proxy-bytecheck-ubuntu @@ -412,6 +490,7 @@ jobs: needs: - net-debug-direct-ubuntu + - net-debug-direct-bytecheck-ubuntu - net-debug-proxy-ubuntu - net-debug-proxy-bytecheck-ubuntu @@ -453,6 +532,7 @@ jobs: needs: - net-debug-direct-ubuntu + - net-debug-direct-bytecheck-ubuntu - net-debug-proxy-ubuntu - net-debug-proxy-bytecheck-ubuntu @@ -494,6 +574,8 @@ jobs: needs: - net-debug-direct-ubuntu + - net-debug-direct-bytecheck-ubuntu + - net-debug-direct-corrupt-bytecheck-ubuntu - net-debug-proxy-ubuntu - net-debug-proxy-bytecheck-ubuntu - net-debug-proxy-corrupt-bytecheck-ubuntu @@ -536,6 +618,8 @@ jobs: needs: - net-debug-direct-ubuntu + - net-debug-direct-bytecheck-ubuntu + - net-debug-direct-corrupt-bytecheck-ubuntu - net-debug-proxy-ubuntu - net-debug-proxy-bytecheck-ubuntu - net-debug-proxy-corrupt-bytecheck-ubuntu @@ -578,6 +662,8 @@ jobs: needs: - net-debug-direct-ubuntu + - net-debug-direct-bytecheck-ubuntu + - net-debug-direct-corrupt-bytecheck-ubuntu - net-debug-proxy-ubuntu - net-debug-proxy-bytecheck-ubuntu - net-debug-proxy-corrupt-bytecheck-ubuntu @@ -620,6 +706,8 @@ jobs: needs: - net-debug-direct-ubuntu + - net-debug-direct-bytecheck-ubuntu + - net-debug-direct-corrupt-bytecheck-ubuntu - net-debug-proxy-ubuntu - net-debug-proxy-bytecheck-ubuntu - net-debug-proxy-corrupt-bytecheck-ubuntu diff --git a/KCP/Kcp/KcpCore.cs b/KCP/Kcp/KcpCore.cs index e59ac163c..e4341f043 100644 --- a/KCP/Kcp/KcpCore.cs +++ b/KCP/Kcp/KcpCore.cs @@ -1969,18 +1969,6 @@ ref length switch (cmd) { case IKCP_CMD_PUSH: -#if BYTE_CHECK_MODE - if (!byteCheck(span.Slice(offset, (int)length), byteCheckMode, byteCheckCode)) - { - if (CanLog(KcpLogMask.IKCP_LOG_IN_DATA)) - { - LogWriteLine($"input psh dropped (checksum failed): sn={sn} ts={ts}", KcpLogMask.IKCP_LOG_IN_DATA.ToString()); - } - offset += (int)length; - continue; - } - break; -#endif case IKCP_CMD_ACK: case IKCP_CMD_WASK: case IKCP_CMD_WINS: @@ -2049,6 +2037,17 @@ ref length if (Itimediff(sn, rcv_nxt + rcv_wnd) < 0) { +#if BYTE_CHECK_MODE + if (!byteCheck(span.Slice(offset, (int)length), byteCheckMode, byteCheckCode)) + { + if (CanLog(KcpLogMask.IKCP_LOG_IN_DATA)) + { + LogWriteLine($"input psh dropped (checksum failed): sn={sn} ts={ts}", KcpLogMask.IKCP_LOG_IN_DATA.ToString()); + } + offset += (int)length; + continue; + } +#endif ///instead of ikcp_ack_push acklist.Enqueue((sn, ts)); @@ -2320,10 +2319,10 @@ ref length { LogWriteLine($"input psh dropped (checksum failed): sn={sn} ts={ts}", KcpLogMask.IKCP_LOG_IN_DATA.ToString()); } + offset += (int)length; continue; } #endif - ///instead of ikcp_ack_push acklist.Enqueue((sn, ts)); diff --git a/KCP/Kcp/KcpSegment.cs b/KCP/Kcp/KcpSegment.cs index 6bb8e85b0..1c3e8a9e4 100644 --- a/KCP/Kcp/KcpSegment.cs +++ b/KCP/Kcp/KcpSegment.cs @@ -623,7 +623,15 @@ public Span data private void CorruptData(Span buffer) { if (buffer.Length == 0 || !corrupt) return; - if (xmit >= 2 || sn <= 500) return; + if (sn <= 500) return; + if (xmit < 2) + { + Log.Verb($"Packet sn={sn}: corrupted packet", nameof(KcpSegment)); + } + else + { + Log.Verb($"Packet sn={sn}: normal packet", nameof(KcpSegment)); + } lock (Random.Shared) { buffer[Random.Shared.Next(0, buffer.Length)] = 0; diff --git a/Tests/KcpTests/SharedLib/KCP/SpecialUdp/SocketUdpClient.cs b/Tests/KcpTests/SharedLib/KCP/SpecialUdp/SocketUdpClient.cs index 0b52ab6e1..26c4850c1 100644 --- a/Tests/KcpTests/SharedLib/KCP/SpecialUdp/SocketUdpClient.cs +++ b/Tests/KcpTests/SharedLib/KCP/SpecialUdp/SocketUdpClient.cs @@ -1,6 +1,6 @@ // #define SOCKET_UDP_VERBOSE // #define SOCKET_UDP_PACKET_CONTENT_VERBOSE -// #define SOCKET_UDP_PACKET_CONTENT_VERBOSE_SYNCRONOUS +#define SOCKET_UDP_PACKET_CONTENT_VERBOSE_SYNCRONOUS // Generated by ChatGPT using System.Net;