SendEDU sends an EDU event to the destinations.
( e *gomatrixserverlib.EDU, origin gomatrixserverlib.ServerName, destinations []gomatrixserverlib.ServerName, )
| 254 | |
| 255 | // SendEDU sends an EDU event to the destinations. |
| 256 | func (oqs *OutgoingQueues) SendEDU( |
| 257 | e *gomatrixserverlib.EDU, origin gomatrixserverlib.ServerName, |
| 258 | destinations []gomatrixserverlib.ServerName, |
| 259 | ) error { |
| 260 | if oqs.disabled { |
| 261 | log.Trace("Federation is disabled, not sending EDU") |
| 262 | return nil |
| 263 | } |
| 264 | if origin != oqs.origin { |
| 265 | // TODO: Support virtual hosting; gh issue #577. |
| 266 | return fmt.Errorf( |
| 267 | "sendevent: unexpected server to send as: got %q expected %q", |
| 268 | origin, oqs.origin, |
| 269 | ) |
| 270 | } |
| 271 | |
| 272 | // Deduplicate destinations and remove the origin from the list of |
| 273 | // destinations just to be sure. |
| 274 | destmap := map[gomatrixserverlib.ServerName]struct{}{} |
| 275 | for _, d := range destinations { |
| 276 | destmap[d] = struct{}{} |
| 277 | } |
| 278 | delete(destmap, oqs.origin) |
| 279 | delete(destmap, oqs.signing.ServerName) |
| 280 | |
| 281 | // There is absolutely no guarantee that the EDU will have a room_id |
| 282 | // field, as it is not required by the spec. However, if it *does* |
| 283 | // (e.g. typing notifications) then we should try to make sure we don't |
| 284 | // bother sending them to servers that are prohibited by the server |
| 285 | // ACLs. |
| 286 | if result := gjson.GetBytes(e.Content, "room_id"); result.Exists() { |
| 287 | for destination := range destmap { |
| 288 | if api.IsServerBannedFromRoom( |
| 289 | oqs.process.Context(), |
| 290 | oqs.rsAPI, |
| 291 | result.Str, |
| 292 | destination, |
| 293 | ) { |
| 294 | delete(destmap, destination) |
| 295 | } |
| 296 | } |
| 297 | } |
| 298 | |
| 299 | // If there are no remaining destinations then give up. |
| 300 | if len(destmap) == 0 { |
| 301 | return nil |
| 302 | } |
| 303 | |
| 304 | log.WithFields(log.Fields{ |
| 305 | "destinations": len(destmap), "edu_type": e.Type, |
| 306 | }).Info("Sending EDU event") |
| 307 | |
| 308 | ephemeralJSON, err := json.Marshal(e) |
| 309 | if err != nil { |
| 310 | return fmt.Errorf("json.Marshal: %w", err) |
| 311 | } |
| 312 | |
| 313 | nid, err := oqs.db.StoreJSON(oqs.process.Context(), string(ephemeralJSON)) |
no test coverage detected