Skip to content

Commit c08bae9

Browse files
committed
Add ASCII chart
1 parent 748fe1f commit c08bae9

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

peerbroker/proxy.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
)
2222

2323
var (
24-
// Each NegotiationConnection() function call spawns a new stream.
24+
// Each NegotiateConnection() function call spawns a new stream.
2525
streamIDLength = len(uuid.NewString())
2626
// We shouldn't PubSub anything larger than this!
2727
maxPayloadSizeBytes = 8192
@@ -36,8 +36,19 @@ type ProxyOptions struct {
3636

3737
// ProxyDial writes client negotiation streams over PubSub.
3838
//
39-
// PubSub is used to geodistribute in a simple way. All message payloads
40-
// are small in size <=8KB, and we don't require delivery guarantees.
39+
// PubSub is used to geodistribute WebRTC handshakes. All negotiation
40+
// messages are small in size (<=8KB), and we don't require delivery
41+
// guarantees because connections can always be renegotiated.
42+
// ┌────────────────────┐ ┌─────────────────────────────┐
43+
// │ coderd │ │ coderd │
44+
// ┌─────────────────────┐ │/<agent-id>/connect │ │ /<agent-id>/listen │
45+
// │ client │ │ │ │ │ ┌─────┐
46+
// │ ├──►│Creates a stream ID │◄─►│Subscribe() to the <agent-id>│◄──┤agent│
47+
// │NegotiateConnection()│ │and Publish() to the│ │channel. Parse the stream ID │ └─────┘
48+
// └─────────────────────┘ │<agent-id> channel: │ │from payloads to create new │
49+
// │ │ │NegotiateConnection() streams│
50+
// │<stream-id><payload>│ │or write to existing ones. │
51+
// └────────────────────┘ └─────────────────────────────┘
4152
func ProxyDial(client proto.DRPCPeerBrokerClient, options ProxyOptions) (io.Closer, error) {
4253
proxyDial := &proxyDial{
4354
channelID: options.ChannelID,

peerbroker/proxy_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package peerbroker_test
22

33
import (
44
"context"
5+
"sync"
56
"testing"
67

78
"github.com/pion/webrtc/v3"
@@ -43,7 +44,10 @@ func TestProxy(t *testing.T) {
4344
_ = proxyCloser.Close()
4445
})
4546

47+
var wg sync.WaitGroup
48+
wg.Add(1)
4649
go func() {
50+
defer wg.Done()
4751
err = peerbroker.ProxyListen(ctx, dialerServer, peerbroker.ProxyOptions{
4852
ChannelID: channelID,
4953
Logger: slogtest.Make(t, nil).Named("proxy-dial").Leveled(slog.LevelDebug),
@@ -71,4 +75,5 @@ func TestProxy(t *testing.T) {
7175

7276
_, err = clientConn.Ping()
7377
require.NoError(t, err)
78+
wg.Wait()
7479
}

0 commit comments

Comments
 (0)