Skip to content

Commit

Permalink
Switch of target framework to netstandard2.0, code cleanup/ refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Juri Furer committed Aug 28, 2019
1 parent d87da20 commit 0cc365b
Show file tree
Hide file tree
Showing 74 changed files with 673 additions and 1,546 deletions.
10 changes: 2 additions & 8 deletions QuicNet.Infrastructure/ErrorCodes.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace QuicNet.Infrastructure
namespace QuicNet.Infrastructure
{
public enum ErrorCode : UInt16
public enum ErrorCode : ushort
{
NO_ERROR = 0x0,
INTERNAL_ERROR = 0x1,
Expand Down
8 changes: 0 additions & 8 deletions QuicNet.Infrastructure/Exceptions/ProtocolException.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace QuicNet.Infrastructure.Exceptions
{
public class ProtocolException : Exception
{
public ProtocolException()
{
}

public ProtocolException(string message) : base(message)
{
}
Expand Down
137 changes: 97 additions & 40 deletions QuicNet.Infrastructure/FrameParser.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
using QuickNet.Utilities;
using QuicNet.Infrastructure.Frames;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace QuicNet.Infrastructure
{
public class FrameParser
{
private ByteArray _array;
private readonly ByteArray _array;

public FrameParser(ByteArray array)
{
Expand All @@ -20,40 +15,102 @@ public FrameParser(ByteArray array)
public Frame GetFrame()
{
Frame result;
byte frameType = _array.PeekByte();
switch(frameType)
var frameType = _array.PeekByte();
switch (frameType)
{
case 0x00: result = new PaddingFrame(); break;
case 0x01: result = new PingFrame(); break;
case 0x02: result = new AckFrame(); break;
case 0x03: result = new AckFrame(); break;
case 0x04: result = new ResetStreamFrame(); break;
case 0x05: result = new StopSendingFrame(); break;
case 0x06: result = new CryptoFrame(); break;
case 0x07: result = new NewTokenFrame(); break;
case 0x08: result = new StreamFrame(); break;
case 0x09: result = new StreamFrame(); break;
case 0x0a: result = new StreamFrame(); break;
case 0x0b: result = new StreamFrame(); break;
case 0x0c: result = new StreamFrame(); break;
case 0x0d: result = new StreamFrame(); break;
case 0x0e: result = new StreamFrame(); break;
case 0x0f: result = new StreamFrame(); break;
case 0x10: result = new MaxDataFrame(); break;
case 0x11: result = new MaxStreamDataFrame(); break;
case 0x12: result = new MaxStreamsFrame(); break;
case 0x13: result = new MaxStreamsFrame(); break;
case 0x14: result = new DataBlockedFrame(); break;
case 0x15: result = new StreamDataBlockedFrame(); break;
case 0x16: result = new StreamsBlockedFrame(); break;
case 0x17: result = new StreamsBlockedFrame(); break;
case 0x18: result = new NewConnectionIdFrame(); break;
case 0x19: result = new RetireConnectionIdFrame(); break;
case 0x1a: result = new PathChallengeFrame(); break;
case 0x1b: result = new PathResponseFrame(); break;
case 0x1c: result = new ConnectionCloseFrame(); break;
case 0x1d: result = new ConnectionCloseFrame(); break;
default: result = null; break;
case 0x00:
result = new PaddingFrame();
break;
case 0x01:
result = new PingFrame();
break;
case 0x02:
result = new AckFrame();
break;
case 0x03:
result = new AckFrame();
break;
case 0x04:
result = new ResetStreamFrame();
break;
case 0x05:
result = new StopSendingFrame();
break;
case 0x06:
result = new CryptoFrame();
break;
case 0x07:
result = new NewTokenFrame();
break;
case 0x08:
result = new StreamFrame();
break;
case 0x09:
result = new StreamFrame();
break;
case 0x0a:
result = new StreamFrame();
break;
case 0x0b:
result = new StreamFrame();
break;
case 0x0c:
result = new StreamFrame();
break;
case 0x0d:
result = new StreamFrame();
break;
case 0x0e:
result = new StreamFrame();
break;
case 0x0f:
result = new StreamFrame();
break;
case 0x10:
result = new MaxDataFrame();
break;
case 0x11:
result = new MaxStreamDataFrame();
break;
case 0x12:
result = new MaxStreamsFrame();
break;
case 0x13:
result = new MaxStreamsFrame();
break;
case 0x14:
result = new DataBlockedFrame();
break;
case 0x15:
result = new StreamDataBlockedFrame();
break;
case 0x16:
result = new StreamsBlockedFrame();
break;
case 0x17:
result = new StreamsBlockedFrame();
break;
case 0x18:
result = new NewConnectionIdFrame();
break;
case 0x19:
result = new RetireConnectionIdFrame();
break;
case 0x1a:
result = new PathChallengeFrame();
break;
case 0x1b:
result = new PathResponseFrame();
break;
case 0x1c:
result = new ConnectionCloseFrame();
break;
case 0x1d:
result = new ConnectionCloseFrame();
break;
default:
result = null;
break;
}

if (result != null)
Expand All @@ -62,4 +119,4 @@ public Frame GetFrame()
return result;
}
}
}
}
4 changes: 0 additions & 4 deletions QuicNet.Infrastructure/Frames/AckFrame.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
using QuickNet.Utilities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace QuicNet.Infrastructure.Frames
{
Expand Down
20 changes: 8 additions & 12 deletions QuicNet.Infrastructure/Frames/ConnectionCloseFrame.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
using QuickNet.Utilities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace QuicNet.Infrastructure.Frames
{
public class ConnectionCloseFrame : Frame
{
public override byte Type => 0x1c;
public UInt16 ErrorCode { get; set; }
public ushort ErrorCode { get; set; }
public VariableInteger ReasonPhraseLength { get; set; }
public string ReasonPhrase { get; set; }

Expand All @@ -24,33 +20,33 @@ public ConnectionCloseFrame(ErrorCode error, string reason)
{
ReasonPhraseLength = new VariableInteger(0);

ErrorCode = (UInt16)error;
ErrorCode = (ushort)error;
ReasonPhrase = reason;
}

public override void Decode(ByteArray array)
{
byte type = array.ReadByte();
array.ReadByte();

ErrorCode = array.ReadUInt16();
ReasonPhraseLength = array.ReadVariableInteger();

byte[] rp = array.ReadBytes((int)ReasonPhraseLength.Value);
var rp = array.ReadBytes((int)ReasonPhraseLength.Value);
ReasonPhrase = ByteUtilities.GetString(rp);
}

public override byte[] Encode()
{
List<byte> result = new List<byte>();
var result = new List<byte>();
result.Add(Type);

byte[] errorCode = ByteUtilities.GetBytes(ErrorCode);
var errorCode = ByteUtilities.GetBytes(ErrorCode);
result.AddRange(errorCode);

if (string.IsNullOrWhiteSpace(ReasonPhrase) == false)
{
byte[] reasonPhrase = ByteUtilities.GetBytes(ReasonPhrase);
byte[] rpl = new VariableInteger((UInt64)ReasonPhrase.Length);
var reasonPhrase = ByteUtilities.GetBytes(ReasonPhrase);
byte[] rpl = new VariableInteger((ulong)ReasonPhrase.Length);
result.AddRange(rpl);
result.AddRange(reasonPhrase);
}
Expand Down
4 changes: 0 additions & 4 deletions QuicNet.Infrastructure/Frames/CryptoFrame.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
using QuickNet.Utilities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace QuicNet.Infrastructure.Frames
{
Expand Down
20 changes: 3 additions & 17 deletions QuicNet.Infrastructure/Frames/DataBlockedFrame.cs
Original file line number Diff line number Diff line change
@@ -1,37 +1,23 @@
using QuickNet.Utilities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace QuicNet.Infrastructure.Frames
{
public class DataBlockedFrame : Frame
{
public override byte Type => 0x14;
public VariableInteger DataLimit { get; set; }

public DataBlockedFrame()
{

}

public DataBlockedFrame(UInt64 dataLimit)
{
DataLimit = dataLimit;
}
public VariableInteger DataLimit { get; set; }

public override void Decode(ByteArray array)
{
byte type = array.ReadByte();
array.ReadByte();
DataLimit = array.ReadVariableInteger();
}

public override byte[] Encode()
{
List<byte> result = new List<byte>();
result.Add(Type);
var result = new List<byte> {Type};
byte[] dataLimit = DataLimit;

result.AddRange(dataLimit);
Expand Down
3 changes: 0 additions & 3 deletions QuicNet.Infrastructure/Frames/Frame.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using QuickNet.Utilities;
using System;
using System.Collections.Generic;
using System.Text;

namespace QuicNet.Infrastructure.Frames
{
Expand Down
6 changes: 1 addition & 5 deletions QuicNet.Infrastructure/Frames/MaxDataFrame.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
using QuickNet.Utilities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace QuicNet.Infrastructure.Frames
{
Expand All @@ -20,7 +16,7 @@ public override void Decode(ByteArray array)

public override byte[] Encode()
{
List<byte> result = new List<byte>();
var result = new List<byte>();
byte[] maxData = MaximumData;

result.Add(Type);
Expand Down
20 changes: 2 additions & 18 deletions QuicNet.Infrastructure/Frames/MaxStreamDataFrame.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
using QuickNet.Utilities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace QuicNet.Infrastructure.Frames
{
Expand All @@ -15,28 +11,16 @@ public class MaxStreamDataFrame : Frame

public StreamId ConvertedStreamId { get; set; }

public MaxStreamDataFrame()
{

}

public MaxStreamDataFrame(UInt64 streamId, UInt64 maximumStreamData)
{
StreamId = streamId;
MaximumStreamData = maximumStreamData;
}

public override void Decode(ByteArray array)
{
byte type = array.ReadByte();
array.ReadByte();
StreamId = array.ReadVariableInteger();
MaximumStreamData = array.ReadVariableInteger();
}

public override byte[] Encode()
{
List<byte> result = new List<byte>();
result.Add(Type);
var result = new List<byte> {Type};

byte[] streamId = StreamId;
result.AddRange(streamId);
Expand Down
Loading

0 comments on commit 0cc365b

Please sign in to comment.