This repository has been archived by the owner on Nov 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
461 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
app/src/main/kotlin/com/neko/v2ray/util/fmt/Hysteria2Fmt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package com.neko.v2ray.util.fmt | ||
|
||
import android.text.TextUtils | ||
import com.neko.v2ray.AppConfig | ||
import com.neko.v2ray.dto.EConfigType | ||
import com.neko.v2ray.dto.ServerConfig | ||
import com.neko.v2ray.dto.V2rayConfig | ||
import com.neko.v2ray.extension.idnHost | ||
import com.neko.v2ray.util.MmkvManager.settingsStorage | ||
import com.neko.v2ray.util.Utils | ||
import java.net.URI | ||
|
||
object Hysteria2Fmt { | ||
|
||
fun parseHysteria2(str: String): ServerConfig { | ||
var allowInsecure = settingsStorage?.decodeBool(AppConfig.PREF_ALLOW_INSECURE) ?: false | ||
val config = ServerConfig.create(EConfigType.HYSTERIA2) | ||
|
||
val uri = URI(Utils.fixIllegalUrl(str)) | ||
config.remarks = Utils.urlDecode(uri.fragment.orEmpty()) | ||
|
||
val queryParam = uri.rawQuery.split("&") | ||
.associate { it.split("=").let { (k, v) -> k to Utils.urlDecode(v) } } | ||
|
||
config.outboundBean?.streamSettings?.populateTlsSettings( | ||
V2rayConfig.TLS, | ||
if ((queryParam["allowInsecure"].orEmpty()) == "1") true else allowInsecure, | ||
queryParam["sni"] ?: uri.idnHost, | ||
null, | ||
queryParam["alpn"], | ||
null, | ||
null, | ||
null | ||
) | ||
|
||
config.outboundBean?.settings?.servers?.get(0)?.let { server -> | ||
server.address = uri.idnHost | ||
server.port = uri.port | ||
server.password = uri.userInfo | ||
} | ||
return config | ||
} | ||
|
||
fun toUri(config: ServerConfig): String { | ||
val outbound = config.getProxyOutbound() ?: return "" | ||
val streamSetting = outbound.streamSettings ?: V2rayConfig.OutboundBean.StreamSettingsBean() | ||
|
||
val remark = "#" + Utils.urlEncode(config.remarks) | ||
val dicQuery = HashMap<String, String>() | ||
dicQuery["security"] = streamSetting.security.ifEmpty { "none" } | ||
streamSetting.tlsSettings?.let { tlsSetting -> | ||
dicQuery["insecure"] = if (tlsSetting.allowInsecure) "1" else "0" | ||
if (!TextUtils.isEmpty(tlsSetting.serverName)) { | ||
dicQuery["sni"] = tlsSetting.serverName | ||
} | ||
if (!tlsSetting.alpn.isNullOrEmpty() && tlsSetting.alpn.isNotEmpty()) { | ||
dicQuery["alpn"] = Utils.removeWhiteSpace(tlsSetting.alpn.joinToString()).orEmpty() | ||
} | ||
} | ||
|
||
val query = "?" + dicQuery.toList().joinToString( | ||
separator = "&", | ||
transform = { it.first + "=" + it.second }) | ||
|
||
val url = String.format( | ||
"%s@%s:%s", | ||
outbound.getPassword(), | ||
Utils.getIpv6Address(outbound.getServerAddress()), | ||
outbound.getServerPort() | ||
) | ||
return url + query + remark | ||
} | ||
} |
Oops, something went wrong.