mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 20:11:19 -04:00
prepare for multiplexed snowflake (#11)
This commit is contained in:
parent
6b5a36ac84
commit
5e318b6219
4 changed files with 20 additions and 19 deletions
|
@ -33,7 +33,7 @@ class Broker
|
|||
@url += '/' if '/' != @url.substr -1
|
||||
|
||||
# Promises some client SDP Offer.
|
||||
# Registers this Snowfalke with the broker using an HTTP POST request, and
|
||||
# Registers this Snowflake with the broker using an HTTP POST request, and
|
||||
# waits for a response containing some client offer that the Broker chooses
|
||||
# for this proxy..
|
||||
# TODO: Actually support multiple clients.
|
||||
|
|
|
@ -8,15 +8,17 @@ Represents a single:
|
|||
class ProxyPair
|
||||
|
||||
MAX_BUFFER: 10 * 1024 * 1024
|
||||
pc: null
|
||||
pc: null
|
||||
c2rSchedule: []
|
||||
r2cSchedule: []
|
||||
client: null # WebRTC Data channel
|
||||
relay: null # websocket
|
||||
running: true
|
||||
client: null # WebRTC Data channel
|
||||
relay: null # websocket
|
||||
running: true
|
||||
active: false # Whether serving a client.
|
||||
flush_timeout_id: null
|
||||
|
||||
constructor: (@clientAddr, @relayAddr, @rateLimit) ->
|
||||
@active = false
|
||||
|
||||
# Prepare a WebRTC PeerConnection and await for an SDP offer.
|
||||
begin: ->
|
||||
|
@ -51,6 +53,7 @@ class ProxyPair
|
|||
log 'Invalid SDP message.'
|
||||
return false
|
||||
dbg 'SDP ' + offer.type + ' successfully received.'
|
||||
@active = true
|
||||
true
|
||||
|
||||
prepareDataChannel: (channel) =>
|
||||
|
|
|
@ -51,10 +51,7 @@ CONFIRMATION_MESSAGE = "You're currently serving a Tor user via Snowflake."
|
|||
class Snowflake
|
||||
|
||||
relayAddr: null
|
||||
# TODO: Actually support multiple ProxyPairs. (makes more sense once meek-
|
||||
# signalling is ready)
|
||||
proxyPairs: []
|
||||
proxyPair: null
|
||||
|
||||
rateLimit: null
|
||||
state: MODE.INIT
|
||||
|
@ -86,7 +83,6 @@ class Snowflake
|
|||
@state = MODE.WEBRTC_CONNECTING
|
||||
for i in [1..CONNECTIONS_PER_CLIENT]
|
||||
@makeProxyPair @relayAddr
|
||||
@proxyPair = @proxyPairs[0]
|
||||
return if COPY_PASTE_ENABLED
|
||||
timer = null
|
||||
# Temporary countdown.
|
||||
|
@ -114,17 +110,19 @@ class Snowflake
|
|||
|
||||
findClients()
|
||||
|
||||
# Receive an SDP offer from some client assigned by the Broker.
|
||||
# Receive an SDP offer from some client assigned by the Broker,
|
||||
receiveOffer: (desc) =>
|
||||
sdp = new RTCSessionDescription desc
|
||||
if @proxyPair.receiveWebRTCOffer sdp
|
||||
@sendAnswer() if 'offer' == sdp.type
|
||||
# Use the first proxyPair that's available.
|
||||
pair = @proxyPairs.find (pp, i, arr) -> return !pp.active
|
||||
if pair.receiveWebRTCOffer sdp
|
||||
@sendAnswer pair if 'offer' == sdp.type
|
||||
|
||||
sendAnswer: =>
|
||||
next = (sdp) =>
|
||||
sendAnswer: (pair) ->
|
||||
next = (sdp) ->
|
||||
dbg 'webrtc: Answer ready.'
|
||||
@proxyPair.pc.setLocalDescription sdp
|
||||
promise = @proxyPair.pc.createAnswer next
|
||||
pair.pc.setLocalDescription sdp
|
||||
promise = pair.pc.createAnswer next
|
||||
promise.then next if promise
|
||||
|
||||
makeProxyPair: (relay) ->
|
||||
|
|
|
@ -49,10 +49,10 @@ describe 'Snowflake', ->
|
|||
|
||||
it 'receives SDP offer', ->
|
||||
s = new Snowflake(new FakeBroker(), fakeUI)
|
||||
s.proxyPair = { receiveWebRTCOffer: -> }
|
||||
spyOn(s.proxyPair, 'receiveWebRTCOffer').and.returnValue true
|
||||
s.proxyPairs[0] = { receiveWebRTCOffer: -> }
|
||||
spyOn(s.proxyPairs[0], 'receiveWebRTCOffer').and.returnValue true
|
||||
spyOn(s, 'sendAnswer')
|
||||
s.receiveOffer 'foo'
|
||||
s.receiveOffer { 'type': 'offer', 'sdp': 'foo' }
|
||||
expect(s.sendAnswer).toHaveBeenCalled()
|
||||
|
||||
it 'can make a proxypair', ->
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue