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"
|
"os/signal"
|
||||||
"sync"
|
"sync"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
"time"
|
||||||
|
|
||||||
"git.torproject.org/pluggable-transports/goptlib.git"
|
"git.torproject.org/pluggable-transports/goptlib.git"
|
||||||
"github.com/keroserene/go-webrtc"
|
"github.com/keroserene/go-webrtc"
|
||||||
|
@ -19,10 +20,10 @@ import (
|
||||||
|
|
||||||
var ptInfo pt.ClientInfo
|
var ptInfo pt.ClientInfo
|
||||||
|
|
||||||
// var logFile *os.File
|
|
||||||
var brokerURL string
|
var brokerURL string
|
||||||
var frontDomain string
|
var frontDomain string
|
||||||
var iceServers IceServerList
|
var iceServers IceServerList
|
||||||
|
var snowflakes []*webRTCConn
|
||||||
|
|
||||||
// When a connection handler starts, +1 is written to this channel; when it
|
// When a connection handler starts, +1 is written to this channel; when it
|
||||||
// ends, -1 is written.
|
// ends, -1 is written.
|
||||||
|
@ -30,6 +31,7 @@ var handlerChan = make(chan int)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ReconnectTimeout = 5
|
ReconnectTimeout = 5
|
||||||
|
SnowflakeCapacity = 1
|
||||||
)
|
)
|
||||||
|
|
||||||
func copyLoop(a, b net.Conn) {
|
func copyLoop(a, b net.Conn) {
|
||||||
|
@ -53,6 +55,20 @@ type SnowflakeChannel interface {
|
||||||
Close() error
|
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.
|
// Initialize a WebRTC Connection.
|
||||||
func dialWebRTC() (*webRTCConn, error) {
|
func dialWebRTC() (*webRTCConn, error) {
|
||||||
// TODO: [#3] Fetch ICE server information from Broker.
|
// TODO: [#3] Fetch ICE server information from Broker.
|
||||||
|
@ -82,8 +98,6 @@ func handler(conn *pt.SocksConn) error {
|
||||||
defer func() {
|
defer func() {
|
||||||
handlerChan <- -1
|
handlerChan <- -1
|
||||||
}()
|
}()
|
||||||
defer conn.Close()
|
|
||||||
log.Println("handler fired:", conn)
|
|
||||||
|
|
||||||
remote, err := dialWebRTC()
|
remote, err := dialWebRTC()
|
||||||
if err != nil || remote == nil {
|
if err != nil || remote == nil {
|
||||||
|
@ -91,6 +105,7 @@ func handler(conn *pt.SocksConn) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer remote.Close()
|
defer remote.Close()
|
||||||
|
defer conn.Close()
|
||||||
webrtcRemote = remote
|
webrtcRemote = remote
|
||||||
|
|
||||||
err = conn.Grant(&net.TCPAddr{IP: net.IPv4zero, Port: 0})
|
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.
|
// Disable the DataChannel as a write destination.
|
||||||
log.Println("WebRTC: DataChannel.OnClose [remotely]")
|
log.Println("WebRTC: DataChannel.OnClose [remotely]")
|
||||||
c.snowflake = nil
|
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()
|
c.Reset()
|
||||||
}
|
}
|
||||||
dc.OnMessage = func(msg []byte) {
|
dc.OnMessage = func(msg []byte) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue