diff --git a/src/org/ice4j/ice/CandidatePair.java b/src/org/ice4j/ice/CandidatePair.java
index 6ee45e4..65a6122 100644
--- a/src/org/ice4j/ice/CandidatePair.java
+++ b/src/org/ice4j/ice/CandidatePair.java
@@ -7,7 +7,6 @@
package org.ice4j.ice;
import java.util.*;
-import java.util.logging.*;
/**
* CandidatePairs map local to remote Candidates so that they
@@ -23,13 +22,6 @@ import java.util.logging.*;
public class CandidatePair
implements Comparable
{
- /**
- * The Logger used by the CandidatePair
- * class and its instances for logging output.
- */
- private static final Logger logger = Logger
- .getLogger(CandidatePair.class.getName());
-
/**
* The local candidate of this pair.
*/
diff --git a/src/org/ice4j/ice/ConnectivityCheckClient.java b/src/org/ice4j/ice/ConnectivityCheckClient.java
index beeb308..5c5f46e 100644
--- a/src/org/ice4j/ice/ConnectivityCheckClient.java
+++ b/src/org/ice4j/ice/ConnectivityCheckClient.java
@@ -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 Logger used by the ConnectivityCheckClient
+ * class and its instances for logging output.
+ */
+ private static final Logger logger = Logger
+ .getLogger(ConnectivityCheckClient.class.getName());
+ /**
+ * The DatagramPacketFilter 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);
+
+ }
}
diff --git a/src/org/ice4j/ice/ConnectivityCheckServer.java b/src/org/ice4j/ice/ConnectivityCheckServer.java
index 44d6485..c331d23 100644
--- a/src/org/ice4j/ice/ConnectivityCheckServer.java
+++ b/src/org/ice4j/ice/ConnectivityCheckServer.java
@@ -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);
+ }
}
diff --git a/src/org/ice4j/ice/HostCandidate.java b/src/org/ice4j/ice/HostCandidate.java
index 67d20be..698c674 100644
--- a/src/org/ice4j/ice/HostCandidate.java
+++ b/src/org/ice4j/ice/HostCandidate.java
@@ -8,8 +8,10 @@
package org.ice4j.ice;
import java.net.*;
+import java.util.logging.*;
import org.ice4j.*;
+import org.ice4j.socket.*;
/**
* HostCandidates are obtained by binding to a specific port from an
@@ -27,6 +29,12 @@ import org.ice4j.*;
*/
public class HostCandidate extends LocalCandidate
{
+ /**
+ * The Logger used by the HostCandidate
+ * 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 DatagramPacketFilter 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 DatagramSocket that this candidate uses when sending
+ * and receiving STUN packets, while harvesting STUN candidates or
+ * performing connectivity checks.
+ *
+ * @return the DatagramSocket 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;
+ }
}
diff --git a/src/org/ice4j/ice/IceMediaStream.java b/src/org/ice4j/ice/IceMediaStream.java
index fda70f0..031f5b4 100644
--- a/src/org/ice4j/ice/IceMediaStream.java
+++ b/src/org/ice4j/ice/IceMediaStream.java
@@ -277,6 +277,7 @@ public class IceMediaStream
orderCheckList();
pruneCheckList();
computeInitialCheckListPairStates();
+ logger.finest("Checklist initialized.");
}
}
diff --git a/src/org/ice4j/ice/harvest/StunCandidateHarvester.java b/src/org/ice4j/ice/harvest/StunCandidateHarvester.java
index 7368e6f..86504f4 100644
--- a/src/org/ice4j/ice/harvest/StunCandidateHarvester.java
+++ b/src/org/ice4j/ice/harvest/StunCandidateHarvester.java
@@ -171,7 +171,7 @@ public class StunCandidateHarvester
* the DatagramSocket to be used for communication with
* {@link #stunServer} when gathering Candidates for a specific
* HostCandidate.
- *
+ *
* @return the DatagramPacketFilter which is to be associated with
* the DatagramSocket to be used for communication with
* {@link #stunServer} when gathering Candidates for a specific