feat(routers): integrate Banana Pi Client API and onboard LibreSpeed measurements
Discover Ethernet routers under the board, map physical SIM slots, expose vendor controls and real telemetry, and provide packaged VPS speed tests with a live monochrome gauge. Enforce compact typography across Core and Node UI.
This commit is contained in:
@@ -307,6 +307,10 @@ func (p *Pairing) sendEncoded(ctx context.Context, b CoreBinding, path string, p
|
||||
func (p *Pairing) channel(ctx context.Context) {
|
||||
instance := "agent_" + token()
|
||||
var changed <-chan struct{}
|
||||
var speedChanged <-chan struct{}
|
||||
if p.Routers != nil {
|
||||
speedChanged = p.Routers.SpeedtestUpdates()
|
||||
}
|
||||
if p.Sensors != nil {
|
||||
var unsubscribe func()
|
||||
changed, unsubscribe = p.Sensors.events.subscribe()
|
||||
@@ -473,6 +477,7 @@ func (p *Pairing) channel(ctx context.Context) {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case <-timer.C:
|
||||
case <-speedChanged:
|
||||
case <-changed:
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package node
|
||||
|
||||
import (
|
||||
"nodedc.local/mission-core/node-agent/internal/routers"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestRouterReadEndpointCannotDispatchWrites(t *testing.T) {
|
||||
read := routers.Command{Action: "inspect", Query: &routers.EvidenceQuery{Resource: "events"}}
|
||||
for _, action := range []string{"reboot", "recovery", "policy", "diagnostics", ""} {
|
||||
if routerRouteMatches("inspect", routers.Command{Action: action}) {
|
||||
t.Fatal("read endpoint admitted", action)
|
||||
}
|
||||
}
|
||||
if !routerRouteMatches("inspect", read) || routerRouteMatches("control", read) || routerRouteMatches("access", read) {
|
||||
t.Fatal("read route boundary")
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
func (p *Pairing) applyRouterCommands(raw json.RawMessage) {
|
||||
if p.Routers == nil || len(raw) > 4096 {
|
||||
if p.Routers == nil || len(raw) > 32768 {
|
||||
return
|
||||
}
|
||||
var commands []routers.Command
|
||||
@@ -33,7 +33,7 @@ func (s *Server) routerRoutes(mux *http.ServeMux) {
|
||||
}
|
||||
json.NewEncoder(w).Encode(s.Pairing.Routers.Snapshot())
|
||||
})
|
||||
submit := func(control bool) http.HandlerFunc {
|
||||
submit := func(kind string) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
if !s.authorized(w, r) {
|
||||
return
|
||||
@@ -42,7 +42,7 @@ func (s *Server) routerRoutes(mux *http.ServeMux) {
|
||||
if !decode(w, r, &command) {
|
||||
return
|
||||
}
|
||||
if (control != (command.Action != "")) || s.Pairing == nil || s.Pairing.Routers == nil || s.Pairing.Routers.Submit(command) != nil {
|
||||
if (!routerRouteMatches(kind, command)) || s.Pairing == nil || s.Pairing.Routers == nil || s.Pairing.Routers.Submit(command) != nil {
|
||||
http.Error(w, "Router unavailable", http.StatusConflict)
|
||||
return
|
||||
}
|
||||
@@ -51,6 +51,11 @@ func (s *Server) routerRoutes(mux *http.ServeMux) {
|
||||
json.NewEncoder(w).Encode(routers.Result{ID: command.ID, State: "queued"})
|
||||
}
|
||||
}
|
||||
mux.HandleFunc("POST /api/routers/access", submit(false))
|
||||
mux.HandleFunc("POST /api/routers/control", submit(true))
|
||||
mux.HandleFunc("POST /api/routers/access", submit("access"))
|
||||
mux.HandleFunc("POST /api/routers/control", submit("control"))
|
||||
mux.HandleFunc("POST /api/routers/inspect", submit("inspect"))
|
||||
}
|
||||
|
||||
func routerRouteMatches(kind string, command routers.Command) bool {
|
||||
return ((kind != "access") == (command.Action != "")) && ((kind == "inspect") == (command.Query != nil))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user