( ctx context.Context, req *api.QueryServerKeysRequest, res *api.QueryServerKeysResponse, )
| 65 | } |
| 66 | |
| 67 | func (a *FederationInternalAPI) QueryServerKeys( |
| 68 | ctx context.Context, req *api.QueryServerKeysRequest, res *api.QueryServerKeysResponse, |
| 69 | ) error { |
| 70 | // attempt to satisfy the entire request from the cache first |
| 71 | results, err := a.fetchServerKeysFromCache(ctx, req) |
| 72 | if err == nil { |
| 73 | // satisfied entirely from cache, return it |
| 74 | res.ServerKeys = results |
| 75 | return nil |
| 76 | } |
| 77 | util.GetLogger(ctx).WithField("server", req.ServerName).WithError(err).Warn("notary: failed to satisfy keys request entirely from cache, hitting direct") |
| 78 | |
| 79 | serverKeys, err := a.fetchServerKeysDirectly(ctx, req.ServerName) |
| 80 | if err != nil { |
| 81 | // try to load as much as we can from the cache in a best effort basis |
| 82 | util.GetLogger(ctx).WithField("server", req.ServerName).WithError(err).Warn("notary: failed to ask server for keys, returning best effort keys") |
| 83 | serverKeysResponses, dbErr := a.db.GetNotaryKeys(ctx, req.ServerName, req.KeyIDs()) |
| 84 | if dbErr != nil { |
| 85 | return fmt.Errorf("notary: server returned %s, and db returned %s", err, dbErr) |
| 86 | } |
| 87 | res.ServerKeys = serverKeysResponses |
| 88 | return nil |
| 89 | } |
| 90 | // cache it! |
| 91 | if err = a.db.UpdateNotaryKeys(context.Background(), req.ServerName, *serverKeys); err != nil { |
| 92 | // non-fatal, still return the response |
| 93 | util.GetLogger(ctx).WithError(err).Warn("failed to UpdateNotaryKeys") |
| 94 | } |
| 95 | res.ServerKeys = []gomatrixserverlib.ServerKeys{*serverKeys} |
| 96 | return nil |
| 97 | } |
nothing calls this directly
no test coverage detected