|
1 | 1 | package org.xmtp.android.library
|
2 | 2 |
|
3 |
| -import io.grpc.InsecureChannelCredentials |
4 | 3 | import io.grpc.ManagedChannel
|
| 4 | +import io.grpc.ManagedChannelBuilder |
5 | 5 | import io.grpc.Metadata
|
6 |
| -import io.grpc.TlsChannelCredentials |
7 |
| -import io.grpc.okhttp.OkHttpChannelBuilder |
8 | 6 | import kotlinx.coroutines.flow.Flow
|
9 | 7 | import org.xmtp.android.library.messages.Pagination
|
10 | 8 | import org.xmtp.android.library.messages.Topic
|
@@ -87,16 +85,39 @@ data class GRPCApiClient(
|
87 | 85 | ): SubscribeRequest = SubscribeRequest.newBuilder().addAllContentTopics(topics).build()
|
88 | 86 | }
|
89 | 87 |
|
| 88 | + private val retryPolicy = mapOf( |
| 89 | + "methodConfig" to listOf( |
| 90 | + mapOf( |
| 91 | + "retryPolicy" to mapOf( |
| 92 | + "maxAttempts" to 4.0, |
| 93 | + "initialBackoff" to "0.5s", |
| 94 | + "maxBackoff" to "30s", |
| 95 | + "backoffMultiplier" to 2.0, |
| 96 | + "retryableStatusCodes" to listOf( |
| 97 | + "UNAVAILABLE", |
| 98 | + "CANCELLED", |
| 99 | + ) |
| 100 | + ) |
| 101 | + ) |
| 102 | + ) |
| 103 | + ) |
| 104 | + |
90 | 105 | private val channel: ManagedChannel =
|
91 |
| - OkHttpChannelBuilder.forAddress( |
| 106 | + ManagedChannelBuilder.forAddress( |
92 | 107 | environment.getValue(),
|
93 |
| - if (environment == XMTPEnvironment.LOCAL) 5556 else 443, |
94 |
| - if (secure) { |
95 |
| - TlsChannelCredentials.create() |
| 108 | + if (environment == XMTPEnvironment.LOCAL) 5556 else 443 |
| 109 | + ).apply { |
| 110 | + keepAliveTime(30L, TimeUnit.SECONDS) |
| 111 | + keepAliveTimeout(20L, TimeUnit.SECONDS) |
| 112 | + keepAliveWithoutCalls(true) |
| 113 | + if (environment != XMTPEnvironment.LOCAL) { |
| 114 | + useTransportSecurity() |
96 | 115 | } else {
|
97 |
| - InsecureChannelCredentials.create() |
98 |
| - }, |
99 |
| - ).build() |
| 116 | + usePlaintext() |
| 117 | + } |
| 118 | + defaultServiceConfig(retryPolicy) |
| 119 | + enableRetry() |
| 120 | + }.build() |
100 | 121 |
|
101 | 122 | private val client: MessageApiGrpcKt.MessageApiCoroutineStub =
|
102 | 123 | MessageApiGrpcKt.MessageApiCoroutineStub(channel)
|
|
0 commit comments