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: 11 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,17 @@ the same pattern anyway, so there is one way to do this in the tree. `mui-crawl
exception and says so at the call site: a process that makes one request and exits *is* the handler's
lifetime.

**The probe's WebSocket dial is not a third HTTP client either.** `ProbeLine` upgrades a `ws://` or
`wss://` URL to telnet over a WebSocket (`telnet.mudstandards.org`, TelnetNegotiationCore 4.12+) with
a `SocketsHttpHandler` that lives for one dial and whose `ConnectCallback` dials **the addresses the
scope guard vetted**, never a fresh lookup of the name — the same rule the TCP path follows. No
proxy, no cookies, no redirects. It is a probe transport, not a fetch: nothing it reads is anything
but a telnet session. `mui-probe wss://…` dials one by hand. A server that picks `gmcp.` or
`terminal.mudstandards.org` (Evennia) is read through TelnetNegotiationCore's client bridge, which
drops our telnet commands rather than typing them at a login. The crawl loop's own check of a declared
`WEBSOCKET` URL is `WebSocketProbe`, a handshake and nothing after it (migration 0045,
`WebSocketEndpointWriter`), not this.

`game_icon` and `icon_attempt` are the **two tables here that may be dropped and refilled**. The fact
is the `ICON` field; those are bytes fetched from the URL it names and our own notes about fetching
them, so §7.5's "nothing is ever deleted" does not reach either. A failed fetch writes **nothing
Expand Down
10 changes: 8 additions & 2 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,15 @@
3.0.0 inflates a stream started with MCCP v1's marker, which both Children of the Night servers
send in answer to DO COMPRESS2; before it, everything after their connect screens, MSSP report
included, arrived as zlib read as text.

4.13 runs every read loop through one ITelnetTransport and hands back a TelnetConnection, so
the probe's socket, TLS tunnel and WebSocket differ in ProbeLine and nowhere else. OnStarting
gives callbacks their interpreter before the first byte is read, which PromptSink used to
argue around. 4.13.4 reads a WebSocket server that picked gmcp or terminal rather than
telnet (Evennia) through a bridge, which ProbeLine offers.
-->
<PackageVersion Include="TelnetNegotiationCore" Version="4.6.1" />
<PackageVersion Include="MarkupString.Ansi" Version="2.31.0" />
<PackageVersion Include="TelnetNegotiationCore" Version="4.13.5" />
<PackageVersion Include="MarkupString.Ansi" Version="2.31.3" />

<!--
No logging, hosting or DI *abstractions* here. The crawler is an in-process BackgroundService in
Expand Down
37 changes: 36 additions & 1 deletion src/MUI.Catalog/Games/Views.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,20 @@ public sealed record ProvenanceChip(
/// <summary>
/// One capability, measured beside declared. Two columns, never merged into one badge.
/// </summary>
/// <param name="WebSocket">
/// For the <c>WEBSOCKET</c> row only: which of the three answers the endpoints give. Null on every other
/// row.
/// </param>
/// <param name="SubProtocol">
/// For <see cref="WebSocketSupport.Standard"/>: the mudstandards.org subprotocol the server chose.
/// </param>
public sealed record CapabilityRow(
string Protocol,
CapabilityState Measured,
CapabilityState Declared,
DateTimeOffset? LastConfirmedAt)
DateTimeOffset? LastConfirmedAt,
WebSocketSupport? WebSocket = null,
string? SubProtocol = null)
{
public bool Disagrees =>
(Measured, Declared) is (CapabilityState.Absent, CapabilityState.Present)
Expand All @@ -52,6 +61,32 @@ public enum CapabilityState
Absent,
}

/// <summary>
/// What a game's WebSocket endpoints showed, as the capability matrix reports it.
/// </summary>
/// <remarks>
/// Read from the endpoints the crawl recorded (migration 0045), never from the declaration: a URL that
/// did not upgrade writes no endpoint, so it is <see cref="Unknown"/> here, the same as a URL nobody
/// declared. That is a fact about what we could see, not about the game (rule 5).
/// </remarks>
public enum WebSocketSupport
{
/// <summary>No WebSocket endpoint we have measured.</summary>
Unknown,

/// <summary>
/// A WebSocket upgraded, but the server chose none of the mudstandards.org subprotocols, so a
/// client has to guess what it speaks (websockify, an Apache proxy).
/// </summary>
None,

/// <summary>
/// The server chose a mudstandards.org subprotocol (<c>telnet.</c>, <c>gmcp.</c>, <c>terminal.</c>
/// or <c>json.mudstandards.org</c>) when we offered them.
/// </summary>
Standard,
}

/// <summary>One hour of the activity grid. The three states of spec §5.4, ready to render.</summary>
public sealed record ActivityCell(int DayOfWeek, int Hour, int? Count, bool Probed)
{
Expand Down
2 changes: 1 addition & 1 deletion src/MUI.Catalog/Persistence/Fields/FieldRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static class CapabilityFields
public static IReadOnlyList<string> Names { get; } =
[
"ANSI", "ATCP", "CHARSET", "EOR", "GMCP", "MCCP", "MCP", "MSDP", "MSP", "MSSP", "MXP",
"NAWS", "NEW-ENVIRON", "PUEBLO", "TLS", "TTYPE", "UTF-8", "VT100",
"NAWS", "NEW-ENVIRON", "PUEBLO", "TLS", "TTYPE", "UTF-8", "VT100", "WEBSOCKET",
"XTERM 256 COLORS", "ZMP",
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ private async Task<GamePage> PageAsync(
StringComparison.Ordinal),
ReachableFraction: Reachability.FractionReachable(intervals, RecentlyReachable * 3, now),
LongestOutage: Reachability.LongestOutage(intervals, RecentlyReachable * 3, now),
Capabilities: CapabilitiesOf(fields),
Capabilities: CapabilitiesOf(fields, endpoints),
Activity: activity,
Declared: DeclaredOf(fields, now),
Changes: changes.Select(Describe).ToList(),
Expand Down Expand Up @@ -271,12 +271,24 @@ private sealed record NeighbourRow(
/// <see cref="CapabilityState.Unknown"/> and renders as a dash — nothing said either way is not
/// the same fact as "it is not there", and only one of them is a measurement.
/// </summary>
private static IReadOnlyList<CapabilityRow> CapabilitiesOf(IReadOnlyList<GameField> fields)
private static IReadOnlyList<CapabilityRow> CapabilitiesOf(
IReadOnlyList<GameField> fields,
IReadOnlyList<GameEndpoint> endpoints)
{
var rows = new List<CapabilityRow>();

foreach (var capability in CapabilityFields.Names)
{
if (capability is WebSocketCapability)
{
if (WebSocketRow(Winner(fields, CapabilityFields.Declared(capability)), endpoints) is { } row)
{
rows.Add(row);
}

continue;
}

var measured = Winner(fields, CapabilityFields.Measured(capability));
var declared = Winner(fields, CapabilityFields.Declared(capability));

Expand All @@ -298,12 +310,76 @@ private static IReadOnlyList<CapabilityRow> CapabilitiesOf(IReadOnlyList<GameFie

return rows;

static CapabilityState StateOf(GameField? field) => field?.Value switch
}

private static CapabilityState StateOf(GameField? field) => field?.Value switch
{
"true" => CapabilityState.Present,
"false" => CapabilityState.Absent,
_ => CapabilityState.Unknown,
};

/// <summary>The capability whose measured side comes from endpoints rather than a handshake.</summary>
private const string WebSocketCapability = "WEBSOCKET";

/// <summary>
/// The <c>WEBSOCKET</c> row: declared from MSSP like any other, measured from the WebSocket
/// endpoints the crawl recorded, which no telnet handshake can show.
/// </summary>
/// <remarks>
/// <para>
/// Only endpoints that are not gone count. <see cref="WebSocketSupport.Standard"/> when any of them
/// chose a mudstandards.org subprotocol, <see cref="WebSocketSupport.None"/> when they upgraded but
/// chose none, and <see cref="WebSocketSupport.Unknown"/> when there are none, which is also what a
/// declared URL that never upgraded looks like. The measured state is never
/// <see cref="CapabilityState.Absent"/>: a failed upgrade writes no endpoint, so nothing here can
/// say a game has no WebSocket (rule 5).
/// </para>
/// <para>
/// No row at all when nothing was declared and nothing measured, as for every other capability.
/// </para>
/// </remarks>
private static CapabilityRow? WebSocketRow(GameField? declared, IReadOnlyList<GameEndpoint> endpoints)
{
var live = endpoints.Where(e => e.IsWebSocket && e.State is not EndpointState.Gone).ToList();

if (declared is null && live.Count == 0)
{
return null;
}

var standard = live
.Where(e => IsStandard(e.SubProtocol))
.OrderBy(e => e.SubProtocol == "telnet.mudstandards.org" ? 0 : 1)
.ThenByDescending(e => e.LastSeenAt)
.FirstOrDefault();

var support = (standard, live.Count) switch
{
"true" => CapabilityState.Present,
"false" => CapabilityState.Absent,
_ => CapabilityState.Unknown,
({ }, _) => WebSocketSupport.Standard,
(null, > 0) => WebSocketSupport.None,
_ => WebSocketSupport.Unknown,
};

DateTimeOffset? seen = live.Count > 0 ? live.Max(e => e.LastSeenAt) : null;
DateTimeOffset? confirmed = (seen, declared?.LastConfirmedAt) switch
{
({ } s, { } d) => s > d ? s : d,
({ } s, null) => s,
(null, { } d) => d,
_ => null,
};

return new CapabilityRow(
WebSocketCapability,
support is WebSocketSupport.Unknown ? CapabilityState.Unknown : CapabilityState.Present,
StateOf(declared),
confirmed,
support,
standard?.SubProtocol);

static bool IsStandard(string? subProtocol) =>
subProtocol is not null && subProtocol.EndsWith(".mudstandards.org", StringComparison.OrdinalIgnoreCase);
}

private IReadOnlyDictionary<string, ProvenanceChip> DeclaredOf(
Expand Down
11 changes: 10 additions & 1 deletion src/MUI.Crawl/Telnet/DialFailure.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Net.Sockets;
using System.Net.WebSockets;
using System.Security.Authentication;

namespace MUI.Crawl;
Expand All @@ -22,6 +23,14 @@ public static FailureDetail Classify(Exception error)
{
ArgumentNullException.ThrowIfNull(error);

// A WebSocket dial reports a failed connect or handshake as a WebSocketException around an
// HttpRequestException around the socket's or the tunnel's own error. The innermost is the
// measurement; the wrappers only say which layer noticed.
if (error is WebSocketException or HttpRequestException && error.InnerException is { } inner)
{
return Classify(inner);
}

return error switch
{
// TryAgain (EAI_AGAIN) is the transient DNS failure; without it here, a resolver retry
Expand All @@ -45,7 +54,7 @@ or SocketError.NoData
or SocketError.HostUnreachable
or SocketError.NetworkDown,
} => new(DialFailureCause.NoRoute, error.Message),
// Only reachable on a dial that asked for TLS: nothing else here builds an SslStream.
// Only reachable on a dial that asked for TLS, raw or wss://.
// "It answered and would not do TLS" is a fact about the far end, so it gets the word
// the catalogue's own cause vocabulary has carried since migration 0028.
AuthenticationException => new(DialFailureCause.Tls, error.Message),
Expand Down
Loading
Loading