-
Notifications
You must be signed in to change notification settings - Fork 887
fix: Remove ICEServer proxying from client to server #400
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,18 +31,26 @@ func TestDial(t *testing.T) { | |
defer client.Close() | ||
defer server.Close() | ||
|
||
listener, err := peerbroker.Listen(server, &peer.ConnOptions{ | ||
Logger: slogtest.Make(t, nil).Named("server").Leveled(slog.LevelDebug), | ||
settingEngine := webrtc.SettingEngine{} | ||
listener, err := peerbroker.Listen(server, func(ctx context.Context) ([]webrtc.ICEServer, error) { | ||
return []webrtc.ICEServer{{ | ||
URLs: []string{"stun:stun.l.google.com:19302"}, | ||
}}, nil | ||
Comment on lines
+35
to
+38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I switch the I guess it indicates there may be a bug with how we're interacting with a 'real' STUN server? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (or just removing the I had trouble finding docs on what the parameter was controlling - I found the code here https://github.com/pion/webrtc/blob/1765e9b913535f5e6aeacf91e7d4b75d1dbcdc9f/settingengine.go#L107 which sets https://github.com/pion/webrtc/blob/157220e800257ee4090f181e7edcca6435adb9f2/icegatherer.go#L102 - but wasn't clear to me how this enforces calling through to the STUN server. |
||
}, &peer.ConnOptions{ | ||
Logger: slogtest.Make(t, nil).Named("server").Leveled(slog.LevelDebug), | ||
SettingEngine: settingEngine, | ||
}) | ||
require.NoError(t, err) | ||
|
||
api := proto.NewDRPCPeerBrokerClient(provisionersdk.Conn(client)) | ||
stream, err := api.NegotiateConnection(ctx) | ||
require.NoError(t, err) | ||
|
||
clientConn, err := peerbroker.Dial(stream, []webrtc.ICEServer{{ | ||
URLs: []string{"stun:stun.l.google.com:19302"}, | ||
}}, &peer.ConnOptions{ | ||
Logger: slogtest.Make(t, nil).Named("client").Leveled(slog.LevelDebug), | ||
Logger: slogtest.Make(t, nil).Named("client").Leveled(slog.LevelDebug), | ||
SettingEngine: settingEngine, | ||
}) | ||
require.NoError(t, err) | ||
defer clientConn.Close() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,12 +17,21 @@ import ( | |
"github.com/coder/coder/peerbroker/proto" | ||
) | ||
|
||
// ICEServersFunc returns ICEServers when a new connection is requested. | ||
type ICEServersFunc func(ctx context.Context) ([]webrtc.ICEServer, error) | ||
|
||
// Listen consumes the transport as the server-side of the PeerBroker dRPC service. | ||
// The Accept function must be serviced, or new connections will hang. | ||
func Listen(connListener net.Listener, opts *peer.ConnOptions) (*Listener, error) { | ||
func Listen(connListener net.Listener, iceServersFunc ICEServersFunc, opts *peer.ConnOptions) (*Listener, error) { | ||
if iceServersFunc == nil { | ||
iceServersFunc = func(ctx context.Context) ([]webrtc.ICEServer, error) { | ||
return []webrtc.ICEServer{}, nil | ||
} | ||
} | ||
ctx, cancelFunc := context.WithCancel(context.Background()) | ||
listener := &Listener{ | ||
connectionChannel: make(chan *peer.Conn), | ||
iceServersFunc: iceServersFunc, | ||
|
||
closeFunc: cancelFunc, | ||
closed: make(chan struct{}), | ||
|
@@ -48,6 +57,7 @@ func Listen(connListener net.Listener, opts *peer.ConnOptions) (*Listener, error | |
|
||
type Listener struct { | ||
connectionChannel chan *peer.Conn | ||
iceServersFunc ICEServersFunc | ||
|
||
closeFunc context.CancelFunc | ||
closed chan struct{} | ||
|
@@ -104,8 +114,12 @@ type peerBrokerService struct { | |
|
||
// NegotiateConnection negotiates a WebRTC connection. | ||
func (b *peerBrokerService) NegotiateConnection(stream proto.DRPCPeerBroker_NegotiateConnectionStream) error { | ||
iceServers, err := b.listener.iceServersFunc(stream.Context()) | ||
if err != nil { | ||
return xerrors.Errorf("get ice servers: %w", err) | ||
} | ||
// Start with no ICE servers. They can be sent by the client if provided. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like this comment might need to be updated now - if I understand correctly, the client won't send ICE servers anymore. |
||
peerConn, err := peer.Server([]webrtc.ICEServer{}, b.connOptions) | ||
peerConn, err := peer.Server(iceServers, b.connOptions) | ||
if err != nil { | ||
return xerrors.Errorf("create peer connection: %w", err) | ||
} | ||
|
@@ -121,9 +135,9 @@ func (b *peerBrokerService) NegotiateConnection(stream proto.DRPCPeerBroker_Nego | |
case <-peerConn.Closed(): | ||
return | ||
case sessionDescription := <-peerConn.LocalSessionDescription(): | ||
err = stream.Send(&proto.NegotiateConnection_ServerToClient{ | ||
Message: &proto.NegotiateConnection_ServerToClient_Answer{ | ||
Answer: &proto.WebRTCSessionDescription{ | ||
err = stream.Send(&proto.Exchange{ | ||
Message: &proto.Exchange_Sdp{ | ||
Sdp: &proto.WebRTCSessionDescription{ | ||
SdpType: int32(sessionDescription.Type), | ||
Sdp: sessionDescription.SDP, | ||
}, | ||
|
@@ -134,8 +148,8 @@ func (b *peerBrokerService) NegotiateConnection(stream proto.DRPCPeerBroker_Nego | |
return | ||
} | ||
case iceCandidate := <-peerConn.LocalCandidate(): | ||
err = stream.Send(&proto.NegotiateConnection_ServerToClient{ | ||
Message: &proto.NegotiateConnection_ServerToClient_IceCandidate{ | ||
err = stream.Send(&proto.Exchange{ | ||
Message: &proto.Exchange_IceCandidate{ | ||
IceCandidate: iceCandidate.Candidate, | ||
}, | ||
}) | ||
|
@@ -156,28 +170,11 @@ func (b *peerBrokerService) NegotiateConnection(stream proto.DRPCPeerBroker_Nego | |
} | ||
|
||
switch { | ||
case clientToServerMessage.GetOffer() != nil: | ||
case clientToServerMessage.GetSdp() != nil: | ||
peerConn.SetRemoteSessionDescription(webrtc.SessionDescription{ | ||
Type: webrtc.SDPType(clientToServerMessage.GetOffer().SdpType), | ||
SDP: clientToServerMessage.GetOffer().Sdp, | ||
Type: webrtc.SDPType(clientToServerMessage.GetSdp().SdpType), | ||
SDP: clientToServerMessage.GetSdp().Sdp, | ||
}) | ||
case clientToServerMessage.GetServers() != nil: | ||
// Convert protobuf ICE servers to the WebRTC type. | ||
iceServers := make([]webrtc.ICEServer, 0, len(clientToServerMessage.GetServers().Servers)) | ||
for _, iceServer := range clientToServerMessage.GetServers().Servers { | ||
iceServers = append(iceServers, webrtc.ICEServer{ | ||
URLs: iceServer.Urls, | ||
Username: iceServer.Username, | ||
Credential: iceServer.Credential, | ||
CredentialType: webrtc.ICECredentialType(iceServer.CredentialType), | ||
}) | ||
} | ||
err = peerConn.SetConfiguration(webrtc.Configuration{ | ||
ICEServers: iceServers, | ||
}) | ||
if err != nil { | ||
return peerConn.CloseWithError(xerrors.Errorf("set ice configuration: %w", err)) | ||
} | ||
case clientToServerMessage.GetIceCandidate() != "": | ||
peerConn.AddRemoteCandidate(webrtc.ICECandidateInit{ | ||
Candidate: clientToServerMessage.GetIceCandidate(), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It wasn't clear to me where the client is sending these up now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was curious because it looks like the ice connection is failing in the tests now:
https://github.com/coder/coder/runs/5426432416?check_suite_focus=true#step:7:130
And I suspect it must be related to this change 🤔