mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 20:11:19 -04:00
only flush datachannel with nonzero bytes, which prevents Tor from marking the SOCKS for close (#12)
This commit is contained in:
parent
38999e02de
commit
f3e0abe0e1
2 changed files with 10 additions and 6 deletions
|
@ -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() {
|
||||
|
|
|
@ -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---")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue