use of org.ethereum.net.server.Channel in project rskj by rsksmart.
the class SyncPool method heartBeat.
private void heartBeat() {
for (Channel peer : this) {
if (!peer.isIdle() && peer.getSyncStats().secondsSinceLastUpdate() > config.peerChannelReadTimeout()) {
logger.info("Peer {}: no response after %d seconds", peer.getPeerIdShort(), config.peerChannelReadTimeout());
peer.dropConnection();
}
}
}
use of org.ethereum.net.server.Channel in project rskj by rsksmart.
the class SyncPool method prepareActive.
private void prepareActive() {
synchronized (peers) {
List<Channel> active = new ArrayList<>(peers.values());
if (active.isEmpty()) {
return;
}
// filtering by 20% from top difficulty
Collections.sort(active, new Comparator<Channel>() {
@Override
public int compare(Channel c1, Channel c2) {
return c2.getTotalDifficulty().compareTo(c1.getTotalDifficulty());
}
});
BigInteger highestDifficulty = active.get(0).getTotalDifficulty();
int thresholdIdx = min(config.syncPeerCount(), active.size()) - 1;
for (int i = thresholdIdx; i >= 0; i--) {
if (isIn20PercentRange(active.get(i).getTotalDifficulty(), highestDifficulty)) {
thresholdIdx = i;
break;
}
}
List<Channel> filtered = active.subList(0, thresholdIdx + 1);
// sorting by latency in asc order
Collections.sort(filtered, new Comparator<Channel>() {
@Override
public int compare(Channel c1, Channel c2) {
return Double.valueOf(c1.getPeerStats().getAvgLatency()).compareTo(c2.getPeerStats().getAvgLatency());
}
});
synchronized (activePeers) {
activePeers.clear();
activePeers.addAll(filtered);
}
}
}
Aggregations