Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions internal/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type Registry struct {
filterIPs bool
freezer *freeze.Freezer
maxPoll int
provMutex sync.Mutex
provMutex sync.RWMutex
pollDone chan struct{}
providers map[peer.ID]*ProviderInfo
sequences *sequences
Expand Down Expand Up @@ -843,17 +843,17 @@ func (r *Registry) register(ctx context.Context, info *ProviderInfo) error {

// IsRegistered checks if the provider is in the registry
func (r *Registry) IsRegistered(providerID peer.ID) bool {
r.provMutex.Lock()
r.provMutex.RLock()
_, found := r.providers[providerID]
r.provMutex.Unlock()
r.provMutex.RUnlock()
return found
}

// ProviderInfo returns information for a registered provider.
func (r *Registry) ProviderInfo(providerID peer.ID) (*ProviderInfo, bool) {
r.provMutex.Lock()
r.provMutex.RLock()
pinfo, ok := r.providers[providerID]
r.provMutex.Unlock()
r.provMutex.RUnlock()
if !ok {
return nil, false
}
Expand All @@ -863,7 +863,7 @@ func (r *Registry) ProviderInfo(providerID peer.ID) (*ProviderInfo, bool) {
// AllProviderInfo returns information for all registered providers that are
// active and allowed.
func (r *Registry) AllProviderInfo() []*ProviderInfo {
r.provMutex.Lock()
r.provMutex.RLock()
infos := make([]*ProviderInfo, 0, len(r.providers))
for _, info := range r.providers {
if r.assigned != nil {
Expand All @@ -878,7 +878,7 @@ func (r *Registry) AllProviderInfo() []*ProviderInfo {
}
infos = append(infos, info)
}
r.provMutex.Unlock()
r.provMutex.RUnlock()

// Stats tracks the number of active, allowed providers.
stats.Record(context.Background(), metrics.ProviderCount.M(int64(len(infos))))
Expand Down Expand Up @@ -1055,8 +1055,8 @@ func (r *Registry) RemoveProvider(ctx context.Context, providerID peer.ID) error
}

func (r *Registry) ProviderByPublisher(pubID peer.ID) (peer.ID, bool) {
r.provMutex.Lock()
defer r.provMutex.Unlock()
r.provMutex.RLock()
defer r.provMutex.RUnlock()

pinfo, ok := r.providers[pubID]
if ok && pinfo.Publisher == pubID {
Expand Down
Loading