Adds a StunCandidateHarvester

This commit is contained in:
emcho 2010-02-15 19:34:29 +00:00
parent 986a66f3b2
commit ee881c9ae0
9 changed files with 64 additions and 31 deletions

View File

@ -101,4 +101,22 @@ public class StunMessageEvent
{ {
return transactionID; return transactionID;
} }
/**
* Returns a <tt>String</tt> representation of this event, containing the
* corresponding message, remote and local addresses.
*
* @return a <tt>String</tt> 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();
}
} }

View File

@ -46,9 +46,16 @@ public class Agent
* The candidate harvester that we use to gather candidate on the local * The candidate harvester that we use to gather candidate on the local
* machine. * machine.
*/ */
private HostCandidateHarvester hostCandidateHarvester private final HostCandidateHarvester hostCandidateHarvester
= new 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<CandidateHarvester> harvesters
= new ArrayList<CandidateHarvester>();
/** /**
* We use the <tt>FoundationsRegistry</tt> to keep track of the foundations * We use the <tt>FoundationsRegistry</tt> to keep track of the foundations
* we assign within a session (i.e. the entire life time of an * we assign within a session (i.e. the entire life time of an
@ -156,7 +163,14 @@ public class Agent
hostCandidateHarvester.harvest( hostCandidateHarvester.harvest(
component, preferredPort, minPort, maxPort); 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); computeFoundations(component);
@ -182,21 +196,17 @@ public class Agent
} }
/** /**
* Computes and sets the priorities for all <tt>Candidate</tt>s currently * Adds <tt>harvester</tt> to the list of harvesters that this agent will
* found in <tt>component</tt>. This happens outside of the * use when gathering <tt>Candidate</tt>s.
* <tt>Candidate</tt> 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.
* *
* @param component the component whose candidates we'd like to prioritize. * @param harvester a <tt>CandidateHarvester</tt> that this agent should use
* when gathering candidates.
*/ */
private void computePriorities(Component component) public void addCandidateHarvester(CandidateHarvester harvester)
{ {
List<Candidate> candidates = component.getLocalCandidates(); synchronized(harvesters)
for (Candidate cand : candidates)
{ {
cand.computePriority(); harvesters.add(harvester);
} }
} }
} }

View File

@ -14,6 +14,7 @@ import java.util.logging.*;
import org.ice4j.*; import org.ice4j.*;
import org.ice4j.ice.*; import org.ice4j.ice.*;
import org.ice4j.socket.*;
/** /**
* A <tt>HostCandidateHarvester</tt> gathers host <tt>Candidate</tt>s for a * A <tt>HostCandidateHarvester</tt> gathers host <tt>Candidate</tt>s for a
@ -193,7 +194,8 @@ public class HostCandidateHarvester
try try
{ {
DatagramSocket sock = new DatagramSocket(port, laddr); DatagramSocket sock
= new MultiplexingDatagramSocket(port, laddr);
if(logger.isLoggable(Level.FINEST)) if(logger.isLoggable(Level.FINEST))
logger.log(Level.FINEST, logger.log(Level.FINEST,

View File

@ -7,7 +7,6 @@
*/ */
package org.ice4j.ice.harvest; package org.ice4j.ice.harvest;
import java.io.*;
import java.net.*; import java.net.*;
import java.util.*; import java.util.*;
import java.util.logging.*; import java.util.logging.*;
@ -157,7 +156,15 @@ public class StunCandidateHarvester
{ {
TransactionID tranID = response.getTransactionID(); 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("received a message tranid=" + tranID);
System.out.println("response=" + response);
} }
} }

View File

@ -676,9 +676,9 @@ public abstract class Message
*/ */
public String toString() public String toString()
{ {
return getName()+"("+getMessageType() return getName()+"(0x"+Integer.toHexString(getMessageType())
+")[attrib.count=" + getAttributeCount() +")[attrib.count=" + getAttributeCount()
+" len=" + this.getDataLength() +" len=" + (int) this.getDataLength()
+" tranID=" + this.getTransactionID() + "]"; +" tranID=" + this.getTransactionID() + "]";
} }

View File

@ -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. * Distributable under LGPL license. See terms of license at gnu.org.
* See terms of license at gnu.org.
*/ */
package org.ice4j.message; package org.ice4j.message;
@ -13,10 +13,7 @@ import org.ice4j.*;
* Response class is to allow better functional definition of the classes in the * Response class is to allow better functional definition of the classes in the
* stack package. * stack package.
* *
* <p>Organisation: <p> Louis Pasteur University, Strasbourg, France</p>
* <p>Network Research Team (http://www-r2.u-strasbg.fr)</p></p>
* @author Emil Ivov * @author Emil Ivov
* @version 0.1
*/ */
public class Response extends Message public class Response extends Message

View File

@ -87,7 +87,8 @@ class Connector
void start() void start()
{ {
this.isRunning = true; this.isRunning = true;
Thread thread = new Thread(this); Thread thread = new Thread(this, "IceConnector@"+hashCode());
thread.setDaemon(true);
thread.start(); thread.start();
} }

View File

@ -171,7 +171,9 @@ class StunClientTransaction
+"generated an invalid transaction ID"); +"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 * @throws IOException if an error occurs while sending message bytes
* through the network socket. * through the network socket.
* @throws IllegalArgumentException if the apDescriptor references an * @throws IllegalArgumentException if the apDescriptor references an
<<<<<<< HEAD
* access point that had not been installed * 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() void sendRequest()
throws IllegalArgumentException, IOException throws IllegalArgumentException, IOException

View File

@ -119,7 +119,8 @@ class StunServerTransaction
this.localListeningAddress = localListeningAddress; this.localListeningAddress = localListeningAddress;
this.requestSource = requestSource; this.requestSource = requestSource;
runningThread = new Thread(this); runningThread = new Thread(this, "StunServerTransaction@"+hashCode());
runningThread.setDaemon(true);
} }
/** /**