Adds an extra getAddress() method to XOR attributes in order to preserve compatibility with our unit tests
This commit is contained in:
parent
14be6345be
commit
aacc2b3c5d
@ -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 <tt>XorMappedAddresses</tt>.
|
||||
* 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 <tt>XorMappedAddresses</tt>.
|
||||
*
|
||||
* @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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -14,13 +14,7 @@ import org.ice4j.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* <p>Title: Stun4J.</p>
|
||||
* <p>Description: Simple Traversal of UDP Through NAT</p>
|
||||
* <p>Copyright: Copyright (c) 2003</p>
|
||||
* <p>Organisation: <p> Organisation: Louis Pasteur University, Strasbourg, France</p>
|
||||
* <p> Network Research Team (http://www-r2.u-strasbg.fr)</p></p>
|
||||
* @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 ...",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user