fix(ui): связывать OSPF узлы по подтверждённым ID
This commit is contained in:
1 parent
7a68ae8184
commit
259c5c3014
16 files changed
+123
-41
No files matched your search
@@ -0,0 +1,19 @@
|
||||
type InstanceIdentity = { serverId: number; routerId: string | null }
|
||||
export function deriveOspfRouterIdentity(instances: InstanceIdentity[]) {
|
||||
const devices = new Map<string, { ids: Set<string>; unknown: boolean }>()
|
||||
for(const instance of instances) {
|
||||
const id=String(instance.serverId), value=instance.routerId?.trim()
|
||||
const entry=devices.get(id) ?? {ids:new Set<string>(),unknown:false}
|
||||
const parts=value?.split(".")
|
||||
if(!value || value === "0.0.0.0" || !parts || parts.length!==4 || parts.some(part=>!/^\d{1,3}$/.test(part) || Number(part)>255)) entry.unknown=true
|
||||
else entry.ids.add(value)
|
||||
devices.set(id,entry)
|
||||
}
|
||||
const routerIds: Record<string,string> = {}
|
||||
for(const [device,entry] of devices) if(!entry.unknown && entry.ids.size===1)routerIds[device]=[...entry.ids][0]
|
||||
const reverse = new Map<string,string | null>()
|
||||
for(const [device,id] of Object.entries(routerIds)) reverse.set(id,reverse.has(id) && reverse.get(id)!==device ? null : device)
|
||||
const serverByRouterId: Record<string,string> = {}
|
||||
for(const [id,device] of reverse) if(device!==null)serverByRouterId[id]=device
|
||||
return {routerIds,serverByRouterId}
|
||||
}
|
||||
Reference in new issue
Block a user