MCPcopy
hub / github.com/cbeuw/Cloak / commitUpdate

Method commitUpdate

internal/server/userpanel.go:162–210  ·  view source on GitHub ↗

commitUpdate put all usageUpdates into a slice of StatusUpdate, calls Manager.UploadStatus, gets the responses and act to each user according to the responses

()

Source from the content-addressed store, hash-verified

160// commitUpdate put all usageUpdates into a slice of StatusUpdate, calls Manager.UploadStatus, gets the responses
161// and act to each user according to the responses
162func (panel *userPanel) commitUpdate() error {
163 panel.usageUpdateQueueM.Lock()
164 statuses := make([]usermanager.StatusUpdate, 0, len(panel.usageUpdateQueue))
165 for arrUID, usage := range panel.usageUpdateQueue {
166 panel.activeUsersM.RLock()
167 user := panel.activeUsers[arrUID]
168 panel.activeUsersM.RUnlock()
169 var numSession int
170 if user != nil {
171 if user.bypass {
172 continue
173 }
174 numSession = user.NumSession()
175 }
176 status := usermanager.StatusUpdate{
177 UID: arrUID[:],
178 Active: panel.isActive(arrUID[:]),
179 NumSession: numSession,
180 UpUsage: *usage.up,
181 DownUsage: *usage.down,
182 Timestamp: time.Now().Unix(),
183 }
184 statuses = append(statuses, status)
185 }
186 panel.usageUpdateQueue = make(map[[16]byte]*usagePair)
187 panel.usageUpdateQueueM.Unlock()
188
189 if len(statuses) == 0 {
190 return nil
191 }
192 responses, err := panel.Manager.UploadStatus(statuses)
193 if err != nil {
194 return err
195 }
196 for _, resp := range responses {
197 var arrUID [16]byte
198 copy(arrUID[:], resp.UID)
199 switch resp.Action {
200 case usermanager.TERMINATE:
201 panel.activeUsersM.RLock()
202 user := panel.activeUsers[arrUID]
203 panel.activeUsersM.RUnlock()
204 if user != nil {
205 panel.TerminateActiveUser(user, resp.Message)
206 }
207 }
208 }
209 return nil
210}
211
212func (panel *userPanel) regularQueueUpload() {
213 for {

Callers 3

regularQueueUploadMethod · 0.95
TestUserPanel_BypassUserFunction · 0.80

Calls 4

isActiveMethod · 0.95
TerminateActiveUserMethod · 0.95
NumSessionMethod · 0.80
UploadStatusMethod · 0.65

Tested by 2

TestUserPanel_BypassUserFunction · 0.64