mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-06 10:04:56 -04:00
Extend ModuleApi with the methods we'll need to reject spam based on IP - resolves #10832 Signed-off-by: David Teller <davidt@element.io>
This commit is contained in:
parent
4ecf51812e
commit
80828eda06
4 changed files with 174 additions and 8 deletions
|
@ -555,8 +555,11 @@ class ClientIpStore(ClientIpWorkerStore):
|
|||
return ret
|
||||
|
||||
async def get_user_ip_and_agents(
|
||||
self, user: UserID
|
||||
self, user: UserID, since_ts: int = 0
|
||||
) -> List[Dict[str, Union[str, int]]]:
|
||||
"""
|
||||
Fetch IP/User Agent connection since a given timestamp.
|
||||
"""
|
||||
user_id = user.to_string()
|
||||
results = {}
|
||||
|
||||
|
@ -568,13 +571,23 @@ class ClientIpStore(ClientIpWorkerStore):
|
|||
) = key
|
||||
if uid == user_id:
|
||||
user_agent, _, last_seen = self._batch_row_update[key]
|
||||
results[(access_token, ip)] = (user_agent, last_seen)
|
||||
if last_seen >= since_ts:
|
||||
results[(access_token, ip)] = (user_agent, last_seen)
|
||||
|
||||
rows = await self.db_pool.simple_select_list(
|
||||
table="user_ips",
|
||||
keyvalues={"user_id": user_id},
|
||||
retcols=["access_token", "ip", "user_agent", "last_seen"],
|
||||
desc="get_user_ip_and_agents",
|
||||
def get_recent(txn):
|
||||
txn.execute(
|
||||
"""
|
||||
SELECT access_token, ip, user_agent, last_seen FROM user_ips
|
||||
WHERE last_seen >= ? AND user_id = ?
|
||||
ORDER BY last_seen
|
||||
DESC
|
||||
""",
|
||||
(since_ts, user_id),
|
||||
)
|
||||
return txn.fetchall()
|
||||
|
||||
rows = await self.db_pool.runInteraction(
|
||||
desc="get_user_ip_and_agents", func=get_recent
|
||||
)
|
||||
|
||||
results.update(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue