From a08eefacfd9c1502e833b41037a44c3aed5ff6ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Wed, 28 Jul 2021 14:08:01 +0800 Subject: [PATCH] Replace NIO with Epoll implementation --- .github/workflows/debug.yml | 36 --------------- .github/workflows/release.yml | 45 ------------------- .gitmodules | 6 +++ .idea/gradle.xml | 1 + .idea/vcs.xml | 2 + app/build.gradle.kts | 3 ++ .../java/io/nekohasekai/sagernet/SagerNet.kt | 2 + .../java/io/nekohasekai/sagernet/ktx/Nets.kt | 16 ++++++- .../java/io/nekohasekai/sagernet/ktx/Utils.kt | 1 + .../nekohasekai/sagernet/tun/TcpForwarder.kt | 16 +++---- .../io/nekohasekai/sagernet/tun/TunThread.kt | 11 ++++- .../nekohasekai/sagernet/tun/UdpForwarder.kt | 14 +++--- bin/init/action/library.sh | 1 + bin/lib/core.sh | 9 ---- buildSrc/src/main/kotlin/Helpers.kt | 39 ++++++++++++---- external/netty | 1 + external/netty-jni-util | 1 + library/epoll/build.gradle.kts | 5 +++ library/epoll/src/main/AndroidManifest.xml | 4 ++ library/epoll/src/main/cpp/CMakeLists.txt | 37 +++++++++++++++ settings.gradle.kts | 1 + 21 files changed, 134 insertions(+), 117 deletions(-) delete mode 100755 bin/lib/core.sh create mode 160000 external/netty create mode 160000 external/netty-jni-util create mode 100644 library/epoll/build.gradle.kts create mode 100644 library/epoll/src/main/AndroidManifest.xml create mode 100644 library/epoll/src/main/cpp/CMakeLists.txt diff --git a/.github/workflows/debug.yml b/.github/workflows/debug.yml index 35bd305a..95d88f54 100644 --- a/.github/workflows/debug.yml +++ b/.github/workflows/debug.yml @@ -13,34 +13,6 @@ on: - dev jobs: - core: - name: Native Build (Core) - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Fetch Status - run: git submodule status 'library/core/*' > core_status - - name: Core Cache - id: cache - uses: actions/cache@v2 - with: - path: | - app/libs/core-release.aar - key: ${{ hashFiles('core_status') }} - - name: Gradle cache - uses: actions/cache@v2 - if: steps.cache.outputs.cache-hit != 'true' - with: - path: ~/.gradle - key: native-${{ hashFiles('**/*.gradle') }} - - name: Native Build - if: steps.cache.outputs.cache-hit != 'true' - run: | - echo "sdk.dir=${ANDROID_HOME}" > local.properties - echo "ndk.dir=${ANDROID_HOME}/ndk/21.4.7075529" >> local.properties - ./run init action library - ./run lib core v2ray: name: Native Build (V2Ray) runs-on: ubuntu-latest @@ -252,7 +224,6 @@ jobs: name: Gradle Build runs-on: ubuntu-latest needs: - - core - v2ray - shadowsocks - shadowsocksr @@ -261,16 +232,9 @@ jobs: uses: actions/checkout@v2 - name: Fetch Status run: | - git submodule status 'library/core/*' > core_status git submodule status 'library/shadowsocks/*' > shadowsocks_status git submodule status 'library/shadowsocksr/*' > shadowsocksr_status git submodule status library/v2ray > v2ray_status - - name: Core Cache - uses: actions/cache@v2 - with: - path: | - app/libs/core-release.aar - key: ${{ hashFiles('core_status') }} - name: V2Ray Cache uses: actions/cache@v2 with: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7e604709..ca3e1354 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -25,35 +25,6 @@ jobs: permission: "write" env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - core: - name: Native Build (Core) - runs-on: ubuntu-latest - needs: check - steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Fetch Status - run: git submodule status 'library/core/*' > core_status - - name: Core Cache - id: cache - uses: actions/cache@v2 - with: - path: | - app/libs/core-release.aar - key: ${{ hashFiles('core_status') }} - - name: Gradle cache - uses: actions/cache@v2 - if: steps.cache.outputs.cache-hit != 'true' - with: - path: ~/.gradle - key: native-${{ hashFiles('**/*.gradle') }} - - name: Native Build - if: steps.cache.outputs.cache-hit != 'true' - run: | - echo "sdk.dir=${ANDROID_HOME}" > local.properties - echo "ndk.dir=${ANDROID_HOME}/ndk/21.4.7075529" >> local.properties - ./run init action library - ./run lib core v2ray: name: Native Build (V2Ray) runs-on: ubuntu-latest @@ -152,7 +123,6 @@ jobs: name: Gradle Build runs-on: ubuntu-latest needs: - - core - v2ray - shadowsocks - shadowsocksr @@ -161,16 +131,9 @@ jobs: uses: actions/checkout@v2 - name: Fetch Status run: | - git submodule status 'library/core/*' > core_status git submodule status 'library/shadowsocks/*' > shadowsocks_status git submodule status 'library/shadowsocksr/*' > shadowsocksr_status git submodule status library/v2ray > v2ray_status - - name: Core Cache - uses: actions/cache@v2 - with: - path: | - app/libs/core-release.aar - key: ${{ hashFiles('core_status') }} - name: V2Ray Cache uses: actions/cache@v2 with: @@ -281,7 +244,6 @@ jobs: if: github.event.inputs.play != 'y' runs-on: ubuntu-latest needs: - - core - v2ray - shadowsocks - shadowsocksr @@ -290,16 +252,9 @@ jobs: uses: actions/checkout@v2 - name: Fetch Status run: | - git submodule status 'library/core/*' > core_status git submodule status 'library/shadowsocks/*' > shadowsocks_status git submodule status 'library/shadowsocksr/*' > shadowsocksr_status git submodule status library/v2ray > v2ray_status - - name: Core Cache - uses: actions/cache@v2 - with: - path: | - app/libs/core-release.aar - key: ${{ hashFiles('core_status') }} - name: V2Ray Cache uses: actions/cache@v2 with: diff --git a/.gitmodules b/.gitmodules index a90d2cb2..a4dc6022 100644 --- a/.gitmodules +++ b/.gitmodules @@ -58,3 +58,9 @@ [submodule "plugin/trojan/src/main/cpp/trojan"] path = plugin/trojan/src/main/cpp/trojan url = https://github.com/trojan-gfw/trojan +[submodule "external/netty"] + path = external/netty + url = https://github.com/netty/netty +[submodule "external/netty-jni-util"] + path = external/netty-jni-util + url = https://github.com/netty/netty-jni-util diff --git a/.idea/gradle.xml b/.idea/gradle.xml index c6670684..1659114b 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -64,6 +64,7 @@