Skip to content
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
11 changes: 2 additions & 9 deletions perf/benchmarkapps/GrpcAspNetCoreServer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,8 @@ public static IHostBuilder CreateHostBuilder(string[] args)
{
Console.WriteLine($"Console Logging enabled with level '{logLevel}'");

loggerFactory
#if NET5_0_OR_GREATER
.AddSimpleConsole(o => o.TimestampFormat = "ss.ffff ")
#else
.AddConsole(o => o.TimestampFormat = "ss.ffff ")
#endif
.SetMinimumLevel(logLevel);
loggerFactory.AddSimpleConsole(o => o.TimestampFormat = "ss.ffff ")
.SetMinimumLevel(logLevel);
}
})
.UseDefaultServiceProvider((context, options) =>
Expand Down Expand Up @@ -163,7 +158,6 @@ private static void ConfigureListenOptions(ListenOptions listenOptions, IConfigu
}
});
}
#if NET6_0_OR_GREATER
else if (protocol.Equals("h3", StringComparison.OrdinalIgnoreCase))
{
listenOptions.Protocols = HttpProtocols.Http1AndHttp2AndHttp3;
Expand All @@ -177,7 +171,6 @@ private static void ConfigureListenOptions(ListenOptions listenOptions, IConfigu
}
});
}
#endif
else if (protocol.Equals("h2c", StringComparison.OrdinalIgnoreCase))
{
listenOptions.Protocols = HttpProtocols.Http2;
Expand Down
12 changes: 1 addition & 11 deletions perf/benchmarkapps/GrpcAspNetCoreServer/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#region Copyright notice and license
#region Copyright notice and license

// Copyright 2019 The gRPC Authors
//
Expand All @@ -21,9 +21,7 @@
using Grpc.Shared;
using Grpc.Testing;
using Grpc.Tests.Shared;
#if NET5_0_OR_GREATER
using Microsoft.AspNetCore.Authentication.Certificate;
#endif
using Newtonsoft.Json;

namespace GrpcAspNetCoreServer;
Expand All @@ -41,10 +39,8 @@ public void ConfigureServices(IServiceCollection services)
{
services.AddGrpc(o =>
{
#if NET5_0_OR_GREATER
// Small performance benefit to not add catch-all routes to handle UNIMPLEMENTED for unknown services
o.IgnoreUnknownServices = true;
#endif
});
services.Configure<RouteOptions>(c =>
{
Expand All @@ -54,7 +50,6 @@ public void ConfigureServices(IServiceCollection services)
services.AddSingleton<BenchmarkServiceImpl>();
services.AddControllers();

#if NET5_0_OR_GREATER
bool.TryParse(_config["enableCertAuth"], out var enableCertAuth);
if (enableCertAuth)
{
Expand All @@ -67,7 +62,6 @@ public void ConfigureServices(IServiceCollection services)
options.AllowedCertificateTypes = CertificateTypes.All;
});
}
#endif
}

public void Configure(IApplicationBuilder app, IHostApplicationLifetime applicationLifetime)
Expand All @@ -83,14 +77,12 @@ public void Configure(IApplicationBuilder app, IHostApplicationLifetime applicat

app.UseRouting();

#if NET5_0_OR_GREATER
bool.TryParse(_config["enableCertAuth"], out var enableCertAuth);
if (enableCertAuth)
{
app.UseAuthentication();
app.UseAuthorization();
}
#endif

#if GRPC_WEB
bool.TryParse(_config["enableGrpcWeb"], out var enableGrpcWeb);
Expand Down Expand Up @@ -139,12 +131,10 @@ public void Configure(IApplicationBuilder app, IHostApplicationLifetime applicat

private void ConfigureAuthorization(IEndpointConventionBuilder builder)
{
#if NET5_0_OR_GREATER
bool.TryParse(_config["enableCertAuth"], out var enableCertAuth);
if (enableCertAuth)
{
builder.RequireAuthorization();
}
#endif
}
}
6 changes: 2 additions & 4 deletions perf/benchmarkapps/GrpcClient/ClientOptions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#region Copyright notice and license
#region Copyright notice and license

// Copyright 2019 The gRPC Authors
//
Expand All @@ -23,10 +23,8 @@ namespace GrpcClient;
public class ClientOptions
{
public Uri? Url { get; set; }
#if NET5_0_OR_GREATER
public string? UdsFileName { get; set; }
public string? NamedPipeName { get; set; }
#endif
public int Connections { get; set; }
public int Warmup { get; set; }
public int Duration { get; set; }
Expand All @@ -41,4 +39,4 @@ public class ClientOptions
public GrpcClientType GrpcClientType { get; set; }
public int Streams { get; set; }
public int Deadline { get; set; }
}
}
6 changes: 1 addition & 5 deletions perf/benchmarkapps/GrpcClient/NamedPipeConnectionFactory.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#region Copyright notice and license
#region Copyright notice and license

// Copyright 2019 The gRPC Authors
//
Expand All @@ -19,8 +19,6 @@
using System.IO.Pipes;
using System.Security.Principal;

#if NET5_0_OR_GREATER

namespace GrpcClient;

public class NamedPipeConnectionFactory
Expand Down Expand Up @@ -56,5 +54,3 @@ public async ValueTask<Stream> ConnectAsync(SocketsHttpConnectionContext _,
}
}
}

#endif
11 changes: 1 addition & 10 deletions perf/benchmarkapps/GrpcClient/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -465,10 +465,6 @@ private static ChannelBase CreateChannel(string target)
var address = useTls ? "https://" : "http://";
address += target;

#if NETCOREAPP3_1
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
#endif

var httpClientHandler = new SocketsHttpHandler();
httpClientHandler.UseProxy = false;
httpClientHandler.AllowAutoRedirect = false;
Expand All @@ -479,7 +475,7 @@ private static ChannelBase CreateChannel(string target)
var clientCertificates = X509CertificateLoader.LoadPkcs12CollectionFromFile(certPath, "1111");
httpClientHandler.SslOptions.ClientCertificates = clientCertificates;
}
#if NET5_0_OR_GREATER

if (!string.IsNullOrEmpty(_options.UdsFileName))
{
var connectionFactory = new UnixDomainSocketConnectionFactory(new UnixDomainSocketEndPoint(ResolveUdsPath(_options.UdsFileName)));
Expand All @@ -490,7 +486,6 @@ private static ChannelBase CreateChannel(string target)
var connectionFactory = new NamedPipeConnectionFactory(_options.NamedPipeName);
httpClientHandler.ConnectCallback = connectionFactory.ConnectAsync;
}
#endif

httpClientHandler.SslOptions.RemoteCertificateValidationCallback =
(object sender, X509Certificate? certificate, X509Chain? chain, SslPolicyErrors sslPolicyErrors) => true;
Expand All @@ -509,11 +504,7 @@ private static ChannelBase CreateChannel(string target)

return GrpcChannel.ForAddress(address, new GrpcChannelOptions
{
#if NET5_0_OR_GREATER
HttpHandler = httpMessageHandler,
#else
HttpClient = new HttpClient(httpMessageHandler),
#endif
LoggerFactory = _loggerFactory,
HttpVersion = versionOverride
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#region Copyright notice and license
#region Copyright notice and license

// Copyright 2019 The gRPC Authors
//
Expand All @@ -19,8 +19,6 @@
using System.Net;
using System.Net.Sockets;

#if NET5_0_OR_GREATER

namespace GrpcClient;

public class UnixDomainSocketConnectionFactory
Expand Down Expand Up @@ -48,5 +46,3 @@ public async ValueTask<Stream> ConnectAsync(SocketsHttpConnectionContext _, Canc
}
}
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,7 @@ public static class GrpcEndpointRouteBuilderExtensions
/// <typeparam name="TService">The service type to map requests to.</typeparam>
/// <param name="builder">The <see cref="IEndpointRouteBuilder"/> to add the route to.</param>
/// <returns>A <see cref="GrpcServiceEndpointConventionBuilder"/> for endpoints associated with the service.</returns>
public static GrpcServiceEndpointConventionBuilder MapGrpcService<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(GrpcProtocolConstants.ServiceAccessibility)]
#endif
TService>(this IEndpointRouteBuilder builder) where TService : class
public static GrpcServiceEndpointConventionBuilder MapGrpcService<[DynamicallyAccessedMembers(GrpcProtocolConstants.ServiceAccessibility)] TService>(this IEndpointRouteBuilder builder) where TService : class
{
ArgumentNullThrowHelper.ThrowIfNull(builder);

Expand Down
9 changes: 1 addition & 8 deletions src/Grpc.AspNetCore.Server/GrpcMethodMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,7 @@ public sealed class GrpcMethodMetadata
/// </summary>
/// <param name="serviceType">The implementing service type.</param>
/// <param name="method">The method representation.</param>
public GrpcMethodMetadata(
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(GrpcProtocolConstants.ServiceAccessibility)]
#endif
Type serviceType,
IMethod method)
public GrpcMethodMetadata([DynamicallyAccessedMembers(GrpcProtocolConstants.ServiceAccessibility)] Type serviceType, IMethod method)
{
ArgumentNullThrowHelper.ThrowIfNull(serviceType);
ArgumentNullThrowHelper.ThrowIfNull(method);
Expand All @@ -50,9 +45,7 @@ public GrpcMethodMetadata(
/// <summary>
/// Gets the implementing service type.
/// </summary>
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(GrpcProtocolConstants.ServiceAccessibility)]
#endif
public Type ServiceType { get; }

/// <summary>
Expand Down
8 changes: 2 additions & 6 deletions src/Grpc.AspNetCore.Server/IGrpcServiceActivator.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#region Copyright notice and license
#region Copyright notice and license

// Copyright 2019 The gRPC Authors
//
Expand All @@ -25,11 +25,7 @@ namespace Grpc.AspNetCore.Server;
/// A <typeparamref name="TGrpcService"/> activator abstraction.
/// </summary>
/// <typeparam name="TGrpcService">The service type.</typeparam>
public interface IGrpcServiceActivator<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(GrpcProtocolConstants.ServiceAccessibility)]
#endif
TGrpcService> where TGrpcService : class
public interface IGrpcServiceActivator<[DynamicallyAccessedMembers(GrpcProtocolConstants.ServiceAccessibility)] TGrpcService> where TGrpcService : class
{
/// <summary>
/// Creates a service.
Expand Down
12 changes: 2 additions & 10 deletions src/Grpc.AspNetCore.Server/InterceptorCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,7 @@ public class InterceptorCollection : Collection<InterceptorRegistration>
/// </summary>
/// <typeparam name="TInterceptor">The interceptor type.</typeparam>
/// <param name="args">The list of arguments to pass to the interceptor constructor when creating an instance.</param>
public void Add<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(InterceptorRegistration.InterceptorAccessibility)]
#endif
TInterceptor>(params object[] args) where TInterceptor : Interceptor
public void Add<[DynamicallyAccessedMembers(InterceptorRegistration.InterceptorAccessibility)] TInterceptor>(params object[] args) where TInterceptor : Interceptor
{
Add(typeof(TInterceptor), args);
}
Expand All @@ -47,11 +43,7 @@ public void Add<
/// </summary>
/// <param name="interceptorType">The interceptor type.</param>
/// <param name="args">The list of arguments to pass to the interceptor constructor when creating an instance.</param>
public void Add(
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(InterceptorRegistration.InterceptorAccessibility)]
#endif
Type interceptorType, params object[] args)
public void Add([DynamicallyAccessedMembers(InterceptorRegistration.InterceptorAccessibility)] Type interceptorType, params object[] args)
{
ArgumentNullThrowHelper.ThrowIfNull(interceptorType);

Expand Down
12 changes: 1 addition & 11 deletions src/Grpc.AspNetCore.Server/InterceptorRegistration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,11 @@ namespace Grpc.AspNetCore.Server;
/// </summary>
public class InterceptorRegistration
{
#if NET5_0_OR_GREATER
internal const DynamicallyAccessedMemberTypes InterceptorAccessibility = DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.PublicMethods;
#endif

internal object[] _args;

internal InterceptorRegistration(
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(InterceptorAccessibility)]
#endif
Type type, object[] arguments)
internal InterceptorRegistration([DynamicallyAccessedMembers(InterceptorAccessibility)]Type type, object[] arguments)
{
ArgumentNullThrowHelper.ThrowIfNull(type);
ArgumentNullThrowHelper.ThrowIfNull(arguments);
Expand All @@ -58,9 +52,7 @@ internal InterceptorRegistration(
/// <summary>
/// Get the type of the interceptor.
/// </summary>
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(InterceptorAccessibility)]
#endif
public Type Type { get; }

/// <summary>
Expand All @@ -71,12 +63,10 @@ internal InterceptorRegistration(
private IGrpcInterceptorActivator? _interceptorActivator;
private ObjectFactory? _factory;

#if NET5_0_OR_GREATER
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern",
Justification = "Type parameter members are preserved with DynamicallyAccessedMembers on InterceptorRegistration.Type property.")]
[UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode",
Justification = "Type definition is explicitly specified and type argument is always an Interceptor type.")]
#endif
internal IGrpcInterceptorActivator GetActivator(IServiceProvider serviceProvider)
{
// Not thread safe. Side effect is resolving the service twice.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@

namespace Grpc.AspNetCore.Server.Internal.CallHandlers;

internal class ClientStreamingServerCallHandler<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(GrpcProtocolConstants.ServiceAccessibility)]
#endif
TService, TRequest, TResponse> : ServerCallHandlerBase<TService, TRequest, TResponse>
internal class ClientStreamingServerCallHandler<[DynamicallyAccessedMembers(GrpcProtocolConstants.ServiceAccessibility)] TService, TRequest, TResponse> : ServerCallHandlerBase<TService, TRequest, TResponse>
where TRequest : class
where TResponse : class
where TService : class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@

namespace Grpc.AspNetCore.Server.Internal.CallHandlers;

internal class DuplexStreamingServerCallHandler<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(GrpcProtocolConstants.ServiceAccessibility)]
#endif
TService, TRequest, TResponse> : ServerCallHandlerBase<TService, TRequest, TResponse>
internal class DuplexStreamingServerCallHandler<[DynamicallyAccessedMembers(GrpcProtocolConstants.ServiceAccessibility)] TService, TRequest, TResponse> : ServerCallHandlerBase<TService, TRequest, TResponse>
where TRequest : class
where TResponse : class
where TService : class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@

namespace Grpc.AspNetCore.Server.Internal.CallHandlers;

internal abstract class ServerCallHandlerBase<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(GrpcProtocolConstants.ServiceAccessibility)]
#endif
TService, TRequest, TResponse>
internal abstract class ServerCallHandlerBase<[DynamicallyAccessedMembers(GrpcProtocolConstants.ServiceAccessibility)] TService, TRequest, TResponse>
where TService : class
where TRequest : class
where TResponse : class
Expand All @@ -60,10 +56,7 @@ public Task HandleCallAsync(HttpContext httpContext)
}

if (!GrpcProtocolConstants.IsHttp2(httpContext.Request.Protocol)
#if NET6_0_OR_GREATER
&& !GrpcProtocolConstants.IsHttp3(httpContext.Request.Protocol)
#endif
)
&& !GrpcProtocolConstants.IsHttp3(httpContext.Request.Protocol))
{
return ProcessNonHttp2Request(httpContext);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@

namespace Grpc.AspNetCore.Server.Internal.CallHandlers;

internal class ServerStreamingServerCallHandler<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(GrpcProtocolConstants.ServiceAccessibility)]
#endif
TService, TRequest, TResponse> : ServerCallHandlerBase<TService, TRequest, TResponse>
internal class ServerStreamingServerCallHandler<[DynamicallyAccessedMembers(GrpcProtocolConstants.ServiceAccessibility)] TService, TRequest, TResponse> : ServerCallHandlerBase<TService, TRequest, TResponse>
where TRequest : class
where TResponse : class
where TService : class
Expand Down
Loading