only flush datachannel with nonzero bytes, which prevents Tor from marking the SOCKS for close (#12)

This commit is contained in:
Serene Han 2016-02-25 01:23:59 -08:00
parent 38999e02de
commit f3e0abe0e1
2 changed files with 10 additions and 6 deletions

View file

@ -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---")
}