Skip to content

Commit

Permalink
set default as fallback dns on retrofit
Browse files Browse the repository at this point in the history
  • Loading branch information
hussainmohd-a committed Sep 20, 2023
1 parent ed99a59 commit 6b64bb7
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class NonStoreAppUpdater(
Log.i(LOG_TAG_APP_UPDATE, "Beginning update check")
val url = baseUrl + BuildConfig.VERSION_CODE

val client = RetrofitManager.okHttpClient(RetrofitManager.Companion.OkHttpDnsType.DEFAULT)
val client = RetrofitManager.okHttpClient(RetrofitManager.Companion.OkHttpDnsType.FALLBACK_DNS)
val request = Request.Builder().url(url).build()

client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class PaymentWorker(val context: Context, workerParameters: WorkerParameters) :
try {
val retrofit =
RetrofitManager.getTcpProxyBaseBuilder(
RetrofitManager.Companion.OkHttpDnsType.DEFAULT
RetrofitManager.Companion.OkHttpDnsType.FALLBACK_DNS
)
.addConverterFactory(GsonConverterFactory.create())
.build()
Expand Down
16 changes: 10 additions & 6 deletions app/src/full/java/com/celzero/bravedns/service/TcpProxyHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ import com.celzero.bravedns.database.TcpProxyRepository
import com.celzero.bravedns.scheduler.PaymentWorker
import com.celzero.bravedns.util.LoggerConstants.Companion.LOG_TAG_PROXY
import dnsx.Dnsx
import java.text.SimpleDateFormat
import java.util.Locale
import java.util.concurrent.TimeUnit
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import org.json.JSONObject
import org.koin.core.component.KoinComponent
import org.koin.core.component.inject
import retrofit2.converter.gson.GsonConverterFactory
import java.text.SimpleDateFormat
import java.util.Locale
import java.util.concurrent.TimeUnit

object TcpProxyHelper : KoinComponent {

Expand Down Expand Up @@ -110,7 +110,7 @@ object TcpProxyHelper : KoinComponent {

fun isCloudflareIp(ip: String): Boolean {
// do not check for cloudflare ips for now
return false
// return false
return try {
cfIpTrie.hasAny(ip)
} catch (e: Exception) {
Expand All @@ -131,7 +131,7 @@ object TcpProxyHelper : KoinComponent {
try {
val retrofit =
RetrofitManager.getTcpProxyBaseBuilder(
RetrofitManager.Companion.OkHttpDnsType.DEFAULT
RetrofitManager.Companion.OkHttpDnsType.FALLBACK_DNS
)
.addConverterFactory(GsonConverterFactory.create())
.build()
Expand All @@ -157,7 +157,11 @@ object TcpProxyHelper : KoinComponent {
Log.w(LOG_TAG_PROXY, "unsuccessful response for ${response?.raw()?.request?.url}")
}
} catch (e: Exception) {
Log.w(LOG_TAG_PROXY, "publicKeyUsable: exception while checking public key", e)
Log.e(
LOG_TAG_PROXY,
"publicKeyUsable: exception while checking public key: ${e.message}",
e
)
}
return works
}
Expand Down
23 changes: 11 additions & 12 deletions app/src/full/java/com/celzero/bravedns/service/WireguardManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,20 @@ import com.celzero.bravedns.wireguard.Peer
import com.celzero.bravedns.wireguard.WgInterface
import ipn.Ipn
import ipn.Key
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import org.json.JSONObject
import org.koin.core.component.KoinComponent
import org.koin.core.component.inject
import retrofit2.converter.gson.GsonConverterFactory
import java.io.ByteArrayInputStream
import java.io.File
import java.io.InputStream
import java.nio.charset.StandardCharsets
import java.util.Locale
import java.util.concurrent.locks.ReentrantReadWriteLock
import kotlin.concurrent.write
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import org.json.JSONObject
import org.koin.core.component.KoinComponent
import org.koin.core.component.inject
import retrofit2.converter.gson.GsonConverterFactory

object WireGuardManager : KoinComponent {

Expand Down Expand Up @@ -83,13 +83,13 @@ object WireGuardManager : KoinComponent {
suspend fun load() {
// go through all files in the wireguard directory and load them
// parse the files as those are encrypted
// increment the id by 1, as the first config id is 0
lastAddedConfigId = wgConfigFilesRepository.getLastAddedConfigId() + 1
lock.write {
if (configs.isNotEmpty()) {
Log.i(LOG_TAG_PROXY, "configs already loaded")
return
}
// increment the id by 1, as the first config id is 0
lastAddedConfigId = wgConfigFilesRepository.getLastAddedConfigId() + 1
mappings = wgConfigFilesRepository.getWgConfigs().toMutableSet()
mappings.forEach {
val path = it.configPath
Expand Down Expand Up @@ -165,7 +165,6 @@ object WireGuardManager : KoinComponent {
}

fun getSecWarpConfig(): Config? {
// warp config will always be the first config in the list
return configs.firstOrNull { it.getId() == SEC_WARP_ID }
}

Expand Down Expand Up @@ -265,7 +264,7 @@ object WireGuardManager : KoinComponent {
val locale = Locale.getDefault().toString()

val retrofit =
RetrofitManager.getWarpBaseBuilder(RetrofitManager.Companion.OkHttpDnsType.DEFAULT)
RetrofitManager.getWarpBaseBuilder(RetrofitManager.Companion.OkHttpDnsType.FALLBACK_DNS)
.addConverterFactory(GsonConverterFactory.create())
.build()
val retrofitInterface = retrofit.create(IWireguardWarp::class.java)
Expand Down Expand Up @@ -304,7 +303,7 @@ object WireGuardManager : KoinComponent {
var works = false
try {
val retrofit =
RetrofitManager.getWarpBaseBuilder(RetrofitManager.Companion.OkHttpDnsType.DEFAULT)
RetrofitManager.getWarpBaseBuilder(RetrofitManager.Companion.OkHttpDnsType.FALLBACK_DNS)
.addConverterFactory(GsonConverterFactory.create())
.build()
val retrofitInterface = retrofit.create(IWireguardWarp::class.java)
Expand Down

0 comments on commit 6b64bb7

Please sign in to comment.