|
|
|
@ -122,17 +122,15 @@ func (m *Machine) applyWireguardConfig(ring int, wg *wireguard.Config) error {
|
|
|
|
|
addr := wg.GetAddress() |
|
|
|
|
zoneID, nodeID, ok := Rings[ring].Decode(addr) |
|
|
|
|
if !ok { |
|
|
|
|
return fmt.Errorf("%s: invalid wg%v address: %s", m.Name, ring, addr) |
|
|
|
|
return fmt.Errorf("%s: invalid address", addr) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if err := m.applyZoneNodeID(zoneID, nodeID); err != nil { |
|
|
|
|
err = core.Wrapf(err, "%s: wg%v:%s", m.Name, ring, addr) |
|
|
|
|
return err |
|
|
|
|
return core.Wrapf(err, "%s: invalid address", addr) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if err := m.applyWireguardInterfaceConfig(ring, wg.Interface); err != nil { |
|
|
|
|
err = core.Wrapf(err, "%s: wg%v:%s", m.Name, ring, addr) |
|
|
|
|
return err |
|
|
|
|
return core.Wrap(err, "interface") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for _, peer := range wg.Peer { |
|
|
|
@ -140,9 +138,14 @@ func (m *Machine) applyWireguardConfig(ring int, wg *wireguard.Config) error {
|
|
|
|
|
switch { |
|
|
|
|
case errors.Is(err, ErrUnknownNode): |
|
|
|
|
// ignore unknown peers
|
|
|
|
|
m.warn(nil). |
|
|
|
|
WithField("subsystem", "wireguard"). |
|
|
|
|
WithField("node", m.Name). |
|
|
|
|
WithField("peer", peer.Endpoint.Host). |
|
|
|
|
WithField("ring", ring). |
|
|
|
|
Print("ignoring unknown endpoint") |
|
|
|
|
case err != nil: |
|
|
|
|
err = core.Wrapf(err, "%s: wg%v:%s", m.Name, ring, addr) |
|
|
|
|
return err |
|
|
|
|
return core.Wrap(err, "peer") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -163,6 +166,10 @@ func (m *Machine) applyRingInfo(ring int, new *RingInfo) error {
|
|
|
|
|
cur, _ := m.getRingInfo(ring) |
|
|
|
|
if cur == nil { |
|
|
|
|
// first, append
|
|
|
|
|
m.debug(). |
|
|
|
|
WithField("node", m.Name). |
|
|
|
|
WithField("ring", ring). |
|
|
|
|
Print("found") |
|
|
|
|
m.Rings = append(m.Rings, new) |
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|