Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion QuicNet.Infrastructure/Frames/MaxDataFrame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,24 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace QuicNet.Infrastructure.Frames
{
public class MaxDataFrame : Frame
{
/// <inheritdoc/>
public override byte Type => 0x10;

public VariableInteger MaximumData { get; set; }

/// <inheritdoc/>
public override void Decode(ByteArray array)
{
array.ReadByte();
MaximumData = array.ReadVariableInteger();
}

/// <inheritdoc/>
public override byte[] Encode()
{
List<byte> result = new List<byte>();
Expand Down
13 changes: 8 additions & 5 deletions QuicNet.Infrastructure/Frames/PingFrame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,28 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace QuicNet.Infrastructure.Frames
{
/// <summary>
/// PING frame with Type==0x01
/// </summary>
public class PingFrame : Frame
{
/// <inheritdoc/>
public override byte Type => 0x01;

/// <inheritdoc/>
public override void Decode(ByteArray array)
{
byte type = array.ReadByte();
}

/// <inheritdoc/>
public override byte[] Encode()
{
List<byte> data = new List<byte>();
data.Add(Type);

return data.ToArray();
byte[] res = new byte[] { Type };
return res;
}
}
}
14 changes: 8 additions & 6 deletions QuickNet.Tests.ConsoleServer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
using QuicNet.Infrastructure.PacketProcessing;
using QuicNet.Infrastructure.Packets;
using QuicNet.Streams;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace QuickNet.Tests.ConsoleServer
{
Expand All @@ -29,17 +29,19 @@ static void ClientConnected(QuicConnection connection)

static void StreamOpened(QuicStream stream)
{
Console.WriteLine("Stream Opened");
Console.WriteLine("Stream Opened. StreamID[{0}]", stream.StreamId);
stream.OnStreamDataReceived += StreamDataReceived;
}

static void StreamDataReceived(QuicStream stream, byte[] data)
{
Console.WriteLine("Stream Data Received: ");
string decoded = Encoding.UTF8.GetString(data);
Console.WriteLine(decoded);
string response = "Response from server: " + decoded.ToUpperInvariant();

Console.WriteLine("Stream Data Received from StreamID[{0}]\r\n <-- {1}\r\n --> {2}\r\n",
stream.StreamId, decoded, response);

stream.Send(Encoding.UTF8.GetBytes("Ping back from server."));
stream.Send(Encoding.UTF8.GetBytes(response));
}

static void Example()
Expand All @@ -49,7 +51,7 @@ static void Example()

listener.Start();

Console.ReadKey();
Console.ReadLine();
}

static void Main(string[] args)
Expand Down
21 changes: 16 additions & 5 deletions QuickNet.Utilities/StreamId.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace QuickNet.Utilities
{
/// <summary>
/// Stream type (Client or Server, Bi-directional or One-directional)
/// </summary>
public enum StreamType
{
ClientBidirectional = 0x0,
Expand All @@ -14,17 +15,20 @@ public enum StreamType
ServerUnidirectional = 0x3
}

/// <summary>
/// Stream identifier combines actual ID and stream type
/// </summary>
public class StreamId
{
public UInt64 Id { get; }
public UInt64 IntegerValue { get; }
public StreamType Type { get; private set; }
public StreamType Type { get; }

public StreamId(UInt64 id, StreamType type)
{
Id = id;
Type = type;
IntegerValue = id << 2 | (UInt64)type;
IntegerValue = (id << 2) | (UInt64)type;
}

public static implicit operator byte[](StreamId id)
Expand All @@ -49,7 +53,7 @@ public static implicit operator StreamId(VariableInteger integer)

public static byte[] Encode(UInt64 id, StreamType type)
{
UInt64 identifier = id << 2 | (UInt64)type;
UInt64 identifier = (id << 2) | (UInt64)type;

byte[] result = ByteUtilities.GetBytes(identifier);

Expand All @@ -68,5 +72,12 @@ public static StreamId Decode(byte[] data)

return result;
}

/// <inheritdoc/>
public override string ToString()
{
string res = "ID:" + Id;
return res;
}
}
}