|
|
|
@ -4,6 +4,7 @@ import (
|
|
|
|
|
"context"
|
|
|
|
|
"net/http"
|
|
|
|
|
"sort"
|
|
|
|
|
"sync"
|
|
|
|
|
|
|
|
|
|
"forge.cadoles.com/Cadoles/go-proxy"
|
|
|
|
|
"forge.cadoles.com/Cadoles/go-proxy/wildcard"
|
|
|
|
@ -23,6 +24,9 @@ type Director struct {
|
|
|
|
|
proxyCache cache.Cache[string, []*store.Proxy]
|
|
|
|
|
layerCache cache.Cache[string, []*store.Layer]
|
|
|
|
|
|
|
|
|
|
proxyCacheLock sync.RWMutex
|
|
|
|
|
layerCacheLock sync.RWMutex
|
|
|
|
|
|
|
|
|
|
handleError HandleErrorFunc
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -103,6 +107,26 @@ func (d *Director) getProxies(ctx context.Context) ([]*store.Proxy, error) {
|
|
|
|
|
return proxies, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
locked := d.proxyCacheLock.TryLock()
|
|
|
|
|
if !locked {
|
|
|
|
|
d.proxyCacheLock.RLock()
|
|
|
|
|
|
|
|
|
|
proxies, exists := d.proxyCache.Get(proxiesCacheKey)
|
|
|
|
|
if exists {
|
|
|
|
|
d.proxyCacheLock.RUnlock()
|
|
|
|
|
logger.Debug(ctx, "using cached proxies")
|
|
|
|
|
return proxies, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
d.proxyCacheLock.RUnlock()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if !locked {
|
|
|
|
|
d.proxyCacheLock.Lock()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
defer d.proxyCacheLock.Unlock()
|
|
|
|
|
|
|
|
|
|
logger.Debug(ctx, "querying fresh proxies")
|
|
|
|
|
|
|
|
|
|
headers, err := d.proxyRepository.QueryProxy(ctx, store.WithProxyQueryEnabled(true))
|
|
|
|
@ -141,6 +165,26 @@ func (d *Director) getLayers(ctx context.Context, proxyName store.ProxyName) ([]
|
|
|
|
|
return layers, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
locked := d.layerCacheLock.TryLock()
|
|
|
|
|
if !locked {
|
|
|
|
|
d.layerCacheLock.RLock()
|
|
|
|
|
|
|
|
|
|
layers, exists := d.layerCache.Get(cacheKey)
|
|
|
|
|
if exists {
|
|
|
|
|
d.layerCacheLock.RUnlock()
|
|
|
|
|
logger.Debug(ctx, "using cached layers")
|
|
|
|
|
return layers, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
d.layerCacheLock.RUnlock()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if !locked {
|
|
|
|
|
d.layerCacheLock.Lock()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
defer d.layerCacheLock.Unlock()
|
|
|
|
|
|
|
|
|
|
logger.Debug(ctx, "querying fresh layers")
|
|
|
|
|
|
|
|
|
|
headers, err := d.layerRepository.QueryLayers(ctx, proxyName, store.WithLayerQueryEnabled(true))
|
|
|
|
|