Skip to content

Commit

Permalink
Draft-23: Changed LongHeaderPacket.
Browse files Browse the repository at this point in the history
  • Loading branch information
Vect0rZ committed Sep 18, 2019
1 parent 80b823f commit 5a9d8e2
Showing 1 changed file with 5 additions and 36 deletions.
41 changes: 5 additions & 36 deletions QuicNet.Infrastructure/Packets/LongHeaderPacket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,14 @@ public class LongHeaderPacket : Packet
{
public override byte Type => 0xC0; // 1100 0000

public byte DCIL_SCIL { get; set; }
public byte DCID { get; set; }
public byte DestinationConnectionId { get; set; }
public byte SCID { get; set; }
public byte SourceConnectionId { get; set; }
public VariableInteger TokenLength { get; set; }
public byte[] Token { get; set; }
public VariableInteger Length { get; set; }
public UInt32 PacketNumber { get; set; }

public PacketType PacketType { get; set; }
public LongHeaderPacket(PacketType packetType)
{
DCIL_SCIL = 0;
PacketType = packetType;
}

Expand All @@ -31,21 +27,6 @@ public override void Decode(byte[] packet)
PacketType = (PacketType)(type & 0x30);

Version = array.ReadUInt32();
DCIL_SCIL = array.ReadByte();

if ((DCIL_SCIL & 0xF0) != 0)
DestinationConnectionId = array.ReadByte();
if ((DCIL_SCIL & 0x0F) != 0)
SourceConnectionId = array.ReadByte();

TokenLength = array.ReadVariableInteger();
if (TokenLength != 0)
Token = array.ReadBytes((int)TokenLength.Value);

Length = array.ReadVariableInteger();
PacketNumber = array.ReadUInt32();

Length = Length - 4;

this.DecodeFrames(array);
}
Expand All @@ -55,27 +36,15 @@ public override byte[] Encode()
byte[] frames = EncodeFrames();

List<byte> result = new List<byte>();

result.Add(EncodeTypeField());
result.AddRange(ByteUtilities.GetBytes(Version));

if (DestinationConnectionId > 0)
DCIL_SCIL = (byte)(DCIL_SCIL | 0x50);
if (SourceConnectionId > 0)
DCIL_SCIL = (byte)(DCIL_SCIL | 0x05);

result.Add(DCIL_SCIL);

if (DestinationConnectionId > 0)
if (DCID > 0)
result.Add(DestinationConnectionId);
if (SourceConnectionId > 0)
if (SCID > 0)
result.Add(SourceConnectionId);

byte[] tokenLength = new VariableInteger(0);
byte[] length = new VariableInteger(4 + (UInt64)frames.Length);

result.AddRange(tokenLength);
result.AddRange(length);
result.AddRange(ByteUtilities.GetBytes(PacketNumber));
result.AddRange(frames);

return result.ToArray();
Expand Down

0 comments on commit 5a9d8e2

Please sign in to comment.