Skip to content

Commit

Permalink
Merge pull request #33 from devilcove/update/peerDetails
Browse files Browse the repository at this point in the history
reset peer to update when looping over network
  • Loading branch information
mattkasun authored Apr 28, 2024
2 parents 58accde + c5d9fa1 commit 0839fb6
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions internal/server/nathandlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ func processConnectionData(data *plexus.CheckinData) {
updatedPeers = append(updatedPeers, peer)
}
network.Peers = updatedPeers
slog.Debug("save connecetion data", "network", network.Name)
if err := boltdb.Save(network, network.Name, networkTable); err != nil {
slog.Error("save peers", "error", err)
}
Expand Down Expand Up @@ -369,7 +370,7 @@ func processDeviceUpdate(id string, request *plexus.Peer) {
}

func processNetworkPeerUpdate(id string, request *plexus.NetworkPeer) {
slog.Debug("received network peer update", "peer", id)
slog.Debug("received network peer update", "peer", request.HostName)
if id != request.WGPublicKey {
slog.Error("invalid update", "id", id, "request", request.WGPublicKey)
return
Expand All @@ -379,8 +380,8 @@ func processNetworkPeerUpdate(id string, request *plexus.NetworkPeer) {
slog.Error("get networks", "errror", err)
return
}
updatedPeers := []plexus.NetworkPeer{}
for _, network := range networks {
updatedPeers := []plexus.NetworkPeer{}
for _, peer := range network.Peers {
slog.Debug("checking peer", "peer", peer.HostName)
if peer.WGPublicKey == id {
Expand All @@ -389,14 +390,15 @@ func processNetworkPeerUpdate(id string, request *plexus.NetworkPeer) {
Action: plexus.UpdatePeer,
Peer: *request,
}
slog.Debug("publish peer update", "network", network.Name, "peer", request.HostName)
if err := eConn.Publish(plexus.Networks+network.Name, data); err != nil {
slog.Error("publish network update", "error", err)
}
}
slog.Debug("adding peer", "peer", peer.HostName)
updatedPeers = append(updatedPeers, peer)
}
network.Peers = updatedPeers
slog.Debug("updating network", "network", network.Name)
if err := boltdb.Save(network, network.Name, networkTable); err != nil {
slog.Error("save network", "error", err)
}
Expand Down

0 comments on commit 0839fb6

Please sign in to comment.