Skip to content

fix: correct stream handling and protocol dialing in example code #207

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

sumanjeet0012
Copy link

@sumanjeet0012 sumanjeet0012 commented Feb 27, 2025

Title

fix: correct stream handling and protocol dialing in example code

Description

This PR addresses issues in the commented-out example code that would prevent it from working if uncommented:

  1. Fixed stream data handling: Added .subarray() when reading from the stream to properly handle buffer data in the active code.

  2. Fixed protocol dialing in commented code:

    • Added missing await keyword when dialing a protocol

    • Changed from node2.peerId to node2.getMultiaddrs() for correct addressing

  3. Fixed data encoding in commented code: Added uint8ArrayFromString() to properly encode string messages

These changes ensure the example code will work correctly when users uncomment it for their own implementations, providing a reliable reference for libp2p protocol and stream muxing.

Notes & open questions

Change checklist

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation if necessary (this includes comments as well)
  • I have added tests that prove my fix is effective or that my feature works

@sumanjeet0012 sumanjeet0012 force-pushed the fix/example-protocol-stream-handling branch from 39a0329 to 4197ac0 Compare March 17, 2025 18:00
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.

1 participant