+1
-1
@@ -88,7 +88,7 @@ func getRingZeroGatewayID(z *Zone) int {
|
||||
firstNodeID = nodeID
|
||||
}
|
||||
|
||||
if _, found := p.getRingInfo(0); found {
|
||||
if p.Gateway() {
|
||||
gatewayID = nodeID
|
||||
}
|
||||
|
||||
|
||||
@@ -47,6 +47,34 @@ func (m *Machine) ID() int {
|
||||
return m.id
|
||||
}
|
||||
|
||||
// Gateway tells if the Machine is a ring0 gateway
|
||||
func (m *Machine) Gateway() bool {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
|
||||
if ri, found := m.getRingInfo(0); found {
|
||||
return ri.Enabled
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func (m *Machine) SetGateway(enable bool) error {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
|
||||
ri, found := m.getRingInfo(0)
|
||||
switch {
|
||||
case !found && !enable:
|
||||
return nil
|
||||
case !found:
|
||||
return m.createRingInfo(0, true)
|
||||
default:
|
||||
ri.Enabled = enable
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// FullName returns the Name of the machine including domain name
|
||||
func (m *Machine) FullName() string {
|
||||
if domain := m.zone.zones.domain; domain != "" {
|
||||
|
||||
@@ -134,3 +134,18 @@ func (m *Machine) applyZoneNodeID(zoneID, nodeID int) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Machine) createRingInfo(ring int, enabled bool) error {
|
||||
keys, err := wireguard.NewKeyPair()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ri := &RingInfo{
|
||||
Ring: ring,
|
||||
Enabled: enabled,
|
||||
Keys: keys,
|
||||
}
|
||||
|
||||
return m.applyRingInfo(ring, ri)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user