client keepalive

This commit is contained in:
OfficialDakari 2024-04-30 11:48:56 +05:00
parent c43e1b0fb2
commit 7c0906401a
1 changed files with 22 additions and 1 deletions

View File

@ -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();
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);