Adds a StunCandidateHarvester
This commit is contained in:
parent
986a66f3b2
commit
ee881c9ae0
@ -101,4 +101,22 @@ public class StunMessageEvent
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@ -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<CandidateHarvester> harvesters
|
||||
= new ArrayList<CandidateHarvester>();
|
||||
|
||||
/**
|
||||
* 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
|
||||
@ -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 <tt>Candidate</tt>s currently
|
||||
* found in <tt>component</tt>. This happens outside of the
|
||||
* <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.
|
||||
* Adds <tt>harvester</tt> to the list of harvesters that this agent will
|
||||
* use when gathering <tt>Candidate</tt>s.
|
||||
*
|
||||
* @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();
|
||||
|
||||
for (Candidate cand : candidates)
|
||||
synchronized(harvesters)
|
||||
{
|
||||
cand.computePriority();
|
||||
harvesters.add(harvester);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -14,6 +14,7 @@ import java.util.logging.*;
|
||||
|
||||
import org.ice4j.*;
|
||||
import org.ice4j.ice.*;
|
||||
import org.ice4j.socket.*;
|
||||
|
||||
/**
|
||||
* A <tt>HostCandidateHarvester</tt> gathers host <tt>Candidate</tt>s 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,
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -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() + "]";
|
||||
}
|
||||
|
||||
|
||||
@ -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.
|
||||
*
|
||||
* <p>Organisation: <p> Louis Pasteur University, Strasbourg, France</p>
|
||||
* <p>Network Research Team (http://www-r2.u-strasbg.fr)</p></p>
|
||||
* @author Emil Ivov
|
||||
* @version 0.1
|
||||
*/
|
||||
|
||||
public class Response extends Message
|
||||
|
||||
@ -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();
|
||||
}
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user