How datahop/kademlia-simulator works
Main Components
• Simulation Engine: This is the heart of the project and is based on PeerSim. It handles core simulation functions such as event scheduling, network node interactions, and protocol executions.
• Configuration Module: Contains multiple configuration files under simulator/config that define different simulation scenarios (e.g., various Kademlia and DAS protocol configurations, including malicious cases).
• Protocol Implementations: Under simulator/src/main/java/peersim:
– Core Simulation Classes from the PeerSim framework (such as Node, Network, Scheduler, etc.).
– Specialized Kademlia components (found in the peersim/kademlia package) and its extensions for DAS protocols. These include classes for protocol configuration, node management, routing tables, traffic generators, and operations (e.g., PutOperation, GetOperation).
– Additional simulation protocols and dynamics (for example, ‘cdsim’ for cyclic simulations, ‘edsim’ for event-driven simulations, and the ‘dynamics’ and ‘reports’ packages for network behaviors and output generation).
• Utility and Support Modules:
– Configuration management utilities (peersim/config) for processing simulation parameters.
– Graph operations and reporting (in packages such as peersim/graph and peersim/reports).
– Miscellaneous utilities (such as those in peersim/util and vector) providing statistical analysis, random distribution functions, etc.
• Visualization Component:
– The visualiser directory (with visualiser/app.py, index.py, and network_visualiser.py) works as a front-end visualization/log analysis tool that reads simulation log output (in visualiser/log_folder).
Relationships and Interactions
• The simulation is initiated by a shell script (simulator/run.sh) that ingests a configuration file (e.g., config/kademlia.cfg) and starts the simulation engine.
• The configuration module feeds parameters into the simulation engine (the PeerSim core) and its protocol instances.
• The protocol components (like Kademlia, DAS protocols) are plugged into the simulation framework. They interact with core modules (such as scheduling and node management) to emulate network behavior.
• Reporting and logging modules capture data as the simulation runs. This data is then consumed by the visualization component (the Python visualiser) for analysis and graphic representation.
• The various Java packages interconnect to allow operations and dynamic updates (for instance, the ‘dynamics’ subpackage influences how nodes or connections are modified at runtime).
Architectural Patterns and Design Principles
• Modular Design: The project is split into clearly separated concerns: configuration, simulation core (engine), protocol implementations, utilities, and visualization.
• Plugin / Extension Pattern: The simulation protocols (especially in the peersim/kademlia directory) are designed to be interchangeable or extensible. New protocols or malicious scenarios can be integrated by simply adding new configuration or protocol files.
• Event-Driven Simulation: PeerSim’s architecture uses event scheduling and progression of simulation time (especially evident in the ‘edsim’ and ‘cdsim’ packages).