Commit 767dc473 authored by jehan's avatar jehan

add seeding server retrieval from url

git-svn-id: svn+ssh://svn.savannah.nongnu.org/linphone/trunk@174 3f6dc0c8-ddfe-455d-9043-3cd528dc4637
parent 26d35611
......@@ -82,6 +82,9 @@ public class JxtaNetworkManager {
public final static String HTTP_LISTENING_PORT="org.linphone.p2pproxy.JxtaNetworkManager.http.port";
public final static String HTTP_LISTENING_PUBLIC_ADDRESS="org.linphone.p2pproxy.JxtaNetworkManager.http.listening.public.address";
public final static String TCP_LISTENING_PUBLIC_ADDRESS="org.linphone.p2pproxy.JxtaNetworkManager.tcp.listening.public.address";
public final static String SEEDING_RDV_URL="org.linphone.p2pproxy.JxtaNetworkManager.seeding-rdv.url-location";
public final static String SEEDING_RELAY_URL="org.linphone.p2pproxy.JxtaNetworkManager.seeding-relay.url-location";
public final static String SO_TIMEOUT="org.linphone.p2pproxy.so-timout";
public final static String ENABLE_HTTP_CLIENT="org.linphone.p2pproxy.JxtaNetworkManager.http.client.enable";
public static int EDGE_MODE = NetworkConfigurator.TCP_CLIENT| NetworkConfigurator.RDV_CLIENT | NetworkConfigurator.RELAY_CLIENT;
......@@ -111,74 +114,92 @@ public class JxtaNetworkManager {
* @throws CertificateException
*/
public JxtaNetworkManager(Configurator aProperties,File aConfigDir) throws JxtaException, InterruptedException, P2pProxyException, IOException, URISyntaxException, CertificateException {
super();
// get configuration
//System.setProperty("JXTA_HOME", aConfigDir.getAbsolutePath());
NetworkConfigurator lNetworkConfigurator;
mProperties = aProperties;
// set mode
mMode = Mode.valueOf(aProperties.getProperty(MODE, Mode.edge.name()));
int lMode;
if (mMode == Mode.relay || mMode == Mode.seeding_server) {
lMode = SUPER_PEER_MODE;
} else {
lMode = EDGE_MODE;
}
if (aProperties.getProperty(ENABLE_HTTP_CLIENT) != null && Boolean.parseBoolean(aProperties.getProperty(ENABLE_HTTP_CLIENT)) == true) {
lMode = lMode | NetworkConfigurator.HTTP_CLIENT;
}
lNetworkConfigurator = new NetworkConfigurator(lMode,aConfigDir.toURI());
if (!lNetworkConfigurator.exists()) {
lNetworkConfigurator.setPeerID(IDFactory.newPeerID(PeerGroupID.defaultNetPeerGroupID));
lNetworkConfigurator.setName(InetAddress.getLocalHost().toString()+" "+aProperties.getProperty(TCP_LISTENING_PORT));
lNetworkConfigurator.setDescription("p2p proxy instance");
lNetworkConfigurator.save();
} else {
lNetworkConfigurator.load();
}
//mode is alway taken from start line
lNetworkConfigurator.setMode(lMode);
// set sedding host
if (aProperties.getProperty(SEEDING_RDV) != null) {
StringTokenizer lSeedingRdvList = new StringTokenizer(aProperties.getProperty(SEEDING_RDV),"|" );
while (lSeedingRdvList.hasMoreTokens()) {
lNetworkConfigurator.addSeedRendezvous(new URI(lSeedingRdvList.nextToken()));
}
}
if (aProperties.getProperty(SEEDING_RELAY) != null) {
StringTokenizer lSeedingRelayList = new StringTokenizer(aProperties.getProperty(SEEDING_RELAY),"|" );
while (lSeedingRelayList.hasMoreTokens()) {
lNetworkConfigurator.addSeedRelay(new URI(lSeedingRelayList.nextToken()));
}
}
if (aProperties.getProperty(HTTP_LISTENING_PUBLIC_ADDRESS) != null) {
lNetworkConfigurator.setHttpPublicAddress(aProperties.getProperty(HTTP_LISTENING_PUBLIC_ADDRESS), true);
}
// set listening ports
if (aProperties.getProperty(HTTP_LISTENING_PORT) != null) {
lNetworkConfigurator.setHttpPort(Integer.parseInt(aProperties.getProperty(HTTP_LISTENING_PORT)));
}
if (aProperties.getProperty(TCP_LISTENING_PUBLIC_ADDRESS) != null) {
lNetworkConfigurator.setTcpPublicAddress(aProperties.getProperty(TCP_LISTENING_PUBLIC_ADDRESS), true);
lNetworkConfigurator.setTcpStartPort(-1);
lNetworkConfigurator.setTcpEndPort(-1);
}
super();
// get configuration
//System.setProperty("JXTA_HOME", aConfigDir.getAbsolutePath());
NetworkConfigurator lNetworkConfigurator;
mProperties = aProperties;
// set mode
mMode = Mode.valueOf(aProperties.getProperty(MODE, Mode.edge.name()));
int lMode;
if (mMode == Mode.relay || mMode == Mode.seeding_server) {
lMode = SUPER_PEER_MODE;
} else {
lMode = EDGE_MODE;
}
if (aProperties.getProperty(ENABLE_HTTP_CLIENT) != null && Boolean.parseBoolean(aProperties.getProperty(ENABLE_HTTP_CLIENT)) == true) {
lMode = lMode | NetworkConfigurator.HTTP_CLIENT;
}
lNetworkConfigurator = new NetworkConfigurator(lMode,aConfigDir.toURI());
if (!lNetworkConfigurator.exists()) {
lNetworkConfigurator.setPeerID(IDFactory.newPeerID(PeerGroupID.defaultNetPeerGroupID));
lNetworkConfigurator.setName(InetAddress.getLocalHost().toString()+" "+aProperties.getProperty(TCP_LISTENING_PORT));
lNetworkConfigurator.setDescription("p2p proxy instance");
lNetworkConfigurator.save();
} else {
lNetworkConfigurator.load();
}
//mode is alway taken from start line
lNetworkConfigurator.setMode(lMode);
// set sedding host
if (aProperties.getProperty(SEEDING_RDV) != null) {
StringTokenizer lSeedingRdvList = new StringTokenizer(aProperties.getProperty(SEEDING_RDV),"|" );
while (lSeedingRdvList.hasMoreTokens()) {
lNetworkConfigurator.addSeedRendezvous(new URI(lSeedingRdvList.nextToken()));
}
}
if (aProperties.getProperty(SEEDING_RELAY) != null) {
StringTokenizer lSeedingRelayList = new StringTokenizer(aProperties.getProperty(SEEDING_RELAY),"|" );
while (lSeedingRelayList.hasMoreTokens()) {
lNetworkConfigurator.addSeedRelay(new URI(lSeedingRelayList.nextToken()));
}
}
if (aProperties.getProperty(SEEDING_RDV_URL) != null) {
StringTokenizer lSeedingRdvList = new StringTokenizer(aProperties.getProperty(SEEDING_RDV_URL),"|" );
while (lSeedingRdvList.hasMoreTokens()) {
lNetworkConfigurator.addRdvSeedingURI(new URI(lSeedingRdvList.nextToken()));
}
} else {
lNetworkConfigurator.addRdvSeedingURI("http://seeding.fonis.net/rdv");
}
if (aProperties.getProperty(SEEDING_RELAY_URL) != null) {
StringTokenizer lSeedingRelayList = new StringTokenizer(aProperties.getProperty(SEEDING_RELAY_URL),"|" );
while (lSeedingRelayList.hasMoreTokens()) {
lNetworkConfigurator.addRelaySeedingURI(new URI(lSeedingRelayList.nextToken()));
}
} else {
lNetworkConfigurator.addRelaySeedingURI("http://seeding.fonis.net/relay");
}
if (aProperties.getProperty(HTTP_LISTENING_PUBLIC_ADDRESS) != null) {
lNetworkConfigurator.setHttpPublicAddress(aProperties.getProperty(HTTP_LISTENING_PUBLIC_ADDRESS), true);
}
// set listening ports
if (aProperties.getProperty(HTTP_LISTENING_PORT) != null) {
lNetworkConfigurator.setHttpPort(Integer.parseInt(aProperties.getProperty(HTTP_LISTENING_PORT)));
}
if (aProperties.getProperty(TCP_LISTENING_PUBLIC_ADDRESS) != null) {
lNetworkConfigurator.setTcpPublicAddress(aProperties.getProperty(TCP_LISTENING_PUBLIC_ADDRESS), true);
lNetworkConfigurator.setTcpStartPort(-1);
lNetworkConfigurator.setTcpEndPort(-1);
}
if (aProperties.getProperty(TCP_LISTENING_PORT) != null) {
lNetworkConfigurator.setTcpPort(Integer.parseInt(aProperties.getProperty(TCP_LISTENING_PORT)));
}
// connect to rdv
int lRdvConnectionTimout = Integer.parseInt(aProperties.getProperty(RDV_CONNECT_TIMEOUT,"60000"));
init(lNetworkConfigurator,lRdvConnectionTimout,mMode);
if (aProperties.getProperty(TCP_LISTENING_PORT) != null) {
lNetworkConfigurator.setTcpPort(Integer.parseInt(aProperties.getProperty(TCP_LISTENING_PORT)));
}
// connect to rdv
int lRdvConnectionTimout = Integer.parseInt(aProperties.getProperty(RDV_CONNECT_TIMEOUT,"60000"));
init(lNetworkConfigurator,lRdvConnectionTimout,mMode);
}
/**
* @param aProperties use to store pipe ID
......
......@@ -79,7 +79,7 @@ public class MediaResourceService implements ServiceProvider {
try {
mStunRtpServerAdvertisement = (NetworkResourceAdvertisement) AdvertisementFactory.newAdvertisement(NetworkResourceAdvertisement.getAdvertisementType());
mStunRtpServerAdvertisement.setAddress("udp://"+mConfig.getAudioVideoPublicSocketAddress().getAddress().getHostAddress()+":"+mConfig.getAudioVideoPublicSocketAddress().getPort());
mStunRtpServerAdvertisement.setID(IDFactory.newCodatID(mJxtaNetworkManager.getPeerGroup().getPeerGroupID()/*, mStunRtpServerAdvertisement.getAddress().getBytes("US-ASCII")*/));
mStunRtpServerAdvertisement.setID(IDFactory.newCodatID(mJxtaNetworkManager.getPeerGroup().getPeerGroupID(), Integer.toHexString(mStunRtpServerAdvertisement.getAddress().hashCode()).getBytes("US-ASCII")));
mStunRtpServerAdvertisement.setName(ADV_NAME);
mJxtaNetworkManager.getPeerGroup().getDiscoveryService().publish(mStunRtpServerAdvertisement,ADV_LIFE_TIME,ADV_LIFE_TIME/2);
mLog.info(mStunRtpServerAdvertisement + "published");
......
......@@ -394,7 +394,7 @@ public void stop() {
private void publishAdvertisement() throws IOException {
if (mProxyRegistrationAdvertisement == null) {
mProxyRegistrationAdvertisement = (NetworkResourceAdvertisement) AdvertisementFactory.newAdvertisement(NetworkResourceAdvertisement.getAdvertisementType());
mProxyRegistrationAdvertisement.setID(IDFactory.newCodatID(mJxtaNetworkManager.getPeerGroup().getPeerGroupID()/*, mSuperPeerProxy.getSipProxyRegistrarAddress().getBytes("US-ASCII")*/));
mProxyRegistrationAdvertisement.setID(IDFactory.newCodatID(mJxtaNetworkManager.getPeerGroup().getPeerGroupID(), Integer.toHexString(mSuperPeerProxy.getSipProxyRegistrarAddress().hashCode()).getBytes("US-ASCII")));
mProxyRegistrationAdvertisement.setAddress(mSuperPeerProxy.getSipProxyRegistrarAddress());
mProxyRegistrationAdvertisement.setName(ADV_NAME);
}
......
......@@ -77,6 +77,9 @@ public class StunClient {
throw new P2pProxyException(e);
}
}
public List<InetSocketAddress> getStrunServerList() {
return mStunServerList;
}
private List<InetSocketAddress> acquireStunServerAddress() throws P2pProxyAdvertisementNotFoundException, InterruptedException, IOException {
List<NetworkResourceAdvertisement> lStunServerAdv = (List<NetworkResourceAdvertisement>) mJxtaNetworkManager.getAdvertisementList(null, MediaResourceService.ADV_NAME, true);
List<InetSocketAddress> lSocketAddressList = new ArrayList<InetSocketAddress>(lStunServerAdv.size());
......
......@@ -12,6 +12,7 @@ import junit.framework.Assert;
import junit.framework.TestCase;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;
import org.junit.After;
import org.junit.Before;
import org.linphone.p2pproxy.core.GenericUdpSession;
......@@ -19,7 +20,7 @@ import org.linphone.p2pproxy.core.media.rtprelay.RtpRelayServer;
import org.linphone.p2pproxy.core.stun.StunServer;
public class RtpRelayServerTester extends TestCase{
private final static Logger mLog = Logger.getLogger(RtpRelayServerTester.class);
static private RtpRelayServer mRtpRelayServer;
static private int RTP_SERVER_PORT = 16000;
private static GenericUdpSession mGenericUdpSession;
......@@ -82,26 +83,26 @@ public class RtpRelayServerTester extends TestCase{
try {
//1 send rtcp app A
DatagramSocket lRtcpSocketA = new DatagramSocket(new InetSocketAddress("localhost", 0));
DatagramSocket lRtcpSocketA = new DatagramSocket();
DatagramPacket lRtcpaPacket = new DatagramPacket(lRtcpA,lRtcpA.length,mServerSocket);
lRtcpSocketA.setSoTimeout(SO_TIMEOUT);
lRtcpSocketA.send(lRtcpaPacket);
//2 send rtcp app B
DatagramSocket lRtcpSocketB = new DatagramSocket(new InetSocketAddress("localhost", 0));
DatagramSocket lRtcpSocketB = new DatagramSocket();
DatagramPacket lRtcpbPacket = new DatagramPacket(lRtcpB,lRtcpB.length,mServerSocket);
lRtcpSocketB.setSoTimeout(SO_TIMEOUT);
lRtcpSocketB.send(lRtcpbPacket);
//3 send rtp A
DatagramSocket lRtpSocketA = new DatagramSocket(new InetSocketAddress("localhost", 0));
DatagramSocket lRtpSocketA = new DatagramSocket();
DatagramPacket lRtpaPacket = new DatagramPacket(lRtpA,lRtpA.length,mServerSocket);
lRtpSocketA.setSoTimeout(SO_TIMEOUT);
lRtpSocketA.send(lRtpaPacket);
//4 send rtp B
DatagramSocket lRtpSocketB = new DatagramSocket(new InetSocketAddress("localhost", 0));
DatagramSocket lRtpSocketB = new DatagramSocket();
DatagramPacket lRtpblPacket = new DatagramPacket(lRtpB,lRtpB.length,mServerSocket);
lRtpSocketB.send(lRtpblPacket);
lRtpSocketB.setSoTimeout(SO_TIMEOUT);
......
......@@ -36,6 +36,7 @@ import org.linphone.p2pproxy.core.media.MediaResoureUnreachableException;
import org.linphone.p2pproxy.core.stun.AddressInfo;
import org.linphone.p2pproxy.core.stun.StunClient;
import org.linphone.p2pproxy.launcher.P2pProxylauncherConstants;
import org.linphone.p2pproxy.test.RtpRelayServerTester;
import org.zoolu.net.SocketAddress;
import org.zoolu.sip.provider.SipProvider;
import org.zoolu.sip.provider.SipStack;
......@@ -45,7 +46,8 @@ private final Thread mFonisThread;
private Timer mTimer = new Timer("Registartion timer");
private final SipProvider mProvider;
private final SipClient mSipClient;
private StunClient mStunClient;
private RtpRelayServerTester mRtpRelayServerTester;
private StunClient mStunClient;
private final int REGISTRATION_PERIOD=60;
private final static Logger mLog = Logger.getLogger(UserInstance.class);
private static boolean mIsRegistered = false;
......@@ -122,7 +124,14 @@ public UserInstance(final String userName,final String aPreferedProxyUri) throws
P2pProxyMain.revokeMediaServer(pex.getResourceAddress());
}
mSipClient.register(REGISTRATION_PERIOD,userName);
try{
mSipClient.register(REGISTRATION_PERIOD,userName);
}catch(Exception e) {
mLog.error("registration error", e);
}
if (lMediaServer.length > 0) {
mRtpRelayServerTester = new RtpRelayServerTester(mStunClient.getStrunServerList().get(0));
}
mIsRegistered = true;
}
catch(Exception e) {
......@@ -141,6 +150,10 @@ public UserInstance(final String userName,final String aPreferedProxyUri) throws
}
public void call(String aTo, int duration) {
mSipClient.call(aTo, true, duration);
if (mRtpRelayServerTester != null) {
mRtpRelayServerTester.testRouting();
mLog.info("rtp relay ok");
}
}
public static void main(String[] args) throws P2pProxyException {
String lFrom=null, lTo=null, lPreferedProxyUri=null;
......
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