From 78f9d28125b00dd90eeebd9133ad0bcfc743ee8f Mon Sep 17 00:00:00 2001 From: jehan Date: Mon, 3 Nov 2008 15:11:21 +0000 Subject: [PATCH] add stun client to UserInstance tester git-svn-id: svn+ssh://svn.savannah.nongnu.org/linphone/trunk@154 3f6dc0c8-ddfe-455d-9043-3cd528dc4637 --- .../org/linphone/p2pproxy/core/P2pProxyMain.java | 10 ++++++++++ .../org/linphone/p2pproxy/core/stun/StunClient.java | 9 +++++++++ .../linphone/p2pproxy/test/utils/UserInstance.java | 13 ++++++++++--- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/p2pproxy/src/org/linphone/p2pproxy/core/P2pProxyMain.java b/p2pproxy/src/org/linphone/p2pproxy/core/P2pProxyMain.java index f49b0b6b7..146c3c3e4 100644 --- a/p2pproxy/src/org/linphone/p2pproxy/core/P2pProxyMain.java +++ b/p2pproxy/src/org/linphone/p2pproxy/core/P2pProxyMain.java @@ -476,6 +476,7 @@ public static String lookupSipProxyUri(String aDomaine) { return null; } } + public static String[] lookupSipProxiesUri(String aDomaine) { try { isReady(); @@ -485,6 +486,15 @@ public static String[] lookupSipProxiesUri(String aDomaine) { } } +public static String[] lookupMediaServerAddress(String aDomaine) { + try { + isReady(); + return mP2pProxyManagement.getMediaServerList(); + } catch (Exception e) { + return null; + } +} + public static int getState() { try { isReady(); diff --git a/p2pproxy/src/org/linphone/p2pproxy/core/stun/StunClient.java b/p2pproxy/src/org/linphone/p2pproxy/core/stun/StunClient.java index 27d3f2400..12c604e2c 100644 --- a/p2pproxy/src/org/linphone/p2pproxy/core/stun/StunClient.java +++ b/p2pproxy/src/org/linphone/p2pproxy/core/stun/StunClient.java @@ -51,6 +51,15 @@ public class StunClient { private int SO_TIME_OUT = 300; + public StunClient(String[] aStunServerList) { + List lAddressList = new ArrayList(); + for (String lStunInstance:aStunServerList) { + URI lUri = URI.create(lStunInstance); + InetSocketAddress lInetSocketAddress = new InetSocketAddress(lUri.getHost(),lUri.getPort()); + lAddressList.add(lInetSocketAddress); + } + mStunServerList = lAddressList; + } StunClient(List aStunServerList) { mStunServerList = aStunServerList; } diff --git a/p2pproxy/test-src/org/linphone/p2pproxy/test/utils/UserInstance.java b/p2pproxy/test-src/org/linphone/p2pproxy/test/utils/UserInstance.java index 051ebd0e8..ae69f4a64 100644 --- a/p2pproxy/test-src/org/linphone/p2pproxy/test/utils/UserInstance.java +++ b/p2pproxy/test-src/org/linphone/p2pproxy/test/utils/UserInstance.java @@ -31,6 +31,7 @@ import org.apache.log4j.Logger; import org.linphone.p2pproxy.api.P2pProxyException; import org.linphone.p2pproxy.api.P2pProxyResourceManagement; import org.linphone.p2pproxy.core.P2pProxyMain; +import org.linphone.p2pproxy.core.stun.StunClient; import org.linphone.p2pproxy.launcher.P2pProxylauncherConstants; import org.zoolu.net.SocketAddress; import org.zoolu.sip.provider.SipProvider; @@ -41,6 +42,7 @@ private final Thread mFonisThread; private Timer mTimer = new Timer("Registartion timer"); private final SipProvider mProvider; private final SipClient mSipClient; +private StunClient mStunClient; private final int REGISTRATION_PERIOD=60; private final static Logger mLog = Logger.getLogger(UserInstance.class); private static boolean mIsRegistered = false; @@ -79,6 +81,7 @@ public UserInstance(final String userName,final String aPreferedProxyUri) throws //InetAddress[] lAddresses = InetAddress.getAllByName("localhost"); mProvider=new SipProvider(null,lSipPort); mSipClient = new SipClient(mProvider,userName,30000); + class RegistrarTimerTask extends TimerTask { @Override public void run() { @@ -102,6 +105,10 @@ public UserInstance(final String userName,final String aPreferedProxyUri) throws //2 setOutbound proxy mProvider.setOutboundProxy(new SocketAddress(lProxyUri.getRawSchemeSpecificPart())); mLog.info("use outband proxy ["+mProvider.getOutboundProxy()+"]"); + //3 setup stun client + + String [] lMediaServer = P2pProxyMain.lookupMediaServerAddress(P2pProxyResourceManagement.DOMAINE); + mStunClient = new StunClient(lMediaServer); mSipClient.register(REGISTRATION_PERIOD,userName); mIsRegistered = true; } catch(Exception e) { @@ -112,7 +119,7 @@ public UserInstance(final String userName,final String aPreferedProxyUri) throws } }; - mTimer.schedule(new RegistrarTimerTask(), REGISTRATION_PERIOD-REGISTRATION_PERIOD/10); + mTimer.schedule(new RegistrarTimerTask(), 0); mSipClient.listen(); } catch (Exception e) { throw new P2pProxyException("cannot start client",e); @@ -123,7 +130,7 @@ public void call(String aTo, int duration) { } public static void main(String[] args) throws P2pProxyException { String lFrom=null, lTo=null, lPreferedProxyUri=null; - int lDuration = 10, lLoop=0; + int lDuration = 10000, lLoop=0; for (int i=0; i < args.length; i=i+2) { String argument = args[i]; if (argument.equals("-from")) { @@ -157,7 +164,7 @@ public static void main(String[] args) throws P2pProxyException { usage(); System.exit(1); } - if (lTo == null) { + if (lLoop != 0 && lTo == null) { System.out.println("missing -to "); usage(); System.exit(1);