Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

Commit

Permalink
Resolving pre-proxy domain issues
Browse files Browse the repository at this point in the history
  • Loading branch information
2dust authored and AnGgIt86 committed Sep 23, 2024
1 parent 8f340f0 commit 51b4b46
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 39 deletions.
7 changes: 0 additions & 7 deletions app/src/main/kotlin/com/neko/v2ray/dto/ServerConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.neko.v2ray.dto
import com.neko.v2ray.AppConfig.TAG_BLOCKED
import com.neko.v2ray.AppConfig.TAG_DIRECT
import com.neko.v2ray.AppConfig.TAG_PROXY
import com.neko.v2ray.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 app/src/main/kotlin/com/neko/v2ray/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
9 changes: 1 addition & 8 deletions app/src/main/kotlin/com/neko/v2ray/ui/MainRecyclerAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@ import android.view.ViewGroup
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import com.google.gson.Gson
import com.neko.v2ray.AngApplication.Companion.application
import com.neko.v2ray.AppConfig
import com.neko.v2ray.R
import com.neko.v2ray.databinding.ItemQrcodeBinding
import com.neko.v2ray.databinding.ItemRecyclerFooterBinding
import com.neko.v2ray.databinding.ItemRecyclerMainBinding
import com.neko.v2ray.dto.EConfigType
import com.neko.v2ray.dto.SubscriptionItem
import com.neko.v2ray.extension.toast
import com.neko.v2ray.helper.ItemTouchHelperAdapter
import com.neko.v2ray.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 app/src/main/kotlin/com/neko/v2ray/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
}
}
10 changes: 2 additions & 8 deletions app/src/main/kotlin/com/neko/v2ray/viewmodel/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@ import com.neko.v2ray.dto.EConfigType
import com.neko.v2ray.dto.ProfileItem
import com.neko.v2ray.dto.ServerConfig
import com.neko.v2ray.dto.ServersCache
import com.neko.v2ray.dto.SubscriptionItem
import com.neko.v2ray.dto.V2rayConfig
import com.neko.v2ray.extension.toast
import com.neko.v2ray.util.AngConfigManager
import com.neko.v2ray.util.AngConfigManager.updateConfigViaSub
import com.neko.v2ray.util.MessageUtil
import com.neko.v2ray.util.MmkvManager
import com.neko.v2ray.util.MmkvManager.KEY_ANG_CONFIGS
import com.neko.v2ray.util.MmkvManager.subStorage
import com.neko.v2ray.util.SpeedtestUtil
import com.neko.v2ray.util.Utils
import com.neko.v2ray.util.V2rayConfigUtil
Expand Down Expand Up @@ -160,12 +158,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 51b4b46

Please sign in to comment.