Repository navigation
Expand file tree
/
Copy pathIBandwidthLimiterProvider.cs
More file actions
88 lines (79 loc) · 3.11 KB
/
Copy pathIBandwidthLimiterProvider.cs
File metadata and controls
88 lines (79 loc) · 3.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
using System.Diagnostics;
using System.Text;
namespace SS.Core.ComponentInterfaces
{
/// <summary>
/// Represents priority of network traffic.
/// </summary>
public enum BandwidthPriority
{
UnreliableLow = 0,
Unreliable,
UnreliableHigh,
Reliable,
Ack,
}
/// <summary>
/// Interface for a service that assists in limiting network bandwidth.
/// </summary>
public interface IBandwidthLimiter
{
/// <summary>
/// Refreshes the current state of how many much bandwidth is available to be used for each priority.
/// </summary>
/// <param name="asOf">The <see cref="Stopwatch"/> timestamp to recalculate stats as of.</param>
void Iter(long asOf);
/// <summary>
/// Checks if a number of <paramref name="bytes"/> can be sent for a given <paramref name="priority"/>.
/// </summary>
/// <remarks>
/// Stats are modified if the <paramref name="bytes"/> can be sent and <paramref name="modify"/> is <see langword="true"/>.
/// </remarks>
/// <param name="bytes">The number of bytes of the data.</param>
/// <param name="priority">The priority of the data.</param>
/// <param name="modify">Whether to modify the stats.</param>
/// <returns><see langword="true"/> if the data should be sent; otherwise, <see langword="false"/>.</returns>
bool Check(int bytes, BandwidthPriority priority, bool modify);
/// <summary>
/// Adjusts stats for when an ACK is received.
/// </summary>
void AdjustForAck();
/// <summary>
/// Adjusts stats for when a reliable packet is resent.
/// </summary>
void AdjustForRetry();
/// <summary>
/// Gets the max # of reliable packets that can be sent at the same time without being ACK'd yet.
/// </summary>
/// <remarks>
/// <para>
/// E.g., if X is the lowest pending (not yet sent OR sent but not yet acknolwedged) reliable sequence # for a connection,
/// then only allow sending of reliable packets with a sequence # less than or equal to:
/// X + <see cref="GetSendWindowSize"/>.
/// </para>
/// </remarks>
/// <returns>The window size.</returns>
int GetSendWindowSize();
/// <summary>
/// Gets info about the limiter.
/// </summary>
/// <param name="sb">The <see cref="StringBuilder"/> to populate with info.</param>
void GetInfo(StringBuilder sb);
}
/// <summary>
/// Interface for a service that provides <see cref="IBandwidthLimiter"/>s.
/// </summary>
public interface IBandwidthLimiterProvider : IComponentInterface
{
/// <summary>
/// Gets a bandwidth limiter for a single connection.
/// </summary>
/// <returns>A bandwidth limiter.</returns>
IBandwidthLimiter New();
/// <summary>
/// Frees a bandwidth limiter.
/// </summary>
/// <param name="limiter">The limiter to free.</param>
void Free(IBandwidthLimiter limiter);
}
}