Implements server side role conflict detection and resolution (RFC 5245: Section 7.2.1.1)

This commit is contained in:
emcho 2010-05-08 21:35:21 +00:00
parent cc51f9ff21
commit 91b3474a79
8 changed files with 35 additions and 8 deletions

View File

@ -19,7 +19,7 @@ public interface ResponseCollector
* *
* @param response the response to dispatch. * @param response the response to dispatch.
*/ */
public void processResponse(StunMessageEvent response); public void processResponse(StunResponseEvent response);
/** /**
* Notifies this collector that no response had been received after repeated * Notifies this collector that no response had been received after repeated

View File

@ -161,8 +161,34 @@ public class ConnectivityCheckClient
} }
} }
public void processResponse(StunMessageEvent response) public void processResponse(StunResponseEvent response)
{ {
if(response.getResponse().getMessageType()
== Response.BINDING_ERROR_RESPONSE)
{
if(! response.getResponse().contains(Attribute.ERROR_CODE))
return; //malformed error response
processErrorResponse(response);
}
}
private void processErrorResponse(StunResponseEvent evt)
{
Response response = evt.getResponse();
Request originalRequest = evt.getRequest();
Attribute errorCode = response.getAttribute(Attribute.ERROR_CODE);
//RESOLVE ROLE_CONFLICTS
if(response.contains(ErrorCodeAttribute.ROLE_CONFLICT))
{
boolean wasControlling = originalRequest
.contains(Attribute.ICE_CONTROLLING);
logger.finest("Swithing to isControlling=" + !wasControlling);
parentAgent.setControlling(!wasControlling);
}
} }
public void processTimeout(StunTimeoutEvent event) public void processTimeout(StunTimeoutEvent event)

View File

@ -309,7 +309,7 @@ public class StunCandidateHarvester
* *
* @param response the response that we've just received from a StunServer. * @param response the response that we've just received from a StunServer.
*/ */
public void processResponse(StunMessageEvent response) public void processResponse(StunResponseEvent response)
{ {
synchronized (resolveMap) synchronized (resolveMap)
{ {

View File

@ -357,7 +357,8 @@ class StunClientTransaction
if( keepTran == null || !keepTran.trim().equalsIgnoreCase("true")) if( keepTran == null || !keepTran.trim().equalsIgnoreCase("true"))
this.cancel(); this.cancel();
this.responseCollector.processResponse(evt); this.responseCollector.processResponse(new StunResponseEvent(
evt.getRawMessage(), (Response)evt.getMessage(), this.request));
} }
/** /**

View File

@ -106,7 +106,7 @@ class BlockingRequestSender
* it may resume. * it may resume.
* @param evt the newly arrived message event. * @param evt the newly arrived message event.
*/ */
public synchronized void processResponse(StunMessageEvent evt) public synchronized void processResponse(StunResponseEvent evt)
{ {
synchronized(sendLock) synchronized(sendLock)
{ {

View File

@ -317,7 +317,7 @@ public class MessageEventDispatchingTest extends TestCase
* @param response a <tt>StunMessageEvent</tt> which describes the * @param response a <tt>StunMessageEvent</tt> which describes the
* received STUN <tt>Response</tt> * received STUN <tt>Response</tt>
*/ */
public synchronized void processResponse(StunMessageEvent response) public synchronized void processResponse(StunResponseEvent response)
{ {
receivedResponses.add(response); receivedResponses.add(response);
notifyAll(); notifyAll();

View File

@ -556,7 +556,7 @@ public class TransactionSupportTests extends TestCase
* *
* @param response the event to log. * @param response the event to log.
*/ */
public void processResponse(StunMessageEvent response) public void processResponse(StunResponseEvent response)
{ {
receivedResponses.add(response); receivedResponses.add(response);
} }

View File

@ -339,7 +339,7 @@ public class ShallowStackTest extends TestCase {
* @param response a <tt>StunMessageEvent</tt> which describes the * @param response a <tt>StunMessageEvent</tt> which describes the
* received STUN <tt>Response</tt> * received STUN <tt>Response</tt>
*/ */
public synchronized void processResponse(StunMessageEvent response) public synchronized void processResponse(StunResponseEvent response)
{ {
collectedResponse = (Response) response.getMessage(); collectedResponse = (Response) response.getMessage();
logger.finest("Received response."); logger.finest("Received response.");