Commit 6c86fb6b authored by Matt Tucker's avatar Matt Tucker Committed by matt

Refactoring work.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@6697 b35dd754-fafc-0310-a699-88a17e54d16e
parent 22f40883
...@@ -16,13 +16,15 @@ import java.util.ArrayList; ...@@ -16,13 +16,15 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
* MediaProxy create and bind relay channels between IP pairs. * A Media Proxy relays UDP traffic between two IPs to provide connectivity between
* This relay can provite UDP connectivity between two parties that are behind NAT. * two parties that are behind NAT devices. It also provides connectivity
* It also work to provide connectivity between two parties that are directly connected to the internet or one party in the internet and another behind a NAT. * between two parties that are directly connected to the internet or one party on the
* The MediaProxy Class add and control the Bridge Agents. * internet and another behind a NAT.<p>
* You can setup a MediaProxy for all your network interfaces with a empty constructor, *
* or bind it to an especific interface with MediaProxy(String localhost) constructor. * Each connection relay between two parties is called a session. You can setup a MediaProxy
* <i>This MediaProxy ONLY works if your are Direct Connected to the Internet with a valid IP address.</i> * for all network interfaces with an empty constructor, or bind it to a specific interface
* with the MediaProxy(String localhost) constructor. <i>The media proxy ONLY works if your
* are directly connected to the Internet with a valid IP address.</i>.
*/ */
public class MediaProxy implements SessionListener { public class MediaProxy implements SessionListener {
...@@ -47,9 +49,9 @@ public class MediaProxy implements SessionListener { ...@@ -47,9 +49,9 @@ public class MediaProxy implements SessionListener {
} }
/** /**
* Contruct a MediaProxy instance that will listen from an especific Network Interface. * Contruct a MediaProxy instance that will listen on a specific network interface.
* *
* @param localhost The IP of the locahost that will listen for packets. * @param localhost the IP of the locahost that will listen for packets.
*/ */
public MediaProxy(String localhost) { public MediaProxy(String localhost) {
this.localhost = localhost; this.localhost = localhost;
...@@ -58,25 +60,27 @@ public class MediaProxy implements SessionListener { ...@@ -58,25 +60,27 @@ public class MediaProxy implements SessionListener {
/** /**
* Get the public IP of this RTP Proxy that listen for the incomming packets * Get the public IP of this RTP Proxy that listen for the incomming packets
* *
* @return Your selected localhost that listen for the incomming packets * @return the host that listens for incomming packets.
*/ */
public String getPublicIP() { public String getPublicIP() {
return localhost; return localhost;
} }
/** /**
* Get time in millis that an Session can stay without receive any packet. * Returns the max time (in millis) that a session can remain open without
* After this time it is auto closed. * receiving any packets. After this time period elapses, the session is
* automatically closed.
* *
* @return Time in millis * @return the max idle time (in millis).
*/ */
public long getKeepAliveDelay() { public long getIdleTime() {
return idleTime; return idleTime;
} }
/** /**
* Returns the maximum amount of time (in milleseconds) that a session can * Sets the max time (in millis) that a session can remain open without
* be idle before it's closed. * receiving any packets. After this time period elapses, the session is
* automatically closed.
* *
* @param idleTime the max idle time in millis. * @param idleTime the max idle time in millis.
*/ */
...@@ -85,77 +89,77 @@ public class MediaProxy implements SessionListener { ...@@ -85,77 +89,77 @@ public class MediaProxy implements SessionListener {
} }
/** /**
* Get the List of all the current active and running Agents. * Returns the list of all currently active and running sessions.
* *
* @return List of the Agents * @return List of the Agents
*/ */
public List<MediaProxySession> getAgents() { public List<MediaProxySession> getSessions() {
return sessions; return sessions;
} }
/** /**
* Get Minimal port value to listen from incoming packets. * Returns the minimum port value to listen for incoming packets.
* *
* @return the minimal port value * @return the minimum port value.
*/ */
public int getMinPort() { public int getMinPort() {
return minPort; return minPort;
} }
/** /**
* Set Minimal port value to listen from incoming packets. * Sets the minimum port value to listen from incoming packets.
* *
* @param minPort the minimal port value * @param minPort the minimum port value.
*/ */
public void setMinPort(int minPort) { public void setMinPort(int minPort) {
this.minPort = minPort; this.minPort = minPort;
} }
/** /**
* Get Maximum port value to listen from incoming packets. * Returns the maximum port value to listen for incoming packets.
* *
* @return the maximun port value * @return the maximun port value.
*/ */
public int getMaxPort() { public int getMaxPort() {
return maxPort; return maxPort;
} }
/** /**
* Set Maximum port value to listen from incoming packets. * Sets the maximum port value to listen for incoming packets.
* *
* @param maxPort the maximun port value * @param maxPort the maximun port value.
*/ */
public void setMaxPort(int maxPort) { public void setMaxPort(int maxPort) {
this.maxPort = maxPort; this.maxPort = maxPort;
} }
/** /**
* Get the Life Time of a channel in seconds * Returns the maximum lifetime (in seconds) of a session. After the time period
* Life Time is the maximum time that a Session can live. After this time the session will be destroyed even if it´s active. * elapses, the session will be destroyed even if currently active.
* *
* @return the Life Time in Seconds * @return the max lifetime of a session (in seconds).
*/ */
public long getLifetime() { public long getLifetime() {
return lifetime; return lifetime;
} }
/** /**
* Sets the Life Time of a Channel in seconds * Sets the maximum lifetime (in seconds) of a session. After the time period
* Life Time is the maximum time that a Session can live. After this time the session will be destroyed even if it´s active. * elapses, the session will be destroyed even if currently active.
* *
* @param lifetime the Life Time in Seconds * @param lifetime the max lifetime of a session (in seconds).
*/ */
public void setLifetime(long lifetime) { public void setLifetime(long lifetime) {
this.lifetime = lifetime; this.lifetime = lifetime;
} }
/** /**
* Get the agent with an especified ID * Returns a media proxy session with the specified ID.
* *
* @param sid the session ID * @param sid the session ID.
* @return the session with the informed sid, if not found, returns null * @return the session or <tt>null</tt> if the session doesn't exist.
*/ */
public MediaProxySession getAgent(String sid) { public MediaProxySession getSession(String sid) {
for (MediaProxySession session : sessions) { for (MediaProxySession session : sessions) {
if (session.getSID().equals(sid)) { if (session.getSID().equals(sid)) {
System.out.println("SID: " + sid + " agentSID: " + session.getSID()); System.out.println("SID: " + sid + " agentSID: " + session.getSID());
...@@ -189,15 +193,14 @@ public class MediaProxy implements SessionListener { ...@@ -189,15 +193,14 @@ public class MediaProxy implements SessionListener {
* @return the added ProxyCandidate * @return the added ProxyCandidate
*/ */
public ProxyCandidate addAgent(String id, String creator, String hostA, int portA, String hostB, public ProxyCandidate addAgent(String id, String creator, String hostA, int portA, String hostB,
int portB) { int portB)
final MediaProxySession session = {
new MediaProxySession(id, creator, localhost, hostA, portA, hostB, portB, minPort, maxPort); MediaProxySession session = new MediaProxySession(
if (session != null) { id, creator, localhost, hostA, portA, hostB, portB, minPort, maxPort);
sessions.add(session); sessions.add(session);
session.addKeepAlive(idleTime); session.addKeepAlive(idleTime);
session.addLifeTime(lifetime); session.addLifeTime(lifetime);
session.addAgentListener(this); session.addAgentListener(this);
}
return session; return session;
} }
...@@ -220,15 +223,14 @@ public class MediaProxy implements SessionListener { ...@@ -220,15 +223,14 @@ public class MediaProxy implements SessionListener {
* @return the added ProxyCandidate * @return the added ProxyCandidate
*/ */
public ProxyCandidate addSmartAgent(String id, String creator, String hostA, int portA, public ProxyCandidate addSmartAgent(String id, String creator, String hostA, int portA,
String hostB, int portB) { String hostB, int portB)
final SmartSession session = new SmartSession(id, creator, localhost, hostA, portA, hostB, portB, {
SmartSession session = new SmartSession(id, creator, localhost, hostA, portA, hostB, portB,
minPort, maxPort); minPort, maxPort);
if (session != null) { sessions.add(session);
sessions.add(session); session.addKeepAlive(idleTime);
session.addKeepAlive(idleTime); session.addLifeTime(lifetime);
session.addLifeTime(lifetime); session.addAgentListener(this);
session.addAgentListener(this);
}
return session; return session;
} }
...@@ -242,7 +244,7 @@ public class MediaProxy implements SessionListener { ...@@ -242,7 +244,7 @@ public class MediaProxy implements SessionListener {
* Every packet received from Point A will be relayed to the new Point B IP and port. * Every packet received from Point A will be relayed to the new Point B IP and port.
* Create a dynamic channel between two IPs. ( Dynamic Point A - Dynamic Point B ) * Create a dynamic channel between two IPs. ( Dynamic Point A - Dynamic Point B )
* *
* @param id id of the candidate returned (Could be a Jingle session ID) * @param id id of the candidate returned (Could be a Jingle session ID)
* @param creator the agent creator name or description * @param creator the agent creator name or description
* @return the added ProxyCandidate * @return the added ProxyCandidate
*/ */
...@@ -254,7 +256,7 @@ public class MediaProxy implements SessionListener { ...@@ -254,7 +256,7 @@ public class MediaProxy implements SessionListener {
* Stop every running sessions. * Stop every running sessions.
*/ */
public void stopProxy() { public void stopProxy() {
for (MediaProxySession session : getAgents()) { for (MediaProxySession session : getSessions()) {
try { try {
session.clearAgentListeners(); session.clearAgentListeners();
session.stopAgent(); session.stopAgent();
......
...@@ -218,7 +218,7 @@ public class MediaProxyService extends BasicModule implements ServerItemsProvide ...@@ -218,7 +218,7 @@ public class MediaProxyService extends BasicModule implements ServerItemsProvide
if (c != null) { if (c != null) {
MediaProxySession session = mediaProxy.getAgent( MediaProxySession session = mediaProxy.getSession(
childElementCopy.attribute("sid").getValue() + "-" + iq.getFrom()); childElementCopy.attribute("sid").getValue() + "-" + iq.getFrom());
Log.debug( Log.debug(
...@@ -364,7 +364,7 @@ public class MediaProxyService extends BasicModule implements ServerItemsProvide ...@@ -364,7 +364,7 @@ public class MediaProxyService extends BasicModule implements ServerItemsProvide
* @return list of active agents * @return list of active agents
*/ */
public List<MediaProxySession> getAgents() { public List<MediaProxySession> getAgents() {
return mediaProxy.getAgents(); return mediaProxy.getSessions();
} }
/** /**
...@@ -384,7 +384,7 @@ public class MediaProxyService extends BasicModule implements ServerItemsProvide ...@@ -384,7 +384,7 @@ public class MediaProxyService extends BasicModule implements ServerItemsProvide
* @return the max idle time in millis. * @return the max idle time in millis.
*/ */
public long getIdleTime() { public long getIdleTime() {
return mediaProxy.getKeepAliveDelay(); return mediaProxy.getIdleTime();
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment