Clean up code and fix linter errors
This commit is contained in:
@@ -16,8 +16,11 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
// UnidentifiedProfileID is the profile ID used for unidentified processes.
|
||||
UnidentifiedProfileID = "_unidentified"
|
||||
SystemProfileID = "_system"
|
||||
|
||||
// SystemProfileID is the profile ID used for the system/kernel.
|
||||
SystemProfileID = "_system"
|
||||
)
|
||||
|
||||
var getProfileSingleInflight singleflight.Group
|
||||
@@ -25,7 +28,7 @@ var getProfileSingleInflight singleflight.Group
|
||||
// GetProfile fetches a profile. This function ensure that the profile loaded
|
||||
// is shared among all callers. You must always supply both the scopedID and
|
||||
// linkedPath parameters whenever available.
|
||||
func GetProfile(source profileSource, id, linkedPath string) (
|
||||
func GetProfile(source profileSource, id, linkedPath string) ( //nolint:gocognit
|
||||
profile *Profile,
|
||||
newProfile bool,
|
||||
err error,
|
||||
|
||||
@@ -38,6 +38,11 @@ func start() error {
|
||||
return err
|
||||
}
|
||||
|
||||
err = registerRevisionProvider()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = startProfileUpdateChecker()
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -4,8 +4,6 @@ import (
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"github.com/safing/portbase/database"
|
||||
|
||||
"github.com/safing/portbase/database/record"
|
||||
"github.com/safing/portbase/runtime"
|
||||
)
|
||||
@@ -16,6 +14,7 @@ const (
|
||||
|
||||
var (
|
||||
errProfileNotActive = errors.New("profile not active")
|
||||
errNoLayeredProfile = errors.New("profile has no layered profile")
|
||||
)
|
||||
|
||||
func registerRevisionProvider() error {
|
||||
@@ -38,7 +37,7 @@ func getRevision(key string) ([]record.Record, error) {
|
||||
// Get layered profile.
|
||||
layeredProfile := profile.LayeredProfile()
|
||||
if layeredProfile == nil {
|
||||
return nil, database.ErrNotFound
|
||||
return nil, errNoLayeredProfile
|
||||
}
|
||||
|
||||
// Update profiles if necessary.
|
||||
|
||||
@@ -10,17 +10,11 @@ import (
|
||||
|
||||
"github.com/safing/portmaster/status"
|
||||
|
||||
"github.com/tevino/abool"
|
||||
|
||||
"github.com/safing/portbase/config"
|
||||
"github.com/safing/portmaster/intel"
|
||||
"github.com/safing/portmaster/profile/endpoints"
|
||||
)
|
||||
|
||||
var (
|
||||
no = abool.NewBool(false)
|
||||
)
|
||||
|
||||
// LayeredProfile combines multiple Profiles.
|
||||
type LayeredProfile struct {
|
||||
record.Base
|
||||
@@ -29,11 +23,8 @@ type LayeredProfile struct {
|
||||
localProfile *Profile
|
||||
layers []*Profile
|
||||
|
||||
LayerIDs []string
|
||||
RevisionCounter uint64
|
||||
|
||||
validityFlag *abool.AtomicBool
|
||||
validityFlagLock sync.Mutex
|
||||
LayerIDs []string
|
||||
RevisionCounter uint64
|
||||
globalValidityFlag *config.ValidityFlag
|
||||
|
||||
securityLevel *uint32
|
||||
@@ -63,7 +54,6 @@ func NewLayeredProfile(localProfile *Profile) *LayeredProfile {
|
||||
localProfile: localProfile,
|
||||
layers: make([]*Profile, 0, len(localProfile.LinkedProfiles)+1),
|
||||
LayerIDs: make([]string, 0, len(localProfile.LinkedProfiles)+1),
|
||||
validityFlag: abool.NewBool(true),
|
||||
globalValidityFlag: config.NewValidityFlag(),
|
||||
securityLevel: &securityLevelVal,
|
||||
}
|
||||
@@ -140,7 +130,7 @@ func (lp *LayeredProfile) LockForUsage() {
|
||||
}
|
||||
}
|
||||
|
||||
// LockForUsage unlocks the layered profile, including all layers individually.
|
||||
// UnlockForUsage unlocks the layered profile, including all layers individually.
|
||||
func (lp *LayeredProfile) UnlockForUsage() {
|
||||
lp.RUnlock()
|
||||
for _, layer := range lp.layers {
|
||||
@@ -156,12 +146,6 @@ func (lp *LayeredProfile) LocalProfile() *Profile {
|
||||
return lp.localProfile
|
||||
}
|
||||
|
||||
func (lp *LayeredProfile) getValidityFlag() *abool.AtomicBool {
|
||||
lp.validityFlagLock.Lock()
|
||||
defer lp.validityFlagLock.Unlock()
|
||||
return lp.validityFlag
|
||||
}
|
||||
|
||||
// RevisionCnt returns the current profile revision counter.
|
||||
func (lp *LayeredProfile) RevisionCnt() (revisionCounter uint64) {
|
||||
if lp == nil {
|
||||
@@ -188,6 +172,7 @@ func (lp *LayeredProfile) MarkStillActive() {
|
||||
}
|
||||
}
|
||||
|
||||
// NeedsUpdate checks for outdated profiles.
|
||||
func (lp *LayeredProfile) NeedsUpdate() (outdated bool) {
|
||||
lp.RLock()
|
||||
defer lp.RUnlock()
|
||||
@@ -207,7 +192,7 @@ func (lp *LayeredProfile) NeedsUpdate() (outdated bool) {
|
||||
return false
|
||||
}
|
||||
|
||||
// Update checks for updated profiles and replaces any outdated profiles.
|
||||
// Update checks for and replaces any outdated profiles.
|
||||
func (lp *LayeredProfile) Update() (revisionCounter uint64) {
|
||||
lp.Lock()
|
||||
defer lp.Unlock()
|
||||
@@ -230,11 +215,6 @@ func (lp *LayeredProfile) Update() (revisionCounter uint64) {
|
||||
}
|
||||
|
||||
if changed {
|
||||
// reset validity flag
|
||||
lp.validityFlagLock.Lock()
|
||||
lp.validityFlag.SetTo(false)
|
||||
lp.validityFlag = abool.NewBool(true)
|
||||
lp.validityFlagLock.Unlock()
|
||||
// get global config validity flag
|
||||
lp.globalValidityFlag.Refresh()
|
||||
|
||||
|
||||
@@ -89,7 +89,7 @@ type Profile struct { //nolint:maligned // not worth the effort
|
||||
// Config holds profile specific setttings. It's a nested
|
||||
// object with keys defining the settings database path. All keys
|
||||
// until the actual settings value (which is everything that is not
|
||||
// an object) need to be concatinated for the settings database
|
||||
// an object) need to be concatenated for the settings database
|
||||
// path.
|
||||
Config map[string]interface{}
|
||||
// ApproxLastUsed holds a UTC timestamp in seconds of
|
||||
@@ -120,7 +120,6 @@ type Profile struct { //nolint:maligned // not worth the effort
|
||||
filterListIDs []string
|
||||
|
||||
// Lifecycle Management
|
||||
usedBy *LayeredProfile
|
||||
outdated *abool.AtomicBool
|
||||
lastActive *int64
|
||||
|
||||
|
||||
Reference in New Issue
Block a user