From 7c0906401ae8641c47ac065422634d2f8e77576a Mon Sep 17 00:00:00 2001 From: OfficialDakari Date: Tue, 30 Apr 2024 11:48:56 +0500 Subject: [PATCH] client keepalive --- client/index.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/client/index.js b/client/index.js index cf78cb2..41fdc37 100644 --- a/client/index.js +++ b/client/index.js @@ -9,6 +9,7 @@ const net = require('net'); const { Tun } = require('tuntap2'); const { encrypt, decrypt } = require('../encryption'); const IP = require('ip-packet'); +const { randomFill, randomFillSync } = require('crypto'); const sock = dgram.createSocket('udp4'); const tun = new Tun(); @@ -79,4 +80,24 @@ function authenticateAndCheck() { }, 2000); } -authenticateAndCheck(); \ No newline at end of file +function keepAlive() { + var buff = Buffer.alloc(64); + randomFillSync(buff); + buff[0] = 0x60; // actually you can send anything just make sure that buff[0] >> 4 !== 4 + sock.send( + encrypt( + buff, + config.privateKey, + config.iv, + config.algorithm + ), + config.port, + config.endpoint + ); +} + +authenticateAndCheck(); + +setInterval(() => { + keepAlive(); +}, 15000); \ No newline at end of file