[tor-commits] [snowflake/master] Do simple HTTP POST signaling in the client.

dcf at torproject.org dcf at torproject.org
Tue Jan 19 07:17:12 UTC 2016


commit e0b36d2f33ba39ec70a3014c0d49c0fc29751f92
Author: David Fifield <david at bamsoftware.com>
Date:   Mon Jan 18 22:53:22 2016 -0800

    Do simple HTTP POST signaling in the client.
    
    This is just enough to be compatible with the HTTP signaling in the
    server, and doesn't do domain fronting or anything like that. It's just
    an interim replacement for the copy-paste FIFO signaling while we
    continue to develop the other pieces that'll be dropped in the middle.
---
 client/meek-webrtc.go |   16 ++++++++++++++++
 client/snowflake.go   |   31 ++++++++++++++++++++++---------
 2 files changed, 38 insertions(+), 9 deletions(-)

diff --git a/client/meek-webrtc.go b/client/meek-webrtc.go
index 6a50bd1..d783781 100644
--- a/client/meek-webrtc.go
+++ b/client/meek-webrtc.go
@@ -82,3 +82,19 @@ func (m *MeekChannel) Negotiate(offer *webrtc.SessionDescription) (
 	answer := webrtc.DeserializeSessionDescription(string(body))
 	return answer, nil
 }
+
+// Simple interim non-fronting HTTP POST negotiation, to be removed when more
+// general fronting is present.
+func sendOfferHTTP(url string, offer *webrtc.SessionDescription) (*webrtc.SessionDescription, error) {
+	resp, err := http.Post(url, "", bytes.NewBuffer([]byte(offer.Serialize())))
+	if err != nil {
+		return nil, err
+	}
+	defer resp.Body.Close()
+	body, err := ioutil.ReadAll(resp.Body)
+	if err != nil {
+		return nil, err
+	}
+	answer := webrtc.DeserializeSessionDescription(string(body))
+	return answer, nil
+}
diff --git a/client/snowflake.go b/client/snowflake.go
index 6bf6fe5..b42b17d 100644
--- a/client/snowflake.go
+++ b/client/snowflake.go
@@ -5,6 +5,7 @@ package main
 
 import (
 	"bufio"
+	"flag"
 	"fmt"
 	"io"
 	"log"
@@ -30,6 +31,7 @@ const (
 
 var ptInfo pt.ClientInfo
 var logFile *os.File
+var offerURL string
 
 // When a connection handler starts, +1 is written to this channel; when it
 // ends, -1 is written.
@@ -177,15 +179,23 @@ func dialWebRTC(config *webrtc.Configuration, meek *MeekChannel) (
 		fmt.Fprintln(logFile, "\n"+offer.Serialize()+"\n")
 		log.Printf("----------------")
 		go func() {
-			log.Printf("Sending offer via meek...")
-			answer, err := meek.Negotiate(pc.LocalDescription())
-			if nil != err {
-				log.Printf("Signalling error: %s", err)
-			}
-			if nil == answer {
-				log.Printf("No answer received from meek channel.")
-			} else {
-				signalChan <- answer
+			// log.Printf("Sending offer via meek...")
+			// answer, err := meek.Negotiate(pc.LocalDescription())
+			// if nil != err {
+			// 	log.Printf("Signalling error: %s", err)
+			// }
+			// if nil == answer {
+			// 	log.Printf("No answer received from meek channel.")
+			// } else {
+			// 	signalChan <- answer
+			// }
+			if offerURL != "" {
+				answer, err := sendOfferHTTP(offerURL, offer)
+				if err != nil {
+					log.Println(err)
+				} else {
+					signalChan <- answer
+				}
 			}
 		}()
 	}
@@ -307,6 +317,9 @@ func readSignalingMessages(f *os.File) {
 func main() {
 	var err error
 
+	flag.StringVar(&offerURL, "url", "", "do signaling through URL")
+	flag.Parse()
+
 	logFile, err = os.OpenFile("snowflake.log", os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0600)
 	if err != nil {
 		log.Fatal(err)



More information about the tor-commits mailing list