Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: corrupt data check #1946

Merged
merged 1 commit into from
Dec 22, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions client/daemon/peer/peertask_conductor.go
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,13 @@ func (pt *peerTaskConductor) updateMetadata(piecePacket *commonv1.PiecePacket) {
pt.SetContentLength(piecePacket.ContentLength)
pt.span.SetAttributes(config.AttributeTaskContentLength.Int64(piecePacket.ContentLength))
pt.Debugf("update content length: %d, dst peer %s", piecePacket.ContentLength, piecePacket.DstPid)
} else if piecePacket.ContentLength > -1 && piecePacket.ContentLength != pt.GetContentLength() {
// corrupt data check
reason := fmt.Sprintf("corrupt data - content length did not match, current: %d, from piece packet: %d",
pt.GetContentLength(), piecePacket.ContentLength)
pt.Errorf(reason)
pt.cancel(commonv1.Code_ClientError, reason)
return
}

if piecePacket.ExtendAttribute != nil && len(piecePacket.ExtendAttribute.Header) > 0 && pt.GetHeader() == nil {
Expand Down Expand Up @@ -1101,6 +1108,15 @@ func (pt *peerTaskConductor) isCompleted() bool {
return true
}

// corrupt data check and avoid hang for mismatch completed length
if pt.readyPieces.Settled() == pt.totalPiece.Load() {
msg := fmt.Sprintf("corrupt data - ready piece count %d seems finished, but completed length %d is not match with content length: %d",
pt.totalPiece.Load(), pt.completedLength.Load(), pt.GetContentLength())
pt.Errorf(msg)
pt.cancel(commonv1.Code_ClientError, msg)
return true
}

return false
}

Expand Down