hub: add _udpCleanerTimer
This commit is contained in:
parent
be1f6e810a
commit
2733305df9
@ -43,6 +43,8 @@ export class Hub {
|
|||||||
|
|
||||||
_connQueue = [];
|
_connQueue = [];
|
||||||
|
|
||||||
|
_udpCleanerTimer = null;
|
||||||
|
|
||||||
constructor(config) {
|
constructor(config) {
|
||||||
this._config = new Config(config);
|
this._config = new Config(config);
|
||||||
this._udpRelays = LRU({ max: 500, maxAge: 1e5, dispose: (_, relay) => relay.destroy() });
|
this._udpRelays = LRU({ max: 500, maxAge: 1e5, dispose: (_, relay) => relay.destroy() });
|
||||||
@ -81,6 +83,9 @@ export class Hub {
|
|||||||
this._udpServer && this._udpServer.close();
|
this._udpServer && this._udpServer.close();
|
||||||
// server
|
// server
|
||||||
this._tcpServer.close();
|
this._tcpServer.close();
|
||||||
|
// others
|
||||||
|
this._connQueue = [];
|
||||||
|
clearInterval(this._udpCleanerTimer);
|
||||||
logger.info('[hub] shutdown');
|
logger.info('[hub] shutdown');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -239,7 +244,8 @@ export class Hub {
|
|||||||
const server = dgram.createSocket('udp4');
|
const server = dgram.createSocket('udp4');
|
||||||
|
|
||||||
// destroy old relays every 5s
|
// destroy old relays every 5s
|
||||||
setInterval(() => relays.prune(), 5e3);
|
clearInterval(this._udpCleanerTimer);
|
||||||
|
this._udpCleanerTimer = setInterval(() => relays.prune(), 5e3);
|
||||||
|
|
||||||
server.on('message', (msg, rinfo) => {
|
server.on('message', (msg, rinfo) => {
|
||||||
const { address, port } = rinfo;
|
const { address, port } = rinfo;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import crypto from 'crypto';
|
import crypto from 'crypto';
|
||||||
import { EVP_BytesToKey, numberToBuffer, hmac, hash } from '../utils';
|
import { EVP_BytesToKey, numberToBuffer, hmac, hash, dumpHex } from '../utils';
|
||||||
import { IPresetAddressing } from './defs';
|
import { IPresetAddressing } from './defs';
|
||||||
|
|
||||||
// available HMACs and length
|
// available HMACs and length
|
||||||
@ -123,20 +123,20 @@ export default class BaseAuthPreset extends IPresetAddressing {
|
|||||||
|
|
||||||
// minimal length required
|
// minimal length required
|
||||||
if (buffer.length < 31) {
|
if (buffer.length < 31) {
|
||||||
return fail(`length is too short: ${buffer.length}, dump=${buffer.toString('hex')}`);
|
return fail(`length is too short: ${buffer.length}, dump=${dumpHex(buffer)}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// decrypt the first byte and check length overflow
|
// decrypt the first byte and check length overflow
|
||||||
const alen = this._decipher.update(buffer.slice(0, 1))[0];
|
const alen = this._decipher.update(buffer.slice(0, 1))[0];
|
||||||
if (buffer.length <= 1 + alen + 2 + hmacLen) {
|
if (buffer.length <= 1 + alen + 2 + hmacLen) {
|
||||||
return fail(`unexpected length: ${buffer.length}, dump=${buffer.toString('hex')}`);
|
return fail(`unexpected length: ${buffer.length}, dump=${dumpHex(buffer)}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// check hmac
|
// check hmac
|
||||||
const givenHmac = buffer.slice(1 + alen + 2, 1 + alen + 2 + hmacLen);
|
const givenHmac = buffer.slice(1 + alen + 2, 1 + alen + 2 + hmacLen);
|
||||||
const expHmac = hmac(this._hmacMethod, this._hmacKey, buffer.slice(0, 1 + alen + 2));
|
const expHmac = hmac(this._hmacMethod, this._hmacKey, buffer.slice(0, 1 + alen + 2));
|
||||||
if (!givenHmac.equals(expHmac)) {
|
if (!givenHmac.equals(expHmac)) {
|
||||||
return fail(`unexpected HMAC=${givenHmac.toString('hex')} want=${expHmac.toString('hex')} dump=${buffer.slice(0, 60).toString('hex')}`);
|
return fail(`unexpected HMAC=${dumpHex(givenHmac)} want=${dumpHex(expHmac)} dump=${dumpHex(buffer)}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// decrypt the following bytes
|
// decrypt the following bytes
|
||||||
|
Loading…
Reference in New Issue
Block a user