diff --git a/src/org/ice4j/StunMessageEvent.java b/src/org/ice4j/StunMessageEvent.java index 927645a..378be8b 100644 --- a/src/org/ice4j/StunMessageEvent.java +++ b/src/org/ice4j/StunMessageEvent.java @@ -9,6 +9,7 @@ package org.ice4j; import java.util.*; import org.ice4j.message.*; +import org.ice4j.stack.*; /** @@ -38,6 +39,12 @@ public class StunMessageEvent */ private TransportAddress remoteAddress = null; + /** + * The TransactionID of the transaction that the source message + * is related to. + */ + private final TransactionID tranID; + /** * Constructs a StunMessageEvent according to the specified message. * @param sourceAddress the access point that received the message @@ -51,6 +58,7 @@ public class StunMessageEvent super(sourceAddress); this.message = message; this.remoteAddress = remoteAddress; + this.transactionID = TransactionID.createTransactionID(message.getTransactionID()); } /** diff --git a/src/org/ice4j/ice/harvest/StunCandidateHarvester.java b/src/org/ice4j/ice/harvest/StunCandidateHarvester.java index 997cec7..b8e2780 100644 --- a/src/org/ice4j/ice/harvest/StunCandidateHarvester.java +++ b/src/org/ice4j/ice/harvest/StunCandidateHarvester.java @@ -10,6 +10,7 @@ package org.ice4j.ice.harvest; import java.io.*; import java.net.*; import java.util.*; +import java.util.logging.*; import org.ice4j.*; import org.ice4j.ice.*; @@ -26,6 +27,11 @@ public class StunCandidateHarvester implements CandidateHarvester, ResponseCollector { + /** + * Our class logger. + */ + private final Logger logger + = Logger.getLogger(StunCandidateHarvester.class.getName()); /** * The stack to use for STUN communication. @@ -40,8 +46,8 @@ public class StunCandidateHarvester /** * The list of candidates that we are currently resolving. */ - private final List resolveList - = new LinkedList(); + private final Map resolveMap + = new Hashtable(); /** * Creates a new STUN harvester that will be running against the specified @@ -98,23 +104,27 @@ public class StunCandidateHarvester DatagramSocket sock = hostCand.getSocket(); stunStack.addSocket(sock); - synchronized(resolveList) + synchronized(resolveMap) { - resolveList.add(hostCand); + TransactionID tran; + try + { + tran = stunStack.sendRequest( + MessageFactory.createBindingRequest(), stunServer, sock, + this); + + } + catch (Exception exception) + { + logger.log(Level.INFO, "Failed to send a STUN Binding Request", + exception); + return; + } + + resolveMap.put(tran, hostCand); } - try - { - stunStack.sendRequest(MessageFactory.createBindingRequest(), - stunServer, sock, this); - } - catch (Exception e) - { - synchronized(resolveList) - { - resolveList.remove(hostCand); - } - } + waitForResolutionEnd(); } /** @@ -123,14 +133,14 @@ public class StunCandidateHarvester */ private void waitForResolutionEnd() { - synchronized(resolveList) + synchronized(resolveMap) { - if(resolveList.isEmpty()) + if(resolveMap.isEmpty()) return; try { - resolveList.wait(); + resolveMap.wait(); } catch (InterruptedException e){} } @@ -143,7 +153,11 @@ public class StunCandidateHarvester */ public void processResponse(StunMessageEvent response) { - response.getMessage().getTransactionID(); + synchronized (resolveMap) + { + //TransactionID tranID = response.getMessage().getTransactionID(); + } + } /** diff --git a/src/org/ice4j/stack/RequestListener.java b/src/org/ice4j/stack/RequestListener.java index 81a2547..b09c9f6 100644 --- a/src/org/ice4j/stack/RequestListener.java +++ b/src/org/ice4j/stack/RequestListener.java @@ -1,24 +1,25 @@ /* - * 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.stack; import org.ice4j.*; /** - *

Title: Stun4J.

- *

Description: Simple Traversal of UDP Through NAT.

- *

Copyright: Copyright (c) 2003.

- *

Organisation:

Louis Pasteur University, Strasbourg, France.

- *

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

+ * Handles incoming requests. + * * @author Emil Ivov - * @version 0.1 */ public interface RequestListener { + /** + * Called when delivering incoming STUN requests. + * + * @param evt the event containing the incoming STUN request. + */ public void requestReceived(StunMessageEvent evt); } diff --git a/src/org/ice4j/stack/TransactionID.java b/src/org/ice4j/stack/TransactionID.java index 6793afa..611cd84 100644 --- a/src/org/ice4j/stack/TransactionID.java +++ b/src/org/ice4j/stack/TransactionID.java @@ -1,24 +1,22 @@ /* - * 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.stack; -import java.util.Random; -import java.util.Arrays; +import java.util.*; /** * This class encapsulates a STUN transaction ID. It is useful for storing - * transaction ids in collection objects as it implements the equals method. - * It also provies a utility for creating unique transaction ids. + * transaction IDs in collection objects as it implements the equals method. + * It also provides a utility for creating unique transaction IDs. * * @author Emil Ivov - * @version 0.1 */ -class TransactionID +public class TransactionID { /** * The id itself