diff --git a/src/inc/api/APISendProgress.class.php b/src/inc/api/APISendProgress.class.php index 4d248c710..66b9b46e3 100644 --- a/src/inc/api/APISendProgress.class.php +++ b/src/inc/api/APISendProgress.class.php @@ -437,10 +437,34 @@ public function execute($QUERY = array()) { } switch ($state) { - case DHashcatStatus::EXHAUSTED: + case DHashcatStatus::EXHAUSTED: // the chunk has finished (exhausted) Factory::getChunkFactory()->mset($chunk, [Chunk::SPEED => 0, Chunk::PROGRESS => 10000, Chunk::CHECKPOINT => $chunk->getSkip() + $chunk->getLength()]); DServerLog::log(DServerLog::TRACE, "Chunk is exhausted (cracker status)", [$this->agent, $chunk]); + + $timeTaken = $chunk->getSolveTime() - $chunk->getDispatchTime(); + if($timeTaken < 0) break; // prevent math & logic errors + + $differenceToChunk = $task->getChunkTime() / $timeTaken; + // Limit how much difference a chunk can have to the previous. + $differenceToChunk = ($differenceToChunk > 1.5) ? 1.5 : $differenceToChunk; + $differenceToChunk = ($differenceToChunk < (2/3)) ? (2/3) : $differenceToChunk; + if ($differenceToChunk > 0.8 && $differenceToChunk < 1.2) break; + + if($task->getStaticChunks() === 0) { // Not static chunks + $qF1 = new QueryFilter(Assignment::AGENT_ID, $chunk->getAgentId(), "="); + $qF2 = new QueryFilter(Assignment::TASK_ID, $chunk->getTaskId(), "="); + $assignment = Factory::getAssignmentFactory()->filter([Factory::FILTER => [$qF1, $qF2]])[0]; + + $benchmark = $assignment->getBenchmark(); + $benchmarkParts = explode(":", $benchmark); + if($benchmarkParts[0] == 0 || count($benchmarkParts) != 2) break; + $newBenchmark = $differenceToChunk * $benchmarkParts[0]; + $assignment->setBenchmark(round($newBenchmark).":".round($benchmarkParts[1])); + DServerLog::log(DServerLog::INFO, "{$timeTaken}---{$task->getChunkTime}", [$this->agent, $assignment]); + DServerLog::log(DServerLog::INFO, "Multiplied the benchmark of agent by ".round($differenceToChunk,2), [$this->agent, $assignment]); + Factory::getAssignmentFactory()->update($assignment); + } break; case DHashcatStatus::CRACKED: // the chunk has finished (cracked whole hashList) @@ -535,4 +559,4 @@ public function execute($QUERY = array()) { ) ); } -} \ No newline at end of file +} diff --git a/src/inc/utils/AgentUtils.class.php b/src/inc/utils/AgentUtils.class.php index e00592571..de43abf03 100644 --- a/src/inc/utils/AgentUtils.class.php +++ b/src/inc/utils/AgentUtils.class.php @@ -372,7 +372,7 @@ public static function deleteDependencies($agent) { public static function assign($agentId, $taskId, $user) { $agent = AgentUtils::getAgent($agentId, $user); - if ($taskId == 0 || empty($taskId)) { // unassign + if ($taskId == 0) { // unassign $qF = new QueryFilter(Agent::AGENT_ID, $agent->getId(), "="); Factory::getAssignmentFactory()->massDeletion([Factory::FILTER => $qF]); if (isset($_GET['task'])) { @@ -565,4 +565,4 @@ public static function deleteVoucher($voucher) { } Factory::getRegVoucherFactory()->delete($voucher); } -} \ No newline at end of file +}