Commit 2c9e6f17 authored by Matt Tucker's avatar Matt Tucker Committed by matt

Work on media proxy.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@6597 b35dd754-fafc-0310-a699-88a17e54d16e
parent 9df13949
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<install4j version="4.0" transformSequenceNumber="1"> <install4j version="4.0.4" transformSequenceNumber="1">
<directoryPresets config="${compiler:RELEASE_FULL_PATH}/resources/security/truststore" /> <directoryPresets config="${compiler:RELEASE_FULL_PATH}/resources/security/truststore" />
<application name="${compiler:APP_NAME}" distributionSourceDir="" applicationId="${compiler:APPLICATION_ID}" mediaDir="../../target/release" mediaFilePattern="${compiler:FILE_PREFIX}_${compiler:VERSION_MAJOR}_${compiler:VERSION_MINOR}_${compiler:VERSION_REVISION}" compression="9" lzmaCompression="true" pack200Compression="false" keepModificationTimes="true" shortName="${compiler:APP_SHORT_NAME}" publisher="${compiler:PUBLISHER}" publisherWeb="${compiler:PUBLISHER_URL}" version="${compiler:VERSION_MAJOR}.${compiler:VERSION_MINOR}.${compiler:VERSION_REVISION}" allPathsRelative="true" backupOnSave="false" autoSave="true" convertDotsToUnderscores="true" macSignature="????" javaMinVersion="1.5" javaMaxVersion="" allowBetaVM="true"> <application name="${compiler:APP_NAME}" distributionSourceDir="" applicationId="${compiler:APPLICATION_ID}" mediaDir="../../target/release" mediaFilePattern="${compiler:FILE_PREFIX}_${compiler:VERSION_MAJOR}_${compiler:VERSION_MINOR}_${compiler:VERSION_REVISION}" compression="9" lzmaCompression="true" pack200Compression="false" keepModificationTimes="true" shortName="${compiler:APP_SHORT_NAME}" publisher="${compiler:PUBLISHER}" publisherWeb="${compiler:PUBLISHER_URL}" version="${compiler:VERSION_MAJOR}.${compiler:VERSION_MINOR}.${compiler:VERSION_REVISION}" allPathsRelative="true" backupOnSave="false" autoSave="true" convertDotsToUnderscores="true" macSignature="????" javaMinVersion="1.5" javaMaxVersion="" allowBetaVM="true">
<languages skipLanguageSelection="false"> <languages skipLanguageSelection="false">
...@@ -308,8 +308,40 @@ ...@@ -308,8 +308,40 @@
</serializedBean> </serializedBean>
<condition /> <condition />
<validation /> <validation />
<actions /> <actions>
<formComponents /> <action name="" id="1292" beanClass="com.install4j.runtime.beans.actions.finish.ExecuteLauncherAction" rollbackBarrier="false" multiExec="false" failureStrategy="1" errorMessage="">
<serializedBean>
<java class="java.beans.XMLDecoder">
<object class="com.install4j.runtime.beans.actions.finish.ExecuteLauncherAction">
<void property="launcherId">
<string>12</string>
</void>
</object>
</java>
</serializedBean>
<condition>context.getBooleanVariable("executeLauncherAction") &amp;&amp; (!context.isUnattended())</condition>
</action>
</actions>
<formComponents>
<formComponent name="Execute launcher" id="1293" beanClass="com.install4j.runtime.beans.formcomponents.CheckboxComponent" insetTop="" insetLeft="" insetBottom="" insetRight="" resetInitOnPrevious="false">
<serializedBean>
<java class="java.beans.XMLDecoder">
<object class="com.install4j.runtime.beans.formcomponents.CheckboxComponent">
<void property="checkboxText">
<string>${i18n:RunEntryExec("${compiler:sys.fullName}")}</string>
</void>
<void property="initiallySelected">
<boolean>true</boolean>
</void>
<void property="variableName">
<string>executeLauncherAction</string>
</void>
</object>
</java>
</serializedBean>
<initScript />
</formComponent>
</formComponents>
</screen> </screen>
</installerScreens> </installerScreens>
<uninstallerScreens> <uninstallerScreens>
......
/**
* $Revision$
* $Date$
*
* Copyright (C) 2007 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.wildfire.mediaproxy; package org.jivesoftware.wildfire.mediaproxy;
import java.net.DatagramPacket; import java.net.DatagramPacket;
/** /**
* Interface to listener datagramReceived events * Listener for datagram packets received.
*/ */
public interface DatagramListener { public interface DatagramListener {
/** /**
* Called when a datagram is received. * Called when a datagram is received. If the method returns false, the
* If method return false the packet MUST NOT be resent from the received Channel. * packet MUST NOT be resent from the received Channel.
* @param datagramPacket The received datagram *
* @param datagramPacket the datagram packet received.
* @return ?
*/ */
public boolean datagramReceived(DatagramPacket datagramPacket); public boolean datagramReceived(DatagramPacket datagramPacket);
} }
\ No newline at end of file
/**
* $Revision$
* $Date$
*
* Copyright (C) 2007 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.wildfire.mediaproxy; package org.jivesoftware.wildfire.mediaproxy;
import org.jivesoftware.util.Log;
import java.util.List; import java.util.List;
import java.util.ArrayList; import java.util.ArrayList;
import java.net.InetAddress; import java.net.InetAddress;
...@@ -15,14 +27,14 @@ import java.net.InetAddress; ...@@ -15,14 +27,14 @@ import java.net.InetAddress;
*/ */
public class MediaProxy implements SessionListener { public class MediaProxy implements SessionListener {
final private List<Session> sessions = new ArrayList<Session>(); final private List<MediaProxySession> sessions = new ArrayList<MediaProxySession>();
private String localhost; private String localhost;
private int minPort = 10000; private int minPort = 10000;
private int maxPort = 20000; private int maxPort = 20000;
private long keepAliveDelay = 90000; private long idleTime = 90000;
/** /**
* Contruct a MediaProxy instance that will listen from every Network Interface. * Contruct a MediaProxy instance that will listen from every Network Interface.
...@@ -57,17 +69,17 @@ public class MediaProxy implements SessionListener { ...@@ -57,17 +69,17 @@ public class MediaProxy implements SessionListener {
* @return Time in millis * @return Time in millis
*/ */
public long getKeepAliveDelay() { public long getKeepAliveDelay() {
return keepAliveDelay; return idleTime;
} }
/** /**
* Set time in millis that an Session can stay without receive any packet. * Returns the maximum amount of time (in milleseconds) that a session can
* After this time it is auto closed. * be idle before it's closed.
* *
* @return Time in millis * @param idleTime the max idle time in millis.
*/ */
public void setKeepAliveDelay(long keepAliveDelay) { public void setIdleTime(long idleTime) {
this.keepAliveDelay = keepAliveDelay; this.idleTime = idleTime;
} }
/** /**
...@@ -75,7 +87,7 @@ public class MediaProxy implements SessionListener { ...@@ -75,7 +87,7 @@ public class MediaProxy implements SessionListener {
* *
* @return List of the Agents * @return List of the Agents
*/ */
public List<Session> getAgents() { public List<MediaProxySession> getAgents() {
return sessions; return sessions;
} }
...@@ -120,8 +132,8 @@ public class MediaProxy implements SessionListener { ...@@ -120,8 +132,8 @@ public class MediaProxy implements SessionListener {
* *
* @param sid the session ID * @param sid the session ID
*/ */
public Session getAgent(String sid) { public MediaProxySession getAgent(String sid) {
for (Session 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());
return session; return session;
...@@ -134,10 +146,11 @@ public class MediaProxy implements SessionListener { ...@@ -134,10 +146,11 @@ public class MediaProxy implements SessionListener {
* Implements Session Listener stopAgent event. * Implements Session Listener stopAgent event.
* Remove the stopped session from the sessions list. * Remove the stopped session from the sessions list.
* *
* @param session * @param session the session to
*/ */
public void agentStopped(Session session) { public void sessionClosed(MediaProxySession session) {
System.out.println("Session: " + session.getSID() + " removed: " + sessions.remove(session)); sessions.remove(session);
Log.debug("Session: " + session.getSID() + " removed.");
} }
/** /**
...@@ -153,11 +166,11 @@ public class MediaProxy implements SessionListener { ...@@ -153,11 +166,11 @@ public class MediaProxy implements SessionListener {
*/ */
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 Session session = final MediaProxySession session =
new Session(id, creator, localhost, hostA, portA, hostB, portB, minPort, maxPort); new MediaProxySession(id, creator, localhost, hostA, portA, hostB, portB, minPort, maxPort);
if (session != null) { if (session != null) {
sessions.add(session); sessions.add(session);
session.addKeepAlive(keepAliveDelay); session.addKeepAlive(idleTime);
session.addAgentListener(this); session.addAgentListener(this);
} }
return session; return session;
...@@ -186,7 +199,7 @@ public class MediaProxy implements SessionListener { ...@@ -186,7 +199,7 @@ public class MediaProxy implements SessionListener {
minPort, maxPort); minPort, maxPort);
if (agent != null) { if (agent != null) {
sessions.add(agent); sessions.add(agent);
agent.addKeepAlive(keepAliveDelay); agent.addKeepAlive(idleTime);
agent.addAgentListener(this); agent.addAgentListener(this);
} }
return agent; return agent;
...@@ -213,7 +226,7 @@ public class MediaProxy implements SessionListener { ...@@ -213,7 +226,7 @@ public class MediaProxy implements SessionListener {
* Stop every running sessions. * Stop every running sessions.
*/ */
public void stopProxy() { public void stopProxy() {
for (Session session : getAgents()) { for (MediaProxySession session : getAgents()) {
try { try {
session.clearAgentListeners(); session.clearAgentListeners();
session.stopAgent(); session.stopAgent();
...@@ -224,23 +237,4 @@ public class MediaProxy implements SessionListener { ...@@ -224,23 +237,4 @@ public class MediaProxy implements SessionListener {
} }
sessions.clear(); sessions.clear();
} }
public static void main(String args[]) {
MediaProxy media = new MediaProxy();
ProxyCandidate ag = media.addSmartAgent("abc", "tester", "200.233.136.54", 20001,
"200.233.136.54", 20008);
ag.start();
try {
Thread.sleep(5000);
System.out.println(InetAddress.getByName("0.0.0.0"));
}
catch (Exception e) {
}
ag.stopAgent();
System.out.println("Closed");
}
} }
\ No newline at end of file
/**
* $Revision$
* $Date$
*
* Copyright (C) 2007 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.wildfire.mediaproxy; package org.jivesoftware.wildfire.mediaproxy;
import org.dom4j.Attribute; import org.dom4j.Attribute;
...@@ -24,9 +34,9 @@ import java.util.Iterator; ...@@ -24,9 +34,9 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
/** /**
* RTP Bridge Media Proxy service plugin. * A proxy service for UDP traffic such as RTP. It provides Jingle transport candidates
* Provides especial relayed Jingle transport candidates to be used for media transmission and receiving of UDP packets. * to be used for media transmission. The media proxy is especially useful for users
* Especialy used for behind NAT users to ensure connectivity between parties. * behind NAT devices or firewalls that prevent peer to peer communication..
* *
* @author Thiago Camargo * @author Thiago Camargo
*/ */
...@@ -54,34 +64,23 @@ public class MediaProxyService extends BasicModule implements ServerItemsProvide ...@@ -54,34 +64,23 @@ public class MediaProxyService extends BasicModule implements ServerItemsProvide
*/ */
private void loadRTPProxyConfig() { private void loadRTPProxyConfig() {
try { try {
long keepAliveDelay = long idleTime =
Long.valueOf(JiveGlobals.getProperty("plugin.rtpbridge.keepalivedelay")); Long.valueOf(JiveGlobals.getProperty("mediaproxy.idleTimeout"));
mediaProxy.setKeepAliveDelay(keepAliveDelay); mediaProxy.setIdleTime(idleTime);
} }
catch (NumberFormatException e) { catch (NumberFormatException e) {
// Do nothing let the default values to be used. // Do nothing let the default values to be used.
} }
try { try {
int minPort = Integer.valueOf(JiveGlobals.getProperty("plugin.rtpbridge.minport")); int minPort = Integer.valueOf(JiveGlobals.getProperty("mediaproxy.portMin"));
mediaProxy.setMinPort(minPort); mediaProxy.setMinPort(minPort);
} }
catch (NumberFormatException e) { catch (NumberFormatException e) {
// Do nothing let the default values to be used. // Do nothing let the default values to be used.
} }
try { int maxPort = JiveGlobals.getIntProperty("mediaproxy.portMax", mediaProxy.getMaxPort());
int maxPort = Integer.valueOf(JiveGlobals.getProperty("plugin.rtpbridge.maxport"));
mediaProxy.setMaxPort(maxPort); mediaProxy.setMaxPort(maxPort);
} this.enabled = JiveGlobals.getBooleanProperty("mediaproxy.enabled");
catch (NumberFormatException e) {
// Do nothing let the default values to be used.
}
try {
boolean enabled = Boolean.valueOf(JiveGlobals.getProperty("plugin.rtpbridge.enabled"));
this.enabled = enabled;
}
catch (NumberFormatException e) {
this.enabled = false;
}
} }
public void destroy() { public void destroy() {
...@@ -211,7 +210,7 @@ public class MediaProxyService extends BasicModule implements ServerItemsProvide ...@@ -211,7 +210,7 @@ public class MediaProxyService extends BasicModule implements ServerItemsProvide
if (c != null) { if (c != null) {
Session session = mediaProxy.getAgent( MediaProxySession session = mediaProxy.getAgent(
childElementCopy.attribute("sid").getValue() + "-" + iq.getFrom()); childElementCopy.attribute("sid").getValue() + "-" + iq.getFrom());
Log.debug( Log.debug(
...@@ -357,7 +356,7 @@ public class MediaProxyService extends BasicModule implements ServerItemsProvide ...@@ -357,7 +356,7 @@ public class MediaProxyService extends BasicModule implements ServerItemsProvide
* *
* @return * @return
*/ */
public List<Session> getAgents() { public List<MediaProxySession> getAgents() {
return mediaProxy.getAgents(); return mediaProxy.getAgents();
} }
...@@ -368,16 +367,16 @@ public class MediaProxyService extends BasicModule implements ServerItemsProvide ...@@ -368,16 +367,16 @@ public class MediaProxyService extends BasicModule implements ServerItemsProvide
* @param delay time in millis * @param delay time in millis
*/ */
public void setKeepAliveDelay(long delay) { public void setKeepAliveDelay(long delay) {
mediaProxy.setKeepAliveDelay(delay); mediaProxy.setIdleTime(delay);
} }
/** /**
* Get the keep alive delay of the mediaproxy agents. * Returns the maximum amount of time (in milleseconds) that a session can
* When an agent stay more then this delay, the agent is destroyed. * be idle before it's closed.
* *
* @return delay time in millis * @return the max idle time in millis.
*/ */
public long getKeepAliveDelay() { public long getIdleTime() {
return mediaProxy.getKeepAliveDelay(); return mediaProxy.getKeepAliveDelay();
} }
......
package org.jivesoftware.wildfire.mediaproxy; package org.jivesoftware.wildfire.mediaproxy;
import org.jivesoftware.util.Log;
import java.util.*; import java.util.*;
import java.net.*; import java.net.*;
import java.io.IOException; import java.io.IOException;
/** /**
* A Session Class will control "receive and relay" proccess. * A media proxy session enables two clients to exchange UDP traffic. Each client connects to
* It creates an UDP channel from Host A to Host B and from Host B to Host A using their specified hosts and ports. * a UDP port and then the proxy is responsible for exchanging traffic. Each session uses
* It has 4 Channels. 2 for data and 2 for control. * a total of four ports: two for traffic exchange, and two control ports.
*
* @author Thiago Camargo
*/ */
public class Session extends Thread implements ProxyCandidate, DatagramListener { public class MediaProxySession extends Thread implements ProxyCandidate, DatagramListener {
private List<SessionListener> sessionListeners = new ArrayList<SessionListener>(); private List<SessionListener> sessionListeners = new ArrayList<SessionListener>();
...@@ -18,7 +22,7 @@ public class Session extends Thread implements ProxyCandidate, DatagramListener ...@@ -18,7 +22,7 @@ public class Session extends Thread implements ProxyCandidate, DatagramListener
private String creator = ""; private String creator = "";
private long timestamp = 0; private long timestamp = 0;
protected InetAddress localhost; protected InetAddress localAddress;
protected InetAddress hostA; protected InetAddress hostA;
protected InetAddress hostB; protected InetAddress hostB;
...@@ -43,7 +47,7 @@ public class Session extends Thread implements ProxyCandidate, DatagramListener ...@@ -43,7 +47,7 @@ public class Session extends Thread implements ProxyCandidate, DatagramListener
protected Thread threadBtoA; protected Thread threadBtoA;
protected Thread threadBtoAControl; protected Thread threadBtoAControl;
private Timer keepAliveTimer = null; private Timer idleTimer = null;
private int minPort = 10000; private int minPort = 10000;
private int maxPort = 20000; private int maxPort = 20000;
...@@ -52,51 +56,39 @@ public class Session extends Thread implements ProxyCandidate, DatagramListener ...@@ -52,51 +56,39 @@ public class Session extends Thread implements ProxyCandidate, DatagramListener
* Creates a new static UDP channel between Host A and Host B. * Creates a new static UDP channel between Host A and Host B.
* *
* @param id of the Session (Could be a Jingle session ID) * @param id of the Session (Could be a Jingle session ID)
* @param localhost The localhost IP that will listen for UDP packets * @param creator
* @param hostA the hostname or IP of the point A of the Channel * @param localAddress the localhost IP that will listen for UDP packets
* @param portA the port number point A of the Channel
* @param hostB the hostname or IP of the point B of the Channel
* @param portB the port number point B of the Channel
*/
public Session(String id, String creator, String localhost, String hostA, int portA, String hostB, int portB) {
this(id, creator, localhost, hostA, portA, hostB, portB,10000,20000);
}
/**
* Creates a new static UDP channel between Host A and Host B.
*
* @param id of the Session (Could be a Jingle session ID)
* @param localhost The localhost IP that will listen for UDP packets
* @param hostA the hostname or IP of the point A of the Channel * @param hostA the hostname or IP of the point A of the Channel
* @param portA the port number point A of the Channel * @param portA the port number point A of the Channel
* @param hostB the hostname or IP of the point B of the Channel * @param hostB the hostname or IP of the point B of the Channel
* @param portB the port number point B of the Channel * @param portB the port number point B of the Channel
* @param minPort
* @param maxPort
*/ */
public Session(String id, String creator, String localhost, String hostA, int portA, String hostB, int portB, int minPort, int maxPort) { public MediaProxySession(String id, String creator, String localAddress, String hostA, int portA, String hostB, int portB, int minPort, int maxPort) {
this.id = id; this.id = id;
this.creator = creator; this.creator = creator;
this.minPort = minPort; this.minPort = minPort;
this.maxPort = maxPort; this.maxPort = maxPort;
this.pass = String.valueOf(Math.abs(new Random().nextLong())); this.pass = String.valueOf(Math.abs(new Random().nextLong()));
try { try {
this.hostA = InetAddress.getByName(hostA); this.hostA = InetAddress.getByName(hostA);
this.hostB = InetAddress.getByName(hostB); this.hostB = InetAddress.getByName(hostB);
this.portA = portA; this.portA = portA;
this.portB = portB; this.portB = portB;
this.localhost = InetAddress.getByName(localhost); this.localAddress = InetAddress.getByName(localAddress);
this.localPortA = getFreePort(); this.localPortA = getFreePort();
this.socketA = new DatagramSocket(localPortA, this.localhost); this.socketA = new DatagramSocket(localPortA, this.localAddress);
this.socketAControl = new DatagramSocket(localPortA + 1, this.localhost); this.socketAControl = new DatagramSocket(localPortA + 1, this.localAddress);
this.localPortB = getFreePort(); this.localPortB = getFreePort();
this.socketB = new DatagramSocket(localPortB, this.localhost); this.socketB = new DatagramSocket(localPortB, this.localAddress);
this.socketBControl = new DatagramSocket(localPortB + 1, this.localhost); this.socketBControl = new DatagramSocket(localPortB + 1, this.localAddress);
System.out.println("Session Created at: A " + localPortA + " : B " + localPortB); Log.debug("Session Created at: A " + localPortA + " : B " + localPortB);
}
} catch (Exception e) { catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
...@@ -211,10 +203,10 @@ public class Session extends Thread implements ProxyCandidate, DatagramListener ...@@ -211,10 +203,10 @@ public class Session extends Thread implements ProxyCandidate, DatagramListener
public void stopAgent() { public void stopAgent() {
try { try {
if (keepAliveTimer != null) { if (idleTimer != null) {
keepAliveTimer.cancel(); idleTimer.cancel();
keepAliveTimer.purge(); idleTimer.purge();
keepAliveTimer = null; idleTimer = null;
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -250,7 +242,7 @@ public class Session extends Thread implements ProxyCandidate, DatagramListener ...@@ -250,7 +242,7 @@ public class Session extends Thread implements ProxyCandidate, DatagramListener
* @return * @return
*/ */
public InetAddress getLocalhost() { public InetAddress getLocalhost() {
return localhost; return localAddress;
} }
/** /**
...@@ -352,8 +344,9 @@ public class Session extends Thread implements ProxyCandidate, DatagramListener ...@@ -352,8 +344,9 @@ public class Session extends Thread implements ProxyCandidate, DatagramListener
channelAtoB.setPort(port); channelAtoB.setPort(port);
channelAtoBControl.setHost(address); channelAtoBControl.setHost(address);
channelAtoBControl.setPort(port + 1); channelAtoBControl.setPort(port + 1);
} catch (Exception e) { }
e.printStackTrace(); catch (Exception e) {
Log.error(e);
} }
} }
...@@ -364,8 +357,9 @@ public class Session extends Thread implements ProxyCandidate, DatagramListener ...@@ -364,8 +357,9 @@ public class Session extends Thread implements ProxyCandidate, DatagramListener
channelBtoA.setPort(port); channelBtoA.setPort(port);
channelBtoAControl.setHost(address); channelBtoAControl.setHost(address);
channelBtoAControl.setPort(port + 1); channelBtoAControl.setPort(port + 1);
} catch (Exception e) { }
e.printStackTrace(); catch (Exception e) {
Log.error(e);
} }
} }
...@@ -375,7 +369,7 @@ public class Session extends Thread implements ProxyCandidate, DatagramListener ...@@ -375,7 +369,7 @@ public class Session extends Thread implements ProxyCandidate, DatagramListener
* @param datagramPacket * @param datagramPacket
*/ */
public boolean datagramReceived(DatagramPacket datagramPacket) { public boolean datagramReceived(DatagramPacket datagramPacket) {
timestamp = new GregorianCalendar().getTimeInMillis(); timestamp = System.currentTimeMillis();
return true; return true;
} }
...@@ -386,9 +380,9 @@ public class Session extends Thread implements ProxyCandidate, DatagramListener ...@@ -386,9 +380,9 @@ public class Session extends Thread implements ProxyCandidate, DatagramListener
* @param delay delay time in millis to check if the channel is inactive * @param delay delay time in millis to check if the channel is inactive
*/ */
void addKeepAlive(long delay) { void addKeepAlive(long delay) {
if (keepAliveTimer != null) return; if (idleTimer != null) return;
keepAliveTimer = new Timer(); idleTimer = new Timer();
keepAliveTimer.scheduleAtFixedRate(new TimerTask() { idleTimer.scheduleAtFixedRate(new TimerTask() {
long lastTimeStamp = getTimestamp(); long lastTimeStamp = getTimestamp();
public void run() { public void run() {
...@@ -433,7 +427,7 @@ public class Session extends Thread implements ProxyCandidate, DatagramListener ...@@ -433,7 +427,7 @@ public class Session extends Thread implements ProxyCandidate, DatagramListener
public void dispatchAgentStopped() { public void dispatchAgentStopped() {
for (SessionListener sessionListener : sessionListeners) for (SessionListener sessionListener : sessionListeners)
try { try {
sessionListener.agentStopped(this); sessionListener.sessionClosed(this);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
...@@ -558,14 +552,15 @@ public class Session extends Thread implements ProxyCandidate, DatagramListener ...@@ -558,14 +552,15 @@ public class Session extends Thread implements ProxyCandidate, DatagramListener
if (resend) relayPacket(packet); if (resend) relayPacket(packet);
} }
} catch (UnknownHostException e) {
System.err.println("Unknown Host");
} }
catch (SocketException e) { catch (UnknownHostException uhe) {
System.err.println("Socket closed"); Log.error(uhe);
} catch (IOException e) { }
System.err.println("Communication error"); catch (SocketException se) {
e.printStackTrace(); Log.error(se);
}
catch (IOException ioe) {
Log.error(ioe);
} }
} }
...@@ -573,29 +568,11 @@ public class Session extends Thread implements ProxyCandidate, DatagramListener ...@@ -573,29 +568,11 @@ public class Session extends Thread implements ProxyCandidate, DatagramListener
try { try {
DatagramPacket echo = new DatagramPacket(packet.getData(), packet.getLength(), DatagramPacket echo = new DatagramPacket(packet.getData(), packet.getLength(),
host, port); host, port);
//System.out.println("Sent (" + packet.getAddress() + ":" + packet.getPort() + ") " + dataSocket.getLocalAddress() + ":" + dataSocket.getLocalPort() + " to " + host + ":" + port);
dataSocket.send(echo); dataSocket.send(echo);
} catch (IOException e) {
System.err.println("Communication error");
e.printStackTrace();
} }
catch (IOException e) {
Log.error(e);
} }
} }
public static void main(String args[]) {
try {
byte packet[] = {0, 0, 1, 1, 1, 1, 1};
DatagramSocket ds = new DatagramSocket(14004, InetAddress.getByName("0.0.0.0"));
DatagramPacket echo = new DatagramPacket(packet, packet.length,
InetAddress.getByName("10.1.1.3"), 16736);
for (int i = 0; i < 10; i++) {
System.out.print("\nSent");
ds.send(echo);
}
} catch (Exception e) {
System.out.print(e.toString());
}
} }
} }
\ No newline at end of file
/**
* $Revision$
* $Date$
*
* Copyright (C) 2007 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.wildfire.mediaproxy; package org.jivesoftware.wildfire.mediaproxy;
import java.net.InetAddress; import java.net.InetAddress;
......
/**
* $Revision$
* $Date$
*
* Copyright (C) 2007 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.wildfire.mediaproxy; package org.jivesoftware.wildfire.mediaproxy;
/** /**
* Listen for Session events * Listener for media proxy session events.
*
* @author Thiago Camargo
*/ */
public interface SessionListener { public interface SessionListener {
public void agentStopped(Session session); /**
* A media proxy session was closed as a result of normal termination or because
* the max idle time elapsed.
*
* @param session the session that closed.
*/
public void sessionClosed(MediaProxySession session);
} }
\ No newline at end of file
/**
* $Revision$
* $Date$
*
* Copyright (C) 2007 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.wildfire.mediaproxy; package org.jivesoftware.wildfire.mediaproxy;
import java.net.*; import java.net.*;
...@@ -16,7 +26,7 @@ import java.io.IOException; ...@@ -16,7 +26,7 @@ import java.io.IOException;
* It has 4 Channels. 2 for data and 2 for control. * It has 4 Channels. 2 for data and 2 for control.
*/ */
public class SmartSession extends Session { public class SmartSession extends MediaProxySession {
/** /**
* Creates a new Smart Session to provide connectivity between Host A and Host B. * Creates a new Smart Session to provide connectivity between Host A and Host B.
......
...@@ -132,14 +132,9 @@ ...@@ -132,14 +132,9 @@
<!-- Server Settings --> <!-- Server Settings -->
<sidebar id="sidebar-media-services" name="Media Services"> <sidebar id="sidebar-media-services" name="Media Services">
<!-- Media Proxy Settings --> <!-- Media Proxy Settings -->
<item id="media-proxy-service" name="Media Proxy Settings" <item id="media-proxy-service" name="Media Proxy"
url="media-proxy-properties.jsp" url="media-proxy.jsp"
description="Media Proxy Settings"/> description="Media proxy settings"/>
<!-- Media Proxy Session Summary -->
<item id="media-proxy-session-summary" name="Media Proxy Sessions"
url="media-proxy-session-summary.jsp"
description="Media Proxy Session Summary"/>
</sidebar> </sidebar>
......
...@@ -20,7 +20,7 @@ This page summarize every active Session in the RTP Media Proxy ...@@ -20,7 +20,7 @@ This page summarize every active Session in the RTP Media Proxy
%> %>
<%@ page import="org.jivesoftware.wildfire.mediaproxy.MediaProxyService" %> <%@ page import="org.jivesoftware.wildfire.mediaproxy.MediaProxyService" %>
<%@ page import="org.jivesoftware.wildfire.XMPPServer" %> <%@ page import="org.jivesoftware.wildfire.XMPPServer" %>
<%@ page import="org.jivesoftware.wildfire.mediaproxy.Session" %> <%@ page import="org.jivesoftware.wildfire.mediaproxy.MediaProxySession" %>
<%@ page import="org.jivesoftware.wildfire.mediaproxy.SmartSession" %> <%@ page import="org.jivesoftware.wildfire.mediaproxy.SmartSession" %>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %> <%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
...@@ -73,7 +73,7 @@ This page summarize every active Session in the RTP Media Proxy ...@@ -73,7 +73,7 @@ This page summarize every active Session in the RTP Media Proxy
<tbody> <tbody>
<% // Print the list of agents <% // Print the list of agents
List<Session> agents = mediaProxyService.getAgents(); List<MediaProxySession> agents = mediaProxyService.getAgents();
if (agents.isEmpty()) { if (agents.isEmpty()) {
%> %>
<tr> <tr>
...@@ -85,7 +85,7 @@ This page summarize every active Session in the RTP Media Proxy ...@@ -85,7 +85,7 @@ This page summarize every active Session in the RTP Media Proxy
<% <%
} }
int i = 0; int i = 0;
for (Session proxySession : agents) { for (MediaProxySession proxySession : agents) {
i++; i++;
%> %>
<tr class="jive-<%= (((i%2)==0) ? "even" : "odd") %>"> <tr class="jive-<%= (((i%2)==0) ? "even" : "odd") %>">
......
<%--
- $Revision: $
- $Date: $
-
- Copyright (C) 2006 Jive Software. All rights reserved.
-
- This software is published under the terms of the GNU Public License (GPL),
- a copy of which is included in this distribution.
--%>
<%@ page import="org.jivesoftware.util.JiveGlobals" %> <%@ page import="org.jivesoftware.util.JiveGlobals" %>
<%@ page import="org.jivesoftware.util.ParamUtils" %> <%@ page import="org.jivesoftware.util.ParamUtils" %>
<%@ page import="org.jivesoftware.wildfire.XMPPServer" %> <%@ page import="org.jivesoftware.wildfire.XMPPServer" %>
<%@ page import="org.jivesoftware.wildfire.mediaproxy.MediaProxyService" %> <%@ page import="org.jivesoftware.wildfire.mediaproxy.MediaProxyService" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt" %>
<% <%
MediaProxyService mediaProxyService = XMPPServer.getInstance().getMediaProxyService(); MediaProxyService mediaProxyService = XMPPServer.getInstance().getMediaProxyService();
...@@ -15,18 +29,18 @@ ...@@ -15,18 +29,18 @@
boolean enabled = false; boolean enabled = false;
if (save) { if (save) {
keepAliveDelay = ParamUtils.getLongParameter(request, "keepalivedelay", keepAliveDelay); keepAliveDelay = ParamUtils.getLongParameter(request, "keepalive", keepAliveDelay);
if (keepAliveDelay > 50) { if (keepAliveDelay > 50) {
mediaProxyService.setKeepAliveDelay(keepAliveDelay); mediaProxyService.setKeepAliveDelay(keepAliveDelay);
JiveGlobals JiveGlobals
.setProperty("plugin.rtpbridge.keepalivedelay", String.valueOf(keepAliveDelay)); .setProperty("mediaproxy.keepalive", String.valueOf(keepAliveDelay));
} }
minPort = ParamUtils.getIntParameter(request, "minport", minPort); minPort = ParamUtils.getIntParameter(request, "minport", minPort);
maxPort = ParamUtils.getIntParameter(request, "maxport", maxPort); maxPort = ParamUtils.getIntParameter(request, "maxport", maxPort);
enabled = ParamUtils.getBooleanParameter(request, "enabled", enabled); enabled = ParamUtils.getBooleanParameter(request, "enabled", enabled);
JiveGlobals.setProperty("plugin.rtpbridge.enabled", String.valueOf(enabled)); JiveGlobals.setProperty("mediaproxy.enabled", String.valueOf(enabled));
mediaProxyService.setEnabled(enabled); mediaProxyService.setEnabled(enabled);
...@@ -34,8 +48,8 @@ ...@@ -34,8 +48,8 @@
if (maxPort - minPort > 1000) { if (maxPort - minPort > 1000) {
mediaProxyService.setMinPort(minPort); mediaProxyService.setMinPort(minPort);
mediaProxyService.setMaxPort(maxPort); mediaProxyService.setMaxPort(maxPort);
JiveGlobals.setProperty("plugin.rtpbridge.minport", String.valueOf(minPort)); JiveGlobals.setProperty("mediaproxy.portMin", String.valueOf(minPort));
JiveGlobals.setProperty("plugin.rtpbridge.maxport", String.valueOf(maxPort)); JiveGlobals.setProperty("mediaproxy.portMax", String.valueOf(maxPort));
} }
} }
...@@ -45,13 +59,15 @@ ...@@ -45,13 +59,15 @@
%> %>
<html> <html>
<head> <head>
<title>Media Proxy Settings</title> <title>Media Proxy</title>
<meta name="pageID" content="media-proxy-service"/> <meta name="pageID" content="media-proxy-service"/>
</head> </head>
<body> <body>
<p> <p>
Use the form below to manage Media Proxy settings.<br> The media proxy enables clients to make rich media (including VoIP) connections to one another
when peer to peer connections fail, such as when one or both clients are behind a
strict firewall.<br>
</p> </p>
<% if (success) { %> <% if (success) { %>
...@@ -71,7 +87,53 @@ ...@@ -71,7 +87,53 @@
<% } %> <% } %>
<form action="media-proxy-properties.jsp" method="post"> <form action="media-proxy.jsp" method="post">
<div class="jive-contentBoxHeader">
Media Proxy Settings
</div>
<div class="jive-contentBox">
<table cellpadding="3" cellspacing="0" border="0">
<tbody>
<tr valign="middle">
<td width="1%" nowrap>
<input type="radio" name="proxyEnabled" value="true" id="rb02"
<%= (enabled ? "checked" : "") %> >
</td>
<td width="99%">
<label for="rb02">
<b>Enabled</b>
- This server will act as a media proxy.
</label>
<br>
Session Idle Timeout:&nbsp<input type="text" size="5" maxlength="8" name="idleTimeout"
value="<%=mediaProxyService.getIdleTime()/1000%>"
align="left">
<input type="text" size="5" maxlength="10" name="port"
value="<%= 38 %>" >
</td>
</tr>
<tr valign="middle">
<td width="1%" nowrap>
<input type="radio" name="proxyEnabled" value="false" id="rb01"
<%= (!enabled ? "checked" : "") %> >
</td>
<td width="99%">
<label for="rb01">
<b>Disabled</b>
- This server will not act as a media proxy.
</label>
</td>
</tr>
</tbody>
</table>
</div>
<input type="submit" name="update" value="<fmt:message key="global.save_settings" />">
</form>
<form action="media-proxy.jsp" method="post">
<fieldset> <fieldset>
<legend>Media Proxy Settings</legend> <legend>Media Proxy Settings</legend>
<div> <div>
...@@ -83,15 +145,15 @@ ...@@ -83,15 +145,15 @@
<table cellpadding="3" cellspacing="0" border="0" width="100%"> <table cellpadding="3" cellspacing="0" border="0" width="100%">
<tbody> <tbody>
<tr> <tr>
<td align="left">Keep Alive Delay:&nbsp<input type="text" size="20" <td align="left">Idle Timeout:&nbsp<input type="text" size="20"
maxlength="100" maxlength="100"
name="keepalivedelay" name="keepalivedelay"
value="<%=mediaProxyService.getKeepAliveDelay()%>" value="<%=mediaProxyService.getIdleTime()%>"
align="left"> align="left">
</td> </td>
</tr> </tr>
<tr> <tr>
<td align="left">Minimal Port Value:&nbsp<input type="text" size="20" <td align="left">Port Range: Min&nbsp<input type="text" size="20"
maxlength="100" maxlength="100"
name="minport" name="minport"
value="<%=mediaProxyService.getMinPort()%>" value="<%=mediaProxyService.getMinPort()%>"
...@@ -99,7 +161,7 @@ ...@@ -99,7 +161,7 @@
</td> </td>
</tr> </tr>
<tr> <tr>
<td align="left">Maximum Port Value:&nbsp<input type="text" size="20" <td align="left">Max:&nbsp<input type="text" size="20"
maxlength="100" maxlength="100"
name="maxport" name="maxport"
value="<%=mediaProxyService.getMaxPort()%>" value="<%=mediaProxyService.getMaxPort()%>"
......
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