Skip to content

Commit

Permalink
sweeper working, still not correctly updating last sweep
Browse files Browse the repository at this point in the history
  • Loading branch information
mfreeman451 committed Jan 21, 2025
1 parent e6daa33 commit 777a799
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 269 deletions.
10 changes: 4 additions & 6 deletions pkg/agent/sweep_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,17 +163,17 @@ func (s *SweepService) performSweep(ctx context.Context) error {

// NewSweepService now creates a persistent service with a single processor instance.
func NewSweepService(config *models.Config) (*SweepService, error) {
// Create persistent processor instance
processor := sweeper.NewInMemoryProcessor()

// Create scanner with config settings
scanner := scan.NewCombinedScanner(
config.Timeout,
config.Concurrency,
config.ICMPCount,
)

// Create store that shares the same processor
// Create processor instance (which now handles both processing and storage)
processor := sweeper.NewBaseProcessor()

// Create an in-memory store that references the same processor if needed:
store := sweeper.NewInMemoryStore(processor)

service := &SweepService{
Expand All @@ -184,8 +184,6 @@ func NewSweepService(config *models.Config) (*SweepService, error) {
closed: make(chan struct{}),
}

log.Printf("Created new sweep service with persistent processor instance")

return service, nil
}

Expand Down
157 changes: 0 additions & 157 deletions pkg/sweeper/memory_processor.go

This file was deleted.

12 changes: 8 additions & 4 deletions pkg/sweeper/memory_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (s *InMemoryStore) processHostResult(r *models.Result, hostMap map[string]*
s.updateHostTimestamps(host, r)
}

func (s *InMemoryStore) getOrCreateHost(r *models.Result, hostMap map[string]*models.HostResult) *models.HostResult {
func (*InMemoryStore) getOrCreateHost(r *models.Result, hostMap map[string]*models.HostResult) *models.HostResult {
host, exists := hostMap[r.Target.Host]
if !exists {
host = &models.HostResult{
Expand All @@ -97,6 +97,7 @@ func (s *InMemoryStore) getOrCreateHost(r *models.Result, hostMap map[string]*mo
}
hostMap[r.Target.Host] = host
}

return host
}

Expand All @@ -115,29 +116,32 @@ func (s *InMemoryStore) processPortResult(host *models.HostResult, r *models.Res
}
}

func (s *InMemoryStore) findPortResult(host *models.HostResult, port int) *models.PortResult {
func (*InMemoryStore) findPortResult(host *models.HostResult, port int) *models.PortResult {
for _, pr := range host.PortResults {
if pr.Port == port {
return pr
}
}

return nil
}

func (s *InMemoryStore) updateHostTimestamps(host *models.HostResult, r *models.Result) {
func (*InMemoryStore) updateHostTimestamps(host *models.HostResult, r *models.Result) {
if r.FirstSeen.Before(host.FirstSeen) {
host.FirstSeen = r.FirstSeen
}

if r.LastSeen.After(host.LastSeen) {
host.LastSeen = r.LastSeen
}
}

func (s *InMemoryStore) convertToSlice(hostMap map[string]*models.HostResult) []models.HostResult {
func (*InMemoryStore) convertToSlice(hostMap map[string]*models.HostResult) []models.HostResult {
hosts := make([]models.HostResult, 0, len(hostMap))
for _, host := range hostMap {
hosts = append(hosts, *host)
}

return hosts
}

Expand Down
Loading

0 comments on commit 777a799

Please sign in to comment.