@@ -33,10 +33,10 @@ type Manager struct {
3333 // are available for use. This map will start out not including any of
3434 // lnd's sub-server permissions. Only when the LND build tags are
3535 // obtained and OnLNDBuildTags is called will this map include the
36- // available LND sub-server permissions. This map must only be accessed
37- // once the permsMu mutex is held.
38- perms map [ string ][]bakery. Op
39- permsMu sync.RWMutex
36+ // available LND sub-server permissions.
37+ perms map [ string ][]bakery. Op
38+
39+ mu sync.RWMutex
4040}
4141
4242// NewManager constructs a new Manager instance and collects any of the
@@ -105,8 +105,8 @@ func NewManager(withAllSubServers bool) (*Manager, error) {
105105// that it does not require a macaroon for validation. A URL is considered
106106// white-listed if it has no operations associated with a URL.
107107func (pm * Manager ) IsWhiteListedURL (url string ) bool {
108- pm .permsMu .Lock ()
109- defer pm .permsMu .Unlock ()
108+ pm .mu .Lock ()
109+ defer pm .mu .Unlock ()
110110
111111 ops , ok := pm .perms [url ]
112112
@@ -118,8 +118,8 @@ func (pm *Manager) IsWhiteListedURL(url string) bool {
118118func (pm * Manager ) RegisterSubServer (name string ,
119119 permissions map [string ][]bakery.Op , whiteListURLs map [string ]struct {}) {
120120
121- pm .permsMu .Lock ()
122- defer pm .permsMu .Unlock ()
121+ pm .mu .Lock ()
122+ defer pm .mu .Unlock ()
123123
124124 pm .fixedPerms [name ] = permissions
125125
@@ -142,8 +142,8 @@ func (pm *Manager) RegisterSubServer(name string,
142142// permissions to add to the main permissions list. This method should only
143143// be called once.
144144func (pm * Manager ) OnLNDBuildTags (lndBuildTags []string ) {
145- pm .permsMu .Lock ()
146- defer pm .permsMu .Unlock ()
145+ pm .mu .Lock ()
146+ defer pm .mu .Unlock ()
147147
148148 tagLookup := make (map [string ]bool )
149149 for _ , t := range lndBuildTags {
@@ -170,8 +170,8 @@ func (pm *Manager) OnLNDBuildTags(lndBuildTags []string) {
170170// the uri is known to the manager. The second return parameter will be false
171171// if the URI is unknown to the manager.
172172func (pm * Manager ) URIPermissions (uri string ) ([]bakery.Op , bool ) {
173- pm .permsMu .RLock ()
174- defer pm .permsMu .RUnlock ()
173+ pm .mu .RLock ()
174+ defer pm .mu .RUnlock ()
175175
176176 ops , ok := pm .perms [uri ]
177177 return ops , ok
@@ -182,8 +182,8 @@ func (pm *Manager) URIPermissions(uri string) ([]bakery.Op, bool) {
182182// are a list of URIs that match the regex and the boolean represents whether
183183// the given uri is in fact a regex.
184184func (pm * Manager ) MatchRegexURI (uriRegex string ) ([]string , bool ) {
185- pm .permsMu .RLock ()
186- defer pm .permsMu .RUnlock ()
185+ pm .mu .RLock ()
186+ defer pm .mu .RUnlock ()
187187
188188 // If the given uri string is one of our permissions, then it is not
189189 // a regex.
@@ -215,8 +215,8 @@ func (pm *Manager) MatchRegexURI(uriRegex string) ([]string, bool) {
215215// manager is aware of. Optionally, readOnly can be set to true if only the
216216// read-only permissions should be returned.
217217func (pm * Manager ) ActivePermissions (readOnly bool ) []bakery.Op {
218- pm .permsMu .RLock ()
219- defer pm .permsMu .RUnlock ()
218+ pm .mu .RLock ()
219+ defer pm .mu .RUnlock ()
220220
221221 // De-dup the permissions and optionally apply the read-only filter.
222222 dedupMap := make (map [string ]map [string ]bool )
@@ -256,6 +256,9 @@ func (pm *Manager) ActivePermissions(readOnly bool) []bakery.Op {
256256// _except_ for any LND permissions. In other words, this returns permissions
257257// for which the external validator of Lit is responsible.
258258func (pm * Manager ) GetLitPerms () map [string ][]bakery.Op {
259+ pm .mu .Lock ()
260+ defer pm .mu .Unlock ()
261+
259262 result := make (map [string ][]bakery.Op )
260263 for subserver , ops := range pm .fixedPerms {
261264 if subserver == lndPerms {
@@ -271,6 +274,9 @@ func (pm *Manager) GetLitPerms() map[string][]bakery.Op {
271274
272275// IsSubServerURI if the given URI belongs to the RPC of the given server.
273276func (pm * Manager ) IsSubServerURI (name string , uri string ) bool {
277+ pm .mu .Lock ()
278+ defer pm .mu .Unlock ()
279+
274280 if name == lndPerms {
275281 return pm .isLndURI (uri )
276282 }
0 commit comments