mirror of
https://github.com/gravitl/netmaker.git
synced 2025-02-26 17:15:23 +08:00
fix missing slash in msg topic; update handling of keyUpdates
This commit is contained in:
parent
30a6b0f4c9
commit
799f32c664
2 changed files with 10 additions and 12 deletions
2
mq/mq.go
2
mq/mq.go
|
@ -98,7 +98,7 @@ func PublishPeerUpdate(client mqtt.Client, newNode *models.Node) error {
|
|||
logger.Log(2, "error marshaling peer update "+err.Error())
|
||||
return err
|
||||
}
|
||||
if token := client.Publish("/update/peers"+node.ID, 0, false, data); token.Wait() && token.Error() != nil {
|
||||
if token := client.Publish("/update/peers/"+node.ID, 0, false, data); token.Wait() && token.Error() != nil {
|
||||
logger.Log(2, "error publishing peer update to peer "+node.ID+" "+token.Error().Error())
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -113,7 +113,9 @@ var NodeUpdate mqtt.MessageHandler = func(client mqtt.Client, msg mqtt.Message)
|
|||
return
|
||||
}
|
||||
case models.NODE_UPDATE_KEY:
|
||||
UpdateKeys(&cfg, client)
|
||||
if err := UpdateKeys(&cfg, client); err != nil {
|
||||
ncutils.PrintLog("err updating wireguard keys: "+err.Error(), 1)
|
||||
}
|
||||
case models.NODE_NOOP:
|
||||
default:
|
||||
}
|
||||
|
@ -170,28 +172,24 @@ var UpdatePeers mqtt.MessageHandler = func(client mqtt.Client, msg mqtt.Message)
|
|||
}
|
||||
|
||||
// UpdateKeys -- updates private key and returns new publickey
|
||||
func UpdateKeys(cfg *config.ClientConfig, client mqtt.Client) (*config.ClientConfig, error) {
|
||||
func UpdateKeys(cfg *config.ClientConfig, client mqtt.Client) error {
|
||||
ncutils.Log("received message to update keys")
|
||||
//potentiall blocking i/o so do this in a go routine
|
||||
key, err := wgtypes.GeneratePrivateKey()
|
||||
if err != nil {
|
||||
ncutils.Log("error generating privatekey " + err.Error())
|
||||
return cfg, err
|
||||
return err
|
||||
}
|
||||
if err := wireguard.UpdatePrivateKey(cfg.Node.Interface, key.String()); err != nil {
|
||||
ncutils.Log("error updating wireguard key " + err.Error())
|
||||
return cfg, err
|
||||
}
|
||||
publicKey := key.PublicKey()
|
||||
if token := client.Publish("update/publickey/"+cfg.Node.ID, 0, false, publicKey.String()); token.Wait() && token.Error() != nil {
|
||||
ncutils.Log("error publishing publickey update " + token.Error().Error())
|
||||
client.Disconnect(250)
|
||||
return cfg, err
|
||||
return err
|
||||
}
|
||||
cfg.Node.PublicKey = key.PublicKey().String()
|
||||
PublishNodeUpdate(cfg)
|
||||
if err := config.ModConfig(&cfg.Node); err != nil {
|
||||
ncutils.Log("error updating local config " + err.Error())
|
||||
}
|
||||
return cfg, nil
|
||||
return nil
|
||||
}
|
||||
|
||||
// Checkin -- go routine that checks for public or local ip changes, publishes changes
|
||||
|
|
Loading…
Reference in a new issue