generator

package module
v1.0.28 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2026 License: BSD-3-Clause Imports: 12 Imported by: 1

Documentation

Overview

Package generator provides ML-driven browser fingerprint generation.

The generator uses the trained neural pipeline to produce realistic fingerprints that pass forgery detection and cross-layer consistency checks. It supports:

  • Random generation: pick a random browser profile and mutate it
  • Targeted generation: specify browser type and OS
  • Batch generation: produce multiple diverse fingerprints
  • ML-validated generation: iteratively refine until quality passes
  • Noise-injected generation: add controlled noise for privacy

Usage:

gen := generator.NewSmartGenerator(mlService, nil)
result, err := gen.Generate(&generator.SmartGenerateConfig{
    TargetBrowser: "chrome",
    TargetOS:      "windows",
})

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoProfilesAvailable indicates no available fingerprint profiles
	ErrNoProfilesAvailable = fmt.Errorf("%w: for generators", errs.ErrNoProfilesAvailable)

	// ErrFailedToGenerateFingerprint indicates fingerprint generation failure
	ErrFailedToGenerateFingerprint = fmt.Errorf("%w: fingerprint generation failed", errs.ErrInvalidFingerprint)

	// ErrInvalidRandomSource indicates invalid random source
	ErrInvalidRandomSource = fmt.Errorf("%w: invalid random source", errs.ErrInvalidFingerprint)
)
View Source
var DefaultSmartGeneratorConfig = &SmartGeneratorConfig{
	MaxRetries:            20,
	DefaultNoiseIntensity: 0.05,
	QualityThreshold:      0.6,
	EnableCaching:         true,
	CacheSize:             100,
}

DefaultSmartGeneratorConfig provides sensible defaults.

Functions

func IsFailedToGenerateFingerprint

func IsFailedToGenerateFingerprint(err error) bool

IsFailedToGenerateFingerprint checks whether the error indicates fingerprint generation failure

func IsNoProfilesAvailable

func IsNoProfilesAvailable(err error) bool

IsNoProfilesAvailable checks whether the error indicates no available fingerprints

Types

type GeneratedProfile added in v1.0.17

type GeneratedProfile struct {
	Profile     *profiles.ClientProfile
	Quality     float64
	Source      string
	GeneratedAt time.Time
}

GeneratedProfile is a cached generation result.

type GeneratorStats added in v1.0.17

type GeneratorStats struct {
	TotalGenerated    int64
	TotalAttempts     int64
	TotalRejected     int64
	AvgAttemptsPerGen float64
	SuccessRate       float64
}

GeneratorStats holds generator statistics.

type ProfileQualityRank added in v1.0.17

type ProfileQualityRank struct {
	ProfileID    string
	BrowserType  string
	QualityScore float64
	ForgeryProb  float64
	Consistency  float64
	Confidence   float64
}

ProfileQualityRank ranks a profile by its ML quality metrics.

type SimilarProfile added in v1.0.17

type SimilarProfile struct {
	Profile    profiles.ClientProfile
	Distance   float64
	Similarity float64
}

SimilarProfile represents a profile similar to a target.

type SmartGenerateConfig added in v1.0.17

type SmartGenerateConfig struct {
	// TargetBrowser is the desired browser family (e.g., "chrome", "firefox").
	TargetBrowser string

	// TargetOS is the desired operating system (e.g., "windows", "macos").
	TargetOS string

	// NoiseIntensity overrides the default noise level [0,1].
	NoiseIntensity float64

	// MaxRetries overrides the default max retries.
	MaxRetries int

	// QualityThreshold overrides the default quality threshold.
	QualityThreshold float64
}

SmartGenerateConfig controls a single generation request.

type SmartGenerateResult added in v1.0.17

type SmartGenerateResult struct {
	// Profile is the generated fingerprint.
	Profile *profiles.ClientProfile

	// QualityScore is the composite quality score [0,1].
	QualityScore float64

	// Validation contains detailed ML validation results.
	Validation *ml.ValidationResult

	// Attempts is how many candidates were evaluated.
	Attempts int

	// SourceProfileID is the base profile that was mutated.
	SourceProfileID string

	// GenerationTime is total generation duration.
	GenerationTime time.Duration
}

SmartGenerateResult is the output of ML-driven generation.

type SmartGenerator added in v1.0.17

type SmartGenerator struct {
	// contains filtered or unexported fields
}

SmartGenerator uses ML models to generate and validate fingerprints.

func NewSmartGenerator added in v1.0.17

func NewSmartGenerator(mlService *ml.MLService, config *SmartGeneratorConfig) *SmartGenerator

NewSmartGenerator creates a new ML-driven generator.

func (*SmartGenerator) FindSimilarProfiles added in v1.0.17

func (g *SmartGenerator) FindSimilarProfiles(target *profiles.ClientProfile, topN int) []SimilarProfile

FindSimilarProfiles finds profiles most similar to a given profile using embedding distance.

func (*SmartGenerator) Generate added in v1.0.17

Generate produces a single ML-validated fingerprint.

func (*SmartGenerator) GenerateBatch added in v1.0.17

func (g *SmartGenerator) GenerateBatch(n int, config *SmartGenerateConfig) ([]*SmartGenerateResult, error)

GenerateBatch produces multiple diverse fingerprints.

func (*SmartGenerator) GenerateEmbedding added in v1.0.17

func (g *SmartGenerator) GenerateEmbedding(browser string) ([]float64, error)

GenerateEmbedding produces a 32-dim embedding for a target browser.

func (*SmartGenerator) GenerateFeatureVector added in v1.0.17

func (g *SmartGenerator) GenerateFeatureVector(browser string) ([]float64, error)

GenerateFeatureVector produces only the feature vector (no full profile) for a given browser type. Useful for embedding similarity searches.

func (*SmartGenerator) GenerateForBrowser added in v1.0.17

func (g *SmartGenerator) GenerateForBrowser(browser string) (*SmartGenerateResult, error)

GenerateForBrowser is a convenience method for generating by browser.

func (*SmartGenerator) GenerateForOS added in v1.0.17

func (g *SmartGenerator) GenerateForOS(os string) (*SmartGenerateResult, error)

GenerateForOS is a convenience method for generating by OS.

func (*SmartGenerator) RankProfiles added in v1.0.17

func (g *SmartGenerator) RankProfiles() []ProfileQualityRank

RankProfiles evaluates and ranks all profiles by ML quality score.

func (*SmartGenerator) Stats added in v1.0.17

func (g *SmartGenerator) Stats() *GeneratorStats

Stats returns current generator statistics.

type SmartGeneratorConfig added in v1.0.17

type SmartGeneratorConfig struct {
	// MaxRetries is the maximum number of generation attempts.
	MaxRetries int

	// DefaultNoiseIntensity is the noise level for mutations [0,1].
	DefaultNoiseIntensity float64

	// QualityThreshold: generated fingerprints must achieve this quality
	// score (composite of forgery, consistency, confidence) in [0,1].
	QualityThreshold float64

	// EnableCaching caches recently generated profiles for dedup.
	EnableCaching bool

	// CacheSize is the max number of cached profiles.
	CacheSize int
}

SmartGeneratorConfig configures the ML-driven generator.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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