[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [snowflake/master] localize ptInfo and iceServers vars, separate copy-paste helpers, move some logging
commit fedb124313a532aa4f105f3d7575245b99e3e92c
Author: Serene Han <keroserene+git@xxxxxxxxx>
Date: Sun Jun 12 11:49:32 2016 -0700
localize ptInfo and iceServers vars, separate copy-paste helpers, move some logging
to more sensible locations
---
client/peers.go | 2 ++
client/rendezvous.go | 2 ++
client/snowflake.go | 68 +++++++++++++++++++++++++---------------------------
client/webrtc.go | 7 +++---
4 files changed, 41 insertions(+), 38 deletions(-)
diff --git a/client/peers.go b/client/peers.go
index 8aeb838..734fdfe 100644
--- a/client/peers.go
+++ b/client/peers.go
@@ -38,6 +38,7 @@ func NewPeers(max int) *Peers {
// As part of |SnowflakeCollector| interface.
func (p *Peers) Collect() error {
+
cnt := p.Count()
if cnt >= p.capacity {
s := fmt.Sprintf("At capacity [%d/%d]", cnt, p.capacity)
@@ -59,6 +60,7 @@ func (p *Peers) Collect() error {
// As part of |SnowflakeCollector| interface.
func (p *Peers) Pop() *webRTCConn {
+
// Blocks until an available snowflake appears.
snowflake, ok := <-p.snowflakeChan
if !ok {
diff --git a/client/rendezvous.go b/client/rendezvous.go
index fbb75dd..3b25c89 100644
--- a/client/rendezvous.go
+++ b/client/rendezvous.go
@@ -46,9 +46,11 @@ func NewBrokerChannel(broker string, front string, transport http.RoundTripper)
if nil != err {
return nil
}
+ log.Println("Rendezvous using Broker at:", broker)
bc := new(BrokerChannel)
bc.url = targetURL
if "" != front { // Optional front domain.
+ log.Println("Domain fronting using:", front)
bc.Host = bc.url.Host
bc.url.Host = front
}
diff --git a/client/snowflake.go b/client/snowflake.go
index 1c17642..948b862 100644
--- a/client/snowflake.go
+++ b/client/snowflake.go
@@ -18,15 +18,11 @@ import (
"github.com/keroserene/go-webrtc"
)
-var ptInfo pt.ClientInfo
-
const (
ReconnectTimeout = 10
DefaultSnowflakeCapacity = 1
)
-var iceServers IceServerList
-
// When a connection handler starts, +1 is written to this channel; when it
// ends, -1 is written.
var handlerChan = make(chan int)
@@ -52,20 +48,20 @@ func ConnectLoop(snowflakes SnowflakeCollector) {
for {
err := snowflakes.Collect()
if nil != err {
- log.Println("WebRTC Error:", err,
+ log.Println("WebRTC:", err,
" Retrying in", ReconnectTimeout, "seconds...")
// Failed collections get a timeout.
<-time.After(time.Second * ReconnectTimeout)
continue
}
// Successful collection gets rate limited to once per second.
- log.Println("ConnectLoop success.")
+ log.Println("WebRTC: Connected to new Snowflake.")
<-time.After(time.Second)
}
}
// Accept local SOCKS connections and pass them to the handler.
-func acceptLoop(ln *pt.SocksListener, snowflakes SnowflakeCollector) error {
+func socksAcceptLoop(ln *pt.SocksListener, snowflakes SnowflakeCollector) error {
defer ln.Close()
log.Println("Started SOCKS listener.")
for {
@@ -98,7 +94,7 @@ func handler(socks SocksConnector, snowflakes SnowflakeCollector) error {
return errors.New("handler: Received invalid Snowflake")
}
defer socks.Close()
- log.Println("handler: Snowflake assigned.")
+ log.Println("---- Snowflake assigned ----")
err := socks.Grant(&net.TCPAddr{IP: net.IPv4zero, Port: 0})
if err != nil {
return err
@@ -114,7 +110,25 @@ func handler(socks SocksConnector, snowflakes SnowflakeCollector) error {
return nil
}
-// TODO: Fix since multiplexing changes access to remotes.
+func setupCopyPaste() {
+ log.Println("No HTTP signaling detected. Waiting for a \"signal\" pipe...")
+ // This FIFO receives signaling messages.
+ err := syscall.Mkfifo("signal", 0600)
+ if err != nil {
+ if syscall.EEXIST != err.(syscall.Errno) {
+ log.Fatal(err)
+ }
+ }
+ signalFile, err := os.OpenFile("signal", os.O_RDONLY, 0600)
+ if nil != err {
+ log.Fatal(err)
+ }
+ defer signalFile.Close()
+ go readSignalingMessages(signalFile)
+}
+
+// Manual copy-paste signalling.
+// TODO: Needs fix since multiplexing changes access to the remotes.
func readSignalingMessages(f *os.File) {
log.Printf("readSignalingMessages")
s := bufio.NewScanner(f)
@@ -144,42 +158,26 @@ func main() {
}
defer logFile.Close()
log.SetOutput(logFile)
- log.Println("\nStarting Snowflake Client...")
+ var iceServers IceServerList
+ log.Println("\n\n\n --- Starting Snowflake Client ---")
+
+ flag.Var(&iceServers, "ice", "comma-separated list of ICE servers")
brokerURL := flag.String("url", "", "URL of signaling broker")
frontDomain := flag.String("front", "", "front domain")
- flag.Var(&iceServers, "ice", "comma-separated list of ICE servers")
max := flag.Int("max", DefaultSnowflakeCapacity,
"capacity for number of multiplexed WebRTC peers")
flag.Parse()
// TODO: Maybe just get rid of copy-paste option entirely.
- if "" != *brokerURL {
- log.Println("Rendezvous using Broker at: ", *brokerURL)
- if "" != *frontDomain {
- log.Println("Domain fronting using:", *frontDomain)
- }
- } else {
- log.Println("No HTTP signaling detected. Waiting for a \"signal\" pipe...")
- // This FIFO receives signaling messages.
- err := syscall.Mkfifo("signal", 0600)
- if err != nil {
- if err.(syscall.Errno) != syscall.EEXIST {
- log.Fatal(err)
- }
- }
- signalFile, err := os.OpenFile("signal", os.O_RDONLY, 0600)
- if err != nil {
- log.Fatal(err)
- }
- defer signalFile.Close()
- go readSignalingMessages(signalFile)
+ if "" == *brokerURL {
+ setupCopyPaste()
}
// Prepare WebRTC SnowflakeCollector, Broker, then accumulate connections.
snowflakes := NewPeers(*max)
broker := NewBrokerChannel(*brokerURL, *frontDomain, CreateBrokerTransport())
- snowflakes.Tongue = NewWebRTCDialer(broker)
+ snowflakes.Tongue = NewWebRTCDialer(broker, iceServers)
// Use a real logger for traffic.
snowflakes.BytesLogger = &BytesSyncLogger{
@@ -190,11 +188,11 @@ func main() {
go ConnectLoop(snowflakes)
go snowflakes.BytesLogger.Log()
- ptInfo, err = pt.ClientSetup(nil)
+ // Begin goptlib client process.
+ ptInfo, err := pt.ClientSetup(nil)
if err != nil {
log.Fatal(err)
}
-
if ptInfo.ProxyURL != nil {
pt.ProxyError("proxy is not supported")
os.Exit(1)
@@ -210,7 +208,7 @@ func main() {
pt.CmethodError(methodName, err.Error())
break
}
- go acceptLoop(ln, snowflakes)
+ go socksAcceptLoop(ln, snowflakes)
pt.Cmethod(methodName, ln.Version(), ln.Addr())
listeners = append(listeners, ln)
default:
diff --git a/client/webrtc.go b/client/webrtc.go
index c978f12..7647cf6 100644
--- a/client/webrtc.go
+++ b/client/webrtc.go
@@ -17,7 +17,9 @@ type WebRTCDialer struct {
webrtcConfig *webrtc.Configuration
}
-func NewWebRTCDialer(broker *BrokerChannel) *WebRTCDialer {
+func NewWebRTCDialer(
+ broker *BrokerChannel, iceServers IceServerList) *WebRTCDialer {
+
config := webrtc.NewConfiguration(iceServers...)
return &WebRTCDialer{
BrokerChannel: broker,
@@ -32,8 +34,7 @@ func (w WebRTCDialer) Catch() (*webRTCConn, error) {
}
// TODO: [#3] Fetch ICE server information from Broker.
// TODO: [#18] Consider TURN servers here too.
- config := webrtc.NewConfiguration(iceServers...)
- connection := NewWebRTCConnection(config, w.BrokerChannel)
+ connection := NewWebRTCConnection(w.webrtcConfig, w.BrokerChannel)
err := connection.Connect()
return connection, err
}
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits