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.
This commit is contained in:
David Fifield 2016-01-18 22:53:22 -08:00
parent c9eeff6fc2
commit e0b36d2f33
2 changed files with 38 additions and 9 deletions

View file

@ -82,3 +82,19 @@ func (m *MeekChannel) Negotiate(offer *webrtc.SessionDescription) (
answer := webrtc.DeserializeSessionDescription(string(body)) answer := webrtc.DeserializeSessionDescription(string(body))
return answer, nil 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
}

View file

@ -5,6 +5,7 @@ package main
import ( import (
"bufio" "bufio"
"flag"
"fmt" "fmt"
"io" "io"
"log" "log"
@ -30,6 +31,7 @@ const (
var ptInfo pt.ClientInfo var ptInfo pt.ClientInfo
var logFile *os.File var logFile *os.File
var offerURL string
// 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.
@ -177,16 +179,24 @@ func dialWebRTC(config *webrtc.Configuration, meek *MeekChannel) (
fmt.Fprintln(logFile, "\n"+offer.Serialize()+"\n") fmt.Fprintln(logFile, "\n"+offer.Serialize()+"\n")
log.Printf("----------------") log.Printf("----------------")
go func() { go func() {
log.Printf("Sending offer via meek...") // log.Printf("Sending offer via meek...")
answer, err := meek.Negotiate(pc.LocalDescription()) // answer, err := meek.Negotiate(pc.LocalDescription())
if nil != err { // if nil != err {
log.Printf("Signalling error: %s", err) // log.Printf("Signalling error: %s", err)
} // }
if nil == answer { // if nil == answer {
log.Printf("No answer received from meek channel.") // 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 { } else {
signalChan <- answer signalChan <- answer
} }
}
}() }()
} }
@ -307,6 +317,9 @@ func readSignalingMessages(f *os.File) {
func main() { func main() {
var err error 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) logFile, err = os.OpenFile("snowflake.log", os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0600)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)