Compare commits
2 Commits
v0.8.1
...
7b8f46fd7f
| Author | SHA1 | Date | |
|---|---|---|---|
| 7b8f46fd7f | |||
| 34f0b910c8 |
@@ -89,8 +89,25 @@ func decodeKey(data string, size int) ([]byte, error) {
|
||||
}
|
||||
}
|
||||
|
||||
func NewPrivateKey() (PrivateKey, error)
|
||||
|
||||
func (PrivateKey) Public() PublicKey
|
||||
|
||||
// KeyPair holds a Key pair
|
||||
type KeyPair struct {
|
||||
PrivateKey PrivateKey
|
||||
PublicKey PublicKey
|
||||
}
|
||||
|
||||
func NewKeyPair() (*KeyPair, error) {
|
||||
key, err := NewPrivateKey()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
out := &KeyPair{
|
||||
PrivateKey: key,
|
||||
PublicKey: key.Public(),
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
+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