mirror of
https://github.com/safing/portmaster
synced 2025-04-25 13:29:10 +00:00
Clean up code and fix linter errors
This commit is contained in:
parent
fa3f873c31
commit
7b72d9fe4b
8 changed files with 23 additions and 37 deletions
firewall
network
profile
updates
|
@ -58,7 +58,7 @@ func prompt(ctx context.Context, conn *network.Connection, pkt packet.Packet) {
|
|||
}
|
||||
|
||||
case <-time.After(1 * time.Second):
|
||||
log.Tracer(ctx).Debugf("filter: continueing prompting async")
|
||||
log.Tracer(ctx).Debugf("filter: continuing prompting async")
|
||||
conn.Deny("prompting in progress", profile.CfgOptionDefaultActionKey)
|
||||
|
||||
case <-ctx.Done():
|
||||
|
|
|
@ -94,7 +94,7 @@ type Connection struct { //nolint:maligned // TODO: fix alignment
|
|||
Started int64
|
||||
// Ended is set to the number of seconds in UNIX epoch time at which
|
||||
// the connection is considered terminated. Ended may be set at any
|
||||
// time so access must be guarded by the conneciton lock.
|
||||
// time so access must be guarded by the connection lock.
|
||||
Ended int64
|
||||
// VerdictPermanent is set to true if the final verdict is permanent
|
||||
// and the connection has been (or will be) handed back to the kernel.
|
||||
|
@ -119,7 +119,7 @@ type Connection struct { //nolint:maligned // TODO: fix alignment
|
|||
// points and access to it must be guarded by the connection lock.
|
||||
Internal bool
|
||||
// process holds a reference to the actor process. That is, the
|
||||
// process instance that initated the conneciton.
|
||||
// process instance that initated the connection.
|
||||
process *process.Process
|
||||
// pkgQueue is used to serialize packet handling for a single
|
||||
// connection and is served by the connections packetHandler.
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -142,10 +142,10 @@ func upgradeCoreNotifyActionHandler(_ context.Context, n *notifications.Notifica
|
|||
nil,
|
||||
)
|
||||
if err != nil {
|
||||
log.Warningf("updates: failed to trigger restart via notification: %s", err)
|
||||
return fmt.Errorf("failed to trigger restart via notification: %s", err)
|
||||
}
|
||||
case "later":
|
||||
n.Delete()
|
||||
return n.Delete()
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
Loading…
Add table
Reference in a new issue