Skip to content

Add state and handle cleanup in NetStream.{reset|close} #528

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

shobit000
Copy link

What was wrong?

The NetStream class was too simple to clean up resources in SwarmConn and to trigger the ClosedStream event in the notifee. There was no state management in NetStream to handle actions for reset/close.

Issue #300: Add state and handle cleanup in NetStream.{reset|close}

How was it fixed?

  • Added StreamState enum to manage different states of the stream.

  • Updated the NetStream class to include state management.

  • Implemented state handling in reset and close methods.

  • Added a remove method to handle cleanup and trigger the ClosedStream event.

Changes made:

  • libp2p/network/stream/net_stream.py:

    • Added StreamState enum.

    • Updated NetStream class to include state management.

    • Modified reset and close methods to handle state changes.

    • Added remove method for cleanup.

To-Do

  • Clean up commit history
  • Add or update documentation related to these changes
  • Add entry to the release notes

Cute Animal Picture

put a cute animal picture link inside the parentheses

@sumanjeet0012
Copy link
Contributor

@shobit000 Thank you for this PR.

Some test cases are currently failing in the CI/CD pipeline. We will be able to proceed further only once all test cases pass successfully.

Some lint checks have failed:

black....................................................................Failed

  • hook id: black
  • files were modified by this hook

reformatted libp2p/network/stream/net_stream.py

All done! ✨ 🍰 ✨
1 file reformatted, 174 files left unchanged.

flake8...................................................................Passed
autoflake................................................................Passed
isort....................................................................Failed

  • hook id: isort
  • files were modified by this hook

Fixing

/home/runner/work/py-libp2p/py-libp2p/libp2p/network/stream/net_stream.py

These issues can be resolved by running: pre-commit run --all-files
This will automatically modify the files to fix the lint errors. Please ensure the modified files are staged and committed before pushing.

There are also some attribute/dependency errors:

run mypy with all dev dependencies present...............................Failed

  • hook id: mypy-local
  • exit code: 1

libp2p/network/stream/net_stream.py:109: error: "IMuxedConn" has no attribute "remove_stream" [attr-defined]
libp2p/network/stream/net_stream.py:111: error: "NetStream" has no attribute "swarm" [attr-defined]
libp2p/network/stream/net_stream.py:112: error: "NetStream" has no attribute "swarm" [attr-defined]
Found 3 errors in 1 file (checked 118 source files)

These errors are due to incorrect usage of attributes or methods that do not exist. You can refer to the definitions here:

IMuxedConn
NetStream

@seetadev
Copy link
Contributor

@sumanjeet0012 , @Sahilgill24 and @mystical-prog : Wish to share that I am closing this pull request as we are handling the above mentioned changes by @sumanjeet0012 in #637 .

@seetadev seetadev closed this Jun 10, 2025
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.

3 participants