Skip to content

Commit

Permalink
Additional logging around incrementally digested uploads.
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholas-signal authored and cody-signal committed Aug 22, 2023
1 parent afd3afc commit e861204
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.whispersystems.signalservice.internal.push.http
import okhttp3.MediaType
import okhttp3.RequestBody
import okio.BufferedSink
import org.signal.libsignal.protocol.logging.Log
import org.whispersystems.signalservice.api.crypto.DigestingOutputStream
import org.whispersystems.signalservice.api.crypto.SkippingOutputStream
import org.whispersystems.signalservice.api.messages.SignalServiceAttachment
Expand Down Expand Up @@ -62,7 +63,13 @@ class DigestingRequestBody(
}

outputStream.flush()

if (isIncremental) {
if (contentLength != total) {
Log.w(TAG, "Content uploaded ${logMessage(total, contentLength)} bytes compared to expected!")
} else {
Log.d(TAG, "Wrote the expected number of bytes.")
}
outputStream.close()
digestStream.close()
incrementalDigest = digestStream.toByteArray()
Expand All @@ -76,6 +83,15 @@ class DigestingRequestBody(

fun getAttachmentDigest() = AttachmentDigest(transmittedDigest, incrementalDigest)

private fun logMessage(actual: Long, expected: Long): String {
val difference = actual - expected
return if (difference > 0) {
"+$difference"
} else {
difference.toString()
}
}

companion object {
const val TAG = "DigestingRequestBody"
}
Expand Down

0 comments on commit e861204

Please sign in to comment.