private static List <byte[]> Receive(AckSystem ackSystem, byte[] packet) { var messages = new List <byte[]>(); var type = (PacketType)packet[0]; switch (type) { case PacketType.Reliable: ackSystem.ReceiveReliable(packet, packet.Length, false); break; case PacketType.Ack: ackSystem.ReceiveAck(packet); break; case PacketType.Command: case PacketType.Unreliable: case PacketType.Notify: case PacketType.KeepAlive: default: break; } while (ackSystem.NextReliablePacket(out var received)) { HandleAllMessageInPacket(messages, received); } return(messages); }
public BadSocket(AckTestInstance instance1, AckTestInstance instance2) { ackSystem1 = instance1.ackSystem; ackSystem2 = instance2.ackSystem; connection1 = instance1.connection; connection2 = instance2.connection; }
public void SetUp() { var config = new Config(); maxSequence = (ushort)((1 << config.SequenceSize) - 1); connection = new SubIRawConnection(); ackSystem = new AckSystem(connection, config, new Time(), bufferPool); message = createRandomData(1); ackSystem.SendNotify(message); // should have got 1 packet Assert.That(connection.packets.Count, Is.EqualTo(1)); packet = connection.packets[0]; // should have sent data Assert.That(packet, Is.Not.Null); }
public void SetUp() { config = new Config(); var mtu = MAX_PACKET_SIZE; var bigSize = (int)(mtu * 1.5f); message = CreateBigData(1, bigSize); var sender = new AckTestInstance(); sender.connection = new SubIRawConnection(); sender.ackSystem = new AckSystem(sender.connection, config, MAX_PACKET_SIZE, new Time(), bufferPool); sender.ackSystem.SendReliable(message); packet1 = sender.packet(0); packet2 = sender.packet(1); var connection = new SubIRawConnection(); ackSystem = new AckSystem(connection, config, MAX_PACKET_SIZE, new Time(), bufferPool); }
public static INotifyToken SendNotify(this AckSystem ackSystem, byte[] array) { return(ackSystem.SendNotify(array, 0, array.Length)); }
public static void SendReliable(this AckSystem ackSystem, byte[] array) { ackSystem.SendReliable(array, 0, array.Length); }
public void SetUp() { connection = new SubIRawConnection(); ackSystem = new AckSystem(connection, default, new Time());
private static List <byte[]> Update(ref int processed, List <byte[]> ToSend, SubIRawConnection connection, AckSystem ackSystem, float dropChance, float skipChance) { var count1 = connection.packets.Count; for (var i = processed; i < count1; i++) { var packet = connection.packets[i]; if (UnityEngine.Random.value > dropChance) { ToSend.Add(packet); } } processed = count1; var newPackets = new List <byte[]>(); for (var i = 0; i < ToSend.Count; i++) { if (UnityEngine.Random.value < skipChance) { continue; } newPackets.AddRange(Receive(ackSystem, ToSend[i])); ToSend.RemoveAt(i); i--; } return(newPackets); }