mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 20:11:19 -04:00
Remove copy/paste signalling
This commit is contained in:
parent
79c84509fc
commit
622005c79e
13 changed files with 18 additions and 283 deletions
|
@ -12,12 +12,9 @@ ClientTransportPlugin snowflake exec ./client \
|
|||
-ice stun:stun.l.google.com:19302
|
||||
```
|
||||
|
||||
`-url` should be the URL of a Broker instance. This is required to have
|
||||
automated signalling (which is desired in most use cases).
|
||||
When omitted, the client uses copy-paste signalling instead.
|
||||
`-url` should be the URL of a Broker instance.
|
||||
|
||||
`-front` is an optional front domain for the Broker request.
|
||||
|
||||
`-ice` is a comma-separated list of ICE servers. These can be STUN or TURN
|
||||
servers.
|
||||
|
||||
|
|
|
@ -1,26 +1,20 @@
|
|||
// WebRTC rendezvous requires the exchange of SessionDescriptions between
|
||||
// peers in order to establish a PeerConnection.
|
||||
//
|
||||
// This file contains the two methods currently available to Snowflake:
|
||||
// This file contains the one method currently available to Snowflake:
|
||||
//
|
||||
// - Domain-fronted HTTP signaling. The Broker automatically exchange offers
|
||||
// and answers between this client and some remote WebRTC proxy.
|
||||
// (This is the recommended default, enabled via the flags in "torrc".)
|
||||
//
|
||||
// - Manual copy-paste signaling. User must create a signaling pipe.
|
||||
// (The flags in torrc-manual allow this)
|
||||
|
||||
package lib
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"syscall"
|
||||
|
||||
"github.com/keroserene/go-webrtc"
|
||||
)
|
||||
|
@ -143,71 +137,3 @@ func (w WebRTCDialer) Catch() (Snowflake, error) {
|
|||
err := connection.Connect()
|
||||
return connection, err
|
||||
}
|
||||
|
||||
// CopyPasteDialer handles the interaction required to copy-paste the
|
||||
// offers and answers.
|
||||
// Implements |Tongue| interface to catch snowflakes manually.
|
||||
// Supports recovery of connections.
|
||||
type CopyPasteDialer struct {
|
||||
webrtcConfig *webrtc.Configuration
|
||||
signal *os.File
|
||||
current *WebRTCPeer
|
||||
}
|
||||
|
||||
func NewCopyPasteDialer(iceServers IceServerList) *CopyPasteDialer {
|
||||
log.Println("No HTTP signaling detected. Using manual copy-paste signaling.")
|
||||
log.Println("Waiting for a \"signal\" pipe...")
|
||||
// This FIFO receives signaling messages.
|
||||
err := syscall.Mkfifo("signal", 0600)
|
||||
if err != nil {
|
||||
if syscall.EEXIST != err.(syscall.Errno) {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
signalFile, err := os.OpenFile("signal", os.O_RDONLY, 0600)
|
||||
if nil != err {
|
||||
log.Fatal(err)
|
||||
return nil
|
||||
}
|
||||
config := webrtc.NewConfiguration(iceServers...)
|
||||
dialer := &CopyPasteDialer{
|
||||
webrtcConfig: config,
|
||||
signal: signalFile,
|
||||
}
|
||||
go dialer.readSignals()
|
||||
return dialer
|
||||
}
|
||||
|
||||
// Initialize a WebRTC Peer via manual copy-paste.
|
||||
func (d *CopyPasteDialer) Catch() (Snowflake, error) {
|
||||
if nil == d.signal {
|
||||
return nil, errors.New("Cannot copy-paste dial without signal pipe.")
|
||||
}
|
||||
connection := NewWebRTCPeer(d.webrtcConfig, nil)
|
||||
// Must keep track of pending new connection until copy-paste completes.
|
||||
d.current = connection
|
||||
// Outputs SDP offer to log, expecting user to copy-paste to the remote Peer.
|
||||
// Blocks until user pastes back the answer.
|
||||
err := connection.Connect()
|
||||
d.current = nil
|
||||
return connection, err
|
||||
}
|
||||
|
||||
// Manual copy-paste signalling.
|
||||
func (d *CopyPasteDialer) readSignals() {
|
||||
defer d.signal.Close()
|
||||
log.Printf("CopyPasteDialer: reading messages from signal pipe.")
|
||||
s := bufio.NewScanner(d.signal)
|
||||
for s.Scan() {
|
||||
msg := s.Text()
|
||||
sdp := webrtc.DeserializeSessionDescription(msg)
|
||||
if sdp == nil {
|
||||
log.Printf("CopyPasteDialer: ignoring invalid signal message %+q", msg)
|
||||
continue
|
||||
}
|
||||
d.current.answerChannel <- sdp
|
||||
}
|
||||
if err := s.Err(); err != nil {
|
||||
log.Printf("signal FIFO: %s", err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -284,14 +284,7 @@ func (c *WebRTCPeer) sendOfferToBroker() {
|
|||
// the Broker or signal pipe, then await for the SDP answer.
|
||||
func (c *WebRTCPeer) exchangeSDP() error {
|
||||
select {
|
||||
case offer := <-c.offerChannel:
|
||||
// Display for copy-paste when no broker available.
|
||||
if nil == c.broker {
|
||||
log.Printf("Please Copy & Paste the following to the peer:")
|
||||
log.Printf("----------------")
|
||||
log.Printf("\n\n" + offer.Serialize() + "\n\n")
|
||||
log.Printf("----------------")
|
||||
}
|
||||
case <-c.offerChannel:
|
||||
case err := <-c.errorChannel:
|
||||
log.Println("Failed to prepare offer", err)
|
||||
c.Close()
|
||||
|
|
|
@ -113,14 +113,11 @@ func main() {
|
|||
|
||||
// Prepare to collect remote WebRTC peers.
|
||||
snowflakes := sf.NewPeers(*max)
|
||||
if "" != *brokerURL {
|
||||
// Use potentially domain-fronting broker to rendezvous.
|
||||
broker := sf.NewBrokerChannel(*brokerURL, *frontDomain, sf.CreateBrokerTransport())
|
||||
snowflakes.Tongue = sf.NewWebRTCDialer(broker, iceServers)
|
||||
} else {
|
||||
// Otherwise, use manual copy and pasting of SDP messages.
|
||||
snowflakes.Tongue = sf.NewCopyPasteDialer(iceServers)
|
||||
}
|
||||
|
||||
// Use potentially domain-fronting broker to rendezvous.
|
||||
broker := sf.NewBrokerChannel(*brokerURL, *frontDomain, sf.CreateBrokerTransport())
|
||||
snowflakes.Tongue = sf.NewWebRTCDialer(broker, iceServers)
|
||||
|
||||
if nil == snowflakes.Tongue {
|
||||
log.Fatal("Unable to prepare rendezvous method.")
|
||||
return
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
UseBridges 1
|
||||
DataDirectory datadir
|
||||
|
||||
ClientTransportPlugin snowflake exec ./client \
|
||||
-log snowflake.log
|
||||
|
||||
Bridge snowflake 0.0.3.0:1
|
Loading…
Add table
Add a link
Reference in a new issue