src/vs/platform/remote/common/managedSocket.ts

145 LOC · 57 covered · 88 uncovered · 9 ranges · 7 concepts · 1 introducers · 6 tests

File neighbourhood

The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the filesrc/vs/platform/remote/common/remoteAgentConnection.ts · 839 LOCcommon/remoteAgentConnec…src/vs/platform/remote/common/remoteSocketFactoryService.ts · 60 LOCcommon/remoteSocketFacto…src/vs/platform/sign/common/sign.ts · 22 LOCcommon/sign.tssrc/vs/platform/tunnel/node/tunnelService.ts · 265 LOCnode/tunnelService.tssrc/vs/workbench/api/node/extHostTunnelService.ts · 419 LOCnode/extHostTunnelServic…src/vs/workbench/services/remote/common/tunnelModel.ts · 1042 LOCcommon/tunnelModel.tsextHostTunnelService.ts ×3 · 22 introduced LOCextHostTunnelService.ts …extHostTunnelService.ts ×2 · 21 introduced LOCextHostTunnelService.ts …extHostTunnelService.ts ×4 · 38 introduced LOCextHostTunnelService.ts …extHostTunnelService.ts ×2 · 23 introduced LOCextHostTunnelService.ts …extHostTunnelService.ts ×1 · 9 introduced LOCextHostTunnelService.ts …extHostTunnelService.ts ×1 · 17 introduced LOCextHostTunnelService.ts …remoteAgentConnection.ts ×53 · 823 introduced LOCremoteAgentConnection.ts…extHostTunnelService.test|title=ExtHostTunnelService findPorts|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/api/test/node/extHostTunnelService.test|title=ExtHostTunnelService findPorts|occurrence=1extHostTunnelService.tes…extHostTunnelService.test|title=ExtHostTunnelService getSockets|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/api/test/node/extHostTunnelService.test|title=ExtHostTunnelService getSockets|occurrence=1extHostTunnelService.tes…extHostTunnelService.test|title=ExtHostTunnelService loadConnectionTable|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/api/test/node/extHostTunnelService.test|title=ExtHostTunnelService loadConnectionTable|occurrence=1extHostTunnelService.tes…extHostTunnelService.test|title=ExtHostTunnelService loadListeningPorts|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/api/test/node/extHostTunnelService.test|title=ExtHostTunnelService loadListeningPorts|occurrence=1extHostTunnelService.tes…extHostTunnelService.test|title=ExtHostTunnelService parseIpAddress|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/api/test/node/extHostTunnelService.test|title=ExtHostTunnelService parseIpAddress|occurrence=1extHostTunnelService.tes…extHostTunnelService.test|title=ExtHostTunnelService tryFindRootPorts|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/api/test/node/extHostTunnelService.test|title=ExtHostTunnelService tryFindRootPorts|occurrence=1extHostTunnelService.tes…Focused file · src/vs/platform/remote/common/managedSocket.ts · 145 LOCcommon/managedSocket.ts

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.

1 > /*--------------------------------------------------------------------------------------------- remoteAgentConnection.ts ×53
2 > * Copyright (c) Microsoft Corporation. All rights reserved.
3 > * Licensed under the MIT License. See License.txt in the project root for license information.
4 > *--------------------------------------------------------------------------------------------*/
5 >
6 > import { VSBuffer, encodeBase64 } from '../../../base/common/buffer.js';
7 > import { Emitter, Event, PauseableEmitter } from '../../../base/common/event.js';
8 > import { Disposable, DisposableStore } from '../../../base/common/lifecycle.js';
9 > import { ISocket, SocketCloseEvent, SocketDiagnostics, SocketDiagnosticsEventType } from '../../../base/parts/ipc/common/ipc.net.js';
10 >
11 > export const makeRawSocketHeaders = (path: string, query: string, deubgLabel: string) => {
12 // https://tools.ietf.org/html/rfc6455#section-4
13 const buffer = new Uint8Array(16);
14 for (let i = 0; i < 16; i++) {
15 buffer[i] = Math.round(Math.random() * 256);
16 }
17 const nonce = encodeBase64(VSBuffer.wrap(buffer));
18
19 const headers = [
20 `GET ws://localhost${path}?${query}&skipWebSocketFrames=true HTTP/1.1`,
21 `Connection: Upgrade`,
22 `Upgrade: websocket`,
23 `Sec-WebSocket-Key: ${nonce}`
24 ];
25
26 return headers.join('\r\n') + '\r\n\r\n';
27 };
29 > export const socketRawEndHeaderSequence = VSBuffer.fromString('\r\n\r\n');
30 >
31 > export interface RemoteSocketHalf {
32 > onData: Emitter<VSBuffer>;
33 > onClose: Emitter<SocketCloseEvent>;
34 > onEnd: Emitter<void>;
35 > }
36 >
37 > /** Should be called immediately after making a ManagedSocket to make it ready for data flow. */
38 export async function connectManagedSocket<T extends ManagedSocket>(
39 socket: T,
40 path: string, query: string, debugLabel: string,
41 half: RemoteSocketHalf
42 ): Promise<T> {
43 socket.write(VSBuffer.fromString(makeRawSocketHeaders(path, query, debugLabel)));
44
45 const d = new DisposableStore();
46 try {
47 return await new Promise<T>((resolve, reject) => {
48 let dataSoFar: VSBuffer | undefined;
49 d.add(socket.onData(d_1 => {
50 if (!dataSoFar) {
51 dataSoFar = d_1;
52 } else {
53 dataSoFar = VSBuffer.concat([dataSoFar, d_1], dataSoFar.byteLength + d_1.byteLength);
54 }
55
56 const index = dataSoFar.indexOf(socketRawEndHeaderSequence);
57 if (index === -1) {
58 return;
59 }
60
61 resolve(socket);
62 // pause data events until the socket consumer is hooked up. We may
63 // immediately emit remaining data, but if not there may still be
64 // microtasks queued which would fire data into the abyss.
65 socket.pauseData();
66
67 const rest = dataSoFar.slice(index + socketRawEndHeaderSequence.byteLength);
68 if (rest.byteLength) {
69 half.onData.fire(rest);
70 }
71 }));
72
73 d.add(socket.onClose(err => reject(err ?? new Error('socket closed'))));
74 d.add(socket.onEnd(() => reject(new Error('socket ended'))));
75 });
76 } catch (e) {
77 socket.dispose();
78 throw e;
79 } finally {
80 d.dispose();
81 }
82 }
84 > export abstract class ManagedSocket extends Disposable implements ISocket {
85 > private readonly pausableDataEmitter = this._register(new PauseableEmitter<VSBuffer>());
86 >
87 > public onData: Event<VSBuffer> = (...args) => {
88 > if (this.pausableDataEmitter.isPaused) {
89 > queueMicrotask(() => this.pausableDataEmitter.resume());
90 > }
91 > return this.pausableDataEmitter.event(...args);
92 > };
93 > public onClose: Event<SocketCloseEvent>;
94 > public onEnd: Event<void>;
95 >
96 > private readonly didDisposeEmitter = this._register(new Emitter<void>());
97 > public onDidDispose = this.didDisposeEmitter.event;
98 >
99 > private ended = false;
100 >
101 > protected constructor(
102 private readonly debugLabel: string,
103 half: RemoteSocketHalf,
104 ) {
105 super();
106
107 this._register(half.onData);
108 this._register(half.onData.event(data => this.pausableDataEmitter.fire(data)));
109
110 this.onClose = this._register(half.onClose).event;
111 this.onEnd = this._register(half.onEnd).event;
112 }
114 > /** Pauses data events until a new listener comes in onData() */
115 > public pauseData() {
116 this.pausableDataEmitter.pause();
117 }
119 > /** Flushes data to the socket. */
120 > public drain(): Promise<void> {
121 return Promise.resolve();
122 }
124 > /** Ends the remote socket. */
125 > public end(): void {
126 this.ended = true;
127 this.closeRemote();
128 }
130 > public abstract write(buffer: VSBuffer): void;
131 > protected abstract closeRemote(): void;
132 >
133 > traceSocketEvent(type: SocketDiagnosticsEventType, data?: VSBuffer | Uint8Array | ArrayBuffer | ArrayBufferView | unknown): void {
134 SocketDiagnostics.traceSocketEvent(this, this.debugLabel, type, data);
135 }
137 > override dispose(): void {
138 if (!this.ended) {
139 this.closeRemote();
140 }
141
142 this.didDisposeEmitter.fire();
143 super.dispose();
144 }