feat: change rate limit to per hour instead of per second
This commit is contained in:
parent
6e67443ea4
commit
09707151c5
3 changed files with 11 additions and 11 deletions
|
|
@ -98,7 +98,7 @@ class NostrClientConnection:
|
||||||
self._auth_challenge: Optional[str] = None
|
self._auth_challenge: Optional[str] = None
|
||||||
self._auth_challenge_created_at = 0
|
self._auth_challenge_created_at = 0
|
||||||
|
|
||||||
self._last_event_timestamp = 0 # in seconds
|
self._last_event_timestamp = 0 # in hours
|
||||||
self._event_count_per_timestamp = 0
|
self._event_count_per_timestamp = 0
|
||||||
|
|
||||||
self.broadcast_event: Optional[
|
self.broadcast_event: Optional[
|
||||||
|
|
@ -296,8 +296,8 @@ class NostrClientConnection:
|
||||||
return True, ""
|
return True, ""
|
||||||
|
|
||||||
def _validate_event(self, e: NostrEvent) -> Tuple[bool, str]:
|
def _validate_event(self, e: NostrEvent) -> Tuple[bool, str]:
|
||||||
if self._exceeded_max_events_per_second():
|
if self._exceeded_max_events_per_hour():
|
||||||
return False, f"Exceeded max events per second limit'!"
|
return False, f"Exceeded max events per hour limit'!"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
e.check_signature()
|
e.check_signature()
|
||||||
|
|
@ -349,11 +349,11 @@ class NostrClientConnection:
|
||||||
|
|
||||||
return True, ""
|
return True, ""
|
||||||
|
|
||||||
def _exceeded_max_events_per_second(self) -> bool:
|
def _exceeded_max_events_per_hour(self) -> bool:
|
||||||
if self.client_config.max_events_per_second == 0:
|
if self.client_config.max_events_per_hour == 0:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
current_time = round(time.time())
|
current_time = round(time.time() / 3600)
|
||||||
if self._last_event_timestamp == current_time:
|
if self._last_event_timestamp == current_time:
|
||||||
self._event_count_per_timestamp += 1
|
self._event_count_per_timestamp += 1
|
||||||
else:
|
else:
|
||||||
|
|
@ -361,7 +361,7 @@ class NostrClientConnection:
|
||||||
self._event_count_per_timestamp = 0
|
self._event_count_per_timestamp = 0
|
||||||
|
|
||||||
return (
|
return (
|
||||||
self._event_count_per_timestamp > self.client_config.max_events_per_second
|
self._event_count_per_timestamp > self.client_config.max_events_per_hour
|
||||||
)
|
)
|
||||||
|
|
||||||
def _created_at_in_range(self, created_at: int) -> Tuple[bool, str]:
|
def _created_at_in_range(self, created_at: int) -> Tuple[bool, str]:
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ class FilterSpec(Spec):
|
||||||
|
|
||||||
|
|
||||||
class EventSpec(Spec):
|
class EventSpec(Spec):
|
||||||
max_events_per_second = Field(0, alias="maxEventsPerSecond")
|
max_events_per_hour = Field(0, alias="maxEventsPerHour")
|
||||||
|
|
||||||
created_at_days_past = Field(0, alias="createdAtDaysPast")
|
created_at_days_past = Field(0, alias="createdAtDaysPast")
|
||||||
created_at_hours_past = Field(0, alias="createdAtHoursPast")
|
created_at_hours_past = Field(0, alias="createdAtHoursPast")
|
||||||
|
|
|
||||||
|
|
@ -497,12 +497,12 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row items-center no-wrap q-mb-md">
|
<div class="row items-center no-wrap q-mb-md">
|
||||||
<div class="col-3 q-pr-lg">Max events per second:</div>
|
<div class="col-3 q-pr-lg">Max events per hour:</div>
|
||||||
<div class="col-3 col-sm-4 q-pr-lg">
|
<div class="col-3 col-sm-4 q-pr-lg">
|
||||||
<q-input
|
<q-input
|
||||||
filled
|
filled
|
||||||
dense
|
dense
|
||||||
v-model.trim="relay.config.maxEventsPerSecond"
|
v-model.trim="relay.config.maxEventsPerHour"
|
||||||
type="number"
|
type="number"
|
||||||
min="0"
|
min="0"
|
||||||
></q-input>
|
></q-input>
|
||||||
|
|
@ -515,7 +515,7 @@
|
||||||
</q-tooltip></q-icon
|
</q-tooltip></q-icon
|
||||||
>
|
>
|
||||||
<q-badge
|
<q-badge
|
||||||
v-if="relay.config.maxEventsPerSecond == 0"
|
v-if="relay.config.maxEventsPerHour == 0"
|
||||||
color="green"
|
color="green"
|
||||||
class="float-right"
|
class="float-right"
|
||||||
><span>No Limit</span>
|
><span>No Limit</span>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue