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

Commit

Permalink
Fix brook
Browse files Browse the repository at this point in the history
  • Loading branch information
nekohasekai committed Jan 16, 2022
1 parent d144dfa commit ac56eb1
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,11 @@ abstract class V2RayInstance(

commands.add(bean.internalUri())

if (bean.protocol.startsWith("ws")) {
commands.add("--serverAddress")
commands.add(bean.wrapUri())
}

if (bean.password.isNotBlank()) {
commands.add("--password")
commands.add(bean.password)
Expand Down
23 changes: 3 additions & 20 deletions app/src/main/java/io/nekohasekai/sagernet/fmt/ConfigBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import io.nekohasekai.sagernet.database.DataStore
import io.nekohasekai.sagernet.database.ProxyEntity
import io.nekohasekai.sagernet.database.SagerDatabase
import io.nekohasekai.sagernet.fmt.V2rayBuildResult.IndexEntity
import io.nekohasekai.sagernet.fmt.brook.BrookBean
import io.nekohasekai.sagernet.fmt.gson.gson
import io.nekohasekai.sagernet.fmt.http.HttpBean
import io.nekohasekai.sagernet.fmt.internal.BalancerBean
Expand Down Expand Up @@ -878,14 +877,7 @@ fun buildV2RayConfig(

if (proxyEntity.needExternal() && !isBalancer && index != profileList.lastIndex) {
val mappingPort = mkPort()
when (bean) {
is BrookBean -> {
dns.hosts[bean.serverAddress] = LOCALHOST
}
else -> {
bean.finalAddress = LOCALHOST
}
}
bean.finalAddress = LOCALHOST
bean.finalPort = mappingPort
bean.isChain = true

Expand All @@ -905,14 +897,7 @@ fun buildV2RayConfig(
})
} else if (bean.canMapping() && proxyEntity.needExternal()) {
val mappingPort = mkPort()
when (bean) {
is BrookBean -> {
dns.hosts[bean.serverAddress] = LOCALHOST
}
else -> {
bean.finalAddress = LOCALHOST
}
}
bean.finalAddress = LOCALHOST
bean.finalPort = mappingPort

inbounds.add(InboundObject().apply {
Expand Down Expand Up @@ -947,9 +932,7 @@ fun buildV2RayConfig(
if (isBalancer) {
val balancerBean = balancer()!!
val observatory = ObservatoryObject().apply {
probeUrl = if (balancerBean.probeUrl.isNotBlank()) {
balancerBean.probeUrl
} else {
probeUrl = balancerBean.probeUrl.ifBlank {
DataStore.connectionTestURL
}
if (balancerBean.probeInterval > 0) {
Expand Down
15 changes: 6 additions & 9 deletions app/src/main/java/io/nekohasekai/sagernet/fmt/brook/BrookFmt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ package io.nekohasekai.sagernet.fmt.brook

import io.nekohasekai.sagernet.fmt.AbstractBean
import io.nekohasekai.sagernet.fmt.socks.SOCKSBean
import io.nekohasekai.sagernet.ktx.pathSafe
import io.nekohasekai.sagernet.ktx.queryParameter
import io.nekohasekai.sagernet.ktx.wrapUri
import io.nekohasekai.sagernet.ktx.*
import libcore.Libcore

fun parseBrook(text: String): AbstractBean {
Expand Down Expand Up @@ -142,12 +140,11 @@ fun BrookBean.toUri(): String {
}

fun BrookBean.internalUri(): String {
var server = wrapUri()
server = when (protocol) {
"ws" -> "ws://"
"wss" -> "wss://"
else -> return server
} + server
var server = when (protocol) {
"ws" -> "ws://" + wrapUriWithOriginHost()
"wss" -> "wss://" + wrapUriWithOriginHost()
else -> return wrapUri()
}
if (wsPath.isNotBlank()) {
if (!wsPath.startsWith("/")) {
server += "/"
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/java/io/nekohasekai/sagernet/ktx/Nets.kt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ fun AbstractBean.wrapUri(): String {
}
}

fun AbstractBean.wrapUriWithOriginHost(): String {
return if (Validator.isIpv6(serverAddress)) {
"[$serverAddress]:$finalPort"
} else {
"$serverAddress:$finalPort"
}
}

fun parseAddress(addressArray: ByteArray) = InetAddress.getByAddress(addressArray)
val INET_TUN = InetAddress.getByName(VpnService.PRIVATE_VLAN4_CLIENT)
val INET6_TUN = InetAddress.getByName(VpnService.PRIVATE_VLAN6_CLIENT)
Expand Down
4 changes: 2 additions & 2 deletions sager.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PACKAGE_NAME=io.nekohasekai.sagernet
VERSION_NAME=0.7-beta05
VERSION_CODE=147
VERSION_NAME=0.7-beta06
VERSION_CODE=148

NAIVE_VERSION_NAME=97.0.4692.71-2
NAIVE_VERSION=10
Expand Down

0 comments on commit ac56eb1

Please sign in to comment.