Moves limits and Filters to quartz
This commit is contained in:
+1
-3
@@ -18,7 +18,7 @@
|
|||||||
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
* 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.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
package com.vitorpamplona.quartz.nip19bech32
|
package com.vitorpamplona.quartz.nip19Bech32
|
||||||
|
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||||
import com.vitorpamplona.quartz.experimental.medical.FhirResourceEvent
|
import com.vitorpamplona.quartz.experimental.medical.FhirResourceEvent
|
||||||
@@ -28,8 +28,6 @@ import com.vitorpamplona.quartz.nip01Core.hasValidSignature
|
|||||||
import com.vitorpamplona.quartz.nip01Core.hexToByteArray
|
import com.vitorpamplona.quartz.nip01Core.hexToByteArray
|
||||||
import com.vitorpamplona.quartz.nip01Core.signers.NostrSignerInternal
|
import com.vitorpamplona.quartz.nip01Core.signers.NostrSignerInternal
|
||||||
import com.vitorpamplona.quartz.nip10Notes.TextNoteEvent
|
import com.vitorpamplona.quartz.nip10Notes.TextNoteEvent
|
||||||
import com.vitorpamplona.quartz.nip19Bech32.Nip19Parser
|
|
||||||
import com.vitorpamplona.quartz.nip19Bech32.decodePrivateKeyAsHexOrNull
|
|
||||||
import com.vitorpamplona.quartz.nip19Bech32.entities.NEmbed
|
import com.vitorpamplona.quartz.nip19Bech32.entities.NEmbed
|
||||||
import com.vitorpamplona.quartz.utils.Hex
|
import com.vitorpamplona.quartz.utils.Hex
|
||||||
import junit.framework.TestCase.assertEquals
|
import junit.framework.TestCase.assertEquals
|
||||||
+4
-40
@@ -18,48 +18,12 @@
|
|||||||
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
* 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.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
package com.vitorpamplona.ammolite.relays
|
package com.vitorpamplona.quartz.experimental.limits
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty
|
|
||||||
import com.vitorpamplona.ammolite.relays.filters.Filter
|
import com.vitorpamplona.ammolite.relays.filters.Filter
|
||||||
import com.vitorpamplona.quartz.nip01Core.core.Event
|
import com.vitorpamplona.quartz.nip01Core.core.Event
|
||||||
import com.vitorpamplona.quartz.nip13Pow.getPoWRank
|
import com.vitorpamplona.quartz.nip13Pow.getPoWRank
|
||||||
import com.vitorpamplona.quartz.utils.TimeUtils.now
|
import com.vitorpamplona.quartz.utils.TimeUtils
|
||||||
|
|
||||||
class Limits(
|
|
||||||
@JsonProperty("can_write")
|
|
||||||
val canWrite: Boolean?,
|
|
||||||
@JsonProperty("can_read")
|
|
||||||
val canRead: Boolean?,
|
|
||||||
@JsonProperty("accepted_event_kinds")
|
|
||||||
val acceptedEventKinds: Set<Int>?,
|
|
||||||
@JsonProperty("blocked_event_kinds")
|
|
||||||
val blockedEventKinds: Set<Int>?,
|
|
||||||
@JsonProperty("min_pow_difficulty")
|
|
||||||
val minPoW: Int?,
|
|
||||||
@JsonProperty("max_message_length")
|
|
||||||
val maxMessageLength: Int?,
|
|
||||||
@JsonProperty("max_subscriptions")
|
|
||||||
val maxSubscriptions: Int?,
|
|
||||||
@JsonProperty("max_filters")
|
|
||||||
val maxFilters: Int?,
|
|
||||||
@JsonProperty("max_limit")
|
|
||||||
val maxLimit: Int?,
|
|
||||||
@JsonProperty("max_event_tags")
|
|
||||||
val maxEventTags: Int?,
|
|
||||||
@JsonProperty("max_content_length")
|
|
||||||
val maxContentLength: Int?,
|
|
||||||
@JsonProperty("created_at_msecs_ago")
|
|
||||||
val createdAtMillisecsAgo: Long?,
|
|
||||||
@JsonProperty("created_at_msecs_ahead")
|
|
||||||
val createdAtMillisecsAhead: Long?,
|
|
||||||
@JsonProperty("filter_rate_limit")
|
|
||||||
val filterRateLimit: Long?,
|
|
||||||
@JsonProperty("publishing_rate_limit")
|
|
||||||
val publishingRateLimit: Long?,
|
|
||||||
@JsonProperty("required_tags")
|
|
||||||
val requiredTags: Array<Array<String>>?,
|
|
||||||
)
|
|
||||||
|
|
||||||
class LimitProcessor {
|
class LimitProcessor {
|
||||||
fun wrapFilterToLimits(
|
fun wrapFilterToLimits(
|
||||||
@@ -117,8 +81,8 @@ class LimitProcessor {
|
|||||||
if (limits.maxEventTags != null && ev.tags.size > limits.maxEventTags) return false
|
if (limits.maxEventTags != null && ev.tags.size > limits.maxEventTags) return false
|
||||||
if (limits.maxContentLength != null && ev.content.length > limits.maxContentLength) return false
|
if (limits.maxContentLength != null && ev.content.length > limits.maxContentLength) return false
|
||||||
|
|
||||||
if (limits.createdAtMillisecsAgo != null && ev.createdAt < now() - limits.createdAtMillisecsAgo) return false
|
if (limits.createdAtMillisecsAgo != null && ev.createdAt < TimeUtils.now() - limits.createdAtMillisecsAgo) return false
|
||||||
if (limits.createdAtMillisecsAhead != null && ev.createdAt > now() + limits.createdAtMillisecsAhead) return false
|
if (limits.createdAtMillisecsAhead != null && ev.createdAt > TimeUtils.now() + limits.createdAtMillisecsAhead) return false
|
||||||
|
|
||||||
if (limits.requiredTags != null && !matchAll(ev, limits.requiredTags)) return false
|
if (limits.requiredTags != null && !matchAll(ev, limits.requiredTags)) return false
|
||||||
|
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2024 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.quartz.experimental.limits
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty
|
||||||
|
|
||||||
|
class Limits(
|
||||||
|
@JsonProperty("can_write")
|
||||||
|
val canWrite: Boolean?,
|
||||||
|
@JsonProperty("can_read")
|
||||||
|
val canRead: Boolean?,
|
||||||
|
@JsonProperty("accepted_event_kinds")
|
||||||
|
val acceptedEventKinds: Set<Int>?,
|
||||||
|
@JsonProperty("blocked_event_kinds")
|
||||||
|
val blockedEventKinds: Set<Int>?,
|
||||||
|
@JsonProperty("min_pow_difficulty")
|
||||||
|
val minPoW: Int?,
|
||||||
|
@JsonProperty("max_message_length")
|
||||||
|
val maxMessageLength: Int?,
|
||||||
|
@JsonProperty("max_subscriptions")
|
||||||
|
val maxSubscriptions: Int?,
|
||||||
|
@JsonProperty("max_filters")
|
||||||
|
val maxFilters: Int?,
|
||||||
|
@JsonProperty("max_limit")
|
||||||
|
val maxLimit: Int?,
|
||||||
|
@JsonProperty("max_event_tags")
|
||||||
|
val maxEventTags: Int?,
|
||||||
|
@JsonProperty("max_content_length")
|
||||||
|
val maxContentLength: Int?,
|
||||||
|
@JsonProperty("created_at_msecs_ago")
|
||||||
|
val createdAtMillisecsAgo: Long?,
|
||||||
|
@JsonProperty("created_at_msecs_ahead")
|
||||||
|
val createdAtMillisecsAhead: Long?,
|
||||||
|
@JsonProperty("filter_rate_limit")
|
||||||
|
val filterRateLimit: Long?,
|
||||||
|
@JsonProperty("publishing_rate_limit")
|
||||||
|
val publishingRateLimit: Long?,
|
||||||
|
@JsonProperty("required_tags")
|
||||||
|
val requiredTags: Array<Array<String>>?,
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user