Jitsi: the OpenSource Java VoIP and Instant Messaging client.

net.java.sip.communicator.impl.protocol.jabber
Class TransportManagerGTalkImpl

java.lang.Object
  extended by net.java.sip.communicator.service.protocol.media.TransportManager<CallPeerGTalkImpl>
      extended by net.java.sip.communicator.impl.protocol.jabber.TransportManagerGTalkImpl
All Implemented Interfaces:
PropertyChangeListener, EventListener

public class TransportManagerGTalkImpl
extends TransportManager<CallPeerGTalkImpl>
implements PropertyChangeListener

TransportManagers gather local candidates for incoming and outgoing calls. Their work starts by calling a start method which, using the remote peer's session description, would start the harvest. Calling a second wrapup method would deliver the candidate harvest, possibly after blocking if it has not yet completed.

Author:
Emil Ivov, Lyubomir Marinov, Sebastien Vincent

Constructor Summary
TransportManagerGTalkImpl(CallPeerGTalkImpl callPeer)
          Creates a new instance of this transport manager, binding it to the specified peer.
 
Method Summary
 void close()
          Close this transport manager and release resources.
(package private) static org.ice4j.ice.Agent createAgent(ProtocolProviderServiceJabberImpl provider, boolean controlling)
          Creates the ICE agent that we would be using in this transport manager for all negotiation.
protected  StreamConnector createStreamConnector(MediaType mediaType)
          Initializes a new StreamConnector to be used as the connector of the MediaStream with a specific MediaType.
protected  int getCurrentGeneration()
          Returns the generation that our current candidates belong to.
 String getICECandidateExtendedType()
          Returns the extended type of the candidate selected if this transport manager is using ICE.
 String getICEState()
          Returns the current state of ICE processing.
protected  InetAddress getIntendedDestination(CallPeerGTalkImpl peer)
          Returns the InetAddress that is most likely to be to be used as a next hop when contacting the specified destination.
protected  String getNextID()
          Returns the ID that we will be assigning to the next candidate we create.
 StreamConnector getStreamConnector(MediaType mediaType)
          Gets the StreamConnector to be used as the connector of the MediaStream with a specific MediaType.
 MediaStreamTarget getStreamTarget(MediaType mediaType)
          Implements TransportManagerJabberImpl.getStreamTarget(MediaType).
protected  void incrementGeneration()
          Increments the generation that we are assigning candidates.
static Hashtable<String,String> parseGoogleRelay(String res)
          Parse HTTP response from Google relay.
 void propertyChange(PropertyChangeEvent evt)
          Retransmit state change events from the Agent.
static List<StunServerDescriptor> requestJingleInfo(ProtocolProviderServiceJabberImpl provider)
          Request Google's Jingle info.
 void sendHolePunchPacket(MediaStreamTarget target, MediaType type)
          Send empty UDP packet to target destination data/control ports in order to open port on NAT or RTP proxy if any.
 void startCandidateHarvest(List<PayloadTypePacketExtension> ourAnswer, CandidatesSender candidatesSender)
          Starts transport candidate harvest.
 boolean startConnectivityEstablishment(Iterable<GTalkCandidatePacketExtension> remote)
          Starts the connectivity establishment of this TransportManagerGTalkImpl i.e.
 void wrapupCandidateHarvest()
          Notifies the transport manager that it should conclude candidate harvesting as soon as possible.
 void wrapupConnectivityEstablishment()
          Waits for the associated ICE Agent to finish any started connectivity checks.
 
Methods inherited from class net.java.sip.communicator.service.protocol.media.TransportManager
closeStreamConnector, closeStreamConnector, getCallPeer, getICECandidateExtendedType, getLastUsedLocalHost, getNextMediaPortToTry, initializePortNumbers, setNextMediaPortToTry, setTrafficClass
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TransportManagerGTalkImpl

public TransportManagerGTalkImpl(CallPeerGTalkImpl callPeer)
Creates a new instance of this transport manager, binding it to the specified peer.

Parameters:
callPeer - the CallPeer whose traffic we will be taking care of.
Method Detail

getNextID

protected String getNextID()
Returns the ID that we will be assigning to the next candidate we create.

Returns:
the next ID to use with a candidate.

getCurrentGeneration

protected int getCurrentGeneration()
Returns the generation that our current candidates belong to.

Returns:
the generation that we should assign to candidates that we are currently advertising.

incrementGeneration

protected void incrementGeneration()
Increments the generation that we are assigning candidates.


getIntendedDestination

protected InetAddress getIntendedDestination(CallPeerGTalkImpl peer)
Returns the InetAddress that is most likely to be to be used as a next hop when contacting the specified destination. This is an utility method that is used whenever we have to choose one of our local addresses to put in the Via, Contact or (in the case of no registrar accounts) From headers.

Specified by:
getIntendedDestination in class TransportManager<CallPeerGTalkImpl>
Parameters:
peer - the CallPeer that we would contact.
Returns:
the InetAddress that is most likely to be to be used as a next hop when contacting the specified destination.
Throws:
IllegalArgumentException - if destination is not a valid host/IP/FQDN

requestJingleInfo

public static List<StunServerDescriptor> requestJingleInfo(ProtocolProviderServiceJabberImpl provider)
Request Google's Jingle info.

Parameters:
provider - ProtocolProviderService instance
Returns:
list of servers

parseGoogleRelay

public static Hashtable<String,String> parseGoogleRelay(String res)
Parse HTTP response from Google relay.

Parameters:
res - content string
Returns:
String

createAgent

static org.ice4j.ice.Agent createAgent(ProtocolProviderServiceJabberImpl provider,
                                       boolean controlling)
Creates the ICE agent that we would be using in this transport manager for all negotiation.

Parameters:
provider - ProtocolProviderServiceJabberImpl instance
controlling - if the peer is controlling or not
Returns:
the ICE agent to use for all the ICE negotiation that this transport manager would be going through

createStreamConnector

protected StreamConnector createStreamConnector(MediaType mediaType)
                                         throws OperationFailedException
Initializes a new StreamConnector to be used as the connector of the MediaStream with a specific MediaType.

Overrides:
createStreamConnector in class TransportManager<CallPeerGTalkImpl>
Parameters:
mediaType - the MediaType of the MediaStream which is to have its connector set to the returned StreamConnector
Returns:
a new StreamConnector to be used as the connector of the MediaStream with the specified MediaType
Throws:
OperationFailedException - if anything goes wrong while initializing the new StreamConnector

getStreamConnector

public StreamConnector getStreamConnector(MediaType mediaType)
                                   throws OperationFailedException
Gets the StreamConnector to be used as the connector of the MediaStream with a specific MediaType.

Overrides:
getStreamConnector in class TransportManager<CallPeerGTalkImpl>
Parameters:
mediaType - the MediaType of the MediaStream which is to have its connector set to the returned StreamConnector
Returns:
the StreamConnector to be used as the connector of the MediaStream with the specified MediaType
Throws:
OperationFailedException - if anything goes wrong while initializing the requested StreamConnector
See Also:
getStreamConnector(MediaType)

getStreamTarget

public MediaStreamTarget getStreamTarget(MediaType mediaType)
Implements TransportManagerJabberImpl.getStreamTarget(MediaType). Gets the MediaStreamTarget to be used as the target of the MediaStream with a specific MediaType.

Parameters:
mediaType - the MediaType of the MediaStream which is to have its target set to the returned MediaStreamTarget
Returns:
the MediaStreamTarget to be used as the target of the MediaStream with the specified MediaType
See Also:
TransportManagerJabberImpl.getStreamTarget(MediaType)

startCandidateHarvest

public void startCandidateHarvest(List<PayloadTypePacketExtension> ourAnswer,
                                  CandidatesSender candidatesSender)
                           throws OperationFailedException
Starts transport candidate harvest. This method should complete rapidly and, in case of lengthy procedures like STUN/TURN/UPnP candidate harvests are necessary, they should be executed in a separate thread.

Parameters:
ourAnswer - the content descriptions that we should be adding our transport lists to (although not necessarily in this very instance).
candidatesSender - the CandidatesSender to be used by this TransportManagerGTalkImpl to send candidates SessionIQs from the local peer to the remote peer if this TransportManagerGTalkImpl wishes to utilize candidates.
Throws:
OperationFailedException - if we fail to allocate a port number.

wrapupCandidateHarvest

public void wrapupCandidateHarvest()
Notifies the transport manager that it should conclude candidate harvesting as soon as possible.


startConnectivityEstablishment

public boolean startConnectivityEstablishment(Iterable<GTalkCandidatePacketExtension> remote)
Starts the connectivity establishment of this TransportManagerGTalkImpl i.e. checks the connectivity between the local and the remote peers given the remote counterpart of the negotiation between them.

Parameters:
remote - the collection of CandidatePacketExtensions which represents the remote counterpart of the negotiation between the local and the remote peer
Returns:
true if connectivity establishment has been started in response to the call; otherwise, false.

wrapupConnectivityEstablishment

public void wrapupConnectivityEstablishment()
                                     throws OperationFailedException
Waits for the associated ICE Agent to finish any started connectivity checks.

Throws:
OperationFailedException - if ICE processing has failed

sendHolePunchPacket

public void sendHolePunchPacket(MediaStreamTarget target,
                                MediaType type)
Send empty UDP packet to target destination data/control ports in order to open port on NAT or RTP proxy if any.

Overrides:
sendHolePunchPacket in class TransportManager<CallPeerGTalkImpl>
Parameters:
target - MediaStreamTarget
type - the MediaType of the connector we'd like to send the hole punching packet through.

close

public void close()
Close this transport manager and release resources.


getICECandidateExtendedType

public String getICECandidateExtendedType()
Returns the extended type of the candidate selected if this transport manager is using ICE.

Specified by:
getICECandidateExtendedType in class TransportManager<CallPeerGTalkImpl>
Returns:
The extended type of the candidate selected if this transport manager is using ICE. Otherwise, returns null.

propertyChange

public void propertyChange(PropertyChangeEvent evt)
Retransmit state change events from the Agent.

Specified by:
propertyChange in interface PropertyChangeListener
Parameters:
evt - the event for state change.

getICEState

public String getICEState()
Returns the current state of ICE processing.

Specified by:
getICEState in class TransportManager<CallPeerGTalkImpl>
Returns:
the current state of ICE processing.

Jitsi: the OpenSource Java VoIP and Instant Messaging client.

Jitsi, the OpenSource Java VoIP and Instant Messaging client.
Distributable under LGPL license.