Skip to content

Commit

Permalink
Resolving pre-proxy domain issues
Browse files Browse the repository at this point in the history
  • Loading branch information
2dust committed Sep 19, 2024
1 parent 9960f49 commit 75c90e3
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 39 deletions.
7 changes: 0 additions & 7 deletions V2rayNG/app/src/main/kotlin/com/v2ray/ang/dto/ServerConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.v2ray.ang.dto
import com.v2ray.ang.AppConfig.TAG_BLOCKED
import com.v2ray.ang.AppConfig.TAG_DIRECT
import com.v2ray.ang.AppConfig.TAG_PROXY
import com.v2ray.ang.util.Utils

data class ServerConfig(
val configVersion: Int = 3,
Expand Down Expand Up @@ -79,10 +78,4 @@ data class ServerConfig(
}
return mutableListOf()
}

fun getV2rayPointDomainAndPort(): String {
val address = getProxyOutbound()?.getServerAddress().orEmpty()
val port = getProxyOutbound()?.getServerPort()
return Utils.getIpv6Address(address) + ":" + port
}
}
7 changes: 7 additions & 0 deletions V2rayNG/app/src/main/kotlin/com/v2ray/ang/dto/V2rayConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.google.gson.JsonSerializationContext
import com.google.gson.JsonSerializer
import com.google.gson.annotations.SerializedName
import com.google.gson.reflect.TypeToken
import com.v2ray.ang.util.Utils
import java.lang.reflect.Type

data class V2rayConfig(
Expand Down Expand Up @@ -449,6 +450,12 @@ data class V2rayConfig(
return null
}

fun getServerAddressAndPort(): String {
val address = getServerAddress().orEmpty()
val port = getServerPort()
return Utils.getIpv6Address(address) + ":" + port
}

fun getPassword(): String? {
if (protocol.equals(EConfigType.VMESS.name, true)
|| protocol.equals(EConfigType.VLESS.name, true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ object V2RayServiceManager {
}

v2rayPoint.configureFileContent = result.content
v2rayPoint.domainName = config.getV2rayPointDomainAndPort()
v2rayPoint.domainName = result.domainPort
currentConfig = config

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@ import android.view.ViewGroup
import androidx.appcompat.app.AlertDialog
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import com.google.gson.Gson
import com.v2ray.ang.AngApplication.Companion.application
import com.v2ray.ang.AppConfig
import com.v2ray.ang.R
import com.v2ray.ang.databinding.ItemQrcodeBinding
import com.v2ray.ang.databinding.ItemRecyclerFooterBinding
import com.v2ray.ang.databinding.ItemRecyclerMainBinding
import com.v2ray.ang.dto.EConfigType
import com.v2ray.ang.dto.SubscriptionItem
import com.v2ray.ang.extension.toast
import com.v2ray.ang.helper.ItemTouchHelperAdapter
import com.v2ray.ang.helper.ItemTouchHelperViewHolder
Expand Down Expand Up @@ -71,12 +69,7 @@ class MainRecyclerAdapter(val activity: MainActivity) : RecyclerView.Adapter<Mai
} else {
holder.itemMainBinding.layoutIndicator.setBackgroundResource(0)
}
holder.itemMainBinding.tvSubscription.text = ""
val json = MmkvManager.subStorage?.decodeString(profile.subscriptionId)
if (!json.isNullOrBlank()) {
val sub = Gson().fromJson(json, SubscriptionItem::class.java)
holder.itemMainBinding.tvSubscription.text = sub.remarks
}
holder.itemMainBinding.tvSubscription.text = MmkvManager.decodeSubscription(profile.subscriptionId)?.remarks ?: ""

var shareOptions = share_method.asList()
when (profile.configType) {
Expand Down
37 changes: 22 additions & 15 deletions V2rayNG/app/src/main/kotlin/com/v2ray/ang/util/V2rayConfigUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,33 +25,33 @@ object V2rayConfigUtil {
private val serverRawStorage by lazy { MMKV.mmkvWithID(MmkvManager.ID_SERVER_RAW, MMKV.MULTI_PROCESS_MODE) }
private val settingsStorage by lazy { MMKV.mmkvWithID(MmkvManager.ID_SETTING, MMKV.MULTI_PROCESS_MODE) }

data class Result(var status: Boolean, var content: String)
data class Result(var status: Boolean, var content: String = "", var domainPort: String? = null)

fun getV2rayConfig(context: Context, guid: String): Result {
try {
val config = MmkvManager.decodeServerConfig(guid) ?: return Result(false, "")
val config = MmkvManager.decodeServerConfig(guid) ?: return Result(false)
if (config.configType == EConfigType.CUSTOM) {
val raw = serverRawStorage?.decodeString(guid)
val customConfig = if (raw.isNullOrBlank()) {
config.fullConfig?.toPrettyPrinting() ?: return Result(false, "")
config.fullConfig?.toPrettyPrinting() ?: return Result(false)
} else {
raw
}
//Log.d(ANG_PACKAGE, customConfig)
return Result(true, customConfig)
val domainPort = config.getProxyOutbound()?.getServerAddressAndPort()
return Result(true, customConfig, domainPort)
}

val result = getV2rayNonCustomConfig(context, config)
//Log.d(ANG_PACKAGE, result.content)
return result
} catch (e: Exception) {
e.printStackTrace()
return Result(false, "")
return Result(false)
}
}

private fun getV2rayNonCustomConfig(context: Context, config: ServerConfig): Result {
val result = Result(false, "")
val result = Result(false)

val outbound = config.getProxyOutbound() ?: return result
val address = outbound.getServerAddress() ?: return result
Expand All @@ -75,7 +75,7 @@ object V2rayConfigUtil {

outbounds(v2rayConfig, outbound)

moreOutbounds(v2rayConfig, config.subscriptionId)
val retMore = moreOutbounds(v2rayConfig, config.subscriptionId)

routing(v2rayConfig)

Expand All @@ -93,6 +93,7 @@ object V2rayConfigUtil {

result.status = true
result.content = v2rayConfig.toPrettyPrinting()
result.domainPort = if (retMore.first) retMore.second else outbound.getServerAddressAndPort()
return result
}

Expand Down Expand Up @@ -646,17 +647,20 @@ object V2rayConfigUtil {
return true
}

private fun moreOutbounds(v2rayConfig: V2rayConfig, subscriptionId: String): Boolean {
private fun moreOutbounds(v2rayConfig: V2rayConfig, subscriptionId: String): Pair<Boolean, String> {
val returnPair = Pair(false, "")
var domainPort: String = ""

//fragment proxy
if (settingsStorage?.decodeBool(AppConfig.PREF_FRAGMENT_ENABLED, false) == true) {
return true
return returnPair
}

if (subscriptionId.isNullOrEmpty()) {
return true
return returnPair
}
try {
val subItem = MmkvManager.decodeSubscription(subscriptionId) ?: return false
val subItem = MmkvManager.decodeSubscription(subscriptionId) ?: return returnPair

//current proxy
val outbound = v2rayConfig.outbounds[0]
Expand All @@ -673,6 +677,7 @@ object V2rayConfigUtil {
V2rayConfig.OutboundBean.StreamSettingsBean.SockoptBean(
dialerProxy = prevOutbound.tag
)
domainPort = prevOutbound.getServerAddressAndPort()
}
}

Expand All @@ -684,7 +689,6 @@ object V2rayConfigUtil {
updateOutboundWithGlobalSettings(nextOutbound)
nextOutbound.tag = TAG_PROXY
v2rayConfig.outbounds.add(0, nextOutbound)

outbound.tag = TAG_PROXY + "1"
nextOutbound.streamSettings?.sockopt =
V2rayConfig.OutboundBean.StreamSettingsBean.SockoptBean(
Expand All @@ -694,9 +698,12 @@ object V2rayConfigUtil {
}
} catch (e: Exception) {
e.printStackTrace()
return false
return returnPair
}

return true
if (domainPort.isNotEmpty()) {
return Pair(true, domainPort)
}
return returnPair
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@ import com.v2ray.ang.dto.EConfigType
import com.v2ray.ang.dto.ProfileItem
import com.v2ray.ang.dto.ServerConfig
import com.v2ray.ang.dto.ServersCache
import com.v2ray.ang.dto.SubscriptionItem
import com.v2ray.ang.dto.V2rayConfig
import com.v2ray.ang.extension.toast
import com.v2ray.ang.util.AngConfigManager
import com.v2ray.ang.util.AngConfigManager.updateConfigViaSub
import com.v2ray.ang.util.MessageUtil
import com.v2ray.ang.util.MmkvManager
import com.v2ray.ang.util.MmkvManager.KEY_ANG_CONFIGS
import com.v2ray.ang.util.MmkvManager.subStorage
import com.v2ray.ang.util.SpeedtestUtil
import com.v2ray.ang.util.Utils
import com.v2ray.ang.util.V2rayConfigUtil
Expand Down Expand Up @@ -159,12 +157,8 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
if (subscriptionId.isNullOrEmpty()) {
return AngConfigManager.updateConfigViaSubAll()
} else {
val json = subStorage?.decodeString(subscriptionId)
if (!json.isNullOrBlank()) {
return updateConfigViaSub(Pair(subscriptionId, Gson().fromJson(json, SubscriptionItem::class.java)))
} else {
return 0
}
val subItem = MmkvManager.decodeSubscription(subscriptionId) ?: return 0
return updateConfigViaSub(Pair(subscriptionId, subItem))
}
}

Expand Down

0 comments on commit 75c90e3

Please sign in to comment.