Cleanup errors handling around piece hash verification (#1382)
This commit is contained in:
parent
5fa7a4a7c6
commit
cce84c9914
@ -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
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user