1
0
Fork 1
mirror of https://github.com/thatmattlove/hyperglass.git synced 2026-04-18 05:48:27 +00:00
thatmattlove-hyperglass/hyperglass/ui/components/path/chart.tsx
Wilhelm Schonfeldt 0398966062
feat: Add structured traceroute support with comprehensive IP enrichment
MAJOR NEW ARCHITECTURE - STRUCTURED TRACEROUTE:
- Complete rewrite of traceroute data processing with structured output
- Dedicated TracerouteResult and TracerouteHop data models
- Platform-specific parsers with unified output format
- Rich metadata including ASN, organization, country, and prefix information
- AS path visualization with organization names in React Flow charts

SUPPORTED PLATFORMS:
- TraceroutePluginMikrotik: Handles MikroTik's complex multi-table format
  * Progressive statistics parsing with deduplication
  * Timeout hop handling and continuation line processing
  * Loss percentage and RTT statistics extraction
- TraceroutePluginHuawei: Unix-style traceroute format parser
  * Standard hop_number ip_address rtt format support
  * Timeout hop detection with * notation
  * Automatic cleanup of excessive trailing timeouts

COMPREHENSIVE IP ENRICHMENT SYSTEM:
- Offline enrichment using BGP.tools bulk data (1.3M+ CIDR entries)
- PeeringDB integration for IXP detection and ASN organization data
- Ultra-fast pickle cache system with combined data files
- Integer-based bitwise IP matching for maximum performance
- Bulk ASN organization lookup capabilities
- Private/reserved IP handling with AS0 fallbacks
- Country code mapping from ASN database
- Graceful fallbacks for missing enrichment data

FRONTEND ENHANCEMENTS:
- New traceroute table components with consistent formatting
- Enhanced AS path visualization with organization names
- Improved copy-to-clipboard functionality with structured data
- Unified table styling across BGP and traceroute results
- Better error handling and loading states

CONCURRENT PROCESSING INFRASTRUCTURE:
- Thread executor implementation for blocking I/O operations
- Query deduplication system to prevent resource conflicts
- Non-blocking Redis cache operations using asyncio executors
- Event coordination for waiting requests
- Background cleanup for completed operations
- Prevents website hangs during long-running queries

PLUGIN ARCHITECTURE IMPROVEMENTS:
- Platform-aware plugin system with proper execution restrictions
- Enhanced MikroTik garbage output cleaning
- IP enrichment plugins for both BGP routes and traceroute
- Conditional plugin execution based on platform detection
- Proper async/sync plugin method handling

CRITICAL BUG FIXES:
- Fixed double AS prefix bug (ASAS123456 → AS123456)
- Resolved TracerouteHop avg_rtt field/property conflicts
- Corrected Huawei traceroute source field validation
- Fixed plugin platform restriction enforcement
- Eliminated blocking I/O causing UI freezes
- Proper timeout and empty response caching prevention
- Enhanced private IP range detection and handling

PERFORMANCE OPTIMIZATIONS:
- Pickle cache system reduces startup time from seconds to milliseconds
- Bulk processing for ASN organization lookups
- Simplified IXP detection using single PeeringDB API call
- Efficient CIDR network sorting and integer-based lookups
- Reduced external API calls by 90%+
- Optimized memory usage for large datasets

API & ROUTING ENHANCEMENTS:
- Enhanced API routes with proper error handling
- Improved middleware for concurrent request processing
- Better state management and event handling
- Enhanced task processing with thread pool execution

This represents a complete transformation of hyperglass traceroute capabilities,
moving from basic text output to rich, structured data with comprehensive
network intelligence and concurrent processing support.
2025-09-28 13:48:04 +02:00

89 lines
2.4 KiB
TypeScript

import { Badge, Box, Flex, VStack } from '@chakra-ui/react';
import { useMemo } from 'react';
import ReactFlow, {
Background,
ReactFlowProvider,
Handle,
Position,
isNode,
isEdge,
} from 'reactflow';
import { useConfig } from '~/context';
import { useColorToken, useColorValue } from '~/hooks';
import { Controls } from './controls';
import { useElements } from './use-elements';
import type { NodeProps as ReactFlowNodeProps } from 'reactflow';
interface ChartProps {
data: AllStructuredResponses;
}
interface NodeProps<D extends unknown> extends Omit<ReactFlowNodeProps, 'data'> {
data: D;
}
export interface NodeData {
asn: string;
name: string;
hasChildren: boolean;
hasParents?: boolean;
}
export const Chart = (props: ChartProps): JSX.Element => {
const { data } = props;
const { primaryAsn, orgName } = useConfig();
const dots = useColorToken('colors', 'blackAlpha.500', 'whiteAlpha.400');
const elements = useElements({ asn: primaryAsn, name: orgName }, data);
const nodes = useMemo(() => elements.filter(isNode), [elements]);
const edges = useMemo(() => elements.filter(isEdge), [elements]);
return (
<ReactFlowProvider>
<Box w="100%" h={{ base: '100vh', lg: '70vh' }} zIndex={1}>
<ReactFlow
snapToGrid
nodes={nodes}
edges={edges}
nodeTypes={{ ASNode }}
edgesUpdatable={false}
nodesDraggable={false}
nodesConnectable={false}
onInit={inst => setTimeout(() => inst.fitView(), 0)}
proOptions={{ hideAttribution: true }}
>
<Background color={dots} />
<Controls />
</ReactFlow>
</Box>
</ReactFlowProvider>
);
};
const ASNode = (props: NodeProps<NodeData>): JSX.Element => {
const { data } = props;
const { asn, name, hasChildren, hasParents } = data;
const color = useColorValue('black', 'white');
const bg = useColorValue('white', 'whiteAlpha.200');
return (
<>
{hasChildren && <Handle type="source" position={Position.Top} />}
<Box py={2} px={3} bg={bg} minW={32} minH={8} color={color} boxShadow="md" borderRadius="md">
<VStack spacing={2}>
<Flex fontSize="lg">
{name}
</Flex>
<Badge fontFamily="mono" fontWeight="normal" fontSize="sm" colorScheme="primary">
{asn}
</Badge>
</VStack>
</Box>
{hasParents && <Handle type="target" position={Position.Bottom} />}
</>
);
};