From 0b0e5da5b5144cbdc831343a24326ee262d1b598 Mon Sep 17 00:00:00 2001 From: emcho Date: Mon, 15 Feb 2010 22:51:18 +0000 Subject: [PATCH] Adds to x-tra classes for STUN support of STUN --- src/org/ice4j/StunFailureEvent.java | 128 ++++++++++++++++++ .../ice4j/ice/ServerReflexiveCandidate.java | 43 ++++++ 2 files changed, 171 insertions(+) create mode 100644 src/org/ice4j/StunFailureEvent.java create mode 100644 src/org/ice4j/ice/ServerReflexiveCandidate.java diff --git a/src/org/ice4j/StunFailureEvent.java b/src/org/ice4j/StunFailureEvent.java new file mode 100644 index 0000000..2eb63be --- /dev/null +++ b/src/org/ice4j/StunFailureEvent.java @@ -0,0 +1,128 @@ +/* + * 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 + * fails asynchronously for reasons like a port unreachable exception for + * example. + * + * @author Emil Ivov + */ +public class StunFailureEvent + extends EventObject +{ + /** + * Serial version UID for this Serializable class. + */ + private static final long serialVersionUID = 41232541L; + + /** + * The message that the corresponding transaction was about. + */ + private final Message message; + + /** + * The TransactionID of the transaction that the source message + * is related to. + */ + private final TransactionID transactionID; + + /** + * The Exception that caused this failure. + */ + private final Throwable cause; + + /** + * Constructs a StunFailureEvent according to the specified + * message. + * + * @param message the message itself + * @param localAddress the local address that the message was sent from. + * @param cause the Exception that caused this failure or + * null if there's no Exception associated with this + * failure + */ + public StunFailureEvent(Message message, + TransportAddress localAddress, + Throwable cause) + { + super(localAddress); + this.message = message; + this.transactionID = TransactionID.createTransactionID(message + .getTransactionID()); + + this.cause = cause; + } + + /** + * Returns the TransportAddress that the message was supposed to + * leave from. + * + * @return the TransportAddress that the message was supposed to + * leave from. + */ + public TransportAddress getLocalAddress() + { + return (TransportAddress)getSource(); + } + + /** + * Returns the Message whose transaction has just failed. + * + * @return the Message whose transaction has just failed. + */ + public Message getMessage() + { + return message; + } + + /** + * Returns the id of the transaction that has just failed. + * + * @return the TransactionID of the transaction that has just + * failed. + */ + public TransactionID getTransactionID() + { + return transactionID; + } + + /** + * Returns the Exception that cause this failure or null + * if the failure is not related to an Exception. + * + * @return the Exception that cause this failure or null + * if the failure is not related to an Exception. + */ + public Throwable getCause() + { + return cause; + } + + /** + * Returns a String representation of this event, containing the + * corresponding message, and local address. + * + * @return a String 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(); + } +} diff --git a/src/org/ice4j/ice/ServerReflexiveCandidate.java b/src/org/ice4j/ice/ServerReflexiveCandidate.java new file mode 100644 index 0000000..dc8aac2 --- /dev/null +++ b/src/org/ice4j/ice/ServerReflexiveCandidate.java @@ -0,0 +1,43 @@ +package org.ice4j.ice; + +import org.ice4j.*; + +/** + * ServerReflexiveCandidates are candidates whose IP address and port + * are a binding allocated by a NAT for an agent when it sent a packet through + * the NAT to a server. ServerReflexiveCandidates can be learned by + * STUN servers using the Binding Request, or TURN servers, which provides + * both a Relayed and Server Reflexive candidate. + *

+ * This class does not contain a socket itself and in order to send bytes + * over the network, one has to retrieve the socket of its basis. + *

+ * + * @author Emil Ivov + */ +public class ServerReflexiveCandidate extends Candidate +{ + + /** + * Creates a ServerReflexiveCandidate for the specified transport + * address, and base. + * + * @param address the {@link TransportAddress} that this Candidate + * is representing. + * @param base the {@link HostCandidate} that this server reflexive + * candidate was obtained through. + * @param stunSrvrAddr the {@link TransportAddress} of the stun server that + * reflected this candidate. + */ + public ServerReflexiveCandidate(TransportAddress address, + HostCandidate base, + TransportAddress stunSrvrAddr) + { + super(address, + base.getParentComponent(), + CandidateType.SERVER_REFLEXIVE_CANDIDATE); + + setBase(base); + setStunServerAddress(stunSrvrAddr); + } +}