Commit 5288dd61 authored by Benoit Lavenier's avatar Benoit Lavenier

[fix] Better way to filter on duniter compatible endpoints

parent ee431cf6
Pipeline #4318 passed with stage
in 25 seconds
......@@ -52,7 +52,21 @@ public final class Peers {
hasEndPointAPI(peer, EndpointApi.BMAS);
}
public static boolean hasWs2pEndpoint(Peer peer) {
return hasEndPointAPI(peer, EndpointApi.WS2P);
}
public static boolean hasDuniterEndpoint(Peer peer) {
return hasBmaEndpoint(peer) ||
hasWs2pEndpoint(peer);
}
public static boolean hasEsCoreEndpoint(Peer peer) {
return hasEndPointAPI(peer, EndpointApi.ES_CORE_API);
}
public static boolean isReacheable(Peer peer) {
return peer.getStats() != null && peer.getStats().isReacheable();
}
}
......@@ -239,7 +239,7 @@ public class NetworkServiceImpl extends BaseRemoteServiceImpl implements Network
if (CollectionUtils.isEmpty(peers)) return peers;
final Map<String,Long> peerCountByBuid = peers.stream()
.filter(peer -> peer.getStats() != null && peer.getStats().isReacheable() && Peers.hasBmaEndpoint(peer))
.filter(peer -> Peers.isReacheable(peer) && Peers.hasDuniterEndpoint(peer))
.map(Peers::buid)
.filter(b -> b != null)
.collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
......@@ -266,7 +266,7 @@ public class NetworkServiceImpl extends BaseRemoteServiceImpl implements Network
String buid = Peers.buid(stats);
// Set consensus stats on each peers
if (buid != null) {
if (buid != null && Peers.hasDuniterEndpoint(peer)) {
boolean isMainConsensus = buid.equals(mainBuid);
stats.setMainConsensus(isMainConsensus);
......
......@@ -109,4 +109,12 @@ public class CollectionUtils {
});
return result;
}
public static <C> Collection<C> union(Collection<C> c1, Collection<C>... cols) {
Collection<C> result = c1;
for (Collection<C> c2 : cols) {
result = union(result, c2);
}
return result;
}
}
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