feat: Add P2P networking capability to shell with Peer struct#21
Merged
feat: Add P2P networking capability to shell with Peer struct#21
Conversation
- Add --with-p2p flag to CapabilityFlags() for P2P networking capability - Update --with-all description to include p2p capability - Follows same pattern as --with-ipfs and --with-exec flags
- Create Peer struct with Host and Ctx fields for P2P networking - Implement Invokable interface with methods: :send, :connect, :is-self, :id - Support both string and builtin.String types for composable expressions - Add proper error handling and type conversion - Enable expressions like (peer :send (peer :id) proc-id data)
- Use stretchr/testify for clean, readable assertions - Test core methods: String, ID, IsSelf, Invoke - Test builtin.String support for composable expressions - Cover both success and error cases - All tests run in parallel for performance
- Replace SendToPeer function with Peer struct in globals - Add Peer to getBaseGlobals() when --with-p2p flag is used - Create libp2p host in shell setup for P2P functionality - Remove old SendToPeer function and unused imports - Update help message to show new peer API syntax - Pass --with-p2p flag through in host mode
- Update tests to work with new getBaseGlobals() function - Add tests for P2P functionality when --with-p2p flag is used - Update help message tests to include new peer commands - Ensure all existing functionality continues to work
mikelsr
approved these changes
Sep 18, 2025
|
|
||
| // Connect establishes a connection to a peer | ||
| func (p *Peer) Connect(peerAddr string) (core.Any, error) { | ||
| ctx := context.TODO() |
Member
There was a problem hiding this comment.
One of my personal pain points when working with concurrent applications is them not stopping when ctrl+C'd, I'm leaving this comment here because although I think the Connect call in this function won't cause that issue, I want to remember it's here in case I'm wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This PR adds P2P networking capability to the wetware shell by introducing a new
Peerstruct that implementscore.Invokable. This enables users to send data to remote peers, connect to peers, and perform peer identity operations directly from the shell.Changes
New Features
--with-p2pflag: New capability flag for P2P networking (follows same pattern as--with-ipfsand--with-exec)core.Invokablewith methods::send- Send data to a peer process:connect- Connect to a peer:is-self- Check if peer ID is our own:id- Get our own peer IDbuiltin.Stringtypes enables expressions like:Implementation Details
--with-p2pflag is usedstringandbuiltin.StringtypesKnown Issues
Working Example