mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-07-28 01:15:26 -04:00
Moved ByteArray to P2PDataStorage class
This commit is contained in:
parent
245d41f07d
commit
7cdb779aae
3 changed files with 40 additions and 40 deletions
|
@ -1,33 +0,0 @@
|
|||
package io.bitsquare.common;
|
||||
|
||||
import io.bitsquare.app.Version;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Arrays;
|
||||
|
||||
// Util for comparing byte arrays
|
||||
public final class ByteArray implements Serializable {
|
||||
// That object is sent over the wire, so we need to take care of version compatibility.
|
||||
private static final long serialVersionUID = Version.P2P_NETWORK_VERSION;
|
||||
|
||||
public final byte[] bytes;
|
||||
|
||||
public ByteArray(byte[] bytes) {
|
||||
this.bytes = bytes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof ByteArray)) return false;
|
||||
|
||||
ByteArray byteArray = (ByteArray) o;
|
||||
|
||||
return Arrays.equals(bytes, byteArray.bytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return bytes != null ? Arrays.hashCode(bytes) : 0;
|
||||
}
|
||||
}
|
6
network/src/main/java/io/bitsquare/p2p/Payload.java
Normal file
6
network/src/main/java/io/bitsquare/p2p/Payload.java
Normal file
|
@ -0,0 +1,6 @@
|
|||
package io.bitsquare.p2p;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public interface Payload extends Serializable {
|
||||
}
|
|
@ -3,7 +3,7 @@ package io.bitsquare.p2p.storage;
|
|||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.util.concurrent.MoreExecutors;
|
||||
import io.bitsquare.app.Log;
|
||||
import io.bitsquare.common.ByteArray;
|
||||
import io.bitsquare.app.Version;
|
||||
import io.bitsquare.common.UserThread;
|
||||
import io.bitsquare.common.crypto.CryptoException;
|
||||
import io.bitsquare.common.crypto.Hash;
|
||||
|
@ -28,10 +28,7 @@ import java.io.File;
|
|||
import java.io.Serializable;
|
||||
import java.security.KeyPair;
|
||||
import java.security.PublicKey;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CopyOnWriteArraySet;
|
||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||
|
@ -490,8 +487,9 @@ public class P2PDataStorage implements MessageListener, ConnectionListener {
|
|||
// Static class
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public static class DataAndSeqNrPair implements Serializable {
|
||||
// data are only used for getting cryptographic hash from both values
|
||||
// Used as container for calculating cryptographic hash of data and sequenceNumber
|
||||
public static final class DataAndSeqNrPair implements Serializable {
|
||||
// data are only used for calculating cryptographic hash from both values so they are kept private
|
||||
private final Serializable data;
|
||||
private final int sequenceNumber;
|
||||
|
||||
|
@ -509,4 +507,33 @@ public class P2PDataStorage implements MessageListener, ConnectionListener {
|
|||
}
|
||||
}
|
||||
|
||||
// Used as key object in map for cryptographic hash of stored data as byte[] as primitive data type cannot be
|
||||
// used as key
|
||||
public static final class ByteArray implements Serializable {
|
||||
// That object is saved to disc. We need to take care of changes to not break deserialization.
|
||||
private static final long serialVersionUID = Version.LOCAL_DB_VERSION;
|
||||
|
||||
public final byte[] bytes;
|
||||
|
||||
public ByteArray(byte[] bytes) {
|
||||
this.bytes = bytes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof ByteArray)) return false;
|
||||
|
||||
ByteArray byteArray = (ByteArray) o;
|
||||
|
||||
return Arrays.equals(bytes, byteArray.bytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return bytes != null ? Arrays.hashCode(bytes) : 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue