Skip to content

Commit c0a2f7b

Browse files
authored
Location streaming tweaks (#3622)
* Various tweaks following initial implementation: - switched from `m.beacon.*` state event to `m.becon` reference relationship to original `m.beacon_info.*` - changed `beacon_info` created to `m.ts` - renamed `lifetime` to `timeout` - added `m.asset` `type`
1 parent 834954a commit c0a2f7b

File tree

1 file changed

+47
-34
lines changed

1 file changed

+47
-34
lines changed

proposals/3489-location-streaming.md

Lines changed: 47 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ users in a room.
1515
This MSC adds the ability to publish real-time location beacons to Matrix by
1616
building on MSC3488 (m.location: Extending events with location data).
1717

18-
We introduce two types of state events to describe beacons: the first contains
18+
We introduce two types of events to describe beacons: the first, a state event, contains
1919
the metadata about the beacons advertised by a given user: `m.beacon_info.*`.
2020
As Matrix doesn't yet have a way to stop other users overwriting an event
2121
other than setting its state_key to be the owner's mxid, we work around this
@@ -24,79 +24,91 @@ by letting the final part of the event type be a unique ID for the beacon.
2424
event to indicate that it can only ever be written by its owner - we may get
2525
this via MSC3414 encrypted state events).
2626

27-
This lets us track an arbitrary number of beacons per user, and avoids becaon
27+
This lets us track an arbitrary number of beacons per user, and avoids beacon
2828
metadata being duplicated as location data is shared.
2929

3030
An example `m.beacon_info.*` event is:
3131

3232
```json5
3333
{
34-
"type": "m.beacon_info.self",
34+
"type": "m.beacon_info.@matthew:matrix.org",
3535
"state_key": "@matthew:matrix.org",
3636
"content": {
3737
"m.beacon_info": {
3838
"description": "The Matthew Tracker", // same as an `m.location` description
39-
"created": 1436829458432, // creation timestamp of the beacon on the client.
40-
"lifetime": 86400000, // how long the beacon will publish for in milliseconds
39+
"timeout": 86400000, // how long from the last event until we consider the beacon inactive in milliseconds
40+
},
41+
"m.ts": 1436829458432, // creation timestamp of the beacon on the client
42+
"m.asset": {
43+
"type": "m.self" // the type of asset being tracked as per MSC3488
4144
}
4245
}
4346
}
4447
```
4548

4649
Separately, we have the actual location data from the beacon in question
47-
stored in `m.beacon.*` state events. Storing the data as state events
48-
ensures that the current location of a given beacon is trivial to determine
49-
(rather than the client having to back-paginate history). It also gives us
50-
location history where desirable. If history is not wanted, then one can use
50+
as `m.beacon` events forming a reference relationship to the original `m.beacon_info` event.
51+
52+
Storing the location data as references as opposed to in a state event has multiple advantages:
53+
* Location data is easily encrypted (no dependency on MSC3414)
54+
* Doesn't thrash state resolution by storing new location points every time they change
55+
* Paginated history easily accessible through the `relations` endpoint. If history is not wanted, then one can use
5156
data retention policies(e.g. exploding messages) to ensure it does not
5257
accumulate unnecessarily.
58+
* Allows other users to request data from a beacon
59+
5360

54-
`m.beacon.*` events should be sent at a variable rate which is meaningful for
61+
`m.beacon` events should be sent at a variable rate which is meaningful for
5562
the use case for the asset being tracked. This rate should not be more
5663
frequent than sending an event every 2 seconds. If the asset is not moving,
57-
the state event should still be refreshed on a regular basis to convey that
64+
the location should still be refreshed on a regular basis to convey that
5865
information - e.g. every 30 seconds.
5966

60-
An example `m.beacon.*` event is:
67+
An example `m.beacon` event is:
6168

62-
```json
69+
```json5
6370
{
64-
"type": "m.beacon.self",
65-
"state_key": "@matthew:matrix.org",
71+
"type": "m.beacon",
72+
"sender": "@matthew:matrix.org",
6673
"content": {
74+
"m.relates_to": { // from MSC2674: https://github.com/matrix-org/matrix-doc/pull/2674
75+
"rel_type": "m.reference", // from MSC3267: https://github.com/matrix-org/matrix-doc/pull/3267
76+
"event_id": "$beacon_info"
77+
},
6778
"m.location": {
6879
"uri": "geo:51.5008,0.1247;u=35",
80+
"description": "Arbitrary beacon information"
6981
},
7082
"m.ts": 1636829458432,
7183
}
7284
}
7385
```
7486

75-
The special ID `self` is used to indicate that the beacon describes the
76-
primary asset associated with that mxid (e.g. the whereabouts of its human
77-
user).
78-
79-
The `m.location` section of the `m.beacon.*` event should not include a
80-
`description` field, as this instead resides on the matching
81-
`m.beacon_info.*` state event.
87+
The `m.location` section of the `m.beacon` event can include an optional
88+
`description` field to provide user facing updates e.g. current address
8289

8390
## Encryption
8491

8592
Location data should be stored end-to-end encrypted for obvious data privacy
86-
reasons - given the beacon data is stored in state events, this should be
87-
achieved by MSC3414.
88-
89-
## Problems
90-
91-
By storing a state event for every location datapoint, we put significant
92-
load on servers' state management implementations. Current implementations
93-
may not handle this well. However, semantically, state events provide the
94-
behaviour we need (easy access to current value; persistent state within
95-
a room), hence adopting them for this.
93+
reasons - given the beacon data is stored as simple events that will be automatic.
9694

9795
## Alternatives
9896

99-
We could behave like MSC3401 and announce users' beacons in
97+
Initially this MSC considered storing location data in a separate state event but
98+
that had multiple downsides:
99+
* No encryption without MSC3414
100+
* Difficult access to historical data, timeline pagination required
101+
* State resolution thrasing on every location update. By storing a state event for every location datapoint,
102+
we put significant load on servers' state management implementations. Current implementations
103+
may not handle this well.
104+
105+
Another option would be using ephemeral data units to broadcast location updates but they
106+
do come with downsides of their own:
107+
* they are not persisted and cannot provide historical data
108+
* there's no per-room API for them
109+
* they are not end to end encrypted
110+
111+
Alternatively, we could behave like MSC3401 and announce users' beacons in
100112
`m.beacon_info.*` (similar to MSC3401's `m.call`), and then send location
101113
data via to-device messages to interested devices.
102114
* Pros:
@@ -133,6 +145,7 @@ unencrypted or persisted. The same security considerations apply as for
133145
## Unstable prefix
134146

135147
* `m.beacon_info.*` should be referred to as `org.matrix.msc3489.beacon_info.*` until this MSC lands.
136-
* `m.beacon.*` should be referred to as `org.matrix.msc3489.beacon.*` until this MSC lands.
148+
* `m.beacon` should be referred to as `org.matrix.msc3489.beacon` until this MSC lands.
137149
* `m.location` should be referred to as `org.matrix.msc3488.location.*` until MSC3488 lands.
138150
* `m.ts` should be referred to as `org.matrix.msc3488.ts.*` until MSC3488 lands.
151+
* `m.asset` should be referred to as `org.matrix.msc3488.asset.*` until MSC3488 lands.

0 commit comments

Comments
 (0)