diff --git a/p2pproxy/src/org/linphone/p2pproxy/core/sipproxy/SipProxyRegistrar.java b/p2pproxy/src/org/linphone/p2pproxy/core/sipproxy/SipProxyRegistrar.java index 08704a16f..4195e485d 100644 --- a/p2pproxy/src/org/linphone/p2pproxy/core/sipproxy/SipProxyRegistrar.java +++ b/p2pproxy/src/org/linphone/p2pproxy/core/sipproxy/SipProxyRegistrar.java @@ -24,6 +24,7 @@ package org.linphone.p2pproxy.core.sipproxy; import java.io.File; import java.io.IOException; import java.net.InetSocketAddress; +import java.util.Collection; import java.util.HashMap; import java.util.Map; import java.util.Timer; @@ -82,6 +83,7 @@ public class SipProxyRegistrar implements SipProviderListener,SipProxyRegistrarM private long mNumberOfUnknownUsersForRegistration; private long mNumberOfUnRegistration; + public static class Registration { long RegistrationDate; public long Expiration; @@ -190,6 +192,23 @@ public class SipProxyRegistrar implements SipProviderListener,SipProxyRegistrarM }; mTimer.scheduleAtFixedRate(lPublisherTask, 0, ADV_LIFE_TIME-ADV_LIFE_TIME/10); + TimerTask lRegistrationTableGC = new TimerTask() { + + @Override + public void run() { + // copy list + Collection lCurrentRegistrations = mRegistrationTab.values(); + long lCurrentDate = System.currentTimeMillis(); + for (Registration lRegistration : lCurrentRegistrations) { + if ((lCurrentDate - lRegistration.RegistrationDate - lRegistration.Expiration) > 0) { + if (mLog.isInfoEnabled()) mLog.info("registration entry ["+lRegistration+"] has expired"); + mRegistrationTab.remove(lRegistration.From); + } + } + } + + }; + mTimer.scheduleAtFixedRate(lRegistrationTableGC, 0, 60000); } public void onReceivedMessage(SipProvider aProvider, Message aMessage) { diff --git a/p2pproxy/src/org/linphone/p2pproxy/core/sipproxy/superpeers/JxtaNetworkResources.java b/p2pproxy/src/org/linphone/p2pproxy/core/sipproxy/superpeers/JxtaNetworkResources.java index e190d7e3d..04a4d8dae 100644 --- a/p2pproxy/src/org/linphone/p2pproxy/core/sipproxy/superpeers/JxtaNetworkResources.java +++ b/p2pproxy/src/org/linphone/p2pproxy/core/sipproxy/superpeers/JxtaNetworkResources.java @@ -58,7 +58,7 @@ public class JxtaNetworkResources { } catch (IOException e1) { throw new P2pProxyException(e1); } - mLog.debug("publishing P2pUserRegistration Advertisement ["+mP2pUserRegistrationAdvertisement+"]published expire ["+aLiveTime+"]"); + mLog.info("publishing P2pUserRegistration Advertisement ["+mP2pUserRegistrationAdvertisement+"]published expire ["+aLiveTime+"]"); } } diff --git a/p2pproxy/src/org/linphone/p2pproxy/core/sipproxy/superpeers/P2pUserRegistrationAdvertisement.java b/p2pproxy/src/org/linphone/p2pproxy/core/sipproxy/superpeers/P2pUserRegistrationAdvertisement.java index 6a7ef2d8b..4e6821977 100644 --- a/p2pproxy/src/org/linphone/p2pproxy/core/sipproxy/superpeers/P2pUserRegistrationAdvertisement.java +++ b/p2pproxy/src/org/linphone/p2pproxy/core/sipproxy/superpeers/P2pUserRegistrationAdvertisement.java @@ -99,7 +99,7 @@ public class P2pUserRegistrationAdvertisement extends ExtendableAdvertisement im private String mRegistrarAddress; private String mUserUri; public final static String REGISTRAR_ADDRESS_TAG = "registrar-address"; - public final static String USER_NAME_TAG = "user-name"; + public final static String USER_NAME_TAG = "registration-user-name"; private final static String ID_TAG = "ID"; private final static String[] mIndexs = {USER_NAME_TAG}; private final static Logger mLog = Logger.getLogger(P2pUserRegistrationAdvertisement.class); 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 4fcb2467b..b20485e84 100644 --- a/p2pproxy/src/org/linphone/p2pproxy/core/sipproxy/superpeers/SuperPeerProxy.java +++ b/p2pproxy/src/org/linphone/p2pproxy/core/sipproxy/superpeers/SuperPeerProxy.java @@ -19,6 +19,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package org.linphone.p2pproxy.core.sipproxy.superpeers; +import java.io.IOException; +import java.util.List; import java.util.Map; @@ -26,6 +28,7 @@ import org.apache.log4j.Logger; import org.linphone.p2pproxy.api.P2pProxyException; import org.linphone.p2pproxy.api.P2pProxyUserNotFoundException; import org.linphone.p2pproxy.core.JxtaNetworkManager; +import org.linphone.p2pproxy.core.P2pProxyAdvertisementNotFoundException; import org.linphone.p2pproxy.core.sipproxy.RegistrationHandler; import org.linphone.p2pproxy.core.sipproxy.SipProxy; import org.linphone.p2pproxy.core.sipproxy.SipUtils; @@ -66,7 +69,16 @@ public class SuperPeerProxy implements SipProxy, RegistrationHandler { //great, just need to get it lNextHope = new SipURL(mRegistrationTab.get(lTo).Contact); } else { - throw new P2pProxyUserNotFoundException("user ["+lTo+"] not found"); + if (aMessage.isInvite() || aMessage.isCancel()) { + //need to found the right proxy + try { + List lAdvList = (List) mJxtaNetworkManager.getAdvertisementList(null, P2pUserRegistrationAdvertisement.USER_NAME_TAG,lTo, true); + lNextHope = new SipURL(lAdvList.get(0).getUserName()); + } catch (Exception e) { + throw new P2pProxyUserNotFoundException("user ["+lTo+"] not found",e); + } + + } } } if (aMessage.isInvite() || aMessage.isCancel()) {