Add prefer_direct_fetch option

This commit is contained in:
Neil Alexander 2020-09-29 16:00:05 +01:00
parent 43cdba9a69
commit 4ad297828b
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944
3 changed files with 24 additions and 5 deletions

View file

@ -274,6 +274,11 @@ server_key_api:
- key_id: ed25519:a_RXGa
public_key: l8Hft5qXKn1vfHrg3p4+W8gELQVo8N13JkluMfmn2sQ
# This option will control whether Dendrite will prefer to look up keys directly
# or whether it should try perspective servers first, using direct fetches as a
# last resort.
prefer_direct_fetch: false
# Configuration for the Sync API.
sync_api:
internal_api:

View file

@ -14,6 +14,9 @@ type ServerKeyAPI struct {
// Perspective keyservers, to use as a backup when direct key fetch
// requests don't succeed
KeyPerspectives KeyPerspectives `yaml:"key_perspectives"`
// Should we prefer direct key fetches over perspective ones?
PreferDirectFetch bool `yaml:"prefer_direct_fetch"`
}
func (c *ServerKeyAPI) Defaults() {

View file

@ -51,15 +51,26 @@ func NewInternalAPI(
ServerKeyValidity: cfg.Matrix.KeyValidityPeriod,
FedClient: fedClient,
OurKeyRing: gomatrixserverlib.KeyRing{
KeyFetchers: []gomatrixserverlib.KeyFetcher{
&gomatrixserverlib.DirectKeyFetcher{
Client: fedClient,
},
},
KeyFetchers: []gomatrixserverlib.KeyFetcher{},
KeyDatabase: serverKeyDB,
},
}
addDirectFetcher := func() {
internalAPI.OurKeyRing.KeyFetchers = append(
internalAPI.OurKeyRing.KeyFetchers,
&gomatrixserverlib.DirectKeyFetcher{
Client: fedClient,
},
)
}
if cfg.PreferDirectFetch {
addDirectFetcher()
} else {
defer addDirectFetcher()
}
var b64e = base64.StdEncoding.WithPadding(base64.NoPadding)
for _, ps := range cfg.KeyPerspectives {
perspective := &gomatrixserverlib.PerspectiveKeyFetcher{