How swagnikdutta/netprobe works
Main Components
• Command-Line Interface (CLI) Component:
• Represented by the cmd/main.go file.
• This is the entry point (npctl) which interacts with the user and invokes various underlying network utilities.
• Dialer Module:
• Located in pkg/dialer.
• Provides the abstraction for making network connections.
• Protocol Implementations:
• Found in pkg/protocols – with subdirectories for “icmp” and “ipv4”.
• Each protocol directory contains implementation files (e.g., icmp.go, ipv4.go), serializers, and type definitions for handling protocol-specific data and communication.
• Utilities:
• Located in pkg/utilities.
• Contains the “dig” subpackage (for DNS lookups) and the “ping” subpackage (for ICMP-based latency checks), along with some general network helper functions.
• General Utilities:
• pkg/utils.go and pkg/protocols/util.go serve to provide common helper functions shared across various modules.
Relationships and Data Flow
• The CLI (cmd/main.go) interacts with the user and issues commands.
• When a command is received (for example, to perform a “ping” or “dig”), the CLI calls into the appropriate utility function from pkg/utilities/ping or pkg/utilities/dig.
• These utilities rely on the underlying protocol implementations in pkg/protocols (ICMP for ping, IPv4 for low-level networking operations) to correctly format, serialize, and handle network packets.
• The dialer (pkg/dialer) provides the necessary low-level control for establishing network connections, feeding into the protocol modules.
• The common utilities ensure that configurations, logging, and network data processing are consistent across the modules.
Architectural Patterns and Design Principles
• Layered Architecture: There is a clear separation between the user interface (CLI), core networking logic (protocol and utility packages), and low-level network operations (dialer).
• Modularity: Each protocol (ICMP, IPv4) and utility (dig, ping) are encapsulated in their own package, which improves maintainability and extensibility.
• Abstraction: The dialer package abstracts network connection details, while the protocol packages abstract the specifics of handling network packet structures and serialization.