Skip to content
Permalink
Browse files

Fix Retransmitter creation to take effect of originalWaitInterval config

  • Loading branch information...
keepsimple1 authored and bgrozev committed Apr 17, 2019
1 parent 0ea60d8 commit 105a49749e32c0ff337f0c0263caa65e303974c1
@@ -7,3 +7,7 @@
.project
.settings/
bin/

# Ignore IntelliJ IDEA files
.idea
*.iml
@@ -150,7 +150,7 @@
/**
* A transaction request retransmitter
*/
private final Retransmitter retransmitter = new Retransmitter();
private final Retransmitter retransmitter;

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

initTransactionConfiguration();

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

this.transactionID = transactionID;

try
@@ -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)
@@ -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.

0 comments on commit 105a497

Please sign in to comment.
You can’t perform that action at this time.