Bug fix relay management
This commit is contained in:
1 parent
db679535aa
commit
f62e04d73b
4 files changed
+10
-5
No files matched your search
@@ -1,6 +1,7 @@
|
|||||||
package ac.cord.auxiliary.compose.network.dto
|
package ac.cord.auxiliary.compose.network.dto
|
||||||
|
|
||||||
import ac.cord.auxiliary.compose.database.model.Relay
|
import ac.cord.auxiliary.compose.database.model.Relay
|
||||||
|
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
@@ -9,7 +10,6 @@ data class RelayDTO(
|
|||||||
val read: Boolean,
|
val read: Boolean,
|
||||||
val write: Boolean,
|
val write: Boolean,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Relay.mapToRelayDTO() =
|
fun Relay.mapToRelayDTO() =
|
||||||
|
|||||||
+5
-2
@@ -117,10 +117,13 @@ class RelayPool(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun addRelaysIfMissing(relays: Set<RelayDTO>) {
|
fun addRelaysIfMissing(relays: Set<RelayDTO>) {
|
||||||
val existingRelayUrls = socketClients.map { it.socketUrl }
|
logger.d("addRelaysIfMissing: ${relays.map { it.url }}")
|
||||||
|
val existingRelayUrls = socketClients.map { NormalizedRelayUrl(it.socketUrl).displayUrl() }
|
||||||
|
logger.d("Existing Relays: $existingRelayUrls")
|
||||||
val newRelayUrls = relays.map { it.url }
|
val newRelayUrls = relays.map { it.url }
|
||||||
|
|
||||||
val toAddRelayUrls = newRelayUrls.filter { it !in existingRelayUrls }.toSet()
|
val toAddRelayUrls = newRelayUrls.filter { NormalizedRelayUrl(it).displayUrl() !in existingRelayUrls }.toSet()
|
||||||
|
logger.d("toAddRelayUrls: $toAddRelayUrls")
|
||||||
val toAddSocketClients = relays.filter { it.url in toAddRelayUrls }.mapAsNostrSocketClient()
|
val toAddSocketClients = relays.filter { it.url in toAddRelayUrls }.mapAsNostrSocketClient()
|
||||||
logger.d("toAddSocketClients: ${toAddSocketClients.map { it.socketUrl }}" )
|
logger.d("toAddSocketClients: ${toAddSocketClients.map { it.socketUrl }}" )
|
||||||
val newSocketClients = socketClients.toMutableSet().apply {
|
val newSocketClients = socketClients.toMutableSet().apply {
|
||||||
|
|||||||
+1
-1
@@ -134,7 +134,7 @@ class RelaysSocketManager constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun tryConnectingToUserRelay(url: String) = relayPool.tryConnectingToRelay(url)
|
// suspend fun tryConnectingToUserRelay(url: String) = relayPool.tryConnectingToRelay(url)
|
||||||
|
|
||||||
suspend fun query(reqCommand: ReqCmd, relayUrl: String): Flow<NostrIncomingMessage> {
|
suspend fun query(reqCommand: ReqCmd, relayUrl: String): Flow<NostrIncomingMessage> {
|
||||||
return relayPool.query(
|
return relayPool.query(
|
||||||
|
|||||||
+3
-1
@@ -2,6 +2,8 @@ package ac.cord.auxiliary.compose.network.sockets
|
|||||||
|
|
||||||
import ac.cord.auxiliary.compose.exceptions.NetworkException
|
import ac.cord.auxiliary.compose.exceptions.NetworkException
|
||||||
import co.touchlab.kermit.Logger
|
import co.touchlab.kermit.Logger
|
||||||
|
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
|
||||||
|
import fr.acinq.lightning.channel.states.Normal
|
||||||
import io.ktor.client.HttpClient
|
import io.ktor.client.HttpClient
|
||||||
import io.ktor.client.plugins.websocket.webSocketSession
|
import io.ktor.client.plugins.websocket.webSocketSession
|
||||||
import io.ktor.websocket.CloseReason
|
import io.ktor.websocket.CloseReason
|
||||||
@@ -61,7 +63,7 @@ internal class NostrSocketClientImpl(
|
|||||||
|
|
||||||
wsMutex.withLock {
|
wsMutex.withLock {
|
||||||
if (wsSession == null || wsSession?.isActive == false) {
|
if (wsSession == null || wsSession?.isActive == false) {
|
||||||
wsSession = acquireWebSocketSession(url = socketUrl)
|
wsSession = acquireWebSocketSession(socketUrl)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user