Skip to content

Commit

Permalink
Fix Retransmitter creation to take effect of originalWaitInterval config
Browse files Browse the repository at this point in the history
  • Loading branch information
keepsimple1 authored and bgrozev committed Apr 24, 2019
1 parent 0ea60d8 commit 105a497
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Expand Up @@ -7,3 +7,7 @@
.project
.settings/
bin/

# Ignore IntelliJ IDEA files
.idea
*.iml
4 changes: 3 additions & 1 deletion src/main/java/org/ice4j/stack/StunClientTransaction.java
Expand Up @@ -150,7 +150,7 @@ public class StunClientTransaction
/**
* A transaction request retransmitter
*/
private final Retransmitter retransmitter = new Retransmitter();
private final Retransmitter retransmitter;

/**
* Creates a client transaction.
Expand Down Expand Up @@ -206,6 +206,8 @@ public StunClientTransaction(StunStack stackCallback,

initTransactionConfiguration();

retransmitter = new Retransmitter(); // create it here to support 'originalWaitInterval' configuration

this.transactionID = transactionID;

try
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/org/ice4j/stack/DatagramCollector.java
Expand Up @@ -36,7 +36,8 @@ public void run()
{
try
{

// The 'receive' method synchronized the packet, hence the 'getData()' (also synchronized) will block
// on this anyway even after 'waitForPacket' and 'collectPacket' calls.
sock.receive(receivedPacket);

synchronized (this)
Expand Down
57 changes: 57 additions & 0 deletions src/test/java/org/ice4j/stack/ShallowStackTest.java
Expand Up @@ -316,6 +316,63 @@ public void testReceiveResponse()
Arrays.equals(expectedReturn, actualReturn));
}

/**
* Verify StackProperties.FIRST_CTRAN_RETRANS_AFTER can indeed update StunClientTransaction.Retransmitter
*/
public void testRetransmissionOriginalWait()
throws Exception
{
long originalWait = 200; // milliseconds
System.setProperty(StackProperties.FIRST_CTRAN_RETRANS_AFTER, String.valueOf(originalWait));

Request bindingRequest = MessageFactory.createBindingRequest();

dgramCollector.startListening(dummyServerSocket);

long firstTime = System.currentTimeMillis();

stunStack.sendRequest(bindingRequest,
dummyServerAddress,
localAddress,
new SimpleResponseCollector());

//wait for its arrival
dgramCollector.waitForPacket();
DatagramPacket receivedPacket = dgramCollector.collectPacket();

assertTrue("The stack did not properly send a Binding Request",
(receivedPacket.getLength() > 0));

Request receivedRequest =
(Request)Request.decode(receivedPacket.getData(),
(char)0,
(char)receivedPacket.getLength());
assertEquals("The received request did not match the "
+"one that was sent.",
bindingRequest, //expected
receivedRequest); // actual

// wait for the 1st retransmission with originalWait
dgramCollector.startListening(dummyServerSocket);
dgramCollector.waitForPacket();
receivedPacket = dgramCollector.collectPacket();

assertTrue("The stack did not retransmit a Binding Request",
(receivedPacket.getLength() > 0));

receivedRequest = (Request)Request.decode(
receivedPacket.getData(),
(char)0,
(char)receivedPacket.getLength());
assertEquals("The retransmitted request did not match the original.",
bindingRequest, //expected
receivedRequest); // actual

// verify the retransmission is longer than the originalWait
long secondTime = System.currentTimeMillis();
assertTrue((secondTime - firstTime) >= originalWait);
}

//--------------------------------------- listener implementations ---------
/**
* A simple utility that allows us to asynchronously collect messages.
Expand Down

0 comments on commit 105a497

Please sign in to comment.