mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-14 05: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)
|
log.Println("handler fired:", conn)
|
||||||
|
|
||||||
remote, err := dialWebRTC()
|
remote, err := dialWebRTC()
|
||||||
if err != nil {
|
if err != nil || remote == nil {
|
||||||
conn.Reject()
|
conn.Reject()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -123,6 +123,7 @@ func handler(conn *pt.SocksConn) error {
|
||||||
func acceptLoop(ln *pt.SocksListener) error {
|
func acceptLoop(ln *pt.SocksListener) error {
|
||||||
defer ln.Close()
|
defer ln.Close()
|
||||||
for {
|
for {
|
||||||
|
log.Println("SOCKS listening...")
|
||||||
conn, err := ln.AcceptSocks()
|
conn, err := ln.AcceptSocks()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if e, ok := err.(net.Error); ok && e.Temporary() {
|
if e, ok := err.(net.Error); ok && e.Temporary() {
|
||||||
|
|
|
@ -172,11 +172,13 @@ func (c *webRTCConn) establishDataChannel() error {
|
||||||
if nil != c.snowflake {
|
if nil != c.snowflake {
|
||||||
panic("PeerConnection snowflake already exists.")
|
panic("PeerConnection snowflake already exists.")
|
||||||
}
|
}
|
||||||
// Flush the buffer, then enable datachannel.
|
// Flush the buffer if necessary.
|
||||||
|
if c.buffer.Len() > 0 {
|
||||||
dc.Send(c.buffer.Bytes())
|
dc.Send(c.buffer.Bytes())
|
||||||
log.Println("Flushed", c.buffer.Len(), "bytes")
|
log.Println("Flushed", c.buffer.Len(), "bytes.")
|
||||||
c.buffer.Reset()
|
c.buffer.Reset()
|
||||||
|
}
|
||||||
|
// Then enable the datachannel.
|
||||||
c.snowflake = dc
|
c.snowflake = dc
|
||||||
}
|
}
|
||||||
dc.OnClose = func() {
|
dc.OnClose = func() {
|
||||||
|
@ -190,6 +192,7 @@ func (c *webRTCConn) establishDataChannel() error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dc.OnMessage = func(msg []byte) {
|
dc.OnMessage = func(msg []byte) {
|
||||||
|
// log.Println("ONMESSAGE: ", len(msg))
|
||||||
if len(msg) <= 0 {
|
if len(msg) <= 0 {
|
||||||
log.Println("0 length---")
|
log.Println("0 length---")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue