Changeset 164:cb9a746904ad in mediastreamer2
- Timestamp:
- Nov 10, 2008 5:41:30 PM (5 years ago)
- Branch:
- default
- Location:
- p2pproxy
- Files:
-
- 1 added
- 2 deleted
- 11 edited
-
src/org/linphone/p2pproxy/api/P2pProxyResourceManagement.java (modified) (1 diff)
-
src/org/linphone/p2pproxy/core/JxtaNetworkManager.java (modified) (3 diffs)
-
src/org/linphone/p2pproxy/core/P2pProxyMain.java (modified) (8 diffs)
-
src/org/linphone/p2pproxy/core/P2pProxyMainMBean.java (modified) (1 diff)
-
src/org/linphone/p2pproxy/core/P2pProxyManagementImpl.java (modified) (1 diff)
-
src/org/linphone/p2pproxy/core/P2pProxyResourceManagementImpl.java (modified) (1 diff)
-
src/org/linphone/p2pproxy/core/media/MediaResourceService.java (modified) (5 diffs)
-
src/org/linphone/p2pproxy/core/media/MediaResoureUnreachableException.java (added)
-
src/org/linphone/p2pproxy/core/media/rtprelay/RtpRelayService.java (deleted)
-
src/org/linphone/p2pproxy/core/media/rtprelay/RtpRelayServiceClient.java (deleted)
-
src/org/linphone/p2pproxy/core/rdvautoconfig/AutoConfigService.java (modified) (2 diffs)
-
src/org/linphone/p2pproxy/core/sipproxy/SipProxyRegistrar.java (modified) (1 diff)
-
src/org/linphone/p2pproxy/core/stun/StunClient.java (modified) (5 diffs)
-
test-src/org/linphone/p2pproxy/test/utils/UserInstance.java (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
p2pproxy/src/org/linphone/p2pproxy/api/P2pProxyResourceManagement.java
r110 r164 31 31 32 32 public void revokeSipProxy(String aProxy) throws P2pProxyException; 33 34 public void revokeMediaServer(String aMediaServer) throws P2pProxyException; 33 35 /** 34 36 * return 2 adresses where to contact media server (stun/rtprelay) -
p2pproxy/src/org/linphone/p2pproxy/core/JxtaNetworkManager.java
r120 r164 22 22 import java.io.File; 23 23 import java.io.IOException; 24 import java.net.InetAddress; 24 25 import java.net.URI; 25 26 import java.net.URISyntaxException; … … 133 134 if (!lNetworkConfigurator.exists()) { 134 135 lNetworkConfigurator.setPeerID(IDFactory.newPeerID(PeerGroupID.defaultNetPeerGroupID)); 136 lNetworkConfigurator.setName(InetAddress.getLocalHost().toString()+" "+aProperties.getProperty(TCP_LISTENING_PORT)); 135 137 lNetworkConfigurator.setDescription("p2p proxy instance"); 136 138 lNetworkConfigurator.save(); … … 369 371 for (Advertisement lAdv: aList) { 370 372 if (lAdv.equals(lNewAdv)) { 371 if (mLog.isDebugEnabled()) mLog.debug("adv ["+lNewAdv.getID()+"]already gathered"); 373 if (mLog.isInfoEnabled()) mLog.info("adv ["+lNewAdv.getID()+"]already gathered"); 374 if (mLog.isDebugEnabled()) mLog.debug(lNewAdv); 372 375 lNewAdv = null; 373 376 break; -
p2pproxy/src/org/linphone/p2pproxy/core/P2pProxyMain.java
r156 r164 42 42 import org.linphone.p2pproxy.api.P2pProxyResourceManagement; 43 43 import org.linphone.p2pproxy.api.P2pProxyUserAlreadyExistException; 44 import org.linphone.p2pproxy.core.media. rtprelay.RtpRelayService;44 import org.linphone.p2pproxy.core.media.MediaResourceService; 45 45 import org.linphone.p2pproxy.core.sipproxy.SipProxyRegistrar; 46 46 import org.zoolu.sip.provider.SipStack; … … 85 85 mConfigHomeDir=System.getProperty("user.home")+"/.p2pproxy"; 86 86 int lsipPort=5040; 87 int lMediaPort=16000; 87 int lMediaPort=MediaResourceService.AUDIO_VIDEO_LOCAL_PORT_DEFAULT_VALUE; 88 int lP2pPort = 9701; 88 89 JxtaNetworkManager.Mode lMode = JxtaNetworkManager.Mode.auto; 89 boolean lEnableHttp = false;90 90 // setup logging 91 91 … … 123 123 mLog.warn("cannot register MBean",e); 124 124 } 125 String lSocksHost = null; 126 String lSocksPort = null; 127 // if (args.length <= 0) { 128 // usage(); 129 // System.exit(1); 130 // } 125 131 126 // get other params 132 127 for (int i=0; i < args.length; i=i+2) { 133 128 String argument = args[i]; 134 if (argument.equals("-jxta") ) {129 if (argument.equals("-jxta") || argument.equals("-home")) { 135 130 mConfigHomeDir = args[i + 1]; 136 131 //nop … … 141 136 } else if (argument.equals("-media")) { 142 137 lMediaPort = Integer.parseInt(args[i + 1]); 143 System.out.println("media detected[" + lsipPort + "]"); 144 mConfigurator.setProperty(RtpRelayService.AUDIO_VIDEO_LOCAL_PORT, Integer.toString(lMediaPort)); 138 System.out.println("media detected[" + lMediaPort + "]"); 139 mConfigurator.setProperty(MediaResourceService.AUDIO_VIDEO_LOCAL_PORT, Integer.toString(lMediaPort)); 140 } else if (argument.equals("-p2p")) { 141 lP2pPort = Integer.parseInt(args[i + 1]); 142 System.out.println("p2p port detected[" + lP2pPort + "]"); 143 mConfigurator.setProperty(JxtaNetworkManager.TCP_LISTENING_PORT, Integer.toString(lP2pPort)); 145 144 } else if (argument.equals("-relay")) { 146 145 lMode = JxtaNetworkManager.Mode.relay; … … 170 169 mConfigurator.setProperty(JxtaNetworkManager.SEEDING_RELAY, args[i + 1]); 171 170 System.out.println("seeding relay detected[" + args[i + 1] + "]"); 171 } else if (argument.equals("-seeding")) { 172 mConfigurator.setProperty(JxtaNetworkManager.SEEDING_RDV, args[i + 1]); 173 mConfigurator.setProperty(JxtaNetworkManager.SEEDING_RELAY, args[i + 1]); 174 System.out.println("seeding detected[" + args[i + 1] + "]"); 172 175 } 173 176 else if (argument.equals("-public-address")) { 174 177 mConfigurator.setProperty(JxtaNetworkManager.HTTP_LISTENING_PUBLIC_ADDRESS,args[i + 1]+":9700"); 175 mConfigurator.setProperty(JxtaNetworkManager.TCP_LISTENING_PUBLIC_ADDRESS,args[i + 1]+": 9701");176 mConfigurator.setProperty( RtpRelayService.AUDIO_VIDEO_PUBLIC_URI,"udp://"+args[i + 1]+":"+lMediaPort);178 mConfigurator.setProperty(JxtaNetworkManager.TCP_LISTENING_PUBLIC_ADDRESS,args[i + 1]+":"+lP2pPort); 179 mConfigurator.setProperty(MediaResourceService.AUDIO_VIDEO_PUBLIC_URI,"udp://"+args[i + 1]+":"+lMediaPort); 177 180 mConfigurator.setProperty(SipProxyRegistrar.REGISTRAR_PUBLIC_ADDRESS,args[i + 1]); 178 181 System.out.println("public address detected[" + args[i + 1] + "]"); 179 }180 else if (argument.equals("-socks-url")) {181 try {182 URI lSocksUrl = new URI(args[i + 1]);183 lSocksHost = lSocksUrl.getHost();184 lSocksPort = Integer.toString(lSocksUrl.getPort());185 }catch (Exception e) {186 mLog.warn("enable to get socks proxy from env",e);187 }188 System.out.println("socks serveur detected[" + args[i + 1] + "]");189 } else if (argument.equals("-enable-http-client")) {190 lEnableHttp = true;191 mConfigurator.setProperty(JxtaNetworkManager.ENABLE_HTTP_CLIENT, "true");192 System.out.println("enable-http mode detected");193 i--;194 182 } 195 183 else … … 200 188 } 201 189 } 202 String lProxyUrlString = null;203 String lProxyHost = null;204 String lProxyPort = null;205 //configure http proxy206 if ((lProxyUrlString = System.getenv("http_proxy")) != null) {207 //get from env208 try {209 URL lProxyUrl = new URL(lProxyUrlString);210 lProxyHost = lProxyUrl.getHost();211 lProxyPort = Integer.toString(lProxyUrl.getPort());212 }catch (Exception e) {213 mLog.warn("enable do get http proxy from env",e);214 }215 }216 //check from config217 if (lProxyHost != null || (lProxyHost = mConfigurator.getProperty("http.proxyHost")) != null) {218 System.setProperty("http.proxyHost", lProxyHost);219 }220 if (lProxyPort != null || (lProxyPort = mConfigurator.getProperty("http.proxyPort")) != null) {221 System.setProperty("http.proxyPort", lProxyPort);222 }223 //configure socks proxy224 if ((lProxyUrlString = System.getenv("socks_proxy")) != null) {225 //get from env226 227 }228 //check from config229 if (lSocksHost != null || (lSocksHost = mConfigurator.getProperty("socksProxyHost")) != null) {230 System.setProperty("socksProxyHost", lSocksHost);231 }232 if (lSocksPort != null || (lSocksPort = mConfigurator.getProperty("socksProxyPort")) != null) {233 System.setProperty("socksProxyPort", lSocksPort);234 }235 236 //check from env237 190 238 191 File lJxtaDirectory = new File (mConfigHomeDir); … … 352 305 private static void usage() { 353 306 System.out.println("p2pproxy"); 354 System.out.println("- jxta: directory where configuration/cache is located (including jxta cache.default is $HOME/.p2pproxy");307 System.out.println("-home : directory where configuration/cache is located (including jxta cache.default is $HOME/.p2pproxy"); 355 308 System.out.println("-sip : udp proxy port, default 5060"); 356 309 System.out.println("-media : udp relay/stun port, default 16000"); 310 System.out.println("-p2p : p2p tcp port, default 9701"); 357 311 System.out.println("-relay : super peer mode"); 358 312 System.out.println("-edge-only : edge mode"); 359 313 System.out.println("-seeding-server : seeding server mode"); 360 314 System.out.println("-auto-config : automatically choose edge or relay (default mode)"); 361 System.out.println("-seeding-rdv : list of boostrap rdv separated by | (ex tcp://127.0.0.1:9701|http://127.0.0.2:9700)"); 362 System.out.println("-seeding-relay : list of boostrap relay separated by |(ex tcp://127.0.0.1:9701|http://127.0.0.2:9700)"); 315 System.out.println("-seeding : list of boostrap rdv separated by | (ex tcp://127.0.0.1:9701|http://127.0.0.2:9700)"); 363 316 System.out.println("-public-address : ip as exported to peers (ex myPublicAddress.no-ip.org)"); 364 System.out.println("-socks-url : tcp://ip:port for socks server (ex tcp://socks.com:1080)"); 365 System.out.println("-enable-http-client : enable http transport for client (default = false)"); 366 } 367 public String getHttpProxy() { 368 return System.getProperty("http.proxyHost", "not-set")+":"+System.getProperty("http.proxyPort", "not-set"); 369 } 370 371 public void setHttpProxy(String aProxyHost, String aProxyPort, String aUserName, String aPassword) { 372 System.setProperty("http.proxyHost",aProxyHost); 373 System.setProperty("http.proxyPort",aProxyPort); 374 375 } 376 public String getSocksServer() { 377 return System.getProperty("socksProxyHost", "not-set")+":"+System.getProperty("socksProxyPort", "not-set"); 378 } 379 public void setSocksServer(String aSocksHost, String aSocksPort, String aUserName, String aPassword) { 380 System.setProperty("socksProxyHost",aSocksHost); 381 System.setProperty("socksProxyPort",aSocksPort); 382 } 317 } 383 318 384 319 public void loadTraceConfigFile() throws P2pProxyException { … … 515 450 } 516 451 } 517 452 public static int revokeMediaServer(String aServer) { 453 try { 454 isReady(); 455 mP2pProxyManagement.revokeMediaServer(aServer); 456 return P2pProxylauncherConstants.P2PPROXY_NO_ERROR; 457 } catch (P2pProxyException e) { 458 return P2pProxylauncherConstants.P2PPROXY_NOT_CONNECTED; 459 } 460 } 518 461 public static void stop() { 519 462 mExit = true; -
p2pproxy/src/org/linphone/p2pproxy/core/P2pProxyMainMBean.java
r0 r164 24 24 25 25 public interface P2pProxyMainMBean { 26 public void setHttpProxy(String aProxyHost,String aProxyPort,String aUserName,String aPassword); 27 public String getHttpProxy(); 28 public void setSocksServer(String aSocksHost,String aSocksPort,String aUserName,String aPassword); 29 public String getSocksServer(); 26 30 27 /** 31 28 * reload traces from file -
p2pproxy/src/org/linphone/p2pproxy/core/P2pProxyManagementImpl.java
r84 r164 20 20 package org.linphone.p2pproxy.core; 21 21 22 import java.io.IOException;23 22 import java.net.InetAddress; 24 23 import java.net.InetSocketAddress; 25 24 import java.net.SocketException; 26 import java.net.URI;27 25 import java.net.UnknownHostException; 28 import java.util.Map;29 26 30 27 import org.apache.log4j.Logger; 31 28 import org.linphone.p2pproxy.api.P2pProxyException; 32 29 import org.linphone.p2pproxy.api.P2pProxyManagement; 33 import org.linphone.p2pproxy.core.media.rtprelay.MediaType; 34 import org.linphone.p2pproxy.core.media.rtprelay.RtpRelayServiceClient; 30 35 31 import org.linphone.p2pproxy.core.rdvautoconfig.PeerInfoServiceClient; 36 import org.linphone.p2pproxy.core.sipproxy.NetworkResourceAdvertisement;37 32 38 33 public abstract class P2pProxyManagementImpl extends P2pProxyResourceManagementImpl implements ServiceProvider,P2pProxyManagement { -
p2pproxy/src/org/linphone/p2pproxy/core/P2pProxyResourceManagementImpl.java
r156 r164 56 56 } 57 57 } 58 public void revokeMediaServer(String aMediaServer) throws P2pProxyException { 59 try { 60 List<NetworkResourceAdvertisement> lMediaResourceAdvertisement = (List<NetworkResourceAdvertisement>) (mJxtaNetworkManager.getAdvertisementList(null,MediaResourceService.ADV_NAME, true)); 61 for (NetworkResourceAdvertisement lMediaResource:lMediaResourceAdvertisement) { 62 if (lMediaResource.getAddress().equals("udp://"+aMediaServer)) { 63 mJxtaNetworkManager.getPeerGroup().getDiscoveryService().flushAdvertisement(lMediaResource); 64 mLog.info(aMediaServer +" revoked"); 65 } 66 67 } 68 } catch (Exception e) { 69 throw new P2pProxyException(e); 70 } 71 72 } 58 73 59 74 } -
p2pproxy/src/org/linphone/p2pproxy/core/media/MediaResourceService.java
r156 r164 20 20 package org.linphone.p2pproxy.core.media; 21 21 22 import java.net.InetAddress; 22 23 import java.net.InetSocketAddress; 23 24 import java.net.SocketException; … … 38 39 import org.linphone.p2pproxy.core.media.rtprelay.RtpRelayServer; 39 40 import org.linphone.p2pproxy.core.media.rtprelay.RtpRelayServerConfig; 40 import org.linphone.p2pproxy.core.media.rtprelay.RtpRelayService;41 41 import org.linphone.p2pproxy.core.sipproxy.NetworkResourceAdvertisement; 42 42 import org.linphone.p2pproxy.core.stun.StunServer; … … 44 44 public class MediaResourceService implements ServiceProvider { 45 45 private final static Logger mLog = Logger.getLogger(MediaResourceService.class); 46 public final static String AUDIO_VIDEO_LOCAL_PORT="org.linphone.p2pproxy.udp-media-relay.audio-video.port"; 47 public final static int AUDIO_VIDEO_LOCAL_PORT_DEFAULT_VALUE=16000; 48 public final static String AUDIO_VIDEO_PUBLIC_URI="org.linphone.p2pproxy.udp-media-relay.audio-video.public-uri"; 49 46 50 private GenericUdpSession mUdpSessionForStunRtp; 47 51 private RtpRelayServer mRtpRelayServer; … … 55 59 TimerTask mPublishTask; 56 60 public MediaResourceService(Configurator aConfigurator, JxtaNetworkManager aJxtaNetworkManager) throws SocketException, UnknownHostException { 57 URI lAudioVideoPublicUri = URI.create(aConfigurator.getProperty(RtpRelayService.AUDIO_VIDEO_PUBLIC_URI,RtpRelayService.getDefaultAudioVideoPublicUri())); 58 int lAudioVideoLocalPort = Integer.valueOf(aConfigurator.getProperty(RtpRelayService.AUDIO_VIDEO_LOCAL_PORT,String.valueOf(lAudioVideoPublicUri.getPort()))); 61 62 int lAudioVideoLocalPort = Integer.valueOf(aConfigurator.getProperty(MediaResourceService.AUDIO_VIDEO_LOCAL_PORT,String.valueOf(AUDIO_VIDEO_LOCAL_PORT_DEFAULT_VALUE))); 63 URI lAudioVideoPublicUri = URI.create(aConfigurator.getProperty(MediaResourceService.AUDIO_VIDEO_PUBLIC_URI,"udp://"+InetAddress.getLocalHost().getHostAddress()+":"+lAudioVideoLocalPort)); 59 64 mConfig = new RtpRelayServerConfig(new InetSocketAddress(lAudioVideoPublicUri.getHost(),lAudioVideoPublicUri.getPort()) 60 65 ,new InetSocketAddress(lAudioVideoLocalPort)); … … 75 80 mStunRtpServerAdvertisement = (NetworkResourceAdvertisement) AdvertisementFactory.newAdvertisement(NetworkResourceAdvertisement.getAdvertisementType()); 76 81 mStunRtpServerAdvertisement.setAddress("udp://"+mConfig.getAudioVideoPublicSocketAddress().getAddress().getHostAddress()+":"+mConfig.getAudioVideoPublicSocketAddress().getPort()); 77 mStunRtpServerAdvertisement.setID(IDFactory.newCodatID(mJxtaNetworkManager.getPeerGroup().getPeerGroupID() , mStunRtpServerAdvertisement.getAddress().toString().getBytes()));82 mStunRtpServerAdvertisement.setID(IDFactory.newCodatID(mJxtaNetworkManager.getPeerGroup().getPeerGroupID()/*, mStunRtpServerAdvertisement.getAddress().getBytes("US-ASCII")*/)); 78 83 mStunRtpServerAdvertisement.setName(ADV_NAME); 79 84 mJxtaNetworkManager.getPeerGroup().getDiscoveryService().publish(mStunRtpServerAdvertisement,ADV_LIFE_TIME,ADV_LIFE_TIME/2); -
p2pproxy/src/org/linphone/p2pproxy/core/rdvautoconfig/AutoConfigService.java
r0 r164 40 40 import org.linphone.p2pproxy.core.JxtaNetworkManager; 41 41 import org.linphone.p2pproxy.core.ServiceProvider; 42 import org.linphone.p2pproxy.core.media.rtprelay.RtpRelayService; 42 import org.linphone.p2pproxy.core.media.MediaResourceService; 43 43 44 44 45 public class AutoConfigService implements ServiceProvider { … … 132 133 } 133 134 public boolean startUdpProxyIfPossible() { 134 int lAudioVideoPort = Integer.parseInt(mProperties.getProperty( RtpRelayService.AUDIO_VIDEO_LOCAL_PORT,"16000"));135 int lAudioVideoPort = Integer.parseInt(mProperties.getProperty(MediaResourceService.AUDIO_VIDEO_LOCAL_PORT,"16000")); 135 136 InetSocketAddress lSocketAddress=null; 136 137 try { -
p2pproxy/src/org/linphone/p2pproxy/core/sipproxy/SipProxyRegistrar.java
r126 r164 395 395 if (mProxyRegistrationAdvertisement == null) { 396 396 mProxyRegistrationAdvertisement = (NetworkResourceAdvertisement) AdvertisementFactory.newAdvertisement(NetworkResourceAdvertisement.getAdvertisementType()); 397 mProxyRegistrationAdvertisement.setID(IDFactory.newCodatID(mJxtaNetworkManager.getPeerGroup().getPeerGroupID() , mSuperPeerProxy.getSipProxyRegistrarAddress().toString().getBytes()));397 mProxyRegistrationAdvertisement.setID(IDFactory.newCodatID(mJxtaNetworkManager.getPeerGroup().getPeerGroupID()/*, mSuperPeerProxy.getSipProxyRegistrarAddress().getBytes("US-ASCII")*/)); 398 398 mProxyRegistrationAdvertisement.setAddress(mSuperPeerProxy.getSipProxyRegistrarAddress()); 399 399 mProxyRegistrationAdvertisement.setName(ADV_NAME); -
p2pproxy/src/org/linphone/p2pproxy/core/stun/StunClient.java
r156 r164 24 24 import java.net.DatagramSocket; 25 25 import java.net.InetSocketAddress; 26 import java.net.PortUnreachableException; 26 27 import java.net.SocketException; 27 28 import java.net.SocketTimeoutException; … … 35 36 import org.linphone.p2pproxy.core.P2pProxyAdvertisementNotFoundException; 36 37 import org.linphone.p2pproxy.core.media.MediaResourceService; 38 import org.linphone.p2pproxy.core.media.MediaResoureUnreachableException; 37 39 import org.linphone.p2pproxy.core.sipproxy.NetworkResourceAdvertisement; 38 40 import de.javawi.jstun.attribute.ChangeRequest; … … 86 88 } 87 89 88 public AddressInfo computeAddressInfo(DatagramSocket lLocalSocket) throws P 2pProxyException {90 public AddressInfo computeAddressInfo(DatagramSocket lLocalSocket) throws PortUnreachableException, P2pProxyException { 89 91 AddressInfo lAddressInfo = new AddressInfo((InetSocketAddress) lLocalSocket.getLocalSocketAddress()); 90 try { 92 InetSocketAddress lCurrentMediaServerAddress = null; 93 try { 91 94 DiscoveryInfo lDiscoveryInfo = new DiscoveryInfo((InetSocketAddress) lLocalSocket.getLocalSocketAddress()); 92 95 //1 bind request 93 bindRequest(lDiscoveryInfo,lLocalSocket,lLocalSocket,null,mStunServerList.get(0));96 bindRequest(lDiscoveryInfo,lLocalSocket,lLocalSocket,null,lCurrentMediaServerAddress = mStunServerList.get(0)); 94 97 //2 bind request 95 98 if (mStunServerList.size() > 1) { 96 99 //open new socket 97 100 DatagramSocket lDatagramSocket = new DatagramSocket(); 98 bindRequest(lDiscoveryInfo,lDatagramSocket, lLocalSocket, lDiscoveryInfo.getPublicSocketAddress(), mStunServerList.get(1));101 bindRequest(lDiscoveryInfo,lDatagramSocket, lLocalSocket, lDiscoveryInfo.getPublicSocketAddress(),lCurrentMediaServerAddress = mStunServerList.get(1)); 99 102 lDatagramSocket.close(); 100 103 } … … 103 106 lAddressInfo.setPublicAddress(lDiscoveryInfo.getPublicSocketAddress()); 104 107 108 } catch (PortUnreachableException pex) { 109 MediaResoureUnreachableException lExeption = new MediaResoureUnreachableException(pex); 110 lExeption.setRourceAddress(lCurrentMediaServerAddress.getAddress().getHostAddress()+":"+lCurrentMediaServerAddress.getPort()); 111 throw lExeption; 105 112 } catch (Exception e) { 106 113 throw new P2pProxyException(e); … … 108 115 return lAddressInfo; 109 116 } 110 private void bindRequest(DiscoveryInfo aDiscoveryInfo,DatagramSocket aLocalSocket, DatagramSocket aResponseSocket,InetSocketAddress aResponseAddress, InetSocketAddress aStunAddress) throws UtilityException, SocketException, UnknownHostException, IOException, MessageAttributeParsingException, MessageHeaderParsingException, P2pProxyException {111 int timeSinceFirstTransmission = 0;112 int lSoTimeOut = SO_TIME_OUT;113 while (true) {114 try {115 aLocalSocket.setReuseAddress(true);116 aLocalSocket.connect(aStunAddress);117 aLocalSocket.setSoTimeout(lSoTimeOut);118 119 MessageHeader sendMH = new MessageHeader(MessageHeader.MessageHeaderType.BindingRequest);120 sendMH.generateTransactionID();121 122 ChangeRequest changeRequest = new ChangeRequest();123 sendMH.addMessageAttribute(changeRequest);124 if (!((InetSocketAddress)aLocalSocket.getLocalSocketAddress()).equals((InetSocketAddress)aResponseSocket.getLocalSocketAddress()) && aResponseAddress != null) {125 // add response address126 ResponseAddress lResponseAddress = new ResponseAddress();127 lResponseAddress.setAddress(new Address(aResponseAddress.getAddress().getHostAddress()));128 try {129 lResponseAddress.setPort(aResponseAddress.getPort());130 sendMH.addMessageAttribute(lResponseAddress);131 } catch (MessageAttributeException e) {132 mLog.info("Cannot set Response address ["+lResponseAddress+"]");133 }134 }135 136 byte[] data = sendMH.getBytes();137 DatagramPacket send = new DatagramPacket(data, data.length);138 aLocalSocket.send(send);139 140 MessageHeader receiveMH = new MessageHeader();141 while (!(receiveMH.equalTransactionID(sendMH))) {142 DatagramPacket receive = new DatagramPacket(new byte[200], 200);143 aResponseSocket.receive(receive);144 receiveMH = MessageHeader.parseHeader(receive.getData());145 receiveMH.parseAttributes(receive.getData());146 }147 148 MappedAddress lMappedAddress = (MappedAddress) receiveMH.getMessageAttribute(MessageAttribute.MessageAttributeType.MappedAddress);149 ErrorCode ec = (ErrorCode) receiveMH.getMessageAttribute(MessageAttribute.MessageAttributeType.ErrorCode);150 if (ec != null) {117 private void bindRequest(DiscoveryInfo aDiscoveryInfo,DatagramSocket aLocalSocket, DatagramSocket aResponseSocket,InetSocketAddress aResponseAddress, InetSocketAddress aStunAddress) throws UtilityException, SocketException, UnknownHostException, IOException, MessageAttributeParsingException, MessageHeaderParsingException, P2pProxyException { 118 int timeSinceFirstTransmission = 0; 119 int lSoTimeOut = SO_TIME_OUT; 120 while (true) { 121 try { 122 aLocalSocket.setReuseAddress(true); 123 aLocalSocket.connect(aStunAddress); 124 aLocalSocket.setSoTimeout(lSoTimeOut); 125 126 MessageHeader sendMH = new MessageHeader(MessageHeader.MessageHeaderType.BindingRequest); 127 sendMH.generateTransactionID(); 128 129 ChangeRequest changeRequest = new ChangeRequest(); 130 sendMH.addMessageAttribute(changeRequest); 131 if (!((InetSocketAddress)aLocalSocket.getLocalSocketAddress()).equals((InetSocketAddress)aResponseSocket.getLocalSocketAddress()) && aResponseAddress != null) { 132 // add response address 133 ResponseAddress lResponseAddress = new ResponseAddress(); 134 lResponseAddress.setAddress(new Address(aResponseAddress.getAddress().getHostAddress())); 135 try { 136 lResponseAddress.setPort(aResponseAddress.getPort()); 137 sendMH.addMessageAttribute(lResponseAddress); 138 } catch (MessageAttributeException e) { 139 mLog.info("Cannot set Response address ["+lResponseAddress+"]"); 140 } 141 } 142 143 byte[] data = sendMH.getBytes(); 144 DatagramPacket send = new DatagramPacket(data, data.length); 145 aLocalSocket.send(send); 146 147 MessageHeader receiveMH = new MessageHeader(); 148 while (!(receiveMH.equalTransactionID(sendMH))) { 149 DatagramPacket receive = new DatagramPacket(new byte[200], 200); 150 aResponseSocket.receive(receive); 151 receiveMH = MessageHeader.parseHeader(receive.getData()); 152 receiveMH.parseAttributes(receive.getData()); 153 } 154 155 MappedAddress lMappedAddress = (MappedAddress) receiveMH.getMessageAttribute(MessageAttribute.MessageAttributeType.MappedAddress); 156 ErrorCode ec = (ErrorCode) receiveMH.getMessageAttribute(MessageAttribute.MessageAttributeType.ErrorCode); 157 if (ec != null) { 151 158 aDiscoveryInfo.setError(ec.getResponseCode(), ec.getReason()); 152 throw new P2pProxyException("Message header contains an Errorcode message attribute. ["+ec+"]");153 }154 if ((lMappedAddress == null)) {155 throw new P2pProxyException("Response does not contain a Mapped Address message attribute.");156 157 } else {158 if (aLocalSocket.getLocalSocketAddress().equals(aResponseSocket.getLocalSocketAddress())) {159 throw new P2pProxyException("Message header contains an Errorcode message attribute. ["+ec+"]"); 160 } 161 if ((lMappedAddress == null)) { 162 throw new P2pProxyException("Response does not contain a Mapped Address message attribute."); 163 164 } else { 165 if (aLocalSocket.getLocalSocketAddress().equals(aResponseSocket.getLocalSocketAddress())) { 159 166 aDiscoveryInfo.setPublicSocketAddress(new InetSocketAddress(lMappedAddress.getAddress().getInetAddress(),lMappedAddress.getPort())); 160 } else {167 } else { 161 168 aDiscoveryInfo.setFullCone(); 162 } 163 } 164 return; 165 166 } catch (SocketTimeoutException ste) { 167 if (timeSinceFirstTransmission < 7900) { 168 if (mLog.isInfoEnabled()) mLog.info("Socket timeout while receiving the response."); 169 timeSinceFirstTransmission += lSoTimeOut; 170 int timeoutAddValue = (timeSinceFirstTransmission * 2); 171 if (timeoutAddValue > 1600) timeoutAddValue = 1600; 172 lSoTimeOut = timeoutAddValue; 173 } else { 174 // node is not capable of udp communication 175 if (mLog.isInfoEnabled()) mLog.info("Socket timeout while receiving the response. Maximum retry limit exceed. Give up."); 176 if (aLocalSocket.getLocalSocketAddress().equals(aResponseSocket.getLocalSocketAddress())) { 169 } 170 } 171 return; 172 173 } catch (PortUnreachableException pex ) { 174 throw pex; 175 } 176 catch (SocketTimeoutException ste) { 177 if (timeSinceFirstTransmission < 7900) { 178 if (mLog.isInfoEnabled()) mLog.info("Socket timeout while receiving the response."); 179 timeSinceFirstTransmission += lSoTimeOut; 180 int timeoutAddValue = (timeSinceFirstTransmission * 2); 181 if (timeoutAddValue > 1600) timeoutAddValue = 1600; 182 lSoTimeOut = timeoutAddValue; 183 } else { 184 // node is not capable of udp communication 185 if (mLog.isInfoEnabled()) mLog.info("Socket timeout while receiving the response. Maximum retry limit exceed. Give up."); 186 if (aLocalSocket.getLocalSocketAddress().equals(aResponseSocket.getLocalSocketAddress())) { 177 187 aDiscoveryInfo.setBlockedUDP(); 178 } else {188 } else { 179 189 aDiscoveryInfo.setSymmetric(); 180 }181 if (mLog.isInfoEnabled()) mLog.info("Node is not capable of UDP communication.");182 return ;183 }184 }185 }186 }190 } 191 if (mLog.isInfoEnabled()) mLog.info("Node is not capable of UDP communication."); 192 return ; 193 } 194 } 195 } 196 } 187 197 } -
p2pproxy/test-src/org/linphone/p2pproxy/test/utils/UserInstance.java
r156 r164 24 24 import java.net.DatagramSocket; 25 25 import java.net.InetAddress; 26 import java.net.PortUnreachableException; 26 27 import java.net.URI; 27 28 import java.util.Timer; … … 32 33 import org.linphone.p2pproxy.api.P2pProxyResourceManagement; 33 34 import org.linphone.p2pproxy.core.P2pProxyMain; 35 import org.linphone.p2pproxy.core.media.MediaResoureUnreachableException; 34 36 import org.linphone.p2pproxy.core.stun.AddressInfo; 35 37 import org.linphone.p2pproxy.core.stun.StunClient; … … 59 61 final String[] lParam = {"-jxta" ,"userinstance-"+lUserNameUri.getSchemeSpecificPart() 60 62 ,"-edge-only" 61 ,"-seeding-rdv", "tcp://82.67.74.86:9701" 62 ,"-seeding-relay", "tcp://82.67.74.86:9701"}; 63 ,"-seeding", "tcp://91.121.81.212:9701|tcp://91.121.81.212:9702"}; 63 64 lSocket.close(); 64 65 … … 114 115 115 116 mStunClient = new StunClient(lMediaServer); 116 AddressInfo lAudioAddressInfo = mStunClient.computeAddressInfo(mAudioSocket); 117 mLog.info("audio socket info ["+lAudioAddressInfo+"]"); 117 try { 118 AddressInfo lAudioAddressInfo = mStunClient.computeAddressInfo(mAudioSocket); 119 mLog.info("audio socket info ["+lAudioAddressInfo+"]"); 120 }catch (MediaResoureUnreachableException pex) { 121 mLog.error("cannot reach media server, flushing ["+pex.getResourceAddress()+"]",pex); 122 P2pProxyMain.revokeMediaServer(pex.getResourceAddress()); 123 } 124 118 125 mSipClient.register(REGISTRATION_PERIOD,userName); 119 126 mIsRegistered = true; 120 } catch(Exception e) { 127 } 128 catch(Exception e) { 121 129 mLog.error("cannot register user["+userName+"]",e); 122 130 } finally {
Note: See TracChangeset
for help on using the changeset viewer.
