satellite/metainfo: remove unused code
This change removed unused 'createRequests' struct. As far I remember it was used to help validating old metainfo beginObject/commitObject flow. Change-Id: I0f139b9934196d73f26eafa347ba5605722f3a55
This commit is contained in:
parent
76f4619a9c
commit
1adb497a71
@ -77,7 +77,6 @@ type Endpoint struct {
|
||||
projectUsage *accounting.Service
|
||||
projects console.Projects
|
||||
apiKeys APIKeys
|
||||
createRequests *createRequests
|
||||
satellite signing.Signer
|
||||
limiterCache *lrucache.ExpiringLRU
|
||||
encInlineSegmentSize int64 // max inline segment size + encryption overhead
|
||||
@ -117,7 +116,6 @@ func NewEndpoint(log *zap.Logger, metainfo *Service, deletePieces *piecedeletion
|
||||
apiKeys: apiKeys,
|
||||
projectUsage: projectUsage,
|
||||
projects: projects,
|
||||
createRequests: newCreateRequests(),
|
||||
satellite: satellite,
|
||||
limiterCache: lrucache.New(lrucache.Options{
|
||||
Capacity: config.RateLimiter.CacheCapacity,
|
||||
|
@ -8,7 +8,6 @@ import (
|
||||
"context"
|
||||
"crypto/subtle"
|
||||
"regexp"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/zeebo/errs"
|
||||
@ -25,102 +24,10 @@ import (
|
||||
"storj.io/storj/satellite/console/consoleauth"
|
||||
)
|
||||
|
||||
const (
|
||||
requestTTL = time.Hour * 4
|
||||
)
|
||||
|
||||
var (
|
||||
ipRegexp = regexp.MustCompile(`^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$`)
|
||||
)
|
||||
|
||||
// TTLItem keeps association between serial number and ttl.
|
||||
type TTLItem struct {
|
||||
serialNumber storj.SerialNumber
|
||||
ttl time.Time
|
||||
}
|
||||
|
||||
type createRequest struct {
|
||||
Expiration time.Time
|
||||
Redundancy *pb.RedundancyScheme
|
||||
|
||||
ttl time.Time
|
||||
}
|
||||
|
||||
type createRequests struct {
|
||||
mu sync.RWMutex
|
||||
// orders limit serial number used because with CreateSegment we don't have path yet
|
||||
entries map[storj.SerialNumber]*createRequest
|
||||
|
||||
muTTL sync.Mutex
|
||||
entriesTTL []*TTLItem
|
||||
}
|
||||
|
||||
func newCreateRequests() *createRequests {
|
||||
return &createRequests{
|
||||
entries: make(map[storj.SerialNumber]*createRequest),
|
||||
entriesTTL: make([]*TTLItem, 0),
|
||||
}
|
||||
}
|
||||
|
||||
func (requests *createRequests) Put(serialNumber storj.SerialNumber, createRequest *createRequest) {
|
||||
ttl := time.Now().Add(requestTTL)
|
||||
|
||||
go func() {
|
||||
requests.muTTL.Lock()
|
||||
requests.entriesTTL = append(requests.entriesTTL, &TTLItem{
|
||||
serialNumber: serialNumber,
|
||||
ttl: ttl,
|
||||
})
|
||||
requests.muTTL.Unlock()
|
||||
}()
|
||||
|
||||
createRequest.ttl = ttl
|
||||
requests.mu.Lock()
|
||||
requests.entries[serialNumber] = createRequest
|
||||
requests.mu.Unlock()
|
||||
|
||||
go requests.cleanup()
|
||||
}
|
||||
|
||||
func (requests *createRequests) Load(serialNumber storj.SerialNumber) (*createRequest, bool) {
|
||||
requests.mu.RLock()
|
||||
request, found := requests.entries[serialNumber]
|
||||
if request != nil && request.ttl.Before(time.Now()) {
|
||||
request = nil
|
||||
found = false
|
||||
}
|
||||
requests.mu.RUnlock()
|
||||
|
||||
return request, found
|
||||
}
|
||||
|
||||
func (requests *createRequests) Remove(serialNumber storj.SerialNumber) {
|
||||
requests.mu.Lock()
|
||||
delete(requests.entries, serialNumber)
|
||||
requests.mu.Unlock()
|
||||
}
|
||||
|
||||
func (requests *createRequests) cleanup() {
|
||||
requests.muTTL.Lock()
|
||||
now := time.Now()
|
||||
remove := make([]storj.SerialNumber, 0)
|
||||
newStart := 0
|
||||
for i, item := range requests.entriesTTL {
|
||||
if item.ttl.Before(now) {
|
||||
remove = append(remove, item.serialNumber)
|
||||
newStart = i + 1
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
requests.entriesTTL = requests.entriesTTL[newStart:]
|
||||
requests.muTTL.Unlock()
|
||||
|
||||
for _, serialNumber := range remove {
|
||||
requests.Remove(serialNumber)
|
||||
}
|
||||
}
|
||||
|
||||
func getAPIKey(ctx context.Context, header *pb.RequestHeader) (key *macaroon.APIKey, err error) {
|
||||
defer mon.Task()(&ctx)(&err)
|
||||
if header != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user