diff --git a/src/org/ice4j/attribute/XorMappedAddressAttribute.java b/src/org/ice4j/attribute/XorMappedAddressAttribute.java index bcf4d09..96f67a9 100644 --- a/src/org/ice4j/attribute/XorMappedAddressAttribute.java +++ b/src/org/ice4j/attribute/XorMappedAddressAttribute.java @@ -113,8 +113,7 @@ public class XorMappedAddressAttribute /** * Returns the result of applying XOR on this attribute's address, using the - * specified transaction ID when converting IPv6 addresses. The method may - * be used for both encoding and decoding XorMappedAddresses. + * specified transaction ID when converting IPv6 addresses. * * @param transactionID the transaction ID to use in case this attribute is * encapsulating an IPv6 address. @@ -128,6 +127,22 @@ public class XorMappedAddressAttribute System.arraycopy(Message.MAGIC_COOKIE, 0, xorMask, 0, 4); System.arraycopy(transactionID, 0, xorMask, 4, 12); + return applyXor(xorMask); + } + + /** + * Returns the result of applying XOR on this attribute's address, using the + * specified XOR mask. The method may be used for both encoding and + * decoding XorMappedAddresses. + * + * @param xorMask the XOR mask to use when obtaining the original address. + * + * @return the XOR-ed address. + */ + public TransportAddress applyXor(byte[] xorMask) + { return applyXor(getAddress(), xorMask); } + + } diff --git a/src/org/ice4j/stunclient/SimpleAddressDetector.java b/src/org/ice4j/stunclient/SimpleAddressDetector.java index a1e24ac..d08177b 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.getAddress(xoring); + return xorAtt.applyXor(xoring); } } diff --git a/test/org/ice4j/attribute/AddressAttributeTest.java b/test/org/ice4j/attribute/AddressAttributeTest.java index fbe76bd..97488a2 100644 --- a/test/org/ice4j/attribute/AddressAttributeTest.java +++ b/test/org/ice4j/attribute/AddressAttributeTest.java @@ -14,13 +14,7 @@ import org.ice4j.*; /** * - *

Title: Stun4J.

- *

Description: Simple Traversal of UDP Through NAT

- *

Copyright: Copyright (c) 2003

- *

Organisation:

Organisation: Louis Pasteur University, Strasbourg, France

- *

Network Research Team (http://www-r2.u-strasbg.fr)

* @author Emil Ivov - * @version 0.1 */ public class AddressAttributeTest extends TestCase { private AddressAttribute addressAttribute = null; @@ -215,7 +209,7 @@ public class AddressAttributeTest extends TestCase { addressAttribute.setAddress(testAddress); //do a xor with an id equal to the v4 address itself so that we get 0000.., - TransportAddress xorredAddr = addressAttribute.getAddress( + TransportAddress xorredAddr = addressAttribute.applyXor( new byte[]{(byte)130,79,95,53,0,0,0,0,0,0,0,0,0,0,0,0,0}); assertTrue("Xorring the address with itself didn't return 00000...", @@ -226,11 +220,11 @@ public class AddressAttributeTest extends TestCase { //Test xor-ing the original with the xored - should get the xor code addressAttribute.setAddress(testAddress); - xorredAddr = addressAttribute.getAddress( + xorredAddr = addressAttribute.applyXor( new byte[]{21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36}); xorredAddr = - addressAttribute.getAddress(xorredAddr.getAddressBytes()); + addressAttribute.applyXor(xorredAddr.getAddressBytes()); assertTrue("Xorring the original with the xor-ed didn't " +"return the code..", @@ -242,11 +236,11 @@ public class AddressAttributeTest extends TestCase { //Test double xor-ing - should get the original addressAttribute.setAddress(testAddress); - xorredAddr = addressAttribute.getAddress( + xorredAddr = addressAttribute.applyXor( new byte[]{21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36}); addressAttribute.setAddress(xorredAddr); - xorredAddr = addressAttribute.getAddress( + xorredAddr = addressAttribute.applyXor( new byte[]{21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36}); assertEquals("Double xorring didn't give the original ...", @@ -267,7 +261,7 @@ public class AddressAttributeTest extends TestCase { //do a xor with an id equal to the v4 address itself so that we get 0000.., TransportAddress xorredAddr = - addressAttribute.getAddress( + addressAttribute.applyXor( new byte[]{(byte)0x20, (byte)0x01, (byte)0x06, (byte)0x60, (byte)0x47, (byte)0x01, (byte)0x10, (byte)0x01, (byte)0x02, (byte)0x02, (byte)0x8a, (byte)0xff, @@ -285,10 +279,10 @@ public class AddressAttributeTest extends TestCase { //Test xor-ing the original with the xored - should get the xor code addressAttribute.setAddress(testAddress); - xorredAddr = addressAttribute.getAddress( + xorredAddr = addressAttribute.applyXor( new byte[]{21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36}); - xorredAddr = addressAttribute.getAddress(xorredAddr.getAddressBytes()); + xorredAddr = addressAttribute.applyXor(xorredAddr.getAddressBytes()); assertTrue("Xorring the original with the xor-ed didn't return the code..", Arrays.equals( @@ -300,11 +294,11 @@ public class AddressAttributeTest extends TestCase { //Test double xor-ing - should get the original addressAttribute.setAddress(testAddress); - xorredAddr = addressAttribute.getAddress( + xorredAddr = addressAttribute.applyXor( new byte[]{21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36}); addressAttribute.setAddress(xorredAddr); - xorredAddr = addressAttribute.getAddress( + xorredAddr = addressAttribute.applyXor( new byte[]{21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36}); assertEquals("Double xorring didn't give the original ...",