Преглед на файлове

fix(topology): render the WAN-peer chip on PPPoE fleets and stamp wanSide in /api/devices (#1517)

Closes #1516.

The chip pick now prefers a device stamped wanSide (the ARP-on-WAN-port evidence from #1488) with the IP==WAN-gateway match kept as fallback, which is what PPPoE fleets need where the gateway IP is the ISP peer. Adds the missing wan-peer case to the semantic link renderer and a defensive chip creation before chipById when only the semantic link knows the peer. attributedDevices() now resolves the gateway's WAN port instead of passing an empty one, so /api/devices agrees with the overview about the WAN-side stamp.

Co-authored-by: Bann-DEV <bann.dev@gmail.com>
Bann-DEV преди 1 месец
родител
ревизия
c113513b41
променени са 3 файла, в които са добавени 54 реда и са изтрити 6 реда
  1. 31 4
      app/src/components/topology/model.ts
  2. 9 1
      app/src/data/types.ts
  3. 14 1
      server-go/internal/adapters/live.go

+ 31 - 4
app/src/components/topology/model.ts

@@ -819,9 +819,9 @@ export function buildTopologyModel({ routers, devices, wan, wireguard, distribut
   // junto al enlace WAN), no como cliente LAN. La semántica server ya lo
   // excluye de los anillos; aquí se excluye de la lista online para el
   // fallback sin semántica y se reserva el device para el chip.
-  const wanPeerDev = devices.find(
-    (d) => d.online && wan.gateway && d.ip && d.ip === wan.gateway,
-  )
+  const wanPeerDev =
+    devices.find((d) => d.online && d.wanSide) ??
+    devices.find((d) => d.online && wan.gateway && d.ip && d.ip === wan.gateway)
   // Chip del wan peer, creado tras fijar la posición final de Internet.
   let wanPeerChip: ChipNode | null = null
   const online = devices.filter(
@@ -1119,7 +1119,7 @@ export function buildTopologyModel({ routers, devices, wan, wireguard, distribut
         const gwTop = { x: gatewayNode.x, y: gatewayNode.y - gatewayNode.r }
         const mx = (internetNode.x + gwTop.x) / 2
         const my = (internetNode.y + gwTop.y) / 2
-        wanPeerChip = { ...mkChip(wanPeerDev, 'internet'), x: mx + 46, y: my }
+        wanPeerChip = { ...mkChip(wanPeerDev, 'internet'), x: mx, y: my }
         chips.push(wanPeerChip)
       }
       // APs y switches: a lo largo del vector desde el gateway hasta su posición
@@ -1457,6 +1457,20 @@ export function buildTopologyModel({ routers, devices, wan, wireguard, distribut
       from: dv.node.parent ?? dv.node.routerId, to: dv.id,
     })
   }
+  // #1485/#1495: con semántica del server, el enlace wan-peer llega en
+  // topology.links; el chip debe existir ANTES de chipById o el enlace
+  // quedaría colgando de un extremo inexistente (pasaba en flotas PPPoE,
+  // donde el fallback por IP no casa y solo la semántica conoce el peer).
+  if (
+    !wanPeerChip && wanPeerDev && gatewayNode &&
+    (topology?.links ?? []).some((l) => l.kind === 'wan-peer')
+  ) {
+    const gwTop = { x: gatewayNode.x, y: gatewayNode.y - gatewayNode.r }
+    const mx = (internetNode.x + gwTop.x) / 2
+    const my = (internetNode.y + gwTop.y) / 2
+    wanPeerChip = { ...mkChip(wanPeerDev, 'internet'), x: mx, y: my }
+    chips.push(wanPeerChip)
+  }
   const chipById = new Map(chips.map((c) => [c.id, c]))
   const hubPos = (hubId: string): { x: number; y: number; r: number } | null => {
     const rn = routerById.get(hubId)
@@ -1540,6 +1554,19 @@ export function buildTopologyModel({ routers, devices, wan, wireguard, distribut
             from: sl.from, to: sl.to,
           }
         }
+        case 'wan-peer': {
+          // #1485/#1495: el chip ya se creó antes de chipById; aquí solo se
+          // dibuja el enlace Internet↔chip que emite la semántica.
+          if (!gatewayNode || !wanPeerChip) return null
+          const a = pos(internetNode.x, internetNode.y, angleTo(internetNode.x, internetNode.y, wanPeerChip.x, wanPeerChip.y), internetNode.r + 2)
+          return {
+            id: 'wan-peer', kind: 'wan-peer',
+            d: `M ${a.x} ${a.y} L ${wanPeerChip.x} ${wanPeerChip.y}`,
+            lx: 0, ly: 0, label: '',
+            width: 1.5, ...flowFor(30),
+            from: 'internet', to: wanPeerChip.id,
+          }
+        }
         case 'uplink': {
           const i = apNodes.findIndex((n) => n.id === sl.to)
           const node = i >= 0 ? apNodes[i] : routerById.get(sl.to)

+ 9 - 1
app/src/data/types.ts

@@ -261,6 +261,14 @@ export interface Device {
    * (hipervisor / switch gestionado identificado).
    */
   attachTo?: string
+  /**
+   * #1485: la única evidencia de este equipo es un ARP en la boca WAN del
+   * gateway (primer salto del enlace: ONT/módem en bridge). El server lo
+   * sella y el mapa lo reserva como chip bajo el nodo Internet; sin esto el
+   * chip solo salía cuando su IP coincidía con la puerta WAN, que en PPPoE
+   * es el peer del ISP y no la ONT bridged.
+   */
+  wanSide?: boolean
   /**
    * Rol de infraestructura sellado server-side (SPEC-65 D65-2): la app NO
    * infiere; pinta el badge si viene. Ausente = dispositivo normal (la app
@@ -469,7 +477,7 @@ export interface TopoSemLink {
   /** id: router | device | distnode | "internet" | "peer-<wgPeerId>" */
   from: string
   to: string
-  kind: 'wan' | 'uplink' | 'wired' | 'dist' | 'wg'
+  kind: 'wan' | 'wan-peer' | 'uplink' | 'wired' | 'dist' | 'wg'
   /** puerto físico si aplica */
   port?: string
   /** velocidad negociada en la boca del padre (Mbps), 0/ausente = sin dato (#1321) */

+ 14 - 1
server-go/internal/adapters/live.go

@@ -4388,9 +4388,22 @@ func (l *Live) attributedDevices() []Device {
 	// (que sobreescribe attachTo con ground truth del cluster).
 	detailNowMs := time.Now().UnixMilli()
 	detailMemo := l.updateFdbMemo(polled, detailNowMs)
+	// #1485 también en el detalle: sin la boca WAN, el bloque de ARP WAN-side
+	// no sella WanSide y /api/devices discrepa del overview (la ONT bridged
+	// vuelve como cliente cableado del gateway y el mapa pierde el chip del
+	// peer WAN). Misma resolución que en buildOverview.
+	detailWanPort := ""
+	l.mu.Lock()
+	gwCfg := l.gatewayCfg
+	l.mu.Unlock()
+	if gwCfg != nil {
+		if gp := polled[gwCfg.ID]; gp != nil {
+			detailWanPort = gp.wanInfo.Port
+		}
+	}
 	devices, _ := inferTopology(
 		overlayStickyFdb(polled, detailMemo, detailNowMs),
-		l.buildDevices(polled, ""),
+		l.buildDevices(polled, detailWanPort),
 	)
 	// #1292: lápidas fuera de la lista del detalle (la fuente viva puede
 	// seguir emitiendo la MAC borrada).