From 514708bec78a3b7ab50d953af36cfcec7a4abc11 Mon Sep 17 00:00:00 2001 From: emcho Date: Tue, 16 Feb 2010 08:15:39 +0000 Subject: [PATCH] Adds support for use of IPv6 STUN servers --- .../attribute/XorMappedAddressAttribute.java | 23 +++++++++++++++---- .../ice/harvest/StunCandidateHarvester.java | 2 +- .../stunclient/SimpleAddressDetector.java | 2 +- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/org/ice4j/attribute/XorMappedAddressAttribute.java b/src/org/ice4j/attribute/XorMappedAddressAttribute.java index bdc69f6..bcf4d09 100644 --- a/src/org/ice4j/attribute/XorMappedAddressAttribute.java +++ b/src/org/ice4j/attribute/XorMappedAddressAttribute.java @@ -9,6 +9,7 @@ package org.ice4j.attribute; import java.net.*; import org.ice4j.*; +import org.ice4j.message.*; /** * The XOR-MAPPED-ADDRESS attribute is only present in Binding @@ -51,8 +52,14 @@ import org.ice4j.*; public class XorMappedAddressAttribute extends AddressAttribute { + /** + * The name of this attribute + */ public static final String NAME = "XOR-MAPPED-ADDRESS"; + /** + * Creates an instance of this attribute + */ XorMappedAddressAttribute() { super(XOR_MAPPED_ADDRESS); @@ -106,15 +113,21 @@ public class XorMappedAddressAttribute /** * Returns the result of applying XOR on this attribute's address, using the - * specified operand. The method may be used for both - * encoding and decoding XorMappedAddresses. + * specified transaction ID when converting IPv6 addresses. The method may + * be used for both encoding and decoding XorMappedAddresses. * - * @param operand the transaction id to use for the XOR + * @param transactionID the transaction ID to use in case this attribute is + * encapsulating an IPv6 address. * * @return the XOR-ed address. */ - public TransportAddress applyXor(byte[] operand) + public TransportAddress getAddress(byte[] transactionID) { - return applyXor(getAddress(), operand); + byte[] xorMask = new byte[16]; + + System.arraycopy(Message.MAGIC_COOKIE, 0, xorMask, 0, 4); + System.arraycopy(transactionID, 0, xorMask, 4, 12); + + return applyXor(getAddress(), xorMask); } } diff --git a/src/org/ice4j/ice/harvest/StunCandidateHarvester.java b/src/org/ice4j/ice/harvest/StunCandidateHarvester.java index 4b3f8a0..86a083a 100644 --- a/src/org/ice4j/ice/harvest/StunCandidateHarvester.java +++ b/src/org/ice4j/ice/harvest/StunCandidateHarvester.java @@ -255,7 +255,7 @@ public class StunCandidateHarvester return; TransportAddress addr = ((XorMappedAddressAttribute)attribute) - .applyXor(Message.MAGIC_COOKIE); + .getAddress(response.getTransactionID()); ServerReflexiveCandidate srvrRflxCand = new ServerReflexiveCandidate(addr, base, stunServer); diff --git a/src/org/ice4j/stunclient/SimpleAddressDetector.java b/src/org/ice4j/stunclient/SimpleAddressDetector.java index d08177b..a1e24ac 100644 --- a/src/org/ice4j/stunclient/SimpleAddressDetector.java +++ b/src/org/ice4j/stunclient/SimpleAddressDetector.java @@ -149,7 +149,7 @@ public class SimpleAddressDetector System.arraycopy(Message.MAGIC_COOKIE, 0, xoring, 0, 4); System.arraycopy(res.getTransactionID(), 0, xoring, 4, 12); - return xorAtt.applyXor(xoring); + return xorAtt.getAddress(xoring); } }