Rename ExpirableMessage and StorageMessage to ExpirablePayload and StoragePayload

This commit is contained in:
Manfred Karrer 2016-02-18 12:50:59 +01:00
parent 3f54cb233e
commit 6f1efdb3c0
19 changed files with 105 additions and 105 deletions

View file

@ -18,12 +18,12 @@
package io.bitsquare.alert;
import io.bitsquare.app.Version;
import io.bitsquare.p2p.storage.messages.StorageMessage;
import io.bitsquare.p2p.storage.messages.StoragePayload;
import java.security.PublicKey;
import java.util.concurrent.TimeUnit;
public final class Alert implements StorageMessage {
public final class Alert implements StoragePayload {
// 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;

View file

@ -61,8 +61,8 @@ public class AlertManager {
alertService.addHashSetChangedListener(new HashMapChangedListener() {
@Override
public void onAdded(ProtectedData data) {
if (data.expirableMessage instanceof Alert) {
Alert alert = (Alert) data.expirableMessage;
if (data.expirablePayload instanceof Alert) {
Alert alert = (Alert) data.expirablePayload;
if (verifySignature(alert))
alertMessageProperty.set(alert);
}
@ -70,8 +70,8 @@ public class AlertManager {
@Override
public void onRemoved(ProtectedData data) {
if (data.expirableMessage instanceof Alert) {
Alert alert = (Alert) data.expirableMessage;
if (data.expirablePayload instanceof Alert) {
Alert alert = (Alert) data.expirablePayload;
if (verifySignature(alert))
alertMessageProperty.set(null);
}

View file

@ -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.StorageMessage;
import io.bitsquare.p2p.storage.messages.StoragePayload;
import java.security.PublicKey;
import java.util.Arrays;
@ -28,7 +28,7 @@ import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;
public final class Arbitrator implements StorageMessage {
public final class Arbitrator implements StoragePayload {
// 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;

View file

@ -84,8 +84,8 @@ public class ArbitratorService {
public Map<NodeAddress, Arbitrator> getArbitrators() {
Set<Arbitrator> arbitratorSet = p2PService.getDataMap().values().stream()
.filter(data -> data.expirableMessage instanceof Arbitrator)
.map(data -> (Arbitrator) data.expirableMessage)
.filter(data -> data.expirablePayload instanceof Arbitrator)
.map(data -> (Arbitrator) data.expirablePayload)
.collect(Collectors.toSet());
Map<NodeAddress, Arbitrator> map = new HashMap<>();

View file

@ -26,7 +26,7 @@ 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.StorageMessage;
import io.bitsquare.p2p.storage.messages.StoragePayload;
import io.bitsquare.payment.PaymentMethod;
import io.bitsquare.trade.protocol.availability.OfferAvailabilityModel;
import io.bitsquare.trade.protocol.availability.OfferAvailabilityProtocol;
@ -47,7 +47,7 @@ import java.util.concurrent.TimeUnit;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
public final class Offer implements StorageMessage, RequiresOwnerIsOnlinePayload {
public final class Offer implements StoragePayload, RequiresOwnerIsOnlinePayload {
// That object is sent over the wire, so we need to take care of version compatibility.
@JsonExclude
private static final long serialVersionUID = Version.P2P_NETWORK_VERSION;

View file

@ -60,16 +60,16 @@ public class OfferBookService {
@Override
public void onAdded(ProtectedData data) {
offerBookChangedListeners.stream().forEach(listener -> {
if (data.expirableMessage instanceof Offer)
listener.onAdded((Offer) data.expirableMessage);
if (data.expirablePayload instanceof Offer)
listener.onAdded((Offer) data.expirablePayload);
});
}
@Override
public void onRemoved(ProtectedData data) {
offerBookChangedListeners.stream().forEach(listener -> {
if (data.expirableMessage instanceof Offer)
listener.onRemoved((Offer) data.expirableMessage);
if (data.expirablePayload instanceof Offer)
listener.onRemoved((Offer) data.expirablePayload);
});
}
});
@ -126,8 +126,8 @@ public class OfferBookService {
public List<Offer> getOffers() {
return p2PService.getDataMap().values().stream()
.filter(data -> data.expirableMessage instanceof Offer)
.map(data -> (Offer) data.expirableMessage)
.filter(data -> data.expirablePayload instanceof Offer)
.map(data -> (Offer) data.expirablePayload)
.collect(Collectors.toList());
}

View file

@ -29,8 +29,8 @@ 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.messages.AddDataMessage;
import io.bitsquare.p2p.storage.messages.ExpirableMessage;
import io.bitsquare.p2p.storage.messages.MailboxMessage;
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;
@ -432,9 +432,9 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
// Seed nodes don't have set the encryptionService
if (optionalEncryptionService.isPresent()) {
Log.traceCall();
ExpirableMessage expirableMessage = mailboxData.expirableMessage;
if (expirableMessage instanceof MailboxMessage) {
MailboxMessage expirableMailboxPayload = (MailboxMessage) expirableMessage;
ExpirablePayload expirablePayload = mailboxData.expirablePayload;
if (expirablePayload instanceof MailboxPayload) {
MailboxPayload expirableMailboxPayload = (MailboxPayload) expirablePayload;
PrefixedSealedAndSignedMessage prefixedSealedAndSignedMessage = expirableMailboxPayload.prefixedSealedAndSignedMessage;
if (verifyAddressPrefixHash(prefixedSealedAndSignedMessage)) {
try {
@ -505,7 +505,7 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
log.info("We cannot send message to peer. Peer might be offline. We will store message in mailbox.");
log.trace("create MailboxEntry with peerAddress " + peersNodeAddress);
PublicKey receiverStoragePublicKey = peersPubKeyRing.getSignaturePubKey();
addMailboxData(new MailboxMessage(prefixedSealedAndSignedMessage,
addMailboxData(new MailboxPayload(prefixedSealedAndSignedMessage,
optionalKeyRing.get().getSignatureKeyPair().getPublic(),
receiverStoragePublicKey),
receiverStoragePublicKey,
@ -527,7 +527,7 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
}
private void addMailboxData(MailboxMessage expirableMailboxPayload,
private void addMailboxData(MailboxPayload expirableMailboxPayload,
PublicKey receiversPublicKey,
SendMailboxMessageListener sendMailboxMessageListener) {
Log.traceCall();
@ -598,8 +598,8 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
if (isBootstrapped()) {
if (mailboxMap.containsKey(decryptedMsgWithPubKey)) {
ProtectedMailboxData mailboxData = mailboxMap.get(decryptedMsgWithPubKey);
if (mailboxData != null && mailboxData.expirableMessage instanceof MailboxMessage) {
MailboxMessage expirableMailboxPayload = (MailboxMessage) mailboxData.expirableMessage;
if (mailboxData != null && mailboxData.expirablePayload instanceof MailboxPayload) {
MailboxPayload expirableMailboxPayload = (MailboxPayload) mailboxData.expirablePayload;
PublicKey receiversPubKey = mailboxData.receiversPubKey;
checkArgument(receiversPubKey.equals(optionalKeyRing.get().getSignatureKeyPair().getPublic()),
"receiversPubKey is not matching with our key. That must not happen.");
@ -631,16 +631,16 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
// Data storage
///////////////////////////////////////////////////////////////////////////////////////////
public boolean addData(ExpirableMessage expirableMessage) {
return addData(expirableMessage, false);
public boolean addData(ExpirablePayload expirablePayload) {
return addData(expirablePayload, false);
}
public boolean addData(ExpirableMessage expirableMessage, boolean forceBroadcast) {
public boolean addData(ExpirablePayload expirablePayload, boolean forceBroadcast) {
Log.traceCall();
checkArgument(optionalKeyRing.isPresent(), "keyRing not set. Seems that is called on a seed node which must not happen.");
if (isBootstrapped()) {
try {
ProtectedData protectedData = p2PDataStorage.getProtectedData(expirableMessage, optionalKeyRing.get().getSignatureKeyPair());
ProtectedData protectedData = p2PDataStorage.getProtectedData(expirablePayload, optionalKeyRing.get().getSignatureKeyPair());
return p2PDataStorage.add(protectedData, networkNode.getNodeAddress(), forceBroadcast);
} catch (CryptoException e) {
log.error("Signing at getDataWithSignedSeqNr failed. That should never happen.");
@ -651,12 +651,12 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
}
}
public boolean refreshTTL(ExpirableMessage expirableMessage) {
public boolean refreshTTL(ExpirablePayload expirablePayload) {
Log.traceCall();
checkArgument(optionalKeyRing.isPresent(), "keyRing not set. Seems that is called on a seed node which must not happen.");
if (isBootstrapped()) {
try {
RefreshTTLBundle refreshTTLBundle = p2PDataStorage.getRefreshTTLPackage(expirableMessage, optionalKeyRing.get().getSignatureKeyPair());
RefreshTTLBundle refreshTTLBundle = p2PDataStorage.getRefreshTTLPackage(expirablePayload, optionalKeyRing.get().getSignatureKeyPair());
return p2PDataStorage.refreshTTL(refreshTTLBundle, networkNode.getNodeAddress());
} catch (CryptoException e) {
log.error("Signing at getDataWithSignedSeqNr failed. That should never happen.");
@ -667,12 +667,12 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
}
}
public boolean removeData(ExpirableMessage expirableMessage) {
public boolean removeData(ExpirablePayload expirablePayload) {
Log.traceCall();
checkArgument(optionalKeyRing.isPresent(), "keyRing not set. Seems that is called on a seed node which must not happen.");
if (isBootstrapped()) {
try {
ProtectedData protectedData = p2PDataStorage.getProtectedData(expirableMessage, optionalKeyRing.get().getSignatureKeyPair());
ProtectedData protectedData = p2PDataStorage.getProtectedData(expirablePayload, optionalKeyRing.get().getSignatureKeyPair());
return p2PDataStorage.remove(protectedData, networkNode.getNodeAddress());
} catch (CryptoException e) {
log.error("Signing at getDataWithSignedSeqNr failed. That should never happen.");

View file

@ -136,16 +136,16 @@ public class P2PDataStorage implements MessageListener, ConnectionListener {
if (connection.getPeersNodeAddressOptional().isPresent() && !closeConnectionReason.isIntended) {
map.values().stream()
.forEach(protectedData -> {
ExpirableMessage expirableMessage = protectedData.expirableMessage;
if (expirableMessage instanceof RequiresOwnerIsOnlinePayload) {
RequiresOwnerIsOnlinePayload requiresOwnerIsOnlinePayload = (RequiresOwnerIsOnlinePayload) expirableMessage;
ExpirablePayload expirablePayload = protectedData.expirablePayload;
if (expirablePayload instanceof RequiresOwnerIsOnlinePayload) {
RequiresOwnerIsOnlinePayload requiresOwnerIsOnlinePayload = (RequiresOwnerIsOnlinePayload) expirablePayload;
NodeAddress ownerNodeAddress = requiresOwnerIsOnlinePayload.getOwnerNodeAddress();
if (ownerNodeAddress.equals(connection.getPeersNodeAddressOptional().get())) {
// We have a RequiresLiveOwnerData data object with the node address of the
// disconnected peer. We remove that data from our map.
// Check if we have the data (e.g. Offer)
ByteArray hashOfPayload = getHashAsByteArray(expirableMessage);
ByteArray hashOfPayload = getHashAsByteArray(expirablePayload);
boolean containsKey = map.containsKey(hashOfPayload);
if (containsKey) {
doRemoveProtectedExpirableData(protectedData, hashOfPayload);
@ -180,7 +180,7 @@ public class P2PDataStorage implements MessageListener, ConnectionListener {
public boolean add(ProtectedData protectedData, @Nullable NodeAddress sender, boolean forceBroadcast) {
Log.traceCall();
ByteArray hashOfPayload = getHashAsByteArray(protectedData.expirableMessage);
ByteArray hashOfPayload = getHashAsByteArray(protectedData.expirablePayload);
boolean result = checkPublicKeys(protectedData, true)
&& checkSignature(protectedData)
&& isSequenceNrValid(protectedData.sequenceNumber, hashOfPayload);
@ -266,7 +266,7 @@ public class P2PDataStorage implements MessageListener, ConnectionListener {
public boolean remove(ProtectedData protectedData, @Nullable NodeAddress sender) {
Log.traceCall();
ByteArray hashOfPayload = getHashAsByteArray(protectedData.expirableMessage);
ByteArray hashOfPayload = getHashAsByteArray(protectedData.expirablePayload);
boolean containsKey = map.containsKey(hashOfPayload);
if (!containsKey) log.debug("Remove data ignored as we don't have an entry for that data.");
boolean result = containsKey
@ -291,7 +291,7 @@ public class P2PDataStorage implements MessageListener, ConnectionListener {
public boolean removeMailboxData(ProtectedMailboxData protectedMailboxData, @Nullable NodeAddress sender) {
Log.traceCall();
ByteArray hashOfData = getHashAsByteArray(protectedMailboxData.expirableMessage);
ByteArray hashOfData = getHashAsByteArray(protectedMailboxData.expirablePayload);
boolean containsKey = map.containsKey(hashOfData);
if (!containsKey) log.debug("Remove data ignored as we don't have an entry for that data.");
boolean result = containsKey
@ -319,7 +319,7 @@ public class P2PDataStorage implements MessageListener, ConnectionListener {
return map;
}
public ProtectedData getProtectedData(ExpirableMessage payload, KeyPair ownerStoragePubKey)
public ProtectedData getProtectedData(ExpirablePayload payload, KeyPair ownerStoragePubKey)
throws CryptoException {
ByteArray hashOfData = getHashAsByteArray(payload);
int sequenceNumber;
@ -333,7 +333,7 @@ public class P2PDataStorage implements MessageListener, ConnectionListener {
return new ProtectedData(payload, payload.getTTL(), ownerStoragePubKey.getPublic(), sequenceNumber, signature);
}
public RefreshTTLBundle getRefreshTTLPackage(ExpirableMessage payload, KeyPair ownerStoragePubKey)
public RefreshTTLBundle getRefreshTTLPackage(ExpirablePayload payload, KeyPair ownerStoragePubKey)
throws CryptoException {
ByteArray hashOfPayload = getHashAsByteArray(payload);
int sequenceNumber;
@ -348,7 +348,7 @@ public class P2PDataStorage implements MessageListener, ConnectionListener {
return new RefreshTTLBundle(ownerPubKey, hashOfDataAndSeqNr, signature, hashOfPayload.bytes, sequenceNumber);
}
public ProtectedMailboxData getMailboxDataWithSignedSeqNr(MailboxMessage expirableMailboxPayload,
public ProtectedMailboxData getMailboxDataWithSignedSeqNr(MailboxPayload expirableMailboxPayload,
KeyPair storageSignaturePubKey, PublicKey receiversPublicKey)
throws CryptoException {
ByteArray hashOfData = getHashAsByteArray(expirableMailboxPayload);
@ -416,20 +416,20 @@ public class P2PDataStorage implements MessageListener, ConnectionListener {
}
private boolean checkSignature(ProtectedData data) {
byte[] hashOfDataAndSeqNr = Hash.getHash(new DataAndSeqNrPair(data.expirableMessage, data.sequenceNumber));
byte[] hashOfDataAndSeqNr = Hash.getHash(new DataAndSeqNrPair(data.expirablePayload, data.sequenceNumber));
return checkSignature(data.ownerPubKey, hashOfDataAndSeqNr, data.signature);
}
private boolean checkPublicKeys(ProtectedData data, boolean isAddOperation) {
boolean result = false;
if (data.expirableMessage instanceof MailboxMessage) {
MailboxMessage expirableMailboxPayload = (MailboxMessage) data.expirableMessage;
if (data.expirablePayload instanceof MailboxPayload) {
MailboxPayload expirableMailboxPayload = (MailboxPayload) data.expirablePayload;
if (isAddOperation)
result = expirableMailboxPayload.senderPubKeyForAddOperation.equals(data.ownerPubKey);
else
result = expirableMailboxPayload.receiverPubKeyForRemoveOperation.equals(data.ownerPubKey);
} else if (data.expirableMessage instanceof StorageMessage) {
result = ((StorageMessage) data.expirableMessage).getOwnerPubKey().equals(data.ownerPubKey);
} else if (data.expirablePayload instanceof StoragePayload) {
result = ((StoragePayload) data.expirablePayload).getOwnerPubKey().equals(data.ownerPubKey);
}
if (!result)
@ -456,7 +456,7 @@ public class P2PDataStorage implements MessageListener, ConnectionListener {
ProtectedMailboxData storedMailboxData = (ProtectedMailboxData) storedData;
// publicKey is not the same (stored: sender, new: receiver)
boolean result = storedMailboxData.receiversPubKey.equals(receiversPubKey)
&& getHashAsByteArray(storedMailboxData.expirableMessage).equals(hashOfData);
&& getHashAsByteArray(storedMailboxData.expirablePayload).equals(hashOfData);
if (!result)
log.error("New data entry does not match our stored data. Consider it might be an attempt of fraud");
@ -471,7 +471,7 @@ public class P2PDataStorage implements MessageListener, ConnectionListener {
broadcaster.broadcast(message, sender);
}
private ByteArray getHashAsByteArray(ExpirableMessage data) {
private ByteArray getHashAsByteArray(ExpirablePayload data) {
return new ByteArray(Hash.getHash(data));
}

View file

@ -2,7 +2,7 @@ package io.bitsquare.p2p.storage.data;
import com.google.common.annotations.VisibleForTesting;
import io.bitsquare.p2p.storage.P2PDataStorage;
import io.bitsquare.p2p.storage.messages.ExpirableMessage;
import io.bitsquare.p2p.storage.messages.ExpirablePayload;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -15,7 +15,7 @@ import java.util.Date;
public class ProtectedData implements Serializable {
private static final Logger log = LoggerFactory.getLogger(P2PDataStorage.class);
public final ExpirableMessage expirableMessage;
public final ExpirablePayload expirablePayload;
//TODO check if that field make sense as it is in expirableMessage.getTTL()
transient public long ttl;
@ -26,8 +26,8 @@ public class ProtectedData implements Serializable {
@VisibleForTesting
transient public Date date;
public ProtectedData(ExpirableMessage expirableMessage, long ttl, PublicKey ownerPubKey, int sequenceNumber, byte[] signature) {
this.expirableMessage = expirableMessage;
public ProtectedData(ExpirablePayload expirablePayload, long ttl, PublicKey ownerPubKey, int sequenceNumber, byte[] signature) {
this.expirablePayload = expirablePayload;
this.ttl = ttl;
this.ownerPubKey = ownerPubKey;
this.sequenceNumber = sequenceNumber;
@ -38,7 +38,7 @@ public class ProtectedData implements Serializable {
private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException {
try {
in.defaultReadObject();
ttl = expirableMessage.getTTL();
ttl = expirablePayload.getTTL();
date = new Date();
} catch (Throwable t) {
@ -58,7 +58,7 @@ public class ProtectedData implements Serializable {
@Override
public String toString() {
return "ProtectedData{" +
"expirablePayload=" + expirableMessage +
"expirablePayload=" + expirablePayload +
", ttl=" + ttl +
", date=" + date +
", sequenceNumber=" + sequenceNumber +

View file

@ -1,7 +1,7 @@
package io.bitsquare.p2p.storage.data;
import io.bitsquare.p2p.storage.P2PDataStorage;
import io.bitsquare.p2p.storage.messages.MailboxMessage;
import io.bitsquare.p2p.storage.messages.MailboxPayload;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -15,7 +15,7 @@ public class ProtectedMailboxData extends ProtectedData {
public final PublicKey receiversPubKey;
public ProtectedMailboxData(MailboxMessage data, long ttl, PublicKey ownerStoragePubKey, int sequenceNumber, byte[] signature, PublicKey receiversPubKey) {
public ProtectedMailboxData(MailboxPayload data, long ttl, PublicKey ownerStoragePubKey, int sequenceNumber, byte[] signature, PublicKey receiversPubKey) {
super(data, ttl, ownerStoragePubKey, sequenceNumber, signature);
this.receiversPubKey = receiversPubKey;
@ -24,7 +24,7 @@ public class ProtectedMailboxData extends ProtectedData {
private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException {
try {
in.defaultReadObject();
ttl = expirableMessage.getTTL();
ttl = expirablePayload.getTTL();
// in case the reported creation date is in the future
// we reset the date to the current time

View file

@ -7,10 +7,10 @@ import java.io.Serializable;
* <p>
* Implementations:
*
* @see StorageMessage
* @see MailboxMessage
* @see StoragePayload
* @see MailboxPayload
*/
public interface ExpirableMessage extends Serializable {
public interface ExpirablePayload extends Serializable {
/**
* @return Time to live in milli seconds
*/

View file

@ -16,7 +16,7 @@ import java.util.concurrent.TimeUnit;
* <p>
* Typical payloads are trade or dispute messages to be stored when the peer is offline.
*/
public final class MailboxMessage implements ExpirableMessage {
public final class MailboxPayload implements ExpirablePayload {
// 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;
@ -45,7 +45,7 @@ public final class MailboxMessage implements ExpirableMessage {
*/
public final PublicKey receiverPubKeyForRemoveOperation;
public MailboxMessage(PrefixedSealedAndSignedMessage prefixedSealedAndSignedMessage, PublicKey senderPubKeyForAddOperation, PublicKey receiverPubKeyForRemoveOperation) {
public MailboxPayload(PrefixedSealedAndSignedMessage prefixedSealedAndSignedMessage, PublicKey senderPubKeyForAddOperation, PublicKey receiverPubKeyForRemoveOperation) {
this.prefixedSealedAndSignedMessage = prefixedSealedAndSignedMessage;
this.senderPubKeyForAddOperation = senderPubKeyForAddOperation;
this.receiverPubKeyForRemoveOperation = receiverPubKeyForRemoveOperation;
@ -59,9 +59,9 @@ public final class MailboxMessage implements ExpirableMessage {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof MailboxMessage)) return false;
if (!(o instanceof MailboxPayload)) return false;
MailboxMessage that = (MailboxMessage) o;
MailboxPayload that = (MailboxPayload) o;
return !(prefixedSealedAndSignedMessage != null ? !prefixedSealedAndSignedMessage.equals(that.prefixedSealedAndSignedMessage) : that.prefixedSealedAndSignedMessage != null);

View file

@ -13,7 +13,7 @@ import java.security.PublicKey;
* io.bitsquare.arbitration.Arbitrator
* io.bitsquare.trade.offer.Offer
*/
public interface StorageMessage extends ExpirableMessage {
public interface StoragePayload extends ExpirablePayload {
/**
* Used for check if the add or remove operation is permitted.
* Only data owner can add or remove the data.

View file

@ -6,7 +6,7 @@ import io.bitsquare.crypto.PrefixedSealedAndSignedMessage;
import io.bitsquare.p2p.messaging.DecryptedMsgWithPubKey;
import io.bitsquare.p2p.messaging.MailboxMessage;
import io.bitsquare.p2p.messaging.SendMailboxMessageListener;
import io.bitsquare.p2p.mocks.MockMailboxMessage;
import io.bitsquare.p2p.mocks.MockMailboxPayload;
import io.bitsquare.p2p.network.LocalhostNetworkNode;
import io.bitsquare.p2p.peers.PeerManager;
import io.bitsquare.p2p.seed.SeedNode;
@ -163,16 +163,16 @@ public class P2PServiceTest {
.map(data -> (ProtectedData) data)
.collect(Collectors.toSet());
ProtectedData origProtectedData = dataSet.stream().findFirst().get();
ProtectedData protectedDataManipulated = new ProtectedData(origProtectedData.expirableMessage, origProtectedData.ttl, origProtectedData.ownerPubKey, origProtectedData.sequenceNumber + 1, origProtectedData.signature);
Assert.assertFalse(p2PService3.removeData(protectedDataManipulated.expirableMessage));
ProtectedData protectedDataManipulated = new ProtectedData(origProtectedData.expirablePayload, origProtectedData.ttl, origProtectedData.ownerPubKey, origProtectedData.sequenceNumber + 1, origProtectedData.signature);
Assert.assertFalse(p2PService3.removeData(protectedDataManipulated.expirablePayload));
Thread.sleep(sleepTime);
Assert.assertEquals(1, p2PService1.getDataMap().size());
Assert.assertEquals(1, p2PService2.getDataMap().size());
Assert.assertEquals(1, p2PService3.getDataMap().size());
// try to manipulate seq nr. + pubKey -> fails
protectedDataManipulated = new ProtectedData(origProtectedData.expirableMessage, origProtectedData.ttl, msgSignatureKeyPairAdversary.getPublic(), origProtectedData.sequenceNumber + 1, origProtectedData.signature);
Assert.assertFalse(p2PService3.removeData(protectedDataManipulated.expirableMessage));
protectedDataManipulated = new ProtectedData(origProtectedData.expirablePayload, origProtectedData.ttl, msgSignatureKeyPairAdversary.getPublic(), origProtectedData.sequenceNumber + 1, origProtectedData.signature);
Assert.assertFalse(p2PService3.removeData(protectedDataManipulated.expirablePayload));
Thread.sleep(sleepTime);
Assert.assertEquals(1, p2PService1.getDataMap().size());
Assert.assertEquals(1, p2PService2.getDataMap().size());
@ -180,10 +180,10 @@ public class P2PServiceTest {
// try to manipulate seq nr. + pubKey + sig -> fails
int sequenceNumberManipulated = origProtectedData.sequenceNumber + 1;
byte[] hashOfDataAndSeqNr = Hash.getHash(new P2PDataStorage.DataAndSeqNrPair(origProtectedData.expirableMessage, sequenceNumberManipulated));
byte[] hashOfDataAndSeqNr = Hash.getHash(new P2PDataStorage.DataAndSeqNrPair(origProtectedData.expirablePayload, sequenceNumberManipulated));
byte[] signature = Sig.sign(msgSignatureKeyPairAdversary.getPrivate(), hashOfDataAndSeqNr);
protectedDataManipulated = new ProtectedData(origProtectedData.expirableMessage, origProtectedData.ttl, msgSignatureKeyPairAdversary.getPublic(), sequenceNumberManipulated, signature);
Assert.assertFalse(p2PService3.removeData(protectedDataManipulated.expirableMessage));
protectedDataManipulated = new ProtectedData(origProtectedData.expirablePayload, origProtectedData.ttl, msgSignatureKeyPairAdversary.getPublic(), sequenceNumberManipulated, signature);
Assert.assertFalse(p2PService3.removeData(protectedDataManipulated.expirablePayload));
Thread.sleep(sleepTime);
Assert.assertEquals(1, p2PService1.getDataMap().size());
Assert.assertEquals(1, p2PService2.getDataMap().size());
@ -204,8 +204,8 @@ public class P2PServiceTest {
sequenceNumberManipulated = 0;
hashOfDataAndSeqNr = Hash.getHash(new P2PDataStorage.DataAndSeqNrPair(manipulatedData, sequenceNumberManipulated));
signature = Sig.sign(msgSignatureKeyPairAdversary.getPrivate(), hashOfDataAndSeqNr);
protectedDataManipulated = new ProtectedData(origProtectedData.expirableMessage, origProtectedData.ttl, msgSignatureKeyPairAdversary.getPublic(), sequenceNumberManipulated, signature);
Assert.assertFalse(p2PService3.addData(protectedDataManipulated.expirableMessage));
protectedDataManipulated = new ProtectedData(origProtectedData.expirablePayload, origProtectedData.ttl, msgSignatureKeyPairAdversary.getPublic(), sequenceNumberManipulated, signature);
Assert.assertFalse(p2PService3.addData(protectedDataManipulated.expirablePayload));
Thread.sleep(sleepTime);
Assert.assertEquals(0, p2PService1.getDataMap().size());
Assert.assertEquals(0, p2PService2.getDataMap().size());
@ -216,8 +216,8 @@ public class P2PServiceTest {
sequenceNumberManipulated = 0;
hashOfDataAndSeqNr = Hash.getHash(new P2PDataStorage.DataAndSeqNrPair(manipulatedData, sequenceNumberManipulated));
signature = Sig.sign(msgSignatureKeyPairAdversary.getPrivate(), hashOfDataAndSeqNr);
protectedDataManipulated = new ProtectedData(origProtectedData.expirableMessage, origProtectedData.ttl, msgSignatureKeyPairAdversary.getPublic(), sequenceNumberManipulated, signature);
Assert.assertFalse(p2PService3.addData(protectedDataManipulated.expirableMessage));
protectedDataManipulated = new ProtectedData(origProtectedData.expirablePayload, origProtectedData.ttl, msgSignatureKeyPairAdversary.getPublic(), sequenceNumberManipulated, signature);
Assert.assertFalse(p2PService3.addData(protectedDataManipulated.expirablePayload));
Thread.sleep(sleepTime);
Assert.assertEquals(0, p2PService1.getDataMap().size());
Assert.assertEquals(0, p2PService2.getDataMap().size());
@ -230,7 +230,7 @@ public class P2PServiceTest {
hashOfDataAndSeqNr = Hash.getHash(new P2PDataStorage.DataAndSeqNrPair(manipulatedData, sequenceNumberManipulated));
signature = Sig.sign(msgSignatureKeyPairAdversary.getPrivate(), hashOfDataAndSeqNr);
protectedDataManipulated = new ProtectedData(manipulatedData, origProtectedData.ttl, msgSignatureKeyPairAdversary.getPublic(), sequenceNumberManipulated, signature);
Assert.assertTrue(p2PService3.addData(protectedDataManipulated.expirableMessage));
Assert.assertTrue(p2PService3.addData(protectedDataManipulated.expirablePayload));
Thread.sleep(sleepTime);
Assert.assertEquals(1, p2PService1.getDataMap().size());
Assert.assertEquals(1, p2PService2.getDataMap().size());
@ -249,8 +249,8 @@ public class P2PServiceTest {
sequenceNumberManipulated = 0;
hashOfDataAndSeqNr = Hash.getHash(new P2PDataStorage.DataAndSeqNrPair(manipulatedData, sequenceNumberManipulated));
signature = Sig.sign(msgSignatureKeyPairAdversary.getPrivate(), hashOfDataAndSeqNr);
protectedDataManipulated = new ProtectedData(origProtectedData.expirableMessage, origProtectedData.ttl, msgSignatureKeyPairAdversary.getPublic(), sequenceNumberManipulated, signature);
Assert.assertFalse(p2PService3.addData(protectedDataManipulated.expirableMessage));
protectedDataManipulated = new ProtectedData(origProtectedData.expirablePayload, origProtectedData.ttl, msgSignatureKeyPairAdversary.getPublic(), sequenceNumberManipulated, signature);
Assert.assertFalse(p2PService3.addData(protectedDataManipulated.expirablePayload));
Thread.sleep(sleepTime);
Assert.assertEquals(0, p2PService1.getDataMap().size());
Assert.assertEquals(0, p2PService2.getDataMap().size());
@ -261,14 +261,14 @@ public class P2PServiceTest {
hashOfDataAndSeqNr = Hash.getHash(new P2PDataStorage.DataAndSeqNrPair(manipulatedData, sequenceNumberManipulated));
signature = Sig.sign(msgSignatureKeyPairAdversary.getPrivate(), hashOfDataAndSeqNr);
protectedDataManipulated = new ProtectedData(manipulatedData, origProtectedData.ttl, msgSignatureKeyPairAdversary.getPublic(), sequenceNumberManipulated, signature);
Assert.assertTrue(p2PService3.addData(protectedDataManipulated.expirableMessage));
Assert.assertTrue(p2PService3.addData(protectedDataManipulated.expirablePayload));
Thread.sleep(sleepTime);
Assert.assertEquals(1, p2PService1.getDataMap().size());
Assert.assertEquals(1, p2PService2.getDataMap().size());
Assert.assertEquals(1, p2PService3.getDataMap().size());
// lets reset map
Assert.assertTrue(p2PService3.removeData(protectedDataManipulated.expirableMessage));
Assert.assertTrue(p2PService3.removeData(protectedDataManipulated.expirablePayload));
Thread.sleep(sleepTime);
Assert.assertEquals(0, p2PService1.getDataMap().size());
Assert.assertEquals(0, p2PService2.getDataMap().size());
@ -289,7 +289,7 @@ public class P2PServiceTest {
// send to online peer
CountDownLatch latch2 = new CountDownLatch(2);
MockMailboxMessage mockMessage = new MockMailboxMessage("MockMailboxMessage", p2PService2.getAddress());
MockMailboxPayload mockMessage = new MockMailboxPayload("MockMailboxMessage", p2PService2.getAddress());
p2PService2.getNetworkNode().addMessageListener((message, connection) -> {
log.trace("message " + message);
if (message instanceof PrefixedSealedAndSignedMessage) {
@ -336,7 +336,7 @@ public class P2PServiceTest {
LocalhostNetworkNode.setSimulateTorDelayHiddenService(0);
// send msg to offline peer
MockMailboxMessage mockMessage = new MockMailboxMessage(
MockMailboxPayload mockMessage = new MockMailboxPayload(
"MockMailboxMessage",
p2PService2.getAddress()
);

View file

@ -3,15 +3,15 @@ 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.ExpirableMessage;
import io.bitsquare.p2p.storage.messages.ExpirablePayload;
public final class MockMailboxMessage implements MailboxMessage, ExpirableMessage {
public final class MockMailboxPayload implements MailboxMessage, ExpirablePayload {
private final int messageVersion = Version.getP2PMessageVersion();
public final String msg;
public final NodeAddress senderNodeAddress;
public long ttl;
public MockMailboxMessage(String msg, NodeAddress senderNodeAddress) {
public MockMailboxPayload(String msg, NodeAddress senderNodeAddress) {
this.msg = msg;
this.senderNodeAddress = senderNodeAddress;
}
@ -24,9 +24,9 @@ public final class MockMailboxMessage implements MailboxMessage, ExpirableMessag
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof MockMailboxMessage)) return false;
if (!(o instanceof MockMailboxPayload)) return false;
MockMailboxMessage that = (MockMailboxMessage) o;
MockMailboxPayload that = (MockMailboxPayload) o;
return !(msg != null ? !msg.equals(that.msg) : that.msg != null);

View file

@ -2,14 +2,14 @@ package io.bitsquare.p2p.mocks;
import io.bitsquare.app.Version;
import io.bitsquare.p2p.Message;
import io.bitsquare.p2p.storage.messages.ExpirableMessage;
import io.bitsquare.p2p.storage.messages.ExpirablePayload;
public final class MockMessage implements Message, ExpirableMessage {
public final class MockPayload implements Message, ExpirablePayload {
public final String msg;
public long ttl;
private final int messageVersion = Version.getP2PMessageVersion();
public MockMessage(String msg) {
public MockPayload(String msg) {
this.msg = msg;
}
@ -21,9 +21,9 @@ public final class MockMessage implements Message, ExpirableMessage {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof MockMessage)) return false;
if (!(o instanceof MockPayload)) return false;
MockMessage that = (MockMessage) o;
MockPayload that = (MockPayload) o;
return !(msg != null ? !msg.equals(that.msg) : that.msg != null);

View file

@ -4,7 +4,7 @@ import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.SettableFuture;
import io.bitsquare.p2p.Message;
import io.bitsquare.p2p.mocks.MockMessage;
import io.bitsquare.p2p.mocks.MockPayload;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.junit.Before;
import org.junit.Ignore;
@ -87,7 +87,7 @@ public class TorNetworkNodeTest {
latch.countDown();
}
});
SettableFuture<Connection> future = node2.sendMessage(node1.getNodeAddress(), new MockMessage("msg1"));
SettableFuture<Connection> future = node2.sendMessage(node1.getNodeAddress(), new MockPayload("msg1"));
Futures.addCallback(future, new FutureCallback<Connection>() {
@Override
public void onSuccess(Connection connection) {
@ -166,7 +166,7 @@ public class TorNetworkNodeTest {
latch.countDown();
}
});
SettableFuture<Connection> future = node1.sendMessage(node2.getNodeAddress(), new MockMessage("msg1"));
SettableFuture<Connection> future = node1.sendMessage(node2.getNodeAddress(), new MockPayload("msg1"));
Futures.addCallback(future, new FutureCallback<Connection>() {
@Override
public void onSuccess(Connection connection) {

View file

@ -105,9 +105,9 @@ public class ProtectedDataStorageTest {
Assert.assertEquals(1, dataStorage1.getMap().size());
int newSequenceNumber = data.sequenceNumber + 1;
byte[] hashOfDataAndSeqNr = Hash.getHash(new P2PDataStorage.DataAndSeqNrPair(data.expirableMessage, newSequenceNumber));
byte[] hashOfDataAndSeqNr = Hash.getHash(new P2PDataStorage.DataAndSeqNrPair(data.expirablePayload, newSequenceNumber));
byte[] signature = Sig.sign(storageSignatureKeyPair1.getPrivate(), hashOfDataAndSeqNr);
ProtectedData dataToRemove = new ProtectedData(data.expirableMessage, data.ttl, data.ownerPubKey, newSequenceNumber, signature);
ProtectedData dataToRemove = new ProtectedData(data.expirablePayload, data.ttl, data.ownerPubKey, newSequenceNumber, signature);
Assert.assertTrue(dataStorage1.remove(dataToRemove, null));
Assert.assertEquals(0, dataStorage1.getMap().size());
}

View file

@ -1,10 +1,10 @@
package io.bitsquare.p2p.storage.mocks;
import io.bitsquare.p2p.storage.messages.StorageMessage;
import io.bitsquare.p2p.storage.messages.StoragePayload;
import java.security.PublicKey;
public class MockData implements StorageMessage {
public class MockData implements StoragePayload {
public final String msg;
public final PublicKey publicKey;
public long ttl;