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