Skip to content

Commit

Permalink
updateServer should use current device status
Browse files Browse the repository at this point in the history
  • Loading branch information
UnAfraid committed Oct 22, 2023
1 parent 7fafbba commit 3dba1f6
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions pkg/manage/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,18 +449,23 @@ func (s *service) configureDevice(ctx context.Context, srv *server.Server, peers
}

func (s *service) updateServer(ctx context.Context, srv *server.Server, device *backend.Device, userId string) (*server.Server, error) {
status, err := s.wireguardService.Status(ctx, srv.Name)
if err != nil {
return nil, err
}

updateOptions := server.UpdateOptions{
Running: true,
Running: status,
PublicKey: device.Wireguard.PublicKey,
PrivateKey: device.Wireguard.PrivateKey,
ListenPort: adapt.ToPointerNilZero(device.Wireguard.ListenPort),
FirewallMark: adapt.ToPointerNilZero(device.Wireguard.FirewallMark),
MTU: device.Interface.Mtu,
}
updateFieldMask := server.UpdateFieldMask{
Running: true,
PublicKey: strings.EqualFold(srv.PublicKey, device.Wireguard.PublicKey),
PrivateKey: strings.EqualFold(srv.PrivateKey, device.Wireguard.PrivateKey),
Running: srv.Running != status,
PublicKey: !strings.EqualFold(srv.PublicKey, device.Wireguard.PublicKey),
PrivateKey: !strings.EqualFold(srv.PrivateKey, device.Wireguard.PrivateKey),
ListenPort: adapt.Dereference(srv.ListenPort) != device.Wireguard.ListenPort,
FirewallMark: adapt.Dereference(srv.FirewallMark) != device.Wireguard.FirewallMark,
MTU: srv.MTU != device.Interface.Mtu,
Expand Down

0 comments on commit 3dba1f6

Please sign in to comment.