Skip to content

Commit

Permalink
remove tunImplementation & pcap
Browse files Browse the repository at this point in the history
  • Loading branch information
arm64v8a committed Feb 15, 2023
1 parent ed74dff commit e3b1f5f
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 68 deletions.
2 changes: 0 additions & 2 deletions app/src/main/java/io/nekohasekai/sagernet/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ object Key {
const val MUX_PROTOCOLS = "mux"
const val MUX_CONCURRENCY = "muxConcurrency"

const val TUN_IMPLEMENTATION = "tunImplementation"
const val ENABLE_PCAP = "enablePcap"
const val ACQUIRE_WAKE_LOCK = "acquireWakeLock"
const val SHOW_BOTTOM_BAR = "showBottomBar"

Expand Down
5 changes: 2 additions & 3 deletions app/src/main/java/io/nekohasekai/sagernet/bg/VpnService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ class VpnService : BaseVpnService(),
val packageName = packageName
var proxyApps = DataStore.proxyApps
var bypass = DataStore.bypass
var workaroundSYSTEM = DataStore.tunImplementation == TunImplementation.SYSTEM
var workaroundSYSTEM = false /* DataStore.tunImplementation == TunImplementation.SYSTEM */
var needBypassRootUid = workaroundSYSTEM || data.proxy!!.config.outboundTagsAll.values.any {
it.nekoBean?.needBypassRootUid() == true || it.hysteriaBean?.protocol == HysteriaBean.PROTOCOL_FAKETCP
}
Expand Down Expand Up @@ -282,13 +282,12 @@ class VpnService : BaseVpnService(),
mtu = DataStore.mtu
v2Ray = data.proxy!!.v2rayPoint
iPv6Mode = ipv6Mode
implementation = DataStore.tunImplementation
implementation = 2 // Tun2Socket
sniffing = DataStore.trafficSniffing
fakeDNS = DataStore.enableFakeDns
debug = DataStore.enableLog
dumpUID = data.proxy!!.config.dumpUid
trafficStats = DataStore.appTrafficStatistics
pCap = DataStore.enablePcap
errorHandler = ErrorHandler {
stopRunner(false, it)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ object DataStore : OnPreferenceDataStoreChangeListener {
var rulesProvider by configurationStore.stringToInt(Key.RULES_PROVIDER)
var enableLog by configurationStore.boolean(Key.ENABLE_LOG)
var logBufSize by configurationStore.int(Key.LOG_BUF_SIZE) { 0 }
var enablePcap by configurationStore.boolean(Key.ENABLE_PCAP)
var acquireWakeLock by configurationStore.boolean(Key.ACQUIRE_WAKE_LOCK)
var showBottomBar by configurationStore.boolean(Key.SHOW_BOTTOM_BAR)

Expand Down Expand Up @@ -190,8 +189,6 @@ object DataStore : OnPreferenceDataStoreChangeListener {
var connectionTestURL by configurationStore.string(Key.CONNECTION_TEST_URL) { CONNECTION_TEST_URL }
var alwaysShowAddress by configurationStore.boolean(Key.ALWAYS_SHOW_ADDRESS)

var tunImplementation by configurationStore.stringToInt(Key.TUN_IMPLEMENTATION) { TunImplementation.SYSTEM }

var appTrafficStatistics by configurationStore.boolean(Key.APP_TRAFFIC_STATISTICS)
var profileTrafficStatistics by configurationStore.boolean(Key.PROFILE_TRAFFIC_STATISTICS) { true }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ data class ProxyEntity(
fun needCoreMux(): Boolean {
return when (type) {
TYPE_VMESS -> Protocols.shouldEnableMux("vmess") && isV2RayNetworkTcp()
TYPE_TROJAN -> Protocols.shouldEnableMux("trojan")
TYPE_TROJAN -> Protocols.shouldEnableMux("trojan") && isV2RayNetworkTcp()
TYPE_TROJAN_GO -> false
else -> false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import com.takisoft.preferencex.SimpleMenuPreference
import io.nekohasekai.sagernet.Key
import io.nekohasekai.sagernet.R
import io.nekohasekai.sagernet.SagerNet
import io.nekohasekai.sagernet.TunImplementation
import io.nekohasekai.sagernet.database.DataStore
import io.nekohasekai.sagernet.database.preference.EditTextPreferenceModifiers
import io.nekohasekai.sagernet.ktx.*
Expand Down Expand Up @@ -257,9 +256,7 @@ class SettingsPreferenceFragment : PreferenceFragmentCompat() {
true
}

val tunImplementation = findPreference<SimpleMenuPreference>(Key.TUN_IMPLEMENTATION)!!
val resolveDestination = findPreference<SwitchPreference>(Key.RESOLVE_DESTINATION)!!
val enablePcap = findPreference<SwitchPreference>(Key.ENABLE_PCAP)!!
val acquireWakeLock = findPreference<SwitchPreference>(Key.ACQUIRE_WAKE_LOCK)!!

speedInterval.onPreferenceChangeListener = reloadListener
Expand Down Expand Up @@ -288,31 +285,9 @@ class SettingsPreferenceFragment : PreferenceFragmentCompat() {
transproxyMode.onPreferenceChangeListener = reloadListener

appTrafficStatistics.onPreferenceChangeListener = reloadListener
tunImplementation.onPreferenceChangeListener = reloadListener
resolveDestination.onPreferenceChangeListener = reloadListener
acquireWakeLock.onPreferenceChangeListener = reloadListener

enablePcap.setOnPreferenceChangeListener { _, newValue ->
if (newValue as Boolean) {
val path = File(app.externalAssets, "pcap").absolutePath
MaterialAlertDialogBuilder(requireContext()).apply {
setTitle(R.string.pcap)
setMessage(resources.getString(R.string.pcap_notice, path))
setPositiveButton(android.R.string.ok) { _, _ ->
needReload()
}
setNegativeButton(android.R.string.copy) { _, _ ->
SagerNet.trySetPrimaryClip(path)
snackbar(R.string.copy_success).show()
}
}.show()
if (tunImplementation.value != "${TunImplementation.GVISOR}") {
tunImplementation.value = "${TunImplementation.GVISOR}"
}
} else needReload()
true
}

}

override fun onResume() {
Expand Down
13 changes: 0 additions & 13 deletions app/src/main/res/xml/global_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,6 @@
app:key="serviceMode"
app:title="@string/service_mode"
app:useSimpleSummaryProvider="true" />
<com.takisoft.preferencex.SimpleMenuPreference
app:defaultValue="2"
app:entries="@array/tun_implementation"
app:entryValues="@array/int_array_3"
app:icon="@drawable/ic_baseline_flip_camera_android_24"
app:key="tunImplementation"
app:title="@string/tun_implementation"
app:useSimpleSummaryProvider="true" />
<moe.matsuri.nya.ui.MTUPreference
app:defaultValue="9000"
app:entries="@array/mtu_select"
Expand Down Expand Up @@ -265,11 +257,6 @@
app:key="tcpKeepAliveInterval"
app:title="@string/tcp_keep_alive_interval"
app:useSimpleSummaryProvider="true" />
<SwitchPreference
app:icon="@drawable/baseline_save_24"
app:key="enablePcap"
app:summary="@string/pcap_summary"
app:title="@string/enable_pcap" />
<com.takisoft.preferencex.SimpleMenuPreference
app:defaultValue="0"
app:entries="@array/exe_prefer_provider"
Expand Down
2 changes: 1 addition & 1 deletion libcore/core_commit.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
67e97b4c2ed5c1e364e4dd0f0e473a3a33ca8050
8134d3cc23aa6b8e2a056887addf22d7d22bd969
19 changes: 1 addition & 18 deletions libcore/tun.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"math"
"net"
"os"
"path/filepath"
"sync"
"sync/atomic"
"time"
Expand Down Expand Up @@ -55,7 +54,6 @@ type TunConfig struct {
Debug bool
DumpUID bool
TrafficStats bool
PCap bool
ErrorHandler ErrorHandler
LocalResolver LocalResolver
FdProtector Protector
Expand Down Expand Up @@ -97,22 +95,7 @@ func NewTun2ray(config *TunConfig) (*Tun2ray, error) {
}
var err error
if config.Implementation == 0 { // gvisor
var pcapFile *os.File
if config.PCap {
path := externalAssetsPath + "/pcap/"
os.RemoveAll(path) // remove old pcap
err = os.MkdirAll(filepath.Dir(path), 0755)
if err != nil {
return nil, newError("unable to create pcap dir").Base(err)
}
path = path + time.Now().UTC().String() + ".pcap"
pcapFile, err = os.Create(path)
if err != nil {
return nil, newError("unable to create pcap file").Base(err)
}
}

t.dev, err = tuns.NewGvisor(config.FileDescriptor, config.MTU, t, 0x01, config.PCap, pcapFile, math.MaxUint32, config.IPv6Mode)
t.dev, err = tuns.NewGvisor(config.FileDescriptor, config.MTU, t, 0x01, math.MaxUint32, config.IPv6Mode)
} else if config.Implementation == 1 { // SYSTEM
t.dev, err = tuns.NewSystem(config.FileDescriptor, config.MTU, t, config.IPv6Mode, config.ErrorHandler.HandleError)
} else if config.Implementation == 2 { // Tun2Socket
Expand Down
7 changes: 5 additions & 2 deletions libcore/tun/tuns/tuns_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ import (
"errors"
"libcore/tun"
"libcore/tun/tun2socket"
"os"
)

func NewGvisor(dev int32, mtu int32, handler tun.Handler, nicId int32, pcap bool, pcapFile *os.File, snapLen uint32, ipv6Mode int32) (tun.Tun, error) {
// TODO wtf
// Now that Go is upgraded to 1.20, it is impossible to continue using the old gvisor.
// If you want to continue using the SagerNet-like gvisor & system stack, why not use a "sing-box For Android".

func NewGvisor(dev int32, mtu int32, handler tun.Handler, nicId int32, snapLen uint32, ipv6Mode int32) (tun.Tun, error) {
// return gvisor.New(dev, mtu, handler, tcpip.NICID(nicId), pcap, pcapFile, snapLen, ipv6Mode)
return nil, errors.New("not available")
}
Expand Down

0 comments on commit e3b1f5f

Please sign in to comment.