mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-07-29 12:42:46 +00:00
fedsender: add cache tables for notary keys (#1923)
* Add notary server tables for postgres * Add sqlite tables * fedsender: GetServerKeys -> QueryServerKeys As it now checks a cache and can return multiple responses
This commit is contained in:
parent
1827dd7c09
commit
c102adaf43
16 changed files with 640 additions and 74 deletions
|
@ -202,20 +202,6 @@ func (a *FederationSenderInternalAPI) GetEvent(
|
|||
return ires.(gomatrixserverlib.Transaction), nil
|
||||
}
|
||||
|
||||
func (a *FederationSenderInternalAPI) GetServerKeys(
|
||||
ctx context.Context, s gomatrixserverlib.ServerName,
|
||||
) (gomatrixserverlib.ServerKeys, error) {
|
||||
ctx, cancel := context.WithTimeout(ctx, time.Second*30)
|
||||
defer cancel()
|
||||
ires, err := a.doRequest(s, func() (interface{}, error) {
|
||||
return a.federation.GetServerKeys(ctx, s)
|
||||
})
|
||||
if err != nil {
|
||||
return gomatrixserverlib.ServerKeys{}, err
|
||||
}
|
||||
return ires.(gomatrixserverlib.ServerKeys), nil
|
||||
}
|
||||
|
||||
func (a *FederationSenderInternalAPI) LookupServerKeys(
|
||||
ctx context.Context, s gomatrixserverlib.ServerName, keyRequests map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.Timestamp,
|
||||
) ([]gomatrixserverlib.ServerKeys, error) {
|
||||
|
|
|
@ -2,8 +2,12 @@ package internal
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/matrix-org/dendrite/federationsender/api"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
"github.com/matrix-org/util"
|
||||
)
|
||||
|
||||
// QueryJoinedHostServerNamesInRoom implements api.FederationSenderInternalAPI
|
||||
|
@ -20,3 +24,30 @@ func (f *FederationSenderInternalAPI) QueryJoinedHostServerNamesInRoom(
|
|||
|
||||
return
|
||||
}
|
||||
|
||||
func (a *FederationSenderInternalAPI) QueryServerKeys(
|
||||
ctx context.Context, req *api.QueryServerKeysRequest, res *api.QueryServerKeysResponse,
|
||||
) error {
|
||||
ctx, cancel := context.WithTimeout(ctx, time.Second*30)
|
||||
defer cancel()
|
||||
ires, err := a.doRequest(req.ServerName, func() (interface{}, error) {
|
||||
return a.federation.GetServerKeys(ctx, req.ServerName)
|
||||
})
|
||||
if err != nil {
|
||||
// try to load from the cache
|
||||
serverKeysResponses, dbErr := a.db.GetNotaryKeys(ctx, req.ServerName, req.OptionalKeyIDs)
|
||||
if dbErr != nil {
|
||||
return fmt.Errorf("server returned %s, and db returned %s", err, dbErr)
|
||||
}
|
||||
res.ServerKeys = serverKeysResponses
|
||||
return nil
|
||||
}
|
||||
serverKeys := ires.(gomatrixserverlib.ServerKeys)
|
||||
// cache it!
|
||||
if err = a.db.UpdateNotaryKeys(context.Background(), req.ServerName, serverKeys); err != nil {
|
||||
// non-fatal, still return the response
|
||||
util.GetLogger(ctx).WithError(err).Warn("failed to UpdateNotaryKeys")
|
||||
}
|
||||
res.ServerKeys = []gomatrixserverlib.ServerKeys{serverKeys}
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue