MCPcopy
hub / github.com/safing/portmaster / startProfileUpdateChecker

Function startProfileUpdateChecker

service/profile/database.go:43–125  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

41}
42
43func startProfileUpdateChecker() error {
44 module.mgr.Go("update active profiles", func(ctx *mgr.WorkerCtx) (err error) {
45 profilesSub, err := profileDB.Subscribe(query.New(ProfilesDBPath))
46 if err != nil {
47 return err
48 }
49 defer func() {
50 err := profilesSub.Cancel()
51 if err != nil {
52 log.Warningf("profile: failed to cancel subscription for updating active profiles: %s", err)
53 }
54 }()
55
56 profileFeed:
57 for {
58 select {
59 case r := <-profilesSub.Feed:
60 // Check if subscription was canceled.
61 if r == nil {
62 return errors.New("subscription canceled")
63 }
64
65 scopedID := strings.TrimPrefix(r.Key(), ProfilesDBPath)
66
67 // Check if fingerprints changed such that the profile ID needs to be
68 // re-derived. This must run before the activeProfile lookup so that it
69 // also applies when the app is not currently running.
70 if !r.Meta().IsDeleted() {
71 if receivedProfile, parseErr := EnsureProfile(r); parseErr == nil && !receivedProfile.savedInternally {
72 if len(receivedProfile.Fingerprints) > 0 &&
73 DeriveProfileID(receivedProfile.Fingerprints) != receivedProfile.ID {
74 if renameErr := migrateProfileOnFingerprintChange(receivedProfile); renameErr != nil {
75 log.Errorf("profile: failed to rename profile %s after fingerprint change: %s", scopedID, renameErr)
76 }
77 // The rename saves a new profile and deletes the old one, each of
78 // which produces its own feed event. Skip further processing here.
79 continue profileFeed
80 }
81 }
82 }
83
84 // Get active profile.
85 activeProfile := getActiveProfile(scopedID)
86 if activeProfile == nil {
87 // Check if profile is being deleted.
88 if r.Meta().IsDeleted() {
89 meta.MarkDeleted(scopedID)
90 }
91
92 // Don't do any additional actions if the profile is not active.
93 continue profileFeed
94 }
95
96 // Always increase the revision counter of the layer profile.
97 // This marks previous connections in the UI as decided with outdated settings.
98 if activeProfile.layeredProfile != nil {
99 activeProfile.layeredProfile.increaseRevisionCounter(true)
100 }

Callers 1

startFunction · 0.85

Calls 15

NewFunction · 0.92
WarningfFunction · 0.92
ErrorfFunction · 0.92
EnsureProfileFunction · 0.85
DeriveProfileIDFunction · 0.85
getActiveProfileFunction · 0.85
NewMethod · 0.80
IsDeletedMethod · 0.80
MarkDeletedMethod · 0.80
KeyMethod · 0.65

Tested by

no test coverage detected