[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [flashproxy/rtmfp] Pulling Facilitator stuff out of rtmfp package, adding some commentary and boilerplate for an SQSProxyPair (currently is just a TCPProxyPair)
commit 6307de6a85132ea3859ab0dca7e95db9b04d0af0
Author: Nate Hardison <nate@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
Date: Thu Jun 9 01:12:37 2011 -0700
Pulling Facilitator stuff out of rtmfp package, adding some commentary and boilerplate for an SQSProxyPair (currently is just a TCPProxyPair)
---
FacilitatorSocket.as | 103 +++++++++++++++++++++++++++++++
SQSProxyPair.as | 86 ++++++++++++++++++++++++++
events/FacilitatorSocketEvent.as | 22 +++++++
rtmfp/FacilitatorSocket.as | 104 --------------------------------
rtmfp/events/FacilitatorSocketEvent.as | 22 -------
swfcat.as | 25 +++++++-
6 files changed, 233 insertions(+), 129 deletions(-)
diff --git a/FacilitatorSocket.as b/FacilitatorSocket.as
new file mode 100644
index 0000000..3930fea
--- /dev/null
+++ b/FacilitatorSocket.as
@@ -0,0 +1,103 @@
+package
+{
+ import flash.events.Event;
+ import flash.events.EventDispatcher;
+ import flash.events.HTTPStatusEvent;
+ import flash.events.IOErrorEvent;
+ import flash.events.SecurityErrorEvent;
+ import flash.net.URLLoader;
+ import flash.net.URLLoaderDataFormat;
+ import flash.net.URLRequest;
+ import flash.net.URLRequestMethod;
+ import flash.net.URLVariables;
+
+ import events.FacilitatorSocketEvent;
+
+ [Event(name=FacilitatorSocketEvent.CONNECT_FAILED, type="com.flashproxy.rtmfp.events.FacilitatorSocketEvent")]
+ [Event(name=FacilitatorSocketEvent.REGISTRATION_FAILED, type="com.flashproxy.rtmfp.events.FacilitatorSocketEvent")]
+ [Event(name=FacilitatorSocketEvent.REGISTRATION_RECEIVED, type="com.flashproxy.rtmfp.events.FacilitatorSocketEvent")]
+ [Event(name=FacilitatorSocketEvent.REGISTRATIONS_EMPTY, type="com.flashproxy.rtmfp.events.FacilitatorSocketEvent")]
+ public class FacilitatorSocket extends EventDispatcher
+ {
+ private var host:String;
+ private var port:uint;
+
+ public function FacilitatorSocket(host:String, port:uint)
+ {
+ this.host = host;
+ this.port = port;
+ }
+
+ public function get_registration():void
+ {
+ make_request(URLRequestMethod.GET);
+ }
+
+ public function post_registration(registration_data:String):void
+ {
+ var data:URLVariables = new URLVariables();
+ data.client = registration_data;
+ make_request(URLRequestMethod.POST, data);
+ }
+
+ private function fail():void
+ {
+ dispatchEvent(new FacilitatorSocketEvent(FacilitatorSocketEvent.CONNECT_FAILED));
+ }
+
+ private function make_request(method:String, data:URLVariables = null):void
+ {
+ var request:URLRequest = new URLRequest(url)
+ request.data = data;
+ request.method = method;
+
+ var url_loader:URLLoader = new URLLoader();
+ url_loader = new URLLoader();
+ url_loader.dataFormat = URLLoaderDataFormat.VARIABLES;
+
+ url_loader.addEventListener(Event.COMPLETE, on_complete_event);
+ url_loader.addEventListener(HTTPStatusEvent.HTTP_STATUS, on_http_status_event);
+ url_loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, on_security_error_event);
+ url_loader.addEventListener(IOErrorEvent.IO_ERROR, on_io_error_event);
+
+ url_loader.load(request);
+ }
+
+ private function on_complete_event(event:Event):void
+ {
+ try {
+ var client_id:String = event.target.data.client;
+ if (client_id == "Registration list empty") {
+ dispatchEvent(new FacilitatorSocketEvent(FacilitatorSocketEvent.REGISTRATIONS_EMPTY));
+ } else {
+ dispatchEvent(new FacilitatorSocketEvent(FacilitatorSocketEvent.REGISTRATION_RECEIVED, client_id));
+ }
+ } catch (e:Error) {
+ /* error is thrown for POST when we don't care about
+ the response anyways */
+ }
+
+ event.target.close()
+ }
+
+ private function on_http_status_event(event:HTTPStatusEvent):void
+ {
+ /* empty for now */
+ }
+
+ private function on_io_error_event(event:IOErrorEvent):void
+ {
+ fail();
+ }
+
+ private function on_security_error_event(event:SecurityErrorEvent):void
+ {
+ fail();
+ }
+
+ private function get url():String
+ {
+ return "http://" + host + ":" + port;
+ }
+ }
+}
\ No newline at end of file
diff --git a/SQSProxyPair.as b/SQSProxyPair.as
new file mode 100644
index 0000000..54f763d
--- /dev/null
+++ b/SQSProxyPair.as
@@ -0,0 +1,86 @@
+package
+{
+ import flash.events.Event;
+ import flash.events.EventDispatcher;
+ import flash.events.IOErrorEvent;
+ import flash.events.ProgressEvent;
+ import flash.events.SecurityErrorEvent;
+ import flash.net.Socket;
+ import flash.utils.ByteArray;
+
+ public class SQSProxyPair extends ProxyPair
+ {
+ private var client_socket:Socket;
+
+ public function SQSProxyPair(ui:swfcat)
+ {
+ super(this, ui);
+
+ log("Starting SQS proxy pair");
+ setup_client_socket();
+ }
+
+ override public function set client(client_addr:Object):void
+ {
+ this.client_addr = client_addr;
+ log("Client: connecting to " + client_addr.host + ":" + client_addr.port + ".");
+ client_socket.connect(client_addr.host, client_addr.port);
+ }
+
+ override public function close():void
+ {
+ super.close();
+ if (client_socket != null && client_socket.connected) {
+ client_socket.close();
+ }
+ dispatchEvent(new Event(Event.CLOSE));
+ }
+
+ override public function get connected():Boolean
+ {
+ return (super.connected && client_socket != null && client_socket.connected);
+ }
+
+ override protected function transfer_bytes(src:Object, dst:Object, num_bytes:uint):void
+ {
+ var bytes:ByteArray = new ByteArray();
+
+ if (src == null) {
+ src = client_socket;
+ }
+
+ if (dst == null) {
+ dst = client_socket;
+ }
+
+ Socket(src).readBytes(bytes, 0, num_bytes);
+ log("SQSProxyPair: transferring " + num_bytes + " bytes.");
+ Socket(dst).writeBytes(bytes);
+ }
+
+ private function setup_client_socket():void
+ {
+ client_socket = new Socket();
+
+ client_socket.addEventListener(Event.CONNECT, function (e:Event):void {
+ log("Client: connected to " + client_addr.host + ":" + client_addr.port + ".");
+ if (connected) {
+ dispatchEvent(new Event(Event.CONNECT));
+ }
+ });
+ client_socket.addEventListener(Event.CLOSE, function (e:Event):void {
+ log("Client: closed.");
+ close();
+ });
+ client_socket.addEventListener(IOErrorEvent.IO_ERROR, function (e:IOErrorEvent):void {
+ log("Client: I/O error: " + e.text + ".");
+ close();
+ });
+ client_socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, function (e:SecurityErrorEvent):void {
+ log("Client: security error: " + e.text + ".");
+ close();
+ });
+ client_socket.addEventListener(ProgressEvent.SOCKET_DATA, client_to_relay);
+ }
+ }
+}
\ No newline at end of file
diff --git a/events/FacilitatorSocketEvent.as b/events/FacilitatorSocketEvent.as
new file mode 100644
index 0000000..9fc478b
--- /dev/null
+++ b/events/FacilitatorSocketEvent.as
@@ -0,0 +1,22 @@
+package events
+{
+ import flash.events.Event;
+
+ public class FacilitatorSocketEvent extends Event
+ {
+ public static const CONNECT_CLOSED:String = "connectClosed";
+ public static const CONNECT_FAILED:String = "connectFailed";
+ public static const CONNECT_SUCCESS:String = "connectSuccess";
+ public static const REGISTRATION_RECEIVED:String = "registrationReceived";
+ public static const REGISTRATION_FAILED:String = "registrationFailed";
+ public static const REGISTRATIONS_EMPTY:String = "registrationsEmpty";
+
+ public var client:String;
+
+ public function FacilitatorSocketEvent(type:String, client:String = null, bubbles:Boolean = false, cancelable:Boolean = false)
+ {
+ super(type, bubbles, cancelable);
+ this.client = client;
+ }
+ }
+}
diff --git a/rtmfp/FacilitatorSocket.as b/rtmfp/FacilitatorSocket.as
deleted file mode 100644
index 32c8a7d..0000000
--- a/rtmfp/FacilitatorSocket.as
+++ /dev/null
@@ -1,104 +0,0 @@
-package rtmfp
-{
- import flash.events.Event;
- import flash.events.EventDispatcher;
- import flash.events.HTTPStatusEvent;
- import flash.events.IOErrorEvent;
- import flash.events.SecurityErrorEvent;
- import flash.net.URLLoader;
- import flash.net.URLLoaderDataFormat;
- import flash.net.URLRequest;
- import flash.net.URLRequestMethod;
- import flash.net.URLVariables;
- import flash.system.Security;
-
- import rtmfp.events.FacilitatorSocketEvent;
-
- [Event(name=FacilitatorSocketEvent.CONNECT_FAILED, type="com.flashproxy.rtmfp.events.FacilitatorSocketEvent")]
- [Event(name=FacilitatorSocketEvent.REGISTRATION_FAILED, type="com.flashproxy.rtmfp.events.FacilitatorSocketEvent")]
- [Event(name=FacilitatorSocketEvent.REGISTRATION_RECEIVED, type="com.flashproxy.rtmfp.events.FacilitatorSocketEvent")]
- [Event(name=FacilitatorSocketEvent.REGISTRATIONS_EMPTY, type="com.flashproxy.rtmfp.events.FacilitatorSocketEvent")]
- public class FacilitatorSocket extends EventDispatcher
- {
- private var host:String;
- private var port:uint;
-
- public function FacilitatorSocket(host:String, port:uint)
- {
- this.host = host;
- this.port = port;
- }
-
- public function get_registration():void
- {
- make_request(URLRequestMethod.GET);
- }
-
- public function post_registration(registration_data:String):void
- {
- var data:URLVariables = new URLVariables();
- data.client = registration_data;
- make_request(URLRequestMethod.POST, data);
- }
-
- private function fail():void
- {
- dispatchEvent(new FacilitatorSocketEvent(FacilitatorSocketEvent.CONNECT_FAILED));
- }
-
- private function make_request(method:String, data:URLVariables = null):void
- {
- var request:URLRequest = new URLRequest(url)
- request.data = data;
- request.method = method;
-
- var url_loader:URLLoader = new URLLoader();
- url_loader = new URLLoader();
- url_loader.dataFormat = URLLoaderDataFormat.VARIABLES;
-
- url_loader.addEventListener(Event.COMPLETE, on_complete_event);
- url_loader.addEventListener(HTTPStatusEvent.HTTP_STATUS, on_http_status_event);
- url_loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, on_security_error_event);
- url_loader.addEventListener(IOErrorEvent.IO_ERROR, on_io_error_event);
-
- url_loader.load(request);
- }
-
- private function on_complete_event(event:Event):void
- {
- try {
- var client_id:String = event.target.data.client;
- if (client_id == "Registration list empty") {
- dispatchEvent(new FacilitatorSocketEvent(FacilitatorSocketEvent.REGISTRATIONS_EMPTY));
- } else {
- dispatchEvent(new FacilitatorSocketEvent(FacilitatorSocketEvent.REGISTRATION_RECEIVED, client_id));
- }
- } catch (e:Error) {
- /* error is thrown for POST when we don't care about
- the response anyways */
- }
-
- event.target.close()
- }
-
- private function on_http_status_event(event:HTTPStatusEvent):void
- {
- /* empty for now */
- }
-
- private function on_io_error_event(event:IOErrorEvent):void
- {
- fail();
- }
-
- private function on_security_error_event(event:SecurityErrorEvent):void
- {
- fail();
- }
-
- private function get url():String
- {
- return "http://" + host + ":" + port;
- }
- }
-}
\ No newline at end of file
diff --git a/rtmfp/events/FacilitatorSocketEvent.as b/rtmfp/events/FacilitatorSocketEvent.as
deleted file mode 100644
index a0599aa..0000000
--- a/rtmfp/events/FacilitatorSocketEvent.as
+++ /dev/null
@@ -1,22 +0,0 @@
-package rtmfp.events
-{
- import flash.events.Event;
-
- public class FacilitatorSocketEvent extends Event
- {
- public static const CONNECT_CLOSED:String = "connectClosed";
- public static const CONNECT_FAILED:String = "connectFailed";
- public static const CONNECT_SUCCESS:String = "connectSuccess";
- public static const REGISTRATION_RECEIVED:String = "registrationReceived";
- public static const REGISTRATION_FAILED:String = "registrationFailed";
- public static const REGISTRATIONS_EMPTY:String = "registrationsEmpty";
-
- public var client:String;
-
- public function FacilitatorSocketEvent(type:String, client:String = null, bubbles:Boolean = false, cancelable:Boolean = false)
- {
- super(type, bubbles, cancelable);
- this.client = client;
- }
- }
-}
diff --git a/swfcat.as b/swfcat.as
index 7729d2c..627a3cd 100644
--- a/swfcat.as
+++ b/swfcat.as
@@ -8,14 +8,22 @@ package
import flash.events.Event;
import flash.utils.setTimeout;
+ import FacilitatorSocket;
+ import events.FacilitatorSocketEvent;
+
+ import ProxyPair;
+ import RTMFPProxyPair;
+ import SQSProxyPair;
+ import TCPProxyPair;
+
import rtmfp.CirrusSocket;
- import rtmfp.FacilitatorSocket;
import rtmfp.events.CirrusSocketEvent;
- import rtmfp.events.FacilitatorSocketEvent;
public class swfcat extends Sprite
{
- /* Adobe's Cirrus server and Nate's key */
+ /* Adobe's Cirrus server for RTMFP connections.
+ The Cirrus key is defined at compile time by
+ reading from the CIRRUS_KEY environment var. */
private const DEFAULT_CIRRUS_ADDR:String = "rtmfp://p2p.rtmfp.net";
private const DEFAULT_CIRRUS_KEY:String = RTMFP::CIRRUS_KEY;
@@ -25,6 +33,7 @@ package
port: 9002
};
+ /* Default Tor client to use in case of RTMFP connection */
private const DEFAULT_TOR_CLIENT_ADDR:Object = {
host: "127.0.0.1",
port: 9002
@@ -122,6 +131,8 @@ package
fac_addr = DEFAULT_FACILITATOR_ADDR;
}
+ /* TODO: modify this for the client so that it can specify
+ a relay for the proxy to use */
relay_spec = this.loaderInfo.parameters["relay"];
if (relay_spec) {
puts("Relay spec: \"" + relay_spec + "\"");
@@ -259,6 +270,14 @@ package
return new RTMFPProxyPair(this, s_c, s_c.local_stream_name);
}
+ // currently is the same as TCPProxyPair
+ // could be interesting to see how this works
+ // can't imagine it will work terribly well...
+ private function sqs_proxy_pair_factory():ProxyPair
+ {
+ return new SQSProxyPair(this);
+ }
+
private function tcp_proxy_pair_factory():ProxyPair
{
return new TCPProxyPair(this);
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits