adding experimental udp6 support
All checks were successful
the build was successful

This commit is contained in:
Fabian Stamm
2018-05-17 13:54:18 +02:00
parent 25131a2d4b
commit 43f4cf358d
4 changed files with 13 additions and 11 deletions

View File

@ -6,10 +6,11 @@ import { PassThrough } from "stream";
export default class Listener {
private udp: dgram.Socket
private tcp: net.Server
constructor(type: "udp" | "tcp", onRequest: (request: Request) => any, host: string = "0.0.0.0") {
constructor(type: "udp4" | "udp6" | "tcp", onRequest: (request: Request) => any, host: string = "0.0.0.0") {
switch (type) {
case "udp":
this.udp = dgram.createSocket("udp4")
case "udp6":
case "udp4":
this.udp = dgram.createSocket(type)
this.udp.on("listening", () => {
console.log(`UDP Server Listening on 53`)
})
@ -25,7 +26,7 @@ export default class Listener {
this.udp.bind(53, host)
break;
case "tcp":
console.log("Not correct implemented")
console.log("Using TCP is experimantal")
this.tcp = net.createServer((socket) => {
let length: number;
let got: number = 0;
@ -34,7 +35,7 @@ export default class Listener {
let offset = 0;
if (!message) {
length = data.readUInt16BE(0);
if (length > 2048) return socket.destroy(); //Requests with more that 2k are ignored
if (length > 4096) return socket.destroy(); //Requests with more that 2k are ignored
message = Buffer.alloc(length);
offset = 2;
}