top of page

QUIC protocol

I came across interesting protocol called quic developed by google, which will solve many problems which we are facing in HTTP/1 and HTTP/2 like head of line blocking etc.

QUIC uses UDP with TLS 1.3


ree

UDP is not reliable but where as QUIC is reliable and since it uses UDP less number of handshakes compare to Http2


ree


QUIC process multiple streams over single connection

ree

Advantages of QUIC:


•No Head of line blocking

•Multiplexing over UDP

•Independent streams

•Faster Handshakes

•Connection id is independent of IP

•Always encrypted


QUIC Challenges

•3-7% of QUIC fails

•Clients need fall back algorithms

•CPU intensive

•Unoptimized UDP stacks

•Funny TLS layer

•All QUIC stacks are user land

•No standard API

•Lack of tooling




Now we understood about quic protocol ,how to implement quic client server with node js??

Node js support to quic still under implementation so we need to build node js from source code get quic protocol lib support.


  • Git clone https://github.com/nodejs/quic.git

  • you can use PowerShell. Run those commands from an elevated PowerShell terminal:

Set-ExecutionPolicy Unrestricted -Force iex ((New-Object System.Net.WebClient).DownloadString('https://boxstarter.org/bootstrapper.ps1')) get-boxstarter -Force

Install-BoxstarterPackage https://raw.githubusercontent.com/nodejs/node/master/tools/bootstrap/windows_boxstarter -DisableReboots

  • .\vcbuild.bat experimental-quic

const quic = require('net'); console.log(quic);

$ ./node quic.js

{

  _createServerHandle: [Function: createServerHandle],

  _normalizeArgs: [Function: normalizeArgs],

  _setSimultaneousAccepts: [Function: _setSimultaneousAccepts],

  connect: [Function: connect],

createConnection: [Function: connect],

createServer: [Function: createServer],

isIP: [Function: isIP],

  isIPv4: [Function: isIPv4],

  isIPv6: [Function: isIPv6],

  Server: [Function: Server],

  Socket: [Function: Socket],

  Stream: [Function: Socket],

createQuicSocket: [Function: createQuicSocket]

}

If node was built with --experimental-quic you should see the createQuicSocket in the output.


  • Genarate self signed sertificates with below commands

mkdir ssl_certs

cd ssl_certs

openssl genrsa 2024 > server.key

openssl req -new -key server.key -subj "/C=JP" > server.csr

openssl x509 -req -days 3650 -signkey server.key < server.csr > server.crt

use these cert in use node js scripts and run the below script to start quic server

use custom node js ex: quic\Release\node.exe .\Quic.js

 const { createQuicSocket } = require('net');
const fs = require('fs');

const key  = fs.readFileSync('./ssl_certs/server.key');
const cert = fs.readFileSync('./ssl_certs/server.crt');
const ca   = fs.readFileSync('./ssl_certs/server.csr');
const port = 1234;

// Create the QUIC UDP IPv4 socket bound to local IP port 1234
const server = createQuicSocket({ endpoint: { port } });

// Tell the socket to operate as a server using the given
// key and certificate to secure new connections, using
// the fictional 'hello' application protocol.
server.listen({ keycertalpn: 'hello' });

server.on('session', (session=> {
 // The peer opened a new stream!
 session.on('stream', (stream=> {
 // Echo server
 stream.pipe(stream);
  });
});

server.on('listening', () => {
 // The socket is listening for sessions!
 console.log(`listening on ${port}...`);
 console.log('input something!');
});

const socket = createQuicSocket({
 client: {
 key,
 cert,
 ca,
 requestCert: true,
 alpn: 'hello',
 servername: 'localhost'
  }
});

const req = socket.connect({
 address: 'localhost',
 port,
});

req.on('secure', () => {
 const stream = req.openStream();
 // stdin -> stream
 process.stdin.pipe(stream);
 stream.on('data', (chunk=> console.log('client(on-secure): 'chunk.toString()));
 stream.on('end', () => console.log('client(on-secure): end'));
 stream.on('close', () => {
 // Graceful shutdown
 socket.close();
  });
 stream.on('error', (err=> console.error(err));
});
 
 

output:

quic\Release\node.exe .\Quic.js

(node:8924) ExperimentalWarning: The QUIC protocol is experimental and not yet supported for production use

(Use `node --trace-warnings ...` to show where the warning was created)

listening on 1234...

input something!

Hello

client(on-secure): Hello



Finally you can monitor you QUIC traffic with Wireshark.


ree

 
 
 

Comentarios


©2020 by Suneetha Yamani. Proudly created with Wix.com

bottom of page