Skip to content

Commit e69ee6b

Browse files
committed
Skip offline endpoints when looking for a tunnel exit
1 parent 90bcdf6 commit e69ee6b

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

agent/apps/ztm/tunnel/api.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -277,23 +277,23 @@ export default function ({ app, mesh }) {
277277
.onStart(() =>
278278
((i.exits && i.exits.length > 0)
279279
? Promise.resolve(i.exits)
280-
: mesh.discover().then(list => list.map(ep => ep.id))
281-
).then(exits => Promise.all(
280+
: mesh.discover().then(list => list.filter(ep => ep.online).map(ep => ep.id))
281+
).then(exits => Promise.any(
282282
exits.map(
283283
id => getOutbound(id, protocol, name).then(
284-
o => o ? { ep: id, ...o } : null
285-
).catch(() => null)
284+
o => {
285+
if (!o) throw null
286+
if (!canAccess(o, app.endpoint.id, app.username)) throw null
287+
return id
288+
}
289+
)
286290
)
287-
)).then(list => {
288-
var ep = app.endpoint.id
289-
var user = app.username
290-
list = list.filter(o => (o && canAccess(o, ep, user)))
291-
if (list.length > 0) {
292-
$selectedEP = list[Math.floor(Math.random() * list.length)].ep
293-
app.log(`Connect to ep ${$selectedEP} for ${protocol}/${name}`)
294-
} else {
295-
app.log(`No exit found for ${protocol}/${name}`)
296-
}
291+
)).then(exit => {
292+
$selectedEP = exit
293+
app.log(`Connect to ep ${$selectedEP} for ${protocol}/${name}`)
294+
return new Data
295+
}).catch(() => {
296+
app.log(`No exit found for ${protocol}/${name}`)
297297
return new Data
298298
})
299299
)

0 commit comments

Comments
 (0)