@@ -19,102 +19,124 @@ time window after a user disconnected.
19
19
20
20
## Proposal
21
21
22
- Events can contain a ` "m.will_expire": "running" | "expired" | "ended" ` field.
23
- This is marking the event as expired ` "m.will_expire": "expired" | "ended" ` or as
24
- still alive ` "m.will_expire": "running" ` .
25
- This field lives outside the ciphertext content (hence it also works for encrypted
26
- events) and is set via the usual ` PUT ` request if the content contains the additional
27
- ` "m.will_expire": 10 ` field (similar how it is done with relations), with the desired
28
- timeout duration in seconds.
22
+ The proposed solution is to allow sending multiple presigned events and delegate
23
+ the control of when to actually send these events to an external services.
29
24
30
- Request
25
+ We call those events ` Futures ` .
26
+
27
+ A new endpoint is introduced:
28
+ ` PUT /_matrix/client/v3/rooms/{roomId}/send/{eventType}/{txnId}/future `
29
+ and
30
+ ` PUT /_matrix/client/v3/rooms/{roomId}/state/{eventType}/{stateKey}/future `
31
+ It behaves exactly like the normal send endpoint except that that it allows
32
+ to send a list of event contents. The body looks as following:
31
33
32
34
``` json
33
35
{
34
- "m.will_expire" : 10 ,
35
- "body" : " hello"
36
+ "m.timeout" : 10 ,
37
+ "m.send_on_timeout" : {...sendEventBody },
38
+
39
+ "m.send_on_action:${actionName}" : {...sendEventBody },
40
+
41
+ // optional
42
+ "m.send_now" : {...sendEventBody },
36
43
}
37
44
```
38
45
39
- If the homeserver detects a ` m.will_expire ` field it will store and distribute the
40
- event as hiding the timeout duration:
46
+ Each of the ` sendEventBody ` objects are exactly the same as sending a normal
47
+ event.
41
48
42
- ``` json
43
- {
44
- "content" :{
45
- "m.will_expire" : " running" ,
46
- "body" : " hello" ,
47
- },
48
- "other_fields" :" sender, origin_server_ts ..."
49
- }
50
- ```
49
+ There can be an arbitrary amount of ` actionName ` s.
50
+
51
+ All of the fields are optional except the ` timeout ` and the ` send_on_timeout ` .
52
+ This guarantees that all tokens will expire eventually.
53
+
54
+ The homeserver can set a limit to the timeout and return an error if the limit
55
+ is exceeded.
51
56
52
- The response to the client will be :
57
+ The response will mimic the request :
53
58
54
59
``` json
55
60
{
56
- "eventId" : " id_hash" ,
57
- "expire_refresh_token" : " refresh_hash" ,
61
+
62
+ "m.send_on_timeout" : {
63
+ "eventId" : " id_hash"
64
+ },
65
+ "m.send_on_action:${actionName}" : {
66
+ "eventId" : " id_hash"
67
+ },
68
+
69
+ "timeout_refresh_token" : " refresh_token" ,
70
+
71
+ // optional
72
+ "m.send_now" : { "eventId" : " id_hash" },
58
73
}
59
74
```
60
75
61
- The default response is extended with the ` expire_refresh_token ` which
62
- can be used to reset the expiration timeout (in this example 10 seconds).
63
- A new unauthenticated endpoint is introduced:
64
- ` PUT /_matrix/client/v3/expiration/{refresh_method} `
65
- where the ` refresh_method ` is one of: ` [refresh, end] `
66
- The body contains the refresh token so the homeserver knows what to refresh.
76
+ The ` refresh_token ` can be used to call another future related endpoint:
77
+ ` PUT /_matrix/client/v3/futures/refresh ` and ` PUT /_matrix/client/v3/futures/action/${actionName} ` .
78
+ where the body is:
67
79
68
80
``` json
69
81
{
70
- "expire_refresh_token" : " refresh_hash " ,
82
+ "timeout_refresh_token" : " refresh_token "
71
83
}
72
84
```
73
85
74
86
The information required to call this endpoint is very limited so that almost
75
87
no metadata is leaked. This allows to share a refresh link to a different
76
88
service (an SFU for instance) that can track the current client connection state,
77
- and pings the HS to refresh and informs the HS about a disconnect.
78
-
79
- The homeserver does the following when receiving an event with ` m.will_expire `
80
-
81
- - It generates a token and stores it alongside with the time of retrieval,
82
- the eventId and the expire duration.
83
- - Starts a timer for the stored expiration token.
84
- - If a ` PUT /_matrix/client/v3/expiration/refresh ` is received, the
85
- timer is restarted with the stored expire duration.
86
- - If a ` PUT /_matrix/client/v3/expiration/end ` is received, the
87
- event _ gets ended_ .
88
- - If the timer times out, the event _ gets expired_ .
89
- - If the event is a state event only the latest/current state is considered. If
90
- the homeserver receives a new state event without ` m.will_expire ` but with the
91
- same state key, the expire_refresh_token gets invalidated and the associated timer
92
- is stopped.
93
-
94
- The event _ gets expired_ /_ gets ended_ means:
95
-
96
- - The homeserver ** sends a new event** that is a copy of the previous event but:
97
- - If it gets _ expired_ the event will include: ` "m.will_expire": "expired" `
98
- - If it gets _ ended_ the event will include: ` "m.will_expire": "ended" ` .
99
- - Additionally it includes a relation to the original event with ` rel_type: "m.expire.relationship" `
100
-
101
- ``` json
102
- "m.relates_to" : {
103
- "event_id" : " $original_event" ,
104
- "rel_type" : " m.expire.relationship"
105
- },
106
- "m.will_expire" : " ended" | "expired",
107
- ```
108
-
109
- - The homeserver stops the associated timer and invalidates (deletes) the `expire_refresh_token`
110
-
111
- So for each event that is sent with `m.will_expire: X` where X is duration in
112
- seconds > 0. The homeserver will sent another event which can be used to trigger
113
- logic on the client. This allows for any generic timeout logic.
114
-
115
- Timed messages/reminders could also be implemented using this where clients ignore
116
- the `"will_expire":"running"` events for a specific event type but render the
117
- `"will_expire":"expired"` events.
89
+ and pings the HS to refresh and call a dedicated action to communicate
90
+ that the user has intentionally left the conference.
91
+
92
+ The homeserver does the following when receiving a Future.
93
+
94
+ - It sends the optional ` m.send_now ` event.
95
+ - It generates a ` timeout_refresh_token ` and stores it alongside with the time
96
+ of retrieval, the event list and the timeout duration.
97
+ - Starts a timer for the stored ` timeout_refresh_token ` .
98
+ - If a ` PUT /_matrix/client/v3/futures/refresh ` is received, the
99
+ timer is restarted with the stored timeout duration.
100
+ - If a ` PUT /_matrix/client/v3/futures/action/${actionName} ` is received, one of
101
+ the associated ` m.action:${actionName} `
102
+ event will be send.
103
+ - If the timer times out, the one of the ` m.send_timeout ` event will be sent.
104
+ - If the future
105
+ - is a state event (` PUT /_matrix/client/v3/rooms/{roomId}/state/{eventType}/{stateKey}/future ` )
106
+ - and includes a ` m.send_now ` event
107
+
108
+ the future is only valid while the ` m.send_now `
109
+ is still the current state. This means, if the homeserver receives
110
+ a new state event for the same state key, the ` timeout_refresh_token `
111
+ gets invalidated and the associated timer is stopped.
112
+ - There is no race condition here since a possible race between timeout and
113
+ new event will always converge to the new event:
114
+ - Timeout -> new event: the room state will be updated twice. once by
115
+ the content of the ` m.send_on_timeout ` event but later with the new event.
116
+ - new event -> timeout: the new event will invalidate the future. No
117
+ - When a timeout or action future is sent, the homeserver stops the associated
118
+ timer and invalidates (deletes) the ` timeout_refresh_token ` .
119
+
120
+ So for each Future the client sends, the homeserver will send one event
121
+ conditionally at an unknown time that can trigger logic on the client.
122
+ This allows for any generic timeout logic.
123
+
124
+ Timed messages/reminders or ephemeral events could be implemented using this where
125
+ clients send a redact as a future or a room event with intentional mentions.
126
+
127
+ In some scenarios it is important to allow to send an event with an associated
128
+ future at the same time.
129
+
130
+ - One example would be redacting an event. It only makes sense to redact the event
131
+ if it exists.
132
+ It might be important to have the guarantee, that the redact is received
133
+ by the server at the time where the original message is sent.
134
+ - In the case of a state event we might want to set the state to ` A ` and after a
135
+ timeout reset it to ` {} ` . If we have two separate request sending ` A ` could work
136
+ but the event with content ` {} ` could fail. The state would not automatically
137
+ reset to ` {} ` .
138
+
139
+ For this usecase an optional ` m.send_now ` field can be added to the body.
118
140
119
141
## Potential issues
120
142
@@ -126,43 +148,22 @@ an indicator to determine if the event is expired. Instead of letting the SFU
126
148
inform about the call termination or using the call app ping loop like we propose
127
149
here.
128
150
129
- ---
130
- It might not be necessary to change the value of `"m.will_expire" = 10` to
131
- `"m.will_expire" = "running"` it makes it easier to understand and also
132
- hides more potential metadata but it is questionable if that bring any benefit.
133
-
134
- ---
135
- The name `m.will_expire` has been chosen since it communicates that it becomes
136
- invalid. And that it is an event that automatically changes state
137
- (`will_expire` vs `expired`). But it does not imply what expired vs non expired
138
- means, it is flexible in how can be used.
139
- Alternatives could by:
140
-
141
- - `m.alive`
142
- - pro: communicates it might change (alive is always temporal)
143
- - con: ver strong bias on how to use it `valid/invalid`
144
- - `m.timeout`
145
- - pro: very unbiased in how its used - timeout over can also mean the client
146
- will show a reminder.
147
- - pro: clear that it has something to do with time.
148
- - con: not so clear the homeserver will automatically do sth.
149
- - con: not so clear that this timeout can be refreshed?
150
-
151
151
## Security considerations
152
152
153
- We are using unauthenticated endpoint to refresh the expirations. Since we use
154
- the token it is hard to guess a correct endpoint and randomly end `will_expire`
155
- events.
153
+ We are using an unauthenticated endpoint to refresh the expirations. Since we use
154
+ the token it is hard to guess a correct request and force one of the actions
155
+ events of the Future .
156
156
157
157
It is an intentional decision to not provide an endpoint like
158
- `PUT /_matrix/client/v3/expiration /room/{roomId}/event/{eventId}`
158
+ ` PUT /_matrix/client/v3/futures /room/{roomId}/event/{eventId} `
159
159
where any client with access to the room could also ` end ` or ` refresh `
160
160
the expiration. With the token the client sending the event has ownership
161
161
over the expiration and only intentional delegation of that ownership
162
162
(sharing the token) is possible.
163
163
164
164
On the other hand the token makes sure that the instance gets as little
165
- information about the matrix metadata of the associated `will_expire` event.
165
+ information about the matrix metadata of the associated ` future ` event. It cannot
166
+ even tell with which room or user it is interacting.
166
167
167
168
## Unstable prefix
168
169
0 commit comments