@@ -33,8 +33,6 @@ import (
33
33
34
34
"cdr.dev/slog"
35
35
"github.com/coder/coder/agent/usershell"
36
- "github.com/coder/coder/peer"
37
- "github.com/coder/coder/peerbroker"
38
36
"github.com/coder/coder/pty"
39
37
"github.com/coder/coder/tailnet"
40
38
"github.com/coder/retry"
62
60
63
61
type Options struct {
64
62
CoordinatorDialer CoordinatorDialer
65
- WebRTCDialer WebRTCDialer
66
63
FetchMetadata FetchMetadata
67
64
68
65
StatsReporter StatsReporter
@@ -78,8 +75,6 @@ type Metadata struct {
78
75
Directory string `json:"directory"`
79
76
}
80
77
81
- type WebRTCDialer func (ctx context.Context , logger slog.Logger ) (* peerbroker.Listener , error )
82
-
83
78
// CoordinatorDialer is a function that constructs a new broker.
84
79
// A dialer must be passed in to allow for reconnects.
85
80
type CoordinatorDialer func (ctx context.Context ) (net.Conn , error )
@@ -93,7 +88,6 @@ func New(options Options) io.Closer {
93
88
}
94
89
ctx , cancelFunc := context .WithCancel (context .Background ())
95
90
server := & agent {
96
- webrtcDialer : options .WebRTCDialer ,
97
91
reconnectingPTYTimeout : options .ReconnectingPTYTimeout ,
98
92
logger : options .Logger ,
99
93
closeCancel : cancelFunc ,
@@ -109,8 +103,7 @@ func New(options Options) io.Closer {
109
103
}
110
104
111
105
type agent struct {
112
- webrtcDialer WebRTCDialer
113
- logger slog.Logger
106
+ logger slog.Logger
114
107
115
108
reconnectingPTYs sync.Map
116
109
reconnectingPTYTimeout time.Duration
@@ -171,9 +164,6 @@ func (a *agent) run(ctx context.Context) {
171
164
}
172
165
}()
173
166
174
- if a .webrtcDialer != nil {
175
- go a .runWebRTCNetworking (ctx )
176
- }
177
167
if metadata .DERPMap != nil {
178
168
go a .runTailnet (ctx , metadata .DERPMap )
179
169
}
@@ -303,49 +293,6 @@ func (a *agent) runCoordinator(ctx context.Context) {
303
293
}
304
294
}
305
295
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
-
349
296
func (a * agent ) runStartupScript (ctx context.Context , script string ) error {
350
297
if script == "" {
351
298
return nil
@@ -378,74 +325,6 @@ func (a *agent) runStartupScript(ctx context.Context, script string) error {
378
325
return nil
379
326
}
380
327
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
-
449
328
func (a * agent ) init (ctx context.Context ) {
450
329
a .logger .Info (ctx , "generating host key" )
451
330
// Clients' should ignore the host key when connecting.
0 commit comments