Adds a StunTimeoutEvent to the processTimeout() method. Adds a reachability check in the stun candidate retriever.
This commit is contained in:
parent
3f2b90bccc
commit
6c08af84a4
@ -28,7 +28,7 @@ public interface ResponseCollector
|
||||
* after repeated retransmissions of the original request (as described
|
||||
* by rfc3489) and that the request should be considered unanswered.
|
||||
*/
|
||||
public void processTimeout();
|
||||
public void processTimeout(StunTimeoutEvent event);
|
||||
|
||||
/**
|
||||
* Notifies this collector that the destination of the request has been
|
||||
|
||||
105
src/org/ice4j/StunTimeoutEvent.java
Normal file
105
src/org/ice4j/StunTimeoutEvent.java
Normal file
@ -0,0 +1,105 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
package org.ice4j;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import org.ice4j.message.*;
|
||||
import org.ice4j.stack.*;
|
||||
|
||||
/**
|
||||
* The class is used to dispatch events that occur when a STUN transaction
|
||||
* expires.
|
||||
*
|
||||
* @author Emil Ivov
|
||||
*/
|
||||
public class StunTimeoutEvent
|
||||
extends EventObject
|
||||
{
|
||||
/**
|
||||
* Serial version UID for this Serializable class.
|
||||
*/
|
||||
private static final long serialVersionUID = 41267841L;
|
||||
|
||||
/**
|
||||
* The message that the corresponding transaction was about.
|
||||
*/
|
||||
private Message message = null;
|
||||
|
||||
/**
|
||||
* The <tt>TransactionID</tt> of the transaction that the source message
|
||||
* is related to.
|
||||
*/
|
||||
private final TransactionID transactionID;
|
||||
|
||||
/**
|
||||
* Constructs a <tt>StunTimeoutEvent</tt> according to the specified
|
||||
* message.
|
||||
*
|
||||
* @param message the message itself
|
||||
* @param localAddress the local address that the message was sent from.
|
||||
*/
|
||||
public StunTimeoutEvent(Message message,
|
||||
TransportAddress localAddress)
|
||||
{
|
||||
super(localAddress);
|
||||
this.message = message;
|
||||
this.transactionID = TransactionID.createTransactionID(message
|
||||
.getTransactionID());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the <tt>TransportAddress</tt> that the message was supposed to
|
||||
* leave from.
|
||||
*
|
||||
* @return the <tt>TransportAddress</tt> that the message was supposed to
|
||||
* leave from.
|
||||
*/
|
||||
public TransportAddress getLocalAddress()
|
||||
{
|
||||
return (TransportAddress)getSource();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the <tt>Message</tt> whose transaction has just expired.
|
||||
*
|
||||
* @return the <tt>Message</tt> whose transaction has just expired.
|
||||
*/
|
||||
public Message getMessage()
|
||||
{
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the id of the transaction that has just expired.
|
||||
*
|
||||
* @return the <tt>TransactionID</tt> of the transaction that has just
|
||||
* expired.
|
||||
*/
|
||||
public TransactionID getTransactionID()
|
||||
{
|
||||
return transactionID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a <tt>String</tt> representation of this event, containing the
|
||||
* corresponding message, and local address.
|
||||
*
|
||||
* @return a <tt>String</tt> representation of this event, containing the
|
||||
* corresponding message, and local address.
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
StringBuffer buff = new StringBuffer("StunTimeoutEvent:\n\tMessage=");
|
||||
|
||||
buff.append(getMessage());
|
||||
buff.append(" localAddr=").append(getLocalAddress());
|
||||
|
||||
return buff.toString();
|
||||
}
|
||||
|
||||
}
|
||||
@ -205,4 +205,41 @@ public class TransportAddress
|
||||
return super.equals(obj)
|
||||
&&( ((TransportAddress)obj).getTransport() == getTransport() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns <tt>true</tt> if this is an IPv6 address and <tt>false</tt>
|
||||
* otherwise.
|
||||
*
|
||||
* @return <tt>true</tt> if this is an IPv6 address and <tt>false</tt>
|
||||
* otherwise.
|
||||
*/
|
||||
public boolean isIPv6()
|
||||
{
|
||||
return getAddress() instanceof Inet6Address;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether this <tt>TransportAddress</tt> is theoretically
|
||||
* capable of communicating with <tt>dst</tt>. An address is certain not
|
||||
* to be able to communicate with another if they do not have the same
|
||||
* <tt>Transport</tt> or family.
|
||||
*
|
||||
* @param dst the <tt>TransportAddress</tt> that we'd like to check for
|
||||
* reachability from this one.
|
||||
*
|
||||
* @return <tt>true</tt> if this {@link TransportAddress} shares the same
|
||||
* <tt>Transport</tt> and family as <tt>dst</tt> or <tt>false</tt>
|
||||
* otherwise.
|
||||
*
|
||||
*/
|
||||
public boolean canReach(TransportAddress dst)
|
||||
{
|
||||
if (dst.getTransport() != getTransport())
|
||||
return false;
|
||||
|
||||
if( isIPv6() != dst.isIPv6())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -206,8 +206,9 @@ public class HostCandidateHarvester
|
||||
{
|
||||
logger.log(Level.INFO,
|
||||
"Retrying a bind because of a failure to bind to address "
|
||||
+ laddr + " and port " + port);
|
||||
logger.log(Level.FINEST, "", se);
|
||||
+ laddr + " and port " + port
|
||||
+ " (" + se.getMessage() +")");
|
||||
logger.log(Level.INFO, "", se);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -100,6 +100,11 @@ public class StunCandidateHarvester
|
||||
*/
|
||||
private void startResolvingCandidate(HostCandidate hostCand)
|
||||
{
|
||||
//first of all, make sure that the STUN server and the Candidate
|
||||
//address are of the same type and that they can communicate.
|
||||
if(!hostCand.getTransportAddress().canReach(stunServer))
|
||||
return;
|
||||
|
||||
DatagramSocket sock = hostCand.getSocket();
|
||||
stunStack.addSocket(sock);
|
||||
|
||||
@ -122,8 +127,6 @@ public class StunCandidateHarvester
|
||||
|
||||
resolveMap.put(tran, hostCand);
|
||||
}
|
||||
|
||||
waitForResolutionEnd();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -170,13 +173,29 @@ public class StunCandidateHarvester
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify the collector that no response had been received
|
||||
* Notifies the collector that no response had been received
|
||||
* after repeated retransmissions of the original request (as described
|
||||
* by rfc3489) and that the request should be considered unanswered.
|
||||
*
|
||||
* @param event the <tt>StunTimeoutEvent</tt> that contains the transaction
|
||||
* which has just expired.
|
||||
*/
|
||||
public void processTimeout()
|
||||
public void processTimeout(StunTimeoutEvent event)
|
||||
{
|
||||
synchronized (resolveMap)
|
||||
{
|
||||
TransactionID tranID = event.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("a tran expired tranid=" + tranID);
|
||||
System.out.println("event=" + event);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -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;
|
||||
|
||||
|
||||
@ -14,8 +14,9 @@ import java.net.*;
|
||||
* Represents a <tt>DatagramSocket</tt> which fixes the following problem: when
|
||||
* {@link DatagramSocket#close()} is called while another thread is blocked in
|
||||
* its {@link DatagramSocket#receive(DatagramPacket)}, calling
|
||||
* {@link DatagramSocket#bind(SocketAddress) throws an "Already bound" exception
|
||||
* until (the native counterpart of) the <tt>receive</tt> method returns.
|
||||
* {@link DatagramSocket#bind(SocketAddress)} throws an "Already bound"
|
||||
* exception until (the native counterpart of) the <tt>receive</tt> method
|
||||
* returns.
|
||||
*
|
||||
* @author Lubomir Marinov
|
||||
*/
|
||||
|
||||
@ -222,7 +222,8 @@ class StunClientTransaction
|
||||
|
||||
waitFor(nextWaitInterval);
|
||||
|
||||
responseCollector.processTimeout();
|
||||
responseCollector.processTimeout(
|
||||
new StunTimeoutEvent(this.request, getLocalAddress()));
|
||||
stackCallback.removeClientTransaction(this);
|
||||
}
|
||||
|
||||
|
||||
@ -99,8 +99,11 @@ class BlockingRequestSender
|
||||
/**
|
||||
* Notifies the discoverer thread when a message has timeout-ed so that
|
||||
* it may resume and consider it as unanswered.
|
||||
*
|
||||
* @param evt the <tt>StunTimeoutEvent</tt> containing the transaction that
|
||||
* has just expired.
|
||||
*/
|
||||
public synchronized void processTimeout()
|
||||
public synchronized void processTimeout(StunTimeoutEvent evt)
|
||||
{
|
||||
synchronized(sendLock){
|
||||
ended = true;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user