Skip to content

Commit

Permalink
Various Network module changes:
Browse files Browse the repository at this point in the history
- BandwidthPriorities enum to not have a fake value for the length. Updated associated logic to use the maximum enum value + 1.
- Fixed logic that converts NetSendFlags to BandwidthPriorities.  It wasn't ignoring the Reiable/Droppable/Urgent flags properly.  Also, changed the logic so that it doesn't run for Ack and Reliable packets since those were overwriting the value anyway.
- Changed the 08 packets to be sent reliably.  This is different than what ASSS does.  I'm not sure if this is right and will need to investigate further.
- DumpPk method to output the text representation in its own column properly for lines that have < 16 bytes.
- Added an overload for SendToOne which takes a Span.  Found that Socket.SendTo does not allow passing a Span yet, but it looks like Microsoft may add it eventually (dotnet/runtime#938).  If they do, then it might be possible to switched everything from byte[] and ArraySegment<byte> to Span<byte>. Right now, the extra copy to a byte[] defeats the purpose.
  • Loading branch information
gigamon-dev committed Sep 27, 2020
1 parent 9243953 commit 86a2b42
Show file tree
Hide file tree
Showing 5 changed files with 318 additions and 108 deletions.
10 changes: 9 additions & 1 deletion src/Core/ComponentInterfaces/INetwork.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,22 @@ public class NetClientStats
public interface INetwork : IComponentInterface
{
/// <summary>
/// To send data to a single player
/// To send data to a single player.
/// </summary>
/// <param name="p">player to send to</param>
/// <param name="data">data to send</param>
/// <param name="len">length of data to send</param>
/// <param name="flags">flags specifying options for the send</param>
void SendToOne(Player p, byte[] data, int len, NetSendFlags flags);

/// <summary>
/// To send data to a single player.
/// </summary>
/// <param name="p">player to send to</param>
/// <param name="data">data to send</param>
/// <param name="flags">flags specifying options for the send</param>
void SendToOne(Player p, Span<byte> data, NetSendFlags flags);

/// <summary>
/// To send data to players in a specific arena or
/// To send data to players in all arenas.
Expand Down
8 changes: 7 additions & 1 deletion src/Core/ComponentInterfaces/INetworkEncryption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ public interface IEncrypt : IComponentInterface
/// <returns>length of the resulting data</returns>
int Encrypt(Player p, byte[] data, int len);

int Encrypt(Player p, ArraySegment<byte> data);
/// <summary>
/// data is encrypted in place
/// </summary>
/// <param name="p"></param>
/// <param name="data"></param>
/// <returns>length of the resulting data</returns>
int Encrypt(Player p, Span<byte> data);

/// <summary>
/// data is decrypted in place
Expand Down
5 changes: 2 additions & 3 deletions src/Core/Modules/BandwidthLimit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public enum BandwidthPriorities
UnreliableHigh,
Reliable,
Ack,
NumPriorities
}

[CoreModuleInfo]
Expand Down Expand Up @@ -116,7 +115,7 @@ private class BWLimit : IBWLimit
/// <summary>
/// this array represents the percentage of traffic that is allowed to be at or lower than each priority level
/// </summary>
public static int[] PriorityLimits = new int[Enum.GetNames(typeof(BandwidthPriorities)).Length];
public static int[] PriorityLimits = new int[(int)((BandwidthPriorities[])Enum.GetValues(typeof(BandwidthPriorities))).Max() + 1];

/// <summary>
/// we need to know how many packets the client is able to buffer
Expand All @@ -130,7 +129,7 @@ private class BWLimit : IBWLimit
#endregion

private int _limit;
private int[] _avail = new int[Enum.GetNames(typeof(BandwidthPriorities)).Length];
private int[] _avail = new int[(int)((BandwidthPriorities[])Enum.GetValues(typeof(BandwidthPriorities))).Max() + 1];
private int _maxavail;
private bool _hitlimit;
private DateTime _sincetime;
Expand Down
Loading

0 comments on commit 86a2b42

Please sign in to comment.