Implement review feedback
This commit is contained in:
@@ -78,7 +78,7 @@ func notifyDisableDNSCache() {
|
|||||||
|
|
||||||
func notifyRebootRequired() {
|
func notifyRebootRequired() {
|
||||||
(¬ifications.Notification{
|
(¬ifications.Notification{
|
||||||
EventID: "interception:©windows-dnscache-reboot-required",
|
EventID: "interception:windows-dnscache-reboot-required",
|
||||||
Message: "Please restart your system to complete Portmaster integration.",
|
Message: "Please restart your system to complete Portmaster integration.",
|
||||||
Type: notifications.Warning,
|
Type: notifications.Warning,
|
||||||
}).Save()
|
}).Save()
|
||||||
|
|||||||
@@ -38,7 +38,9 @@ import (
|
|||||||
|
|
||||||
const noReasonOptionKey = ""
|
const noReasonOptionKey = ""
|
||||||
|
|
||||||
var deciders = []func(context.Context, *network.Connection, packet.Packet) bool{
|
type deciderFn func(context.Context, *network.Connection, packet.Packet) bool
|
||||||
|
|
||||||
|
var deciders = []deciderFn{
|
||||||
checkPortmasterConnection,
|
checkPortmasterConnection,
|
||||||
checkSelfCommunication,
|
checkSelfCommunication,
|
||||||
checkConnectionType,
|
checkConnectionType,
|
||||||
@@ -152,7 +154,7 @@ func checkSelfCommunication(ctx context.Context, conn *network.Connection, pkt p
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Tracer(ctx).Warningf("filter: failed to find load local peer process with PID %d: %s", otherPid, err)
|
log.Tracer(ctx).Warningf("filter: failed to find load local peer process with PID %d: %s", otherPid, err)
|
||||||
} else if otherProcess.Pid == conn.Process().Pid {
|
} else if otherProcess.Pid == conn.Process().Pid {
|
||||||
conn.Accept("connection to self", noReasonOptionKey)
|
conn.Accept("process internal connection", noReasonOptionKey)
|
||||||
conn.Internal = true
|
conn.Internal = true
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -227,11 +227,8 @@ func setCaptivePortal(portalURL *url.URL) {
|
|||||||
|
|
||||||
// notify
|
// notify
|
||||||
cleanUpPortalNotification()
|
cleanUpPortalNotification()
|
||||||
// TODO: add "open" button
|
|
||||||
captivePortalNotification = notifications.Notify(¬ifications.Notification{
|
captivePortalNotification = notifications.Notify(¬ifications.Notification{
|
||||||
EventID: fmt.Sprintf(
|
EventID: "netenv:captive-portal",
|
||||||
"netenv:captive-portal:%s", captivePortal.Domain,
|
|
||||||
),
|
|
||||||
Type: notifications.Info,
|
Type: notifications.Info,
|
||||||
Title: "Captive Portal",
|
Title: "Captive Portal",
|
||||||
Category: "Core",
|
Category: "Core",
|
||||||
@@ -239,6 +236,7 @@ func setCaptivePortal(portalURL *url.URL) {
|
|||||||
"Portmaster detected a captive portal at %s",
|
"Portmaster detected a captive portal at %s",
|
||||||
captivePortal.Domain,
|
captivePortal.Domain,
|
||||||
),
|
),
|
||||||
|
EventData: captivePortal,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -122,11 +122,12 @@ func CleanProcessStorage(activePIDs map[int]struct{}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Process is inactive, start deletion process
|
// Process is inactive, start deletion process
|
||||||
|
lastSeen := p.GetLastSeen()
|
||||||
switch {
|
switch {
|
||||||
case p.LastSeen == 0:
|
case lastSeen == 0:
|
||||||
// add last
|
// add last seen timestamp
|
||||||
p.LastSeen = time.Now().Unix()
|
p.SetLastSeen(time.Now().Unix())
|
||||||
case p.LastSeen > threshold:
|
case lastSeen > threshold:
|
||||||
// within keep period
|
// within keep period
|
||||||
default:
|
default:
|
||||||
// delete now
|
// delete now
|
||||||
|
|||||||
@@ -59,9 +59,29 @@ type Process struct {
|
|||||||
|
|
||||||
// Profile returns the assigned layered profile.
|
// Profile returns the assigned layered profile.
|
||||||
func (p *Process) Profile() *profile.LayeredProfile {
|
func (p *Process) Profile() *profile.LayeredProfile {
|
||||||
|
if p == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
return p.profile
|
return p.profile
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetLastSeen returns the unix timestamp when the process was last seen.
|
||||||
|
func (p *Process) GetLastSeen() int64 {
|
||||||
|
p.Lock()
|
||||||
|
defer p.Unlock()
|
||||||
|
|
||||||
|
return p.LastSeen
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetLastSeen sets the unix timestamp when the process was last seen.
|
||||||
|
func (p *Process) SetLastSeen(lastSeen int64) {
|
||||||
|
p.Lock()
|
||||||
|
defer p.Unlock()
|
||||||
|
|
||||||
|
p.LastSeen = lastSeen
|
||||||
|
}
|
||||||
|
|
||||||
// Strings returns a string representation of process.
|
// Strings returns a string representation of process.
|
||||||
func (p *Process) String() string {
|
func (p *Process) String() string {
|
||||||
if p == nil {
|
if p == nil {
|
||||||
|
|||||||
@@ -97,7 +97,8 @@ func GetProfile(source profileSource, id, linkedPath string) (
|
|||||||
// Process profiles coming directly from the database.
|
// Process profiles coming directly from the database.
|
||||||
// As we don't use any caching, these will be new objects.
|
// As we don't use any caching, these will be new objects.
|
||||||
|
|
||||||
// Mark the profile as being saved internally in order to bypass checks.
|
// Mark the profile as being saved internally in order to not trigger an
|
||||||
|
// update after saving it to the database.
|
||||||
profile.internalSave = true
|
profile.internalSave = true
|
||||||
|
|
||||||
// Add a layeredProfile to local profiles.
|
// Add a layeredProfile to local profiles.
|
||||||
|
|||||||
@@ -63,7 +63,6 @@ func NewLayeredProfile(localProfile *Profile) *LayeredProfile {
|
|||||||
localProfile: localProfile,
|
localProfile: localProfile,
|
||||||
layers: make([]*Profile, 0, len(localProfile.LinkedProfiles)+1),
|
layers: make([]*Profile, 0, len(localProfile.LinkedProfiles)+1),
|
||||||
LayerIDs: make([]string, 0, len(localProfile.LinkedProfiles)+1),
|
LayerIDs: make([]string, 0, len(localProfile.LinkedProfiles)+1),
|
||||||
RevisionCounter: 0,
|
|
||||||
validityFlag: abool.NewBool(true),
|
validityFlag: abool.NewBool(true),
|
||||||
globalValidityFlag: config.NewValidityFlag(),
|
globalValidityFlag: config.NewValidityFlag(),
|
||||||
securityLevel: &securityLevelVal,
|
securityLevel: &securityLevelVal,
|
||||||
@@ -361,21 +360,26 @@ func (lp *LayeredProfile) wrapSecurityLevelOption(configKey string, globalConfig
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (lp *LayeredProfile) wrapBoolOption(configKey string, globalConfig config.BoolOption) config.BoolOption {
|
func (lp *LayeredProfile) wrapBoolOption(configKey string, globalConfig config.BoolOption) config.BoolOption {
|
||||||
valid := no
|
revCnt := lp.RevisionCounter
|
||||||
var value bool
|
var value bool
|
||||||
|
var refreshLock sync.Mutex
|
||||||
|
|
||||||
return func() bool {
|
return func() bool {
|
||||||
if !valid.IsSet() {
|
refreshLock.Lock()
|
||||||
valid = lp.getValidityFlag()
|
defer refreshLock.Unlock()
|
||||||
|
|
||||||
|
// Check if we need to refresh the value.
|
||||||
|
if revCnt != lp.RevisionCounter {
|
||||||
|
revCnt = lp.RevisionCounter
|
||||||
|
|
||||||
|
// Go through all layers to find an active value.
|
||||||
found := false
|
found := false
|
||||||
layerLoop:
|
|
||||||
for _, layer := range lp.layers {
|
for _, layer := range lp.layers {
|
||||||
layerValue, ok := layer.configPerspective.GetAsBool(configKey)
|
layerValue, ok := layer.configPerspective.GetAsBool(configKey)
|
||||||
if ok {
|
if ok {
|
||||||
found = true
|
found = true
|
||||||
value = layerValue
|
value = layerValue
|
||||||
break layerLoop
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !found {
|
if !found {
|
||||||
@@ -388,21 +392,26 @@ func (lp *LayeredProfile) wrapBoolOption(configKey string, globalConfig config.B
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (lp *LayeredProfile) wrapIntOption(configKey string, globalConfig config.IntOption) config.IntOption {
|
func (lp *LayeredProfile) wrapIntOption(configKey string, globalConfig config.IntOption) config.IntOption {
|
||||||
valid := no
|
revCnt := lp.RevisionCounter
|
||||||
var value int64
|
var value int64
|
||||||
|
var refreshLock sync.Mutex
|
||||||
|
|
||||||
return func() int64 {
|
return func() int64 {
|
||||||
if !valid.IsSet() {
|
refreshLock.Lock()
|
||||||
valid = lp.getValidityFlag()
|
defer refreshLock.Unlock()
|
||||||
|
|
||||||
|
// Check if we need to refresh the value.
|
||||||
|
if revCnt != lp.RevisionCounter {
|
||||||
|
revCnt = lp.RevisionCounter
|
||||||
|
|
||||||
|
// Go through all layers to find an active value.
|
||||||
found := false
|
found := false
|
||||||
layerLoop:
|
|
||||||
for _, layer := range lp.layers {
|
for _, layer := range lp.layers {
|
||||||
layerValue, ok := layer.configPerspective.GetAsInt(configKey)
|
layerValue, ok := layer.configPerspective.GetAsInt(configKey)
|
||||||
if ok {
|
if ok {
|
||||||
found = true
|
found = true
|
||||||
value = layerValue
|
value = layerValue
|
||||||
break layerLoop
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !found {
|
if !found {
|
||||||
@@ -432,21 +441,26 @@ func (lp *LayeredProfile) GetProfileSource(configKey string) string {
|
|||||||
For later:
|
For later:
|
||||||
|
|
||||||
func (lp *LayeredProfile) wrapStringOption(configKey string, globalConfig config.StringOption) config.StringOption {
|
func (lp *LayeredProfile) wrapStringOption(configKey string, globalConfig config.StringOption) config.StringOption {
|
||||||
valid := no
|
revCnt := lp.RevisionCounter
|
||||||
var value string
|
var value string
|
||||||
|
var refreshLock sync.Mutex
|
||||||
|
|
||||||
return func() string {
|
return func() string {
|
||||||
if !valid.IsSet() {
|
refreshLock.Lock()
|
||||||
valid = lp.getValidityFlag()
|
defer refreshLock.Unlock()
|
||||||
|
|
||||||
|
// Check if we need to refresh the value.
|
||||||
|
if revCnt != lp.RevisionCounter {
|
||||||
|
revCnt = lp.RevisionCounter
|
||||||
|
|
||||||
|
// Go through all layers to find an active value.
|
||||||
found := false
|
found := false
|
||||||
layerLoop:
|
|
||||||
for _, layer := range lp.layers {
|
for _, layer := range lp.layers {
|
||||||
layerValue, ok := layer.configPerspective.GetAsString(configKey)
|
layerValue, ok := layer.configPerspective.GetAsString(configKey)
|
||||||
if ok {
|
if ok {
|
||||||
found = true
|
found = true
|
||||||
value = layerValue
|
value = layerValue
|
||||||
break layerLoop
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !found {
|
if !found {
|
||||||
|
|||||||
Reference in New Issue
Block a user