mirror of
https://github.com/mudler/edgevpn.git
synced 2025-10-09 18:50:39 +08:00
🐛 Fixup peerstore view, display node state
This commit is contained in:
25
api/api.go
25
api/api.go
@@ -151,8 +151,24 @@ func API(ctx context.Context, l string, defaultInterval, timeout time.Duration,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sum up state also from services
|
||||||
|
online := services.AvailableNodes(ledger, 10*time.Minute)
|
||||||
|
p := map[string]interface{}{}
|
||||||
|
|
||||||
|
for _, v := range online {
|
||||||
|
p[v] = nil
|
||||||
|
}
|
||||||
|
|
||||||
for _, v := range peers {
|
for _, v := range peers {
|
||||||
list = append(list, apiTypes.Peer{ID: v.String()})
|
_, exists := p[v.String()]
|
||||||
|
if !exists {
|
||||||
|
p[v.String()] = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for id, _ := range p {
|
||||||
|
list = append(list, apiTypes.Peer{ID: id, Online: true})
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.JSON(http.StatusOK, list)
|
return c.JSON(http.StatusOK, list)
|
||||||
@@ -163,12 +179,7 @@ func API(ctx context.Context, l string, defaultInterval, timeout time.Duration,
|
|||||||
for _, v := range e.Host().Network().Peerstore().Peers() {
|
for _, v := range e.Host().Network().Peerstore().Peers() {
|
||||||
list = append(list, apiTypes.Peer{ID: v.String()})
|
list = append(list, apiTypes.Peer{ID: v.String()})
|
||||||
}
|
}
|
||||||
peers, err := e.MessageHub.ListPeers()
|
return c.JSON(http.StatusOK, list)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return c.JSON(http.StatusOK, peers)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
ec.GET(UsersURL, func(c echo.Context) error {
|
ec.GET(UsersURL, func(c echo.Context) error {
|
||||||
|
@@ -138,6 +138,7 @@
|
|||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<th ><abbr title="ID">PeerID</abbr></th>
|
<th ><abbr title="ID">PeerID</abbr></th>
|
||||||
|
<th ><abbr title="Online">Online</abbr></th>
|
||||||
|
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@@ -162,6 +163,7 @@
|
|||||||
},
|
},
|
||||||
"columns": [
|
"columns": [
|
||||||
{ "data": "ID" },
|
{ "data": "ID" },
|
||||||
|
{ "data": "Online" },
|
||||||
],
|
],
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
@@ -16,5 +16,6 @@
|
|||||||
package types
|
package types
|
||||||
|
|
||||||
type Peer struct {
|
type Peer struct {
|
||||||
ID string
|
ID string
|
||||||
|
Online bool
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user