mirror of
https://github.com/fosrl/pangolin.git
synced 2026-03-04 01:36:39 +00:00
newts not being on when olm is started
This commit is contained in:
@@ -3,7 +3,6 @@ import { MessageHandler } from "../ws";
|
||||
import { clients, Olm } from "@server/db/schema";
|
||||
import { eq, lt, isNull } from "drizzle-orm";
|
||||
import logger from "@server/logger";
|
||||
import { time } from "console";
|
||||
|
||||
// Track if the offline checker interval is running
|
||||
let offlineCheckerInterval: NodeJS.Timeout | null = null;
|
||||
|
||||
@@ -68,13 +68,26 @@ export const handleOlmRegisterMessage: MessageHandler = async (context) => {
|
||||
return;
|
||||
}
|
||||
|
||||
// Update the client's public key
|
||||
await db
|
||||
.update(clients)
|
||||
.set({
|
||||
pubKey: publicKey
|
||||
})
|
||||
.where(eq(clients.clientId, olm.clientId));
|
||||
if (client.pubKey !== publicKey) {
|
||||
logger.info(
|
||||
"Public key mismatch. Updating public key and clearing session info..."
|
||||
);
|
||||
// Update the client's public key
|
||||
await db
|
||||
.update(clients)
|
||||
.set({
|
||||
pubKey: publicKey
|
||||
})
|
||||
.where(eq(clients.clientId, olm.clientId));
|
||||
|
||||
// set isRelay to false for all of the client's sites to reset the connection metadata
|
||||
await db
|
||||
.update(clientSites)
|
||||
.set({
|
||||
isRelayed: false
|
||||
})
|
||||
.where(eq(clientSites.clientId, olm.clientId));
|
||||
}
|
||||
|
||||
// Get all sites data
|
||||
const sitesData = await db
|
||||
@@ -143,7 +156,7 @@ export const handleOlmRegisterMessage: MessageHandler = async (context) => {
|
||||
endpoint: site.endpoint,
|
||||
publicKey: site.publicKey,
|
||||
serverIP: site.address,
|
||||
serverPort: site.listenPort,
|
||||
serverPort: site.listenPort
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
70
server/routers/olm/peers.ts
Normal file
70
server/routers/olm/peers.ts
Normal file
@@ -0,0 +1,70 @@
|
||||
import db from '@server/db';
|
||||
import { clients, olms, newts } from '@server/db/schema';
|
||||
import { eq } from 'drizzle-orm';
|
||||
import { sendToClient } from '../ws';
|
||||
import logger from '@server/logger';
|
||||
|
||||
export async function addPeer(clientId: number, peer: {
|
||||
siteId: number,
|
||||
publicKey: string;
|
||||
allowedIps: string[];
|
||||
endpoint: string;
|
||||
serverIP: string | null;
|
||||
serverPort: number | null;
|
||||
}) {
|
||||
const [olm] = await db.select().from(olms).where(eq(olms.clientId, clientId)).limit(1);
|
||||
if (!olm) {
|
||||
throw new Error(`Olm with ID ${clientId} not found`);
|
||||
}
|
||||
|
||||
sendToClient(olm.olmId, {
|
||||
type: 'olm/wg/peer/add',
|
||||
data: {
|
||||
publicKey: peer.publicKey,
|
||||
allowedIps: peer.allowedIps,
|
||||
endpoint: peer.endpoint,
|
||||
serverIP: peer.serverIP,
|
||||
serverPort: peer.serverPort
|
||||
}
|
||||
});
|
||||
|
||||
logger.info(`Added peer ${peer.publicKey} to olm ${olm.olmId}`);
|
||||
}
|
||||
|
||||
export async function deletePeer(clientId: number, publicKey: string) {
|
||||
const [olm] = await db.select().from(olms).where(eq(olms.clientId, clientId)).limit(1);
|
||||
if (!olm) {
|
||||
throw new Error(`Olm with ID ${clientId} not found`);
|
||||
}
|
||||
|
||||
sendToClient(olm.olmId, {
|
||||
type: 'olm/wg/peer/remove',
|
||||
data: {
|
||||
publicKey
|
||||
}
|
||||
});
|
||||
|
||||
logger.info(`Deleted peer ${publicKey} from olm ${olm.olmId}`);
|
||||
}
|
||||
|
||||
export async function updatePeer(clientId: number, publicKey: string, peer: {
|
||||
allowedIps?: string[];
|
||||
endpoint?: string;
|
||||
serverIP?: string;
|
||||
serverPort?: number;
|
||||
}) {
|
||||
const [olm] = await db.select().from(olms).where(eq(olms.clientId, clientId)).limit(1);
|
||||
if (!olm) {
|
||||
throw new Error(`Olm with ID ${clientId} not found`);
|
||||
}
|
||||
|
||||
sendToClient(olm.olmId, {
|
||||
type: 'olm/wg/peer/update',
|
||||
data: {
|
||||
publicKey,
|
||||
...peer
|
||||
}
|
||||
});
|
||||
|
||||
logger.info(`Updated peer ${publicKey} on olm ${olm.olmId}`);
|
||||
}
|
||||
Reference in New Issue
Block a user