Skip to content

Commit

Permalink
Add websocket modes to dotnet-dsrouter (#3461)
Browse files Browse the repository at this point in the history
* 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 <lateralusx.github@gmail.com>
  • Loading branch information
lambdageek and lateralusX authored Nov 15, 2022
1 parent 8647f5f commit dd56ba1
Show file tree
Hide file tree
Showing 18 changed files with 1,093 additions and 280 deletions.
3 changes: 3 additions & 0 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
<MicrosoftDiagnosticsTracingTraceEventVersion>2.0.64</MicrosoftDiagnosticsTracingTraceEventVersion>
<!-- Use pinned version to avoid picking up latest (which doesn't support netcoreapp3.1) during source-build -->
<MicrosoftExtensionsLoggingPinnedVersion>2.1.1</MicrosoftExtensionsLoggingPinnedVersion>
<!-- dotnet-dsrouter needs a net6.0 version of logging -->
<MicrosoftExtensionsLoggingVersion>6.0.0</MicrosoftExtensionsLoggingVersion>
<MicrosoftExtensionsLoggingConsoleVersion>6.0.0</MicrosoftExtensionsLoggingConsoleVersion>
<!-- Need version that understands UseAppFilters sentinel. -->
<MicrosoftExtensionsLoggingEventSourceVersion>5.0.1</MicrosoftExtensionsLoggingEventSourceVersion>
<SystemCommandLineVersion>2.0.0-beta1.20468.1</SystemCommandLineVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ internal abstract class IpcServerTransport : IDisposable
private IIpcServerTransportCallbackInternal _callback;
private bool _disposed;

public static IpcServerTransport Create(string address, int maxConnections, bool enableTcpIpProtocol, IIpcServerTransportCallbackInternal transportCallback = null)
public static IpcServerTransport Create(string address, int maxConnections, ReversedDiagnosticsServer.Kind kind, IIpcServerTransportCallbackInternal transportCallback = null)
{
if (!enableTcpIpProtocol || !IpcTcpSocketEndPoint.IsTcpIpEndPoint(address))
if (kind == ReversedDiagnosticsServer.Kind.WebSocket)
{
return new IpcWebSocketServerTransport(address, maxConnections, transportCallback);
}
else if (kind == ReversedDiagnosticsServer.Kind.Ipc || !IpcTcpSocketEndPoint.IsTcpIpEndPoint(address))
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;

namespace Microsoft.Diagnostics.NETCore.Client;

internal sealed class IpcWebSocketServerTransport : IpcServerTransport
{
public IpcWebSocketServerTransport(string address, int maxAllowedConnections, IIpcServerTransportCallbackInternal transportCallback = null)
: base(transportCallback)
{
}

protected override void Dispose(bool disposing)
{
}

public override async Task<Stream> AcceptAsync(CancellationToken token)
{
WebSocketServer.IWebSocketServer server = WebSocketServer.WebSocketServerProvider.GetWebSocketServerInstance();
return await server.AcceptConnection(token);
}
}
Loading

0 comments on commit dd56ba1

Please sign in to comment.