mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 20:11:19 -04:00
defer snowflake.Reset to fix handler recovery when localhost SOCKS occassionally fails first
This commit is contained in:
parent
0ae71952d2
commit
ea2e052a7d
5 changed files with 17 additions and 14 deletions
|
@ -58,12 +58,14 @@ func (c *WebRTCPeer) Write(b []byte) (int, error) {
|
|||
|
||||
// As part of |Snowflake|
|
||||
func (c *WebRTCPeer) Close() error {
|
||||
var err error = nil
|
||||
if c.closed { // Skip if already closed.
|
||||
return nil
|
||||
}
|
||||
log.Printf("WebRTC: Closing")
|
||||
c.cleanup()
|
||||
// Mark for deletion.
|
||||
c.closed = true
|
||||
return err
|
||||
return nil
|
||||
}
|
||||
|
||||
// As part of |Resetter|
|
||||
|
@ -79,7 +81,7 @@ func (c *WebRTCPeer) Reset() {
|
|||
func (c *WebRTCPeer) WaitForReset() { <-c.reset }
|
||||
|
||||
// Construct a WebRTC PeerConnection.
|
||||
func NewWebRTCConnection(config *webrtc.Configuration,
|
||||
func NewWebRTCPeer(config *webrtc.Configuration,
|
||||
broker *BrokerChannel) *WebRTCPeer {
|
||||
connection := new(WebRTCPeer)
|
||||
connection.id = "snowflake-" + uniuri.New()
|
||||
|
@ -298,8 +300,8 @@ func (c *WebRTCPeer) cleanup() {
|
|||
if nil != c.transport {
|
||||
log.Printf("WebRTC: closing DataChannel")
|
||||
dataChannel := c.transport
|
||||
// Setting dc to nil *before* Close indicates to OnClose that it
|
||||
// was locally triggered.
|
||||
// Setting transport to nil *before* dc Close indicates to OnClose that
|
||||
// this was locally triggered.
|
||||
c.transport = nil
|
||||
dataChannel.Close()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue