Fix bug when trader is offline and use password protection signing payout tx fails

This commit is contained in:
Manfred Karrer 2016-04-13 13:56:23 +02:00
parent 81fcc82972
commit c021ea8ea2
6 changed files with 44 additions and 77 deletions

View File

@ -95,7 +95,6 @@ public class ArbitratorManager {
private final ArbitratorService arbitratorService;
private final User user;
private final ObservableMap<NodeAddress, Arbitrator> arbitratorsObservableMap = FXCollections.observableHashMap();
private BootstrapListener bootstrapListener;
private Timer republishArbitratorTimer, retryRepublishArbitratorTimer;
@ -125,9 +124,6 @@ public class ArbitratorManager {
public void shutDown() {
stopRepublishArbitratorTimer();
stopRetryRepublishArbitratorTimer();
if (bootstrapListener != null)
arbitratorService.getP2PService().removeP2PServiceListener(bootstrapListener);
}
@ -138,22 +134,15 @@ public class ArbitratorManager {
public void onAllServicesInitialized() {
if (user.getRegisteredArbitrator() != null) {
P2PService p2PService = arbitratorService.getP2PService();
if (!p2PService.isBootstrapped()) {
bootstrapListener = new BootstrapListener() {
if (p2PService.isBootstrapped())
republishArbitrator();
else
p2PService.addP2PServiceListener(new BootstrapListener() {
@Override
public void onBootstrapComplete() {
ArbitratorManager.this.onBootstrapComplete();
republishArbitrator();
}
};
if (p2PService.isBootstrapped())
onBootstrapComplete();
else
p2PService.addP2PServiceListener(bootstrapListener);
} else {
republishArbitrator();
}
});
}
republishArbitratorTimer = UserThread.runPeriodically(this::republishArbitrator, REPUBLISH_MILLIS, TimeUnit.MILLISECONDS);
@ -247,15 +236,6 @@ public class ArbitratorManager {
// Private
///////////////////////////////////////////////////////////////////////////////////////////
private void onBootstrapComplete() {
if (bootstrapListener != null) {
arbitratorService.getP2PService().removeP2PServiceListener(bootstrapListener);
bootstrapListener = null;
}
republishArbitrator();
}
private void republishArbitrator() {
Arbitrator registeredArbitrator = user.getRegisteredArbitrator();
if (registeredArbitrator != null) {

View File

@ -70,7 +70,6 @@ public class DisputeManager {
private final DisputeList<Dispute> disputes;
transient private final ObservableList<Dispute> disputesObservableList;
private final String disputeInfo;
private final BootstrapListener bootstrapListener;
private final CopyOnWriteArraySet<DecryptedMsgWithPubKey> decryptedMailboxMessageWithPubKeys = new CopyOnWriteArraySet<>();
private final CopyOnWriteArraySet<DecryptedMsgWithPubKey> decryptedDirectMessageWithPubKeys = new CopyOnWriteArraySet<>();
@ -118,17 +117,23 @@ public class DisputeManager {
if (p2PService.isBootstrapped())
applyMessages();
});
}
bootstrapListener = new BootstrapListener() {
@Override
public void onBootstrapComplete() {
applyMessages();
}
};
///////////////////////////////////////////////////////////////////////////////////////////
// API
///////////////////////////////////////////////////////////////////////////////////////////
public void onAllServicesInitialized() {
if (p2PService.isBootstrapped())
applyMessages();
else
p2PService.addP2PServiceListener(bootstrapListener);
p2PService.addP2PServiceListener(new BootstrapListener() {
@Override
public void onBootstrapComplete() {
applyMessages();
}
});
}
private void applyMessages() {
@ -148,17 +153,6 @@ public class DisputeManager {
}
});
decryptedMailboxMessageWithPubKeys.clear();
if (bootstrapListener != null)
p2PService.removeP2PServiceListener(bootstrapListener);
}
///////////////////////////////////////////////////////////////////////////////////////////
// API
///////////////////////////////////////////////////////////////////////////////////////////
public void onAllServicesInitialized() {
}
private void dispatchMessage(DisputeMessage message) {

View File

@ -81,7 +81,6 @@ public class TradeManager {
private final Storage<TradableList<Trade>> tradableListStorage;
private final TradableList<Trade> trades;
private final BooleanProperty pendingTradesInitialized = new SimpleBooleanProperty();
private final BootstrapListener bootstrapListener;
///////////////////////////////////////////////////////////////////////////////////////////
@ -147,19 +146,20 @@ public class TradeManager {
}
}
});
}
bootstrapListener = new BootstrapListener() {
@Override
public void onBootstrapComplete() {
// Get called after onMailboxMessageAdded from initial data request
// The mailbox message will be removed inside the tasks after they are processed successfully
initPendingTrades();
}
};
public void onAllServicesInitialized() {
if (p2PService.isBootstrapped())
initPendingTrades();
else
p2PService.addP2PServiceListener(bootstrapListener);
p2PService.addP2PServiceListener(new BootstrapListener() {
@Override
public void onBootstrapComplete() {
// Get called after onMailboxMessageAdded from initial data request
// The mailbox message will be removed inside the tasks after they are processed successfully
initPendingTrades();
}
});
}
@ -169,8 +169,6 @@ public class TradeManager {
private void initPendingTrades() {
Log.traceCall();
if (bootstrapListener != null)
p2PService.removeP2PServiceListener(bootstrapListener);
//List<Trade> failedTrades = new ArrayList<>();
for (Trade trade : trades) {

View File

@ -81,7 +81,6 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
private final Storage<TradableList<OpenOffer>> openOffersStorage;
private boolean stopped;
private Timer periodicRepublishOffersTimer, periodicRefreshOffersTimer, retryRepublishOffersTimer;
private BootstrapListener bootstrapListener;
///////////////////////////////////////////////////////////////////////////////////////////
@ -114,19 +113,17 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
}
public void onAllServicesInitialized() {
bootstrapListener = new BootstrapListener() {
@Override
public void onBootstrapComplete() {
OpenOfferManager.this.onBootstrapComplete();
}
};
p2PService.addP2PServiceListener(bootstrapListener);
p2PService.addDecryptedDirectMessageListener(this);
if (p2PService.isBootstrapped())
onBootstrapComplete();
else
p2PService.addP2PServiceListener(bootstrapListener);
p2PService.addP2PServiceListener(new BootstrapListener() {
@Override
public void onBootstrapComplete() {
OpenOfferManager.this.onBootstrapComplete();
}
});
}
@SuppressWarnings("WeakerAccess")
@ -138,8 +135,6 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
stopped = true;
p2PService.getPeerManager().removeListener(this);
p2PService.removeDecryptedDirectMessageListener(this);
if (bootstrapListener != null)
p2PService.removeP2PServiceListener(bootstrapListener);
stopPeriodicRefreshOffersTimer();
stopPeriodicRepublishOffersTimer();
@ -187,9 +182,6 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
///////////////////////////////////////////////////////////////////////////////////////////
public void onBootstrapComplete() {
if (bootstrapListener != null)
p2PService.removeP2PServiceListener(bootstrapListener);
stopped = false;
// Republish means we send the complete offer object

View File

@ -468,6 +468,7 @@ public class MainViewModel implements ViewModel {
onDisputesChangeListener(disputeManager.getDisputesAsObservableList(), null);
// tradeManager
tradeManager.onAllServicesInitialized();
tradeManager.getTrades().addListener((ListChangeListener<Trade>) c -> updateBalance());
tradeManager.getTrades().addListener((ListChangeListener<Trade>) change -> onTradesChanged());
onTradesChanged();

View File

@ -116,8 +116,9 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
}
private void init(boolean useLocalhost, int networkId, File storageDir) {
FileUtil.rollingBackup(new File(Paths.get(torDir.getAbsolutePath(), "hiddenservice").toString()), "private_key");
if (!useLocalhost)
FileUtil.rollingBackup(new File(Paths.get(torDir.getAbsolutePath(), "hiddenservice").toString()), "private_key");
networkNode = useLocalhost ? new LocalhostNetworkNode(port) : new TorNetworkNode(port, torDir);
networkNode.addConnectionListener(this);
networkNode.addMessageListener(this);
@ -277,10 +278,11 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
"seedNodeOfPreliminaryDataRequest must be present");
peerExchangeManager.requestReportedPeersFromSeedNodes(seedNodeOfPreliminaryDataRequest.get());
isBootstrapped = true;
p2pServiceListeners.stream().forEach(P2PServiceListener::onBootstrapComplete);
p2PDataStorage.onBootstrapComplete();
if (!isBootstrapped) {
isBootstrapped = true;
p2pServiceListeners.stream().forEach(P2PServiceListener::onBootstrapComplete);
p2PDataStorage.onBootstrapComplete();
}
}
@Override