-
-
Notifications
You must be signed in to change notification settings - Fork 386
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(portforward): trigger after VPN restart
- Loading branch information
Showing
10 changed files
with
112 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package portforward | ||
|
||
import ( | ||
"github.com/qdm12/gluetun/internal/portforward/service" | ||
"github.com/qdm12/gosettings" | ||
) | ||
|
||
type Settings struct { | ||
// VPNIsUp can be optionally set to signal the loop | ||
// the VPN is up (true) or down (false). If left to nil, | ||
// it is assumed the VPN is in the same previous state. | ||
VPNIsUp *bool | ||
Service service.Settings | ||
} | ||
|
||
// updateWith deep copies the receiving settings, overrides the copy with | ||
// fields set in the partialUpdate argument, validates the new settings | ||
// and returns them if they are valid, or returns an error otherwise. | ||
// In all cases, the receiving settings are unmodified. | ||
func (s Settings) updateWith(partialUpdate Settings) (updated Settings, err error) { | ||
updated = s.copy() | ||
updated.overrideWith(partialUpdate) | ||
err = updated.validate() | ||
if err != nil { | ||
return updated, err | ||
} | ||
return updated, nil | ||
} | ||
|
||
func (s Settings) copy() (copied Settings) { | ||
copied.VPNIsUp = gosettings.CopyPointer(s.VPNIsUp) | ||
copied.Service = s.Service.Copy() | ||
return copied | ||
} | ||
|
||
func (s *Settings) overrideWith(update Settings) { | ||
s.VPNIsUp = gosettings.OverrideWithPointer(s.VPNIsUp, update.VPNIsUp) | ||
s.Service.OverrideWith(update.Service) | ||
} | ||
|
||
func (s Settings) validate() (err error) { | ||
return s.Service.Validate() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters