Check entries but do not remove if they fail
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
f71e19aec4
commit
6730dd54b1
|
@ -210,7 +210,7 @@ func handle(ctx *httputils.RequestContext) {
|
|||
continue
|
||||
}
|
||||
|
||||
result := c.CheckEntryKey(key, privateKey)
|
||||
result, err := c.CheckEntryKey(key, privateKey)
|
||||
if result != nil {
|
||||
if e == nil {
|
||||
e = &content.Entry{
|
||||
|
@ -220,7 +220,7 @@ func handle(ctx *httputils.RequestContext) {
|
|||
CheckTime: time.Now().UTC().Unix() + 3600*24*3, // Check sooner after addition, not all servers might have it yet
|
||||
}
|
||||
}
|
||||
} else {
|
||||
} else if err == nil {
|
||||
newInvalidList = append(newInvalidList, c.Index)
|
||||
}
|
||||
}
|
||||
|
@ -277,7 +277,9 @@ func getContentEntry(key *content.HashIdentifier) *content.Entry {
|
|||
}
|
||||
continue
|
||||
}
|
||||
if c.CheckEntryKey(&e.Key, privateKey) == nil {
|
||||
|
||||
h, err := c.CheckEntryKey(&e.Key, privateKey)
|
||||
if h == nil && err == nil {
|
||||
newInvalidList = append(newInvalidList, c.Index)
|
||||
}
|
||||
}
|
||||
|
@ -366,7 +368,7 @@ func main() {
|
|||
|
||||
go func() {
|
||||
ticker := time.NewTicker(1 * time.Minute)
|
||||
for _ = range ticker.C {
|
||||
for range ticker.C {
|
||||
checkContentServers()
|
||||
}
|
||||
}()
|
||||
|
|
|
@ -97,7 +97,7 @@ func (s *Server) Check() {
|
|||
s.setCheckResult(true)
|
||||
}
|
||||
|
||||
func (s *Server) CheckEntryKey(key *HashIdentifier, privateKey ed25519.PrivateKey) *HashIdentifier {
|
||||
func (s *Server) CheckEntryKey(key *HashIdentifier, privateKey ed25519.PrivateKey) (*HashIdentifier, error) {
|
||||
customTransport := http.DefaultTransport.(*http.Transport).Clone()
|
||||
customTransport.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
|
||||
client := &http.Client{
|
||||
|
@ -107,27 +107,31 @@ func (s *Server) CheckEntryKey(key *HashIdentifier, privateKey ed25519.PrivateKe
|
|||
response, err := client.Head(s.GetHashURL(key.Hash(), privateKey, []int{}))
|
||||
|
||||
if err != nil {
|
||||
return nil
|
||||
return nil, err
|
||||
}
|
||||
|
||||
defer response.Body.Close()
|
||||
|
||||
if response.StatusCode == http.StatusNotFound {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
if response.StatusCode != http.StatusOK {
|
||||
return nil
|
||||
return nil, fmt.Errorf("unexpected status code %d", response.StatusCode)
|
||||
}
|
||||
|
||||
v := strings.Split(response.Header.Get("Digest"), "=")
|
||||
if len(v) >= 2 && v[0] == "sha-256" {
|
||||
sha, err := base64.StdEncoding.DecodeString(strings.Join(v[1:], "="))
|
||||
if err != nil {
|
||||
return nil
|
||||
return nil, nil
|
||||
}
|
||||
mh, err := multihash.Encode(sha, multihash.SHA2_256)
|
||||
if err != nil {
|
||||
return nil
|
||||
return nil, nil
|
||||
}
|
||||
return NewHashIdentifierFromMultihash(mh)
|
||||
return NewHashIdentifierFromMultihash(mh), nil
|
||||
}
|
||||
|
||||
return nil
|
||||
return nil, nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue