Commit 41faef41 authored by Michel Schudel's avatar Michel Schudel

peers logica gefixed.

parent 86725f78
......@@ -124,14 +124,16 @@ public class Network {
if (!peers.contains(newPeer)) {
LOGGER.info("peer {} is not previously known to this node. Peer registration will be forwarded to known peer: {}", newPeer, peers);
peers.add(newPeer);
Set<String> newPeers = new HashSet<>();
for (String node : peers.stream().filter(p -> !p.equals(newPeer)).collect(Collectors.toSet())) {
ResponseEntity<Set<String>> listResponseEntity = post(node, "/registernode", newPeer, new ParameterizedTypeReference<Set<String>>() {
});
if (listResponseEntity != null) {
Set<String> list = listResponseEntity.getBody();
peers.addAll(list.stream().filter(e -> !e.equals(instanceInfo.getNode())).collect(Collectors.toSet()));
newPeers.addAll(list.stream().filter(e -> !e.equals(instanceInfo.getNode())).collect(Collectors.toSet()));
}
}
peers.addAll(newPeers);
peersRepository.savePeers(peers);
LOGGER.info("adding node {} to the list of known peers.", newPeer);
} else {
......
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