mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-11-10 07:37:12 +01:00
Renames the MinimumRelayList to RecommendationProcessor
This commit is contained in:
@@ -24,9 +24,9 @@ import com.vitorpamplona.quartz.encoders.HexKey
|
||||
import com.vitorpamplona.quartz.encoders.RelayUrlFormatter
|
||||
import com.vitorpamplona.quartz.events.AdvertisedRelayListEvent
|
||||
|
||||
class MinimumRelayListProcessor {
|
||||
class RelayListRecommendationProcessor {
|
||||
companion object {
|
||||
fun transpose(
|
||||
private fun transpose(
|
||||
userList: Map<HexKey, MutableSet<String>>,
|
||||
ignore: Set<String> = setOf(),
|
||||
): Map<String, MutableSet<HexKey>> {
|
||||
@@ -52,7 +52,7 @@ class MinimumRelayListProcessor {
|
||||
* filter onion and local host from write relays
|
||||
* for each user pubkey, a list of valid relays.
|
||||
*/
|
||||
fun filterValidRelays(
|
||||
private fun filterValidRelays(
|
||||
userList: List<AdvertisedRelayListEvent>,
|
||||
hasOnionConnection: Boolean = false,
|
||||
): MutableMap<HexKey, MutableSet<String>> {
|
||||
@@ -76,17 +76,7 @@ class MinimumRelayListProcessor {
|
||||
return validWriteRelayUrls
|
||||
}
|
||||
|
||||
fun reliableRelaySetFor(
|
||||
userList: List<AdvertisedRelayListEvent>,
|
||||
relayUrlsToIgnore: Set<String> = emptySet(),
|
||||
hasOnionConnection: Boolean = false,
|
||||
): Set<RelayRecommendation> =
|
||||
reliableRelaySetFor(
|
||||
filterValidRelays(userList, hasOnionConnection),
|
||||
relayUrlsToIgnore,
|
||||
)
|
||||
|
||||
fun reliableRelaySetFor(
|
||||
private fun reliableRelaySetFor(
|
||||
usersAndRelays: MutableMap<HexKey, MutableSet<String>>,
|
||||
relayUrlsToIgnore: Set<String> = emptySet(),
|
||||
): Set<RelayRecommendation> {
|
||||
@@ -154,6 +144,16 @@ class MinimumRelayListProcessor {
|
||||
|
||||
return returningSet
|
||||
}
|
||||
|
||||
fun reliableRelaySetFor(
|
||||
userList: List<AdvertisedRelayListEvent>,
|
||||
relayUrlsToIgnore: Set<String> = emptySet(),
|
||||
hasOnionConnection: Boolean = false,
|
||||
): Set<RelayRecommendation> =
|
||||
reliableRelaySetFor(
|
||||
filterValidRelays(userList, hasOnionConnection),
|
||||
relayUrlsToIgnore,
|
||||
)
|
||||
}
|
||||
|
||||
class RelayRecommendation(
|
||||
@@ -24,7 +24,7 @@ import junit.framework.TestCase.assertEquals
|
||||
import junit.framework.TestCase.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
class MinimumRelayListProcessorTest {
|
||||
class RelayListRecommendationProcessorTest {
|
||||
val userList =
|
||||
mutableMapOf(
|
||||
"User1" to mutableSetOf("wss://relay1.com", "wss://relay2.com", "wss://relay3.com"),
|
||||
@@ -44,13 +44,13 @@ class MinimumRelayListProcessorTest {
|
||||
"wss://relay5.com" to listOf("User2"),
|
||||
"wss://relay6.com" to listOf("User2", "User3"),
|
||||
).toString(),
|
||||
MinimumRelayListProcessor.transpose(userList).toString(),
|
||||
RelayListRecommendationProcessor.transpose(userList).toString(),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testProcessor() {
|
||||
val recommendations = MinimumRelayListProcessor.reliableRelaySetFor(userList).toList()
|
||||
val recommendations = RelayListRecommendationProcessor.reliableRelaySetFor(userList).toList()
|
||||
|
||||
val rec1 = recommendations[0]
|
||||
|
||||
Reference in New Issue
Block a user