-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Closed
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractionsIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractionsenhancementThis issue represents an ask for new feature or an enhancement to an existing oneThis issue represents an ask for new feature or an enhancement to an existing one
Milestone
Description
This issue is inspired by @deanward81's post at https://bakedbean.org.uk/posts/2021-05-airdrop-anywhere-part-3/
Is your feature request related to a problem? Please describe.
We recently exposed the Listen socket via a connection feature. In similar vein, we should probably also expose the Listen Socket via a server feature.
The workaround today is to replace the TransportFactory (code snippet copied from the blog post)
// Actual implementation: https://github.com/deanward81/AirDropAnywhere/blob/2021-05-17-receiving-files/src/AirDropAnywhere.Core/HttpTransport/AwdlSocketTransportFactory.cs
internal class AwdlSocketTransportFactory : IConnectionListenerFactory
{
private readonly IConnectionListenerFactory _connectionListenerFactory;
private readonly FieldInfo _listenSocketField;
public AwdlSocketTransportFactory(IOptions<SocketTransportOptions> options, ILoggerFactory loggerFactory)
{
_connectionListenerFactory = new SocketTransportFactory(options, loggerFactory);
// HACK: this merry little reflective dance is because of sealed internal classes
// and no extensibility points, yay :/
_listenSocketField = typeof(SocketTransportFactory).Assembly
.GetType("Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketConnectionListener")
.GetField("_listenSocket", BindingFlags.Instance | BindingFlags.NonPublic);
}
public async ValueTask<IConnectionListener> BindAsync(EndPoint endpoint, CancellationToken cancellationToken = default)
{
var transport = await _connectionListenerFactory.BindAsync(endpoint, cancellationToken);
// HACK: fix up the listen socket to support listening on AWDL
var listenSocket = (Socket?) _listenSocketField.GetValue(transport);
if (listenSocket != null)
{
listenSocket.SetAwdlSocketOption();
}
return transport;
}
}
Describe the solution you'd like
I haven't thought this through yet. 😅 I know an IStartupFilter
is too early since the server hasn't started yet
Additional context
Here's a fun read: https://bakedbean.org.uk/posts/2021-05-airdrop-anywhere-part-3/
deanward81
Metadata
Metadata
Assignees
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractionsIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractionsenhancementThis issue represents an ask for new feature or an enhancement to an existing oneThis issue represents an ask for new feature or an enhancement to an existing one