Skip to content

Commit f31c02e

Browse files
committed
Fixes TlsHandler from operation, perf and compat POVs.
Motivation: TlsHandler Fix TlsHandler, optimize encryption / decryption wrt Write vs Flush semantics, optimize memory retention for sparse communication, adopt IByteBuffer.GetIoBuffers() in TlsHandler. Modifications: - TlsHandler is rewritten to use batch->copy->write approach instead of writing directly to SslStream in order to reduce overhead of framing / writing out everything separately. - TlsHandler uses IByteBuffer.GetIoBuffers intead of direct array access increasing compatibility for non-array-backed buffers. - TlsHandler and TlsHandler.MediationStream use Task semantics now when reading through SslStream. - Extra: upgraded to NBench 2.2, xUnit 2.1.0. - Extra: better portability for .NET Core support. Result: TlsHandler provides better framing and much better (x2+) performance (depends on application control of flushing). TlsHandler operates properly in edge cases when more than one frame is accepted at once and if decrypted frame size is more than 4 KB. TlsHandler holds only 256 byte buffer while waiting for more data to arrive off the wire. Extra: DotNetty is almost .NET Core compatible.
1 parent 86749e9 commit f31c02e

File tree

54 files changed

+1886
-306
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1886
-306
lines changed

DotNetty.sln

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotNetty.Tests.Common", "te
5757
EndProject
5858
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotNetty.Transport.Tests.Performance", "test\DotNetty.Transport.Tests.Performance\DotNetty.Transport.Tests.Performance.csproj", "{F2C39894-476D-441D-878F-23A03B848E06}"
5959
EndProject
60+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotNetty.Handlers.Tests", "test\DotNetty.Handlers.Tests\DotNetty.Handlers.Tests.csproj", "{0F5AC479-520B-476F-8E2B-1849F5B63A91}"
61+
EndProject
6062
Global
6163
GlobalSection(SolutionConfigurationPlatforms) = preSolution
6264
Debug|Any CPU = Debug|Any CPU
@@ -158,6 +160,12 @@ Global
158160
{F2C39894-476D-441D-878F-23A03B848E06}.Release|Any CPU.Build.0 = Release|Any CPU
159161
{F2C39894-476D-441D-878F-23A03B848E06}.Signed|Any CPU.ActiveCfg = Release|Any CPU
160162
{F2C39894-476D-441D-878F-23A03B848E06}.Signed|Any CPU.Build.0 = Release|Any CPU
163+
{0F5AC479-520B-476F-8E2B-1849F5B63A91}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
164+
{0F5AC479-520B-476F-8E2B-1849F5B63A91}.Debug|Any CPU.Build.0 = Debug|Any CPU
165+
{0F5AC479-520B-476F-8E2B-1849F5B63A91}.Release|Any CPU.ActiveCfg = Release|Any CPU
166+
{0F5AC479-520B-476F-8E2B-1849F5B63A91}.Release|Any CPU.Build.0 = Release|Any CPU
167+
{0F5AC479-520B-476F-8E2B-1849F5B63A91}.Signed|Any CPU.ActiveCfg = Release|Any CPU
168+
{0F5AC479-520B-476F-8E2B-1849F5B63A91}.Signed|Any CPU.Build.0 = Release|Any CPU
161169
EndGlobalSection
162170
GlobalSection(SolutionProperties) = preSolution
163171
HideSolutionNode = FALSE
@@ -181,5 +189,6 @@ Global
181189
{D0D45DCD-EF82-43FA-8B95-D85D50378806} = {6A0821D4-8A5D-42AD-8E3F-F519100F4AD8}
182190
{EDF30087-8B53-4432-84B8-D21BD9F49E95} = {6A0821D4-8A5D-42AD-8E3F-F519100F4AD8}
183191
{F2C39894-476D-441D-878F-23A03B848E06} = {6A0821D4-8A5D-42AD-8E3F-F519100F4AD8}
192+
{0F5AC479-520B-476F-8E2B-1849F5B63A91} = {6A0821D4-8A5D-42AD-8E3F-F519100F4AD8}
184193
EndGlobalSection
185194
EndGlobal

DotNetty.sln.DotSettings

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=RedundantIfElseBlock/@EntryIndexedValue">DO_NOT_SHOW</s:String>
1616
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=RedundantNameQualifier/@EntryIndexedValue">DO_NOT_SHOW</s:String>
1717
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=RedundantThisQualifier/@EntryIndexedValue">DO_NOT_SHOW</s:String>
18+
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=RedundantToStringCallForValueType/@EntryIndexedValue">DO_NOT_SHOW</s:String>
1819
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=SimplifyConditionalTernaryExpression/@EntryIndexedValue">HINT</s:String>
1920
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=StyleCop_002ESA1208/@EntryIndexedValue">DO_NOT_SHOW</s:String>
2021
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=SuggestUseVarKeywordEvident/@EntryIndexedValue">HINT</s:String>

build.cmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ copy %CACHED_NUGET% .nuget\nuget.exe > nul
2222
.nuget\NuGet.exe install FAKE -OutputDirectory packages -ExcludeVersion -Version 4.25.4
2323

2424
.nuget\NuGet.exe install xunit.runner.console -OutputDirectory packages\FAKE -ExcludeVersion -Version 2.1.0
25-
.nuget\NuGet.exe install NBench.Runner -OutputDirectory packages -ExcludeVersion -Version 0.2.1
25+
.nuget\NuGet.exe install NBench.Runner -OutputDirectory packages -ExcludeVersion -Version 0.2.2
2626

2727
if not exist packages\SourceLink.Fake\tools\SourceLink.fsx (
2828
.nuget\nuget.exe install SourceLink.Fake -OutputDirectory packages -ExcludeVersion

build.fsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,7 @@ Target "All" DoNothing
440440
"CleanTests" ==> "RunTests"
441441

442442
// NBench dependencies
443+
"BuildRelease" ==> "NBench"
443444
"CleanPerf" ==> "NBench"
444445

445446
// nuget dependencies

build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ mono $SCRIPT_PATH/.nuget/nuget.exe update -self
1919
mono $SCRIPT_PATH/.nuget/nuget.exe install FAKE -OutputDirectory $SCRIPT_PATH/packages -ExcludeVersion -Version 4.25.4
2020

2121
mono $SCRIPT_PATH/.nuget/nuget.exe install xunit.runners -OutputDirectory $SCRIPT_PATH/packages/FAKE -ExcludeVersion -Version 2.1.0
22-
mono $SCRIPT_PATH/.nuget/nuget.exe install NBench.Runner -OutputDirectory packages -ExcludeVersion -Version 0.2.1
22+
mono $SCRIPT_PATH/.nuget/nuget.exe install NBench.Runner -OutputDirectory packages -ExcludeVersion -Version 0.2.2
2323

2424
if ! [ -e $SCRIPT_PATH/packages/SourceLink.Fake/tools/SourceLink.fsx ] ; then
2525
mono $SCRIPT_PATH/.nuget/nuget.exe install SourceLink.Fake -OutputDirectory $SCRIPT_PATH/packages -ExcludeVersion

src/DotNetty.Common/ResourceLeakDetector.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,13 +298,13 @@ public override string ToString()
298298
.Append(StringUtil.Newline)
299299
.Append(array[i]);
300300
}
301+
buf.Append(StringUtil.Newline);
301302
}
302303

303304
buf.Append("Created at:")
304305
.Append(StringUtil.Newline)
305306
.Append(this.creationRecord);
306307

307-
buf.Length -= StringUtil.Newline.Length;
308308
return buf.ToString();
309309
}
310310
}

src/DotNetty.Handlers/DotNetty.Handlers.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
<Compile Include="Logging\LogLevel.cs" />
4747
<Compile Include="Logging\LogLevelExtensions.cs" />
4848
<Compile Include="Properties\AssemblyInfo.cs" />
49+
<Compile Include="Tls\NotSslRecordException.cs" />
4950
<Compile Include="Tls\TlsHandshakeCompletionEvent.cs" />
5051
<Compile Include="Tls\TlsHandler.cs" />
5152
<Compile Include="Timeout\IdleState.cs" />
@@ -56,6 +57,7 @@
5657
<Compile Include="Timeout\WriteTimeoutException.cs" />
5758
<Compile Include="Timeout\ReadTimeoutHandler.cs" />
5859
<Compile Include="Timeout\WriteTimeoutHandler.cs" />
60+
<Compile Include="Tls\TlsUtils.cs" />
5961
</ItemGroup>
6062
<ItemGroup>
6163
<ProjectReference Include="..\DotNetty.Buffers\DotNetty.Buffers.csproj">
@@ -86,7 +88,5 @@
8688
<Target Name="AfterBuild">
8789
</Target>
8890
-->
89-
<ItemGroup>
90-
<Folder Include="Timeout\" />
91-
</ItemGroup>
91+
<ItemGroup />
9292
</Project>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
namespace DotNetty.Handlers.Tls
5+
{
6+
using System;
7+
8+
/// <summary>
9+
/// Special exception which will get thrown if a packet is
10+
/// received that not looks like a TLS/SSL record. A user can check for
11+
/// this <see cref="NotSslRecordException" /> and so detect if one peer tries to
12+
/// use secure and the other plain connection.
13+
/// </summary>
14+
public class NotSslRecordException : Exception
15+
{
16+
public NotSslRecordException()
17+
: base(string.Empty)
18+
{
19+
}
20+
21+
public NotSslRecordException(string message)
22+
: base(message)
23+
{
24+
}
25+
26+
public NotSslRecordException(Exception cause)
27+
: base(string.Empty, cause)
28+
{
29+
}
30+
31+
public NotSslRecordException(string message, Exception cause)
32+
: base(message, cause)
33+
{
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)