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.
|
||||
func NewPeers(max int) *Peers {
|
||||
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.activePeers = list.New()
|
||||
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.
|
||||
func (bc *BrokerChannel) Negotiate(offer *webrtc.SessionDescription) (
|
||||
*webrtc.SessionDescription, error) {
|
||||
log.Println("Negotiating via BrokerChannel...\nTarget URL: ",
|
||||
bc.Host, "\nFront URL: ", bc.url.Host)
|
||||
data := bytes.NewReader([]byte(offer.Serialize()))
|
||||
// Suffix with broker's client registration handler.
|
||||
request, err := http.NewRequest("POST", bc.url.String()+"client", data)
|
||||
|
|
|
@ -22,11 +22,9 @@ var ptInfo pt.ClientInfo
|
|||
|
||||
const (
|
||||
ReconnectTimeout = 10
|
||||
SnowflakeCapacity = 1
|
||||
DefaultSnowflakeCapacity = 1
|
||||
)
|
||||
|
||||
var brokerURL string
|
||||
var frontDomain string
|
||||
var iceServers IceServerList
|
||||
|
||||
// When a connection handler starts, +1 is written to this channel; when it
|
||||
|
@ -148,16 +146,18 @@ func main() {
|
|||
log.SetOutput(logFile)
|
||||
log.Println("\nStarting Snowflake Client...")
|
||||
|
||||
flag.StringVar(&brokerURL, "url", "", "URL of signaling broker")
|
||||
flag.StringVar(&frontDomain, "front", "", "front domain")
|
||||
brokerURL := flag.String("url", "", "URL of signaling broker")
|
||||
frontDomain := flag.String("front", "", "front domain")
|
||||
flag.Var(&iceServers, "ice", "comma-separated list of ICE servers")
|
||||
max := flag.Int("max", DefaultSnowflakeCapacity,
|
||||
"capacity for number of multiplexed WebRTC peers")
|
||||
flag.Parse()
|
||||
|
||||
// TODO: Maybe just get rid of copy-paste option entirely.
|
||||
if "" != brokerURL {
|
||||
log.Println("Rendezvous using Broker at: ", brokerURL)
|
||||
if "" != frontDomain {
|
||||
log.Println("Domain fronting using:", frontDomain)
|
||||
if "" != *brokerURL {
|
||||
log.Println("Rendezvous using Broker at: ", *brokerURL)
|
||||
if "" != *frontDomain {
|
||||
log.Println("Domain fronting using:", *frontDomain)
|
||||
}
|
||||
} else {
|
||||
log.Println("No HTTP signaling detected. Waiting for a \"signal\" pipe...")
|
||||
|
@ -176,11 +176,9 @@ func main() {
|
|||
go readSignalingMessages(signalFile)
|
||||
}
|
||||
|
||||
// Prepare WebRTC SnowflakeCollector and the Broker, then accumulate connections.
|
||||
// TODO: Expose remote peer capacity as a flag?
|
||||
snowflakes := NewPeers(SnowflakeCapacity)
|
||||
|
||||
broker := NewBrokerChannel(brokerURL, frontDomain, CreateBrokerTransport())
|
||||
// Prepare WebRTC SnowflakeCollector, Broker, then accumulate connections.
|
||||
snowflakes := NewPeers(*max)
|
||||
broker := NewBrokerChannel(*brokerURL, *frontDomain, CreateBrokerTransport())
|
||||
snowflakes.Tongue = NewWebRTCDialer(broker)
|
||||
|
||||
// Use a real logger for traffic.
|
||||
|
|
|
@ -4,6 +4,7 @@ DataDirectory datadir
|
|||
ClientTransportPlugin snowflake exec ./client \
|
||||
-url https://snowflake-reg.appspot.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
|
||||
|
|
|
@ -264,12 +264,10 @@ func (c *webRTCConn) establishDataChannel() error {
|
|||
}
|
||||
|
||||
func (c *webRTCConn) sendOfferToBroker() {
|
||||
if "" == brokerURL {
|
||||
if nil == c.broker {
|
||||
return
|
||||
}
|
||||
offer := c.pc.LocalDescription()
|
||||
log.Println("Sending offer via BrokerChannel...\nTarget URL: ", brokerURL,
|
||||
"\nFront URL: ", frontDomain)
|
||||
answer, err := c.broker.Negotiate(offer)
|
||||
if nil != err || nil == answer {
|
||||
log.Printf("BrokerChannel Error: %s", err)
|
||||
|
@ -284,7 +282,7 @@ func (c *webRTCConn) exchangeSDP() error {
|
|||
select {
|
||||
case offer := <-c.offerChannel:
|
||||
// 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("----------------")
|
||||
log.Printf("\n" + offer.Serialize() + "\n")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue