Merge branch 'master' into kegan/device-db-glue

This commit is contained in:
Kegan Dougal 2017-05-23 09:17:36 +01:00
commit 9d5eb03a67
5 changed files with 31 additions and 9 deletions

View file

@ -7,3 +7,9 @@ go fmt ./src/...
go tool vet --all --shadow ./src
gocyclo -over 12 src/
gb test
# Check that all the packages can build.
# When `go build` is given multiple packages it won't output anything, and just
# checks that everything builds. This seems to do a better job of handling
# missing imports than `gb build` does.
GOPATH=$(pwd):$(pwd)/vendor go build github.com/matrix-org/dendrite/cmd/...

View file

@ -19,7 +19,9 @@ import (
"net/http"
"github.com/gorilla/mux"
"github.com/matrix-org/dendrite/clientapi/auth/storage"
"github.com/matrix-org/dendrite/clientapi/auth"
"github.com/matrix-org/dendrite/clientapi/auth/storage/accounts"
"github.com/matrix-org/dendrite/clientapi/auth/storage/devices"
"github.com/matrix-org/dendrite/clientapi/auth/types"
"github.com/matrix-org/dendrite/clientapi/config"
"github.com/matrix-org/dendrite/clientapi/producers"
@ -34,7 +36,7 @@ const pathPrefixR0 = "/_matrix/client/r0"
// Setup registers HTTP handlers with the given ServeMux. It also supplies the given http.Client
// to clients which need to make outbound HTTP requests.
func Setup(servMux *http.ServeMux, httpClient *http.Client, cfg config.ClientAPI, producer *producers.RoomserverProducer, queryAPI api.RoomserverQueryAPI, accountDB *storage.AccountDatabase) {
func Setup(servMux *http.ServeMux, httpClient *http.Client, cfg config.ClientAPI, producer *producers.RoomserverProducer, queryAPI api.RoomserverQueryAPI, accountDB *accounts.Database) {
apiMux := mux.NewRouter()
r0mux := apiMux.PathPrefix(pathPrefixR0).Subrouter()
r0mux.Handle("/createRoom",
@ -155,11 +157,11 @@ func Setup(servMux *http.ServeMux, httpClient *http.Client, cfg config.ClientAPI
// make a util.JSONRequestHandler function into an http.Handler which checks the access token in the request.
func makeAuthAPI(metricsName string, deviceDB *devices.Database, f func(*http.Request, types.Device) util.JSONResponse) http.Handler {
h := util.NewJSONRequestHandler(func(req *http.Request) util.JSONResponse {
device, resErr := auth.VerifyAccessToken(req, deviceDB)
device, resErr := auth.VerifyAccessTokenNew(req, deviceDB)
if resErr != nil {
return resErr
return *resErr
}
return f(req, device)
return f(req, *device)
})
return prometheus.InstrumentHandler(metricsName, util.MakeJSONAPI(h))
}

View file

@ -5,7 +5,7 @@ import (
"net/http"
log "github.com/Sirupsen/logrus"
"github.com/matrix-org/dendrite/clientapi/auth/storage"
"github.com/matrix-org/dendrite/clientapi/auth/storage/accounts"
"github.com/matrix-org/dendrite/clientapi/auth/types"
"github.com/matrix-org/dendrite/clientapi/httputil"
"github.com/matrix-org/dendrite/clientapi/jsonerror"
@ -90,7 +90,7 @@ func (r *registerRequest) Validate() *util.JSONResponse {
}
// Register processes a /register request. http://matrix.org/speculator/spec/HEAD/client_server/unstable.html#post-matrix-client-unstable-register
func Register(req *http.Request, accountDB *storage.AccountDatabase) util.JSONResponse {
func Register(req *http.Request, accountDB *accounts.Database) util.JSONResponse {
var r registerRequest
resErr := httputil.UnmarshalJSONRequest(req, &r)
if resErr != nil {
@ -140,7 +140,7 @@ func Register(req *http.Request, accountDB *storage.AccountDatabase) util.JSONRe
}
}
func completeRegistration(accountDB *storage.AccountDatabase, username, password string) util.JSONResponse {
func completeRegistration(accountDB *accounts.Database, username, password string) util.JSONResponse {
acc, err := accountDB.CreateAccount(username, password)
if err != nil {
return util.JSONResponse{

2
vendor/manifest vendored
View file

@ -98,7 +98,7 @@
{
"importpath": "github.com/matrix-org/gomatrixserverlib",
"repository": "https://github.com/matrix-org/gomatrixserverlib",
"revision": "8e7504f3b62366e621525c962314f53c045512e3",
"revision": "785a53c41170526aa7a91a1fc534afac6ce01a9b",
"branch": "master"
},
{

View file

@ -119,6 +119,10 @@ func (eb *EventBuilder) Build(eventID string, now time.Time, origin ServerName,
EventID string `json:"event_id"`
OriginServerTS Timestamp `json:"origin_server_ts"`
Origin ServerName `json:"origin"`
// This key is either absent or an empty list.
// If it is absent then the pointer is nil and omitempty removes it.
// Otherwise it points to an empty list and omitempty keeps it.
PrevState *[]EventReference `json:"prev_state,omitempty"`
}
event.EventBuilder = *eb
if event.PrevEvents == nil {
@ -131,6 +135,16 @@ func (eb *EventBuilder) Build(eventID string, now time.Time, origin ServerName,
event.Origin = origin
event.EventID = eventID
if event.StateKey != nil {
// In early versions of the matrix protocol state events
// had a "prev_state" key that listed the state events with
// the same type and state key that this event replaced.
// This was later dropped from the protocol.
// Synapse ignores the contents of the key but still expects
// the key to be present in state events.
event.PrevState = &emptyEventReferenceList
}
// TODO: Check size limits.
var eventJSON []byte