From 007d55186392819a49b55fb318bd972db86b7ac6 Mon Sep 17 00:00:00 2001 From: emcho Date: Sat, 8 May 2010 21:38:00 +0000 Subject: [PATCH] Commits work on pair nomination (Section 8.1.1). Work in progress --- src/org/ice4j/StunResponseEvent.java | 72 +++++++++++++++++++ src/org/ice4j/ice/PeerReflexiveCandidate.java | 64 +++++++++++++++++ 2 files changed, 136 insertions(+) create mode 100644 src/org/ice4j/StunResponseEvent.java create mode 100644 src/org/ice4j/ice/PeerReflexiveCandidate.java diff --git a/src/org/ice4j/StunResponseEvent.java b/src/org/ice4j/StunResponseEvent.java new file mode 100644 index 0000000..615127e --- /dev/null +++ b/src/org/ice4j/StunResponseEvent.java @@ -0,0 +1,72 @@ +/* + * 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 org.ice4j.message.*; +import org.ice4j.stack.*; + +/** + * The class is used to dispatch incoming STUN {@link Response}s. Apart from + * the {@link Response} itself this event also carries a reference to the + * {@link Request} that started the corresponding transaction as well as other + * useful things. + * + * @author Emil Ivov + */ +public class StunResponseEvent + extends StunMessageEvent +{ + /** + * Serial version UID for this Serializable class. + */ + private static final long serialVersionUID = -1L; + + /** + * The original {@link Request} that started the client transaction that + * the {@link Response} carried in this event belongs to. + */ + private final Request request; + + /** + * Creates a new instance of this event. + * + * @param rawMessage the crude message we got off the wire. + * @param response the STUN {@link Response} that we've just received. + * @param request the message itself + */ + public StunResponseEvent(RawMessage rawMessage, + Response response, + Request request) + { + super(rawMessage, response); + this.request = request; + } + + /** + * Returns the {@link Request} that started the transaction that this + * {@link Response} has just arrived in. + * + * @return the {@link Request} that started the transaction that this + * {@link Response} has just arrived in. + */ + public Request getRequest() + { + return request; + } + + /** + * Returns the {@link Response} that has just arrived and that caused this + * event. + * + * @return the {@link Response} that has just arrived and that caused this + * event. + */ + public Response getResponse() + { + return (Response)getMessage(); + } +} diff --git a/src/org/ice4j/ice/PeerReflexiveCandidate.java b/src/org/ice4j/ice/PeerReflexiveCandidate.java new file mode 100644 index 0000000..dd52224 --- /dev/null +++ b/src/org/ice4j/ice/PeerReflexiveCandidate.java @@ -0,0 +1,64 @@ +/* + * 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.ice; + +import java.net.*; + +import org.ice4j.*; + +/** + * Peer Reflexive Candidates are candidates whose IP address and port are a + * binding explicitly allocated by a NAT for an agent when it sent a STUN + * Binding request through the NAT to its peer. + *

+ * Peer Reflexive Candidates are generally allocated by NATs with endpoint + * dependent mapping also known as Symmetric NATs. PeerReflexiveCandidates + * are generally preferred to relayed ones. RFC 5245 explains this with + * better security ... although simply avoiding a relay would probably be + * enough of a reason for many. + * + * @author Emil Ivov + */ +public class PeerReflexiveCandidate + extends LocalCandidate +{ + /** + * Creates a PeerReflexiveCandidate instance for the specified + * transport address and properties. + * + * @param transportAddress the transport address that this candidate is + * encapsulating. + * @param parentComponent the Component that this candidate + * belongs to. + * @param base the base of a peer reflexive candidate base is the local + * candidate of the candidate pair from which the STUN check was sent. + * @param priority the priority of the candidate. + */ + public PeerReflexiveCandidate(TransportAddress transportAddress, + Component parentComponent, + LocalCandidate base, + long priority) + { + super(transportAddress, parentComponent, + CandidateType.PEER_REFLEXIVE_CANDIDATE); + super.setBase(base); + super.priority = priority; + } + + /** + * Returns the DatagramSocket associated with this + * Candidate. + * + * @return the DatagramSocket associated with this + * Candidate + * @see LocalCandidate#getSocket() + */ + public DatagramSocket getSocket() + { + return ((HostCandidate)getBase()).getSocket(); + } +}