Makes stun transactions more visible to users of the stun stack

This commit is contained in:
emcho 2010-02-15 15:53:39 +00:00
parent 8d42bce81c
commit 0786b771c6
4 changed files with 59 additions and 38 deletions

View File

@ -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 <tt>TransactionID</tt> 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());
}
/**

View File

@ -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<HostCandidate> resolveList
= new LinkedList<HostCandidate>();
private final Map<TransactionID, HostCandidate> resolveMap
= new Hashtable<TransactionID, HostCandidate>();
/**
* 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();
}
}
/**

View File

@ -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.*;
/**
* <p>Title: Stun4J.</p>
* <p>Description: Simple Traversal of UDP Through NAT.</p>
* <p>Copyright: Copyright (c) 2003.</p>
* <p>Organisation: <p> Louis Pasteur University, Strasbourg, France.</p>
* <p>Network Research Team (http://www-r2.u-strasbg.fr).</p></p>
* 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);
}

View File

@ -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