mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-14 05:11:19 -04:00
Remove now unecessary timeoutConn
This commit is contained in:
parent
76087a6a77
commit
11bd32f62e
1 changed files with 5 additions and 24 deletions
|
@ -204,38 +204,19 @@ func sendAnswer(sid string, pc *webrtc.PeerConnection) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type timeoutConn struct {
|
func CopyLoop(c1 net.Conn, c2 net.Conn) {
|
||||||
c net.Conn
|
|
||||||
t time.Duration
|
|
||||||
}
|
|
||||||
|
|
||||||
func (tc timeoutConn) Read(buf []byte) (int, error) {
|
|
||||||
return tc.c.Read(buf)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (tc timeoutConn) Write(buf []byte) (int, error) {
|
|
||||||
return tc.c.Write(buf)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (tc timeoutConn) Close() error {
|
|
||||||
return tc.c.Close()
|
|
||||||
}
|
|
||||||
|
|
||||||
func CopyLoopTimeout(c1 net.Conn, c2 net.Conn, timeout time.Duration) {
|
|
||||||
tc1 := timeoutConn{c: c1, t: timeout}
|
|
||||||
tc2 := timeoutConn{c: c2, t: timeout}
|
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
copyer := func(dst io.ReadWriteCloser, src io.ReadWriteCloser) {
|
copyer := func(dst io.ReadWriteCloser, src io.ReadWriteCloser) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
if _, err := io.Copy(dst, src); err != nil {
|
if _, err := io.Copy(dst, src); err != nil {
|
||||||
log.Printf("io.Copy inside CopyLoopTimeout generated an error: %v", err)
|
log.Printf("io.Copy inside CopyLoop generated an error: %v", err)
|
||||||
}
|
}
|
||||||
dst.Close()
|
dst.Close()
|
||||||
src.Close()
|
src.Close()
|
||||||
}
|
}
|
||||||
wg.Add(2)
|
wg.Add(2)
|
||||||
go copyer(tc1, tc2)
|
go copyer(c1, c2)
|
||||||
go copyer(tc2, tc1)
|
go copyer(c2, c1)
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -271,7 +252,7 @@ func datachannelHandler(conn *webRTCConn, remoteAddr net.Addr) {
|
||||||
log.Printf("connected to relay")
|
log.Printf("connected to relay")
|
||||||
defer wsConn.Close()
|
defer wsConn.Close()
|
||||||
wsConn.PayloadType = websocket.BinaryFrame
|
wsConn.PayloadType = websocket.BinaryFrame
|
||||||
CopyLoopTimeout(conn, wsConn, time.Minute)
|
CopyLoop(conn, wsConn)
|
||||||
log.Printf("datachannelHandler ends")
|
log.Printf("datachannelHandler ends")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue