mirror of
https://github.com/gravitl/netmaker.git
synced 2025-10-05 16:57:51 +08:00
fix UpdateWgPeers
This commit is contained in:
@@ -61,8 +61,16 @@ func MessageQueue(ctx context.Context, network string) {
|
|||||||
if token := client.Subscribe("#", 0, nil); token.Wait() && token.Error() != nil {
|
if token := client.Subscribe("#", 0, nil); token.Wait() && token.Error() != nil {
|
||||||
log.Fatal(token.Error())
|
log.Fatal(token.Error())
|
||||||
}
|
}
|
||||||
client.AddRoute("update/"+cfg.Node.ID, NodeUpdate)
|
if token := client.Subscribe("update/"+cfg.Node.ID, 0, NodeUpdate); token.Wait() && token.Error() != nil {
|
||||||
client.AddRoute("update/peers/"+cfg.Node.ID, UpdatePeers)
|
log.Fatal(token.Error())
|
||||||
|
}
|
||||||
|
if token := client.Subscribe("/update/peers/"+cfg.Node.ID, 0, UpdatePeers); token.Wait() && token.Error() != nil {
|
||||||
|
log.Fatal(token.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
//addroute doesn't seem to work consistently
|
||||||
|
//client.AddRoute("update/"+cfg.Node.ID, NodeUpdate)
|
||||||
|
//client.AddRoute("update/peers/"+cfg.Node.ID, UpdatePeers)
|
||||||
//handle key updates in node update
|
//handle key updates in node update
|
||||||
//client.AddRoute("update/keys/"+cfg.Node.ID, UpdateKeys)
|
//client.AddRoute("update/keys/"+cfg.Node.ID, UpdateKeys)
|
||||||
defer client.Disconnect(250)
|
defer client.Disconnect(250)
|
||||||
@@ -73,8 +81,9 @@ func MessageQueue(ctx context.Context, network string) {
|
|||||||
|
|
||||||
// All -- mqtt message hander for all ('#') topics
|
// All -- mqtt message hander for all ('#') topics
|
||||||
var All mqtt.MessageHandler = func(client mqtt.Client, msg mqtt.Message) {
|
var All mqtt.MessageHandler = func(client mqtt.Client, msg mqtt.Message) {
|
||||||
|
ncutils.Log("default message handler -- received message but not handling")
|
||||||
ncutils.Log("Topic: " + string(msg.Topic()))
|
ncutils.Log("Topic: " + string(msg.Topic()))
|
||||||
ncutils.Log("Message: " + string(msg.Payload()))
|
//ncutils.Log("Message: " + string(msg.Payload()))
|
||||||
}
|
}
|
||||||
|
|
||||||
// NodeUpdate -- mqtt message handler for /update/<NodeID> topic
|
// NodeUpdate -- mqtt message handler for /update/<NodeID> topic
|
||||||
@@ -137,7 +146,6 @@ var NodeUpdate mqtt.MessageHandler = func(client mqtt.Client, msg mqtt.Message)
|
|||||||
|
|
||||||
// UpdatePeers -- mqtt message handler for /update/peers/<NodeID> topic
|
// UpdatePeers -- mqtt message handler for /update/peers/<NodeID> topic
|
||||||
var UpdatePeers mqtt.MessageHandler = func(client mqtt.Client, msg mqtt.Message) {
|
var UpdatePeers mqtt.MessageHandler = func(client mqtt.Client, msg mqtt.Message) {
|
||||||
ncutils.Log("received message to update peers " + string(msg.Payload()))
|
|
||||||
go func() {
|
go func() {
|
||||||
var peerUpdate models.PeerUpdate
|
var peerUpdate models.PeerUpdate
|
||||||
err := json.Unmarshal(msg.Payload(), &peerUpdate)
|
err := json.Unmarshal(msg.Payload(), &peerUpdate)
|
||||||
@@ -145,6 +153,14 @@ var UpdatePeers mqtt.MessageHandler = func(client mqtt.Client, msg mqtt.Message)
|
|||||||
ncutils.Log("error unmarshalling peer data")
|
ncutils.Log("error unmarshalling peer data")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
ncutils.Log("update peer handler")
|
||||||
|
ncutils.Log("recieved " + string(len(peerUpdate.Peers)) + "peers to update")
|
||||||
|
ncutils.Log(string(msg.Payload()))
|
||||||
|
ncutils.Log(peerUpdate.Network)
|
||||||
|
for _, peer := range peerUpdate.Peers {
|
||||||
|
key := peer.PublicKey.String()
|
||||||
|
ncutils.Log(key)
|
||||||
|
}
|
||||||
var cfg config.ClientConfig
|
var cfg config.ClientConfig
|
||||||
cfg.Network = peerUpdate.Network
|
cfg.Network = peerUpdate.Network
|
||||||
cfg.ReadConfig()
|
cfg.ReadConfig()
|
||||||
@@ -153,8 +169,9 @@ var UpdatePeers mqtt.MessageHandler = func(client mqtt.Client, msg mqtt.Message)
|
|||||||
ncutils.Log("error updating wireguard peers" + err.Error())
|
ncutils.Log("error updating wireguard peers" + err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// path hardcoded for now... should be updated
|
file := ncutils.GetNetclientPathSpecific() + cfg.Node.Interface + ".conf"
|
||||||
err = wireguard.ApplyWGQuickConf("/etc/netclient/config/" + cfg.Node.Interface + ".conf")
|
ncutils.Log("applyWGQuickConf to " + file)
|
||||||
|
err = wireguard.ApplyWGQuickConf(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ncutils.Log("error restarting wg after peer update " + err.Error())
|
ncutils.Log("error restarting wg after peer update " + err.Error())
|
||||||
return
|
return
|
||||||
|
Reference in New Issue
Block a user