mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-14 05:11:19 -04:00
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:
parent
c9eeff6fc2
commit
e0b36d2f33
2 changed files with 38 additions and 9 deletions
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue