MCPcopy Create free account
hub / github.com/daodst/chat / QueryServerKeys

Method QueryServerKeys

federationapi/internal/query.go:67–97  ·  view source on GitHub ↗
(
	ctx context.Context, req *api.QueryServerKeysRequest, res *api.QueryServerKeysResponse,
)

Source from the content-addressed store, hash-verified

65}
66
67func (a *FederationInternalAPI) QueryServerKeys(
68 ctx context.Context, req *api.QueryServerKeysRequest, res *api.QueryServerKeysResponse,
69) error {
70 // attempt to satisfy the entire request from the cache first
71 results, err := a.fetchServerKeysFromCache(ctx, req)
72 if err == nil {
73 // satisfied entirely from cache, return it
74 res.ServerKeys = results
75 return nil
76 }
77 util.GetLogger(ctx).WithField("server", req.ServerName).WithError(err).Warn("notary: failed to satisfy keys request entirely from cache, hitting direct")
78
79 serverKeys, err := a.fetchServerKeysDirectly(ctx, req.ServerName)
80 if err != nil {
81 // try to load as much as we can from the cache in a best effort basis
82 util.GetLogger(ctx).WithField("server", req.ServerName).WithError(err).Warn("notary: failed to ask server for keys, returning best effort keys")
83 serverKeysResponses, dbErr := a.db.GetNotaryKeys(ctx, req.ServerName, req.KeyIDs())
84 if dbErr != nil {
85 return fmt.Errorf("notary: server returned %s, and db returned %s", err, dbErr)
86 }
87 res.ServerKeys = serverKeysResponses
88 return nil
89 }
90 // cache it!
91 if err = a.db.UpdateNotaryKeys(context.Background(), req.ServerName, *serverKeys); err != nil {
92 // non-fatal, still return the response
93 util.GetLogger(ctx).WithError(err).Warn("failed to UpdateNotaryKeys")
94 }
95 res.ServerKeys = []gomatrixserverlib.ServerKeys{*serverKeys}
96 return nil
97}

Callers

nothing calls this directly

Calls 5

KeyIDsMethod · 0.80
GetNotaryKeysMethod · 0.65
UpdateNotaryKeysMethod · 0.65

Tested by

no test coverage detected