refactor: remove SPNGroup from 'control.instance' interface and update pause logic
This commit is contained in:
@@ -31,7 +31,6 @@ type Control struct {
|
|||||||
type instance interface {
|
type instance interface {
|
||||||
Config() *config.Config
|
Config() *config.Config
|
||||||
InterceptionGroup() *mgr.GroupModule
|
InterceptionGroup() *mgr.GroupModule
|
||||||
SPNGroup() *mgr.ExtendedGroup
|
|
||||||
IsShuttingDown() bool
|
IsShuttingDown() bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,15 +32,18 @@ func (c *Control) pause(duration time.Duration, onlySPN bool) (retErr error) {
|
|||||||
return errors.New("invalid pause duration")
|
return errors.New("invalid pause duration")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
spn_enabled := config.GetAsBool("spn/enable", false)
|
||||||
if onlySPN {
|
if onlySPN {
|
||||||
if c.pauseInfo.Interception {
|
if c.pauseInfo.Interception {
|
||||||
return errors.New("cannot pause SPN separately when core is paused")
|
return errors.New("cannot pause SPN separately when core is paused")
|
||||||
}
|
}
|
||||||
if !c.pauseInfo.SPN && !c.instance.SPNGroup().Ready() {
|
// If SPN is not running and not already paused, cannot pause it or change pause duration.
|
||||||
|
if !spn_enabled() && !c.pauseInfo.SPN {
|
||||||
return errors.New("cannot pause SPN when it is not running")
|
return errors.New("cannot pause SPN when it is not running")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Stop resume worker if running and start a new one later.
|
||||||
c.stopResumeWorker()
|
c.stopResumeWorker()
|
||||||
defer func() {
|
defer func() {
|
||||||
if retErr == nil {
|
if retErr == nil {
|
||||||
@@ -49,18 +52,16 @@ func (c *Control) pause(duration time.Duration, onlySPN bool) (retErr error) {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
// Pause SPN if not already paused.
|
||||||
if !c.pauseInfo.SPN {
|
if !c.pauseInfo.SPN {
|
||||||
if c.instance.SPNGroup().Ready() {
|
if spn_enabled() {
|
||||||
enabled := config.GetAsBool("spn/enable", false)
|
// TODO: the 'pause' state must not make permanent config changes.
|
||||||
if enabled() {
|
// Consider possibility to not store permanent config changes.
|
||||||
// TODO: the 'pause' state must not make permanent config changes.
|
// E.g. SPN enabled -> pause SPN -> restart PC/Portmaster -> SPN should be enabled again.
|
||||||
// Consider possibility to not store permanent config changes.
|
config.SetConfigOption("spn/enable", false)
|
||||||
// E.g. SPN enabled -> pause SPN -> restart PC/Portmaster -> SPN should be enabled again.
|
c.mgr.Info("SPN paused")
|
||||||
config.SetConfigOption("spn/enable", false)
|
|
||||||
c.mgr.Info("SPN paused")
|
|
||||||
}
|
|
||||||
c.pauseInfo.SPN = true
|
|
||||||
}
|
}
|
||||||
|
c.pauseInfo.SPN = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if onlySPN {
|
if onlySPN {
|
||||||
|
|||||||
@@ -317,7 +317,11 @@ func New(svcCfg *ServiceConfig) (*Instance, error) { //nolint:maintidx
|
|||||||
// Grouped interception modules that can be paused/resumed together.
|
// Grouped interception modules that can be paused/resumed together.
|
||||||
instance.serviceGroupInterception = mgr.NewGroupModule("Interception Group",
|
instance.serviceGroupInterception = mgr.NewGroupModule("Interception Group",
|
||||||
instance.interception,
|
instance.interception,
|
||||||
instance.dnsmonitor,
|
|
||||||
|
// TODO: The dnsmonitor is currently not part of this group, as it has inconsistent issue when stopping.
|
||||||
|
// Fix chars-issue of this module and re-add it here.
|
||||||
|
//instance.dnsmonitor,
|
||||||
|
|
||||||
instance.compat)
|
instance.compat)
|
||||||
|
|
||||||
// Add all modules to instance group.
|
// Add all modules to instance group.
|
||||||
@@ -348,11 +352,12 @@ func New(svcCfg *ServiceConfig) (*Instance, error) { //nolint:maintidx
|
|||||||
instance.filterLists,
|
instance.filterLists,
|
||||||
instance.customlist,
|
instance.customlist,
|
||||||
|
|
||||||
// Grouped interception modules:
|
// Grouped pausable interception modules:
|
||||||
// instance.interception,
|
// instance.interception,
|
||||||
// instance.dnsmonitor,
|
// instance.dnsmonitor,
|
||||||
// instance.compat
|
// instance.compat
|
||||||
instance.serviceGroupInterception,
|
instance.serviceGroupInterception,
|
||||||
|
instance.dnsmonitor, // TODO: Remove when re-added to serviceGroupInterception group.
|
||||||
|
|
||||||
instance.status,
|
instance.status,
|
||||||
instance.broadcasts,
|
instance.broadcasts,
|
||||||
|
|||||||
Reference in New Issue
Block a user