commit c834c76fc50677cfb98e516e5d9d630ecfe691c2 Author: David Fifield david@bamsoftware.com Date: Mon Mar 12 19:59:21 2018 -0700
Call explicit frees in server-webrtc.
https://bugs.torproject.org/21312
Cf. corresponding change for proxy-go: https://gitweb.torproject.org/pluggable-transports/snowflake.git/commit/?id=... --- server-webrtc/snowflake.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)
diff --git a/server-webrtc/snowflake.go b/server-webrtc/snowflake.go index b95829d..82b6afe 100644 --- a/server-webrtc/snowflake.go +++ b/server-webrtc/snowflake.go @@ -52,12 +52,14 @@ func (c *webRTCConn) Read(b []byte) (int, error) { func (c *webRTCConn) Write(b []byte) (int, error) { // log.Printf("webrtc Write %d %+q", len(b), string(b)) log.Printf("Write %d bytes --> WebRTC", len(b)) - c.dc.Send(b) + if c.dc != nil { + c.dc.Send(b) + } return len(b), nil }
func (c *webRTCConn) Close() error { - return c.pc.Close() + return c.pc.Destroy() }
func (c *webRTCConn) LocalAddr() net.Addr { @@ -121,12 +123,16 @@ func makePeerConnectionFromOffer(sdp *webrtc.SessionDescription, config *webrtc.
pr, pw := io.Pipe()
+ conn := &webRTCConn{pc: pc, dc: dc, pr: pr} + dc.OnOpen = func() { log.Println("OnOpen channel") } dc.OnClose = func() { log.Println("OnClose channel") pw.Close() + conn.dc = nil + pc.DeleteDataChannel(dc) } dc.OnMessage = func(msg []byte) { log.Printf("OnMessage <--- %d bytes", len(msg)) @@ -139,13 +145,12 @@ func makePeerConnectionFromOffer(sdp *webrtc.SessionDescription, config *webrtc. } }
- conn := &webRTCConn{pc: pc, dc: dc, pr: pr} go datachannelHandler(conn) }
err = pc.SetRemoteDescription(sdp) if err != nil { - pc.Close() + pc.Destroy() return nil, fmt.Errorf("accept: SetRemoteDescription: %s", err) } log.Println("sdp offer successfully received.") @@ -167,11 +172,11 @@ func makePeerConnectionFromOffer(sdp *webrtc.SessionDescription, config *webrtc. // Wait until answer is ready. select { case err = <-errChan: - pc.Close() + pc.Destroy() return nil, err case _, ok := <-answerChan: if !ok { - pc.Close() + pc.Destroy() return nil, fmt.Errorf("Failed gathering ICE candidates.") } }
tor-commits@lists.torproject.org