refactor(tor): extract TorRelaySettings, TorRelayEvaluation to commons/commonMain
Move relay routing logic to shared commons module: - TorRelaySettings data class - TorRelayEvaluation with useTor() routing logic Android files replaced with typealiases for backward compatibility. All tests pass. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
+2
-27
@@ -20,30 +20,5 @@
|
|||||||
*/
|
*/
|
||||||
package com.vitorpamplona.amethyst.model.torState
|
package com.vitorpamplona.amethyst.model.torState
|
||||||
|
|
||||||
import com.vitorpamplona.amethyst.commons.tor.TorType
|
// Canonical type now lives in commons
|
||||||
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
|
typealias TorRelayEvaluation = com.vitorpamplona.amethyst.commons.tor.TorRelayEvaluation
|
||||||
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.isLocalHost
|
|
||||||
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.isOnion
|
|
||||||
|
|
||||||
class TorRelayEvaluation(
|
|
||||||
val torSettings: TorRelaySettings,
|
|
||||||
val trustedRelayList: Set<NormalizedRelayUrl>,
|
|
||||||
val dmRelayList: Set<NormalizedRelayUrl>,
|
|
||||||
) {
|
|
||||||
fun useTor(relay: NormalizedRelayUrl): Boolean =
|
|
||||||
if (torSettings.torType == TorType.OFF) {
|
|
||||||
false
|
|
||||||
} else {
|
|
||||||
if (relay.isLocalHost()) {
|
|
||||||
false
|
|
||||||
} else if (relay.isOnion()) {
|
|
||||||
torSettings.onionRelaysViaTor
|
|
||||||
} else if (relay in dmRelayList) {
|
|
||||||
torSettings.dmRelaysViaTor
|
|
||||||
} else if (relay in trustedRelayList) {
|
|
||||||
torSettings.trustedRelaysViaTor
|
|
||||||
} else {
|
|
||||||
torSettings.newRelaysViaTor
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
+2
-9
@@ -20,12 +20,5 @@
|
|||||||
*/
|
*/
|
||||||
package com.vitorpamplona.amethyst.model.torState
|
package com.vitorpamplona.amethyst.model.torState
|
||||||
|
|
||||||
import com.vitorpamplona.amethyst.commons.tor.TorType
|
// Canonical type now lives in commons
|
||||||
|
typealias TorRelaySettings = com.vitorpamplona.amethyst.commons.tor.TorRelaySettings
|
||||||
data class TorRelaySettings(
|
|
||||||
val torType: TorType = TorType.OFF,
|
|
||||||
val onionRelaysViaTor: Boolean = true,
|
|
||||||
val dmRelaysViaTor: Boolean = false,
|
|
||||||
val newRelaysViaTor: Boolean = false,
|
|
||||||
val trustedRelaysViaTor: Boolean = false,
|
|
||||||
)
|
|
||||||
|
|||||||
+48
@@ -0,0 +1,48 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2025 Vitor Pamplona
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
* this software and associated documentation files (the "Software"), to deal in
|
||||||
|
* the Software without restriction, including without limitation the rights to use,
|
||||||
|
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
|
||||||
|
* Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
|
* subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||||
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
||||||
|
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package com.vitorpamplona.amethyst.commons.tor
|
||||||
|
|
||||||
|
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
|
||||||
|
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.isLocalHost
|
||||||
|
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.isOnion
|
||||||
|
|
||||||
|
class TorRelayEvaluation(
|
||||||
|
val torSettings: TorRelaySettings,
|
||||||
|
val trustedRelayList: Set<NormalizedRelayUrl>,
|
||||||
|
val dmRelayList: Set<NormalizedRelayUrl>,
|
||||||
|
) {
|
||||||
|
fun useTor(relay: NormalizedRelayUrl): Boolean =
|
||||||
|
if (torSettings.torType == TorType.OFF) {
|
||||||
|
false
|
||||||
|
} else {
|
||||||
|
if (relay.isLocalHost()) {
|
||||||
|
false
|
||||||
|
} else if (relay.isOnion()) {
|
||||||
|
torSettings.onionRelaysViaTor
|
||||||
|
} else if (relay in dmRelayList) {
|
||||||
|
torSettings.dmRelaysViaTor
|
||||||
|
} else if (relay in trustedRelayList) {
|
||||||
|
torSettings.trustedRelaysViaTor
|
||||||
|
} else {
|
||||||
|
torSettings.newRelaysViaTor
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+29
@@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2025 Vitor Pamplona
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
* this software and associated documentation files (the "Software"), to deal in
|
||||||
|
* the Software without restriction, including without limitation the rights to use,
|
||||||
|
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
|
||||||
|
* Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
|
* subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||||
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
||||||
|
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package com.vitorpamplona.amethyst.commons.tor
|
||||||
|
|
||||||
|
data class TorRelaySettings(
|
||||||
|
val torType: TorType = TorType.OFF,
|
||||||
|
val onionRelaysViaTor: Boolean = true,
|
||||||
|
val dmRelaysViaTor: Boolean = false,
|
||||||
|
val newRelaysViaTor: Boolean = false,
|
||||||
|
val trustedRelaysViaTor: Boolean = false,
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user