cdp-tunnel 3.0.6 → 3.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/extension-new/manifest.json +1 -1
- package/package.json +1 -1
- package/server/modules/port-pool.js +13 -18
- package/server/proxy-server.js +15 -0
package/package.json
CHANGED
|
@@ -65,26 +65,18 @@ class PortPoolManager {
|
|
|
65
65
|
this.portSessions[portIndex] = session;
|
|
66
66
|
|
|
67
67
|
const server = http.createServer();
|
|
68
|
-
|
|
69
|
-
this.createWss[portIndex] = wss;
|
|
70
|
-
|
|
71
|
-
// HTTP 请求(非 upgrade)
|
|
72
|
-
server.on('request', (req, res) => {
|
|
73
|
-
this._handleHttp(req, res, session);
|
|
74
|
-
});
|
|
68
|
+
this.createServers[portIndex] = server;
|
|
75
69
|
|
|
76
|
-
//
|
|
70
|
+
// 端口池端口复用主 proxy 的 wss——通过 localPort 区分
|
|
77
71
|
server.on('upgrade', (req, socket, head) => {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
socket.destroy();
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
wss.handleUpgrade(req, socket, head, (ws) => {
|
|
86
|
-
this._handleClientConnect(ws, req, session);
|
|
72
|
+
req._poolPortIndex = portIndex;
|
|
73
|
+
req._poolPort = port;
|
|
74
|
+
// 转发给主 proxy 的 wss 处理
|
|
75
|
+
this.mainProxy.handlePoolUpgrade(req, socket, head, portIndex, port);
|
|
87
76
|
});
|
|
77
|
+
|
|
78
|
+
server.on('request', (req, res) => {
|
|
79
|
+
this._handleHttp(req, res, session);
|
|
88
80
|
});
|
|
89
81
|
|
|
90
82
|
server.on('error', (err) => {
|
|
@@ -100,7 +92,6 @@ class PortPoolManager {
|
|
|
100
92
|
});
|
|
101
93
|
|
|
102
94
|
this.createServers[portIndex] = server;
|
|
103
|
-
this.createWss[portIndex] = wss;
|
|
104
95
|
}
|
|
105
96
|
|
|
106
97
|
_startTakeoverPort() {
|
|
@@ -195,6 +186,10 @@ class PortPoolManager {
|
|
|
195
186
|
await this._ensureVisible(session, pluginWs, msg.sessionId);
|
|
196
187
|
}
|
|
197
188
|
|
|
189
|
+
if (msg.method === 'Network.enable' || msg.method === 'Page.startScreencast') {
|
|
190
|
+
// 已转发,继续
|
|
191
|
+
}
|
|
192
|
+
|
|
198
193
|
// 命令:分配新 id,记录映射(含 method 名供响应后处理),转发给 plugin
|
|
199
194
|
const newId = `pool${session.portIndex}_${msg.id}`;
|
|
200
195
|
session.pendingRequests.set(newId, {
|
package/server/proxy-server.js
CHANGED
|
@@ -456,6 +456,15 @@ wss.on('connection', (ws, req) => {
|
|
|
456
456
|
const path = url.pathname;
|
|
457
457
|
const pathParts = path.split('/').filter(Boolean);
|
|
458
458
|
|
|
459
|
+
// v3.0 端口池连接:走 PortPoolManager 的隔离逻辑
|
|
460
|
+
if (req._poolPortIndex !== undefined && portPool) {
|
|
461
|
+
const session = portPool.portSessions[req._poolPortIndex];
|
|
462
|
+
if (session) {
|
|
463
|
+
portPool._handleClientConnect(ws, req, session);
|
|
464
|
+
return;
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
|
|
459
468
|
const clientInfo = {
|
|
460
469
|
ip: req.socket.remoteAddress,
|
|
461
470
|
port: req.socket.remotePort
|
|
@@ -2130,6 +2139,12 @@ portPool = new PortPoolManager({
|
|
|
2130
2139
|
for (const ws of pluginConnections) return ws;
|
|
2131
2140
|
return null;
|
|
2132
2141
|
},
|
|
2142
|
+
handlePoolUpgrade: (req, socket, head, portIndex, port) => {
|
|
2143
|
+
req._poolPortIndex = portIndex;
|
|
2144
|
+
wss.handleUpgrade(req, socket, head, (ws) => {
|
|
2145
|
+
wss.emit('connection', ws, req);
|
|
2146
|
+
});
|
|
2147
|
+
},
|
|
2133
2148
|
getAllTargets: async (portIndex) => {
|
|
2134
2149
|
const session = portPool.portSessions[portIndex];
|
|
2135
2150
|
if (!session) return [];
|