Begins work on a connectivity check client and server

This commit is contained in:
emcho 2010-04-25 14:39:54 +00:00
parent 9ee59ef0d2
commit cf2bee10aa
6 changed files with 157 additions and 9 deletions

View File

@ -7,7 +7,6 @@
package org.ice4j.ice;
import java.util.*;
import java.util.logging.*;
/**
* <tt>CandidatePair</tt>s map local to remote <tt>Candidate</tt>s so that they
@ -23,13 +22,6 @@ import java.util.logging.*;
public class CandidatePair
implements Comparable<CandidatePair>
{
/**
* The <tt>Logger</tt> used by the <tt>CandidatePair</tt>
* class and its instances for logging output.
*/
private static final Logger logger = Logger
.getLogger(CandidatePair.class.getName());
/**
* The local candidate of this pair.
*/

View File

@ -6,10 +6,91 @@
*/
package org.ice4j.ice;
import java.net.*;
import java.util.logging.*;
import org.ice4j.*;
import org.ice4j.message.*;
import org.ice4j.socket.*;
import org.ice4j.stack.*;
/**
* @author Emil Ivov
*/
public class ConnectivityCheckClient
implements ResponseCollector
{
/**
* The <tt>Logger</tt> used by the <tt>ConnectivityCheckClient</tt>
* class and its instances for logging output.
*/
private static final Logger logger = Logger
.getLogger(ConnectivityCheckClient.class.getName());
/**
* The <tt>DatagramPacketFilter</tt> that only accepts STUN messages.
*/
private DatagramPacketFilter stunDatagramPacketFilter;
private final CheckList checkList;
public ConnectivityCheckClient(CheckList list)
{
this.checkList = list;
}
public void startChecks()
{
for(CandidatePair pair : checkList)
{
startCheckForPair(pair);
}
}
private void startCheckForPair(CandidatePair pair)
{
//we don't need to do a canReach() verification here as it has been
//already verified during the gathering process.
DatagramSocket stunSocket = ((HostCandidate)pair.getLocalCandidate())
.getStunSocket(pair.getRemoteCandidate().getTransportAddress());
StunStack.getInstance().addSocket(stunSocket);
Request request = MessageFactory.createBindingRequest();
TransactionID tran;
try
{
tran = StunStack.getInstance().sendRequest(
request, pair.getRemoteCandidate().getTransportAddress(),
stunSocket,
this);
}
catch (Exception exception)
{
logger.log(
Level.INFO,
"Failed to send " + request + " through "
+ stunSocket.getLocalSocketAddress(),
exception);
return;
}
}
public void processResponse(StunMessageEvent response)
{
System.out.println("stun response=" + response);
}
public void processTimeout(StunTimeoutEvent event)
{
System.out.println("timeout event=" + event);
}
public void processUnreachable(StunFailureEvent event)
{
System.out.println("failure event=" + event);
}
}

View File

@ -6,10 +6,34 @@
*/
package org.ice4j.ice;
import org.ice4j.*;
import org.ice4j.stack.*;
/**
* @author Emil Ivov
*/
public class ConnectivityCheckServer
implements RequestListener
{
StunStack stunStack = StunStack.getInstance();
public ConnectivityCheckServer()
{
stunStack.addRequestListener(this);
}
public void startListening(LocalCandidate candidate)
{
stunStack.addSocket(candidate.getSocket());
}
public void stopListenint(LocalCandidate candidate)
{
stunStack.removeSocket(candidate.getTransportAddress());
}
public void requestReceived(StunMessageEvent evt)
{
System.out.println("evt=" + evt);
}
}

View File

@ -8,8 +8,10 @@
package org.ice4j.ice;
import java.net.*;
import java.util.logging.*;
import org.ice4j.*;
import org.ice4j.socket.*;
/**
* <tt>HostCandidate</tt>s are obtained by binding to a specific port from an
@ -27,6 +29,12 @@ import org.ice4j.*;
*/
public class HostCandidate extends LocalCandidate
{
/**
* The <tt>Logger</tt> used by the <tt>HostCandidate</tt>
* class and its instances for logging output.
*/
private static final Logger logger = Logger
.getLogger(HostCandidate.class.getName());
/**
* If this is a local candidate the field contains the socket that is
@ -34,6 +42,11 @@ public class HostCandidate extends LocalCandidate
*/
private final DatagramSocket socket;
/**
* The <tt>DatagramPacketFilter</tt> that only accepts STUN messages.
*/
private DatagramPacketFilter stunDatagramPacketFilter;
/**
* Creates a HostCandidate for the specified transport address.
*
@ -65,4 +78,41 @@ public class HostCandidate extends LocalCandidate
{
return socket;
}
/**
* Returns the <tt>DatagramSocket</tt> that this candidate uses when sending
* and receiving STUN packets, while harvesting STUN candidates or
* performing connectivity checks.
*
* @return the <tt>DatagramSocket</tt> that this candidate uses when sending
* and receiving STUN packets, while harvesting STUN candidates or
* performing connectivity checks.
*/
public DatagramSocket getStunSocket(TransportAddress serverAddress)
{
DatagramSocket hostSocket = getSocket();
DatagramSocket stunSocket = null;
Throwable exception = null;
if (hostSocket instanceof MultiplexingDatagramSocket)
try
{
stunSocket
= ((MultiplexingDatagramSocket) hostSocket)
.getSocket( new StunDatagramPacketFilter(
serverAddress));
}
catch (SocketException sex)//don't u just luv da name? ;)
{
logger.log( Level.SEVERE,
"Failed to acquire DatagramSocket"
+ " specific to STUN communication.",
sex);
exception = sex;
}
if (stunSocket == null)
throw new IllegalArgumentException("hostCand", exception);
else
return stunSocket;
}
}

View File

@ -277,6 +277,7 @@ public class IceMediaStream
orderCheckList();
pruneCheckList();
computeInitialCheckListPairStates();
logger.finest("Checklist initialized.");
}
}

View File

@ -171,7 +171,7 @@ public class StunCandidateHarvester
* the <tt>DatagramSocket</tt> to be used for communication with
* {@link #stunServer} when gathering <tt>Candidate</tt>s for a specific
* <tt>HostCandidate</tt>.
*
*
* @return the <tt>DatagramPacketFilter</tt> which is to be associated with
* the <tt>DatagramSocket</tt> to be used for communication with
* {@link #stunServer} when gathering <tt>Candidate</tt>s for a specific