forked from Qortal/qortal
More online accounts improvements
This commit is contained in:
parent
8ae7a1d65b
commit
3215bb638d
@ -414,7 +414,7 @@ public class OnlineAccountsManager {
|
|||||||
boolean isSuperiorEntry = isOnlineAccountsDataSuperior(onlineAccountData);
|
boolean isSuperiorEntry = isOnlineAccountsDataSuperior(onlineAccountData);
|
||||||
if (isSuperiorEntry)
|
if (isSuperiorEntry)
|
||||||
// Remove existing inferior entry so it can be re-added below (it's likely the existing copy is missing a nonce value)
|
// Remove existing inferior entry so it can be re-added below (it's likely the existing copy is missing a nonce value)
|
||||||
onlineAccounts.remove(onlineAccountData);
|
onlineAccounts.removeIf(a -> Objects.equals(a.getPublicKey(), onlineAccountData.getPublicKey()));
|
||||||
|
|
||||||
boolean isNewEntry = onlineAccounts.add(onlineAccountData);
|
boolean isNewEntry = onlineAccounts.add(onlineAccountData);
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package org.qortal.data.network;
|
package org.qortal.data.network;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import javax.xml.bind.annotation.XmlAccessType;
|
import javax.xml.bind.annotation.XmlAccessType;
|
||||||
import javax.xml.bind.annotation.XmlAccessorType;
|
import javax.xml.bind.annotation.XmlAccessorType;
|
||||||
@ -34,10 +35,6 @@ public class OnlineAccountData {
|
|||||||
this.nonce = nonce;
|
this.nonce = nonce;
|
||||||
}
|
}
|
||||||
|
|
||||||
public OnlineAccountData(long timestamp, byte[] signature, byte[] publicKey) {
|
|
||||||
this(timestamp, signature, publicKey, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getTimestamp() {
|
public long getTimestamp() {
|
||||||
return this.timestamp;
|
return this.timestamp;
|
||||||
}
|
}
|
||||||
@ -76,6 +73,10 @@ public class OnlineAccountData {
|
|||||||
if (otherOnlineAccountData.timestamp != this.timestamp)
|
if (otherOnlineAccountData.timestamp != this.timestamp)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
// Almost as quick
|
||||||
|
if (!Objects.equals(otherOnlineAccountData.nonce, this.nonce))
|
||||||
|
return false;
|
||||||
|
|
||||||
if (!Arrays.equals(otherOnlineAccountData.publicKey, this.publicKey))
|
if (!Arrays.equals(otherOnlineAccountData.publicKey, this.publicKey))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -88,9 +89,10 @@ public class OnlineAccountData {
|
|||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int h = this.hash;
|
int h = this.hash;
|
||||||
if (h == 0) {
|
if (h == 0) {
|
||||||
this.hash = h = Long.hashCode(this.timestamp)
|
h = Objects.hash(timestamp, nonce);
|
||||||
^ Arrays.hashCode(this.publicKey);
|
h = 31 * h + Arrays.hashCode(publicKey);
|
||||||
// We don't use signature because newer aggregate signatures use random nonces
|
// We don't use signature because newer aggregate signatures use random nonces
|
||||||
|
this.hash = h;
|
||||||
}
|
}
|
||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
@ -99,9 +99,10 @@ public class OnlineAccountsV3Message extends Message {
|
|||||||
bytes.get(publicKey);
|
bytes.get(publicKey);
|
||||||
|
|
||||||
// Nonce is optional - will be -1 if missing
|
// Nonce is optional - will be -1 if missing
|
||||||
|
// ... but we should skip/ignore an online account if it has no nonce
|
||||||
Integer nonce = bytes.getInt();
|
Integer nonce = bytes.getInt();
|
||||||
if (nonce < 0) {
|
if (nonce < 0) {
|
||||||
nonce = null;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
onlineAccounts.add(new OnlineAccountData(timestamp, signature, publicKey, nonce));
|
onlineAccounts.add(new OnlineAccountData(timestamp, signature, publicKey, nonce));
|
||||||
|
@ -165,7 +165,9 @@ public class OnlineAccountsV3Tests {
|
|||||||
byte[] pubkey = new byte[Transformer.PUBLIC_KEY_LENGTH];
|
byte[] pubkey = new byte[Transformer.PUBLIC_KEY_LENGTH];
|
||||||
RANDOM.nextBytes(pubkey);
|
RANDOM.nextBytes(pubkey);
|
||||||
|
|
||||||
onlineAccounts.add(new OnlineAccountData(timestamp, sig, pubkey));
|
Integer nonce = RANDOM.nextInt();
|
||||||
|
|
||||||
|
onlineAccounts.add(new OnlineAccountData(timestamp, sig, pubkey, nonce));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user