File Scanner 1.0.0
A high-performance C++ malicious file scanner.
Loading...
Searching...
No Matches
scanner::Scanner Class Referencefinal

The concrete, internal implementation of the IScanner interface. More...

#include <scanner.h>

Inheritance diagram for scanner::Scanner:
Inheritance graph
Collaboration diagram for scanner::Scanner:
Collaboration graph

Public Member Functions

 Scanner (IHashDatabase &db, ILogger &logger, IFileHasher &hasher, std::size_t num_threads)
 Constructs a Scanner instance with its dependencies.
 
ScanResult Scan (const std::filesystem::path &scan_path) override
 Scans the specified directory.
 
- Public Member Functions inherited from scanner::IScanner
virtual ~IScanner ()=default
 

Private Member Functions

void ProducerTask (const std::filesystem::path &scan_path, ThreadPool &pool, std::promise< void > &producer_promise)
 The task executed by the producer thread.
 
void ConsumerTask (const std::filesystem::path &path)
 The task executed by consumer threads in the pool.
 

Private Attributes

IHashDatabasedb_
 
ILoggerlogger_
 
IFileHasherhasher_
 
std::size_t num_threads_
 
std::atomic< std::uint64_t > total_files_processed_ {0}
 
std::atomic< std::uint64_t > malicious_files_detected_ {0}
 
std::atomic< std::uint64_t > errors_ {0}
 

Detailed Description

The concrete, internal implementation of the IScanner interface.

This class is not exported and is only accessible via the CreateScanner factory function. It orchestrates the multithreaded scanning process.

Constructor & Destructor Documentation

◆ Scanner()

scanner::Scanner::Scanner ( IHashDatabase db,
ILogger logger,
IFileHasher hasher,
std::size_t  num_threads 
)
explicit

Constructs a Scanner instance with its dependencies.

Parameters
dbA reference to a hash database implementation.
loggerA reference to a logger implementation.
hasherA reference to a file hasher implementation.
num_threadsThe number of worker threads to use for scanning.

Member Function Documentation

◆ ConsumerTask()

void scanner::Scanner::ConsumerTask ( const std::filesystem::path &  path)
private

The task executed by consumer threads in the pool.

Processes a single file: hashes it, checks the hash against the database, and logs a detection if found. It also updates the atomic counters for scan statistics.

Parameters
pathThe path of the file to process.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ProducerTask()

void scanner::Scanner::ProducerTask ( const std::filesystem::path &  scan_path,
ThreadPool pool,
std::promise< void > &  producer_promise 
)
private

The task executed by the producer thread.

Traverses the filesystem recursively from the given root path, enqueues a consumer task for each regular file found, and signals completion or error via a promise.

Parameters
scan_pathThe root directory to traverse.
poolThe thread pool to enqueue tasks into.
producer_promiseA promise to signal the outcome of the traversal.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Scan()

ScanResult scanner::Scanner::Scan ( const std::filesystem::path &  scan_path)
overridevirtual

Scans the specified directory.

Parameters
scan_pathThe root directory for the scan.
Returns
The results of the scan.

Implements scanner::IScanner.

Here is the call graph for this function:

Member Data Documentation

◆ db_

IHashDatabase& scanner::Scanner::db_
private

◆ errors_

std::atomic<std::uint64_t> scanner::Scanner::errors_ {0}
private

◆ hasher_

IFileHasher& scanner::Scanner::hasher_
private

◆ logger_

ILogger& scanner::Scanner::logger_
private

◆ malicious_files_detected_

std::atomic<std::uint64_t> scanner::Scanner::malicious_files_detected_ {0}
private

◆ num_threads_

std::size_t scanner::Scanner::num_threads_
private

◆ total_files_processed_

std::atomic<std::uint64_t> scanner::Scanner::total_files_processed_ {0}
private

The documentation for this class was generated from the following files: