Update VPN proxy client behavior
This commit is contained in:
@@ -127,12 +127,16 @@ interface TrafficSample {
|
||||
observedAt: string | null | undefined;
|
||||
gatewayBytes: string;
|
||||
proxyBytes: string;
|
||||
uploadBytes: string;
|
||||
downloadBytes: string;
|
||||
}
|
||||
|
||||
interface TrafficCursor {
|
||||
signature: string;
|
||||
gateway: bigint;
|
||||
proxy: bigint;
|
||||
upload: bigint;
|
||||
download: bigint;
|
||||
}
|
||||
|
||||
interface DeviceObservation {
|
||||
@@ -674,10 +678,12 @@ export function createDeviceInventoryService({
|
||||
const proxy = state.traffic.proxy.totalsByMac[device.mac];
|
||||
const signature = `${traffic?.observedAt || ''}|${proxy?.observedAt || ''}`;
|
||||
if (signature === '|') continue;
|
||||
const upload = BigInt(traffic?.uploadBytes || '0') + BigInt(proxy?.uploadBytes || '0');
|
||||
const download = BigInt(traffic?.downloadBytes || '0') + BigInt(proxy?.downloadBytes || '0');
|
||||
const gateway = BigInt(traffic?.uploadBytes || '0') + BigInt(traffic?.downloadBytes || '0');
|
||||
const proxyTotal = BigInt(proxy?.uploadBytes || '0') + BigInt(proxy?.downloadBytes || '0');
|
||||
const previous = trafficCursorByMac.get(device.mac);
|
||||
trafficCursorByMac.set(device.mac, { signature, gateway, proxy: proxyTotal });
|
||||
trafficCursorByMac.set(device.mac, { signature, gateway, proxy: proxyTotal, upload, download });
|
||||
if (!previous || previous.signature === signature) continue;
|
||||
const observedAt = [traffic?.observedAt, proxy?.observedAt].filter(Boolean).sort().at(-1);
|
||||
const samples = trafficHistoryByMac.get(device.mac) || [];
|
||||
@@ -685,6 +691,8 @@ export function createDeviceInventoryService({
|
||||
observedAt,
|
||||
gatewayBytes: gateway > previous.gateway ? (gateway - previous.gateway).toString() : '0',
|
||||
proxyBytes: proxyTotal > previous.proxy ? (proxyTotal - previous.proxy).toString() : '0',
|
||||
uploadBytes: upload > previous.upload ? (upload - previous.upload).toString() : '0',
|
||||
downloadBytes: download > previous.download ? (download - previous.download).toString() : '0',
|
||||
}].slice(-TRAFFIC_HISTORY_LIMIT));
|
||||
}
|
||||
for (const mac of trafficCursorByMac.keys()) {
|
||||
@@ -695,16 +703,20 @@ export function createDeviceInventoryService({
|
||||
}
|
||||
const gatewaySource = state.traffic.global.gateway;
|
||||
const proxySource = state.traffic.global.proxy;
|
||||
const upload = BigInt(gatewaySource.uploadBytes) + BigInt(proxySource.uploadBytes);
|
||||
const download = BigInt(gatewaySource.downloadBytes) + BigInt(proxySource.downloadBytes);
|
||||
const gateway = BigInt(gatewaySource.uploadBytes) + BigInt(gatewaySource.downloadBytes);
|
||||
const proxy = BigInt(proxySource.uploadBytes) + BigInt(proxySource.downloadBytes);
|
||||
const signature = `${gatewaySource.lastObservedAt || ''}|${proxySource.lastObservedAt || ''}`;
|
||||
const previous = globalTrafficCursor;
|
||||
globalTrafficCursor = { signature, gateway, proxy };
|
||||
globalTrafficCursor = { signature, gateway, proxy, upload, download };
|
||||
if (previous && previous.signature !== signature) {
|
||||
globalTrafficHistory = [...globalTrafficHistory, {
|
||||
observedAt: [gatewaySource.lastObservedAt, proxySource.lastObservedAt].filter(Boolean).sort().at(-1),
|
||||
gatewayBytes: gateway > previous.gateway ? (gateway - previous.gateway).toString() : '0',
|
||||
proxyBytes: proxy > previous.proxy ? (proxy - previous.proxy).toString() : '0',
|
||||
uploadBytes: upload > previous.upload ? (upload - previous.upload).toString() : '0',
|
||||
downloadBytes: download > previous.download ? (download - previous.download).toString() : '0',
|
||||
}].slice(-TRAFFIC_HISTORY_LIMIT);
|
||||
}
|
||||
}
|
||||
@@ -800,6 +812,8 @@ export function createDeviceInventoryService({
|
||||
traffic: {
|
||||
gatewayBytes: gatewayBytes.toString(),
|
||||
proxyBytes: proxyBytes.toString(),
|
||||
uploadBytes: (BigInt(gatewayTraffic.uploadBytes) + BigInt(proxyTraffic.uploadBytes)).toString(),
|
||||
downloadBytes: (BigInt(gatewayTraffic.downloadBytes) + BigInt(proxyTraffic.downloadBytes)).toString(),
|
||||
totalBytes: (gatewayBytes + proxyBytes).toString(),
|
||||
gatewayObservedAt: gatewayTraffic.lastObservedAt,
|
||||
proxyObservedAt: proxyTraffic.lastObservedAt,
|
||||
|
||||
Reference in New Issue
Block a user