mirror of
https://github.com/matrix-org/pantalaimon.git
synced 2024-10-01 03:35:38 -04:00
daemon: Connect the queue for unverified devices messages while sending.
This commit is contained in:
parent
212baad49e
commit
186560dd4f
@ -31,14 +31,17 @@ from pantalaimon.client import PanClient
|
||||
from pantalaimon.log import logger
|
||||
from pantalaimon.store import ClientInfo, PanStore
|
||||
from pantalaimon.thread_messages import (AcceptSasMessage, CancelSasMessage,
|
||||
CancelSendingMessage,
|
||||
ConfirmSasMessage, DaemonResponse,
|
||||
DeviceBlacklistMessage,
|
||||
DeviceUnblacklistMessage,
|
||||
DeviceUnverifyMessage,
|
||||
DeviceVerifyMessage,
|
||||
ExportKeysMessage, ImportKeysMessage,
|
||||
SasMessage, StartSasMessage,
|
||||
SasMessage, SendAnywaysMessage,
|
||||
StartSasMessage,
|
||||
UnverifiedDevicesSignal,
|
||||
UnverifiedResponse,
|
||||
UpdateDevicesMessage,
|
||||
UpdateUsersMessage)
|
||||
|
||||
@ -55,7 +58,7 @@ class ProxyDaemon:
|
||||
ssl = attr.ib(default=None)
|
||||
|
||||
decryption_timeout = 10
|
||||
unverified_send_timeout = 10
|
||||
unverified_send_timeout = 60
|
||||
|
||||
store = attr.ib(type=PanStore, init=False)
|
||||
homeserver_url = attr.ib(init=False, default=attr.Factory(dict))
|
||||
@ -314,6 +317,23 @@ class ProxyDaemon:
|
||||
info_msg
|
||||
)
|
||||
|
||||
elif isinstance(message, UnverifiedResponse):
|
||||
client = self.pan_clients[message.pan_user]
|
||||
|
||||
if message.room_id not in client.send_decision_queues:
|
||||
msg = (f"No send request found for user {message.pan_user} "
|
||||
f"and room {message.room_id}.")
|
||||
await self.send_response(
|
||||
message.message_id,
|
||||
message.pan_user,
|
||||
"m.unknown_request",
|
||||
msg
|
||||
)
|
||||
return
|
||||
|
||||
queue = client.send_decision_queues[message.room_id]
|
||||
await queue.put(message)
|
||||
|
||||
def get_access_token(self, request):
|
||||
# type: (aiohttp.web.BaseRequest) -> str
|
||||
"""Extract the access token from the request.
|
||||
@ -777,15 +797,15 @@ class ProxyDaemon:
|
||||
# There are unverified/unblocked devices in the room, notify
|
||||
# the UI thread about this and wait for a response.
|
||||
queue = asyncio.Queue()
|
||||
client.send_decision_queues[room_id] = queue
|
||||
|
||||
message = UnverifiedDevicesSignal(
|
||||
client.user_id,
|
||||
room_id,
|
||||
room.display_name
|
||||
)
|
||||
await self.send_queue.put(message)
|
||||
|
||||
# TODO allow dbus clients to answer us here.
|
||||
await self.send_queue.put(message)
|
||||
|
||||
try:
|
||||
response = await asyncio.wait_for(
|
||||
@ -793,12 +813,34 @@ class ProxyDaemon:
|
||||
self.unverified_send_timeout
|
||||
)
|
||||
|
||||
if response == "cancel":
|
||||
if isinstance(response, CancelSendingMessage):
|
||||
# The send was canceled notify the client that sent the
|
||||
# request about this.
|
||||
info_msg = (f"Canceled message sending for room "
|
||||
f"{room.display_name} ({room_id}).")
|
||||
logger.info(info_msg)
|
||||
await self.send_response(
|
||||
response.message_id,
|
||||
client.user_id,
|
||||
"m.ok",
|
||||
info_msg
|
||||
)
|
||||
|
||||
return web.Response(status=503, text=str(e))
|
||||
elif response == "send-anyways":
|
||||
|
||||
elif isinstance(response, SendAnywaysMessage):
|
||||
# We are sending and ignoring devices along the way.
|
||||
info_msg = (f"Ignoring unverified devices and sending "
|
||||
f"message to room "
|
||||
f"{room.display_name} ({room_id}).")
|
||||
logger.info(info_msg)
|
||||
await self.send_response(
|
||||
response.message_id,
|
||||
client.user_id,
|
||||
"m.ok",
|
||||
info_msg
|
||||
)
|
||||
|
||||
ret = await _send(True)
|
||||
await self.send_update_devcies()
|
||||
return ret
|
||||
@ -807,11 +849,6 @@ class ProxyDaemon:
|
||||
# We didn't get a response to our signal, send out an error
|
||||
# response.
|
||||
|
||||
ret = await _send(True)
|
||||
await self.send_update_devcies()
|
||||
|
||||
return ret
|
||||
|
||||
return web.Response(
|
||||
status=503,
|
||||
text=(f"Room contains unverified devices and no "
|
||||
@ -821,8 +858,7 @@ class ProxyDaemon:
|
||||
)
|
||||
|
||||
finally:
|
||||
# Clear up the queue
|
||||
pass
|
||||
client.send_decision_queues.pop(room_id)
|
||||
|
||||
async def filter(self, request):
|
||||
access_token = self.get_access_token(request)
|
||||
|
@ -356,7 +356,7 @@ class PanCtl:
|
||||
self.completer.rooms[pan_user].add(room_id)
|
||||
print(f"Error sending message for user {pan_user}, "
|
||||
f"there are unverified devices in the room {display_name} "
|
||||
f"({room_id}). Use the send-anyways or cancel-sending commands "
|
||||
f"({room_id}).\nUse the send-anyways or cancel-sending commands "
|
||||
f"to ignore the devices or cancel the sending.")
|
||||
|
||||
def show_response(self, response_id, pan_user, message):
|
||||
|
@ -27,6 +27,23 @@ class UnverifiedDevicesSignal(Message):
|
||||
room_display_name = attr.ib()
|
||||
|
||||
|
||||
@attr.s
|
||||
class UnverifiedResponse(Message):
|
||||
message_id = attr.ib()
|
||||
pan_user = attr.ib()
|
||||
room_id = attr.ib()
|
||||
|
||||
|
||||
@attr.s
|
||||
class SendAnywaysMessage(UnverifiedResponse):
|
||||
pass
|
||||
|
||||
|
||||
@attr.s
|
||||
class CancelSendingMessage(UnverifiedResponse):
|
||||
pass
|
||||
|
||||
|
||||
@attr.s
|
||||
class DaemonResponse(Message):
|
||||
message_id = attr.ib()
|
||||
|
@ -23,6 +23,7 @@ from pydbus.generic import signal
|
||||
from pantalaimon.log import logger
|
||||
from pantalaimon.store import PanStore
|
||||
from pantalaimon.thread_messages import (AcceptSasMessage, CancelSasMessage,
|
||||
CancelSendingMessage,
|
||||
ConfirmSasMessage, DaemonResponse,
|
||||
DeviceBlacklistMessage,
|
||||
DeviceUnblacklistMessage,
|
||||
@ -30,7 +31,8 @@ from pantalaimon.thread_messages import (AcceptSasMessage, CancelSasMessage,
|
||||
DeviceVerifyMessage,
|
||||
ExportKeysMessage, ImportKeysMessage,
|
||||
InviteSasSignal, SasDoneSignal,
|
||||
ShowSasSignal, StartSasMessage,
|
||||
SendAnywaysMessage, ShowSasSignal,
|
||||
StartSasMessage,
|
||||
UnverifiedDevicesSignal,
|
||||
UpdateDevicesMessage,
|
||||
UpdateUsersMessage)
|
||||
@ -73,11 +75,13 @@ class Control:
|
||||
<method name='SendAnyways'>
|
||||
<arg type='s' name='pan_user' direction='in'/>
|
||||
<arg type='s' name='room_id' direction='in'/>
|
||||
<arg type='u' name='id' direction='out'/>
|
||||
</method>
|
||||
|
||||
<method name='CancelSending'>
|
||||
<arg type='s' name='pan_user' direction='in'/>
|
||||
<arg type='s' name='room_id' direction='in'/>
|
||||
<arg type='u' name='id' direction='out'/>
|
||||
</method>
|
||||
|
||||
<signal name="Response">
|
||||
@ -140,10 +144,22 @@ class Control:
|
||||
return message.message_id
|
||||
|
||||
def SendAnyways(self, pan_user, room_id):
|
||||
pass
|
||||
message = SendAnywaysMessage(
|
||||
self.message_id,
|
||||
pan_user,
|
||||
room_id
|
||||
)
|
||||
self.queue.put(message)
|
||||
return message.message_id
|
||||
|
||||
def CancelSending(self, pan_user, room_id):
|
||||
pass
|
||||
message = CancelSendingMessage(
|
||||
self.message_id,
|
||||
pan_user,
|
||||
room_id
|
||||
)
|
||||
self.queue.put(message)
|
||||
return message.message_id
|
||||
|
||||
|
||||
class Devices:
|
||||
|
Loading…
Reference in New Issue
Block a user