[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [snowflake/master] Remove the abandoned server-webrtc test code
commit 6054c09949dfeb807a898e369c546344e26373dd
Author: Cecylia Bocovich <cohosh@xxxxxxxxxxxxxx>
Date: Tue Mar 17 12:36:12 2020 -0400
Remove the abandoned server-webrtc test code
This existed solely for testing purposes and is no longer being
maintained.
---
README.md | 7 +-
server-webrtc/README.md | 26 -----
server-webrtc/http.go | 74 -------------
server-webrtc/snowflake.go | 255 ---------------------------------------------
server-webrtc/torrc | 8 --
5 files changed, 1 insertion(+), 369 deletions(-)
diff --git a/README.md b/README.md
index fdb039c..05fb5f7 100644
--- a/README.md
+++ b/README.md
@@ -15,7 +15,7 @@ Pluggable Transport using WebRTC, inspired by Flashproxy.
- [Test Environment](#test-environment)
- [FAQ](#faq)
- [Appendix](#appendix)
- - [-- Testing directly via WebRTC Server --](#---testing-directly-via-webrtc-server---)
+ - [-- Testing with Standalone Proxy --](#---testing-with-standalone-proxy---)
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
@@ -142,11 +142,6 @@ go build
./proxy-go
```
-##### -- Testing directly via WebRTC Server --
-
-See server-webrtc/README.md for information on connecting directly to a
-WebRTC server transport plugin, bypassing the Broker and browser proxy.
-
More documentation on the way.
Also available at:
diff --git a/server-webrtc/README.md b/server-webrtc/README.md
deleted file mode 100644
index 53cad14..0000000
--- a/server-webrtc/README.md
+++ /dev/null
@@ -1,26 +0,0 @@
-Ordinarily, the WebRTC client plugin speaks with a Broker which helps
-match and signal with a browser proxy, which ultimately speaks with a default
-websocket server.
-
-
-However, this directory contains a WebRTC server plugin which uses an
-HTTP server that simulates the interaction that a client would have with
-the broker, for direct testing.
-
-Edit server-webrtc/torrc and add "-http 127.0.0.1:8080" to the end of the
-ServerTransportPlugin line:
-```
-ServerTransportPlugin snowflake exec ./server-webrtc -http 127.0.0.1:8080
-```
-
-```
-cd server-webrtc/
-go build
-tor -f torrc
-```
-
-Edit client/torrc and add "-url http://127.0.0.1:8080" to the end of the
-ClientTransportPlugin line:
-```
-ClientTransportPlugin snowflake exec ./client -url http://127.0.0.1:8080/
-```
diff --git a/server-webrtc/http.go b/server-webrtc/http.go
deleted file mode 100644
index 1232239..0000000
--- a/server-webrtc/http.go
+++ /dev/null
@@ -1,74 +0,0 @@
-// An HTTP-based signaling channel for the WebRTC server. It imitates the
-// broker as seen by clients, but it doesn't connect them to an
-// intermediate WebRTC proxy, rather connects them directly to this WebRTC
-// server. This code should be deleted when we have proxies in place.
-
-package main
-
-import (
- "fmt"
- "io/ioutil"
- "log"
- "net/http"
-
- "github.com/keroserene/go-webrtc"
-)
-
-type httpHandler struct {
- config *webrtc.Configuration
-}
-
-func (h *httpHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
- switch req.Method {
- case "GET":
- w.Header().Set("Content-Type", "text/plain; charset=utf-8")
- w.WriteHeader(http.StatusOK)
- _, err := w.Write([]byte(`HTTP signaling channel
-
-Send a POST request containing an SDP offer. The response will
-contain an SDP answer.
-`))
- if err != nil {
- log.Printf("GET request write failed with error: %v", err)
- }
- return
- case "POST":
- break
- default:
- http.Error(w, "Bad request.", http.StatusBadRequest)
- return
- }
-
- // POST handling begins here.
- body, err := ioutil.ReadAll(http.MaxBytesReader(w, req.Body, 100000))
- if err != nil {
- http.Error(w, "Bad request.", http.StatusBadRequest)
- return
- }
- offer := webrtc.DeserializeSessionDescription(string(body))
- if offer == nil {
- http.Error(w, "Bad request.", http.StatusBadRequest)
- return
- }
-
- pc, err := makePeerConnectionFromOffer(offer, h.config)
- if err != nil {
- http.Error(w, fmt.Sprintf("Cannot create offer: %s", err), http.StatusInternalServerError)
- return
- }
-
- log.Println("answering HTTP POST")
-
- w.WriteHeader(http.StatusOK)
- _, err = w.Write([]byte(pc.LocalDescription().Serialize()))
- if err != nil {
- log.Printf("answering HTTP POST write failed with error %v", err)
- }
-
-}
-
-func receiveSignalsHTTP(addr string, config *webrtc.Configuration) error {
- http.Handle("/", &httpHandler{config})
- log.Printf("listening HTTP on %s", addr)
- return http.ListenAndServe(addr, nil)
-}
diff --git a/server-webrtc/snowflake.go b/server-webrtc/snowflake.go
deleted file mode 100644
index 9ca82cb..0000000
--- a/server-webrtc/snowflake.go
+++ /dev/null
@@ -1,255 +0,0 @@
-package main
-
-import (
- "flag"
- "fmt"
- "io"
- "io/ioutil"
- "log"
- "net"
- "os"
- "os/signal"
- "sync"
- "syscall"
- "time"
-
- pt "git.torproject.org/pluggable-transports/goptlib.git"
- "github.com/keroserene/go-webrtc"
-)
-
-var ptMethodName = "snowflake"
-var ptInfo pt.ServerInfo
-var logFile *os.File
-
-func copyLoop(webRTC, orPort net.Conn) {
- var wg sync.WaitGroup
- wg.Add(2)
- go func() {
- if _, err := io.Copy(orPort, webRTC); err != nil {
- log.Printf("copy WebRTC to ORPort error in copyLoop: %v", err)
- }
- wg.Done()
- }()
- go func() {
- if _, err := io.Copy(webRTC, orPort); err != nil {
- log.Printf("copy ORPort to WebRTC error in copyLoop: %v", err)
- }
- wg.Done()
- }()
- wg.Wait()
-}
-
-type webRTCConn struct {
- dc *webrtc.DataChannel
- pc *webrtc.PeerConnection
- pr *io.PipeReader
-
- lock sync.Mutex // Synchronization for DataChannel destruction
- once sync.Once // Synchronization for PeerConnection destruction
-}
-
-func (c *webRTCConn) Read(b []byte) (int, error) {
- return c.pr.Read(b)
-}
-
-func (c *webRTCConn) Write(b []byte) (int, error) {
- c.lock.Lock()
- defer c.lock.Unlock()
- // log.Printf("webrtc Write %d %+q", len(b), string(b))
- log.Printf("Write %d bytes --> WebRTC", len(b))
- if c.dc != nil {
- c.dc.Send(b)
- }
- return len(b), nil
-}
-
-func (c *webRTCConn) Close() (err error) {
- c.once.Do(func() {
- err = c.pc.Destroy()
- })
- return
-}
-
-func (c *webRTCConn) LocalAddr() net.Addr {
- return nil
-}
-
-func (c *webRTCConn) RemoteAddr() net.Addr {
- return nil
-}
-
-func (c *webRTCConn) SetDeadline(t time.Time) error {
- // nolint:golint
- return fmt.Errorf("SetDeadline not implemented")
-}
-
-func (c *webRTCConn) SetReadDeadline(t time.Time) error {
- // nolint:golint
- return fmt.Errorf("SetReadDeadline not implemented")
-}
-
-func (c *webRTCConn) SetWriteDeadline(t time.Time) error {
- // nolint:golint
- return fmt.Errorf("SetWriteDeadline not implemented")
-}
-
-func datachannelHandler(conn *webRTCConn) {
- defer conn.Close()
-
- or, err := pt.DialOr(&ptInfo, "", ptMethodName) // TODO: Extended OR
- if err != nil {
- log.Printf("Failed to connect to ORPort: " + err.Error())
- return
- }
- defer or.Close()
-
- copyLoop(conn, or)
-}
-
-// Create a PeerConnection from an SDP offer. Blocks until the gathering of ICE
-// candidates is complete and the answer is available in LocalDescription.
-// Installs an OnDataChannel callback that creates a webRTCConn and passes it to
-// datachannelHandler.
-func makePeerConnectionFromOffer(sdp *webrtc.SessionDescription, config *webrtc.Configuration) (*webrtc.PeerConnection, error) {
- pc, err := webrtc.NewPeerConnection(config)
- if err != nil {
- return nil, fmt.Errorf("accept: NewPeerConnection: %s", err)
- }
- pc.OnNegotiationNeeded = func() {
- panic("OnNegotiationNeeded")
- }
- pc.OnDataChannel = func(dc *webrtc.DataChannel) {
- log.Println("OnDataChannel")
-
- pr, pw := io.Pipe()
- conn := &webRTCConn{pc: pc, dc: dc, pr: pr}
-
- dc.OnOpen = func() {
- log.Println("OnOpen channel")
- }
- dc.OnClose = func() {
- conn.lock.Lock()
- defer conn.lock.Unlock()
- log.Println("OnClose channel")
- conn.dc = nil
- pc.DeleteDataChannel(dc)
- pw.Close()
- }
- dc.OnMessage = func(msg []byte) {
- log.Printf("OnMessage <--- %d bytes", len(msg))
- var n int
- n, err = pw.Write(msg)
- if err != nil {
- if inerr := pw.CloseWithError(err); inerr != nil {
- log.Printf("close with error returned error: %v", inerr)
- }
- }
- if n != len(msg) {
- panic("short write")
- }
- }
-
- go datachannelHandler(conn)
- }
-
- err = pc.SetRemoteDescription(sdp)
- if err != nil {
- if err = pc.Destroy(); err != nil {
- log.Printf("pc.Destroy returned an error: %v", err)
- }
- return nil, fmt.Errorf("accept: SetRemoteDescription: %s", err)
- }
- log.Println("sdp offer successfully received.")
-
- log.Println("Generating answer...")
- answer, err := pc.CreateAnswer()
- if err != nil {
- if err = pc.Destroy(); err != nil {
- log.Printf("pc.Destroy returned an error: %v", err)
- }
- return nil, err
- }
-
- if answer == nil {
- if err = pc.Destroy(); err != nil {
- log.Printf("pc.Destroy returned an error: %v", err)
- }
- return nil, fmt.Errorf("failed gathering ICE candidates")
- }
-
- err = pc.SetLocalDescription(answer)
- if err != nil {
- if err = pc.Destroy(); err != nil {
- log.Printf("pc.Destroy returned an error: %v", err)
- }
- return nil, err
- }
-
- return pc, nil
-}
-
-func main() {
- var httpAddr string
- var logFilename string
-
- flag.StringVar(&httpAddr, "http", "", "listen for HTTP signaling")
- flag.StringVar(&logFilename, "log", "", "log file to write to")
- flag.Parse()
-
- log.SetFlags(log.LstdFlags | log.LUTC)
- if logFilename != "" {
- f, err := os.OpenFile(logFilename, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0600)
- if err != nil {
- log.Fatalf("can't open log file: %s", err)
- }
- defer logFile.Close()
- log.SetOutput(f)
- }
-
- log.Println("starting")
- webrtc.SetLoggingVerbosity(1)
- var err error
- ptInfo, err = pt.ServerSetup(nil)
- if err != nil {
- log.Fatal(err)
- }
-
- webRTCConfig := webrtc.NewConfiguration(webrtc.OptionIceServer("stun:stun.l.google.com:19302"))
-
- // Start HTTP-based signaling receiver.
- go func() {
- err := receiveSignalsHTTP(httpAddr, webRTCConfig)
- if err != nil {
- log.Printf("receiveSignalsHTTP: %s", err)
- }
- }()
-
- for _, bindaddr := range ptInfo.Bindaddrs {
- switch bindaddr.MethodName {
- case ptMethodName:
- bindaddr.Addr.Port = 12345 // lies!!!
- pt.Smethod(bindaddr.MethodName, bindaddr.Addr)
- default:
- pt.SmethodError(bindaddr.MethodName, "no such method")
- }
- }
- pt.SmethodsDone()
-
- sigChan := make(chan os.Signal, 1)
- signal.Notify(sigChan, syscall.SIGTERM)
-
- if os.Getenv("TOR_PT_EXIT_ON_STDIN_CLOSE") == "1" {
- // This environment variable means we should treat EOF on stdin
- // just like SIGTERM: https://bugs.torproject.org/15435.
- go func() {
- if _, err := io.Copy(ioutil.Discard, os.Stdin); err != nil {
- log.Printf("error copying os.Stdin to ioutil.Discard: %v", err)
- }
- log.Printf("synthesizing SIGTERM because of stdin close")
- sigChan <- syscall.SIGTERM
- }()
- }
-
- // wait for a signal
- <-sigChan
-}
diff --git a/server-webrtc/torrc b/server-webrtc/torrc
deleted file mode 100644
index e037c97..0000000
--- a/server-webrtc/torrc
+++ /dev/null
@@ -1,8 +0,0 @@
-BridgeRelay 1
-ORPort 9001
-ExtORPort auto
-SocksPort 0
-ExitPolicy reject *:*
-DataDirectory datadir
-
-ServerTransportPlugin snowflake exec ./server-webrtc
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits