mirror of
https://github.com/fosrl/pangolin.git
synced 2025-07-29 15:14:56 +02:00
Solve olm not having chance to send hp message
This commit is contained in:
parent
68ebdda1ff
commit
e57574ba9c
2 changed files with 30 additions and 28 deletions
|
@ -45,12 +45,13 @@ export async function updateHolePunch(
|
||||||
|
|
||||||
const { olmId, newtId, ip, port, timestamp, token } = parsedParams.data;
|
const { olmId, newtId, ip, port, timestamp, token } = parsedParams.data;
|
||||||
|
|
||||||
// logger.debug(`Got hole punch with ip: ${ip}, port: ${port} for olmId: ${olmId} or newtId: ${newtId}`);
|
|
||||||
|
|
||||||
let currentSiteId: number | undefined;
|
let currentSiteId: number | undefined;
|
||||||
let destinations: PeerDestination[] = [];
|
let destinations: PeerDestination[] = [];
|
||||||
|
|
||||||
if (olmId) {
|
if (olmId) {
|
||||||
|
logger.debug(`Got hole punch with ip: ${ip}, port: ${port} for olmId: ${olmId}`);
|
||||||
|
|
||||||
const { session, olm: olmSession } =
|
const { session, olm: olmSession } =
|
||||||
await validateOlmSessionToken(token);
|
await validateOlmSessionToken(token);
|
||||||
if (!session || !olmSession) {
|
if (!session || !olmSession) {
|
||||||
|
@ -197,33 +198,33 @@ export async function updateHolePunch(
|
||||||
}
|
}
|
||||||
|
|
||||||
// If this is a newt/site, also add other sites in the same org
|
// If this is a newt/site, also add other sites in the same org
|
||||||
if (updatedSite.orgId) {
|
// if (updatedSite.orgId) {
|
||||||
const orgSites = await db
|
// const orgSites = await db
|
||||||
.select()
|
// .select()
|
||||||
.from(sites)
|
// .from(sites)
|
||||||
.where(eq(sites.orgId, updatedSite.orgId));
|
// .where(eq(sites.orgId, updatedSite.orgId));
|
||||||
|
|
||||||
for (const site of orgSites) {
|
// for (const site of orgSites) {
|
||||||
// Don't add the current site to the destinations
|
// // Don't add the current site to the destinations
|
||||||
if (site.siteId !== currentSiteId && site.subnet && site.endpoint && site.listenPort) {
|
// if (site.siteId !== currentSiteId && site.subnet && site.endpoint && site.listenPort) {
|
||||||
const [host, portStr] = site.endpoint.split(':');
|
// const [host, portStr] = site.endpoint.split(':');
|
||||||
if (host && portStr) {
|
// if (host && portStr) {
|
||||||
destinations.push({
|
// destinations.push({
|
||||||
destinationIP: host,
|
// destinationIP: host,
|
||||||
destinationPort: site.listenPort
|
// destinationPort: site.listenPort
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
if (destinations.length === 0) {
|
// if (destinations.length === 0) {
|
||||||
logger.warn(
|
// logger.warn(
|
||||||
`No peer destinations found for olmId: ${olmId} or newtId: ${newtId}`
|
// `No peer destinations found for olmId: ${olmId} or newtId: ${newtId}`
|
||||||
);
|
// );
|
||||||
return next(createHttpError(HttpCode.NOT_FOUND, "No peer destinations found"));
|
// return next(createHttpError(HttpCode.NOT_FOUND, "No peer destinations found"));
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Return the new multi-peer structure
|
// Return the new multi-peer structure
|
||||||
return res.status(HttpCode.OK).send({
|
return res.status(HttpCode.OK).send({
|
||||||
|
|
|
@ -63,8 +63,9 @@ export const handleOlmRegisterMessage: MessageHandler = async (context) => {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (client.lastHolePunch && now - client.lastHolePunch > 6) {
|
if (now - (client.lastHolePunch || 0) > 6) {
|
||||||
logger.warn("Client last hole punch is too old, skipping all sites");
|
logger.warn("Client last hole punch is too old, skipping all sites");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the client's public key
|
// Update the client's public key
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue