Check entries but do not remove if they fail
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
DataHoarder 2022-01-20 10:38:20 +01:00
parent f71e19aec4
commit 6730dd54b1
2 changed files with 17 additions and 11 deletions

View file

@ -210,7 +210,7 @@ func handle(ctx *httputils.RequestContext) {
continue continue
} }
result := c.CheckEntryKey(key, privateKey) result, err := c.CheckEntryKey(key, privateKey)
if result != nil { if result != nil {
if e == nil { if e == nil {
e = &content.Entry{ 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 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) newInvalidList = append(newInvalidList, c.Index)
} }
} }
@ -277,7 +277,9 @@ func getContentEntry(key *content.HashIdentifier) *content.Entry {
} }
continue 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) newInvalidList = append(newInvalidList, c.Index)
} }
} }
@ -366,7 +368,7 @@ func main() {
go func() { go func() {
ticker := time.NewTicker(1 * time.Minute) ticker := time.NewTicker(1 * time.Minute)
for _ = range ticker.C { for range ticker.C {
checkContentServers() checkContentServers()
} }
}() }()

View file

@ -97,7 +97,7 @@ func (s *Server) Check() {
s.setCheckResult(true) 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 := http.DefaultTransport.(*http.Transport).Clone()
customTransport.TLSClientConfig = &tls.Config{InsecureSkipVerify: true} customTransport.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
client := &http.Client{ 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{})) response, err := client.Head(s.GetHashURL(key.Hash(), privateKey, []int{}))
if err != nil { if err != nil {
return nil return nil, err
} }
defer response.Body.Close() defer response.Body.Close()
if response.StatusCode == http.StatusNotFound {
return nil, nil
}
if response.StatusCode != http.StatusOK { if response.StatusCode != http.StatusOK {
return nil return nil, fmt.Errorf("unexpected status code %d", response.StatusCode)
} }
v := strings.Split(response.Header.Get("Digest"), "=") v := strings.Split(response.Header.Get("Digest"), "=")
if len(v) >= 2 && v[0] == "sha-256" { if len(v) >= 2 && v[0] == "sha-256" {
sha, err := base64.StdEncoding.DecodeString(strings.Join(v[1:], "=")) sha, err := base64.StdEncoding.DecodeString(strings.Join(v[1:], "="))
if err != nil { if err != nil {
return nil return nil, nil
} }
mh, err := multihash.Encode(sha, multihash.SHA2_256) mh, err := multihash.Encode(sha, multihash.SHA2_256)
if err != nil { if err != nil {
return nil return nil, nil
} }
return NewHashIdentifierFromMultihash(mh) return NewHashIdentifierFromMultihash(mh), nil
} }
return nil return nil, nil
} }