feat: limit the number of filters a client can have
This commit is contained in:
parent
2cb9d083c6
commit
b4094ad2f5
1 changed files with 8 additions and 2 deletions
|
|
@ -198,6 +198,9 @@ class NostrClientConnection:
|
||||||
async def _handle_request(self, subscription_id: str, filter: NostrFilter) -> List:
|
async def _handle_request(self, subscription_id: str, filter: NostrFilter) -> List:
|
||||||
filter.subscription_id = subscription_id
|
filter.subscription_id = subscription_id
|
||||||
self.remove_filter(subscription_id)
|
self.remove_filter(subscription_id)
|
||||||
|
if self._can_add_filter():
|
||||||
|
return [["NOTICE", f"Maximum number of filters ({self.client_config.max_client_filters}) exceeded."]]
|
||||||
|
|
||||||
self.filters.append(filter)
|
self.filters.append(filter)
|
||||||
events = await get_events(self.relay_id, filter)
|
events = await get_events(self.relay_id, filter)
|
||||||
serialized_events = [
|
serialized_events = [
|
||||||
|
|
@ -207,8 +210,11 @@ class NostrClientConnection:
|
||||||
serialized_events.append(resp_nip15)
|
serialized_events.append(resp_nip15)
|
||||||
return serialized_events
|
return serialized_events
|
||||||
|
|
||||||
|
def remove_filter(self, subscription_id: str):
|
||||||
|
self.filters = [f for f in self.filters if f.subscription_id != subscription_id]
|
||||||
|
|
||||||
def _handle_close(self, subscription_id: str):
|
def _handle_close(self, subscription_id: str):
|
||||||
self.remove_filter(subscription_id)
|
self.remove_filter(subscription_id)
|
||||||
|
|
||||||
def remove_filter(self, subscription_id: str):
|
def _can_add_filter(self) -> bool:
|
||||||
self.filters = [f for f in self.filters if f.subscription_id != subscription_id]
|
return self.client_config.max_client_filters != 0 and len(self.filters) >= self.client_config.max_client_filters
|
||||||
Loading…
Add table
Add a link
Reference in a new issue