[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [pluggable-transports/snowflake] 02/04: Add timeout for webRTCConn
This is an automated email from the git hooks/post-receive script.
cohosh pushed a commit to branch main
in repository pluggable-transports/snowflake.
commit 5c23fcf14ab7342be57244731b80937c0dad27f3
Author: Cecylia Bocovich <cohosh@xxxxxxxxxxxxxx>
AuthorDate: Tue Oct 18 15:43:30 2022 -0400
Add timeout for webRTCConn
---
proxy/lib/webrtcconn.go | 23 ++++++++++++++++++++++-
1 file changed, 22 insertions(+), 1 deletion(-)
diff --git a/proxy/lib/webrtcconn.go b/proxy/lib/webrtcconn.go
index 0a851df..c243449 100644
--- a/proxy/lib/webrtcconn.go
+++ b/proxy/lib/webrtcconn.go
@@ -32,20 +32,41 @@ type webRTCConn struct {
bytesLogger bytesLogger
eventLogger event.SnowflakeEventReceiver
+
+ inactivityTimeout time.Duration
+ activity 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.bytesLogger = newBytesSyncLogger()
+ conn.activity = make(chan struct{}, 100)
+ conn.inactivityTimeout = 30 * time.Second
+ go conn.timeoutLoop()
return conn
}
+func (c *webRTCConn) timeoutLoop() {
+ for {
+ select {
+ case <-time.After(c.inactivityTimeout):
+ c.Close()
+ log.Println("Closed connection due to inactivity")
+ return
+ case <-c.activity:
+ continue
+ }
+ }
+
+}
+
func (c *webRTCConn) Read(b []byte) (int, error) {
return c.pr.Read(b)
}
func (c *webRTCConn) Write(b []byte) (int, error) {
c.bytesLogger.AddInbound(int64(len(b)))
+ c.activity <- struct{}{}
c.lock.Lock()
defer c.lock.Unlock()
if c.dc != nil {
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits