handleDatabaseKeys handles cases where the key requests can be satisfied from our local database/cache.
( ctx context.Context, now gomatrixserverlib.Timestamp, requests map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.Timestamp, results map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.PublicKeyLookupResult, )
| 145 | // handleDatabaseKeys handles cases where the key requests can be |
| 146 | // satisfied from our local database/cache. |
| 147 | func (s *FederationInternalAPI) handleDatabaseKeys( |
| 148 | ctx context.Context, |
| 149 | now gomatrixserverlib.Timestamp, |
| 150 | requests map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.Timestamp, |
| 151 | results map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.PublicKeyLookupResult, |
| 152 | ) error { |
| 153 | // Ask the database/cache for the keys. |
| 154 | dbResults, err := s.keyRing.KeyDatabase.FetchKeys(ctx, requests) |
| 155 | if err != nil { |
| 156 | return err |
| 157 | } |
| 158 | |
| 159 | // We successfully got some keys. Add them to the results. |
| 160 | for req, res := range dbResults { |
| 161 | // The key we've retrieved from the database/cache might |
| 162 | // have passed its validity period, but right now, it's |
| 163 | // the best thing we've got, and it might be sufficient to |
| 164 | // verify a past event. |
| 165 | results[req] = res |
| 166 | |
| 167 | // If the key is valid right now then we can also remove it |
| 168 | // from the request list as we don't need to fetch it again |
| 169 | // in that case. If the key isn't valid right now, then by |
| 170 | // leaving it in the 'requests' map, we'll try to update the |
| 171 | // key using the fetchers in handleFetcherKeys. |
| 172 | if res.WasValidAt(now, true) { |
| 173 | delete(requests, req) |
| 174 | } |
| 175 | } |
| 176 | return nil |
| 177 | } |
| 178 | |
| 179 | // handleFetcherKeys handles cases where a fetcher can satisfy |
| 180 | // the remaining requests. |