From 0ed285e8e55ecac248f44c389aaa29158520a3c4 Mon Sep 17 00:00:00 2001 From: WildSoft Date: Tue, 13 Oct 2026 10:15:09 +0300 Subject: [PATCH] Update public source --- cracklab/server/repositories/handshakes.py | 100 +++++++++++++++++++++ cracklab/server/services/job_issuance.py | 44 +++++++++ 2 files changed, 144 insertions(+) diff --git a/cracklab/server/repositories/handshakes.py b/cracklab/server/repositories/handshakes.py index 04a47ab..b2d6d0e 100644 --- a/cracklab/server/repositories/handshakes.py +++ b/cracklab/server/repositories/handshakes.py @@ -208,3 +208,103 @@ class HandshakesRepository: method_version, ), ).fetchone() + + def get_search_context_statistics( + self, + handshake_ids: list[int] | tuple[int, ...], + method_id: str, + method_version: int, + ) -> sqlite3.Row | None: + if not handshake_ids: + return None + + placeholders = ", ".join("?" for _ in handshake_ids) + + return self._conn.execute( + f""" + SELECT + COUNT(*) AS matched_count, + SUM( + CASE + WHEN h.hash22000 IS NOT NULL + AND TRIM(h.hash22000) <> '' + THEN 1 + ELSE 0 + END + ) AS valid_hash_count, + SUM( + CASE + WHEN h.hash22000 IS NOT NULL + AND TRIM(h.hash22000) <> '' + AND EXISTS ( + SELECT 1 + FROM credentials AS c + WHERE c.handshake_id = h.id + ) + THEN 1 + ELSE 0 + END + ) AS found_count, + SUM( + CASE + WHEN h.hash22000 IS NOT NULL + AND TRIM(h.hash22000) <> '' + AND NOT EXISTS ( + SELECT 1 + FROM credentials AS c + WHERE c.handshake_id = h.id + ) + AND EXISTS ( + SELECT 1 + FROM crack_attempts AS a + WHERE a.handshake_id = h.id + AND a.method_id = ? + AND a.method_version = ? + AND a.status = 'COMPLETED' + ) + THEN 1 + ELSE 0 + END + ) AS covered_count, + SUM( + CASE + WHEN h.hash22000 IS NOT NULL + AND TRIM(h.hash22000) <> '' + AND NOT EXISTS ( + SELECT 1 + FROM credentials AS c + WHERE c.handshake_id = h.id + ) + AND NOT EXISTS ( + SELECT 1 + FROM crack_attempts AS a + WHERE a.handshake_id = h.id + AND a.method_id = ? + AND a.method_version = ? + AND a.status = 'COMPLETED' + ) + AND EXISTS ( + SELECT 1 + FROM crack_reservations AS r + WHERE r.handshake_id = h.id + AND r.method_id = ? + AND r.method_version = ? + AND r.status = 'ACTIVE' + ) + THEN 1 + ELSE 0 + END + ) AS reserved_count + FROM handshakes AS h + WHERE h.id IN ({placeholders}) + """, + ( + method_id, + method_version, + method_id, + method_version, + method_id, + method_version, + *handshake_ids, + ), + ).fetchone() diff --git a/cracklab/server/services/job_issuance.py b/cracklab/server/services/job_issuance.py index d791fd9..258e901 100644 --- a/cracklab/server/services/job_issuance.py +++ b/cracklab/server/services/job_issuance.py @@ -76,6 +76,50 @@ class JobIssuanceService: ), } + def get_search_context_statistics( + self, + handshake_ids: list[int] | tuple[int, ...], + method_id: str, + method_version: int, + ) -> dict[str, int]: + row = self._handshakes.get_search_context_statistics( + handshake_ids, + method_id, + method_version, + ) + + if row is None: + return { + "matched_count": 0, + "valid_hash_count": 0, + "found_count": 0, + "covered_count": 0, + "reserved_count": 0, + "available_count": 0, + "unsupported_count": 0, + } + + matched_count = int(row["matched_count"] or 0) + valid_hash_count = int(row["valid_hash_count"] or 0) + found_count = int(row["found_count"] or 0) + covered_count = int(row["covered_count"] or 0) + reserved_count = int(row["reserved_count"] or 0) + + return { + "matched_count": matched_count, + "valid_hash_count": valid_hash_count, + "found_count": found_count, + "covered_count": covered_count, + "reserved_count": reserved_count, + "available_count": ( + valid_hash_count + - found_count + - covered_count + - reserved_count + ), + "unsupported_count": matched_count - valid_hash_count, + } + def issue_job( self, method_id: str,