[pluggable-transports/snowflake] branch main updated (90d1a56 -> b547d44)

This is an automated email from the git hooks/post-receive script. cohosh pushed a change to branch main in repository pluggable-transports/snowflake. from 90d1a56 change regexes for ipv6 addresses to catch url-encoded addresses new 6007d5e Refactor creation of webRTCConn in proxy new 5c23fcf Add timeout for webRTCConn new b010de5 Terminate timeoutLoop when conn is closed new b547d44 Refactor timeout loop to use a context and reuse timers The 4 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "add" were already present in the repository and have only been added to this reference. Summary of changes: proxy/lib/snowflake.go | 3 +-- proxy/lib/webrtcconn.go | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) -- To stop receiving notification emails like this one, please contact the administrator of this repository.

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 6007d5e08e981b739e5dab23ce5597fc086ca1c2 Author: Cecylia Bocovich <cohosh@torproject.org> AuthorDate: Tue Oct 18 14:55:50 2022 -0400 Refactor creation of webRTCConn in proxy --- proxy/lib/snowflake.go | 3 +-- proxy/lib/webrtcconn.go | 6 ++++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/proxy/lib/snowflake.go b/proxy/lib/snowflake.go index ac88f0c..352c6e7 100644 --- a/proxy/lib/snowflake.go +++ b/proxy/lib/snowflake.go @@ -384,8 +384,7 @@ func (sf *SnowflakeProxy) makePeerConnectionFromOffer(sdp *webrtc.SessionDescrip close(dataChan) pr, pw := io.Pipe() - conn := &webRTCConn{pc: pc, dc: dc, pr: pr, eventLogger: sf.EventDispatcher} - conn.bytesLogger = newBytesSyncLogger() + conn := newWebRTCConn(pc, dc, pr, sf.EventDispatcher) dc.OnOpen(func() { log.Println("OnOpen channel") diff --git a/proxy/lib/webrtcconn.go b/proxy/lib/webrtcconn.go index 49f98d8..0a851df 100644 --- a/proxy/lib/webrtcconn.go +++ b/proxy/lib/webrtcconn.go @@ -34,6 +34,12 @@ type webRTCConn struct { eventLogger event.SnowflakeEventReceiver } +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() + return conn +} + func (c *webRTCConn) Read(b []byte) (int, error) { return c.pr.Read(b) } -- To stop receiving notification emails like this one, please contact the administrator of this repository.

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@torproject.org> 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.

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 b010de5abb89aba37da73e50eb5c7dbe054c4362 Author: Cecylia Bocovich <cohosh@torproject.org> AuthorDate: Wed Oct 19 10:05:18 2022 -0400 Terminate timeoutLoop when conn is closed --- proxy/lib/webrtcconn.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/proxy/lib/webrtcconn.go b/proxy/lib/webrtcconn.go index c243449..40b26c9 100644 --- a/proxy/lib/webrtcconn.go +++ b/proxy/lib/webrtcconn.go @@ -35,12 +35,14 @@ type webRTCConn struct { inactivityTimeout time.Duration activity chan struct{} + closed chan struct{} } 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.closed = make(chan struct{}) conn.inactivityTimeout = 30 * time.Second go conn.timeoutLoop() return conn @@ -55,9 +57,10 @@ func (c *webRTCConn) timeoutLoop() { return case <-c.activity: continue + case <-c.closed: + return } } - } 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) { c.once.Do(func() { + close(c.closed) err = c.pc.Close() }) return -- To stop receiving notification emails like this one, please contact the administrator of this repository.

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 b547d449cb3f7710ecb70f55a3cbe3a2fe8382d3 Author: Cecylia Bocovich <cohosh@torproject.org> AuthorDate: Mon Nov 28 17:30:05 2022 -0500 Refactor timeout loop to use a context and reuse timers --- proxy/lib/webrtcconn.go | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/proxy/lib/webrtcconn.go b/proxy/lib/webrtcconn.go index 40b26c9..c876fbe 100644 --- a/proxy/lib/webrtcconn.go +++ b/proxy/lib/webrtcconn.go @@ -1,6 +1,7 @@ package snowflake_proxy import ( + "context" "fmt" "io" "log" @@ -35,29 +36,35 @@ type webRTCConn struct { inactivityTimeout time.Duration activity chan struct{} - closed chan struct{} + cancelTimeoutLoop context.CancelFunc } 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.closed = make(chan struct{}) conn.inactivityTimeout = 30 * time.Second - go conn.timeoutLoop() + ctx, cancel := context.WithCancel(context.Background()) + conn.cancelTimeoutLoop = cancel + go conn.timeoutLoop(ctx) return conn } -func (c *webRTCConn) timeoutLoop() { +func (c *webRTCConn) timeoutLoop(ctx context.Context) { + timer := time.NewTimer(c.inactivityTimeout) for { select { - case <-time.After(c.inactivityTimeout): + case <-timer.C: c.Close() log.Println("Closed connection due to inactivity") return case <-c.activity: + if !timer.Stop() { + <-timer.C + } + timer.Reset(c.inactivityTimeout) continue - case <-c.closed: + case <-ctx.Done(): return } } @@ -80,7 +87,7 @@ func (c *webRTCConn) Write(b []byte) (int, error) { func (c *webRTCConn) Close() (err error) { c.once.Do(func() { - close(c.closed) + c.cancelTimeoutLoop() err = c.pc.Close() }) return -- To stop receiving notification emails like this one, please contact the administrator of this repository.
participants (1)
-
gitolite role