mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2024-12-12 02:04:20 -05:00
Merge pull request #2309 from matrix-org/erikj/user_ip_repl
Fix up user_ip replication commands
This commit is contained in:
commit
ed9a7f5436
@ -209,7 +209,7 @@ class Auth(object):
|
|||||||
)[0]
|
)[0]
|
||||||
if user and access_token and ip_addr:
|
if user and access_token and ip_addr:
|
||||||
self.store.insert_client_ip(
|
self.store.insert_client_ip(
|
||||||
user=user,
|
user_id=user.to_string(),
|
||||||
access_token=access_token,
|
access_token=access_token,
|
||||||
ip=ip_addr,
|
ip=ip_addr,
|
||||||
user_agent=user_agent,
|
user_agent=user_agent,
|
||||||
|
@ -29,9 +29,8 @@ class SlavedClientIpStore(BaseSlavedStore):
|
|||||||
max_entries=50000 * CACHE_SIZE_FACTOR,
|
max_entries=50000 * CACHE_SIZE_FACTOR,
|
||||||
)
|
)
|
||||||
|
|
||||||
def insert_client_ip(self, user, access_token, ip, user_agent, device_id):
|
def insert_client_ip(self, user_id, access_token, ip, user_agent, device_id):
|
||||||
now = int(self._clock.time_msec())
|
now = int(self._clock.time_msec())
|
||||||
user_id = user.to_string()
|
|
||||||
key = (user_id, access_token, ip)
|
key = (user_id, access_token, ip)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -323,14 +323,18 @@ class UserIpCommand(Command):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_line(cls, line):
|
def from_line(cls, line):
|
||||||
user_id, access_token, ip, device_id, last_seen, user_agent = line.split(" ", 5)
|
user_id, jsn = line.split(" ", 1)
|
||||||
|
|
||||||
return cls(user_id, access_token, ip, user_agent, device_id, int(last_seen))
|
access_token, ip, user_agent, device_id, last_seen = json.loads(jsn)
|
||||||
|
|
||||||
|
return cls(
|
||||||
|
user_id, access_token, ip, user_agent, device_id, last_seen
|
||||||
|
)
|
||||||
|
|
||||||
def to_line(self):
|
def to_line(self):
|
||||||
return " ".join((
|
return self.user_id + " " + json.dumps((
|
||||||
self.user_id, self.access_token, self.ip, self.device_id,
|
self.access_token, self.ip, self.user_agent, self.device_id,
|
||||||
str(self.last_seen), self.user_agent,
|
self.last_seen,
|
||||||
))
|
))
|
||||||
|
|
||||||
|
|
||||||
|
@ -56,9 +56,11 @@ class ClientIpStore(background_updates.BackgroundUpdateStore):
|
|||||||
)
|
)
|
||||||
reactor.addSystemEventTrigger("before", "shutdown", self._update_client_ips_batch)
|
reactor.addSystemEventTrigger("before", "shutdown", self._update_client_ips_batch)
|
||||||
|
|
||||||
def insert_client_ip(self, user, access_token, ip, user_agent, device_id):
|
def insert_client_ip(self, user_id, access_token, ip, user_agent, device_id,
|
||||||
now = int(self._clock.time_msec())
|
now=None):
|
||||||
key = (user.to_string(), access_token, ip)
|
if not now:
|
||||||
|
now = int(self._clock.time_msec())
|
||||||
|
key = (user_id, access_token, ip)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
last_seen = self.client_ip_last_seen.get(key)
|
last_seen = self.client_ip_last_seen.get(key)
|
||||||
|
@ -19,7 +19,6 @@ import synapse.api.errors
|
|||||||
import synapse.handlers.device
|
import synapse.handlers.device
|
||||||
|
|
||||||
import synapse.storage
|
import synapse.storage
|
||||||
from synapse import types
|
|
||||||
from tests import unittest, utils
|
from tests import unittest, utils
|
||||||
|
|
||||||
user1 = "@boris:aaa"
|
user1 = "@boris:aaa"
|
||||||
@ -179,6 +178,6 @@ class DeviceTestCase(unittest.TestCase):
|
|||||||
|
|
||||||
if ip is not None:
|
if ip is not None:
|
||||||
yield self.store.insert_client_ip(
|
yield self.store.insert_client_ip(
|
||||||
types.UserID.from_string(user_id),
|
user_id,
|
||||||
access_token, ip, "user_agent", device_id)
|
access_token, ip, "user_agent", device_id)
|
||||||
self.clock.advance_time(1000)
|
self.clock.advance_time(1000)
|
||||||
|
@ -15,9 +15,6 @@
|
|||||||
|
|
||||||
from twisted.internet import defer
|
from twisted.internet import defer
|
||||||
|
|
||||||
import synapse.server
|
|
||||||
import synapse.storage
|
|
||||||
import synapse.types
|
|
||||||
import tests.unittest
|
import tests.unittest
|
||||||
import tests.utils
|
import tests.utils
|
||||||
|
|
||||||
@ -39,7 +36,7 @@ class ClientIpStoreTestCase(tests.unittest.TestCase):
|
|||||||
self.clock.now = 12345678
|
self.clock.now = 12345678
|
||||||
user_id = "@user:id"
|
user_id = "@user:id"
|
||||||
yield self.store.insert_client_ip(
|
yield self.store.insert_client_ip(
|
||||||
synapse.types.UserID.from_string(user_id),
|
user_id,
|
||||||
"access_token", "ip", "user_agent", "device_id",
|
"access_token", "ip", "user_agent", "device_id",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user