[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [snowflake/master] Make Broker run standalone



commit b7df69fa55629cfc3528d9daaea4e7e1dd7de005
Author: Hooman <hoomanm@xxxxxxxxxxxxx>
Date:   Thu Jun 29 13:51:55 2017 -0700

    Make Broker run standalone
---
 broker/broker.go                | 41 +++++++++++++++++++++++++++++++++++++++--
 broker/metrics.go               |  2 +-
 broker/snowflake-broker_test.go |  2 +-
 broker/snowflake-heap.go        |  2 +-
 4 files changed, 42 insertions(+), 5 deletions(-)

diff --git a/broker/broker.go b/broker/broker.go
index 1673601..8550400 100644
--- a/broker/broker.go
+++ b/broker/broker.go
@@ -3,7 +3,7 @@ Broker acts as the HTTP signaling channel.
 It matches clients and snowflake proxies by passing corresponding
 SessionDescriptions in order to negotiate a WebRTC connection.
 */
-package snowflake_broker
+package main
 
 import (
 	"container/heap"
@@ -13,6 +13,8 @@ import (
 	"net"
 	"net/http"
 	"time"
+	"sync"
+	"os"
 )
 
 const (
@@ -226,7 +228,19 @@ func ipHandler(w http.ResponseWriter, r *http.Request) {
 	w.Write([]byte(remoteAddr))
 }
 
-func init() {
+func main() {
+
+	if len(os.Args) < 3 {
+		log.Println("Usage: broker cert cert_key")
+		os.Exit(1)
+	}
+
+	cert := os.Args[1]
+	log.Println("Using cert file:", cert)
+	cert_key := os.Args[2]
+	log.Println("Using cert key file: ", cert_key)
+
+
 	ctx := NewBrokerContext()
 
 	go ctx.Broker()
@@ -238,4 +252,27 @@ func init() {
 	http.Handle("/client", SnowflakeHandler{ctx, clientOffers})
 	http.Handle("/answer", SnowflakeHandler{ctx, proxyAnswers})
 	http.Handle("/debug", SnowflakeHandler{ctx, debugHandler})
+
+	var wg sync.WaitGroup
+	wg.Add(2)
+
+	//Run HTTP server
+	go func(){
+		defer wg.Done()
+		err := http.ListenAndServe(":80", nil)
+		if err != nil {
+			log.Println("ListenAndServe: ", err)
+		}
+	}()
+
+	//Run HTTPS server
+	go func(){
+		defer wg.Done()
+		err := http.ListenAndServeTLS(":443", cert, cert_key, nil)
+		if err != nil {
+			log.Println("ListenAndServeTLS: ", err)
+		}
+	}()
+
+	wg.Wait()
 }
diff --git a/broker/metrics.go b/broker/metrics.go
index f64d1cc..002fdfe 100644
--- a/broker/metrics.go
+++ b/broker/metrics.go
@@ -1,4 +1,4 @@
-package snowflake_broker
+package main
 
 import (
 	// "golang.org/x/net/internal/timeseries"
diff --git a/broker/snowflake-broker_test.go b/broker/snowflake-broker_test.go
index 44940a3..109d7df 100644
--- a/broker/snowflake-broker_test.go
+++ b/broker/snowflake-broker_test.go
@@ -1,4 +1,4 @@
-package snowflake_broker
+package main
 
 import (
 	"bytes"
diff --git a/broker/snowflake-heap.go b/broker/snowflake-heap.go
index cf249fe..419956f 100644
--- a/broker/snowflake-heap.go
+++ b/broker/snowflake-heap.go
@@ -2,7 +2,7 @@
 Keeping track of pending available snowflake proxies.
 */
 
-package snowflake_broker
+package main
 
 /*
 The Snowflake struct contains a single interaction



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits