Skip to content

Commit

Permalink
build server instead
Browse files Browse the repository at this point in the history
  • Loading branch information
segfault-bilibili committed Aug 30, 2022
1 parent 9f6b3a4 commit 0681aa6
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 65 deletions.
3 changes: 2 additions & 1 deletion core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ android {

cargo {
module = "src/main/rust/shadowsocks-rust"
libname = "sslocal"
libname = "ssserver"
targets = listOf("arm", "arm64", "x86", "x86_64")
profile = findProperty("CARGO_PROFILE")?.toString() ?: currentFlavor
extraCargoBuildArguments = listOf("--bin", libname!!)
featureSpec.noDefaultBut(arrayOf(
"server",
"stream-cipher",
"aead-cipher-extra",
"logging",
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/com/github/shadowsocks/bg/Executable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ import java.io.IOException

object Executable {
const val REDSOCKS = "libredsocks.so"
const val SS_LOCAL = "libsslocal.so"
const val SS_SERVER = "libssserver.so"
const val TUN2SOCKS = "libtun2socks.so"

private val EXECUTABLES = setOf(SS_LOCAL, REDSOCKS, TUN2SOCKS)
private val EXECUTABLES = setOf(SS_SERVER, REDSOCKS, TUN2SOCKS)

fun killAll() {
for (process in File("/proc").listFiles { _, name -> TextUtils.isDigitsOnly(name) } ?: return) {
Expand Down
29 changes: 6 additions & 23 deletions core/src/main/java/com/github/shadowsocks/bg/ProxyInstance.kt
Original file line number Diff line number Diff line change
Expand Up @@ -71,38 +71,21 @@ class ProxyInstance(val profile: Profile, private val route: String = profile.ro
config.put("plugin", path).put("plugin_opts", opts.toString())
}
config.put("dns", "system")
config.put("locals", JSONArray().apply {
config.put("servers", JSONArray().apply {
// local SOCKS5 proxy
put(JSONObject().apply {
put("local_address", DataStore.listenAddress)
put("local_port", DataStore.portProxy)
put("local_udp_address", DataStore.listenAddress)
put("local_udp_port", DataStore.portProxy)
put("address", profile.host)
put("port", profile.remotePort)
put("mode", mode)
put("method", profile.method)
put("password", profile.password);
})

// local DNS proxy
if (dnsRelay) try {
URI("dns://${profile.remoteDns}")
} catch (e: URISyntaxException) {
throw BaseService.ExpectedExceptionWrapper(e)
}.let { dns ->
put(JSONObject().apply {
put("local_address", DataStore.listenAddress)
put("local_port", DataStore.portLocalDns)
put("local_dns_address", "local_dns_path")
put("remote_dns_address", dns.host ?: "0.0.0.0")
put("remote_dns_port", if (dns.port < 0) 53 else dns.port)
put("protocol", "dns")
})
}
})
configFile.writeText(config.toString())

// build the command line
val cmd = arrayListOf(
File((service as Context).applicationInfo.nativeLibraryDir, Executable.SS_LOCAL).absolutePath,
"--stat-path", stat.absolutePath,
File((service as Context).applicationInfo.nativeLibraryDir, Executable.SS_SERVER).absolutePath,
"-c", configFile.absolutePath,
)

Expand Down
33 changes: 3 additions & 30 deletions core/src/main/java/com/github/shadowsocks/database/Profile.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ data class Profile(
// user configurable fields
var name: String? = "",

var host: String = "example.shadowsocks.org",
var host: String = "127.0.0.1",
var remotePort: Int = 8388,
var password: String = "u1rRWTssNv0p",
var method: String = "aes-256-cfb",
var password: String = "magireco",
var method: String = "chacha20-ietf-poly1305",

var route: String = "all",
var remoteDns: String = "dns.google",
Expand Down Expand Up @@ -309,33 +309,6 @@ data class Profile(
override fun toString() = toUri().toString()

fun toJson(profiles: LongSparseArray<Profile>? = null): JSONObject = JSONObject().apply {
put("server", host)
put("server_port", remotePort)
put("password", password)
put("method", method)
if (profiles == null) return@apply
PluginConfiguration(plugin ?: "").getOptions().also {
if (it.id.isNotEmpty()) {
put("plugin", it.id)
put("plugin_opts", it.toString())
}
}
put("remarks", name)
put("route", route)
put("remote_dns", remoteDns)
put("ipv6", ipv6)
put("metered", metered)
put("proxy_apps", JSONObject().apply {
put("enabled", proxyApps)
if (proxyApps) {
put("bypass", bypass)
// android_ prefix is used because package names are Android specific
put("android_list", JSONArray(individual.split("\n")))
}
})
put("udpdns", udpdns)
val fallback = profiles.get(udpFallback ?: return@apply)
if (fallback != null && fallback.plugin.isNullOrEmpty()) fallback.toJson().also { put("udp_fallback", it) }
}

fun serialize() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ object DataStore : OnPreferenceDataStoreChangeListener {
?: BootReceiver.enabled.also { publicStore.putBoolean(Key.persistAcrossReboot, it) }
val canToggleLocked: Boolean get() = publicStore.getBoolean(Key.directBootAware) == true
val directBootAware: Boolean get() = Core.directBootSupported && canToggleLocked
val serviceMode get() = publicStore.getString(Key.serviceMode) ?: Key.modeVpn
val serviceMode get() = publicStore.getString(Key.serviceMode) ?: Key.modeProxy
val listenAddress get() = if (publicStore.getBoolean(Key.shareOverLan, false)) "0.0.0.0" else "127.0.0.1"
var portProxy: Int
get() = getLocalPort(Key.portProxy, 1080)
Expand Down
2 changes: 1 addition & 1 deletion mobile/src/main/res/layout/navigation_header.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
android:layout_centerVertical="true"
android:fontFamily="@font/iceland"
android:gravity="center"
android:text="shadowsocks"
android:text="shadowsocks-server"
android:textColor="@android:color/white"
android:textSize="32sp"
tools:ignore="HardcodedText"/>
Expand Down
2 changes: 1 addition & 1 deletion mobile/src/main/res/raw/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<p>A <a href="http://shadowsocks.org">Shadowsocks</a> client for Android, written in Kotlin.</p>
<p>A <a href="http://shadowsocks.org">Shadowsocks</a> server for Android, written in Kotlin.</p>
<p>Copyright (C) 2017 by Max Lv <a href="&#x6d;&#97;&#x69;&#108;&#116;&#111;&#x3a;&#x6d;&#97;x&#46;&#99;.&#108;&#118;&#x40;&#103;&#109;&#97;&#x69;&#108;&#46;&#x63;&#x6f;&#109;">&#x6d;&#97;&#x78;.&#x63;&#x2e;&#108;v&#64;&#x67;&#109;&#x61;&#x69;&#108;&#x2e;&#99;&#111;&#109;</a></p>
<p>Copyright (C) 2017 by Mygod Studio <a href="mailto:[email protected]">[email protected]</a></p>
<p>This program is free software: you can redistribute it and/or modify
Expand Down
4 changes: 0 additions & 4 deletions mobile/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,8 @@

<string-array name="service_modes">
<item>@string/service_mode_proxy</item>
<item>@string/service_mode_vpn</item>
<item>@string/service_mode_transproxy</item>
</string-array>
<string-array name="service_mode_values" translatable="false">
<item>proxy</item>
<item>vpn</item>
<item>transproxy</item>
</string-array>
</resources>
2 changes: 1 addition & 1 deletion mobile/src/main/res/xml/pref_global.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
app:icon="@drawable/ic_device_developer_mode"
app:entries="@array/service_modes"
app:entryValues="@array/service_mode_values"
app:defaultValue="vpn"
app:defaultValue="proxy"
app:title="@string/service_mode"
app:useSimpleSummaryProvider="true"/>
<EditTextPreference
Expand Down
2 changes: 1 addition & 1 deletion tv/src/main/res/xml/pref_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
app:key="serviceMode"
app:entries="@array/service_modes"
app:entryValues="@array/service_mode_values"
app:defaultValue="vpn"
app:defaultValue="proxy"
app:title="@string/service_mode"
app:useSimpleSummaryProvider="true"/>
<SwitchPreference
Expand Down

0 comments on commit 0681aa6

Please sign in to comment.