Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 30 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Realtime highly decentralised chat app.

![libp2p topology](libp2p-hero.svg)

Showcasing [libp2p](https://libp2p.io/)'s superpowers in establishing ubiquitous peer-to-peer [connectivity](https://connectivity.libp2p.io/) in modern programming languages (Go, Rust, TypeScript) and runtimes (Web, native binary).
Showcasing [libp2p](https://libp2p.io/)'s superpowers in establishing ubiquitous peer-to-peer [connectivity](https://connectivity.libp2p.io/) in modern programming languages (Go, Rust, TypeScript, Python) and runtimes (Web, native binary).

On top of this strong foundation, it layers a GossipSub: A Secure PubSub Protocol for Unstructured Decentralised P2P Overlays. By analogy, an event broker with distributed brokering, or a distributed PubSub protocol.

Expand All @@ -20,11 +20,12 @@ Some of the cool and cutting-edge [transport protocols](https://connectivity.lib

## Packages

| Package | Description | WebTransport | WebRTC | WebRTC-direct | QUIC | TCP |
| :-------------------------- | :------------------------------ | ------------ | ------ | ------------- | ---- | --- |
| [`js-peer`](./js-peer/) | Browser Chat Peer in TypeScript | ✅ | ✅ | ✅ | ❌ | ❌ |
| [`go-peer`](./go-peer/) | Chat peer implemented in Go | ✅ | ❌ | ✅ | ✅ | ✅ |
| [`rust-peer`](./rust-peer/) | Chat peer implemented in Rust | ❌ | ❌ | ✅ | ✅ | ❌ |
| Package | Description | WebTransport | WebRTC | WebRTC-direct | QUIC | TCP |
| :------------------------------ | :------------------------------- | ------------ | ------ | ------------- | ---- | --- |
| [`js-peer`](./js-peer/) | Browser Chat Peer in TypeScript | ✅ | ✅ | ✅ | ❌ | ❌ |
| [`go-peer`](./go-peer/) | Chat peer implemented in Go | ✅ | ❌ | ✅ | ✅ | ✅ |
| [`rust-peer`](./rust-peer/) | Chat peer implemented in Rust | ❌ | ❌ | ✅ | ✅ | ❌ |
| [`python-peer`](./python-peer/) | Chat peer implemented in Python | ❌ | ❌ | ❌ | ❌ | ✅ |

✅ - Protocol supported
❌ - Protocol not supported
Expand Down Expand Up @@ -82,3 +83,26 @@ cargo run -- --help
cd go-peer
go run .
```

## Getting started: Python

### 1. Install dependencies

```
cd python-peer
pip install -r requirements.txt
```

### 2. Start the Python peer

```
python main.py
```

This will start the Python peer with an interactive UI. You can connect to other peers using the `/connect` command.

For more options, try:

```
python main.py --help
```
34 changes: 34 additions & 0 deletions python-peer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
FROM python:3.9-slim

WORKDIR /app

# Install system dependencies
RUN apt-get update && apt-get install -y \
build-essential \
libssl-dev \
libffi-dev \
python3-dev \
git \
&& rm -rf /var/lib/apt/lists/*

# Copy requirements first to leverage Docker cache
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Copy the rest of the application
COPY . .

# Generate protobuf files
RUN pip install --no-cache-dir protobuf && \
python -m pip install --no-cache-dir protobuf-compiler && \
protoc --python_out=. direct_message.proto

# Expose port for libp2p
EXPOSE 9095/tcp
EXPOSE 9095/udp

# Command to run the application
ENTRYPOINT ["python", "main.py"]

# Default arguments
CMD ["--headless"]
71 changes: 71 additions & 0 deletions python-peer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Python libp2p Universal Connectivity

This is a Python implementation of the Universal Connectivity chat application, demonstrating libp2p's capabilities in establishing peer-to-peer connections across different platforms and languages.

## Features

- Cross-platform connectivity with JS, Go, and Rust implementations
- Support for multiple transport protocols:
- WebRTC Direct
- TCP
- (WebTransport and QUIC support planned for future releases)
- PubSub using GossipSub for group messaging
- Direct messaging between peers
- File sharing capabilities
- Peer discovery using mDNS and DHT

## Getting Started

### Prerequisites

- Python 3.8 or later

### Installation

1. Clone the repository
2. Install dependencies:

```bash
pip install -r requirements.txt
```

### Running the application

Start the Python peer:

```bash
python main.py
```

Optional arguments:
- `--nick NAME`: Set your nickname (default: generated from peer ID)
- `--identity PATH`: Path to identity key file (default: identity.key)
- `--connect ADDR`: Multiaddr to connect to (can be repeated for multiple peers)

## Architecture

The Python peer implementation consists of several key components:

1. **Node Configuration**: Setup of the libp2p node with appropriate transports and protocols
2. **Chat Room**: Implementation of the GossipSub-based group chat
3. **Direct Messaging**: Protocol for peer-to-peer direct messages
4. **File Exchange**: Protocol for sharing files between peers
5. **UI**: Terminal-based user interface

## Integration with Other Implementations

This Python implementation is compatible with the JS, Go, and Rust peers in the Universal Connectivity project. It can:

- Connect to bootstrap nodes
- Discover peers via mDNS and DHT
- Exchange messages via GossipSub
- Send direct messages to peers
- Share files with peers

## Development

See the `CONTRIBUTING.md` file for guidelines on contributing to this project.

## License

This project is licensed under the dual MIT/Apache-2.0 license - see the LICENSE-MIT and LICENSE-APACHE files for details.
Loading