Update CHANGELOG.md and rename ServerConnectionListener.kt function.

This commit is contained in:
dkadrikj 2021-11-22 10:53:58 +01:00 committed by Dino Kadrikj
parent 42b21ec123
commit b69d40f9fb
6 changed files with 16 additions and 16 deletions

View File

@ -4,10 +4,10 @@
### Changes
- Added GuestHole support, that can be used by the clients to overcome potential blocked api. Mainly
this is supported now from VPN client.
- Added Server Connection error support, that can be used by the clients to overcome potential blocked api.
Mainly and initially this is supported now from VPN client for their guest hole feature.
- Clients should provide a new dependency for `GuestHoleFallbackListener` or use the default one that
Core provides `DefaultGustHoleFallbackListener` which does not do anything.
Core provides `ServerConnectionListener` which does not do anything.
## Auth [1.18.4], Network [1.15.8], Util Kotlin [1.15.3]
## Auth [1.18.5], Network [1.15.9], Util Kotlin [1.15.4]

View File

@ -142,13 +142,13 @@ class NetworkModule {
@Provides
@Singleton
fun provideGuestHoleFallbackListener(): ServerConnectionListener = object: ServerConnectionListener {
override suspend fun <T> fallbackCall(
override suspend fun <T> onPotentiallyBlocked(
path: String?,
query: String?,
blockToRetry: suspend () -> ApiResult<T>
backendCall: suspend () -> ApiResult<T>
): ApiResult<T>? {
delay(1000)
return blockToRetry()
return backendCall()
}
}
}

View File

@ -137,15 +137,15 @@ class ApiManagerFactory(
): List<ApiErrorHandler<Api>> {
val refreshTokenHandler = RefreshTokenHandler<Api>(sessionId, sessionProvider, sessionListener, monoClockMs)
val forceUpdateHandler = ProtonForceUpdateHandler<Api>(apiClient)
val guestHoleHandler = ServerConnectionHandler<Api>(serverConnectionListener)
val serverConnectionHandler = ServerConnectionHandler<Api>(serverConnectionListener)
val humanVerificationNeededHandler =
HumanVerificationNeededHandler<Api>(sessionId, clientIdProvider, humanVerificationListener, monoClockMs)
val humanVerificationInvalidHandler =
HumanVerificationInvalidHandler<Api>(sessionId, clientIdProvider, humanVerificationListener)
return listOf(
serverConnectionHandler,
refreshTokenHandler,
forceUpdateHandler,
guestHoleHandler,
humanVerificationInvalidHandler,
humanVerificationNeededHandler
)

View File

@ -47,7 +47,7 @@ internal suspend fun <Api, T> safeApiCall(
} catch (e: CertificateException) {
ApiResult.Error.Certificate(e)
} catch (e: ServerConnectionException) {
e.parse(networkManager)
e.toApiResult(networkManager)
}
if (result is ApiResult.Error) {
result.cause?.let { CoreLogger.e(LogTag.DEFAULT, it) }
@ -55,7 +55,7 @@ internal suspend fun <Api, T> safeApiCall(
return result
}
private fun ServerConnectionException.parse(networkManager: NetworkManager): ApiResult.Error.Connection {
private fun ServerConnectionException.toApiResult(networkManager: NetworkManager): ApiResult.Error.Connection {
// handle the exceptions that might indicate that the API is potentially blocked
return when (originalException) {
is SSLHandshakeException -> ApiResult.Error.Certificate(this)

View File

@ -36,12 +36,12 @@ class ServerConnectionHandler<Api>(
): ApiResult<T> {
if (!error.isPotentialBlocking) return error
if (error !is ApiResult.Error.Connection) return error
// it should suspend and ask the client to establish guest hole
val result =
return serverConnectionListener?.let { listener ->
globalMutex.withLock {
serverConnectionListener?.fallbackCall(error.path, error.query) { backend(call) }
listener.onPotentiallyBlocked(error.path, error.query) { backend(call) }
}
return result ?: error
} ?: error
}
companion object {

View File

@ -22,9 +22,9 @@ import me.proton.core.network.domain.ApiResult
interface ServerConnectionListener {
suspend fun <T> fallbackCall(
suspend fun <T> onPotentiallyBlocked(
path: String?,
query: String?,
blockToRetry: suspend () -> ApiResult<T>
backendCall: suspend () -> ApiResult<T>
): ApiResult<T>?
}