feat: track what modules are listening on a socket connection by their module id

This commit is contained in:
Derrick Hammer 2023-07-22 09:49:31 -04:00
parent 9d2b64d510
commit 39a91144de
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 7 additions and 0 deletions

View File

@ -24,6 +24,7 @@ interface SwarmConnection {
swarm: number;
conn: any;
channels: Map<number, Protomux>;
listeners: Set<string>;
}
interface SwarmEvents {
@ -122,6 +123,7 @@ async function createSwarm(): Promise<number> {
swarm: id,
conn: peer,
channels: new Map<number, Protomux>(),
listeners: new Set<string>(),
});
peer.once("close", () => {
@ -155,6 +157,8 @@ function handleSocketListenEvent(aq: ActiveQuery) {
return;
}
const conn = connections.get(aq.callerInput.id) as SwarmConnection;
let responded = false;
const respond = () => {
if (responded) {
@ -162,6 +166,7 @@ function handleSocketListenEvent(aq: ActiveQuery) {
}
responded = true;
conn.listeners.delete(aq.domain);
aq.respond();
};
@ -182,6 +187,8 @@ function handleSocketListenEvent(aq: ActiveQuery) {
socket.off(event, cb);
respond();
});
conn.listeners.add(aq.domain);
}
async function handleSocketExists(aq: ActiveQuery) {