mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-04-22 08:29:16 -04:00
Use Persistable interface for local db data
This commit is contained in:
parent
8792666f78
commit
6a25e1c56c
@ -1,6 +0,0 @@
|
||||
package io.bitsquare.common;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public interface Payload extends Serializable {
|
||||
}
|
@ -20,11 +20,11 @@ package io.bitsquare.common.crypto;
|
||||
import java.io.Serializable;
|
||||
import java.security.PublicKey;
|
||||
|
||||
public final class DecryptedPayloadWithPubKey implements Serializable {
|
||||
public final class DecryptedDataTuple {
|
||||
public final Serializable payload;
|
||||
public final PublicKey sigPublicKey;
|
||||
|
||||
public DecryptedPayloadWithPubKey(Serializable payload, PublicKey sigPublicKey) {
|
||||
public DecryptedDataTuple(Serializable payload, PublicKey sigPublicKey) {
|
||||
this.payload = payload;
|
||||
this.sigPublicKey = sigPublicKey;
|
||||
}
|
||||
@ -32,9 +32,9 @@ public final class DecryptedPayloadWithPubKey implements Serializable {
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof DecryptedPayloadWithPubKey)) return false;
|
||||
if (!(o instanceof DecryptedDataTuple)) return false;
|
||||
|
||||
DecryptedPayloadWithPubKey that = (DecryptedPayloadWithPubKey) o;
|
||||
DecryptedDataTuple that = (DecryptedDataTuple) o;
|
||||
|
||||
if (payload != null ? !payload.equals(that.payload) : that.payload != null) return false;
|
||||
return !(sigPublicKey != null ? !sigPublicKey.equals(that.sigPublicKey) : that.sigPublicKey != null);
|
@ -233,7 +233,7 @@ public class Encryption {
|
||||
* @return A DecryptedPayloadWithPubKey object.
|
||||
* @throws CryptoException
|
||||
*/
|
||||
public static DecryptedPayloadWithPubKey decryptHybridWithSignature(SealedAndSigned sealedAndSigned, PrivateKey privateKey) throws CryptoException {
|
||||
public static DecryptedDataTuple decryptHybridWithSignature(SealedAndSigned sealedAndSigned, PrivateKey privateKey) throws CryptoException {
|
||||
SecretKey secretKey = getSecretKeyFromBytes(decrypt(sealedAndSigned.encryptedSecretKey, privateKey));
|
||||
boolean isValid = Sig.verify(sealedAndSigned.sigPublicKey,
|
||||
Hash.getHash(sealedAndSigned.encryptedPayloadWithHmac),
|
||||
@ -242,7 +242,7 @@ public class Encryption {
|
||||
throw new CryptoException("Signature verification failed.");
|
||||
|
||||
Serializable decryptedPayload = Utilities.deserialize(decryptPayloadWithHmac(sealedAndSigned.encryptedPayloadWithHmac, secretKey));
|
||||
return new DecryptedPayloadWithPubKey(decryptedPayload, sealedAndSigned.sigPublicKey);
|
||||
return new DecryptedDataTuple(decryptedPayload, sealedAndSigned.sigPublicKey);
|
||||
}
|
||||
|
||||
|
||||
|
@ -18,12 +18,12 @@
|
||||
package io.bitsquare.common.crypto;
|
||||
|
||||
import io.bitsquare.app.Version;
|
||||
import io.bitsquare.common.wire.Payload;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.Serializable;
|
||||
import java.security.KeyFactory;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.NoSuchProviderException;
|
||||
@ -35,7 +35,7 @@ import java.security.spec.X509EncodedKeySpec;
|
||||
* Same as KeyRing but with public keys only.
|
||||
* Used to send public keys over the wire to other peer.
|
||||
*/
|
||||
public final class PubKeyRing implements Serializable {
|
||||
public final class PubKeyRing implements Payload {
|
||||
// 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;
|
||||
|
||||
|
@ -18,12 +18,12 @@
|
||||
package io.bitsquare.common.crypto;
|
||||
|
||||
import io.bitsquare.app.Version;
|
||||
import io.bitsquare.common.wire.Payload;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.security.PublicKey;
|
||||
import java.util.Arrays;
|
||||
|
||||
public final class SealedAndSigned implements Serializable {
|
||||
public final class SealedAndSigned implements Payload {
|
||||
// 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;
|
||||
|
||||
|
@ -0,0 +1,9 @@
|
||||
package io.bitsquare.common.persistance;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Marker interface for data which is used for local data persistence
|
||||
*/
|
||||
public interface Persistable extends Serializable {
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package io.bitsquare.common.wire;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Marker interface for data which is sent over the wire
|
||||
*/
|
||||
public interface Payload extends Serializable {
|
||||
}
|
@ -18,7 +18,7 @@
|
||||
package io.bitsquare.alert;
|
||||
|
||||
import io.bitsquare.app.Version;
|
||||
import io.bitsquare.p2p.storage.messages.StoragePayload;
|
||||
import io.bitsquare.p2p.storage.data.StoragePayload;
|
||||
|
||||
import java.security.PublicKey;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
@ -20,7 +20,7 @@ package io.bitsquare.arbitration;
|
||||
import io.bitsquare.app.Version;
|
||||
import io.bitsquare.common.crypto.PubKeyRing;
|
||||
import io.bitsquare.p2p.NodeAddress;
|
||||
import io.bitsquare.p2p.storage.messages.StoragePayload;
|
||||
import io.bitsquare.p2p.storage.data.StoragePayload;
|
||||
|
||||
import java.security.PublicKey;
|
||||
import java.util.Arrays;
|
||||
|
@ -20,6 +20,7 @@ package io.bitsquare.arbitration;
|
||||
import io.bitsquare.app.Version;
|
||||
import io.bitsquare.arbitration.messages.DisputeCommunicationMessage;
|
||||
import io.bitsquare.common.crypto.PubKeyRing;
|
||||
import io.bitsquare.common.wire.Payload;
|
||||
import io.bitsquare.storage.Storage;
|
||||
import io.bitsquare.trade.Contract;
|
||||
import javafx.beans.property.*;
|
||||
@ -32,13 +33,12 @@ import org.slf4j.LoggerFactory;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public final class Dispute implements Serializable {
|
||||
public final class Dispute implements Payload {
|
||||
// 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;
|
||||
private static final Logger log = LoggerFactory.getLogger(Dispute.class);
|
||||
|
@ -18,6 +18,7 @@
|
||||
package io.bitsquare.arbitration;
|
||||
|
||||
import io.bitsquare.app.Version;
|
||||
import io.bitsquare.common.persistance.Persistable;
|
||||
import io.bitsquare.storage.Storage;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
@ -27,10 +28,9 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class DisputeList<DisputeCase> extends ArrayList<DisputeCase> implements Serializable {
|
||||
public class DisputeList<DisputeCase> extends ArrayList<DisputeCase> implements Persistable {
|
||||
// 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;
|
||||
|
||||
|
@ -19,6 +19,7 @@ package io.bitsquare.arbitration;
|
||||
|
||||
import io.bitsquare.app.Version;
|
||||
import io.bitsquare.arbitration.messages.DisputeCommunicationMessage;
|
||||
import io.bitsquare.common.wire.Payload;
|
||||
import javafx.beans.property.*;
|
||||
import org.bitcoinj.core.Coin;
|
||||
import org.slf4j.Logger;
|
||||
@ -26,11 +27,10 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.Serializable;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
|
||||
public final class DisputeResult implements Serializable {
|
||||
public final class DisputeResult implements Payload {
|
||||
// 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;
|
||||
private static final Logger log = LoggerFactory.getLogger(DisputeResult.class);
|
||||
|
@ -1,13 +1,13 @@
|
||||
package io.bitsquare.arbitration.payload;
|
||||
|
||||
import io.bitsquare.app.Version;
|
||||
import io.bitsquare.common.wire.Payload;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Arrays;
|
||||
|
||||
public final class Attachment implements Serializable {
|
||||
public final class Attachment implements Payload {
|
||||
// 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;
|
||||
private static final Logger log = LoggerFactory.getLogger(Attachment.class);
|
||||
|
@ -18,6 +18,7 @@
|
||||
package io.bitsquare.btc;
|
||||
|
||||
import io.bitsquare.app.Version;
|
||||
import io.bitsquare.common.persistance.Persistable;
|
||||
import org.bitcoinj.core.Address;
|
||||
import org.bitcoinj.core.NetworkParameters;
|
||||
import org.bitcoinj.crypto.DeterministicKey;
|
||||
@ -30,14 +31,13 @@ import org.slf4j.LoggerFactory;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Every trade use a addressEntry with a dedicated address for all transactions related to the trade.
|
||||
* That way we have a kind of separated trade wallet, isolated from other transactions and avoiding coin merge.
|
||||
* If we would not avoid coin merge the user would lose privacy between trades.
|
||||
*/
|
||||
public class AddressEntry implements Serializable {
|
||||
public class AddressEntry implements Persistable {
|
||||
// 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;
|
||||
|
||||
|
@ -19,19 +19,19 @@ package io.bitsquare.btc;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import io.bitsquare.app.Version;
|
||||
import io.bitsquare.common.persistance.Persistable;
|
||||
import io.bitsquare.storage.Storage;
|
||||
import org.bitcoinj.core.Wallet;
|
||||
import org.bitcoinj.crypto.DeterministicKey;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* The List supporting our persistence solution.
|
||||
*/
|
||||
public class AddressEntryList extends ArrayList<AddressEntry> implements Serializable {
|
||||
public class AddressEntryList extends ArrayList<AddressEntry> implements Persistable {
|
||||
// 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;
|
||||
private static final Logger log = LoggerFactory.getLogger(AddressEntryList.class);
|
||||
|
@ -17,15 +17,13 @@
|
||||
|
||||
package io.bitsquare.btc;
|
||||
|
||||
import io.bitsquare.common.persistance.Persistable;
|
||||
import org.bitcoinj.core.NetworkParameters;
|
||||
import org.bitcoinj.params.MainNetParams;
|
||||
import org.bitcoinj.params.RegTestParams;
|
||||
import org.bitcoinj.params.TestNet3Params;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public enum BitcoinNetwork implements Serializable {
|
||||
|
||||
public enum BitcoinNetwork implements Persistable {
|
||||
MAINNET(MainNetParams.get()),
|
||||
TESTNET(TestNet3Params.get()),
|
||||
REGTEST(RegTestParams.get());
|
||||
|
@ -18,11 +18,11 @@
|
||||
package io.bitsquare.btc.data;
|
||||
|
||||
import io.bitsquare.app.Version;
|
||||
import io.bitsquare.common.wire.Payload;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Arrays;
|
||||
|
||||
public final class RawInput implements Serializable {
|
||||
public final class RawInput implements Payload {
|
||||
// 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;
|
||||
|
||||
|
@ -18,12 +18,12 @@
|
||||
package io.bitsquare.locale;
|
||||
|
||||
import io.bitsquare.app.Version;
|
||||
import io.bitsquare.common.persistance.Persistable;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
import java.io.Serializable;
|
||||
|
||||
@Immutable
|
||||
public class Country implements Serializable {
|
||||
public class Country implements Persistable {
|
||||
// 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;
|
||||
|
||||
|
@ -18,10 +18,9 @@
|
||||
package io.bitsquare.locale;
|
||||
|
||||
import io.bitsquare.app.Version;
|
||||
import io.bitsquare.common.persistance.Persistable;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class CryptoCurrency extends TradeCurrency implements Serializable {
|
||||
public class CryptoCurrency extends TradeCurrency implements Persistable {
|
||||
// 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;
|
||||
|
||||
|
@ -18,12 +18,12 @@
|
||||
package io.bitsquare.locale;
|
||||
|
||||
import io.bitsquare.app.Version;
|
||||
import io.bitsquare.common.persistance.Persistable;
|
||||
import io.bitsquare.user.Preferences;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Currency;
|
||||
|
||||
public class FiatCurrency extends TradeCurrency implements Serializable {
|
||||
public class FiatCurrency extends TradeCurrency implements Persistable {
|
||||
// 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;
|
||||
|
||||
|
@ -18,12 +18,12 @@
|
||||
package io.bitsquare.locale;
|
||||
|
||||
import io.bitsquare.app.Version;
|
||||
import io.bitsquare.common.persistance.Persistable;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
import java.io.Serializable;
|
||||
|
||||
@Immutable
|
||||
public class Region implements Serializable {
|
||||
public class Region implements Persistable {
|
||||
// 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;
|
||||
|
||||
|
@ -18,10 +18,9 @@
|
||||
package io.bitsquare.locale;
|
||||
|
||||
import io.bitsquare.app.Version;
|
||||
import io.bitsquare.common.persistance.Persistable;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class TradeCurrency implements Serializable {
|
||||
public class TradeCurrency implements Persistable {
|
||||
// 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;
|
||||
|
||||
|
@ -20,9 +20,7 @@ package io.bitsquare.payment;
|
||||
import io.bitsquare.app.Version;
|
||||
import io.bitsquare.locale.FiatCurrency;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class AliPayAccount extends PaymentAccount implements Serializable {
|
||||
public class AliPayAccount extends PaymentAccount {
|
||||
// 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;
|
||||
|
||||
|
@ -19,9 +19,7 @@ package io.bitsquare.payment;
|
||||
|
||||
import io.bitsquare.app.Version;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public final class AliPayAccountContractData extends PaymentAccountContractData implements Serializable {
|
||||
public final class AliPayAccountContractData extends PaymentAccountContractData {
|
||||
// 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;
|
||||
|
||||
|
@ -19,9 +19,7 @@ package io.bitsquare.payment;
|
||||
|
||||
import io.bitsquare.app.Version;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class BlockChainAccount extends PaymentAccount implements Serializable {
|
||||
public class BlockChainAccount extends PaymentAccount {
|
||||
// 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;
|
||||
|
||||
|
@ -19,9 +19,7 @@ package io.bitsquare.payment;
|
||||
|
||||
import io.bitsquare.app.Version;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public final class BlockChainAccountContractData extends PaymentAccountContractData implements Serializable {
|
||||
public final class BlockChainAccountContractData extends PaymentAccountContractData {
|
||||
// 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;
|
||||
|
||||
@ -49,7 +47,7 @@ public final class BlockChainAccountContractData extends PaymentAccountContractD
|
||||
@Override
|
||||
public String getPaymentDetailsForTradePopup() {
|
||||
return getPaymentDetails();
|
||||
}
|
||||
}
|
||||
|
||||
public void setPaymentId(String paymentId) {
|
||||
this.paymentId = paymentId;
|
||||
|
@ -22,9 +22,7 @@ import io.bitsquare.locale.CurrencyUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class OKPayAccount extends PaymentAccount implements Serializable {
|
||||
public class OKPayAccount extends PaymentAccount {
|
||||
// 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;
|
||||
|
||||
|
@ -19,9 +19,7 @@ package io.bitsquare.payment;
|
||||
|
||||
import io.bitsquare.app.Version;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public final class OKPayAccountContractData extends PaymentAccountContractData implements Serializable {
|
||||
public final class OKPayAccountContractData extends PaymentAccountContractData {
|
||||
// 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;
|
||||
|
||||
|
@ -18,19 +18,19 @@
|
||||
package io.bitsquare.payment;
|
||||
|
||||
import io.bitsquare.app.Version;
|
||||
import io.bitsquare.common.persistance.Persistable;
|
||||
import io.bitsquare.locale.Country;
|
||||
import io.bitsquare.locale.TradeCurrency;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PaymentAccount implements Serializable {
|
||||
public class PaymentAccount implements Persistable {
|
||||
// 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;
|
||||
|
||||
|
@ -18,11 +18,11 @@
|
||||
package io.bitsquare.payment;
|
||||
|
||||
import io.bitsquare.app.Version;
|
||||
import io.bitsquare.common.wire.Payload;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.Serializable;
|
||||
|
||||
public abstract class PaymentAccountContractData implements Serializable {
|
||||
public abstract class PaymentAccountContractData implements Payload {
|
||||
// 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;
|
||||
|
||||
|
@ -18,17 +18,17 @@
|
||||
package io.bitsquare.payment;
|
||||
|
||||
import io.bitsquare.app.Version;
|
||||
import io.bitsquare.common.persistance.Persistable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
// Don't use Enum as it breaks serialisation when changing entries and we want to stay flexible here
|
||||
public class PaymentMethod implements Serializable, Comparable {
|
||||
public class PaymentMethod implements Persistable, Comparable {
|
||||
// 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;
|
||||
|
||||
|
@ -20,9 +20,7 @@ package io.bitsquare.payment;
|
||||
import io.bitsquare.app.Version;
|
||||
import io.bitsquare.locale.FiatCurrency;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class PerfectMoneyAccount extends PaymentAccount implements Serializable {
|
||||
public class PerfectMoneyAccount extends PaymentAccount {
|
||||
// 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;
|
||||
|
||||
|
@ -19,9 +19,7 @@ package io.bitsquare.payment;
|
||||
|
||||
import io.bitsquare.app.Version;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public final class PerfectMoneyAccountContractData extends PaymentAccountContractData implements Serializable {
|
||||
public final class PerfectMoneyAccountContractData extends PaymentAccountContractData {
|
||||
// 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;
|
||||
|
||||
|
@ -19,10 +19,9 @@ package io.bitsquare.payment;
|
||||
|
||||
import io.bitsquare.app.Version;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
public class SepaAccount extends PaymentAccount implements Serializable {
|
||||
public class SepaAccount extends PaymentAccount {
|
||||
// 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;
|
||||
|
||||
|
@ -22,13 +22,12 @@ import io.bitsquare.locale.CountryUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public final class SepaAccountContractData extends PaymentAccountContractData implements Serializable {
|
||||
public final class SepaAccountContractData extends PaymentAccountContractData {
|
||||
// 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;
|
||||
|
||||
|
@ -20,9 +20,7 @@ package io.bitsquare.payment;
|
||||
import io.bitsquare.app.Version;
|
||||
import io.bitsquare.locale.FiatCurrency;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class SwishAccount extends PaymentAccount implements Serializable {
|
||||
public class SwishAccount extends PaymentAccount {
|
||||
// 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;
|
||||
|
||||
|
@ -19,9 +19,7 @@ package io.bitsquare.payment;
|
||||
|
||||
import io.bitsquare.app.Version;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public final class SwishAccountContractData extends PaymentAccountContractData implements Serializable {
|
||||
public final class SwishAccountContractData extends PaymentAccountContractData {
|
||||
// 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;
|
||||
|
||||
|
@ -23,10 +23,8 @@ import io.bitsquare.payment.PaymentMethod;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
// US only
|
||||
public class FedWireAccount extends PaymentAccount implements Serializable {
|
||||
public class FedWireAccount extends PaymentAccount {
|
||||
// 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;
|
||||
|
||||
|
@ -23,9 +23,7 @@ import io.bitsquare.payment.PaymentMethod;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class TransferWiseAccount extends PaymentAccount implements Serializable {
|
||||
public class TransferWiseAccount extends PaymentAccount {
|
||||
// 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;
|
||||
|
||||
|
@ -22,9 +22,7 @@ import io.bitsquare.payment.PaymentAccount;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class USPostalMoneyOrderAccount extends PaymentAccount implements Serializable {
|
||||
public class USPostalMoneyOrderAccount extends PaymentAccount {
|
||||
// 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;
|
||||
|
||||
|
@ -28,11 +28,9 @@ import org.bitcoinj.core.Coin;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
|
||||
public abstract class BuyerTrade extends Trade implements Serializable {
|
||||
public abstract class BuyerTrade extends Trade {
|
||||
// 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;
|
||||
|
||||
|
@ -20,20 +20,20 @@ package io.bitsquare.trade;
|
||||
import io.bitsquare.app.Version;
|
||||
import io.bitsquare.common.crypto.PubKeyRing;
|
||||
import io.bitsquare.common.util.JsonExclude;
|
||||
import io.bitsquare.common.wire.Payload;
|
||||
import io.bitsquare.p2p.NodeAddress;
|
||||
import io.bitsquare.payment.PaymentAccountContractData;
|
||||
import io.bitsquare.trade.offer.Offer;
|
||||
import org.bitcoinj.core.Coin;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
import java.io.Serializable;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
@Immutable
|
||||
public final class Contract implements Serializable {
|
||||
public final class Contract implements Payload {
|
||||
// That object is sent over the wire, so we need to take care of version compatibility.
|
||||
@JsonExclude
|
||||
public static final long serialVersionUID = Version.P2P_NETWORK_VERSION;
|
||||
|
@ -26,11 +26,9 @@ import org.bitcoinj.core.Coin;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
|
||||
public abstract class SellerTrade extends Trade implements Serializable {
|
||||
public abstract class SellerTrade extends Trade {
|
||||
// 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;
|
||||
|
||||
|
@ -17,12 +17,12 @@
|
||||
|
||||
package io.bitsquare.trade;
|
||||
|
||||
import io.bitsquare.common.persistance.Persistable;
|
||||
import io.bitsquare.trade.offer.Offer;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
public interface Tradable extends Serializable {
|
||||
public interface Tradable extends Persistable {
|
||||
Offer getOffer();
|
||||
|
||||
Date getDate();
|
||||
|
@ -18,6 +18,7 @@
|
||||
package io.bitsquare.trade;
|
||||
|
||||
import io.bitsquare.app.Version;
|
||||
import io.bitsquare.common.persistance.Persistable;
|
||||
import io.bitsquare.storage.Storage;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
@ -26,10 +27,9 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class TradableList<T extends Tradable> extends ArrayList<T> implements Serializable {
|
||||
public class TradableList<T extends Tradable> extends ArrayList<T> implements Persistable {
|
||||
// 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;
|
||||
|
||||
|
@ -50,14 +50,13 @@ import org.slf4j.LoggerFactory;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Holds all data which are relevant to the trade, but not those which are only needed in the trade process as shared data between tasks. Those data are
|
||||
* stored in the task model.
|
||||
*/
|
||||
abstract public class Trade implements Tradable, Model, Serializable {
|
||||
abstract public class Trade implements Tradable, Model {
|
||||
// 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;
|
||||
|
||||
|
@ -25,8 +25,8 @@ import io.bitsquare.common.handlers.ResultHandler;
|
||||
import io.bitsquare.common.util.JsonExclude;
|
||||
import io.bitsquare.locale.Country;
|
||||
import io.bitsquare.p2p.NodeAddress;
|
||||
import io.bitsquare.p2p.storage.messages.RequiresOwnerIsOnlinePayload;
|
||||
import io.bitsquare.p2p.storage.messages.StoragePayload;
|
||||
import io.bitsquare.p2p.storage.data.RequiresOwnerIsOnlinePayload;
|
||||
import io.bitsquare.p2p.storage.data.StoragePayload;
|
||||
import io.bitsquare.payment.PaymentMethod;
|
||||
import io.bitsquare.trade.protocol.availability.OfferAvailabilityModel;
|
||||
import io.bitsquare.trade.protocol.availability.OfferAvailabilityProtocol;
|
||||
|
@ -122,13 +122,12 @@ public class OpenOfferManager {
|
||||
});
|
||||
|
||||
NetworkNode networkNode = p2PService.getNetworkNode();
|
||||
|
||||
// TODO: Use check for detecting inactivity instead. run timer and check if elapsed time is in expected range,
|
||||
// if not we have been in standby and need a republish
|
||||
networkNode.addConnectionListener(new ConnectionListener() {
|
||||
@Override
|
||||
public void onConnection(Connection connection) {
|
||||
log.error("ConnectionListener onConnection size " + networkNode.getAllConnections().size());
|
||||
log.error("ConnectionListener onConnection lostAllConnections " + lostAllConnections);
|
||||
log.error("ConnectionListener onConnection allowRefreshOffers " + allowRefreshOffers);
|
||||
log.error("ConnectionListener onConnection republishOffersTime " + republishOffersTime);
|
||||
if (lostAllConnections) {
|
||||
lostAllConnections = false;
|
||||
allowRefreshOffers = false;
|
||||
@ -148,7 +147,6 @@ public class OpenOfferManager {
|
||||
|
||||
@Override
|
||||
public void onDisconnect(CloseConnectionReason closeConnectionReason, Connection connection) {
|
||||
log.error("ConnectionListener onDisconnect size " + networkNode.getAllConnections().size());
|
||||
lostAllConnections = networkNode.getAllConnections().isEmpty();
|
||||
if (lostAllConnections)
|
||||
allowRefreshOffers = false;
|
||||
@ -225,7 +223,6 @@ public class OpenOfferManager {
|
||||
}
|
||||
|
||||
private void republishOffers() {
|
||||
log.error("republishOffers ");
|
||||
Log.traceCall("Number of offer for republish: " + openOffers.size());
|
||||
for (OpenOffer openOffer : openOffers) {
|
||||
offerBookService.republishOffers(openOffer.getOffer(),
|
||||
|
@ -20,6 +20,7 @@ package io.bitsquare.trade.protocol.trade;
|
||||
import io.bitsquare.app.Version;
|
||||
import io.bitsquare.btc.data.RawInput;
|
||||
import io.bitsquare.common.crypto.PubKeyRing;
|
||||
import io.bitsquare.common.persistance.Persistable;
|
||||
import io.bitsquare.payment.PaymentAccountContractData;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -27,10 +28,9 @@ import org.slf4j.LoggerFactory;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
public class TradingPeer implements Serializable {
|
||||
public class TradingPeer implements Persistable {
|
||||
// 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;
|
||||
|
||||
|
@ -18,12 +18,11 @@
|
||||
package io.bitsquare.user;
|
||||
|
||||
import io.bitsquare.app.Version;
|
||||
import io.bitsquare.common.persistance.Persistable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class BlockChainExplorer implements Serializable {
|
||||
public class BlockChainExplorer implements Persistable {
|
||||
// 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;
|
||||
|
||||
|
@ -21,6 +21,7 @@ import io.bitsquare.app.BitsquareEnvironment;
|
||||
import io.bitsquare.app.Version;
|
||||
import io.bitsquare.btc.BitcoinNetwork;
|
||||
import io.bitsquare.btc.FeePolicy;
|
||||
import io.bitsquare.common.persistance.Persistable;
|
||||
import io.bitsquare.locale.CountryUtil;
|
||||
import io.bitsquare.locale.CurrencyUtil;
|
||||
import io.bitsquare.locale.TradeCurrency;
|
||||
@ -39,10 +40,9 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
|
||||
public class Preferences implements Serializable {
|
||||
public class Preferences implements Persistable {
|
||||
// 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;
|
||||
|
||||
|
@ -21,6 +21,7 @@ import io.bitsquare.alert.Alert;
|
||||
import io.bitsquare.app.Version;
|
||||
import io.bitsquare.arbitration.Arbitrator;
|
||||
import io.bitsquare.common.crypto.KeyRing;
|
||||
import io.bitsquare.common.persistance.Persistable;
|
||||
import io.bitsquare.locale.LanguageUtil;
|
||||
import io.bitsquare.locale.TradeCurrency;
|
||||
import io.bitsquare.p2p.NodeAddress;
|
||||
@ -38,7 +39,6 @@ import javax.annotation.Nullable;
|
||||
import javax.inject.Inject;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.Serializable;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
@ -48,7 +48,7 @@ import java.util.stream.Collectors;
|
||||
* The User is persisted locally.
|
||||
* It must never be transmitted over the wire (messageKeyPair contains private key!).
|
||||
*/
|
||||
public class User implements Serializable {
|
||||
public class User implements Persistable {
|
||||
// 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;
|
||||
|
||||
|
@ -19,6 +19,7 @@ package io.bitsquare.gui;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import io.bitsquare.app.Version;
|
||||
import io.bitsquare.common.persistance.Persistable;
|
||||
import io.bitsquare.gui.common.view.View;
|
||||
import io.bitsquare.gui.common.view.ViewPath;
|
||||
import io.bitsquare.gui.main.MainView;
|
||||
@ -27,11 +28,10 @@ import io.bitsquare.storage.Storage;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.CopyOnWriteArraySet;
|
||||
|
||||
public class Navigation implements Serializable {
|
||||
public class Navigation implements Persistable {
|
||||
// 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;
|
||||
private static final Logger log = LoggerFactory.getLogger(Navigation.class);
|
||||
|
@ -18,14 +18,14 @@
|
||||
package io.bitsquare.gui.common.view;
|
||||
|
||||
import io.bitsquare.app.Version;
|
||||
import io.bitsquare.common.persistance.Persistable;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class ViewPath extends ArrayList<Class<? extends View>> implements Serializable {
|
||||
public class ViewPath extends ArrayList<Class<? extends View>> implements Persistable {
|
||||
// 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;
|
||||
|
||||
|
@ -90,7 +90,8 @@ public class ArbitratorSelectionView extends ActivatableViewAndModel<GridPane, A
|
||||
@Override
|
||||
protected void deactivate() {
|
||||
languagesListView.getItems().removeListener(listChangeListener);
|
||||
model.languageCodes.removeListener(languageCodesListChangeListener);
|
||||
if (languageCodesListChangeListener != null)
|
||||
model.languageCodes.removeListener(languageCodesListChangeListener);
|
||||
}
|
||||
|
||||
|
||||
|
@ -38,11 +38,11 @@ public class EncryptionService {
|
||||
}
|
||||
|
||||
public DecryptedMsgWithPubKey decryptAndVerify(SealedAndSigned sealedAndSigned) throws CryptoException {
|
||||
DecryptedPayloadWithPubKey decryptedPayloadWithPubKey = Encryption.decryptHybridWithSignature(sealedAndSigned,
|
||||
DecryptedDataTuple decryptedDataTuple = Encryption.decryptHybridWithSignature(sealedAndSigned,
|
||||
keyRing.getEncryptionKeyPair().getPrivate());
|
||||
if (decryptedPayloadWithPubKey.payload instanceof Message) {
|
||||
return new DecryptedMsgWithPubKey((Message) decryptedPayloadWithPubKey.payload,
|
||||
decryptedPayloadWithPubKey.sigPublicKey);
|
||||
if (decryptedDataTuple.payload instanceof Message) {
|
||||
return new DecryptedMsgWithPubKey((Message) decryptedDataTuple.payload,
|
||||
decryptedDataTuple.sigPublicKey);
|
||||
} else {
|
||||
throw new CryptoException("decryptedPayloadWithPubKey.payload is not instance of Message");
|
||||
}
|
||||
|
@ -1,11 +1,14 @@
|
||||
package io.bitsquare.http;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
|
||||
// TODO route over tor
|
||||
public class HttpClient implements Serializable {
|
||||
public class HttpClient {
|
||||
|
||||
private final String baseUrl;
|
||||
|
||||
|
@ -1,11 +1,16 @@
|
||||
package io.bitsquare.p2p;
|
||||
|
||||
import io.bitsquare.app.Version;
|
||||
import io.bitsquare.common.crypto.Hash;
|
||||
import io.bitsquare.common.persistance.Persistable;
|
||||
import io.bitsquare.common.wire.Payload;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class NodeAddress implements Serializable {
|
||||
public class NodeAddress implements Persistable, Payload {
|
||||
// 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 String hostName;
|
||||
public final int port;
|
||||
transient private byte[] addressPrefixHash;
|
||||
|
@ -8,7 +8,6 @@ import com.google.inject.Inject;
|
||||
import com.google.inject.name.Named;
|
||||
import io.bitsquare.app.Log;
|
||||
import io.bitsquare.app.ProgramArguments;
|
||||
import io.bitsquare.common.ByteArray;
|
||||
import io.bitsquare.common.UserThread;
|
||||
import io.bitsquare.common.crypto.CryptoException;
|
||||
import io.bitsquare.common.crypto.KeyRing;
|
||||
@ -25,12 +24,8 @@ import io.bitsquare.p2p.peers.peerexchange.PeerExchangeManager;
|
||||
import io.bitsquare.p2p.seed.SeedNodesRepository;
|
||||
import io.bitsquare.p2p.storage.HashMapChangedListener;
|
||||
import io.bitsquare.p2p.storage.P2PDataStorage;
|
||||
import io.bitsquare.p2p.storage.data.ProtectedData;
|
||||
import io.bitsquare.p2p.storage.data.ProtectedMailboxData;
|
||||
import io.bitsquare.p2p.storage.data.RefreshTTLBundle;
|
||||
import io.bitsquare.p2p.storage.data.*;
|
||||
import io.bitsquare.p2p.storage.messages.AddDataMessage;
|
||||
import io.bitsquare.p2p.storage.messages.ExpirablePayload;
|
||||
import io.bitsquare.p2p.storage.messages.MailboxPayload;
|
||||
import javafx.beans.property.*;
|
||||
import javafx.beans.value.ChangeListener;
|
||||
import org.fxmisc.easybind.EasyBind;
|
||||
@ -737,7 +732,7 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
|
||||
return numConnectedPeers;
|
||||
}
|
||||
|
||||
public Map<ByteArray, ProtectedData> getDataMap() {
|
||||
public Map<P2PDataStorage.ByteArray, ProtectedData> getDataMap() {
|
||||
return p2PDataStorage.getMap();
|
||||
}
|
||||
|
||||
|
@ -1,12 +1,13 @@
|
||||
package io.bitsquare.p2p.peers.peerexchange;
|
||||
|
||||
import io.bitsquare.app.Version;
|
||||
import io.bitsquare.common.persistance.Persistable;
|
||||
import io.bitsquare.common.wire.Payload;
|
||||
import io.bitsquare.p2p.NodeAddress;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
public class ReportedPeer implements Serializable {
|
||||
public class ReportedPeer implements Payload, Persistable {
|
||||
// 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;
|
||||
|
||||
|
@ -8,15 +8,14 @@ import io.bitsquare.common.UserThread;
|
||||
import io.bitsquare.common.crypto.CryptoException;
|
||||
import io.bitsquare.common.crypto.Hash;
|
||||
import io.bitsquare.common.crypto.Sig;
|
||||
import io.bitsquare.common.util.Tuple2;
|
||||
import io.bitsquare.common.persistance.Persistable;
|
||||
import io.bitsquare.common.util.Utilities;
|
||||
import io.bitsquare.common.wire.Payload;
|
||||
import io.bitsquare.p2p.Message;
|
||||
import io.bitsquare.p2p.NodeAddress;
|
||||
import io.bitsquare.p2p.network.*;
|
||||
import io.bitsquare.p2p.peers.Broadcaster;
|
||||
import io.bitsquare.p2p.storage.data.ProtectedData;
|
||||
import io.bitsquare.p2p.storage.data.ProtectedMailboxData;
|
||||
import io.bitsquare.p2p.storage.data.RefreshTTLBundle;
|
||||
import io.bitsquare.p2p.storage.data.*;
|
||||
import io.bitsquare.p2p.storage.messages.*;
|
||||
import io.bitsquare.storage.Storage;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@ -44,7 +43,7 @@ public class P2PDataStorage implements MessageListener, ConnectionListener {
|
||||
private final Broadcaster broadcaster;
|
||||
private final Map<ByteArray, ProtectedData> map = new ConcurrentHashMap<>();
|
||||
private final CopyOnWriteArraySet<HashMapChangedListener> hashMapChangedListeners = new CopyOnWriteArraySet<>();
|
||||
private HashMap<ByteArray, Tuple2<Integer, Long>> sequenceNumberMap = new HashMap<>();
|
||||
private HashMap<ByteArray, MapValue> sequenceNumberMap = new HashMap<>();
|
||||
private final Storage<HashMap> storage;
|
||||
private final ScheduledThreadPoolExecutor removeExpiredEntriesExecutor;
|
||||
|
||||
@ -65,7 +64,7 @@ public class P2PDataStorage implements MessageListener, ConnectionListener {
|
||||
}
|
||||
|
||||
private void init() {
|
||||
HashMap<ByteArray, Tuple2<Integer, Long>> persisted = storage.initAndGetPersisted("SequenceNumberMap");
|
||||
HashMap<ByteArray, MapValue> persisted = storage.initAndGetPersisted("SequenceNumberMap");
|
||||
if (persisted != null)
|
||||
sequenceNumberMap = getPurgedSequenceNumberMap(persisted);
|
||||
|
||||
@ -192,9 +191,9 @@ public class P2PDataStorage implements MessageListener, ConnectionListener {
|
||||
// Republished data have a larger sequence number. We set the rePublish flag to enable broadcasting
|
||||
// even we had the data with the old seq nr. already
|
||||
if (sequenceNumberMap.containsKey(hashOfPayload) &&
|
||||
protectedData.sequenceNumber > sequenceNumberMap.get(hashOfPayload).first)
|
||||
protectedData.sequenceNumber > sequenceNumberMap.get(hashOfPayload).sequenceNr)
|
||||
|
||||
sequenceNumberMap.put(hashOfPayload, new Tuple2<>(protectedData.sequenceNumber, System.currentTimeMillis()));
|
||||
sequenceNumberMap.put(hashOfPayload, new MapValue(protectedData.sequenceNumber, System.currentTimeMillis()));
|
||||
storage.queueUpForSave(sequenceNumberMap, 5000);
|
||||
|
||||
StringBuilder sb = new StringBuilder("\n\n------------------------------------------------------------\n");
|
||||
@ -226,7 +225,7 @@ public class P2PDataStorage implements MessageListener, ConnectionListener {
|
||||
ByteArray hashOfPayload = new ByteArray(refreshTTLBundle.hashOfPayload);
|
||||
|
||||
if (map.containsKey(hashOfPayload)) {
|
||||
if (sequenceNumberMap.containsKey(hashOfPayload) && sequenceNumberMap.get(hashOfPayload).first == sequenceNumber) {
|
||||
if (sequenceNumberMap.containsKey(hashOfPayload) && sequenceNumberMap.get(hashOfPayload).sequenceNr == sequenceNumber) {
|
||||
log.warn("We got that message with that seq nr already from another peer. We ignore that message.");
|
||||
return true;
|
||||
} else {
|
||||
@ -239,7 +238,7 @@ public class P2PDataStorage implements MessageListener, ConnectionListener {
|
||||
ProtectedData storedData = map.get(hashOfPayload);
|
||||
storedData.refreshDate();
|
||||
|
||||
sequenceNumberMap.put(hashOfPayload, new Tuple2<>(sequenceNumber, System.currentTimeMillis()));
|
||||
sequenceNumberMap.put(hashOfPayload, new MapValue(sequenceNumber, System.currentTimeMillis()));
|
||||
storage.queueUpForSave(sequenceNumberMap, 5000);
|
||||
|
||||
StringBuilder sb = new StringBuilder("\n\n------------------------------------------------------------\n");
|
||||
@ -278,7 +277,7 @@ public class P2PDataStorage implements MessageListener, ConnectionListener {
|
||||
|
||||
broadcast(new RemoveDataMessage(protectedData), sender);
|
||||
|
||||
sequenceNumberMap.put(hashOfPayload, new Tuple2<>(protectedData.sequenceNumber, System.currentTimeMillis()));
|
||||
sequenceNumberMap.put(hashOfPayload, new MapValue(protectedData.sequenceNumber, System.currentTimeMillis()));
|
||||
storage.queueUpForSave(sequenceNumberMap, 5000);
|
||||
} else {
|
||||
log.debug("remove failed");
|
||||
@ -303,7 +302,7 @@ public class P2PDataStorage implements MessageListener, ConnectionListener {
|
||||
|
||||
broadcast(new RemoveMailboxDataMessage(protectedMailboxData), sender);
|
||||
|
||||
sequenceNumberMap.put(hashOfData, new Tuple2<>(protectedMailboxData.sequenceNumber, System.currentTimeMillis()));
|
||||
sequenceNumberMap.put(hashOfData, new MapValue(protectedMailboxData.sequenceNumber, System.currentTimeMillis()));
|
||||
storage.queueUpForSave(sequenceNumberMap, 5000);
|
||||
} else {
|
||||
log.debug("removeMailboxData failed");
|
||||
@ -321,7 +320,7 @@ public class P2PDataStorage implements MessageListener, ConnectionListener {
|
||||
ByteArray hashOfData = getHashAsByteArray(payload);
|
||||
int sequenceNumber;
|
||||
if (sequenceNumberMap.containsKey(hashOfData))
|
||||
sequenceNumber = sequenceNumberMap.get(hashOfData).first + 1;
|
||||
sequenceNumber = sequenceNumberMap.get(hashOfData).sequenceNr + 1;
|
||||
else
|
||||
sequenceNumber = 0;
|
||||
|
||||
@ -335,7 +334,7 @@ public class P2PDataStorage implements MessageListener, ConnectionListener {
|
||||
ByteArray hashOfPayload = getHashAsByteArray(payload);
|
||||
int sequenceNumber;
|
||||
if (sequenceNumberMap.containsKey(hashOfPayload))
|
||||
sequenceNumber = sequenceNumberMap.get(hashOfPayload).first + 1;
|
||||
sequenceNumber = sequenceNumberMap.get(hashOfPayload).sequenceNr + 1;
|
||||
else
|
||||
sequenceNumber = 0;
|
||||
|
||||
@ -351,7 +350,7 @@ public class P2PDataStorage implements MessageListener, ConnectionListener {
|
||||
ByteArray hashOfData = getHashAsByteArray(expirableMailboxPayload);
|
||||
int sequenceNumber;
|
||||
if (sequenceNumberMap.containsKey(hashOfData))
|
||||
sequenceNumber = sequenceNumberMap.get(hashOfData).first + 1;
|
||||
sequenceNumber = sequenceNumberMap.get(hashOfData).sequenceNr + 1;
|
||||
else
|
||||
sequenceNumber = 0;
|
||||
|
||||
@ -385,7 +384,7 @@ public class P2PDataStorage implements MessageListener, ConnectionListener {
|
||||
|
||||
private boolean isSequenceNrValid(int newSequenceNumber, ByteArray hashOfData) {
|
||||
if (sequenceNumberMap.containsKey(hashOfData)) {
|
||||
Integer storedSequenceNumber = sequenceNumberMap.get(hashOfData).first;
|
||||
Integer storedSequenceNumber = sequenceNumberMap.get(hashOfData).sequenceNr;
|
||||
if (newSequenceNumber < storedSequenceNumber) {
|
||||
log.warn("Sequence number is invalid. newSequenceNumber="
|
||||
+ newSequenceNumber + " / storedSequenceNumber=" + storedSequenceNumber);
|
||||
@ -472,11 +471,11 @@ public class P2PDataStorage implements MessageListener, ConnectionListener {
|
||||
return new ByteArray(Hash.getHash(data));
|
||||
}
|
||||
|
||||
private HashMap<ByteArray, Tuple2<Integer, Long>> getPurgedSequenceNumberMap(HashMap<ByteArray, Tuple2<Integer, Long>> persisted) {
|
||||
HashMap<ByteArray, Tuple2<Integer, Long>> purged = new HashMap<>();
|
||||
private HashMap<ByteArray, MapValue> getPurgedSequenceNumberMap(HashMap<ByteArray, MapValue> persisted) {
|
||||
HashMap<ByteArray, MapValue> purged = new HashMap<>();
|
||||
long maxAgeTs = System.currentTimeMillis() - TimeUnit.DAYS.toMillis(10);
|
||||
persisted.entrySet().stream().forEach(entry -> {
|
||||
if (entry.getValue().second > maxAgeTs)
|
||||
if (entry.getValue().timeStamp > maxAgeTs)
|
||||
purged.put(entry.getKey(), entry.getValue());
|
||||
});
|
||||
return purged;
|
||||
@ -487,13 +486,18 @@ public class P2PDataStorage implements MessageListener, ConnectionListener {
|
||||
// Static class
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Used as container for calculating cryptographic hash of data and sequenceNumber
|
||||
|
||||
/**
|
||||
* Used as container for calculating cryptographic hash of data and sequenceNumber.
|
||||
* Needs to be Serializable because we convert the object to a byte array via java serialization
|
||||
* before calculating the hash.
|
||||
*/
|
||||
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 Payload data;
|
||||
private final int sequenceNumber;
|
||||
|
||||
public DataAndSeqNrPair(Serializable data, int sequenceNumber) {
|
||||
public DataAndSeqNrPair(Payload data, int sequenceNumber) {
|
||||
this.data = data;
|
||||
this.sequenceNumber = sequenceNumber;
|
||||
}
|
||||
@ -507,9 +511,12 @@ 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 {
|
||||
|
||||
/**
|
||||
* 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 Persistable {
|
||||
// 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;
|
||||
|
||||
@ -536,4 +543,46 @@ public class P2PDataStorage implements MessageListener, ConnectionListener {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Used as value in map
|
||||
*/
|
||||
private static final class MapValue implements Persistable {
|
||||
// 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;
|
||||
|
||||
final public int sequenceNr;
|
||||
final public long timeStamp;
|
||||
|
||||
public MapValue(int sequenceNr, long timeStamp) {
|
||||
this.sequenceNr = sequenceNr;
|
||||
this.timeStamp = timeStamp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof MapValue)) return false;
|
||||
|
||||
MapValue mapValue = (MapValue) o;
|
||||
|
||||
if (sequenceNr != mapValue.sequenceNr) return false;
|
||||
return timeStamp == mapValue.timeStamp;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = sequenceNr;
|
||||
result = 31 * result + (int) (timeStamp ^ (timeStamp >>> 32));
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "MapValue{" +
|
||||
"sequenceNr=" + sequenceNr +
|
||||
", timeStamp=" + timeStamp +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package io.bitsquare.p2p.storage.messages;
|
||||
package io.bitsquare.p2p.storage.data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import io.bitsquare.common.wire.Payload;
|
||||
|
||||
/**
|
||||
* Messages which support a time to live
|
||||
@ -10,7 +10,7 @@ import java.io.Serializable;
|
||||
* @see StoragePayload
|
||||
* @see MailboxPayload
|
||||
*/
|
||||
public interface ExpirablePayload extends Serializable {
|
||||
public interface ExpirablePayload extends Payload {
|
||||
/**
|
||||
* @return Time to live in milli seconds
|
||||
*/
|
@ -1,9 +1,8 @@
|
||||
package io.bitsquare.p2p.storage.messages;
|
||||
package io.bitsquare.p2p.storage.data;
|
||||
|
||||
import io.bitsquare.app.Version;
|
||||
import io.bitsquare.crypto.PrefixedSealedAndSignedMessage;
|
||||
import io.bitsquare.p2p.NodeAddress;
|
||||
import io.bitsquare.p2p.storage.data.ProtectedData;
|
||||
|
||||
import java.security.PublicKey;
|
||||
import java.util.concurrent.TimeUnit;
|
@ -1,18 +1,17 @@
|
||||
package io.bitsquare.p2p.storage.data;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import io.bitsquare.common.wire.Payload;
|
||||
import io.bitsquare.p2p.storage.P2PDataStorage;
|
||||
import io.bitsquare.p2p.storage.messages.ExpirablePayload;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.security.PublicKey;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
|
||||
public class ProtectedData implements Serializable {
|
||||
public class ProtectedData implements Payload {
|
||||
private static final Logger log = LoggerFactory.getLogger(P2PDataStorage.class);
|
||||
|
||||
public final ExpirablePayload expirablePayload;
|
||||
|
@ -1,7 +1,6 @@
|
||||
package io.bitsquare.p2p.storage.data;
|
||||
|
||||
import io.bitsquare.p2p.storage.P2PDataStorage;
|
||||
import io.bitsquare.p2p.storage.messages.MailboxPayload;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -2,12 +2,12 @@ package io.bitsquare.p2p.storage.data;
|
||||
|
||||
import io.bitsquare.app.Version;
|
||||
import io.bitsquare.common.crypto.Sig;
|
||||
import io.bitsquare.common.wire.Payload;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.Serializable;
|
||||
import java.security.KeyFactory;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.NoSuchProviderException;
|
||||
@ -16,7 +16,7 @@ import java.security.spec.InvalidKeySpecException;
|
||||
import java.security.spec.X509EncodedKeySpec;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class RefreshTTLBundle implements Serializable {
|
||||
public class RefreshTTLBundle implements Payload {
|
||||
// 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;
|
||||
|
||||
|
@ -1,16 +1,15 @@
|
||||
package io.bitsquare.p2p.storage.messages;
|
||||
package io.bitsquare.p2p.storage.data;
|
||||
|
||||
import io.bitsquare.common.wire.Payload;
|
||||
import io.bitsquare.p2p.NodeAddress;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Used for messages which require that the data owner is online.
|
||||
* <p>
|
||||
* This is used for the offers to avoid dead offers in case the offerer is in sleep/hibernate mode or the app has
|
||||
* terminated without sending the remove message (e.g. in case of a crash).
|
||||
*/
|
||||
public interface RequiresOwnerIsOnlinePayload extends Serializable {
|
||||
public interface RequiresOwnerIsOnlinePayload extends Payload {
|
||||
/**
|
||||
* @return NodeAddress of the data owner
|
||||
*/
|
@ -1,7 +1,6 @@
|
||||
package io.bitsquare.p2p.storage.messages;
|
||||
package io.bitsquare.p2p.storage.data;
|
||||
|
||||
import io.bitsquare.p2p.NodeAddress;
|
||||
import io.bitsquare.p2p.storage.data.ProtectedData;
|
||||
|
||||
import java.security.PublicKey;
|
||||
|
@ -3,7 +3,7 @@ package io.bitsquare.p2p.mocks;
|
||||
import io.bitsquare.app.Version;
|
||||
import io.bitsquare.p2p.NodeAddress;
|
||||
import io.bitsquare.p2p.messaging.MailboxMessage;
|
||||
import io.bitsquare.p2p.storage.messages.ExpirablePayload;
|
||||
import io.bitsquare.p2p.storage.data.ExpirablePayload;
|
||||
|
||||
public final class MockMailboxPayload implements MailboxMessage, ExpirablePayload {
|
||||
private final int messageVersion = Version.getP2PMessageVersion();
|
||||
|
@ -2,7 +2,7 @@ package io.bitsquare.p2p.mocks;
|
||||
|
||||
import io.bitsquare.app.Version;
|
||||
import io.bitsquare.p2p.Message;
|
||||
import io.bitsquare.p2p.storage.messages.ExpirablePayload;
|
||||
import io.bitsquare.p2p.storage.data.ExpirablePayload;
|
||||
|
||||
public final class MockPayload implements Message, ExpirablePayload {
|
||||
public final String msg;
|
||||
|
@ -1,6 +1,6 @@
|
||||
package io.bitsquare.p2p.storage.mocks;
|
||||
|
||||
import io.bitsquare.p2p.storage.messages.StoragePayload;
|
||||
import io.bitsquare.p2p.storage.data.StoragePayload;
|
||||
|
||||
import java.security.PublicKey;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user