package server import ( "fmt" "net/netip" "time" log "git.wntrmute.dev/kyle/goutils/log" "git.wntrmute.dev/kyle/kdhcp/iptools" "git.wntrmute.dev/kyle/kdhcp/leases" ) // pools.go adds pool functionality to the server. func (srv *Server) loadPoolsFromConfig() error { for host, ip := range srv.Config.Statics { addr, ok := netip.AddrFromSlice(ip.To4()) if !ok { return fmt.Errorf("server: while instantiating pools, could not load IP %s", ip) } log.Debugf("server: added static host entry %s -> %s", host, addr) srv.Static[host] = &leases.Info{ HostName: host, Addr: addr, } } for name, ipRange := range srv.Config.Pools { pool, err := iptools.NewPool(name, ipRange) if err != nil { return fmt.Errorf("server: couldn't load pool %s: %w", name, err) } log.Debugf("server: added pool %s: %s -> %s", name, ipRange.Start, ipRange.End) srv.Pools[name] = pool } return nil } func (srv *Server) updatePoolLoop() { for { time.Sleep(time.Minute) for _, p := range srv.Pools { if p.Update(srv.clock.Now()) { log.Debugln("pools updated") } } } }