Class EventSender
Builds local events into the room graph: previous events, auth events, hash, signature, ID, authorization, state and storage.
Inherited Members
Namespace: Uniform.Matrix.Server.Rooms
Assembly: Uniform.Matrix.Server.dll
Syntax
public sealed class EventSender
Remarks
Events are written through the ServerStream, one at a time, so stream positions are committed in order.
EventSender.cs: local events, joins and leaves of other servers' users, and rooms joined elsewhere.EventSender.Remote.cs: events other servers send, checked against their auth events, the state before them and the current state, with forks merged by StateResolution.
Constructors
| Edit this page View SourceEventSender(IDbContextFactory<ServerDbContext>, ServerKeys, IOptions<ServerOptions>, TimeProvider, ServerStream)
Create the sender.
Declaration
public EventSender(IDbContextFactory<ServerDbContext> contexts, ServerKeys keys, IOptions<ServerOptions> options, TimeProvider time, ServerStream stream)
Parameters
| Type | Name | Description |
|---|---|---|
| IDbContextFactory<ServerDbContext> | contexts | |
| ServerKeys | keys | |
| IOptions<ServerOptions> | options | |
| TimeProvider | time | |
| ServerStream | stream |
Properties
| Edit this page View SourceOwnKeys
Return this server's public keys by key ID, for AcceptEventAsync(JsonObject, IReadOnlyDictionary<string, string>, CancellationToken, IReadOnlyDictionary<(string Type, string StateKey), string>?) of its own events.
Declaration
public IReadOnlyDictionary<string, string> OwnKeys { get; }
Property Value
| Type | Description |
|---|---|
| IReadOnlyDictionary<string, string> |
Methods
| Edit this page View SourceAcceptEventAsync(JsonObject, IReadOnlyDictionary<string, string>, CancellationToken, IReadOnlyDictionary<(string Type, string StateKey), string>?)
Accept an event another server sent; return its ID, if known, and null when stored or already here, else why it was rejected.
Declaration
public Task<(string? EventId, string? Error)> AcceptEventAsync(JsonObject pdu, IReadOnlyDictionary<string, string> senderKeys, CancellationToken cancellationToken, IReadOnlyDictionary<(string Type, string StateKey), string>? reportedStateBefore = null)
Parameters
| Type | Name | Description |
|---|---|---|
| JsonObject | pdu | The event. |
| IReadOnlyDictionary<string, string> | senderKeys | Public keys of the sender's server by key ID. |
| CancellationToken | cancellationToken | Cancellation token. |
| IReadOnlyDictionary<(string Type, string StateKey), string> | reportedStateBefore | State before the event as its server reported it, for previous events not here; null when all are here. |
Returns
| Type | Description |
|---|---|
| Task<(string EventId, string Error)> |
Remarks
As the spec's checks on receipt: the event must be allowed by its own auth events, which must be here, and by the state before it, merged from its previous events; otherwise it is rejected and not stored. When the room's current state no longer allows it, as when its sender was banned meanwhile, it is stored but soft-failed.
AcceptMembershipAsync(JsonObject, string, string, string, IReadOnlyDictionary<string, string>, CancellationToken)
Accept a membership event that another server built from MakeMembershipAsync(string, string, string, CancellationToken) and signed; for a join return the state before it and its auth chain, as send_join answers, for a leave nothing.
Declaration
public Task<(List<JsonObject> State, List<JsonObject> AuthChain)> AcceptMembershipAsync(JsonObject pdu, string membership, string eventId, string origin, IReadOnlyDictionary<string, string> originKeys, CancellationToken cancellationToken)
Parameters
| Type | Name | Description |
|---|---|---|
| JsonObject | pdu | The signed event. |
| string | membership |
|
| string | eventId | Event ID from the URL, which must match the event. |
| string | origin | Server that sent it, which must be the joining user's. |
| IReadOnlyDictionary<string, string> | originKeys | Public keys of |
| CancellationToken | cancellationToken | Cancellation token. |
Returns
| Type | Description |
|---|---|
| Task<(List<JsonObject> State, List<JsonObject> AuthChain)> |
CreateHashedRoomAsync(RoomVersion, string, JsonObject, bool, CancellationToken)
Create a room whose ID is its create event's hash, as from room version 12: build and sign the create event first, then store the room under the ID it gives.
Declaration
public Task<string> CreateHashedRoomAsync(RoomVersion version, string creator, JsonObject content, bool published, CancellationToken cancellationToken)
Parameters
| Type | Name | Description |
|---|---|---|
| RoomVersion | version | Room version with RoomIdIsCreateHash. |
| string | creator | Local user creating the room. |
| JsonObject | content | Create event content, with |
| bool | published | Whether the room is listed in the public directory. |
| CancellationToken | cancellationToken | Cancellation token. |
Returns
| Type | Description |
|---|---|
| Task<string> |
FindUnknownAsync(IReadOnlyCollection<string>, CancellationToken)
Return the IDs among eventIds that are not stored here, soft-failed ones counting as stored.
Declaration
public Task<IReadOnlyList<string>> FindUnknownAsync(IReadOnlyCollection<string> eventIds, CancellationToken cancellationToken)
Parameters
| Type | Name | Description |
|---|---|---|
| IReadOnlyCollection<string> | eventIds | |
| CancellationToken | cancellationToken |
Returns
| Type | Description |
|---|---|
| Task<IReadOnlyList<string>> |
InviteRoomStateAsync(string, string, CancellationToken)
Return the state an invitee sees before joining, as stripped events: create, join rules, name, avatar, alias, encryption, and the inviter's membership.
Declaration
public Task<JsonArray> InviteRoomStateAsync(string roomId, string inviter, CancellationToken cancellationToken)
Parameters
| Type | Name | Description |
|---|---|---|
| string | roomId | |
| string | inviter | |
| CancellationToken | cancellationToken |
Returns
| Type | Description |
|---|---|
| Task<JsonArray> |
MakeMembershipAsync(string, string, string, CancellationToken)
Return an unsigned membership event of userId for another server to sign, as make_join and make_leave answer, with the room version.
Declaration
public Task<(JsonObject Template, RoomVersion Version)> MakeMembershipAsync(string roomId, string userId, string membership, CancellationToken cancellationToken)
Parameters
| Type | Name | Description |
|---|---|---|
| string | roomId | Room here. |
| string | userId | User of the asking server. |
| string | membership |
|
| CancellationToken | cancellationToken | Cancellation token. |
Returns
| Type | Description |
|---|---|
| Task<(JsonObject Template, RoomVersion Version)> |
SendAsync(EventDraft, CancellationToken)
Send an event; return its ID. Throws M_FORBIDDEN when the auth rules reject it, and return the earlier event for a retried transaction.
Declaration
public Task<string> SendAsync(EventDraft draft, CancellationToken cancellationToken)
Parameters
| Type | Name | Description |
|---|---|---|
| EventDraft | draft | |
| CancellationToken | cancellationToken |
Returns
| Type | Description |
|---|---|
| Task<string> |
SignAsync(EventDraft, CancellationToken)
Build, hash and sign a local event and check it against the room's rules without storing it, for events another server must sign too, such as invites of its users; store it with AcceptEventAsync(JsonObject, IReadOnlyDictionary<string, string>, CancellationToken, IReadOnlyDictionary<(string Type, string StateKey), string>?).
Declaration
public Task<(JsonObject Pdu, string EventId, RoomVersion Version)> SignAsync(EventDraft draft, CancellationToken cancellationToken)
Parameters
| Type | Name | Description |
|---|---|---|
| EventDraft | draft | |
| CancellationToken | cancellationToken |
Returns
| Type | Description |
|---|---|
| Task<(JsonObject Pdu, string EventId, RoomVersion Version)> |
StoreFetchedAsync(string, IReadOnlyDictionary<string, JsonObject>, CancellationToken)
Store events of a room fetched to fill a gap, e.g. the state before an event and its auth chain, as earlier history; those not allowed by their own auth events are left out. Return the IDs stored.
Declaration
public Task<IReadOnlySet<string>> StoreFetchedAsync(string roomId, IReadOnlyDictionary<string, JsonObject> events, CancellationToken cancellationToken)
Parameters
| Type | Name | Description |
|---|---|---|
| string | roomId | Room, which must be here. |
| IReadOnlyDictionary<string, JsonObject> | events | Events by ID, with hashes and signatures already checked. |
| CancellationToken | cancellationToken | Cancellation token. |
Returns
| Type | Description |
|---|---|
| Task<IReadOnlySet<string>> |
StoreJoinedRoomAsync(RoomVersion, JsonObject, string, IReadOnlyDictionary<string, JsonObject>, IReadOnlyCollection<string>, CancellationToken)
Store a room joined on another server: its state and auth chain as they were before the join, then the join as the room's first own event.
Declaration
public Task StoreJoinedRoomAsync(RoomVersion version, JsonObject join, string joinId, IReadOnlyDictionary<string, JsonObject> events, IReadOnlyCollection<string> stateIds, CancellationToken cancellationToken)
Parameters
| Type | Name | Description |
|---|---|---|
| RoomVersion | version | Room version. |
| JsonObject | join | The signed join, already accepted by the resident server. |
| string | joinId | Its event ID. |
| IReadOnlyDictionary<string, JsonObject> | events | State and auth chain events by ID, already checked. |
| IReadOnlyCollection<string> | stateIds | IDs of the state events before the join. |
| CancellationToken | cancellationToken | Cancellation token. |
Returns
| Type | Description |
|---|---|
| Task |