commit 451edb6decf7790db2ec0efceb94dc994952b0e8 Author: Serene Han keroserene+git@gmail.com Date: Sun Mar 20 11:11:21 2016 -0700
begin multiplex snowflake connect loop for #31 --- client/snowflake.go | 21 ++++++++++++++++++--- client/webrtc.go | 3 --- 2 files changed, 18 insertions(+), 6 deletions(-)
diff --git a/client/snowflake.go b/client/snowflake.go index c78eed0..ac593a4 100644 --- a/client/snowflake.go +++ b/client/snowflake.go @@ -12,6 +12,7 @@ import ( "os/signal" "sync" "syscall" + "time"
"git.torproject.org/pluggable-transports/goptlib.git" "github.com/keroserene/go-webrtc" @@ -19,10 +20,10 @@ import (
var ptInfo pt.ClientInfo
-// var logFile *os.File var brokerURL string var frontDomain string var iceServers IceServerList +var snowflakes []*webRTCConn
// When a connection handler starts, +1 is written to this channel; when it // ends, -1 is written. @@ -30,6 +31,7 @@ var handlerChan = make(chan int)
const ( ReconnectTimeout = 5 + SnowflakeCapacity = 1 )
func copyLoop(a, b net.Conn) { @@ -53,6 +55,20 @@ type SnowflakeChannel interface { Close() error }
+// Maintain |WebRTCSlots| number of open connections to +// transfer to SOCKS when needed. TODO: complete +func SnowflakeConnectLoop() { + for len(snowflakes) < SnowflakeCapacity { + s, err := dialWebRTC() + if err != nil { + snowflakes = append(snowflakes, s) + continue + } + log.Println("WebRTC Error: ", err) + <-time.After(time.Second * ReconnectTimeout) + } +} + // Initialize a WebRTC Connection. func dialWebRTC() (*webRTCConn, error) { // TODO: [#3] Fetch ICE server information from Broker. @@ -82,8 +98,6 @@ func handler(conn *pt.SocksConn) error { defer func() { handlerChan <- -1 }() - defer conn.Close() - log.Println("handler fired:", conn)
remote, err := dialWebRTC() if err != nil || remote == nil { @@ -91,6 +105,7 @@ func handler(conn *pt.SocksConn) error { return err } defer remote.Close() + defer conn.Close() webrtcRemote = remote
err = conn.Grant(&net.TCPAddr{IP: net.IPv4zero, Port: 0}) diff --git a/client/webrtc.go b/client/webrtc.go index 1300212..55f39e0 100644 --- a/client/webrtc.go +++ b/client/webrtc.go @@ -207,9 +207,6 @@ func (c *webRTCConn) establishDataChannel() error { // Disable the DataChannel as a write destination. log.Println("WebRTC: DataChannel.OnClose [remotely]") c.snowflake = nil - // TODO(issue #12): Need a way to update the circuit so that when a new WebRTC - // data channel is available, the relay actually recognizes the new - // snowflake. c.Reset() } dc.OnMessage = func(msg []byte) {
tor-commits@lists.torproject.org