diff --git a/src/org/ice4j/ice/ServerReflexiveCandidate.java b/src/org/ice4j/ice/ServerReflexiveCandidate.java index a3a1798..27d9b5b 100644 --- a/src/org/ice4j/ice/ServerReflexiveCandidate.java +++ b/src/org/ice4j/ice/ServerReflexiveCandidate.java @@ -24,7 +24,8 @@ import org.ice4j.*; * * @author Emil Ivov */ -public class ServerReflexiveCandidate extends LocalCandidate +public class ServerReflexiveCandidate + extends LocalCandidate { /** diff --git a/src/org/ice4j/ice/checks/ConnectivityCheckClient.java b/src/org/ice4j/ice/checks/ConnectivityCheckClient.java index aacc34b..7d71d0b 100644 --- a/src/org/ice4j/ice/checks/ConnectivityCheckClient.java +++ b/src/org/ice4j/ice/checks/ConnectivityCheckClient.java @@ -182,9 +182,8 @@ public class ConnectivityCheckClient +". Failing"); pair.setState(CandidatePairState.FAILED, null); } - //handle error responses. - if(evt.getResponse().getMessageType() + else if(evt.getResponse().getMessageType() == Response.BINDING_ERROR_RESPONSE) { if(! evt.getResponse().contains(Attribute.ERROR_CODE)) @@ -195,7 +194,95 @@ public class ConnectivityCheckClient 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 } diff --git a/src/org/ice4j/ice/checks/ConnectivityCheckServer.java b/src/org/ice4j/ice/checks/ConnectivityCheckServer.java index ff86125..fe9ccf3 100644 --- a/src/org/ice4j/ice/checks/ConnectivityCheckServer.java +++ b/src/org/ice4j/ice/checks/ConnectivityCheckServer.java @@ -129,6 +129,12 @@ public class ConnectivityCheckServer //then chances are the 500 will fail too. throw new RuntimeException("Failed to send a response", e); } + + if (!parentAgent.isControlling() + && request.contains(Attribute.USE_CANDIDATE)) + { + + } } /** diff --git a/src/org/ice4j/message/Message.java b/src/org/ice4j/message/Message.java index 20c3b42..f5d6d08 100644 --- a/src/org/ice4j/message/Message.java +++ b/src/org/ice4j/message/Message.java @@ -44,7 +44,7 @@ public abstract class Message public static final char STUN_METHOD_BINDING = 0x0001; 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 SHARED_SECRET_REQUEST = 0x0002; public static final char SHARED_SECRET_RESPONSE = 0x0102; @@ -433,7 +433,7 @@ public abstract class Message switch (messageType) { 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 SHARED_SECRET_REQUEST: msgIndex = SHARED_SECRET_REQUEST_PRESENTITY_INDEX; break; case SHARED_SECRET_RESPONSE: msgIndex = SHARED_SECRET_RESPONSE_PRESENTITY_INDEX; break; @@ -492,7 +492,7 @@ public abstract class Message switch (messageType) { 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 SHARED_SECRET_REQUEST: return "SHARED-SECRET-REQUEST"; case SHARED_SECRET_RESPONSE: return "SHARED-SECRET-RESPONSE"; diff --git a/src/org/ice4j/message/MessageFactory.java b/src/org/ice4j/message/MessageFactory.java index c1eae18..d6b0f29 100644 --- a/src/org/ice4j/message/MessageFactory.java +++ b/src/org/ice4j/message/MessageFactory.java @@ -133,7 +133,7 @@ public class MessageFactory throws IllegalArgumentException { Response bindingResponse = new Response(); - bindingResponse.setMessageType(Message.BINDING_RESPONSE); + bindingResponse.setMessageType(Message.BINDING_SUCCESS_RESPONSE); // mapped address MappedAddressAttribute mappedAddressAttribute = AttributeFactory @@ -187,7 +187,7 @@ public class MessageFactory throws IllegalArgumentException { Response bindingResponse = new Response(); - bindingResponse.setMessageType(Message.BINDING_RESPONSE); + bindingResponse.setMessageType(Message.BINDING_SUCCESS_RESPONSE); // xor mapped address XorMappedAddressAttribute xorMappedAddressAttribute = AttributeFactory diff --git a/test/org/ice4j/message/MessageFactoryTest.java b/test/org/ice4j/message/MessageFactoryTest.java index e5edd22..fc7059c 100644 --- a/test/org/ice4j/message/MessageFactoryTest.java +++ b/test/org/ice4j/message/MessageFactoryTest.java @@ -145,7 +145,7 @@ public class MessageFactoryTest extends TestCase { throws Exception { Response bindingResponse = new Response(); - bindingResponse.setMessageType(Message.BINDING_RESPONSE); + bindingResponse.setMessageType(Message.BINDING_SUCCESS_RESPONSE); Attribute mappedAddress = AttributeFactory.createMappedAddressAttribute( new TransportAddress( msgFixture.ADDRESS_ATTRIBUTE_ADDRESS, diff --git a/test/org/ice4j/message/MessageTest.java b/test/org/ice4j/message/MessageTest.java index 29afa12..d47e16f 100644 --- a/test/org/ice4j/message/MessageTest.java +++ b/test/org/ice4j/message/MessageTest.java @@ -46,7 +46,7 @@ public class MessageTest extends TestCase { //binding response bindingResponse = new Response(); - bindingResponse.setMessageType(Message.BINDING_RESPONSE); + bindingResponse.setMessageType(Message.BINDING_SUCCESS_RESPONSE); mappedAddress = AttributeFactory.createMappedAddressAttribute( new TransportAddress( @@ -102,7 +102,7 @@ public class MessageTest extends TestCase { public void testAddAndGetAttribute() throws StunException { Response message = new Response(); - message.setMessageType(Message.BINDING_RESPONSE); + message.setMessageType(Message.BINDING_SUCCESS_RESPONSE); message.addAttribute(mappedAddress); Attribute getResult = null; @@ -223,7 +223,7 @@ public class MessageTest extends TestCase { //Create a binding response with the same attributes as //this.bindingRequest Response binResTarget = new Response(); - binResTarget.setMessageType(Message.BINDING_RESPONSE); + binResTarget.setMessageType(Message.BINDING_SUCCESS_RESPONSE); binResTarget.addAttribute(mappedAddress); binResTarget.addAttribute(sourceAddress); binResTarget.addAttribute(changedAddress);