|
1 | 1 | import datetime
|
2 | 2 | import fcntl
|
| 3 | +import json |
3 | 4 | import logging
|
4 | 5 | import random
|
5 | 6 | import shutil
|
|
8 | 9 | import traceback
|
9 | 10 | import urllib.parse
|
10 | 11 | from ipaddress import ip_address
|
11 |
| -from typing import Any, Callable, List, Optional, Tuple |
| 12 | +from typing import Any, Callable, Dict, List, Optional, Tuple |
12 | 13 |
|
13 | 14 | import timeout_decorator
|
14 | 15 | from karton.core import Karton, Task
|
@@ -89,6 +90,12 @@ def __init__(self, db: Optional[DB] = None, *args, **kwargs) -> None: # type: i
|
89 | 90 | hosts_file.write(additional_data_file.read())
|
90 | 91 | fcntl.flock(hosts_file.fileno(), fcntl.LOCK_UN)
|
91 | 92 |
|
| 93 | + if Config.Limits.SCAN_SPEED_OVERRIDES_FILE: |
| 94 | + with open(Config.Limits.SCAN_SPEED_OVERRIDES_FILE, "r") as f: |
| 95 | + self._scan_speed_overrides: Dict[str, float] = json.load(f) |
| 96 | + else: |
| 97 | + self._scan_speed_overrides = {} |
| 98 | + |
92 | 99 | if Config.Miscellaneous.BLOCKLIST_FILE:
|
93 | 100 | self._blocklist = load_blocklist(Config.Miscellaneous.BLOCKLIST_FILE)
|
94 | 101 | else:
|
@@ -288,12 +295,17 @@ def _single_iteration(self) -> int:
|
288 | 295 | if "requests_per_second_override" in task.payload_persistent
|
289 | 296 | ]
|
290 | 297 |
|
| 298 | + for task in tasks: |
| 299 | + destination = self._get_scan_destination(task) |
| 300 | + if destination in self._scan_speed_overrides: |
| 301 | + requests_per_second_overrides.append(self._scan_speed_overrides[destination]) |
| 302 | + |
291 | 303 | self.requests_per_second_for_current_tasks = min( # type: ignore
|
292 | 304 | requests_per_second_overrides if requests_per_second_overrides else [Config.Limits.REQUESTS_PER_SECOND]
|
293 | 305 | )
|
294 | 306 |
|
295 | 307 | if requests_per_second_overrides:
|
296 |
| - self.log.info("Overriding requests per second to %f", self.requests_per_second_for_current_tasks) |
| 308 | + self.log.info("Setting requests per second to %f", self.requests_per_second_for_current_tasks) |
297 | 309 |
|
298 | 310 | if len(tasks):
|
299 | 311 | time_start = time.time()
|
|
0 commit comments