task

package
v0.6.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 27, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package task provides task management and execution logic for the CipherSwarm agent. It handles the full task lifecycle: retrieval, acceptance, execution, status reporting, and error handling.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrTaskBadResponse is returned when the server returns a bad response.
	ErrTaskBadResponse = errors.New("bad response")
	// ErrTaskIsNil is returned when a task parameter is nil.
	ErrTaskIsNil = errors.New("task is nil")
	// ErrNoTaskAvailable is returned when no task is available from the server.
	ErrNoTaskAvailable = errors.New("no task available")
)

Functions

func CleanupTaskFiles

func CleanupTaskFiles(attackID int64)

CleanupTaskFiles removes task-related files (hash list and restore file) for the given attack ID. It is used to clean up files when a task fails before a hashcat session is created, since Session.Cleanup() is not available in those code paths. Resource files (word lists, rule lists, mask lists) are intentionally NOT cleaned here because they are shared across attacks and may be reused via checksum-based caching. It is idempotent — files already removed (e.g., by Session.Cleanup) are silently skipped. Errors during removal are logged but do not halt the cleanup process.

func DownloadFiles

func DownloadFiles(ctx context.Context, attack *api.Attack) error

DownloadFiles downloads the necessary files for the provided attack. It performs the following steps: 1. Logs the start of the download process. 2. Downloads the hash list associated with the attack. 3. Iterates over resource files (word list, rule list, and mask list) and downloads each one. If any step encounters an error, the function returns that error.

Types

type Manager

type Manager struct {
	BackendDevices string
	OpenCLDevices  string
	// contains filtered or unexported fields
}

Manager orchestrates task lifecycle operations using injected API clients.

func NewManager

func NewManager(tc api.TasksClient, ac api.AttacksClient) *Manager

NewManager creates a new task Manager with the given API clients.

func (*Manager) AbandonTask

func (m *Manager) AbandonTask(ctx context.Context, task *api.Task)

AbandonTask sets the given task to an abandoned state and logs any errors that occur. If the task is nil, it logs an error and returns immediately.

func (*Manager) AcceptTask

func (m *Manager) AcceptTask(ctx context.Context, task *api.Task) error

AcceptTask attempts to accept the given task identified by its ID. It logs an error and returns if the task is nil.

func (*Manager) GetAttackParameters

func (m *Manager) GetAttackParameters(ctx context.Context, attackID int64) (*api.Attack, error)

GetAttackParameters retrieves the attack parameters for a given attackID via the API client interface. Returns an Attack object if the API call is successful and the response status is OK.

func (*Manager) GetNewTask

func (m *Manager) GetNewTask(ctx context.Context) (*api.Task, error)

GetNewTask retrieves a new task from the server. If the server responds with HTTP 204 (no content), it returns (nil, ErrNoTaskAvailable). For any other unexpected response status, an error is returned.

func (*Manager) RunTask

func (m *Manager) RunTask(ctx context.Context, task *api.Task, attack *api.Attack) error

RunTask performs a hashcat attack based on the provided task and attack objects. It initializes the task, creates job parameters, starts the hashcat session, and handles task completion or errors.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL