-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathglob.go
More file actions
80 lines (66 loc) · 2.08 KB
/
glob.go
File metadata and controls
80 lines (66 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package main
import (
"net/http"
"sync"
"time"
)
const (
cacheSuffix = ".cache"
cacheMetaSuffix = ".meta.json"
defaultShortCacheDir = "./shortCache/"
defaultLongCacheDir = "./longCache/"
defaultBytesSavedFilename = "saved.txt"
defaultListenAddr = "127.0.0.1:55555"
defaultUpstreamRate = time.Second
defaultUpstreamBurst = 1
defaultFetchTimeout = 2 * time.Minute
defaultMetricsInterval = time.Minute
cacheFormatVersion = 1
shortCacheDuration = time.Minute * 10
longCacheDuration = time.Hour * 24 * 30
//Prevent case of probable corrupted data
minCacheSize = 100
shortCacheCleanupInterval = time.Minute
longCacheCleanupInterval = time.Hour
savedBytesFlushInterval = 30 * time.Second
)
type safeInfo struct {
URL string
longTermCache bool
MinValidSize int
}
type cacheMetadata struct {
Version int `json:"version"`
Status int `json:"status"`
Headers http.Header `json:"headers,omitempty"`
ContentLength int64 `json:"content_length,omitempty"`
}
var (
shortCacheDir = defaultShortCacheDir
longCacheDir = defaultLongCacheDir
bytesSavedFilename = defaultBytesSavedFilename
listenAddr = defaultListenAddr
upstreamRate = defaultUpstreamRate
upstreamBurst = defaultUpstreamBurst
fetchTimeout = defaultFetchTimeout
metricsInterval = defaultMetricsInterval
cacheLocks = make(map[string]*cacheLockEntry)
cacheLocksMutex sync.Mutex
bytesSavedMutex sync.Mutex
bytesBandwidthSaved uint64
bytesBandwidthSavedDirty bool
safeURLs []safeInfo = []safeInfo{
//Factorio download
{URL: "factorio.com/get-download", MinValidSize: 1024 * 1024 * 50},
{URL: "factorio.com/download/sha256sums", MinValidSize: 1024 * 100},
//Mod download
{URL: "mods.factorio.com/download", longTermCache: true, MinValidSize: 1024 * 5},
//JSON data
{URL: "factorio.com/api/latest-releases", MinValidSize: 100},
{URL: "mods.factorio.com/api/mods", MinValidSize: 500},
}
)
type cacheLockEntry struct {
mu sync.Mutex
refs int
}