Skip to content

Commit

Permalink
Skip offline endpoints when looking for a tunnel exit
Browse files Browse the repository at this point in the history
  • Loading branch information
pajama-coder committed Oct 21, 2024
1 parent 90bcdf6 commit e69ee6b
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions agent/apps/ztm/tunnel/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,23 +277,23 @@ export default function ({ app, mesh }) {
.onStart(() =>
((i.exits && i.exits.length > 0)
? Promise.resolve(i.exits)
: mesh.discover().then(list => list.map(ep => ep.id))
).then(exits => Promise.all(
: mesh.discover().then(list => list.filter(ep => ep.online).map(ep => ep.id))
).then(exits => Promise.any(
exits.map(
id => getOutbound(id, protocol, name).then(
o => o ? { ep: id, ...o } : null
).catch(() => null)
o => {
if (!o) throw null
if (!canAccess(o, app.endpoint.id, app.username)) throw null
return id
}
)
)
)).then(list => {
var ep = app.endpoint.id
var user = app.username
list = list.filter(o => (o && canAccess(o, ep, user)))
if (list.length > 0) {
$selectedEP = list[Math.floor(Math.random() * list.length)].ep
app.log(`Connect to ep ${$selectedEP} for ${protocol}/${name}`)
} else {
app.log(`No exit found for ${protocol}/${name}`)
}
)).then(exit => {
$selectedEP = exit
app.log(`Connect to ep ${$selectedEP} for ${protocol}/${name}`)
return new Data
}).catch(() => {
app.log(`No exit found for ${protocol}/${name}`)
return new Data
})
)
Expand Down

0 comments on commit e69ee6b

Please sign in to comment.