Adds password support for google relayed candidate.

This commit is contained in:
chenzo 2012-08-10 13:34:49 +00:00
parent f2529200be
commit dfcde11376
9 changed files with 119 additions and 102 deletions

View File

@ -808,21 +808,7 @@ public class Agent
public String generateLocalUserName(RemoteCandidate remoteCandidate, public String generateLocalUserName(RemoteCandidate remoteCandidate,
LocalCandidate localCandidate) LocalCandidate localCandidate)
{ {
String ret = null; return generateUserName(remoteCandidate, localCandidate);
String remoteUfrag = remoteCandidate.getUfrag();
String localUfrag = localCandidate.getUfrag();
/* Google Talk specific
* each candidate has its own username/password
*/
if(localUfrag == null || remoteUfrag == null ||
compatibilityMode != CompatibilityMode.GTALK)
{
return null;
}
ret = remoteUfrag + localUfrag;
return ret;
} }
/** /**
@ -837,22 +823,38 @@ public class Agent
*/ */
public String generateRemoteUserName(RemoteCandidate remoteCandidate, public String generateRemoteUserName(RemoteCandidate remoteCandidate,
LocalCandidate localCandidate) LocalCandidate localCandidate)
{
return generateUserName(localCandidate, remoteCandidate);
}
/**
* Returns the user name that we should expect a peer <tt>Agent</tt> to use
* in connectivity checks for Binding Requests its sending our way in a
* Google Talk session.
*
* @param candidate1 The first candidate of a candidatePair.
* @param candidate2 The second candidate of a candidatePair.
* @return a user name that a peer <tt>Agent</tt> would use in connectivity
* check for outgoing Binding Requests.
*/
private String generateUserName(
Candidate candidate1,
Candidate candidate2)
{ {
String ret = null; String ret = null;
String remoteUfrag = remoteCandidate.getUfrag(); String ufrag1 = candidate1.getUfrag();
String localUfrag = localCandidate.getUfrag(); String ufrag2 = candidate2.getUfrag();
/* Google Talk specific /* Google Talk specific
* each candidate has its own username/password * each candidate has its own username/password
*/ */
if(remoteUfrag == null || localUfrag == null || if(ufrag1 != null
compatibilityMode != CompatibilityMode.GTALK) && ufrag2 != null
&& compatibilityMode == CompatibilityMode.GTALK)
{ {
return null; ret = ufrag1 + ufrag2;
} }
ret = localUfrag + remoteUfrag;
return ret; return ret;
} }
@ -1258,15 +1260,13 @@ public class Agent
String localUFrag, String localUFrag,
boolean useCandidate) boolean useCandidate)
{ {
String ufrag = null;
LocalCandidate localCandidate = null; LocalCandidate localCandidate = null;
if(compatibilityMode == CompatibilityMode.GTALK) if(compatibilityMode == CompatibilityMode.GTALK
&& localAddress.getTransport() != Transport.TCP)
{ {
if(localAddress.getTransport() == Transport.TCP) localCandidate = findLocalCandidate(localAddress, remoteUFrag);
localCandidate = findLocalCandidate(localAddress);
else
localCandidate = findLocalCandidate(localAddress,
remoteUFrag);
} }
else else
{ {
@ -1306,23 +1306,15 @@ public class Agent
useCandidate = pair2.useCandidateReceived(); useCandidate = pair2.useCandidateReceived();
} }
ufrag = ((RemoteCandidate)pair.getRemoteCandidate()).getUfrag();
}
remoteCandidate = new RemoteCandidate( remoteCandidate = new RemoteCandidate(
remoteAddress, parentComponent, remoteAddress,
parentComponent,
CandidateType.PEER_REFLEXIVE_CANDIDATE, CandidateType.PEER_REFLEXIVE_CANDIDATE,
foundationsRegistry. foundationsRegistry.obtainFoundationForPeerReflexiveCandidate(),
obtainFoundationForPeerReflexiveCandidate(),
priority, priority,
((RemoteCandidate)pair.getRemoteCandidate()).getUfrag()); ufrag);
}
else
{
remoteCandidate = new RemoteCandidate(
remoteAddress, parentComponent,
CandidateType.PEER_REFLEXIVE_CANDIDATE,
foundationsRegistry.
obtainFoundationForPeerReflexiveCandidate(),
priority);
}
CandidatePair triggeredPair CandidatePair triggeredPair
= new CandidatePair(localCandidate, remoteCandidate); = new CandidatePair(localCandidate, remoteCandidate);

View File

@ -766,4 +766,11 @@ public abstract class Candidate
* Component yet. * Component yet.
*/ */
public abstract boolean isDefault(); public abstract boolean isDefault();
/**
* Get the local ufrag.
*
* @return local ufrag
*/
public abstract String getUfrag();
} }

View File

@ -378,24 +378,7 @@ class ConnectivityCheckClient
//If all of the pairs in the check list are now either in the Failed or //If all of the pairs in the check list are now either in the Failed or
//Succeeded state: //Succeeded state:
boolean allPairsDone = true; if(checkList.allChecksCompleted())
synchronized(checkList)
{
for(CandidatePair pair : checkList)
{
CandidatePairState pairState = pair.getState();
if((pairState != CandidatePairState.FAILED)
&& (pairState != CandidatePairState.SUCCEEDED))
{
allPairsDone = false;
break;
}
}
}
if (allPairsDone)
{ {
//If there is not a pair in the valid list for each component of the //If there is not a pair in the valid list for each component of the
//media stream, the state of the check list is set to Failed. //media stream, the state of the check list is set to Failed.

View File

@ -55,6 +55,11 @@ public class GoogleRelayedCandidate
*/ */
private final String username; private final String username;
/**
* Password.
*/
private final String password;
/** /**
* Initializes a new <tt>RelayedCandidate</tt> which is to represent a * Initializes a new <tt>RelayedCandidate</tt> which is to represent a
* specific <tt>TransportAddress</tt> harvested through a specific * specific <tt>TransportAddress</tt> harvested through a specific
@ -69,13 +74,16 @@ public class GoogleRelayedCandidate
* TURN server with the delivery of the replayed <tt>transportAddress</tt> * TURN server with the delivery of the replayed <tt>transportAddress</tt>
* to be represented by the new instance * to be represented by the new instance
* @param username username (Send request to the Google relay server need * @param username username (Send request to the Google relay server need
* it * it)
* @param password password (used with XMPP gingle candidates).
* it)
*/ */
public GoogleRelayedCandidate( public GoogleRelayedCandidate(
TransportAddress transportAddress, TransportAddress transportAddress,
GoogleTurnCandidateHarvest turnCandidateHarvest, GoogleTurnCandidateHarvest turnCandidateHarvest,
TransportAddress mappedAddress, TransportAddress mappedAddress,
String username) String username,
String password)
{ {
super( super(
transportAddress, transportAddress,
@ -91,6 +99,7 @@ public class GoogleRelayedCandidate
this.turnCandidateHarvest = turnCandidateHarvest; this.turnCandidateHarvest = turnCandidateHarvest;
this.username = username; this.username = username;
this.password = password;
// RFC 5245: The base of a relayed candidate is that candidate itself. // RFC 5245: The base of a relayed candidate is that candidate itself.
setBase(this); setBase(this);
@ -197,4 +206,13 @@ public class GoogleRelayedCandidate
} }
return socket; return socket;
} }
/**
* Returns the password for this candidate.
* @return the password for this candidate.
*/
public String getPassword()
{
return this.password;
}
} }

View File

@ -891,31 +891,6 @@ public class IceMediaStream
} }
} }
/**
* Returns the {@link CandidatePair} from <tt>component</tt> that's
* currently first in our valid list and that is therefore with the highest
* priority.
*
* @param component the {@link Component} whose highest priority valid
* {@link CandidatePair} we are looking for.
*
* @return the {@link CandidatePair} with the highest priority in our
* valid list or <tt>null</tt> if our valid list is still empty.
*/
public CandidatePair getFirstValidPair(Component component)
{
synchronized(validList)
{
for(CandidatePair pair : validList)
{
if (pair.getParentComponent() == component)
return pair;
}
}
return null;
}
/** /**
* Specifies the user name that we received from the remote peer. * Specifies the user name that we received from the remote peer.
* *

View File

@ -49,9 +49,12 @@ public class RemoteCandidate
String foundation, String foundation,
long priority) long priority)
{ {
super(transportAddress, parentComponent, type); this(transportAddress,
setFoundation(foundation); parentComponent,
setPriority(priority); type,
foundation,
priority,
null);
} }
/** /**
@ -76,7 +79,9 @@ public class RemoteCandidate
long priority, long priority,
String ufrag) String ufrag)
{ {
this(transportAddress, parentComponent, type, foundation, priority); super(transportAddress, parentComponent, type);
setFoundation(foundation);
setPriority(priority);
this.ufrag = ufrag; this.ufrag = ufrag;
} }

View File

@ -40,6 +40,11 @@ public class GoogleTurnCandidateHarvest
*/ */
private Request requestToStartResolvingCandidate; private Request requestToStartResolvingCandidate;
/**
* The gingle candidates password necessary to use the TURN server.
*/
private String password;
/** /**
* Initializes a new <tt>TurnCandidateHarvest</tt> which is to represent the * Initializes a new <tt>TurnCandidateHarvest</tt> which is to represent the
* harvesting of TURN <tt>Candidate</tt>s for a specific * harvesting of TURN <tt>Candidate</tt>s for a specific
@ -50,12 +55,16 @@ public class GoogleTurnCandidateHarvest
* the TURN harvesting * the TURN harvesting
* @param hostCandidate the <tt>HostCandidate</tt> for which TURN * @param hostCandidate the <tt>HostCandidate</tt> for which TURN
* <tt>Candidate</tt>s are to be harvested * <tt>Candidate</tt>s are to be harvested
* @param password The gingle candidates password necessary to use this TURN
* server.
*/ */
public GoogleTurnCandidateHarvest( public GoogleTurnCandidateHarvest(
GoogleTurnCandidateHarvester harvester, GoogleTurnCandidateHarvester harvester,
HostCandidate hostCandidate) HostCandidate hostCandidate,
String password)
{ {
super(harvester, hostCandidate); super(harvester, hostCandidate);
this.password = password;
} }
/** /**
@ -144,7 +153,8 @@ public class GoogleTurnCandidateHarvest
transportAddress, transportAddress,
this, this,
mappedAddress, mappedAddress,
harvester.getShortTermCredentialUsername()); harvester.getShortTermCredentialUsername(),
this.password);
candidate.setUfrag(harvester.getShortTermCredentialUsername()); candidate.setUfrag(harvester.getShortTermCredentialUsername());
return candidate; return candidate;

View File

@ -19,6 +19,11 @@ import org.ice4j.ice.*;
public class GoogleTurnCandidateHarvester public class GoogleTurnCandidateHarvester
extends StunCandidateHarvester extends StunCandidateHarvester
{ {
/**
* The gingle candidates password necessary to use the TURN server.
*/
private String password = null;
/** /**
* Initializes a new <tt>GoogleTurnCandidateHarvester</tt> instance which * Initializes a new <tt>GoogleTurnCandidateHarvester</tt> instance which
* is to work with a specific Google TURN server. * is to work with a specific Google TURN server.
@ -28,7 +33,7 @@ public class GoogleTurnCandidateHarvester
*/ */
public GoogleTurnCandidateHarvester(TransportAddress turnServer) public GoogleTurnCandidateHarvester(TransportAddress turnServer)
{ {
this(turnServer, null); this(turnServer, null, null);
} }
/** /**
@ -42,11 +47,15 @@ public class GoogleTurnCandidateHarvester
* instance for the purposes of the STUN short-term credential mechanism or * instance for the purposes of the STUN short-term credential mechanism or
* <tt>null</tt> if the use of the STUN short-term credential mechanism is * <tt>null</tt> if the use of the STUN short-term credential mechanism is
* not determined at the time of the construction of the new instance * not determined at the time of the construction of the new instance
* @param password The gingle candidates password necessary to use this TURN
* server.
*/ */
public GoogleTurnCandidateHarvester(TransportAddress turnServer, public GoogleTurnCandidateHarvester(TransportAddress turnServer,
String shortTermCredentialUsername) String shortTermCredentialUsername,
String password)
{ {
super(turnServer, shortTermCredentialUsername); super(turnServer, shortTermCredentialUsername);
this.password = password;
} }
/** /**
@ -63,6 +72,18 @@ public class GoogleTurnCandidateHarvester
protected GoogleTurnCandidateHarvest createHarvest( protected GoogleTurnCandidateHarvest createHarvest(
HostCandidate hostCandidate) HostCandidate hostCandidate)
{ {
return new GoogleTurnCandidateHarvest(this, hostCandidate); return new GoogleTurnCandidateHarvest(
this,
hostCandidate,
this.password);
}
/**
* Returns the password for this candidate.
* @return the password for this candidate.
*/
public String getPassword()
{
return this.password;
} }
} }

View File

@ -67,7 +67,7 @@ public class GoogleTurnSSLCandidateHarvester
*/ */
public GoogleTurnSSLCandidateHarvester(TransportAddress turnServer) public GoogleTurnSSLCandidateHarvester(TransportAddress turnServer)
{ {
this(turnServer, null); this(turnServer, null, null);
} }
/** /**
@ -81,11 +81,14 @@ public class GoogleTurnSSLCandidateHarvester
* instance for the purposes of the STUN short-term credential mechanism or * instance for the purposes of the STUN short-term credential mechanism or
* <tt>null</tt> if the use of the STUN short-term credential mechanism is * <tt>null</tt> if the use of the STUN short-term credential mechanism is
* not determined at the time of the construction of the new instance * not determined at the time of the construction of the new instance
* @param password The gingle candidates password necessary to use this TURN
* server.
*/ */
public GoogleTurnSSLCandidateHarvester(TransportAddress turnServer, public GoogleTurnSSLCandidateHarvester(TransportAddress turnServer,
String shortTermCredentialUsername) String shortTermCredentialUsername,
String password)
{ {
super(turnServer, shortTermCredentialUsername); super(turnServer, shortTermCredentialUsername, password);
} }
/** /**
@ -102,7 +105,10 @@ public class GoogleTurnSSLCandidateHarvester
protected GoogleTurnCandidateHarvest createHarvest( protected GoogleTurnCandidateHarvest createHarvest(
HostCandidate hostCandidate) HostCandidate hostCandidate)
{ {
return new GoogleTurnCandidateHarvest(this, hostCandidate); return new GoogleTurnCandidateHarvest(
this,
hostCandidate,
this.getPassword());
} }
/** /**