diff --git a/quartz/src/androidTest/java/com/vitorpamplona/quartz/nip19bech32/NIP19EmbedTests.kt b/quartz/src/androidTest/java/com/vitorpamplona/quartz/nip19Bech32/NIP19EmbedTests.kt similarity index 98% rename from quartz/src/androidTest/java/com/vitorpamplona/quartz/nip19bech32/NIP19EmbedTests.kt rename to quartz/src/androidTest/java/com/vitorpamplona/quartz/nip19Bech32/NIP19EmbedTests.kt index 9570e4282..21640fde3 100644 --- a/quartz/src/androidTest/java/com/vitorpamplona/quartz/nip19bech32/NIP19EmbedTests.kt +++ b/quartz/src/androidTest/java/com/vitorpamplona/quartz/nip19Bech32/NIP19EmbedTests.kt @@ -18,7 +18,7 @@ * 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.nip19bech32 +package com.vitorpamplona.quartz.nip19Bech32 import androidx.test.ext.junit.runners.AndroidJUnit4 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.signers.NostrSignerInternal 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.utils.Hex import junit.framework.TestCase.assertEquals diff --git a/ammolite/src/main/java/com/vitorpamplona/ammolite/relays/Limits.kt b/quartz/src/main/java/com/vitorpamplona/quartz/experimental/limits/LimitProcessor.kt similarity index 75% rename from ammolite/src/main/java/com/vitorpamplona/ammolite/relays/Limits.kt rename to quartz/src/main/java/com/vitorpamplona/quartz/experimental/limits/LimitProcessor.kt index 16a91de50..6731efd1d 100644 --- a/ammolite/src/main/java/com/vitorpamplona/ammolite/relays/Limits.kt +++ b/quartz/src/main/java/com/vitorpamplona/quartz/experimental/limits/LimitProcessor.kt @@ -18,48 +18,12 @@ * 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.ammolite.relays +package com.vitorpamplona.quartz.experimental.limits -import com.fasterxml.jackson.annotation.JsonProperty import com.vitorpamplona.ammolite.relays.filters.Filter import com.vitorpamplona.quartz.nip01Core.core.Event import com.vitorpamplona.quartz.nip13Pow.getPoWRank -import com.vitorpamplona.quartz.utils.TimeUtils.now - -class Limits( - @JsonProperty("can_write") - val canWrite: Boolean?, - @JsonProperty("can_read") - val canRead: Boolean?, - @JsonProperty("accepted_event_kinds") - val acceptedEventKinds: Set?, - @JsonProperty("blocked_event_kinds") - val blockedEventKinds: Set?, - @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>?, -) +import com.vitorpamplona.quartz.utils.TimeUtils class LimitProcessor { fun wrapFilterToLimits( @@ -117,8 +81,8 @@ class LimitProcessor { if (limits.maxEventTags != null && ev.tags.size > limits.maxEventTags) 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.createdAtMillisecsAhead != null && ev.createdAt > now() + limits.createdAtMillisecsAhead) return false + if (limits.createdAtMillisecsAgo != null && ev.createdAt < TimeUtils.now() - limits.createdAtMillisecsAgo) return false + if (limits.createdAtMillisecsAhead != null && ev.createdAt > TimeUtils.now() + limits.createdAtMillisecsAhead) return false if (limits.requiredTags != null && !matchAll(ev, limits.requiredTags)) return false diff --git a/quartz/src/main/java/com/vitorpamplona/quartz/experimental/limits/Limits.kt b/quartz/src/main/java/com/vitorpamplona/quartz/experimental/limits/Limits.kt new file mode 100644 index 000000000..348cd9454 --- /dev/null +++ b/quartz/src/main/java/com/vitorpamplona/quartz/experimental/limits/Limits.kt @@ -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?, + @JsonProperty("blocked_event_kinds") + val blockedEventKinds: Set?, + @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>?, +) diff --git a/ammolite/src/main/java/com/vitorpamplona/ammolite/relays/filters/Filter.kt b/quartz/src/main/java/com/vitorpamplona/quartz/nip01Core/relays/Filter.kt similarity index 100% rename from ammolite/src/main/java/com/vitorpamplona/ammolite/relays/filters/Filter.kt rename to quartz/src/main/java/com/vitorpamplona/quartz/nip01Core/relays/Filter.kt diff --git a/ammolite/src/main/java/com/vitorpamplona/ammolite/relays/filters/FilterMatcher.kt b/quartz/src/main/java/com/vitorpamplona/quartz/nip01Core/relays/FilterMatcher.kt similarity index 100% rename from ammolite/src/main/java/com/vitorpamplona/ammolite/relays/filters/FilterMatcher.kt rename to quartz/src/main/java/com/vitorpamplona/quartz/nip01Core/relays/FilterMatcher.kt diff --git a/ammolite/src/main/java/com/vitorpamplona/ammolite/relays/filters/FilterSerializer.kt b/quartz/src/main/java/com/vitorpamplona/quartz/nip01Core/relays/FilterSerializer.kt similarity index 100% rename from ammolite/src/main/java/com/vitorpamplona/ammolite/relays/filters/FilterSerializer.kt rename to quartz/src/main/java/com/vitorpamplona/quartz/nip01Core/relays/FilterSerializer.kt