using System;
namespace RynthCore.Plugin.RynthNet.Transport;
///
/// 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 of its connect waits
/// before the next dial, then doubling to ; one that
/// lasts clears the count. Pure (the tests run it).
///
internal static class FlapBackoff
{
public const long FlapLifeMs = 10_000, StableLifeMs = 30_000, FirstDelayMs = 2_000, MaxDelayMs = 60_000;
/// The wait before redialing after short-lived links in a row.
public static long DelayMs(int flaps)
=> flaps <= 0 ? 0 : Math.Min(MaxDelayMs, FirstDelayMs << Math.Min(flaps - 1, 10));
}