Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelangel-nubla committed Jan 1, 2025
1 parent 32fe808 commit febc6d0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
2 changes: 0 additions & 2 deletions addr_collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ func (c *AddrCollection) PrettyPrint(prefix string) string {
defer c.addressesMutex.RUnlock()

var result strings.Builder
c.addressesMutex.RLock()

// Get the keys from the map
keys := make([]netip.Addr, 0, len(c.addresses))
Expand All @@ -186,7 +185,6 @@ func (c *AddrCollection) PrettyPrint(prefix string) string {
ipAddressInfo := c.addresses[key.String()]
fmt.Fprintf(&result, prefix+"%s %s\n", ipAddressInfo.Addr.String(), time.Until(ipAddressInfo.GetExpiration()).Round(time.Second))
}
c.addressesMutex.RUnlock()

return result.String()
}
Expand Down
13 changes: 7 additions & 6 deletions state.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,16 @@ func (s *State) Enlist(hw net.HardwareAddr, netipAddr netip.Addr, ttl time.Durat

func (s *State) Filter(hws []net.HardwareAddr, prefixes []netip.Prefix) *AddrCollection {
results := NewAddrCollection()

s.macsMutex.Lock()
defer s.macsMutex.Unlock()

for _, prefix := range prefixes {
for _, hw := range hws {
s.macsMutex.RLock()
collection, exists := s.macs[hw.String()]
if exists {
results.Join(collection.FilterPrefix(prefix))
}
s.macsMutex.RUnlock()
}
}

Expand All @@ -60,9 +62,10 @@ func (s *State) Filter(hws []net.HardwareAddr, prefixes []netip.Prefix) *AddrCol
func (s *State) PrettyPrint(prefix string) string {
var result strings.Builder

fmt.Fprintf(&result, "%sDiscovery:\n", prefix)
s.macsMutex.Lock()
defer s.macsMutex.Unlock()

s.macsMutex.RLock()
fmt.Fprintf(&result, "%sDiscovery:\n", prefix)

// Get the keys from the map
keys := make([]string, 0, len(s.macs))
Expand All @@ -79,8 +82,6 @@ func (s *State) PrettyPrint(prefix string) string {
fmt.Fprint(&result, s.macs[key].PrettyPrint(prefix+" "))
}

s.macsMutex.RUnlock()

return result.String()
}

Expand Down

0 comments on commit febc6d0

Please sign in to comment.