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.

64 lines
1.0 KiB

package zones
import (
"context"
"net/netip"
"strconv"
"time"
)
func (m *Machine) lookupNetIP() ([]netip.Addr, error) {
timeout := 2 * time.Second
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
return m.zone.zones.resolver.LookupNetIP(ctx, "ip", m.FullName())
}
func (m *Machine) updatePublicAddresses() error {
addrs, err := m.lookupNetIP()
if err != nil {
return err
}
m.PublicAddresses = addrs
return nil
}
func (m *Machine) init() error {
if err := m.setID(); err != nil {
return err
}
for i := 0; i < RingsCount; i++ {
if err := m.tryReadWireguardKeys(i); err != nil {
return err
}
}
return nil
}
func (m *Machine) setID() error {
zoneName := m.zone.Name
suffix := m.Name[len(zoneName)+1:]
id, err := strconv.ParseInt(suffix, 10, 8)
if err != nil {
return err
}
m.ID = int(id)
return nil
}
func (m *Machine) scan() error {
for i := 0; i < RingsCount; i++ {
if err := m.tryApplyWireguardConfig(i); err != nil {
return err
}
}
return m.updatePublicAddresses()
}