Skip to content

Commit 43e26f2

Browse files
paberrjgraef
authored andcommitted
Fix DoS protection
1 parent 0621b17 commit 43e26f2

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

consensus-albatross/src/sync/history.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -413,9 +413,12 @@ impl<TNetwork: Network> Stream for HistorySync<TNetwork> {
413413
}
414414

415415
// Stop pulling in new EpochIds if we hit a maximum a number of clusters to prevent DoS.
416-
if self.sync_clusters.len() < Self::MAX_CLUSTERS {
417-
// FIXME: move check into loop!
418-
while let Poll::Ready(Some(epoch_ids)) = self.epoch_ids_stream.poll_next_unpin(cx) {
416+
loop {
417+
if self.sync_clusters.len() >= Self::MAX_CLUSTERS {
418+
break;
419+
}
420+
421+
if let Poll::Ready(Some(epoch_ids)) = self.epoch_ids_stream.poll_next_unpin(cx) {
419422
if let Some(epoch_ids) = epoch_ids {
420423
// The peer might have disconnected during the request.
421424
// FIXME Check if the peer is still connected
@@ -429,6 +432,8 @@ impl<TNetwork: Network> Stream for HistorySync<TNetwork> {
429432
}
430433
self.cluster_epoch_ids(epoch_ids);
431434
}
435+
} else {
436+
break;
432437
}
433438
}
434439

0 commit comments

Comments
 (0)