use of bisq.network.p2p.storage.payload.ProtectedStoragePayload in project bisq-core by bisq-network.
the class ProposalCollectionsService method onAllServicesInitialized.
// /////////////////////////////////////////////////////////////////////////////////////////
// API
// /////////////////////////////////////////////////////////////////////////////////////////
public void onAllServicesInitialized() {
p2PService.addHashSetChangedListener(this);
// At startup the P2PDataStorage initializes earlier, otherwise we get the listener called.
p2PService.getP2PDataStorage().getMap().values().forEach(e -> {
final ProtectedStoragePayload protectedStoragePayload = e.getProtectedStoragePayload();
if (protectedStoragePayload instanceof ProposalPayload)
addProposal((ProposalPayload) protectedStoragePayload, false);
});
// Republish own active proposals once we are well connected
numConnectedPeersListener = (observable, oldValue, newValue) -> {
// Delay a bit for localhost testing to not fail as isBootstrapped is false
UserThread.runAfter(() -> {
if (((int) newValue > 4 && p2PService.isBootstrapped()) || DevEnv.isDevMode()) {
p2PService.getNumConnectedPeers().removeListener(numConnectedPeersListener);
activeProposals.stream().filter(this::isMine).forEach(e -> addToP2PNetwork(e.getProposalPayload()));
}
}, 2);
};
p2PService.getNumConnectedPeers().addListener(numConnectedPeersListener);
bsqWalletService.getChainHeightProperty().addListener((observable, oldValue, newValue) -> {
onChainHeightChanged();
});
onChainHeightChanged();
}
use of bisq.network.p2p.storage.payload.ProtectedStoragePayload in project bisq-core by bisq-network.
the class ProposalCollectionsService method onRemoved.
@Override
public void onRemoved(ProtectedStorageEntry data) {
final ProtectedStoragePayload protectedStoragePayload = data.getProtectedStoragePayload();
if (protectedStoragePayload instanceof ProposalPayload) {
findProposal((ProposalPayload) protectedStoragePayload).ifPresent(proposal -> {
if (isInPhaseOrUnconfirmed(proposal.getProposalPayload())) {
removeProposalFromList(proposal);
} else {
final String msg = "onRemoved called of a Proposal which is outside of the Request phase is invalid and we ignore it.";
log.warn(msg);
if (DevEnv.isDevMode())
throw new RuntimeException(msg);
}
});
}
}
use of bisq.network.p2p.storage.payload.ProtectedStoragePayload in project bisq-core by bisq-network.
the class VoteService method onAllServicesInitialized.
// /////////////////////////////////////////////////////////////////////////////////////////
// API
// /////////////////////////////////////////////////////////////////////////////////////////
public void onAllServicesInitialized() {
p2PService.addHashSetChangedListener(this);
// At startup the P2PDataStorage initializes earlier, otherwise we get the listener called.
p2PService.getP2PDataStorage().getMap().values().forEach(e -> {
final ProtectedStoragePayload protectedStoragePayload = e.getProtectedStoragePayload();
if (protectedStoragePayload instanceof BlindVote)
addBlindVote((BlindVote) protectedStoragePayload);
});
// Republish own active blindVotes once we are well connected
numConnectedPeersListener = (observable, oldValue, newValue) -> {
// Delay a bit for localhost testing to not fail as isBootstrapped is false
UserThread.runAfter(() -> {
if (((int) newValue > 4 && p2PService.isBootstrapped()) || DevEnv.isDevMode()) {
p2PService.getNumConnectedPeers().removeListener(numConnectedPeersListener);
myVotesList.stream().filter(myVote -> daoPeriodService.isTxInPhase(myVote.getTxId(), DaoPeriodService.Phase.BLIND_VOTE)).forEach(myVote -> addBlindVoteToP2PNetwork(myVote.getBlindVote()));
}
}, 2);
};
p2PService.getNumConnectedPeers().addListener(numConnectedPeersListener);
daoPeriodService.getPhaseProperty().addListener((observable, oldValue, newValue) -> {
onPhaseChanged(newValue);
});
onPhaseChanged(daoPeriodService.getPhaseProperty().get());
}
use of bisq.network.p2p.storage.payload.ProtectedStoragePayload in project bisq-core by bisq-network.
the class FilterManager method onAllServicesInitialized.
public void onAllServicesInitialized() {
if (!ignoreDevMsg) {
final List<ProtectedStorageEntry> list = new ArrayList<>(p2PService.getP2PDataStorage().getMap().values());
list.forEach(e -> {
final ProtectedStoragePayload protectedStoragePayload = e.getProtectedStoragePayload();
if (protectedStoragePayload instanceof Filter)
addFilter((Filter) protectedStoragePayload);
});
p2PService.addHashSetChangedListener(new HashMapChangedListener() {
@Override
public void onAdded(ProtectedStorageEntry data) {
if (data.getProtectedStoragePayload() instanceof Filter) {
Filter filter = (Filter) data.getProtectedStoragePayload();
addFilter(filter);
}
}
@Override
public void onRemoved(ProtectedStorageEntry data) {
if (data.getProtectedStoragePayload() instanceof Filter) {
Filter filter = (Filter) data.getProtectedStoragePayload();
if (verifySignature(filter))
resetFilters();
}
}
});
}
p2PService.addP2PServiceListener(new P2PServiceListener() {
@Override
public void onDataReceived() {
}
@Override
public void onNoSeedNodeAvailable() {
}
@Override
public void onNoPeersAvailable() {
}
@Override
public void onUpdatedDataReceived() {
// We should have received all data at that point and if the filers was not set we
// clean up as it might be that we missed the filter remove message if we have not been online.
UserThread.runAfter(() -> {
if (filterProperty.get() == null)
resetFilters();
}, 1);
}
@Override
public void onTorNodeReady() {
}
@Override
public void onHiddenServicePublished() {
}
@Override
public void onSetupFailed(Throwable throwable) {
}
@Override
public void onRequestCustomBridges() {
}
});
}
use of bisq.network.p2p.storage.payload.ProtectedStoragePayload in project bisq-core by bisq-network.
the class TradeStatisticsManager method onAllServicesInitialized.
public void onAllServicesInitialized() {
if (dumpStatistics) {
ArrayList<CurrencyTuple> fiatCurrencyList = new ArrayList<>(CurrencyUtil.getAllSortedFiatCurrencies().stream().map(e -> new CurrencyTuple(e.getCode(), e.getName(), 8)).collect(Collectors.toList()));
jsonFileManager.writeToDisc(Utilities.objectToJson(fiatCurrencyList), "fiat_currency_list");
ArrayList<CurrencyTuple> cryptoCurrencyList = new ArrayList<>(CurrencyUtil.getAllSortedCryptoCurrencies().stream().map(e -> new CurrencyTuple(e.getCode(), e.getName(), 8)).collect(Collectors.toList()));
cryptoCurrencyList.add(0, new CurrencyTuple(Res.getBaseCurrencyCode(), Res.getBaseCurrencyName(), 8));
jsonFileManager.writeToDisc(Utilities.objectToJson(cryptoCurrencyList), "crypto_currency_list");
}
p2PService.getP2PDataStorage().addPersistableNetworkPayloadMapListener(payload -> {
if (payload instanceof TradeStatistics2)
addToMap((TradeStatistics2) payload, true);
});
p2PService.getP2PDataStorage().getPersistableNetworkPayloadList().getMap().values().forEach(e -> {
if (e instanceof TradeStatistics2)
addToMap((TradeStatistics2) e, false);
});
// TODO can be removed after version older than v0.6.0 are not used anymore
// We listen to TradeStatistics objects from old clients as well and convert them into TradeStatistics2 objects
p2PService.addHashSetChangedListener(new HashMapChangedListener() {
@Override
public void onAdded(ProtectedStorageEntry data) {
final ProtectedStoragePayload protectedStoragePayload = data.getProtectedStoragePayload();
if (protectedStoragePayload instanceof TradeStatistics)
p2PService.getP2PDataStorage().addPersistableNetworkPayload(ConvertToTradeStatistics2((TradeStatistics) protectedStoragePayload), p2PService.getNetworkNode().getNodeAddress(), true, false, false, false);
}
@Override
public void onRemoved(ProtectedStorageEntry data) {
// We don't remove items
}
});
priceFeedService.applyLatestBisqMarketPrice(tradeStatisticsSet);
dump();
// print all currencies sorted by nr. of trades
// printAllCurrencyStats();
}
Aggregations