mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-07-30 13:02:46 +00: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
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/matrix-org/dendrite/internal/caching"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
|
@ -69,9 +70,12 @@ func (s *httpServerKeyInternalAPI) FetcherName() string {
|
|||
}
|
||||
|
||||
func (s *httpServerKeyInternalAPI) StoreKeys(
|
||||
ctx context.Context,
|
||||
_ context.Context,
|
||||
results map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.PublicKeyLookupResult,
|
||||
) error {
|
||||
// Run in a background context - we don't want to stop this work just
|
||||
// because the caller gives up waiting.
|
||||
ctx := context.Background()
|
||||
request := InputPublicKeysRequest{
|
||||
Keys: make(map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.PublicKeyLookupResult),
|
||||
}
|
||||
|
@ -84,9 +88,12 @@ func (s *httpServerKeyInternalAPI) StoreKeys(
|
|||
}
|
||||
|
||||
func (s *httpServerKeyInternalAPI) FetchKeys(
|
||||
ctx context.Context,
|
||||
_ context.Context,
|
||||
requests map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.Timestamp,
|
||||
) (map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.PublicKeyLookupResult, error) {
|
||||
// Run in a background context - we don't want to stop this work just
|
||||
// because the caller gives up waiting.
|
||||
ctx := context.Background()
|
||||
result := make(map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.PublicKeyLookupResult)
|
||||
request := QueryPublicKeysRequest{
|
||||
Requests: make(map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.Timestamp),
|
||||
|
@ -94,8 +101,12 @@ func (s *httpServerKeyInternalAPI) FetchKeys(
|
|||
response := QueryPublicKeysResponse{
|
||||
Results: make(map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.PublicKeyLookupResult),
|
||||
}
|
||||
now := gomatrixserverlib.AsTimestamp(time.Now())
|
||||
for req, ts := range requests {
|
||||
if res, ok := s.immutableCache.GetServerKey(req); ok {
|
||||
if now > res.ValidUntilTS && res.ExpiredTS == gomatrixserverlib.PublicKeyNotExpired {
|
||||
continue
|
||||
}
|
||||
result[req] = res
|
||||
continue
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue