mirror of
https://github.com/haveno-dex/haveno.git
synced 2024-12-22 11:39:29 +00:00
republish offers unless deactivated or canceled
This commit is contained in:
parent
8d8aa65d1d
commit
76f8f85487
1 changed files with 24 additions and 10 deletions
|
@ -688,7 +688,7 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
|
||||||
addOpenOffer(editedOpenOffer);
|
addOpenOffer(editedOpenOffer);
|
||||||
|
|
||||||
if (editedOpenOffer.isAvailable())
|
if (editedOpenOffer.isAvailable())
|
||||||
republishOffer(editedOpenOffer);
|
maybeRepublishOffer(editedOpenOffer);
|
||||||
|
|
||||||
offersToBeEdited.remove(openOffer.getId());
|
offersToBeEdited.remove(openOffer.getId());
|
||||||
requestPersistence();
|
requestPersistence();
|
||||||
|
@ -1714,11 +1714,11 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
|
||||||
synchronized (openOffers) {
|
synchronized (openOffers) {
|
||||||
contained = openOffers.contains(openOffer);
|
contained = openOffers.contains(openOffer);
|
||||||
}
|
}
|
||||||
if (contained && openOffer.isAvailable()) {
|
if (contained) {
|
||||||
// TODO It is not clear yet if it is better for the node and the network to send out all add offer
|
// TODO It is not clear yet if it is better for the node and the network to send out all add offer
|
||||||
// messages in one go or to spread it over a delay. With power users who have 100-200 offers that can have
|
// messages in one go or to spread it over a delay. With power users who have 100-200 offers that can have
|
||||||
// some significant impact to user experience and the network
|
// some significant impact to user experience and the network
|
||||||
republishOffer(openOffer, () -> processListForRepublishOffers(list));
|
maybeRepublishOffer(openOffer, () -> processListForRepublishOffers(list));
|
||||||
|
|
||||||
/* republishOffer(openOffer,
|
/* republishOffer(openOffer,
|
||||||
() -> UserThread.runAfter(() -> processListForRepublishOffers(list),
|
() -> UserThread.runAfter(() -> processListForRepublishOffers(list),
|
||||||
|
@ -1730,13 +1730,19 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void republishOffer(OpenOffer openOffer) {
|
private void maybeRepublishOffer(OpenOffer openOffer) {
|
||||||
republishOffer(openOffer, null);
|
maybeRepublishOffer(openOffer, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void republishOffer(OpenOffer openOffer, @Nullable Runnable completeHandler) {
|
private void maybeRepublishOffer(OpenOffer openOffer, @Nullable Runnable completeHandler) {
|
||||||
ThreadUtils.execute(() -> {
|
ThreadUtils.execute(() -> {
|
||||||
|
|
||||||
|
// skip if prevented from publishing
|
||||||
|
if (preventedFromPublishing(openOffer)) {
|
||||||
|
if (completeHandler != null) completeHandler.run();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// determine if offer is valid
|
// determine if offer is valid
|
||||||
boolean isValid = true;
|
boolean isValid = true;
|
||||||
Arbitrator arbitrator = user.getAcceptedArbitratorByAddress(openOffer.getOffer().getOfferPayload().getArbitratorSigner());
|
Arbitrator arbitrator = user.getAcceptedArbitratorByAddress(openOffer.getOffer().getOfferPayload().getArbitratorSigner());
|
||||||
|
@ -1811,6 +1817,10 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
|
||||||
}, THREAD_ID);
|
}, THREAD_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean preventedFromPublishing(OpenOffer openOffer) {
|
||||||
|
return openOffer.isDeactivated() || openOffer.isCanceled();
|
||||||
|
}
|
||||||
|
|
||||||
private void startPeriodicRepublishOffersTimer() {
|
private void startPeriodicRepublishOffersTimer() {
|
||||||
stopped = false;
|
stopped = false;
|
||||||
if (periodicRepublishOffersTimer == null) {
|
if (periodicRepublishOffersTimer == null) {
|
||||||
|
@ -1843,8 +1853,11 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
|
||||||
final OpenOffer openOffer = openOffersList.get(i);
|
final OpenOffer openOffer = openOffersList.get(i);
|
||||||
UserThread.runAfterRandomDelay(() -> {
|
UserThread.runAfterRandomDelay(() -> {
|
||||||
// we need to check if in the meantime the offer has been removed
|
// we need to check if in the meantime the offer has been removed
|
||||||
if (openOffers.contains(openOffer) && openOffer.isAvailable())
|
boolean contained = false;
|
||||||
refreshOffer(openOffer, 0, 1);
|
synchronized (openOffers) {
|
||||||
|
contained = openOffers.contains(openOffer);
|
||||||
|
}
|
||||||
|
if (contained) maybeRefreshOffer(openOffer, 0, 1);
|
||||||
}, minDelay, maxDelay, TimeUnit.MILLISECONDS);
|
}, minDelay, maxDelay, TimeUnit.MILLISECONDS);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -1857,13 +1870,14 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
|
||||||
log.trace("periodicRefreshOffersTimer already stated");
|
log.trace("periodicRefreshOffersTimer already stated");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void refreshOffer(OpenOffer openOffer, int numAttempts, int maxAttempts) {
|
private void maybeRefreshOffer(OpenOffer openOffer, int numAttempts, int maxAttempts) {
|
||||||
|
if (preventedFromPublishing(openOffer)) return;
|
||||||
offerBookService.refreshTTL(openOffer.getOffer().getOfferPayload(),
|
offerBookService.refreshTTL(openOffer.getOffer().getOfferPayload(),
|
||||||
() -> log.debug("Successful refreshed TTL for offer"),
|
() -> log.debug("Successful refreshed TTL for offer"),
|
||||||
(errorMessage) -> {
|
(errorMessage) -> {
|
||||||
log.warn(errorMessage);
|
log.warn(errorMessage);
|
||||||
if (numAttempts + 1 < maxAttempts) {
|
if (numAttempts + 1 < maxAttempts) {
|
||||||
UserThread.runAfter(() -> refreshOffer(openOffer, numAttempts + 1, maxAttempts), 10);
|
UserThread.runAfter(() -> maybeRefreshOffer(openOffer, numAttempts + 1, maxAttempts), 10);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue