mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-14 05:11:19 -04:00
begin multiplex snowflake connect loop for #31
This commit is contained in:
parent
346f316038
commit
451edb6dec
2 changed files with 18 additions and 6 deletions
|
@ -12,6 +12,7 @@ import (
|
|||
"os/signal"
|
||||
"sync"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"git.torproject.org/pluggable-transports/goptlib.git"
|
||||
"github.com/keroserene/go-webrtc"
|
||||
|
@ -19,10 +20,10 @@ import (
|
|||
|
||||
var ptInfo pt.ClientInfo
|
||||
|
||||
// var logFile *os.File
|
||||
var brokerURL string
|
||||
var frontDomain string
|
||||
var iceServers IceServerList
|
||||
var snowflakes []*webRTCConn
|
||||
|
||||
// When a connection handler starts, +1 is written to this channel; when it
|
||||
// ends, -1 is written.
|
||||
|
@ -30,6 +31,7 @@ var handlerChan = make(chan int)
|
|||
|
||||
const (
|
||||
ReconnectTimeout = 5
|
||||
SnowflakeCapacity = 1
|
||||
)
|
||||
|
||||
func copyLoop(a, b net.Conn) {
|
||||
|
@ -53,6 +55,20 @@ type SnowflakeChannel interface {
|
|||
Close() error
|
||||
}
|
||||
|
||||
// Maintain |WebRTCSlots| number of open connections to
|
||||
// transfer to SOCKS when needed. TODO: complete
|
||||
func SnowflakeConnectLoop() {
|
||||
for len(snowflakes) < SnowflakeCapacity {
|
||||
s, err := dialWebRTC()
|
||||
if err != nil {
|
||||
snowflakes = append(snowflakes, s)
|
||||
continue
|
||||
}
|
||||
log.Println("WebRTC Error: ", err)
|
||||
<-time.After(time.Second * ReconnectTimeout)
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize a WebRTC Connection.
|
||||
func dialWebRTC() (*webRTCConn, error) {
|
||||
// TODO: [#3] Fetch ICE server information from Broker.
|
||||
|
@ -82,8 +98,6 @@ func handler(conn *pt.SocksConn) error {
|
|||
defer func() {
|
||||
handlerChan <- -1
|
||||
}()
|
||||
defer conn.Close()
|
||||
log.Println("handler fired:", conn)
|
||||
|
||||
remote, err := dialWebRTC()
|
||||
if err != nil || remote == nil {
|
||||
|
@ -91,6 +105,7 @@ func handler(conn *pt.SocksConn) error {
|
|||
return err
|
||||
}
|
||||
defer remote.Close()
|
||||
defer conn.Close()
|
||||
webrtcRemote = remote
|
||||
|
||||
err = conn.Grant(&net.TCPAddr{IP: net.IPv4zero, Port: 0})
|
||||
|
|
|
@ -207,9 +207,6 @@ func (c *webRTCConn) establishDataChannel() error {
|
|||
// Disable the DataChannel as a write destination.
|
||||
log.Println("WebRTC: DataChannel.OnClose [remotely]")
|
||||
c.snowflake = nil
|
||||
// TODO(issue #12): Need a way to update the circuit so that when a new WebRTC
|
||||
// data channel is available, the relay actually recognizes the new
|
||||
// snowflake.
|
||||
c.Reset()
|
||||
}
|
||||
dc.OnMessage = func(msg []byte) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue