Skip to content

Commit

Permalink
Move all filter/interception config to interception module
Browse files Browse the repository at this point in the history
  • Loading branch information
dhaavi committed Sep 27, 2022
1 parent 084a1a2 commit 59392e4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 27 deletions.
11 changes: 11 additions & 0 deletions firewall/config.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package firewall

import (
"github.com/safing/portbase/api"
"github.com/safing/portbase/config"
"github.com/safing/portbase/notifications"
"github.com/safing/portmaster/core"
"github.com/safing/spn/captain"
)

Expand Down Expand Up @@ -107,13 +109,22 @@ func registerConfig() error {
return nil
}

// Config variables for interception and filter module.
// Everything is registered by the interception module, as the filter module
// can be disabled.
var (
devMode config.BoolOption
apiListenAddress config.StringOption

filterEnabled config.BoolOption
tunnelEnabled config.BoolOption
useCommunityNodes config.BoolOption
)

func getConfig() {
devMode = config.Concurrent.GetAsBool(core.CfgDevModeKey, false)
apiListenAddress = config.GetAsString(api.CfgDefaultListenAddressKey, "")

filterEnabled = config.Concurrent.GetAsBool(CfgOptionEnableFilterKey, true)
tunnelEnabled = config.Concurrent.GetAsBool(captain.CfgOptionEnableSPNKey, false)
useCommunityNodes = config.Concurrent.GetAsBool(captain.CfgOptionUseCommunityNodesKey, true)
Expand Down
17 changes: 1 addition & 16 deletions firewall/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
var filterModule *modules.Module

func init() {
filterModule = modules.Register("filter", filterPrep, filterStart, nil, "core", "intel")
filterModule = modules.Register("filter", nil, nil, nil, "core", "interception", "intel")
subsystems.Register(
"filter",
"Privacy Filter",
Expand All @@ -31,18 +31,3 @@ func init() {
},
)
}

func filterPrep() (err error) {
err = registerConfig()
if err != nil {
return err
}

return nil
}

func filterStart() error {
getConfig()

return nil
}
16 changes: 5 additions & 11 deletions firewall/interception.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,9 @@ import (
"github.com/tevino/abool"
"golang.org/x/sync/singleflight"

"github.com/safing/portbase/api"
"github.com/safing/portbase/config"
"github.com/safing/portbase/log"
"github.com/safing/portbase/modules"
"github.com/safing/portmaster/compat"
"github.com/safing/portmaster/core"
_ "github.com/safing/portmaster/core/base"
"github.com/safing/portmaster/firewall/inspection"
"github.com/safing/portmaster/firewall/interception"
Expand Down Expand Up @@ -46,12 +43,6 @@ var (
ownPID = os.Getpid()
)

// Config variables for interception module.
var (
devMode config.BoolOption
apiListenAddress config.StringOption
)

func init() {
// TODO: Move interception module to own package (dir).
interceptionModule = modules.Register("interception", interceptionPrep, interceptionStart, interceptionStop, "base", "updates", "network", "notifications")
Expand All @@ -60,12 +51,15 @@ func init() {
}

func interceptionPrep() error {
if err := registerConfig(); err != nil {
return err
}

return prepAPIAuth()
}

func interceptionStart() error {
devMode = config.Concurrent.GetAsBool(core.CfgDevModeKey, false)
apiListenAddress = config.GetAsString(api.CfgDefaultListenAddressKey, "")
getConfig()

if err := registerMetrics(); err != nil {
return err
Expand Down

0 comments on commit 59392e4

Please sign in to comment.