From ee28f9718a68cf58db6ed8e404568af904923833 Mon Sep 17 00:00:00 2001 From: Max Lv Date: Sun, 23 Feb 2020 16:10:46 +0800 Subject: [PATCH 01/57] Integrate shadowsocks-rust --- .gitmodules | 3 +++ build.gradle | 4 ++++ core/build.gradle | 10 ++++++++++ core/shadowsocks-rust | 1 + 4 files changed, 18 insertions(+) create mode 160000 core/shadowsocks-rust diff --git a/.gitmodules b/.gitmodules index b9e2447a19..3b10fd5435 100644 --- a/.gitmodules +++ b/.gitmodules @@ -33,3 +33,6 @@ [submodule "core/src/main/jni/re2"] path = core/src/main/jni/re2 url = https://github.com/google/re2.git +[submodule "core/shadowsocks-rust"] + path = core/shadowsocks-rust + url = https://github.com/madeye/shadowsocks-rust diff --git a/build.gradle b/build.gradle index 39937ac99e..b9c99a0e26 100644 --- a/build.gradle +++ b/build.gradle @@ -25,9 +25,13 @@ buildscript { maven { url 'https://maven.fabric.io/public' } + maven { + url "https://plugins.gradle.org/m2/" + } } dependencies { + classpath 'gradle.plugin.org.mozilla.rust-android-gradle:plugin:0.8.3' classpath 'com.android.tools.build:gradle:4.0.0-alpha09' classpath 'com.github.ben-manes:gradle-versions-plugin:0.27.0' classpath 'com.google.android.gms:oss-licenses-plugin:0.9.5' diff --git a/core/build.gradle b/core/build.gradle index b15f0542dd..7e988e473e 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -2,6 +2,7 @@ apply plugin: 'com.android.library' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' apply plugin: 'kotlin-kapt' +apply plugin: 'org.mozilla.rust-android-gradle.rust-android' android { compileSdkVersion rootProject.compileSdkVersion @@ -50,6 +51,15 @@ androidExtensions { experimental = true } +cargo { + module = 'shadowsocks-rust' + libname = 'shadowsocks-rust' + targets = ['arm', 'arm64', 'x86', 'x86_64'] + features { + noDefaultBut "sodium", "trust-dns" + } +} + def coroutinesVersion = '1.3.3' def roomVersion = '2.2.3' def workVersion = '2.3.1' diff --git a/core/shadowsocks-rust b/core/shadowsocks-rust new file mode 160000 index 0000000000..b8beabe3de --- /dev/null +++ b/core/shadowsocks-rust @@ -0,0 +1 @@ +Subproject commit b8beabe3de9c986f4bb57922985a0ee64403e821 From c84c8a427170a38604c06f699c6d21f599e58cde Mon Sep 17 00:00:00 2001 From: Max Lv Date: Sun, 23 Feb 2020 22:46:11 +0800 Subject: [PATCH 02/57] Remove trust-dns feature --- core/build.gradle | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core/build.gradle b/core/build.gradle index 7e988e473e..6787df96ad 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -53,10 +53,11 @@ androidExtensions { cargo { module = 'shadowsocks-rust' - libname = 'shadowsocks-rust' + libname = 'shadowsocks' targets = ['arm', 'arm64', 'x86', 'x86_64'] + profile = 'release' features { - noDefaultBut "sodium", "trust-dns" + noDefaultBut "sodium" } } From 302231ae534c10df5bf6724baec243aa0a1d533a Mon Sep 17 00:00:00 2001 From: Max Lv Date: Sun, 23 Feb 2020 23:48:08 +0800 Subject: [PATCH 03/57] Only build sslocal binary --- core/build.gradle | 2 ++ core/shadowsocks-rust | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/core/build.gradle b/core/build.gradle index 6787df96ad..a9e80d7a2e 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -56,6 +56,8 @@ cargo { libname = 'shadowsocks' targets = ['arm', 'arm64', 'x86', 'x86_64'] profile = 'release' + targetIncludes = ['sslocal'] + extraCargoBuildArguments = ['--bin', 'sslocal'] features { noDefaultBut "sodium" } diff --git a/core/shadowsocks-rust b/core/shadowsocks-rust index b8beabe3de..a6bad0389f 160000 --- a/core/shadowsocks-rust +++ b/core/shadowsocks-rust @@ -1 +1 @@ -Subproject commit b8beabe3de9c986f4bb57922985a0ee64403e821 +Subproject commit a6bad0389f44dec993afc39c71f1ddfe02b65fa9 From 40915ff4af0db2ef70d4c1cc331739a1bfc13795 Mon Sep 17 00:00:00 2001 From: Max Lv Date: Mon, 24 Feb 2020 01:53:50 +0800 Subject: [PATCH 04/57] Rename sslocal to libsslocal.so --- core/build.gradle | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/core/build.gradle b/core/build.gradle index a9e80d7a2e..6ef4c53c51 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -53,14 +53,17 @@ androidExtensions { cargo { module = 'shadowsocks-rust' - libname = 'shadowsocks' + libname = 'sslocal' targets = ['arm', 'arm64', 'x86', 'x86_64'] profile = 'release' - targetIncludes = ['sslocal'] + targetIncludes = ['libsslocal.so'] extraCargoBuildArguments = ['--bin', 'sslocal'] features { noDefaultBut "sodium" } + exec { spec, toolchain -> + spec.environment("RUSTFLAGS", "-C link-arg=-o -C link-arg=target/${toolchain.target}/release/libsslocal.so") + } } def coroutinesVersion = '1.3.3' From bdae24298b9e271f906028db88f515edc6a6e73a Mon Sep 17 00:00:00 2001 From: Max Lv Date: Wed, 26 Feb 2020 17:27:46 +0800 Subject: [PATCH 05/57] Enable cargo build --- core/build.gradle | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/build.gradle b/core/build.gradle index 6ef4c53c51..0c20f50c25 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -66,6 +66,8 @@ cargo { } } +preBuild.dependsOn "cargoBuild" + def coroutinesVersion = '1.3.3' def roomVersion = '2.2.3' def workVersion = '2.3.1' From fa1169429d54a3cde9cdbcdfd1382b9cd2648af9 Mon Sep 17 00:00:00 2001 From: Max Lv Date: Wed, 26 Feb 2020 18:31:09 +0800 Subject: [PATCH 06/57] Clean up --- .circleci/config.yml | 2 +- .gitmodules | 27 +- build.gradle | 1 + core/build.gradle | 6 +- .../com/github/shadowsocks/bg/Executable.kt | 2 +- .../github/shadowsocks/bg/ProxyInstance.kt | 5 +- core/src/main/jni/Android.mk | 261 +----------------- core/src/main/jni/libev | 1 - core/src/main/jni/libsodium | 1 - core/src/main/jni/mbedtls | 1 - core/src/main/jni/pcre | 1 - core/src/main/jni/shadowsocks-libev | 1 - core/{shadowsocks-rust => src/main/rust} | 0 mobile/build.gradle | 1 + tv/build.gradle | 1 + 15 files changed, 16 insertions(+), 295 deletions(-) delete mode 160000 core/src/main/jni/libev delete mode 160000 core/src/main/jni/libsodium delete mode 160000 core/src/main/jni/mbedtls delete mode 160000 core/src/main/jni/pcre delete mode 160000 core/src/main/jni/shadowsocks-libev rename core/{shadowsocks-rust => src/main/rust} (100%) diff --git a/.circleci/config.yml b/.circleci/config.yml index 1c9c25dba1..32fac5fe5b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -13,7 +13,7 @@ jobs: key: jars-{{ checksum "build.gradle" }} - run: name: Run Build and Tests - command: ./gradlew assembleDebug check + command: ./gradlew cargoBuild && ./gradlew assembleDebug check - save_cache: paths: - ~/.gradle diff --git a/.gitmodules b/.gitmodules index 3b10fd5435..c65a7e8f8b 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,14 +1,7 @@ -[submodule "core/src/main/jni/shadowsocks-libev"] - path = core/src/main/jni/shadowsocks-libev - url = https://github.com/shadowsocks/shadowsocks-libev [submodule "core/src/main/jni/badvpn"] path = core/src/main/jni/badvpn url = https://github.com/shadowsocks/badvpn.git branch = shadowsocks-android -[submodule "core/src/main/jni/libancillary"] - path = core/src/main/jni/libancillary - url = https://github.com/shadowsocks/libancillary.git - branch = shadowsocks-android [submodule "core/src/main/jni/libevent"] path = core/src/main/jni/libevent url = https://github.com/shadowsocks/libevent.git @@ -17,22 +10,12 @@ path = core/src/main/jni/redsocks url = https://github.com/shadowsocks/redsocks.git branch = shadowsocks-android -[submodule "core/src/main/jni/mbedtls"] - path = core/src/main/jni/mbedtls - url = https://github.com/ARMmbed/mbedtls -[submodule "core/src/main/jni/pcre"] - path = core/src/main/jni/pcre - url = https://android.googlesource.com/platform/external/pcre -[submodule "core/src/main/jni/libsodium"] - path = core/src/main/jni/libsodium - url = https://github.com/jedisct1/libsodium.git - branch = stable -[submodule "core/src/main/jni/libev"] - path = core/src/main/jni/libev - url = https://git.lighttpd.net/libev.git [submodule "core/src/main/jni/re2"] path = core/src/main/jni/re2 url = https://github.com/google/re2.git -[submodule "core/shadowsocks-rust"] - path = core/shadowsocks-rust +[submodule "core/src/main/rust"] + path = core/src/main/rust url = https://github.com/madeye/shadowsocks-rust +[submodule "core/src/main/jni/libancillary"] + path = core/src/main/jni/libancillary + url = https://github.com/shadowsocks/libancillary.git diff --git a/build.gradle b/build.gradle index b9c99a0e26..9b92fc85c1 100644 --- a/build.gradle +++ b/build.gradle @@ -14,6 +14,7 @@ buildscript { junitVersion = '4.13' androidTestVersion = '1.2.0' androidEspressoVersion = '3.2.0' + ndkVersion = '21.0.6113669' versionCode = 5000550 versionName = '5.0.5-nightly' resConfigs = ['ar', 'es', 'fa', 'fr', 'ja', 'ko', 'ru', 'tr', 'zh-rCN', 'zh-rTW'] diff --git a/core/build.gradle b/core/build.gradle index 0c20f50c25..60c3471806 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -45,6 +45,8 @@ android { sourceSets { androidTest.assets.srcDirs += files("$projectDir/schemas".toString()) } + + ndkVersion rootProject.ndkVersion } androidExtensions { @@ -52,7 +54,7 @@ androidExtensions { } cargo { - module = 'shadowsocks-rust' + module = 'src/main/rust' libname = 'sslocal' targets = ['arm', 'arm64', 'x86', 'x86_64'] profile = 'release' @@ -66,8 +68,6 @@ cargo { } } -preBuild.dependsOn "cargoBuild" - def coroutinesVersion = '1.3.3' def roomVersion = '2.2.3' def workVersion = '2.3.1' diff --git a/core/src/main/java/com/github/shadowsocks/bg/Executable.kt b/core/src/main/java/com/github/shadowsocks/bg/Executable.kt index 01c97419b4..0e6136d6c2 100644 --- a/core/src/main/java/com/github/shadowsocks/bg/Executable.kt +++ b/core/src/main/java/com/github/shadowsocks/bg/Executable.kt @@ -31,7 +31,7 @@ import java.io.IOException object Executable { const val REDSOCKS = "libredsocks.so" - const val SS_LOCAL = "libss-local.so" + const val SS_LOCAL = "libsslocal.so" const val TUN2SOCKS = "libtun2socks.so" private val EXECUTABLES = setOf(SS_LOCAL, REDSOCKS, TUN2SOCKS) diff --git a/core/src/main/java/com/github/shadowsocks/bg/ProxyInstance.kt b/core/src/main/java/com/github/shadowsocks/bg/ProxyInstance.kt index 488bc8ace4..3f62de71a3 100644 --- a/core/src/main/java/com/github/shadowsocks/bg/ProxyInstance.kt +++ b/core/src/main/java/com/github/shadowsocks/bg/ProxyInstance.kt @@ -115,13 +115,12 @@ class ProxyInstance(val profile: Profile, private val route: String = profile.ro this.configFile = configFile val config = profile.toJson() plugin?.let { (path, opts) -> config.put("plugin", path).put("plugin_opts", opts.toString()) } + config.put("local_addr", DataStore.listenAddress) + config.put("local_port", DataStore.portProxy) configFile.writeText(config.toString()) val cmd = service.buildAdditionalArguments(arrayListOf( File((service as Context).applicationInfo.nativeLibraryDir, Executable.SS_LOCAL).absolutePath, - "-b", DataStore.listenAddress, - "-l", DataStore.portProxy.toString(), - "-t", "600", "-S", stat.absolutePath, "-c", configFile.absolutePath)) if (extraFlag != null) cmd.add(extraFlag) diff --git a/core/src/main/jni/Android.mk b/core/src/main/jni/Android.mk index f8549e58c6..ecf283d2dd 100755 --- a/core/src/main/jni/Android.mk +++ b/core/src/main/jni/Android.mk @@ -18,93 +18,6 @@ ROOT_PATH := $(LOCAL_PATH) BUILD_SHARED_EXECUTABLE := $(LOCAL_PATH)/build-shared-executable.mk -######################################################## -## libsodium -######################################################## - -include $(CLEAR_VARS) - -SODIUM_SOURCE := \ - crypto_aead/aes256gcm/aesni/aead_aes256gcm_aesni.c \ - crypto_aead/chacha20poly1305/sodium/aead_chacha20poly1305.c \ - crypto_aead/xchacha20poly1305/sodium/aead_xchacha20poly1305.c \ - crypto_core/ed25519/ref10/ed25519_ref10.c \ - crypto_core/hchacha20/core_hchacha20.c \ - crypto_core/salsa/ref/core_salsa_ref.c \ - crypto_generichash/blake2b/ref/blake2b-compress-ref.c \ - crypto_generichash/blake2b/ref/blake2b-ref.c \ - crypto_generichash/blake2b/ref/generichash_blake2b.c \ - crypto_onetimeauth/poly1305/onetimeauth_poly1305.c \ - crypto_onetimeauth/poly1305/donna/poly1305_donna.c \ - crypto_pwhash/crypto_pwhash.c \ - crypto_pwhash/argon2/argon2-core.c \ - crypto_pwhash/argon2/argon2.c \ - crypto_pwhash/argon2/argon2-encoding.c \ - crypto_pwhash/argon2/argon2-fill-block-ref.c \ - crypto_pwhash/argon2/blake2b-long.c \ - crypto_pwhash/argon2/pwhash_argon2i.c \ - crypto_scalarmult/curve25519/scalarmult_curve25519.c \ - crypto_scalarmult/curve25519/ref10/x25519_ref10.c \ - crypto_stream/chacha20/stream_chacha20.c \ - crypto_stream/chacha20/ref/chacha20_ref.c \ - crypto_stream/salsa20/stream_salsa20.c \ - crypto_stream/salsa20/ref/salsa20_ref.c \ - crypto_verify/sodium/verify.c \ - randombytes/randombytes.c \ - randombytes/sysrandom/randombytes_sysrandom.c \ - sodium/core.c \ - sodium/runtime.c \ - sodium/utils.c \ - sodium/version.c - -LOCAL_MODULE := sodium -LOCAL_CFLAGS += -I$(LOCAL_PATH)/libsodium/src/libsodium/include \ - -I$(LOCAL_PATH)/include \ - -I$(LOCAL_PATH)/include/sodium \ - -I$(LOCAL_PATH)/libsodium/src/libsodium/include/sodium \ - -DPACKAGE_NAME=\"libsodium\" -DPACKAGE_TARNAME=\"libsodium\" \ - -DPACKAGE_VERSION=\"1.0.15\" -DPACKAGE_STRING=\"libsodium-1.0.15\" \ - -DPACKAGE_BUGREPORT=\"https://github.com/jedisct1/libsodium/issues\" \ - -DPACKAGE_URL=\"https://github.com/jedisct1/libsodium\" \ - -DPACKAGE=\"libsodium\" -DVERSION=\"1.0.15\" \ - -DHAVE_PTHREAD=1 \ - -DSTDC_HEADERS=1 \ - -DHAVE_SYS_TYPES_H=1 \ - -DHAVE_SYS_STAT_H=1 \ - -DHAVE_STDLIB_H=1 \ - -DHAVE_STRING_H=1 \ - -DHAVE_MEMORY_H=1 \ - -DHAVE_STRINGS_H=1 \ - -DHAVE_INTTYPES_H=1 \ - -DHAVE_STDINT_H=1 \ - -DHAVE_UNISTD_H=1 \ - -D__EXTENSIONS__=1 \ - -D_ALL_SOURCE=1 \ - -D_GNU_SOURCE=1 \ - -D_POSIX_PTHREAD_SEMANTICS=1 \ - -D_TANDEM_SOURCE=1 \ - -DHAVE_DLFCN_H=1 \ - -DLT_OBJDIR=\".libs/\" \ - -DHAVE_SYS_MMAN_H=1 \ - -DNATIVE_LITTLE_ENDIAN=1 \ - -DASM_HIDE_SYMBOL=.hidden \ - -DHAVE_WEAK_SYMBOLS=1 \ - -DHAVE_ATOMIC_OPS=1 \ - -DHAVE_ARC4RANDOM=1 \ - -DHAVE_ARC4RANDOM_BUF=1 \ - -DHAVE_MMAP=1 \ - -DHAVE_MLOCK=1 \ - -DHAVE_MADVISE=1 \ - -DHAVE_MPROTECT=1 \ - -DHAVE_NANOSLEEP=1 \ - -DHAVE_POSIX_MEMALIGN=1 \ - -DHAVE_GETPID=1 \ - -DCONFIGURED=1 - -LOCAL_SRC_FILES := $(addprefix libsodium/src/libsodium/,$(SODIUM_SOURCE)) - -include $(BUILD_STATIC_LIBRARY) - ######################################################## ## libevent ######################################################## @@ -138,87 +51,6 @@ LOCAL_SRC_FILES := $(addprefix libancillary/, $(ANCILLARY_SOURCE)) include $(BUILD_STATIC_LIBRARY) -######################################################## -## libbloom -######################################################## - -include $(CLEAR_VARS) - -BLOOM_SOURCE := bloom.c murmur2/MurmurHash2.c - -LOCAL_MODULE := libbloom -LOCAL_CFLAGS += -I$(LOCAL_PATH)/shadowsocks-libev/libbloom \ - -I$(LOCAL_PATH)/shadowsocks-libev/libbloom/murmur2 - -LOCAL_SRC_FILES := $(addprefix shadowsocks-libev/libbloom/, $(BLOOM_SOURCE)) - -include $(BUILD_STATIC_LIBRARY) - -######################################################## -## libipset -######################################################## - -include $(CLEAR_VARS) - -bdd_src = bdd/assignments.c bdd/basics.c bdd/bdd-iterator.c bdd/expanded.c \ - bdd/reachable.c bdd/read.c bdd/write.c -map_src = map/allocation.c map/inspection.c map/ipv4_map.c map/ipv6_map.c \ - map/storage.c -set_src = set/allocation.c set/inspection.c set/ipv4_set.c set/ipv6_set.c \ - set/iterator.c set/storage.c - -IPSET_SOURCE := general.c $(bdd_src) $(map_src) $(set_src) - -LOCAL_MODULE := libipset -LOCAL_CFLAGS += -I$(LOCAL_PATH)/shadowsocks-libev/libipset/include \ - -I$(LOCAL_PATH)/shadowsocks-libev/libcork/include - -LOCAL_SRC_FILES := $(addprefix shadowsocks-libev/libipset/src/libipset/,$(IPSET_SOURCE)) - -include $(BUILD_STATIC_LIBRARY) - -######################################################## -## libcork -######################################################## - -include $(CLEAR_VARS) - -cli_src := cli/commands.c -core_src := core/allocator.c core/error.c core/gc.c \ - core/hash.c core/ip-address.c core/mempool.c \ - core/timestamp.c core/u128.c -ds_src := ds/array.c ds/bitset.c ds/buffer.c ds/dllist.c \ - ds/file-stream.c ds/hash-table.c ds/managed-buffer.c \ - ds/ring-buffer.c ds/slice.c -posix_src := posix/directory-walker.c posix/env.c posix/exec.c \ - posix/files.c posix/process.c posix/subprocess.c -pthreads_src := pthreads/thread.c - -CORK_SOURCE := $(cli_src) $(core_src) $(ds_src) $(posix_src) $(pthreads_src) - -LOCAL_MODULE := libcork -LOCAL_CFLAGS += -I$(LOCAL_PATH)/shadowsocks-libev/libcork/include \ - -DCORK_API=CORK_LOCAL - -LOCAL_SRC_FILES := $(addprefix shadowsocks-libev/libcork/src/libcork/,$(CORK_SOURCE)) - -include $(BUILD_STATIC_LIBRARY) - -######################################################## -## libev -######################################################## - -include $(CLEAR_VARS) - -LOCAL_MODULE := libev -LOCAL_CFLAGS += -DNDEBUG -DHAVE_CONFIG_H \ - -I$(LOCAL_PATH)/include/libev -LOCAL_SRC_FILES := \ - libev/ev.c \ - libev/event.c - -include $(BUILD_STATIC_LIBRARY) - ######################################################## ## redsocks ######################################################## @@ -233,7 +65,7 @@ REDSOCKS_SOURCES := base.c http-connect.c \ LOCAL_STATIC_LIBRARIES := libevent LOCAL_MODULE := redsocks -LOCAL_SRC_FILES := $(addprefix redsocks/, $(REDSOCKS_SOURCES)) +LOCAL_SRC_FILES := $(addprefix redsocks/, $(REDSOCKS_SOURCES)) LOCAL_CFLAGS := -std=gnu99 -DUSE_IPTABLES \ -I$(LOCAL_PATH)/redsocks \ -I$(LOCAL_PATH)/libevent/include \ @@ -241,43 +73,6 @@ LOCAL_CFLAGS := -std=gnu99 -DUSE_IPTABLES \ include $(BUILD_SHARED_EXECUTABLE) -######################################################## -## shadowsocks-libev local -######################################################## - -include $(CLEAR_VARS) - -SHADOWSOCKS_SOURCES := local.c \ - cache.c udprelay.c utils.c netutils.c json.c jconf.c \ - acl.c http.c tls.c rule.c \ - crypto.c aead.c stream.c base64.c \ - plugin.c ppbloom.c \ - android.c - -LOCAL_MODULE := ss-local -LOCAL_SRC_FILES := $(addprefix shadowsocks-libev/src/, $(SHADOWSOCKS_SOURCES)) -LOCAL_CFLAGS := -Wall -fno-strict-aliasing -DMODULE_LOCAL \ - -DUSE_CRYPTO_MBEDTLS -DHAVE_CONFIG_H \ - -DCONNECT_IN_PROGRESS=EINPROGRESS \ - -I$(LOCAL_PATH)/include/shadowsocks-libev \ - -I$(LOCAL_PATH)/include \ - -I$(LOCAL_PATH)/libancillary \ - -I$(LOCAL_PATH)/mbedtls/include \ - -I$(LOCAL_PATH)/pcre \ - -I$(LOCAL_PATH)/libsodium/src/libsodium/include \ - -I$(LOCAL_PATH)/libsodium/src/libsodium/include/sodium \ - -I$(LOCAL_PATH)/shadowsocks-libev/libcork/include \ - -I$(LOCAL_PATH)/shadowsocks-libev/libipset/include \ - -I$(LOCAL_PATH)/shadowsocks-libev/libbloom \ - -I$(LOCAL_PATH)/libev - -LOCAL_STATIC_LIBRARIES := libev libmbedtls libipset libcork libbloom \ - libsodium libancillary libpcre - -LOCAL_LDLIBS := -llog - -include $(BUILD_SHARED_EXECUTABLE) - ######################################################## ## jni-helper ######################################################## @@ -404,57 +199,3 @@ LOCAL_LDLIBS := -ldl -llog LOCAL_SRC_FILES := $(addprefix badvpn/, $(TUN2SOCKS_SOURCES)) include $(BUILD_SHARED_EXECUTABLE) - -######################################################## -## mbed TLS -######################################################## - -include $(CLEAR_VARS) - -LOCAL_MODULE := mbedtls - -LOCAL_C_INCLUDES := $(LOCAL_PATH)/mbedtls/include - -MBEDTLS_SOURCES := $(wildcard $(LOCAL_PATH)/mbedtls/library/*.c) - -LOCAL_SRC_FILES := $(MBEDTLS_SOURCES:$(LOCAL_PATH)/%=%) - -include $(BUILD_STATIC_LIBRARY) - -######################################################## -## pcre -######################################################## - -include $(CLEAR_VARS) - -LOCAL_MODULE := pcre - -LOCAL_CFLAGS += -DHAVE_CONFIG_H - -LOCAL_C_INCLUDES := $(LOCAL_PATH)/pcre/dist $(LOCAL_PATH)/pcre - -libpcre_src_files := \ - dist/pcre_byte_order.c \ - dist/pcre_compile.c \ - dist/pcre_config.c \ - dist/pcre_dfa_exec.c \ - dist/pcre_exec.c \ - dist/pcre_fullinfo.c \ - dist/pcre_get.c \ - dist/pcre_globals.c \ - dist/pcre_jit_compile.c \ - dist/pcre_maketables.c \ - dist/pcre_newline.c \ - dist/pcre_ord2utf8.c \ - dist/pcre_refcount.c \ - dist/pcre_string_utils.c \ - dist/pcre_study.c \ - dist/pcre_tables.c \ - dist/pcre_ucd.c \ - dist/pcre_valid_utf8.c \ - dist/pcre_version.c \ - dist/pcre_xclass.c - -LOCAL_SRC_FILES := $(addprefix pcre/, $(libpcre_src_files)) $(LOCAL_PATH)/patch/pcre/pcre_chartables.c - -include $(BUILD_STATIC_LIBRARY) diff --git a/core/src/main/jni/libev b/core/src/main/jni/libev deleted file mode 160000 index 31ca40b7a1..0000000000 --- a/core/src/main/jni/libev +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 31ca40b7a18ed424213a4ecba0d57706ed3e56a0 diff --git a/core/src/main/jni/libsodium b/core/src/main/jni/libsodium deleted file mode 160000 index b732443c44..0000000000 --- a/core/src/main/jni/libsodium +++ /dev/null @@ -1 +0,0 @@ -Subproject commit b732443c442239c2e0184820e9b23cca0de0828c diff --git a/core/src/main/jni/mbedtls b/core/src/main/jni/mbedtls deleted file mode 160000 index 9f4f8eec93..0000000000 --- a/core/src/main/jni/mbedtls +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 9f4f8eec93dd1f32d78e0bcceddbef0ca570e66f diff --git a/core/src/main/jni/pcre b/core/src/main/jni/pcre deleted file mode 160000 index 222bbf4b3f..0000000000 --- a/core/src/main/jni/pcre +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 222bbf4b3fb8e13c21686803e47e31aa3e4ad130 diff --git a/core/src/main/jni/shadowsocks-libev b/core/src/main/jni/shadowsocks-libev deleted file mode 160000 index 6b5025bf74..0000000000 --- a/core/src/main/jni/shadowsocks-libev +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 6b5025bf741cff93212ba048353eb3d2c02b5c46 diff --git a/core/shadowsocks-rust b/core/src/main/rust similarity index 100% rename from core/shadowsocks-rust rename to core/src/main/rust diff --git a/mobile/build.gradle b/mobile/build.gradle index 2a33042c93..a6447cda17 100644 --- a/mobile/build.gradle +++ b/mobile/build.gradle @@ -54,6 +54,7 @@ android { } sourceSets.main.jniLibs.srcDirs += new File(project(':core').buildDir, "intermediates/bundles/${getCurrentFlavor()}/jni") + ndkVersion rootProject.ndkVersion } androidExtensions { diff --git a/tv/build.gradle b/tv/build.gradle index f13743846f..92fcaba0f4 100644 --- a/tv/build.gradle +++ b/tv/build.gradle @@ -53,6 +53,7 @@ android { } sourceSets.main.jniLibs.srcDirs += new File(project(':core').buildDir, "intermediates/bundles/${getCurrentFlavor()}/jni") + ndkVersion rootProject.ndkVersion } dependencies { From 608d022784727092421963fdb1b77ab2ea3ec8e2 Mon Sep 17 00:00:00 2001 From: Max Lv Date: Thu, 27 Feb 2020 14:16:27 +0800 Subject: [PATCH 07/57] Enable shadowsocks-rust --- core/build.gradle | 6 ++-- .../com/github/shadowsocks/bg/BaseService.kt | 4 +-- .../github/shadowsocks/bg/ProxyInstance.kt | 10 +++---- .../com/github/shadowsocks/bg/VpnService.kt | 5 ---- core/src/main/res/values/arrays.xml | 30 +------------------ core/src/main/rust | 2 +- 6 files changed, 11 insertions(+), 46 deletions(-) diff --git a/core/build.gradle b/core/build.gradle index 60c3471806..bef79877b0 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -57,14 +57,14 @@ cargo { module = 'src/main/rust' libname = 'sslocal' targets = ['arm', 'arm64', 'x86', 'x86_64'] - profile = 'release' + profile = 'debug' targetIncludes = ['libsslocal.so'] extraCargoBuildArguments = ['--bin', 'sslocal'] features { - noDefaultBut "sodium" + noDefaultBut "sodium", "android" } exec { spec, toolchain -> - spec.environment("RUSTFLAGS", "-C link-arg=-o -C link-arg=target/${toolchain.target}/release/libsslocal.so") + spec.environment("RUSTFLAGS", "-C link-arg=-o -C link-arg=target/${toolchain.target}/${profile}/libsslocal.so") } } diff --git a/core/src/main/java/com/github/shadowsocks/bg/BaseService.kt b/core/src/main/java/com/github/shadowsocks/bg/BaseService.kt index e46b56b217..bf471ded97 100644 --- a/core/src/main/java/com/github/shadowsocks/bg/BaseService.kt +++ b/core/src/main/java/com/github/shadowsocks/bg/BaseService.kt @@ -241,12 +241,12 @@ object BaseService { data.proxy!!.start(this, File(Core.deviceStorage.noBackupFilesDir, "stat_main"), File(configRoot, CONFIG_FILE), - if (udpFallback == null) "-u" else null) + if (udpFallback == null) "-U" else null) check(udpFallback?.plugin == null) { "UDP fallback cannot have plugins" } udpFallback?.start(this, File(Core.deviceStorage.noBackupFilesDir, "stat_udp"), File(configRoot, CONFIG_FILE_UDP), - "-U") + "-u") } fun startRunner() { diff --git a/core/src/main/java/com/github/shadowsocks/bg/ProxyInstance.kt b/core/src/main/java/com/github/shadowsocks/bg/ProxyInstance.kt index 3f62de71a3..d35d0d917d 100644 --- a/core/src/main/java/com/github/shadowsocks/bg/ProxyInstance.kt +++ b/core/src/main/java/com/github/shadowsocks/bg/ProxyInstance.kt @@ -115,13 +115,14 @@ class ProxyInstance(val profile: Profile, private val route: String = profile.ro this.configFile = configFile val config = profile.toJson() plugin?.let { (path, opts) -> config.put("plugin", path).put("plugin_opts", opts.toString()) } - config.put("local_addr", DataStore.listenAddress) + config.put("local_address", DataStore.listenAddress) config.put("local_port", DataStore.portProxy) configFile.writeText(config.toString()) val cmd = service.buildAdditionalArguments(arrayListOf( File((service as Context).applicationInfo.nativeLibraryDir, Executable.SS_LOCAL).absolutePath, - "-S", stat.absolutePath, + "--stat-path", stat.absolutePath, + "--protect-path", "protect_path", "-c", configFile.absolutePath)) if (extraFlag != null) cmd.add(extraFlag) @@ -130,10 +131,7 @@ class ProxyInstance(val profile: Profile, private val route: String = profile.ro cmd += Acl.getFile(route).absolutePath } - // for UDP profile, it's only going to operate in UDP relay mode-only so this flag has no effect - if (profile.route == Acl.ALL) cmd += "-D" - - if (DataStore.tcpFastOpen) cmd += "--fast-open" + // if (DataStore.tcpFastOpen) cmd += "--fast-open" service.data.processes!!.start(cmd) } diff --git a/core/src/main/java/com/github/shadowsocks/bg/VpnService.kt b/core/src/main/java/com/github/shadowsocks/bg/VpnService.kt index 1b238241f4..c68e3c5d44 100644 --- a/core/src/main/java/com/github/shadowsocks/bg/VpnService.kt +++ b/core/src/main/java/com/github/shadowsocks/bg/VpnService.kt @@ -151,11 +151,6 @@ class VpnService : BaseVpnService(), LocalDnsService.Interface { sendFd(startVpn()) } - override fun buildAdditionalArguments(cmd: ArrayList): ArrayList { - cmd += "-V" - return cmd - } - private suspend fun startVpn(): FileDescriptor { val profile = data.proxy!!.profile val builder = Builder() diff --git a/core/src/main/res/values/arrays.xml b/core/src/main/res/values/arrays.xml index 62398ca903..654a00867b 100644 --- a/core/src/main/res/values/arrays.xml +++ b/core/src/main/res/values/arrays.xml @@ -1,20 +1,6 @@ - RC4-MD5 - AES-128-CFB - AES-192-CFB - AES-256-CFB - AES-128-CTR - AES-192-CTR - AES-256-CTR - BF-CFB - CAMELLIA-128-CFB - CAMELLIA-192-CFB - CAMELLIA-256-CFB - SALSA20 - CHACHA20 - CHACHA20-IETF AES-128-GCM AES-192-GCM AES-256-GCM @@ -23,20 +9,6 @@ - rc4-md5 - aes-128-cfb - aes-192-cfb - aes-256-cfb - aes-128-ctr - aes-192-ctr - aes-256-ctr - bf-cfb - camellia-128-cfb - camellia-192-cfb - camellia-256-cfb - salsa20 - chacha20 - chacha20-ietf aes-128-gcm aes-192-gcm aes-256-gcm @@ -212,4 +184,4 @@ vpn transproxy - \ No newline at end of file + diff --git a/core/src/main/rust b/core/src/main/rust index a6bad0389f..71b29f66b0 160000 --- a/core/src/main/rust +++ b/core/src/main/rust @@ -1 +1 @@ -Subproject commit a6bad0389f44dec993afc39c71f1ddfe02b65fa9 +Subproject commit 71b29f66b06ec01e1f0747db0bb85676e0f1663c From c138232c376d73a5ece2e8a2e0ddf12ddca4cb8e Mon Sep 17 00:00:00 2001 From: Max Lv Date: Thu, 27 Feb 2020 16:51:21 +0800 Subject: [PATCH 08/57] Update docker image --- .circleci/config.yml | 2 +- core/src/main/res/values/arrays.xml | 2 ++ core/src/main/rust | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 32fac5fe5b..9ffbfd8e82 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,7 +3,7 @@ jobs: build: working_directory: ~/code docker: - - image: circleci/android:api-29-ndk + - image: shadowsocks/android-ndk-go:v1.0 environment: GRADLE_OPTS: -Dorg.gradle.workers.max=1 -Dorg.gradle.daemon=false -Dkotlin.compiler.execution.strategy="in-process" steps: diff --git a/core/src/main/res/values/arrays.xml b/core/src/main/res/values/arrays.xml index 654a00867b..549f460992 100644 --- a/core/src/main/res/values/arrays.xml +++ b/core/src/main/res/values/arrays.xml @@ -1,6 +1,7 @@ + PLAIN AES-128-GCM AES-192-GCM AES-256-GCM @@ -9,6 +10,7 @@ + plain aes-128-gcm aes-192-gcm aes-256-gcm diff --git a/core/src/main/rust b/core/src/main/rust index 71b29f66b0..b9f56a5677 160000 --- a/core/src/main/rust +++ b/core/src/main/rust @@ -1 +1 @@ -Subproject commit 71b29f66b06ec01e1f0747db0bb85676e0f1663c +Subproject commit b9f56a567770199fde78b1c6fe51b9c76acf479a From 8cad12a0295fc9198f8cc53277a57188870b4fe1 Mon Sep 17 00:00:00 2001 From: Max Lv Date: Thu, 27 Feb 2020 17:41:24 +0800 Subject: [PATCH 09/57] Update shadowsocks-rust --- core/src/main/rust | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/rust b/core/src/main/rust index b9f56a5677..8db01506d6 160000 --- a/core/src/main/rust +++ b/core/src/main/rust @@ -1 +1 @@ -Subproject commit b9f56a567770199fde78b1c6fe51b9c76acf479a +Subproject commit 8db01506d6c7b221abe6837417d8be87db1e7d7e From d46b3b3cd799e7fa16709f926a6b14d9971ee995 Mon Sep 17 00:00:00 2001 From: Max Lv Date: Thu, 27 Feb 2020 21:29:15 +0800 Subject: [PATCH 10/57] Remove aes-192-gcm --- core/src/main/res/values/arrays.xml | 2 -- 1 file changed, 2 deletions(-) diff --git a/core/src/main/res/values/arrays.xml b/core/src/main/res/values/arrays.xml index 549f460992..2a85add47c 100644 --- a/core/src/main/res/values/arrays.xml +++ b/core/src/main/res/values/arrays.xml @@ -3,7 +3,6 @@ PLAIN AES-128-GCM - AES-192-GCM AES-256-GCM CHACHA20-IETF-POLY1305 XCHACHA20-IETF-POLY1305 @@ -12,7 +11,6 @@ plain aes-128-gcm - aes-192-gcm aes-256-gcm chacha20-ietf-poly1305 xchacha20-ietf-poly1305 From 616603a25723603e4bbaab19fea035c6273be5e7 Mon Sep 17 00:00:00 2001 From: Max Lv Date: Fri, 28 Feb 2020 12:25:27 +0800 Subject: [PATCH 11/57] Fix the plugin issue --- .../src/main/java/com/github/shadowsocks/bg/BaseService.kt | 2 +- .../main/java/com/github/shadowsocks/bg/ProxyInstance.kt | 7 ++++--- core/src/main/java/com/github/shadowsocks/bg/VpnService.kt | 2 ++ core/src/main/rust | 2 +- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/com/github/shadowsocks/bg/BaseService.kt b/core/src/main/java/com/github/shadowsocks/bg/BaseService.kt index bf471ded97..78618b2d97 100644 --- a/core/src/main/java/com/github/shadowsocks/bg/BaseService.kt +++ b/core/src/main/java/com/github/shadowsocks/bg/BaseService.kt @@ -232,7 +232,7 @@ object BaseService { } } - fun buildAdditionalArguments(cmd: ArrayList): ArrayList = cmd + fun isVpnService(): Boolean = false suspend fun startProcesses(hosts: HostsFile) { val configRoot = (if (Build.VERSION.SDK_INT < 24 || app.getSystemService() diff --git a/core/src/main/java/com/github/shadowsocks/bg/ProxyInstance.kt b/core/src/main/java/com/github/shadowsocks/bg/ProxyInstance.kt index d35d0d917d..6ebb234cae 100644 --- a/core/src/main/java/com/github/shadowsocks/bg/ProxyInstance.kt +++ b/core/src/main/java/com/github/shadowsocks/bg/ProxyInstance.kt @@ -114,16 +114,17 @@ class ProxyInstance(val profile: Profile, private val route: String = profile.ro this.configFile = configFile val config = profile.toJson() - plugin?.let { (path, opts) -> config.put("plugin", path).put("plugin_opts", opts.toString()) } + val vpnFlags = if (service.isVpnService()) ";V" else "" + plugin?.let { (path, opts) -> config.put("plugin", path).put("plugin_opts", opts.toString() + vpnFlags) } config.put("local_address", DataStore.listenAddress) config.put("local_port", DataStore.portProxy) configFile.writeText(config.toString()) - val cmd = service.buildAdditionalArguments(arrayListOf( + val cmd = (arrayListOf( File((service as Context).applicationInfo.nativeLibraryDir, Executable.SS_LOCAL).absolutePath, "--stat-path", stat.absolutePath, - "--protect-path", "protect_path", "-c", configFile.absolutePath)) + if (service.isVpnService()) cmd += arrayListOf("--protect-path", "protect_path") if (extraFlag != null) cmd.add(extraFlag) if (route != Acl.ALL) { diff --git a/core/src/main/java/com/github/shadowsocks/bg/VpnService.kt b/core/src/main/java/com/github/shadowsocks/bg/VpnService.kt index c68e3c5d44..144506e132 100644 --- a/core/src/main/java/com/github/shadowsocks/bg/VpnService.kt +++ b/core/src/main/java/com/github/shadowsocks/bg/VpnService.kt @@ -151,6 +151,8 @@ class VpnService : BaseVpnService(), LocalDnsService.Interface { sendFd(startVpn()) } + override fun isVpnService(): Boolean = true + private suspend fun startVpn(): FileDescriptor { val profile = data.proxy!!.profile val builder = Builder() diff --git a/core/src/main/rust b/core/src/main/rust index 8db01506d6..f39954ac74 160000 --- a/core/src/main/rust +++ b/core/src/main/rust @@ -1 +1 @@ -Subproject commit 8db01506d6c7b221abe6837417d8be87db1e7d7e +Subproject commit f39954ac74d6e7a5343a07610c1dd156c0d60fab From 95ab2cd506226574f9ef54d664703a2f6e96f164 Mon Sep 17 00:00:00 2001 From: Max Lv Date: Fri, 28 Feb 2020 19:46:02 +0800 Subject: [PATCH 12/57] Make Codacy happy --- core/src/main/java/com/github/shadowsocks/bg/ProxyInstance.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/com/github/shadowsocks/bg/ProxyInstance.kt b/core/src/main/java/com/github/shadowsocks/bg/ProxyInstance.kt index 6ebb234cae..6cfe313ed3 100644 --- a/core/src/main/java/com/github/shadowsocks/bg/ProxyInstance.kt +++ b/core/src/main/java/com/github/shadowsocks/bg/ProxyInstance.kt @@ -120,10 +120,10 @@ class ProxyInstance(val profile: Profile, private val route: String = profile.ro config.put("local_port", DataStore.portProxy) configFile.writeText(config.toString()) - val cmd = (arrayListOf( + val cmd = arrayListOf( File((service as Context).applicationInfo.nativeLibraryDir, Executable.SS_LOCAL).absolutePath, "--stat-path", stat.absolutePath, - "-c", configFile.absolutePath)) + "-c", configFile.absolutePath) if (service.isVpnService()) cmd += arrayListOf("--protect-path", "protect_path") if (extraFlag != null) cmd.add(extraFlag) From ab6887d8445ba0852b6fcafc6ad5efc1a0d83f9a Mon Sep 17 00:00:00 2001 From: Max Lv Date: Sat, 29 Feb 2020 11:01:24 +0800 Subject: [PATCH 13/57] Get openssl works now --- core/build.gradle | 2 +- core/src/main/res/values/arrays.xml | 30 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/core/build.gradle b/core/build.gradle index bef79877b0..7a1dcdebe8 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -61,7 +61,7 @@ cargo { targetIncludes = ['libsslocal.so'] extraCargoBuildArguments = ['--bin', 'sslocal'] features { - noDefaultBut "sodium", "android" + noDefaultBut "sodium", "android", "rc4", "aes-cfb", "aes-ctr", "camellia-cfb", "openssl-vendored" } exec { spec, toolchain -> spec.environment("RUSTFLAGS", "-C link-arg=-o -C link-arg=target/${toolchain.target}/${profile}/libsslocal.so") diff --git a/core/src/main/res/values/arrays.xml b/core/src/main/res/values/arrays.xml index 2a85add47c..37d0095104 100644 --- a/core/src/main/res/values/arrays.xml +++ b/core/src/main/res/values/arrays.xml @@ -2,7 +2,22 @@ PLAIN + RC4-MD5 + AES-128-CFB + AES-192-CFB + AES-256-CFB + AES-128-CTR + AES-192-CTR + AES-256-CTR + BF-CFB + CAMELLIA-128-CFB + CAMELLIA-192-CFB + CAMELLIA-256-CFB + SALSA20 + CHACHA20 + CHACHA20-IETF AES-128-GCM + AES-192-GCM AES-256-GCM CHACHA20-IETF-POLY1305 XCHACHA20-IETF-POLY1305 @@ -10,7 +25,22 @@ plain + rc4-md5 + aes-128-cfb + aes-192-cfb + aes-256-cfb + aes-128-ctr + aes-192-ctr + aes-256-ctr + bf-cfb + camellia-128-cfb + camellia-192-cfb + camellia-256-cfb + salsa20 + chacha20 + chacha20-ietf aes-128-gcm + aes-192-gcm aes-256-gcm chacha20-ietf-poly1305 xchacha20-ietf-poly1305 From 4afd71f836d23cea41e48c6a7a3798954064145b Mon Sep 17 00:00:00 2001 From: Mygod Date: Sun, 1 Mar 2020 01:07:40 +0000 Subject: [PATCH 14/57] Fix rust not building by default --- .gitmodules | 4 ++-- build.gradle | 6 +++--- core/build.gradle | 20 +++++++++++--------- gradle/wrapper/gradle-wrapper.properties | 2 +- mobile/build.gradle | 2 +- 5 files changed, 18 insertions(+), 16 deletions(-) diff --git a/.gitmodules b/.gitmodules index c65a7e8f8b..1417093c26 100644 --- a/.gitmodules +++ b/.gitmodules @@ -13,8 +13,8 @@ [submodule "core/src/main/jni/re2"] path = core/src/main/jni/re2 url = https://github.com/google/re2.git -[submodule "core/src/main/rust"] - path = core/src/main/rust +[submodule "core/src/main/rust/shadowsocks-rust"] + path = core/src/main/rust/shadowsocks-rust url = https://github.com/madeye/shadowsocks-rust [submodule "core/src/main/jni/libancillary"] path = core/src/main/jni/libancillary diff --git a/build.gradle b/build.gradle index 9b92fc85c1..2dbdd805b9 100644 --- a/build.gradle +++ b/build.gradle @@ -32,12 +32,12 @@ buildscript { } dependencies { - classpath 'gradle.plugin.org.mozilla.rust-android-gradle:plugin:0.8.3' - classpath 'com.android.tools.build:gradle:4.0.0-alpha09' - classpath 'com.github.ben-manes:gradle-versions-plugin:0.27.0' + classpath 'com.android.tools.build:gradle:4.0.0-beta01' + classpath 'com.github.ben-manes:gradle-versions-plugin:0.28.0' classpath 'com.google.android.gms:oss-licenses-plugin:0.9.5' classpath 'com.google.gms:google-services:4.3.3' classpath 'com.vanniktech:gradle-maven-publish-plugin:0.9.0' + classpath 'gradle.plugin.org.mozilla.rust-android-gradle:plugin:0.8.3' classpath 'io.fabric.tools:gradle:1.31.2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion" } diff --git a/core/build.gradle b/core/build.gradle index 7a1dcdebe8..ebc886a133 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -54,26 +54,28 @@ androidExtensions { } cargo { - module = 'src/main/rust' + module = 'src/main/rust/shadowsocks-rust' libname = 'sslocal' targets = ['arm', 'arm64', 'x86', 'x86_64'] profile = 'debug' - targetIncludes = ['libsslocal.so'] + targetIncludes = ["lib${libname}.so"] extraCargoBuildArguments = ['--bin', 'sslocal'] features { noDefaultBut "sodium", "android", "rc4", "aes-cfb", "aes-ctr", "camellia-cfb", "openssl-vendored" } exec { spec, toolchain -> - spec.environment("RUSTFLAGS", "-C link-arg=-o -C link-arg=target/${toolchain.target}/${profile}/libsslocal.so") + spec.environment("RUSTFLAGS", "-C link-arg=-o -C link-arg=target/${toolchain.target}/$profile/lib${libname}.so") } } +preBuild.dependsOn "cargoBuild" + def coroutinesVersion = '1.3.3' -def roomVersion = '2.2.3' -def workVersion = '2.3.1' +def roomVersion = '2.2.4' +def workVersion = '2.3.2' dependencies { api project(':plugin') - api 'androidx.fragment:fragment-ktx:1.2.1' + api 'androidx.fragment:fragment-ktx:1.2.2' api "androidx.lifecycle:lifecycle-common-java8:$lifecycleVersion" api "androidx.lifecycle:lifecycle-livedata-core-ktx:$lifecycleVersion" api 'androidx.preference:preference:1.1.0' @@ -83,9 +85,9 @@ dependencies { api 'com.crashlytics.sdk.android:crashlytics:2.10.1' api 'com.google.android.gms:play-services-oss-licenses:17.0.0' api 'com.google.code.gson:gson:2.8.6' - api 'com.google.firebase:firebase-analytics:17.2.2' - api 'com.google.firebase:firebase-config:19.1.1' - api 'dnsjava:dnsjava:2.1.9' + api 'com.google.firebase:firebase-analytics:17.2.3' + api 'com.google.firebase:firebase-config:19.1.2' + api 'dnsjava:dnsjava:3.0.0' api "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutinesVersion" api "org.jetbrains.kotlinx:kotlinx-coroutines-play-services:$coroutinesVersion" api 'org.connectbot.jsocks:jsocks:1.0.0' diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 4e1cc9db6b..6254d2d4ae 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.2.1-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/mobile/build.gradle b/mobile/build.gradle index a6447cda17..dd34d94070 100644 --- a/mobile/build.gradle +++ b/mobile/build.gradle @@ -72,7 +72,7 @@ dependencies { implementation 'com.google.zxing:core:3.4.0' implementation 'com.takisoft.preferencex:preferencex-simplemenu:1.1.0' implementation 'com.twofortyfouram:android-plugin-api-for-locale:1.0.4' - implementation 'me.zhanghai.android.fastscroll:library:1.1.0' + implementation 'me.zhanghai.android.fastscroll:library:1.1.1' implementation 'xyz.belvi.mobilevision:barcodescanner:2.0.3' testImplementation "junit:junit:$junitVersion" androidTestImplementation "androidx.test:runner:$androidTestVersion" From c80a24aa1a910da194f5b991565662bf04ba9992 Mon Sep 17 00:00:00 2001 From: Max Lv Date: Sun, 1 Mar 2020 01:38:02 +0000 Subject: [PATCH 15/57] Use thin LTO --- core/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/build.gradle b/core/build.gradle index ebc886a133..9a2f236231 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -57,14 +57,14 @@ cargo { module = 'src/main/rust/shadowsocks-rust' libname = 'sslocal' targets = ['arm', 'arm64', 'x86', 'x86_64'] - profile = 'debug' + profile = 'release' targetIncludes = ["lib${libname}.so"] extraCargoBuildArguments = ['--bin', 'sslocal'] features { noDefaultBut "sodium", "android", "rc4", "aes-cfb", "aes-ctr", "camellia-cfb", "openssl-vendored" } exec { spec, toolchain -> - spec.environment("RUSTFLAGS", "-C link-arg=-o -C link-arg=target/${toolchain.target}/$profile/lib${libname}.so") + spec.environment("RUSTFLAGS", "-C lto=thin -C link-arg=-o -C link-arg=target/${toolchain.target}/$profile/lib${libname}.so") } } From 9e0a863bd02864d46bc7b94a8061c9e9f2319c6d Mon Sep 17 00:00:00 2001 From: Max Lv Date: Sun, 1 Mar 2020 09:44:53 +0800 Subject: [PATCH 16/57] Move the submodule --- core/src/main/rust | 1 - core/src/main/rust/shadowsocks-rust | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) delete mode 160000 core/src/main/rust create mode 160000 core/src/main/rust/shadowsocks-rust diff --git a/core/src/main/rust b/core/src/main/rust deleted file mode 160000 index f39954ac74..0000000000 --- a/core/src/main/rust +++ /dev/null @@ -1 +0,0 @@ -Subproject commit f39954ac74d6e7a5343a07610c1dd156c0d60fab diff --git a/core/src/main/rust/shadowsocks-rust b/core/src/main/rust/shadowsocks-rust new file mode 160000 index 0000000000..9b7f63ac13 --- /dev/null +++ b/core/src/main/rust/shadowsocks-rust @@ -0,0 +1 @@ +Subproject commit 9b7f63ac13a937f6bf132e7fee4695b5ef9eaa21 From ad868f54a16375a0fa5be026d67a5f0bd1dfdd7c Mon Sep 17 00:00:00 2001 From: Max Lv Date: Sun, 1 Mar 2020 10:09:34 +0800 Subject: [PATCH 17/57] Disable lto totally --- core/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/build.gradle b/core/build.gradle index 9a2f236231..81154bd177 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -64,7 +64,7 @@ cargo { noDefaultBut "sodium", "android", "rc4", "aes-cfb", "aes-ctr", "camellia-cfb", "openssl-vendored" } exec { spec, toolchain -> - spec.environment("RUSTFLAGS", "-C lto=thin -C link-arg=-o -C link-arg=target/${toolchain.target}/$profile/lib${libname}.so") + spec.environment("RUSTFLAGS", "-C lto=no -C link-arg=-o -C link-arg=target/${toolchain.target}/$profile/lib${libname}.so") } } From 347d00fb62d0ced9e4c5171746720400ab7fcb28 Mon Sep 17 00:00:00 2001 From: Mygod Date: Sun, 1 Mar 2020 02:36:22 +0000 Subject: [PATCH 18/57] Add draft impl for local_dns_path --- .../shadowsocks/bg/DnsResolverCompat.kt | 42 +++++++++++++ .../com/github/shadowsocks/bg/VpnService.kt | 61 +++++++++++++++---- .../github/shadowsocks/net/LocalDnsServer.kt | 31 +++++----- 3 files changed, 107 insertions(+), 27 deletions(-) diff --git a/core/src/main/java/com/github/shadowsocks/bg/DnsResolverCompat.kt b/core/src/main/java/com/github/shadowsocks/bg/DnsResolverCompat.kt index c4790ad4dc..f29e3c0ee9 100644 --- a/core/src/main/java/com/github/shadowsocks/bg/DnsResolverCompat.kt +++ b/core/src/main/java/com/github/shadowsocks/bg/DnsResolverCompat.kt @@ -31,13 +31,19 @@ import android.system.ErrnoException import android.system.Os import android.system.OsConstants import com.github.shadowsocks.Core +import com.github.shadowsocks.net.LocalDnsServer import com.github.shadowsocks.utils.closeQuietly import com.github.shadowsocks.utils.int import com.github.shadowsocks.utils.parseNumericAddress import com.github.shadowsocks.utils.printLog import kotlinx.coroutines.* +import org.xbill.DNS.Message +import org.xbill.DNS.Opcode +import org.xbill.DNS.Type import java.io.FileDescriptor import java.io.IOException +import java.net.Inet4Address +import java.net.Inet6Address import java.net.InetAddress import java.util.concurrent.Executor import java.util.concurrent.Executors @@ -94,6 +100,7 @@ sealed class DnsResolverCompat { override fun bindSocket(network: Network, socket: FileDescriptor) = instance.bindSocket(network, socket) override suspend fun resolve(network: Network, host: String) = instance.resolve(network, host) override suspend fun resolveOnActiveNetwork(host: String) = instance.resolveOnActiveNetwork(host) + override suspend fun resolveRaw(network: Network, query: ByteArray) = instance.resolveRaw(network, query) } @Throws(IOException::class) @@ -102,6 +109,7 @@ sealed class DnsResolverCompat { Os.connect(fd, address, port) abstract suspend fun resolve(network: Network, host: String): Array abstract suspend fun resolveOnActiveNetwork(host: String): Array + abstract suspend fun resolveRaw(network: Network, query: ByteArray): ByteArray @SuppressLint("PrivateApi") private open class DnsResolverCompat21 : DnsResolverCompat() { @@ -138,6 +146,28 @@ sealed class DnsResolverCompat { GlobalScope.async(unboundedIO) { network.getAllByName(host) }.await() override suspend fun resolveOnActiveNetwork(host: String) = GlobalScope.async(unboundedIO) { InetAddress.getAllByName(host) }.await() + + override suspend fun resolveRaw(network: Network, query: ByteArray): ByteArray { + val request = try { + Message(query) + } catch (e: IOException) { + throw UnsupportedOperationException(e) // unrecognized packet + } + when (val opcode = request.header.opcode) { + Opcode.QUERY -> { } + else -> throw UnsupportedOperationException("Unsupported opcode $opcode") + } + val question = request.question + val isIpv6 = when (val type = question?.type) { + Type.A -> false + Type.AAAA -> true + else -> throw UnsupportedOperationException("Unsupported query type $type") + } + val host = question.name.canonicalize().toString(true) + return LocalDnsServer.cookDnsResponse(request, resolve(network, host).asIterable().run { + if (isIpv6) filterIsInstance() else filterIsInstance() + }) + } } @TargetApi(23) @@ -171,5 +201,17 @@ sealed class DnsResolverCompat { override suspend fun resolveOnActiveNetwork(host: String): Array { return resolve(Core.connectivity.activeNetwork ?: return emptyArray(), host) } + + override suspend fun resolveRaw(network: Network, query: ByteArray): ByteArray { + return suspendCancellableCoroutine { cont -> + val signal = CancellationSignal() + cont.invokeOnCancellation { signal.cancel() } + DnsResolver.getInstance().rawQuery(network, query, DnsResolver.FLAG_NO_RETRY, this, + signal, object : DnsResolver.Callback { + override fun onAnswer(answer: ByteArray, rcode: Int) = cont.resume(answer) + override fun onError(error: DnsResolver.DnsException) = cont.resumeWithException(IOException(error)) + }) + } + } } } diff --git a/core/src/main/java/com/github/shadowsocks/bg/VpnService.kt b/core/src/main/java/com/github/shadowsocks/bg/VpnService.kt index 144506e132..d3c271c524 100644 --- a/core/src/main/java/com/github/shadowsocks/bg/VpnService.kt +++ b/core/src/main/java/com/github/shadowsocks/bg/VpnService.kt @@ -30,27 +30,23 @@ import android.os.Build import android.os.ParcelFileDescriptor import android.system.ErrnoException import android.system.OsConstants +import android.util.Log +import com.crashlytics.android.Crashlytics import com.github.shadowsocks.Core import com.github.shadowsocks.VpnRequestActivity import com.github.shadowsocks.acl.Acl import com.github.shadowsocks.core.R -import com.github.shadowsocks.net.ConcurrentLocalSocketListener -import com.github.shadowsocks.net.DefaultNetworkListener -import com.github.shadowsocks.net.HostsFile -import com.github.shadowsocks.net.Subnet +import com.github.shadowsocks.net.* import com.github.shadowsocks.preference.DataStore import com.github.shadowsocks.utils.Key import com.github.shadowsocks.utils.closeQuietly import com.github.shadowsocks.utils.int import com.github.shadowsocks.utils.printLog -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.delay -import kotlinx.coroutines.launch -import java.io.File -import java.io.FileDescriptor -import java.io.IOException +import kotlinx.coroutines.* +import org.xbill.DNS.Message +import org.xbill.DNS.Rcode +import java.io.* import java.net.URL -import java.util.* import android.net.VpnService as BaseVpnService class VpnService : BaseVpnService(), LocalDnsService.Interface { @@ -91,6 +87,45 @@ class VpnService : BaseVpnService(), LocalDnsService.Interface { } } + private inner class LocalDnsWorker : ConcurrentLocalSocketListener("LocalDnsThread", + File(Core.deviceStorage.noBackupFilesDir, "local_dns_path")), CoroutineScope { + override fun acceptInternal(socket: LocalSocket) = error("big no no") + override fun accept(socket: LocalSocket) { + launch { + socket.use { + val input = DataInputStream(socket.inputStream) + while (true) { + val length = try { + input.readUnsignedShort() + } catch (_: EOFException) { + break + } + val query = ByteArray(length) + input.read(query) + try { + DnsResolverCompat.resolveRaw(underlyingNetwork ?: throw IOException("no network"), query) + } catch (e: Exception) { + when (e) { + is TimeoutCancellationException -> Crashlytics.log(Log.WARN, name, "Resolving timed out") + is CancellationException -> { } // ignore + is IOException -> Crashlytics.log(Log.WARN, name, e.message) + else -> printLog(e) + } + try { + LocalDnsServer.prepareDnsResponse(Message(query)).apply { + header.rcode = Rcode.SERVFAIL + }.toWire() + } catch (e: Exception) { + printLog(e) + null + } + }?.let { response -> socket.outputStream.write(response) } + } + } + } + } + } + inner class NullConnectionException : NullPointerException(), BaseService.ExpectedException { override fun getLocalizedMessage() = getString(R.string.reboot_required) } @@ -102,6 +137,7 @@ class VpnService : BaseVpnService(), LocalDnsService.Interface { private var conn: ParcelFileDescriptor? = null private var worker: ProtectWorker? = null + private var localDns: LocalDnsWorker? = null private var active = false private var metered = false private var underlyingNetwork: Network? = null @@ -126,6 +162,8 @@ class VpnService : BaseVpnService(), LocalDnsService.Interface { scope.launch { DefaultNetworkListener.stop(this) } worker?.shutdown(scope) worker = null + localDns?.shutdown(scope) + localDns = null conn?.close() conn = null } @@ -147,6 +185,7 @@ class VpnService : BaseVpnService(), LocalDnsService.Interface { override suspend fun startProcesses(hosts: HostsFile) { worker = ProtectWorker().apply { start() } + localDns = LocalDnsWorker().apply { start() } super.startProcesses(hosts) sendFd(startVpn()) } diff --git a/core/src/main/java/com/github/shadowsocks/net/LocalDnsServer.kt b/core/src/main/java/com/github/shadowsocks/net/LocalDnsServer.kt index 9bfc5aa2d2..d3ad8ad042 100644 --- a/core/src/main/java/com/github/shadowsocks/net/LocalDnsServer.kt +++ b/core/src/main/java/com/github/shadowsocks/net/LocalDnsServer.kt @@ -62,21 +62,20 @@ class LocalDnsServer(private val localResolver: suspend (String) -> Array) = - ByteBuffer.wrap(prepareDnsResponse(request).apply { - header.setFlag(Flags.RA.toInt()) // recursion available - for (address in results) addRecord(when (address) { - is Inet4Address -> ARecord(question.name, DClass.IN, TTL, address) - is Inet6Address -> AAAARecord(question.name, DClass.IN, TTL, address) - else -> error("Unsupported address $address") - }, Section.ANSWER) - }.toWire()) + fun cookDnsResponse(request: Message, results: Iterable) = prepareDnsResponse(request).apply { + header.setFlag(Flags.RA.toInt()) // recursion available + for (address in results) addRecord(when (address) { + is Inet4Address -> ARecord(question.name, DClass.IN, TTL, address) + is Inet6Address -> AAAARecord(question.name, DClass.IN, TTL, address) + else -> error("Unsupported address $address") + }, Section.ANSWER) + }.toWire() } private val monitor = ChannelMonitor() @@ -127,9 +126,9 @@ class LocalDnsServer(private val localResolver: suspend (String) -> Array() else filterIsInstance() - }) + })) } val acl = acl?.await() ?: return@supervisorScope remote.await() val useLocal = when (acl.shouldBypass(host)) { @@ -147,17 +146,17 @@ class LocalDnsServer(private val localResolver: suspend (String) -> Array() - if (useLocal) return@supervisorScope cookDnsResponse(request, filtered) + if (useLocal) return@supervisorScope ByteBuffer.wrap(cookDnsResponse(request, filtered)) if (filtered.any { acl.shouldBypassIpv6(it.address) }) { remote.cancel() - cookDnsResponse(request, filtered) + ByteBuffer.wrap(cookDnsResponse(request, filtered)) } else remote.await() } else { val filtered = localResults.filterIsInstance() - if (useLocal) return@supervisorScope cookDnsResponse(request, filtered) + if (useLocal) return@supervisorScope ByteBuffer.wrap(cookDnsResponse(request, filtered)) if (filtered.any { acl.shouldBypassIpv4(it.address) }) { remote.cancel() - cookDnsResponse(request, filtered) + ByteBuffer.wrap(cookDnsResponse(request, filtered)) } else remote.await() } } catch (e: Exception) { From 281935960e8b00b5cae355add447888440bcabfa Mon Sep 17 00:00:00 2001 From: Mygod Date: Sun, 1 Mar 2020 02:42:02 +0000 Subject: [PATCH 19/57] Fix local_dns_path blocking --- .../com/github/shadowsocks/bg/VpnService.kt | 43 +++++++++---------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/core/src/main/java/com/github/shadowsocks/bg/VpnService.kt b/core/src/main/java/com/github/shadowsocks/bg/VpnService.kt index d3c271c524..7cf64c2051 100644 --- a/core/src/main/java/com/github/shadowsocks/bg/VpnService.kt +++ b/core/src/main/java/com/github/shadowsocks/bg/VpnService.kt @@ -94,32 +94,29 @@ class VpnService : BaseVpnService(), LocalDnsService.Interface { launch { socket.use { val input = DataInputStream(socket.inputStream) - while (true) { - val length = try { - input.readUnsignedShort() - } catch (_: EOFException) { - break + val query = ByteArray(input.readUnsignedShort()) + input.read(query) + try { + DnsResolverCompat.resolveRaw(underlyingNetwork ?: throw IOException("no network"), query) + } catch (e: Exception) { + when (e) { + is TimeoutCancellationException -> Crashlytics.log(Log.WARN, name, "Resolving timed out") + is CancellationException -> { } // ignore + is IOException -> Crashlytics.log(Log.WARN, name, e.message) + else -> printLog(e) } - val query = ByteArray(length) - input.read(query) try { - DnsResolverCompat.resolveRaw(underlyingNetwork ?: throw IOException("no network"), query) + LocalDnsServer.prepareDnsResponse(Message(query)).apply { + header.rcode = Rcode.SERVFAIL + }.toWire() } catch (e: Exception) { - when (e) { - is TimeoutCancellationException -> Crashlytics.log(Log.WARN, name, "Resolving timed out") - is CancellationException -> { } // ignore - is IOException -> Crashlytics.log(Log.WARN, name, e.message) - else -> printLog(e) - } - try { - LocalDnsServer.prepareDnsResponse(Message(query)).apply { - header.rcode = Rcode.SERVFAIL - }.toWire() - } catch (e: Exception) { - printLog(e) - null - } - }?.let { response -> socket.outputStream.write(response) } + printLog(e) + null + } + }?.let { response -> + val output = DataOutputStream(socket.outputStream) + output.writeShort(response.size) + output.write(response) } } } From a3a70f0d3c874dd4f0ed41b63bf25768da6c89fe Mon Sep 17 00:00:00 2001 From: Max Lv Date: Sun, 1 Mar 2020 13:39:46 +0800 Subject: [PATCH 20/57] Update shadowsocks-rust --- core/src/main/rust/shadowsocks-rust | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/rust/shadowsocks-rust b/core/src/main/rust/shadowsocks-rust index 9b7f63ac13..9a9cf76e89 160000 --- a/core/src/main/rust/shadowsocks-rust +++ b/core/src/main/rust/shadowsocks-rust @@ -1 +1 @@ -Subproject commit 9b7f63ac13a937f6bf132e7fee4695b5ef9eaa21 +Subproject commit 9a9cf76e892db52869bb4a90c7656571cbdfd5f4 From 1ff8174e00343c921c6b30d334918d433603429e Mon Sep 17 00:00:00 2001 From: Max Lv Date: Sun, 1 Mar 2020 18:23:10 +0800 Subject: [PATCH 21/57] Refine command line interface --- .circleci/config.yml | 2 +- core/src/main/java/com/github/shadowsocks/bg/BaseService.kt | 2 +- .../src/main/java/com/github/shadowsocks/bg/ProxyInstance.kt | 5 ++--- core/src/main/java/com/github/shadowsocks/bg/VpnService.kt | 2 +- core/src/main/rust/shadowsocks-rust | 2 +- 5 files changed, 6 insertions(+), 7 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 9ffbfd8e82..77e765f0df 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -13,7 +13,7 @@ jobs: key: jars-{{ checksum "build.gradle" }} - run: name: Run Build and Tests - command: ./gradlew cargoBuild && ./gradlew assembleDebug check + command: ./gradlew assembleDebug check - save_cache: paths: - ~/.gradle diff --git a/core/src/main/java/com/github/shadowsocks/bg/BaseService.kt b/core/src/main/java/com/github/shadowsocks/bg/BaseService.kt index 78618b2d97..aa394b48ad 100644 --- a/core/src/main/java/com/github/shadowsocks/bg/BaseService.kt +++ b/core/src/main/java/com/github/shadowsocks/bg/BaseService.kt @@ -232,7 +232,7 @@ object BaseService { } } - fun isVpnService(): Boolean = false + val isVpnService get() = false suspend fun startProcesses(hosts: HostsFile) { val configRoot = (if (Build.VERSION.SDK_INT < 24 || app.getSystemService() diff --git a/core/src/main/java/com/github/shadowsocks/bg/ProxyInstance.kt b/core/src/main/java/com/github/shadowsocks/bg/ProxyInstance.kt index 6cfe313ed3..af89c8978f 100644 --- a/core/src/main/java/com/github/shadowsocks/bg/ProxyInstance.kt +++ b/core/src/main/java/com/github/shadowsocks/bg/ProxyInstance.kt @@ -114,7 +114,7 @@ class ProxyInstance(val profile: Profile, private val route: String = profile.ro this.configFile = configFile val config = profile.toJson() - val vpnFlags = if (service.isVpnService()) ";V" else "" + val vpnFlags = if (service.isVpnService) ";V" else "" plugin?.let { (path, opts) -> config.put("plugin", path).put("plugin_opts", opts.toString() + vpnFlags) } config.put("local_address", DataStore.listenAddress) config.put("local_port", DataStore.portProxy) @@ -122,9 +122,8 @@ class ProxyInstance(val profile: Profile, private val route: String = profile.ro val cmd = arrayListOf( File((service as Context).applicationInfo.nativeLibraryDir, Executable.SS_LOCAL).absolutePath, - "--stat-path", stat.absolutePath, "-c", configFile.absolutePath) - if (service.isVpnService()) cmd += arrayListOf("--protect-path", "protect_path") + if (service.isVpnService) cmd += arrayListOf("--vpn") if (extraFlag != null) cmd.add(extraFlag) if (route != Acl.ALL) { diff --git a/core/src/main/java/com/github/shadowsocks/bg/VpnService.kt b/core/src/main/java/com/github/shadowsocks/bg/VpnService.kt index 7cf64c2051..52986e01d3 100644 --- a/core/src/main/java/com/github/shadowsocks/bg/VpnService.kt +++ b/core/src/main/java/com/github/shadowsocks/bg/VpnService.kt @@ -187,7 +187,7 @@ class VpnService : BaseVpnService(), LocalDnsService.Interface { sendFd(startVpn()) } - override fun isVpnService(): Boolean = true + override val isVpnService get() = true private suspend fun startVpn(): FileDescriptor { val profile = data.proxy!!.profile diff --git a/core/src/main/rust/shadowsocks-rust b/core/src/main/rust/shadowsocks-rust index 9a9cf76e89..ce05fb8ad5 160000 --- a/core/src/main/rust/shadowsocks-rust +++ b/core/src/main/rust/shadowsocks-rust @@ -1 +1 @@ -Subproject commit 9a9cf76e892db52869bb4a90c7656571cbdfd5f4 +Subproject commit ce05fb8ad50c69976b7e63b713c32d8ed164250d From 5fed95f98c26c822ac3a9134b6f3f6bb719bf7c5 Mon Sep 17 00:00:00 2001 From: Max Lv Date: Sun, 1 Mar 2020 19:45:28 +0800 Subject: [PATCH 22/57] Make lint happy --- core/build.gradle | 4 ++++ mobile/build.gradle | 3 +++ .../main/java/com/github/shadowsocks/ProfileConfigFragment.kt | 4 ++-- .../github/shadowsocks/subscription/SubscriptionFragment.kt | 2 +- tv/build.gradle | 3 +++ 5 files changed, 13 insertions(+), 3 deletions(-) diff --git a/core/build.gradle b/core/build.gradle index 81154bd177..b71b080657 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -47,6 +47,10 @@ android { } ndkVersion rootProject.ndkVersion + + lintOptions { + disable 'InvalidPackage' + } } androidExtensions { diff --git a/mobile/build.gradle b/mobile/build.gradle index dd34d94070..8fee3c2076 100644 --- a/mobile/build.gradle +++ b/mobile/build.gradle @@ -55,6 +55,9 @@ android { sourceSets.main.jniLibs.srcDirs += new File(project(':core').buildDir, "intermediates/bundles/${getCurrentFlavor()}/jni") ndkVersion rootProject.ndkVersion + lintOptions { + disable 'InvalidPackage' + } } androidExtensions { diff --git a/mobile/src/main/java/com/github/shadowsocks/ProfileConfigFragment.kt b/mobile/src/main/java/com/github/shadowsocks/ProfileConfigFragment.kt index 8071e97e77..3ae7224c64 100644 --- a/mobile/src/main/java/com/github/shadowsocks/ProfileConfigFragment.kt +++ b/mobile/src/main/java/com/github/shadowsocks/ProfileConfigFragment.kt @@ -177,7 +177,7 @@ class ProfileConfigFragment : PreferenceFragmentCompat(), DataStore.dirty = true true } catch (exc: RuntimeException) { - Snackbar.make(view!!, exc.readableMessage, Snackbar.LENGTH_LONG).show() + Snackbar.make(requireView(), exc.readableMessage, Snackbar.LENGTH_LONG).show() false } @@ -217,7 +217,7 @@ class ProfileConfigFragment : PreferenceFragmentCompat(), plugin.value = pluginConfiguration.selected pluginConfigure.isEnabled = selected !is NoPlugin pluginConfigure.text = pluginConfiguration.getOptions().toString() - if (!selected.trusted) Snackbar.make(view!!, R.string.plugin_untrusted, Snackbar.LENGTH_LONG).show() + if (!selected.trusted) Snackbar.make(requireView(), R.string.plugin_untrusted, Snackbar.LENGTH_LONG).show() } REQUEST_CODE_PLUGIN_CONFIGURE -> when (resultCode) { Activity.RESULT_OK -> { diff --git a/mobile/src/main/java/com/github/shadowsocks/subscription/SubscriptionFragment.kt b/mobile/src/main/java/com/github/shadowsocks/subscription/SubscriptionFragment.kt index 786ed0585a..72171b241b 100644 --- a/mobile/src/main/java/com/github/shadowsocks/subscription/SubscriptionFragment.kt +++ b/mobile/src/main/java/com/github/shadowsocks/subscription/SubscriptionFragment.kt @@ -220,7 +220,7 @@ class SubscriptionFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener toolbar.setTitle(R.string.subscriptions) toolbar.inflateMenu(R.menu.subscription_menu) toolbar.setOnMenuItemClickListener(this) - SubscriptionService.idle.observe(this) { + SubscriptionService.idle.observe(viewLifecycleOwner) { toolbar.menu.findItem(R.id.action_update_subscription).isEnabled = it } val activity = activity as MainActivity diff --git a/tv/build.gradle b/tv/build.gradle index 92fcaba0f4..bfc02191cc 100644 --- a/tv/build.gradle +++ b/tv/build.gradle @@ -54,6 +54,9 @@ android { sourceSets.main.jniLibs.srcDirs += new File(project(':core').buildDir, "intermediates/bundles/${getCurrentFlavor()}/jni") ndkVersion rootProject.ndkVersion + lintOptions { + disable 'InvalidPackage' + } } dependencies { From be4d03672a53aaacd1714858d943e83d81e85e40 Mon Sep 17 00:00:00 2001 From: Max Lv Date: Tue, 3 Mar 2020 08:56:33 +0800 Subject: [PATCH 23/57] Fix traffic stat report --- core/build.gradle | 2 +- core/src/main/java/com/github/shadowsocks/bg/ProxyInstance.kt | 1 + core/src/main/rust/shadowsocks-rust | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/core/build.gradle b/core/build.gradle index b71b080657..9f6134729b 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -65,7 +65,7 @@ cargo { targetIncludes = ["lib${libname}.so"] extraCargoBuildArguments = ['--bin', 'sslocal'] features { - noDefaultBut "sodium", "android", "rc4", "aes-cfb", "aes-ctr", "camellia-cfb", "openssl-vendored" + noDefaultBut "sodium", "rc4", "aes-cfb", "aes-ctr", "camellia-cfb", "openssl-vendored" } exec { spec, toolchain -> spec.environment("RUSTFLAGS", "-C lto=no -C link-arg=-o -C link-arg=target/${toolchain.target}/$profile/lib${libname}.so") diff --git a/core/src/main/java/com/github/shadowsocks/bg/ProxyInstance.kt b/core/src/main/java/com/github/shadowsocks/bg/ProxyInstance.kt index af89c8978f..03e38c67dc 100644 --- a/core/src/main/java/com/github/shadowsocks/bg/ProxyInstance.kt +++ b/core/src/main/java/com/github/shadowsocks/bg/ProxyInstance.kt @@ -122,6 +122,7 @@ class ProxyInstance(val profile: Profile, private val route: String = profile.ro val cmd = arrayListOf( File((service as Context).applicationInfo.nativeLibraryDir, Executable.SS_LOCAL).absolutePath, + "--stat-path", stat.absolutePath, "-c", configFile.absolutePath) if (service.isVpnService) cmd += arrayListOf("--vpn") if (extraFlag != null) cmd.add(extraFlag) diff --git a/core/src/main/rust/shadowsocks-rust b/core/src/main/rust/shadowsocks-rust index ce05fb8ad5..8b836065d2 160000 --- a/core/src/main/rust/shadowsocks-rust +++ b/core/src/main/rust/shadowsocks-rust @@ -1 +1 @@ -Subproject commit ce05fb8ad50c69976b7e63b713c32d8ed164250d +Subproject commit 8b836065d26f1fc6e3f51fc47e4622ac61017ea3 From 2eb9adb32862e0801e1b7f8ebcf6f7916cafb9fe Mon Sep 17 00:00:00 2001 From: Max Lv Date: Fri, 13 Mar 2020 19:57:25 +0800 Subject: [PATCH 24/57] Integrate DNS relay --- build.gradle | 6 +- .../github/shadowsocks/bg/LocalDnsService.kt | 17 +-- .../github/shadowsocks/bg/ProxyInstance.kt | 9 ++ .../github/shadowsocks/net/LocalDnsServer.kt | 138 ++++++------------ core/src/main/rust/shadowsocks-rust | 2 +- 5 files changed, 59 insertions(+), 113 deletions(-) diff --git a/build.gradle b/build.gradle index 2dbdd805b9..f999d90199 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ apply plugin: 'com.github.ben-manes.versions' buildscript { ext { javaVersion = JavaVersion.VERSION_1_8 - kotlinVersion = '1.3.61' + kotlinVersion = '1.3.70' minSdkVersion = 21 sdkVersion = 29 compileSdkVersion = 29 @@ -32,9 +32,9 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:4.0.0-beta01' + classpath 'com.android.tools.build:gradle:4.0.0-beta02' classpath 'com.github.ben-manes:gradle-versions-plugin:0.28.0' - classpath 'com.google.android.gms:oss-licenses-plugin:0.9.5' + classpath 'com.google.android.gms:oss-licenses-plugin:0.10.2' classpath 'com.google.gms:google-services:4.3.3' classpath 'com.vanniktech:gradle-maven-publish-plugin:0.9.0' classpath 'gradle.plugin.org.mozilla.rust-android-gradle:plugin:0.8.3' diff --git a/core/src/main/java/com/github/shadowsocks/bg/LocalDnsService.kt b/core/src/main/java/com/github/shadowsocks/bg/LocalDnsService.kt index f5979c5e71..753ee8135b 100644 --- a/core/src/main/java/com/github/shadowsocks/bg/LocalDnsService.kt +++ b/core/src/main/java/com/github/shadowsocks/bg/LocalDnsService.kt @@ -38,22 +38,9 @@ object LocalDnsService { interface Interface : BaseService.Interface { override suspend fun startProcesses(hosts: HostsFile) { super.startProcesses(hosts) - val profile = data.proxy!!.profile - val dns = try { - URI("dns://${profile.remoteDns}") - } catch (e: URISyntaxException) { - throw BaseService.ExpectedExceptionWrapper(e) - } - LocalDnsServer(this::resolver, - Socks5Endpoint(dns.host, if (dns.port < 0) 53 else dns.port), - DataStore.proxyAddress, - hosts, - !profile.udpdns, - if (profile.route == Acl.ALL) null else object { - suspend fun createAcl() = AclMatcher().apply { init(profile.route) } - }::createAcl).also { + LocalDnsServer(this::resolver, hosts).also { servers[this] = it - }.start(InetSocketAddress(DataStore.listenAddress, DataStore.portLocalDns)) + }.start(InetSocketAddress(DataStore.listenAddress, 8153)) } override fun killProcesses(scope: CoroutineScope) { diff --git a/core/src/main/java/com/github/shadowsocks/bg/ProxyInstance.kt b/core/src/main/java/com/github/shadowsocks/bg/ProxyInstance.kt index 03e38c67dc..e0bbd6ebac 100644 --- a/core/src/main/java/com/github/shadowsocks/bg/ProxyInstance.kt +++ b/core/src/main/java/com/github/shadowsocks/bg/ProxyInstance.kt @@ -120,9 +120,18 @@ class ProxyInstance(val profile: Profile, private val route: String = profile.ro config.put("local_port", DataStore.portProxy) configFile.writeText(config.toString()) + val dns = try { + URI("dns://${profile.remoteDns}") + } catch (e: URISyntaxException) { + throw BaseService.ExpectedExceptionWrapper(e) + } + val cmd = arrayListOf( File((service as Context).applicationInfo.nativeLibraryDir, Executable.SS_LOCAL).absolutePath, "--stat-path", stat.absolutePath, + "--dns-relay", "127.0.0.1:${DataStore.portLocalDns}", + "--remote-dns", "${dns.host}:${if (dns.port < 0) 53 else dns.port}", + "--local-dns", "127.0.0.1:8153", "-c", configFile.absolutePath) if (service.isVpnService) cmd += arrayListOf("--vpn") if (extraFlag != null) cmd.add(extraFlag) diff --git a/core/src/main/java/com/github/shadowsocks/net/LocalDnsServer.kt b/core/src/main/java/com/github/shadowsocks/net/LocalDnsServer.kt index d3ad8ad042..a5d77f4038 100644 --- a/core/src/main/java/com/github/shadowsocks/net/LocalDnsServer.kt +++ b/core/src/main/java/com/github/shadowsocks/net/LocalDnsServer.kt @@ -44,14 +44,7 @@ import java.nio.channels.SocketChannel * https://github.com/shadowsocks/overture/tree/874f22613c334a3b78e40155a55479b7b69fee04 */ class LocalDnsServer(private val localResolver: suspend (String) -> Array, - private val remoteDns: Socks5Endpoint, - private val proxy: SocketAddress, - private val hosts: HostsFile, - /** - * Forward UDP queries to TCP. - */ - private val tcp: Boolean = false, - aclSpawn: (suspend () -> AclMatcher)? = null) : CoroutineScope { + private val hosts: HostsFile) : CoroutineScope { companion object { private const val TAG = "LocalDnsServer" private const val TIMEOUT = 10_000L @@ -62,6 +55,10 @@ class LocalDnsServer(private val localResolver: suspend (String) -> Array Array if (t is IOException) Crashlytics.log(Log.WARN, TAG, t.message) else printLog(t) } - private val acl = aclSpawn?.let { async { it() } } suspend fun start(listen: SocketAddress) = DatagramChannel.open().run { configureBlocking(false) @@ -110,95 +106,50 @@ class LocalDnsServer(private val localResolver: suspend (String) -> Array false - Type.AAAA -> true - else -> return@supervisorScope remote.await() - } - val host = question.name.canonicalize().toString(true) - val hostsResults = hosts.resolve(host) - if (hostsResults.isNotEmpty()) { - remote.cancel() - return@supervisorScope ByteBuffer.wrap(cookDnsResponse(request, hostsResults.run { - if (isIpv6) filterIsInstance() else filterIsInstance() - })) - } - val acl = acl?.await() ?: return@supervisorScope remote.await() - val useLocal = when (acl.shouldBypass(host)) { - true -> true.also { remote.cancel() } - false -> return@supervisorScope remote.await() - null -> false - } - val localResults = try { - withTimeout(TIMEOUT) { localResolver(host) } - } catch (_: TimeoutCancellationException) { - Crashlytics.log(Log.WARN, TAG, "Local resolving timed out, falling back to remote resolving") - return@supervisorScope remote.await() - } catch (_: UnknownHostException) { - return@supervisorScope remote.await() - } - if (isIpv6) { - val filtered = localResults.filterIsInstance() - if (useLocal) return@supervisorScope ByteBuffer.wrap(cookDnsResponse(request, filtered)) - if (filtered.any { acl.shouldBypassIpv6(it.address) }) { - remote.cancel() - ByteBuffer.wrap(cookDnsResponse(request, filtered)) - } else remote.await() - } else { - val filtered = localResults.filterIsInstance() - if (useLocal) return@supervisorScope ByteBuffer.wrap(cookDnsResponse(request, filtered)) - if (filtered.any { acl.shouldBypassIpv4(it.address) }) { - remote.cancel() - ByteBuffer.wrap(cookDnsResponse(request, filtered)) - } else remote.await() - } - } catch (e: Exception) { - remote.cancel() - when (e) { - is TimeoutCancellationException -> Crashlytics.log(Log.WARN, TAG, "Remote resolving timed out") - is CancellationException -> { } // ignore - is IOException -> Crashlytics.log(Log.WARN, TAG, e.message) - else -> printLog(e) - } - ByteBuffer.wrap(prepareDnsResponse(request).apply { - header.rcode = Rcode.SERVFAIL - }.toWire()) - } + + val question = request.question + val isIpv6 = when (question?.type) { + Type.A -> false + Type.AAAA -> true + else -> return ByteBuffer.wrap(prepareDnsResponse(request).apply { + header.rcode = Rcode.SERVFAIL + }.toWire()) } - } + val host = question.name.canonicalize().toString(true) + val hostsResults = hosts.resolve(host) + if (hostsResults.isNotEmpty()) { + return ByteBuffer.wrap(cookDnsResponse(request, hostsResults.run { + if (isIpv6) filterIsInstance() else filterIsInstance() + })) + } + + Log.d("dns", "host: " + host) - private suspend fun forward(packet: ByteBuffer): ByteBuffer { - packet.position(0) // the packet might have been parsed, reset to beginning - return if (tcp) SocketChannel.open().use { channel -> - channel.configureBlocking(false) - channel.connect(proxy) - val wrapped = remoteDns.tcpWrap(packet) - while (!channel.finishConnect()) monitor.wait(channel, SelectionKey.OP_CONNECT) - while (channel.write(wrapped) >= 0 && wrapped.hasRemaining()) monitor.wait(channel, SelectionKey.OP_WRITE) - val result = remoteDns.tcpReceiveBuffer(UDP_PACKET_SIZE) - remoteDns.tcpUnwrap(result, channel::read) { monitor.wait(channel, SelectionKey.OP_READ) } - result - } else DatagramChannel.open().use { channel -> - channel.configureBlocking(false) - monitor.wait(channel, SelectionKey.OP_WRITE) - check(channel.send(remoteDns.udpWrap(packet), proxy) > 0) - val result = remoteDns.udpReceiveBuffer(UDP_PACKET_SIZE) - while (isActive) { - monitor.wait(channel, SelectionKey.OP_READ) - if (channel.receive(result) == proxy) break - result.clear() + val localResults = try { + withTimeout(TIMEOUT) { localResolver(host) } + } catch (e: java.lang.Exception) { + when (e) { + is TimeoutCancellationException -> Crashlytics.log(Log.WARN, TAG, "Remote resolving timed out") + is CancellationException -> { } // ignore + is IOException -> Crashlytics.log(Log.WARN, TAG, e.message) + else -> printLog(e) } - result.flip() - remoteDns.udpUnwrap(result) - result + return ByteBuffer.wrap(prepareDnsResponse(request).apply { + header.rcode = Rcode.SERVFAIL + }.toWire()) } + + val filtered = if (isIpv6) { + localResults.filterIsInstance() + } else { + localResults.filterIsInstance() + } + + return ByteBuffer.wrap(cookDnsResponse(request, filtered)) } fun shutdown(scope: CoroutineScope) { @@ -206,7 +157,6 @@ class LocalDnsServer(private val localResolver: suspend (String) -> Array Date: Fri, 13 Mar 2020 20:35:39 +0800 Subject: [PATCH 25/57] Update shadowsocks-rust --- core/src/main/rust/shadowsocks-rust | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/rust/shadowsocks-rust b/core/src/main/rust/shadowsocks-rust index 92fef6ed12..5cc84be32a 160000 --- a/core/src/main/rust/shadowsocks-rust +++ b/core/src/main/rust/shadowsocks-rust @@ -1 +1 @@ -Subproject commit 92fef6ed1204737f2a94fd6efefa8aeadbd4d648 +Subproject commit 5cc84be32a76dedd3263604fb7eff3d90345c733 From e2adca90b40731a68624171c42ed0226507b679e Mon Sep 17 00:00:00 2001 From: Max Lv Date: Sat, 14 Mar 2020 09:57:38 +0800 Subject: [PATCH 26/57] Fix remote DNS using domain name --- core/src/main/rust/shadowsocks-rust | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/rust/shadowsocks-rust b/core/src/main/rust/shadowsocks-rust index 5cc84be32a..fea5720157 160000 --- a/core/src/main/rust/shadowsocks-rust +++ b/core/src/main/rust/shadowsocks-rust @@ -1 +1 @@ -Subproject commit 5cc84be32a76dedd3263604fb7eff3d90345c733 +Subproject commit fea5720157c91ec10741d2d4cc05c90c8f0b8207 From 97a71a56559bc24e517a95ba76c5dbb8a02c702a Mon Sep 17 00:00:00 2001 From: Max Lv Date: Sat, 14 Mar 2020 10:34:02 +0800 Subject: [PATCH 27/57] Update shadowsocks-rust --- core/src/main/rust/shadowsocks-rust | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/rust/shadowsocks-rust b/core/src/main/rust/shadowsocks-rust index fea5720157..84c43062ef 160000 --- a/core/src/main/rust/shadowsocks-rust +++ b/core/src/main/rust/shadowsocks-rust @@ -1 +1 @@ -Subproject commit fea5720157c91ec10741d2d4cc05c90c8f0b8207 +Subproject commit 84c43062efe3adfcfa52f01475a58d43c9d28275 From a8caa108a50da658b4e71ff58044855fe02e9542 Mon Sep 17 00:00:00 2001 From: Max Lv Date: Sat, 14 Mar 2020 13:36:30 +0800 Subject: [PATCH 28/57] Fix bypass china mode --- core/src/main/rust/shadowsocks-rust | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/rust/shadowsocks-rust b/core/src/main/rust/shadowsocks-rust index 84c43062ef..69327737da 160000 --- a/core/src/main/rust/shadowsocks-rust +++ b/core/src/main/rust/shadowsocks-rust @@ -1 +1 @@ -Subproject commit 84c43062efe3adfcfa52f01475a58d43c9d28275 +Subproject commit 69327737dabbc5bf356b9c72ea9da693db81cc7f From 12e8fd38816a4044d8c3b9f167a4b9277fee91cc Mon Sep 17 00:00:00 2001 From: Max Lv Date: Sat, 14 Mar 2020 20:05:47 +0800 Subject: [PATCH 29/57] Update shadowsocks-rust --- core/src/main/rust/shadowsocks-rust | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/rust/shadowsocks-rust b/core/src/main/rust/shadowsocks-rust index 69327737da..7cc39f1553 160000 --- a/core/src/main/rust/shadowsocks-rust +++ b/core/src/main/rust/shadowsocks-rust @@ -1 +1 @@ -Subproject commit 69327737dabbc5bf356b9c72ea9da693db81cc7f +Subproject commit 7cc39f155355597bbe0bb66389921cb2fd3dedf2 From d8ce2b81348a3dcc57b8eeea4e82e232aad68212 Mon Sep 17 00:00:00 2001 From: Max Lv Date: Sun, 15 Mar 2020 08:27:20 +0800 Subject: [PATCH 30/57] Update shadowsocks-rust --- core/src/main/rust/shadowsocks-rust | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/rust/shadowsocks-rust b/core/src/main/rust/shadowsocks-rust index 7cc39f1553..bd2fe561bc 160000 --- a/core/src/main/rust/shadowsocks-rust +++ b/core/src/main/rust/shadowsocks-rust @@ -1 +1 @@ -Subproject commit 7cc39f155355597bbe0bb66389921cb2fd3dedf2 +Subproject commit bd2fe561bc1cb3e068387877035f3edae2774be2 From 7c35f25ef6f1c12de243a0a416712ce167300220 Mon Sep 17 00:00:00 2001 From: Max Lv Date: Mon, 16 Mar 2020 09:08:13 +0800 Subject: [PATCH 31/57] Use non-blocking UnixStream to send FDs --- core/src/main/rust/shadowsocks-rust | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/rust/shadowsocks-rust b/core/src/main/rust/shadowsocks-rust index bd2fe561bc..8d64cce45a 160000 --- a/core/src/main/rust/shadowsocks-rust +++ b/core/src/main/rust/shadowsocks-rust @@ -1 +1 @@ -Subproject commit bd2fe561bc1cb3e068387877035f3edae2774be2 +Subproject commit 8d64cce45aeb1ac6d18f52f89a5af62bd615da1b From e919a584599539bc611e5ad3097c2a3d05e4d82d Mon Sep 17 00:00:00 2001 From: Max Lv Date: Tue, 17 Mar 2020 10:46:54 +0800 Subject: [PATCH 32/57] Update shadowsocks-rust --- core/build.gradle | 2 +- core/src/main/rust/shadowsocks-rust | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/build.gradle b/core/build.gradle index 9f6134729b..99bb057873 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -65,7 +65,7 @@ cargo { targetIncludes = ["lib${libname}.so"] extraCargoBuildArguments = ['--bin', 'sslocal'] features { - noDefaultBut "sodium", "rc4", "aes-cfb", "aes-ctr", "camellia-cfb", "openssl-vendored" + noDefaultBut "sodium", "rc4", "aes-cfb", "aes-ctr", "camellia-cfb", "openssl-vendored", "local-flow-stat", "local-dns-relay" } exec { spec, toolchain -> spec.environment("RUSTFLAGS", "-C lto=no -C link-arg=-o -C link-arg=target/${toolchain.target}/$profile/lib${libname}.so") diff --git a/core/src/main/rust/shadowsocks-rust b/core/src/main/rust/shadowsocks-rust index 8d64cce45a..7ec11dfe17 160000 --- a/core/src/main/rust/shadowsocks-rust +++ b/core/src/main/rust/shadowsocks-rust @@ -1 +1 @@ -Subproject commit 8d64cce45aeb1ac6d18f52f89a5af62bd615da1b +Subproject commit 7ec11dfe1713424d064d0a136a1f1edf4795e30a From 253b4c7e76b7f6d7db05008afacd65f1f8a76f90 Mon Sep 17 00:00:00 2001 From: Max Lv Date: Sun, 22 Mar 2020 10:27:03 +0800 Subject: [PATCH 33/57] Clean up --- .../github/shadowsocks/bg/LocalDnsService.kt | 51 ------------------- .../shadowsocks/bg/TransproxyService.kt | 4 +- .../com/github/shadowsocks/bg/VpnService.kt | 6 +-- core/src/main/rust/shadowsocks-rust | 2 +- 4 files changed, 6 insertions(+), 57 deletions(-) delete mode 100644 core/src/main/java/com/github/shadowsocks/bg/LocalDnsService.kt diff --git a/core/src/main/java/com/github/shadowsocks/bg/LocalDnsService.kt b/core/src/main/java/com/github/shadowsocks/bg/LocalDnsService.kt deleted file mode 100644 index 753ee8135b..0000000000 --- a/core/src/main/java/com/github/shadowsocks/bg/LocalDnsService.kt +++ /dev/null @@ -1,51 +0,0 @@ -/******************************************************************************* - * * - * Copyright (C) 2017 by Max Lv * - * Copyright (C) 2017 by Mygod Studio * - * * - * This program is free software: you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation, either version 3 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program. If not, see . * - * * - *******************************************************************************/ - -package com.github.shadowsocks.bg - -import com.github.shadowsocks.acl.Acl -import com.github.shadowsocks.acl.AclMatcher -import com.github.shadowsocks.net.HostsFile -import com.github.shadowsocks.net.LocalDnsServer -import com.github.shadowsocks.net.Socks5Endpoint -import com.github.shadowsocks.preference.DataStore -import kotlinx.coroutines.CoroutineScope -import java.net.InetSocketAddress -import java.net.URI -import java.net.URISyntaxException -import java.util.* - -object LocalDnsService { - private val servers = WeakHashMap() - - interface Interface : BaseService.Interface { - override suspend fun startProcesses(hosts: HostsFile) { - super.startProcesses(hosts) - LocalDnsServer(this::resolver, hosts).also { - servers[this] = it - }.start(InetSocketAddress(DataStore.listenAddress, 8153)) - } - - override fun killProcesses(scope: CoroutineScope) { - servers.remove(this)?.shutdown(scope) - super.killProcesses(scope) - } - } -} diff --git a/core/src/main/java/com/github/shadowsocks/bg/TransproxyService.kt b/core/src/main/java/com/github/shadowsocks/bg/TransproxyService.kt index d3b6ff4325..ff30cf5329 100644 --- a/core/src/main/java/com/github/shadowsocks/bg/TransproxyService.kt +++ b/core/src/main/java/com/github/shadowsocks/bg/TransproxyService.kt @@ -27,7 +27,7 @@ import com.github.shadowsocks.net.HostsFile import com.github.shadowsocks.preference.DataStore import java.io.File -class TransproxyService : Service(), LocalDnsService.Interface { +class TransproxyService : Service(), BaseService.Interface { override val data = BaseService.Data(this) override val tag: String get() = "ShadowsocksTransproxyService" override fun createNotification(profileName: String): ServiceNotification = @@ -35,7 +35,7 @@ class TransproxyService : Service(), LocalDnsService.Interface { override fun onBind(intent: Intent) = super.onBind(intent) override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int = - super.onStartCommand(intent, flags, startId) + super.onStartCommand(intent, flags, startId) private fun startRedsocksDaemon() { File(Core.deviceStorage.noBackupFilesDir, "redsocks.conf").writeText("""base { diff --git a/core/src/main/java/com/github/shadowsocks/bg/VpnService.kt b/core/src/main/java/com/github/shadowsocks/bg/VpnService.kt index 52986e01d3..c956b54e1e 100644 --- a/core/src/main/java/com/github/shadowsocks/bg/VpnService.kt +++ b/core/src/main/java/com/github/shadowsocks/bg/VpnService.kt @@ -49,7 +49,7 @@ import java.io.* import java.net.URL import android.net.VpnService as BaseVpnService -class VpnService : BaseVpnService(), LocalDnsService.Interface { +class VpnService : BaseVpnService(), BaseService.Interface { companion object { private const val VPN_MTU = 1500 private const val PRIVATE_VLAN4_CLIENT = "172.19.0.1" @@ -148,7 +148,7 @@ class VpnService : BaseVpnService(), LocalDnsService.Interface { override fun onBind(intent: Intent) = when (intent.action) { SERVICE_INTERFACE -> super.onBind(intent) - else -> super.onBind(intent) + else -> super.onBind(intent) } override fun onRevoke() = stopRunner() @@ -169,7 +169,7 @@ class VpnService : BaseVpnService(), LocalDnsService.Interface { if (DataStore.serviceMode == Key.modeVpn) { if (prepare(this) != null) { startActivity(Intent(this, VpnRequestActivity::class.java).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)) - } else return super.onStartCommand(intent, flags, startId) + } else return super.onStartCommand(intent, flags, startId) } stopRunner() return Service.START_NOT_STICKY diff --git a/core/src/main/rust/shadowsocks-rust b/core/src/main/rust/shadowsocks-rust index 7ec11dfe17..63208f9411 160000 --- a/core/src/main/rust/shadowsocks-rust +++ b/core/src/main/rust/shadowsocks-rust @@ -1 +1 @@ -Subproject commit 7ec11dfe1713424d064d0a136a1f1edf4795e30a +Subproject commit 63208f941129c7338e54e6339d33ed01cdec6c6f From 1fc7f1442bf544550585a952234bc34ec4c95c12 Mon Sep 17 00:00:00 2001 From: Max Lv Date: Sun, 22 Mar 2020 10:35:20 +0800 Subject: [PATCH 34/57] Update shadowsocks-rust --- core/src/main/rust/shadowsocks-rust | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/rust/shadowsocks-rust b/core/src/main/rust/shadowsocks-rust index 63208f9411..e96f1beadd 160000 --- a/core/src/main/rust/shadowsocks-rust +++ b/core/src/main/rust/shadowsocks-rust @@ -1 +1 @@ -Subproject commit 63208f941129c7338e54e6339d33ed01cdec6c6f +Subproject commit e96f1beadd18dcadf18c2792cffe390b4f5a9c35 From 07bddef20ff33207235095ecb2b77fd3ff06455f Mon Sep 17 00:00:00 2001 From: Max Lv Date: Sun, 22 Mar 2020 10:46:03 +0800 Subject: [PATCH 35/57] Make codacy happy --- core/src/main/java/com/github/shadowsocks/bg/VpnService.kt | 6 +++++- .../java/com/github/shadowsocks/ProfileConfigFragment.kt | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/com/github/shadowsocks/bg/VpnService.kt b/core/src/main/java/com/github/shadowsocks/bg/VpnService.kt index c956b54e1e..542fcd8d44 100644 --- a/core/src/main/java/com/github/shadowsocks/bg/VpnService.kt +++ b/core/src/main/java/com/github/shadowsocks/bg/VpnService.kt @@ -110,7 +110,11 @@ class VpnService : BaseVpnService(), BaseService.Interface { header.rcode = Rcode.SERVFAIL }.toWire() } catch (e: Exception) { - printLog(e) + when (e) { + is CancellationException -> { } // ignore + is IOException -> Crashlytics.log(Log.WARN, name, e.message) + else -> printLog(e) + } null } }?.let { response -> diff --git a/mobile/src/main/java/com/github/shadowsocks/ProfileConfigFragment.kt b/mobile/src/main/java/com/github/shadowsocks/ProfileConfigFragment.kt index 3ae7224c64..838e932568 100644 --- a/mobile/src/main/java/com/github/shadowsocks/ProfileConfigFragment.kt +++ b/mobile/src/main/java/com/github/shadowsocks/ProfileConfigFragment.kt @@ -217,7 +217,9 @@ class ProfileConfigFragment : PreferenceFragmentCompat(), plugin.value = pluginConfiguration.selected pluginConfigure.isEnabled = selected !is NoPlugin pluginConfigure.text = pluginConfiguration.getOptions().toString() - if (!selected.trusted) Snackbar.make(requireView(), R.string.plugin_untrusted, Snackbar.LENGTH_LONG).show() + if (!selected.trusted) { + Snackbar.make(requireView(), R.string.plugin_untrusted, Snackbar.LENGTH_LONG).show() + } } REQUEST_CODE_PLUGIN_CONFIGURE -> when (resultCode) { Activity.RESULT_OK -> { From 2b4d045f0e1ec578d32e5a2d5604238fefe477c3 Mon Sep 17 00:00:00 2001 From: Max Lv Date: Sun, 22 Mar 2020 10:59:33 +0800 Subject: [PATCH 36/57] Remove the unnecessary try-catch --- .../java/com/github/shadowsocks/bg/VpnService.kt | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/core/src/main/java/com/github/shadowsocks/bg/VpnService.kt b/core/src/main/java/com/github/shadowsocks/bg/VpnService.kt index 542fcd8d44..25f3b946f8 100644 --- a/core/src/main/java/com/github/shadowsocks/bg/VpnService.kt +++ b/core/src/main/java/com/github/shadowsocks/bg/VpnService.kt @@ -105,18 +105,9 @@ class VpnService : BaseVpnService(), BaseService.Interface { is IOException -> Crashlytics.log(Log.WARN, name, e.message) else -> printLog(e) } - try { - LocalDnsServer.prepareDnsResponse(Message(query)).apply { - header.rcode = Rcode.SERVFAIL - }.toWire() - } catch (e: Exception) { - when (e) { - is CancellationException -> { } // ignore - is IOException -> Crashlytics.log(Log.WARN, name, e.message) - else -> printLog(e) - } - null - } + LocalDnsServer.prepareDnsResponse(Message(query)).apply { + header.rcode = Rcode.SERVFAIL + }.toWire() }?.let { response -> val output = DataOutputStream(socket.outputStream) output.writeShort(response.size) From 46a16dc32fbbe3091783116d09cf6d6dd813b737 Mon Sep 17 00:00:00 2001 From: Max Lv Date: Fri, 10 Apr 2020 08:56:08 +0800 Subject: [PATCH 37/57] Add ndkVersion --- build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/build.gradle b/build.gradle index 9fe4f3f093..0149aeab69 100644 --- a/build.gradle +++ b/build.gradle @@ -17,6 +17,7 @@ buildscript { versionCode = 5000650 versionName = '5.0.6-nightly' resConfigs = ['ar', 'es', 'fa', 'fr', 'ja', 'ko', 'ru', 'tr', 'zh-rCN', 'zh-rTW'] + ndkVersion = "21.1.6210238" } repositories { From c8166c0b950139160c0f29bd830496f5d7f2dd07 Mon Sep 17 00:00:00 2001 From: Mygod Date: Sun, 19 Apr 2020 06:18:27 +0800 Subject: [PATCH 38/57] Update dependencies --- build.gradle | 7 +++---- core/build.gradle | 18 +++++++++--------- core/src/main/AndroidManifest.xml | 1 - gradle/wrapper/gradle-wrapper.properties | 2 +- gradlew.bat | 3 +++ mobile/build.gradle | 7 +++---- plugin/build.gradle | 2 +- tv/build.gradle | 1 - 8 files changed, 20 insertions(+), 21 deletions(-) diff --git a/build.gradle b/build.gradle index 0149aeab69..4e038aa5da 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ apply plugin: 'com.github.ben-manes.versions' buildscript { ext { javaVersion = JavaVersion.VERSION_1_8 - kotlinVersion = '1.3.70' + kotlinVersion = '1.3.72' minSdkVersion = 21 sdkVersion = 29 compileSdkVersion = 29 @@ -17,7 +17,6 @@ buildscript { versionCode = 5000650 versionName = '5.0.6-nightly' resConfigs = ['ar', 'es', 'fa', 'fr', 'ja', 'ko', 'ru', 'tr', 'zh-rCN', 'zh-rTW'] - ndkVersion = "21.1.6210238" } repositories { @@ -32,11 +31,11 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:4.0.0-beta02' + classpath 'com.android.tools.build:gradle:4.0.0-beta04' classpath 'com.github.ben-manes:gradle-versions-plugin:0.28.0' classpath 'com.google.android.gms:oss-licenses-plugin:0.10.2' classpath 'com.google.gms:google-services:4.3.3' - classpath 'com.vanniktech:gradle-maven-publish-plugin:0.9.0' + classpath 'com.vanniktech:gradle-maven-publish-plugin:0.11.1' classpath 'gradle.plugin.org.mozilla.rust-android-gradle:plugin:0.8.3' classpath 'io.fabric.tools:gradle:1.31.2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion" diff --git a/core/build.gradle b/core/build.gradle index 99bb057873..d208761a9d 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -46,7 +46,7 @@ android { androidTest.assets.srcDirs += files("$projectDir/schemas".toString()) } - ndkVersion rootProject.ndkVersion + ndkVersion '21.1.6210238' lintOptions { disable 'InvalidPackage' @@ -74,24 +74,24 @@ cargo { preBuild.dependsOn "cargoBuild" -def coroutinesVersion = '1.3.3' -def roomVersion = '2.2.4' -def workVersion = '2.3.2' +def coroutinesVersion = '1.3.5' +def roomVersion = '2.2.5' +def workVersion = '2.3.4' dependencies { api project(':plugin') - api 'androidx.fragment:fragment-ktx:1.2.2' + api 'androidx.fragment:fragment-ktx:1.2.4' api "androidx.lifecycle:lifecycle-common-java8:$lifecycleVersion" api "androidx.lifecycle:lifecycle-livedata-core-ktx:$lifecycleVersion" - api 'androidx.preference:preference:1.1.0' + api 'androidx.preference:preference:1.1.1' api "androidx.room:room-runtime:$roomVersion" api "androidx.work:work-runtime-ktx:$workVersion" api "androidx.work:work-gcm:$workVersion" api 'com.crashlytics.sdk.android:crashlytics:2.10.1' api 'com.google.android.gms:play-services-oss-licenses:17.0.0' api 'com.google.code.gson:gson:2.8.6' - api 'com.google.firebase:firebase-analytics:17.2.3' - api 'com.google.firebase:firebase-config:19.1.2' - api 'dnsjava:dnsjava:3.0.0' + api 'com.google.firebase:firebase-analytics:17.3.0' + api 'com.google.firebase:firebase-config:19.1.3' + api 'dnsjava:dnsjava:3.0.2' api "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutinesVersion" api "org.jetbrains.kotlinx:kotlinx-coroutines-play-services:$coroutinesVersion" api 'org.connectbot.jsocks:jsocks:1.0.0' diff --git a/core/src/main/AndroidManifest.xml b/core/src/main/AndroidManifest.xml index 6a1cdc3006..a1d1bddea0 100644 --- a/core/src/main/AndroidManifest.xml +++ b/core/src/main/AndroidManifest.xml @@ -103,7 +103,6 @@ Date: Sun, 19 Apr 2020 06:51:02 +0800 Subject: [PATCH 39/57] Fix listening address --- core/src/main/java/com/github/shadowsocks/bg/ProxyInstance.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core/src/main/java/com/github/shadowsocks/bg/ProxyInstance.kt b/core/src/main/java/com/github/shadowsocks/bg/ProxyInstance.kt index e0bbd6ebac..ff7c95740f 100644 --- a/core/src/main/java/com/github/shadowsocks/bg/ProxyInstance.kt +++ b/core/src/main/java/com/github/shadowsocks/bg/ProxyInstance.kt @@ -129,9 +129,8 @@ class ProxyInstance(val profile: Profile, private val route: String = profile.ro val cmd = arrayListOf( File((service as Context).applicationInfo.nativeLibraryDir, Executable.SS_LOCAL).absolutePath, "--stat-path", stat.absolutePath, - "--dns-relay", "127.0.0.1:${DataStore.portLocalDns}", + "--dns-relay", "${DataStore.listenAddress}:${DataStore.portLocalDns}", "--remote-dns", "${dns.host}:${if (dns.port < 0) 53 else dns.port}", - "--local-dns", "127.0.0.1:8153", "-c", configFile.absolutePath) if (service.isVpnService) cmd += arrayListOf("--vpn") if (extraFlag != null) cmd.add(extraFlag) From 445461f33c54fe052a41e75ddcc52840992fc423 Mon Sep 17 00:00:00 2001 From: Mygod Date: Sun, 19 Apr 2020 06:59:10 +0800 Subject: [PATCH 40/57] Enable hosts and local DNS settings always --- .../GlobalSettingsPreferenceFragment.kt | 14 +++----------- .../shadowsocks/tv/MainPreferenceFragment.kt | 13 +++---------- 2 files changed, 6 insertions(+), 21 deletions(-) diff --git a/mobile/src/main/java/com/github/shadowsocks/GlobalSettingsPreferenceFragment.kt b/mobile/src/main/java/com/github/shadowsocks/GlobalSettingsPreferenceFragment.kt index 76a9e2e64b..7e8efe9487 100644 --- a/mobile/src/main/java/com/github/shadowsocks/GlobalSettingsPreferenceFragment.kt +++ b/mobile/src/main/java/com/github/shadowsocks/GlobalSettingsPreferenceFragment.kt @@ -91,25 +91,17 @@ class GlobalSettingsPreferenceFragment : PreferenceFragmentCompat() { val portTransproxy = findPreference(Key.portTransproxy)!! portTransproxy.setOnBindEditTextListener(EditTextPreferenceModifiers.Port) val onServiceModeChange = Preference.OnPreferenceChangeListener { _, newValue -> - val (enabledLocalDns, enabledTransproxy) = when (newValue as String?) { - Key.modeProxy -> Pair(false, false) - Key.modeVpn -> Pair(true, false) - Key.modeTransproxy -> Pair(true, true) - else -> throw IllegalArgumentException("newValue: $newValue") - } - hosts.isEnabled = enabledLocalDns - portLocalDns.isEnabled = enabledLocalDns - portTransproxy.isEnabled = enabledTransproxy + portTransproxy.isEnabled = newValue as String? == Key.modeTransproxy true } val listener: (BaseService.State) -> Unit = { val stopped = it == BaseService.State.Stopped tfo.isEnabled = stopped + hosts.isEnabled = stopped serviceMode.isEnabled = stopped portProxy.isEnabled = stopped + portLocalDns.isEnabled = stopped if (stopped) onServiceModeChange.onPreferenceChange(null, DataStore.serviceMode) else { - hosts.isEnabled = false - portLocalDns.isEnabled = false portTransproxy.isEnabled = false } } diff --git a/tv/src/main/java/com/github/shadowsocks/tv/MainPreferenceFragment.kt b/tv/src/main/java/com/github/shadowsocks/tv/MainPreferenceFragment.kt index d2b990aad3..ab5e5a1be2 100644 --- a/tv/src/main/java/com/github/shadowsocks/tv/MainPreferenceFragment.kt +++ b/tv/src/main/java/com/github/shadowsocks/tv/MainPreferenceFragment.kt @@ -76,15 +76,7 @@ class MainPreferenceFragment : LeanbackPreferenceFragmentCompat(), ShadowsocksCo private lateinit var portLocalDns: EditTextPreference private lateinit var portTransproxy: EditTextPreference private val onServiceModeChange = Preference.OnPreferenceChangeListener { _, newValue -> - val (enabledLocalDns, enabledTransproxy) = when (newValue as String?) { - Key.modeProxy -> Pair(false, false) - Key.modeVpn -> Pair(true, false) - Key.modeTransproxy -> Pair(true, true) - else -> throw IllegalArgumentException("newValue: $newValue") - } - hosts.isEnabled = enabledLocalDns - portLocalDns.isEnabled = enabledLocalDns - portTransproxy.isEnabled = enabledTransproxy + portTransproxy.isEnabled = newValue as String? == Key.modeTransproxy true } private val tester by viewModels() @@ -125,11 +117,12 @@ class MainPreferenceFragment : LeanbackPreferenceFragmentCompat(), ShadowsocksCo val stopped = state == BaseService.State.Stopped controlImport.isEnabled = stopped tfo.isEnabled = stopped + hosts.isEnabled = stopped serviceMode.isEnabled = stopped shareOverLan.isEnabled = stopped portProxy.isEnabled = stopped + portLocalDns.isEnabled = stopped if (stopped) onServiceModeChange.onPreferenceChange(null, DataStore.serviceMode) else { - portLocalDns.isEnabled = false portTransproxy.isEnabled = false } } From 91632d103aeff2e94a61f6a6e99cd2186c1e435e Mon Sep 17 00:00:00 2001 From: Mygod Date: Sun, 19 Apr 2020 07:50:58 +0800 Subject: [PATCH 41/57] Move local dns handler to BaseService --- .../com/github/shadowsocks/bg/BaseService.kt | 6 ++- .../shadowsocks/bg/DnsResolverCompat.kt | 19 ++++--- .../github/shadowsocks/bg/LocalDnsWorker.kt | 54 +++++++++++++++++++ .../com/github/shadowsocks/bg/VpnService.kt | 43 ++------------- 4 files changed, 76 insertions(+), 46 deletions(-) create mode 100644 core/src/main/java/com/github/shadowsocks/bg/LocalDnsWorker.kt diff --git a/core/src/main/java/com/github/shadowsocks/bg/BaseService.kt b/core/src/main/java/com/github/shadowsocks/bg/BaseService.kt index aa394b48ad..e0331884ae 100644 --- a/core/src/main/java/com/github/shadowsocks/bg/BaseService.kt +++ b/core/src/main/java/com/github/shadowsocks/bg/BaseService.kt @@ -46,7 +46,6 @@ import java.io.File import java.io.IOException import java.net.URL import java.net.UnknownHostException -import java.util.* /** * This object uses WeakMap to simulate the effects of multi-inheritance. @@ -74,6 +73,7 @@ object BaseService { var processes: GuardedProcessPool? = null var proxy: ProxyInstance? = null var udpFallback: ProxyInstance? = null + var localDns: LocalDnsWorker? = null var notification: ServiceNotification? = null val closeReceiver = broadcastReceiver { _, intent -> @@ -247,6 +247,7 @@ object BaseService { File(Core.deviceStorage.noBackupFilesDir, "stat_udp"), File(configRoot, CONFIG_FILE_UDP), "-u") + data.localDns = LocalDnsWorker(this::rawResolver).apply { start() } } fun startRunner() { @@ -260,6 +261,8 @@ object BaseService { close(scope) data.processes = null } + data.localDns?.shutdown(scope) + data.localDns = null } fun stopRunner(restart: Boolean = false, msg: String? = null) { @@ -309,6 +312,7 @@ object BaseService { suspend fun preInit() { } suspend fun getActiveNetwork() = if (Build.VERSION.SDK_INT >= 23) Core.connectivity.activeNetwork else null suspend fun resolver(host: String) = DnsResolverCompat.resolveOnActiveNetwork(host) + suspend fun rawResolver(query: ByteArray) = DnsResolverCompat.resolveRawOnActiveNetwork(query) suspend fun openConnection(url: URL) = url.openConnection() fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { diff --git a/core/src/main/java/com/github/shadowsocks/bg/DnsResolverCompat.kt b/core/src/main/java/com/github/shadowsocks/bg/DnsResolverCompat.kt index f29e3c0ee9..c03ec7a863 100644 --- a/core/src/main/java/com/github/shadowsocks/bg/DnsResolverCompat.kt +++ b/core/src/main/java/com/github/shadowsocks/bg/DnsResolverCompat.kt @@ -101,6 +101,7 @@ sealed class DnsResolverCompat { override suspend fun resolve(network: Network, host: String) = instance.resolve(network, host) override suspend fun resolveOnActiveNetwork(host: String) = instance.resolveOnActiveNetwork(host) override suspend fun resolveRaw(network: Network, query: ByteArray) = instance.resolveRaw(network, query) + override suspend fun resolveRawOnActiveNetwork(query: ByteArray) = instance.resolveRawOnActiveNetwork(query) } @Throws(IOException::class) @@ -110,6 +111,7 @@ sealed class DnsResolverCompat { abstract suspend fun resolve(network: Network, host: String): Array abstract suspend fun resolveOnActiveNetwork(host: String): Array abstract suspend fun resolveRaw(network: Network, query: ByteArray): ByteArray + abstract suspend fun resolveRawOnActiveNetwork(query: ByteArray): ByteArray @SuppressLint("PrivateApi") private open class DnsResolverCompat21 : DnsResolverCompat() { @@ -147,7 +149,8 @@ sealed class DnsResolverCompat { override suspend fun resolveOnActiveNetwork(host: String) = GlobalScope.async(unboundedIO) { InetAddress.getAllByName(host) }.await() - override suspend fun resolveRaw(network: Network, query: ByteArray): ByteArray { + private suspend fun resolveRaw(query: ByteArray, + hostResolver: suspend (String) -> Array): ByteArray { val request = try { Message(query) } catch (e: IOException) { @@ -164,10 +167,14 @@ sealed class DnsResolverCompat { else -> throw UnsupportedOperationException("Unsupported query type $type") } val host = question.name.canonicalize().toString(true) - return LocalDnsServer.cookDnsResponse(request, resolve(network, host).asIterable().run { + return LocalDnsServer.cookDnsResponse(request, hostResolver(host).asIterable().run { if (isIpv6) filterIsInstance() else filterIsInstance() }) } + override suspend fun resolveRaw(network: Network, query: ByteArray) = + resolveRaw(query) { resolve(network, it) } + override suspend fun resolveRawOnActiveNetwork(query: ByteArray) = + resolveRaw(query, this::resolveOnActiveNetwork) } @TargetApi(23) @@ -184,6 +191,8 @@ sealed class DnsResolverCompat { override fun bindSocket(network: Network, socket: FileDescriptor) = network.bindSocket(socket) + private val activeNetwork get() = Core.connectivity.activeNetwork ?: throw IOException("no network") + override suspend fun resolve(network: Network, host: String): Array { return suspendCancellableCoroutine { cont -> val signal = CancellationSignal() @@ -197,10 +206,7 @@ sealed class DnsResolverCompat { }) } } - - override suspend fun resolveOnActiveNetwork(host: String): Array { - return resolve(Core.connectivity.activeNetwork ?: return emptyArray(), host) - } + override suspend fun resolveOnActiveNetwork(host: String) = resolve(activeNetwork, host) override suspend fun resolveRaw(network: Network, query: ByteArray): ByteArray { return suspendCancellableCoroutine { cont -> @@ -213,5 +219,6 @@ sealed class DnsResolverCompat { }) } } + override suspend fun resolveRawOnActiveNetwork(query: ByteArray) = resolveRaw(activeNetwork, query) } } diff --git a/core/src/main/java/com/github/shadowsocks/bg/LocalDnsWorker.kt b/core/src/main/java/com/github/shadowsocks/bg/LocalDnsWorker.kt new file mode 100644 index 0000000000..ad91beb8d7 --- /dev/null +++ b/core/src/main/java/com/github/shadowsocks/bg/LocalDnsWorker.kt @@ -0,0 +1,54 @@ +package com.github.shadowsocks.bg + +import android.net.LocalSocket +import android.util.Log +import com.crashlytics.android.Crashlytics +import com.github.shadowsocks.Core +import com.github.shadowsocks.net.ConcurrentLocalSocketListener +import com.github.shadowsocks.net.LocalDnsServer +import com.github.shadowsocks.utils.printLog +import kotlinx.coroutines.CancellationException +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.TimeoutCancellationException +import kotlinx.coroutines.launch +import org.xbill.DNS.Message +import org.xbill.DNS.Rcode +import java.io.DataInputStream +import java.io.DataOutputStream +import java.io.File +import java.io.IOException + +class LocalDnsWorker(private val resolver: suspend (ByteArray) -> ByteArray) : ConcurrentLocalSocketListener( + "LocalDnsThread", File(Core.deviceStorage.noBackupFilesDir, "local_dns_path")), CoroutineScope { + override fun acceptInternal(socket: LocalSocket) = error("big no no") + override fun accept(socket: LocalSocket) { + launch { + socket.use { + val input = DataInputStream(socket.inputStream) + val query = ByteArray(input.readUnsignedShort()) + input.read(query) + try { + resolver(query) + } catch (e: Exception) { + when (e) { + is TimeoutCancellationException -> Crashlytics.log(Log.WARN, name, "Resolving timed out") + is CancellationException -> { } // ignore + is IOException -> Crashlytics.log(Log.WARN, name, e.message) + else -> printLog(e) + } + try { + LocalDnsServer.prepareDnsResponse(Message(query)).apply { + header.rcode = Rcode.SERVFAIL + }.toWire() + } catch (_: IOException) { + byteArrayOf() // return empty if cannot parse packet + } + }?.let { response -> + val output = DataOutputStream(socket.outputStream) + output.writeShort(response.size) + output.write(response) + } + } + } + } +} diff --git a/core/src/main/java/com/github/shadowsocks/bg/VpnService.kt b/core/src/main/java/com/github/shadowsocks/bg/VpnService.kt index 25f3b946f8..b529492668 100644 --- a/core/src/main/java/com/github/shadowsocks/bg/VpnService.kt +++ b/core/src/main/java/com/github/shadowsocks/bg/VpnService.kt @@ -30,8 +30,6 @@ import android.os.Build import android.os.ParcelFileDescriptor import android.system.ErrnoException import android.system.OsConstants -import android.util.Log -import com.crashlytics.android.Crashlytics import com.github.shadowsocks.Core import com.github.shadowsocks.VpnRequestActivity import com.github.shadowsocks.acl.Acl @@ -43,8 +41,6 @@ import com.github.shadowsocks.utils.closeQuietly import com.github.shadowsocks.utils.int import com.github.shadowsocks.utils.printLog import kotlinx.coroutines.* -import org.xbill.DNS.Message -import org.xbill.DNS.Rcode import java.io.* import java.net.URL import android.net.VpnService as BaseVpnService @@ -87,37 +83,6 @@ class VpnService : BaseVpnService(), BaseService.Interface { } } - private inner class LocalDnsWorker : ConcurrentLocalSocketListener("LocalDnsThread", - File(Core.deviceStorage.noBackupFilesDir, "local_dns_path")), CoroutineScope { - override fun acceptInternal(socket: LocalSocket) = error("big no no") - override fun accept(socket: LocalSocket) { - launch { - socket.use { - val input = DataInputStream(socket.inputStream) - val query = ByteArray(input.readUnsignedShort()) - input.read(query) - try { - DnsResolverCompat.resolveRaw(underlyingNetwork ?: throw IOException("no network"), query) - } catch (e: Exception) { - when (e) { - is TimeoutCancellationException -> Crashlytics.log(Log.WARN, name, "Resolving timed out") - is CancellationException -> { } // ignore - is IOException -> Crashlytics.log(Log.WARN, name, e.message) - else -> printLog(e) - } - LocalDnsServer.prepareDnsResponse(Message(query)).apply { - header.rcode = Rcode.SERVFAIL - }.toWire() - }?.let { response -> - val output = DataOutputStream(socket.outputStream) - output.writeShort(response.size) - output.write(response) - } - } - } - } - } - inner class NullConnectionException : NullPointerException(), BaseService.ExpectedException { override fun getLocalizedMessage() = getString(R.string.reboot_required) } @@ -129,7 +94,6 @@ class VpnService : BaseVpnService(), BaseService.Interface { private var conn: ParcelFileDescriptor? = null private var worker: ProtectWorker? = null - private var localDns: LocalDnsWorker? = null private var active = false private var metered = false private var underlyingNetwork: Network? = null @@ -154,8 +118,6 @@ class VpnService : BaseVpnService(), BaseService.Interface { scope.launch { DefaultNetworkListener.stop(this) } worker?.shutdown(scope) worker = null - localDns?.shutdown(scope) - localDns = null conn?.close() conn = null } @@ -173,11 +135,14 @@ class VpnService : BaseVpnService(), BaseService.Interface { override suspend fun preInit() = DefaultNetworkListener.start(this) { underlyingNetwork = it } override suspend fun getActiveNetwork() = DefaultNetworkListener.get() override suspend fun resolver(host: String) = DnsResolverCompat.resolve(DefaultNetworkListener.get(), host) + override suspend fun rawResolver(query: ByteArray) = + // no need to listen for network here as this is only used for forwarding local DNS queries. + // retries should be attempted by client. + DnsResolverCompat.resolveRaw(underlyingNetwork ?: throw IOException("no network"), query) override suspend fun openConnection(url: URL) = DefaultNetworkListener.get().openConnection(url) override suspend fun startProcesses(hosts: HostsFile) { worker = ProtectWorker().apply { start() } - localDns = LocalDnsWorker().apply { start() } super.startProcesses(hosts) sendFd(startVpn()) } From fb8e18c8fb0230635f6c3698a2898f1c75349b39 Mon Sep 17 00:00:00 2001 From: Mygod Date: Sun, 19 Apr 2020 08:09:24 +0800 Subject: [PATCH 42/57] Clean up unused code --- .gitmodules | 9 +- .../github/shadowsocks/acl/AclMatcherTest.kt | 85 --------- .../com/github/shadowsocks/acl/AclMatcher.kt | 101 ----------- .../shadowsocks/bg/DnsResolverCompat.kt | 32 +++- .../github/shadowsocks/bg/LocalDnsWorker.kt | 3 +- .../github/shadowsocks/net/LocalDnsServer.kt | 162 ------------------ core/src/main/jni/Android.mk | 33 ---- core/src/main/jni/jni-helper.cpp | 112 ------------ core/src/main/jni/re2 | 1 - 9 files changed, 29 insertions(+), 509 deletions(-) delete mode 100644 core/src/androidTest/java/com/github/shadowsocks/acl/AclMatcherTest.kt delete mode 100644 core/src/main/java/com/github/shadowsocks/acl/AclMatcher.kt delete mode 100644 core/src/main/java/com/github/shadowsocks/net/LocalDnsServer.kt delete mode 100644 core/src/main/jni/jni-helper.cpp delete mode 160000 core/src/main/jni/re2 diff --git a/.gitmodules b/.gitmodules index 1417093c26..b071b06ee1 100644 --- a/.gitmodules +++ b/.gitmodules @@ -2,6 +2,9 @@ path = core/src/main/jni/badvpn url = https://github.com/shadowsocks/badvpn.git branch = shadowsocks-android +[submodule "core/src/main/jni/libancillary"] + path = core/src/main/jni/libancillary + url = https://github.com/shadowsocks/libancillary.git [submodule "core/src/main/jni/libevent"] path = core/src/main/jni/libevent url = https://github.com/shadowsocks/libevent.git @@ -10,12 +13,6 @@ path = core/src/main/jni/redsocks url = https://github.com/shadowsocks/redsocks.git branch = shadowsocks-android -[submodule "core/src/main/jni/re2"] - path = core/src/main/jni/re2 - url = https://github.com/google/re2.git [submodule "core/src/main/rust/shadowsocks-rust"] path = core/src/main/rust/shadowsocks-rust url = https://github.com/madeye/shadowsocks-rust -[submodule "core/src/main/jni/libancillary"] - path = core/src/main/jni/libancillary - url = https://github.com/shadowsocks/libancillary.git diff --git a/core/src/androidTest/java/com/github/shadowsocks/acl/AclMatcherTest.kt b/core/src/androidTest/java/com/github/shadowsocks/acl/AclMatcherTest.kt deleted file mode 100644 index 003c38c47d..0000000000 --- a/core/src/androidTest/java/com/github/shadowsocks/acl/AclMatcherTest.kt +++ /dev/null @@ -1,85 +0,0 @@ -/******************************************************************************* - * * - * Copyright (C) 2020 by Max Lv * - * Copyright (C) 2020 by Mygod Studio * - * * - * This program is free software: you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation, either version 3 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program. If not, see . * - * * - *******************************************************************************/ - -package com.github.shadowsocks.acl - -import androidx.test.core.app.ApplicationProvider -import com.github.shadowsocks.Core -import com.github.shadowsocks.utils.parseNumericAddress -import kotlinx.coroutines.runBlocking -import org.junit.Assert -import org.junit.BeforeClass -import org.junit.Test - -class AclMatcherTest { - companion object { - @BeforeClass - @JvmStatic - fun setup() { - Core.app = ApplicationProvider.getApplicationContext() - } - } - - @Test - fun emptyFile() { - runBlocking { - AclMatcher().apply { - init(AclTest.BYPASS_BASE.reader()) - Assert.assertTrue(shouldBypassIpv4(ByteArray(4))) - Assert.assertTrue(shouldBypassIpv6(ByteArray(16))) - Assert.assertNull(shouldBypass("www.google.com")) - } - } - } - - @Test - fun basic() { - runBlocking { - AclMatcher().apply { - init(AclTest.INPUT1.reader()) - Assert.assertTrue(shouldBypassIpv4("0.1.2.3".parseNumericAddress()!!.address)) - Assert.assertFalse(shouldBypassIpv4("1.0.1.2".parseNumericAddress()!!.address)) - Assert.assertTrue(shouldBypassIpv4("1.0.3.2".parseNumericAddress()!!.address)) - Assert.assertTrue(shouldBypassIpv6("::".parseNumericAddress()!!.address)) - Assert.assertFalse(shouldBypassIpv6("2020::2020".parseNumericAddress()!!.address)) - Assert.assertTrue(shouldBypassIpv6("fe80::2020".parseNumericAddress()!!.address)) - Assert.assertTrue(shouldBypass("4tern.com") == false) - Assert.assertTrue(shouldBypass("www.4tern.com") == false) - Assert.assertNull(shouldBypass("www.google.com")) - } - } - } - - @Test - fun bypassList() { - runBlocking { - AclMatcher().apply { - init(AclTest.INPUT2.reader()) - Assert.assertFalse(shouldBypassIpv4("0.1.2.3".parseNumericAddress()!!.address)) - Assert.assertTrue(shouldBypassIpv4("10.0.1.2".parseNumericAddress()!!.address)) - Assert.assertTrue(shouldBypassIpv4("10.10.1.2".parseNumericAddress()!!.address)) - Assert.assertFalse(shouldBypassIpv4("11.0.1.2".parseNumericAddress()!!.address)) - Assert.assertTrue(shouldBypass("chrome.com") == true) - Assert.assertTrue(shouldBypass("about.google") == false) - Assert.assertNull(shouldBypass("www.google.com")) - } - } - } -} diff --git a/core/src/main/java/com/github/shadowsocks/acl/AclMatcher.kt b/core/src/main/java/com/github/shadowsocks/acl/AclMatcher.kt deleted file mode 100644 index fbd9eef1f4..0000000000 --- a/core/src/main/java/com/github/shadowsocks/acl/AclMatcher.kt +++ /dev/null @@ -1,101 +0,0 @@ -/******************************************************************************* - * * - * Copyright (C) 2019 by Max Lv * - * Copyright (C) 2019 by Mygod Studio * - * * - * This program is free software: you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation, either version 3 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program. If not, see . * - * * - *******************************************************************************/ - -package com.github.shadowsocks.acl - -import com.github.shadowsocks.Core -import com.github.shadowsocks.net.Subnet -import java.io.Reader -import java.net.Inet4Address -import java.net.Inet6Address - -class AclMatcher : AutoCloseable { - companion object { - init { - System.loadLibrary("jni-helper") - } - - @JvmStatic private external fun init(): Long - @JvmStatic private external fun close(handle: Long) - - @JvmStatic private external fun addBypassDomain(handle: Long, regex: String): Boolean - @JvmStatic private external fun addProxyDomain(handle: Long, regex: String): Boolean - @JvmStatic private external fun build(handle: Long, memoryLimit: Long): String? - @JvmStatic private external fun matchHost(handle: Long, host: String): Int - } - - class Re2Exception(message: String) : IllegalArgumentException(message) - - private var handle = 0L - override fun close() { - if (handle != 0L) { - close(handle) - handle = 0L - } - } - - private var subnetsIpv4 = emptyList() - private var subnetsIpv6 = emptyList() - private var bypass = false - - suspend fun init(id: String) = init(Acl.getFile(id).bufferedReader()) - suspend fun init(reader: Reader) { - fun Sequence.dedup() = sequence { - val iterator = map { it.toImmutable() }.sortedWith(Subnet.Immutable).iterator() - var current: Subnet.Immutable? = null - while (iterator.hasNext()) { - val next = iterator.next() - if (current?.matches(next) == true) continue - yield(next) - current = next - } - }.toList() - check(handle == 0L) - handle = init() - try { - val (bypass, subnets) = Acl.parse(reader, { - check(addBypassDomain(handle, it)) - }, { - check(addProxyDomain(handle, it)) - }) - build(handle, if (Core.activity.isLowRamDevice) 8 shl 20 else 64 shl 20)?.also { throw Re2Exception(it) } - subnetsIpv4 = subnets.asSequence().filter { it.address is Inet4Address }.dedup() - subnetsIpv6 = subnets.asSequence().filter { it.address is Inet6Address }.dedup() - this.bypass = bypass - } catch (e: Exception) { - close() - throw e - } - } - - private fun quickMatches(subnets: List, ip: ByteArray): Boolean { - val i = subnets.binarySearch(Subnet.Immutable(ip), Subnet.Immutable) - return i >= 0 || i < -1 && subnets[-i - 2].matches(ip) - } - - fun shouldBypassIpv4(ip: ByteArray) = bypass xor quickMatches(subnetsIpv4, ip) - fun shouldBypassIpv6(ip: ByteArray) = bypass xor quickMatches(subnetsIpv6, ip) - fun shouldBypass(host: String) = when (val e = matchHost(handle, host)) { - 0 -> null - 1 -> true - 2 -> false - else -> error("matchHost -> $e") - } -} diff --git a/core/src/main/java/com/github/shadowsocks/bg/DnsResolverCompat.kt b/core/src/main/java/com/github/shadowsocks/bg/DnsResolverCompat.kt index c03ec7a863..f0cff158d6 100644 --- a/core/src/main/java/com/github/shadowsocks/bg/DnsResolverCompat.kt +++ b/core/src/main/java/com/github/shadowsocks/bg/DnsResolverCompat.kt @@ -31,15 +31,12 @@ import android.system.ErrnoException import android.system.Os import android.system.OsConstants import com.github.shadowsocks.Core -import com.github.shadowsocks.net.LocalDnsServer import com.github.shadowsocks.utils.closeQuietly import com.github.shadowsocks.utils.int import com.github.shadowsocks.utils.parseNumericAddress import com.github.shadowsocks.utils.printLog import kotlinx.coroutines.* -import org.xbill.DNS.Message -import org.xbill.DNS.Opcode -import org.xbill.DNS.Type +import org.xbill.DNS.* import java.io.FileDescriptor import java.io.IOException import java.net.Inet4Address @@ -102,6 +99,20 @@ sealed class DnsResolverCompat { override suspend fun resolveOnActiveNetwork(host: String) = instance.resolveOnActiveNetwork(host) override suspend fun resolveRaw(network: Network, query: ByteArray) = instance.resolveRaw(network, query) override suspend fun resolveRawOnActiveNetwork(query: ByteArray) = instance.resolveRawOnActiveNetwork(query) + + // additional platform-independent DNS helpers + + /** + * TTL returned from localResolver is set to 120. Android API does not provide TTL, + * so we suppose Android apps should not care about TTL either. + */ + private const val TTL = 120L + + fun prepareDnsResponse(request: Message) = Message(request.header.id).apply { + header.setFlag(Flags.QR.toInt()) // this is a response + if (request.header.getFlag(Flags.RD.toInt())) header.setFlag(Flags.RD.toInt()) + request.question?.also { addRecord(it, Section.QUESTION) } + } } @Throws(IOException::class) @@ -167,9 +178,16 @@ sealed class DnsResolverCompat { else -> throw UnsupportedOperationException("Unsupported query type $type") } val host = question.name.canonicalize().toString(true) - return LocalDnsServer.cookDnsResponse(request, hostResolver(host).asIterable().run { - if (isIpv6) filterIsInstance() else filterIsInstance() - }) + return prepareDnsResponse(request).apply { + header.setFlag(Flags.RA.toInt()) // recursion available + for (address in hostResolver(host).asIterable().run { + if (isIpv6) filterIsInstance() else filterIsInstance() + }) addRecord(when (address) { + is Inet4Address -> ARecord(question.name, DClass.IN, TTL, address) + is Inet6Address -> AAAARecord(question.name, DClass.IN, TTL, address) + else -> error("Unsupported address $address") + }, Section.ANSWER) + }.toWire() } override suspend fun resolveRaw(network: Network, query: ByteArray) = resolveRaw(query) { resolve(network, it) } diff --git a/core/src/main/java/com/github/shadowsocks/bg/LocalDnsWorker.kt b/core/src/main/java/com/github/shadowsocks/bg/LocalDnsWorker.kt index ad91beb8d7..2c329a98e9 100644 --- a/core/src/main/java/com/github/shadowsocks/bg/LocalDnsWorker.kt +++ b/core/src/main/java/com/github/shadowsocks/bg/LocalDnsWorker.kt @@ -5,7 +5,6 @@ import android.util.Log import com.crashlytics.android.Crashlytics import com.github.shadowsocks.Core import com.github.shadowsocks.net.ConcurrentLocalSocketListener -import com.github.shadowsocks.net.LocalDnsServer import com.github.shadowsocks.utils.printLog import kotlinx.coroutines.CancellationException import kotlinx.coroutines.CoroutineScope @@ -37,7 +36,7 @@ class LocalDnsWorker(private val resolver: suspend (ByteArray) -> ByteArray) : C else -> printLog(e) } try { - LocalDnsServer.prepareDnsResponse(Message(query)).apply { + DnsResolverCompat.prepareDnsResponse(Message(query)).apply { header.rcode = Rcode.SERVFAIL }.toWire() } catch (_: IOException) { diff --git a/core/src/main/java/com/github/shadowsocks/net/LocalDnsServer.kt b/core/src/main/java/com/github/shadowsocks/net/LocalDnsServer.kt deleted file mode 100644 index a5d77f4038..0000000000 --- a/core/src/main/java/com/github/shadowsocks/net/LocalDnsServer.kt +++ /dev/null @@ -1,162 +0,0 @@ -/******************************************************************************* - * * - * Copyright (C) 2019 by Max Lv * - * Copyright (C) 2019 by Mygod Studio * - * * - * This program is free software: you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation, either version 3 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program. If not, see . * - * * - *******************************************************************************/ - -package com.github.shadowsocks.net - -import android.util.Log -import com.crashlytics.android.Crashlytics -import com.github.shadowsocks.acl.AclMatcher -import com.github.shadowsocks.bg.BaseService -import com.github.shadowsocks.utils.printLog -import kotlinx.coroutines.* -import org.xbill.DNS.* -import java.io.IOException -import java.net.* -import java.nio.ByteBuffer -import java.nio.channels.DatagramChannel -import java.nio.channels.SelectionKey -import java.nio.channels.SocketChannel - -/** - * A simple DNS conditional forwarder. - * - * No cache is provided as localResolver may change from time to time. We expect DNS clients to do cache themselves. - * - * Based on: - * https://github.com/bitcoinj/httpseed/blob/809dd7ad9280f4bc98a356c1ffb3d627bf6c7ec5/src/main/kotlin/dns.kt - * https://github.com/shadowsocks/overture/tree/874f22613c334a3b78e40155a55479b7b69fee04 - */ -class LocalDnsServer(private val localResolver: suspend (String) -> Array, - private val hosts: HostsFile) : CoroutineScope { - companion object { - private const val TAG = "LocalDnsServer" - private const val TIMEOUT = 10_000L - /** - * TTL returned from localResolver is set to 120. Android API does not provide TTL, - * so we suppose Android apps should not care about TTL either. - */ - private const val TTL = 120L - private const val UDP_PACKET_SIZE = 512 - - fun emptyDnsResponse() = Message().apply { - header.setFlag(Flags.QR.toInt()) // this is a response - } - - fun prepareDnsResponse(request: Message) = Message(request.header.id).apply { - header.setFlag(Flags.QR.toInt()) // this is a response - if (request.header.getFlag(Flags.RD.toInt())) header.setFlag(Flags.RD.toInt()) - request.question?.also { addRecord(it, Section.QUESTION) } - } - - fun cookDnsResponse(request: Message, results: Iterable) = prepareDnsResponse(request).apply { - header.setFlag(Flags.RA.toInt()) // recursion available - for (address in results) addRecord(when (address) { - is Inet4Address -> ARecord(question.name, DClass.IN, TTL, address) - is Inet6Address -> AAAARecord(question.name, DClass.IN, TTL, address) - else -> error("Unsupported address $address") - }, Section.ANSWER) - }.toWire() - } - - private val monitor = ChannelMonitor() - - override val coroutineContext = SupervisorJob() + CoroutineExceptionHandler { _, t -> - if (t is IOException) Crashlytics.log(Log.WARN, TAG, t.message) else printLog(t) - } - - suspend fun start(listen: SocketAddress) = DatagramChannel.open().run { - configureBlocking(false) - try { - socket().bind(listen) - } catch (e: BindException) { - throw BaseService.ExpectedExceptionWrapper(e) - } - monitor.register(this, SelectionKey.OP_READ) { handlePacket(this) } - } - - private fun handlePacket(channel: DatagramChannel) { - val buffer = ByteBuffer.allocateDirect(UDP_PACKET_SIZE) - val source = channel.receive(buffer)!! - buffer.flip() - launch { - val reply = resolve(buffer) - while (channel.send(reply, source) <= 0) monitor.wait(channel, SelectionKey.OP_WRITE) - } - } - - private suspend fun resolve(packet: ByteBuffer): ByteBuffer { - val request = try { - Message(packet) - } catch (e: IOException) { // we cannot parse the message, do not attempt to handle it at all - Crashlytics.log(Log.WARN, TAG, e.message) - return ByteBuffer.wrap(emptyDnsResponse().apply { - header.rcode = Rcode.SERVFAIL - }.toWire()) - } - - val question = request.question - val isIpv6 = when (question?.type) { - Type.A -> false - Type.AAAA -> true - else -> return ByteBuffer.wrap(prepareDnsResponse(request).apply { - header.rcode = Rcode.SERVFAIL - }.toWire()) - } - val host = question.name.canonicalize().toString(true) - val hostsResults = hosts.resolve(host) - if (hostsResults.isNotEmpty()) { - return ByteBuffer.wrap(cookDnsResponse(request, hostsResults.run { - if (isIpv6) filterIsInstance() else filterIsInstance() - })) - } - - Log.d("dns", "host: " + host) - - val localResults = try { - withTimeout(TIMEOUT) { localResolver(host) } - } catch (e: java.lang.Exception) { - when (e) { - is TimeoutCancellationException -> Crashlytics.log(Log.WARN, TAG, "Remote resolving timed out") - is CancellationException -> { } // ignore - is IOException -> Crashlytics.log(Log.WARN, TAG, e.message) - else -> printLog(e) - } - return ByteBuffer.wrap(prepareDnsResponse(request).apply { - header.rcode = Rcode.SERVFAIL - }.toWire()) - } - - val filtered = if (isIpv6) { - localResults.filterIsInstance() - } else { - localResults.filterIsInstance() - } - - return ByteBuffer.wrap(cookDnsResponse(request, filtered)) - } - - fun shutdown(scope: CoroutineScope) { - cancel() - monitor.close(scope) - scope.launch { - this@LocalDnsServer.coroutineContext[Job]!!.join() - } - } -} diff --git a/core/src/main/jni/Android.mk b/core/src/main/jni/Android.mk index ecf283d2dd..9fb93e07f6 100755 --- a/core/src/main/jni/Android.mk +++ b/core/src/main/jni/Android.mk @@ -73,39 +73,6 @@ LOCAL_CFLAGS := -std=gnu99 -DUSE_IPTABLES \ include $(BUILD_SHARED_EXECUTABLE) -######################################################## -## jni-helper -######################################################## - -include $(CLEAR_VARS) - -LOCAL_MODULE:= jni-helper - -LOCAL_C_INCLUDES := $(LOCAL_PATH)/re2 - -LOCAL_CFLAGS := -std=c++17 - -LOCAL_SRC_FILES := jni-helper.cpp \ - $(LOCAL_PATH)/re2/re2/bitstate.cc \ - $(LOCAL_PATH)/re2/re2/compile.cc \ - $(LOCAL_PATH)/re2/re2/dfa.cc \ - $(LOCAL_PATH)/re2/re2/nfa.cc \ - $(LOCAL_PATH)/re2/re2/onepass.cc \ - $(LOCAL_PATH)/re2/re2/parse.cc \ - $(LOCAL_PATH)/re2/re2/perl_groups.cc \ - $(LOCAL_PATH)/re2/re2/prog.cc \ - $(LOCAL_PATH)/re2/re2/re2.cc \ - $(LOCAL_PATH)/re2/re2/regexp.cc \ - $(LOCAL_PATH)/re2/re2/simplify.cc \ - $(LOCAL_PATH)/re2/re2/stringpiece.cc \ - $(LOCAL_PATH)/re2/re2/tostring.cc \ - $(LOCAL_PATH)/re2/re2/unicode_casefold.cc \ - $(LOCAL_PATH)/re2/re2/unicode_groups.cc \ - $(LOCAL_PATH)/re2/util/rune.cc \ - $(LOCAL_PATH)/re2/util/strutil.cc - -include $(BUILD_SHARED_LIBRARY) - ######################################################## ## tun2socks ######################################################## diff --git a/core/src/main/jni/jni-helper.cpp b/core/src/main/jni/jni-helper.cpp deleted file mode 100644 index 60936bbb04..0000000000 --- a/core/src/main/jni/jni-helper.cpp +++ /dev/null @@ -1,112 +0,0 @@ -/******************************************************************************* - * * - * Copyright (C) 2019 by Max Lv * - * Copyright (C) 2019 by Mygod Studio * - * * - * This program is free software: you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation, either version 3 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program. If not, see . * - * * - *******************************************************************************/ - -#include - -#include "jni.h" -#include "re2/re2.h" - -using namespace std; - -struct AclMatcher { - stringstream bypassDomainsBuilder, proxyDomainsBuilder; - RE2 *bypassDomains, *proxyDomains; - - ~AclMatcher() { - if (bypassDomains) delete bypassDomains; - if (proxyDomains) delete proxyDomains; - } -}; - -bool addDomain(JNIEnv *env, stringstream &domains, jstring regex) { - const char *regexChars = env->GetStringUTFChars(regex, nullptr); - if (regexChars == nullptr) return false; - if (domains.rdbuf()->in_avail()) domains << '|'; - domains << regexChars; - env->ReleaseStringUTFChars(regex, regexChars); - return true; -} - -const char *buildRE2(stringstream &domains, RE2 *&out, const RE2::Options &options) { - if (domains.rdbuf()->in_avail()) { - out = new RE2(domains.str(), options); - domains.clear(); - if (!out->ok()) return out->error().c_str(); - } else { - delete out; - out = nullptr; - } - return nullptr; -} - -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wunused-parameter" -extern "C" { -JNIEXPORT jlong JNICALL Java_com_github_shadowsocks_acl_AclMatcher_init(JNIEnv *env, jclass clazz) { - return reinterpret_cast(new AclMatcher()); -} - -JNIEXPORT void JNICALL -Java_com_github_shadowsocks_acl_AclMatcher_close(JNIEnv *env, jclass clazz, jlong handle) { - delete reinterpret_cast(handle); -} - -JNIEXPORT jboolean JNICALL -Java_com_github_shadowsocks_acl_AclMatcher_addBypassDomain(JNIEnv *env, jclass clazz, jlong handle, - jstring regex) { - return static_cast(handle && - ::addDomain(env, reinterpret_cast(handle)->bypassDomainsBuilder, regex)); -} - -JNIEXPORT jboolean JNICALL -Java_com_github_shadowsocks_acl_AclMatcher_addProxyDomain(JNIEnv *env, jclass clazz, jlong handle, - jstring regex) { - return static_cast(handle && - ::addDomain(env, reinterpret_cast(handle)->proxyDomainsBuilder, regex)); -} - -JNIEXPORT jstring JNICALL -Java_com_github_shadowsocks_acl_AclMatcher_build(JNIEnv *env, jclass clazz, jlong handle, - jlong memory_limit) { - if (!handle) return env->NewStringUTF("AclMatcher closed"); - auto matcher = reinterpret_cast(handle); - RE2::Options options; - options.set_max_mem(memory_limit); - options.set_never_capture(true); - const char *e = ::buildRE2(matcher->bypassDomainsBuilder, matcher->bypassDomains, options); - if (e) return env->NewStringUTF(e); - e = ::buildRE2(matcher->proxyDomainsBuilder, matcher->proxyDomains, options); - if (e) return env->NewStringUTF(e); - return nullptr; -} - -JNIEXPORT jint JNICALL -Java_com_github_shadowsocks_acl_AclMatcher_matchHost(JNIEnv *env, jclass clazz, jlong handle, - jstring host) { - if (!handle) return -1; - auto matcher = reinterpret_cast(handle); - const char *hostChars = env->GetStringUTFChars(host, nullptr); - jint result = 0; - if (matcher->bypassDomains && RE2::PartialMatch(hostChars, *matcher->bypassDomains)) result = 1; - else if (matcher->proxyDomains && RE2::PartialMatch(hostChars, *matcher->proxyDomains)) result = 2; - env->ReleaseStringUTFChars(host, hostChars); - return result; -} -} diff --git a/core/src/main/jni/re2 b/core/src/main/jni/re2 deleted file mode 160000 index bb8e777557..0000000000 --- a/core/src/main/jni/re2 +++ /dev/null @@ -1 +0,0 @@ -Subproject commit bb8e777557ddbdeabdedea4f23613c5021ffd7b1 From 30ae0d75a86dba0833668fc150f6ee1406c267e6 Mon Sep 17 00:00:00 2001 From: Mygod Date: Sun, 19 Apr 2020 08:18:44 +0800 Subject: [PATCH 43/57] Remove more unused code --- .gitmodules | 1 + core/build.gradle | 1 - .../github/shadowsocks/net/ChannelMonitor.kt | 127 ----------------- .../github/shadowsocks/net/Socks5Endpoint.kt | 128 ------------------ 4 files changed, 1 insertion(+), 256 deletions(-) delete mode 100644 core/src/main/java/com/github/shadowsocks/net/ChannelMonitor.kt delete mode 100644 core/src/main/java/com/github/shadowsocks/net/Socks5Endpoint.kt diff --git a/.gitmodules b/.gitmodules index b071b06ee1..954b512529 100644 --- a/.gitmodules +++ b/.gitmodules @@ -5,6 +5,7 @@ [submodule "core/src/main/jni/libancillary"] path = core/src/main/jni/libancillary url = https://github.com/shadowsocks/libancillary.git + branch = shadowsocks-android [submodule "core/src/main/jni/libevent"] path = core/src/main/jni/libevent url = https://github.com/shadowsocks/libevent.git diff --git a/core/build.gradle b/core/build.gradle index d208761a9d..8c520f351b 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -94,7 +94,6 @@ dependencies { api 'dnsjava:dnsjava:3.0.2' api "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutinesVersion" api "org.jetbrains.kotlinx:kotlinx-coroutines-play-services:$coroutinesVersion" - api 'org.connectbot.jsocks:jsocks:1.0.0' coreLibraryDesugaring "com.android.tools:desugar_jdk_libs:$desugarLibsVersion" kapt "androidx.room:room-compiler:$roomVersion" testImplementation "junit:junit:$junitVersion" diff --git a/core/src/main/java/com/github/shadowsocks/net/ChannelMonitor.kt b/core/src/main/java/com/github/shadowsocks/net/ChannelMonitor.kt deleted file mode 100644 index fa8d7a989c..0000000000 --- a/core/src/main/java/com/github/shadowsocks/net/ChannelMonitor.kt +++ /dev/null @@ -1,127 +0,0 @@ -/******************************************************************************* - * * - * Copyright (C) 2019 by Max Lv * - * Copyright (C) 2019 by Mygod Studio * - * * - * This program is free software: you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation, either version 3 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program. If not, see . * - * * - *******************************************************************************/ - -package com.github.shadowsocks.net - -import android.os.Build -import com.github.shadowsocks.utils.printLog -import kotlinx.coroutines.* -import kotlinx.coroutines.channels.Channel -import kotlinx.coroutines.channels.sendBlocking -import java.io.IOException -import java.nio.ByteBuffer -import java.nio.channels.* - -class ChannelMonitor : Thread("ChannelMonitor") { - private data class Registration(val channel: SelectableChannel, - val ops: Int, - val listener: (SelectionKey) -> Unit) { - val result = CompletableDeferred() - } - - private val selector = Selector.open() - private val registrationPipe = Pipe.open() - private val pendingRegistrations = Channel(Channel.UNLIMITED) - private val closeChannel = Channel(1) - @Volatile - private var running = true - - private fun registerInternal(channel: SelectableChannel, ops: Int, block: (SelectionKey) -> Unit) = - channel.register(selector, ops, block) - - init { - registrationPipe.source().apply { - configureBlocking(false) - registerInternal(this, SelectionKey.OP_READ) { - val junk = ByteBuffer.allocateDirect(1) - while (read(junk) > 0) { - pendingRegistrations.poll()!!.apply { - try { - result.complete(registerInternal(channel, ops, listener)) - } catch (e: Exception) { - result.completeExceptionally(e) - } - } - junk.clear() - } - } - } - start() - } - - /** - * Prevent NetworkOnMainThreadException because people enable strict mode for no reasons. - */ - private suspend fun WritableByteChannel.writeCompat(src: ByteBuffer) = - if (Build.VERSION.SDK_INT <= 23) withContext(Dispatchers.Default) { write(src) } else write(src) - - suspend fun register(channel: SelectableChannel, ops: Int, block: (SelectionKey) -> Unit): SelectionKey { - val registration = Registration(channel, ops, block) - pendingRegistrations.send(registration) - ByteBuffer.allocateDirect(1).also { junk -> - loop@ while (running) when (registrationPipe.sink().writeCompat(junk)) { - 0 -> kotlinx.coroutines.yield() - 1 -> break@loop - else -> throw IOException("Failed to register in the channel") - } - } - if (!running) throw CancellationException() - return registration.result.await() - } - - suspend fun wait(channel: SelectableChannel, ops: Int) = CompletableDeferred().run { - register(channel, ops) { - if (it.isValid) try { - it.interestOps(0) // stop listening - } catch (_: CancelledKeyException) { } - complete(it) - } - await() - } - - override fun run() { - while (running) { - val num = try { - selector.select() - } catch (e: Exception) { - printLog(e) - continue - } - if (num <= 0) continue - val iterator = selector.selectedKeys().iterator() - while (iterator.hasNext()) { - val key = iterator.next() - iterator.remove() - (key.attachment() as (SelectionKey) -> Unit)(key) - } - } - closeChannel.sendBlocking(Unit) - } - - fun close(scope: CoroutineScope) { - running = false - selector.wakeup() - scope.launch { - closeChannel.receive() - selector.keys().forEach { it.channel().close() } - selector.close() - } - } -} diff --git a/core/src/main/java/com/github/shadowsocks/net/Socks5Endpoint.kt b/core/src/main/java/com/github/shadowsocks/net/Socks5Endpoint.kt deleted file mode 100644 index f30b98a4d9..0000000000 --- a/core/src/main/java/com/github/shadowsocks/net/Socks5Endpoint.kt +++ /dev/null @@ -1,128 +0,0 @@ -/******************************************************************************* - * * - * Copyright (C) 2019 by Max Lv * - * Copyright (C) 2019 by Mygod Studio * - * * - * This program is free software: you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation, either version 3 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program. If not, see . * - * * - *******************************************************************************/ - -package com.github.shadowsocks.net - -import com.github.shadowsocks.utils.parseNumericAddress -import net.sourceforge.jsocks.Socks4Message -import net.sourceforge.jsocks.Socks5Message -import java.io.EOFException -import java.io.IOException -import java.net.Inet4Address -import java.net.Inet6Address -import java.nio.ByteBuffer -import kotlin.math.max - -class Socks5Endpoint(host: String, port: Int) { - private val dest = host.parseNumericAddress().let { numeric -> - val bytes = numeric?.address ?: host.toByteArray().apply { check(size < 256) { "Hostname too long" } } - val type = when (numeric) { - null -> Socks5Message.SOCKS_ATYP_DOMAINNAME - is Inet4Address -> Socks5Message.SOCKS_ATYP_IPV4 - is Inet6Address -> Socks5Message.SOCKS_ATYP_IPV6 - else -> error("Unsupported address type $numeric") - } - ByteBuffer.allocate(bytes.size + (if (numeric == null) 1 else 0) + 3).apply { - put(type.toByte()) - if (numeric == null) put(bytes.size.toByte()) - put(bytes) - putShort(port.toShort()) - } - }.array() - private val headerReserved = max(3 + 3 + 16, 3 + dest.size) - - fun tcpWrap(message: ByteBuffer): ByteBuffer { - check(message.remaining() < 65536) { "TCP message too large" } - return ByteBuffer.allocateDirect(8 + dest.size + message.remaining()).apply { - put(Socks5Message.SOCKS_VERSION.toByte()) - put(1) // nmethods - put(0) // no authentication required - // header - put(Socks5Message.SOCKS_VERSION.toByte()) - put(Socks4Message.REQUEST_CONNECT.toByte()) - put(0) // reserved - put(dest) - // data - putShort(message.remaining().toShort()) - put(message) - flip() - } - } - fun tcpReceiveBuffer(size: Int) = ByteBuffer.allocateDirect(headerReserved + 4 + size) - suspend fun tcpUnwrap(buffer: ByteBuffer, reader: (ByteBuffer) -> Int, wait: suspend () -> Unit) { - suspend fun readBytes(till: Int) { - if (buffer.position() >= till) return - while (reader(buffer) >= 0 && buffer.position() < till) wait() - if (buffer.position() < till) throw EOFException("${buffer.position()} < $till") - } - suspend fun read(index: Int): Byte { - readBytes(index + 1) - return buffer[index] - } - if (read(0) != Socks5Message.SOCKS_VERSION.toByte()) throw IOException("Unsupported SOCKS version ${buffer[0]}") - if (read(1) != 0.toByte()) throw IOException("Unsupported authentication ${buffer[1]}") - if (read(2) != Socks5Message.SOCKS_VERSION.toByte()) throw IOException("Unsupported SOCKS version ${buffer[2]}") - if (read(3) != 0.toByte()) throw IOException("SOCKS5 server returned error ${buffer[3]}") - val dataOffset = when (val type = read(5)) { - Socks5Message.SOCKS_ATYP_IPV4.toByte() -> 4 - Socks5Message.SOCKS_ATYP_DOMAINNAME.toByte() -> 1 + read(6) - Socks5Message.SOCKS_ATYP_IPV6.toByte() -> 16 - else -> throw IOException("Unsupported address type $type") - } + 8 - readBytes(dataOffset + 2) - buffer.limit(buffer.position()) // store old position to update mark - buffer.position(dataOffset) - val dataLength = buffer.short.toUShort().toInt() - val end = buffer.position() + dataLength - if (end > buffer.capacity()) throw IOException( - "Buffer too small to contain the message: $dataLength > ${buffer.capacity() - buffer.position()}") - buffer.mark() - buffer.position(buffer.limit()) // restore old position - buffer.limit(end) - readBytes(buffer.limit()) - buffer.reset() - } - - private fun ByteBuffer.tryPosition(newPosition: Int) { - if (limit() < newPosition) throw EOFException("${limit()} < $newPosition") - position(newPosition) - } - - fun udpWrap(packet: ByteBuffer) = ByteBuffer.allocateDirect(3 + dest.size + packet.remaining()).apply { - // header - putShort(0) // reserved - put(0) // fragment number - put(dest) - // data - put(packet) - flip() - } - fun udpReceiveBuffer(size: Int) = ByteBuffer.allocateDirect(headerReserved + size) - fun udpUnwrap(packet: ByteBuffer) { - packet.tryPosition(3) - packet.tryPosition(6 + when (val type = packet.get()) { - Socks5Message.SOCKS_ATYP_IPV4.toByte() -> 4 - Socks5Message.SOCKS_ATYP_DOMAINNAME.toByte() -> 1 + packet.get() - Socks5Message.SOCKS_ATYP_IPV6.toByte() -> 16 - else -> throw IOException("Unsupported address type $type") - }) - packet.mark() - } -} From b3b150a5e064f79880252ac3c7b3d25348717fcd Mon Sep 17 00:00:00 2001 From: Mygod Date: Sun, 19 Apr 2020 08:21:39 +0800 Subject: [PATCH 44/57] Move DnsResolverCompat --- core/src/main/java/com/github/shadowsocks/bg/BaseService.kt | 1 + core/src/main/java/com/github/shadowsocks/bg/LocalDnsWorker.kt | 1 + core/src/main/java/com/github/shadowsocks/bg/ProxyInstance.kt | 1 + .../com/github/shadowsocks/{bg => net}/DnsResolverCompat.kt | 2 +- 4 files changed, 4 insertions(+), 1 deletion(-) rename core/src/main/java/com/github/shadowsocks/{bg => net}/DnsResolverCompat.kt (99%) diff --git a/core/src/main/java/com/github/shadowsocks/bg/BaseService.kt b/core/src/main/java/com/github/shadowsocks/bg/BaseService.kt index e0331884ae..069abc2758 100644 --- a/core/src/main/java/com/github/shadowsocks/bg/BaseService.kt +++ b/core/src/main/java/com/github/shadowsocks/bg/BaseService.kt @@ -37,6 +37,7 @@ import com.github.shadowsocks.aidl.IShadowsocksService import com.github.shadowsocks.aidl.IShadowsocksServiceCallback import com.github.shadowsocks.aidl.TrafficStats import com.github.shadowsocks.core.R +import com.github.shadowsocks.net.DnsResolverCompat import com.github.shadowsocks.net.HostsFile import com.github.shadowsocks.preference.DataStore import com.github.shadowsocks.utils.* diff --git a/core/src/main/java/com/github/shadowsocks/bg/LocalDnsWorker.kt b/core/src/main/java/com/github/shadowsocks/bg/LocalDnsWorker.kt index 2c329a98e9..5bdc7c7076 100644 --- a/core/src/main/java/com/github/shadowsocks/bg/LocalDnsWorker.kt +++ b/core/src/main/java/com/github/shadowsocks/bg/LocalDnsWorker.kt @@ -5,6 +5,7 @@ import android.util.Log import com.crashlytics.android.Crashlytics import com.github.shadowsocks.Core import com.github.shadowsocks.net.ConcurrentLocalSocketListener +import com.github.shadowsocks.net.DnsResolverCompat import com.github.shadowsocks.utils.printLog import kotlinx.coroutines.CancellationException import kotlinx.coroutines.CoroutineScope diff --git a/core/src/main/java/com/github/shadowsocks/bg/ProxyInstance.kt b/core/src/main/java/com/github/shadowsocks/bg/ProxyInstance.kt index ff7c95740f..e93eef67b2 100644 --- a/core/src/main/java/com/github/shadowsocks/bg/ProxyInstance.kt +++ b/core/src/main/java/com/github/shadowsocks/bg/ProxyInstance.kt @@ -26,6 +26,7 @@ import com.github.shadowsocks.Core import com.github.shadowsocks.acl.Acl import com.github.shadowsocks.acl.AclSyncer import com.github.shadowsocks.database.Profile +import com.github.shadowsocks.net.DnsResolverCompat import com.github.shadowsocks.net.HostsFile import com.github.shadowsocks.plugin.PluginConfiguration import com.github.shadowsocks.plugin.PluginManager diff --git a/core/src/main/java/com/github/shadowsocks/bg/DnsResolverCompat.kt b/core/src/main/java/com/github/shadowsocks/net/DnsResolverCompat.kt similarity index 99% rename from core/src/main/java/com/github/shadowsocks/bg/DnsResolverCompat.kt rename to core/src/main/java/com/github/shadowsocks/net/DnsResolverCompat.kt index f0cff158d6..25568313b6 100644 --- a/core/src/main/java/com/github/shadowsocks/bg/DnsResolverCompat.kt +++ b/core/src/main/java/com/github/shadowsocks/net/DnsResolverCompat.kt @@ -18,7 +18,7 @@ * * *******************************************************************************/ -package com.github.shadowsocks.bg +package com.github.shadowsocks.net import android.annotation.SuppressLint import android.annotation.TargetApi From 0efeff0127a9e999e585f57d72449ed2ffc6e989 Mon Sep 17 00:00:00 2001 From: Mygod Date: Sun, 19 Apr 2020 08:23:14 +0800 Subject: [PATCH 45/57] Remove lintOptions --- core/build.gradle | 4 ---- mobile/build.gradle | 3 --- tv/build.gradle | 3 --- 3 files changed, 10 deletions(-) diff --git a/core/build.gradle b/core/build.gradle index 8c520f351b..580cbd9ebb 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -47,10 +47,6 @@ android { } ndkVersion '21.1.6210238' - - lintOptions { - disable 'InvalidPackage' - } } androidExtensions { diff --git a/mobile/build.gradle b/mobile/build.gradle index aaeb994107..890d5064ab 100644 --- a/mobile/build.gradle +++ b/mobile/build.gradle @@ -54,9 +54,6 @@ android { } sourceSets.main.jniLibs.srcDirs += new File(project(':core').buildDir, "intermediates/bundles/${getCurrentFlavor()}/jni") - lintOptions { - disable 'InvalidPackage' - } } androidExtensions { diff --git a/tv/build.gradle b/tv/build.gradle index 74434adc2d..f13743846f 100644 --- a/tv/build.gradle +++ b/tv/build.gradle @@ -53,9 +53,6 @@ android { } sourceSets.main.jniLibs.srcDirs += new File(project(':core').buildDir, "intermediates/bundles/${getCurrentFlavor()}/jni") - lintOptions { - disable 'InvalidPackage' - } } dependencies { From b630bf8a6164443afffbb8d43b2ddd5a77936a7b Mon Sep 17 00:00:00 2001 From: Mygod Date: Sun, 19 Apr 2020 08:31:22 +0800 Subject: [PATCH 46/57] Remove hardcoded ndkVersion --- core/build.gradle | 2 -- 1 file changed, 2 deletions(-) diff --git a/core/build.gradle b/core/build.gradle index 580cbd9ebb..a10383824d 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -45,8 +45,6 @@ android { sourceSets { androidTest.assets.srcDirs += files("$projectDir/schemas".toString()) } - - ndkVersion '21.1.6210238' } androidExtensions { From 871c83d90df34fab0124d00806925d3ebf77aba2 Mon Sep 17 00:00:00 2001 From: Mygod Date: Sun, 19 Apr 2020 08:56:08 +0800 Subject: [PATCH 47/57] Fix lint --- core/src/main/java/com/github/shadowsocks/utils/Utils.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/com/github/shadowsocks/utils/Utils.kt b/core/src/main/java/com/github/shadowsocks/utils/Utils.kt index d0582dc49d..69c3b45a8d 100644 --- a/core/src/main/java/com/github/shadowsocks/utils/Utils.kt +++ b/core/src/main/java/com/github/shadowsocks/utils/Utils.kt @@ -70,7 +70,7 @@ fun FileDescriptor.closeQuietly() = try { Os.close(this) } catch (_: ErrnoException) { } -private val parseNumericAddress by lazy @SuppressLint("DiscouragedPrivateApi") { +private val parseNumericAddress by lazy @SuppressLint("SoonBlockedPrivateApi") { InetAddress::class.java.getDeclaredMethod("parseNumericAddress", String::class.java).apply { isAccessible = true } From a12d0b0a06c12330021545397e035fce416a42e5 Mon Sep 17 00:00:00 2001 From: Mygod Date: Sun, 19 Apr 2020 09:00:02 +0800 Subject: [PATCH 48/57] Refine code style --- build.gradle | 2 +- .../subscription/SubscriptionService.kt | 3 - detekt.yml | 66 ++++++++++--------- 3 files changed, 37 insertions(+), 34 deletions(-) diff --git a/build.gradle b/build.gradle index 4e038aa5da..b21f490fb8 100644 --- a/build.gradle +++ b/build.gradle @@ -10,7 +10,7 @@ buildscript { sdkVersion = 29 compileSdkVersion = 29 lifecycleVersion = '2.2.0' - desugarLibsVersion = '1.0.4' + desugarLibsVersion = '1.0.5' junitVersion = '4.13' androidTestVersion = '1.2.0' androidEspressoVersion = '3.2.0' diff --git a/core/src/main/java/com/github/shadowsocks/subscription/SubscriptionService.kt b/core/src/main/java/com/github/shadowsocks/subscription/SubscriptionService.kt index 5778a376b2..5b39b0b75a 100644 --- a/core/src/main/java/com/github/shadowsocks/subscription/SubscriptionService.kt +++ b/core/src/main/java/com/github/shadowsocks/subscription/SubscriptionService.kt @@ -24,8 +24,6 @@ import android.app.NotificationChannel import android.app.NotificationManager import android.app.PendingIntent import android.app.Service -import android.content.BroadcastReceiver -import android.content.Context import android.content.Intent import android.content.IntentFilter import android.os.IBinder @@ -35,7 +33,6 @@ import androidx.annotation.RequiresApi import androidx.core.app.NotificationCompat import androidx.core.content.ContextCompat import androidx.lifecycle.MutableLiveData -import com.crashlytics.android.Crashlytics import com.github.shadowsocks.Core import com.github.shadowsocks.Core.app import com.github.shadowsocks.core.R diff --git a/detekt.yml b/detekt.yml index 235590d0ca..4874946f52 100644 --- a/detekt.yml +++ b/detekt.yml @@ -1,4 +1,4 @@ -# https://github.com/arturbosch/detekt/blob/1.5.0/detekt-cli/src/main/resources/default-detekt-config.yml +# https://github.com/arturbosch/detekt/blob/1.7.1/detekt-cli/src/main/resources/default-detekt-config.yml comments: active: false @@ -12,6 +12,7 @@ complexity: active: true threshold: 10 includeStaticDeclarations: false + includePrivateDeclarations: false ComplexMethod: active: true threshold: 15 @@ -21,7 +22,7 @@ complexity: nestingFunctions: run,let,apply,with,also,use,forEach,isNotNull,ifNull LabeledExpression: active: false - ignoredLabels: "" + ignoredLabels: '' LargeClass: active: true threshold: 600 @@ -30,8 +31,10 @@ complexity: threshold: 60 LongParameterList: active: true - threshold: 6 + functionThreshold: 6 + constructorThreshold: 7 ignoreDefaultParameters: true + ignoreDataClasses: true MethodOverloading: active: false NestedBlockDepth: @@ -39,14 +42,14 @@ complexity: threshold: 4 StringLiteralDuplication: active: true - excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt" + excludes: '**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt' threshold: 3 ignoreAnnotation: true excludeStringsWithLessThan5Characters: true ignoreStringsRegex: '$^' TooManyFunctions: active: true - excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt" + excludes: '**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt' thresholdInFiles: 11 thresholdInClasses: 11 thresholdInInterfaces: 11 @@ -67,7 +70,7 @@ empty-blocks: active: true EmptyCatchBlock: active: true - allowedExceptionNameRegex: "^(_|(ignore|expected).*)" + allowedExceptionNameRegex: '^(_|(ignore|expected).*)' EmptyClassBlock: active: true EmptyDefaultConstructor: @@ -91,6 +94,8 @@ empty-blocks: active: true EmptySecondaryConstructor: active: true + EmptyTryBlock: + active: true EmptyWhenBlock: active: true EmptyWhileBlock: @@ -115,7 +120,7 @@ exceptions: SwallowedException: active: true ignoredExceptionTypes: 'InterruptedException,NumberFormatException,ParseException,MalformedURLException' - allowedExceptionNameRegex: "^(_|(ignore|expected).*)" + allowedExceptionNameRegex: '^(_|(ignore|expected).*)' ThrowingExceptionFromFinally: active: false ThrowingExceptionInMain: @@ -127,7 +132,7 @@ exceptions: active: true TooGenericExceptionCaught: active: true - excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt" + excludes: '**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt' exceptionNames: - ArrayIndexOutOfBoundsException - Error @@ -137,7 +142,7 @@ exceptions: - IndexOutOfBoundsException - RuntimeException - Throwable - allowedExceptionNameRegex: "^(_|(ignore|expected).*)" + allowedExceptionNameRegex: '^(_|(ignore|expected).*)' TooGenericExceptionThrown: active: true exceptionNames: @@ -166,6 +171,7 @@ formatting: FinalNewline: active: true autoCorrect: true + insertFinalNewLine: true ImportOrdering: active: false Indentation: @@ -253,37 +259,37 @@ naming: ClassNaming: active: true classPattern: '[A-Z$][a-zA-Z0-9$]*' - excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt" + excludes: '**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt' ConstructorParameterNaming: active: true - excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt" + excludes: '**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt' parameterPattern: '[a-z][A-Za-z0-9]*' privateParameterPattern: '[a-z][A-Za-z0-9]*' excludeClassPattern: '$^' ignoreOverridden: true EnumNaming: active: true - excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt" + excludes: '**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt' enumEntryPattern: '^[A-Z][_a-zA-Z0-9]*' ForbiddenClassName: active: true - excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt" + excludes: '**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt' forbiddenName: '' FunctionMaxLength: active: true - excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt" + excludes: '**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt' maximumFunctionNameLength: 30 FunctionMinLength: active: false FunctionNaming: active: true - excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt" + excludes: '**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt' functionPattern: '^([a-z$][a-zA-Z$0-9]*)|(`.*`)$' excludeClassPattern: '$^' ignoreOverridden: true FunctionParameterNaming: active: true - excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt" + excludes: '**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt' parameterPattern: '[a-z][A-Za-z0-9]*' excludeClassPattern: '$^' ignoreOverridden: true @@ -292,33 +298,34 @@ naming: rootPackage: '' MatchingDeclarationName: active: true + mustBeFirst: true MemberNameEqualsClassName: active: false ObjectPropertyNaming: active: true - excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt" + excludes: '**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt' constantPattern: '[A-Za-z][_A-Za-z0-9]*' propertyPattern: '[A-Za-z][_A-Za-z0-9]*' privatePropertyPattern: '(_)?[A-Za-z][_A-Za-z0-9]*' PackageNaming: active: true - excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt" + excludes: '**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt' packagePattern: '^[a-z]+(\.[a-z][A-Za-z0-9]*)*$' TopLevelPropertyNaming: active: true - excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt" + excludes: '**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt' constantPattern: '[A-Z][_A-Z0-9]*' propertyPattern: '[A-Za-z][_A-Za-z0-9]*' privatePropertyPattern: '_?[A-Za-z][_A-Za-z0-9]*' VariableMaxLength: active: true - excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt" + excludes: '**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt' maximumVariableNameLength: 64 VariableMinLength: active: false VariableNaming: active: true - excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt" + excludes: '**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt' variablePattern: '[a-z][A-Za-z0-9]*' privateVariablePattern: '(_)?[a-z][A-Za-z0-9]*' excludeClassPattern: '$^' @@ -330,10 +337,10 @@ performance: active: true ForEachOnRange: active: true - excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt" + excludes: '**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt' SpreadOperator: active: true - excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt" + excludes: '**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt' UnnecessaryTemporaryInstantiation: active: true @@ -402,11 +409,11 @@ style: ForbiddenComment: active: true values: 'TODO:,FIXME:,STOPSHIP:' - allowedPatterns: "" + allowedPatterns: '' ForbiddenImport: active: true - imports: '' - forbiddenPatterns: "" + imports: [] + forbiddenPatterns: '' ForbiddenMethodCall: active: true methods: '' @@ -421,7 +428,7 @@ style: active: true ignoreOverridableFunction: true excludedFunctions: 'describeContents' - excludeAnnotatedFunction: "dagger.Provides" + excludeAnnotatedFunction: 'dagger.Provides' LibraryCodeMustSpecifyReturnType: active: true LoopWithTooManyJumpStatements: @@ -477,8 +484,7 @@ style: UnderscoresInNumericLiterals: active: false UnnecessaryAbstractClass: - active: true - excludeAnnotatedClasses: "dagger.Module" + active: false UnnecessaryAnnotationUseSiteTarget: active: true UnnecessaryApply: @@ -497,7 +503,7 @@ style: active: true UnusedPrivateMember: active: true - allowedNames: "(_|ignored|expected|serialVersionUID)" + allowedNames: '(_|ignored|expected|serialVersionUID)' UseArrayLiteralsInAnnotations: active: true UseCheckOrError: From a252f19a7ba8922c95d914f4b01963d96e1057fd Mon Sep 17 00:00:00 2001 From: Mygod Date: Sun, 19 Apr 2020 09:53:15 +0800 Subject: [PATCH 49/57] Add hack to make UDP fallback work --- .../main/java/com/github/shadowsocks/bg/BaseService.kt | 2 +- .../main/java/com/github/shadowsocks/bg/ProxyInstance.kt | 8 +++++--- .../com/github/shadowsocks/plugin/AlertDialogFragment.kt | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/com/github/shadowsocks/bg/BaseService.kt b/core/src/main/java/com/github/shadowsocks/bg/BaseService.kt index 069abc2758..d590386d4f 100644 --- a/core/src/main/java/com/github/shadowsocks/bg/BaseService.kt +++ b/core/src/main/java/com/github/shadowsocks/bg/BaseService.kt @@ -247,7 +247,7 @@ object BaseService { udpFallback?.start(this, File(Core.deviceStorage.noBackupFilesDir, "stat_udp"), File(configRoot, CONFIG_FILE_UDP), - "-u") + "-u", false) data.localDns = LocalDnsWorker(this::rawResolver).apply { start() } } diff --git a/core/src/main/java/com/github/shadowsocks/bg/ProxyInstance.kt b/core/src/main/java/com/github/shadowsocks/bg/ProxyInstance.kt index e93eef67b2..6d17ad09bb 100644 --- a/core/src/main/java/com/github/shadowsocks/bg/ProxyInstance.kt +++ b/core/src/main/java/com/github/shadowsocks/bg/ProxyInstance.kt @@ -110,7 +110,8 @@ class ProxyInstance(val profile: Profile, private val route: String = profile.ro * Sensitive shadowsocks configuration file requires extra protection. It may be stored in encrypted storage or * device storage, depending on which is currently available. */ - fun start(service: BaseService.Interface, stat: File, configFile: File, extraFlag: String? = null) { + fun start(service: BaseService.Interface, stat: File, configFile: File, extraFlag: String? = null, + dnsRelay: Boolean = true) { trafficMonitor = TrafficMonitor(stat) this.configFile = configFile @@ -130,11 +131,12 @@ class ProxyInstance(val profile: Profile, private val route: String = profile.ro val cmd = arrayListOf( File((service as Context).applicationInfo.nativeLibraryDir, Executable.SS_LOCAL).absolutePath, "--stat-path", stat.absolutePath, - "--dns-relay", "${DataStore.listenAddress}:${DataStore.portLocalDns}", - "--remote-dns", "${dns.host}:${if (dns.port < 0) 53 else dns.port}", "-c", configFile.absolutePath) if (service.isVpnService) cmd += arrayListOf("--vpn") if (extraFlag != null) cmd.add(extraFlag) + if (dnsRelay) cmd += arrayListOf( + "--dns-relay", "${DataStore.listenAddress}:${DataStore.portLocalDns}", + "--remote-dns", "${dns.host}:${if (dns.port < 0) 53 else dns.port}") if (route != Acl.ALL) { cmd += "--acl" diff --git a/plugin/src/main/java/com/github/shadowsocks/plugin/AlertDialogFragment.kt b/plugin/src/main/java/com/github/shadowsocks/plugin/AlertDialogFragment.kt index fcf7a55807..67571adae2 100644 --- a/plugin/src/main/java/com/github/shadowsocks/plugin/AlertDialogFragment.kt +++ b/plugin/src/main/java/com/github/shadowsocks/plugin/AlertDialogFragment.kt @@ -41,7 +41,7 @@ abstract class AlertDialogFragment : } protected abstract fun AlertDialog.Builder.prepare(listener: DialogInterface.OnClickListener) - protected val arg by lazy { arguments!!.getParcelable(KEY_ARG)!! } + protected val arg by lazy { requireArguments().getParcelable(KEY_ARG)!! } protected open fun ret(which: Int): Ret? = null fun withArg(arg: Arg) = apply { arguments = Bundle().apply { putParcelable(KEY_ARG, arg) } } From 9ce5d9e56768160c61daea745a3dc5a4aa150c7f Mon Sep 17 00:00:00 2001 From: Max Lv Date: Sun, 19 Apr 2020 10:31:04 +0800 Subject: [PATCH 50/57] Use debug cargo profile in CI --- .circleci/config.yml | 2 +- core/build.gradle | 2 +- core/src/main/rust/shadowsocks-rust | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 77e765f0df..2465703dd9 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -13,7 +13,7 @@ jobs: key: jars-{{ checksum "build.gradle" }} - run: name: Run Build and Tests - command: ./gradlew assembleDebug check + command: ./gradlew assembleDebug check -PCARGO_PROFILE=debug - save_cache: paths: - ~/.gradle diff --git a/core/build.gradle b/core/build.gradle index a10383824d..72a927314d 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -55,7 +55,7 @@ cargo { module = 'src/main/rust/shadowsocks-rust' libname = 'sslocal' targets = ['arm', 'arm64', 'x86', 'x86_64'] - profile = 'release' + profile = findProperty('CARGO_PROFILE') ?: 'release' targetIncludes = ["lib${libname}.so"] extraCargoBuildArguments = ['--bin', 'sslocal'] features { diff --git a/core/src/main/rust/shadowsocks-rust b/core/src/main/rust/shadowsocks-rust index e96f1beadd..6cc2ac327b 160000 --- a/core/src/main/rust/shadowsocks-rust +++ b/core/src/main/rust/shadowsocks-rust @@ -1 +1 @@ -Subproject commit e96f1beadd18dcadf18c2792cffe390b4f5a9c35 +Subproject commit 6cc2ac327b476219872734ad539a273810a58a7d From 0a1536a7261b794a21623d47356ee086d5b7843e Mon Sep 17 00:00:00 2001 From: Mygod Date: Sun, 19 Apr 2020 10:37:42 +0800 Subject: [PATCH 51/57] Remove outdated fix --- core/proguard-rules.pro | 5 ----- 1 file changed, 5 deletions(-) diff --git a/core/proguard-rules.pro b/core/proguard-rules.pro index f2c7cde94e..97f6f95aaa 100644 --- a/core/proguard-rules.pro +++ b/core/proguard-rules.pro @@ -20,8 +20,3 @@ # If you keep the line number information, uncomment this to # hide the original source file name. #-renamesourcefileattribute SourceFile - -# https://issuetracker.google.com/issues/147972078#comment4 --keepclasseswithmembers class * extends androidx.lifecycle.ViewModel { - (); -} From 3c7d045c5a7052abf5fd435bef8f981987143537 Mon Sep 17 00:00:00 2001 From: Mygod Date: Mon, 20 Apr 2020 02:38:48 +0800 Subject: [PATCH 52/57] Fix deprecation --- .../java/com/github/shadowsocks/AdsManager.kt | 41 +++++++++++++++++++ .../github/shadowsocks/ProfilesFragment.kt | 11 +---- 2 files changed, 43 insertions(+), 9 deletions(-) create mode 100644 mobile/src/main/java/com/github/shadowsocks/AdsManager.kt diff --git a/mobile/src/main/java/com/github/shadowsocks/AdsManager.kt b/mobile/src/main/java/com/github/shadowsocks/AdsManager.kt new file mode 100644 index 0000000000..4ebb8fa8b8 --- /dev/null +++ b/mobile/src/main/java/com/github/shadowsocks/AdsManager.kt @@ -0,0 +1,41 @@ +/******************************************************************************* + * * + * Copyright (C) 2020 by Max Lv * + * Copyright (C) 2020 by Mygod Studio * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see . * + * * + *******************************************************************************/ + +package com.github.shadowsocks + +import android.content.Context +import com.google.android.gms.ads.AdLoader +import com.google.android.gms.ads.AdRequest +import com.google.android.gms.ads.MobileAds +import com.google.android.gms.ads.RequestConfiguration + +internal object AdsManager { + init { + MobileAds.setRequestConfiguration(RequestConfiguration.Builder().apply { + setTestDeviceIds(listOf( + "B08FC1764A7B250E91EA9D0D5EBEB208", "7509D18EB8AF82F915874FEF53877A64", + "F58907F28184A828DD0DB6F8E38189C6", "FE983F496D7C5C1878AA163D9420CA97")) + }.build()) + } + + fun load(context: Context?, setup: AdLoader.Builder.() -> Unit) = + AdLoader.Builder(context, "ca-app-pub-3283768469187309/8632513739").apply(setup).build() + .loadAd(AdRequest.Builder().build()) +} diff --git a/mobile/src/main/java/com/github/shadowsocks/ProfilesFragment.kt b/mobile/src/main/java/com/github/shadowsocks/ProfilesFragment.kt index 26af06fc24..d6a2c00dd9 100644 --- a/mobile/src/main/java/com/github/shadowsocks/ProfilesFragment.kt +++ b/mobile/src/main/java/com/github/shadowsocks/ProfilesFragment.kt @@ -59,8 +59,6 @@ import com.github.shadowsocks.utils.readableMessage import com.github.shadowsocks.widget.ListHolderListener import com.github.shadowsocks.widget.MainListListener import com.github.shadowsocks.widget.UndoSnackbarManager -import com.google.android.gms.ads.AdLoader -import com.google.android.gms.ads.AdRequest import com.google.android.gms.ads.VideoOptions import com.google.android.gms.ads.formats.NativeAdOptions import com.google.android.gms.ads.formats.UnifiedNativeAd @@ -249,7 +247,7 @@ class ProfilesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener { if (adHost != null || !item.isSponsored) return if (nativeAdView == null) { nativeAdView = layoutInflater.inflate(R.layout.ad_unified, adContainer, false) as UnifiedNativeAdView - AdLoader.Builder(context, "ca-app-pub-3283768469187309/8632513739").apply { + AdsManager.load(context) { forUnifiedNativeAd { unifiedNativeAd -> // You must call destroy on old ads when you are done with them, // otherwise you will have a memory leak. @@ -262,12 +260,7 @@ class ProfilesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener { setStartMuted(true) }.build()) }.build()) - }.build().loadAd(AdRequest.Builder().apply { - addTestDevice("B08FC1764A7B250E91EA9D0D5EBEB208") - addTestDevice("7509D18EB8AF82F915874FEF53877A64") - addTestDevice("F58907F28184A828DD0DB6F8E38189C6") - addTestDevice("FE983F496D7C5C1878AA163D9420CA97") - }.build()) + } } else if (nativeAd != null) populateUnifiedNativeAdView(nativeAd!!, nativeAdView!!) } From fb0dbafbc1219fd2003281b3315fa76363082262 Mon Sep 17 00:00:00 2001 From: Mygod Date: Mon, 20 Apr 2020 04:13:37 +0800 Subject: [PATCH 53/57] Suppress local DNS resolve timeout exceptions --- .../main/java/com/github/shadowsocks/bg/LocalDnsWorker.kt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/com/github/shadowsocks/bg/LocalDnsWorker.kt b/core/src/main/java/com/github/shadowsocks/bg/LocalDnsWorker.kt index 5bdc7c7076..3c7cd82cbe 100644 --- a/core/src/main/java/com/github/shadowsocks/bg/LocalDnsWorker.kt +++ b/core/src/main/java/com/github/shadowsocks/bg/LocalDnsWorker.kt @@ -44,9 +44,11 @@ class LocalDnsWorker(private val resolver: suspend (ByteArray) -> ByteArray) : C byteArrayOf() // return empty if cannot parse packet } }?.let { response -> - val output = DataOutputStream(socket.outputStream) - output.writeShort(response.size) - output.write(response) + try { + val output = DataOutputStream(socket.outputStream) + output.writeShort(response.size) + output.write(response) + } catch (_: IOException) { } // connection early close possibly due to resolving timeout } } } From 98aa9355b77cdf1ee629898405043857b5f6a9d3 Mon Sep 17 00:00:00 2001 From: Mygod Date: Mon, 20 Apr 2020 11:01:25 +0800 Subject: [PATCH 54/57] Clean up unused jni files --- core/src/main/jni/include/libev/config.h | 126 ----- core/src/main/jni/include/pdnsd/config.h | 437 ------------------ .../jni/include/shadowsocks-libev/config.h | 428 ----------------- core/src/main/jni/include/sodium/version.h | 29 -- .../src/main/jni/patch/pcre/pcre_chartables.c | 198 -------- 5 files changed, 1218 deletions(-) delete mode 100644 core/src/main/jni/include/libev/config.h delete mode 100644 core/src/main/jni/include/pdnsd/config.h delete mode 100644 core/src/main/jni/include/shadowsocks-libev/config.h delete mode 100644 core/src/main/jni/include/sodium/version.h delete mode 100644 core/src/main/jni/patch/pcre/pcre_chartables.c diff --git a/core/src/main/jni/include/libev/config.h b/core/src/main/jni/include/libev/config.h deleted file mode 100644 index 5c46ab0fa1..0000000000 --- a/core/src/main/jni/include/libev/config.h +++ /dev/null @@ -1,126 +0,0 @@ -/* config.h. Generated from config.h.in by configure. */ -/* config.h.in. Generated from configure.ac by autoheader. */ - -/* Define to 1 if you have the `clock_gettime' function. */ -/* #undef HAVE_CLOCK_GETTIME */ - -/* Define to 1 to use the syscall interface for clock_gettime */ -#define HAVE_CLOCK_SYSCALL 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_DLFCN_H 1 - -/* Define to 1 if you have the `epoll_ctl' function. */ -#define HAVE_EPOLL_CTL 1 - -/* Define to 1 if you have the `eventfd' function. */ -#define HAVE_EVENTFD 1 - -/* Define to 1 if the floor function is available */ -#define HAVE_FLOOR 1 - -/* Define to 1 if you have the `inotify_init' function. */ -#define HAVE_INOTIFY_INIT 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_INTTYPES_H 1 - -/* Define to 1 if you have the `kqueue' function. */ -/* #undef HAVE_KQUEUE */ - -/* Define to 1 if you have the `rt' library (-lrt). */ -/* #undef HAVE_LIBRT */ - -/* Define to 1 if you have the header file. */ -#define HAVE_MEMORY_H 1 - -/* Define to 1 if you have the `nanosleep' function. */ -#define HAVE_NANOSLEEP 1 - -/* Define to 1 if you have the `poll' function. */ -#define HAVE_POLL 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_POLL_H 1 - -/* Define to 1 if you have the `port_create' function. */ -/* #undef HAVE_PORT_CREATE */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_PORT_H */ - -/* Define to 1 if you have the `select' function. */ -#define HAVE_SELECT 1 - -/* Define to 1 if you have the `signalfd' function. */ -#define HAVE_SIGNALFD 0 - -/* Define to 1 if you have the header file. */ -#define HAVE_STDINT_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STDLIB_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STRINGS_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STRING_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_EPOLL_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_EVENTFD_H 1 - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_SYS_EVENT_H */ - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_INOTIFY_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_SELECT_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_SIGNALFD_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_STAT_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_TYPES_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_UNISTD_H 1 - -/* Define to the sub-directory in which libtool stores uninstalled libraries. - */ -#define LT_OBJDIR ".libs/" - -/* Name of package */ -#define PACKAGE "libev" - -/* Define to the address where bug reports for this package should be sent. */ -#define PACKAGE_BUGREPORT "" - -/* Define to the full name of this package. */ -#define PACKAGE_NAME "" - -/* Define to the full name and version of this package. */ -#define PACKAGE_STRING "" - -/* Define to the one symbol short name of this package. */ -#define PACKAGE_TARNAME "" - -/* Define to the home page for this package. */ -#define PACKAGE_URL "" - -/* Define to the version of this package. */ -#define PACKAGE_VERSION "" - -/* Define to 1 if you have the ANSI C header files. */ -#define STDC_HEADERS 1 - -/* Version number of package */ -#define VERSION "4.11" diff --git a/core/src/main/jni/include/pdnsd/config.h b/core/src/main/jni/include/pdnsd/config.h deleted file mode 100644 index 3740beae73..0000000000 --- a/core/src/main/jni/include/pdnsd/config.h +++ /dev/null @@ -1,437 +0,0 @@ -/* config.h. Generated from config.h.in by configure. */ -/* config.h.in. Generated from configure.in by autoheader. */ -#ifndef _CONFIG_H_ -#define _CONFIG_H_ - -/* ONLY EDIT acconfig.h, NEVER config.h or config.h.in! - * config.h MAY BE OVERWRITTEN BY make, config.h.in by autoheader! */ - -/* Define your Target here. Currently defined are TARGET_LINUX (any - * architecture), TARGET_BSD (experimental; tested on FreeBSD, hopefully - * works for other BSD variants) and TARGET_CYGWIN. */ -#define TARGET TARGET_LINUX - -/* change the #undef to #define if you do not want to compile with special - * ISDN support for Linux. Note that the ISDN support will not compile ok on - * unpatched kernerls earlier than 2.2.12 (if you did apply newer isdn patches, - * it may work fine). This is not on by default because it will cause compile - * problems on some systems */ -/* #undef ISDN_SUPPORT */ - -/* The following regulates the IP Protocol support. Supported types are IPv4 - * and IPv6 (aka IPng). You may enable either or both of these protocols. - * Enabling in this context means that support for the respective protocol - * will be in the binary. When running the binary, one of the protocols may - * be activated via command line switches. Note that activating both IPv4 and - * IPv6 is pointless (and will not work because two UDP and two TCP threads - * will be started that concur for ports). Because of that, it is not allowed. - * When pdnsd runs with IPv6 activated it should be able to service queries - * from IPv6 as well as from IPv4 hosts, provided that you host is configured - * properly. - * For each of the protocols there are two options: ENABLE_IPV4 and ENABLE_IPV6 - * control whether support for the respective protocol is available in the - * binary. DEFAULT_IPV4 selects which protocol is enabled on pdnsd - * startup by default. 1 means IPv4, while 0 means IPv6. If support for - * a protocol was included in the executable, you can specify command line - * parameters to activate or deactivate that protocol (the options are -4 and - * -6), but it makes more sense to use the run_ipv4=on/off option in the - * configuration file. - * Make your choice. Note that IPv6 support is experimental in pdnsd. - * In normal operation, you will currently only need IPv4. */ -#define ENABLE_IPV4 1 -#define DEFAULT_IPV4 1 -#undef ENABLE_IPV6 - -/* In all pdnsd versions before 1.0.6, DNS queries were always done over - * TCP. Now, you have the choice. You can control that behaviour using - * the -m command line switch, and you can give a preset here. There - * are 3 different modes: - * UDP_ONLY: This is undoubtedly the fastest query method, because - * no TCP negotiation needs to be done. - * TCP_ONLY: This is slower than uo, but generally more secure - * against DNS spoofing. Note that some name servers on the - * internet do not support TCP queries, notably dnscache. - * TCP_UDP: TCP, then UDP. If the TCP query fails with a "connection refused"- - * error or times out, the query is retried using UDP. - * UDP_TCP: UDP, then TCP. If the UDP reply is truncated (i.e. the tc flag is set), - * the query is retried using TCP. */ -#define M_PRESET TCP_ONLY - -/* In addition to choosing the presets, you may also completely disable - * one of the protocols (TCP for preset UDP_ONLY and UDP for preset TCP_ONLY). - * This saves some executable space. */ -/* #undef NO_UDP_QUERIES */ -/* #undef NO_TCP_QUERIES */ - -/* With the following option, you can disable the TCP server functionality - * of pdnsd. Nearly no program does TCP queries, so you probably can do - * this safely and save some executable space and one thread. - * You also can turn off the TCP server at runtime with the --notcp option. */ -/* #undef NO_TCP_SERVER */ - -/* By undefining the following, you can disable the UDP source address - * discovery code. This is not recommended, but you may need it when - * running into compilation problems. */ -#define SRC_ADDR_DISC 1 - -/* NO_POLL specifies not to use poll(2), but select(2) instead. If you are - * unsure about what this means, just leave this as it is.*/ -/* #undef NO_POLL */ - -/* Define this for "hard" RFC 2181 compliance: this RFC states that - * implementations should discard answers whose RR sets have multiple - * different time stamps. While correct answers are generated, incorrect - * ones are normally tolerated and corrected. Full RFC compliance is - * however only achieved by deactivating this behaviour and thus being - * intolerant. */ -/* #undef RFC2181_ME_HARDER */ - -/* Define this to the device you want to use for getting random numbers. - * Leave this undefined if you wand to use the standard C library random - * function, which basically should be sufficient. - * Linux and FreeBSD have two random number devices: /dev/random and - * /dev/urandom. /dev/urandom might be less secure in some cases, but - * should still be more than sufficient. The use of /dev/random is - * discouraged, as reading from this device blocks when new random bits - * need to be gathered. */ -/* #undef RANDOM_DEVICE */ -#define R_DEFAULT 1 -/* #undef R_RANDOM */ -/* #undef R_ARC4RANDOM */ -/*#define RANDOM_DEVICE "/dev/urandom"*/ - -/* Designate which database manager to use for cacheing. - * default: native; others: gdbm */ -#define CACHE_DBM DBM_NATIVE - -#define CONFDIR "/data/data/com.github.shadowsocks" - -#define CACHEDIR "/data/data/com.github.shadowsocks" - -#define TEMPDIR "/data/data/com.github.shadowsocks/cache"; - -/* This is for various debugging facilities that produce debug output and - * double-check some values. You can enable debug messages with the -g option. - * Normally, you can switch this off safely by setting the number after DEBUG - * to 0. This will increase speed (although only marginally), save space - * in the executable (only about 12kB) and some stack space per thread - * (which may be significant if you have many threads running simultaneously). - * However, it may be an aid when debugging config files. - * The only defined debug levels by now are in the range 0 - 9. - * Define this to 9 if you want hex dumps of all the queries and replies pdnsd - * receives (you must also call pdnsd with -v9 to actually see the hex dumps). - * When in doubt, leave it defined to 1. */ -#define DEBUG 1 - -/* This defines the default verbosity of informational messages you will get. - This has nothing to to with the debug option (-g), but may be set with -v - option. 0 is for normal operation, up to 3 for debugging. - Unlike the debug messages, these messages will also be written to the syslog.*/ -#define VERBOSITY 0 - -/* Redefine this if you want another hash size. - * The number of hash buckets is computed as power of two (1< and it should be used (not on Ultrix). - */ -#define HAVE_ALLOCA_H 1 - -/* Define to 1 if you have the `asprintf' function. */ -#define HAVE_ASPRINTF 1 - -/* Define to 1 if you don't have `vprintf' but do have `_doprnt.' */ -/* #undef HAVE_DOPRNT */ - -/* Define to 1 if you have the header file. */ -#define HAVE_FCNTL_H 1 - -/* Define to 1 if you have the `getline' function. */ -#if defined(__aarch64__) || defined(__x86_64__) -#define HAVE_GETLINE 1 -#endif - -/* Define to 1 if you have the `getpwnam_r' function. */ -//#define HAVE_GETPWNAM_R 1 - -/* Define to 1 if you have the `gettimeofday' function. */ -#define HAVE_GETTIMEOFDAY 1 - -/* Define to 1 if you have the `inet_ntop' function. */ -#define HAVE_INET_NTOP 1 - -/* Define to 1 if you have the `inet_pton' function. */ -#define HAVE_INET_PTON 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_INTTYPES_H 1 - -/* Define to 1 if you have the `pthread' library (-lpthread). */ -#define HAVE_LIBPTHREAD 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_MALLOC_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_MEMORY_H 1 - -/* Define to 1 if you have the `mempcpy' function. */ -//#define HAVE_MEMPCPY 1 - -/* Define to 1 if you have the `mkfifo' function. */ -#define HAVE_MKFIFO 1 - -/* Define to 1 if you have the `nanosleep' function. */ -#define HAVE_NANOSLEEP 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_NETINET_IN_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_NET_IF_H 1 - -/* Define to 1 if you have the `poll' function. */ -#define HAVE_POLL 1 - -/* Define to 1 if you have the `select' function. */ -#define HAVE_SELECT 1 - -/* Define to 1 if you have the `snprintf' function. */ -#define HAVE_SNPRINTF 1 - -/* Define to 1 if you have the `socket' function. */ -#define HAVE_SOCKET 1 - -/* Define to 1 if the system has the type `socklen_t'. */ -#define HAVE_SOCKLEN_T 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STDINT_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STDLIB_H 1 - -/* Define to 1 if you have the `stpcpy' function. */ -#if defined(__aarch64__) || defined(__x86_64__) -#define HAVE_STPCPY 1 -#endif - -/* Define to 1 if you have the `stpncpy' function. */ -//#define HAVE_STPNCPY 1 - -/* Define to 1 if you have the `strdup' function. */ -#define HAVE_STRDUP 1 - -/* Define to 1 if you have the `strerror' function. */ -#define HAVE_STRERROR 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STRINGS_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STRING_H 1 - -/* Define to 1 if you have the `strlcpy' function. */ -/* #undef HAVE_STRLCPY */ - -/* Define to 1 if you have the `strndup' function. */ -#define HAVE_STRNDUP 1 - -/* Define to 1 if the system has the type `struct ifreq'. */ -#define HAVE_STRUCT_IFREQ 1 - -/* Define to 1 if the system has the type `struct in6_addr'. */ -#define HAVE_STRUCT_IN6_ADDR 1 - -/* Define to 1 if the system has the type `struct in_pktinfo'. */ -#define HAVE_STRUCT_IN_PKTINFO 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYSLOG_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_IOCTL_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_POLL_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_SOCKET_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_STAT_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_TIME_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_TYPES_H 1 - -/* Define to 1 if you have that is POSIX.1 compatible. */ -#define HAVE_SYS_WAIT_H 1 - -/* Define to 1 if you have the `uname' function. */ -#define HAVE_UNAME 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_UNISTD_H 1 - -/* Define to 1 if you have the `vasprintf' function. */ -#define HAVE_VASPRINTF 1 - -/* Define to 1 if you have the `vprintf' function. */ -#define HAVE_VPRINTF 1 - -/* Define to 1 if you have the `vsnprintf' function. */ -#define HAVE_VSNPRINTF 1 - -/* Define to 1 if your C compiler doesn't accept -c and -o together. */ -/* #undef NO_MINUS_C_MINUS_O */ - -/* Define to the address where bug reports for this package should be sent. */ -#define PACKAGE_BUGREPORT "" - -/* Define to the full name of this package. */ -#define PACKAGE_NAME "" - -/* Define to the full name and version of this package. */ -#define PACKAGE_STRING "" - -/* Define to the one symbol short name of this package. */ -#define PACKAGE_TARNAME "" - -/* Define to the version of this package. */ -#define PACKAGE_VERSION "" - -/* Define as the return type of signal handlers (`int' or `void'). */ -#define RETSIGTYPE void - -/* If using the C implementation of alloca, define if you know the - direction of stack growth for your system; otherwise it will be - automatically deduced at runtime. - STACK_DIRECTION > 0 => grows toward higher addresses - STACK_DIRECTION < 0 => grows toward lower addresses - STACK_DIRECTION = 0 => direction of growth unknown */ -/* #undef STACK_DIRECTION */ - -/* Define to 1 if you have the ANSI C header files. */ -#define STDC_HEADERS 1 - -/* Define to 1 if you can safely include both and . */ -#define TIME_WITH_SYS_TIME 1 - -/* Define to 1 if your declares `struct tm'. */ -/* #undef TM_IN_SYS_TIME */ - -/* Enable extensions on AIX 3, Interix. */ -#ifndef _ALL_SOURCE -# define _ALL_SOURCE 1 -#endif -/* Enable GNU extensions on systems that have them. */ -#ifndef _GNU_SOURCE -# define _GNU_SOURCE 1 -#endif -/* Enable threading extensions on Solaris. */ -#ifndef _POSIX_PTHREAD_SEMANTICS -# define _POSIX_PTHREAD_SEMANTICS 1 -#endif -/* Enable extensions on HP NonStop. */ -#ifndef _TANDEM_SOURCE -# define _TANDEM_SOURCE 1 -#endif -/* Enable general extensions on Solaris. */ -#ifndef __EXTENSIONS__ -# define __EXTENSIONS__ 1 -#endif - - -/* Define to 1 if on MINIX. */ -/* #undef _MINIX */ - -/* Define to 2 if the system does not provide POSIX.1 features except with - this defined. */ -/* #undef _POSIX_1_SOURCE */ - -/* Define to 1 if you need to in order for `stat' and other things to work. */ -/* #undef _POSIX_SOURCE */ - -/* Define to empty if `const' does not conform to ANSI C. */ -/* #undef const */ - -/* Define to `int' if does not define. */ -/* #undef pid_t */ - -/* Define to `unsigned int' if does not define. */ -/* #undef size_t */ diff --git a/core/src/main/jni/include/shadowsocks-libev/config.h b/core/src/main/jni/include/shadowsocks-libev/config.h deleted file mode 100644 index 8594fa0dbe..0000000000 --- a/core/src/main/jni/include/shadowsocks-libev/config.h +++ /dev/null @@ -1,428 +0,0 @@ -/* config.h. Generated from config.h.in by configure. */ -/* config.h.in. Generated from configure.ac by autoheader. */ - -/* Define if building universal (internal helper macro) */ -/* #undef AC_APPLE_UNIVERSAL_BUILD */ - -/* errno for incomplete non-blocking connect(2) */ -#define CONNECT_IN_PROGRESS EINPROGRESS - -/* Override libev default fd conversion macro. */ -/* #undef EV_FD_TO_WIN32_HANDLE */ - -/* Override libev default fd close macro. */ -/* #undef EV_WIN32_CLOSE_FD */ - -/* Override libev default handle conversion macro. */ -/* #undef EV_WIN32_HANDLE_TO_FD */ - -/* Reset max file descriptor size. */ -/* #undef FD_SETSIZE */ - -/* Define to 1 if you have the header file. */ -#define HAVE_ARPA_INET_H 1 - -/* Define to 1 if you have the `CCCryptorCreateWithMode' function. */ -/* #undef HAVE_CCCRYPTORCREATEWITHMODE */ - -/* Define to 1 if you have the `clock_gettime' function. */ -/* #undef HAVE_CLOCK_GETTIME */ - -/* Define to 1 to use the syscall interface for clock_gettime */ -/* #undef HAVE_CLOCK_SYSCALL */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_COMMONCRYPTO_COMMONCRYPTO_H */ - -/* Define to 1 if you have the declaration of `inet_ntop', and to 0 if you - don't. */ -#define HAVE_DECL_INET_NTOP 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_DLFCN_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_LINUX_TCP_H 1 - -/* Define to 1 if you have the `epoll_ctl' function. */ -/* #undef HAVE_EPOLL_CTL */ - -/* Define to 1 if you have the `eventfd' function. */ -/* #undef HAVE_EVENTFD */ - -/* Define to 1 if you have the `EVP_EncryptInit_ex' function. */ -/* #undef HAVE_EVP_ENCRYPTINIT_EX */ - -/* Define to 1 if you have the header file. */ -#define HAVE_FCNTL_H 1 - -/* Define to 1 if the floor function is available */ -#define HAVE_FLOOR 1 - -/* Define to 1 if you have the `fork' function. */ -#define HAVE_FORK 1 - -/* Define to 1 if you have the `getpwnam_r' function. */ -#define HAVE_GETPWNAM_R 1 - -/* Define to 1 if you have the `inet_ntop' function. */ -/* #undef HAVE_INET_NTOP */ - -/* Define to 1 if you have the `inotify_init' function. */ -/* #undef HAVE_INOTIFY_INIT */ - -/* Define to 1 if you have the header file. */ -#define HAVE_INTTYPES_H 1 - -/* Enable IPv6 support in libudns */ -#define HAVE_IPv6 1 - -/* Define to 1 if you have the `kqueue' function. */ -#define HAVE_KQUEUE 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_LANGINFO_H 1 - -/* Define to 1 if you have the `rt' library (-lrt). */ -/* #undef HAVE_LIBRT */ - -/* Define to 1 if you have the `socket' library (-lsocket). */ -/* #undef HAVE_LIBSOCKET */ - -/* Define to 1 if you have the header file. */ -#define HAVE_LIMITS_H 1 - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_LINUX_IF_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_LINUX_NETFILTER_IPV4_H */ - -/* Define to 1 if you have the header - file. */ -/* #undef HAVE_LINUX_NETFILTER_IPV6_IP6_TABLES_H */ - -/* Define to 1 if you have the header file. */ -#define HAVE_LOCALE_H 1 - -/* Define to 1 if you have the `malloc' function. */ -#define HAVE_MALLOC 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_MEMORY_H 1 - -/* Define to 1 if you have the `memset' function. */ -#define HAVE_MEMSET 1 - -/* Define to 1 if you have the `nanosleep' function. */ -#define HAVE_NANOSLEEP 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_NETDB_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_NETINET_IN_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_NET_IF_H 1 - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_OPENSSL_ENGINE_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_OPENSSL_ERR_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_OPENSSL_EVP_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_OPENSSL_PEM_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_OPENSSL_RAND_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_OPENSSL_RSA_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_OPENSSL_SHA_H */ - -/* Define to 1 if you have the `poll' function. */ -#define HAVE_POLL 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_POLL_H 1 - -/* Define to 1 if you have the `port_create' function. */ -/* #undef HAVE_PORT_CREATE */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_PORT_H */ - -/* Have PTHREAD_PRIO_INHERIT. */ -#define HAVE_PTHREAD_PRIO_INHERIT 1 - -/* Define to 1 if you have the `RAND_pseudo_bytes' function. */ -/* #undef HAVE_RAND_PSEUDO_BYTES */ - -/* Define to 1 if you have the 'select' function. */ -#define HAVE_SELECT 1 - -/* Define to 1 if you have the `setresuid' function. */ -/* #undef HAVE_SETRESUID */ - -/* Define to 1 if you have the `setreuid' function. */ -#define HAVE_SETREUID 1 - -/* Define to 1 if you have the `setrlimit' function. */ -#define HAVE_SETRLIMIT 1 - -/* Define to 1 if you have the `signalfd' function. */ -/* #undef HAVE_SIGNALFD */ - -/* Define to 1 if you have the `socket' function. */ -#define HAVE_SOCKET 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STDINT_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STDLIB_H 1 - -/* Define to 1 if you have the `strerror' function. */ -#define HAVE_STRERROR 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STRINGS_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STRING_H 1 - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_SYS_EPOLL_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_SYS_EVENTFD_H */ - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_EVENT_H 1 - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_SYS_INOTIFY_H */ - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_IOCTL_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_SELECT_H 1 - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_SYS_SIGNALFD_H */ - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_SOCKET_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_STAT_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_TYPES_H 1 - -/* Define to 1 if you have that is POSIX.1 compatible. */ -#define HAVE_SYS_WAIT_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_UNISTD_H 1 - -/* Define to 1 if you have the `vfork' function. */ -#define HAVE_VFORK 1 - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_VFORK_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_WINDOWS_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_WINSOCK2_H */ - -/* Define to 1 if `fork' works. */ -#define HAVE_WORKING_FORK 1 - -/* Define to 1 if `vfork' works. */ -#define HAVE_WORKING_VFORK 1 - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_WS2TCPIP_H */ - -/* have zlib compression support */ -/* #undef HAVE_ZLIB */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_ZLIB_H */ - -/* Define to the sub-directory in which libtool stores uninstalled libraries. - */ -#define LT_OBJDIR ".libs/" - -/* Define to 1 if assertions should be disabled. */ -/* #undef NDEBUG */ - -/* Name of package */ -#define PACKAGE "shadowsocks-libev" - -/* Define to the address where bug reports for this package should be sent. */ -#define PACKAGE_BUGREPORT "max.c.lv@gmail.com" - -/* Define to the full name of this package. */ -#define PACKAGE_NAME "shadowsocks-libev" - -/* Define to the full name and version of this package. */ -#define PACKAGE_STRING "shadowsocks-libev 2.4.8" - -/* Define to the one symbol short name of this package. */ -#define PACKAGE_TARNAME "shadowsocks-libev" - -/* Define to the home page for this package. */ -#define PACKAGE_URL "" - -/* Define to the version of this package. */ -#define PACKAGE_VERSION "2.4.8" - -/* Define to necessary symbol if this constant uses a non-standard name on - your system. */ -/* #undef PTHREAD_CREATE_JOINABLE */ - -/* Define as the return type of signal handlers (`int' or `void'). */ -#define RETSIGTYPE void - -/* Define to the type of arg 1 for `select'. */ -#define SELECT_TYPE_ARG1 int - -/* Define to the type of args 2, 3 and 4 for `select'. */ -#define SELECT_TYPE_ARG234 (fd_set *) - -/* Define to the type of arg 5 for `select'. */ -#define SELECT_TYPE_ARG5 (struct timeval *) - -/* Define to 1 if you have the ANSI C header files. */ -#define STDC_HEADERS 1 - -/* Define to 1 if you can safely include both and . */ -#define TIME_WITH_SYS_TIME 1 - -/* If the compiler supports a TLS storage class define it to that here */ -#define TLS __thread - -/* Use Apple CommonCrypto library */ -/* #undef USE_CRYPTO_APPLECC */ - -/* Use mbed TLS library */ -#define USE_CRYPTO_MBEDTLS 1 - -/* Use OpenSSL library */ -/* #undef USE_CRYPTO_OPENSSL */ - -/* Use PolarSSL library */ -/* #undef USE_CRYPTO_POLARSSL */ - -/* Enable extensions on AIX 3, Interix. */ -#ifndef _ALL_SOURCE -# define _ALL_SOURCE 1 -#endif -/* Enable GNU extensions on systems that have them. */ -#ifndef _GNU_SOURCE -# define _GNU_SOURCE 1 -#endif -/* Enable threading extensions on Solaris. */ -#ifndef _POSIX_PTHREAD_SEMANTICS -# define _POSIX_PTHREAD_SEMANTICS 1 -#endif -/* Enable extensions on HP NonStop. */ -#ifndef _TANDEM_SOURCE -# define _TANDEM_SOURCE 1 -#endif -/* Enable general extensions on Solaris. */ -#ifndef __EXTENSIONS__ -# define __EXTENSIONS__ 1 -#endif - - -/* Version number of package */ -#define VERSION "2.4.8" - -/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most - significant byte first (like Motorola and SPARC, unlike Intel). */ -#if defined AC_APPLE_UNIVERSAL_BUILD -# if defined __BIG_ENDIAN__ -# define WORDS_BIGENDIAN 1 -# endif -#else -# ifndef WORDS_BIGENDIAN -/* # undef WORDS_BIGENDIAN */ -# endif -#endif - -/* Define to 1 if on MINIX. */ -/* #undef _MINIX */ - -/* Define to 2 if the system does not provide POSIX.1 features except with - this defined. */ -/* #undef _POSIX_1_SOURCE */ - -/* Define to 1 if you need to in order for `stat' and other things to work. */ -/* #undef _POSIX_SOURCE */ - -/* Define for Solaris 2.5.1 so the uint8_t typedef from , - , or is not used. If the typedef were allowed, the - #define below would cause a syntax error. */ -/* #undef _UINT8_T */ - -/* Define to empty if `const' does not conform to ANSI C. */ -/* #undef const */ - -/* Define to `__inline__' or `__inline' if that's what the C compiler - calls it, or to nothing if 'inline' is not supported under any name. */ -#ifndef __cplusplus -/* #undef inline */ -#endif - -/* Define to `int' if does not define. */ -/* #undef pid_t */ - -/* Define to the equivalent of the C99 'restrict' keyword, or to - nothing if this is not supported. Do not define if restrict is - supported directly. */ -#define restrict __restrict -/* Work around a bug in Sun C++: it does not support _Restrict or - __restrict__, even though the corresponding Sun C compiler ends up with - "#define restrict _Restrict" or "#define restrict __restrict__" in the - previous line. Perhaps some future version of Sun C++ will work with - restrict; if so, hopefully it defines __RESTRICT like Sun C does. */ -#if defined __SUNPRO_CC && !defined __RESTRICT -# define _Restrict -# define __restrict__ -#endif - -/* Define to `unsigned int' if does not define. */ -/* #undef size_t */ - -/* Define to `int' if does not define. */ -/* #undef ssize_t */ - -/* Define to the type of an unsigned integer type of width exactly 16 bits if - such a type exists and the standard includes do not define it. */ -/* #undef uint16_t */ - -/* Define to the type of an unsigned integer type of width exactly 8 bits if - such a type exists and the standard includes do not define it. */ -/* #undef uint8_t */ - -/* Define as `fork' if `vfork' does not work. */ -/* #undef vfork */ - -/* Define to 1 if you have the header file. */ -#define HAVE_PCRE_H 1 - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_PCRE_PCRE_H */ diff --git a/core/src/main/jni/include/sodium/version.h b/core/src/main/jni/include/sodium/version.h deleted file mode 100644 index b95c40b523..0000000000 --- a/core/src/main/jni/include/sodium/version.h +++ /dev/null @@ -1,29 +0,0 @@ - -#ifndef sodium_version_H -#define sodium_version_H - -#include "export.h" - -#define SODIUM_VERSION_STRING "1.0.7" - -#define SODIUM_LIBRARY_VERSION_MAJOR 9 -#define SODIUM_LIBRARY_VERSION_MINOR 0 - -#ifdef __cplusplus -extern "C" { -#endif - -SODIUM_EXPORT -const char *sodium_version_string(void); - -SODIUM_EXPORT -int sodium_library_version_major(void); - -SODIUM_EXPORT -int sodium_library_version_minor(void); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/core/src/main/jni/patch/pcre/pcre_chartables.c b/core/src/main/jni/patch/pcre/pcre_chartables.c deleted file mode 100644 index 1e20ec29d0..0000000000 --- a/core/src/main/jni/patch/pcre/pcre_chartables.c +++ /dev/null @@ -1,198 +0,0 @@ -/************************************************* -* Perl-Compatible Regular Expressions * -*************************************************/ - -/* This file contains character tables that are used when no external tables -are passed to PCRE by the application that calls it. The tables are used only -for characters whose code values are less than 256. - -This is a default version of the tables that assumes ASCII encoding. A program -called dftables (which is distributed with PCRE) can be used to build -alternative versions of this file. This is necessary if you are running in an -EBCDIC environment, or if you want to default to a different encoding, for -example ISO-8859-1. When dftables is run, it creates these tables in the -current locale. If PCRE is configured with --enable-rebuild-chartables, this -happens automatically. - -The following #includes are present because without them gcc 4.x may remove the -array definition from the final binary if PCRE is built into a static library -and dead code stripping is activated. This leads to link errors. Pulling in the -header ensures that the array gets flagged as "someone outside this compilation -unit might reference this" and so it will always be supplied to the linker. */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "pcre_internal.h" - -const pcre_uint8 PRIV(default_tables)[] = { - -/* This table is a lower casing table. */ - - 0, 1, 2, 3, 4, 5, 6, 7, - 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, - 24, 25, 26, 27, 28, 29, 30, 31, - 32, 33, 34, 35, 36, 37, 38, 39, - 40, 41, 42, 43, 44, 45, 46, 47, - 48, 49, 50, 51, 52, 53, 54, 55, - 56, 57, 58, 59, 60, 61, 62, 63, - 64, 97, 98, 99,100,101,102,103, - 104,105,106,107,108,109,110,111, - 112,113,114,115,116,117,118,119, - 120,121,122, 91, 92, 93, 94, 95, - 96, 97, 98, 99,100,101,102,103, - 104,105,106,107,108,109,110,111, - 112,113,114,115,116,117,118,119, - 120,121,122,123,124,125,126,127, - 128,129,130,131,132,133,134,135, - 136,137,138,139,140,141,142,143, - 144,145,146,147,148,149,150,151, - 152,153,154,155,156,157,158,159, - 160,161,162,163,164,165,166,167, - 168,169,170,171,172,173,174,175, - 176,177,178,179,180,181,182,183, - 184,185,186,187,188,189,190,191, - 192,193,194,195,196,197,198,199, - 200,201,202,203,204,205,206,207, - 208,209,210,211,212,213,214,215, - 216,217,218,219,220,221,222,223, - 224,225,226,227,228,229,230,231, - 232,233,234,235,236,237,238,239, - 240,241,242,243,244,245,246,247, - 248,249,250,251,252,253,254,255, - -/* This table is a case flipping table. */ - - 0, 1, 2, 3, 4, 5, 6, 7, - 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, - 24, 25, 26, 27, 28, 29, 30, 31, - 32, 33, 34, 35, 36, 37, 38, 39, - 40, 41, 42, 43, 44, 45, 46, 47, - 48, 49, 50, 51, 52, 53, 54, 55, - 56, 57, 58, 59, 60, 61, 62, 63, - 64, 97, 98, 99,100,101,102,103, - 104,105,106,107,108,109,110,111, - 112,113,114,115,116,117,118,119, - 120,121,122, 91, 92, 93, 94, 95, - 96, 65, 66, 67, 68, 69, 70, 71, - 72, 73, 74, 75, 76, 77, 78, 79, - 80, 81, 82, 83, 84, 85, 86, 87, - 88, 89, 90,123,124,125,126,127, - 128,129,130,131,132,133,134,135, - 136,137,138,139,140,141,142,143, - 144,145,146,147,148,149,150,151, - 152,153,154,155,156,157,158,159, - 160,161,162,163,164,165,166,167, - 168,169,170,171,172,173,174,175, - 176,177,178,179,180,181,182,183, - 184,185,186,187,188,189,190,191, - 192,193,194,195,196,197,198,199, - 200,201,202,203,204,205,206,207, - 208,209,210,211,212,213,214,215, - 216,217,218,219,220,221,222,223, - 224,225,226,227,228,229,230,231, - 232,233,234,235,236,237,238,239, - 240,241,242,243,244,245,246,247, - 248,249,250,251,252,253,254,255, - -/* This table contains bit maps for various character classes. Each map is 32 -bytes long and the bits run from the least significant end of each byte. The -classes that have their own maps are: space, xdigit, digit, upper, lower, word, -graph, print, punct, and cntrl. Other classes are built from combinations. */ - - 0x00,0x3e,0x00,0x00,0x01,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - - 0x00,0x00,0x00,0x00,0x00,0x00,0xff,0x03, - 0x7e,0x00,0x00,0x00,0x7e,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - - 0x00,0x00,0x00,0x00,0x00,0x00,0xff,0x03, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0xfe,0xff,0xff,0x07,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0xfe,0xff,0xff,0x07, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - - 0x00,0x00,0x00,0x00,0x00,0x00,0xff,0x03, - 0xfe,0xff,0xff,0x87,0xfe,0xff,0xff,0x07, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - - 0x00,0x00,0x00,0x00,0xfe,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x7f, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - - 0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x7f, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - - 0x00,0x00,0x00,0x00,0xfe,0xff,0x00,0xfc, - 0x01,0x00,0x00,0xf8,0x01,0x00,0x00,0x78, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - - 0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - -/* This table identifies various classes of character by individual bits: - 0x01 white space character - 0x02 letter - 0x04 decimal digit - 0x08 hexadecimal digit - 0x10 alphanumeric or '_' - 0x80 regular expression metacharacter or binary zero -*/ - - 0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 0- 7 */ - 0x00,0x01,0x01,0x01,0x01,0x01,0x00,0x00, /* 8- 15 */ - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 16- 23 */ - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 24- 31 */ - 0x01,0x00,0x00,0x00,0x80,0x00,0x00,0x00, /* - ' */ - 0x80,0x80,0x80,0x80,0x00,0x00,0x80,0x00, /* ( - / */ - 0x1c,0x1c,0x1c,0x1c,0x1c,0x1c,0x1c,0x1c, /* 0 - 7 */ - 0x1c,0x1c,0x00,0x00,0x00,0x00,0x00,0x80, /* 8 - ? */ - 0x00,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x12, /* @ - G */ - 0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12, /* H - O */ - 0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12, /* P - W */ - 0x12,0x12,0x12,0x80,0x80,0x00,0x80,0x10, /* X - _ */ - 0x00,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x12, /* ` - g */ - 0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12, /* h - o */ - 0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12, /* p - w */ - 0x12,0x12,0x12,0x80,0x80,0x00,0x00,0x00, /* x -127 */ - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 128-135 */ - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 136-143 */ - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 144-151 */ - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 152-159 */ - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 160-167 */ - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 168-175 */ - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 176-183 */ - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 184-191 */ - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 192-199 */ - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 200-207 */ - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 208-215 */ - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 216-223 */ - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 224-231 */ - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 232-239 */ - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 240-247 */ - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};/* 248-255 */ - -/* End of pcre_chartables.c */ From 8fd03bfc6f7ef4c99e41c3b84e2af6dfb9d3679e Mon Sep 17 00:00:00 2001 From: Max Lv Date: Mon, 20 Apr 2020 12:13:29 +0800 Subject: [PATCH 55/57] Fix the UDP relay --- core/src/main/rust/shadowsocks-rust | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/rust/shadowsocks-rust b/core/src/main/rust/shadowsocks-rust index 6cc2ac327b..edeff210bd 160000 --- a/core/src/main/rust/shadowsocks-rust +++ b/core/src/main/rust/shadowsocks-rust @@ -1 +1 @@ -Subproject commit 6cc2ac327b476219872734ad539a273810a58a7d +Subproject commit edeff210bd2d94cc6a61500b009428623341af3e From cbbe3f0fa9477d7efe73adba161536607ff39c56 Mon Sep 17 00:00:00 2001 From: Max Lv Date: Mon, 20 Apr 2020 13:21:51 +0800 Subject: [PATCH 56/57] Update shadowsocks-rust --- core/src/main/rust/shadowsocks-rust | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/rust/shadowsocks-rust b/core/src/main/rust/shadowsocks-rust index edeff210bd..246b6c48bc 160000 --- a/core/src/main/rust/shadowsocks-rust +++ b/core/src/main/rust/shadowsocks-rust @@ -1 +1 @@ -Subproject commit edeff210bd2d94cc6a61500b009428623341af3e +Subproject commit 246b6c48bce6d4a83af046bd3feb4843f772b9d2 From d7b8ef6a36e6180fe71ceae0cef8004acaca35a4 Mon Sep 17 00:00:00 2001 From: Max Lv Date: Mon, 20 Apr 2020 13:29:35 +0800 Subject: [PATCH 57/57] Update Licenses --- README.md | 7 ++----- mobile/src/main/res/raw/about.html | 7 ++----- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 314e956a1c..28de976b1c 100644 --- a/README.md +++ b/README.md @@ -45,14 +45,11 @@ If you are interested in contributing or getting involved with this project, ple diff --git a/mobile/src/main/res/raw/about.html b/mobile/src/main/res/raw/about.html index f67992340e..2bd462d24b 100644 --- a/mobile/src/main/res/raw/about.html +++ b/mobile/src/main/res/raw/about.html @@ -20,14 +20,11 @@

Open Source Licenses