Skip to content

Add initial Eclipse attack simulation module with metrics collection#950

Merged
seetadev merged 115 commits into
libp2p:mainfrom
Fatumayattani:feature/attack-simulation
Feb 12, 2026
Merged

Add initial Eclipse attack simulation module with metrics collection#950
seetadev merged 115 commits into
libp2p:mainfrom
Fatumayattani:feature/attack-simulation

Conversation

@Fatumayattani

Copy link
Copy Markdown
Contributor

What was wrong?

This PR implements the initial setup for the Network Attack Simulation module in py-libp2p, as discussed in [[Discussion #929]] and tracked under Issue #57. The primary focus is on Eclipse attack simulation, building the test network, simulating malicious peers, and establishing the framework for network attack testing.

How was it fixed?

  • Added tests/security/attack_simulation/ submodule containing:

    Eclipse attack:

    • malicious_peer.py – Simulates malicious peer behavior
    • network_builder.py – Builds test networks with honest and malicious nodes
    • metrics_collector.py – Collects attack metrics during simulation
    • attack_scenarios.py – Defines different Eclipse attack scenarios
    • test_eclipse_simulation.py – Test suite validating network setup and malicious behavior

    Utilities:

    • Metrics calculation (attack_metrics.py)
    • Network monitoring (network_monitor.py)
    • Peer behavior simulation (peer_behavior_simulator.py)
    • Tests for utilities

    Configuration:

    • attack_configs.py – Attack configuration options
    • network_topologies.py – Predefined network topologies
  • Added README.md documenting module overview, structure, setup, usage, testing, metrics, roadmap, and Eclipse attack flow (Mermaid diagram)

  • All tests pass locally (6/6) confirming:

    • Network setup works as expected
    • Malicious peer behaviors execute correctly
    • Metrics collection framework functions properly

To-Do

  • Clean up commit history if necessary
  • Add or update documentation related to these changes

Cute Animal Picture

Cute White Cat

@seetadev

Copy link
Copy Markdown
Contributor

@Fatumayattani : Thank you for opening the PR on eclipse attack simulation.

Great effort indeed. CCing @acul71, @yashksaini-coder, @bomanaps for their thoughts and feedback. This PR will indeed impact the py-libp2p library.

There is one CI/CD issue too, which is not related to your pull request.

I investigated it and documented it at #949 .

@yashksaini-coder , @sumanjeet0012 and @acul71 are fixing it. We will soon have all the CI/CD tests passing.

@Fatumayattani : Will re-run CI/CD pipeline once the issue is fixed today or tomorrow. In the meantime, assigning you more projects and issues on py-libp2p.

@yashksaini-coder

Copy link
Copy Markdown
Contributor

@Fatumayattani can I get the access for this ?

@Fatumayattani

Copy link
Copy Markdown
Contributor Author

Thank you @seetadev for the review and for coordinating on the CI/CD issue. I’ll re-run the checks once that’s resolved.

@yashksaini-coder I’ve added you as a collaborator so you now have access to the feature/attack-simulation branch. Please let me know if you face any issues or need anything else to get started.

Really appreciate everyone’s feedback and support in pushing this forward.

@yashksaini-coder

yashksaini-coder commented Sep 24, 2025

Copy link
Copy Markdown
Contributor

@Fatumayattani @seetadev Hi, I've reviewed the PR, and executed the checks and all tests on my end. Everything is good, all test cases passed ✔️ and some new changes to fix the linting and minor errors.

I will work on this for adding more attack simulation and review

@seetadev

Copy link
Copy Markdown
Contributor

@Fatumayattani , @yashksaini-coder : Wonderful, great to hear. Appreciate your efforts.

We will review this PR in detail. Re-ran the CI/CD pipeline.

Since, it is an important module addition, wish to have feedback first from @acul71 , @lla-dane and @sumanjeet0012 .

We will discuss with @pacrob and have his review after discussing in tomorrow's maintainer's call.

@acul71 acul71 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR #950 Review: Eclipse Attack Simulation Module

Summary

This PR introduces a Network Attack Simulation module for py-libp2p with a well-designed dual-layer architecture for Eclipse attack testing.

Recommendation: ✅ APPROVE with mods

Implementation Analysis

What's Working Well:

  • Dual-layer architecture - Simulation + Real integration
  • Real integration tests - 3/3 tests pass with actual libp2p hosts
  • Comprehensive framework - Well-structured attack simulation foundation
  • Test coverage - 9/9 tests pass (6 simulation + 3 real integration)

Architecture Design:

  • Simulation Layer: Fast framework validation with placeholder metrics (by design)
  • Real Integration Layer: Comprehensive attack simulation with actual libp2p components

Current Assessment

  • Test Coverage: 100% (9/9 tests pass)
  • Code Quality: Excellent structure with real integration
  • Documentation: Comprehensive README with clear usage examples
  • Performance: Fast simulation (0.40s) + Real integration (2.06s)
  • Functionality:COMPLETE - Both layers working as designed

Final Recommendation

✅ APPROVE but answer questions
and also wait is there a newsfragment?

(venv) luca@r17:~/PNL_Launchpad_Curriculum/Libp2p/py-libp2p$ l newsfragments/57
ls: cannot access 'newsfragments/57': No such file or directory

1. [Metrics and Analysis](#metrics-and-analysis)
1. [Roadmap](#roadmap)
1. [Eclipse Attack Flow](#eclipse-attack-flow)
1. [Contributing](#contributing)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are all this 1s here not 1,2,3,....

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just noticed the auto-tab completion

"honest_nodes": 10,
"malicious_nodes": 3,
"attack_intensity": 0.5,
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you try with different settings? are them handled ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some logs with different settings?
You may want to open a discussion page, and only put a link here, to not over bloat the PR

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will try with different settings and have the screenshot of the results in the Discussion page for this.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@acul71 I have done some more attack simulation test with multiple configs, and new test suite, shared the new disucssion here, #960

@Fatumayattani

Copy link
Copy Markdown
Contributor Author

Thanks everyone for the feedback and contributions.

I’ve added the missing newsfragment.

Kudos to @yashksaini-coder for running additional tests, and Discussion #960 contains the comprehensive Eclipse attack simulation results.

Special thanks to @acul71 for the detailed review and @seetadev for coordinating the CI/CD workflow. Really appreciate everyone’s collaboration and support on this.

yashksaini-coder and others added 13 commits January 27, 2026 12:25
- Converted 143+ print statements across 4 test files to logging
- Added logging.getLogger(__name__) to each file
- Used appropriate log levels (debug for verbose, info for important)
- Removed emoji decorations from test output
- Removed if __name__ == '__main__' blocks from pure test files
- All test files compile without errors

Files updated:
- test_attacks_simple.py: 45 prints → logger calls
- test_real_eclipse_simulation.py: 26 prints → logger calls
- test_multiple_scenarios.py: 14 prints → logger calls
- test_runner.py: 50 prints → logger calls

Addresses reviewer feedback: 'large number of print statements across several files'
Ref: Discussion libp2p#929, PR libp2p#950
- Resolves ModuleNotFoundError: No module named 'requests'
- requests is required by libp2p/security/tls/autotls/acme.py and broker.py
- types-requests (for type stubs) was already included but requests itself was missing
- Version constraint: requests>=2.28.0
@pacrob

pacrob commented Feb 3, 2026

Copy link
Copy Markdown
Member

I see you've added a whole new attack-simulation.yml. I don't think that's necessary.

If you just move the folder tests/core/security/attack_simulation over so it is tests/examples/attack_simulation, it will get caught with the existing examples CI run.

@yashksaini-coder

yashksaini-coder commented Feb 4, 2026

Copy link
Copy Markdown
Contributor

I see you've added a whole new attack-simulation.yml. I don't think that's necessary.

If you just move the folder tests/core/security/attack_simulation over so it is tests/examples/attack_simulation, it will get caught with the existing examples CI run.

Thanks for clarifying this, didn't know we can do that. Hopefully this resolves our ci-cd check issues.

@pacrob

pacrob commented Feb 4, 2026

Copy link
Copy Markdown
Member

Thanks for clarifying this, didn't know we can do that. Hopefully this resolves our ci-cd check issues.

You've moved it to libp2p/examples. It still needs to be within tests to get caught, so libp2p/tests/examples/attack_simulation.

@yashksaini-coder yashksaini-coder force-pushed the feature/attack-simulation branch from cec0633 to b44ab16 Compare February 4, 2026 17:01
@yashksaini-coder

Copy link
Copy Markdown
Contributor

Thanks for clarifying this, didn't know we can do that. Hopefully this resolves our ci-cd check issues.

You've moved it to libp2p/examples. It still needs to be within tests to get caught, so libp2p/tests/examples/attack_simulation.

Moved them to the tests/examples

Comment thread docs/tls-support.rst Outdated
Comment on lines +184 to +186
* - `ImportError: No module named libp2p.security.tls`
- TLS extras not installed
- Run `pip install "libp2p[tls]"`.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be deleted. There is no tls install target.

Comment thread tox.ini Outdated
docs: make check-docs-ci
interop: pytest -n auto --timeout=1200 {posargs:tests/interop}
utils: pytest -n auto --timeout=1200 {posargs:tests/utils}
attack-simulation: pytest -v --timeout=180 --log-cli-level=WARNING {posargs:tests/core/security/attack_simulation}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be deleted - they're now part of the demos CI run.

@pacrob pacrob left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've noted 2 places where code that is no longer relevant can be deleted. Once that is done, approved to merge.

@yashksaini-coder

Copy link
Copy Markdown
Contributor

@pacrob I've removed the dead code which is no longer relevant, Hope now we have the PR ready for merge 👍🏼

@seetadev

Copy link
Copy Markdown
Contributor

@pacrob and @acul71: Thank you so much for your review and feedback. Appreciate it.

@yashksaini-coder and @Fatumayattani : Looks great. This PR sets up a clean, well-structured foundation for network attack simulation in py-libp2p, with clear separation between malicious behavior, network construction, metrics, and scenarios. The module is thoughtfully organized, well documented, and easy to extend for future attack types.

All tests passing and the framework is solid. Thank you so much @yashksaini-coder and taking all the important steps for taking this PR to production.

Ready for merge. Great work!

@seetadev seetadev merged commit b9fa02f into libp2p:main Feb 12, 2026
38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants