RynthSuite as of 2026-11-23 (internal 327a8263): release 2026.11.23.1

This commit is contained in:
Tom Bohar 2026-11-23 11:13:51 -05:00
commit 759009b569
196 changed files with 21066 additions and 1021 deletions

View file

@ -181,6 +181,7 @@ public sealed partial class RynthNetPlugin : RynthPluginBase
for (int i = 0; i < 64 && node.TryDequeueEvent(out NetEvent e); i++)
HandleEvent(node, e, now);
FlushJoins(now);
for (int i = 0; i < 16 && _localCommands.TryDequeue(out var queued); i++)
{
@ -299,13 +300,36 @@ public sealed partial class RynthNetPlugin : RynthPluginBase
// ── Network events ──────────────────────────────────────────────────────
/// <summary>A client's "connected" line waits this long, so a link that drops at once says nothing.</summary>
internal const long JoinSayDelayMs = 3000;
private readonly Dictionary<string, long> _joinsToSay = new(); // node id -> when it joined (not said yet)
private readonly HashSet<string> _saidJoined = new(); // node ids whose "connected" was said
/// <summary>Every tick: says "X connected." for each client whose link has held JoinSayDelayMs.</summary>
private void FlushJoins(long now)
{
if (_joinsToSay.Count == 0) return;
List<string>? done = null;
foreach (var kv in _joinsToSay)
{
if (now - kv.Value < JoinSayDelayMs) continue;
(done ??= new List<string>()).Add(kv.Key);
if (_loggedIn && _peerNames.TryGetValue(kv.Key, out string? name) && name.Length > 0)
{
ChatLine($"{name} connected.");
_saidJoined.Add(kv.Key);
}
}
if (done != null) foreach (string id in done) _joinsToSay.Remove(id);
}
private void HandleEvent(NetNode node, NetEvent e, long now)
{
switch (e.Kind)
{
case NetEventKind.PeerJoined:
_peerNames[e.NodeId] = e.From;
if (_loggedIn && e.From.Length > 0) ChatLine($"{e.From} connected.");
if (_loggedIn && e.From.Length > 0) _joinsToSay[e.NodeId] = now; // said once it has held (FlushJoins)
break;
case NetEventKind.PeerUpdated:
{
@ -315,13 +339,18 @@ public sealed partial class RynthNetPlugin : RynthPluginBase
if (before == e.From) break;
_peerNames[e.NodeId] = e.From;
if (!_loggedIn) break;
if (before.Length == 0) ChatLine($"{e.From} connected.");
else if (e.From.Length == 0) ChatLine($"{before} logged out.");
if (before.Length == 0) _joinsToSay[e.NodeId] = now;
else if (!_saidJoined.Contains(e.NodeId)) _joinsToSay[e.NodeId] = now; // not said yet: said under the new name
else if (e.From.Length == 0) { ChatLine($"{before} logged out."); _saidJoined.Remove(e.NodeId); }
else ChatLine($"{before} is now {e.From}.");
break;
}
case NetEventKind.PeerLeft:
if (_loggedIn && e.From.Length > 0) ChatLine($"{e.From} disconnected ({e.Text}).");
// Only a client whose "connected" was said is said to go: a link that dropped within
// JoinSayDelayMs said nothing either way (R-20261122-193027-b795: a connect and a disconnect
// line every second while muling).
_joinsToSay.Remove(e.NodeId);
if (_saidJoined.Remove(e.NodeId) && _loggedIn && e.From.Length > 0) ChatLine($"{e.From} disconnected ({e.Text}).");
_peerNames.Remove(e.NodeId);
_rate.Remove(e.NodeId);
break;

View file

@ -0,0 +1,19 @@
using System;
namespace RynthCore.Plugin.RynthNet.Transport;
/// <summary>
/// A dialed peer that drops right after connecting (R-20261122-193027-b795): muling, another client
/// hung up within a few ms of each connect and the next scan (1 s) dialed it again, a connect and a
/// disconnect every second. A link that dies within <see cref="FlapLifeMs"/> of its connect waits
/// before the next dial, <see cref="FirstDelayMs"/> then doubling to <see cref="MaxDelayMs"/>; one that
/// lasts <see cref="StableLifeMs"/> clears the count. Pure (the tests run it).
/// </summary>
internal static class FlapBackoff
{
public const long FlapLifeMs = 10_000, StableLifeMs = 30_000, FirstDelayMs = 2_000, MaxDelayMs = 60_000;
/// <summary>The wait before redialing after <paramref name="flaps"/> short-lived links in a row.</summary>
public static long DelayMs(int flaps)
=> flaps <= 0 ? 0 : Math.Min(MaxDelayMs, FirstDelayMs << Math.Min(flaps - 1, 10));
}

View file

@ -455,6 +455,7 @@ public sealed class NetNode : IDisposable
if (!IsRunning) { client.Dispose(); return; }
peer = new PeerConnection(this, client, outbound: true, expectedNodeId: nodeId, kernelPid: pid);
_connections.Add(peer);
_dialedPipes[nodeId] = name;
}
peer.Start(Wire.Hello(NodeId, Pid, _identity));
}
@ -645,12 +646,31 @@ public sealed class NetNode : IDisposable
return true;
}
// ── A peer that drops right after connecting (FlapBackoff.cs, R-20261122-193027-b795) ─────────
private readonly Dictionary<string, string> _dialedPipes = new(); // expected node id -> the pipe dialed
private readonly Dictionary<string, int> _flaps = new(); // pipe name -> short-lived links in a row
/// <summary>Under _lock: a dialed link closed; a short-lived one sets the wait before the next dial.</summary>
private void NoteDialedClosed(PeerConnection peer, long now)
{
if (!peer.Outbound || !_dialedPipes.TryGetValue(peer.ExpectedNodeId, out string? pipe)) return;
_dialedPipes.Remove(peer.ExpectedNodeId);
long life = now - peer.ConnectedAtMs;
if (life >= FlapBackoff.StableLifeMs) { _flaps.Remove(pipe); return; }
if (life >= FlapBackoff.FlapLifeMs) return;
int n = _flaps.TryGetValue(pipe, out int f) ? f + 1 : 1;
_flaps[pipe] = n;
_badPipes[pipe] = now + FlapBackoff.DelayMs(n);
if (n == 3) Log($"[RynthNet] {pipe} keeps dropping right after connecting: redialing it less often (up to every {FlapBackoff.MaxDelayMs / 1000} s).");
}
internal void OnPeerClosed(PeerConnection peer, string reason)
{
bool wasJoined = false;
NodeIdentity identity;
lock (_lock)
{
NoteDialedClosed(peer, NowMs);
_connections.Remove(peer);
if (peer.Joined && _peers.TryGetValue(peer.NodeId, out PeerConnection? current) && ReferenceEquals(current, peer))
{