You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
606 B

  1. package p2p
  2. import (
  3. "strings"
  4. )
  5. // TODO Test
  6. func AddToIPRangeCounts(counts map[string]int, ip string) map[string]int {
  7. changes := make(map[string]int)
  8. ipParts := strings.Split(ip, ":")
  9. for i := 1; i < len(ipParts); i++ {
  10. prefix := strings.Join(ipParts[:i], ":")
  11. counts[prefix] += 1
  12. changes[prefix] = counts[prefix]
  13. }
  14. return changes
  15. }
  16. // TODO Test
  17. func CheckIPRangeCounts(counts map[string]int, limits []int) bool {
  18. for prefix, count := range counts {
  19. ipParts := strings.Split(prefix, ":")
  20. numParts := len(ipParts)
  21. if limits[numParts] < count {
  22. return false
  23. }
  24. }
  25. return true
  26. }