mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-04-20 10:43:40 +00:00
Try this again
This commit is contained in:
parent
28b038390e
commit
8630960141
1 changed files with 22 additions and 17 deletions
|
@ -231,6 +231,7 @@ func (a *KeyInternalAPI) QueryKeys(ctx context.Context, req *api.QueryKeysReques
|
||||||
|
|
||||||
// make a map from domain to device keys
|
// make a map from domain to device keys
|
||||||
domainToDeviceKeys := make(map[string]map[string][]string)
|
domainToDeviceKeys := make(map[string]map[string][]string)
|
||||||
|
domainToCrossSigningKeys := make(map[string]map[string]struct{})
|
||||||
for userID, deviceIDs := range req.UserToDevices {
|
for userID, deviceIDs := range req.UserToDevices {
|
||||||
_, serverName, err := gomatrixserverlib.SplitID('@', userID)
|
_, serverName, err := gomatrixserverlib.SplitID('@', userID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -284,37 +285,41 @@ func (a *KeyInternalAPI) QueryKeys(ctx context.Context, req *api.QueryKeysReques
|
||||||
// work out if our cross-signing request for this user was
|
// work out if our cross-signing request for this user was
|
||||||
// satisfied, if not add them to the list of things to fetch
|
// satisfied, if not add them to the list of things to fetch
|
||||||
if _, ok := res.MasterKeys[userID]; !ok {
|
if _, ok := res.MasterKeys[userID]; !ok {
|
||||||
util.GetLogger(ctx).Infof("No cross-signing master keys for %s found", userID)
|
if _, ok := domainToCrossSigningKeys[domain]; !ok {
|
||||||
if _, ok := domainToDeviceKeys[domain]; !ok {
|
domainToCrossSigningKeys[domain] = make(map[string]struct{})
|
||||||
domainToDeviceKeys[domain] = make(map[string][]string)
|
|
||||||
}
|
}
|
||||||
if _, ok := domainToDeviceKeys[domain][userID]; !ok {
|
if _, ok := domainToCrossSigningKeys[domain][userID]; !ok {
|
||||||
util.GetLogger(ctx).Infof("Request cross-signing keys from %s for %s", domain, userID)
|
domainToCrossSigningKeys[domain][userID] = struct{}{}
|
||||||
domainToDeviceKeys[domain][userID] = []string{}
|
|
||||||
} else {
|
|
||||||
util.GetLogger(ctx).Infof("Already requesting keys from %s for %s", domain, userID)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if _, ok := res.SelfSigningKeys[userID]; !ok {
|
if _, ok := res.SelfSigningKeys[userID]; !ok {
|
||||||
util.GetLogger(ctx).Infof("No cross-signing self-signing keys for %s found", userID)
|
if _, ok := domainToCrossSigningKeys[domain]; !ok {
|
||||||
if _, ok := domainToDeviceKeys[domain]; !ok {
|
domainToCrossSigningKeys[domain] = make(map[string]struct{})
|
||||||
domainToDeviceKeys[domain] = make(map[string][]string)
|
|
||||||
}
|
}
|
||||||
if _, ok := domainToDeviceKeys[domain][userID]; !ok {
|
if _, ok := domainToCrossSigningKeys[domain][userID]; !ok {
|
||||||
util.GetLogger(ctx).Infof("Request cross-signing keys from %s for %s", domain, userID)
|
domainToCrossSigningKeys[domain][userID] = struct{}{}
|
||||||
domainToDeviceKeys[domain][userID] = []string{}
|
|
||||||
} else {
|
|
||||||
util.GetLogger(ctx).Infof("Already requesting keys from %s for %s", domain, userID)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// attempt to satisfy key queries from the local database first as we should get device updates pushed to us
|
// attempt to satisfy key queries from the local database first as we should get device updates pushed to us
|
||||||
domainToDeviceKeys = a.remoteKeysFromDatabase(ctx, res, domainToDeviceKeys)
|
domainToDeviceKeys = a.remoteKeysFromDatabase(ctx, res, domainToDeviceKeys)
|
||||||
if len(domainToDeviceKeys) == 0 {
|
if len(domainToDeviceKeys) == 0 && len(domainToCrossSigningKeys) == 0 {
|
||||||
return // nothing to query
|
return // nothing to query
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// add in any cross-signing requests that need to be made to the list
|
||||||
|
for domain, forDomain := range domainToCrossSigningKeys {
|
||||||
|
for userID := range forDomain {
|
||||||
|
if _, ok := domainToDeviceKeys[domain]; !ok {
|
||||||
|
domainToDeviceKeys[domain] = make(map[string][]string)
|
||||||
|
}
|
||||||
|
if _, ok := domainToDeviceKeys[domain][userID]; !ok {
|
||||||
|
domainToDeviceKeys[domain][userID] = []string{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// perform key queries for remote devices
|
// perform key queries for remote devices
|
||||||
a.queryRemoteKeys(ctx, req.Timeout, res, domainToDeviceKeys)
|
a.queryRemoteKeys(ctx, req.Timeout, res, domainToDeviceKeys)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue