diff --git a/src/org/ice4j/StunMessageEvent.java b/src/org/ice4j/StunMessageEvent.java index 24104bf..1310f5a 100644 --- a/src/org/ice4j/StunMessageEvent.java +++ b/src/org/ice4j/StunMessageEvent.java @@ -101,4 +101,22 @@ public class StunMessageEvent { return transactionID; } + + /** + * Returns a String representation of this event, containing the + * corresponding message, remote and local addresses. + * + * @return a String representation of this event, containing the + * corresponding message, remote and local addresses. + */ + public String toString() + { + StringBuffer buff = new StringBuffer("StunMessageEvent:\n\tMessage="); + + buff.append(getMessage()); + buff.append(" remoteAddr=").append(getRemoteAddress()); + buff.append(" localAddr=").append(getLocalAddress()); + + return buff.toString(); + } } diff --git a/src/org/ice4j/ice/Agent.java b/src/org/ice4j/ice/Agent.java index d36b88a..872c553 100644 --- a/src/org/ice4j/ice/Agent.java +++ b/src/org/ice4j/ice/Agent.java @@ -46,9 +46,16 @@ public class Agent * The candidate harvester that we use to gather candidate on the local * machine. */ - private HostCandidateHarvester hostCandidateHarvester + private final HostCandidateHarvester hostCandidateHarvester = new HostCandidateHarvester(); + /** + * The list of harvesters (i.e. STUN, TURN, and others) that the agent + * should use when gathering candidates for components. + */ + private final List harvesters + = new ArrayList(); + /** * We use the FoundationsRegistry to keep track of the foundations * we assign within a session (i.e. the entire life time of an @@ -156,7 +163,14 @@ public class Agent hostCandidateHarvester.harvest( component, preferredPort, minPort, maxPort); - //TODO: apply STUN and TURN harvesters now. + //apply other harvesters here: + synchronized(harvesters) + { + for (CandidateHarvester h : harvesters ) + { + h.harvest(component); + } + } computeFoundations(component); @@ -182,21 +196,17 @@ public class Agent } /** - * Computes and sets the priorities for all Candidates currently - * found in component. This happens outside of the - * Candidate class because some of the decisions made about the - * priority of the candidates is made based on the number of candidates of - * a certain type. + * Adds harvester to the list of harvesters that this agent will + * use when gathering Candidates. * - * @param component the component whose candidates we'd like to prioritize. + * @param harvester a CandidateHarvester that this agent should use + * when gathering candidates. */ - private void computePriorities(Component component) + public void addCandidateHarvester(CandidateHarvester harvester) { - List candidates = component.getLocalCandidates(); - - for (Candidate cand : candidates) + synchronized(harvesters) { - cand.computePriority(); + harvesters.add(harvester); } } } diff --git a/src/org/ice4j/ice/harvest/HostCandidateHarvester.java b/src/org/ice4j/ice/harvest/HostCandidateHarvester.java index abec65f..2ebf44f 100644 --- a/src/org/ice4j/ice/harvest/HostCandidateHarvester.java +++ b/src/org/ice4j/ice/harvest/HostCandidateHarvester.java @@ -14,6 +14,7 @@ import java.util.logging.*; import org.ice4j.*; import org.ice4j.ice.*; +import org.ice4j.socket.*; /** * A HostCandidateHarvester gathers host Candidates for a @@ -193,7 +194,8 @@ public class HostCandidateHarvester try { - DatagramSocket sock = new DatagramSocket(port, laddr); + DatagramSocket sock + = new MultiplexingDatagramSocket(port, laddr); if(logger.isLoggable(Level.FINEST)) logger.log(Level.FINEST, diff --git a/src/org/ice4j/ice/harvest/StunCandidateHarvester.java b/src/org/ice4j/ice/harvest/StunCandidateHarvester.java index 94ef50d..5411f75 100644 --- a/src/org/ice4j/ice/harvest/StunCandidateHarvester.java +++ b/src/org/ice4j/ice/harvest/StunCandidateHarvester.java @@ -7,7 +7,6 @@ */ package org.ice4j.ice.harvest; -import java.io.*; import java.net.*; import java.util.*; import java.util.logging.*; @@ -157,7 +156,15 @@ public class StunCandidateHarvester { TransactionID tranID = response.getTransactionID(); + Candidate localCand = resolveMap.remove(tranID); + + //if this was the last candidate, we are done with the STUN + //resolution and need to notify the waiters. + if(resolveMap.isEmpty()) + resolveMap.notify(); + System.out.println("received a message tranid=" + tranID); + System.out.println("response=" + response); } } diff --git a/src/org/ice4j/message/Message.java b/src/org/ice4j/message/Message.java index 7911cc8..5229070 100644 --- a/src/org/ice4j/message/Message.java +++ b/src/org/ice4j/message/Message.java @@ -676,9 +676,9 @@ public abstract class Message */ public String toString() { - return getName()+"("+getMessageType() + return getName()+"(0x"+Integer.toHexString(getMessageType()) +")[attrib.count=" + getAttributeCount() - +" len=" + this.getDataLength() + +" len=" + (int) this.getDataLength() +" tranID=" + this.getTransactionID() + "]"; } diff --git a/src/org/ice4j/message/Response.java b/src/org/ice4j/message/Response.java index f5e629c..61974c8 100644 --- a/src/org/ice4j/message/Response.java +++ b/src/org/ice4j/message/Response.java @@ -1,8 +1,8 @@ /* - * Stun4j, the OpenSource Java Solution for NAT and Firewall Traversal. + * ice4j, the OpenSource Java Solution for NAT and Firewall Traversal. + * Maintained by the SIP Communicator community (http://sip-communicator.org). * - * Distributable under LGPL license. - * See terms of license at gnu.org. + * Distributable under LGPL license. See terms of license at gnu.org. */ package org.ice4j.message; @@ -13,10 +13,7 @@ import org.ice4j.*; * Response class is to allow better functional definition of the classes in the * stack package. * - *

Organisation:

Louis Pasteur University, Strasbourg, France

- *

Network Research Team (http://www-r2.u-strasbg.fr)

* @author Emil Ivov - * @version 0.1 */ public class Response extends Message diff --git a/src/org/ice4j/stack/Connector.java b/src/org/ice4j/stack/Connector.java index 6b4804d..005cc59 100644 --- a/src/org/ice4j/stack/Connector.java +++ b/src/org/ice4j/stack/Connector.java @@ -87,7 +87,8 @@ class Connector void start() { this.isRunning = true; - Thread thread = new Thread(this); + Thread thread = new Thread(this, "IceConnector@"+hashCode()); + thread.setDaemon(true); thread.start(); } diff --git a/src/org/ice4j/stack/StunClientTransaction.java b/src/org/ice4j/stack/StunClientTransaction.java index cff9416..a740d24 100644 --- a/src/org/ice4j/stack/StunClientTransaction.java +++ b/src/org/ice4j/stack/StunClientTransaction.java @@ -171,7 +171,9 @@ class StunClientTransaction +"generated an invalid transaction ID"); } - retransmissionsThread = new Thread(this); + retransmissionsThread = new Thread(this, + "StunClientTransaction@"+hashCode()); + retransmissionsThread.setDaemon(true); } /** @@ -231,13 +233,8 @@ class StunClientTransaction * @throws IOException if an error occurs while sending message bytes * through the network socket. * @throws IllegalArgumentException if the apDescriptor references an -<<<<<<< HEAD * access point that had not been installed - * @throws StunException if message encoding fails -======= - * access point that had not been installed, * ->>>>>>> Makes stun transactions more visible to users of the stun stack */ void sendRequest() throws IllegalArgumentException, IOException diff --git a/src/org/ice4j/stack/StunServerTransaction.java b/src/org/ice4j/stack/StunServerTransaction.java index bb9068a..604e7e8 100644 --- a/src/org/ice4j/stack/StunServerTransaction.java +++ b/src/org/ice4j/stack/StunServerTransaction.java @@ -119,7 +119,8 @@ class StunServerTransaction this.localListeningAddress = localListeningAddress; this.requestSource = requestSource; - runningThread = new Thread(this); + runningThread = new Thread(this, "StunServerTransaction@"+hashCode()); + runningThread.setDaemon(true); } /**