Commit 3f6d008b authored by jehan's avatar jehan

debug sip proxy

git-svn-id: svn+ssh://svn.savannah.nongnu.org/linphone/trunk@113 3f6dc0c8-ddfe-455d-9043-3cd528dc4637
parent 6b110e34
......@@ -25,14 +25,16 @@ public interface P2pProxyResourceManagement {
public final String DOMAINE="p2p.linphone.org";
/**
*
* @return the SIP uri of an available sip proxy registrar for a given domaine
* @return the SIP uris of an available sip proxy registrar for a given domaine
*/
public String lookupSipProxyUri(String aDomaine) throws P2pProxyException ;
public String[] lookupSipProxiesUri(String aDomaine) throws P2pProxyException ;
public void revokeSipProxy(String aProxy) throws P2pProxyException;
/**
* return 2 adresses where to contact media server (stun/rtprelay)
*/
public String[] getMediaServerList() throws P2pProxyException;
}
......@@ -271,15 +271,19 @@ public class JxtaNetworkManager {
}
public List<? extends Advertisement> getAdvertisementList(String aPeerId, String anAttributeName,String anAttributeValue, boolean isTryFromLocal) throws InterruptedException, IOException, P2pProxyAdvertisementNotFoundException {
return getAdvertisementList(aPeerId, anAttributeName, anAttributeValue, isTryFromLocal, 1);
}
public List<? extends Advertisement> getAdvertisementList(String aPeerId, String anAttributeName,String anAttributeValue, boolean isTryFromLocal, int numberOfexpectedAdv) throws InterruptedException, IOException, P2pProxyAdvertisementNotFoundException {
DiscoveryService lDiscoveryService = getPeerGroup().getDiscoveryService();
final Semaphore lSemaphore = new Semaphore(0);
final Semaphore lSemaphore = new Semaphore(1-numberOfexpectedAdv);
final List<Advertisement> lReturnList = new ArrayList<Advertisement>();
DiscoveryListener lDiscoveryListener = new DiscoveryListener() {
public void discoveryEvent(DiscoveryEvent event) {
DiscoveryResponseMsg lRes = event.getResponse();
int lOrigListSize = lReturnList.size();
enumeration2List(lRes.getAdvertisements(), lReturnList);
lSemaphore.release();
lSemaphore.release(lReturnList.size()-lOrigListSize);
}
};
......@@ -288,10 +292,10 @@ public class JxtaNetworkManager {
Enumeration lEnumeration = lDiscoveryService.getLocalAdvertisements(DiscoveryService.ADV, anAttributeName,anAttributeValue);
enumeration2List(lEnumeration, lReturnList);
}
if (lReturnList.isEmpty() == true) {
mLog.info("no advertisement found in local, trying remote...");
if (lReturnList.size() < numberOfexpectedAdv) {
mLog.info(lReturnList.size() +" of ["+numberOfexpectedAdv+"] advertisements found in local, trying remote...");
lDiscoveryService.getRemoteAdvertisements(aPeerId, DiscoveryService.ADV, anAttributeName,anAttributeValue, 10,lDiscoveryListener);
if (lSemaphore.tryAcquire(ADV_DISCOVERY_TIMEOUT_INT,TimeUnit.MILLISECONDS) == false) {
if (lSemaphore.tryAcquire(ADV_DISCOVERY_TIMEOUT_INT,TimeUnit.MILLISECONDS) == false && lReturnList.isEmpty()) {
throw new P2pProxyAdvertisementNotFoundException( anAttributeName+"="+anAttributeValue+ " not found");
}
lSemaphore.release();
......@@ -354,14 +358,26 @@ public class JxtaNetworkManager {
mNetworkPeerGroup.stopApp();
//mNetworkPeerGroup.unref();
}
private List<Advertisement> enumeration2List(Enumeration<Advertisement> lEnumeration,List<Advertisement> lList) {
if (lList == null) {
lList = new ArrayList<Advertisement>();
private List<Advertisement> enumeration2List(Enumeration<Advertisement> lEnumeration,List<Advertisement> aList) {
if (aList == null) {
aList = new ArrayList<Advertisement>();
}
while (lEnumeration.hasMoreElements()) {
lList.add((Advertisement) lEnumeration.nextElement()) ;
Advertisement lNewAdv = lEnumeration.nextElement();
//1 check if already exist
for (Advertisement lAdv: aList) {
if (lAdv.equals(lNewAdv)) {
if (mLog.isDebugEnabled()) mLog.debug("adv ["+lNewAdv.getID()+"]already gathered");
lNewAdv = null;
break;
}
}
if (lNewAdv != null) {
aList.add((lNewAdv)) ;
}
}
return lList;
return aList;
}
}
......@@ -466,11 +466,25 @@ public static int isValidAccount(String aUserName){
public static String lookupSipProxyUri(String aDomaine) {
try {
isReady();
return mP2pProxySipProxyRegistrarManagement.lookupSipProxyUri(aDomaine);
String[] lProxies = mP2pProxySipProxyRegistrarManagement.lookupSipProxiesUri(aDomaine);
if (lProxies.length != 0) {
return lProxies[0];
} else {
return null;
}
} catch (Exception e) {
return null;
}
}
public static String[] lookupSipProxiesUri(String aDomaine) {
try {
isReady();
return mP2pProxySipProxyRegistrarManagement.lookupSipProxiesUri(aDomaine);
} catch (Exception e) {
return null;
}
}
public static int getState() {
try {
isReady();
......
package org.linphone.p2pproxy.core;
import java.util.List;
import org.apache.log4j.Logger;
import org.linphone.p2pproxy.api.P2pProxyException;
import org.linphone.p2pproxy.api.P2pProxyResourceManagement;
......@@ -13,14 +15,18 @@ public class P2pProxyResourceManagementImpl implements P2pProxyResourceManagemen
P2pProxyResourceManagementImpl(JxtaNetworkManager aJxtaNetworkManager) {
mJxtaNetworkManager = aJxtaNetworkManager;
}
public String lookupSipProxyUri(String aDomaine) throws P2pProxyException {
public String[] lookupSipProxiesUri(String aDomaine) throws P2pProxyException {
try {
if (!DOMAINE.equals(aDomaine)) {
//unknown domaine
return null;
return new String[0];
}
List<NetworkResourceAdvertisement> lSipProxyRegistrarAdvertisements = (List<NetworkResourceAdvertisement>) (mJxtaNetworkManager.getAdvertisementList(null, "Name",SipProxyRegistrar.ADV_NAME, true,2));
String[] lAddresses = new String[lSipProxyRegistrarAdvertisements.size()];
for (int i=0;i<lSipProxyRegistrarAdvertisements.size();i++) {
lAddresses[i] = lSipProxyRegistrarAdvertisements.get(i).getAddress();
}
NetworkResourceAdvertisement lSipProxyRegistrarAdvertisement = (NetworkResourceAdvertisement) (mJxtaNetworkManager.getAdvertisement(null, SipProxyRegistrar.ADV_NAME, true));
return lSipProxyRegistrarAdvertisement.getAddress();
return lAddresses;
}catch (Exception e) {
throw new P2pProxyException(e);
}
......
......@@ -44,7 +44,7 @@ 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 {
public UserInstance(final String userName,final String aPreferedProxyUri) throws P2pProxyException {
try {
DatagramSocket lSocket = new DatagramSocket();
lSocket.setReuseAddress(true);
......@@ -83,14 +83,25 @@ public UserInstance(final String userName) throws P2pProxyException {
@Override
public void run() {
try {
URI lProxyUri = null;
// 1 get proxy address
URI lProxyUri = URI.create(P2pProxyMain.lookupSipProxyUri(P2pProxyResourceManagement.DOMAINE));
if (lProxyUri == null) {
String [] lProxies = P2pProxyMain.lookupSipProxiesUri(P2pProxyResourceManagement.DOMAINE);
if (lProxies.length == 0) {
System.out.println("cannot find registrar");
return;
}
//default choice
lProxyUri = URI.create(lProxies[0]);
//search
for (String lProxy: lProxies) {
if (lProxy.equals(aPreferedProxyUri)) {
lProxyUri = URI.create(lProxy);
break;
}
}
//2 setOutbound proxy
mProvider.setOutboundProxy(new SocketAddress(lProxyUri.getRawSchemeSpecificPart()));
mLog.info("use outband proxy ["+mProvider.getOutboundProxy()+"]");
mSipClient.register(REGISTRATION_PERIOD,userName);
mIsRegistered = true;
} catch(Exception e) {
......@@ -111,7 +122,7 @@ public void call(String aTo, int duration) {
mSipClient.call(aTo, true, duration);
}
public static void main(String[] args) throws P2pProxyException {
String lFrom=null, lTo=null;
String lFrom=null, lTo=null, lPreferedProxyUri=null;
int lDuration = 10, lLoop=0;
for (int i=0; i < args.length; i=i+2) {
String argument = args[i];
......@@ -130,7 +141,11 @@ public static void main(String[] args) throws P2pProxyException {
} else if (argument.equals("-nb-call")) {
lLoop = Integer.parseInt(args[i + 1]);
System.out.println("nb-call [" + lLoop + "]");
} else {
} else if (argument.equals("-prefered-proxy")) {
lPreferedProxyUri = args[i + 1];
System.out.println("prefered-proxy [" + lLoop + "]");
}
else {
System.out.println("Invalid option: " + args[i]);
usage();
System.exit(1);
......@@ -148,7 +163,7 @@ public static void main(String[] args) throws P2pProxyException {
System.exit(1);
}
UserInstance lUserInstance= new UserInstance(lFrom);
UserInstance lUserInstance= new UserInstance(lFrom,lPreferedProxyUri);
while (mIsRegistered == false) {
try {
Thread.sleep(1000);
......
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