benchmark

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package benchmark provides benchmark management for the CipherSwarm agent. It handles running hashcat benchmarks, submitting results to the server, and caching results for retry on failure.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config added in v0.6.2

type Config struct {
	// OutPath is the directory for hashcat output and charset temp files.
	OutPath string
	// ZapsPath is the directory for zap files, removed on cleanup unless retained.
	ZapsPath string
	// RetainZapsOnCompletion keeps the zaps directory after a session completes.
	RetainZapsOnCompletion bool
	// EnableAdditionalHashTypes enables all hash types in full benchmark mode.
	EnableAdditionalHashTypes bool
}

Config holds injected path and benchmark-mode configuration for a Manager. It is a value type (safe to copy), mirroring task.Config and devices.DeviceConfig, so benchmark sessions are constructable without reading agentstate directly.

type Manager

type Manager struct {
	DeviceConfig devices.DeviceConfig
	// Config holds injected path and benchmark-mode configuration for this Manager.
	Config Config
	// contains filtered or unexported fields
}

Manager handles benchmark operations including running benchmarks, submitting results, and managing the benchmark cache.

func NewManager

func NewManager(agentsClient api.AgentsClient) *Manager

NewManager creates a new benchmark Manager with the given API client.

func (*Manager) RunBackgroundBenchmarks added in v0.6.2

func (m *Manager) RunBackgroundBenchmarks(ctx context.Context, isIdle func() bool)

RunBackgroundBenchmarks replaces placeholder cache entries with real benchmark results by running hashcat --benchmark -m <type> for each placeholder hash type. It waits for the agent to be idle (per the injected isIdle predicate) before each run and submits results incrementally. The method is designed to run as a long-lived goroutine.

func (*Manager) RunCapabilityDetection added in v0.6.2

func (m *Manager) RunCapabilityDetection(ctx context.Context) ([]Result, error)

RunCapabilityDetection runs hashcat --hash-info --machine-readable to discover supported hash types without executing a full benchmark. It returns placeholder Result entries (SpeedHs="1", Placeholder=true) for each discovered type.

func (*Manager) SubmitCapabilityResults added in v0.6.2

func (m *Manager) SubmitCapabilityResults(ctx context.Context, results []Result) error

SubmitCapabilityResults caches and submits placeholder capability-detection results. It is the deferred-benchmark equivalent of the full UpdateBenchmarks path.

func (*Manager) TrySubmitCachedBenchmarks

func (m *Manager) TrySubmitCachedBenchmarks(ctx context.Context) bool

TrySubmitCachedBenchmarks attempts to submit previously cached benchmark results to the server. Returns false immediately if the force-benchmark flag is set (stale results should not be submitted). If all cached results are already marked as submitted, returns true immediately without re-persisting the cache. Otherwise, filters to only unsubmitted results, sends them, marks as submitted, and persists the updated cache. Returns true if all results are now submitted, false otherwise (cache is preserved for the next attempt).

func (*Manager) UpdateBenchmarks

func (m *Manager) UpdateBenchmarks(ctx context.Context) error

UpdateBenchmarks updates the benchmark metrics using Hashcat. It first checks for cached results from a previous run. If a valid cache exists (and the force-benchmark flag is not set), it attempts submission of only unsubmitted results. Submission failure of cached results is non-fatal — it returns nil and the cache is preserved for retry via TrySubmitCachedBenchmarks.

When no cache exists (or force re-run is requested), it runs a new benchmark session and delegates to cacheAndSubmitBenchmarks, which may return an error if both the cache save and submission fail simultaneously.

type Result added in v0.6.2

type Result struct {
	Device      string `json:"device,omitempty"`      // Device is the numeric device ID used for the benchmark.
	DeviceName  string `json:"device_name,omitempty"` // DeviceName is the human-readable device name (display-only, not sent to API).
	HashType    string `json:"hash_type,omitempty"`   // HashType is the type of hash used for the benchmark.
	RuntimeMs   string `json:"runtime,omitempty"`     // RuntimeMs is the runtime of the benchmark in milliseconds.
	HashTimeMs  string `json:"hash_time,omitempty"`   // HashTimeMs is the time taken to hash in milliseconds.
	SpeedHs     string `json:"hash_speed,omitempty"`  // SpeedHs is the hash speed in hashes per second.
	Submitted   bool   `json:"submitted,omitempty"`   // Submitted indicates whether this result has been accepted by the server.
	Placeholder bool   `json:"placeholder,omitempty"` // Placeholder indicates this is a capability-detection result, not a real benchmark.
}

Result represents the outcome of a benchmark session.

Jump to

Keyboard shortcuts

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