Skip to content

Commit c9a416a

Browse files
committed
chore: Remove WebRTC networking
1 parent 38825b9 commit c9a416a

40 files changed

+279
-4158
lines changed

Makefile

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ endif
117117
fmt: fmt/prettier fmt/terraform fmt/shfmt
118118
.PHONY: fmt
119119

120-
gen: coderd/database/querier.go peerbroker/proto/peerbroker.pb.go provisionersdk/proto/provisioner.pb.go provisionerd/proto/provisionerd.pb.go site/src/api/typesGenerated.ts
120+
gen: coderd/database/querier.go provisionersdk/proto/provisioner.pb.go provisionerd/proto/provisionerd.pb.go site/src/api/typesGenerated.ts
121121
.PHONY: gen
122122

123123
install: site/out/index.html $(shell find . -not -path './vendor/*' -type f -name '*.go') go.mod go.sum $(shell find ./examples/templates)
@@ -152,14 +152,6 @@ lint/shellcheck: $(shell shfmt -f .)
152152
shellcheck --external-sources $(shell shfmt -f .)
153153
.PHONY: lint/shellcheck
154154

155-
peerbroker/proto/peerbroker.pb.go: peerbroker/proto/peerbroker.proto
156-
protoc \
157-
--go_out=. \
158-
--go_opt=paths=source_relative \
159-
--go-drpc_out=. \
160-
--go-drpc_opt=paths=source_relative \
161-
./peerbroker/proto/peerbroker.proto
162-
163155
provisionerd/proto/provisionerd.pb.go: provisionerd/proto/provisionerd.proto
164156
protoc \
165157
--go_out=. \

agent/agent.go

Lines changed: 1 addition & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ import (
3333

3434
"cdr.dev/slog"
3535
"github.com/coder/coder/agent/usershell"
36-
"github.com/coder/coder/peer"
37-
"github.com/coder/coder/peerbroker"
3836
"github.com/coder/coder/pty"
3937
"github.com/coder/coder/tailnet"
4038
"github.com/coder/retry"
@@ -62,7 +60,6 @@ var (
6260

6361
type Options struct {
6462
CoordinatorDialer CoordinatorDialer
65-
WebRTCDialer WebRTCDialer
6663
FetchMetadata FetchMetadata
6764

6865
StatsReporter StatsReporter
@@ -78,8 +75,6 @@ type Metadata struct {
7875
Directory string `json:"directory"`
7976
}
8077

81-
type WebRTCDialer func(ctx context.Context, logger slog.Logger) (*peerbroker.Listener, error)
82-
8378
// CoordinatorDialer is a function that constructs a new broker.
8479
// A dialer must be passed in to allow for reconnects.
8580
type CoordinatorDialer func(ctx context.Context) (net.Conn, error)
@@ -93,7 +88,6 @@ func New(options Options) io.Closer {
9388
}
9489
ctx, cancelFunc := context.WithCancel(context.Background())
9590
server := &agent{
96-
webrtcDialer: options.WebRTCDialer,
9791
reconnectingPTYTimeout: options.ReconnectingPTYTimeout,
9892
logger: options.Logger,
9993
closeCancel: cancelFunc,
@@ -109,8 +103,7 @@ func New(options Options) io.Closer {
109103
}
110104

111105
type agent struct {
112-
webrtcDialer WebRTCDialer
113-
logger slog.Logger
106+
logger slog.Logger
114107

115108
reconnectingPTYs sync.Map
116109
reconnectingPTYTimeout time.Duration
@@ -171,9 +164,6 @@ func (a *agent) run(ctx context.Context) {
171164
}
172165
}()
173166

174-
if a.webrtcDialer != nil {
175-
go a.runWebRTCNetworking(ctx)
176-
}
177167
if metadata.DERPMap != nil {
178168
go a.runTailnet(ctx, metadata.DERPMap)
179169
}
@@ -303,49 +293,6 @@ func (a *agent) runCoordinator(ctx context.Context) {
303293
}
304294
}
305295

306-
func (a *agent) runWebRTCNetworking(ctx context.Context) {
307-
var peerListener *peerbroker.Listener
308-
var err error
309-
// An exponential back-off occurs when the connection is failing to dial.
310-
// This is to prevent server spam in case of a coderd outage.
311-
for retrier := retry.New(50*time.Millisecond, 10*time.Second); retrier.Wait(ctx); {
312-
peerListener, err = a.webrtcDialer(ctx, a.logger)
313-
if err != nil {
314-
if errors.Is(err, context.Canceled) {
315-
return
316-
}
317-
if a.isClosed() {
318-
return
319-
}
320-
a.logger.Warn(context.Background(), "failed to dial", slog.Error(err))
321-
continue
322-
}
323-
a.logger.Info(context.Background(), "connected to webrtc broker")
324-
break
325-
}
326-
select {
327-
case <-ctx.Done():
328-
return
329-
default:
330-
}
331-
332-
for {
333-
conn, err := peerListener.Accept()
334-
if err != nil {
335-
if a.isClosed() {
336-
return
337-
}
338-
a.logger.Debug(ctx, "peer listener accept exited; restarting connection", slog.Error(err))
339-
a.runWebRTCNetworking(ctx)
340-
return
341-
}
342-
a.closeMutex.Lock()
343-
a.connCloseWait.Add(1)
344-
a.closeMutex.Unlock()
345-
go a.handlePeerConn(ctx, conn)
346-
}
347-
}
348-
349296
func (a *agent) runStartupScript(ctx context.Context, script string) error {
350297
if script == "" {
351298
return nil
@@ -378,74 +325,6 @@ func (a *agent) runStartupScript(ctx context.Context, script string) error {
378325
return nil
379326
}
380327

381-
func (a *agent) handlePeerConn(ctx context.Context, peerConn *peer.Conn) {
382-
go func() {
383-
select {
384-
case <-a.closed:
385-
case <-peerConn.Closed():
386-
}
387-
_ = peerConn.Close()
388-
a.connCloseWait.Done()
389-
}()
390-
for {
391-
channel, err := peerConn.Accept(ctx)
392-
if err != nil {
393-
if errors.Is(err, peer.ErrClosed) || a.isClosed() {
394-
return
395-
}
396-
a.logger.Debug(ctx, "accept channel from peer connection", slog.Error(err))
397-
return
398-
}
399-
400-
conn := channel.NetConn()
401-
402-
switch channel.Protocol() {
403-
case ProtocolSSH:
404-
go a.sshServer.HandleConn(a.stats.wrapConn(conn))
405-
case ProtocolReconnectingPTY:
406-
rawID := channel.Label()
407-
// The ID format is referenced in conn.go.
408-
// <uuid>:<height>:<width>
409-
idParts := strings.SplitN(rawID, ":", 4)
410-
if len(idParts) != 4 {
411-
a.logger.Warn(ctx, "client sent invalid id format", slog.F("raw-id", rawID))
412-
continue
413-
}
414-
id := idParts[0]
415-
// Enforce a consistent format for IDs.
416-
_, err := uuid.Parse(id)
417-
if err != nil {
418-
a.logger.Warn(ctx, "client sent reconnection token that isn't a uuid", slog.F("id", id), slog.Error(err))
419-
continue
420-
}
421-
// Parse the initial terminal dimensions.
422-
height, err := strconv.Atoi(idParts[1])
423-
if err != nil {
424-
a.logger.Warn(ctx, "client sent invalid height", slog.F("id", id), slog.F("height", idParts[1]))
425-
continue
426-
}
427-
width, err := strconv.Atoi(idParts[2])
428-
if err != nil {
429-
a.logger.Warn(ctx, "client sent invalid width", slog.F("id", id), slog.F("width", idParts[2]))
430-
continue
431-
}
432-
go a.handleReconnectingPTY(ctx, reconnectingPTYInit{
433-
ID: id,
434-
Height: uint16(height),
435-
Width: uint16(width),
436-
Command: idParts[3],
437-
}, a.stats.wrapConn(conn))
438-
case ProtocolDial:
439-
go a.handleDial(ctx, channel.Label(), a.stats.wrapConn(conn))
440-
default:
441-
a.logger.Warn(ctx, "unhandled protocol from channel",
442-
slog.F("protocol", channel.Protocol()),
443-
slog.F("label", channel.Label()),
444-
)
445-
}
446-
}
447-
}
448-
449328
func (a *agent) init(ctx context.Context) {
450329
a.logger.Info(ctx, "generating host key")
451330
// Clients' should ignore the host key when connecting.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy