mirror of
https://github.com/element-hq/dendrite.git
synced 2025-09-14 13:22:26 +03:00
Add key validity fetching to server key API (#1094)
* Add key validity checks * Store fetched keys * Don't double-cache key results * Perform server key API operations using new context * Revert "Perform server key API operations using new context" This reverts commit 02172223f5cb7850b0852c6ed6836ad82508ea76. * Perform server key API operations using new context
This commit is contained in:
parent
f4c676ccdd
commit
d785ad82b9
3 changed files with 31 additions and 18 deletions
|
@ -14,28 +14,16 @@ import (
|
|||
func (s *ServerKeyAPI) SetupHTTP(internalAPIMux *mux.Router) {
|
||||
internalAPIMux.Handle(api.ServerKeyQueryPublicKeyPath,
|
||||
internal.MakeInternalAPI("queryPublicKeys", func(req *http.Request) util.JSONResponse {
|
||||
result := map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.PublicKeyLookupResult{}
|
||||
request := api.QueryPublicKeysRequest{}
|
||||
response := api.QueryPublicKeysResponse{}
|
||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
||||
}
|
||||
lookup := make(map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.Timestamp)
|
||||
for req, timestamp := range request.Requests {
|
||||
if res, ok := s.ImmutableCache.GetServerKey(req); ok {
|
||||
result[req] = res
|
||||
continue
|
||||
}
|
||||
lookup[req] = timestamp
|
||||
}
|
||||
keys, err := s.FetchKeys(req.Context(), lookup)
|
||||
keys, err := s.FetchKeys(req.Context(), request.Requests)
|
||||
if err != nil {
|
||||
return util.ErrorResponse(err)
|
||||
}
|
||||
for req, res := range keys {
|
||||
result[req] = res
|
||||
}
|
||||
response.Results = result
|
||||
response.Results = keys
|
||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
||||
}),
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue