Skip to content

Commit 57a260e

Browse files
committed
Fixed an exception error in tunnel app when an endpoint goes offline
1 parent 48245d6 commit 57a260e

File tree

2 files changed

+14
-53
lines changed

2 files changed

+14
-53
lines changed

agent/apps/ztm/tunnel/api.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ export default function ({ app, mesh }) {
4949
inbound: [],
5050
outbound: [],
5151
})
52-
var ep = (endpoints[params.ep] ??= {})
52+
var ep = (endpoints[params.ep] ??= { id: params.ep })
5353
if (filename.endsWith('/inbound.json')) tunnel.inbound.push(ep)
5454
if (filename.endsWith('/outbound.json')) tunnel.outbound.push(ep)
5555
}
5656
})
5757
return mesh.discover(Object.keys(endpoints)).then(
5858
list => {
59-
list.forEach(ep => Object.assign(endpoints[ep.id], ep))
59+
list.filter(ep => ep).forEach(ep => Object.assign(endpoints[ep.id], ep))
6060
return [
6161
...Object.values(tcp),
6262
...Object.values(udp),
@@ -110,14 +110,14 @@ export default function ({ app, mesh }) {
110110
Object.keys(files).forEach(filename => {
111111
var params = inboundPattern(filename) || outboundPattern(filename)
112112
if (params) {
113-
var ep = (endpoints[params.ep] ??= {})
113+
var ep = (endpoints[params.ep] ??= { id: params.ep })
114114
if (filename.endsWith('/inbound.json')) inbound.push(ep)
115115
if (filename.endsWith('/outbound.json')) outbound.push(ep)
116116
}
117117
})
118118
return mesh.discover(Object.keys(endpoints)).then(
119119
list => {
120-
list.forEach(ep => Object.assign(endpoints[ep.id], ep))
120+
list.filter(ep => ep).forEach(ep => Object.assign(endpoints[ep.id], ep))
121121
return {
122122
protocol,
123123
name,
@@ -387,7 +387,7 @@ export default function ({ app, mesh }) {
387387
}
388388
})
389389
return mesh.discover(eps).then(
390-
endpoints => endpoints.filter(ep => ep.online).map(ep => ep.id)
390+
endpoints => endpoints.filter(ep => ep?.online).map(ep => ep.id)
391391
)
392392
}
393393
)

agent/apps/ztm/tunnel/cli.js

Lines changed: 9 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -139,18 +139,18 @@ export default function ({ api, utils }) {
139139
return api.allTunnels().then(
140140
list => {
141141
printTable(list, {
142-
'NAME': r => r.name,
142+
'NAME': r => `${r.protocol}/${r.name}`,
143143
'INBOUND': r => {
144144
var ib = r.inbound
145145
if (ib.length === 0) return '-'
146146
if (ib.length > 10) ib.length = 10
147-
return ib.map(ep => ep.name).join(', ')
147+
return ib.map(ep => ep.name || ep.id).join(', ')
148148
},
149149
'OUTBOUND': r => {
150150
var ob = r.outbound
151151
if (ob.length === 0) return '-'
152152
if (ob.length > 10) ob.length = 10
153-
return ob.map(ep => ep.name).join(', ')
153+
return ob.map(ep => ep.name || ep.id).join(', ')
154154
},
155155
})
156156
}
@@ -193,54 +193,15 @@ export default function ({ api, utils }) {
193193

194194
function describeTunnel(tunnelName) {
195195
var obj = validateObjectName(tunnelName)
196-
var protocol = obj.protocol
197-
var name = obj.name
198-
var inbound = []
199-
var outbound = []
200-
return api.allEndpoints().then(
201-
endpoints => Promise.all(endpoints.map(
202-
ep => api.allTunnels(ep.id).then(
203-
ret => {
204-
if (ret) {
205-
ret.inbound?.forEach?.(i => {
206-
if (i.protocol === protocol && i.name === name) {
207-
inbound.push({ ep, in: i })
208-
}
209-
})
210-
ret.outbound?.forEach?.(o => {
211-
if (o.protocol === protocol && o.name === name) {
212-
outbound.push({ ep, out: o })
213-
}
214-
})
215-
}
216-
}
217-
)
218-
))
219-
).then(() => {
220-
output(`Tunnel: ${protocol}/${name}\n`)
196+
return api.getTunnel(obj.protocol, obj.name).then(tunnel => {
197+
output(`Tunnel: ${tunnel.protocol}/${tunnel.name}\n`)
221198
output(`Inbound:\n`)
222-
inbound.forEach(i => {
223-
output(` Endpoint: ${i.ep.name} (${i.ep.id})\n`)
224-
output(` Listens:\n`)
225-
i.in.listens.forEach(l => output(` ${l.ip}:${l.port}\n`))
226-
output(` Exits:\n`)
227-
i.in.exits.forEach(e => output(` ${e}\n`))
228-
if (i.in.exits.length === 0) output(` (all endpoints)\n`)
199+
tunnel.inbound.forEach(ep => {
200+
output(` Endpoint: ${ep.name || '(n/a)'} (${ep.id})\n`)
229201
})
230202
output(`Outbound:\n`)
231-
outbound.forEach(o => {
232-
output(` Endpoint: ${o.ep.name} (${o.ep.id})\n`)
233-
output(` Targets:\n`)
234-
o.out.targets.forEach(t => output(` ${t.host}:${t.port}\n`))
235-
output(` Entrances:\n`)
236-
o.out.entrances.forEach(e => output(` ${e}\n`))
237-
if (o.out.entrances.length === 0) output(` (all endpoints)\n`)
238-
output(` Users:\n`)
239-
if (o.out.users && o.out.users.length > 0) {
240-
o.out.users.forEach(u => output(` ${u}\n`))
241-
} else {
242-
output(` (all users)\n`)
243-
}
203+
tunnel.outbound.forEach(ep => {
204+
output(` Endpoint: ${ep.name || '(n/a)'} (${ep.id})\n`)
244205
})
245206
})
246207
}

0 commit comments

Comments
 (0)