Adds support for client side discovery of PEER-REFLEXIVE-CANDIDATES. (RFC 5245: Section 7.1.3.2.1)
This commit is contained in:
parent
9fe7cce92e
commit
ba1fdf0a9d
@ -24,7 +24,8 @@ import org.ice4j.*;
|
|||||||
*
|
*
|
||||||
* @author Emil Ivov
|
* @author Emil Ivov
|
||||||
*/
|
*/
|
||||||
public class ServerReflexiveCandidate extends LocalCandidate
|
public class ServerReflexiveCandidate
|
||||||
|
extends LocalCandidate
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -182,9 +182,8 @@ public class ConnectivityCheckClient
|
|||||||
+". Failing");
|
+". Failing");
|
||||||
pair.setState(CandidatePairState.FAILED, null);
|
pair.setState(CandidatePairState.FAILED, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
//handle error responses.
|
//handle error responses.
|
||||||
if(evt.getResponse().getMessageType()
|
else if(evt.getResponse().getMessageType()
|
||||||
== Response.BINDING_ERROR_RESPONSE)
|
== Response.BINDING_ERROR_RESPONSE)
|
||||||
{
|
{
|
||||||
if(! evt.getResponse().contains(Attribute.ERROR_CODE))
|
if(! evt.getResponse().contains(Attribute.ERROR_CODE))
|
||||||
@ -195,7 +194,95 @@ public class ConnectivityCheckClient
|
|||||||
|
|
||||||
processErrorResponse(evt);
|
processErrorResponse(evt);
|
||||||
}
|
}
|
||||||
|
//handle error responses.
|
||||||
|
else if(evt.getResponse().getMessageType()
|
||||||
|
== Response.BINDING_SUCCESS_RESPONSE)
|
||||||
|
{
|
||||||
|
processSuccessResponse(evt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles STUN success responses as per the rules in RFC 5245.
|
||||||
|
*
|
||||||
|
* @param evt the event that delivered the error response.
|
||||||
|
*/
|
||||||
|
private void processSuccessResponse(StunResponseEvent evt)
|
||||||
|
{
|
||||||
|
Response response = evt.getResponse();
|
||||||
|
Request request = evt.getRequest();
|
||||||
|
|
||||||
|
CandidatePair checkedPair = ((CandidatePair)evt.getTransactionID()
|
||||||
|
.getApplicationData());
|
||||||
|
|
||||||
|
|
||||||
|
if(! response.contains(Attribute.XOR_MAPPED_ADDRESS))
|
||||||
|
{
|
||||||
|
logger.fine("Received a success response with no "
|
||||||
|
+"XOR_MAPPED_ADDRESS attribute.");
|
||||||
|
checkedPair.setState(CandidatePairState.FAILED, null);
|
||||||
|
return; //malformed error response
|
||||||
|
}
|
||||||
|
|
||||||
|
XorMappedAddressAttribute mappedAddressAttr
|
||||||
|
= (XorMappedAddressAttribute)response
|
||||||
|
.getAttribute(Attribute.XOR_MAPPED_ADDRESS);
|
||||||
|
|
||||||
|
TransportAddress mappedAddress = mappedAddressAttr
|
||||||
|
.getAddress(response.getTransactionID());
|
||||||
|
|
||||||
|
LocalCandidate validLocalCandidate = parentAgent
|
||||||
|
.findLocalCandidate(mappedAddress);
|
||||||
|
Candidate validRemoteCandidate = checkedPair.getRemoteCandidate();
|
||||||
|
|
||||||
|
// RFC 5245: The agent checks the mapped address from the STUN
|
||||||
|
// response. If the transport address does not match any of the
|
||||||
|
// local candidates that the agent knows about, the mapped address
|
||||||
|
// represents a new candidate -- a peer reflexive candidate.
|
||||||
|
if ( validLocalCandidate == null)
|
||||||
|
{
|
||||||
|
//Like other candidates, PEER-REFLEXIVE candidates have a type,
|
||||||
|
//base, priority, and foundation. They are computed as follows:
|
||||||
|
//o The type is equal to peer reflexive.
|
||||||
|
//o The base is the local candidate of the candidate
|
||||||
|
// pair from which the STUN check was sent.
|
||||||
|
//o Its priority is set equal to the value of the PRIORITY attribute
|
||||||
|
// in the Binding request.
|
||||||
|
PriorityAttribute prioAttr = (PriorityAttribute)request
|
||||||
|
.getAttribute(Attribute.PRIORITY);
|
||||||
|
|
||||||
|
LocalCandidate peerReflexiveCandidate = new PeerReflexiveCandidate(
|
||||||
|
mappedAddress, checkedPair.getParentComponent(),
|
||||||
|
checkedPair.getLocalCandidate(),
|
||||||
|
prioAttr.getPriority());
|
||||||
|
|
||||||
|
peerReflexiveCandidate.setBase(checkedPair.getLocalCandidate());
|
||||||
|
|
||||||
|
//This peer reflexive candidate is then added to the list of local
|
||||||
|
//candidates for the media stream, so that it would be available for
|
||||||
|
//updated offers.
|
||||||
|
checkedPair.getParentComponent().addLocalCandidate(
|
||||||
|
peerReflexiveCandidate);
|
||||||
|
|
||||||
|
//However, the peer reflexive candidate is not paired with other
|
||||||
|
//remote candidates. This is not necessary; a valid pair will be
|
||||||
|
//generated from it momentarily
|
||||||
|
validLocalCandidate = peerReflexiveCandidate;
|
||||||
|
}
|
||||||
|
|
||||||
|
// RFC 5245: 7.1.3.2.2. The agent constructs a candidate pair whose
|
||||||
|
// local candidate equals the mapped address of the response, and whose
|
||||||
|
// remote candidate equals the destination address to which the request
|
||||||
|
// was sent. This is called a valid pair, since it has been validated
|
||||||
|
// by a STUN connectivity check.
|
||||||
|
CandidatePair validPair = new CandidatePair(validLocalCandidate,
|
||||||
|
validRemoteCandidate);
|
||||||
|
|
||||||
|
//If the pair equals the pair that generated the check or is on a check
|
||||||
|
//list currently, it is also added to the VALID LIST, which is
|
||||||
|
// maintained by the agent for each media stream.
|
||||||
|
|
||||||
|
//if
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -129,6 +129,12 @@ public class ConnectivityCheckServer
|
|||||||
//then chances are the 500 will fail too.
|
//then chances are the 500 will fail too.
|
||||||
throw new RuntimeException("Failed to send a response", e);
|
throw new RuntimeException("Failed to send a response", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!parentAgent.isControlling()
|
||||||
|
&& request.contains(Attribute.USE_CANDIDATE))
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -44,7 +44,7 @@ public abstract class Message
|
|||||||
public static final char STUN_METHOD_BINDING = 0x0001;
|
public static final char STUN_METHOD_BINDING = 0x0001;
|
||||||
|
|
||||||
public static final char BINDING_REQUEST = (STUN_METHOD_BINDING | STUN_REQUEST);
|
public static final char BINDING_REQUEST = (STUN_METHOD_BINDING | STUN_REQUEST);
|
||||||
public static final char BINDING_RESPONSE = (STUN_METHOD_BINDING | STUN_SUCCESS_RESP);
|
public static final char BINDING_SUCCESS_RESPONSE = (STUN_METHOD_BINDING | STUN_SUCCESS_RESP);
|
||||||
public static final char BINDING_ERROR_RESPONSE = (STUN_METHOD_BINDING | STUN_ERROR_RESP);
|
public static final char BINDING_ERROR_RESPONSE = (STUN_METHOD_BINDING | STUN_ERROR_RESP);
|
||||||
public static final char SHARED_SECRET_REQUEST = 0x0002;
|
public static final char SHARED_SECRET_REQUEST = 0x0002;
|
||||||
public static final char SHARED_SECRET_RESPONSE = 0x0102;
|
public static final char SHARED_SECRET_RESPONSE = 0x0102;
|
||||||
@ -433,7 +433,7 @@ public abstract class Message
|
|||||||
switch (messageType)
|
switch (messageType)
|
||||||
{
|
{
|
||||||
case BINDING_REQUEST: msgIndex = BINDING_REQUEST_PRESENTITY_INDEX; break;
|
case BINDING_REQUEST: msgIndex = BINDING_REQUEST_PRESENTITY_INDEX; break;
|
||||||
case BINDING_RESPONSE: msgIndex = BINDING_RESPONSE_PRESENTITY_INDEX; break;
|
case BINDING_SUCCESS_RESPONSE: msgIndex = BINDING_RESPONSE_PRESENTITY_INDEX; break;
|
||||||
case BINDING_ERROR_RESPONSE: msgIndex = BINDING_ERROR_RESPONSE_PRESENTITY_INDEX; break;
|
case BINDING_ERROR_RESPONSE: msgIndex = BINDING_ERROR_RESPONSE_PRESENTITY_INDEX; break;
|
||||||
case SHARED_SECRET_REQUEST: msgIndex = SHARED_SECRET_REQUEST_PRESENTITY_INDEX; break;
|
case SHARED_SECRET_REQUEST: msgIndex = SHARED_SECRET_REQUEST_PRESENTITY_INDEX; break;
|
||||||
case SHARED_SECRET_RESPONSE: msgIndex = SHARED_SECRET_RESPONSE_PRESENTITY_INDEX; break;
|
case SHARED_SECRET_RESPONSE: msgIndex = SHARED_SECRET_RESPONSE_PRESENTITY_INDEX; break;
|
||||||
@ -492,7 +492,7 @@ public abstract class Message
|
|||||||
switch (messageType)
|
switch (messageType)
|
||||||
{
|
{
|
||||||
case BINDING_REQUEST: return "BINDING-REQUEST";
|
case BINDING_REQUEST: return "BINDING-REQUEST";
|
||||||
case BINDING_RESPONSE: return "BINDING-RESPONSE";
|
case BINDING_SUCCESS_RESPONSE: return "BINDING-RESPONSE";
|
||||||
case BINDING_ERROR_RESPONSE: return "BINDING-ERROR-RESPONSE";
|
case BINDING_ERROR_RESPONSE: return "BINDING-ERROR-RESPONSE";
|
||||||
case SHARED_SECRET_REQUEST: return "SHARED-SECRET-REQUEST";
|
case SHARED_SECRET_REQUEST: return "SHARED-SECRET-REQUEST";
|
||||||
case SHARED_SECRET_RESPONSE: return "SHARED-SECRET-RESPONSE";
|
case SHARED_SECRET_RESPONSE: return "SHARED-SECRET-RESPONSE";
|
||||||
|
|||||||
@ -133,7 +133,7 @@ public class MessageFactory
|
|||||||
throws IllegalArgumentException
|
throws IllegalArgumentException
|
||||||
{
|
{
|
||||||
Response bindingResponse = new Response();
|
Response bindingResponse = new Response();
|
||||||
bindingResponse.setMessageType(Message.BINDING_RESPONSE);
|
bindingResponse.setMessageType(Message.BINDING_SUCCESS_RESPONSE);
|
||||||
|
|
||||||
// mapped address
|
// mapped address
|
||||||
MappedAddressAttribute mappedAddressAttribute = AttributeFactory
|
MappedAddressAttribute mappedAddressAttribute = AttributeFactory
|
||||||
@ -187,7 +187,7 @@ public class MessageFactory
|
|||||||
throws IllegalArgumentException
|
throws IllegalArgumentException
|
||||||
{
|
{
|
||||||
Response bindingResponse = new Response();
|
Response bindingResponse = new Response();
|
||||||
bindingResponse.setMessageType(Message.BINDING_RESPONSE);
|
bindingResponse.setMessageType(Message.BINDING_SUCCESS_RESPONSE);
|
||||||
|
|
||||||
// xor mapped address
|
// xor mapped address
|
||||||
XorMappedAddressAttribute xorMappedAddressAttribute = AttributeFactory
|
XorMappedAddressAttribute xorMappedAddressAttribute = AttributeFactory
|
||||||
|
|||||||
@ -145,7 +145,7 @@ public class MessageFactoryTest extends TestCase {
|
|||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
Response bindingResponse = new Response();
|
Response bindingResponse = new Response();
|
||||||
bindingResponse.setMessageType(Message.BINDING_RESPONSE);
|
bindingResponse.setMessageType(Message.BINDING_SUCCESS_RESPONSE);
|
||||||
|
|
||||||
Attribute mappedAddress = AttributeFactory.createMappedAddressAttribute(
|
Attribute mappedAddress = AttributeFactory.createMappedAddressAttribute(
|
||||||
new TransportAddress( msgFixture.ADDRESS_ATTRIBUTE_ADDRESS,
|
new TransportAddress( msgFixture.ADDRESS_ATTRIBUTE_ADDRESS,
|
||||||
|
|||||||
@ -46,7 +46,7 @@ public class MessageTest extends TestCase {
|
|||||||
|
|
||||||
//binding response
|
//binding response
|
||||||
bindingResponse = new Response();
|
bindingResponse = new Response();
|
||||||
bindingResponse.setMessageType(Message.BINDING_RESPONSE);
|
bindingResponse.setMessageType(Message.BINDING_SUCCESS_RESPONSE);
|
||||||
|
|
||||||
mappedAddress = AttributeFactory.createMappedAddressAttribute(
|
mappedAddress = AttributeFactory.createMappedAddressAttribute(
|
||||||
new TransportAddress(
|
new TransportAddress(
|
||||||
@ -102,7 +102,7 @@ public class MessageTest extends TestCase {
|
|||||||
public void testAddAndGetAttribute() throws StunException {
|
public void testAddAndGetAttribute() throws StunException {
|
||||||
|
|
||||||
Response message = new Response();
|
Response message = new Response();
|
||||||
message.setMessageType(Message.BINDING_RESPONSE);
|
message.setMessageType(Message.BINDING_SUCCESS_RESPONSE);
|
||||||
message.addAttribute(mappedAddress);
|
message.addAttribute(mappedAddress);
|
||||||
|
|
||||||
Attribute getResult = null;
|
Attribute getResult = null;
|
||||||
@ -223,7 +223,7 @@ public class MessageTest extends TestCase {
|
|||||||
//Create a binding response with the same attributes as
|
//Create a binding response with the same attributes as
|
||||||
//this.bindingRequest
|
//this.bindingRequest
|
||||||
Response binResTarget = new Response();
|
Response binResTarget = new Response();
|
||||||
binResTarget.setMessageType(Message.BINDING_RESPONSE);
|
binResTarget.setMessageType(Message.BINDING_SUCCESS_RESPONSE);
|
||||||
binResTarget.addAttribute(mappedAddress);
|
binResTarget.addAttribute(mappedAddress);
|
||||||
binResTarget.addAttribute(sourceAddress);
|
binResTarget.addAttribute(sourceAddress);
|
||||||
binResTarget.addAttribute(changedAddress);
|
binResTarget.addAttribute(changedAddress);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user