perf: sync protocol and core hardening updates
This commit is contained in:
parent
152fed3b87
commit
4390ebf5a9
283 changed files with 29231 additions and 2295 deletions
70
internal/store/memory/code_cas.go
Normal file
70
internal/store/memory/code_cas.go
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
package memory
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"telesrv/internal/store"
|
||||
)
|
||||
|
||||
func (s *CodeStore) GetSnapshot(_ context.Context, hash string) (store.PhoneCodeSnapshot, bool, error) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
entry, found := s.liveCodeLocked(hash)
|
||||
if !found {
|
||||
return store.PhoneCodeSnapshot{}, false, nil
|
||||
}
|
||||
if entry.code.Version != store.PhoneCodeVersionCurrent || entry.code.Revision == "" {
|
||||
s.deleteCodeLocked(hash, entry.code)
|
||||
return store.PhoneCodeSnapshot{}, false, nil
|
||||
}
|
||||
return store.PhoneCodeSnapshot{Record: entry.code, Revision: entry.code.Revision}, true, nil
|
||||
}
|
||||
|
||||
func (s *CodeStore) CompareAndUpdate(_ context.Context, hash, expectedRevision string, next store.PhoneCode) (bool, error) {
|
||||
if expectedRevision == "" || next.Version != store.PhoneCodeVersionCurrent || next.Purpose != "" {
|
||||
return false, nil
|
||||
}
|
||||
revision, err := store.NewPhoneCodeRevisionToken()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
next.Revision = revision
|
||||
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
entry, found := s.liveCodeLocked(hash)
|
||||
if !found {
|
||||
return false, nil
|
||||
}
|
||||
if entry.code.Version != store.PhoneCodeVersionCurrent || entry.code.Revision == "" {
|
||||
s.deleteCodeLocked(hash, entry.code)
|
||||
return false, nil
|
||||
}
|
||||
if entry.code.Purpose != "" || entry.code.Revision != expectedRevision {
|
||||
return false, nil
|
||||
}
|
||||
entry.code = next
|
||||
s.m[hash] = entry
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (s *CodeStore) CompareAndDelete(_ context.Context, hash, expectedRevision string) (bool, error) {
|
||||
if expectedRevision == "" {
|
||||
return false, nil
|
||||
}
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
entry, found := s.liveCodeLocked(hash)
|
||||
if !found {
|
||||
return false, nil
|
||||
}
|
||||
if entry.code.Version != store.PhoneCodeVersionCurrent || entry.code.Revision == "" {
|
||||
s.deleteCodeLocked(hash, entry.code)
|
||||
return false, nil
|
||||
}
|
||||
if entry.code.Purpose != "" || entry.code.Revision != expectedRevision {
|
||||
return false, nil
|
||||
}
|
||||
s.deleteCodeLocked(hash, entry.code)
|
||||
return true, nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue