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