Skip to content

Commit

Permalink
scanner: rename interface
Browse files Browse the repository at this point in the history
  • Loading branch information
peterjan authored and ChrisSchinnerl committed Jul 31, 2024
1 parent 5abb25b commit f69ec3d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
14 changes: 7 additions & 7 deletions autopilot/scanner/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@ const (
)

type (
HostScanner interface {
RHPScan(ctx context.Context, hostKey types.PublicKey, hostIP string, timeout time.Duration) (api.RHPScanResponse, error)
}

HostStore interface {
HostsForScanning(ctx context.Context, opts api.HostsForScanningOptions) ([]api.HostAddress, error)
RemoveOfflineHosts(ctx context.Context, minRecentScanFailures uint64, maxDowntime time.Duration) (uint64, error)
}

Scanner interface {
Scan(ctx context.Context, w HostScanner, force bool)
Scan(ctx context.Context, w WorkerRHPScan, force bool)
Shutdown(ctx context.Context) error
Status() (bool, time.Time)
UpdateHostsConfig(cfg api.HostsConfig)
}

WorkerRHPScan interface {
RHPScan(ctx context.Context, hostKey types.PublicKey, hostIP string, timeout time.Duration) (api.RHPScanResponse, error)
}
)

type (
Expand Down Expand Up @@ -87,7 +87,7 @@ func New(hs HostStore, scanBatchSize, scanThreads uint64, scanMinInterval time.D
}, nil
}

func (s *scanner) Scan(ctx context.Context, w HostScanner, force bool) {
func (s *scanner) Scan(ctx context.Context, w WorkerRHPScan, force bool) {
if s.canSkipScan(force) {
s.logger.Debug("host scan skipped")
return
Expand Down Expand Up @@ -194,7 +194,7 @@ func (s *scanner) fetchHosts(ctx context.Context, cutoff time.Time) chan scanJob
return jobsChan
}

func (s *scanner) scanHosts(ctx context.Context, w HostScanner, hosts chan scanJob) (scanned uint64) {
func (s *scanner) scanHosts(ctx context.Context, w WorkerRHPScan, hosts chan scanJob) (scanned uint64) {
// define worker
worker := func() {
for h := range hosts {
Expand Down
6 changes: 3 additions & 3 deletions autopilot/scanner/scanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ func (hs *mockHostStore) state() ([]string, []string) {
return hs.scans, hs.removals
}

type mockHostScanner struct {
type mockWorker struct {
blockChan chan struct{}

mu sync.Mutex
scanCount int
}

func (w *mockHostScanner) RHPScan(ctx context.Context, hostKey types.PublicKey, hostIP string, _ time.Duration) (api.RHPScanResponse, error) {
func (w *mockWorker) RHPScan(ctx context.Context, hostKey types.PublicKey, hostIP string, _ time.Duration) (api.RHPScanResponse, error) {
if w.blockChan != nil {
<-w.blockChan
}
Expand Down Expand Up @@ -101,7 +101,7 @@ func TestScanner(t *testing.T) {
}

// initiate a host scan using a worker that blocks
w := &mockHostScanner{blockChan: make(chan struct{})}
w := &mockWorker{blockChan: make(chan struct{})}
s.Scan(context.Background(), w, false)

// assert it's scanning
Expand Down

0 comments on commit f69ec3d

Please sign in to comment.