[tor-commits] [snowflake/master] only flush datachannel with nonzero bytes, which prevents Tor from marking the SOCKS for close (#12)

serene at torproject.org serene at torproject.org
Fri Mar 4 21:22:52 UTC 2016


commit f3e0abe0e169f6e5467aae75286ace935924370f
Author: Serene Han <keroserene+git at gmail.com>
Date:   Thu Feb 25 01:23:59 2016 -0800

    only flush datachannel with nonzero bytes, which prevents Tor from marking the SOCKS for close (#12)
---
 client/snowflake.go |  3 ++-
 client/webrtc.go    | 13 ++++++++-----
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/client/snowflake.go b/client/snowflake.go
index 615038c..2c40796 100644
--- a/client/snowflake.go
+++ b/client/snowflake.go
@@ -101,7 +101,7 @@ func handler(conn *pt.SocksConn) error {
 	log.Println("handler fired:", conn)
 
 	remote, err := dialWebRTC()
-	if err != nil {
+	if err != nil || remote == nil {
 		conn.Reject()
 		return err
 	}
@@ -123,6 +123,7 @@ func handler(conn *pt.SocksConn) error {
 func acceptLoop(ln *pt.SocksListener) error {
 	defer ln.Close()
 	for {
+		log.Println("SOCKS listening...")
 		conn, err := ln.AcceptSocks()
 		if err != nil {
 			if e, ok := err.(net.Error); ok && e.Temporary() {
diff --git a/client/webrtc.go b/client/webrtc.go
index 0c865fa..d60f212 100644
--- a/client/webrtc.go
+++ b/client/webrtc.go
@@ -172,11 +172,13 @@ func (c *webRTCConn) establishDataChannel() error {
 		if nil != c.snowflake {
 			panic("PeerConnection snowflake already exists.")
 		}
-		// Flush the buffer, then enable datachannel.
-		dc.Send(c.buffer.Bytes())
-		log.Println("Flushed", c.buffer.Len(), "bytes")
-		c.buffer.Reset()
-
+		// Flush the buffer if necessary.
+		if c.buffer.Len() > 0 {
+			dc.Send(c.buffer.Bytes())
+			log.Println("Flushed", c.buffer.Len(), "bytes.")
+			c.buffer.Reset()
+		}
+		// Then enable the datachannel.
 		c.snowflake = dc
 	}
 	dc.OnClose = func() {
@@ -190,6 +192,7 @@ func (c *webRTCConn) establishDataChannel() error {
 		}
 	}
 	dc.OnMessage = func(msg []byte) {
+		// log.Println("ONMESSAGE: ", len(msg))
 		if len(msg) <= 0 {
 			log.Println("0 length---")
 		}





More information about the tor-commits mailing list