(ctx context.Context, req *api.PerformClaimKeysRequest, res *api.PerformClaimKeysResponse)
| 70 | } |
| 71 | |
| 72 | func (a *KeyInternalAPI) PerformClaimKeys(ctx context.Context, req *api.PerformClaimKeysRequest, res *api.PerformClaimKeysResponse) { |
| 73 | res.OneTimeKeys = make(map[string]map[string]map[string]json.RawMessage) |
| 74 | res.Failures = make(map[string]interface{}) |
| 75 | // wrap request map in a top-level by-domain map |
| 76 | domainToDeviceKeys := make(map[string]map[string]map[string]string) |
| 77 | for userID, val := range req.OneTimeKeys { |
| 78 | _, serverName, err := gomatrixserverlib.SplitID('@', userID) |
| 79 | if err != nil { |
| 80 | continue // ignore invalid users |
| 81 | } |
| 82 | nested, ok := domainToDeviceKeys[string(serverName)] |
| 83 | if !ok { |
| 84 | nested = make(map[string]map[string]string) |
| 85 | } |
| 86 | nested[userID] = val |
| 87 | domainToDeviceKeys[string(serverName)] = nested |
| 88 | } |
| 89 | // claim local keys |
| 90 | if local, ok := domainToDeviceKeys[string(a.ThisServer)]; ok { |
| 91 | keys, err := a.DB.ClaimKeys(ctx, local) |
| 92 | if err != nil { |
| 93 | res.Error = &api.KeyError{ |
| 94 | Err: fmt.Sprintf("failed to ClaimKeys locally: %s", err), |
| 95 | } |
| 96 | } |
| 97 | util.GetLogger(ctx).WithField("keys_claimed", len(keys)).WithField("num_users", len(local)).Info("Claimed local keys") |
| 98 | for _, key := range keys { |
| 99 | _, ok := res.OneTimeKeys[key.UserID] |
| 100 | if !ok { |
| 101 | res.OneTimeKeys[key.UserID] = make(map[string]map[string]json.RawMessage) |
| 102 | } |
| 103 | _, ok = res.OneTimeKeys[key.UserID][key.DeviceID] |
| 104 | if !ok { |
| 105 | res.OneTimeKeys[key.UserID][key.DeviceID] = make(map[string]json.RawMessage) |
| 106 | } |
| 107 | for keyID, keyJSON := range key.KeyJSON { |
| 108 | res.OneTimeKeys[key.UserID][key.DeviceID][keyID] = keyJSON |
| 109 | } |
| 110 | } |
| 111 | delete(domainToDeviceKeys, string(a.ThisServer)) |
| 112 | } |
| 113 | if len(domainToDeviceKeys) > 0 { |
| 114 | a.claimRemoteKeys(ctx, req.Timeout, res, domainToDeviceKeys) |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | func (a *KeyInternalAPI) claimRemoteKeys( |
| 119 | ctx context.Context, timeout time.Duration, res *api.PerformClaimKeysResponse, domainToDeviceKeys map[string]map[string]map[string]string, |
nothing calls this directly
no test coverage detected