@@ -7,6 +7,11 @@ namespace Discord.Rest
/// </summary>
/// </summary>
public class GatewayLimits
public class GatewayLimits
{
{
/// <summary>
/// Creates a new <see cref="GatewayLimits"/> with the default values.
/// </summary>
public static GatewayLimits Default => new GatewayLimits();
/// <summary>
/// <summary>
/// Gets or sets the global limits for the gateway rate limiter.
/// Gets or sets the global limits for the gateway rate limiter.
/// </summary>
/// </summary>
@@ -15,6 +20,7 @@ namespace Discord.Rest
/// and it is per websocket.
/// and it is per websocket.
/// </remarks>
/// </remarks>
public GatewayLimit Global { get; set; }
public GatewayLimit Global { get; set; }
/// <summary>
/// <summary>
/// Gets or sets the limits of Identify requests.
/// Gets or sets the limits of Identify requests.
/// </summary>
/// </summary>
@@ -23,6 +29,7 @@ namespace Discord.Rest
/// also per account.
/// also per account.
/// </remarks>
/// </remarks>
public GatewayLimit Identify { get; set; }
public GatewayLimit Identify { get; set; }
/// <summary>
/// <summary>
/// Gets or sets the limits of Presence Update requests.
/// Gets or sets the limits of Presence Update requests.
/// </summary>
/// </summary>
@@ -31,11 +38,35 @@ namespace Discord.Rest
/// and status (online, idle, etc)
/// and status (online, idle, etc)
/// </remarks>
/// </remarks>
public GatewayLimit PresenceUpdate { get; set; }
public GatewayLimit PresenceUpdate { get; set; }
/// <summary>
/// Gets or sets the name of the master <see cref="System.Threading.Semaphore"/>
/// used by identify.
/// </summary>
/// <remarks>
/// It is used to define what slave <see cref="System.Threading.Semaphore"/>
/// is free to run for concurrent identify requests.
/// </remarks>
public string IdentifyMasterSemaphoreName { get; set; }
/// <summary>
/// <summary>
/// Gets or sets the name of the <see cref="System.Threading.Semaphore"/> used by identify.
/// Gets or sets the name of the slave <see cref="System.Threading.Semaphore"/>
/// used by identify.
/// </summary>
/// </summary>
/// <remarks>
/// If the maximum concurrency is higher than one and you are using the sharded client,
/// it will be dinamilly renamed to fit the necessary needs.
/// </remarks>
public string IdentifySemaphoreName { get; set; }
public string IdentifySemaphoreName { get; set; }
/// <summary>
/// Gets or sets the maximum identify concurrency.
/// </summary>
/// <remarks>
/// This limit is provided by Discord.
/// </remarks>
public int IdentifyMaxConcurrency { get; set; }
/// <summary>
/// <summary>
/// Initializes a new <see cref="GatewayLimits"/> with the default values.
/// Initializes a new <see cref="GatewayLimits"/> with the default values.
/// </summary>
/// </summary>
@@ -44,10 +75,26 @@ namespace Discord.Rest
Global = new GatewayLimit(120, 60);
Global = new GatewayLimit(120, 60);
Identify = new GatewayLimit(1, 5);
Identify = new GatewayLimit(1, 5);
PresenceUpdate = new GatewayLimit(5, 60);
PresenceUpdate = new GatewayLimit(5, 60);
IdentifyMasterSemaphoreName = Guid.NewGuid().ToString();
IdentifySemaphoreName = Guid.NewGuid().ToString();
IdentifySemaphoreName = Guid.NewGuid().ToString();
IdentifyMaxConcurrency = 1;
}
}
internal static GatewayLimits GetOrCreate(GatewayLimits limits)
=> limits ?? new GatewayLimits();
internal GatewayLimits(GatewayLimits limits)
{
Global = new GatewayLimit(limits.Global.Count, limits.Global.Seconds);
Identify = new GatewayLimit(limits.Identify.Count, limits.Identify.Seconds);
PresenceUpdate = new GatewayLimit(limits.PresenceUpdate.Count, limits.PresenceUpdate.Seconds);
IdentifyMasterSemaphoreName = limits.IdentifyMasterSemaphoreName;
IdentifySemaphoreName = limits.IdentifySemaphoreName;
IdentifyMaxConcurrency = limits.IdentifyMaxConcurrency;
}
internal static GatewayLimits GetOrCreate(GatewayLimits? limits)
=> limits ?? Default;
public GatewayLimits Clone()
=> new GatewayLimits(this);
}
}
}
}