Commit 92ace8fd authored by jehan's avatar jehan

prepare stun server

git-svn-id: svn+ssh://svn.savannah.nongnu.org/linphone/trunk@85 3f6dc0c8-ddfe-455d-9043-3cd528dc4637
parent 09ca76f8
......@@ -29,7 +29,7 @@ all: p2pproxy-launcher
p2pproxy-launcher: $(OBJS) $(USER_OBJS)
@echo 'Building target: $@'
@echo 'Invoking: GCC C Linker'
gcc -L/usr/lib/jvm/java-6-openjdk/jre/lib/amd64 -L/usr/lib/jvm/java-6-openjdk/jre/lib/amd64/server -o"p2pproxy-launcher" $(OBJS) $(USER_OBJS) $(LIBS)
gcc -L/usr/lib/jvm/java-6-openjdk/jre/lib/amd64 -L/usr/lib/jvm/java-6-openjdk/jre/lib/i386 -L/usr/lib/jvm/java-6-openjdk/jre/lib/amd64/server -L/usr/lib/jvm/java-6-openjdk/jre/lib/i386/server -o"p2pproxy-launcher" $(OBJS) $(USER_OBJS) $(LIBS)
@echo 'Finished building target: $@'
@echo ' '
......
......@@ -5,6 +5,7 @@
static void * thread_starter(void *args){
char* largs[] = {"-seeding-server","-sip", "5058"};
p2pproxy_application_start(3,largs);
printf("exit from application \n");
return NULL;
}
......
......@@ -16,11 +16,11 @@
JavaVM* p2pproxy_application_jvm = 0;
#define GET_JNI_ENV \
jint lResut = 0 ;\
jint lResult = 0 ;\
JNIEnv* lJniEnv = 0;\
jclass lMainClass = 0;\
lResut = (*p2pproxy_application_jvm)->AttachCurrentThread(p2pproxy_application_jvm,&lJniEnv,NULL);\
if (lResut != 0) { \
lResult = (*p2pproxy_application_jvm)->AttachCurrentThread(p2pproxy_application_jvm,&lJniEnv,NULL);\
if (lResult != 0) { \
fprintf(stderr,"cannot attach VM\n");\
return P2PPROXY_ERROR;\
}\
......@@ -95,10 +95,11 @@ int p2pproxy_application_start(int argc, char **argv) {
}
(*lJniEnv)->CallStaticVoidMethod(lJniEnv, lMainClass, mainMethod, applicationArgsList);
(*p2pproxy_application_jvm)->DestroyJavaVM(p2pproxy_application_jvm);
p2pproxy_application_jvm = 0;
return P2PPROXY_NO_ERROR;
}
int lResult;
const char* p2pproxy_status_string(int status_code) {
......@@ -164,17 +165,14 @@ int p2pproxy_resourcemgt_lookup_sip_proxy(char* proxy_uri,size_t size, char* dom
int p2pproxy_resourcemgt_revoke_sip_proxy(char* proxy_uri) {
jmethodID revokeProxyMethod;
jstring lJStringResult;
const jbyte* lString;
jboolean lIsCopy;
jstring applicationArg;
GET_JNI_ENV
revokeProxyMethod = (*lJniEnv)->GetStaticMethodID(lJniEnv, lMainClass, "revokeSipProxy", "(Ljava/lang/String;)V");
(*lJniEnv)->CallStaticVoidMethod(lJniEnv, lMainClass, revokeProxyMethod);
if (lJStringResult == 0) {
return P2PPROXY_ERROR;
}
return P2PPROXY_NO_ERROR;
applicationArg = (*lJniEnv)->NewStringUTF(lJniEnv, proxy_uri);
revokeProxyMethod = (*lJniEnv)->GetStaticMethodID(lJniEnv, lMainClass, "revokeSipProxy", "(Ljava/lang/String;)I");
lResult = (*lJniEnv)->CallStaticIntMethod(lJniEnv, lMainClass, revokeProxyMethod,applicationArg);
(*p2pproxy_application_jvm)->DetachCurrentThread(p2pproxy_application_jvm);
return lResult;
}
int p2pproxy_application_get_state() {
jmethodID stateMethod;
......@@ -193,8 +191,6 @@ void p2pproxy_application_stop() {
stopMethod = (*lJniEnv)->GetStaticMethodID(lJniEnv, lMainClass, "stop", "()V");
(*lJniEnv)->CallStaticVoidMethod(lJniEnv, lMainClass, stopMethod);
(*p2pproxy_application_jvm)->DetachCurrentThread(p2pproxy_application_jvm);
(*p2pproxy_application_jvm)->DestroyJavaVM(p2pproxy_application_jvm);
p2pproxy_application_jvm = 0;
return;
}
......
......@@ -21,7 +21,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
package org.linphone.p2pproxy.api;
public interface P2pProxyManagement extends P2pProxyNetworkProbe,P2pProxySipProxyRegistrarManagement {
public interface P2pProxyManagement extends P2pProxyNetworkProbe,P2pProxyResourceManagement {
/**
* test if according both to local peer capabilities and supeer peer election polity this peer should become a super peer
......
......@@ -21,7 +21,7 @@ package org.linphone.p2pproxy.api;
public interface P2pProxySipProxyRegistrarManagement {
public interface P2pProxyResourceManagement {
/**
*
* @return the SIP uri of an available sip proxy registrar for a given domaine
......@@ -29,5 +29,9 @@ public interface P2pProxySipProxyRegistrarManagement {
public String lookupSipProxyUri(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;
}
......@@ -55,7 +55,7 @@ public class GenericUdpSession implements Runnable {
byte[] lBuff = new byte[1500];
DatagramPacket lDatagramPacket = new DatagramPacket(lBuff,lBuff.length);
mLocalSocket.receive(lDatagramPacket);
// if destination is known just send
if (mLog.isInfoEnabled()) mLog.info(mLocalSocket.getLocalAddress().getHostAddress() + ":" + mLocalSocket.getLocalPort() + " datagram received from " + lDatagramPacket.getAddress().getHostAddress() + ":" + lDatagramPacket.getPort());
mMessageHandler.onMessage(lDatagramPacket);
}catch(Exception e) {
......
......@@ -39,7 +39,7 @@ import org.apache.log4j.PropertyConfigurator;
import org.linphone.p2pproxy.api.P2pProxyException;
import org.linphone.p2pproxy.api.P2pProxyManagement;
import org.linphone.p2pproxy.api.P2pProxyNotReadyException;
import org.linphone.p2pproxy.api.P2pProxySipProxyRegistrarManagement;
import org.linphone.p2pproxy.api.P2pProxyResourceManagement;
import org.linphone.p2pproxy.api.P2pProxyUserAlreadyExistException;
import org.linphone.p2pproxy.core.media.rtprelay.RtpRelayService;
import org.linphone.p2pproxy.core.sipproxy.SipProxyRegistrar;
......@@ -53,7 +53,7 @@ public class P2pProxyMain implements P2pProxyMainMBean {
private static P2pProxyManagement mP2pProxyManagement;
private static SipProxyRegistrar mSipAndPipeListener;
private static P2pProxyAccountManagementMBean mP2pProxyAccountManagement;
private static P2pProxySipProxyRegistrarManagement mP2pProxySipProxyRegistrarManagement;
private static P2pProxyResourceManagement mP2pProxySipProxyRegistrarManagement;
public final static String ACCOUNT_MGR_MBEAN_NAME="org.linphone.p2proxy:type=account-manager";
public final static String PROXY_REG_MBEAN_NAME="org.linphone.p2proxy:type=proxy-registrar";
public final static String MAIN_MBEAN_NAME="org.linphone.p2proxy:type=main";
......@@ -290,6 +290,7 @@ public class P2pProxyMain implements P2pProxyMainMBean {
if (mSipAndPipeListener!= null) mSipAndPipeListener.stop();
if (mJxtaNetworkManager != null) mJxtaNetworkManager.stop();
mLog.info("p2pproxy stopped");
return;
} catch (Exception e) {
mLog.fatal("error",e);
......@@ -301,7 +302,7 @@ public class P2pProxyMain implements P2pProxyMainMBean {
mJxtaNetworkManager = new JxtaNetworkManager(aProperties,aConfigDir);
mServiceProvider = new EdgePeerServiceManager(aProperties, mJxtaNetworkManager);
mP2pProxyManagement = (P2pProxyManagement) mServiceProvider;
mP2pProxySipProxyRegistrarManagement = (P2pProxySipProxyRegistrarManagement) mServiceProvider;
mP2pProxySipProxyRegistrarManagement = (P2pProxyResourceManagement) mServiceProvider;
mServiceProvider.start(3000L);
}
......@@ -310,7 +311,7 @@ public class P2pProxyMain implements P2pProxyMainMBean {
mJxtaNetworkManager = new JxtaNetworkManager(aProperties,aConfigDir);
mServiceProvider = new SuperPeerServiceManager(aProperties, mJxtaNetworkManager);
mP2pProxyManagement = (P2pProxyManagement) mServiceProvider;
mP2pProxySipProxyRegistrarManagement = (P2pProxySipProxyRegistrarManagement) mServiceProvider;
mP2pProxySipProxyRegistrarManagement = (P2pProxyResourceManagement) mServiceProvider;
mServiceProvider.start(3000L);
}
private static void startSeeding(Configurator aProperties,File aConfigDir) throws Exception{
......@@ -318,7 +319,7 @@ public class P2pProxyMain implements P2pProxyMainMBean {
mJxtaNetworkManager = new JxtaNetworkManager(aProperties,aConfigDir);
mServiceProvider = new SeedingPeerServiceManager(aProperties, mJxtaNetworkManager,true);
mP2pProxyManagement = null;
mP2pProxySipProxyRegistrarManagement = (P2pProxySipProxyRegistrarManagement) mServiceProvider;
mP2pProxySipProxyRegistrarManagement = (P2pProxyResourceManagement) mServiceProvider;
mServiceProvider.start(3000L);
}
private static void usage() {
......
......@@ -35,7 +35,7 @@ import org.linphone.p2pproxy.core.media.rtprelay.RtpRelayServiceClient;
import org.linphone.p2pproxy.core.rdvautoconfig.PeerInfoServiceClient;
import org.linphone.p2pproxy.core.sipproxy.SipProxyRegistrarAdvertisement;
public abstract class P2pProxyManagementImpl extends P2pProxySipProxyRegistrarManagementImpl implements ServiceProvider,P2pProxyManagement {
public abstract class P2pProxyManagementImpl extends P2pProxyResourceManagementImpl implements ServiceProvider,P2pProxyManagement {
protected final Configurator mConfigurator;
private final PeerInfoServiceClient mPeerInfoServiceClient;
private final static Logger mLog = Logger.getLogger(P2pProxyManagementImpl.class);
......
......@@ -2,14 +2,14 @@ package org.linphone.p2pproxy.core;
import org.apache.log4j.Logger;
import org.linphone.p2pproxy.api.P2pProxyException;
import org.linphone.p2pproxy.api.P2pProxySipProxyRegistrarManagement;
import org.linphone.p2pproxy.api.P2pProxyResourceManagement;
import org.linphone.p2pproxy.core.sipproxy.SipProxyRegistrarAdvertisement;
public class P2pProxySipProxyRegistrarManagementImpl implements P2pProxySipProxyRegistrarManagement {
public class P2pProxyResourceManagementImpl implements P2pProxyResourceManagement {
protected final JxtaNetworkManager mJxtaNetworkManager;
private final String DOMAINE="p2p.linphone.org";
private final static Logger mLog = Logger.getLogger(P2pProxySipProxyRegistrarManagementImpl.class);
P2pProxySipProxyRegistrarManagementImpl(JxtaNetworkManager aJxtaNetworkManager) {
private final static Logger mLog = Logger.getLogger(P2pProxyResourceManagementImpl.class);
P2pProxyResourceManagementImpl(JxtaNetworkManager aJxtaNetworkManager) {
mJxtaNetworkManager = aJxtaNetworkManager;
}
public String lookupSipProxyUri(String aDomaine) throws P2pProxyException {
......@@ -34,5 +34,8 @@ public class P2pProxySipProxyRegistrarManagementImpl implements P2pProxySipProxy
throw new P2pProxyException(e);
}
}
public String[] getMediaServerList() throws P2pProxyException {
throw new RuntimeException("not implmented yet");
}
}
......@@ -17,7 +17,7 @@ import org.linphone.p2pproxy.core.media.rtprelay.RtpRelayService;
import org.linphone.p2pproxy.core.media.rtprelay.RtpRelayServerConfig;
import org.linphone.p2pproxy.core.rdvautoconfig.PeerInfoProviderService;
public class SeedingPeerServiceManager extends P2pProxySipProxyRegistrarManagementImpl implements ServiceProvider {
public class SeedingPeerServiceManager extends P2pProxyResourceManagementImpl implements ServiceProvider {
protected final Configurator mConfigurator;
private final PeerInfoProviderService mPeerInfoProviderService;
private RtpRelayService mUdpRelayService = null;
......
/*
* This file is part of JSTUN.
*
* Copyright (c) 2005 Thomas King <king@t-king.de> - All rights
* reserved.
*
* This software is licensed under either the GNU Public License (GPL),
* or the Apache 2.0 license. Copies of both license agreements are
* included in this distribution.
*/
p2pproxy Copyright (C) 2007 Jehan Monnier ()
StunServer.java - .
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package org.linphone.p2pproxy.core.stun;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.Vector;
import java.util.logging.FileHandler;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;
import org.apache.log4j.Logger;
import org.linphone.p2pproxy.api.P2pProxyException;
import org.linphone.p2pproxy.core.GenericUdpSession;
import org.linphone.p2pproxy.core.ServiceProvider;
import de.javawi.jstun.attribute.ChangeRequest;
import de.javawi.jstun.attribute.ChangedAddress;
import de.javawi.jstun.attribute.ErrorCode;
import de.javawi.jstun.attribute.MappedAddress;
import de.javawi.jstun.attribute.MessageAttributeException;
import de.javawi.jstun.attribute.MessageAttributeParsingException;
import de.javawi.jstun.attribute.ResponseAddress;
import de.javawi.jstun.attribute.SourceAddress;
import de.javawi.jstun.attribute.UnknownAttribute;
......@@ -38,147 +41,107 @@ import de.javawi.jstun.header.MessageHeader;
import de.javawi.jstun.header.MessageHeaderParsingException;
import de.javawi.jstun.header.MessageHeaderInterface.MessageHeaderType;
import de.javawi.jstun.util.Address;
import de.javawi.jstun.util.UtilityException;
/*
* This class implements a STUN server as described in RFC 3489.
* The server requires a machine that is dual-homed to be functional.
* neither change port nor change address are implemented
*/
public class StunServer {
private static Logger logger = Logger.getLogger("org.linphone.p2pproxy.core.stun.StunServer");
Vector<DatagramSocket> sockets;
public StunServer(int primaryPort, InetAddress primary, int secondaryPort) throws SocketException {
sockets = new Vector<DatagramSocket>();
sockets.add(new DatagramSocket(primaryPort, primary));
sockets.add(new DatagramSocket(secondaryPort, primary));
public class StunServer implements GenericUdpSession.MessageHandler {
private static Logger mLog = Logger.getLogger(StunServer.class);
private final DatagramSocket mSocket;
public StunServer(DatagramSocket mListeningSocket) throws SocketException {
mSocket = mListeningSocket;
}
public void start() throws SocketException {
for (DatagramSocket socket : sockets) {
socket.setReceiveBufferSize(2000);
StunServerReceiverThread ssrt = new StunServerReceiverThread(socket);
ssrt.start();
public void onMessage(DatagramPacket lMessage) {
// derivated from JSTUN (Thomas King)
MessageHeader receiveMH = null;
try {
receiveMH = MessageHeader.parseHeader(lMessage.getData());
} catch (MessageHeaderParsingException e1) {
if (mLog.isInfoEnabled()) mLog.info("not a stun message");
return;
}
}
/*
* Inner class to handle incoming packets and react accordingly.
* I decided not to start a thread for every received Binding Request, because the time
* required to receive a Binding Request, parse it, generate a Binding Response and send
* it varies only between 2 and 4 milliseconds. This amount of time is small enough so
* that no extra thread is needed for incoming Binding Request.
*/
class StunServerReceiverThread extends Thread {
private DatagramSocket receiverSocket;
private DatagramSocket changedPort;
StunServerReceiverThread(DatagramSocket datagramSocket) {
this.receiverSocket = datagramSocket;
for (DatagramSocket socket : sockets) {
if ((socket.getLocalPort() != receiverSocket.getLocalPort()) &&
(socket.getLocalAddress().equals(receiverSocket.getLocalAddress())))
changedPort = socket;
try {
receiveMH.parseAttributes(lMessage.getData());
if (receiveMH.getType() == MessageHeaderType.BindingRequest) {
ChangeRequest cr = (ChangeRequest) receiveMH.getMessageAttribute(MessageAttributeType.ChangeRequest);
if (cr == null) throw new MessageAttributeException("Message attribute change request is not set.");
ResponseAddress ra = (ResponseAddress) receiveMH.getMessageAttribute(MessageAttributeType.ResponseAddress);
MessageHeader sendMH = new MessageHeader(MessageHeaderType.BindingResponse);
sendMH.setTransactionID(receiveMH.getTransactionID());
// Mapped address attribute
MappedAddress ma = new MappedAddress();
ma.setAddress(new Address(lMessage.getAddress().getAddress()));
ma.setPort(lMessage.getPort());
sendMH.addMessageAttribute(ma);
if ((!cr.isChangePort()) && (!cr.isChangeIP())) {
if (mLog.isInfoEnabled()) mLog.info("Nothing received in Change Request attribute");
// Source address attribute
SourceAddress sa = new SourceAddress();
sa.setAddress(new Address(mSocket.getLocalAddress().getAddress()));
sa.setPort(mSocket.getLocalPort());
sendMH.addMessageAttribute(sa);
byte[] data = sendMH.getBytes();
DatagramPacket send = new DatagramPacket(data, data.length);
if (ra != null) {
send.setPort(ra.getPort());
send.setAddress(ra.getAddress().getInetAddress());
} else {
send.setPort(lMessage.getPort());
send.setAddress(lMessage.getAddress());
}
mSocket.send(send);
if (mLog.isInfoEnabled()) mLog.info(mSocket.getLocalAddress().getHostAddress() + ":" + mSocket.getLocalPort() + " send Binding Response to " + send.getAddress().getHostAddress() + ":" + send.getPort());
} else {
// Generate Binding error response
sendMH = new MessageHeader(MessageHeaderType.BindingErrorResponse);
sendMH.setTransactionID(receiveMH.getTransactionID());
ErrorCode lErrorCode = new ErrorCode();
lErrorCode.setResponseCode(400); //bad request
sendMH.addMessageAttribute(lErrorCode);
byte[] data = sendMH.getBytes();
DatagramPacket send = new DatagramPacket(data, data.length);
send.setPort(lMessage.getPort());
send.setAddress(lMessage.getAddress());
mSocket.send(send);
if (mLog.isInfoEnabled()) mLog.info("cannot handle cr ["+cr+"] attibute");
}
}
}
public void run() {
while (true) {
try {
DatagramPacket receive = new DatagramPacket(new byte[200], 200);
receiverSocket.receive(receive);
logger.finest(receiverSocket.getLocalAddress().getHostAddress() + ":" + receiverSocket.getLocalPort() + " datagram received from " + receive.getAddress().getHostAddress() + ":" + receive.getPort());
MessageHeader receiveMH = MessageHeader.parseHeader(receive.getData());
try {
receiveMH.parseAttributes(receive.getData());
if (receiveMH.getType() == MessageHeaderType.BindingRequest) {
logger.config(receiverSocket.getLocalAddress().getHostAddress() + ":" + receiverSocket.getLocalPort() + " Binding Request received from " + receive.getAddress().getHostAddress() + ":" + receive.getPort());
ChangeRequest cr = (ChangeRequest) receiveMH.getMessageAttribute(MessageAttributeType.ChangeRequest);
if (cr == null) throw new MessageAttributeException("Message attribute change request is not set.");
ResponseAddress ra = (ResponseAddress) receiveMH.getMessageAttribute(MessageAttributeType.ResponseAddress);
MessageHeader sendMH = new MessageHeader(MessageHeaderType.BindingResponse);
sendMH.setTransactionID(receiveMH.getTransactionID());
// Mapped address attribute
MappedAddress ma = new MappedAddress();
ma.setAddress(new Address(receive.getAddress().getAddress()));
ma.setPort(receive.getPort());
sendMH.addMessageAttribute(ma);
if (cr.isChangePort()) {
logger.finer("Change port received in Change Request attribute");
// Source address attribute
SourceAddress sa = new SourceAddress();
sa.setAddress(new Address(changedPort.getLocalAddress().getAddress()));
sa.setPort(changedPort.getLocalPort());
sendMH.addMessageAttribute(sa);
byte[] data = sendMH.getBytes();
DatagramPacket send = new DatagramPacket(data, data.length);
if (ra != null) {
send.setPort(ra.getPort());
send.setAddress(ra.getAddress().getInetAddress());
} else {
send.setPort(receive.getPort());
send.setAddress(receive.getAddress());
}
changedPort.send(send);
logger.config(changedPort.getLocalAddress().getHostAddress() + ":" + changedPort.getLocalPort() + " send Binding Response to " + send.getAddress().getHostAddress() + ":" + send.getPort());
} else if ((!cr.isChangePort()) && (!cr.isChangeIP())) {
logger.finer("Nothing received in Change Request attribute");
// Source address attribute
SourceAddress sa = new SourceAddress();
sa.setAddress(new Address(receiverSocket.getLocalAddress().getAddress()));
sa.setPort(receiverSocket.getLocalPort());
sendMH.addMessageAttribute(sa);
byte[] data = sendMH.getBytes();
DatagramPacket send = new DatagramPacket(data, data.length);
if (ra != null) {
send.setPort(ra.getPort());
send.setAddress(ra.getAddress().getInetAddress());
} else {
send.setPort(receive.getPort());
send.setAddress(receive.getAddress());
}
receiverSocket.send(send);
logger.config(receiverSocket.getLocalAddress().getHostAddress() + ":" + receiverSocket.getLocalPort() + " send Binding Response to " + send.getAddress().getHostAddress() + ":" + send.getPort());
} else {
logger.warning("cannot handle cr ["+cr+"]");
}
}
} catch (UnknownMessageAttributeException umae) {
umae.printStackTrace();
// Generate Binding error response
MessageHeader sendMH = new MessageHeader(MessageHeaderType.BindingErrorResponse);
sendMH.setTransactionID(receiveMH.getTransactionID());
// Unknown attributes
UnknownAttribute ua = new UnknownAttribute();
ua.addAttribute(umae.getType());
sendMH.addMessageAttribute(ua);
byte[] data = sendMH.getBytes();
DatagramPacket send = new DatagramPacket(data, data.length);
send.setPort(receive.getPort());
send.setAddress(receive.getAddress());
receiverSocket.send(send);
logger.config(" send Binding Error Response to " + send.getAddress().getHostAddress() + ":" + send.getPort());
}
} catch (IOException ioe) {
ioe.printStackTrace();
} catch (MessageAttributeParsingException mape) {
mape.printStackTrace();
} catch (MessageAttributeException mae) {
mae.printStackTrace();
} catch (MessageHeaderParsingException mhpe) {
mhpe.printStackTrace();
} catch (UtilityException ue) {
ue.printStackTrace();
} catch (ArrayIndexOutOfBoundsException aioobe) {
aioobe.printStackTrace();
} catch ( Exception e) {
try {
// Generate Binding error response
MessageHeader sendMH = new MessageHeader(MessageHeaderType.BindingErrorResponse);
sendMH.setTransactionID(receiveMH.getTransactionID());
if (e instanceof UnknownMessageAttributeException) {
// Unknown attributes
UnknownAttribute ua = new UnknownAttribute();
ua.addAttribute(((UnknownMessageAttributeException) e).getType());
sendMH.addMessageAttribute(ua);
} else {
ErrorCode lErrorCode = new ErrorCode();
lErrorCode.setResponseCode(500);
sendMH.addMessageAttribute(lErrorCode);
}
byte[] data = sendMH.getBytes();
DatagramPacket send = new DatagramPacket(data, data.length);
send.setPort(lMessage.getPort());
send.setAddress(lMessage.getAddress());
mSocket.send(send);
mLog.error(" send Binding Error Response to " + send.getAddress().getHostAddress() + ":" + send.getPort(),e);
} catch(Exception e1) {
mLog.error("cannot handle error", e1);
}
}
}
}
}
\ No newline at end of file
......@@ -25,6 +25,7 @@ import junit.framework.TestCase;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;
import org.linphone.p2pproxy.core.GenericUdpSession;
import org.linphone.p2pproxy.core.stun.StunServer;
......@@ -53,12 +54,14 @@ public class StunServerTester extends TestCase {
DatagramSocket socketTest1 = null;
DiscoveryInfo di = null;
static StunServer mSturServer = null;
static GenericUdpSession mGenericUdpSession = null;
public void setUp() throws Exception {
if (mSturServer == null) {
BasicConfigurator.configure();
mGenericUdpSession = new GenericUdpSession(aSocketAddress,this);
if (mSturServer == null) mSturServer = new StunServer(port,InetAddress.getByName("localhost"),port+1);
mSturServer.start();
iaddress = InetAddress.getLocalHost();
......
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