mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-08-01 05:42:46 +00:00
Convert serverkeys to inthttp (#1097)
This commit is contained in:
parent
9834ac97db
commit
2bd12f635c
12 changed files with 164 additions and 169 deletions
|
@ -5,7 +5,6 @@ import (
|
|||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/matrix-org/dendrite/internal/caching"
|
||||
"github.com/matrix-org/dendrite/serverkeyapi/api"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
)
|
||||
|
@ -13,9 +12,8 @@ import (
|
|||
type ServerKeyAPI struct {
|
||||
api.ServerKeyInternalAPI
|
||||
|
||||
ImmutableCache caching.ImmutableCache
|
||||
OurKeyRing gomatrixserverlib.KeyRing
|
||||
FedClient *gomatrixserverlib.FederationClient
|
||||
OurKeyRing gomatrixserverlib.KeyRing
|
||||
FedClient *gomatrixserverlib.FederationClient
|
||||
}
|
||||
|
||||
func (s *ServerKeyAPI) KeyRing() *gomatrixserverlib.KeyRing {
|
||||
|
|
|
@ -1,48 +0,0 @@
|
|||
package internal
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/matrix-org/dendrite/internal"
|
||||
"github.com/matrix-org/dendrite/serverkeyapi/api"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
"github.com/matrix-org/util"
|
||||
)
|
||||
|
||||
func (s *ServerKeyAPI) SetupHTTP(internalAPIMux *mux.Router) {
|
||||
internalAPIMux.Handle(api.ServerKeyQueryPublicKeyPath,
|
||||
internal.MakeInternalAPI("queryPublicKeys", func(req *http.Request) util.JSONResponse {
|
||||
request := api.QueryPublicKeysRequest{}
|
||||
response := api.QueryPublicKeysResponse{}
|
||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
||||
}
|
||||
keys, err := s.FetchKeys(req.Context(), request.Requests)
|
||||
if err != nil {
|
||||
return util.ErrorResponse(err)
|
||||
}
|
||||
response.Results = keys
|
||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
||||
}),
|
||||
)
|
||||
internalAPIMux.Handle(api.ServerKeyInputPublicKeyPath,
|
||||
internal.MakeInternalAPI("inputPublicKeys", func(req *http.Request) util.JSONResponse {
|
||||
request := api.InputPublicKeysRequest{}
|
||||
response := api.InputPublicKeysResponse{}
|
||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
||||
}
|
||||
store := make(map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.PublicKeyLookupResult)
|
||||
for req, res := range request.Keys {
|
||||
store[req] = res
|
||||
s.ImmutableCache.StoreServerKey(req, res)
|
||||
}
|
||||
if err := s.StoreKeys(req.Context(), store); err != nil {
|
||||
return util.ErrorResponse(err)
|
||||
}
|
||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
||||
}),
|
||||
)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue