Simplify IP pool and convert it to host pool

This commit is contained in:
2025-01-16 09:39:20 +02:00
parent 4a345a1763
commit 9ade26b6e8
3 changed files with 25 additions and 40 deletions

View File

@@ -1,28 +0,0 @@
package gemini
import (
"gemini-grc/logging"
)
var IPPool = IpAddressPool{IPs: make(map[string]int)}
func AddIPsToPool(ips []string) {
IPPool.Lock.Lock()
for _, ip := range ips {
logging.LogDebug("Adding %s to pool", ip)
IPPool.IPs[ip] = 1
}
IPPool.Lock.Unlock()
}
func RemoveIPsFromPool(IPs []string) {
IPPool.Lock.Lock()
for _, ip := range IPs {
_, ok := IPPool.IPs[ip]
if ok {
logging.LogDebug("Removing %s from pool", ip)
delete(IPPool.IPs, ip)
}
}
IPPool.Lock.Unlock()
}

View File

@@ -4,7 +4,6 @@ import (
"crypto/tls"
"errors"
"fmt"
"gemini-grc/common"
"io"
"net"
gourl "net/url"
@@ -14,6 +13,7 @@ import (
"strings"
"time"
"gemini-grc/common"
"gemini-grc/config"
"gemini-grc/logging"
"github.com/guregu/null/v5"
@@ -28,20 +28,11 @@ type PageData struct {
Data []byte
}
// Resolve the URL hostname and
// check if we already have an open
// connection to this host.
// If we can connect, return a list
// of the resolved IPs.
func getHostIPAddresses(hostname string) ([]string, error) {
addrs, err := net.LookupHost(hostname)
if err != nil {
return nil, fmt.Errorf("%w:%w", common.ErrNetworkDNS, err)
}
IPPool.Lock.RLock()
defer func() {
IPPool.Lock.RUnlock()
}()
return addrs, nil
}