Various API changes and simplifications to fix mobile builds

This commit is contained in:
Neil Alexander 2019-07-27 15:00:09 +01:00
parent 9b99f0b5e4
commit de1005e4fa
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944
13 changed files with 63 additions and 122 deletions

View file

@ -16,21 +16,27 @@ type NodeState struct {
Mutex sync.RWMutex
}
// Get returns both the current and previous node configs
func (s *NodeState) Get() (NodeConfig, NodeConfig) {
// Current returns the current node config
func (s *NodeState) GetCurrent() NodeConfig {
s.Mutex.RLock()
defer s.Mutex.RUnlock()
return s.Current, s.Previous
return s.Current
}
// Previous returns the previous node config
func (s *NodeState) GetPrevious() NodeConfig {
s.Mutex.RLock()
defer s.Mutex.RUnlock()
return s.Previous
}
// Replace the node configuration with new configuration. This method returns
// both the new and the previous node configs
func (s *NodeState) Replace(n NodeConfig) (NodeConfig, NodeConfig) {
func (s *NodeState) Replace(n NodeConfig) {
s.Mutex.Lock()
defer s.Mutex.Unlock()
s.Previous = s.Current
s.Current = n
return s.Current, s.Previous
}
// NodeConfig defines all configuration values needed to run a signle yggdrasil node
@ -115,3 +121,19 @@ func GenerateConfig() *NodeConfig {
return &cfg
}
// NewEncryptionKeys generates a new encryption keypair. The encryption keys are
// used to encrypt traffic and to derive the IPv6 address/subnet of the node.
func (cfg *NodeConfig) NewEncryptionKeys() {
bpub, bpriv := crypto.NewBoxKeys()
cfg.EncryptionPublicKey = hex.EncodeToString(bpub[:])
cfg.EncryptionPrivateKey = hex.EncodeToString(bpriv[:])
}
// NewSigningKeys generates a new signing keypair. The signing keys are used to
// derive the structure of the spanning tree.
func (cfg *NodeConfig) NewSigningKeys() {
spub, spriv := crypto.NewSigKeys()
cfg.SigningPublicKey = hex.EncodeToString(spub[:])
cfg.SigningPrivateKey = hex.EncodeToString(spriv[:])
}