commit 598e2a3bfb1cd8effab4c1b945035c870be16bff Author: Arlo Breault arlolra@gmail.com Date: Fri Mar 18 21:29:31 2016 -0700
Close SocksConn when WebRTC connection is reset
* This will induce the tor client to establish a new SocksConn, which in turn will dial a new WebRTC connection.
To be improved upon.
* Part of #12 --- client/snowflake.go | 6 ++++++ client/webrtc.go | 37 +++++++++++++++++-------------------- 2 files changed, 23 insertions(+), 20 deletions(-)
diff --git a/client/snowflake.go b/client/snowflake.go index 652032a..5fe55a9 100644 --- a/client/snowflake.go +++ b/client/snowflake.go @@ -99,6 +99,12 @@ func handler(conn *pt.SocksConn) error { defer remote.Close() webrtcRemote = remote
+ // Induce another call to handler + go func() { + <-remote.reset + conn.Close() + }() + err = conn.Grant(&net.TCPAddr{IP: net.IPv4zero, Port: 0}) if err != nil { return err diff --git a/client/webrtc.go b/client/webrtc.go index af32ddd..2be31b5 100644 --- a/client/webrtc.go +++ b/client/webrtc.go @@ -101,27 +101,24 @@ func NewWebRTCConnection(config *webrtc.Configuration,
// WebRTC re-establishment loop. Expected in own goroutine. func (c *webRTCConn) ConnectLoop() { - for { - log.Println("Establishing WebRTC connection...") - // TODO: When go-webrtc is more stable, it's possible that a new - // PeerConnection won't need to be re-prepared each time. - err := c.preparePeerConnection() - if err != nil { - log.Println("WebRTC: Could not create PeerConnection.") - break - } - err = c.establishDataChannel() - if err != nil { - log.Println("WebRTC: Could not establish DataChannel.") - } else { - go c.exchangeSDP() - <-c.reset - log.Println(" --- snowflake connection reset ---") - } - <-time.After(time.Second * 1) - c.cleanup() + log.Println("Establishing WebRTC connection...") + // TODO: When go-webrtc is more stable, it's possible that a new + // PeerConnection won't need to be re-prepared each time. + err := c.preparePeerConnection() + if err != nil { + log.Println("WebRTC: Could not create PeerConnection.") + return } - log.Println("WebRTC cannot connect.") + err = c.establishDataChannel() + if err != nil { + log.Println("WebRTC: Could not establish DataChannel.") + } else { + go c.exchangeSDP() + <-c.reset + log.Println(" --- snowflake connection reset ---") + } + <-time.After(time.Second * 1) + c.cleanup() }
// Create and prepare callbacks on a new WebRTC PeerConnection.
tor-commits@lists.torproject.org