(
ctx context.Context, timeout time.Duration, res *api.QueryKeysResponse,
domainToDeviceKeys map[string]map[string][]string, domainToCrossSigningKeys map[string]map[string]struct{},
)
| 401 | } |
| 402 | |
| 403 | func (a *KeyInternalAPI) queryRemoteKeys( |
| 404 | ctx context.Context, timeout time.Duration, res *api.QueryKeysResponse, |
| 405 | domainToDeviceKeys map[string]map[string][]string, domainToCrossSigningKeys map[string]map[string]struct{}, |
| 406 | ) { |
| 407 | resultCh := make(chan *gomatrixserverlib.RespQueryKeys, len(domainToDeviceKeys)) |
| 408 | // allows us to wait until all federation servers have been poked |
| 409 | var wg sync.WaitGroup |
| 410 | // mutex for writing directly to res (e.g failures) |
| 411 | var respMu sync.Mutex |
| 412 | |
| 413 | domains := map[string]struct{}{} |
| 414 | for domain := range domainToDeviceKeys { |
| 415 | if domain == string(a.ThisServer) { |
| 416 | continue |
| 417 | } |
| 418 | domains[domain] = struct{}{} |
| 419 | } |
| 420 | for domain := range domainToCrossSigningKeys { |
| 421 | if domain == string(a.ThisServer) { |
| 422 | continue |
| 423 | } |
| 424 | domains[domain] = struct{}{} |
| 425 | } |
| 426 | wg.Add(len(domains)) |
| 427 | |
| 428 | // fan out |
| 429 | for domain := range domains { |
| 430 | go a.queryRemoteKeysOnServer( |
| 431 | ctx, domain, domainToDeviceKeys[domain], domainToCrossSigningKeys[domain], |
| 432 | &wg, &respMu, timeout, resultCh, res, |
| 433 | ) |
| 434 | } |
| 435 | |
| 436 | // Close the result channel when the goroutines have quit so the for .. range exits |
| 437 | go func() { |
| 438 | wg.Wait() |
| 439 | close(resultCh) |
| 440 | }() |
| 441 | |
| 442 | for result := range resultCh { |
| 443 | for userID, nest := range result.DeviceKeys { |
| 444 | res.DeviceKeys[userID] = make(map[string]json.RawMessage) |
| 445 | for deviceID, deviceKey := range nest { |
| 446 | keyJSON, err := json.Marshal(deviceKey) |
| 447 | if err != nil { |
| 448 | continue |
| 449 | } |
| 450 | res.DeviceKeys[userID][deviceID] = keyJSON |
| 451 | } |
| 452 | } |
| 453 | |
| 454 | for userID, body := range result.MasterKeys { |
| 455 | res.MasterKeys[userID] = body |
| 456 | } |
| 457 | |
| 458 | for userID, body := range result.SelfSigningKeys { |
| 459 | res.SelfSigningKeys[userID] = body |
| 460 | } |
no test coverage detected