Begins work on a connectivity check client and server
This commit is contained in:
parent
9ee59ef0d2
commit
cf2bee10aa
@ -7,7 +7,6 @@
|
|||||||
package org.ice4j.ice;
|
package org.ice4j.ice;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.logging.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <tt>CandidatePair</tt>s map local to remote <tt>Candidate</tt>s so that they
|
* <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
|
public class CandidatePair
|
||||||
implements Comparable<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.
|
* The local candidate of this pair.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -6,10 +6,91 @@
|
|||||||
*/
|
*/
|
||||||
package org.ice4j.ice;
|
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
|
* @author Emil Ivov
|
||||||
*/
|
*/
|
||||||
public class ConnectivityCheckClient
|
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);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,10 +6,34 @@
|
|||||||
*/
|
*/
|
||||||
package org.ice4j.ice;
|
package org.ice4j.ice;
|
||||||
|
|
||||||
|
import org.ice4j.*;
|
||||||
|
import org.ice4j.stack.*;
|
||||||
/**
|
/**
|
||||||
* @author Emil Ivov
|
* @author Emil Ivov
|
||||||
*/
|
*/
|
||||||
public class ConnectivityCheckServer
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,8 +8,10 @@
|
|||||||
package org.ice4j.ice;
|
package org.ice4j.ice;
|
||||||
|
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
|
import java.util.logging.*;
|
||||||
|
|
||||||
import org.ice4j.*;
|
import org.ice4j.*;
|
||||||
|
import org.ice4j.socket.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <tt>HostCandidate</tt>s are obtained by binding to a specific port from an
|
* <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
|
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
|
* 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;
|
private final DatagramSocket socket;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The <tt>DatagramPacketFilter</tt> that only accepts STUN messages.
|
||||||
|
*/
|
||||||
|
private DatagramPacketFilter stunDatagramPacketFilter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a HostCandidate for the specified transport address.
|
* Creates a HostCandidate for the specified transport address.
|
||||||
*
|
*
|
||||||
@ -65,4 +78,41 @@ public class HostCandidate extends LocalCandidate
|
|||||||
{
|
{
|
||||||
return socket;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -277,6 +277,7 @@ public class IceMediaStream
|
|||||||
orderCheckList();
|
orderCheckList();
|
||||||
pruneCheckList();
|
pruneCheckList();
|
||||||
computeInitialCheckListPairStates();
|
computeInitialCheckListPairStates();
|
||||||
|
logger.finest("Checklist initialized.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -171,7 +171,7 @@ public class StunCandidateHarvester
|
|||||||
* the <tt>DatagramSocket</tt> to be used for communication with
|
* the <tt>DatagramSocket</tt> to be used for communication with
|
||||||
* {@link #stunServer} when gathering <tt>Candidate</tt>s for a specific
|
* {@link #stunServer} when gathering <tt>Candidate</tt>s for a specific
|
||||||
* <tt>HostCandidate</tt>.
|
* <tt>HostCandidate</tt>.
|
||||||
*
|
*
|
||||||
* @return the <tt>DatagramPacketFilter</tt> which is to be associated with
|
* @return the <tt>DatagramPacketFilter</tt> which is to be associated with
|
||||||
* the <tt>DatagramSocket</tt> to be used for communication with
|
* the <tt>DatagramSocket</tt> to be used for communication with
|
||||||
* {@link #stunServer} when gathering <tt>Candidate</tt>s for a specific
|
* {@link #stunServer} when gathering <tt>Candidate</tt>s for a specific
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user