mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 20:11:19 -04:00
Terminate timeoutLoop when conn is closed
This commit is contained in:
parent
5c23fcf14a
commit
b010de5abb
1 changed files with 5 additions and 1 deletions
|
@ -35,12 +35,14 @@ type webRTCConn struct {
|
||||||
|
|
||||||
inactivityTimeout time.Duration
|
inactivityTimeout time.Duration
|
||||||
activity chan struct{}
|
activity chan struct{}
|
||||||
|
closed chan struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func newWebRTCConn(pc *webrtc.PeerConnection, dc *webrtc.DataChannel, pr *io.PipeReader, eventLogger event.SnowflakeEventReceiver) *webRTCConn {
|
func newWebRTCConn(pc *webrtc.PeerConnection, dc *webrtc.DataChannel, pr *io.PipeReader, eventLogger event.SnowflakeEventReceiver) *webRTCConn {
|
||||||
conn := &webRTCConn{pc: pc, dc: dc, pr: pr, eventLogger: eventLogger}
|
conn := &webRTCConn{pc: pc, dc: dc, pr: pr, eventLogger: eventLogger}
|
||||||
conn.bytesLogger = newBytesSyncLogger()
|
conn.bytesLogger = newBytesSyncLogger()
|
||||||
conn.activity = make(chan struct{}, 100)
|
conn.activity = make(chan struct{}, 100)
|
||||||
|
conn.closed = make(chan struct{})
|
||||||
conn.inactivityTimeout = 30 * time.Second
|
conn.inactivityTimeout = 30 * time.Second
|
||||||
go conn.timeoutLoop()
|
go conn.timeoutLoop()
|
||||||
return conn
|
return conn
|
||||||
|
@ -55,9 +57,10 @@ func (c *webRTCConn) timeoutLoop() {
|
||||||
return
|
return
|
||||||
case <-c.activity:
|
case <-c.activity:
|
||||||
continue
|
continue
|
||||||
|
case <-c.closed:
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *webRTCConn) Read(b []byte) (int, error) {
|
func (c *webRTCConn) Read(b []byte) (int, error) {
|
||||||
|
@ -77,6 +80,7 @@ func (c *webRTCConn) Write(b []byte) (int, error) {
|
||||||
|
|
||||||
func (c *webRTCConn) Close() (err error) {
|
func (c *webRTCConn) Close() (err error) {
|
||||||
c.once.Do(func() {
|
c.once.Do(func() {
|
||||||
|
close(c.closed)
|
||||||
err = c.pc.Close()
|
err = c.pc.Close()
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue