[tor-commits] [snowflake/master] expose multiplex capacity as flag, un-global some more

serene at torproject.org serene at torproject.org
Sun Jun 12 19:44:05 UTC 2016


commit b6f15a8d5c206829a694ab79c7bbdd1ed4c68a96
Author: Serene Han <keroserene+git at gmail.com>
Date:   Sun Jun 12 00:20:54 2016 -0700

    expose multiplex capacity as flag, un-global some more
---
 client/peers.go      |  2 +-
 client/rendezvous.go |  2 ++
 client/snowflake.go  | 28 +++++++++++++---------------
 client/torrc         |  3 ++-
 client/webrtc.go     |  6 ++----
 5 files changed, 20 insertions(+), 21 deletions(-)

diff --git a/client/peers.go b/client/peers.go
index 57570bf..8aeb838 100644
--- a/client/peers.go
+++ b/client/peers.go
@@ -30,7 +30,7 @@ type Peers struct {
 // Construct a fresh container of remote peers.
 func NewPeers(max int) *Peers {
 	p := &Peers{capacity: max}
-	// Use buffered go channel to pass new snowflakes onwards to the SOCKS handler.
+	// Use buffered go channel to pass snowflakes onwards to the SOCKS handler.
 	p.snowflakeChan = make(chan *webRTCConn, max)
 	p.activePeers = list.New()
 	return p
diff --git a/client/rendezvous.go b/client/rendezvous.go
index 85549d3..fbb75dd 100644
--- a/client/rendezvous.go
+++ b/client/rendezvous.go
@@ -63,6 +63,8 @@ func NewBrokerChannel(broker string, front string, transport http.RoundTripper)
 // with an SDP answer from a designated remote WebRTC peer.
 func (bc *BrokerChannel) Negotiate(offer *webrtc.SessionDescription) (
 	*webrtc.SessionDescription, error) {
+	log.Println("Negotiating via BrokerChannel...\nTarget URL: ",
+		bc.Host, "\nFront URL:  ", bc.url.Host)
 	data := bytes.NewReader([]byte(offer.Serialize()))
 	// Suffix with broker's client registration handler.
 	request, err := http.NewRequest("POST", bc.url.String()+"client", data)
diff --git a/client/snowflake.go b/client/snowflake.go
index aa0e470..1c17642 100644
--- a/client/snowflake.go
+++ b/client/snowflake.go
@@ -21,12 +21,10 @@ import (
 var ptInfo pt.ClientInfo
 
 const (
-	ReconnectTimeout  = 10
-	SnowflakeCapacity = 1
+	ReconnectTimeout         = 10
+	DefaultSnowflakeCapacity = 1
 )
 
-var brokerURL string
-var frontDomain string
 var iceServers IceServerList
 
 // When a connection handler starts, +1 is written to this channel; when it
@@ -148,16 +146,18 @@ func main() {
 	log.SetOutput(logFile)
 	log.Println("\nStarting Snowflake Client...")
 
-	flag.StringVar(&brokerURL, "url", "", "URL of signaling broker")
-	flag.StringVar(&frontDomain, "front", "", "front domain")
+	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)
+	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...")
@@ -176,11 +176,9 @@ func main() {
 		go readSignalingMessages(signalFile)
 	}
 
-	// Prepare WebRTC SnowflakeCollector and the Broker, then accumulate connections.
-	// TODO: Expose remote peer capacity as a flag?
-	snowflakes := NewPeers(SnowflakeCapacity)
-
-	broker := NewBrokerChannel(brokerURL, frontDomain, CreateBrokerTransport())
+	// Prepare WebRTC SnowflakeCollector, Broker, then accumulate connections.
+	snowflakes := NewPeers(*max)
+	broker := NewBrokerChannel(*brokerURL, *frontDomain, CreateBrokerTransport())
 	snowflakes.Tongue = NewWebRTCDialer(broker)
 
 	// Use a real logger for traffic.
diff --git a/client/torrc b/client/torrc
index c4af61f..d066454 100644
--- a/client/torrc
+++ b/client/torrc
@@ -4,6 +4,7 @@ DataDirectory datadir
 ClientTransportPlugin snowflake exec ./client \
 -url https://snowflake-reg.appspot.com/ \
 -front www.google.com \
--ice stun:stun.l.google.com:19302
+-ice stun:stun.l.google.com:19302 \
+-max 1
 
 Bridge snowflake 0.0.3.0:1
diff --git a/client/webrtc.go b/client/webrtc.go
index 87a1d19..c978f12 100644
--- a/client/webrtc.go
+++ b/client/webrtc.go
@@ -264,12 +264,10 @@ func (c *webRTCConn) establishDataChannel() error {
 }
 
 func (c *webRTCConn) sendOfferToBroker() {
-	if "" == brokerURL {
+	if nil == c.broker {
 		return
 	}
 	offer := c.pc.LocalDescription()
-	log.Println("Sending offer via BrokerChannel...\nTarget URL: ", brokerURL,
-		"\nFront URL:  ", frontDomain)
 	answer, err := c.broker.Negotiate(offer)
 	if nil != err || nil == answer {
 		log.Printf("BrokerChannel Error: %s", err)
@@ -284,7 +282,7 @@ func (c *webRTCConn) exchangeSDP() error {
 	select {
 	case offer := <-c.offerChannel:
 		// Display for copy-paste, when no broker available.
-		if "" == brokerURL {
+		if nil == c.broker {
 			log.Printf("Please Copy & Paste the following to the peer:")
 			log.Printf("----------------")
 			log.Printf("\n" + offer.Serialize() + "\n")





More information about the tor-commits mailing list