commit 3a8df84e3bb8dcc16d411a4c2fb9f4e005f313c8 Author: Nate Hardison nate@rescomp-09-154551.stanford.edu Date: Thu Jun 2 13:47:34 2011 -0700
Changing terminology to use relay/proxy instead of Tor/RTMFP --- rtmfp/ProxyPair.as | 112 ++++++++++++++++++++++++++-------------------------- rtmfpcat.as | 26 ++++++------ 2 files changed, 69 insertions(+), 69 deletions(-)
diff --git a/rtmfp/ProxyPair.as b/rtmfp/ProxyPair.as index fb184cc..159abde 100644 --- a/rtmfp/ProxyPair.as +++ b/rtmfp/ProxyPair.as @@ -18,126 +18,126 @@ package rtmfp { private var ui:rtmfpcat;
- private var s_r:RTMFPSocket; - private var s_t:Socket; + private var s_p:RTMFPSocket; + private var s_r:Socket;
- private var tor_host:String; - private var tor_port:uint; + private var relay_host:String; + private var relay_port:uint;
- private var p2t_schedule:Array; - private var t2p_schedule:Array; + private var p2r_schedule:Array; + private var r2p_schedule:Array;
// Bytes per second. Set to undefined to disable limit. public const RATE_LIMIT:Number = 10000; // Seconds. - private const RATE_LIMIT_HISTORY:Number = 5.0; + private const RATE_LIMIT_HISrelayY:Number = 5.0;
private var rate_limit:RateLimit;
// Callback id. private var flush_id:uint;
- public function ProxyPair(ui:rtmfpcat, s_c:CirrusSocket, tor_host:String, tor_port:uint) + public function ProxyPair(ui:rtmfpcat, s_c:CirrusSocket, relay_host:String, relay_port:uint) { this.ui = ui; - this.tor_host = tor_host; - this.tor_port = tor_port; + this.relay_host = relay_host; + this.relay_port = relay_port;
- this.p2t_schedule = new Array(); - this.t2p_schedule = new Array(); + this.p2r_schedule = new Array(); + this.r2p_schedule = new Array();
if (RATE_LIMIT) - rate_limit = new BucketRateLimit(RATE_LIMIT * RATE_LIMIT_HISTORY, RATE_LIMIT_HISTORY); + rate_limit = new BucketRateLimit(RATE_LIMIT * RATE_LIMIT_HISrelayY, RATE_LIMIT_HISrelayY); else rate_limit = new RateUnlimit();
setup_rtmfp_socket(s_c); - setup_tor_socket(); + setup_relay_socket(); }
public function close():void { + if (s_p.connected) { + s_p.close(); + } if (s_r.connected) { s_r.close(); } - if (s_t.connected) { - s_t.close(); - } dispatchEvent(new Event(Event.CLOSE)); }
public function connect(peer:String, stream:String):void { - s_r.connect(peer, stream); + s_p.connect(peer, stream); }
public function get connected():Boolean { - return (s_r.connected && s_t.connected); + return (s_p.connected && s_r.connected); }
public function listen(stream:String):void { - s_r.listen(stream); + s_p.listen(stream); }
private function setup_rtmfp_socket(s_c:CirrusSocket):void { - s_r = new RTMFPSocket(s_c); - s_r.addEventListener(RTMFPSocketEvent.CONNECT_FAILED, function (e:RTMFPSocketEvent):void { + s_p = new RTMFPSocket(s_c); + s_p.addEventListener(RTMFPSocketEvent.CONNECT_FAILED, function (e:RTMFPSocketEvent):void { ui.puts("Peering failed."); }); - s_r.addEventListener(RTMFPSocketEvent.CONNECT_SUCCESS, function (e:RTMFPSocketEvent):void { + s_p.addEventListener(RTMFPSocketEvent.CONNECT_SUCCESS, function (e:RTMFPSocketEvent):void { ui.puts("Peering success."); - s_t.connect(tor_host, tor_port); + s_r.connect(relay_host, relay_port); }); - s_r.addEventListener(RTMFPSocketEvent.PEER_CONNECTED, function (e:RTMFPSocketEvent):void { + s_p.addEventListener(RTMFPSocketEvent.PEER_CONNECTED, function (e:RTMFPSocketEvent):void { ui.puts("Peer connected."); }); - s_r.addEventListener(RTMFPSocketEvent.PEER_DISCONNECTED, function (e:RTMFPSocketEvent):void { + s_p.addEventListener(RTMFPSocketEvent.PEER_DISCONNECTED, function (e:RTMFPSocketEvent):void { ui.puts("Peer disconnected."); close(); }); - s_r.addEventListener(RTMFPSocketEvent.PLAY_STARTED, function (e:RTMFPSocketEvent):void { + s_p.addEventListener(RTMFPSocketEvent.PLAY_STARTED, function (e:RTMFPSocketEvent):void { ui.puts("Play started."); }); - s_r.addEventListener(RTMFPSocketEvent.PUBLISH_STARTED, function (e:RTMFPSocketEvent):void { + s_p.addEventListener(RTMFPSocketEvent.PUBLISH_STARTED, function (e:RTMFPSocketEvent):void { ui.puts("Publishing started."); }); - s_r.addEventListener(ProgressEvent.SOCKET_DATA, proxy_to_tor); + s_p.addEventListener(ProgressEvent.SOCKET_DATA, proxy_to_relay); }
- private function setup_tor_socket():void + private function setup_relay_socket():void { - s_t = new Socket(); - s_t.addEventListener(Event.CONNECT, function (e:Event):void { - ui.puts("Tor: connected to " + tor_host + ":" + tor_port + "."); + s_r = new Socket(); + s_r.addEventListener(Event.CONNECT, function (e:Event):void { + ui.puts("Relay: connected to " + relay_host + ":" + relay_port + "."); dispatchEvent(new Event(Event.CONNECT)); }); - s_t.addEventListener(Event.CLOSE, function (e:Event):void { - ui.puts("Tor: closed connection."); + s_r.addEventListener(Event.CLOSE, function (e:Event):void { + ui.puts("Relay: closed connection."); close(); }); - s_t.addEventListener(IOErrorEvent.IO_ERROR, function (e:IOErrorEvent):void { - ui.puts("Tor: I/O error: " + e.text + "."); + s_r.addEventListener(IOErrorEvent.IO_ERROR, function (e:IOErrorEvent):void { + ui.puts("Relay: I/O error: " + e.text + "."); close(); }); - s_t.addEventListener(SecurityErrorEvent.SECURITY_ERROR, function (e:SecurityErrorEvent):void { - ui.puts("Tor: security error: " + e.text + "."); + s_r.addEventListener(SecurityErrorEvent.SECURITY_ERROR, function (e:SecurityErrorEvent):void { + ui.puts("Relay: security error: " + e.text + "."); close(); }); - s_t.addEventListener(ProgressEvent.SOCKET_DATA, tor_to_proxy); + s_r.addEventListener(ProgressEvent.SOCKET_DATA, relay_to_proxy); }
- private function tor_to_proxy(e:ProgressEvent):void + private function relay_to_proxy(e:ProgressEvent):void { - t2p_schedule.push(e.bytesLoaded); + r2p_schedule.push(e.bytesLoaded); flush(); }
- private function proxy_to_tor(e:ProgressEvent):void + private function proxy_to_relay(e:ProgressEvent):void { - p2t_schedule.push(e.bytesLoaded); + p2r_schedule.push(e.bytesLoaded); flush(); }
@@ -148,34 +148,34 @@ package rtmfp clearTimeout(flush_id); flush_id = undefined;
- if (!(s_r.connected && s_t.connected)) + if (!(s_p.connected && s_r.connected)) /* Can't do anything until both sockets are connected. */ return;
- while (!rate_limit.is_limited() && (p2t_schedule.length > 0 || t2p_schedule.length > 0)) { + while (!rate_limit.is_limited() && (p2r_schedule.length > 0 || r2p_schedule.length > 0)) { var numBytes:uint; var bytes:ByteArray;
- if (p2t_schedule.length > 0) { - numBytes = p2t_schedule.shift(); + if (p2r_schedule.length > 0) { + numBytes = p2r_schedule.shift(); bytes = new ByteArray(); - s_r.readBytes(bytes, 0, numBytes); + s_p.readBytes(bytes, 0, numBytes); ui.puts("ProxyPair: RTMFP: read " + bytes.length + " bytes."); - s_t.writeBytes(bytes); + s_r.writeBytes(bytes); rate_limit.update(numBytes); } - if (t2p_schedule.length > 0) { - numBytes = t2p_schedule.shift(); + if (r2p_schedule.length > 0) { + numBytes = r2p_schedule.shift(); bytes = new ByteArray(); - s_t.readBytes(bytes, 0, numBytes); - ui.puts("ProxyPair: Tor: read " + bytes.length + " bytes."); - s_r.writeBytes(bytes); + s_r.readBytes(bytes, 0, numBytes); + ui.puts("ProxyPair: Relay: read " + bytes.length + " bytes."); + s_p.writeBytes(bytes); rate_limit.update(numBytes); } }
/* Call again when safe, if necessary. */ - if (p2t_schedule.length > 0 || t2p_schedule.length > 0) + if (p2r_schedule.length > 0 || r2p_schedule.length > 0) flush_id = setTimeout(flush, rate_limit.when() * 1000); } } diff --git a/rtmfpcat.as b/rtmfpcat.as index 2273bc9..713fc45 100644 --- a/rtmfpcat.as +++ b/rtmfpcat.as @@ -33,7 +33,7 @@ package
/* David's relay (nickname 3VXRyxz67OeRoqHn) that also serves a crossdomain policy. */ - private const DEFAULT_TOR_PROXY_ADDR:Object = { + private const DEFAULT_TOR_RELAY_ADDR:Object = { host: "173.255.221.44", port: 9001 }; @@ -56,7 +56,7 @@ package private var output_text:TextField;
private var fac_addr:Object; - private var tor_addr:Object; + private var relay_addr:Object;
public function rtmfpcat() { @@ -86,7 +86,7 @@ package private function loaderinfo_complete(e:Event):void { var fac_spec:String; - var tor_spec:String; + var relay_spec:String;
puts("Parameters loaded.");
@@ -104,20 +104,20 @@ package } else { fac_addr = DEFAULT_FACILITATOR_ADDR; } - - tor_spec = this.loaderInfo.parameters["tor"]; - if (tor_spec) { - puts("Tor spec: "" + tor_spec + """); - tor_addr = parse_addr_spec(tor_spec); - if (!tor_addr) { - puts("Error: Tor spec must be in the form "host:port"."); + + relay_spec = this.loaderInfo.parameters["relay"]; + if (relay_spec) { + puts("Relay spec: "" + relay_spec + """); + relay_addr = parse_addr_spec(relay_spec); + if (!relay_addr) { + puts("Error: Relay spec must be in the form "host:port"."); return; } } else { if (proxy_mode) { - tor_addr = DEFAULT_TOR_PROXY_ADDR; + relay_addr = DEFAULT_TOR_RELAY_ADDR; } else { - tor_addr = DEFAULT_TOR_CLIENT_ADDR; + relay_addr = DEFAULT_TOR_CLIENT_ADDR; } }
@@ -206,7 +206,7 @@ package private function start_proxy_pair():void { puts("Starting proxy pair on stream " + s_c.local_stream_name); - p_p = new ProxyPair(this, s_c, tor_addr.host, tor_addr.port); + p_p = new ProxyPair(this, s_c, relay_addr.host, relay_addr.port); p_p.addEventListener(Event.CONNECT, function (e:Event):void { puts("ProxyPair: connected!"); });