From 933a8982a333b053c505a98613fef7daa20e846c Mon Sep 17 00:00:00 2001 From: jehan Date: Sun, 19 Oct 2008 19:21:24 +0000 Subject: [PATCH] start UserInstance testing git-svn-id: svn+ssh://svn.savannah.nongnu.org/linphone/trunk@104 3f6dc0c8-ddfe-455d-9043-3cd528dc4637 --- .../linphone/p2pproxy/core/P2pProxyMain.java | 13 ++-- .../p2pproxy/test/utils/UserInstance.java | 59 +++++++++++++++---- 2 files changed, 52 insertions(+), 20 deletions(-) diff --git a/p2pproxy/src/org/linphone/p2pproxy/core/P2pProxyMain.java b/p2pproxy/src/org/linphone/p2pproxy/core/P2pProxyMain.java index ca91acb46..89950347d 100644 --- a/p2pproxy/src/org/linphone/p2pproxy/core/P2pProxyMain.java +++ b/p2pproxy/src/org/linphone/p2pproxy/core/P2pProxyMain.java @@ -269,17 +269,10 @@ public class P2pProxyMain implements P2pProxyMainMBean { //setup account manager mP2pProxyAccountManagement = new P2pProxyAccountManagement(mJxtaNetworkManager); - // setup sip provider - SipStack.log_path = mConfigHomeDir+"/logs"; - mSipAndPipeListener = new SipProxyRegistrar(mConfigurator,mJxtaNetworkManager,mP2pProxyAccountManagement); //set management try { ObjectName lObjectName = new ObjectName(ACCOUNT_MGR_MBEAN_NAME); ManagementFactory.getPlatformMBeanServer().registerMBean(mP2pProxyAccountManagement,lObjectName); - - lObjectName = new ObjectName(PROXY_REG_MBEAN_NAME); - ManagementFactory.getPlatformMBeanServer().registerMBean(mSipAndPipeListener,lObjectName); - } catch (Exception e) { mLog.warn("cannot register MBean",e); } @@ -418,7 +411,11 @@ private static void isReady() throws P2pProxyNotReadyException { (mJxtaNetworkManager!=null && mJxtaNetworkManager.getPeerGroup().getRendezVousService().isRendezVous())) { //nop connected } else { - throw new P2pProxyNotReadyException("not connected to any rdv: status ["+mJxtaNetworkManager.getPeerGroup().getRendezVousService().getRendezVousStatus()+"]"); + if (mJxtaNetworkManager != null ) { + throw new P2pProxyNotReadyException("not connected to any rdv: status ["+mJxtaNetworkManager.getPeerGroup().getRendezVousService().getRendezVousStatus()+"]"); + } else { + throw new P2pProxyNotReadyException("initializing"); + } } } catch (InterruptedException e) { throw new P2pProxyNotReadyException(e); 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 1c220bb82..79ebb1598 100644 --- a/p2pproxy/test-src/org/linphone/p2pproxy/test/utils/UserInstance.java +++ b/p2pproxy/test-src/org/linphone/p2pproxy/test/utils/UserInstance.java @@ -22,6 +22,7 @@ package org.linphone.p2pproxy.test.utils; import java.io.File; import java.net.DatagramSocket; +import java.net.URI; import java.util.Timer; import java.util.TimerTask; @@ -36,21 +37,23 @@ import org.zoolu.sip.provider.SipStack; public class UserInstance { private final Thread mFonisThread; -private Timer mTimer; +private Timer mTimer = new Timer("Registartion timer"); private final SipProvider mProvider; private final SipClient mSipClient; private final int REGISTRATION_PERIOD=60; private final static Logger mLog = Logger.getLogger(UserInstance.class); +private static boolean mIsRegistered = false; public UserInstance(final String userName) throws P2pProxyException { try { DatagramSocket lSocket = new DatagramSocket(); lSocket.setReuseAddress(true); int lSipPort = lSocket.getLocalPort(); lSocket.close(); - final String[] lParam = {"-jxta userinstance-"+userName - ," -edge-only" - ," -seeding-rdv tcp://82.67.74.86:9701" - ," -seeding-relay tcp://82.67.74.86:9701"}; + URI lUserNameUri = URI.create(userName); + final String[] lParam = {"-jxta" ,"userinstance-"+lUserNameUri.getUserInfo() + ,"-edge-only" + ,"-seeding-rdv", "tcp://82.67.74.86:9701" + ,"-seeding-relay", "tcp://82.67.74.86:9701"}; lSocket.close(); Runnable lFonisTask = new Runnable() { @@ -69,7 +72,7 @@ public UserInstance(final String userName) throws P2pProxyException { throw new P2pProxyException("Cannot connect to fonis network"); } P2pProxyMain.createAccount(userName); - SipStack.log_path = "userinstance-"+userName+"/logs"; + SipStack.log_path = "userinstance-"+lUserNameUri.getUserInfo()+"/logs"; File lFile = new File(SipStack.log_path); if (lFile.exists() == false) lFile.mkdir(); mProvider=new SipProvider(null,lSipPort); @@ -80,9 +83,14 @@ public UserInstance(final String userName) throws P2pProxyException { try { // 1 get proxy address String lProxyUri = P2pProxyMain.lookupSipProxyUri(P2pProxyResourceManagement.DOMAINE); + if (lProxyUri == null) { + System.out.println("cannot find registrar"); + return; + } //2 setOutbound proxy mProvider.setOutboundProxy(new SocketAddress(lProxyUri)); mSipClient.register(REGISTRATION_PERIOD,userName); + mIsRegistered = true; } catch(Exception e) { mLog.error("cannot register user["+userName+"]",e); } finally { @@ -100,8 +108,8 @@ public UserInstance(final String userName) throws P2pProxyException { public void call(String aTo, int duration) { mSipClient.call(aTo, true, duration); } -static int main(String[] args) throws P2pProxyException { - String lFrom="sip:toto", lTo; +public static void main(String[] args) throws P2pProxyException { + String lFrom=null, lTo=null; int lDuration = 10, lLoop=1; for (int i=0; i < args.length; i=i+2) { String argument = args[i]; @@ -120,16 +128,43 @@ static int main(String[] args) throws P2pProxyException { } else if (argument.equals("-nb-call")) { lLoop = Integer.parseInt(args[i + 1]); System.out.println("nb-call [" + lLoop + "]"); - + isRegistered } else { System.out.println("Invalid option: " + args[i]); usage(); System.exit(1); } - } UserInstance lUserInstance= new UserInstance(lFrom); - for (int i=0;i