Cleanup errors handling around piece hash verification (#1382)

This commit is contained in:
Michal Niewrzal 2019-03-04 15:29:35 +01:00 committed by GitHub
parent 5fa7a4a7c6
commit cce84c9914
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 9 deletions

View File

@ -163,13 +163,15 @@ func (ps *PieceStore) Put(ctx context.Context, id PieceID, data io.Reader, ttl t
}
err = writer.Close()
if err == ErrHashDoesNotMatch {
return nil, errs.Combine(err, ps.Delete(ctx, id, rba.PayerAllocation.SatelliteId))
}
if err != nil && err != io.EOF {
return nil, ClientError.New("failure during closing writer: %v", err)
}
err = writer.Verify()
if err != nil {
return nil, ClientError.Wrap(err)
}
return writer.storagenodeHash, nil
}

View File

@ -71,19 +71,24 @@ func (s *StreamWriter) Close() error {
return err
}
if err := auth.VerifyMsg(reply.SignedHash, s.signer.remoteID); err != nil {
s.storagenodeHash = reply.SignedHash
zap.S().Debugf("Stream close and recv summary: %s, %d", reply.Message, reply.TotalReceived)
return nil
}
// Verify storage node signed hash
func (s *StreamWriter) Verify() error {
if err := auth.VerifyMsg(s.storagenodeHash, s.signer.remoteID); err != nil {
return ClientError.Wrap(err)
}
clientHash := s.hash.Sum(nil)
if bytes.Compare(reply.SignedHash.Hash, clientHash) != 0 {
if bytes.Compare(s.storagenodeHash.Hash, clientHash) != 0 {
return ErrHashDoesNotMatch
}
s.storagenodeHash = reply.SignedHash
zap.S().Debugf("Stream close and recv summary: %s, %d", reply.Message, reply.TotalReceived)
return nil
}