From 8103c6d88b2ef1ba4862067f26bf37733dfbd0fd Mon Sep 17 00:00:00 2001 From: jehan Date: Tue, 21 Oct 2008 20:06:20 +0000 Subject: [PATCH] debug sip proxy git-svn-id: svn+ssh://svn.savannah.nongnu.org/linphone/trunk@111 3f6dc0c8-ddfe-455d-9043-3cd528dc4637 --- p2pproxy/launcher/.cdtproject | 12 +++++++++++ .../linphone/p2pproxy/core/P2pProxyMain.java | 7 ++++--- .../core/sipproxy/SipProxyRegistrar.java | 5 +++-- .../sipproxy/superpeers/SuperPeerProxy.java | 17 ++++++++------- .../p2pproxy/test/utils/SipClient.java | 21 ++++++++++--------- .../p2pproxy/test/utils/UserInstance.java | 12 ++++++----- 6 files changed, 47 insertions(+), 27 deletions(-) create mode 100644 p2pproxy/launcher/.cdtproject diff --git a/p2pproxy/launcher/.cdtproject b/p2pproxy/launcher/.cdtproject new file mode 100644 index 000000000..a080fffa3 --- /dev/null +++ b/p2pproxy/launcher/.cdtproject @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/p2pproxy/src/org/linphone/p2pproxy/core/P2pProxyMain.java b/p2pproxy/src/org/linphone/p2pproxy/core/P2pProxyMain.java index 577a58f50..eff98dc2b 100644 --- a/p2pproxy/src/org/linphone/p2pproxy/core/P2pProxyMain.java +++ b/p2pproxy/src/org/linphone/p2pproxy/core/P2pProxyMain.java @@ -61,6 +61,7 @@ public class P2pProxyMain implements P2pProxyMainMBean { private static Configurator mConfigurator; private static String mConfigHomeDir; static private boolean mExit = false; + static private boolean isReady = false; static { @@ -279,7 +280,7 @@ public class P2pProxyMain implements P2pProxyMainMBean { mLog.warn("p2pproxy initilized"); - + isReady = true; while (mExit == false) { Thread.sleep(1000); } @@ -412,9 +413,9 @@ public static void staticLoadTraceConfigFile() throws P2pProxyException { private static void isReady() throws P2pProxyNotReadyException { try { - if ((mJxtaNetworkManager!=null && mJxtaNetworkManager.isConnectedToRendezVous(0) == true) + if ((isReady == true && mJxtaNetworkManager.isConnectedToRendezVous(0) == true) || - (mJxtaNetworkManager!=null && mJxtaNetworkManager.getPeerGroup().getRendezVousService().isRendezVous())) { + (isReady == true && mJxtaNetworkManager.getPeerGroup().getRendezVousService().isRendezVous())) { //nop connected } else { if (mJxtaNetworkManager != null ) { diff --git a/p2pproxy/src/org/linphone/p2pproxy/core/sipproxy/SipProxyRegistrar.java b/p2pproxy/src/org/linphone/p2pproxy/core/sipproxy/SipProxyRegistrar.java index 17b9b22d8..08704a16f 100644 --- a/p2pproxy/src/org/linphone/p2pproxy/core/sipproxy/SipProxyRegistrar.java +++ b/p2pproxy/src/org/linphone/p2pproxy/core/sipproxy/SipProxyRegistrar.java @@ -299,7 +299,8 @@ public class SipProxyRegistrar implements SipProviderListener,SipProxyRegistrarM if (mP2pProxyAccountManagement.isValidAccount(lFromName)) { lRegistration = new Registration(lFromName); - lRegistration.Contact = aMessage.getContactHeader().getNameAddress().getAddress().toString();; + // forgot contact, use rport lRegistration.Contact = aMessage.getContactHeader().getNameAddress().getAddress().toString();; + updateRegistration(lRegistration,aMessage); mRegistrationTab.put(lFromName, lRegistration); } else { @@ -325,7 +326,7 @@ public class SipProxyRegistrar implements SipProviderListener,SipProxyRegistrarM if (aRegistrationMessage.getExpiresHeader() != null ) { aRegistration.Expiration = aRegistrationMessage.getExpiresHeader().getDeltaSeconds()*1000; } - + aRegistration.Contact = "sip:"+aRegistrationMessage.getRemoteAddress()+":"+aRegistrationMessage.getRemotePort(); mSuperPeerProxy.updateRegistration(aRegistration, aRegistrationMessage); } diff --git a/p2pproxy/src/org/linphone/p2pproxy/core/sipproxy/superpeers/SuperPeerProxy.java b/p2pproxy/src/org/linphone/p2pproxy/core/sipproxy/superpeers/SuperPeerProxy.java index fed98539f..4fcb2467b 100644 --- a/p2pproxy/src/org/linphone/p2pproxy/core/sipproxy/superpeers/SuperPeerProxy.java +++ b/p2pproxy/src/org/linphone/p2pproxy/core/sipproxy/superpeers/SuperPeerProxy.java @@ -58,8 +58,7 @@ public class SuperPeerProxy implements SipProxy, RegistrationHandler { if (mLog.isDebugEnabled()) mLog.debug("processing request " +aMessage); String lTo = aMessage.getToHeader().getNameAddress().getAddress().toString(); SipURL lNextHope = null; - //check if invite - if (aMessage.isInvite() || aMessage.isCancel()) { + //ok need to find the root //is local ? synchronized (mRegistrationTab) { @@ -70,11 +69,14 @@ public class SuperPeerProxy implements SipProxy, RegistrationHandler { throw new P2pProxyUserNotFoundException("user ["+lTo+"] not found"); } } - // add recordRoute - SipUtils.addRecordRoute(aProvider,aMessage); - + if (aMessage.isInvite() || aMessage.isCancel()) { + //check if invite + // add recordRoute + SipUtils.addRecordRoute(aProvider,aMessage); + } - } else { + if (lNextHope == null) { + // not for us //just look at route set MultipleHeader lMultipleRoute = aMessage.getRoutes(); @@ -82,7 +84,8 @@ public class SuperPeerProxy implements SipProxy, RegistrationHandler { lNextHope = ((RecordRouteHeader)lMultipleRoute.getTop()).getNameAddress().getAddress(); } else { // last proxy, get route from request uri - lNextHope = aMessage.getRequestLine().getAddress(); + //check if we know the user + lNextHope = aMessage.getRequestLine().getAddress(); } } diff --git a/p2pproxy/test-src/org/linphone/p2pproxy/test/utils/SipClient.java b/p2pproxy/test-src/org/linphone/p2pproxy/test/utils/SipClient.java index f6c61fcc7..01086a263 100644 --- a/p2pproxy/test-src/org/linphone/p2pproxy/test/utils/SipClient.java +++ b/p2pproxy/test-src/org/linphone/p2pproxy/test/utils/SipClient.java @@ -141,7 +141,7 @@ public class SipClient { String lCallerUri = mSipIdentity; String lCalleeUri = aTo; mLog.info("Calling ["+aTo+"] from ["+mSipIdentity+"]"); - long lTimout = 75000; + long lTimout = 30000; final Semaphore lCallerSemaphoreAccepted = new Semaphore(0); final Semaphore lCalleeSemaphoreClosed = new Semaphore(0); @@ -218,7 +218,7 @@ public class SipClient { String lCallerUri = mSipIdentity; String lCalleeUri = aTo; mLog.info("Calling ["+aTo+"] from ["+mSipIdentity+"]"); - long lTimout = 75000; + long lTimout = 30000; final Semaphore lCallerSemaphoreAccepted = new Semaphore(0); final Semaphore lCalleeSemaphoreClosed = new Semaphore(0); @@ -228,12 +228,13 @@ public class SipClient { lCallerSemaphoreAccepted.release(); call.ackWithAnswer(sdp); } - public void onCallClosing(Call call, Message bye) { - //nop - } + public void onCallRinging(Call call, Message resp) { lCallerSemaphoreRinging.release(); } + public void onCallClosed(Call call, Message resp) { + lCalleeSemaphoreClosed.release(); + } }; Call lCaller = new Call(mProvider, lCallerUri, getContact(mProvider), lCallerListener); if (enableSdp) { @@ -250,8 +251,8 @@ public class SipClient { } lCaller.bye(); - Assert.assertTrue("caller call not closed until ["+lTimout+"]", lCalleeSemaphoreClosed.tryAcquire(lTimout,TimeUnit.MILLISECONDS)); - + Assert.assertTrue("caller call not closed until ["+aCallDuration + aCallDuration/10+"]", lCalleeSemaphoreClosed.tryAcquire(aCallDuration + aCallDuration/10,TimeUnit.MILLISECONDS)); + mLog.info("Call ok"); return lCaller; } catch (Exception e) { @@ -271,9 +272,9 @@ public class SipClient { public void onCallIncoming(Call call, NameAddress callee, NameAddress caller, String sdp, Message invite) { call.accept(sdp); } - public void onCallClosed(Call call, Message resp) { - //nop - } + public void onCallClosing(Call call, Message bye) { + //nop + } }; Call lCallee = new Call(mProvider, mSipIdentity, getContact(mProvider), lCalleeListener); lCallee.setLocalSessionDescriptor(sdp_offer); 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 b168c8cc5..b78f8edd1 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.InetAddress; import java.net.URI; import java.util.Timer; import java.util.TimerTask; @@ -75,26 +76,27 @@ public UserInstance(final String userName) throws P2pProxyException { 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); + //InetAddress[] lAddresses = InetAddress.getAllByName("localhost"); + mProvider=new SipProvider(null,lSipPort); mSipClient = new SipClient(mProvider,userName,30000); class RegistrarTimerTask extends TimerTask { @Override public void run() { try { // 1 get proxy address - String lProxyUri = P2pProxyMain.lookupSipProxyUri(P2pProxyResourceManagement.DOMAINE); + URI lProxyUri = URI.create(P2pProxyMain.lookupSipProxyUri(P2pProxyResourceManagement.DOMAINE)); if (lProxyUri == null) { System.out.println("cannot find registrar"); return; } //2 setOutbound proxy - mProvider.setOutboundProxy(new SocketAddress(lProxyUri)); + mProvider.setOutboundProxy(new SocketAddress(lProxyUri.getRawSchemeSpecificPart())); mSipClient.register(REGISTRATION_PERIOD,userName); mIsRegistered = true; } catch(Exception e) { mLog.error("cannot register user["+userName+"]",e); } finally { - mTimer.schedule(new RegistrarTimerTask(), REGISTRATION_PERIOD-REGISTRATION_PERIOD/10); + mTimer.schedule(new RegistrarTimerTask(), 1000 *(REGISTRATION_PERIOD-REGISTRATION_PERIOD/10)); } } @@ -110,7 +112,7 @@ public void call(String aTo, int duration) { } public static void main(String[] args) throws P2pProxyException { String lFrom=null, lTo=null; - int lDuration = 10, lLoop=1; + int lDuration = 10, lLoop=0; for (int i=0; i < args.length; i=i+2) { String argument = args[i]; if (argument.equals("-from")) {