Eliminate separate WebRTCPeer.Connect method.

Do it as a side effect of NewWebRTCPeer.

Remove WebRTCPeer tests as they currently require invasively modifying
internal fields at different stages of construction.
This commit is contained in:
David Fifield 2020-04-24 00:05:06 -06:00
parent b48fb781ee
commit 32207d6f06
4 changed files with 10 additions and 111 deletions

View file

@ -41,7 +41,7 @@ type WebRTCPeer struct {
// Construct a WebRTC PeerConnection.
func NewWebRTCPeer(config *webrtc.Configuration,
broker *BrokerChannel) *WebRTCPeer {
broker *BrokerChannel) (*WebRTCPeer, error) {
connection := new(WebRTCPeer)
{
var buf [8]byte
@ -60,7 +60,13 @@ func NewWebRTCPeer(config *webrtc.Configuration,
// Pipes remain the same even when DataChannel gets switched.
connection.recvPipe, connection.writePipe = io.Pipe()
return connection
err := connection.connect()
if err != nil {
connection.Close()
return nil, err
}
return connection, nil
}
// Read bytes from local SOCKS.
@ -113,8 +119,7 @@ func (c *WebRTCPeer) checkForStaleness() {
}
}
// As part of |Connector| interface.
func (c *WebRTCPeer) Connect() error {
func (c *WebRTCPeer) connect() error {
log.Println(c.id, " connecting...")
// TODO: When go-webrtc is more stable, it's possible that a new
// PeerConnection won't need to be re-prepared each time.