Compare commits
2 Commits
30a7bceda3
..
v0.4.0
| Author | SHA1 | Date | |
|---|---|---|---|
| c81b782b26 | |||
| 0f62ee2e53 |
+1
-1
@@ -86,7 +86,7 @@ func getRingZeroGatewayID(z *Zone) int {
|
|||||||
firstNodeID = p.ID
|
firstNodeID = p.ID
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, found := p.getRingInfo(0); found {
|
if p.IsGateway() {
|
||||||
gatewayID = p.ID
|
gatewayID = p.ID
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,19 +6,16 @@ import (
|
|||||||
"net/netip"
|
"net/netip"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// A Machine is a machine on a Zone
|
// A Machine is a machine on a Zone
|
||||||
type Machine struct {
|
type Machine struct {
|
||||||
mu sync.Mutex
|
|
||||||
|
|
||||||
zone *Zone
|
zone *Zone
|
||||||
ID int
|
ID int
|
||||||
Name string `toml:"name"`
|
Name string `toml:"name"`
|
||||||
|
|
||||||
PublicAddresses []netip.Addr `toml:"public,omitempty"`
|
PublicAddresses []netip.Addr `toml:"public,omitempty"`
|
||||||
RingAddresses []*RingInfo `toml:"rings,omitempty"`
|
Rings []*RingInfo `toml:"rings,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Machine) String() string {
|
func (m *Machine) String() string {
|
||||||
@@ -61,6 +58,12 @@ func (m *Machine) getFilename(name string, args ...any) string {
|
|||||||
return filepath.Join(s...)
|
return filepath.Join(s...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsGateway tells if the Machine is a ring0 gateway
|
||||||
|
func (m *Machine) IsGateway() bool {
|
||||||
|
_, ok := m.getRingInfo(0)
|
||||||
|
return ok
|
||||||
|
}
|
||||||
|
|
||||||
func (m *Machine) getPeerByName(name string) (*Machine, bool) {
|
func (m *Machine) getPeerByName(name string) (*Machine, bool) {
|
||||||
return m.zone.zones.GetMachineByName(name)
|
return m.zone.zones.GetMachineByName(name)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -123,9 +123,9 @@ func (m *Machine) applyWireguardConfig(ring int, wg *wireguard.Config) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *Machine) getRingInfo(ring int) (*RingInfo, bool) {
|
func (m *Machine) getRingInfo(ring int) (*RingInfo, bool) {
|
||||||
for _, ri := range m.RingAddresses {
|
for _, ri := range m.Rings {
|
||||||
if ri.Ring == ring {
|
if ri.Ring == ring {
|
||||||
return ri, true
|
return ri, ri.Enabled
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,10 +133,10 @@ func (m *Machine) getRingInfo(ring int) (*RingInfo, bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *Machine) applyRingInfo(ring int, new *RingInfo) error {
|
func (m *Machine) applyRingInfo(ring int, new *RingInfo) error {
|
||||||
cur, found := m.getRingInfo(ring)
|
cur, _ := m.getRingInfo(ring)
|
||||||
if !found {
|
if cur == nil {
|
||||||
// first, append
|
// first, append
|
||||||
m.RingAddresses = append(m.RingAddresses, new)
|
m.Rings = append(m.Rings, new)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -102,9 +102,9 @@ func (m *Zones) scanSort() error {
|
|||||||
})
|
})
|
||||||
|
|
||||||
m.ForEachMachine(func(p *Machine) bool {
|
m.ForEachMachine(func(p *Machine) bool {
|
||||||
sort.SliceStable(p.RingAddresses, func(i, j int) bool {
|
sort.SliceStable(p.Rings, func(i, j int) bool {
|
||||||
ri1 := p.RingAddresses[i]
|
ri1 := p.Rings[i]
|
||||||
ri2 := p.RingAddresses[j]
|
ri2 := p.Rings[j]
|
||||||
|
|
||||||
return ri1.Ring < ri2.Ring
|
return ri1.Ring < ri2.Ring
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user