MCPcopy Create free account
hub / github.com/daodst/chat / SendEvent

Method SendEvent

federationapi/queue/queue.go:190–253  ·  view source on GitHub ↗

SendEvent sends an event to the destinations

(
	ev *gomatrixserverlib.HeaderedEvent, origin gomatrixserverlib.ServerName,
	destinations []gomatrixserverlib.ServerName,
)

Source from the content-addressed store, hash-verified

188
189// SendEvent sends an event to the destinations
190func (oqs *OutgoingQueues) SendEvent(
191 ev *gomatrixserverlib.HeaderedEvent, origin gomatrixserverlib.ServerName,
192 destinations []gomatrixserverlib.ServerName,
193) error {
194 if oqs.disabled {
195 log.Trace("Federation is disabled, not sending event")
196 return nil
197 }
198 if origin != oqs.origin {
199 // TODO: Support virtual hosting; gh issue #577.
200 return fmt.Errorf(
201 "sendevent: unexpected server to send as: got %q expected %q",
202 origin, oqs.origin,
203 )
204 }
205
206 // Deduplicate destinations and remove the origin from the list of
207 // destinations just to be sure.
208 destmap := map[gomatrixserverlib.ServerName]struct{}{}
209 for _, d := range destinations {
210 destmap[d] = struct{}{}
211 }
212 delete(destmap, oqs.origin)
213 delete(destmap, oqs.signing.ServerName)
214
215 // Check if any of the destinations are prohibited by server ACLs.
216 for destination := range destmap {
217 if api.IsServerBannedFromRoom(
218 oqs.process.Context(),
219 oqs.rsAPI,
220 ev.RoomID(),
221 destination,
222 ) {
223 delete(destmap, destination)
224 }
225 }
226
227 // If there are no remaining destinations then give up.
228 if len(destmap) == 0 {
229 return nil
230 }
231
232 log.WithFields(log.Fields{
233 "destinations": len(destmap), "event": ev.EventID(),
234 }).Infof("Sending event")
235
236 headeredJSON, err := json.Marshal(ev)
237 if err != nil {
238 return fmt.Errorf("json.Marshal: %w", err)
239 }
240
241 nid, err := oqs.db.StoreJSON(oqs.process.Context(), string(headeredJSON))
242 if err != nil {
243 return fmt.Errorf("sendevent: oqs.db.StoreJSON: %w", err)
244 }
245
246 for destination := range destmap {
247 if queue := oqs.getQueue(destination); queue != nil {

Callers 1

processMessageMethod · 0.80

Calls 6

getQueueMethod · 0.95
ContextMethod · 0.80
InfofMethod · 0.80
sendEventMethod · 0.80
StoreJSONMethod · 0.65

Tested by

no test coverage detected