diff --git a/serverkeyapi/internal/api.go b/serverkeyapi/internal/api.go index b2348e1ed..ffd3c1131 100644 --- a/serverkeyapi/internal/api.go +++ b/serverkeyapi/internal/api.go @@ -157,11 +157,17 @@ func (s *ServerKeyAPI) handleDatabaseKeys( // We successfully got some keys. Add them to the results. for req, res := range dbResults { + // The key we've retrieved from the database/cache might + // have passed its validity period, but right now, it's + // the best thing we've got, and it might be sufficient to + // verify a past event. results[req] = res // If the key is valid right now then we can also remove it // from the request list as we don't need to fetch it again - // in that case. + // in that case. If the key isn't valid right now, then by + // leaving it in the 'requests' map, we'll try to update the + // key using the fetchers in handleFetcherKeys. if res.WasValidAt(now, true) { delete(requests, req) } @@ -169,7 +175,7 @@ func (s *ServerKeyAPI) handleDatabaseKeys( return nil } -// handleDatabaseKeys handles cases where a fetcher can satisfy +// handleFetcherKeys handles cases where a fetcher can satisfy // the remaining requests. func (s *ServerKeyAPI) handleFetcherKeys( ctx context.Context, diff --git a/serverkeyapi/serverkeyapi_test.go b/serverkeyapi/serverkeyapi_test.go index 953e91644..3368f5b2a 100644 --- a/serverkeyapi/serverkeyapi_test.go +++ b/serverkeyapi/serverkeyapi_test.go @@ -21,12 +21,12 @@ import ( ) type server struct { - name gomatrixserverlib.ServerName - validity time.Duration - config *config.Dendrite - fedclient *gomatrixserverlib.FederationClient - cache *caching.Caches - api api.ServerKeyInternalAPI + name gomatrixserverlib.ServerName // server name + validity time.Duration // key validity duration from now + config *config.Dendrite // skeleton config, from TestMain + fedclient *gomatrixserverlib.FederationClient // uses MockRoundTripper + cache *caching.Caches // server-specific cache + api api.ServerKeyInternalAPI // server-specific server key API } func (s *server) renew() {