Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ class ServerEditFragment : ComposeFragment() {
name = model.name,
address = model.address,
port = model.port,
useIPv4Only = model.useIPv4Only,
httpsEnabled = model.httpsEnabled,
apiPath = model.apiPath,
authentication = model.authentication,
Expand Down Expand Up @@ -158,6 +159,7 @@ private fun ServerEditScreen(
name: MutableState<String>,
address: MutableState<String>,
port: TremotesfIntegerNumberInputFieldState,
useIPv4Only: MutableState<Boolean>,
httpsEnabled: MutableState<Boolean>,
apiPath: MutableState<String>,
authentication: MutableState<Boolean>,
Expand Down Expand Up @@ -329,6 +331,14 @@ private fun ServerEditScreen(
.padding(horizontal = horizontalPadding)
)

TremotesfSwitchWithText(
checked = useIPv4Only.value,
text = R.string.use_ipv4_only,
onCheckedChange = useIPv4Only::value::set,
modifier = Modifier.fillMaxWidth(),
horizontalContentPadding = horizontalPadding
)

TremotesfSwitchWithText(
checked = httpsEnabled.value,
text = R.string.use_https_protocol,
Expand Down Expand Up @@ -642,6 +652,7 @@ private fun ServerEditScreenPreview() = ScreenPreview {
name = remember { mutableStateOf("hmm") },
address = remember { mutableStateOf("4.2.4.2") },
port = rememberTremotesfIntegerNumberInputFieldState(42),
useIPv4Only = remember { mutableStateOf(false) },
httpsEnabled = remember { mutableStateOf(false) },
apiPath = remember { mutableStateOf("/lol") },
authentication = remember { mutableStateOf(false) },
Expand Down Expand Up @@ -679,6 +690,7 @@ class ServerEditFragmentViewModel(
val port by savedStateHandle.saveable(saver = TremotesfIntegerNumberInputFieldState.Saver()) {
TremotesfIntegerNumberInputFieldState((editingServer.port).toLong())
}
val useIPv4Only by savedStateHandle.saveable<MutableState<Boolean>> { mutableStateOf(editingServer.useIPv4Only) }
val httpsEnabled by savedStateHandle.saveable<MutableState<Boolean>> { mutableStateOf(editingServer.httpsEnabled) }
val apiPath by savedStateHandle.saveable<MutableState<String>> { mutableStateOf(editingServer.apiPath) }
val authentication by savedStateHandle.saveable<MutableState<Boolean>> { mutableStateOf(editingServer.authentication) }
Expand Down Expand Up @@ -782,6 +794,7 @@ class ServerEditFragmentViewModel(
proxyUser = proxyUser.value.trim(),
proxyPassword = proxyPassword.value.trim(),

useIPv4Only = useIPv4Only.value,
httpsEnabled = httpsEnabled.value,
selfSignedCertificateEnabled = selfSignedCertificateEnabled.value,
selfSignedCertificate = selfSignedCertificate.value.trim(),
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -565,4 +565,6 @@ SPDX-License-Identifier: GPL-3.0-or-later
<string name="sort_order">Sort order:</string>
<string name="ascending">Ascending</string>
<string name="descending">Descending</string>

<string name="use_ipv4_only">Use IPv4 only</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ internal fun createConnectionConfiguration(server: Server, retryOnConnectionFail
InetSocketAddress.createUnresolved(server.proxyHostname, server.proxyPort)
)
})
.dns(DnsFilter(server.useIPv4Only))
var clientCertificates: List<Certificate> = emptyList()
val clientCertificate = if (server.clientCertificateEnabled) server.clientCertificate.takeIf { it.isNotBlank() } else null
val serverCertificate = if (server.selfSignedCertificateEnabled) server.selfSignedCertificate.takeIf { it.isNotBlank() } else null
Expand Down
17 changes: 17 additions & 0 deletions rpc/src/main/kotlin/org/equeim/tremotesf/rpc/DnsFilter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.equeim.tremotesf.rpc

import okhttp3.Dns
import java.net.InetAddress
import java.net.Inet4Address

class DnsFilter(private val useIPv4Only: Boolean) : Dns {
override fun lookup(hostname: String): List<InetAddress> {
var addresses = Dns.SYSTEM.lookup(hostname)

if (useIPv4Only) {
addresses = addresses.filter { Inet4Address::class.java.isInstance(it) }
}

return addresses
}
}
2 changes: 2 additions & 0 deletions rpc/src/main/kotlin/org/equeim/tremotesf/rpc/Server.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ data class Server(
@SerialName("proxyPassword")
val proxyPassword: String = "",

@SerialName("useIPv4Only")
val useIPv4Only: Boolean = false,
@SerialName("httpsEnabled")
val httpsEnabled: Boolean = false,
@SerialName("selfSignedCertificateEnabled")
Expand Down