Skip to content
Snippets Groups Projects
Commit 5288dd61 authored by Benoit Lavenier's avatar Benoit Lavenier
Browse files

[fix] Better way to filter on duniter compatible endpoints

parent ee431cf6
No related branches found
No related tags found
No related merge requests found
Pipeline #4318 passed
...@@ -52,7 +52,21 @@ public final class Peers { ...@@ -52,7 +52,21 @@ public final class Peers {
hasEndPointAPI(peer, EndpointApi.BMAS); 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) { public static boolean hasEsCoreEndpoint(Peer peer) {
return hasEndPointAPI(peer, EndpointApi.ES_CORE_API); 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 ...@@ -239,7 +239,7 @@ public class NetworkServiceImpl extends BaseRemoteServiceImpl implements Network
if (CollectionUtils.isEmpty(peers)) return peers; if (CollectionUtils.isEmpty(peers)) return peers;
final Map<String,Long> peerCountByBuid = peers.stream() 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) .map(Peers::buid)
.filter(b -> b != null) .filter(b -> b != null)
.collect(Collectors.groupingBy(Function.identity(), Collectors.counting())); .collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
...@@ -266,7 +266,7 @@ public class NetworkServiceImpl extends BaseRemoteServiceImpl implements Network ...@@ -266,7 +266,7 @@ public class NetworkServiceImpl extends BaseRemoteServiceImpl implements Network
String buid = Peers.buid(stats); String buid = Peers.buid(stats);
// Set consensus stats on each peers // Set consensus stats on each peers
if (buid != null) { if (buid != null && Peers.hasDuniterEndpoint(peer)) {
boolean isMainConsensus = buid.equals(mainBuid); boolean isMainConsensus = buid.equals(mainBuid);
stats.setMainConsensus(isMainConsensus); stats.setMainConsensus(isMainConsensus);
......
...@@ -109,4 +109,12 @@ public class CollectionUtils { ...@@ -109,4 +109,12 @@ public class CollectionUtils {
}); });
return result; 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;
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment