Skip to content

Commit c4e5602

Browse files
committed
Changes to QuicListener.
1 parent bc3d299 commit c4e5602

4 files changed

Lines changed: 59 additions & 16 deletions

File tree

QuicNet/Context/QuicContext.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Net;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace QuicNet.Context
9+
{
10+
public class QuicContext
11+
{
12+
public IPEndPoint EndPoint { get; set; }
13+
public byte[] Data { get; set; }
14+
15+
public QuicContext()
16+
{
17+
18+
}
19+
}
20+
}

QuicNet/QuicListener.cs

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using QuicNet.Infrastructure;
1+
using QuicNet.Context;
2+
using QuicNet.Infrastructure;
23
using QuicNet.Infrastructure.Packets;
34
using System;
45
using System.Collections.Generic;
@@ -13,43 +14,57 @@ namespace QuicNet
1314
public class QuicListener
1415
{
1516
private UdpClient _client;
16-
private IPEndPoint _endPoint;
1717

1818
private Unpacker _unpacker;
1919
private PacketCreator _packetCreator;
2020
private Dispatcher _dispatcher;
2121

22+
private int _port;
23+
private bool _started;
24+
25+
public event Action<QuicContext> OnDataReceived;
26+
2227
public QuicListener(int port)
2328
{
24-
_endPoint = new IPEndPoint(IPAddress.Any, port);
25-
_client = new UdpClient(port);
29+
_started = false;
30+
_port = port;
31+
2632
_unpacker = new Unpacker();
2733
_packetCreator = new PacketCreator();
2834
_dispatcher = new Dispatcher(_packetCreator);
2935
}
3036

3137
public void Start()
3238
{
33-
Receive();
39+
_client = new UdpClient(_port);
40+
}
41+
42+
public void Close()
43+
{
44+
_client.Close();
3445
}
3546

3647
public void Receive()
3748
{
38-
byte[] data = _client.Receive(ref _endPoint);
49+
while (true)
50+
{
51+
IPEndPoint endpoint = new IPEndPoint(IPAddress.Any, _port);
52+
byte[] data = _client.Receive(ref endpoint);
3953

40-
Packet packet = _unpacker.Unpack(data);
54+
Packet packet = _unpacker.Unpack(data);
4155

42-
// Discard unknown packets
43-
if (packet == null)
44-
return;
56+
// Discard unknown packets
57+
if (packet == null)
58+
continue;
4559

46-
// TODO: Validate packet before dispatching
47-
Packet result = _dispatcher.Dispatch(packet);
60+
// TODO: Validate packet before dispatching
61+
Packet result = _dispatcher.Dispatch(packet);
4862

49-
// Send a response packet if the dispatcher has information for the peer.
50-
if (result != null)
51-
{
52-
63+
// Send a response packet if the dispatcher has information for the peer. (1-RTT)
64+
if (result != null)
65+
{
66+
67+
}
5368
}
5469
}
5570
}

QuicNet/QuicNet.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
<Compile Include="Connections\ConnectionPool.cs" />
4444
<Compile Include="Connections\ConnectionState.cs" />
4545
<Compile Include="Connections\QuicConnection.cs" />
46+
<Compile Include="Context\QuicContext.cs" />
4647
<Compile Include="Dispatcher.cs" />
4748
<Compile Include="QuicClient.cs" />
4849
<Compile Include="QuicListener.cs" />

QuickNet.Console/Program.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using QuickNet.Utilities;
22
using QuicNet;
3+
using QuicNet.Context;
34
using QuicNet.Infrastructure;
45
using QuicNet.Infrastructure.Frames;
56
using QuicNet.Infrastructure.Packets;
@@ -45,9 +46,15 @@ static void Main(string[] args)
4546
StreamId streamId = streamIdData;
4647

4748
QuicListener listener = new QuicListener(11000);
49+
listener.OnDataReceived += Listener_OnDataReceived;
4850
listener.Start();
4951
}
5052

53+
private static void Listener_OnDataReceived(QuicContext obj)
54+
{
55+
throw new NotImplementedException();
56+
}
57+
5158
static string ToBase64(byte[] data)
5259
{
5360
return Convert.ToBase64String(data);

0 commit comments

Comments
 (0)