chore: use socks.Duplex constructor instead of extending (#31816)

This commit is contained in:
Max Schmitt 2024-07-23 15:44:16 +02:00 committed by GitHub
parent bbe5df3f5f
commit 526e4118fa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -26,17 +26,6 @@ import type { SocksSocketClosedPayload, SocksSocketDataPayload, SocksSocketReque
import { SocksProxy } from '../common/socksProxy';
import type * as channels from '@protocol/channels';
class SocksConnectionDuplex extends stream.Duplex {
constructor(private readonly writeCallback: (data: Buffer) => void) {
super();
}
override _read(): void { }
override _write(chunk: Buffer, encoding: BufferEncoding, callback: (error?: Error | null | undefined) => void): void {
this.writeCallback(chunk);
callback();
}
}
class SocksProxyConnection {
private readonly socksProxy: ClientCertificatesProxy;
private readonly uid: string;
@ -89,7 +78,13 @@ class SocksProxyConnection {
}
private _attachTLSListeners() {
this.internal = new SocksConnectionDuplex(data => this.socksProxy._socksProxy.sendSocketData({ uid: this.uid, data }));
this.internal = new stream.Duplex({
read: () => {},
write: (data, encoding, callback) => {
this.socksProxy._socksProxy.sendSocketData({ uid: this.uid, data });
callback();
}
});
const internalTLS = new tls.TLSSocket(this.internal, {
isServer: true,
key: fs.readFileSync(path.join(__dirname, '../../bin/socks-certs/key.pem')),