Skip to content

Commit dd56ba1

Browse files
Add websocket modes to dotnet-dsrouter (#3461)
* Add "dsrouter server-websocket" command boilerplate * More WebSocketStreamAdapter work add an interface for it in the Client library, and expose a way to check that it's conncted. * update after rebase * Move WebSocketServer bits to a separate assembly outside dotnet-dsrouter * use a factory for creating WebSocketServer instances, instead of env var * Remove IpcServerWebSocketServerRouterFactory Use IpcServerTcpServerRouterFactory since everything is sufficiently abstracted * Suppress generic host startup messages * Factor out common run loop for dsrouter commands * Add client-webserver mode In this mode the tracing command will start a domain socket and the runtime will connect to it: ``` dotnet trace collect --diagnostic-port /tmp/sock ``` Then ``` dotnet run --project src/Tools/dotnet-dsrouter -- client-websocket -ipcc /tmp/sock -ws http://localhost:8088/diagnostics ``` And finally launch the app in the browser http://localhost:8000 (or whatever you configured) In this mode, the app should be configured without suspending on startup ``` <WasmExtraConfig Include="environmentVariables" Value=' { "DOTNET_DiagnosticPorts": "ws://localhost:8088/diagnostics", }' /> ``` * Remove IpcWebSocketEndPointer class * Pass LogLevel from dotnet-dsrouter to the webserver * Add comments, remove unused interface * make the IWebSocketServer interface internal and IVT for Microsoft.Diagnostics.WebSocketServer that holds the implementation * Start/Stop the web server from the toplevel Instead of trying to start the webserver when the diagnostics code first calls AcceptConnection, just start the webserver when we start running, and stop it when the router is done. This also matches the expected use by WasmAppHost (`dotnet run`) which will start/stop the webserver itself, and we will just provide middleware for diagnostics * Use net6.0 logging for dotnet-dsrouter * fix help string for dsrouter client-websocket command Co-authored-by: Johan Lorensson <[email protected]>
1 parent 8647f5f commit dd56ba1

18 files changed

+1093
-280
lines changed

eng/Versions.props

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@
5050
<MicrosoftDiagnosticsTracingTraceEventVersion>2.0.64</MicrosoftDiagnosticsTracingTraceEventVersion>
5151
<!-- Use pinned version to avoid picking up latest (which doesn't support netcoreapp3.1) during source-build -->
5252
<MicrosoftExtensionsLoggingPinnedVersion>2.1.1</MicrosoftExtensionsLoggingPinnedVersion>
53+
<!-- dotnet-dsrouter needs a net6.0 version of logging -->
54+
<MicrosoftExtensionsLoggingVersion>6.0.0</MicrosoftExtensionsLoggingVersion>
55+
<MicrosoftExtensionsLoggingConsoleVersion>6.0.0</MicrosoftExtensionsLoggingConsoleVersion>
5356
<!-- Need version that understands UseAppFilters sentinel. -->
5457
<MicrosoftExtensionsLoggingEventSourceVersion>5.0.1</MicrosoftExtensionsLoggingEventSourceVersion>
5558
<SystemCommandLineVersion>2.0.0-beta1.20468.1</SystemCommandLineVersion>

src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsIpc/IpcServerTransport.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@ internal abstract class IpcServerTransport : IDisposable
1717
private IIpcServerTransportCallbackInternal _callback;
1818
private bool _disposed;
1919

20-
public static IpcServerTransport Create(string address, int maxConnections, bool enableTcpIpProtocol, IIpcServerTransportCallbackInternal transportCallback = null)
20+
public static IpcServerTransport Create(string address, int maxConnections, ReversedDiagnosticsServer.Kind kind, IIpcServerTransportCallbackInternal transportCallback = null)
2121
{
22-
if (!enableTcpIpProtocol || !IpcTcpSocketEndPoint.IsTcpIpEndPoint(address))
22+
if (kind == ReversedDiagnosticsServer.Kind.WebSocket)
23+
{
24+
return new IpcWebSocketServerTransport(address, maxConnections, transportCallback);
25+
}
26+
else if (kind == ReversedDiagnosticsServer.Kind.Ipc || !IpcTcpSocketEndPoint.IsTcpIpEndPoint(address))
2327
{
2428
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
2529
{
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System;
5+
using System.IO;
6+
using System.Threading;
7+
using System.Threading.Tasks;
8+
9+
namespace Microsoft.Diagnostics.NETCore.Client;
10+
11+
internal sealed class IpcWebSocketServerTransport : IpcServerTransport
12+
{
13+
public IpcWebSocketServerTransport(string address, int maxAllowedConnections, IIpcServerTransportCallbackInternal transportCallback = null)
14+
: base(transportCallback)
15+
{
16+
}
17+
18+
protected override void Dispose(bool disposing)
19+
{
20+
}
21+
22+
public override async Task<Stream> AcceptAsync(CancellationToken token)
23+
{
24+
WebSocketServer.IWebSocketServer server = WebSocketServer.WebSocketServerProvider.GetWebSocketServerInstance();
25+
return await server.AcceptConnection(token);
26+
}
27+
}

0 commit comments

Comments
 (0)