Removes duplication, simplifies the implementation of ResponseCollector.
This commit is contained in:
parent
41ed1c9e41
commit
0b0986dd29
51
src/org/ice4j/AbstractResponseCollector.java
Normal file
51
src/org/ice4j/AbstractResponseCollector.java
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Lubomir Marinov
|
||||||
|
*/
|
||||||
|
public abstract class AbstractResponseCollector
|
||||||
|
implements ResponseCollector
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notifies this <tt>ResponseCollector</tt> that a transaction described by
|
||||||
|
* the specified <tt>BaseStunMessageEvent</tt> has failed. The possible
|
||||||
|
* reasons for the failure include timeouts, unreachable destination, etc.
|
||||||
|
*
|
||||||
|
* @param event the <tt>BaseStunMessageEvent</tt> which describes the failed
|
||||||
|
* transaction and the runtime type of which specifies the failure reason
|
||||||
|
*/
|
||||||
|
protected abstract void processFailure(BaseStunMessageEvent event);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notifies this 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> containing a reference to the
|
||||||
|
* transaction that has just failed.
|
||||||
|
*/
|
||||||
|
public void processTimeout(StunTimeoutEvent event)
|
||||||
|
{
|
||||||
|
processFailure(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notifies this collector that the destination of the request has been
|
||||||
|
* determined to be unreachable and that the request should be considered
|
||||||
|
* unanswered.
|
||||||
|
*
|
||||||
|
* @param event the <tt>StunFailureEvent</tt> containing the
|
||||||
|
* <tt>PortUnreachableException</tt> that has just occurred.
|
||||||
|
*/
|
||||||
|
public void processUnreachable(StunFailureEvent event)
|
||||||
|
{
|
||||||
|
processFailure(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
84
src/org/ice4j/BaseStunMessageEvent.java
Normal file
84
src/org/ice4j/BaseStunMessageEvent.java
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
/*
|
||||||
|
* 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.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents an <tt>EventObject</tt> which notifies of an event associated with
|
||||||
|
* a specific STUN <tt>Message</tt>.
|
||||||
|
*
|
||||||
|
* @author Lubomir Marinov
|
||||||
|
*/
|
||||||
|
public class BaseStunMessageEvent
|
||||||
|
extends EventObject
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The STUN <tt>Message</tt> associated with this event.
|
||||||
|
*/
|
||||||
|
private final Message message;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The ID of the transaction related to {@link #message}.
|
||||||
|
*/
|
||||||
|
private TransactionID transactionID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes a new <tt>BaseStunMessageEvent</tt> associated with a
|
||||||
|
* specific STUN <tt>Message</tt>.
|
||||||
|
*
|
||||||
|
* @param sourceAddress the <tt>TransportAddress</tt> which is to be
|
||||||
|
* reported as the source of the new event
|
||||||
|
* @param message the STUN <tt>Message</tt> associated with the new event
|
||||||
|
*/
|
||||||
|
public BaseStunMessageEvent(TransportAddress sourceAddress, Message message)
|
||||||
|
{
|
||||||
|
super(sourceAddress);
|
||||||
|
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the STUN <tt>Message</tt> associated with this event.
|
||||||
|
*
|
||||||
|
* @return the STUN <tt>Message</tt> associated with this event
|
||||||
|
*/
|
||||||
|
public Message getMessage()
|
||||||
|
{
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the <tt>TransportAddress</tt> which is the source of this event.
|
||||||
|
*
|
||||||
|
* @return the <tt>TransportAddress</tt> which is the source of this event
|
||||||
|
*/
|
||||||
|
protected TransportAddress getSourceAddress()
|
||||||
|
{
|
||||||
|
return (TransportAddress) getSource();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the ID of the transaction related to the STUN <tt>Message</tt>
|
||||||
|
* associated with this event.
|
||||||
|
*
|
||||||
|
* @return the ID of the transaction related to the STUN <tt>Message</tt>
|
||||||
|
* associated with this event
|
||||||
|
*/
|
||||||
|
public TransactionID getTransactionID()
|
||||||
|
{
|
||||||
|
if (transactionID == null)
|
||||||
|
transactionID
|
||||||
|
= TransactionID
|
||||||
|
.createTransactionID(getMessage().getTransactionID());
|
||||||
|
return transactionID;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -22,12 +22,12 @@ public interface ResponseCollector
|
|||||||
public void processResponse(StunMessageEvent response);
|
public void processResponse(StunMessageEvent response);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notify the collector that no response had been received
|
* Notifies this collector that no response had been received after repeated
|
||||||
* after repeated retransmissions of the original request (as described
|
* retransmissions of the original request (as described by rfc3489) and
|
||||||
* by rfc3489) and that the request should be considered unanswered.
|
* that the request should be considered unanswered.
|
||||||
*
|
*
|
||||||
* @param event the <tt>StunTimeoutEvent</tt> containing a reference to
|
* @param event the <tt>StunTimeoutEvent</tt> containing a reference to the
|
||||||
* the transaction that has just failed.
|
* transaction that has just failed.
|
||||||
*/
|
*/
|
||||||
public void processTimeout(StunTimeoutEvent event);
|
public void processTimeout(StunTimeoutEvent event);
|
||||||
|
|
||||||
|
|||||||
@ -6,10 +6,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.ice4j;
|
package org.ice4j;
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
import org.ice4j.message.*;
|
import org.ice4j.message.*;
|
||||||
import org.ice4j.stack.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The class is used to dispatch events that occur when a STUN transaction
|
* The class is used to dispatch events that occur when a STUN transaction
|
||||||
@ -19,24 +16,13 @@ import org.ice4j.stack.*;
|
|||||||
* @author Emil Ivov
|
* @author Emil Ivov
|
||||||
*/
|
*/
|
||||||
public class StunFailureEvent
|
public class StunFailureEvent
|
||||||
extends EventObject
|
extends BaseStunMessageEvent
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Serial version UID for this Serializable class.
|
* Serial version UID for this Serializable class.
|
||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = 41232541L;
|
private static final long serialVersionUID = 41232541L;
|
||||||
|
|
||||||
/**
|
|
||||||
* The message that the corresponding transaction was about.
|
|
||||||
*/
|
|
||||||
private final Message message;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The <tt>TransactionID</tt> of the transaction that the source message
|
|
||||||
* is related to.
|
|
||||||
*/
|
|
||||||
private final TransactionID transactionID;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The <tt>Exception</tt> that caused this failure.
|
* The <tt>Exception</tt> that caused this failure.
|
||||||
*/
|
*/
|
||||||
@ -56,10 +42,7 @@ public class StunFailureEvent
|
|||||||
TransportAddress localAddress,
|
TransportAddress localAddress,
|
||||||
Throwable cause)
|
Throwable cause)
|
||||||
{
|
{
|
||||||
super(localAddress);
|
super(localAddress, message);
|
||||||
this.message = message;
|
|
||||||
this.transactionID = TransactionID.createTransactionID(message
|
|
||||||
.getTransactionID());
|
|
||||||
|
|
||||||
this.cause = cause;
|
this.cause = cause;
|
||||||
}
|
}
|
||||||
@ -73,28 +56,7 @@ public class StunFailureEvent
|
|||||||
*/
|
*/
|
||||||
public TransportAddress getLocalAddress()
|
public TransportAddress getLocalAddress()
|
||||||
{
|
{
|
||||||
return (TransportAddress)getSource();
|
return getSourceAddress();
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the <tt>Message</tt> whose transaction has just failed.
|
|
||||||
*
|
|
||||||
* @return the <tt>Message</tt> whose transaction has just failed.
|
|
||||||
*/
|
|
||||||
public Message getMessage()
|
|
||||||
{
|
|
||||||
return message;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the id of the transaction that has just failed.
|
|
||||||
*
|
|
||||||
* @return the <tt>TransactionID</tt> of the transaction that has just
|
|
||||||
* failed.
|
|
||||||
*/
|
|
||||||
public TransactionID getTransactionID()
|
|
||||||
{
|
|
||||||
return transactionID;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -116,9 +78,10 @@ public class StunFailureEvent
|
|||||||
* @return a <tt>String</tt> representation of this event, containing the
|
* @return a <tt>String</tt> representation of this event, containing the
|
||||||
* corresponding message, and local address.
|
* corresponding message, and local address.
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
StringBuffer buff = new StringBuffer("StunTimeoutEvent:\n\tMessage=");
|
StringBuffer buff = new StringBuffer("StunFailureEvent:\n\tMessage=");
|
||||||
|
|
||||||
buff.append(getMessage());
|
buff.append(getMessage());
|
||||||
buff.append(" localAddr=").append(getLocalAddress());
|
buff.append(" localAddr=").append(getLocalAddress());
|
||||||
|
|||||||
@ -6,11 +6,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.ice4j;
|
package org.ice4j;
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
import org.ice4j.message.*;
|
import org.ice4j.message.*;
|
||||||
import org.ice4j.stack.*;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The class is used to dispatch incoming stun messages. Apart from the message
|
* The class is used to dispatch incoming stun messages. Apart from the message
|
||||||
@ -22,28 +18,17 @@ import org.ice4j.stack.*;
|
|||||||
* @author Emil Ivov
|
* @author Emil Ivov
|
||||||
*/
|
*/
|
||||||
public class StunMessageEvent
|
public class StunMessageEvent
|
||||||
extends EventObject
|
extends BaseStunMessageEvent
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Serial version UID for this Serializable class.
|
* Serial version UID for this Serializable class.
|
||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = 41267843L;
|
private static final long serialVersionUID = 41267843L;
|
||||||
|
|
||||||
/**
|
|
||||||
* The message itself.
|
|
||||||
*/
|
|
||||||
private Message message = null;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The sending address.
|
* The sending address.
|
||||||
*/
|
*/
|
||||||
private TransportAddress remoteAddress = null;
|
private final TransportAddress remoteAddress;
|
||||||
|
|
||||||
/**
|
|
||||||
* The <tt>TransactionID</tt> of the transaction that the source message
|
|
||||||
* is related to.
|
|
||||||
*/
|
|
||||||
private final TransactionID transactionID;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a StunMessageEvent according to the specified message.
|
* Constructs a StunMessageEvent according to the specified message.
|
||||||
@ -55,11 +40,9 @@ public class StunMessageEvent
|
|||||||
Message message,
|
Message message,
|
||||||
TransportAddress remoteAddress)
|
TransportAddress remoteAddress)
|
||||||
{
|
{
|
||||||
super(sourceAddress);
|
super(sourceAddress, message);
|
||||||
this.message = message;
|
|
||||||
this.remoteAddress = remoteAddress;
|
this.remoteAddress = remoteAddress;
|
||||||
this.transactionID = TransactionID.createTransactionID(message
|
|
||||||
.getTransactionID());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -69,16 +52,7 @@ public class StunMessageEvent
|
|||||||
*/
|
*/
|
||||||
public TransportAddress getLocalAddress()
|
public TransportAddress getLocalAddress()
|
||||||
{
|
{
|
||||||
return (TransportAddress)getSource();
|
return getSourceAddress();
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the message being dispatched.
|
|
||||||
* @return the message that caused the event.
|
|
||||||
*/
|
|
||||||
public Message getMessage()
|
|
||||||
{
|
|
||||||
return message;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -90,18 +64,6 @@ public class StunMessageEvent
|
|||||||
return remoteAddress;
|
return remoteAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the id of the transaction associated with the message that
|
|
||||||
* triggered this event.
|
|
||||||
*
|
|
||||||
* @return the id of the transaction associated with the message that
|
|
||||||
* triggered this event.
|
|
||||||
*/
|
|
||||||
public TransactionID getTransactionID()
|
|
||||||
{
|
|
||||||
return transactionID;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a <tt>String</tt> representation of this event, containing the
|
* Returns a <tt>String</tt> representation of this event, containing the
|
||||||
* corresponding message, remote and local addresses.
|
* corresponding message, remote and local addresses.
|
||||||
@ -109,6 +71,7 @@ public class StunMessageEvent
|
|||||||
* @return a <tt>String</tt> representation of this event, containing the
|
* @return a <tt>String</tt> representation of this event, containing the
|
||||||
* corresponding message, remote and local addresses.
|
* corresponding message, remote and local addresses.
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
StringBuffer buff = new StringBuffer("StunMessageEvent:\n\tMessage=");
|
StringBuffer buff = new StringBuffer("StunMessageEvent:\n\tMessage=");
|
||||||
|
|||||||
@ -6,10 +6,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.ice4j;
|
package org.ice4j;
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
import org.ice4j.message.*;
|
import org.ice4j.message.*;
|
||||||
import org.ice4j.stack.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The class is used to dispatch events that occur when a STUN transaction
|
* The class is used to dispatch events that occur when a STUN transaction
|
||||||
@ -18,24 +15,13 @@ import org.ice4j.stack.*;
|
|||||||
* @author Emil Ivov
|
* @author Emil Ivov
|
||||||
*/
|
*/
|
||||||
public class StunTimeoutEvent
|
public class StunTimeoutEvent
|
||||||
extends EventObject
|
extends BaseStunMessageEvent
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Serial version UID for this Serializable class.
|
* Serial version UID for this Serializable class.
|
||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = 41267841L;
|
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
|
* Constructs a <tt>StunTimeoutEvent</tt> according to the specified
|
||||||
* message.
|
* message.
|
||||||
@ -46,10 +32,7 @@ public class StunTimeoutEvent
|
|||||||
public StunTimeoutEvent(Message message,
|
public StunTimeoutEvent(Message message,
|
||||||
TransportAddress localAddress)
|
TransportAddress localAddress)
|
||||||
{
|
{
|
||||||
super(localAddress);
|
super(localAddress, message);
|
||||||
this.message = message;
|
|
||||||
this.transactionID = TransactionID.createTransactionID(message
|
|
||||||
.getTransactionID());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -61,28 +44,7 @@ public class StunTimeoutEvent
|
|||||||
*/
|
*/
|
||||||
public TransportAddress getLocalAddress()
|
public TransportAddress getLocalAddress()
|
||||||
{
|
{
|
||||||
return (TransportAddress)getSource();
|
return getSourceAddress();
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -92,6 +54,7 @@ public class StunTimeoutEvent
|
|||||||
* @return a <tt>String</tt> representation of this event, containing the
|
* @return a <tt>String</tt> representation of this event, containing the
|
||||||
* corresponding message, and local address.
|
* corresponding message, and local address.
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
StringBuffer buff = new StringBuffer("StunTimeoutEvent:\n\tMessage=");
|
StringBuffer buff = new StringBuffer("StunTimeoutEvent:\n\tMessage=");
|
||||||
@ -101,5 +64,4 @@ public class StunTimeoutEvent
|
|||||||
|
|
||||||
return buff.toString();
|
return buff.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,8 +27,8 @@ import org.ice4j.stack.*;
|
|||||||
* @author Lubomir Marinov
|
* @author Lubomir Marinov
|
||||||
*/
|
*/
|
||||||
public class StunCandidateHarvester
|
public class StunCandidateHarvester
|
||||||
implements CandidateHarvester,
|
extends AbstractResponseCollector
|
||||||
ResponseCollector
|
implements CandidateHarvester
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* The <tt>Logger</tt> used by the <tt>StunCandidateHarvester</tt>
|
* The <tt>Logger</tt> used by the <tt>StunCandidateHarvester</tt>
|
||||||
@ -267,6 +267,20 @@ public class StunCandidateHarvester
|
|||||||
waitForResolutionEnd();
|
waitForResolutionEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notifies this <tt>ResponseCollector</tt> that a transaction described by
|
||||||
|
* the specified <tt>BaseStunMessageEvent</tt> has failed. The possible
|
||||||
|
* reasons for the failure include timeouts, unreachable destination, etc.
|
||||||
|
*
|
||||||
|
* @param event the <tt>BaseStunMessageEvent</tt> which describes the failed
|
||||||
|
* transaction and the runtime type of which specifies the failure reason
|
||||||
|
* @see AbstractResponseCollector#processFailure(BaseStunMessageEvent)
|
||||||
|
*/
|
||||||
|
protected void processFailure(BaseStunMessageEvent event)
|
||||||
|
{
|
||||||
|
processFailure(event.getTransactionID());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes the corresponding local candidate from the list of candidates
|
* Removes the corresponding local candidate from the list of candidates
|
||||||
* that we are waiting on in order to complete the harvest.
|
* that we are waiting on in order to complete the harvest.
|
||||||
@ -315,34 +329,6 @@ public class StunCandidateHarvester
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 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(StunTimeoutEvent event)
|
|
||||||
{
|
|
||||||
processFailure(event.getTransactionID());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when one of our requests results in a
|
|
||||||
* <tt>PortUnreachableException</tt> ... which is actually quite rare
|
|
||||||
* because of the oddities of the BSD and Java socket implementations, which
|
|
||||||
* is why we currently ignore this method.
|
|
||||||
*
|
|
||||||
* @param event the <tt>StunFailureEvent</tt> containing the
|
|
||||||
* <tt>PortUnreachableException</tt> which signaled that the destination of
|
|
||||||
* the request was found to be unreachable.
|
|
||||||
*/
|
|
||||||
public void processUnreachable(StunFailureEvent event)
|
|
||||||
{
|
|
||||||
processFailure(event.getTransactionID());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resends a binding request to our stun server through the specified
|
* Resends a binding request to our stun server through the specified
|
||||||
* <tt>srflxCand</tt> candidate so that it would keep the potential NAT
|
* <tt>srflxCand</tt> candidate so that it would keep the potential NAT
|
||||||
|
|||||||
@ -31,9 +31,10 @@ import org.ice4j.stack.*;
|
|||||||
*</code>
|
*</code>
|
||||||
*
|
*
|
||||||
* @author Emil Ivov
|
* @author Emil Ivov
|
||||||
|
* @author Lubomir Marinov
|
||||||
*/
|
*/
|
||||||
class BlockingRequestSender
|
class BlockingRequestSender
|
||||||
implements ResponseCollector
|
extends AbstractResponseCollector
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Our class logger
|
* Our class logger
|
||||||
@ -81,50 +82,35 @@ class BlockingRequestSender
|
|||||||
this.localAddress = localAddress;
|
this.localAddress = localAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notifies this <tt>ResponseCollector</tt> that a transaction described by
|
||||||
|
* the specified <tt>BaseStunMessageEvent</tt> has failed. The possible
|
||||||
|
* reasons for the failure include timeouts, unreachable destination, etc.
|
||||||
|
* Notifies the discoverer so that it may resume.
|
||||||
|
*
|
||||||
|
* @param event the <tt>BaseStunMessageEvent</tt> which describes the failed
|
||||||
|
* transaction and the runtime type of which specifies the failure reason
|
||||||
|
* @see AbstractResponseCollector#processFailure(BaseStunMessageEvent)
|
||||||
|
*/
|
||||||
|
protected synchronized void processFailure(BaseStunMessageEvent event)
|
||||||
|
{
|
||||||
|
synchronized(sendLock)
|
||||||
|
{
|
||||||
|
ended = true;
|
||||||
|
notifyAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Saves the message event and notifies the discoverer thread so that
|
* Saves the message event and notifies the discoverer thread so that
|
||||||
* it may resume.
|
* it may resume.
|
||||||
* @param evt the newly arrived message event.
|
* @param evt the newly arrived message event.
|
||||||
*/
|
*/
|
||||||
public synchronized void processResponse(StunMessageEvent evt)
|
public synchronized void processResponse(StunMessageEvent evt)
|
||||||
{
|
|
||||||
synchronized(sendLock){
|
|
||||||
this.responseEvent = evt;
|
|
||||||
ended = true;
|
|
||||||
notifyAll();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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(StunTimeoutEvent evt)
|
|
||||||
{
|
|
||||||
synchronized(sendLock){
|
|
||||||
ended = true;
|
|
||||||
notifyAll();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Notifies this collector that the destination of the request has been
|
|
||||||
* determined to be unreachable and that the request should be considered
|
|
||||||
* unanswered.
|
|
||||||
*
|
|
||||||
* @param event the <tt>StunFailureEvent</tt> that contains the
|
|
||||||
* <tt>PortUnreachableException</tt> which signaled that the destination of
|
|
||||||
* the request was found to be unreachable
|
|
||||||
* @see ResponseCollector#processUnreachable(StunFailureEvent)
|
|
||||||
*/
|
|
||||||
public synchronized void processUnreachable(
|
|
||||||
StunFailureEvent event)
|
|
||||||
{
|
{
|
||||||
synchronized(sendLock)
|
synchronized(sendLock)
|
||||||
{
|
{
|
||||||
|
this.responseEvent = evt;
|
||||||
ended = true;
|
ended = true;
|
||||||
notifyAll();
|
notifyAll();
|
||||||
}
|
}
|
||||||
@ -150,13 +136,15 @@ class BlockingRequestSender
|
|||||||
throws StunException,
|
throws StunException,
|
||||||
IOException
|
IOException
|
||||||
{
|
{
|
||||||
synchronized(sendLock){
|
synchronized(sendLock)
|
||||||
|
{
|
||||||
stunStack.sendRequest(request, serverAddress, localAddress,
|
stunStack.sendRequest(request, serverAddress, localAddress,
|
||||||
BlockingRequestSender.this);
|
BlockingRequestSender.this);
|
||||||
}
|
}
|
||||||
|
|
||||||
ended = false;
|
ended = false;
|
||||||
while(!ended){
|
while(!ended)
|
||||||
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
wait();
|
wait();
|
||||||
|
|||||||
@ -281,13 +281,36 @@ public class MessageEventDispatchingTest extends TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A utility class we use to collect incoming responses.
|
* A utility class to collect incoming responses.
|
||||||
*/
|
*/
|
||||||
private class PlainResponseCollector
|
private static class PlainResponseCollector
|
||||||
implements ResponseCollector
|
extends AbstractResponseCollector
|
||||||
{
|
{
|
||||||
public final Vector<Object> receivedResponses = new Vector<Object>();
|
public final Vector<Object> receivedResponses = new Vector<Object>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notifies this <tt>ResponseCollector</tt> that a transaction described by
|
||||||
|
* the specified <tt>BaseStunMessageEvent</tt> has failed. The possible
|
||||||
|
* reasons for the failure include timeouts, unreachable destination, etc.
|
||||||
|
*
|
||||||
|
* @param event the <tt>BaseStunMessageEvent</tt> which describes the failed
|
||||||
|
* transaction and the runtime type of which specifies the failure reason
|
||||||
|
* @see AbstractResponseCollector#processFailure(BaseStunMessageEvent)
|
||||||
|
*/
|
||||||
|
protected void processFailure(BaseStunMessageEvent event)
|
||||||
|
{
|
||||||
|
String receivedResponse;
|
||||||
|
|
||||||
|
if (event instanceof StunFailureEvent)
|
||||||
|
receivedResponse = "unreachable";
|
||||||
|
else if (event instanceof StunTimeoutEvent)
|
||||||
|
receivedResponse = "timeout";
|
||||||
|
else
|
||||||
|
receivedResponse = "failure";
|
||||||
|
receivedResponses.add(receivedResponse);
|
||||||
|
notifyAll();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stores incoming requests.
|
* Stores incoming requests.
|
||||||
*
|
*
|
||||||
@ -299,36 +322,6 @@ public class MessageEventDispatchingTest extends TestCase
|
|||||||
notifyAll();
|
notifyAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when the associated transaction expires.
|
|
||||||
*
|
|
||||||
* @param evt the <tt>StunTimeoutEvent</tt> containing a reference to
|
|
||||||
* the failed <tt>Message</tt> and the expired transaction.
|
|
||||||
*/
|
|
||||||
public synchronized void processTimeout(StunTimeoutEvent evt)
|
|
||||||
{
|
|
||||||
receivedResponses.add("timeout");
|
|
||||||
notifyAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Notifies this collector that the destination of the request has been
|
|
||||||
* determined to be unreachable and that the request should be
|
|
||||||
* considered unanswered.
|
|
||||||
*
|
|
||||||
* @param event the <tt>StunFailureEvent</tt>
|
|
||||||
* <tt>PortUnreachableException</tt> which signaled that the destination
|
|
||||||
* of the request was found to be unreachable
|
|
||||||
*
|
|
||||||
* @see ResponseCollector#processUnreachable(StunFailureEvent)
|
|
||||||
*/
|
|
||||||
public synchronized void processUnreachable(
|
|
||||||
StunFailureEvent event)
|
|
||||||
{
|
|
||||||
receivedResponses.add("unreachable");
|
|
||||||
notifyAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Waits for a short period of time for a response to arrive
|
* Waits for a short period of time for a response to arrive
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -516,14 +516,36 @@ public class TransactionSupportTests extends TestCase
|
|||||||
/**
|
/**
|
||||||
* A simple utility for asynchronously collecting responses.
|
* A simple utility for asynchronously collecting responses.
|
||||||
*/
|
*/
|
||||||
private class PlainResponseCollector
|
private static class PlainResponseCollector
|
||||||
implements ResponseCollector
|
extends AbstractResponseCollector
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* The responses we've collected so far.
|
* The responses we've collected so far.
|
||||||
*/
|
*/
|
||||||
public final Vector<Object> receivedResponses = new Vector<Object>();
|
public final Vector<Object> receivedResponses = new Vector<Object>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notifies this <tt>ResponseCollector</tt> that a transaction described by
|
||||||
|
* the specified <tt>BaseStunMessageEvent</tt> has failed. The possible
|
||||||
|
* reasons for the failure include timeouts, unreachable destination, etc.
|
||||||
|
*
|
||||||
|
* @param event the <tt>BaseStunMessageEvent</tt> which describes the failed
|
||||||
|
* transaction and the runtime type of which specifies the failure reason
|
||||||
|
* @see AbstractResponseCollector#processFailure(BaseStunMessageEvent)
|
||||||
|
*/
|
||||||
|
protected void processFailure(BaseStunMessageEvent event)
|
||||||
|
{
|
||||||
|
String receivedResponse;
|
||||||
|
|
||||||
|
if (event instanceof StunFailureEvent)
|
||||||
|
receivedResponse = "unreachable";
|
||||||
|
else if (event instanceof StunTimeoutEvent)
|
||||||
|
receivedResponse = "timeout";
|
||||||
|
else
|
||||||
|
receivedResponse = "failure";
|
||||||
|
receivedResponses.add(receivedResponse);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Logs the received <tt>responseEvt</tt>
|
* Logs the received <tt>responseEvt</tt>
|
||||||
*
|
*
|
||||||
@ -533,32 +555,5 @@ public class TransactionSupportTests extends TestCase
|
|||||||
{
|
{
|
||||||
receivedResponses.add(responseEvt);
|
receivedResponses.add(responseEvt);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when the associated transaction expires.
|
|
||||||
*
|
|
||||||
* @param evt the <tt>StunTimeoutEvent</tt> containing a reference to
|
|
||||||
* the failed <tt>Message</tt> and the expired transaction.
|
|
||||||
*/
|
|
||||||
public void processTimeout(StunTimeoutEvent evt)
|
|
||||||
{
|
|
||||||
receivedResponses.add("timeout");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Notifies this collector that the destination of the request has been
|
|
||||||
* determined to be unreachable and that the request should be
|
|
||||||
* considered unanswered.
|
|
||||||
*
|
|
||||||
* @param event the <tt>StunFailureEvent</tt> containing
|
|
||||||
* <tt>PortUnreachableException</tt> which signaled
|
|
||||||
* that the destination of the request was found to be unreachable
|
|
||||||
*
|
|
||||||
* @see ResponseCollector#processUnreachable(StunFailureEvent)
|
|
||||||
*/
|
|
||||||
public void processUnreachable(StunFailureEvent event)
|
|
||||||
{
|
|
||||||
receivedResponses.add("unreachable");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -37,8 +37,6 @@ public class ShallowStackTest extends TestCase {
|
|||||||
private DatagramSocket localSock = null;
|
private DatagramSocket localSock = null;
|
||||||
|
|
||||||
private DatagramSocket dummyServerSocket = null;
|
private DatagramSocket dummyServerSocket = null;
|
||||||
private DatagramPacket bindingRequestPacket
|
|
||||||
= new DatagramPacket(new byte[4096], 4096);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a test instance for the method with the specified name.
|
* Creates a test instance for the method with the specified name.
|
||||||
@ -216,12 +214,12 @@ public class ShallowStackTest extends TestCase {
|
|||||||
|
|
||||||
//---------- create the response ---------------------------------------
|
//---------- create the response ---------------------------------------
|
||||||
Response bindingResponse = MessageFactory.createBindingResponse(
|
Response bindingResponse = MessageFactory.createBindingResponse(
|
||||||
new TransportAddress( msgFixture.ADDRESS_ATTRIBUTE_ADDRESS,
|
new TransportAddress( MsgFixture.ADDRESS_ATTRIBUTE_ADDRESS,
|
||||||
msgFixture.ADDRESS_ATTRIBUTE_PORT, Transport.UDP ),
|
MsgFixture.ADDRESS_ATTRIBUTE_PORT, Transport.UDP ),
|
||||||
new TransportAddress( msgFixture.ADDRESS_ATTRIBUTE_ADDRESS_2,
|
new TransportAddress( MsgFixture.ADDRESS_ATTRIBUTE_ADDRESS_2,
|
||||||
msgFixture.ADDRESS_ATTRIBUTE_PORT_2, Transport.UDP),
|
MsgFixture.ADDRESS_ATTRIBUTE_PORT_2, Transport.UDP),
|
||||||
new TransportAddress( msgFixture.ADDRESS_ATTRIBUTE_ADDRESS_3,
|
new TransportAddress( MsgFixture.ADDRESS_ATTRIBUTE_ADDRESS_3,
|
||||||
msgFixture.ADDRESS_ATTRIBUTE_PORT_3, Transport.UDP));
|
MsgFixture.ADDRESS_ATTRIBUTE_PORT_3, Transport.UDP));
|
||||||
|
|
||||||
//---------- send & receive the response -------------------------------
|
//---------- send & receive the response -------------------------------
|
||||||
dgramCollector.startListening(dummyServerSocket);
|
dgramCollector.startListening(dummyServerSocket);
|
||||||
@ -302,8 +300,8 @@ public class ShallowStackTest extends TestCase {
|
|||||||
/**
|
/**
|
||||||
* A simple utility that allows us to asynchronously collect messages.
|
* A simple utility that allows us to asynchronously collect messages.
|
||||||
*/
|
*/
|
||||||
public class SimpleResponseCollector
|
public static class SimpleResponseCollector
|
||||||
implements ResponseCollector
|
extends AbstractResponseCollector
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -312,6 +310,29 @@ public class ShallowStackTest extends TestCase {
|
|||||||
*/
|
*/
|
||||||
Response collectedResponse = null;
|
Response collectedResponse = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notifies this <tt>ResponseCollector</tt> that a transaction described by
|
||||||
|
* the specified <tt>BaseStunMessageEvent</tt> has failed. The possible
|
||||||
|
* reasons for the failure include timeouts, unreachable destination, etc.
|
||||||
|
*
|
||||||
|
* @param event the <tt>BaseStunMessageEvent</tt> which describes the failed
|
||||||
|
* transaction and the runtime type of which specifies the failure reason
|
||||||
|
* @see AbstractResponseCollector#processFailure(BaseStunMessageEvent)
|
||||||
|
*/
|
||||||
|
protected synchronized void processFailure(BaseStunMessageEvent event)
|
||||||
|
{
|
||||||
|
String msg;
|
||||||
|
|
||||||
|
if (event instanceof StunFailureEvent)
|
||||||
|
msg = "Unreachable";
|
||||||
|
else if (event instanceof StunTimeoutEvent)
|
||||||
|
msg = "Timeout";
|
||||||
|
else
|
||||||
|
msg = "Failure";
|
||||||
|
logger.info(msg);
|
||||||
|
notifyAll();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Logs the received response and notifies the wait method.
|
* Logs the received response and notifies the wait method.
|
||||||
*/
|
*/
|
||||||
@ -322,35 +343,6 @@ public class ShallowStackTest extends TestCase {
|
|||||||
notifyAll();
|
notifyAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Logs the timeout event for later use.
|
|
||||||
*
|
|
||||||
* @param evt the timeout event that has just occurred.
|
|
||||||
*/
|
|
||||||
public synchronized void processTimeout(StunTimeoutEvent evt)
|
|
||||||
{
|
|
||||||
logger.info("Timeout");
|
|
||||||
notifyAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Notifies this collector that the destination of the request has been
|
|
||||||
* determined to be unreachable and that the request should be
|
|
||||||
* considered unanswered.
|
|
||||||
*
|
|
||||||
* @param evt the <tt>StunFailureEvent</tt> containing the
|
|
||||||
* <tt>PortUnreachableException</tt> which signaled
|
|
||||||
* that the destination of the request was found to be unreachable
|
|
||||||
*
|
|
||||||
* @see ResponseCollector#processUnreachable(StunFailureEvent)
|
|
||||||
*/
|
|
||||||
public synchronized void processUnreachable(
|
|
||||||
StunFailureEvent evt)
|
|
||||||
{
|
|
||||||
logger.info("Unreachable");
|
|
||||||
notifyAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Blocks until a request arrives or 50 ms pass.
|
* Blocks until a request arrives or 50 ms pass.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user