Skip to content

Commit 121440b

Browse files
Merge branch 'main' into py-peer-development
2 parents 5ce7d62 + e18a6de commit 121440b

66 files changed

Lines changed: 13833 additions & 1888 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/generated-pr.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: Close Generated PRs
2+
3+
on:
4+
schedule:
5+
- cron: '0 0 * * *'
6+
workflow_dispatch:
7+
8+
permissions:
9+
issues: write
10+
pull-requests: write
11+
12+
jobs:
13+
stale:
14+
uses: ipdxco/unified-github-workflows/.github/workflows/reusable-generated-pr.yml@v1
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"skip32bit": true
3+
}

.github/workflows/go-ci.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
name: go-peer ci
22

3-
on:
3+
on:
44
pull_request:
55
paths:
6-
- 'go-peer/**'
6+
- "go-peer/**"
77

88
concurrency:
99
group: ${{ github.workflow }}-${{ github.ref }}
1010
cancel-in-progress: true
1111

1212
jobs:
1313
go-check:
14-
uses: libp2p/uci/.github/workflows/go-check.yml@v0.0
14+
uses: ipdxco/unified-github-workflows/.github/workflows/go-check.yml@v0.0
1515
with:
16-
go-version: '1.23.x'
16+
go-version: "1.25.x"
1717
go-test:
18-
uses: libp2p/uci/.github/workflows/go-test.yml@v0.0
18+
uses: ipdxco/unified-github-workflows/.github/workflows/go-test.yml@v0.0
1919
with:
20-
go-versions: '["1.23.x"]'
20+
go-versions: '["1.25.x"]'

.github/workflows/stale.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
name: Close and mark stale issue
1+
name: Close Stale Issues
22

33
on:
44
schedule:
55
- cron: '0 0 * * *'
6+
workflow_dispatch:
67

78
permissions:
89
issues: write
910
pull-requests: write
1011

1112
jobs:
1213
stale:
13-
uses: pl-strflt/.github/.github/workflows/reusable-stale-issue.yml@v0.3
14+
uses: ipdxco/unified-github-workflows/.github/workflows/reusable-stale-issue.yml@v1

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@ yarn.lock
88
.vscode/
99
.DS_Store
1010
go-peer/go-peer
11-
**/.idea
11+
**/.idea
12+
nim-peer/nim_peer
13+
nim-peer/local.*

README.md

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ Some of the cool and cutting-edge [transport protocols](https://connectivity.lib
2020

2121
## Packages
2222

23-
| Package | Description | WebTransport | WebRTC | WebRTC-direct | QUIC | TCP |
24-
| :-------------------------- | :------------------------------ | ------------ | ------ | ------------- | ---- | --- |
25-
| [`js-peer`](./js-peer/) | Browser Chat Peer in TypeScript ||||||
26-
| [`go-peer`](./go-peer/) | Chat peer implemented in Go ||||||
27-
| [`rust-peer`](./rust-peer/) | Chat peer implemented in Rust ||||||
28-
| [`py-peer`](./py-peer/) | Chat peer implemented in Python ||||||
23+
| Package | Description | WebTransport | WebRTC | WebRTC-direct | QUIC | TCP |
24+
| :-------------------------------- | :------------------------------ | ------------ | ------ | ------------- | ---- | --- |
25+
| [`js-peer`](./js-peer/) | Browser Chat Peer in TypeScript ||||||
26+
| [`node-js-peer`](./node-js-peer/) | Node.js Chat Peer in TypeScript ||||||
27+
| [`go-peer`](./go-peer/) | Chat peer implemented in Go ||||||
28+
| [`rust-peer`](./rust-peer/) | Chat peer implemented in Rust ||||||
29+
| [`py-peer`](./py-peer/) | Chat peer implemented in Python ||||||
30+
| [`nim-peer`](./nim-peer/) | Chat peer implemented in Nim ||||||
2931

3032
✅ - Protocol supported
3133
❌ - Protocol not supported
@@ -42,8 +44,7 @@ There are two ways to connect to a peer:
4244

4345
Load the UI, and enter the multiaddr into the UI. Ensure that it includes the peerID, e.g.`/ip4/192.168.178.21/udp/61838/quic-v1/webtransport/certhash/uEiCQCALYac4V3LJ2ourLdauXOswIXpIuJ_JNT-8Wavmxyw/certhash/uEiCdYghq5FlXGkVONQXT07CteA16BDyMPI23-0GjA9Ej_w/p2p/12D3KooWF7ovRNBKPxERf6GtUbFdiqJsQviKUb7Z8a2Uuuo6MrDX`
4446

45-
46-
## Getting started: JS
47+
## Getting started: Browser JS
4748

4849
### 1. Install dependencies
4950

@@ -62,14 +63,29 @@ Start the dev server:
6263
npm run dev
6364
```
6465

66+
## Getting started: Node.js
67+
68+
### 1. Install dependencies
69+
70+
```
71+
cd node-js-peer
72+
npm i
73+
```
74+
75+
### 2. Start the app
76+
77+
```
78+
npm start
79+
```
80+
6581
## Getting started: Rust
6682

6783
```
6884
cd rust-peer
6985
cargo run
7086
```
7187

72-
This will automatically connect you to the bootstrap node running on [fly.io](https://fly.io).
88+
This will automatically connect you to the bootstrap nodes running on bootstrap.libp2p.io.
7389

7490
To explore more advanced configurations if you e.g. want to set up our own network, try:
7591

@@ -119,4 +135,15 @@ If you want a specific mode, you can pass flags such as `--ui`, `--kivy`, or `--
119135

120136
```bash
121137
python main.py --ui
138+
139+
## Getting started: Nim
140+
```
141+
cd nim-peer
142+
nimble build
143+
144+
# Wait for connections in tcp/9093
145+
./nim_peer
146+
147+
# Connect to another node (e.g. in localhost tcp/9092)
148+
./nim_peer --connect /ip4/127.0.0.1/tcp/9092/p2p/12D3KooSomePeerId
122149
```

go-peer/Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Use a specific version of golang alpine for better reproducibility
2-
FROM golang:1.23-alpine AS builder
2+
FROM golang:1.25-alpine AS builder
33

44
WORKDIR /usr/src/app
55

@@ -18,11 +18,11 @@ FROM alpine:latest
1818

1919
# Add CA certificates for HTTPS and create non-root user
2020
RUN apk --no-cache add ca-certificates && \
21-
adduser -D appuser
21+
adduser -D appuser
2222

2323
# Create a directory for the application and set proper permissions
2424
RUN mkdir -p /app/data && \
25-
chown -R appuser:appuser /app
25+
chown -R appuser:appuser /app
2626

2727
# Copy the binary from builder
2828
COPY --from=builder /usr/local/bin/universal-chat-go /usr/local/bin/universal-chat-go

go-peer/chatroom.go

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ const ChatRoomBufSize = 128
1818
// Topic used to broadcast browser WebRTC addresses
1919
const PubSubDiscoveryTopic string = "universal-connectivity-browser-peer-discovery"
2020

21-
const ChatTopic string = "universal-connectivity"
22-
const ChatFileTopic string = "universal-connectivity-file"
23-
2421
// ChatRoom represents a subscription to a single PubSub topic. Messages
2522
// can be published to the topic with ChatRoom.Publish, and received
2623
// messages are pushed to the Messages channel.
@@ -46,15 +43,15 @@ type ChatRoom struct {
4643
// ChatMessage gets converted to/from JSON and sent in the body of pubsub messages.
4744
type ChatMessage struct {
4845
Message string
49-
SenderID string
46+
SenderID peer.ID
5047
SenderNick string
5148
}
5249

5350
// JoinChatRoom tries to subscribe to the PubSub topic for the room name, returning
5451
// a ChatRoom on success.
55-
func JoinChatRoom(ctx context.Context, h host.Host, ps *pubsub.PubSub, nickname string) (*ChatRoom, error) {
52+
func JoinChatRoom(ctx context.Context, h host.Host, ps *pubsub.PubSub, nickname string, roomName string) (*ChatRoom, error) {
5653
// join the pubsub chatTopic
57-
chatTopic, err := ps.Join(ChatTopic)
54+
chatTopic, err := ps.Join(roomName)
5855
if err != nil {
5956
return nil, err
6057
}
@@ -66,7 +63,8 @@ func JoinChatRoom(ctx context.Context, h host.Host, ps *pubsub.PubSub, nickname
6663
}
6764

6865
// join the pubsub fileTopic
69-
fileTopic, err := ps.Join(ChatFileTopic)
66+
fileTopicName := roomName + "-file"
67+
fileTopic, err := ps.Join(fileTopicName)
7068
if err != nil {
7169
return nil, err
7270
}
@@ -100,6 +98,7 @@ func JoinChatRoom(ctx context.Context, h host.Host, ps *pubsub.PubSub, nickname
10098
peerDiscoveryTopic: peerDiscoveryTopic,
10199
peerDiscoverySub: peerDiscoverySub,
102100
nick: nickname,
101+
roomName: roomName,
103102
Messages: make(chan *ChatMessage, ChatRoomBufSize),
104103
SysMessages: make(chan *ChatMessage, ChatRoomBufSize),
105104
}
@@ -115,7 +114,7 @@ func (cr *ChatRoom) Publish(message string) error {
115114
}
116115

117116
func (cr *ChatRoom) ListPeers() []peer.ID {
118-
return cr.ps.ListPeers(ChatTopic)
117+
return cr.ps.ListPeers(cr.roomName)
119118
}
120119

121120
// readLoop pulls messages from the pubsub chat/file topic and handles them.
@@ -138,8 +137,9 @@ func (cr *ChatRoom) readChatLoop() {
138137
}
139138
cm := new(ChatMessage)
140139
cm.Message = string(msg.Data)
141-
cm.SenderID = msg.ID
142-
cm.SenderNick = string(msg.ID[len(msg.ID)-8])
140+
cm.SenderID = msg.GetFrom()
141+
senderStr := cm.SenderID.String()
142+
cm.SenderNick = senderStr[len(senderStr)-8:]
143143
// send valid messages onto the Messages channel
144144
cr.Messages <- cm
145145
}
@@ -167,8 +167,9 @@ func (cr *ChatRoom) readFileLoop() {
167167

168168
cm := new(ChatMessage)
169169
cm.Message = fmt.Sprintf("File: %s (%v bytes) from %s", string(fileID), len(fileBody), msg.GetFrom().String())
170-
cm.SenderID = msg.ID
171-
cm.SenderNick = string(msg.ID[len(msg.ID)-8])
170+
cm.SenderID = msg.GetFrom()
171+
senderStr := cm.SenderID.String()
172+
cm.SenderNick = senderStr[len(senderStr)-8:]
172173
// send valid messages onto the Messages channel
173174
cr.Messages <- cm
174175
}
@@ -183,13 +184,13 @@ func (cr *ChatRoom) requestFile(toPeer peer.ID, fileID []byte) ([]byte, error) {
183184
defer stream.Close()
184185

185186
reqLen := binary.AppendUvarint([]byte{}, uint64(len(fileID)))
186-
if _, err := stream.Write(reqLen); err != nil {
187+
if _, err = stream.Write(reqLen); err != nil {
187188
return nil, fmt.Errorf("failed to write fileID to the stream: %w", err)
188189
}
189-
if _, err := stream.Write(fileID); err != nil {
190+
if _, err = stream.Write(fileID); err != nil {
190191
return nil, fmt.Errorf("failed to write fileID to the stream: %w", err)
191192
}
192-
if err := stream.CloseWrite(); err != nil {
193+
if err = stream.CloseWrite(); err != nil {
193194
return nil, fmt.Errorf("failed to close write stream: %w", err)
194195
}
195196

0 commit comments

Comments
 (0)