mirror of
https://github.com/tapframe/NuvioStreaming.git
synced 2026-08-05 19:11:11 +00:00
fix: handle torrent cache pressure on Android
This commit is contained in:
parent
d92b4d4c2e
commit
ad1b8b79c6
3 changed files with 77 additions and 9 deletions
Binary file not shown.
|
|
@ -89,4 +89,53 @@ class P2pStreamingEngineAndroidTest {
|
|||
),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun globalCachePressureDoesNotBecomeTerminalError() {
|
||||
assertNull(
|
||||
unexpectedTorrentError(
|
||||
requestId = 0L,
|
||||
eventTorrentId = null,
|
||||
currentTorrentId = "torrent",
|
||||
message = "disk cache budget is exceeded by protected torrent data",
|
||||
fallbackMessage = "unknown",
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun matchingUnsolicitedTorrentFailureBecomesTerminalError() {
|
||||
assertEquals(
|
||||
P2pStreamingState.Error("file write failed"),
|
||||
unexpectedTorrentError(
|
||||
requestId = 0L,
|
||||
eventTorrentId = "torrent",
|
||||
currentTorrentId = "torrent",
|
||||
message = "file write failed",
|
||||
fallbackMessage = "unknown",
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun commandAndStaleTorrentFailuresAreIgnored() {
|
||||
assertNull(
|
||||
unexpectedTorrentError(
|
||||
requestId = 9L,
|
||||
eventTorrentId = "torrent",
|
||||
currentTorrentId = "torrent",
|
||||
message = "failed",
|
||||
fallbackMessage = "unknown",
|
||||
)
|
||||
)
|
||||
assertNull(
|
||||
unexpectedTorrentError(
|
||||
requestId = 0L,
|
||||
eventTorrentId = "old-torrent",
|
||||
currentTorrentId = "torrent",
|
||||
message = "failed",
|
||||
fallbackMessage = "unknown",
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,6 +73,25 @@ internal fun unexpectedStreamStopError(
|
|||
)
|
||||
}
|
||||
|
||||
internal fun unexpectedTorrentError(
|
||||
requestId: Long,
|
||||
eventTorrentId: String?,
|
||||
currentTorrentId: String?,
|
||||
message: String?,
|
||||
fallbackMessage: String,
|
||||
): P2pStreamingState.Error? {
|
||||
if (requestId != 0L ||
|
||||
eventTorrentId == null ||
|
||||
currentTorrentId == null ||
|
||||
eventTorrentId != currentTorrentId
|
||||
) {
|
||||
return null
|
||||
}
|
||||
return P2pStreamingState.Error(
|
||||
message?.trim()?.takeIf(String::isNotEmpty) ?: fallbackMessage,
|
||||
)
|
||||
}
|
||||
|
||||
actual object P2pStreamingEngine {
|
||||
private data class EngineConfigurationKey(
|
||||
val uploadEnabled: Boolean,
|
||||
|
|
@ -517,16 +536,16 @@ actual object P2pStreamingEngine {
|
|||
if (engine !== activeEngine) return@collect
|
||||
when (event.type) {
|
||||
NuvioEventType.TorrentError -> {
|
||||
if (event.requestId != 0L) return@collect
|
||||
val terminalError = P2pStreamingState.Error(
|
||||
event.message ?: localizedP2pUnknownTorrentError()
|
||||
)
|
||||
val fallbackMessage = localizedP2pUnknownTorrentError()
|
||||
synchronized(lifecycleLock) {
|
||||
if (engine !== activeEngine ||
|
||||
(event.torrentId != null && event.torrentId != currentTorrentId)
|
||||
) {
|
||||
return@synchronized
|
||||
}
|
||||
if (engine !== activeEngine) return@synchronized
|
||||
val terminalError = unexpectedTorrentError(
|
||||
requestId = event.requestId,
|
||||
eventTorrentId = event.torrentId,
|
||||
currentTorrentId = currentTorrentId,
|
||||
message = event.message,
|
||||
fallbackMessage = fallbackMessage,
|
||||
) ?: return@synchronized
|
||||
streamGeneration += 1
|
||||
statsJob?.cancel()
|
||||
statsJob = null
|
||||
|
|
|
|||
Loading…
Reference in a new issue