Modern Apps git

← Modern-Apps.git

youpipe: fix SABR playback — add attestation retry coordinator (re-mint PO token on rejection) around session.requestOnce for init + pump + downloads (matches PipePipeClient SabrRequestCoordinator/AttestationRetryHandler)

Commit
e9fa0f677974562abd021f305ef078b453b71a52
Author
vayun-mathur <[email protected]>
When
2026-08-16 20:12 UTC (3 months ago)
Parents
ef3f357

Diff

youpipe/src/main/java/com/vayunmathur/youpipe/util/PlaybackService.kt
diff --git a/youpipe/src/main/java/com/vayunmathur/youpipe/util/PlaybackService.kt b/youpipe/src/main/java/com/vayunmathur/youpipe/util/PlaybackService.ktindex bf409bad1b..9a96a03617 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/util/PlaybackService.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/util/PlaybackService.kt@@ -24,7 +24,6 @@ import com.vayunmathur.youpipe.util.sabr.LocalDomPoTokenProvider import com.vayunmathur.youpipe.util.sabr.SabrNgDashMediaSource import com.vayunmathur.youpipe.util.sabr.SabrNgSessionStore import org.schabi.newpipe.extractor.localization.Localization-import org.schabi.newpipe.extractor.services.youtube.sabrng.YoutubeSabrInfo import org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.isAndroidStreamingUrl import org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.isIosStreamingUrl import org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.isVisionOsStreamingUrl@@ -119,26 +118,19 @@ class PlaybackService : MediaSessionService() {                     val sabrSource = run {                         val vAudioItag = audioItag                         val vAudioTrackId = audioTrackIdOverride+                        val tokenMinter: (Boolean) -> ByteArray? = { force ->+                            provider.getPoTokenBytes(videoId, info.getVisitorData(), force)+                        }                         val specSupplier: () -> com.vayunmathur.youpipe.util.sabr.SabrNgSourceSpec = {-                            val poToken = provider.getPoTokenBytes(videoId, info.getVisitorData())+                            val poToken = tokenMinter(false)                             SabrNgSessionStore.createSourceSpec(                                 videoId, vitag, vAudioItag, vAudioTrackId, info, poToken,-                                localization-                            )-                        }-                        val onAttestationFailure: () -> YoutubeSabrInfo? = {-                            val fresh = provider.getPoTokenBytes(-                                videoId, info.getVisitorData(), true-                            )-                            YoutubeSabrInfo(-                                info.getVideoId(), info.getCpn(), info.getClientVersion(),-                                info.getVisitorData(), info.getServerAbrStreamingUrl(),-                                info.getVideoPlaybackUstreamerConfig(), info.getFormats(), fresh+                                localization, tokenMinter                             )                         }                         SabrNgDashMediaSource(                             this@PlaybackService, mediaItem, videoId, specSupplier,-                            onAttestationFailure+                            tokenMinter                         )                     }                     return if (subtitleSources.isNotEmpty()) {
youpipe/src/main/java/com/vayunmathur/youpipe/util/sabr/SabrAttestationRetryHandler.kt
diff --git a/youpipe/src/main/java/com/vayunmathur/youpipe/util/sabr/SabrAttestationRetryHandler.kt b/youpipe/src/main/java/com/vayunmathur/youpipe/util/sabr/SabrAttestationRetryHandler.ktnew file mode 100644index 0000000000..4ca525b689--- /dev/null+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/util/sabr/SabrAttestationRetryHandler.kt@@ -0,0 +1,62 @@+package com.vayunmathur.youpipe.util.sabr++import org.schabi.newpipe.extractor.services.youtube.sabrng.YoutubeSabrSession+import org.schabi.newpipe.extractor.services.youtube.sabrng.exception.SabrAttestationException++/**+ * Maintains the PO-token recovery budget for one SABR media acquisition. On a rejected attestation+ * identity it mints a fresh PO token and injects it into the session, mirroring PipePipe's+ * `SabrAttestationRetryHandler` (the #92 "rotate rejected SABR attestation identities" fix).+ */+internal class SabrAttestationRetryHandler(+    private val videoId: String,+    private val tokenMinter: ((Boolean) -> ByteArray?)?+) {+    private var retriesRemaining = MAX_RETRIES++    @Synchronized+    @Throws(SabrAttestationException::class)+    fun prepareRetry(session: YoutubeSabrSession, rejectedTokenError: SabrAttestationException) {+        if (retriesRemaining == 0) {+            throw SabrAttestationException(+                "SABR PO token was rejected after $MAX_RETRIES attestation recovery retries " ++                    "for video=$videoId",+                rejectedTokenError+            )+        }+        val minter = tokenMinter+            ?: throw SabrAttestationException(+                "SABR attestation failed and no PO token minter is available for video=$videoId",+                rejectedTokenError+            )+        val retryNumber = MAX_RETRIES - retriesRemaining + 1+        retriesRemaining--+        val token = try {+            minter(true)+        } catch (error: Exception) {+            throw SabrAttestationException(+                "SABR PO token recovery failed on retry $retryNumber of $MAX_RETRIES " ++                    "for video=$videoId: ${error.message}",+                error+            )+        }+        if (token == null || token.isEmpty()) {+            throw SabrAttestationException(+                "SABR PO token recovery returned no token on retry $retryNumber of $MAX_RETRIES " ++                    "for video=$videoId",+                rejectedTokenError+            )+        }+        session.setPoToken(token)+    }++    /** A media payload proves the current token is usable and restores a fresh budget. */+    @Synchronized+    fun onMediaReceived() {+        retriesRemaining = MAX_RETRIES+    }++    private companion object {+        private const val MAX_RETRIES = 3+    }+}
youpipe/src/main/java/com/vayunmathur/youpipe/util/sabr/SabrNgDashMediaSource.kt
diff --git a/youpipe/src/main/java/com/vayunmathur/youpipe/util/sabr/SabrNgDashMediaSource.kt b/youpipe/src/main/java/com/vayunmathur/youpipe/util/sabr/SabrNgDashMediaSource.ktindex e4f7113719..efb83edd88 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/util/sabr/SabrNgDashMediaSource.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/util/sabr/SabrNgDashMediaSource.kt@@ -50,7 +50,7 @@ class SabrNgDashMediaSource(     private val mediaItem: MediaItem,     private val videoId: String,     private val specSupplier: () -> SabrNgSourceSpec,-    private val onAttestationFailure: (() -> YoutubeSabrInfo?)? = null+    private val tokenMinter: ((Boolean) -> ByteArray?)? = null ) : CompositeMediaSource<Int>() {      private val appContext: Context = context.applicationContext@@ -90,7 +90,7 @@ class SabrNgDashMediaSource(             // Heavy, off-main: mint the PO token (WebView/DOM JS) and fetch init segments.             val spec = specSupplier()             val spoolDir = File(appContext.cacheDir, "sabrng").apply { mkdirs() }-            val builtSession = SabrNgSession(spec, spoolDir, onAttestationFailure)+            val builtSession = SabrNgSession(spec, spoolDir, tokenMinter)             val durationMs = spec.getDurationMs()             val dataSourceFactory = DataSource.Factory {                 SabrNgSegmentDataSource(builtSession, SEGMENT_TIMEOUT_MS)
youpipe/src/main/java/com/vayunmathur/youpipe/util/sabr/SabrNgDownloadHelper.kt
diff --git a/youpipe/src/main/java/com/vayunmathur/youpipe/util/sabr/SabrNgDownloadHelper.kt b/youpipe/src/main/java/com/vayunmathur/youpipe/util/sabr/SabrNgDownloadHelper.ktindex c812f970f8..43de3f20e0 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/util/sabr/SabrNgDownloadHelper.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/util/sabr/SabrNgDownloadHelper.kt@@ -35,15 +35,19 @@ internal object SabrNgDownloadHelper {         if (!workDir.exists() && !workDir.mkdirs()) {             throw IOException("Could not create SABR download directory: $workDir")         }-        val poToken = LocalDomPoTokenProvider.shared(context.applicationContext)-            .getPoTokenBytes(videoId, info.getVisitorData())+        val provider = LocalDomPoTokenProvider.shared(context.applicationContext)+        val tokenMinter: (Boolean) -> ByteArray? = { force ->+            provider.getPoTokenBytes(videoId, info.getVisitorData(), force)+        }+        val poToken = tokenMinter(false)         val spec = SabrNgSessionStore.createSourceSpec(-            videoId, videoItag, audioItag, audioTrackId, info, poToken, DOWNLOAD_LOCALIZATION+            videoId, videoItag, audioItag, audioTrackId, info, poToken, DOWNLOAD_LOCALIZATION,+            tokenMinter         )         val audioFile = File(workDir, "sabr-audio-$videoId-${spec.audioFormat.getItag()}.media")         val videoFile = File(workDir, "sabr-video-$videoId-${spec.videoFormat.getItag()}.media")         val spoolDir = File(workDir, "spool").apply { mkdirs() }-        val session = SabrNgSession(spec, spoolDir, onAttestationFailure = null)+        val session = SabrNgSession(spec, spoolDir, tokenMinter)          val totalSegments =             (spec.audioTimeline.getEndSequence() + spec.videoTimeline.getEndSequence())
youpipe/src/main/java/com/vayunmathur/youpipe/util/sabr/SabrNgSession.kt
diff --git a/youpipe/src/main/java/com/vayunmathur/youpipe/util/sabr/SabrNgSession.kt b/youpipe/src/main/java/com/vayunmathur/youpipe/util/sabr/SabrNgSession.ktindex 3c0a7277e7..1860919b7d 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/util/sabr/SabrNgSession.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/util/sabr/SabrNgSession.kt@@ -1,11 +1,9 @@ package com.vayunmathur.youpipe.util.sabr -import android.util.Log+import org.schabi.newpipe.extractor.exceptions.ExtractionException import org.schabi.newpipe.extractor.services.youtube.sabrng.YoutubeSabrInfo import org.schabi.newpipe.extractor.services.youtube.sabrng.YoutubeSabrRequest import org.schabi.newpipe.extractor.services.youtube.sabrng.YoutubeSabrSession-import org.schabi.newpipe.extractor.services.youtube.sabrng.exception.SabrAttestationException-import org.schabi.newpipe.extractor.services.youtube.sabrng.exception.SabrProtocolException import org.schabi.newpipe.extractor.services.youtube.sabrng.media.SabrMediaSegment import org.schabi.newpipe.extractor.services.youtube.sabrng.protocol.SabrStreamingResponseReader import java.io.File@@ -14,19 +12,20 @@ import java.util.concurrent.ConcurrentHashMap  /**  * Drives a session-based ([YoutubeSabrSession]) SABR stream for media3 playback: a background pump- * repeatedly issues `requestOnce` around the current playhead, caches emitted [SabrMediaSegment]s by- * (itag, sequence), honors server backoff, and rotates identity on attestation failure via the- * supplied [onAttestationFailure] hook. Segments are served to the media3 data source through the- * blocking [getMediaSegment].+ * repeatedly issues requests (through [SabrRequestCoordinator], which retries the attestation+ * handshake by re-minting the PO token via [tokenMinter] and honors server backoff) around the+ * current playhead, caches emitted [SabrMediaSegment]s by (itag, sequence), and serves them to the+ * media3 data source through the blocking [getMediaSegment].  */ class SabrNgSession(     private val spec: SabrNgSourceSpec,     spoolDirectory: File?,-    private val onAttestationFailure: (() -> YoutubeSabrInfo?)? = null+    tokenMinter: ((Boolean) -> ByteArray?)? = null ) {-    @Volatile-    private var session: YoutubeSabrSession = newSession(spec.info, spoolDirectory, spec.poToken)-    private val spoolDirectory: File? = spoolDirectory+    private val session: YoutubeSabrSession = newSession(spec.info, spoolDirectory, spec.poToken)+    private val coordinator = SabrRequestCoordinator(+        session, SabrAttestationRetryHandler(spec.videoId, tokenMinter), null+    )      private val mediaCache = ConcurrentHashMap<Long, SabrMediaSegment>()     private val initCache = ConcurrentHashMap<Int, SabrMediaSegment>()@@ -141,11 +140,6 @@ class SabrNgSession(     private fun pumpLoop() {         val consumer = SabrStreamingResponseReader.SegmentConsumer { segment -> onSegment(segment) }         while (running) {-            val backoffMs = session.getBackoffRemainingMs()-            if (backoffMs > 0) {-                sleepQuietly(minOf(backoffMs, 500L))-                continue-            }             if (isFullyBuffered()) {                 sleepQuietly(200L)                 continue@@ -163,18 +157,13 @@ class SabrNgSession(                 )             )             try {-                session.requestOnce(request, consumer)-            } catch (e: SabrAttestationException) {-                if (!rotateIdentity(e)) {-                    fail(IOException("SABR attestation failed", e))-                    return-                }-            } catch (e: SabrProtocolException) {-                fail(IOException("SABR protocol error", e))-                return+                coordinator.request(request, consumer)             } catch (e: IOException) {                 fail(e)                 return+            } catch (e: ExtractionException) {+                fail(IOException("SABR request failed", e))+                return             } catch (e: Exception) {                 fail(IOException("SABR request failed", e))                 return@@ -182,20 +171,6 @@ class SabrNgSession(         }     } -    private fun rotateIdentity(cause: SabrAttestationException): Boolean {-        val refetch = onAttestationFailure ?: return false-        return try {-            val refreshed = refetch() ?: return false-            val replacement = newSession(refreshed, spoolDirectory, refreshed.getPoToken())-            session = replacement-            Log.d(TAG, "rotated SABR identity for ${spec.videoId} after attestation failure")-            true-        } catch (e: Exception) {-            Log.d(TAG, "SABR identity rotation failed for ${spec.videoId}: $e", cause)-            false-        }-    }-     private fun onSegment(segment: SabrMediaSegment) {         val header = segment.getHeader()         val itag = header.getItag()@@ -244,8 +219,4 @@ class SabrNgSession(      private fun key(itag: Int, sequenceNumber: Int): Long =         (itag.toLong() shl 32) or (sequenceNumber.toLong() and 0xffffffffL)--    private companion object {-        private const val TAG = "SabrNgSession"-    } }
youpipe/src/main/java/com/vayunmathur/youpipe/util/sabr/SabrNgSessionStore.kt
diff --git a/youpipe/src/main/java/com/vayunmathur/youpipe/util/sabr/SabrNgSessionStore.kt b/youpipe/src/main/java/com/vayunmathur/youpipe/util/sabr/SabrNgSessionStore.ktindex 471a961eb1..026d279b57 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/util/sabr/SabrNgSessionStore.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/util/sabr/SabrNgSessionStore.kt@@ -1,7 +1,6 @@ package com.vayunmathur.youpipe.util.sabr  import android.util.Log-import org.schabi.newpipe.extractor.exceptions.ExtractionException import org.schabi.newpipe.extractor.localization.Localization import org.schabi.newpipe.extractor.services.youtube.sabrng.YoutubeSabrInfo import org.schabi.newpipe.extractor.services.youtube.sabrng.YoutubeSabrRequest@@ -24,8 +23,6 @@ import java.util.concurrent.ConcurrentHashMap  */ object SabrNgSessionStore {     private const val TAG = "SabrNgSessionStore"-    private const val MAX_INIT_ATTEMPTS = 8-    private const val INIT_BACKOFF_SLEEP_MS = 400L      private val extractorInfo = ConcurrentHashMap<String, YoutubeSabrInfo>() @@ -40,6 +37,7 @@ object SabrNgSessionStore {     }      @Throws(IOException::class)+    @JvmOverloads     fun createSourceSpec(         videoId: String,         preferredVideoItag: Int,@@ -47,7 +45,8 @@ object SabrNgSessionStore {         preferredAudioTrackId: String?,         info: YoutubeSabrInfo,         poToken: ByteArray?,-        localization: Localization+        localization: Localization,+        tokenMinter: ((Boolean) -> ByteArray?)? = null     ): SabrNgSourceSpec {         val videoFormat = selectVideoFormat(info, preferredVideoItag)             ?: throw IOException("No SABR video format for $videoId (itag=$preferredVideoItag)")@@ -55,7 +54,7 @@ object SabrNgSessionStore {             ?: throw IOException("No SABR audio format for $videoId (itag=$preferredAudioItag)")         val token = poToken ?: info.getPoToken() ?: ByteArray(0)         val initByItag = fetchInitializationSegments(-            videoId, info, listOf(audioFormat, videoFormat), token+            videoId, info, listOf(audioFormat, videoFormat), token, tokenMinter         )         val audioInit = initByItag[audioFormat.getItag()]             ?: throw IOException(@@ -81,7 +80,8 @@ object SabrNgSessionStore {         videoId: String,         info: YoutubeSabrInfo,         formats: List<YoutubeSabrInfo.Format>,-        token: ByteArray+        token: ByteArray,+        tokenMinter: ((Boolean) -> ByteArray?)?     ): Map<Int, ByteArray> {         val session = YoutubeSabrSession(info)         if (token.isNotEmpty()) {@@ -97,22 +97,19 @@ object SabrNgSessionStore {                 initByItag[header.getItag()] = segment.getData()             }         }-        var attempts = 0-        while (initByItag.size < formats.size && attempts < MAX_INIT_ATTEMPTS) {-            attempts++-            val backoffMs = session.getBackoffRemainingMs()-            if (backoffMs > 0) {-                sleepQuietly(minOf(backoffMs, INIT_BACKOFF_SLEEP_MS))-                continue-            }-            val request = YoutubeSabrRequest.preparation(0, formats)-            try {-                session.requestOnce(request, consumer)-            } catch (e: IOException) {-                throw e-            } catch (e: ExtractionException) {-                throw IOException("SABR initialization request failed for $videoId", e)-            }+        // A preparation transaction fetches the init segment (with its fragment index) for the+        // preferred formats. The coordinator loops requestOnce through the attestation handshake+        // (re-minting the PO token on rejection) and server backoff until both inits arrive.+        val coordinator = SabrRequestCoordinator(+            session, SabrAttestationRetryHandler(videoId, tokenMinter), null+        )+        val request = YoutubeSabrRequest.preparation(0, formats)+        try {+            coordinator.request(request, consumer) { initByItag.size >= formats.size }+        } catch (e: IOException) {+            throw e+        } catch (e: org.schabi.newpipe.extractor.exceptions.ExtractionException) {+            throw IOException("SABR initialization request failed for $videoId", e)         }         if (initByItag.size < formats.size) {             Log.w(@@ -123,14 +120,6 @@ object SabrNgSessionStore {         return initByItag     } -    private fun sleepQuietly(millis: Long) {-        try {-            Thread.sleep(millis)-        } catch (e: InterruptedException) {-            Thread.currentThread().interrupt()-        }-    }-     private fun selectVideoFormat(         info: YoutubeSabrInfo,         preferredItag: Int
youpipe/src/main/java/com/vayunmathur/youpipe/util/sabr/SabrRequestCoordinator.kt
diff --git a/youpipe/src/main/java/com/vayunmathur/youpipe/util/sabr/SabrRequestCoordinator.kt b/youpipe/src/main/java/com/vayunmathur/youpipe/util/sabr/SabrRequestCoordinator.ktnew file mode 100644index 0000000000..9fa8bf8e64--- /dev/null+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/util/sabr/SabrRequestCoordinator.kt@@ -0,0 +1,141 @@+package com.vayunmathur.youpipe.util.sabr++import org.schabi.newpipe.extractor.exceptions.ExtractionException+import org.schabi.newpipe.extractor.services.youtube.sabrng.YoutubeSabrRequest+import org.schabi.newpipe.extractor.services.youtube.sabrng.YoutubeSabrSession+import org.schabi.newpipe.extractor.services.youtube.sabrng.exception.SabrAttestationException+import org.schabi.newpipe.extractor.services.youtube.sabrng.protocol.SabrStreamingResponseReader+import java.io.IOException+import java.io.InterruptedIOException++/**+ * Coordinates protocol-level SABR request recovery: loops [YoutubeSabrSession.requestOnce] until it+ * makes progress, retrying attestation-rejected requests with a freshly minted PO token+ * ([SabrAttestationRetryHandler]) and honoring server backoff. Kotlin port of PipePipe's+ * `SabrRequestCoordinator`.+ */+internal class SabrRequestCoordinator(+    private val session: YoutubeSabrSession,+    private val attestationRetryHandler: SabrAttestationRetryHandler,+    backoffObserver: ((Long) -> Unit)?+) {+    private val backoffObserver: (Long) -> Unit = backoffObserver ?: {}+    private var backoffDeadlineNs: Long = 0+    private var noProgressDeadlineNs: Long = 0++    /**+     * Executes a logical request until it produces progress. [progressChecker] reports whether the+     * response advanced the caller's state; when null, any delivered media segment counts.+     */+    @Throws(IOException::class, ExtractionException::class)+    fun request(+        request: YoutubeSabrRequest,+        consumer: SabrStreamingResponseReader.SegmentConsumer,+        progressChecker: (() -> Boolean)? = null+    ): YoutubeSabrSession.RequestResult {+        while (true) {+            awaitBackoff()+            val result: YoutubeSabrSession.RequestResult = try {+                session.requestOnce(+                    request,+                    SabrStreamingResponseReader.SegmentConsumer { segment ->+                        attestationRetryHandler.onMediaReceived()+                        consumer.accept(segment)+                    }+                )+            } catch (error: SabrAttestationException) {+                attestationRetryHandler.prepareRetry(session, error)+                continue+            }++            val progress = progressChecker?.invoke() ?: (result.getSegmentCount() > 0)+            val backoffMs = result.getBackoffMs().toLong()+            backoffObserver(backoffMs)+            updateBackoffEpisode(progress, backoffMs)+            updateNoProgressEpisode(progress, backoffMs)+            if (progress) {+                return result+            }+            if (result.isDeferred()) {+                continue+            }+            sleep(EMPTY_RESPONSE_RETRY_MS)+        }+    }++    @Throws(IOException::class)+    private fun awaitBackoff() {+        while (true) {+            val remainingMs = session.getBackoffRemainingMs()+            backoffObserver(remainingMs)+            if (remainingMs <= 0) {+                return+            }+            throwIfBudgetExceeded(+                backoffDeadlineNs, remainingMs,+                "SABR continuous backoff exceeded ${MAX_CONTINUOUS_BACKOFF_MS}ms"+            )+            sleep(minOf(remainingMs, EMPTY_RESPONSE_RETRY_MS))+        }+    }++    @Throws(IOException::class)+    private fun updateBackoffEpisode(progress: Boolean, backoffMs: Long) {+        if (progress) {+            backoffDeadlineNs = 0+        }+        if (backoffMs <= 0) {+            return+        }+        if (backoffDeadlineNs == 0L) {+            backoffDeadlineNs = System.nanoTime() + MAX_CONTINUOUS_BACKOFF_MS * 1_000_000L+            return+        }+        throwIfBudgetExceeded(+            backoffDeadlineNs, backoffMs,+            "SABR continuous backoff exceeded ${MAX_CONTINUOUS_BACKOFF_MS}ms"+        )+    }++    @Throws(IOException::class)+    private fun updateNoProgressEpisode(progress: Boolean, backoffMs: Long) {+        if (progress) {+            noProgressDeadlineNs = 0+            return+        }+        if (noProgressDeadlineNs == 0L) {+            noProgressDeadlineNs = System.nanoTime() + MAX_CONTINUOUS_NO_PROGRESS_MS * 1_000_000L+            return+        }+        throwIfBudgetExceeded(+            noProgressDeadlineNs,+            if (backoffMs > 0) backoffMs else EMPTY_RESPONSE_RETRY_MS,+            "SABR continuous no-progress exceeded ${MAX_CONTINUOUS_NO_PROGRESS_MS}ms"+        )+    }++    private companion object {+        private const val EMPTY_RESPONSE_RETRY_MS = 250L+        private const val MAX_CONTINUOUS_BACKOFF_MS = 30_000L+        private const val MAX_CONTINUOUS_NO_PROGRESS_MS = 30_000L++        @Throws(IOException::class)+        private fun throwIfBudgetExceeded(deadlineNs: Long, waitMs: Long, message: String) {+            if (deadlineNs != 0L && waitMs * 1_000_000L > deadlineNs - System.nanoTime()) {+                throw IOException(message)+            }+        }++        @Throws(IOException::class)+        private fun sleep(milliseconds: Long) {+            try {+                Thread.sleep(milliseconds)+            } catch (error: InterruptedException) {+                Thread.currentThread().interrupt()+                val interrupted = InterruptedIOException("Interrupted during SABR request")+                interrupted.initCause(error)+                throw interrupted+            }+        }+    }+}