Skip to content

Commit a9be9b5

Browse files
committed
Added padding frame. Added PMTU padding to initial packet.
1 parent 78b16c1 commit a9be9b5

File tree

5 files changed

+22
-6
lines changed

5 files changed

+22
-6
lines changed

QuicNet.Infrastructure/Frames/PaddingFrame.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@ public class PaddingFrame : Frame
1313

1414
public override void Decode(ByteArray array)
1515
{
16-
throw new NotImplementedException();
16+
byte type = array.ReadByte();
1717
}
1818

1919
public override byte[] Encode()
2020
{
21-
throw new NotImplementedException();
21+
List<byte> data = new List<byte>();
22+
data.Add(Type);
23+
24+
return data.ToArray();
2225
}
2326
}
2427
}

QuicNet.Infrastructure/PacketCreator.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using QuicNet.Infrastructure.Packets;
1+
using QuicNet.Infrastructure.Frames;
2+
using QuicNet.Infrastructure.Packets;
23
using QuicNet.Infrastructure.Settings;
34
using System;
45
using System.Collections.Generic;
@@ -23,6 +24,10 @@ public InitialPacket CreateInitialPacket(byte sourceConnectionId, byte destinati
2324
packet.Version = QuicVersion.CurrentVersion;
2425

2526
int length = packet.Encode().Length;
27+
int padding = QuicSettings.PMTU - length;
28+
29+
for (int i = 0; i < padding; i++)
30+
packet.AttachFrame(new PaddingFrame());
2631

2732
return packet;
2833
}

QuicNet.Infrastructure/Packets/Packet.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public virtual void DecodeFrames(ByteArray array)
3636
FrameParser factory = new FrameParser(array);
3737
Frame result;
3838
int frames = 0;
39-
while (array.HasData() && frames <= QuicSettings.MaximumFramesPerPacket)
39+
while (array.HasData() && frames <= QuicSettings.PMTU)
4040
{
4141
result = factory.GetFrame();
4242
if (result != null)

QuicNet/QuicListener.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,15 @@ private void ProcessInitialPacket(Packet packet, IPEndPoint endPoint)
9595
return;
9696
}
9797

98-
9998
InitialPacket cast = packet as InitialPacket;
10099
InitialPacket ip = _packetCreator.CreateInitialPacket(0, cast.SourceConnectionId);
101-
if (ConnectionPool.AddConnection(cast.SourceConnectionId) == true)
100+
101+
// Protocol violation if the initial packet is smaller than the PMTU. (pt. 14 / 16th draft)
102+
if (cast.Encode().Length < QuicSettings.PMTU)
103+
{
104+
ip.AttachFrame(new ConnectionCloseFrame(ErrorCode.PROTOCOL_VIOLATION, "PMTU have not been reached."));
105+
}
106+
else if (ConnectionPool.AddConnection(cast.SourceConnectionId) == true)
102107
{
103108
// We're including the maximum possible stream id during the connection handshake. (4.5 / 16th draft)
104109
ip.AttachFrame(new MaxStreamIdFrame(QuicSettings.MaximumStreamId, StreamType.ServerBidirectional));

QuickNet.Console/Program.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ static void Main(string[] args)
2929
PacketNumber = 777521,
3030
TokenLength = 0
3131
};
32+
33+
packet = new PacketCreator().CreateInitialPacket(124, 0);
34+
3235
ConnectionCloseFrame frame = new ConnectionCloseFrame(ErrorCode.SERVER_BUSY, "The server is too busy to process your request.");
3336
MaxStreamIdFrame msidframe = new MaxStreamIdFrame(144123, StreamType.ClientUnidirectional);
3437
//packet.AttachFrame(frame);

0 commit comments

Comments
 (0)