Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue 4 #65

Merged
merged 7 commits into from
Jul 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
</PropertyGroup>

<PropertyGroup>
<ExamplesTargetFramework>netcoreapp3.1</ExamplesTargetFramework>
<ExamplesTargetFramework>net5.0;netcoreapp3.1</ExamplesTargetFramework>
<SignAssembly>True</SignAssembly>
<AssemblyOriginatorKeyFile>$(SourceRoot)/build/DotNetty.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
Expand Down
20 changes: 10 additions & 10 deletions build/Dependencies.CuteAnt.props
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,16 @@
<ReactiveStreamsSignedPackageVersion>1.4.2009.1814</ReactiveStreamsSignedPackageVersion>
<ReactiveStreamsTCKSignedPackageVersion>1.4.2009.1814</ReactiveStreamsTCKSignedPackageVersion>

<SpanNettyBuffersPackageVersion>1.0.0-beta-210610</SpanNettyBuffersPackageVersion>
<SpanNettyCodecsHttpPackageVersion>1.0.0-beta-210610</SpanNettyCodecsHttpPackageVersion>
<SpanNettyCodecsHttp2PackageVersion>1.0.0-beta-210610</SpanNettyCodecsHttp2PackageVersion>
<SpanNettyCodecsMqttPackageVersion>1.0.0-beta-210610</SpanNettyCodecsMqttPackageVersion>
<SpanNettyCodecsProtobufPackageVersion>1.0.0-beta-210610</SpanNettyCodecsProtobufPackageVersion>
<SpanNettyCodecsPackageVersion>1.0.0-beta-210610</SpanNettyCodecsPackageVersion>
<SpanNettyCommonPackageVersion>1.0.0-beta-210610</SpanNettyCommonPackageVersion>
<SpanNettyHandlersPackageVersion>1.0.0-beta-210610</SpanNettyHandlersPackageVersion>
<SpanNettyTransportLibuvPackageVersion>1.0.0-beta-210610</SpanNettyTransportLibuvPackageVersion>
<SpanNettyTransportPackageVersion>1.0.0-beta-210610</SpanNettyTransportPackageVersion>
<SpanNettyBuffersPackageVersion>1.0.0-beta-210716</SpanNettyBuffersPackageVersion>
<SpanNettyCodecsHttpPackageVersion>1.0.0-beta-210716</SpanNettyCodecsHttpPackageVersion>
<SpanNettyCodecsHttp2PackageVersion>1.0.0-beta-210716</SpanNettyCodecsHttp2PackageVersion>
<SpanNettyCodecsMqttPackageVersion>1.0.0-beta-210716</SpanNettyCodecsMqttPackageVersion>
<SpanNettyCodecsProtobufPackageVersion>1.0.0-beta-210716</SpanNettyCodecsProtobufPackageVersion>
<SpanNettyCodecsPackageVersion>1.0.0-beta-210716</SpanNettyCodecsPackageVersion>
<SpanNettyCommonPackageVersion>1.0.0-beta-210716</SpanNettyCommonPackageVersion>
<SpanNettyHandlersPackageVersion>1.0.0-beta-210716</SpanNettyHandlersPackageVersion>
<SpanNettyTransportLibuvPackageVersion>1.0.0-beta-210716</SpanNettyTransportLibuvPackageVersion>
<SpanNettyTransportPackageVersion>1.0.0-beta-210716</SpanNettyTransportPackageVersion>

<!-- Serialization related packages -->
<HyperionUnofficialPackageVersion>0.9.16-rtm-200824-01</HyperionUnofficialPackageVersion>
Expand Down
8 changes: 2 additions & 6 deletions buildNetstandard.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -220,18 +220,14 @@ Target "RunTests" (fun _ ->
let projects =
let rawProjects = match (isWindows) with
| true -> !! "./test/*.Tests.Netstandard/*.Tests.csproj"
-- "./test/*.Tests.Netstandard/DotNetty.Transport.Tests.csproj"
-- "./test/*.Tests.Netstandard/DotNetty.Suite.Tests.csproj"
| _ -> !! "./test/*.Tests.Netstandard/*.Tests.csproj" // if you need to filter specs for Linux vs. Windows, do it here
-- "./test/*.Tests.Netstandard/DotNetty.Transport.Tests.csproj"
-- "./test/*.Tests.Netstandard/DotNetty.Suite.Tests.csproj"
rawProjects |> Seq.choose filterProjects

let runSingleProject project =
let arguments =
match (hasTeamCity) with
| true -> (sprintf "test -c Debug --no-build --logger:trx --logger:\"console;verbosity=normal\" --framework %s -- RunConfiguration.TargetPlatform=x64 --results-directory \"%s\" -- -parallel none -teamcity" testNetCoreVersion outputTests)
| false -> (sprintf "test -c Debug --no-build --logger:trx --logger:\"console;verbosity=normal\" --framework %s -- RunConfiguration.TargetPlatform=x64 --results-directory \"%s\" -- -parallel none" testNetCoreVersion outputTests)
| true -> (sprintf "test -c Debug --no-build --logger:trx --logger:\"console;verbosity=normal\" --framework %s -- RunConfiguration.TargetPlatform=x64 --results-directory \"%s\" -- -parallel none -teamcity" testNetVersion outputTests)
| false -> (sprintf "test -c Debug --no-build --logger:trx --logger:\"console;verbosity=normal\" --framework %s -- RunConfiguration.TargetPlatform=x64 --results-directory \"%s\" -- -parallel none" testNetVersion outputTests)

let result = ExecProcess(fun info ->
info.FileName <- "dotnet"
Expand Down
26 changes: 8 additions & 18 deletions examples/Http2Helloworld.Client/Http2ClientInitializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,30 +79,21 @@ protected void ConfigureEndOfPipeline(IChannelPipeline pipeline)
void ConfigureSsl(IChannel ch)
{
var pipeline = ch.Pipeline;
pipeline.AddLast("tls", new TlsHandler(
stream => new SslStream(stream, true, (sender, certificate, chain, errors) => true),
new ClientTlsSettings(_targetHost)
#if NETCOREAPP_2_0_GREATER
var tlsSettings = new ClientTlsSettings(_targetHost)
{
ApplicationProtocols = new List<SslApplicationProtocol>(new[]
{
ApplicationProtocols = new List<SslApplicationProtocol>(new[]
{
SslApplicationProtocol.Http2,
SslApplicationProtocol.Http11
})
}
#endif
));
SslApplicationProtocol.Http2,
SslApplicationProtocol.Http11
})
}.AllowAnyServerCertificate();
pipeline.AddLast("tls", new TlsHandler(tlsSettings));

// We must wait for the handshake to finish and the protocol to be negotiated before configuring
// the HTTP/2 components of the pipeline.
#if NETCOREAPP_2_0_GREATER
pipeline.AddLast(new ClientApplicationProtocolNegotiationHandler(this));
#else
this.ConfigureClearText(ch);
#endif
}

#if NETCOREAPP_2_0_GREATER
sealed class ClientApplicationProtocolNegotiationHandler : ApplicationProtocolNegotiationHandler
{
readonly Http2ClientInitializer _self;
Expand All @@ -126,7 +117,6 @@ protected override void ConfigurePipeline(IChannelHandlerContext ctx, SslApplica
throw new InvalidOperationException("unknown protocol: " + protocol);
}
}
#endif

/// <summary>
/// Configure the pipeline for a cleartext upgrade from HTTP to HTTP/2.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,15 @@ protected override void InitChannel(IChannel ch)
var pipeline = ch.Pipeline;
if (_cert is object)
{
pipeline.AddLast("tls", new TlsHandler(
stream => new SslStream(stream, true, (sender, certificate, chain, errors) => true),
new ClientTlsSettings(_targetHost)
var tlsSettings = new ClientTlsSettings(_targetHost)
{
ApplicationProtocols = new List<SslApplicationProtocol>(new[]
{
ApplicationProtocols = new List<SslApplicationProtocol>(new[]
{
SslApplicationProtocol.Http2,
//SslApplicationProtocol.Http11
})
}
));
SslApplicationProtocol.Http2,
SslApplicationProtocol.Http11
})
}.AllowAnyServerCertificate();
pipeline.AddLast("tls", new TlsHandler(tlsSettings));
}
var build = Http2FrameCodecBuilder.ForClient();
build.InitialSettings = Http2Settings.DefaultSettings(); // this is the default, but shows it can be changed.
Expand Down
24 changes: 9 additions & 15 deletions examples/Http2Helloworld.FrameServer/Http2ServerInitializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,17 @@ protected override void InitChannel(IChannel channel)
*/
void ConfigureSsl(IChannel ch)
{
ch.Pipeline.AddLast(new TlsHandler(new ServerTlsSettings(this.tlsCertificate)
#if NETCOREAPP_2_0_GREATER
var tlsSettings = new ServerTlsSettings(this.tlsCertificate)
{
ApplicationProtocols = new List<SslApplicationProtocol>(new[]
{
ApplicationProtocols = new List<SslApplicationProtocol>(new[]
{
SslApplicationProtocol.Http2,
SslApplicationProtocol.Http11
})
}
#endif
));
#if NETCOREAPP_2_0_GREATER
SslApplicationProtocol.Http2,
SslApplicationProtocol.Http11
})
};
tlsSettings.AllowAnyClientCertificate();
ch.Pipeline.AddLast(new TlsHandler(tlsSettings));
ch.Pipeline.AddLast(new Http2OrHttpHandler());
#else
this.ConfigureClearText(ch);
#endif

}

void ConfigureClearText(IChannel ch)
Expand Down
22 changes: 8 additions & 14 deletions examples/Http2Helloworld.MultiplexServer/Http2ServerInitializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,17 @@ protected override void InitChannel(IChannel channel)
*/
void ConfigureSsl(IChannel ch)
{
ch.Pipeline.AddLast(new TlsHandler(new ServerTlsSettings(this.tlsCertificate)
#if NETCOREAPP_2_0_GREATER
var tlsSettings = new ServerTlsSettings(this.tlsCertificate)
{
ApplicationProtocols = new List<SslApplicationProtocol>(new[]
{
SslApplicationProtocol.Http2,
SslApplicationProtocol.Http11
})
}
#endif
));
#if NETCOREAPP_2_0_GREATER
{
SslApplicationProtocol.Http2,
SslApplicationProtocol.Http11
})
};
//tlsSettings.AllowAnyClientCertificate();
ch.Pipeline.AddLast(new TlsHandler(tlsSettings));
ch.Pipeline.AddLast(new Http2OrHttpHandler());
#else
this.ConfigureClearText(ch);
#endif

}

void ConfigureClearText(IChannel ch)
Expand Down
24 changes: 9 additions & 15 deletions examples/Http2Helloworld.Server/Http2ServerInitializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,17 @@ protected override void InitChannel(IChannel channel)
*/
void ConfigureSsl(IChannel ch)
{
ch.Pipeline.AddLast(new TlsHandler(new ServerTlsSettings(this.tlsCertificate)
#if NETCOREAPP_2_0_GREATER
var tlsSettings = new ServerTlsSettings(this.tlsCertificate)
{
ApplicationProtocols = new List<SslApplicationProtocol>(new[]
{
ApplicationProtocols = new List<SslApplicationProtocol>(new[]
{
SslApplicationProtocol.Http2,
SslApplicationProtocol.Http11
})
}
#endif
));
#if NETCOREAPP_2_0_GREATER
SslApplicationProtocol.Http2,
SslApplicationProtocol.Http11
})
};
tlsSettings.AllowAnyClientCertificate();
ch.Pipeline.AddLast(new TlsHandler(tlsSettings));
ch.Pipeline.AddLast(new Http2OrHttpHandler());
#else
this.ConfigureClearText(ch);
#endif

}

void ConfigureClearText(IChannel ch)
Expand Down
1 change: 0 additions & 1 deletion examples/Http2Helloworld.Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ static async Task Main(string[] args)
+ $"\nProcessor Count : {Environment.ProcessorCount}\n");

bool useLibuv = ServerSettings.UseLibuv;
useLibuv = false;
Console.WriteLine("Transport type : " + (useLibuv ? "Libuv" : "Socket"));

if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
Expand Down
5 changes: 4 additions & 1 deletion examples/Http2Tiles/Http2RequestHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ protected virtual void SendResponse(IChannelHandlerContext ctx, string streamId,
HttpUtil.SetContentLength(response, response.Content.ReadableBytes);
StreamId(response, streamId);

ctx.Executor.Schedule(() => ctx.WriteAndFlushAsync(response), TimeSpan.FromMilliseconds(latency));
ctx.Executor.Schedule(() =>
{
ctx.WriteAndFlushAsync(response);
}, TimeSpan.FromMilliseconds(latency));
}

private static string StreamId(IFullHttpRequest request)
Expand Down
18 changes: 11 additions & 7 deletions examples/Http2Tiles/Http2Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace Http2Tiles
using System.Runtime.InteropServices;
using System.Security.Cryptography.X509Certificates;
using System.Threading.Tasks;
using DotNetty.Buffers;
using DotNetty.Handlers.Logging;
using DotNetty.Handlers.Tls;
using DotNetty.Transport.Bootstrapping;
Expand All @@ -25,19 +26,19 @@ public class Http2Server
{
public static readonly int PORT = int.Parse(ExampleHelper.Configuration["http2-port"]);

readonly IEventLoopGroup bossGroup;
readonly IEventLoopGroup workGroup;
readonly IEventLoopGroup _bossGroup;
readonly IEventLoopGroup _workGroup;

public Http2Server(IEventLoopGroup bossGroup, IEventLoopGroup workGroup)
{
this.bossGroup = bossGroup;
this.workGroup = workGroup;
_bossGroup = bossGroup;
_workGroup = workGroup;
}

public Task<IChannel> StartAsync()
{
var bootstrap = new ServerBootstrap();
bootstrap.Group(this.bossGroup, this.workGroup);
bootstrap.Group(_bossGroup, _workGroup);

if (ServerSettings.UseLibuv)
{
Expand All @@ -59,19 +60,22 @@ public Task<IChannel> StartAsync()

bootstrap
.Option(ChannelOption.SoBacklog, 1024)
//.Option(ChannelOption.Allocator, UnpooledByteBufferAllocator.Default)

.Handler(new LoggingHandler("LSTN"))

.ChildHandler(new ActionChannelInitializer<IChannel>(ch =>
{
ch.Pipeline.AddLast(new TlsHandler(new ServerTlsSettings(tlsCertificate)
var tlsSettings = new ServerTlsSettings(tlsCertificate)
{
ApplicationProtocols = new List<SslApplicationProtocol>(new[]
{
SslApplicationProtocol.Http2,
SslApplicationProtocol.Http11
})
}));
};
tlsSettings.AllowAnyClientCertificate();
ch.Pipeline.AddLast(new TlsHandler(tlsSettings));
ch.Pipeline.AddLast(new Http2OrHttpHandler());
}));

Expand Down
2 changes: 2 additions & 0 deletions examples/Http2Tiles/HttpServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace Http2Tiles
using System.Net;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using DotNetty.Buffers;
using DotNetty.Codecs.Http;
using DotNetty.Handlers.Logging;
using DotNetty.Transport.Bootstrapping;
Expand Down Expand Up @@ -54,6 +55,7 @@ public Task<IChannel> StartAsync()

bootstrap
.Option(ChannelOption.SoBacklog, 1024)
//.Option(ChannelOption.Allocator, UnpooledByteBufferAllocator.Default)

.Handler(new LoggingHandler("LSTN"))

Expand Down
2 changes: 1 addition & 1 deletion examples/WebSockets.Client/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ static async Task Main(string[] args)
IChannelPipeline pipeline = channel.Pipeline;
if (cert != null)
{
pipeline.AddLast("tls", new TlsHandler(stream => new SslStream(stream, true, (sender, certificate, chain, errors) => true), new ClientTlsSettings(targetHost)));
pipeline.AddLast("tls", new TlsHandler(new ClientTlsSettings(targetHost).AllowAnyServerCertificate()));
}

pipeline.AddLast("idleStateHandler", new IdleStateHandler(0, 0, 60));
Expand Down
2 changes: 1 addition & 1 deletion examples/WebSockets.Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ static async Task Main(string[] args)
IChannelPipeline pipeline = channel.Pipeline;
if (ServerSettings.IsSsl)
{
pipeline.AddLast(TlsHandler.Server(tlsCertificate));
pipeline.AddLast(TlsHandler.Server(tlsCertificate, true));
}

pipeline.AddLast("idleStateHandler", new IdleStateHandler(0, 0, 120));
Expand Down
Binary file modified shared/contoso.com.pfx
Binary file not shown.
Binary file modified shared/dotnetty.com.pfx
Binary file not shown.
6 changes: 0 additions & 6 deletions src/DotNetty.Buffers/CompositeByteBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -740,12 +740,6 @@ public override bool IsSingleIoBuffer
return _components[0].Buffer.IsSingleIoBuffer;
default:
return false;
//int count = 0;
//for (int i = 0; i < size; i++)
//{
// count += _components[i].Buffer.IoBufferCount;
//}
//return 1u >= (uint)count;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/DotNetty.Codecs.Http/HttpServerUpgradeHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ bool Upgrade(IChannelHandlerContext ctx, IFullHttpRequest request)
static readonly Action<Task, object> CloseOnFailureAction = (t, s) => CloseOnFailure(t, s);
static void CloseOnFailure(Task t, object s)
{
if (!t.IsSuccess())
if (t.IsFailure())
{
_ = ((IChannelHandlerContext)s).Channel.CloseAsync();
}
Expand Down
6 changes: 3 additions & 3 deletions src/DotNetty.Codecs.Http2/DefaultHttp2ConnectionEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -583,11 +583,11 @@ private static void NotifyLifecycleManagerOnError(Task future, IHttp2LifecycleMa
private static readonly Action<Task, object> NotifyLifecycleManagerOnErrorAction = (t, s) => NotifyLifecycleManagerOnError0(t, s);
private static void NotifyLifecycleManagerOnError0(Task t, object s)
{
var wrapped = ((IHttp2LifecycleManager, IChannelHandlerContext))s;
var (lm, ctx) = ((IHttp2LifecycleManager, IChannelHandlerContext))s;
var cause = t.Exception;
if (cause is object)
{
wrapped.Item1.OnError(wrapped.Item2, true, cause.InnerException);
lm.OnError(ctx, true, cause.InnerException);
}
}

Expand Down Expand Up @@ -681,7 +681,7 @@ public FlowControlledBase(DefaultHttp2ConnectionEncoder encoder, IHttp2Stream st
private static readonly Action<Task, object> LinkOutcomeContinuationAction = (t, s) => LinkOutcomeContinuation(t, s);
private static void LinkOutcomeContinuation(Task task, object state)
{
if (!task.IsSuccess())
if (task.IsFailure())
{
var self = (FlowControlledBase)state;
self.Error(self._owner.FlowController.ChannelHandlerContext, task.Exception.InnerException);
Expand Down
Loading