(
ctx context.Context, serverName string, devKeys map[string][]string, crossSigningKeys map[string]struct{},
wg *sync.WaitGroup, respMu *sync.Mutex, timeout time.Duration, resultCh chan<- *gomatrixserverlib.RespQueryKeys,
res *api.QueryKeysResponse,
)
| 465 | } |
| 466 | |
| 467 | func (a *KeyInternalAPI) queryRemoteKeysOnServer( |
| 468 | ctx context.Context, serverName string, devKeys map[string][]string, crossSigningKeys map[string]struct{}, |
| 469 | wg *sync.WaitGroup, respMu *sync.Mutex, timeout time.Duration, resultCh chan<- *gomatrixserverlib.RespQueryKeys, |
| 470 | res *api.QueryKeysResponse, |
| 471 | ) { |
| 472 | defer wg.Done() |
| 473 | fedCtx := ctx |
| 474 | if timeout > 0 { |
| 475 | var cancel context.CancelFunc |
| 476 | fedCtx, cancel = context.WithTimeout(ctx, timeout) |
| 477 | defer cancel() |
| 478 | } |
| 479 | // for users who we do not have any knowledge about, try to start doing device list updates for them |
| 480 | // by hitting /users/devices - otherwise fallback to /keys/query which has nicer bulk properties but |
| 481 | // lack a stream ID. |
| 482 | userIDsForAllDevices := map[string]struct{}{} |
| 483 | for userID, deviceIDs := range devKeys { |
| 484 | if len(deviceIDs) == 0 { |
| 485 | userIDsForAllDevices[userID] = struct{}{} |
| 486 | } |
| 487 | } |
| 488 | // for cross-signing keys, it's probably easier just to hit /keys/query if we aren't already doing |
| 489 | // a device list update, so we'll populate those back into the /keys/query list if not |
| 490 | for userID := range crossSigningKeys { |
| 491 | if devKeys == nil { |
| 492 | devKeys = map[string][]string{} |
| 493 | } |
| 494 | if _, ok := userIDsForAllDevices[userID]; !ok { |
| 495 | devKeys[userID] = []string{} |
| 496 | } |
| 497 | } |
| 498 | for userID := range userIDsForAllDevices { |
| 499 | err := a.Updater.ManualUpdate(context.Background(), gomatrixserverlib.ServerName(serverName), userID) |
| 500 | if err != nil { |
| 501 | logrus.WithFields(logrus.Fields{ |
| 502 | logrus.ErrorKey: err, |
| 503 | "user_id": userID, |
| 504 | "server": serverName, |
| 505 | }).Error("Failed to manually update device lists for user") |
| 506 | // try to do it via /keys/query |
| 507 | devKeys[userID] = []string{} |
| 508 | continue |
| 509 | } |
| 510 | // refresh entries from DB: unlike remoteKeysFromDatabase we know we previously had no device info for this |
| 511 | // user so the fact that we're populating all devices here isn't a problem so long as we have devices. |
| 512 | respMu.Lock() |
| 513 | err = a.populateResponseWithDeviceKeysFromDatabase(ctx, res, userID, nil) |
| 514 | respMu.Unlock() |
| 515 | if err != nil { |
| 516 | logrus.WithFields(logrus.Fields{ |
| 517 | logrus.ErrorKey: err, |
| 518 | "user_id": userID, |
| 519 | "server": serverName, |
| 520 | }).Error("Failed to manually update device lists for user") |
| 521 | // try to do it via /keys/query |
| 522 | devKeys[userID] = []string{} |
| 523 | continue |
| 524 | } |
no test coverage detected