Skip to content

Commit

Permalink
add mutex for set peers
Browse files Browse the repository at this point in the history
  • Loading branch information
yabinma committed Sep 23, 2024
1 parent 66e8b97 commit 2e0d709
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion functions/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ func startGoRoutines(wg *sync.WaitGroup) context.CancelFunc {
}
}
slog.Info("configuring netmaker wireguard interface")
pullresp, _, _, pullErr := Pull(true)
pullresp, _, _, pullErr := Pull(false)
if pullErr != nil {
slog.Error("fail to pull config from server", "error", pullErr.Error())
}
Expand Down
5 changes: 4 additions & 1 deletion wireguard/wireguard.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ func ShouldReplace(incomingPeers []wgtypes.PeerConfig) bool {

// SetPeers - sets peers on netmaker WireGuard interface
func SetPeers(replace bool) error {

wgMutex.Lock()
defer wgMutex.Unlock()
peers := config.Netclient().HostPeers
for i := range peers {
peer := peers[i]
Expand Down Expand Up @@ -70,6 +71,8 @@ func SetPeers(replace bool) error {
// temporarily making public func to pass staticchecks
// this function will be required in future when update node on server is refactored
func UpdatePeer(p *wgtypes.PeerConfig) error {
wgMutex.Lock()
defer wgMutex.Unlock()
config := wgtypes.Config{
Peers: []wgtypes.PeerConfig{*p},
ReplacePeers: false,
Expand Down

0 comments on commit 2e0d709

Please sign in to comment.