// Extension-level state shared across background modules. const DEFAULT_PROXY_PORT = 8443; /** CONNECT proxy port (browser must send CONNECT here, not to HTTPS port). Use when host omits connectProxyPort. */ const DEFAULT_CONNECT_PROXY_PORT = 8442; // Track which swarmIds belong to which tab: tabId -> Set const tabSwarms = new Map(); // Track how many tabs are using each swarm: swarmId -> count const swarmRefCount = new Map(); // Track active connections from native host: connId -> { swarmId, peerKey, createdAt } const activeConnections = new Map(); let notifyOnDisconnect = false; let notifyOnTunnelError = true; // True once proxy.settings.get confirms mode=pac_script controlled_by_this_extension let pacConfirmedActive = false; const extensionState = { hostConnected: false, proxyPort: 8443, connectProxyPort: null, // PAC uses this when set (CONNECT proxy); else proxyPort servers: [], // Holesail server tunnels virtualHosts: [], // virtual hostname -> hsUrl mappings stats: { totalConnections: 0, uptime: Date.now() } }; function updateExtensionState() { extensionState.hostConnected = !!port; extensionState.stats.totalConnections = activeConnections.size; }