Skip to content

Commit f80be8b

Browse files
committed
Merge branch 'main' into fix-room-go-peer
2 parents 5e22f89 + 6b6b8c4 commit f80be8b

File tree

19 files changed

+1050
-481
lines changed

19 files changed

+1050
-481
lines changed
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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
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 }}
@@ -13,8 +13,8 @@ jobs:
1313
go-check:
1414
uses: ipdxco/unified-github-workflows/.github/workflows/[email protected]
1515
with:
16-
go-version: '1.23.x'
16+
go-version: "1.25.x"
1717
go-test:
1818
uses: ipdxco/unified-github-workflows/.github/workflows/[email protected]
1919
with:
20-
go-versions: '["1.23.x"]'
20+
go-versions: '["1.25.x"]'

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ yarn.lock
99
.DS_Store
1010
go-peer/go-peer
1111
**/.idea
12+
nim-peer/nim_peer
13+
nim-peer/local.*

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Some of the cool and cutting-edge [transport protocols](https://connectivity.lib
2626
| [`node-js-peer`](./node-js-peer/) | Node.js Chat Peer in TypeScript ||||||
2727
| [`go-peer`](./go-peer/) | Chat peer implemented in Go ||||||
2828
| [`rust-peer`](./rust-peer/) | Chat peer implemented in Rust ||||||
29+
| [`nim-peer`](./nim-peer/) | Chat peer implemented in Nim ||||||
2930

3031
✅ - Protocol supported
3132
❌ - Protocol not supported
@@ -97,3 +98,15 @@ cargo run -- --help
9798
cd go-peer
9899
go run .
99100
```
101+
102+
## Getting started: Nim
103+
```
104+
cd nim-peer
105+
nimble build
106+
107+
# Wait for connections in tcp/9093
108+
./nim_peer
109+
110+
# Connect to another node (e.g. in localhost tcp/9092)
111+
./nim_peer --connect /ip4/127.0.0.1/tcp/9092/p2p/12D3KooSomePeerId
112+
```

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: 14 additions & 14 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.
5552
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
}
@@ -116,7 +114,7 @@ func (cr *ChatRoom) Publish(message string) error {
116114
}
117115

118116
func (cr *ChatRoom) ListPeers() []peer.ID {
119-
return cr.ps.ListPeers(ChatTopic)
117+
return cr.ps.ListPeers(cr.roomName)
120118
}
121119

122120
// readLoop pulls messages from the pubsub chat/file topic and handles them.
@@ -139,8 +137,9 @@ func (cr *ChatRoom) readChatLoop() {
139137
}
140138
cm := new(ChatMessage)
141139
cm.Message = string(msg.Data)
142-
cm.SenderID = msg.ID
143-
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:]
144143
// send valid messages onto the Messages channel
145144
cr.Messages <- cm
146145
}
@@ -168,8 +167,9 @@ func (cr *ChatRoom) readFileLoop() {
168167

169168
cm := new(ChatMessage)
170169
cm.Message = fmt.Sprintf("File: %s (%v bytes) from %s", string(fileID), len(fileBody), msg.GetFrom().String())
171-
cm.SenderID = msg.ID
172-
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:]
173173
// send valid messages onto the Messages channel
174174
cr.Messages <- cm
175175
}
@@ -184,13 +184,13 @@ func (cr *ChatRoom) requestFile(toPeer peer.ID, fileID []byte) ([]byte, error) {
184184
defer stream.Close()
185185

186186
reqLen := binary.AppendUvarint([]byte{}, uint64(len(fileID)))
187-
if _, err := stream.Write(reqLen); err != nil {
187+
if _, err = stream.Write(reqLen); err != nil {
188188
return nil, fmt.Errorf("failed to write fileID to the stream: %w", err)
189189
}
190-
if _, err := stream.Write(fileID); err != nil {
190+
if _, err = stream.Write(fileID); err != nil {
191191
return nil, fmt.Errorf("failed to write fileID to the stream: %w", err)
192192
}
193-
if err := stream.CloseWrite(); err != nil {
193+
if err = stream.CloseWrite(); err != nil {
194194
return nil, fmt.Errorf("failed to close write stream: %w", err)
195195
}
196196

go-peer/go.mod

Lines changed: 75 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,70 @@
11
module github.com/libp2p/universal-connectivity/go-peer
22

3-
go 1.22.0
4-
5-
toolchain go1.22.8
3+
go 1.25.4
64

75
require (
8-
github.com/caddyserver/certmagic v0.21.7
9-
github.com/gdamore/tcell/v2 v2.7.4
10-
github.com/ipfs/go-log/v2 v2.5.1
11-
github.com/ipshipyard/p2p-forge v0.3.1
12-
github.com/libp2p/go-libp2p v0.39.1
13-
github.com/libp2p/go-libp2p-kad-dht v0.29.0
14-
github.com/libp2p/go-libp2p-pubsub v0.13.0
15-
github.com/multiformats/go-multiaddr v0.14.0
16-
github.com/rivo/tview v0.0.0-20241030223020-e34b54cd4c27
6+
github.com/caddyserver/certmagic v0.25.0
7+
github.com/gdamore/tcell/v2 v2.9.0
8+
github.com/ipfs/go-log/v2 v2.9.0
9+
github.com/ipshipyard/p2p-forge v0.6.1
10+
github.com/libp2p/go-libp2p v0.45.0
11+
github.com/libp2p/go-libp2p-kad-dht v0.35.1
12+
github.com/libp2p/go-libp2p-pubsub v0.15.0
13+
github.com/multiformats/go-multiaddr v0.16.1
14+
github.com/rivo/tview v0.42.0
1715
)
1816

1917
require (
2018
github.com/benbjohnson/clock v1.3.5 // indirect
2119
github.com/beorn7/perks v1.0.1 // indirect
2220
github.com/caddyserver/zerossl v0.1.3 // indirect
2321
github.com/cespare/xxhash/v2 v2.3.0 // indirect
24-
github.com/containerd/cgroups v1.1.0 // indirect
25-
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
22+
github.com/clipperhouse/stringish v0.1.1 // indirect
23+
github.com/clipperhouse/uax29/v2 v2.3.0 // indirect
2624
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
2725
github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c // indirect
28-
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
29-
github.com/docker/go-units v0.5.0 // indirect
30-
github.com/elastic/gosigar v0.14.3 // indirect
26+
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0 // indirect
27+
github.com/filecoin-project/go-clock v0.1.0 // indirect
3128
github.com/flynn/noise v1.1.0 // indirect
3229
github.com/francoispqt/gojay v1.2.13 // indirect
3330
github.com/gdamore/encoding v1.0.1 // indirect
34-
github.com/go-logr/logr v1.4.2 // indirect
31+
github.com/go-logr/logr v1.4.3 // indirect
3532
github.com/go-logr/stdr v1.2.2 // indirect
36-
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
37-
github.com/godbus/dbus/v5 v5.1.0 // indirect
3833
github.com/gogo/protobuf v1.3.2 // indirect
3934
github.com/google/gopacket v1.1.19 // indirect
40-
github.com/google/pprof v0.0.0-20250208200701-d0013a598941 // indirect
4135
github.com/google/uuid v1.6.0 // indirect
4236
github.com/gorilla/websocket v1.5.3 // indirect
43-
github.com/hashicorp/errwrap v1.1.0 // indirect
44-
github.com/hashicorp/go-multierror v1.1.1 // indirect
4537
github.com/hashicorp/golang-lru v1.0.2 // indirect
4638
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
4739
github.com/huin/goupnp v1.3.0 // indirect
48-
github.com/ipfs/boxo v0.27.4 // indirect
49-
github.com/ipfs/go-cid v0.5.0 // indirect
50-
github.com/ipfs/go-datastore v0.6.0 // indirect
40+
github.com/ipfs/boxo v0.35.1 // indirect
41+
github.com/ipfs/go-cid v0.6.0 // indirect
42+
github.com/ipfs/go-datastore v0.9.0 // indirect
5143
github.com/ipld/go-ipld-prime v0.21.0 // indirect
5244
github.com/jackpal/go-nat-pmp v1.0.2 // indirect
5345
github.com/jbenet/go-temp-err-catcher v0.1.0 // indirect
54-
github.com/jbenet/goprocess v0.1.4 // indirect
55-
github.com/klauspost/compress v1.17.11 // indirect
56-
github.com/klauspost/cpuid/v2 v2.2.9 // indirect
57-
github.com/koron/go-ssdp v0.0.5 // indirect
58-
github.com/libdns/libdns v0.2.2 // indirect
46+
github.com/klauspost/compress v1.18.1 // indirect
47+
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
48+
github.com/koron/go-ssdp v0.1.0 // indirect
49+
github.com/libdns/libdns v1.1.1 // indirect
5950
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
6051
github.com/libp2p/go-cidranger v1.1.0 // indirect
61-
github.com/libp2p/go-flow-metrics v0.2.0 // indirect
52+
github.com/libp2p/go-flow-metrics v0.3.0 // indirect
6253
github.com/libp2p/go-libp2p-asn-util v0.4.1 // indirect
63-
github.com/libp2p/go-libp2p-kbucket v0.6.5 // indirect
54+
github.com/libp2p/go-libp2p-kbucket v0.8.0 // indirect
6455
github.com/libp2p/go-libp2p-record v0.3.1 // indirect
65-
github.com/libp2p/go-libp2p-routing-helpers v0.7.4 // indirect
56+
github.com/libp2p/go-libp2p-routing-helpers v0.7.5 // indirect
6657
github.com/libp2p/go-msgio v0.3.0 // indirect
67-
github.com/libp2p/go-nat v0.2.0 // indirect
68-
github.com/libp2p/go-netroute v0.2.2 // indirect
58+
github.com/libp2p/go-netroute v0.4.0 // indirect
6959
github.com/libp2p/go-reuseport v0.4.0 // indirect
70-
github.com/libp2p/go-yamux/v4 v4.0.2 // indirect
60+
github.com/libp2p/go-yamux/v5 v5.1.0 // indirect
7161
github.com/libp2p/zeroconf/v2 v2.2.0 // indirect
72-
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
62+
github.com/lucasb-eyer/go-colorful v1.3.0 // indirect
7363
github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd // indirect
7464
github.com/mattn/go-isatty v0.0.20 // indirect
75-
github.com/mattn/go-runewidth v0.0.16 // indirect
76-
github.com/mholt/acmez/v3 v3.0.1 // indirect
77-
github.com/miekg/dns v1.1.63 // indirect
65+
github.com/mattn/go-runewidth v0.0.19 // indirect
66+
github.com/mholt/acmez/v3 v3.1.4 // indirect
67+
github.com/miekg/dns v1.1.68 // indirect
7868
github.com/mikioh/tcpinfo v0.0.0-20190314235526-30a79bb1804b // indirect
7969
github.com/mikioh/tcpopt v0.0.0-20190314235656-172688c1accc // indirect
8070
github.com/minio/sha256-simd v1.0.1 // indirect
@@ -84,75 +74,67 @@ require (
8474
github.com/multiformats/go-multiaddr-dns v0.4.1 // indirect
8575
github.com/multiformats/go-multiaddr-fmt v0.1.0 // indirect
8676
github.com/multiformats/go-multibase v0.2.0 // indirect
87-
github.com/multiformats/go-multicodec v0.9.0 // indirect
77+
github.com/multiformats/go-multicodec v0.10.0 // indirect
8878
github.com/multiformats/go-multihash v0.2.3 // indirect
89-
github.com/multiformats/go-multistream v0.6.0 // indirect
90-
github.com/multiformats/go-varint v0.0.7 // indirect
79+
github.com/multiformats/go-multistream v0.6.1 // indirect
80+
github.com/multiformats/go-varint v0.1.0 // indirect
9181
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
92-
github.com/onsi/ginkgo/v2 v2.22.2 // indirect
93-
github.com/opencontainers/runtime-spec v1.2.0 // indirect
9482
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect
9583
github.com/pion/datachannel v1.5.10 // indirect
9684
github.com/pion/dtls/v2 v2.2.12 // indirect
97-
github.com/pion/dtls/v3 v3.0.4 // indirect
98-
github.com/pion/ice/v2 v2.3.37 // indirect
99-
github.com/pion/ice/v4 v4.0.6 // indirect
100-
github.com/pion/interceptor v0.1.37 // indirect
101-
github.com/pion/logging v0.2.3 // indirect
102-
github.com/pion/mdns v0.0.12 // indirect
85+
github.com/pion/dtls/v3 v3.0.7 // indirect
86+
github.com/pion/ice/v4 v4.0.10 // indirect
87+
github.com/pion/interceptor v0.1.41 // indirect
88+
github.com/pion/logging v0.2.4 // indirect
10389
github.com/pion/mdns/v2 v2.0.7 // indirect
10490
github.com/pion/randutil v0.1.0 // indirect
105-
github.com/pion/rtcp v1.2.15 // indirect
106-
github.com/pion/rtp v1.8.11 // indirect
107-
github.com/pion/sctp v1.8.35 // indirect
108-
github.com/pion/sdp/v3 v3.0.10 // indirect
109-
github.com/pion/srtp/v3 v3.0.4 // indirect
91+
github.com/pion/rtcp v1.2.16 // indirect
92+
github.com/pion/rtp v1.8.25 // indirect
93+
github.com/pion/sctp v1.8.40 // indirect
94+
github.com/pion/sdp/v3 v3.0.16 // indirect
95+
github.com/pion/srtp/v3 v3.0.8 // indirect
11096
github.com/pion/stun v0.6.1 // indirect
111-
github.com/pion/stun/v3 v3.0.0 // indirect
97+
github.com/pion/stun/v3 v3.0.1 // indirect
11298
github.com/pion/transport/v2 v2.2.10 // indirect
113-
github.com/pion/transport/v3 v3.0.7 // indirect
114-
github.com/pion/turn/v2 v2.1.6 // indirect
115-
github.com/pion/turn/v4 v4.0.0 // indirect
116-
github.com/pion/webrtc/v4 v4.0.9 // indirect
117-
github.com/pkg/errors v0.9.1 // indirect
118-
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
99+
github.com/pion/transport/v3 v3.0.8 // indirect
100+
github.com/pion/turn/v4 v4.1.2 // indirect
101+
github.com/pion/webrtc/v4 v4.1.6 // indirect
119102
github.com/polydawn/refmt v0.89.0 // indirect
120-
github.com/prometheus/client_golang v1.20.5 // indirect
121-
github.com/prometheus/client_model v0.6.1 // indirect
122-
github.com/prometheus/common v0.62.0 // indirect
123-
github.com/prometheus/procfs v0.15.1 // indirect
103+
github.com/prometheus/client_golang v1.23.2 // indirect
104+
github.com/prometheus/client_model v0.6.2 // indirect
105+
github.com/prometheus/common v0.67.2 // indirect
106+
github.com/prometheus/procfs v0.19.2 // indirect
124107
github.com/quic-go/qpack v0.5.1 // indirect
125-
github.com/quic-go/quic-go v0.49.0 // indirect
126-
github.com/quic-go/webtransport-go v0.8.1-0.20241018022711-4ac2c9250e66 // indirect
127-
github.com/raulk/go-watchdog v1.3.0 // indirect
108+
github.com/quic-go/quic-go v0.55.0 // indirect
109+
github.com/quic-go/webtransport-go v0.9.0 // indirect
128110
github.com/rivo/uniseg v0.4.7 // indirect
129111
github.com/spaolacci/murmur3 v1.1.0 // indirect
130-
github.com/stretchr/testify v1.10.0 // indirect
131112
github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1 // indirect
132113
github.com/wlynxg/anet v0.0.5 // indirect
133114
github.com/zeebo/blake3 v0.2.4 // indirect
134-
go.opencensus.io v0.24.0 // indirect
135-
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
136-
go.opentelemetry.io/otel v1.34.0 // indirect
137-
go.opentelemetry.io/otel/metric v1.34.0 // indirect
138-
go.opentelemetry.io/otel/trace v1.34.0 // indirect
139-
go.uber.org/dig v1.18.0 // indirect
140-
go.uber.org/fx v1.23.0 // indirect
141-
go.uber.org/mock v0.5.0 // indirect
115+
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
116+
go.opentelemetry.io/otel v1.38.0 // indirect
117+
go.opentelemetry.io/otel/metric v1.38.0 // indirect
118+
go.opentelemetry.io/otel/trace v1.38.0 // indirect
119+
go.uber.org/dig v1.19.0 // indirect
120+
go.uber.org/fx v1.24.0 // indirect
121+
go.uber.org/mock v0.6.0 // indirect
142122
go.uber.org/multierr v1.11.0 // indirect
143123
go.uber.org/zap v1.27.0 // indirect
144124
go.uber.org/zap/exp v0.3.0 // indirect
145-
golang.org/x/crypto v0.33.0 // indirect
146-
golang.org/x/exp v0.0.0-20250210185358-939b2ce775ac // indirect
147-
golang.org/x/mod v0.23.0 // indirect
148-
golang.org/x/net v0.35.0 // indirect
149-
golang.org/x/sync v0.11.0 // indirect
150-
golang.org/x/sys v0.30.0 // indirect
151-
golang.org/x/term v0.29.0 // indirect
152-
golang.org/x/text v0.22.0 // indirect
153-
golang.org/x/tools v0.30.0 // indirect
154-
gonum.org/v1/gonum v0.15.1 // indirect
155-
google.golang.org/protobuf v1.36.5 // indirect
156-
gopkg.in/yaml.v3 v3.0.1 // indirect
157-
lukechampine.com/blake3 v1.3.0 // indirect
125+
go.yaml.in/yaml/v2 v2.4.3 // indirect
126+
golang.org/x/crypto v0.43.0 // indirect
127+
golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546 // indirect
128+
golang.org/x/mod v0.29.0 // indirect
129+
golang.org/x/net v0.46.0 // indirect
130+
golang.org/x/sync v0.17.0 // indirect
131+
golang.org/x/sys v0.37.0 // indirect
132+
golang.org/x/telemetry v0.0.0-20251105150722-cbe4531f26c3 // indirect
133+
golang.org/x/term v0.36.0 // indirect
134+
golang.org/x/text v0.30.0 // indirect
135+
golang.org/x/time v0.14.0 // indirect
136+
golang.org/x/tools v0.38.0 // indirect
137+
gonum.org/v1/gonum v0.16.0 // indirect
138+
google.golang.org/protobuf v1.36.10 // indirect
139+
lukechampine.com/blake3 v1.4.1 // indirect
158140
)

0 commit comments

Comments
 (0)