@@ -23,9 +23,7 @@ import (
23
23
"github.com/coder/coder/coderd/httpapi"
24
24
"github.com/coder/coder/coderd/httpmw"
25
25
"github.com/coder/coder/coderd/rbac"
26
- "github.com/coder/coder/coderd/turnconn"
27
26
"github.com/coder/coder/codersdk"
28
- "github.com/coder/coder/peer"
29
27
"github.com/coder/coder/peerbroker"
30
28
"github.com/coder/coder/peerbroker/proto"
31
29
"github.com/coder/coder/provisionersdk"
@@ -468,74 +466,6 @@ func (api *API) dialWorkspaceAgentTailnet(r *http.Request, agentID uuid.UUID) (a
468
466
}, nil
469
467
}
470
468
471
- // dialWorkspaceAgent connects to a workspace agent by ID. Only rely on
472
- // r.Context() for cancellation if it's use is safe or r.Hijack() has
473
- // not been performed.
474
- func (api * API ) dialWorkspaceAgent (r * http.Request , agentID uuid.UUID ) (agent.Conn , error ) {
475
- client , server := provisionersdk .TransportPipe ()
476
- ctx , cancelFunc := context .WithCancel (context .Background ())
477
- go func () {
478
- _ = peerbroker .ProxyListen (ctx , server , peerbroker.ProxyOptions {
479
- ChannelID : agentID .String (),
480
- Logger : api .Logger .Named ("peerbroker-proxy-dial" ),
481
- Pubsub : api .Pubsub ,
482
- })
483
- _ = client .Close ()
484
- _ = server .Close ()
485
- }()
486
-
487
- peerClient := proto .NewDRPCPeerBrokerClient (provisionersdk .Conn (client ))
488
- stream , err := peerClient .NegotiateConnection (ctx )
489
- if err != nil {
490
- cancelFunc ()
491
- return nil , xerrors .Errorf ("negotiate: %w" , err )
492
- }
493
- options := & peer.ConnOptions {
494
- Logger : api .Logger .Named ("agent-dialer" ),
495
- }
496
- options .SettingEngine .SetSrflxAcceptanceMinWait (0 )
497
- options .SettingEngine .SetRelayAcceptanceMinWait (0 )
498
- // Use the ProxyDialer for the TURN server.
499
- // This is required for connections where P2P is not enabled.
500
- options .SettingEngine .SetICEProxyDialer (turnconn .ProxyDialer (func () (c net.Conn , err error ) {
501
- clientPipe , serverPipe := net .Pipe ()
502
- go func () {
503
- <- ctx .Done ()
504
- _ = clientPipe .Close ()
505
- _ = serverPipe .Close ()
506
- }()
507
- localAddress , _ := r .Context ().Value (http .LocalAddrContextKey ).(* net.TCPAddr )
508
- remoteAddress := & net.TCPAddr {
509
- IP : net .ParseIP (r .RemoteAddr ),
510
- }
511
- // By default requests have the remote address and port.
512
- host , port , err := net .SplitHostPort (r .RemoteAddr )
513
- if err != nil {
514
- return nil , xerrors .Errorf ("split remote address: %w" , err )
515
- }
516
- remoteAddress .IP = net .ParseIP (host )
517
- remoteAddress .Port , err = strconv .Atoi (port )
518
- if err != nil {
519
- return nil , xerrors .Errorf ("convert remote port: %w" , err )
520
- }
521
- api .TURNServer .Accept (clientPipe , remoteAddress , localAddress )
522
- return serverPipe , nil
523
- }))
524
- peerConn , err := peerbroker .Dial (stream , append (api .ICEServers , turnconn .Proxy ), options )
525
- if err != nil {
526
- cancelFunc ()
527
- return nil , xerrors .Errorf ("dial: %w" , err )
528
- }
529
- go func () {
530
- <- peerConn .Closed ()
531
- cancelFunc ()
532
- }()
533
- return & agent.WebRTCConn {
534
- Negotiator : peerClient ,
535
- Conn : peerConn ,
536
- }, nil
537
- }
538
-
539
469
func (api * API ) workspaceAgentConnection (rw http.ResponseWriter , r * http.Request ) {
540
470
workspace := httpmw .WorkspaceParam (r )
541
471
if ! api .Authorize (r , rbac .ActionRead , workspace ) {
0 commit comments