mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-20 02:12:00 +01:00
Check accountWitness date only if we receive it from other peers in the P2P network
This commit is contained in:
parent
7c78db5101
commit
14bb75ded5
@ -79,6 +79,8 @@ public class AccountAgeWitness implements LazyProcessedPayload, PersistableNetwo
|
||||
|
||||
@Override
|
||||
public boolean isDateInTolerance() {
|
||||
// We don't allow older or newer then 1 day.
|
||||
// Preventing forward dating is also important to protect against a sophisticated attack
|
||||
return Math.abs(new Date().getTime() - date) <= TOLERANCE;
|
||||
}
|
||||
|
||||
|
@ -280,7 +280,7 @@ public class AccountAgeWitnessService {
|
||||
ErrorMessageHandler errorMessageHandler) {
|
||||
// Check if trade date in witness is not older than the release date of that feature (was added in v0.6)
|
||||
// TODO set date before releasing
|
||||
if (!isTradeDateAfterReleaseDate(witness.getDate(), new GregorianCalendar(2017, GregorianCalendar.OCTOBER, 17).getTime(), errorMessageHandler))
|
||||
if (!isDateAfterReleaseDate(witness.getDate(), new GregorianCalendar(2017, GregorianCalendar.OCTOBER, 17).getTime(), errorMessageHandler))
|
||||
return false;
|
||||
|
||||
final byte[] peersAccountInputDataWithSalt = Utilities.concatenateByteArrays(peersPaymentAccountPayload.getAgeWitnessInputData(), peersPaymentAccountPayload.getSalt());
|
||||
@ -307,7 +307,7 @@ public class AccountAgeWitnessService {
|
||||
// Package scope verification subroutines
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
boolean isTradeDateAfterReleaseDate(long witnessDateAsLong, Date ageWitnessReleaseDate, ErrorMessageHandler errorMessageHandler) {
|
||||
boolean isDateAfterReleaseDate(long witnessDateAsLong, Date ageWitnessReleaseDate, ErrorMessageHandler errorMessageHandler) {
|
||||
// Release date minus 1 day as tolerance for not synced clocks
|
||||
Date releaseDateWithTolerance = new Date(ageWitnessReleaseDate.getTime() - TimeUnit.DAYS.toMillis(1));
|
||||
final Date witnessDate = new Date(witnessDateAsLong);
|
||||
@ -334,6 +334,7 @@ public class AccountAgeWitnessService {
|
||||
return result;
|
||||
}
|
||||
|
||||
// TODO use peers local date and check tolerance
|
||||
private boolean verifyPeersTradeLimit(Offer offer,
|
||||
PaymentAccountPayload paymentAccountPayload,
|
||||
ErrorMessageHandler errorMessageHandler) {
|
||||
|
@ -60,15 +60,20 @@ public class AccountAgeWitnessServiceTest {
|
||||
public void testIsTradeDateAfterReleaseDate() throws CryptoException {
|
||||
Date ageWitnessReleaseDate = new GregorianCalendar(2017, 9, 23).getTime();
|
||||
Date tradeDate = new GregorianCalendar(2017, 10, 1).getTime();
|
||||
assertTrue(service.isTradeDateAfterReleaseDate(tradeDate.getTime(), ageWitnessReleaseDate, errorMessage -> {}));
|
||||
assertTrue(service.isDateAfterReleaseDate(tradeDate.getTime(), ageWitnessReleaseDate, errorMessage -> {
|
||||
}));
|
||||
tradeDate = new GregorianCalendar(2017, 9, 23).getTime();
|
||||
assertTrue(service.isTradeDateAfterReleaseDate(tradeDate.getTime(), ageWitnessReleaseDate, errorMessage -> {}));
|
||||
assertTrue(service.isDateAfterReleaseDate(tradeDate.getTime(), ageWitnessReleaseDate, errorMessage -> {
|
||||
}));
|
||||
tradeDate = new GregorianCalendar(2017, 9, 22, 0, 0, 1).getTime();
|
||||
assertTrue(service.isTradeDateAfterReleaseDate(tradeDate.getTime(), ageWitnessReleaseDate, errorMessage -> {}));
|
||||
assertTrue(service.isDateAfterReleaseDate(tradeDate.getTime(), ageWitnessReleaseDate, errorMessage -> {
|
||||
}));
|
||||
tradeDate = new GregorianCalendar(2017, 9, 22).getTime();
|
||||
assertFalse(service.isTradeDateAfterReleaseDate(tradeDate.getTime(), ageWitnessReleaseDate, errorMessage -> {}));
|
||||
assertFalse(service.isDateAfterReleaseDate(tradeDate.getTime(), ageWitnessReleaseDate, errorMessage -> {
|
||||
}));
|
||||
tradeDate = new GregorianCalendar(2017, 9, 21).getTime();
|
||||
assertFalse(service.isTradeDateAfterReleaseDate(tradeDate.getTime(), ageWitnessReleaseDate, errorMessage -> {}));
|
||||
assertFalse(service.isDateAfterReleaseDate(tradeDate.getTime(), ageWitnessReleaseDate, errorMessage -> {
|
||||
}));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -789,7 +789,7 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public boolean addPersistableNetworkPayload(PersistableNetworkPayload payload, boolean reBroadcast) {
|
||||
return p2PDataStorage.addPersistableNetworkPayload(payload, networkNode.getNodeAddress(), true, true, reBroadcast);
|
||||
return p2PDataStorage.addPersistableNetworkPayload(payload, networkNode.getNodeAddress(), true, true, reBroadcast, false);
|
||||
}
|
||||
|
||||
public boolean addData(ProtectedStoragePayload protectedStoragePayload, boolean isDataOwner) {
|
||||
|
@ -242,7 +242,7 @@ public class RequestDataHandler implements MessageListener {
|
||||
processDelayedItems.add(e);
|
||||
} else {
|
||||
// We dont broadcast here as we are only connected to the seed node and would be pointless
|
||||
dataStorage.addPersistableNetworkPayload(e, sender, false, false, false);
|
||||
dataStorage.addPersistableNetworkPayload(e, sender, false, false, false, false);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -272,7 +272,7 @@ public class RequestDataHandler implements MessageListener {
|
||||
if (item instanceof ProtectedStorageEntry)
|
||||
dataStorage.add((ProtectedStorageEntry) item, sender, null, false, false);
|
||||
else if (item instanceof PersistableNetworkPayload)
|
||||
dataStorage.addPersistableNetworkPayload((PersistableNetworkPayload) item, sender, false, false, false);
|
||||
dataStorage.addPersistableNetworkPayload((PersistableNetworkPayload) item, sender, false, false, false, false);
|
||||
}), delay, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
|
@ -245,7 +245,7 @@ public class P2PDataStorage implements MessageListener, ConnectionListener, Pers
|
||||
refreshTTL((RefreshOfferMessage) networkEnvelop, peersNodeAddress, false);
|
||||
} else if (networkEnvelop instanceof AddPersistableNetworkPayloadMessage) {
|
||||
addPersistableNetworkPayload(((AddPersistableNetworkPayloadMessage) networkEnvelop).getPersistableNetworkPayload(),
|
||||
peersNodeAddress, false, true, false);
|
||||
peersNodeAddress, false, true, false, true);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -321,12 +321,13 @@ public class P2PDataStorage implements MessageListener, ConnectionListener, Pers
|
||||
@Nullable NodeAddress sender,
|
||||
boolean isDataOwner,
|
||||
boolean allowBroadcast,
|
||||
boolean reBroadcast) {
|
||||
boolean reBroadcast,
|
||||
boolean checkDate) {
|
||||
log.debug("addPersistableNetworkPayload payload={}", payload);
|
||||
final ByteArray hashAsByteArray = new ByteArray(payload.getHash());
|
||||
boolean containsKey = persistableNetworkPayloadCollection.getMap().containsKey(hashAsByteArray);
|
||||
if (!containsKey || reBroadcast) {
|
||||
if (!(payload instanceof DateTolerantPayload) || ((DateTolerantPayload) payload).isDateInTolerance()) {
|
||||
if (!(payload instanceof DateTolerantPayload) || !checkDate || ((DateTolerantPayload) payload).isDateInTolerance()) {
|
||||
if (!containsKey) {
|
||||
persistableNetworkPayloadCollection.getMap().put(hashAsByteArray, payload);
|
||||
persistableNetworkPayloadMapStorage.queueUpForSave(persistableNetworkPayloadCollection, 2000);
|
||||
|
Loading…
Reference in New Issue
Block a user