use of org.tron.common.utils.Time in project java-tron by tronprotocol.
the class NodeImpl method startFetchSyncBlock.
private synchronized void startFetchSyncBlock() {
// TODO: check how many block is processing and decide if fetch more
HashMap<PeerConnection, List<BlockId>> send = new HashMap<>();
HashSet<BlockId> request = new HashSet<>();
getActivePeer().stream().filter(peer -> peer.isNeedSyncFromPeer() && !peer.isBusy()).forEach(peer -> {
if (!send.containsKey(peer)) {
// TODO: Attention multi thread here
send.put(peer, new LinkedList<>());
}
for (BlockId blockId : peer.getSyncBlockToFetch()) {
if (// TODO: clean processing block
!request.contains(blockId) && !syncBlockIdWeRequested.containsKey(blockId)) {
send.get(peer).add(blockId);
request.add(blockId);
// TODO: check max block num to fetch from one peer.
// if (send.get(peer).size() > 200) { //Max Blocks peer get one time
// break;
// }
}
}
});
send.forEach((peer, blockIds) -> {
// TODO: use collector
blockIds.forEach(blockId -> {
syncBlockIdWeRequested.put(blockId, System.currentTimeMillis());
peer.getSyncBlockRequested().put(blockId, System.currentTimeMillis());
});
List<Sha256Hash> ids = new LinkedList<>();
ids.addAll(blockIds);
peer.sendMessage(new FetchInvDataMessage(ids, InventoryType.BLOCK));
});
send.clear();
}
Aggregations