sweeper

package
v1.0.78 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2025 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package sweeper pkg/sweeper/memory_store.go

Package sweeper is a generated GoMock package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseProcessor

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

func NewBaseProcessor

func NewBaseProcessor(config *models.Config, log logger.Logger) *BaseProcessor

func (*BaseProcessor) GetFirstSeenTimes

func (p *BaseProcessor) GetFirstSeenTimes() map[string]time.Time

func (*BaseProcessor) GetHostCount

func (p *BaseProcessor) GetHostCount() int

func (*BaseProcessor) GetHostMap

func (p *BaseProcessor) GetHostMap() map[string]*models.HostResult

func (*BaseProcessor) GetLatestSweepTime

func (p *BaseProcessor) GetLatestSweepTime() time.Time

func (*BaseProcessor) GetPortCounts

func (p *BaseProcessor) GetPortCounts() map[int]int

GetPortCounts aggregates port counts across all shards

func (*BaseProcessor) GetSummary

func (p *BaseProcessor) GetSummary(ctx context.Context) (*models.SweepSummary, error)

func (*BaseProcessor) GetSummaryStream

func (p *BaseProcessor) GetSummaryStream(ctx context.Context, hostCh chan<- models.HostResult) (*models.SweepSummary, error)

GetSummaryStream provides a streaming interface for large-scale summaries to avoid building large slices in memory. Sends HostResult objects to the channel.

func (*BaseProcessor) Process

func (p *BaseProcessor) Process(result *models.Result) error

func (*BaseProcessor) UpdateConfig

func (p *BaseProcessor) UpdateConfig(config *models.Config)

type DeviceRegistryService

type DeviceRegistryService interface {
	ProcessSweepResult(ctx context.Context, result *models.SweepResult) error
	UpdateDevice(ctx context.Context, update *models.DeviceUpdate) error
	GetDevice(ctx context.Context, deviceID string) (*models.UnifiedDevice, error)
	GetDevicesByIP(ctx context.Context, ip string) ([]*models.UnifiedDevice, error)
	ListDevices(ctx context.Context, limit, offset int) ([]*models.UnifiedDevice, error)
}

DeviceRegistryService interface for device registry operations

type DeviceResultAggregator added in v1.0.55

type DeviceResultAggregator struct {
	DeviceID    string
	Results     []*models.Result
	ExpectedIPs []string
	Metadata    map[string]interface{}
	AgentID     string
	PollerID    string
	Partition   string
	// contains filtered or unexported fields
}

DeviceResultAggregator aggregates scan results for a device with multiple IPs

type InMemoryStore

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

InMemoryStore implements Store interface for temporary storage.

func (*InMemoryStore) Close

func (s *InMemoryStore) Close() error

func (*InMemoryStore) GetHostResults

func (s *InMemoryStore) GetHostResults(_ context.Context, filter *models.ResultFilter) ([]models.HostResult, error)

GetHostResults returns a slice of HostResult based on the provided filter.

func (*InMemoryStore) GetResults

func (s *InMemoryStore) GetResults(_ context.Context, filter *models.ResultFilter) ([]models.Result, error)

GetResults returns a list of Results that match the filter.

func (*InMemoryStore) GetSweepSummary

func (s *InMemoryStore) GetSweepSummary(_ context.Context) (*models.SweepSummary, error)

GetSweepSummary gathers high-level sweep information.

func (*InMemoryStore) PruneResults

func (s *InMemoryStore) PruneResults(_ context.Context, age time.Duration) error

PruneResults removes old results that haven't been seen since 'age' ago.

func (*InMemoryStore) SaveHostResult

func (s *InMemoryStore) SaveHostResult(_ context.Context, result *models.HostResult) error

SaveHostResult updates the last-seen time (and possibly availability) for the given host. For in-memory store, we'll store the latest host result for each host.

func (*InMemoryStore) SaveResult

func (s *InMemoryStore) SaveResult(_ context.Context, result *models.Result) error

SaveResult stores (or updates) a Result in memory.

type InMemoryStoreOption added in v1.0.55

type InMemoryStoreOption func(*inMemoryStoreConfig)

InMemoryStoreOption configures optional behaviour for NewInMemoryStore.

func WithCleanupInterval added in v1.0.55

func WithCleanupInterval(interval time.Duration) InMemoryStoreOption

WithCleanupInterval overrides the background cleanup interval. Passing zero or a negative duration disables the background cleanup goroutine, which is helpful in tight unit tests.

func WithMaxResults added in v1.0.55

func WithMaxResults(max int) InMemoryStoreOption

WithMaxResults overrides the default result preallocation hint.

func WithoutPreallocation added in v1.0.55

func WithoutPreallocation() InMemoryStoreOption

WithoutPreallocation disables up-front slice/map capacity hints. Useful for tests that need to avoid large allocations while still exercising core behaviour.

type KVStore

type KVStore interface {
	Get(ctx context.Context, key string) (value []byte, found bool, err error)
	Watch(ctx context.Context, key string) (<-chan []byte, error)
}

type MockDeviceRegistryService added in v1.0.55

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

MockDeviceRegistryService is a mock of DeviceRegistryService interface.

func NewMockDeviceRegistryService added in v1.0.55

func NewMockDeviceRegistryService(ctrl *gomock.Controller) *MockDeviceRegistryService

NewMockDeviceRegistryService creates a new mock instance.

func (*MockDeviceRegistryService) EXPECT added in v1.0.55

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockDeviceRegistryService) GetDevice added in v1.0.55

func (m *MockDeviceRegistryService) GetDevice(ctx context.Context, deviceID string) (*models.UnifiedDevice, error)

GetDevice mocks base method.

func (*MockDeviceRegistryService) GetDeviceByIDStrict added in v1.0.68

func (m *MockDeviceRegistryService) GetDeviceByIDStrict(ctx context.Context, deviceID string) (*models.UnifiedDevice, error)

GetDeviceByIDStrict mocks base method.

func (*MockDeviceRegistryService) GetDevicesByIP added in v1.0.55

func (m *MockDeviceRegistryService) GetDevicesByIP(ctx context.Context, ip string) ([]*models.UnifiedDevice, error)

GetDevicesByIP mocks base method.

func (*MockDeviceRegistryService) ListDevices added in v1.0.55

func (m *MockDeviceRegistryService) ListDevices(ctx context.Context, limit, offset int) ([]*models.UnifiedDevice, error)

ListDevices mocks base method.

func (*MockDeviceRegistryService) ProcessSweepResult added in v1.0.55

func (m *MockDeviceRegistryService) ProcessSweepResult(ctx context.Context, result *models.SweepResult) error

ProcessSweepResult mocks base method.

func (*MockDeviceRegistryService) UpdateDevice added in v1.0.55

func (m *MockDeviceRegistryService) UpdateDevice(ctx context.Context, update *models.DeviceUpdate) error

UpdateDevice mocks base method.

type MockDeviceRegistryServiceMockRecorder added in v1.0.55

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

MockDeviceRegistryServiceMockRecorder is the mock recorder for MockDeviceRegistryService.

func (*MockDeviceRegistryServiceMockRecorder) GetDevice added in v1.0.55

func (mr *MockDeviceRegistryServiceMockRecorder) GetDevice(ctx, deviceID any) *gomock.Call

GetDevice indicates an expected call of GetDevice.

func (*MockDeviceRegistryServiceMockRecorder) GetDeviceByIDStrict added in v1.0.68

func (mr *MockDeviceRegistryServiceMockRecorder) GetDeviceByIDStrict(ctx, deviceID any) *gomock.Call

GetDeviceByIDStrict indicates an expected call of GetDeviceByIDStrict.

func (*MockDeviceRegistryServiceMockRecorder) GetDevicesByIP added in v1.0.55

func (mr *MockDeviceRegistryServiceMockRecorder) GetDevicesByIP(ctx, ip any) *gomock.Call

GetDevicesByIP indicates an expected call of GetDevicesByIP.

func (*MockDeviceRegistryServiceMockRecorder) ListDevices added in v1.0.55

func (mr *MockDeviceRegistryServiceMockRecorder) ListDevices(ctx, limit, offset any) *gomock.Call

ListDevices indicates an expected call of ListDevices.

func (*MockDeviceRegistryServiceMockRecorder) ProcessSweepResult added in v1.0.55

func (mr *MockDeviceRegistryServiceMockRecorder) ProcessSweepResult(ctx, result any) *gomock.Call

ProcessSweepResult indicates an expected call of ProcessSweepResult.

func (*MockDeviceRegistryServiceMockRecorder) UpdateDevice added in v1.0.55

func (mr *MockDeviceRegistryServiceMockRecorder) UpdateDevice(ctx, update any) *gomock.Call

UpdateDevice indicates an expected call of UpdateDevice.

type MockKVStore

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

MockKVStore is a mock of KVStore interface.

func NewMockKVStore

func NewMockKVStore(ctrl *gomock.Controller) *MockKVStore

NewMockKVStore creates a new mock instance.

func (*MockKVStore) EXPECT

func (m *MockKVStore) EXPECT() *MockKVStoreMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockKVStore) Get added in v1.0.55

func (m *MockKVStore) Get(ctx context.Context, key string) ([]byte, bool, error)

Get mocks base method.

func (*MockKVStore) Watch

func (m *MockKVStore) Watch(ctx context.Context, key string) (<-chan []byte, error)

Watch mocks base method.

type MockKVStoreMockRecorder

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

MockKVStoreMockRecorder is the mock recorder for MockKVStore.

func (*MockKVStoreMockRecorder) Get added in v1.0.55

func (mr *MockKVStoreMockRecorder) Get(ctx, key any) *gomock.Call

Get indicates an expected call of Get.

func (*MockKVStoreMockRecorder) Watch

func (mr *MockKVStoreMockRecorder) Watch(ctx, key any) *gomock.Call

Watch indicates an expected call of Watch.

type MockObjectStore added in v1.0.55

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

MockObjectStore is a mock of ObjectStore interface.

func NewMockObjectStore added in v1.0.55

func NewMockObjectStore(ctrl *gomock.Controller) *MockObjectStore

NewMockObjectStore creates a new mock instance.

func (*MockObjectStore) DownloadObject added in v1.0.55

func (m *MockObjectStore) DownloadObject(ctx context.Context, key string) ([]byte, error)

DownloadObject mocks base method.

func (*MockObjectStore) EXPECT added in v1.0.55

EXPECT returns an object that allows the caller to indicate expected use.

type MockObjectStoreMockRecorder added in v1.0.55

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

MockObjectStoreMockRecorder is the mock recorder for MockObjectStore.

func (*MockObjectStoreMockRecorder) DownloadObject added in v1.0.55

func (mr *MockObjectStoreMockRecorder) DownloadObject(ctx, key any) *gomock.Call

DownloadObject indicates an expected call of DownloadObject.

type MockReporter

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

MockReporter is a mock of Reporter interface.

func NewMockReporter

func NewMockReporter(ctrl *gomock.Controller) *MockReporter

NewMockReporter creates a new mock instance.

func (*MockReporter) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockReporter) Report

func (m *MockReporter) Report(arg0 context.Context, arg1 *models.SweepSummary) error

Report mocks base method.

type MockReporterMockRecorder

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

MockReporterMockRecorder is the mock recorder for MockReporter.

func (*MockReporterMockRecorder) Report

func (mr *MockReporterMockRecorder) Report(arg0, arg1 any) *gomock.Call

Report indicates an expected call of Report.

type MockResultProcessor

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

MockResultProcessor is a mock of ResultProcessor interface.

func NewMockResultProcessor

func NewMockResultProcessor(ctrl *gomock.Controller) *MockResultProcessor

NewMockResultProcessor creates a new mock instance.

func (*MockResultProcessor) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockResultProcessor) GetSummary

GetSummary mocks base method.

func (*MockResultProcessor) Process

func (m *MockResultProcessor) Process(result *models.Result) error

Process mocks base method.

type MockResultProcessorMockRecorder

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

MockResultProcessorMockRecorder is the mock recorder for MockResultProcessor.

func (*MockResultProcessorMockRecorder) GetSummary

func (mr *MockResultProcessorMockRecorder) GetSummary(ctx any) *gomock.Call

GetSummary indicates an expected call of GetSummary.

func (*MockResultProcessorMockRecorder) Process

func (mr *MockResultProcessorMockRecorder) Process(result any) *gomock.Call

Process indicates an expected call of Process.

type MockStore

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

MockStore is a mock of Store interface.

func NewMockStore

func NewMockStore(ctrl *gomock.Controller) *MockStore

NewMockStore creates a new mock instance.

func (*MockStore) EXPECT

func (m *MockStore) EXPECT() *MockStoreMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockStore) GetResults

func (m *MockStore) GetResults(arg0 context.Context, arg1 *models.ResultFilter) ([]models.Result, error)

GetResults mocks base method.

func (*MockStore) GetSweepSummary

func (m *MockStore) GetSweepSummary(arg0 context.Context) (*models.SweepSummary, error)

GetSweepSummary mocks base method.

func (*MockStore) PruneResults

func (m *MockStore) PruneResults(arg0 context.Context, arg1 time.Duration) error

PruneResults mocks base method.

func (*MockStore) SaveResult

func (m *MockStore) SaveResult(arg0 context.Context, arg1 *models.Result) error

SaveResult mocks base method.

type MockStoreMockRecorder

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

MockStoreMockRecorder is the mock recorder for MockStore.

func (*MockStoreMockRecorder) GetResults

func (mr *MockStoreMockRecorder) GetResults(arg0, arg1 any) *gomock.Call

GetResults indicates an expected call of GetResults.

func (*MockStoreMockRecorder) GetSweepSummary

func (mr *MockStoreMockRecorder) GetSweepSummary(arg0 any) *gomock.Call

GetSweepSummary indicates an expected call of GetSweepSummary.

func (*MockStoreMockRecorder) PruneResults

func (mr *MockStoreMockRecorder) PruneResults(arg0, arg1 any) *gomock.Call

PruneResults indicates an expected call of PruneResults.

func (*MockStoreMockRecorder) SaveResult

func (mr *MockStoreMockRecorder) SaveResult(arg0, arg1 any) *gomock.Call

SaveResult indicates an expected call of SaveResult.

type MockSweepService

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

MockSweepService is a mock of SweepService interface.

func NewMockSweepService

func NewMockSweepService(ctrl *gomock.Controller) *MockSweepService

NewMockSweepService creates a new mock instance.

func (*MockSweepService) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockSweepService) GetStatus

func (m *MockSweepService) GetStatus(arg0 context.Context) (*models.SweepSummary, error)

GetStatus mocks base method.

func (*MockSweepService) Start

func (m *MockSweepService) Start(arg0 context.Context) error

Start mocks base method.

func (*MockSweepService) Stop

func (m *MockSweepService) Stop() error

Stop mocks base method.

func (*MockSweepService) UpdateConfig

func (m *MockSweepService) UpdateConfig(arg0 *models.Config) error

UpdateConfig mocks base method.

type MockSweepServiceMockRecorder

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

MockSweepServiceMockRecorder is the mock recorder for MockSweepService.

func (*MockSweepServiceMockRecorder) GetStatus

func (mr *MockSweepServiceMockRecorder) GetStatus(arg0 any) *gomock.Call

GetStatus indicates an expected call of GetStatus.

func (*MockSweepServiceMockRecorder) Start

func (mr *MockSweepServiceMockRecorder) Start(arg0 any) *gomock.Call

Start indicates an expected call of Start.

func (*MockSweepServiceMockRecorder) Stop

Stop indicates an expected call of Stop.

func (*MockSweepServiceMockRecorder) UpdateConfig

func (mr *MockSweepServiceMockRecorder) UpdateConfig(arg0 any) *gomock.Call

UpdateConfig indicates an expected call of UpdateConfig.

type MockSweeper

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

MockSweeper is a mock of Sweeper interface.

func NewMockSweeper

func NewMockSweeper(ctrl *gomock.Controller) *MockSweeper

NewMockSweeper creates a new mock instance.

func (*MockSweeper) EXPECT

func (m *MockSweeper) EXPECT() *MockSweeperMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockSweeper) GetConfig

func (m *MockSweeper) GetConfig() models.Config

GetConfig mocks base method.

func (*MockSweeper) GetResults

func (m *MockSweeper) GetResults(arg0 context.Context, arg1 *models.ResultFilter) ([]models.Result, error)

GetResults mocks base method.

func (*MockSweeper) Start

func (m *MockSweeper) Start(arg0 context.Context) error

Start mocks base method.

func (*MockSweeper) Stop

func (m *MockSweeper) Stop() error

Stop mocks base method.

func (*MockSweeper) UpdateConfig

func (m *MockSweeper) UpdateConfig(arg0 *models.Config) error

UpdateConfig mocks base method.

type MockSweeperMockRecorder

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

MockSweeperMockRecorder is the mock recorder for MockSweeper.

func (*MockSweeperMockRecorder) GetConfig

func (mr *MockSweeperMockRecorder) GetConfig() *gomock.Call

GetConfig indicates an expected call of GetConfig.

func (*MockSweeperMockRecorder) GetResults

func (mr *MockSweeperMockRecorder) GetResults(arg0, arg1 any) *gomock.Call

GetResults indicates an expected call of GetResults.

func (*MockSweeperMockRecorder) Start

func (mr *MockSweeperMockRecorder) Start(arg0 any) *gomock.Call

Start indicates an expected call of Start.

func (*MockSweeperMockRecorder) Stop

func (mr *MockSweeperMockRecorder) Stop() *gomock.Call

Stop indicates an expected call of Stop.

func (*MockSweeperMockRecorder) UpdateConfig

func (mr *MockSweeperMockRecorder) UpdateConfig(arg0 any) *gomock.Call

UpdateConfig indicates an expected call of UpdateConfig.

type NetworkSweeper

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

NetworkSweeper implements both Sweeper and SweepService interfaces.

func NewNetworkSweeper

func NewNetworkSweeper(
	config *models.Config,
	store Store,
	processor ResultProcessor,
	configStore KVStore,
	objectStore ObjectStore,
	deviceRegistry DeviceRegistryService,
	configKey string,
	log logger.Logger,
	opts ...Option) (*NetworkSweeper, error)

NewNetworkSweeper creates a new scanner for network sweeping.

func (*NetworkSweeper) GetConfig

func (s *NetworkSweeper) GetConfig() models.Config

GetConfig returns current sweeper configuration.

func (*NetworkSweeper) GetResults

func (s *NetworkSweeper) GetResults(ctx context.Context, filter *models.ResultFilter) ([]models.Result, error)

GetResults retrieves sweep results based on filter.

func (*NetworkSweeper) GetStatus

func (s *NetworkSweeper) GetStatus(ctx context.Context) (*models.SweepSummary, error)

GetStatus returns current sweep status.

func (*NetworkSweeper) Start

func (s *NetworkSweeper) Start(ctx context.Context) error

Start begins periodic sweeping and KV watching.

func (*NetworkSweeper) Stop

func (s *NetworkSweeper) Stop() error

Stop gracefully stops sweeping and KV watching.

func (*NetworkSweeper) UpdateConfig

func (s *NetworkSweeper) UpdateConfig(config *models.Config) error

UpdateConfig updates sweeper configuration.

type ObjectStore added in v1.0.55

type ObjectStore interface {
	DownloadObject(ctx context.Context, key string) ([]byte, error)
}

type Option added in v1.0.55

type Option func(*NetworkSweeper)

Option configures a NetworkSweeper instance.

func WithKVWatchBackoff added in v1.0.55

func WithKVWatchBackoff(initial, max time.Duration, factor, jitter float64) Option

WithKVWatchBackoff overrides the KV watch backoff behaviour (primarily used in tests).

type ProcessorShard

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

ProcessorShard represents a single shard of the processor

type Reporter

type Reporter interface {
	// Report sends a summary somewhere (e.g., to a core service)
	Report(context.Context, *models.SweepSummary) error
}

Reporter defines how to report sweep results.

type ResultProcessor

type ResultProcessor interface {
	// Process takes a Result and updates internal state.
	Process(result *models.Result) error

	// GetSummary returns the current summary of all processed results.
	GetSummary(ctx context.Context) (*models.SweepSummary, error)
}

ResultProcessor defines how to process and aggregate sweep results.

type Store

type Store interface {
	// SaveResult persists a single scan result
	SaveResult(context.Context, *models.Result) error

	// GetResults retrieves results matching the filter
	GetResults(context.Context, *models.ResultFilter) ([]models.Result, error)

	// GetSweepSummary gets the latest sweep summary
	GetSweepSummary(context.Context) (*models.SweepSummary, error)

	// PruneResults removes results older than given duration
	PruneResults(context.Context, time.Duration) error
}

Store defines storage operations for sweep results.

func NewInMemoryStore

func NewInMemoryStore(processor ResultProcessor, log logger.Logger, opts ...InMemoryStoreOption) Store

NewInMemoryStore creates a new in-memory store for sweep results.

type SweepService

type SweepService interface {
	// Start begins periodic sweeping
	Start(context.Context) error
	// Stop gracefully stops sweeping
	Stop() error
	// GetStatus returns current sweep status
	GetStatus(context.Context) (*models.SweepSummary, error)
	// UpdateConfig updates service configuration
	UpdateConfig(*models.Config) error
}

SweepService combines scanning, storage, and reporting.

type Sweeper

type Sweeper interface {
	// Start begins periodic sweeping based on configuration
	Start(context.Context) error

	// Stop gracefully stops sweeping
	Stop() error

	// GetResults retrieves sweep results based on filter
	GetResults(context.Context, *models.ResultFilter) ([]models.Result, error)

	// GetConfig returns current sweeper configuration
	GetConfig() models.Config

	// UpdateConfig updates sweeper configuration
	UpdateConfig(*models.Config) error
}

Sweeper defines the main interface for network sweeping.

Jump to

Keyboard shortcuts

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