mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 20:11:19 -04:00
Close SocksConn when WebRTC connection is reset
* This will induce the tor client to establish a new SocksConn, which in turn will dial a new WebRTC connection. To be improved upon. * Part of #12
This commit is contained in:
parent
cf1b0a49f1
commit
598e2a3bfb
2 changed files with 23 additions and 20 deletions
|
@ -99,6 +99,12 @@ func handler(conn *pt.SocksConn) error {
|
||||||
defer remote.Close()
|
defer remote.Close()
|
||||||
webrtcRemote = remote
|
webrtcRemote = remote
|
||||||
|
|
||||||
|
// Induce another call to handler
|
||||||
|
go func() {
|
||||||
|
<-remote.reset
|
||||||
|
conn.Close()
|
||||||
|
}()
|
||||||
|
|
||||||
err = conn.Grant(&net.TCPAddr{IP: net.IPv4zero, Port: 0})
|
err = conn.Grant(&net.TCPAddr{IP: net.IPv4zero, Port: 0})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -101,27 +101,24 @@ func NewWebRTCConnection(config *webrtc.Configuration,
|
||||||
|
|
||||||
// WebRTC re-establishment loop. Expected in own goroutine.
|
// WebRTC re-establishment loop. Expected in own goroutine.
|
||||||
func (c *webRTCConn) ConnectLoop() {
|
func (c *webRTCConn) ConnectLoop() {
|
||||||
for {
|
log.Println("Establishing WebRTC connection...")
|
||||||
log.Println("Establishing WebRTC connection...")
|
// TODO: When go-webrtc is more stable, it's possible that a new
|
||||||
// TODO: When go-webrtc is more stable, it's possible that a new
|
// PeerConnection won't need to be re-prepared each time.
|
||||||
// PeerConnection won't need to be re-prepared each time.
|
err := c.preparePeerConnection()
|
||||||
err := c.preparePeerConnection()
|
if err != nil {
|
||||||
if err != nil {
|
log.Println("WebRTC: Could not create PeerConnection.")
|
||||||
log.Println("WebRTC: Could not create PeerConnection.")
|
return
|
||||||
break
|
|
||||||
}
|
|
||||||
err = c.establishDataChannel()
|
|
||||||
if err != nil {
|
|
||||||
log.Println("WebRTC: Could not establish DataChannel.")
|
|
||||||
} else {
|
|
||||||
go c.exchangeSDP()
|
|
||||||
<-c.reset
|
|
||||||
log.Println(" --- snowflake connection reset ---")
|
|
||||||
}
|
|
||||||
<-time.After(time.Second * 1)
|
|
||||||
c.cleanup()
|
|
||||||
}
|
}
|
||||||
log.Println("WebRTC cannot connect.")
|
err = c.establishDataChannel()
|
||||||
|
if err != nil {
|
||||||
|
log.Println("WebRTC: Could not establish DataChannel.")
|
||||||
|
} else {
|
||||||
|
go c.exchangeSDP()
|
||||||
|
<-c.reset
|
||||||
|
log.Println(" --- snowflake connection reset ---")
|
||||||
|
}
|
||||||
|
<-time.After(time.Second * 1)
|
||||||
|
c.cleanup()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create and prepare callbacks on a new WebRTC PeerConnection.
|
// Create and prepare callbacks on a new WebRTC PeerConnection.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue