Skip to content

Commit

Permalink
backport: set url test concurrency
Browse files Browse the repository at this point in the history
  • Loading branch information
arm64v8a committed Apr 17, 2023
1 parent ac03e37 commit 4f035ca
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 129 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ object DataStore : OnPreferenceDataStoreChangeListener {
var requireTransproxy by configurationStore.boolean(Key.REQUIRE_TRANSPROXY)
var transproxyMode by configurationStore.stringToInt(Key.TRANSPROXY_MODE)
var connectionTestURL by configurationStore.string(Key.CONNECTION_TEST_URL) { CONNECTION_TEST_URL }
var connectionTestConcurrent by configurationStore.int("connectionTestConcurrent") { 5 }
var alwaysShowAddress by configurationStore.boolean(Key.ALWAYS_SHOW_ADDRESS)

var appTrafficStatistics by configurationStore.boolean(Key.APP_TRAFFIC_STATISTICS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,7 @@ class ConfigurationFragment @JvmOverloads constructor(
if (DataStore.serviceState.started) SagerNet.stopService()
}

@OptIn(DelicateCoroutinesApi::class)
@Suppress("EXPERIMENTAL_API_USAGE")
fun pingTest(icmpPing: Boolean) {
stopService()
Expand Down Expand Up @@ -816,8 +817,11 @@ class ConfigurationFragment @JvmOverloads constructor(
}
test.proxyN = profilesUnfiltered.size
val profiles = ConcurrentLinkedQueue(profilesUnfiltered)
val testPool = newFixedThreadPoolContext(5, "Connection test pool")
repeat(5) {
val testPool = newFixedThreadPoolContext(
DataStore.connectionTestConcurrent,
"Connection test pool"
)
repeat(DataStore.connectionTestConcurrent) {
testJobs.add(launch(testPool) {
while (isActive) {
val profile = profiles.poll() ?: break
Expand Down Expand Up @@ -986,7 +990,7 @@ class ConfigurationFragment @JvmOverloads constructor(
val profiles = ConcurrentLinkedQueue(profilesUnfiltered)
val urlTest = UrlTest() // note: this is NOT in bg process

repeat(5) {
repeat(DataStore.connectionTestConcurrent) {
testJobs.add(launch {
while (isActive) {
val profile = profiles.poll() ?: break
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class LinkOrContentPreference : EditTextPreference {


init {
dialogLayoutResource = R.layout.layout_link_dialog
dialogLayoutResource = R.layout.layout_urltest_preference_dialog

setOnBindEditTextListener {
val linkLayout = it.rootView.findViewById<TextInputLayout>(R.id.input_layout)
Expand Down
112 changes: 0 additions & 112 deletions app/src/main/java/io/nekohasekai/sagernet/widget/LinkPreference.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,6 @@
android:layout_height="wrap_content"
android:orientation="vertical">

<TextView
android:id="@android:id/message"
style="?android:attr/textAppearanceSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginLeft="24dp"
android:layout_marginEnd="24dp"
android:layout_marginRight="24dp"
android:layout_marginBottom="48dp"
android:textColor="?android:attr/textColorSecondary" />

<com.google.android.material.textfield.TextInputLayout
android:id="@+id/input_layout"
android:layout_width="match_parent"
Expand All @@ -41,6 +29,30 @@
android:paddingTop="12dp"
android:singleLine="true"
android:typeface="monospace" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<TextView
style="?android:attr/textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/test_concurrency"
android:textColor="?android:attr/textColorSecondary" />

<com.google.android.material.textfield.TextInputEditText
android:id="@+id/edit_concurrent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:minHeight="48dp"
android:paddingTop="12dp"
android:singleLine="true"
android:typeface="monospace" />

</LinearLayout>

</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
</ScrollView>
1 change: 1 addition & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -485,4 +485,5 @@
<string name="show_group_in_notification">在通知中显示组名</string>
<string name="reset_connections">重置连接</string>
<string name="remove_duplicate">删除重复的服务器</string>
<string name="test_concurrency">测试并发</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -525,5 +525,6 @@ Anyone can write advanced plugins, which can control Matsuri. please download an
<string name="show_group_in_notification">Show group name in in notification</string>
<string name="reset_connections">Reset Connections</string>
<string name="remove_duplicate">Remove duplicate servers</string>
<string name="test_concurrency">Test concurrency</string>

</resources>
2 changes: 1 addition & 1 deletion app/src/main/res/xml/global_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@
</PreferenceCategory>

<PreferenceCategory app:title="@string/cag_misc">
<EditTextPreference
<moe.matsuri.nb4a.ui.UrlTestPreference
app:defaultValue="http://cp.cloudflare.com/"
app:icon="@drawable/ic_baseline_cast_connected_24"
app:key="connectionTestURL"
Expand Down

0 comments on commit 4f035ca

Please sign in to comment.