mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 20:11:19 -04:00
expose multiplex capacity as flag, un-global some more
This commit is contained in:
parent
2caa47988d
commit
b6f15a8d5c
5 changed files with 20 additions and 21 deletions
|
@ -30,7 +30,7 @@ type Peers struct {
|
||||||
// Construct a fresh container of remote peers.
|
// Construct a fresh container of remote peers.
|
||||||
func NewPeers(max int) *Peers {
|
func NewPeers(max int) *Peers {
|
||||||
p := &Peers{capacity: max}
|
p := &Peers{capacity: max}
|
||||||
// Use buffered go channel to pass new snowflakes onwards to the SOCKS handler.
|
// Use buffered go channel to pass snowflakes onwards to the SOCKS handler.
|
||||||
p.snowflakeChan = make(chan *webRTCConn, max)
|
p.snowflakeChan = make(chan *webRTCConn, max)
|
||||||
p.activePeers = list.New()
|
p.activePeers = list.New()
|
||||||
return p
|
return p
|
||||||
|
|
|
@ -63,6 +63,8 @@ func NewBrokerChannel(broker string, front string, transport http.RoundTripper)
|
||||||
// with an SDP answer from a designated remote WebRTC peer.
|
// with an SDP answer from a designated remote WebRTC peer.
|
||||||
func (bc *BrokerChannel) Negotiate(offer *webrtc.SessionDescription) (
|
func (bc *BrokerChannel) Negotiate(offer *webrtc.SessionDescription) (
|
||||||
*webrtc.SessionDescription, error) {
|
*webrtc.SessionDescription, error) {
|
||||||
|
log.Println("Negotiating via BrokerChannel...\nTarget URL: ",
|
||||||
|
bc.Host, "\nFront URL: ", bc.url.Host)
|
||||||
data := bytes.NewReader([]byte(offer.Serialize()))
|
data := bytes.NewReader([]byte(offer.Serialize()))
|
||||||
// Suffix with broker's client registration handler.
|
// Suffix with broker's client registration handler.
|
||||||
request, err := http.NewRequest("POST", bc.url.String()+"client", data)
|
request, err := http.NewRequest("POST", bc.url.String()+"client", data)
|
||||||
|
|
|
@ -21,12 +21,10 @@ import (
|
||||||
var ptInfo pt.ClientInfo
|
var ptInfo pt.ClientInfo
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ReconnectTimeout = 10
|
ReconnectTimeout = 10
|
||||||
SnowflakeCapacity = 1
|
DefaultSnowflakeCapacity = 1
|
||||||
)
|
)
|
||||||
|
|
||||||
var brokerURL string
|
|
||||||
var frontDomain string
|
|
||||||
var iceServers IceServerList
|
var iceServers IceServerList
|
||||||
|
|
||||||
// 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
|
||||||
|
@ -148,16 +146,18 @@ func main() {
|
||||||
log.SetOutput(logFile)
|
log.SetOutput(logFile)
|
||||||
log.Println("\nStarting Snowflake Client...")
|
log.Println("\nStarting Snowflake Client...")
|
||||||
|
|
||||||
flag.StringVar(&brokerURL, "url", "", "URL of signaling broker")
|
brokerURL := flag.String("url", "", "URL of signaling broker")
|
||||||
flag.StringVar(&frontDomain, "front", "", "front domain")
|
frontDomain := flag.String("front", "", "front domain")
|
||||||
flag.Var(&iceServers, "ice", "comma-separated list of ICE servers")
|
flag.Var(&iceServers, "ice", "comma-separated list of ICE servers")
|
||||||
|
max := flag.Int("max", DefaultSnowflakeCapacity,
|
||||||
|
"capacity for number of multiplexed WebRTC peers")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
// TODO: Maybe just get rid of copy-paste option entirely.
|
// TODO: Maybe just get rid of copy-paste option entirely.
|
||||||
if "" != brokerURL {
|
if "" != *brokerURL {
|
||||||
log.Println("Rendezvous using Broker at: ", brokerURL)
|
log.Println("Rendezvous using Broker at: ", *brokerURL)
|
||||||
if "" != frontDomain {
|
if "" != *frontDomain {
|
||||||
log.Println("Domain fronting using:", frontDomain)
|
log.Println("Domain fronting using:", *frontDomain)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.Println("No HTTP signaling detected. Waiting for a \"signal\" pipe...")
|
log.Println("No HTTP signaling detected. Waiting for a \"signal\" pipe...")
|
||||||
|
@ -176,11 +176,9 @@ func main() {
|
||||||
go readSignalingMessages(signalFile)
|
go readSignalingMessages(signalFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepare WebRTC SnowflakeCollector and the Broker, then accumulate connections.
|
// Prepare WebRTC SnowflakeCollector, Broker, then accumulate connections.
|
||||||
// TODO: Expose remote peer capacity as a flag?
|
snowflakes := NewPeers(*max)
|
||||||
snowflakes := NewPeers(SnowflakeCapacity)
|
broker := NewBrokerChannel(*brokerURL, *frontDomain, CreateBrokerTransport())
|
||||||
|
|
||||||
broker := NewBrokerChannel(brokerURL, frontDomain, CreateBrokerTransport())
|
|
||||||
snowflakes.Tongue = NewWebRTCDialer(broker)
|
snowflakes.Tongue = NewWebRTCDialer(broker)
|
||||||
|
|
||||||
// Use a real logger for traffic.
|
// Use a real logger for traffic.
|
||||||
|
|
|
@ -4,6 +4,7 @@ DataDirectory datadir
|
||||||
ClientTransportPlugin snowflake exec ./client \
|
ClientTransportPlugin snowflake exec ./client \
|
||||||
-url https://snowflake-reg.appspot.com/ \
|
-url https://snowflake-reg.appspot.com/ \
|
||||||
-front www.google.com \
|
-front www.google.com \
|
||||||
-ice stun:stun.l.google.com:19302
|
-ice stun:stun.l.google.com:19302 \
|
||||||
|
-max 1
|
||||||
|
|
||||||
Bridge snowflake 0.0.3.0:1
|
Bridge snowflake 0.0.3.0:1
|
||||||
|
|
|
@ -264,12 +264,10 @@ func (c *webRTCConn) establishDataChannel() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *webRTCConn) sendOfferToBroker() {
|
func (c *webRTCConn) sendOfferToBroker() {
|
||||||
if "" == brokerURL {
|
if nil == c.broker {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
offer := c.pc.LocalDescription()
|
offer := c.pc.LocalDescription()
|
||||||
log.Println("Sending offer via BrokerChannel...\nTarget URL: ", brokerURL,
|
|
||||||
"\nFront URL: ", frontDomain)
|
|
||||||
answer, err := c.broker.Negotiate(offer)
|
answer, err := c.broker.Negotiate(offer)
|
||||||
if nil != err || nil == answer {
|
if nil != err || nil == answer {
|
||||||
log.Printf("BrokerChannel Error: %s", err)
|
log.Printf("BrokerChannel Error: %s", err)
|
||||||
|
@ -284,7 +282,7 @@ func (c *webRTCConn) exchangeSDP() error {
|
||||||
select {
|
select {
|
||||||
case offer := <-c.offerChannel:
|
case offer := <-c.offerChannel:
|
||||||
// Display for copy-paste, when no broker available.
|
// Display for copy-paste, when no broker available.
|
||||||
if "" == brokerURL {
|
if nil == c.broker {
|
||||||
log.Printf("Please Copy & Paste the following to the peer:")
|
log.Printf("Please Copy & Paste the following to the peer:")
|
||||||
log.Printf("----------------")
|
log.Printf("----------------")
|
||||||
log.Printf("\n" + offer.Serialize() + "\n")
|
log.Printf("\n" + offer.Serialize() + "\n")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue