diff --git a/src/org/ice4j/BaseStunMessageEvent.java b/src/org/ice4j/BaseStunMessageEvent.java index 91136fb..b66aca0 100644 --- a/src/org/ice4j/BaseStunMessageEvent.java +++ b/src/org/ice4j/BaseStunMessageEvent.java @@ -15,7 +15,7 @@ import org.ice4j.stack.*; * Represents an EventObject which notifies of an event associated with * a specific STUN Message. * - * @author Lubomir Marinov + * @author Lyubomir Marinov */ public class BaseStunMessageEvent extends EventObject @@ -30,6 +30,11 @@ public class BaseStunMessageEvent */ private final Message message; + /** + * The StunStack associated with this instance. + */ + private final StunStack stunStack; + /** * The ID of the transaction related to {@link #message}. */ @@ -39,14 +44,20 @@ public class BaseStunMessageEvent * Initializes a new BaseStunMessageEvent associated with a * specific STUN Message. * + * @param stunStack the StunStack to be associated with the new + * instance * @param sourceAddress the TransportAddress which is to be * reported as the source of the new event * @param message the STUN Message associated with the new event */ - public BaseStunMessageEvent(TransportAddress sourceAddress, Message message) + public BaseStunMessageEvent( + StunStack stunStack, + TransportAddress sourceAddress, + Message message) { super(sourceAddress); + this.stunStack = stunStack; this.message = message; } @@ -70,6 +81,16 @@ public class BaseStunMessageEvent return (TransportAddress) getSource(); } + /** + * Gets the StunStack associated with this instance. + * + * @return the StunStack associated with this instance + */ + public StunStack getStunStack() + { + return stunStack; + } + /** * Gets the ID of the transaction related to the STUN Message * associated with this event. @@ -80,9 +101,12 @@ public class BaseStunMessageEvent public TransactionID getTransactionID() { if (transactionID == null) + { transactionID - = TransactionID - .createTransactionID(getMessage().getTransactionID()); + = TransactionID.createTransactionID( + getStunStack(), + getMessage().getTransactionID()); + } return transactionID; } diff --git a/src/org/ice4j/StunFailureEvent.java b/src/org/ice4j/StunFailureEvent.java index fd9bc30..0dd67e6 100644 --- a/src/org/ice4j/StunFailureEvent.java +++ b/src/org/ice4j/StunFailureEvent.java @@ -7,6 +7,7 @@ package org.ice4j; import org.ice4j.message.*; +import org.ice4j.stack.*; /** * The class is used to dispatch events that occur when a STUN transaction @@ -31,18 +32,22 @@ public class StunFailureEvent /** * Constructs a StunFailureEvent according to the specified * message. - * + * + * @param stunStack the StunStack to be associated with the new + * instance * @param message the message itself * @param localAddress the local address that the message was sent from. * @param cause the Exception that caused this failure or * null if there's no Exception associated with this * failure */ - public StunFailureEvent(Message message, - TransportAddress localAddress, - Throwable cause) + public StunFailureEvent( + StunStack stunStack, + Message message, + TransportAddress localAddress, + Throwable cause) { - super(localAddress, message); + super(stunStack, localAddress, message); this.cause = cause; } diff --git a/src/org/ice4j/StunMessageEvent.java b/src/org/ice4j/StunMessageEvent.java index aa060af..5a24420 100644 --- a/src/org/ice4j/StunMessageEvent.java +++ b/src/org/ice4j/StunMessageEvent.java @@ -34,13 +34,18 @@ public class StunMessageEvent /** * Constructs a StunMessageEvent according to the specified message. * + * @param stunStack the StunStack to be associated with the new + * instance * @param rawMessage the crude message we got off the wire. * @param parsedMessage the message itself */ - public StunMessageEvent(RawMessage rawMessage, - Message parsedMessage) + public StunMessageEvent( + StunStack stunStack, + RawMessage rawMessage, + Message parsedMessage) { - super(rawMessage.getLocalAddress(), parsedMessage); + super(stunStack, rawMessage.getLocalAddress(), parsedMessage); + this.rawMessage = rawMessage; } diff --git a/src/org/ice4j/StunResponseEvent.java b/src/org/ice4j/StunResponseEvent.java index 101ee3e..8c86c59 100644 --- a/src/org/ice4j/StunResponseEvent.java +++ b/src/org/ice4j/StunResponseEvent.java @@ -34,18 +34,22 @@ public class StunResponseEvent /** * Creates a new instance of this event. * + * @param stunStack the StunStack to be associated with the new + * instance * @param rawMessage the crude message we got off the wire. * @param response the STUN {@link Response} that we've just received. * @param request the message itself * @param transactionID a reference to the exact {@link TransactionID} * instance that represents the corresponding client transaction. */ - public StunResponseEvent(RawMessage rawMessage, - Response response, - Request request, - TransactionID transactionID) + public StunResponseEvent( + StunStack stunStack, + RawMessage rawMessage, + Response response, + Request request, + TransactionID transactionID) { - super(rawMessage, response); + super(stunStack, rawMessage, response); this.request = request; super.setTransactionID(transactionID); } diff --git a/src/org/ice4j/StunTimeoutEvent.java b/src/org/ice4j/StunTimeoutEvent.java index 794d6eb..0dfc895 100644 --- a/src/org/ice4j/StunTimeoutEvent.java +++ b/src/org/ice4j/StunTimeoutEvent.java @@ -27,16 +27,21 @@ public class StunTimeoutEvent * Constructs a StunTimeoutEvent according to the specified * message. * + * @param stunStack the StunStack to be associated with the new + * instance * @param message the message itself * @param localAddress the local address that the message was sent from. * @param transactionID the ID of the associated with this event. */ - public StunTimeoutEvent(Message message, - TransportAddress localAddress, - TransactionID transactionID) + public StunTimeoutEvent( + StunStack stunStack, + Message message, + TransportAddress localAddress, + TransactionID transactionID) { - super(localAddress, message); - super.setTransactionID(transactionID); + super(stunStack, localAddress, message); + + setTransactionID(transactionID); } /** diff --git a/src/org/ice4j/attribute/ContentDependentAttribute.java b/src/org/ice4j/attribute/ContentDependentAttribute.java index ed739e8..f63282b 100644 --- a/src/org/ice4j/attribute/ContentDependentAttribute.java +++ b/src/org/ice4j/attribute/ContentDependentAttribute.java @@ -6,6 +6,8 @@ */ package org.ice4j.attribute; +import org.ice4j.stack.*; + /** * ContentDependentAttributes have a value that depend on the content * of the message. The {@link MessageIntegrityAttribute} and {@link @@ -13,6 +15,7 @@ package org.ice4j.attribute; *
* Rather than encoding them via the standard {@link Attribute#encode()} method, * the stack would use the one from this interface. + *
* * @author Emil Ivov */ @@ -21,6 +24,8 @@ public interface ContentDependentAttribute /** * Returns a binary representation of this attribute. * + * @param stunStack the StunStack in the context of which the + * request to encode this ContentDependentAttribute is being made * @param content the content of the message that this attribute will be * transported in * @param offset the content-related offset where the actual @@ -30,5 +35,7 @@ public interface ContentDependentAttribute * @return a binary representation of this attribute valid for the message * with the specified content. */ - public byte[] encode(byte[] content, int offset, int length); + public byte[] encode( + StunStack stunStack, + byte[] content, int offset, int length); } diff --git a/src/org/ice4j/attribute/FingerprintAttribute.java b/src/org/ice4j/attribute/FingerprintAttribute.java index 4d4bbca..14f5e6e 100644 --- a/src/org/ice4j/attribute/FingerprintAttribute.java +++ b/src/org/ice4j/attribute/FingerprintAttribute.java @@ -9,6 +9,7 @@ package org.ice4j.attribute; import java.util.zip.*; import org.ice4j.*; +import org.ice4j.stack.*; /** * The FINGERPRINT attribute is used to distinguish STUN packets from packets @@ -145,6 +146,8 @@ public class FingerprintAttribute /** * Returns a binary representation of this attribute. * + * @param stunStack the StunStack in the context of which the + * request to encode this ContentDependentAttribute is being made * @param content the content of the message that this attribute will be * transported in * @param offset the content-related offset where the actual @@ -154,7 +157,9 @@ public class FingerprintAttribute * @return a binary representation of this attribute valid for the message * with the specified content. */ - public byte[] encode(byte[] content, int offset, int length) + public byte[] encode( + StunStack stunStack, + byte[] content, int offset, int length) { char type = getAttributeType(); byte binValue[] = new byte[HEADER_LENGTH + getDataLength()]; diff --git a/src/org/ice4j/attribute/MessageIntegrityAttribute.java b/src/org/ice4j/attribute/MessageIntegrityAttribute.java index 3a2743b..dcdfa89 100644 --- a/src/org/ice4j/attribute/MessageIntegrityAttribute.java +++ b/src/org/ice4j/attribute/MessageIntegrityAttribute.java @@ -228,6 +228,8 @@ public class MessageIntegrityAttribute /** * Returns a binary representation of this attribute. * + * @param stunStack the StunStack in the context of which the + * request to encode this ContentDependentAttribute is being made * @param content the content of the message that this attribute will be * transported in * @param offset the content-related offset where the actual @@ -237,7 +239,9 @@ public class MessageIntegrityAttribute * @return a binary representation of this attribute valid for the message * with the specified content. */ - public byte[] encode(byte[] content, int offset, int length) + public byte[] encode( + StunStack stunStack, + byte[] content, int offset, int length) { char type = getAttributeType(); byte binValue[] = new byte[HEADER_LENGTH + getDataLength()]; @@ -250,8 +254,7 @@ public class MessageIntegrityAttribute binValue[2] = (byte)(getDataLength()>>8); binValue[3] = (byte)(getDataLength()&0x00FF); - byte[] key = StunStack.getInstance().getCredentialsManager() - .getRemoteKey(username); + byte[] key = stunStack.getCredentialsManager().getRemoteKey(username); //now calculate the HMAC-SHA1 this.hmacSha1Content = calculateHmacSha1(content, offset, length, key); diff --git a/src/org/ice4j/ice/Agent.java b/src/org/ice4j/ice/Agent.java index c6b88ba..2bd821b 100644 --- a/src/org/ice4j/ice/Agent.java +++ b/src/org/ice4j/ice/Agent.java @@ -30,6 +30,7 @@ import org.ice4j.stack.*; *
*
* @author Emil Ivov
+ * @author Lyubomir Marinov
*/
public class Agent
{
@@ -189,13 +190,18 @@ public class Agent
private final List
Mac.getInstance(MessageIntegrityAttribute.HMAC_SHA1_ALGORITHM)
+ * has been called.
+ *
+ * @see #StunStack()
+ */
+ private static Mac mac;
+
+ /**
+ * Our network gateway.
+ */
+ private NetAccessManager netAccessManager = null;
+
/**
* The {@link CredentialsManager} that we are using for retrieving
* passwords.
@@ -51,12 +63,6 @@ public class StunStack
private final CredentialsManager credentialsManager
= new CredentialsManager();
- /**
- * Our class logger.
- */
- private static final Logger logger =
- Logger.getLogger(StunStack.class.getName());
-
/**
* Stores active client transactions mapped against TransactionID-s.
*/
@@ -77,34 +83,6 @@ public class StunStack
*/
private final EventDispatcher eventDispatcher = new EventDispatcher();
- /**
- * Returns a reference to the singleton StunStack instance. If the stack
- * had not yet been initialized, a new instance will be created.
- *
- * @return a reference to the StunStack.
- */
- public static synchronized StunStack getInstance()
- {
- if (stackInstance == null)
- {
- //the Mac instantiation used in MessageIntegrityAttribute could
- //take several hundred milliseconds so we don't want it instantiated
- //only after we get a response because the delay may cause the
- //transaction to fail.
- try
- {
- Mac.getInstance(MessageIntegrityAttribute.HMAC_SHA1_ALGORITHM);
- }
- catch (NoSuchAlgorithmException e)
- {
- e.printStackTrace();
- }
- stackInstance = new StunStack();
- }
-
- return stackInstance;
- }
-
/**
* Sets the number of Message processors running in the same time.
*
@@ -265,10 +243,32 @@ public class StunStack
}
/**
- * Private constructor as we want a singleton pattern.
+ * Initializes a new StunStack instance.
*/
- private StunStack()
+ public StunStack()
{
+ /*
+ * The Mac instantiation used in MessageIntegrityAttribute could take
+ * several hundred milliseconds so we don't want it instantiated only
+ * after we get a response because the delay may cause the transaction
+ * to fail.
+ */
+ synchronized (StunStack.class)
+ {
+ if (mac == null)
+ {
+ try
+ {
+ mac
+ = Mac.getInstance(
+ MessageIntegrityAttribute.HMAC_SHA1_ALGORITHM);
+ }
+ catch (NoSuchAlgorithmException nsaex)
+ {
+ nsaex.printStackTrace();
+ }
+ }
+ }
netAccessManager = new NetAccessManager(this);
}
@@ -453,9 +453,9 @@ public class StunStack
IOException,
IllegalArgumentException
{
- TransactionID tid = TransactionID.createTransactionID(transactionID);
- StunServerTransaction sTran =
- serverTransactions.get(tid);
+ TransactionID tid
+ = TransactionID.createTransactionID(this, transactionID);
+ StunServerTransaction sTran = serverTransactions.get(tid);
if(sTran == null)
{
@@ -1012,7 +1012,7 @@ public class StunStack
* @return true if username contains a valid username;
* false, otherwise
*/
- private static boolean validateUsername(String username)
+ private boolean validateUsername(String username)
{
int colon = username.indexOf(":");
@@ -1028,7 +1028,6 @@ public class StunStack
String lfrag = username.substring(0, colon);
- return StunStack.getInstance()
- .getCredentialsManager().checkLocalUserName(lfrag);
+ return getCredentialsManager().checkLocalUserName(lfrag);
}
}
diff --git a/src/org/ice4j/stack/TransactionID.java b/src/org/ice4j/stack/TransactionID.java
index f331168..33d090d 100644
--- a/src/org/ice4j/stack/TransactionID.java
+++ b/src/org/ice4j/stack/TransactionID.java
@@ -84,24 +84,28 @@ public class TransactionID
* to that transaction's instance so that we could use it to for storing
* application data.
*
+ * @param stunStack the StunStack in the context of which the
+ * request to create a TransactionID is being made
* @param transactionID the value of the ID.
*
* @return a reference to the (possibly already existing)
* TransactionID corresponding to the value of
* transactionID
*/
- public static TransactionID createTransactionID(byte[] transactionID)
+ public static TransactionID createTransactionID(
+ StunStack stunStack,
+ byte[] transactionID)
{
//first check whether we can find a client or a server tran with the
//specified id.
- StunClientTransaction cliTran = StunStack.getInstance()
- .getClientTransaction(transactionID);
+ StunClientTransaction cliTran
+ = stunStack.getClientTransaction(transactionID);
if(cliTran != null)
return cliTran.getTransactionID();
- StunServerTransaction serTran = StunStack.getInstance()
- .getServerTransaction(transactionID);
+ StunServerTransaction serTran
+ = stunStack.getServerTransaction(transactionID);
if(serTran != null)
return serTran.getTransactionID();
diff --git a/src/org/ice4j/stunclient/NetworkConfigurationDiscoveryProcess.java b/src/org/ice4j/stunclient/NetworkConfigurationDiscoveryProcess.java
index c88ab81..ebd1b5d 100644
--- a/src/org/ice4j/stunclient/NetworkConfigurationDiscoveryProcess.java
+++ b/src/org/ice4j/stunclient/NetworkConfigurationDiscoveryProcess.java
@@ -80,7 +80,6 @@ import org.ice4j.stack.*;
*
* @author Emil Ivov
*/
-
public class NetworkConfigurationDiscoveryProcess
{
/**
@@ -94,11 +93,6 @@ public class NetworkConfigurationDiscoveryProcess
*/
private boolean started = false;
- /**
- * The stack to use for STUN communication.
- */
- private StunStack stunStack = null;
-
/**
* The point where we'll be listening.
*/
@@ -122,18 +116,29 @@ public class NetworkConfigurationDiscoveryProcess
private DatagramSocket sock = null;
/**
- * Creates a StunAddressDiscoverer. In order to use it one must start the
- * discoverer.
+ * The StunStack used by this instance for the purposes of STUN
+ * communication.
+ */
+ private final StunStack stunStack;
+
+ /**
+ * Initializes a StunAddressDiscoverer with a specific
+ * StunStack. In order to use it one must first start it.
*
+ * @param stunStack the StunStack to be used by the new instance
* @param localAddress the address where the stack should bind.
* @param serverAddress the address of the server to interrogate.
*/
- public NetworkConfigurationDiscoveryProcess(TransportAddress localAddress,
- TransportAddress serverAddress)
+ public NetworkConfigurationDiscoveryProcess(
+ StunStack stunStack,
+ TransportAddress localAddress, TransportAddress serverAddress)
{
+ if (stunStack == null)
+ throw new NullPointerException("stunStack");
+
+ this.stunStack = stunStack;
this.localAddress = localAddress;
this.serverAddress = serverAddress;
-
}
/**
@@ -146,12 +151,10 @@ public class NetworkConfigurationDiscoveryProcess
sock.close();
sock = null;
- stunStack = null;
localAddress = null;
requestSender = null;
this.started = false;
-
}
/**
@@ -162,8 +165,6 @@ public class NetworkConfigurationDiscoveryProcess
public void start()
throws IOException, StunException
{
- stunStack = StunStack.getInstance();
-
sock = new SafeCloseDatagramSocket(localAddress);
stunStack.addSocket(sock);
diff --git a/src/org/ice4j/stunclient/SimpleAddressDetector.java b/src/org/ice4j/stunclient/SimpleAddressDetector.java
index 5d8f81a..3e5776e 100644
--- a/src/org/ice4j/stunclient/SimpleAddressDetector.java
+++ b/src/org/ice4j/stunclient/SimpleAddressDetector.java
@@ -83,7 +83,7 @@ public class SimpleAddressDetector
*/
public void start()
{
- stunStack = StunStack.getInstance();
+ stunStack = new StunStack();
}
diff --git a/test/org/ice4j/MessageEventDispatchingTest.java b/test/org/ice4j/MessageEventDispatchingTest.java
index 1fc91bc..db81262 100644
--- a/test/org/ice4j/MessageEventDispatchingTest.java
+++ b/test/org/ice4j/MessageEventDispatchingTest.java
@@ -89,7 +89,7 @@ public class MessageEventDispatchingTest extends TestCase
{
super.setUp();
- stunStack = StunStack.getInstance();
+ stunStack = new StunStack();
clientSock = new SafeCloseDatagramSocket(clientAddress);
serverSock = new SafeCloseDatagramSocket(serverAddress);
diff --git a/test/org/ice4j/TransactionSupportTests.java b/test/org/ice4j/TransactionSupportTests.java
index 19b137f..615a917 100644
--- a/test/org/ice4j/TransactionSupportTests.java
+++ b/test/org/ice4j/TransactionSupportTests.java
@@ -46,6 +46,11 @@ public class TransactionSupportTests extends TestCase
*/
DatagramSocket serverSock = null;
+ /**
+ * The StunStack used by this TransactionSupportTests.
+ */
+ private StunStack stunStack;
+
/**
* The request we send in this test.
*/
@@ -79,8 +84,9 @@ public class TransactionSupportTests extends TestCase
clientSock = new SafeCloseDatagramSocket(clientAddress);
serverSock = new SafeCloseDatagramSocket(serverAddress);
- StunStack.getInstance().addSocket(clientSock);
- StunStack.getInstance().addSocket(serverSock);
+ stunStack = new StunStack();
+ stunStack.addSocket(clientSock);
+ stunStack.addSocket(serverSock);
bindingRequest = MessageFactory.createBindingRequest();
bindingResponse = MessageFactory.create3482BindingResponse(
@@ -89,16 +95,21 @@ public class TransactionSupportTests extends TestCase
requestCollector = new PlainRequestCollector();
responseCollector = new PlainResponseCollector();
- System.setProperty(StackProperties.PROPAGATE_RECEIVED_RETRANSMISSIONS,
- "false");
- System.setProperty(StackProperties.KEEP_CRANS_AFTER_A_RESPONSE,
- "false");
- System.setProperty(StackProperties.MAX_CTRAN_RETRANSMISSIONS,
- "");
- System.setProperty(StackProperties.MAX_CTRAN_RETRANS_TIMER,
- "");
- System.setProperty(StackProperties.FIRST_CTRAN_RETRANS_AFTER,
- "");
+ System.setProperty(
+ StackProperties.PROPAGATE_RECEIVED_RETRANSMISSIONS,
+ "false");
+ System.setProperty(
+ StackProperties.KEEP_CRANS_AFTER_A_RESPONSE,
+ "false");
+ System.setProperty(
+ StackProperties.MAX_CTRAN_RETRANSMISSIONS,
+ "");
+ System.setProperty(
+ StackProperties.MAX_CTRAN_RETRANS_TIMER,
+ "");
+ System.setProperty(
+ StackProperties.FIRST_CTRAN_RETRANS_AFTER,
+ "");
}
/**
@@ -109,8 +120,8 @@ public class TransactionSupportTests extends TestCase
protected void tearDown()
throws Exception
{
- StunStack.getInstance().removeSocket(clientAddress);
- StunStack.getInstance().removeSocket(serverAddress);
+ stunStack.removeSocket(clientAddress);
+ stunStack.removeSocket(serverAddress);
clientSock.close();
serverSock.close();
@@ -118,16 +129,21 @@ public class TransactionSupportTests extends TestCase
requestCollector = null;
responseCollector = null;
- System.setProperty(StackProperties.PROPAGATE_RECEIVED_RETRANSMISSIONS,
- "false");
- System.setProperty(StackProperties.KEEP_CRANS_AFTER_A_RESPONSE,
- "false");
- System.setProperty(StackProperties.MAX_CTRAN_RETRANSMISSIONS,
- "");
- System.setProperty(StackProperties.MAX_CTRAN_RETRANS_TIMER,
- "");
- System.setProperty(StackProperties.FIRST_CTRAN_RETRANS_AFTER,
- "");
+ System.setProperty(
+ StackProperties.PROPAGATE_RECEIVED_RETRANSMISSIONS,
+ "false");
+ System.setProperty(
+ StackProperties.KEEP_CRANS_AFTER_A_RESPONSE,
+ "false");
+ System.setProperty(
+ StackProperties.MAX_CTRAN_RETRANSMISSIONS,
+ "");
+ System.setProperty(
+ StackProperties.MAX_CTRAN_RETRANS_TIMER,
+ "");
+ System.setProperty(
+ StackProperties.FIRST_CTRAN_RETRANS_AFTER,
+ "");
super.tearDown();
}
@@ -151,11 +167,13 @@ public class TransactionSupportTests extends TestCase
System.setProperty(StackProperties.PROPAGATE_RECEIVED_RETRANSMISSIONS,
"true");
- StunStack.getInstance()
- .addRequestListener(serverAddress, requestCollector);
+ stunStack.addRequestListener(serverAddress, requestCollector);
//send
- StunStack.getInstance().sendRequest(bindingRequest,
- serverAddress, clientAddress, responseCollector);
+ stunStack.sendRequest(
+ bindingRequest,
+ serverAddress,
+ clientAddress,
+ responseCollector);
//wait for retransmissions
Thread.sleep(1000);
@@ -198,11 +216,13 @@ public class TransactionSupportTests extends TestCase
StackProperties.MAX_CTRAN_RETRANSMISSIONS);
System.setProperty(StackProperties.MAX_CTRAN_RETRANSMISSIONS, "2");
//prepare to listen
- StunStack.getInstance().addRequestListener(
- serverAddress, requestCollector);
+ stunStack.addRequestListener(serverAddress, requestCollector);
//send
- StunStack.getInstance().sendRequest(bindingRequest,
- serverAddress, clientAddress, responseCollector);
+ stunStack.sendRequest(
+ bindingRequest,
+ serverAddress,
+ clientAddress,
+ responseCollector);
//wait for retransmissions
Thread.sleep(1000);
@@ -240,14 +260,16 @@ public class TransactionSupportTests extends TestCase
System.setProperty(StackProperties.MAX_CTRAN_RETRANS_TIMER, "100");
//prepare to listen
- System.setProperty(StackProperties.KEEP_CRANS_AFTER_A_RESPONSE,
- "true");
- StunStack.getInstance().addRequestListener(
- serverAddress, requestCollector);
+ System.setProperty(
+ StackProperties.KEEP_CRANS_AFTER_A_RESPONSE,
+ "true");
+ stunStack.addRequestListener(serverAddress, requestCollector);
//send
- StunStack.getInstance().sendRequest(
- bindingRequest, serverAddress,
- clientAddress, responseCollector);
+ stunStack.sendRequest(
+ bindingRequest,
+ serverAddress,
+ clientAddress,
+ responseCollector);
//wait for the message to arrive
requestCollector.waitForRequest();
@@ -258,8 +280,12 @@ public class TransactionSupportTests extends TestCase
StunMessageEvent evt = reqs.get(0);
byte[] tid = evt.getMessage().getTransactionID();
- StunStack.getInstance().sendResponse(
- tid, bindingResponse, serverAddress, clientAddress);
+
+ stunStack.sendResponse(
+ tid,
+ bindingResponse,
+ serverAddress,
+ clientAddress);
//wait for retransmissions
Thread.sleep(500);
@@ -287,11 +313,13 @@ public class TransactionSupportTests extends TestCase
*/
public void testUniqueIDs() throws Exception
{
- StunStack.getInstance().addRequestListener(
- serverAddress, requestCollector);
+ stunStack.addRequestListener(serverAddress, requestCollector);
//send req 1
- StunStack.getInstance().sendRequest(bindingRequest,
- serverAddress, clientAddress, responseCollector);
+ stunStack.sendRequest(
+ bindingRequest,
+ serverAddress,
+ clientAddress,
+ responseCollector);
//wait for retransmissions
requestCollector.waitForRequest();
@@ -303,12 +331,19 @@ public class TransactionSupportTests extends TestCase
//send a response to make the other guy shut up
byte[] tid = evt1.getMessage().getTransactionID();
- StunStack.getInstance().sendResponse(tid,
- bindingResponse, serverAddress, clientAddress);
+
+ stunStack.sendResponse(
+ tid,
+ bindingResponse,
+ serverAddress,
+ clientAddress);
//send req 2
- StunStack.getInstance().sendRequest(bindingRequest,
- serverAddress, clientAddress, responseCollector);
+ stunStack.sendRequest(
+ bindingRequest,
+ serverAddress,
+ clientAddress,
+ responseCollector);
//wait for retransmissions
Thread.sleep(1000);
@@ -336,16 +371,19 @@ public class TransactionSupportTests extends TestCase
{
//MAX_RETRANSMISSIONS
- System.setProperty(StackProperties.MAX_CTRAN_RETRANSMISSIONS,
- "2");
+ System.setProperty(StackProperties.MAX_CTRAN_RETRANSMISSIONS, "2");
//make sure we see retransmissions so that we may count them
- System.setProperty(StackProperties.PROPAGATE_RECEIVED_RETRANSMISSIONS,
- "true");
- StunStack.getInstance().addRequestListener(
+ System.setProperty(
+ StackProperties.PROPAGATE_RECEIVED_RETRANSMISSIONS,
+ "true");
+ stunStack.addRequestListener(
serverAddress, requestCollector);
//send
- StunStack.getInstance().sendRequest(
- bindingRequest, serverAddress, clientAddress, responseCollector);
+ stunStack.sendRequest(
+ bindingRequest,
+ serverAddress,
+ clientAddress,
+ responseCollector);
//wait for retransmissions
Thread.sleep(1600);
@@ -373,16 +411,18 @@ public class TransactionSupportTests extends TestCase
throws Exception
{
//MAX_RETRANSMISSIONS
- System.setProperty(StackProperties.FIRST_CTRAN_RETRANS_AFTER,
- "50");
+ System.setProperty(StackProperties.FIRST_CTRAN_RETRANS_AFTER, "50");
//make sure we see retransmissions so that we may count them
- System.setProperty(StackProperties.PROPAGATE_RECEIVED_RETRANSMISSIONS,
- "true");
- StunStack.getInstance().addRequestListener(
- serverAddress, requestCollector);
+ System.setProperty(
+ StackProperties.PROPAGATE_RECEIVED_RETRANSMISSIONS,
+ "true");
+ stunStack.addRequestListener(serverAddress, requestCollector);
//send
- StunStack.getInstance().sendRequest(bindingRequest,
- serverAddress, clientAddress, responseCollector);
+ stunStack.sendRequest(
+ bindingRequest,
+ serverAddress,
+ clientAddress,
+ responseCollector);
//wait a while
requestCollector.waitForRequest();
@@ -421,11 +461,13 @@ public class TransactionSupportTests extends TestCase
"true");
System.setProperty(StackProperties.MAX_CTRAN_RETRANSMISSIONS,
"11");
- StunStack.getInstance()
- .addRequestListener(serverAddress, requestCollector);
+ stunStack.addRequestListener(serverAddress, requestCollector);
//send
- StunStack.getInstance().sendRequest(bindingRequest,
- serverAddress, clientAddress, responseCollector);
+ stunStack.sendRequest(
+ bindingRequest,
+ serverAddress,
+ clientAddress,
+ responseCollector);
//wait a while
Thread.sleep(1200);
diff --git a/test/org/ice4j/message/MessageTest.java b/test/org/ice4j/message/MessageTest.java
index 8c16bda..6b03902 100644
--- a/test/org/ice4j/message/MessageTest.java
+++ b/test/org/ice4j/message/MessageTest.java
@@ -12,6 +12,7 @@ import junit.framework.*;
import org.ice4j.*;
import org.ice4j.attribute.*;
+import org.ice4j.stack.*;
public class MessageTest extends TestCase {
private Message bindingRequest = null;
@@ -25,11 +26,18 @@ public class MessageTest extends TestCase {
private MsgFixture msgFixture;
+ /**
+ * The StunStack used by this MessageTest.
+ */
+ private StunStack stunStack;
+
protected void setUp() throws Exception {
super.setUp();
+
msgFixture = new MsgFixture();
msgFixture.setUp();
+ stunStack = new StunStack();
//binding request
bindingRequest = new Request();
@@ -78,9 +86,11 @@ public class MessageTest extends TestCase {
changeRequest = null;
changeRequest = null;
- msgFixture.tearDown();
+ stunStack = null;
+ msgFixture.tearDown();
msgFixture = null;
+
super.tearDown();
}
@@ -130,14 +140,14 @@ public class MessageTest extends TestCase {
//Binding Request
byte[] expectedReturn = msgFixture.bindingRequest;
- byte[] actualReturn = bindingRequest.encode();
+ byte[] actualReturn = bindingRequest.encode(stunStack);
assertTrue("A binding request was not properly encoded",
Arrays.equals( expectedReturn, actualReturn ) );
//Binding Response
expectedReturn = msgFixture.bindingResponse;
- actualReturn = bindingResponse.encode();
+ actualReturn = bindingResponse.encode(stunStack);
assertTrue("A binding response was not properly encoded",
Arrays.equals( expectedReturn, actualReturn ) );
diff --git a/test/org/ice4j/stack/ShallowStackTest.java b/test/org/ice4j/stack/ShallowStackTest.java
index 5a4d3a2..b313ee8 100644
--- a/test/org/ice4j/stack/ShallowStackTest.java
+++ b/test/org/ice4j/stack/ShallowStackTest.java
@@ -21,12 +21,19 @@ import org.ice4j.socket.*;
*
* @author Emil Ivov
*/
-public class ShallowStackTest extends TestCase {
+public class ShallowStackTest extends TestCase
+{
+ /**
+ * The Logger used by the ShallowStackTest class and its
+ * instances for logging output.
+ */
+ private static final Logger logger
+ = Logger.getLogger(ShallowStackTest.class.getName());
- private static final Logger logger =
- Logger.getLogger(ShallowStackTest.class.getName());
-
- private StunStack stunStack = null;
+ /**
+ * The StunStack used by this ShallowStackTest
+ */
+ private StunStack stunStack;
private MsgFixture msgFixture = null;
private TransportAddress dummyServerAddress = null;
@@ -57,6 +64,7 @@ public class ShallowStackTest extends TestCase {
throws Exception
{
super.setUp();
+
msgFixture = new MsgFixture();
msgFixture.setUp();
//Addresses
@@ -66,7 +74,7 @@ public class ShallowStackTest extends TestCase {
"127.0.0.1", 5004, Transport.UDP);
//init the stack
- stunStack = StunStack.getInstance();
+ stunStack = new StunStack();
//access point
localSock = new SafeCloseDatagramSocket(localAddress);
@@ -177,7 +185,7 @@ public class ShallowStackTest extends TestCase {
assertNotNull("No request has been received", collectedRequest);
byte expectedReturn[] = msgFixture.bindingRequest2;
- byte actualReturn[] = collectedRequest.encode();
+ byte actualReturn[] = collectedRequest.encode(stunStack);
assertTrue("Received request was not the same as the one that was sent",
Arrays.equals(expectedReturn, actualReturn));
}
@@ -208,7 +216,7 @@ public class ShallowStackTest extends TestCase {
Request collectedRequest = requestCollector.collectedRequest;
byte expectedReturn[] = msgFixture.bindingRequest;
- byte actualReturn[] = collectedRequest.encode();
+ byte actualReturn[] = collectedRequest.encode(stunStack);
assertTrue("Received request was not the same as the one that was sent",
Arrays.equals(expectedReturn, actualReturn));
@@ -291,7 +299,7 @@ public class ShallowStackTest extends TestCase {
Response collectedResponse = collector.collectedResponse;
byte expectedReturn[] = response;
- byte actualReturn[] = collectedResponse.encode();
+ byte actualReturn[] = collectedResponse.encode(stunStack);
assertTrue("Received request was not the same as the one that was sent",
Arrays.equals(expectedReturn, actualReturn));
}
diff --git a/test/org/ice4j/stunclient/ResponseSequenceServer.java b/test/org/ice4j/stunclient/ResponseSequenceServer.java
index b234bae..ed4913a 100644
--- a/test/org/ice4j/stunclient/ResponseSequenceServer.java
+++ b/test/org/ice4j/stunclient/ResponseSequenceServer.java
@@ -21,26 +21,46 @@ import org.ice4j.stack.*;
* sequences of responses. It may be used to test whether a STUN client
* behaves correctly in different use cases.
*
- *
* @author Emil Ivov
*/
public class ResponseSequenceServer
implements RequestListener
{
- private static final Logger logger =
- Logger.getLogger(ResponseSequenceServer.class.getName());
+ /**
+ * The Logger used by the ResponseSequenceServer class and
+ * its instances for logging output.
+ */
+ private static final Logger logger
+ = Logger.getLogger(ResponseSequenceServer.class.getName());
+
/**
* The sequence of responses to send.
*/
private Vector