From c3172a04b1afea2c4355ed7754650c8e484bfa32 Mon Sep 17 00:00:00 2001 From: SerinaNya <34389622+SerinaNya@users.noreply.github.com> Date: Thu, 27 Aug 2026 23:19:53 +0800 Subject: [PATCH] refactor(web)!: remove obsolete interfaces endpoint --- AGENTS.md | 6 ++-- dashboard | 2 +- .../network/klalb/web/KLALBWebServer.java | 32 ++----------------- 3 files changed, 7 insertions(+), 33 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 5c9ebac..16377ee 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -39,7 +39,7 @@ No test suite, no CI. Classes named `*Test*` (`nathole/`, `ntp/`) are manual `ma - Entrypoint `org.kne.cloud.network.klalb.KLALBMain`: load config → build `KLALBProxySystem` → open Swing GUI (`KLALBStateGUI3`) unless `"nogui": true` → start `KLALBWebServer` (if `"webUI": true` or web server enabled, default port `4665`) → interactive console (`help`, `links-state`, `route`, `kperf`, ...). - `org.kne.cloud.network.klalb.web.KLALBWebServer` — built-in HTTP/SSE server (JDK `HttpServer`): - - API endpoints: `/api/status`, `/api/events` (SSE stream, 200ms intervals), `/api/links`, `/api/links/action`, `/api/links/reconnect`, `/api/routes`, `/api/nodes` (topology graph), `/api/interfaces`, `/api/config`. + - API endpoints: `/api/status`, `/api/events` (SSE stream, 200ms intervals), `/api/links`, `/api/links/action`, `/api/links/reconnect`, `/api/routing-table`, `/api/nodes` (topology graph), `/api/node-info?address=` (on-demand full node info), `/api/config`. - Static file hosting / SPA fallback: serves `dashboard/dist/` assets directly. - `org.kne.cloud.network` — generic socket framework: `VirtualSocket*` hierarchy, `SocketBridge` port-forwarding proxies, `ProtocolDetector` (multi-protocol mux on one port), `MultiProtocolSocketAddress` = URI-style addresses (`tcp://`, `udp://`, `kltp://`, `ntp://`) dispatched through the `SocketType` registry. - `...network.klalb` — app core: `KLALBController` (the virtual SRv6 network), `KLALBRemoteLink` (WAN lines), `*Packet` wire-format classes, virtual socket implementations. @@ -59,7 +59,7 @@ No test suite, no CI. Classes named `*Test*` (`nathole/`, `ntp/`) are manual `ma Located in `dashboard/`: - **Git layout**: `dashboard/` is a separate git repo wired in as a submodule (own origin on `git.code.cq.cn`). Commit frontend changes inside `dashboard/` first, then bump the submodule pointer in the parent repo — parent-repo commits alone do not capture them. - **Stack**: Vite + React 19 + TypeScript + Tailwind CSS v4 + `@base-ui/react` (style: `base-nova`, icons: `lucide-react`, toasts: `@base-ui/react/toast`). -- **Routing**: Hash-based routing (`#/overview`, `#/connections`, `#/topology`, `#/settings`, etc.) for seamless SPA hosting under Java `KLALBWebServer`. +- **Routing**: Hash-based routing (`#/overview`, `#/connections`, `#/routing-table`, `#/topology`, `#/settings`) for seamless SPA hosting under Java `KLALBWebServer`. - **Package Manager**: `pnpm` (run all commands from `dashboard/` directory). - **Component installation**: **Must** use CLI via `pnpm dlx shadcn@latest add ` (e.g. `pnpm dlx shadcn@latest add alert card badge toast`). Never create or fake shadcn components manually. Non-shadcn libs (`@xyflow/react`, `d3-force`) are installed via plain `pnpm add`. - **Commands**: @@ -69,7 +69,9 @@ Located in `dashboard/`: - **Pages & data flow**: - Overview / Connections read the SSE stream (`use-klalb-sse.ts`, 200ms pushes of status + links). - Settings loads/saves `/api/config` (`use-klalb-config.ts`); save payload must keep legacy field aliases alongside new names for compatibility. + - Routing table polls `/api/routing-table` every 1s (`use-routing-table.ts`); `cost` is delay-derived and displayed in milliseconds. - Topology polls `/api/nodes` every 1s (`use-topology.ts`) — SSE does NOT carry topology. + - Selecting a topology node queries `/api/node-info`; remote node descriptions require a full SRv6 node-info request and can time out after 3s. - Topology layout: `d3-force` headless simulation (recomputed only when node/edge structure changes) rendered by `@xyflow/react` with custom `device-node` / `link-edge` components in `src/components/topology/`. - React hooks lint rule forbids `setState` synchronously inside effects — initialize form state via component `key` remount + lazy `useState(() => ...)` initializers (see `SettingsForm` pattern). diff --git a/dashboard b/dashboard index ad94d2c..89474b9 160000 --- a/dashboard +++ b/dashboard @@ -1 +1 @@ -Subproject commit ad94d2c2747b851546ed1a07d8df505bfda87b15 +Subproject commit 89474b9e91791b8efe098a13171e6ff962ad7ba1 diff --git a/src/org/kne/cloud/network/klalb/web/KLALBWebServer.java b/src/org/kne/cloud/network/klalb/web/KLALBWebServer.java index 19d7f71..d967389 100644 --- a/src/org/kne/cloud/network/klalb/web/KLALBWebServer.java +++ b/src/org/kne/cloud/network/klalb/web/KLALBWebServer.java @@ -68,10 +68,9 @@ public class KLALBWebServer { server.createContext("/api/links", this::handleLinks); server.createContext("/api/links/action", this::handleLinkAction); server.createContext("/api/links/reconnect", this::handleReconnectAll); - server.createContext("/api/routes", this::handleRoutes); + server.createContext("/api/routing-table", this::handleRoutingTable); server.createContext("/api/nodes", this::handleNodes); server.createContext("/api/node-info", this::handleNodeInfo); - server.createContext("/api/interfaces", this::handleInterfaces); server.createContext("/api/config", this::handleConfig); // Static Files / SPA Fallback Handler @@ -429,7 +428,7 @@ public class KLALBWebServer { } } - private void handleRoutes(HttpExchange exchange) throws IOException { + private void handleRoutingTable(HttpExchange exchange) throws IOException { if (handleCorsPreflight(exchange)) return; if (!"GET".equalsIgnoreCase(exchange.getRequestMethod())) { sendError(exchange, 405, "Method not allowed"); @@ -633,33 +632,6 @@ public class KLALBWebServer { sendJsonResponse(exchange, 200, result); } - private void handleInterfaces(HttpExchange exchange) throws IOException { - if (handleCorsPreflight(exchange)) return; - if (!"GET".equalsIgnoreCase(exchange.getRequestMethod())) { - sendError(exchange, 405, "Method not allowed"); - return; - } - - KLALBController kc = proxySystem.getKlalbController(); - JsonArray ifacesArray = new JsonArray(); - if (kc != null && kc.getNetworkInterfaceManager() != null) { - List ifaces = kc.getNetworkInterfaceManager().getAllAvaliableNetworkInterface(); - for (NetworkInterface nif : ifaces) { - JsonObject obj = new JsonObject(); - obj.addProperty("name", nif.getName()); - obj.addProperty("displayName", nif.getDisplayName()); - JsonArray ips = new JsonArray(); - List addrs = kc.getNetworkInterfaceManager().getNetworkInterfaceAddress(nif); - for (InetAddress a : addrs) { - ips.add(new JsonPrimitive(a.getHostAddress())); - } - obj.add("addresses", ips); - ifacesArray.add(obj); - } - } - sendJsonResponse(exchange, 200, ifacesArray); - } - private void handleConfig(HttpExchange exchange) throws IOException { if (handleCorsPreflight(exchange)) return; String method = exchange.getRequestMethod();