mirror of
https://github.com/oxen-io/session-android.git
synced 2025-01-11 22:53:39 +00:00
fix: uninitialized exception for lateinit guardSnode in certain cases, replace with a nullable version for error handling (#926)
This commit is contained in:
parent
d3e2ef0b40
commit
2ea7f638d8
@ -308,10 +308,11 @@ object OnionRequestAPI {
|
|||||||
*/
|
*/
|
||||||
private fun sendOnionRequest(destination: Destination, payload: Map<*, *>): Promise<Map<*, *>, Exception> {
|
private fun sendOnionRequest(destination: Destination, payload: Map<*, *>): Promise<Map<*, *>, Exception> {
|
||||||
val deferred = deferred<Map<*, *>, Exception>()
|
val deferred = deferred<Map<*, *>, Exception>()
|
||||||
lateinit var guardSnode: Snode
|
var guardSnode: Snode? = null
|
||||||
buildOnionForDestination(payload, destination).success { result ->
|
buildOnionForDestination(payload, destination).success { result ->
|
||||||
guardSnode = result.guardSnode
|
guardSnode = result.guardSnode
|
||||||
val url = "${guardSnode.address}:${guardSnode.port}/onion_req/v2"
|
val nonNullGuardSnode = result.guardSnode
|
||||||
|
val url = "${nonNullGuardSnode.address}:${nonNullGuardSnode.port}/onion_req/v2"
|
||||||
val finalEncryptionResult = result.finalEncryptionResult
|
val finalEncryptionResult = result.finalEncryptionResult
|
||||||
val onion = finalEncryptionResult.ciphertext
|
val onion = finalEncryptionResult.ciphertext
|
||||||
if (destination is Destination.Server && onion.count().toDouble() > 0.75 * FileServerAPIV2.maxFileSize.toDouble()) {
|
if (destination is Destination.Server && onion.count().toDouble() > 0.75 * FileServerAPIV2.maxFileSize.toDouble()) {
|
||||||
@ -398,13 +399,17 @@ object OnionRequestAPI {
|
|||||||
val promise = deferred.promise
|
val promise = deferred.promise
|
||||||
promise.fail { exception ->
|
promise.fail { exception ->
|
||||||
if (exception is HTTP.HTTPRequestFailedException && SnodeModule.isInitialized) {
|
if (exception is HTTP.HTTPRequestFailedException && SnodeModule.isInitialized) {
|
||||||
val path = paths.firstOrNull { it.contains(guardSnode) }
|
val checkedGuardSnode = guardSnode
|
||||||
|
val path =
|
||||||
|
if (checkedGuardSnode == null) null
|
||||||
|
else paths.firstOrNull { it.contains(checkedGuardSnode) }
|
||||||
|
|
||||||
fun handleUnspecificError() {
|
fun handleUnspecificError() {
|
||||||
if (path == null) { return }
|
if (path == null) { return }
|
||||||
var pathFailureCount = OnionRequestAPI.pathFailureCount[path] ?: 0
|
var pathFailureCount = OnionRequestAPI.pathFailureCount[path] ?: 0
|
||||||
pathFailureCount += 1
|
pathFailureCount += 1
|
||||||
if (pathFailureCount >= pathFailureThreshold) {
|
if (pathFailureCount >= pathFailureThreshold) {
|
||||||
dropGuardSnode(guardSnode)
|
guardSnode?.let { dropGuardSnode(it) }
|
||||||
path.forEach { snode ->
|
path.forEach { snode ->
|
||||||
@Suppress("ThrowableNotThrown")
|
@Suppress("ThrowableNotThrown")
|
||||||
SnodeAPI.handleSnodeError(exception.statusCode, exception.json, snode, null) // Intentionally don't throw
|
SnodeAPI.handleSnodeError(exception.statusCode, exception.json, snode, null) // Intentionally don't throw
|
||||||
|
Loading…
x
Reference in New Issue
Block a user