Fixed feature bitfield calculation/resolution
This commit is contained in:
parent
c31ec7a9e5
commit
ddd5826f42
@ -76,16 +76,19 @@ public abstract class Pubkey extends ObjectPayload {
|
||||
* Receiving node expects that the RIPE hash encoded in their address preceedes the encrypted message data of msg
|
||||
* messages bound for them.
|
||||
*/
|
||||
INCLUDE_DESTINATION(1 << 30),
|
||||
INCLUDE_DESTINATION(30),
|
||||
/**
|
||||
* If true, the receiving node does send acknowledgements (rather than dropping them).
|
||||
*/
|
||||
DOES_ACK(1 << 31);
|
||||
DOES_ACK(31);
|
||||
|
||||
private int bit;
|
||||
|
||||
Feature(int bit) {
|
||||
this.bit = bit;
|
||||
Feature(int bitNumber) {
|
||||
// The Bitmessage Protocol Specification starts counting at the most significant bit,
|
||||
// thus the slightly awkward calculation.
|
||||
// https://bitmessage.org/wiki/Protocol_specification#Pubkey_bitfield_features
|
||||
this.bit = 1 << (31 - bitNumber);
|
||||
}
|
||||
|
||||
public static int bitfield(Feature... features) {
|
||||
|
@ -20,20 +20,25 @@ import ch.dissem.bitmessage.entity.payload.Pubkey;
|
||||
import ch.dissem.bitmessage.entity.payload.V4Pubkey;
|
||||
import ch.dissem.bitmessage.entity.valueobject.PrivateKey;
|
||||
import ch.dissem.bitmessage.exception.DecryptionFailedException;
|
||||
import ch.dissem.bitmessage.utils.Base58;
|
||||
import ch.dissem.bitmessage.utils.Bytes;
|
||||
import ch.dissem.bitmessage.utils.Strings;
|
||||
import ch.dissem.bitmessage.utils.TestUtils;
|
||||
import ch.dissem.bitmessage.utils.*;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static ch.dissem.bitmessage.entity.payload.Pubkey.Feature.DOES_ACK;
|
||||
import static ch.dissem.bitmessage.entity.payload.Pubkey.Feature.INCLUDE_DESTINATION;
|
||||
import static ch.dissem.bitmessage.utils.Singleton.security;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class BitmessageAddressTest {
|
||||
public class BitmessageAddressTest extends TestBase {
|
||||
@Test
|
||||
public void ensureFeatureFlagIsCalculatedCorrectly() {
|
||||
assertEquals(1, Pubkey.Feature.bitfield(DOES_ACK));
|
||||
assertEquals(2, Pubkey.Feature.bitfield(INCLUDE_DESTINATION));
|
||||
assertEquals(3, Pubkey.Feature.bitfield(DOES_ACK, INCLUDE_DESTINATION));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ensureBase58DecodesCorrectly() {
|
||||
assertHexEquals("800C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D507A5B8D",
|
||||
@ -61,6 +66,7 @@ public class BitmessageAddressTest {
|
||||
public void ensureIdentityCanBeCreated() {
|
||||
BitmessageAddress address = new BitmessageAddress(new PrivateKey(false, 1, 1000, 1000, DOES_ACK));
|
||||
assertNotNull(address.getPubkey());
|
||||
assertTrue(address.has(DOES_ACK));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -90,6 +96,7 @@ public class BitmessageAddressTest {
|
||||
}
|
||||
|
||||
assertArrayEquals(Bytes.fromHex("007402be6e76c3cb87caa946d0c003a3d4d8e1d5"), pubkey.getRipe());
|
||||
assertTrue(address.has(DOES_ACK));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -104,6 +111,7 @@ public class BitmessageAddressTest {
|
||||
} catch (Exception e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
assertTrue(address.has(DOES_ACK));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -17,12 +17,14 @@
|
||||
package ch.dissem.bitmessage.repository;
|
||||
|
||||
import ch.dissem.bitmessage.entity.BitmessageAddress;
|
||||
import ch.dissem.bitmessage.entity.payload.Pubkey;
|
||||
import ch.dissem.bitmessage.entity.valueobject.PrivateKey;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static ch.dissem.bitmessage.entity.payload.Pubkey.Feature.DOES_ACK;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class JdbcAddressRepositoryTest extends TestBase {
|
||||
@ -46,7 +48,7 @@ public class JdbcAddressRepositoryTest extends TestBase {
|
||||
repo.save(new BitmessageAddress(CONTACT_B));
|
||||
repo.save(new BitmessageAddress(CONTACT_C));
|
||||
|
||||
BitmessageAddress identityA = new BitmessageAddress(new PrivateKey(false, 1, 1000, 1000));
|
||||
BitmessageAddress identityA = new BitmessageAddress(new PrivateKey(false, 1, 1000, 1000, DOES_ACK));
|
||||
repo.save(identityA);
|
||||
IDENTITY_A = identityA.getAddress();
|
||||
BitmessageAddress identityB = new BitmessageAddress(new PrivateKey(false, 1, 1000, 1000));
|
||||
@ -68,6 +70,7 @@ public class JdbcAddressRepositoryTest extends TestBase {
|
||||
assertEquals(4, identity.getVersion());
|
||||
assertEquals(identity, repo.findIdentity(identity.getTag()));
|
||||
assertNull(repo.findContact(identity.getTag()));
|
||||
assertTrue(identity.has(Pubkey.Feature.DOES_ACK));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
Reference in New Issue
Block a user