mirror of
https://github.com/fosrl/pangolin.git
synced 2026-03-06 18:56:39 +00:00
Add ping; working on newt tunnel reliability
This commit is contained in:
@@ -105,18 +105,22 @@ export const handleGetConfigMessage: MessageHandler = async (context) => {
|
||||
.innerJoin(clientSites, eq(clients.clientId, clientSites.clientId))
|
||||
.where(eq(clientSites.siteId, siteId));
|
||||
|
||||
const now = new Date().getTime() / 1000;
|
||||
const peers = await Promise.all(
|
||||
clientsRes
|
||||
.filter((client) => {
|
||||
// This filter wasn't returning anything - fixed to properly filter clients
|
||||
if (
|
||||
!client.clients.lastHolePunch ||
|
||||
now - client.clients.lastHolePunch > 6
|
||||
) {
|
||||
logger.warn("Client last hole punch is too old");
|
||||
if (!client.clients.pubKey) {
|
||||
return false;
|
||||
}
|
||||
if (!client.clients.subnet) {
|
||||
return false;
|
||||
}
|
||||
if (!client.clients.endpoint) {
|
||||
return false;
|
||||
}
|
||||
if (!client.clients.online) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
})
|
||||
.map(async (client) => {
|
||||
|
||||
@@ -37,22 +37,6 @@ export const handleReceiveBandwidthMessage: MessageHandler = async (context) =>
|
||||
if (!client) {
|
||||
continue;
|
||||
}
|
||||
let online = client.online;
|
||||
|
||||
// if the bandwidth for the client is > 0 then set it to online. if it has been less than 0 (no update) for 5 minutes then set it to offline
|
||||
if (bytesIn > 0) { // only track the bytes in because we are always sending bytes out with persistent keep alive
|
||||
online = true;
|
||||
} else if (client.lastBandwidthUpdate) {
|
||||
const lastBandwidthUpdate = new Date(
|
||||
client.lastBandwidthUpdate
|
||||
);
|
||||
const currentTime = new Date();
|
||||
const diff =
|
||||
currentTime.getTime() - lastBandwidthUpdate.getTime();
|
||||
if (diff < 300000) {
|
||||
online = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Update the client's bandwidth usage
|
||||
await trx
|
||||
@@ -61,7 +45,6 @@ export const handleReceiveBandwidthMessage: MessageHandler = async (context) =>
|
||||
megabytesOut: (client.megabytesIn || 0) + bytesIn,
|
||||
megabytesIn: (client.megabytesOut || 0) + bytesOut,
|
||||
lastBandwidthUpdate: new Date().toISOString(),
|
||||
online
|
||||
})
|
||||
.where(eq(clients.clientId, client.clientId));
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
export * from "./createNewt";
|
||||
export * from "./getNewtToken";
|
||||
export * from "./handleNewtRegisterMessage";
|
||||
export* from "./handleReceiveBandwidthMessage";
|
||||
export * from "./handleReceiveBandwidthMessage";
|
||||
export * from "./handleGetConfigMessage";
|
||||
Reference in New Issue
Block a user