[tor-commits] [flashproxy/master] Attempted to fix stream disconnection notification, also trying to fix whitespace
dcf at torproject.org
dcf at torproject.org
Sun Jun 12 08:56:29 UTC 2011
commit 60e2c5afa70435c9f336bf33097717ff24573515
Author: Nate Hardison <nate at rescomp-09-154551.stanford.edu>
Date: Thu Jun 2 10:50:09 2011 -0700
Attempted to fix stream disconnection notification, also trying to fix whitespace
---
rtmfp/CirrusSocket.as | 28 +++++++++++++-------------
rtmfp/RTMFPSocket.as | 53 +++++++++++++++++++++++++-----------------------
rtmfpcat.as | 3 ++
3 files changed, 45 insertions(+), 39 deletions(-)
diff --git a/rtmfp/CirrusSocket.as b/rtmfp/CirrusSocket.as
index 9e97c7d..071ac0d 100644
--- a/rtmfp/CirrusSocket.as
+++ b/rtmfp/CirrusSocket.as
@@ -31,10 +31,10 @@ package rtmfp
{
private static const CONNECT_TIMEOUT:uint = 4000; // in milliseconds
- /* We'll append a unique number to the DATA_STREAM_PREFIX for each
+ /* We'll append a unique number to the DATA_STREAM_PREFIX for each
new stream we create so that we have unique streams per player. */
private static const DATA_STREAM_PREFIX:String = "DATA";
- private var data_stream_suffix:uint = 0;
+ private var data_stream_suffix:uint = 0;
/* Connection to the Cirrus rendezvous service */
public var connection:NetConnection;
@@ -94,18 +94,18 @@ package rtmfp
return DATA_STREAM_PREFIX + data_stream_suffix;
}
- /* Sends a hello message to the Flash player with Cirrus ID "id"
- We use this new call protocol outlined here:
- http://forums.adobe.com/thread/780788?tstart=0 */
- public function send_hello(id:String):void
- {
- if (this.connected) {
- connection.call("relay", null, id, local_stream_name);
- } else {
- throw new Error("Cannot send hello: Cirrus socket not connected.");
- }
- }
-
+ /* Sends a hello message to the Flash player with Cirrus ID "id"
+ We use this new call protocol outlined here:
+ http://forums.adobe.com/thread/780788?tstart=0 */
+ public function send_hello(id:String):void
+ {
+ if (this.connected) {
+ connection.call("relay", null, id, local_stream_name);
+ } else {
+ throw new Error("Cannot send hello: Cirrus socket not connected.");
+ }
+ }
+
/*************************** PRIVATE HELPER FUNCTIONS *************************/
private function fail():void
diff --git a/rtmfp/RTMFPSocket.as b/rtmfp/RTMFPSocket.as
index 6e9a45e..bcbee67 100644
--- a/rtmfp/RTMFPSocket.as
+++ b/rtmfp/RTMFPSocket.as
@@ -27,26 +27,28 @@ package rtmfp
[Event(name=RTMFPSocketEvent.PUBLISH_FAILED, type="com.flashproxy.rtmfp.events.RTMFPSocketEvent")]
public class RTMFPSocket extends EventDispatcher
{
- private const CONNECT_TIMEOUT:uint = 10000;
+ private const CONNECT_TIMEOUT:uint = 10000;
private var s_c:CirrusSocket;
- private var recv_stream:NetStream;
+ private var recv_stream:NetStream;
private var send_stream:NetStream;
- private var connect_timeout:int;
+ private var peer_stream:NetStream;
+
+ private var connect_timeout:int;
public function RTMFPSocket(s_c:CirrusSocket)
{
this.s_c = s_c;
recv_stream = null;
- send_stream = null;
- connect_timeout = 0;
+ send_stream = null;
+ connect_timeout = 0;
}
- /* Tears down this RTMFPSocket, closing both its streams.
- To be used when destroying this object. */
- public function close():void
+ /* Tears down this RTMFPSocket, closing both its streams.
+ To be used when destroying this object. */
+ public function close():void
{
if (send_stream != null) {
s_c.connection.removeEventListener(NetStatusEvent.NET_STATUS, on_stream_disconnection_event);
@@ -81,23 +83,23 @@ package rtmfp
RTMFPSocketClient(recv_stream.client).connect_acknowledged);
}
- /* In RTMFP, you open a listening socket by publishing a named
+ /* In RTMFP, you open a listening socket by publishing a named
stream that others can connect to instead of listening on a port.
You register this stream with the Cirrus server via the Cirrus
socket so that it can redirect connection requests for an id/stream
tuple to this socket. */
public function listen(stream:String):void
{
- // apparently streams don't get disconnection events, only the NetConnection
- // object does...bleh.
- s_c.connection.addEventListener(NetStatusEvent.NET_STATUS, on_stream_disconnection_event);
+ // apparently streams don't get disconnection events, only the NetConnection
+ // object does...bleh.
+ s_c.connection.addEventListener(NetStatusEvent.NET_STATUS, on_stream_disconnection_event);
send_stream = new NetStream(s_c.connection, NetStream.DIRECT_CONNECTIONS);
- send_stream.addEventListener(NetStatusEvent.NET_STATUS, on_send_stream_event);
- var client:Object = new Object();
- client.onPeerConnect = on_peer_connect;
- send_stream.client = client;
- send_stream.publish(stream);
+ send_stream.addEventListener(NetStatusEvent.NET_STATUS, on_send_stream_event);
+ var client:Object = new Object();
+ client.onPeerConnect = on_peer_connect;
+ send_stream.client = client;
+ send_stream.publish(stream);
}
public function get peer():String
@@ -113,16 +115,16 @@ package rtmfp
public function readBytes(bytes:ByteArray, offset:uint = 0, length:uint = 0):void
{
- if (recv_stream != null && recv_stream.client != null) {
- recv_stream.client.bytes.readBytes(bytes, offset, length);
- }
+ if (recv_stream != null && recv_stream.client != null) {
+ recv_stream.client.bytes.readBytes(bytes, offset, length);
+ }
}
public function writeBytes(bytes:ByteArray):void
{
if (send_stream != null && peer_connected) {
- send_stream.send(RTMFPSocketClient.DATA_AVAILABLE, bytes);
- }
+ send_stream.send(RTMFPSocketClient.DATA_AVAILABLE, bytes);
+ }
}
/* Listens for acknowledgement of a connection attempt to a
@@ -130,7 +132,7 @@ package rtmfp
private function on_connect_acknowledged(event:Event):void
{
clearTimeout(connect_timeout);
- dispatchEvent(new RTMFPSocketEvent(RTMFPSocketEvent.CONNECT_SUCCESS, recv_stream));
+ dispatchEvent(new RTMFPSocketEvent(RTMFPSocketEvent.CONNECT_SUCCESS, recv_stream));
}
/* If we don't get a connection acknowledgement by the time this
@@ -163,6 +165,7 @@ package rtmfp
return false;
}
+ peer_stream = peer;
peer.send(RTMFPSocketClient.SET_CONNECT_ACKNOWLEDGED);
// need to do this in a timeout so that this function can
@@ -190,10 +193,10 @@ package rtmfp
private function on_stream_disconnection_event(event:NetStatusEvent):void
{
- if (event.info.code == "NetStream.Connect.Closed") {
+ if (event.info.code == "NetStream.Connect.Closed" && event.info.stream === peer_stream) {
dispatchEvent(new RTMFPSocketEvent(RTMFPSocketEvent.PEER_DISCONNECTED));
- //disconnect();
}
}
}
}
+
diff --git a/rtmfpcat.as b/rtmfpcat.as
index 866175e..25099dd 100644
--- a/rtmfpcat.as
+++ b/rtmfpcat.as
@@ -49,6 +49,8 @@ package
private var s_f:FacilitatorSocket;
// Handle local-remote traffic
private var p_p:ProxyPair;
+
+ private var proxy_pairs:Array;
private var proxy_mode:Boolean;
@@ -87,6 +89,7 @@ package
puts("Parameters loaded.");
proxy_mode = (this.loaderInfo.parameters["proxy"] != null);
+ proxy_pairs = new Array();
fac_spec = this.loaderInfo.parameters["facilitator"];
if (fac_spec) {
More information about the tor-commits
mailing list