mirror of
https://github.com/ipfs/kubo.git
synced 2026-03-03 15:27:57 +08:00
Merge pull request #2867 from ipfs/feature/api-offline
Add way to check if node is online or offline
This commit is contained in:
commit
a6fb581371
@ -44,8 +44,13 @@ Prints out information about your computer to aid in easier debugging.
|
||||
res.SetError(err, cmds.ErrNormal)
|
||||
return
|
||||
}
|
||||
node, err := req.InvocContext().GetNode()
|
||||
if err != nil {
|
||||
res.SetError(err, cmds.ErrNormal)
|
||||
return
|
||||
}
|
||||
|
||||
err = netInfo(info)
|
||||
err = netInfo(node.OnlineMode(), info)
|
||||
if err != nil {
|
||||
res.SetError(err, cmds.ErrNormal)
|
||||
return
|
||||
@ -117,7 +122,7 @@ func memInfo(out map[string]interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func netInfo(out map[string]interface{}) error {
|
||||
func netInfo(online bool, out map[string]interface{}) error {
|
||||
n := make(map[string]interface{})
|
||||
addrs, err := manet.InterfaceMultiaddrs()
|
||||
if err != nil {
|
||||
@ -130,6 +135,7 @@ func netInfo(out map[string]interface{}) error {
|
||||
}
|
||||
|
||||
n["interface_addresses"] = straddrs
|
||||
n["online"] = online
|
||||
out["net"] = n
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -17,7 +17,8 @@ test_expect_success "ipfs diag sys succeeds" '
|
||||
test_expect_success "output contains some expected keys" '
|
||||
grep "virt" output &&
|
||||
grep "interface_addresses" output &&
|
||||
grep "arch" output
|
||||
grep "arch" output &&
|
||||
grep "online" output
|
||||
'
|
||||
|
||||
test_expect_success "uname succeeds" '
|
||||
|
||||
Loading…
Reference in New Issue
Block a user