GetAuthChain fetches the auth chain for the given auth events. An auth chain is the list of all events that are referenced in the auth_events section, and all their auth_events, recursively. The returned set of events contain the given events. Will *not* error if we don't have all auth events.
( ctx context.Context, fn eventsFromIDs, authEventIDs []string, )
| 530 | // all their auth_events, recursively. The returned set of events contain the |
| 531 | // given events. Will *not* error if we don't have all auth events. |
| 532 | func GetAuthChain( |
| 533 | ctx context.Context, fn eventsFromIDs, authEventIDs []string, |
| 534 | ) ([]*gomatrixserverlib.Event, error) { |
| 535 | // List of event IDs to fetch. On each pass, these events will be requested |
| 536 | // from the database and the `eventsToFetch` will be updated with any new |
| 537 | // events that we have learned about and need to find. When `eventsToFetch` |
| 538 | // is eventually empty, we should have reached the end of the chain. |
| 539 | eventsToFetch := authEventIDs |
| 540 | authEventsMap := make(map[string]*gomatrixserverlib.Event) |
| 541 | |
| 542 | for len(eventsToFetch) > 0 { |
| 543 | // Try to retrieve the events from the database. |
| 544 | events, err := fn(ctx, eventsToFetch) |
| 545 | if err != nil { |
| 546 | return nil, err |
| 547 | } |
| 548 | |
| 549 | // We've now fetched these events so clear out `eventsToFetch`. Soon we may |
| 550 | // add newly discovered events to this for the next pass. |
| 551 | eventsToFetch = eventsToFetch[:0] |
| 552 | |
| 553 | for _, event := range events { |
| 554 | // Store the event in the event map - this prevents us from requesting it |
| 555 | // from the database again. |
| 556 | authEventsMap[event.EventID()] = event.Event |
| 557 | |
| 558 | // Extract all of the auth events from the newly obtained event. If we |
| 559 | // don't already have a record of the event, record it in the list of |
| 560 | // events we want to request for the next pass. |
| 561 | for _, authEvent := range event.AuthEvents() { |
| 562 | if _, ok := authEventsMap[authEvent.EventID]; !ok { |
| 563 | eventsToFetch = append(eventsToFetch, authEvent.EventID) |
| 564 | } |
| 565 | } |
| 566 | } |
| 567 | } |
| 568 | |
| 569 | // We've now retrieved all of the events we can. Flatten them down into an |
| 570 | // array and return them. |
| 571 | var authEvents []*gomatrixserverlib.Event |
| 572 | for _, event := range authEventsMap { |
| 573 | authEvents = append(authEvents, event) |
| 574 | } |
| 575 | |
| 576 | return authEvents, nil |
| 577 | } |
| 578 | |
| 579 | // QueryRoomVersionCapabilities implements api.RoomserverInternalAPI |
| 580 | func (r *Queryer) QueryRoomVersionCapabilities( |
no outgoing calls