Skip to content

feat: Implement py-peer of Universal Connectivity dApp#294

Open
sumanjeet0012 wants to merge 82 commits intolibp2p:py-peer-developmentfrom
sumanjeet0012:py-peer-development
Open

feat: Implement py-peer of Universal Connectivity dApp#294
sumanjeet0012 wants to merge 82 commits intolibp2p:py-peer-developmentfrom
sumanjeet0012:py-peer-development

Conversation

@sumanjeet0012
Copy link
Copy Markdown

@sumanjeet0012 sumanjeet0012 commented Jul 4, 2025

Python Implementation of Universal Connectivity Chat Application

Overview

This PR implements a complete Python peer-to-peer chat application using libp2p and GossipSub protocol, addressing the request for a Python peer in the Universal Connectivity project.

Related Issue

Fixes: libp2p/py-libp2p#624

Implementation Details

Core Features

  • Peer-to-Peer Chat: Real-time messaging using GossipSub pubsub protocol
  • Multiple UI Modes:
    • Textual TUI interface for rich terminal experience
    • CLI mode for simple interactive chat
    • Headless mode for background operation
  • Peer Discovery: Manual connection to other peers using Multiaddr
  • System Logging: Structured logging with timestamped system events

Technical Stack

  • libp2p: Core peer-to-peer networking (py-libp2p 0.2.9)
  • Trio: Async/await framework for concurrent operations
  • Textual: Modern terminal user interface framework
  • GossipSub: Publish-subscribe messaging protocol
  • TCP Transport: Reliable connection transport (QUIC support planned)

Key Components

  • main.py - Application entry point with argument parsing
  • chatroom.py - Chat room logic and message handling
  • headless.py - Background service managing libp2p operations
  • ui.py - Textual-based terminal user interface

Usage Examples

# Start with Textual TUI
py-peer --nick "Sumanjeet" --ui

# Connect to specific peer
py-peer --nick "Devs" --connect /ip4/127.0.0.1/tcp/PORT/p2p/PEER_ID

# Headless mode
py-peer --nick "User" --headless

Testing

  • ✅ Multi-peer chat sessions tested
  • ✅ Peer discovery and connection verified
  • ✅ All UI modes functional
  • ✅ Cross-platform compatibility (Linux/macOS/Windows)

Dependencies

  • Python 3.12+
  • All dependencies managed via pyproject.toml with uv.lock for reproducible builds

Documentation

  • Comprehensive README with installation, usage, and troubleshooting
  • Architecture diagrams and component descriptions
  • Screenshot of working Textual UI interface

Additional Notes

  • Uses TCP transport currently; QUIC support may be added in future
  • Follows Python best practices with type hints and async patterns
  • Modular architecture allows easy extension and customization

dependabot bot and others added 20 commits March 27, 2025 17:41
Bumps the npm_and_yarn group in /js-peer with 1 update: [next](https://github.com/vercel/next.js).


Updates `next` from 14.2.13 to 14.2.25
- [Release notes](https://github.com/vercel/next.js/releases)
- [Changelog](https://github.com/vercel/next.js/blob/canary/release.js)
- [Commits](vercel/next.js@v14.2.13...v14.2.25)

---
updated-dependencies:
- dependency-name: next
  dependency-type: direct:production
  dependency-group: npm_and_yarn
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Adds a basic Node.js peer with a terminal user interface.

Lifts some code from the existing js-peer. Doesn't support DMs or dialing peers directly (yet).

Fixes libp2p#214

---------

Co-authored-by: Daniel N <2color@users.noreply.github.com>
* chore: add or force update .github/workflows/stale.yml

* chore: add or force update .github/workflows/generated-pr.yml
* add tui ui
* add polling of events
* clean up peer code
* all hooked up
* clean up system messages
* smarter system messages
* add tcp
* fix channel handling
* drop peers when they hang up
* fix listen address is not necessarily an external address
* add better logging and peer list
* add headless, kademlia, relay, dcutr, webrtc, peer discovery
* fix clippy
* add tui ui
* add polling of events
* clean up peer code
* all hooked up
* clean up system messages
* smarter system messages
* add tcp
* fix channel handling
* drop peers when they hang up
* fix listen address is not necessarily an external address
* add better logging and peer list
* add headless, kademlia, relay, dcutr, webrtc, peer discovery
* fix clippy

Signed-off-by: Dave Grantham <dwg@linuxprogrammer.org>
- Refactored UI code to utilize trio memory channels for asynchronous communication, replacing the previous queue-based approach.
- Implemented handling of incoming and outgoing messages using async methods, improving responsiveness and error handling.
- Simplified message sending and processing logic, ensuring UI updates are handled safely within the async context.
… Textual;

integrated Janus queue for communication between service and TUI.
@sumanjeet0012
Copy link
Copy Markdown
Author

@seetadev Ready for review

@sumanjeet0012 sumanjeet0012 requested a review from a team as a code owner August 25, 2025 17:47
Comment thread py-peer/headless.py Outdated
BOOTSTRAP_PEERS = [
"/ip4/139.178.65.157/tcp/4001/p2p/QmQCU2EcMqAqQPR2i9bChDtGNJchTbq5TbXJJ16u19uLTa",
"/ip4/139.178.91.71/tcp/4001/p2p/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN",
"/ip4/145.40.118.135/tcp/4001/p2p/QmcZf59bWwK5XFi76CZX8cbJ4BhTzzA3gU1ZjYZcYW3dwt"
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.

missing a comma

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

added comma.

Comment thread py-peer/headless.py Outdated
# nursery.start_soon(maintain_connections, self.host)

except (MultiselectClientError, StreamFailure) as e:
logger.log(f"The protocol negotitaion failed: {e}")
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.

My pylance is showing this missing an arg. Looks like logger.log takes both a level and a msg.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yes, that is correct. I have replaced logger.log with logger.error.

Comment thread py-peer/main.py
port=args.port,
connect_addrs=args.connect,
strict_signing=strict_signing,
seed=args.seed,
Copy link
Copy Markdown
Member

@pacrob pacrob Mar 3, 2026

Choose a reason for hiding this comment

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

We take and pass seed here, but over in HeadlessService the value is never used.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

The seed is now handled as follows:

secret = hashlib.sha256(self.seed.encode()).digest()
key_pair = create_new_key_pair(seed=secret)

@pacrob
Copy link
Copy Markdown
Member

pacrob commented Mar 3, 2026

You've removed hello.py, but the top-level README still says to run py-peer with uv run hello.py.

@seetadev
Copy link
Copy Markdown

@sumanjeet0012 : Hi Sumanjeet. Please ping me and @pacrob once this dapp is fully ready for final merge.

Will collaborate with the maintainers of the repo to see this PR landed.

@seetadev seetadev self-requested a review March 30, 2026 21:53
@sumanjeet0012
Copy link
Copy Markdown
Author

sumanjeet0012 commented Apr 3, 2026

You've removed hello.py, but the top-level README still says to run py-peer with uv run hello.py.

Added proper documentation for running py-peer of universal connectivity.

@sumanjeet0012
Copy link
Copy Markdown
Author

@pacrob @seetadev I have made all the required changes.

@sumanjeet0012 sumanjeet0012 requested a review from a team as a code owner April 9, 2026 18:25
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.