MCPcopy Create free account
hub / github.com/chainreactors/EvilProxy / prepareAuthUpdatesLocked

Method prepareAuthUpdatesLocked

internal/watcher/dispatcher.go:145–195  ·  view source on GitHub ↗
(auths []*coreauth.Auth, force bool)

Source from the content-addressed store, hash-verified

143}
144
145func (w *Watcher) prepareAuthUpdatesLocked(auths []*coreauth.Auth, force bool) []AuthUpdate {
146 newState := make(map[string]*coreauth.Auth, len(auths))
147 orderedIDs := make([]string, 0, len(auths))
148 for _, auth := range auths {
149 if auth == nil || auth.ID == "" {
150 continue
151 }
152 if _, exists := newState[auth.ID]; !exists {
153 orderedIDs = append(orderedIDs, auth.ID)
154 }
155 newState[auth.ID] = auth.Clone()
156 }
157 if w.currentAuths == nil {
158 w.currentAuths = newState
159 if w.authQueue == nil {
160 return nil
161 }
162 updates := make([]AuthUpdate, 0, len(newState))
163 for _, id := range orderedIDs {
164 auth := newState[id]
165 if auth == nil {
166 continue
167 }
168 updates = append(updates, AuthUpdate{Action: AuthUpdateActionAdd, ID: id, Auth: auth.Clone()})
169 }
170 return updates
171 }
172 if w.authQueue == nil {
173 w.currentAuths = newState
174 return nil
175 }
176 updates := make([]AuthUpdate, 0, len(newState)+len(w.currentAuths))
177 for _, id := range orderedIDs {
178 auth := newState[id]
179 if auth == nil {
180 continue
181 }
182 if existing, ok := w.currentAuths[id]; !ok {
183 updates = append(updates, AuthUpdate{Action: AuthUpdateActionAdd, ID: id, Auth: auth.Clone()})
184 } else if force || !authEqual(existing, auth) {
185 updates = append(updates, AuthUpdate{Action: AuthUpdateActionModify, ID: id, Auth: auth.Clone()})
186 }
187 }
188 for id := range w.currentAuths {
189 if _, ok := newState[id]; !ok {
190 updates = append(updates, AuthUpdate{Action: AuthUpdateActionDelete, ID: id})
191 }
192 }
193 w.currentAuths = newState
194 return updates
195}
196
197func (w *Watcher) dispatchAuthUpdates(updates []AuthUpdate) {
198 if len(updates) == 0 {

Callers 2

refreshAuthStateMethod · 0.95

Calls 2

authEqualFunction · 0.85
CloneMethod · 0.45