diff --git a/src/org/ice4j/StunException.java b/src/org/ice4j/StunException.java index a11ad8d..b54c411 100644 --- a/src/org/ice4j/StunException.java +++ b/src/org/ice4j/StunException.java @@ -53,6 +53,11 @@ public class StunException extends Exception */ public static final int NETWORK_ERROR = 4; + /** + * Thrown when trying to send responses through a transaction that have + * already sent a response. + */ + public static final int TRANSACTION_ALREADY_ANSWERED = 5; /** * Identifies the exception. diff --git a/src/org/ice4j/stack/StunStack.java b/src/org/ice4j/stack/StunStack.java index a4489f5..4c90e23 100644 --- a/src/org/ice4j/stack/StunStack.java +++ b/src/org/ice4j/stack/StunStack.java @@ -489,7 +489,7 @@ public class StunStack } else if( sTran.isRetransmitting()) { - throw new StunException(StunException.TRANSACTION_DOES_NOT_EXIST, + throw new StunException(StunException.TRANSACTION_ALREADY_ANSWERED, "The transaction specified in the response " + "(tid="+ tid.toString() +") " + "has already seen a previous response. " @@ -690,6 +690,19 @@ public class StunStack Response error; logger.log(Level.INFO, "Received an invalid request.", t); + Throwable cause = t.getCause(); + + if(((t instanceof StunException) && + ((StunException)t).getID() == + StunException.TRANSACTION_ALREADY_ANSWERED) || + (cause != null && (cause instanceof StunException) && + ((StunException)cause).getID() == + StunException.TRANSACTION_ALREADY_ANSWERED)) + { + // do not try to send an error response since we will + // get another TRANSACTION_ALREADY_ANSWERED + return; + } if(t instanceof IllegalArgumentException) {