mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-28 20:45:17 +00:00
fix: 404s causing snode errors and trying to retrieve avatars that have already 404'd a lot
This commit is contained in:
parent
c741ec5093
commit
6c70b38ab1
@ -17,12 +17,13 @@ import java.io.FileInputStream
|
|||||||
import java.io.FileOutputStream
|
import java.io.FileOutputStream
|
||||||
import java.io.InputStream
|
import java.io.InputStream
|
||||||
import java.security.SecureRandom
|
import java.security.SecureRandom
|
||||||
|
import java.util.concurrent.ConcurrentSkipListSet
|
||||||
|
|
||||||
class RetrieveProfileAvatarJob(private val profileAvatar: String?, val recipientAddress: Address): Job {
|
class RetrieveProfileAvatarJob(private val profileAvatar: String?, val recipientAddress: Address): Job {
|
||||||
override var delegate: JobDelegate? = null
|
override var delegate: JobDelegate? = null
|
||||||
override var id: String? = null
|
override var id: String? = null
|
||||||
override var failureCount: Int = 0
|
override var failureCount: Int = 0
|
||||||
override val maxFailureCount: Int = 0
|
override val maxFailureCount: Int = 3
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val TAG = RetrieveProfileAvatarJob::class.simpleName
|
val TAG = RetrieveProfileAvatarJob::class.simpleName
|
||||||
@ -31,10 +32,14 @@ class RetrieveProfileAvatarJob(private val profileAvatar: String?, val recipient
|
|||||||
// Keys used for database storage
|
// Keys used for database storage
|
||||||
private const val PROFILE_AVATAR_KEY = "profileAvatar"
|
private const val PROFILE_AVATAR_KEY = "profileAvatar"
|
||||||
private const val RECEIPIENT_ADDRESS_KEY = "recipient"
|
private const val RECEIPIENT_ADDRESS_KEY = "recipient"
|
||||||
|
|
||||||
|
val errorUrls = ConcurrentSkipListSet<String>()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun execute(dispatcherName: String) {
|
override suspend fun execute(dispatcherName: String) {
|
||||||
val delegate = delegate ?: return
|
val delegate = delegate ?: return
|
||||||
|
if (profileAvatar in errorUrls) return delegate.handleJobFailed(this, dispatcherName, Exception("Profile URL 404'd this app instance"))
|
||||||
val context = MessagingModuleConfiguration.shared.context
|
val context = MessagingModuleConfiguration.shared.context
|
||||||
val storage = MessagingModuleConfiguration.shared.storage
|
val storage = MessagingModuleConfiguration.shared.storage
|
||||||
val recipient = Recipient.from(context, recipientAddress, true)
|
val recipient = Recipient.from(context, recipientAddress, true)
|
||||||
@ -85,7 +90,10 @@ class RetrieveProfileAvatarJob(private val profileAvatar: String?, val recipient
|
|||||||
storage.setProfileAvatar(recipient, profileAvatar)
|
storage.setProfileAvatar(recipient, profileAvatar)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.e("Loki", "Failed to download profile avatar", e)
|
Log.e("Loki", "Failed to download profile avatar", e)
|
||||||
return delegate.handleJobFailedPermanently(this, dispatcherName, e)
|
if (failureCount + 1 >= maxFailureCount) {
|
||||||
|
errorUrls += profileAvatar
|
||||||
|
}
|
||||||
|
return delegate.handleJobFailed(this, dispatcherName, e)
|
||||||
} finally {
|
} finally {
|
||||||
downloadDestination.delete()
|
downloadDestination.delete()
|
||||||
}
|
}
|
||||||
|
@ -419,6 +419,8 @@ object OnionRequestAPI {
|
|||||||
Log.d("Loki","Destination server returned ${exception.statusCode}")
|
Log.d("Loki","Destination server returned ${exception.statusCode}")
|
||||||
} else if (message == "Loki Server error") {
|
} else if (message == "Loki Server error") {
|
||||||
Log.d("Loki", "message was $message")
|
Log.d("Loki", "message was $message")
|
||||||
|
} else if (exception.statusCode == 404) {
|
||||||
|
// 404 is probably file server missing a file, don't rebuild path or mark a snode as bad here
|
||||||
} else { // Only drop snode/path if not receiving above two exception cases
|
} else { // Only drop snode/path if not receiving above two exception cases
|
||||||
handleUnspecificError()
|
handleUnspecificError()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user