Commit 47efbf57 authored by Benoit Lavenier's avatar Benoit Lavenier

[fix] Network: filter on last 100 blocks

parent c2871dea
Pipeline #4526 passed with stage
in 25 seconds
......@@ -4,7 +4,7 @@ duniter4j.client.network.action=Display network peers
duniter4j.client.network.cesiumPlus=Cs+
duniter4j.client.network.error.outputFieNotWritable=Output file not writable
duniter4j.client.network.executionTime=Execution time\: %s ms
duniter4j.client.network.header=Head: block {%1$s} computed at %2$s (UTC time) validated by {%3$3.2f%%} of the peers
duniter4j.client.network.header=Head\: block {%1$s} computed at %2$s (UTC time) validated by {%3$3.2f%%} of the peers
duniter4j.client.network.loadingPeers=Reading network peers... (timeout\: %s ms)
duniter4j.client.network.mirror=Mirror
duniter4j.client.network.noPeers=No peers found
......
......@@ -4,7 +4,7 @@ duniter4j.client.network.action=Afficher les noeuds Duniter
duniter4j.client.network.cesiumPlus=Cs+
duniter4j.client.network.error.outputFieNotWritable=Fichier de sortie non inscriptible
duniter4j.client.network.executionTime=Temps d'execution \: %s ms
duniter4j.client.network.header=Branche principale: bloc {%1$s} calculé à %2$s (heure UTC) validé par {%3$3.2f%%} des noeuds
duniter4j.client.network.header=Branche principale\: bloc {%1$s} calculé à %2$s (heure UTC) validé par {%3$3.2f%%} des noeuds
duniter4j.client.network.loadingPeers=Lecture des noeuds du réseau... (Délai d'attente \: %s ms)
duniter4j.client.network.mirror=Mirroir
duniter4j.client.network.noPeers=Aucun noeud trouvé
......
......@@ -37,6 +37,7 @@ import org.duniter.core.client.config.Configuration;
import org.duniter.core.client.model.bma.*;
import org.duniter.core.client.model.bma.jackson.JacksonUtils;
import org.duniter.core.client.model.local.Peer;
import org.duniter.core.client.service.ServiceLocator;
import org.duniter.core.exception.TechnicalException;
import org.duniter.core.util.Preconditions;
import org.duniter.core.util.websocket.WebsocketClientEndpoint;
......@@ -68,11 +69,16 @@ public class NetworkRemoteServiceImpl extends BaseRemoteServiceImpl implements N
public static final String URL_WS2P_HEADS = URL_WS2P + "/heads";
public final Configuration config;
private Configuration config;
public NetworkRemoteServiceImpl() {
super();
this.config = Configuration.instance();
}
@Override
public void afterPropertiesSet() {
super.afterPropertiesSet();
config = Configuration.instance();
}
public NetworkPeering getPeering(Peer peer) {
......
......@@ -26,6 +26,7 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.apache.commons.collections4.MapUtils;
import org.duniter.core.client.config.Configuration;
import org.duniter.core.client.model.ModelUtils;
import org.duniter.core.client.model.bma.*;
import org.duniter.core.client.model.local.*;
......@@ -76,6 +77,7 @@ public class WotRemoteServiceImpl extends BaseRemoteServiceImpl implements WotRe
private CryptoService cryptoService;
private BlockchainRemoteService bcService;
private CurrencyService currencyService;
private Configuration config;
public WotRemoteServiceImpl() {
super();
......@@ -87,6 +89,7 @@ public class WotRemoteServiceImpl extends BaseRemoteServiceImpl implements WotRe
cryptoService = ServiceLocator.instance().getCryptoService();
bcService = ServiceLocator.instance().getBlockchainRemoteService();
currencyService = ServiceLocator.instance().getCurrencyService();
config = Configuration.instance();
}
public List<Identity> findIdentities(Set<String> currenciesIds, String uidOrPubKey) {
......@@ -132,7 +135,7 @@ public class WotRemoteServiceImpl extends BaseRemoteServiceImpl implements WotRe
@Override
public Map<String, String> getMembersUids(Peer peer) {
// get /wot/members
JsonNode json = httpService.executeRequest(peer, URL_MEMBERS, JsonNode.class);
JsonNode json = httpService.executeRequest(peer, URL_MEMBERS, JsonNode.class, config.getNetworkLargerTimeout());
if (json == null || !json.has("results")) return null;
......
......@@ -55,6 +55,7 @@ public interface NetworkService extends Service {
public Boolean filterSsl;
public List<String> filterEndpoints;
public String currency;
public Integer minBlockNumber;
}
......
......@@ -102,11 +102,14 @@ public class NetworkServiceImpl extends BaseRemoteServiceImpl implements Network
@Override
public List<Peer> getPeers(Peer firstPeer) {
BlockchainBlock current = blockchainRemoteService.getCurrentBlock(firstPeer);
// Default filter
Filter filterDef = new Filter();
filterDef.filterType = null;
filterDef.filterStatus = Peer.PeerStatus.UP;
filterDef.filterEndpoints = ImmutableList.of(EndpointApi.BASIC_MERKLED_API.name(), EndpointApi.BMAS.name(), EndpointApi.WS2P.name());
filterDef.minBlockNumber = current.getNumber().intValue() - 100;
// Default sort
Sort sortDef = new Sort();
......@@ -125,7 +128,6 @@ public class NetworkServiceImpl extends BaseRemoteServiceImpl implements Network
try {
return getPeersAsync(mainPeer, (filter != null ? filter.filterEndpoints : null), executor)
//.thenComposeAsync(CompletableFutures::allOfToList)
.thenApplyAsync(this::fillPeerStatsConsensus)
.thenApplyAsync(peers -> peers.stream()
// Filter on currency
......@@ -197,8 +199,11 @@ public class NetworkServiceImpl extends BaseRemoteServiceImpl implements Network
// BMA or ES_CORE
if (Peers.hasBmaEndpoint(peer) || Peers.hasEsCoreEndpoint(peer)) {
return CompletableFuture.supplyAsync(() -> fillNodeSummary(peer), pool)
.thenApplyAsync(this::fillCurrentBlock)
return CompletableFuture.allOf(
CompletableFuture.supplyAsync(() -> fillNodeSummary(peer), pool),
CompletableFuture.supplyAsync(() -> fillCurrentBlock(peer), pool)
)
.thenApply((v) -> peer)
.exceptionally(throwable -> {
peer.getStats().setStatus(Peer.PeerStatus.DOWN);
if(!(throwable instanceof HttpConnectException)) {
......@@ -362,6 +367,7 @@ public class NetworkServiceImpl extends BaseRemoteServiceImpl implements Network
public void addPeersChangeListener(final Peer mainPeer, final PeersChangeListener listener) {
BlockchainParameters parameters = blockchainRemoteService.getParameters(mainPeer);
fillCurrentBlock(mainPeer);
// Default filter
Filter filterDef = new Filter();
......@@ -370,6 +376,11 @@ public class NetworkServiceImpl extends BaseRemoteServiceImpl implements Network
filterDef.filterEndpoints = ImmutableList.of(EndpointApi.BASIC_MERKLED_API.name(), EndpointApi.BMAS.name(), EndpointApi.WS2P.name());
filterDef.currency = parameters.getCurrency();
// Skip node on an old fork
if (mainPeer.getStats().getBlockNumber() != null) {
filterDef.minBlockNumber = mainPeer.getStats().getBlockNumber() - 100;
}
// Default sort
Sort sortDef = new Sort();
sortDef.sortType = null;
......@@ -671,6 +682,11 @@ public class NetworkServiceImpl extends BaseRemoteServiceImpl implements Network
return false;
}
// Filter block number
if (filter.minBlockNumber != null && (stats.getBlockNumber() == null || stats.getBlockNumber().intValue() < filter.minBlockNumber.intValue())) {
return false;
}
return true;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment