Code Monkey home page Code Monkey logo

quic.net's Introduction

0x5C2AAD80

Build Status

QuicNet

Table of contents

What is QuicNet?

QuicNet is a .NET implementation of the QUIC protocol mentioned below. The implementation stays in line with the 32nd version of the quic-transport draft, and does NOT YET offer implementation of the following related drafts:

Get started

Minimal working examples

Preview

Alt

Server

using System;
using System.Text;
using QuicNet;
using QuicNet.Streams;
using QuicNet.Connections;

namespace QuickNet.Tests.ConsoleServer
{
    class Program
    {
        // Fired when a client is connected
        static void ClientConnected(QuicConnection connection)
        {
            connection.OnStreamOpened += StreamOpened;
        }
        
        // Fired when a new stream has been opened (It does not carry data with it)
        static void StreamOpened(QuicStream stream)
        {
            stream.OnStreamDataReceived += StreamDataReceived;
        }
        
        // Fired when a stream received full batch of data
        static void StreamDataReceived(QuicStream stream, byte[] data)
        {
            string decoded = Encoding.UTF8.GetString(data);
            
            // Send back data to the client on the same stream
            stream.Send(Encoding.UTF8.GetBytes("Ping back from server."));
        }
        
        static void Main(string[] args)
        {
            QuicListener listener = new QuicListener(11000);
            listener.OnClientConnected += ClientConnected;

            listener.Start();

            Console.ReadKey();
        }
    }
}

Client

using System;
using System.Text;
using QuicNet.Connections;
using QuicNet.Streams;

namespace QuicNet.Tests.ConsoleClient
{
    class Program
    {
        static void Main(string[] args)
        {
            QuicClient client = new QuicClient();

            // Connect to peer (Server)
            QuicConnection connection = client.Connect("127.0.0.1", 11000);
            // Create a data stream
            QuicStream stream = connection.CreateStream(QuickNet.Utilities.StreamType.ClientBidirectional);
            // Send Data
            stream.Send(Encoding.UTF8.GetBytes("Hello from Client!"));   
            // Wait reponse back from the server (Blocks)
            byte[] data = stream.Receive();

            Console.WriteLine(Encoding.UTF8.GetString(data));

            // Create a new data stream
            stream = connection.CreateStream(QuickNet.Utilities.StreamType.ClientBidirectional);
            // Send Data
            stream.Send(Encoding.UTF8.GetBytes("Hello from Client2!"));
            // Wait reponse back from the server (Blocks)
            data = stream.Receive();

            Console.WriteLine(Encoding.UTF8.GetString(data));

            Console.ReadKey();
        }
    }
}

What is QUIC?

QUIC is an standardised transport layer protocol conforming with RFC 9000 designed by Google, aiming to speed up the data transfer of connection-oriented web applications. This application-level protocol aims to switch from TCP to UDP by using several techniques to resemble the TCP transfer while reducing the connection handshakes, as well as to provide sensible multiplexing techniques in a way that different data entities can be interleaved during transfer.

Connections

Connections are the first tier logical channels representing a communication between two endpoints. When a connection is established, a Connection ID is negotiated between the two endpoints. The Connection ID is used for identifying connection even if changes occur on the lower protocol layers, such as a Phone changing Wi-Fi or switching from Wi-Fi to Mobile data. This mechanism is called Connection Migration which prevents restarting the negotiation flow and resending data.

Streams

Streams are second tier logical channels representing streams of data. A single connection can have a negotiated number of streams (8 maximum for example) which serve as multiplexing entities. Every stream has it's own, generated Stream ID, used for identifiying the different data objects being transferred. Streams are closed when all of the data is read, or the negotiated maximum data transfer is reached.

Packet

Packets are the data transfer units. The packet header contains information about the connection that this packet is being sent to, and cryptographic information. After stripping off the additional transfer information, what is left are the Frames of data (A packet can have multiple frames).

Frame

Frames are the smallest unit that contain either data that needs to be trasferred to the Endpoint or protocol packets necessary for actions such as handshake negotiation, error handling and other.

Contributing

Following the Fork and Pull GitHub workflow:

  1. Fork the repo on GitHub;
  2. Clone the project locally;
  3. Commit changes;
  4. Push your work back up to your fork;
  5. Submit a Pull request so that the changes go through a review.

For more info, read the CONTRIBUTING

More

The quic-transport draft can be found, as previously mentioned at quic-transport.

To test QUIC and find additional information, you can visit Playing with QUIC.

The official C++ source code can be found at proto-quic.

quic.net's People

Contributors

karthikdasari0423 avatar stevehayles avatar vect0rz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

quic.net's Issues

Allow further reads / writes to stream

Recommendation

I may be wrong in this but it seems impossible to write additional data to an open stream ? Is it required within the spec to create a stream for every write. It's possible to write large amounts of data in one go but would it not be preferable to be able to read / write smaller 'payloads' and continue to read and write from an open stream much like you could with a normal socket connection ?

Base ideology of connections

What does that mean
Currently the Server acts as a continuously running entity on a single connection, awaiting packets.

What is the expectation
The connection should be handled exactly as HTTP/2's idea of "reusing" connections, rather than a long-running instance.

Example

You open up a website, that needs to load a html page and a css file and a logo. How should QUIC handle this:

  1. Connection has been opened
  • A bidirectional stream is opened for the HTML
  • A bidirectional stream is opened for the CSS
  • A bidirectional stream is opened for the logo
  1. All of those are interleaved in a single connection.
    Each of the streams is being closed by RESET_SREAM frames in the last data packets or immediately in a single packet.
    After all of the streams are closed, a CONNECTION_CLOSE is being send by the server to disband the client/server connection.

Bug report QuicNet.Tests.ConsoleClient

Describe the bug
When i run QuickNet.Tests.ConsoleServer and QuicNet.Tests.ConsoleClient.
I receive an exception ArgumentException at Program.cs line 34.
byte[] data = stream.Receive();

Additional context
The exception raise at QuicStream.cs line 117.
_data.Add(0, frame.StreamData);
When _data already have an item.

Document installation process

Hello!

This seems like a very interesting project and I am trying to use it; however, I am not sure if this is your nuget package? The username is different and your website is down so not sure if documented there. Please document how to install this and if there is not a nuget package is that something that is planned down the road?

QuicClient.CreateStream is hardcoded to 1.

I've changed my local version to:

public QuicStreamContext CreateStream(ulong streamId = 1, StreamType streamType = StreamType.ClientBidirectional);

in order to keep the compatibility.

Shift to .NET Core

It would be great if this project was targeting .NET Core especially with 3.1 getting LTS for 3 years :)

Bug report

I can't send more than 64K of data, what should I do

Is Bidirectional working (client to server to client)?

Hello again,

I'm not a 100% sure that I understand the meaning of "Bidirectional"
But in your console client sample, I've added

// in the QuicNet.Tests.ConsoleClient.Program.Main
context.OnDataReceived += Context_OnDataReceived;

// in the QuicNet.Tests.ConsoleClient.Program
private static void Context_OnDataReceived(QuicStreamContext obj)
{
      Console.WriteLine("Data Received!");
}

I saw that in your server code you send an "Echo!", and was expecting a way to get the data through the delegate, but for some reason, I'm not getting anything. I've traced in the code, and the bytes are sent successfully, but maybe at a lower level, the data is not processed in the client?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.