Skip to content

Commit

Permalink
Multiple tunnels at once
Browse files Browse the repository at this point in the history
  • Loading branch information
LuKks committed Oct 20, 2024
1 parent 630965e commit bbe5391
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions lib/bin/tunnel.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ module.exports = async function tunnel (keyOrName, opts = {}) {
await keygen({ f: keyFilename })
}

if (!opts.L && !opts.R) {
throw new Error('-L o -R is required')
}

const serverPublicKey = await getKnownPeer(keyOrName, { verbose: true })

const hs = new Hypershell({ bootstrap: opts.bootstrap })
Expand All @@ -22,14 +26,18 @@ module.exports = async function tunnel (keyOrName, opts = {}) {
keyPair: await fileToKeyPair(keyFilename)
})

let proxy = null
const proxies = []

if (opts.L) {
proxy = await tunnel.local(opts.L)
} else if (opts.R) {
proxy = await tunnel.remote(opts.R)
} else {
throw new Error('-L o -R is required')
for (const local of opts.L) {
proxies.push(await tunnel.local(local))
}
}

if (opts.R) {
for (const remote of opts.R) {
proxies.push(await tunnel.remote(remote))
}
}

console.log('Tunnel is ready!')
Expand All @@ -43,7 +51,9 @@ module.exports = async function tunnel (keyOrName, opts = {}) {
}

async function close () {
await proxy.close()
for (const proxy of proxies) {
await proxy.close()
}
await tunnel.close()
await hs.destroy()
}
Expand Down

0 comments on commit bbe5391

Please sign in to comment.