-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
120 lines (96 loc) · 3.42 KB
/
types.go
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
Copyright 2017 Luke Granger-Brown
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package ngdp
import "crypto/md5"
type hash [md5.Size]byte
// Equal checks two hashes for equality.
func (h hash) Equal(o hash) bool {
for n := 0; n < md5.Size; n++ {
if h[n] != o[n] {
return false
}
}
return true
}
// Less checks if a given hash is less than another.
func (h hash) Less(o hash) bool {
for n := 0; n < md5.Size; n++ {
if h[n] < o[n] {
return true
}
if h[n] > o[n] {
return false
}
}
return false
}
// A CDNHash is usually an MD5 hash of the BLTE header of a data file. Blizzard uses these to generate filenames for storage on the CDN.
type CDNHash hash
func (h CDNHash) Equal(o CDNHash) bool { return hash(h).Equal(hash(o)) }
func (h CDNHash) Less(o CDNHash) bool { return hash(h).Less(hash(o)) }
// A ContentHash is an MD5 hash of the raw contents of a file, before it is BLTE-encoded. These must be looked up in the encoding table to get a CDNHash before files can be downloaded.
type ContentHash hash
func (h ContentHash) Equal(o ContentHash) bool { return hash(h).Equal(hash(o)) }
func (h ContentHash) Less(o ContentHash) bool { return hash(h).Less(hash(o)) }
// A CDNInfo contains information on which CDNs hold data for which regions, as well as what path the data is stored under.
type CDNInfo struct {
Name Region
Path string
Hosts []string
ConfigPath string // unknown purpose
}
// A VersionInfo lists the current build and CDN config CDNHashes.
type VersionInfo struct {
Region Region
BuildConfig CDNHash
CDNConfig CDNHash
BuildID int `configtable:"BuildId"`
VersionsName string
ProductConfig CDNHash
}
// A BuildConfigEncoding contains the content and CDN hashes of an encoding file.
type BuildConfigEncoding struct {
ContentHash ContentHash
CDNHash CDNHash
}
// A BuildConfigEncodingSize contains the BLTE-encoded and raw sizes of the encoding file.
type BuildConfigEncodingSize struct {
UncompressedSize uint64
CompressedSize uint64
}
// A BuildConfig contains information on the current root, install, and download files, as well as the encoding file, and the currently available patch.
type BuildConfig struct {
Root ContentHash
Install ContentHash
InstallSize uint64
Download ContentHash
DownloadSize uint64
Encoding BuildConfigEncoding
EncodingSize BuildConfigEncodingSize
Patch ContentHash
PatchSize uint64
PatchConfig CDNHash
}
// A CDNConfig contains information on the archives, which are used to bundle smaller files together on the CDN.
type CDNConfig struct {
Archives []CDNHash
ArchiveGroup CDNHash
PatchArchives []CDNHash
PatchArchiveGroup CDNHash
}
// A FilenameMapper represents a way for mapping filenames to content hashes.
//
// This might be implemented by a listfile, or MNDX, or any of the myriad other ways Blizzard has deigned to refer to files.
type FilenameMapper interface {
ToContentHash(fn string) (h ContentHash, ok bool)
}