Fixes transaction management issues
This commit is contained in:
parent
8ce8be2cc8
commit
be0ab56e9c
@ -37,13 +37,17 @@ public class StunResponseEvent
|
||||
* @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)
|
||||
public StunResponseEvent(RawMessage rawMessage,
|
||||
Response response,
|
||||
Request request,
|
||||
TransactionID transactionID)
|
||||
{
|
||||
super(rawMessage, response);
|
||||
this.request = request;
|
||||
super.setTransactionID(transactionID);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -88,7 +88,7 @@ public class MessageIntegrityAttribute
|
||||
/**
|
||||
* The HMAC-SHA1 algorithm.
|
||||
*/
|
||||
private static final String HMAC_SHA1_ALGORITHM = "HmacSHA1";
|
||||
public static final String HMAC_SHA1_ALGORITHM = "HmacSHA1";
|
||||
|
||||
/**
|
||||
* The HMAC-SHA1 algorithm.
|
||||
|
||||
@ -1178,8 +1178,7 @@ public class Agent
|
||||
}
|
||||
else
|
||||
{
|
||||
setState(IceProcessingState.FAILED);
|
||||
|
||||
terminate(IceProcessingState.FAILED);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1383,21 +1382,30 @@ public class Agent
|
||||
+"speed up termination", e);
|
||||
}
|
||||
|
||||
parentAgent.terminate();
|
||||
parentAgent.terminate(IceProcessingState.TERMINATED);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares everything associated with this {@link Agent} for garbage
|
||||
* collection and moves it into the terminated state.
|
||||
*
|
||||
* @param terminationState the state that we'd like processing to terminate
|
||||
* with or in other words {@link IceProcessingState#TERMINATED} or
|
||||
* {@link IceProcessingState#FAILED}
|
||||
*/
|
||||
private void terminate()
|
||||
private void terminate(IceProcessingState terminationState)
|
||||
{
|
||||
// free candidates
|
||||
for(IceMediaStream stream : getStreams())
|
||||
{
|
||||
removeStream(stream);
|
||||
}
|
||||
|
||||
// stop listening for checks
|
||||
connCheckClient.stop();
|
||||
connCheckServer.stop();
|
||||
|
||||
setState(IceProcessingState.TERMINATED);
|
||||
setState(terminationState);
|
||||
}
|
||||
}
|
||||
|
||||
@ -263,6 +263,7 @@ class ConnectivityCheckClient
|
||||
checkList.setState(CheckListState.FAILED);
|
||||
}
|
||||
|
||||
|
||||
//For each frozen check list, the agent groups together all of the
|
||||
//pairs with the same foundation, and for each group, sets the
|
||||
//state of the pair with the lowest component ID to Waiting. If
|
||||
@ -497,7 +498,7 @@ class ConnectivityCheckClient
|
||||
CandidatePair pair = ((CandidatePair)evt.getTransactionID()
|
||||
.getApplicationData());
|
||||
|
||||
logger.finest("Received error code " + errorCode.getErrorCode());
|
||||
logger.finer("Received error code " + (int)errorCode.getErrorCode());
|
||||
|
||||
//RESOLVE ROLE_CONFLICTS
|
||||
if(errorCode.getErrorCode() == ErrorCodeAttribute.ROLE_CONFLICT)
|
||||
|
||||
@ -68,6 +68,9 @@ class ConnectivityCheckServer
|
||||
public void processRequest(StunMessageEvent evt)
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
if(logger.isLoggable(Level.FINER))
|
||||
logger.finer("Received request " + evt);
|
||||
|
||||
Request request = (Request)evt.getMessage();
|
||||
|
||||
//ignore incoming requests that are not meant for the local user.
|
||||
@ -210,7 +213,7 @@ class ConnectivityCheckServer
|
||||
//role.
|
||||
else
|
||||
{
|
||||
logger.finest(
|
||||
logger.finer(
|
||||
"Swithing to controlled because theirTieBreaker="
|
||||
+ theirTieBreaker + " and ourTieBreaker="
|
||||
+ ourTieBreaker);
|
||||
@ -232,7 +235,7 @@ class ConnectivityCheckServer
|
||||
//the controlling role.
|
||||
if(ourTieBreaker >= theirTieBreaker)
|
||||
{
|
||||
logger.finest(
|
||||
logger.finer(
|
||||
"Swithing to controlling because theirTieBreaker="
|
||||
+ theirTieBreaker + " and ourTieBreaker="
|
||||
+ ourTieBreaker);
|
||||
|
||||
@ -10,6 +10,7 @@ package org.ice4j.ice;
|
||||
import java.net.*;
|
||||
|
||||
import org.ice4j.*;
|
||||
import org.ice4j.stack.*;
|
||||
|
||||
/**
|
||||
* <tt>LocalCandidate</tt>s are obtained by an agent for every stream component
|
||||
@ -52,6 +53,8 @@ public abstract class LocalCandidate
|
||||
*/
|
||||
protected void free()
|
||||
{
|
||||
//remove our socket from the stack.
|
||||
StunStack.getInstance().removeSocket(getTransportAddress());
|
||||
getSocket().close();
|
||||
}
|
||||
|
||||
|
||||
@ -79,7 +79,7 @@ public class StunCandidateHarvester
|
||||
|
||||
//these should be configurable.
|
||||
System.setProperty(StackProperties.MAX_CTRAN_RETRANS_TIMER, "400");
|
||||
System.setProperty(StackProperties.MAX_CTRAN_RETRANSMISSIONS, "2");
|
||||
System.setProperty(StackProperties.MAX_CTRAN_RETRANSMISSIONS, "3");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -146,7 +146,7 @@ class Connector
|
||||
if (isRunning)
|
||||
{
|
||||
logger.log(Level.WARNING,
|
||||
"A net access point has gone useless:", ex);
|
||||
"A connector died:", ex);
|
||||
|
||||
stop();
|
||||
//Something wrong has happened
|
||||
|
||||
@ -213,42 +213,48 @@ class StunClientTransaction
|
||||
retransmissionsThread.setName("ice4j.ClientTransaction");
|
||||
nextWaitInterval = originalWaitInterval;
|
||||
|
||||
for (retransmissionCounter = 0;
|
||||
retransmissionCounter < maxRetransmissions;
|
||||
retransmissionCounter ++)
|
||||
synchronized(this)
|
||||
{
|
||||
for (retransmissionCounter = 0;
|
||||
retransmissionCounter < maxRetransmissions;
|
||||
retransmissionCounter ++)
|
||||
{
|
||||
waitFor(nextWaitInterval);
|
||||
|
||||
//did someone tell us to get lost?
|
||||
if(cancelled)
|
||||
return;
|
||||
|
||||
if(nextWaitInterval < maxWaitInterval)
|
||||
nextWaitInterval *= 2;
|
||||
|
||||
try
|
||||
{
|
||||
sendRequest0();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//I wonder whether we should notify anyone that a
|
||||
//retransmission has failed
|
||||
logger.log(Level.INFO,
|
||||
"A client tran retransmission failed", ex);
|
||||
}
|
||||
}
|
||||
|
||||
//before stating that a transaction has timeout-ed we should first
|
||||
//wait for a reception of the response
|
||||
if(nextWaitInterval < maxWaitInterval)
|
||||
nextWaitInterval *= 2;
|
||||
|
||||
waitFor(nextWaitInterval);
|
||||
|
||||
//did someone tell us to get lost?
|
||||
if(cancelled)
|
||||
return;
|
||||
|
||||
if(nextWaitInterval < maxWaitInterval)
|
||||
nextWaitInterval *= 2;
|
||||
|
||||
try
|
||||
{
|
||||
sendRequest0();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//I wonder whether we should notify anyone that a retransmission
|
||||
//has failed
|
||||
logger.log(Level.WARNING,
|
||||
"A client tran retransmission failed", ex);
|
||||
}
|
||||
stackCallback.removeClientTransaction(this);
|
||||
responseCollector.processTimeout( new StunTimeoutEvent(
|
||||
this.request, getLocalAddress(), transactionID));
|
||||
}
|
||||
|
||||
//before stating that a transaction has timeout-ed we should first wait
|
||||
//for a reception of the response
|
||||
if(nextWaitInterval < maxWaitInterval)
|
||||
nextWaitInterval *= 2;
|
||||
|
||||
waitFor(nextWaitInterval);
|
||||
|
||||
responseCollector.processTimeout( new StunTimeoutEvent(
|
||||
this.request, getLocalAddress(), transactionID));
|
||||
stackCallback.removeClientTransaction(this);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -306,7 +312,7 @@ class StunClientTransaction
|
||||
*
|
||||
* @param millis the number of milliseconds to wait for.
|
||||
*/
|
||||
synchronized void waitFor(long millis)
|
||||
void waitFor(long millis)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -349,16 +355,14 @@ class StunClientTransaction
|
||||
*
|
||||
* @param evt the event that contains the newly received message
|
||||
*/
|
||||
void handleResponse(StunMessageEvent evt)
|
||||
synchronized void handleResponse(StunMessageEvent evt)
|
||||
{
|
||||
String keepTran = System.getProperty(
|
||||
StackProperties.KEEP_CRANS_AFTER_A_RESPONSE);
|
||||
|
||||
if( keepTran == null || !keepTran.trim().equalsIgnoreCase("true"))
|
||||
if( !Boolean.getBoolean(StackProperties.KEEP_CRANS_AFTER_A_RESPONSE) )
|
||||
this.cancel();
|
||||
|
||||
this.responseCollector.processResponse(new StunResponseEvent(
|
||||
evt.getRawMessage(), (Response)evt.getMessage(), this.request));
|
||||
evt.getRawMessage(), (Response)evt.getMessage(),
|
||||
this.request, getTransactionID()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -8,9 +8,12 @@ package org.ice4j.stack;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.security.*;
|
||||
import java.util.*;
|
||||
import java.util.logging.*;
|
||||
|
||||
import javax.crypto.*;
|
||||
|
||||
import org.ice4j.*;
|
||||
import org.ice4j.attribute.*;
|
||||
import org.ice4j.message.*;
|
||||
@ -84,7 +87,21 @@ public class 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;
|
||||
}
|
||||
@ -478,7 +495,7 @@ public class StunStack
|
||||
Message msg = event.getMessage();
|
||||
|
||||
if(logger.isLoggable(Level.FINEST))
|
||||
logger.finest("Received a message on NetAP"
|
||||
logger.finest("Received a message on "
|
||||
+ event.getLocalAddress()
|
||||
+ " of type:"
|
||||
+ (int)msg.getMessageType());
|
||||
@ -517,7 +534,7 @@ public class StunStack
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.finest("exising transaction not found");
|
||||
logger.finest("existing transaction not found");
|
||||
sTran = new StunServerTransaction(this, serverTid,
|
||||
event.getLocalAddress(), event.getRemoteAddress());
|
||||
|
||||
@ -532,7 +549,8 @@ public class StunStack
|
||||
}
|
||||
catch(Exception exc)
|
||||
{
|
||||
//validation failed. get lost.
|
||||
//validation failed. log get lost.
|
||||
logger.log(Level.FINE, "Failed to validate msg: " + event, exc);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -543,7 +561,7 @@ public class StunStack
|
||||
catch (Throwable t)
|
||||
{
|
||||
Response error;
|
||||
t.printStackTrace();
|
||||
|
||||
logger.log(Level.FINER, "Received an invalid request.", t);
|
||||
|
||||
if(t instanceof IllegalArgumentException)
|
||||
@ -809,6 +827,7 @@ t.printStackTrace();
|
||||
if (logger.isLoggable(Level.FINEST))
|
||||
logger.finest("Successfully verified msg integrity");
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user