added ack and done signals

This commit is contained in:
0xdcarns
2022-02-17 09:08:20 -05:00
parent bd8b66c169
commit 506a897f26
4 changed files with 46 additions and 17 deletions

View File

@@ -199,11 +199,11 @@ func NodeUpdate(client mqtt.Client, msg mqtt.Message) {
return
}
if ifaceDelta { // if a change caused an ifacedelta we need to notify the server to update the peers
pubErr := publishClientPeers(&cfg)
if pubErr != nil {
ncutils.Log("could not notify server to update peers after interface change")
ackErr := publishSignal(&cfg, ncutils.ACK)
if ackErr != nil {
ncutils.Log("could not notify server that it received an interface update")
} else {
ncutils.Log("signalled peer update to server")
ncutils.Log("signalled acknowledgement of change to server")
}
ncutils.Log("applying WG conf to " + file)
err = wireguard.ApplyConf(&cfg.Node, cfg.Node.Interface, file)
@@ -221,6 +221,12 @@ func NodeUpdate(client mqtt.Client, msg mqtt.Message) {
}
}
}
doneErr := publishSignal(&cfg, ncutils.DONE)
if doneErr != nil {
ncutils.Log("could not notify server to update peers after interface change")
} else {
ncutils.Log("signalled finshed interface update to server")
}
}
//deal with DNS
if newNode.DNSOn != "yes" && shouldDNSChange && cfg.Node.Interface != "" {
@@ -480,9 +486,8 @@ func setupMQTT(cfg *config.ClientConfig, publish bool) mqtt.Client {
}
// publishes a message to server to update peers on this peer's behalf
func publishClientPeers(cfg *config.ClientConfig) error {
payload := []byte(ncutils.MakeRandomString(16)) // just random string for now to keep the bytes different
if err := publish(cfg, fmt.Sprintf("signal/%s", cfg.Node.ID), payload, 1); err != nil {
func publishSignal(cfg *config.ClientConfig, signal byte) error {
if err := publish(cfg, fmt.Sprintf("signal/%s", cfg.Node.ID), []byte{signal}, 1); err != nil {
return err
}
return nil