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; package io.bitsquare.alert;
import io.bitsquare.app.Version; 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.security.PublicKey;
import java.util.concurrent.TimeUnit; 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. // 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 long serialVersionUID = Version.P2P_NETWORK_VERSION;

View file

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

View file

@ -20,7 +20,7 @@ package io.bitsquare.arbitration;
import io.bitsquare.app.Version; import io.bitsquare.app.Version;
import io.bitsquare.common.crypto.PubKeyRing; import io.bitsquare.common.crypto.PubKeyRing;
import io.bitsquare.p2p.NodeAddress; 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.security.PublicKey;
import java.util.Arrays; import java.util.Arrays;
@ -28,7 +28,7 @@ import java.util.Date;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit; 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. // 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 long serialVersionUID = Version.P2P_NETWORK_VERSION;

View file

@ -84,8 +84,8 @@ public class ArbitratorService {
public Map<NodeAddress, Arbitrator> getArbitrators() { public Map<NodeAddress, Arbitrator> getArbitrators() {
Set<Arbitrator> arbitratorSet = p2PService.getDataMap().values().stream() Set<Arbitrator> arbitratorSet = p2PService.getDataMap().values().stream()
.filter(data -> data.expirableMessage instanceof Arbitrator) .filter(data -> data.expirablePayload instanceof Arbitrator)
.map(data -> (Arbitrator) data.expirableMessage) .map(data -> (Arbitrator) data.expirablePayload)
.collect(Collectors.toSet()); .collect(Collectors.toSet());
Map<NodeAddress, Arbitrator> map = new HashMap<>(); 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.locale.Country;
import io.bitsquare.p2p.NodeAddress; import io.bitsquare.p2p.NodeAddress;
import io.bitsquare.p2p.storage.messages.RequiresOwnerIsOnlinePayload; 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.payment.PaymentMethod;
import io.bitsquare.trade.protocol.availability.OfferAvailabilityModel; import io.bitsquare.trade.protocol.availability.OfferAvailabilityModel;
import io.bitsquare.trade.protocol.availability.OfferAvailabilityProtocol; 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.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull; 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. // That object is sent over the wire, so we need to take care of version compatibility.
@JsonExclude @JsonExclude
private static final long serialVersionUID = Version.P2P_NETWORK_VERSION; private static final long serialVersionUID = Version.P2P_NETWORK_VERSION;

View file

@ -60,16 +60,16 @@ public class OfferBookService {
@Override @Override
public void onAdded(ProtectedData data) { public void onAdded(ProtectedData data) {
offerBookChangedListeners.stream().forEach(listener -> { offerBookChangedListeners.stream().forEach(listener -> {
if (data.expirableMessage instanceof Offer) if (data.expirablePayload instanceof Offer)
listener.onAdded((Offer) data.expirableMessage); listener.onAdded((Offer) data.expirablePayload);
}); });
} }
@Override @Override
public void onRemoved(ProtectedData data) { public void onRemoved(ProtectedData data) {
offerBookChangedListeners.stream().forEach(listener -> { offerBookChangedListeners.stream().forEach(listener -> {
if (data.expirableMessage instanceof Offer) if (data.expirablePayload instanceof Offer)
listener.onRemoved((Offer) data.expirableMessage); listener.onRemoved((Offer) data.expirablePayload);
}); });
} }
}); });
@ -126,8 +126,8 @@ public class OfferBookService {
public List<Offer> getOffers() { public List<Offer> getOffers() {
return p2PService.getDataMap().values().stream() return p2PService.getDataMap().values().stream()
.filter(data -> data.expirableMessage instanceof Offer) .filter(data -> data.expirablePayload instanceof Offer)
.map(data -> (Offer) data.expirableMessage) .map(data -> (Offer) data.expirablePayload)
.collect(Collectors.toList()); .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.ProtectedMailboxData;
import io.bitsquare.p2p.storage.data.RefreshTTLBundle; import io.bitsquare.p2p.storage.data.RefreshTTLBundle;
import io.bitsquare.p2p.storage.messages.AddDataMessage; import io.bitsquare.p2p.storage.messages.AddDataMessage;
import io.bitsquare.p2p.storage.messages.ExpirableMessage; import io.bitsquare.p2p.storage.messages.ExpirablePayload;
import io.bitsquare.p2p.storage.messages.MailboxMessage; import io.bitsquare.p2p.storage.messages.MailboxPayload;
import javafx.beans.property.*; import javafx.beans.property.*;
import javafx.beans.value.ChangeListener; import javafx.beans.value.ChangeListener;
import org.fxmisc.easybind.EasyBind; import org.fxmisc.easybind.EasyBind;
@ -432,9 +432,9 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
// Seed nodes don't have set the encryptionService // Seed nodes don't have set the encryptionService
if (optionalEncryptionService.isPresent()) { if (optionalEncryptionService.isPresent()) {
Log.traceCall(); Log.traceCall();
ExpirableMessage expirableMessage = mailboxData.expirableMessage; ExpirablePayload expirablePayload = mailboxData.expirablePayload;
if (expirableMessage instanceof MailboxMessage) { if (expirablePayload instanceof MailboxPayload) {
MailboxMessage expirableMailboxPayload = (MailboxMessage) expirableMessage; MailboxPayload expirableMailboxPayload = (MailboxPayload) expirablePayload;
PrefixedSealedAndSignedMessage prefixedSealedAndSignedMessage = expirableMailboxPayload.prefixedSealedAndSignedMessage; PrefixedSealedAndSignedMessage prefixedSealedAndSignedMessage = expirableMailboxPayload.prefixedSealedAndSignedMessage;
if (verifyAddressPrefixHash(prefixedSealedAndSignedMessage)) { if (verifyAddressPrefixHash(prefixedSealedAndSignedMessage)) {
try { 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.info("We cannot send message to peer. Peer might be offline. We will store message in mailbox.");
log.trace("create MailboxEntry with peerAddress " + peersNodeAddress); log.trace("create MailboxEntry with peerAddress " + peersNodeAddress);
PublicKey receiverStoragePublicKey = peersPubKeyRing.getSignaturePubKey(); PublicKey receiverStoragePublicKey = peersPubKeyRing.getSignaturePubKey();
addMailboxData(new MailboxMessage(prefixedSealedAndSignedMessage, addMailboxData(new MailboxPayload(prefixedSealedAndSignedMessage,
optionalKeyRing.get().getSignatureKeyPair().getPublic(), optionalKeyRing.get().getSignatureKeyPair().getPublic(),
receiverStoragePublicKey), receiverStoragePublicKey),
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, PublicKey receiversPublicKey,
SendMailboxMessageListener sendMailboxMessageListener) { SendMailboxMessageListener sendMailboxMessageListener) {
Log.traceCall(); Log.traceCall();
@ -598,8 +598,8 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
if (isBootstrapped()) { if (isBootstrapped()) {
if (mailboxMap.containsKey(decryptedMsgWithPubKey)) { if (mailboxMap.containsKey(decryptedMsgWithPubKey)) {
ProtectedMailboxData mailboxData = mailboxMap.get(decryptedMsgWithPubKey); ProtectedMailboxData mailboxData = mailboxMap.get(decryptedMsgWithPubKey);
if (mailboxData != null && mailboxData.expirableMessage instanceof MailboxMessage) { if (mailboxData != null && mailboxData.expirablePayload instanceof MailboxPayload) {
MailboxMessage expirableMailboxPayload = (MailboxMessage) mailboxData.expirableMessage; MailboxPayload expirableMailboxPayload = (MailboxPayload) mailboxData.expirablePayload;
PublicKey receiversPubKey = mailboxData.receiversPubKey; PublicKey receiversPubKey = mailboxData.receiversPubKey;
checkArgument(receiversPubKey.equals(optionalKeyRing.get().getSignatureKeyPair().getPublic()), checkArgument(receiversPubKey.equals(optionalKeyRing.get().getSignatureKeyPair().getPublic()),
"receiversPubKey is not matching with our key. That must not happen."); "receiversPubKey is not matching with our key. That must not happen.");
@ -631,16 +631,16 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
// Data storage // Data storage
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
public boolean addData(ExpirableMessage expirableMessage) { public boolean addData(ExpirablePayload expirablePayload) {
return addData(expirableMessage, false); return addData(expirablePayload, false);
} }
public boolean addData(ExpirableMessage expirableMessage, boolean forceBroadcast) { public boolean addData(ExpirablePayload expirablePayload, boolean forceBroadcast) {
Log.traceCall(); Log.traceCall();
checkArgument(optionalKeyRing.isPresent(), "keyRing not set. Seems that is called on a seed node which must not happen."); checkArgument(optionalKeyRing.isPresent(), "keyRing not set. Seems that is called on a seed node which must not happen.");
if (isBootstrapped()) { if (isBootstrapped()) {
try { try {
ProtectedData protectedData = p2PDataStorage.getProtectedData(expirableMessage, optionalKeyRing.get().getSignatureKeyPair()); ProtectedData protectedData = p2PDataStorage.getProtectedData(expirablePayload, optionalKeyRing.get().getSignatureKeyPair());
return p2PDataStorage.add(protectedData, networkNode.getNodeAddress(), forceBroadcast); return p2PDataStorage.add(protectedData, networkNode.getNodeAddress(), forceBroadcast);
} catch (CryptoException e) { } catch (CryptoException e) {
log.error("Signing at getDataWithSignedSeqNr failed. That should never happen."); 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(); Log.traceCall();
checkArgument(optionalKeyRing.isPresent(), "keyRing not set. Seems that is called on a seed node which must not happen."); checkArgument(optionalKeyRing.isPresent(), "keyRing not set. Seems that is called on a seed node which must not happen.");
if (isBootstrapped()) { if (isBootstrapped()) {
try { try {
RefreshTTLBundle refreshTTLBundle = p2PDataStorage.getRefreshTTLPackage(expirableMessage, optionalKeyRing.get().getSignatureKeyPair()); RefreshTTLBundle refreshTTLBundle = p2PDataStorage.getRefreshTTLPackage(expirablePayload, optionalKeyRing.get().getSignatureKeyPair());
return p2PDataStorage.refreshTTL(refreshTTLBundle, networkNode.getNodeAddress()); return p2PDataStorage.refreshTTL(refreshTTLBundle, networkNode.getNodeAddress());
} catch (CryptoException e) { } catch (CryptoException e) {
log.error("Signing at getDataWithSignedSeqNr failed. That should never happen."); 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(); Log.traceCall();
checkArgument(optionalKeyRing.isPresent(), "keyRing not set. Seems that is called on a seed node which must not happen."); checkArgument(optionalKeyRing.isPresent(), "keyRing not set. Seems that is called on a seed node which must not happen.");
if (isBootstrapped()) { if (isBootstrapped()) {
try { try {
ProtectedData protectedData = p2PDataStorage.getProtectedData(expirableMessage, optionalKeyRing.get().getSignatureKeyPair()); ProtectedData protectedData = p2PDataStorage.getProtectedData(expirablePayload, optionalKeyRing.get().getSignatureKeyPair());
return p2PDataStorage.remove(protectedData, networkNode.getNodeAddress()); return p2PDataStorage.remove(protectedData, networkNode.getNodeAddress());
} catch (CryptoException e) { } catch (CryptoException e) {
log.error("Signing at getDataWithSignedSeqNr failed. That should never happen."); 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) { if (connection.getPeersNodeAddressOptional().isPresent() && !closeConnectionReason.isIntended) {
map.values().stream() map.values().stream()
.forEach(protectedData -> { .forEach(protectedData -> {
ExpirableMessage expirableMessage = protectedData.expirableMessage; ExpirablePayload expirablePayload = protectedData.expirablePayload;
if (expirableMessage instanceof RequiresOwnerIsOnlinePayload) { if (expirablePayload instanceof RequiresOwnerIsOnlinePayload) {
RequiresOwnerIsOnlinePayload requiresOwnerIsOnlinePayload = (RequiresOwnerIsOnlinePayload) expirableMessage; RequiresOwnerIsOnlinePayload requiresOwnerIsOnlinePayload = (RequiresOwnerIsOnlinePayload) expirablePayload;
NodeAddress ownerNodeAddress = requiresOwnerIsOnlinePayload.getOwnerNodeAddress(); NodeAddress ownerNodeAddress = requiresOwnerIsOnlinePayload.getOwnerNodeAddress();
if (ownerNodeAddress.equals(connection.getPeersNodeAddressOptional().get())) { if (ownerNodeAddress.equals(connection.getPeersNodeAddressOptional().get())) {
// We have a RequiresLiveOwnerData data object with the node address of the // We have a RequiresLiveOwnerData data object with the node address of the
// disconnected peer. We remove that data from our map. // disconnected peer. We remove that data from our map.
// Check if we have the data (e.g. Offer) // Check if we have the data (e.g. Offer)
ByteArray hashOfPayload = getHashAsByteArray(expirableMessage); ByteArray hashOfPayload = getHashAsByteArray(expirablePayload);
boolean containsKey = map.containsKey(hashOfPayload); boolean containsKey = map.containsKey(hashOfPayload);
if (containsKey) { if (containsKey) {
doRemoveProtectedExpirableData(protectedData, hashOfPayload); doRemoveProtectedExpirableData(protectedData, hashOfPayload);
@ -180,7 +180,7 @@ public class P2PDataStorage implements MessageListener, ConnectionListener {
public boolean add(ProtectedData protectedData, @Nullable NodeAddress sender, boolean forceBroadcast) { public boolean add(ProtectedData protectedData, @Nullable NodeAddress sender, boolean forceBroadcast) {
Log.traceCall(); Log.traceCall();
ByteArray hashOfPayload = getHashAsByteArray(protectedData.expirableMessage); ByteArray hashOfPayload = getHashAsByteArray(protectedData.expirablePayload);
boolean result = checkPublicKeys(protectedData, true) boolean result = checkPublicKeys(protectedData, true)
&& checkSignature(protectedData) && checkSignature(protectedData)
&& isSequenceNrValid(protectedData.sequenceNumber, hashOfPayload); && isSequenceNrValid(protectedData.sequenceNumber, hashOfPayload);
@ -266,7 +266,7 @@ public class P2PDataStorage implements MessageListener, ConnectionListener {
public boolean remove(ProtectedData protectedData, @Nullable NodeAddress sender) { public boolean remove(ProtectedData protectedData, @Nullable NodeAddress sender) {
Log.traceCall(); Log.traceCall();
ByteArray hashOfPayload = getHashAsByteArray(protectedData.expirableMessage); ByteArray hashOfPayload = getHashAsByteArray(protectedData.expirablePayload);
boolean containsKey = map.containsKey(hashOfPayload); boolean containsKey = map.containsKey(hashOfPayload);
if (!containsKey) log.debug("Remove data ignored as we don't have an entry for that data."); if (!containsKey) log.debug("Remove data ignored as we don't have an entry for that data.");
boolean result = containsKey boolean result = containsKey
@ -291,7 +291,7 @@ public class P2PDataStorage implements MessageListener, ConnectionListener {
public boolean removeMailboxData(ProtectedMailboxData protectedMailboxData, @Nullable NodeAddress sender) { public boolean removeMailboxData(ProtectedMailboxData protectedMailboxData, @Nullable NodeAddress sender) {
Log.traceCall(); Log.traceCall();
ByteArray hashOfData = getHashAsByteArray(protectedMailboxData.expirableMessage); ByteArray hashOfData = getHashAsByteArray(protectedMailboxData.expirablePayload);
boolean containsKey = map.containsKey(hashOfData); boolean containsKey = map.containsKey(hashOfData);
if (!containsKey) log.debug("Remove data ignored as we don't have an entry for that data."); if (!containsKey) log.debug("Remove data ignored as we don't have an entry for that data.");
boolean result = containsKey boolean result = containsKey
@ -319,7 +319,7 @@ public class P2PDataStorage implements MessageListener, ConnectionListener {
return map; return map;
} }
public ProtectedData getProtectedData(ExpirableMessage payload, KeyPair ownerStoragePubKey) public ProtectedData getProtectedData(ExpirablePayload payload, KeyPair ownerStoragePubKey)
throws CryptoException { throws CryptoException {
ByteArray hashOfData = getHashAsByteArray(payload); ByteArray hashOfData = getHashAsByteArray(payload);
int sequenceNumber; int sequenceNumber;
@ -333,7 +333,7 @@ public class P2PDataStorage implements MessageListener, ConnectionListener {
return new ProtectedData(payload, payload.getTTL(), ownerStoragePubKey.getPublic(), sequenceNumber, signature); 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 { throws CryptoException {
ByteArray hashOfPayload = getHashAsByteArray(payload); ByteArray hashOfPayload = getHashAsByteArray(payload);
int sequenceNumber; int sequenceNumber;
@ -348,7 +348,7 @@ public class P2PDataStorage implements MessageListener, ConnectionListener {
return new RefreshTTLBundle(ownerPubKey, hashOfDataAndSeqNr, signature, hashOfPayload.bytes, sequenceNumber); return new RefreshTTLBundle(ownerPubKey, hashOfDataAndSeqNr, signature, hashOfPayload.bytes, sequenceNumber);
} }
public ProtectedMailboxData getMailboxDataWithSignedSeqNr(MailboxMessage expirableMailboxPayload, public ProtectedMailboxData getMailboxDataWithSignedSeqNr(MailboxPayload expirableMailboxPayload,
KeyPair storageSignaturePubKey, PublicKey receiversPublicKey) KeyPair storageSignaturePubKey, PublicKey receiversPublicKey)
throws CryptoException { throws CryptoException {
ByteArray hashOfData = getHashAsByteArray(expirableMailboxPayload); ByteArray hashOfData = getHashAsByteArray(expirableMailboxPayload);
@ -416,20 +416,20 @@ public class P2PDataStorage implements MessageListener, ConnectionListener {
} }
private boolean checkSignature(ProtectedData data) { 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); return checkSignature(data.ownerPubKey, hashOfDataAndSeqNr, data.signature);
} }
private boolean checkPublicKeys(ProtectedData data, boolean isAddOperation) { private boolean checkPublicKeys(ProtectedData data, boolean isAddOperation) {
boolean result = false; boolean result = false;
if (data.expirableMessage instanceof MailboxMessage) { if (data.expirablePayload instanceof MailboxPayload) {
MailboxMessage expirableMailboxPayload = (MailboxMessage) data.expirableMessage; MailboxPayload expirableMailboxPayload = (MailboxPayload) data.expirablePayload;
if (isAddOperation) if (isAddOperation)
result = expirableMailboxPayload.senderPubKeyForAddOperation.equals(data.ownerPubKey); result = expirableMailboxPayload.senderPubKeyForAddOperation.equals(data.ownerPubKey);
else else
result = expirableMailboxPayload.receiverPubKeyForRemoveOperation.equals(data.ownerPubKey); result = expirableMailboxPayload.receiverPubKeyForRemoveOperation.equals(data.ownerPubKey);
} else if (data.expirableMessage instanceof StorageMessage) { } else if (data.expirablePayload instanceof StoragePayload) {
result = ((StorageMessage) data.expirableMessage).getOwnerPubKey().equals(data.ownerPubKey); result = ((StoragePayload) data.expirablePayload).getOwnerPubKey().equals(data.ownerPubKey);
} }
if (!result) if (!result)
@ -456,7 +456,7 @@ public class P2PDataStorage implements MessageListener, ConnectionListener {
ProtectedMailboxData storedMailboxData = (ProtectedMailboxData) storedData; ProtectedMailboxData storedMailboxData = (ProtectedMailboxData) storedData;
// publicKey is not the same (stored: sender, new: receiver) // publicKey is not the same (stored: sender, new: receiver)
boolean result = storedMailboxData.receiversPubKey.equals(receiversPubKey) boolean result = storedMailboxData.receiversPubKey.equals(receiversPubKey)
&& getHashAsByteArray(storedMailboxData.expirableMessage).equals(hashOfData); && getHashAsByteArray(storedMailboxData.expirablePayload).equals(hashOfData);
if (!result) if (!result)
log.error("New data entry does not match our stored data. Consider it might be an attempt of fraud"); 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); broadcaster.broadcast(message, sender);
} }
private ByteArray getHashAsByteArray(ExpirableMessage data) { private ByteArray getHashAsByteArray(ExpirablePayload data) {
return new ByteArray(Hash.getHash(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 com.google.common.annotations.VisibleForTesting;
import io.bitsquare.p2p.storage.P2PDataStorage; 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.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -15,7 +15,7 @@ import java.util.Date;
public class ProtectedData implements Serializable { public class ProtectedData implements Serializable {
private static final Logger log = LoggerFactory.getLogger(P2PDataStorage.class); 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() //TODO check if that field make sense as it is in expirableMessage.getTTL()
transient public long ttl; transient public long ttl;
@ -26,8 +26,8 @@ public class ProtectedData implements Serializable {
@VisibleForTesting @VisibleForTesting
transient public Date date; transient public Date date;
public ProtectedData(ExpirableMessage expirableMessage, long ttl, PublicKey ownerPubKey, int sequenceNumber, byte[] signature) { public ProtectedData(ExpirablePayload expirablePayload, long ttl, PublicKey ownerPubKey, int sequenceNumber, byte[] signature) {
this.expirableMessage = expirableMessage; this.expirablePayload = expirablePayload;
this.ttl = ttl; this.ttl = ttl;
this.ownerPubKey = ownerPubKey; this.ownerPubKey = ownerPubKey;
this.sequenceNumber = sequenceNumber; this.sequenceNumber = sequenceNumber;
@ -38,7 +38,7 @@ public class ProtectedData implements Serializable {
private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException { private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException {
try { try {
in.defaultReadObject(); in.defaultReadObject();
ttl = expirableMessage.getTTL(); ttl = expirablePayload.getTTL();
date = new Date(); date = new Date();
} catch (Throwable t) { } catch (Throwable t) {
@ -58,7 +58,7 @@ public class ProtectedData implements Serializable {
@Override @Override
public String toString() { public String toString() {
return "ProtectedData{" + return "ProtectedData{" +
"expirablePayload=" + expirableMessage + "expirablePayload=" + expirablePayload +
", ttl=" + ttl + ", ttl=" + ttl +
", date=" + date + ", date=" + date +
", sequenceNumber=" + sequenceNumber + ", sequenceNumber=" + sequenceNumber +

View file

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

View file

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

View file

@ -16,7 +16,7 @@ import java.util.concurrent.TimeUnit;
* <p> * <p>
* Typical payloads are trade or dispute messages to be stored when the peer is offline. * 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. // 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 long serialVersionUID = Version.P2P_NETWORK_VERSION;
@ -45,7 +45,7 @@ public final class MailboxMessage implements ExpirableMessage {
*/ */
public final PublicKey receiverPubKeyForRemoveOperation; public final PublicKey receiverPubKeyForRemoveOperation;
public MailboxMessage(PrefixedSealedAndSignedMessage prefixedSealedAndSignedMessage, PublicKey senderPubKeyForAddOperation, PublicKey receiverPubKeyForRemoveOperation) { public MailboxPayload(PrefixedSealedAndSignedMessage prefixedSealedAndSignedMessage, PublicKey senderPubKeyForAddOperation, PublicKey receiverPubKeyForRemoveOperation) {
this.prefixedSealedAndSignedMessage = prefixedSealedAndSignedMessage; this.prefixedSealedAndSignedMessage = prefixedSealedAndSignedMessage;
this.senderPubKeyForAddOperation = senderPubKeyForAddOperation; this.senderPubKeyForAddOperation = senderPubKeyForAddOperation;
this.receiverPubKeyForRemoveOperation = receiverPubKeyForRemoveOperation; this.receiverPubKeyForRemoveOperation = receiverPubKeyForRemoveOperation;
@ -59,9 +59,9 @@ public final class MailboxMessage implements ExpirableMessage {
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; 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); 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.arbitration.Arbitrator
* io.bitsquare.trade.offer.Offer * 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. * Used for check if the add or remove operation is permitted.
* Only data owner can add or remove the data. * 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.DecryptedMsgWithPubKey;
import io.bitsquare.p2p.messaging.MailboxMessage; import io.bitsquare.p2p.messaging.MailboxMessage;
import io.bitsquare.p2p.messaging.SendMailboxMessageListener; 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.network.LocalhostNetworkNode;
import io.bitsquare.p2p.peers.PeerManager; import io.bitsquare.p2p.peers.PeerManager;
import io.bitsquare.p2p.seed.SeedNode; import io.bitsquare.p2p.seed.SeedNode;
@ -163,16 +163,16 @@ public class P2PServiceTest {
.map(data -> (ProtectedData) data) .map(data -> (ProtectedData) data)
.collect(Collectors.toSet()); .collect(Collectors.toSet());
ProtectedData origProtectedData = dataSet.stream().findFirst().get(); ProtectedData origProtectedData = dataSet.stream().findFirst().get();
ProtectedData protectedDataManipulated = new ProtectedData(origProtectedData.expirableMessage, origProtectedData.ttl, origProtectedData.ownerPubKey, origProtectedData.sequenceNumber + 1, origProtectedData.signature); ProtectedData protectedDataManipulated = new ProtectedData(origProtectedData.expirablePayload, origProtectedData.ttl, origProtectedData.ownerPubKey, origProtectedData.sequenceNumber + 1, origProtectedData.signature);
Assert.assertFalse(p2PService3.removeData(protectedDataManipulated.expirableMessage)); Assert.assertFalse(p2PService3.removeData(protectedDataManipulated.expirablePayload));
Thread.sleep(sleepTime); Thread.sleep(sleepTime);
Assert.assertEquals(1, p2PService1.getDataMap().size()); Assert.assertEquals(1, p2PService1.getDataMap().size());
Assert.assertEquals(1, p2PService2.getDataMap().size()); Assert.assertEquals(1, p2PService2.getDataMap().size());
Assert.assertEquals(1, p2PService3.getDataMap().size()); Assert.assertEquals(1, p2PService3.getDataMap().size());
// try to manipulate seq nr. + pubKey -> fails // try to manipulate seq nr. + pubKey -> fails
protectedDataManipulated = new ProtectedData(origProtectedData.expirableMessage, origProtectedData.ttl, msgSignatureKeyPairAdversary.getPublic(), origProtectedData.sequenceNumber + 1, origProtectedData.signature); protectedDataManipulated = new ProtectedData(origProtectedData.expirablePayload, origProtectedData.ttl, msgSignatureKeyPairAdversary.getPublic(), origProtectedData.sequenceNumber + 1, origProtectedData.signature);
Assert.assertFalse(p2PService3.removeData(protectedDataManipulated.expirableMessage)); Assert.assertFalse(p2PService3.removeData(protectedDataManipulated.expirablePayload));
Thread.sleep(sleepTime); Thread.sleep(sleepTime);
Assert.assertEquals(1, p2PService1.getDataMap().size()); Assert.assertEquals(1, p2PService1.getDataMap().size());
Assert.assertEquals(1, p2PService2.getDataMap().size()); Assert.assertEquals(1, p2PService2.getDataMap().size());
@ -180,10 +180,10 @@ public class P2PServiceTest {
// try to manipulate seq nr. + pubKey + sig -> fails // try to manipulate seq nr. + pubKey + sig -> fails
int sequenceNumberManipulated = origProtectedData.sequenceNumber + 1; 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); byte[] signature = Sig.sign(msgSignatureKeyPairAdversary.getPrivate(), hashOfDataAndSeqNr);
protectedDataManipulated = new ProtectedData(origProtectedData.expirableMessage, origProtectedData.ttl, msgSignatureKeyPairAdversary.getPublic(), sequenceNumberManipulated, signature); protectedDataManipulated = new ProtectedData(origProtectedData.expirablePayload, origProtectedData.ttl, msgSignatureKeyPairAdversary.getPublic(), sequenceNumberManipulated, signature);
Assert.assertFalse(p2PService3.removeData(protectedDataManipulated.expirableMessage)); Assert.assertFalse(p2PService3.removeData(protectedDataManipulated.expirablePayload));
Thread.sleep(sleepTime); Thread.sleep(sleepTime);
Assert.assertEquals(1, p2PService1.getDataMap().size()); Assert.assertEquals(1, p2PService1.getDataMap().size());
Assert.assertEquals(1, p2PService2.getDataMap().size()); Assert.assertEquals(1, p2PService2.getDataMap().size());
@ -204,8 +204,8 @@ public class P2PServiceTest {
sequenceNumberManipulated = 0; sequenceNumberManipulated = 0;
hashOfDataAndSeqNr = Hash.getHash(new P2PDataStorage.DataAndSeqNrPair(manipulatedData, sequenceNumberManipulated)); hashOfDataAndSeqNr = Hash.getHash(new P2PDataStorage.DataAndSeqNrPair(manipulatedData, sequenceNumberManipulated));
signature = Sig.sign(msgSignatureKeyPairAdversary.getPrivate(), hashOfDataAndSeqNr); signature = Sig.sign(msgSignatureKeyPairAdversary.getPrivate(), hashOfDataAndSeqNr);
protectedDataManipulated = new ProtectedData(origProtectedData.expirableMessage, origProtectedData.ttl, msgSignatureKeyPairAdversary.getPublic(), sequenceNumberManipulated, signature); protectedDataManipulated = new ProtectedData(origProtectedData.expirablePayload, origProtectedData.ttl, msgSignatureKeyPairAdversary.getPublic(), sequenceNumberManipulated, signature);
Assert.assertFalse(p2PService3.addData(protectedDataManipulated.expirableMessage)); Assert.assertFalse(p2PService3.addData(protectedDataManipulated.expirablePayload));
Thread.sleep(sleepTime); Thread.sleep(sleepTime);
Assert.assertEquals(0, p2PService1.getDataMap().size()); Assert.assertEquals(0, p2PService1.getDataMap().size());
Assert.assertEquals(0, p2PService2.getDataMap().size()); Assert.assertEquals(0, p2PService2.getDataMap().size());
@ -216,8 +216,8 @@ public class P2PServiceTest {
sequenceNumberManipulated = 0; sequenceNumberManipulated = 0;
hashOfDataAndSeqNr = Hash.getHash(new P2PDataStorage.DataAndSeqNrPair(manipulatedData, sequenceNumberManipulated)); hashOfDataAndSeqNr = Hash.getHash(new P2PDataStorage.DataAndSeqNrPair(manipulatedData, sequenceNumberManipulated));
signature = Sig.sign(msgSignatureKeyPairAdversary.getPrivate(), hashOfDataAndSeqNr); signature = Sig.sign(msgSignatureKeyPairAdversary.getPrivate(), hashOfDataAndSeqNr);
protectedDataManipulated = new ProtectedData(origProtectedData.expirableMessage, origProtectedData.ttl, msgSignatureKeyPairAdversary.getPublic(), sequenceNumberManipulated, signature); protectedDataManipulated = new ProtectedData(origProtectedData.expirablePayload, origProtectedData.ttl, msgSignatureKeyPairAdversary.getPublic(), sequenceNumberManipulated, signature);
Assert.assertFalse(p2PService3.addData(protectedDataManipulated.expirableMessage)); Assert.assertFalse(p2PService3.addData(protectedDataManipulated.expirablePayload));
Thread.sleep(sleepTime); Thread.sleep(sleepTime);
Assert.assertEquals(0, p2PService1.getDataMap().size()); Assert.assertEquals(0, p2PService1.getDataMap().size());
Assert.assertEquals(0, p2PService2.getDataMap().size()); Assert.assertEquals(0, p2PService2.getDataMap().size());
@ -230,7 +230,7 @@ public class P2PServiceTest {
hashOfDataAndSeqNr = Hash.getHash(new P2PDataStorage.DataAndSeqNrPair(manipulatedData, sequenceNumberManipulated)); hashOfDataAndSeqNr = Hash.getHash(new P2PDataStorage.DataAndSeqNrPair(manipulatedData, sequenceNumberManipulated));
signature = Sig.sign(msgSignatureKeyPairAdversary.getPrivate(), hashOfDataAndSeqNr); signature = Sig.sign(msgSignatureKeyPairAdversary.getPrivate(), hashOfDataAndSeqNr);
protectedDataManipulated = new ProtectedData(manipulatedData, origProtectedData.ttl, msgSignatureKeyPairAdversary.getPublic(), sequenceNumberManipulated, signature); 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); Thread.sleep(sleepTime);
Assert.assertEquals(1, p2PService1.getDataMap().size()); Assert.assertEquals(1, p2PService1.getDataMap().size());
Assert.assertEquals(1, p2PService2.getDataMap().size()); Assert.assertEquals(1, p2PService2.getDataMap().size());
@ -249,8 +249,8 @@ public class P2PServiceTest {
sequenceNumberManipulated = 0; sequenceNumberManipulated = 0;
hashOfDataAndSeqNr = Hash.getHash(new P2PDataStorage.DataAndSeqNrPair(manipulatedData, sequenceNumberManipulated)); hashOfDataAndSeqNr = Hash.getHash(new P2PDataStorage.DataAndSeqNrPair(manipulatedData, sequenceNumberManipulated));
signature = Sig.sign(msgSignatureKeyPairAdversary.getPrivate(), hashOfDataAndSeqNr); signature = Sig.sign(msgSignatureKeyPairAdversary.getPrivate(), hashOfDataAndSeqNr);
protectedDataManipulated = new ProtectedData(origProtectedData.expirableMessage, origProtectedData.ttl, msgSignatureKeyPairAdversary.getPublic(), sequenceNumberManipulated, signature); protectedDataManipulated = new ProtectedData(origProtectedData.expirablePayload, origProtectedData.ttl, msgSignatureKeyPairAdversary.getPublic(), sequenceNumberManipulated, signature);
Assert.assertFalse(p2PService3.addData(protectedDataManipulated.expirableMessage)); Assert.assertFalse(p2PService3.addData(protectedDataManipulated.expirablePayload));
Thread.sleep(sleepTime); Thread.sleep(sleepTime);
Assert.assertEquals(0, p2PService1.getDataMap().size()); Assert.assertEquals(0, p2PService1.getDataMap().size());
Assert.assertEquals(0, p2PService2.getDataMap().size()); Assert.assertEquals(0, p2PService2.getDataMap().size());
@ -261,14 +261,14 @@ public class P2PServiceTest {
hashOfDataAndSeqNr = Hash.getHash(new P2PDataStorage.DataAndSeqNrPair(manipulatedData, sequenceNumberManipulated)); hashOfDataAndSeqNr = Hash.getHash(new P2PDataStorage.DataAndSeqNrPair(manipulatedData, sequenceNumberManipulated));
signature = Sig.sign(msgSignatureKeyPairAdversary.getPrivate(), hashOfDataAndSeqNr); signature = Sig.sign(msgSignatureKeyPairAdversary.getPrivate(), hashOfDataAndSeqNr);
protectedDataManipulated = new ProtectedData(manipulatedData, origProtectedData.ttl, msgSignatureKeyPairAdversary.getPublic(), sequenceNumberManipulated, signature); 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); Thread.sleep(sleepTime);
Assert.assertEquals(1, p2PService1.getDataMap().size()); Assert.assertEquals(1, p2PService1.getDataMap().size());
Assert.assertEquals(1, p2PService2.getDataMap().size()); Assert.assertEquals(1, p2PService2.getDataMap().size());
Assert.assertEquals(1, p2PService3.getDataMap().size()); Assert.assertEquals(1, p2PService3.getDataMap().size());
// lets reset map // lets reset map
Assert.assertTrue(p2PService3.removeData(protectedDataManipulated.expirableMessage)); Assert.assertTrue(p2PService3.removeData(protectedDataManipulated.expirablePayload));
Thread.sleep(sleepTime); Thread.sleep(sleepTime);
Assert.assertEquals(0, p2PService1.getDataMap().size()); Assert.assertEquals(0, p2PService1.getDataMap().size());
Assert.assertEquals(0, p2PService2.getDataMap().size()); Assert.assertEquals(0, p2PService2.getDataMap().size());
@ -289,7 +289,7 @@ public class P2PServiceTest {
// send to online peer // send to online peer
CountDownLatch latch2 = new CountDownLatch(2); CountDownLatch latch2 = new CountDownLatch(2);
MockMailboxMessage mockMessage = new MockMailboxMessage("MockMailboxMessage", p2PService2.getAddress()); MockMailboxPayload mockMessage = new MockMailboxPayload("MockMailboxMessage", p2PService2.getAddress());
p2PService2.getNetworkNode().addMessageListener((message, connection) -> { p2PService2.getNetworkNode().addMessageListener((message, connection) -> {
log.trace("message " + message); log.trace("message " + message);
if (message instanceof PrefixedSealedAndSignedMessage) { if (message instanceof PrefixedSealedAndSignedMessage) {
@ -336,7 +336,7 @@ public class P2PServiceTest {
LocalhostNetworkNode.setSimulateTorDelayHiddenService(0); LocalhostNetworkNode.setSimulateTorDelayHiddenService(0);
// send msg to offline peer // send msg to offline peer
MockMailboxMessage mockMessage = new MockMailboxMessage( MockMailboxPayload mockMessage = new MockMailboxPayload(
"MockMailboxMessage", "MockMailboxMessage",
p2PService2.getAddress() p2PService2.getAddress()
); );

View file

@ -3,15 +3,15 @@ package io.bitsquare.p2p.mocks;
import io.bitsquare.app.Version; import io.bitsquare.app.Version;
import io.bitsquare.p2p.NodeAddress; import io.bitsquare.p2p.NodeAddress;
import io.bitsquare.p2p.messaging.MailboxMessage; 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(); private final int messageVersion = Version.getP2PMessageVersion();
public final String msg; public final String msg;
public final NodeAddress senderNodeAddress; public final NodeAddress senderNodeAddress;
public long ttl; public long ttl;
public MockMailboxMessage(String msg, NodeAddress senderNodeAddress) { public MockMailboxPayload(String msg, NodeAddress senderNodeAddress) {
this.msg = msg; this.msg = msg;
this.senderNodeAddress = senderNodeAddress; this.senderNodeAddress = senderNodeAddress;
} }
@ -24,9 +24,9 @@ public final class MockMailboxMessage implements MailboxMessage, ExpirableMessag
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; 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); 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.app.Version;
import io.bitsquare.p2p.Message; 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 final String msg;
public long ttl; public long ttl;
private final int messageVersion = Version.getP2PMessageVersion(); private final int messageVersion = Version.getP2PMessageVersion();
public MockMessage(String msg) { public MockPayload(String msg) {
this.msg = msg; this.msg = msg;
} }
@ -21,9 +21,9 @@ public final class MockMessage implements Message, ExpirableMessage {
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; 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); 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.Futures;
import com.google.common.util.concurrent.SettableFuture; import com.google.common.util.concurrent.SettableFuture;
import io.bitsquare.p2p.Message; 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.bouncycastle.jce.provider.BouncyCastleProvider;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore; import org.junit.Ignore;
@ -87,7 +87,7 @@ public class TorNetworkNodeTest {
latch.countDown(); 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>() { Futures.addCallback(future, new FutureCallback<Connection>() {
@Override @Override
public void onSuccess(Connection connection) { public void onSuccess(Connection connection) {
@ -166,7 +166,7 @@ public class TorNetworkNodeTest {
latch.countDown(); 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>() { Futures.addCallback(future, new FutureCallback<Connection>() {
@Override @Override
public void onSuccess(Connection connection) { public void onSuccess(Connection connection) {

View file

@ -105,9 +105,9 @@ public class ProtectedDataStorageTest {
Assert.assertEquals(1, dataStorage1.getMap().size()); Assert.assertEquals(1, dataStorage1.getMap().size());
int newSequenceNumber = data.sequenceNumber + 1; 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); 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.assertTrue(dataStorage1.remove(dataToRemove, null));
Assert.assertEquals(0, dataStorage1.getMap().size()); Assert.assertEquals(0, dataStorage1.getMap().size());
} }

View file

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