fix proxy

This commit is contained in:
JOLIMAITRE Matthieu 2023-12-10 23:24:28 +01:00
parent 33caad6317
commit 36891699c4

View file

@ -12,15 +12,19 @@ async function main() {
console.log("[proxy] listening on port", from_port, "redirecting to", to_ip, "port", to_port); console.log("[proxy] listening on port", from_port, "redirecting to", to_ip, "port", to_port);
for await (const connection of server) { for await (const connection of server) {
try { serve(to_ip, to_port, connection);
const client = await Deno.connect({ transport: "tcp", hostname: to_ip, port: parseInt(to_port) });
const promise_connection_done = connection.readable.pipeTo(client.writable);
const promise_client_done = client.readable.pipeTo(connection.writable);
await Promise.all([promise_client_done, promise_connection_done]);
} catch (_) { /* isok */ }
} }
} }
async function serve(to_ip: string, to_port: string, connection: Deno.Conn) {
try {
const client = await Deno.connect({ transport: "tcp", hostname: to_ip, port: parseInt(to_port) });
const promise_connection_done = connection.readable.pipeTo(client.writable);
const promise_client_done = client.readable.pipeTo(connection.writable);
await Promise.all([promise_client_done, promise_connection_done]);
} catch (_) { /* isok */ }
}
export function proxy_command(from_port: number, to_ip: string, to_port: number) { export function proxy_command(from_port: number, to_ip: string, to_port: number) {
const path = new URL("", import.meta.url).pathname; const path = new URL("", import.meta.url).pathname;
const args = [from_port, to_ip, to_port].map((v) => v.toString()); const args = [from_port, to_ip, to_port].map((v) => v.toString());