github.com/database64128/shadowsocks-go@v1.10.2-0.20240315062903-143a773533f1/ss2022/credstore.go (about) 1 package ss2022 2 3 import "sync" 4 5 // CredStore stores credentials for a Shadowsocks 2022 server. 6 type CredStore struct { 7 mu sync.Mutex 8 ulm UserLookupMap 9 } 10 11 // Lock locks its internal mutex. 12 func (s *CredStore) Lock() { 13 s.mu.Lock() 14 } 15 16 // Unlock unlocks its internal mutex. 17 func (s *CredStore) Unlock() { 18 s.mu.Unlock() 19 } 20 21 // UpdateUserLookupMap calls the given function with the current user lookup map. 22 func (s *CredStore) UpdateUserLookupMap(f func(ulm UserLookupMap)) { 23 s.mu.Lock() 24 f(s.ulm) 25 s.mu.Unlock() 26 } 27 28 // ReplaceUserLookupMap replaces the current user lookup map with the given one. 29 func (s *CredStore) ReplaceUserLookupMap(ulm UserLookupMap) { 30 s.mu.Lock() 31 s.ulm = ulm 32 s.mu.Unlock() 33 }