diff --git a/src/org/ice4j/ice/checks/ConnectivityCheckClient.java b/src/org/ice4j/ice/checks/ConnectivityCheckClient.java index 6db44ef..6ee4069 100644 --- a/src/org/ice4j/ice/checks/ConnectivityCheckClient.java +++ b/src/org/ice4j/ice/checks/ConnectivityCheckClient.java @@ -171,6 +171,29 @@ public class ConnectivityCheckClient } + /** + * Removes the corresponding local candidate from the list of candidates + * that we are waiting on in order to complete the harvest. + * + * @param transactionID the ID of the transaction that has just ended. + */ +/* + private void processFailure(TransactionID transactionID) + { + synchronized (resolveMap) + { + Candidate localCand = resolveMap.remove(transactionID); + + //if this was the last candidate, we are done with the STUN + //resolution and need to notify the waiters. + if(resolveMap.isEmpty()) + resolveMap.notify(); + + logger.finest("a tran expired tranid=" + transactionID); + logger.finest("localAddr=" + localCand); + } + } +*/ /** * The thread that actually sends the checks for a particular check list * in the pace defined in RFC 5245. diff --git a/src/org/ice4j/ice/checks/ConnectivityCheckServer.java b/src/org/ice4j/ice/checks/ConnectivityCheckServer.java index d9ce552..952dedd 100644 --- a/src/org/ice4j/ice/checks/ConnectivityCheckServer.java +++ b/src/org/ice4j/ice/checks/ConnectivityCheckServer.java @@ -71,11 +71,20 @@ public class ConnectivityCheckServer stunStack.getCredentialsManager().registerAuthority(this); } + /** + * Handles the {@link Request} delivered in evt by possibly + * queueing a triggered check and sending a success or or error response + * depending on how processing goes. + * + * @param evt the {@link StunMessageEvent} containing the {@link Request} + * that we need to process. + * + * @throws IllegalArgumentException if the request is malformed and the + * stack needs to reply with a 400 Bad Request response. + */ public void processRequest(StunMessageEvent evt) + throws IllegalArgumentException { - if(true) - throw new NullPointerException("i am the king fo the w"); - Request request = (Request)evt.getMessage(); //ignore incoming requests that are not meant for the local user. @@ -109,7 +118,8 @@ public class ConnectivityCheckServer logger.log(Level.FINE, "Received a connectivity ckeck with" +"no PRIORITY attribute. Discarting."); } - return; + + throw new IllegalArgumentException("Missing PRIORITY attribtue!"); } long priority = priorityAttr.getPriority(); diff --git a/src/org/ice4j/stack/RequestListener.java b/src/org/ice4j/stack/RequestListener.java index 874eb32..b0b26f9 100644 --- a/src/org/ice4j/stack/RequestListener.java +++ b/src/org/ice4j/stack/RequestListener.java @@ -7,6 +7,9 @@ package org.ice4j.stack; import org.ice4j.*; +import org.ice4j.message.*; + +import com.sun.corba.se.impl.protocol.*; /** * Handles incoming requests. @@ -17,9 +20,19 @@ import org.ice4j.*; public interface RequestListener { /** - * Called when delivering incoming STUN requests. + * Called when delivering incoming STUN requests. Throwing an + * {@link IllegalArgumentException} from within this method would cause the + * stack to reply with a 400 Bad Request {@link Response} using + * the exception's message as a reason phrase for the error response. Any + * other exception would result in a 500 Server Error {@link + * Response}. * * @param evt the event containing the incoming STUN request. + * + * @throws IllegalArgumentException if evt contains a malformed + * {@link Request} and the stack would need to response with a + * 400 Bad Request {@link Response}. */ - public void processRequest(StunMessageEvent evt); + public void processRequest(StunMessageEvent evt) + throws IllegalArgumentException; } diff --git a/src/org/ice4j/stack/StunStack.java b/src/org/ice4j/stack/StunStack.java index bfe08c4..aabb77c 100644 --- a/src/org/ice4j/stack/StunStack.java +++ b/src/org/ice4j/stack/StunStack.java @@ -542,9 +542,20 @@ public class StunStack } catch (Throwable t) { - Response error = MessageFactory.createBindingErrorResponse( + Response error; + + if(t instanceof IllegalArgumentException) + { + error = MessageFactory.createBindingErrorResponse( + ErrorCodeAttribute.BAD_REQUEST, + t.getMessage()); + } + else + { + error = MessageFactory.createBindingErrorResponse( ErrorCodeAttribute.SERVER_ERROR, "Oops! Something went wrong on our side :("); + } try {