runtime-node icon indicating copy to clipboard operation
runtime-node copied to clipboard

Keep all ports that we connect to

Open foca opened this issue 1 year ago • 2 comments

Currently, when connecting to multiple ports in the same hostname, the firewall only tracks the first port connected to, and discards the rest. This fixes the code so that we track all ports connected to and report them to the server.

foca avatar Aug 29 '24 09:08 foca

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

:loudspeaker: Thoughts on this report? Let us know!

codecov[bot] avatar Aug 30 '24 09:08 codecov[bot]

PR looks good to me. 👍 Maybe this approach would be slightly more efficient:

export class Hostnames {
   private map = new Map<string, Ports>();
 
   constructor(private readonly maxEntries: number = 200) {}
 
   add(hostname: string, port: number | undefined) {
     if (!this.map.has(hostname)) {
-      this.map.set(hostname, new Set());
+      this.map.set(hostname, new Set([port]));
+    } else {
+      this.map.get(hostname)?.add(port);
     }
-    (this.map.get(hostname) as Ports).add(port);
 

timokoessler avatar Sep 02 '24 10:09 timokoessler