arn-browser 0.1.20 → 0.1.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -365,10 +365,10 @@ export async function startProxyServer({
|
|
|
365
365
|
for (const [key, val] of Object.entries(stats)) {
|
|
366
366
|
formatted[key] = {
|
|
367
367
|
req: val.request,
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
368
|
+
sTx: formatBytes(val.srcTx),
|
|
369
|
+
sRx: formatBytes(val.srcRx),
|
|
370
|
+
tTx: formatBytes(val.trgTx),
|
|
371
|
+
tRx: formatBytes(val.trgRx),
|
|
372
372
|
};
|
|
373
373
|
}
|
|
374
374
|
return formatted;
|
|
@@ -382,10 +382,10 @@ export async function startProxyServer({
|
|
|
382
382
|
.reduce((acc, [host, hostData]) => {
|
|
383
383
|
acc[host] = {
|
|
384
384
|
req: hostData.req,
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
385
|
+
sTx: formatBytes(hostData.srcTx),
|
|
386
|
+
sRx: formatBytes(hostData.srcRx),
|
|
387
|
+
tTx: formatBytes(hostData.trgTx),
|
|
388
|
+
tRx: formatBytes(hostData.trgRx),
|
|
389
389
|
};
|
|
390
390
|
return acc;
|
|
391
391
|
}, {});
|
|
@@ -421,16 +421,34 @@ export async function startProxyServer({
|
|
|
421
421
|
isServerRunning: () => serverRunning,
|
|
422
422
|
|
|
423
423
|
closeServer: async () => {
|
|
424
|
-
// Close the server — triggers
|
|
424
|
+
// Close the server — triggers socket destroys
|
|
425
425
|
await server.close(true);
|
|
426
426
|
serverRunning = false;
|
|
427
427
|
|
|
428
|
-
//
|
|
428
|
+
// Wait up to 2000ms (2 seconds) for all async 'connectionClosed' events to fire
|
|
429
|
+
// When sockets are destroyed, their 'close' events happen asynchronously
|
|
430
|
+
let maxWait = 200; // 200 * 10ms = 2000ms
|
|
431
|
+
while (Object.keys(connectionMap).length > 0 && maxWait > 0) {
|
|
432
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
433
|
+
maxWait--;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
// Log stats AFTER close so all connectionClosed events have accumulated bytes
|
|
429
437
|
if (proxy_stats) {
|
|
430
|
-
console.log("░░ Proxy Stats:"
|
|
438
|
+
console.log("\n░░ Proxy Stats:");
|
|
439
|
+
for (const [type, data] of Object.entries(getProxyStatsFormatted())) {
|
|
440
|
+
console.log(` ${type}: { req: ${data.req}, sTx: '${data.sTx}', sRx: '${data.sRx}', tTx: '${data.tTx}', tRx: '${data.tRx}' }`);
|
|
441
|
+
}
|
|
431
442
|
}
|
|
432
443
|
if (host_stats) {
|
|
433
|
-
console.log("░░ Host Stats:"
|
|
444
|
+
console.log("░░ Host Stats:");
|
|
445
|
+
for (const [type, hosts] of Object.entries(getHostStatsFormatted())) {
|
|
446
|
+
console.log(` ${type}: {`);
|
|
447
|
+
for (const [host, data] of Object.entries(hosts)) {
|
|
448
|
+
console.log(` '${host}': { req: ${data.req}, sTx: '${data.sTx}', sRx: '${data.sRx}', tTx: '${data.tTx}', tRx: '${data.tRx}' }`);
|
|
449
|
+
}
|
|
450
|
+
console.log(` }`);
|
|
451
|
+
}
|
|
434
452
|
}
|
|
435
453
|
|
|
436
454
|
console.log("░░ Proxy server closed.");
|