diff --git a/INSTALL.md b/INSTALL.md index 82f7f00af..0fb0c08e5 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -35,10 +35,10 @@ cd dendrite If using Kafka, install and start it (c.f. [scripts/install-local-kafka.sh](scripts/install-local-kafka.sh)): ```bash -MIRROR=http://apache.mirror.anlx.net/kafka/0.10.2.0/kafka_2.11-0.10.2.0.tgz +KAFKA_URL=http://archive.apache.org/dist/kafka/2.1.0/kafka_2.11-2.1.0.tgz # Only download the kafka if it isn't already downloaded. -test -f kafka.tgz || wget $MIRROR -O kafka.tgz +test -f kafka.tgz || wget $KAFKA_URL -O kafka.tgz # Unpack the kafka over the top of any existing installation mkdir -p kafka && tar xzf kafka.tgz -C kafka --strip-components 1 diff --git a/clientapi/routing/account_data.go b/clientapi/routing/account_data.go index 30e00f723..d57a6d370 100644 --- a/clientapi/routing/account_data.go +++ b/clientapi/routing/account_data.go @@ -33,13 +33,6 @@ func SaveAccountData( req *http.Request, accountDB *accounts.Database, device *authtypes.Device, userID string, roomID string, dataType string, syncProducer *producers.SyncAPIProducer, ) util.JSONResponse { - if req.Method != http.MethodPut { - return util.JSONResponse{ - Code: http.StatusMethodNotAllowed, - JSON: jsonerror.NotFound("Bad method"), - } - } - if userID != device.UserID { return util.JSONResponse{ Code: http.StatusForbidden, diff --git a/clientapi/routing/device.go b/clientapi/routing/device.go index cf6f24a7d..c858e88aa 100644 --- a/clientapi/routing/device.go +++ b/clientapi/routing/device.go @@ -106,13 +106,6 @@ func UpdateDeviceByID( req *http.Request, deviceDB *devices.Database, device *authtypes.Device, deviceID string, ) util.JSONResponse { - if req.Method != http.MethodPut { - return util.JSONResponse{ - Code: http.StatusMethodNotAllowed, - JSON: jsonerror.NotFound("Bad Method"), - } - } - localpart, _, err := gomatrixserverlib.SplitID('@', device.UserID) if err != nil { return httputil.LogThenError(req, err) diff --git a/clientapi/routing/filter.go b/clientapi/routing/filter.go index 1ed91cd2f..291a165b7 100644 --- a/clientapi/routing/filter.go +++ b/clientapi/routing/filter.go @@ -32,12 +32,6 @@ import ( func GetFilter( req *http.Request, device *authtypes.Device, accountDB *accounts.Database, userID string, filterID string, ) util.JSONResponse { - if req.Method != http.MethodGet { - return util.JSONResponse{ - Code: http.StatusMethodNotAllowed, - JSON: jsonerror.NotFound("Bad method"), - } - } if userID != device.UserID { return util.JSONResponse{ Code: http.StatusForbidden, @@ -79,12 +73,6 @@ type filterResponse struct { func PutFilter( req *http.Request, device *authtypes.Device, accountDB *accounts.Database, userID string, ) util.JSONResponse { - if req.Method != http.MethodPost { - return util.JSONResponse{ - Code: http.StatusMethodNotAllowed, - JSON: jsonerror.NotFound("Bad method"), - } - } if userID != device.UserID { return util.JSONResponse{ Code: http.StatusForbidden, diff --git a/clientapi/routing/logout.go b/clientapi/routing/logout.go index d20138534..3294fbcdc 100644 --- a/clientapi/routing/logout.go +++ b/clientapi/routing/logout.go @@ -20,7 +20,6 @@ import ( "github.com/matrix-org/dendrite/clientapi/auth/authtypes" "github.com/matrix-org/dendrite/clientapi/auth/storage/devices" "github.com/matrix-org/dendrite/clientapi/httputil" - "github.com/matrix-org/dendrite/clientapi/jsonerror" "github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/util" ) @@ -29,13 +28,6 @@ import ( func Logout( req *http.Request, deviceDB *devices.Database, device *authtypes.Device, ) util.JSONResponse { - if req.Method != http.MethodPost { - return util.JSONResponse{ - Code: http.StatusMethodNotAllowed, - JSON: jsonerror.NotFound("Bad method"), - } - } - localpart, _, err := gomatrixserverlib.SplitID('@', device.UserID) if err != nil { return httputil.LogThenError(req, err) diff --git a/clientapi/routing/profile.go b/clientapi/routing/profile.go index eb1acab74..034b9ac84 100644 --- a/clientapi/routing/profile.go +++ b/clientapi/routing/profile.go @@ -37,12 +37,6 @@ import ( func GetProfile( req *http.Request, accountDB *accounts.Database, userID string, asAPI appserviceAPI.AppServiceQueryAPI, ) util.JSONResponse { - if req.Method != http.MethodGet { - return util.JSONResponse{ - Code: http.StatusMethodNotAllowed, - JSON: jsonerror.NotFound("Bad method"), - } - } profile, err := appserviceAPI.RetrieveUserProfile(req.Context(), userID, asAPI, accountDB) if err != nil { return httputil.LogThenError(req, err) diff --git a/clientapi/routing/register.go b/clientapi/routing/register.go index 243f9dd23..fa15f4fc0 100644 --- a/clientapi/routing/register.go +++ b/clientapi/routing/register.go @@ -85,6 +85,12 @@ func (d sessionsDict) GetCompletedStages(sessionID string) []authtypes.LoginType // AddCompletedStage records that a session has completed an auth stage. func (d *sessionsDict) AddCompletedStage(sessionID string, stage authtypes.LoginType) { + // Return if the stage is already present + for _, completedStage := range d.GetCompletedStages(sessionID) { + if completedStage == stage { + return + } + } d.sessions[sessionID] = append(d.GetCompletedStages(sessionID), stage) } diff --git a/clientapi/routing/room_tagging.go b/clientapi/routing/room_tagging.go index 3c304b0ed..00774b462 100644 --- a/clientapi/routing/room_tagging.go +++ b/clientapi/routing/room_tagging.go @@ -26,12 +26,13 @@ import ( "github.com/matrix-org/gomatrix" "github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/util" + "github.com/sirupsen/logrus" ) // newTag creates and returns a new Tag type func newTag() gomatrix.TagContent { return gomatrix.TagContent{ - Tags: make(map[string]gomatrix.TagProperties), + Map: make(map[string]gomatrix.TagProperties), } } @@ -69,8 +70,13 @@ func GetTags( return httputil.LogThenError(req, err) } + logrus.Info("MYDUMBDATA") + var tagData []gomatrix.TagData tagContent := newTag() - err = json.Unmarshal(dataByte, &tagContent) + err = json.Unmarshal(dataByte, &tagData) + tagData[0].Content.Map["something"] = gomatrix.TagProperties{0} + logrus.Info(tagData[0].Content.Map) + tagContent = tagData[0].Content if err != nil { return httputil.LogThenError(req, err) @@ -83,7 +89,7 @@ func GetTags( return util.JSONResponse{ Code: http.StatusOK, - JSON: tagContent, + JSON: tagContent.Map, } } @@ -128,7 +134,7 @@ func PutTag( return httputil.LogThenError(req, err) } } - tagContent.Tags[tag] = properties + tagContent.Map[tag] = properties err = saveTagData(req, localpart, roomID, accountDB, tagContent) if err != nil { return httputil.LogThenError(req, err) @@ -188,8 +194,8 @@ func DeleteTag( } // Check whether the Tag to be deleted exists - if _, ok := tagContent.Tags[tag]; ok { - delete(tagContent.Tags, tag) + if _, ok := tagContent.Map[tag]; ok { + delete(tagContent.Map, tag) } else { //Synapse returns a 200 OK response on finding no Tags, same policy is followed here. return util.JSONResponse{ diff --git a/federationapi/routing/routing.go b/federationapi/routing/routing.go index 16704e0b2..ed32c8904 100644 --- a/federationapi/routing/routing.go +++ b/federationapi/routing/routing.go @@ -65,7 +65,7 @@ func Setup( v2keysmux.Handle("/server/{keyID}", localKeys).Methods(http.MethodGet) v2keysmux.Handle("/server/", localKeys).Methods(http.MethodGet) - v1fedmux.Handle("/send/{txnID}/", common.MakeFedAPI( + v1fedmux.Handle("/send/{txnID}", common.MakeFedAPI( "federation_send", cfg.Matrix.ServerName, keys, func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest) util.JSONResponse { vars, err := common.URLDecodeMapValues(mux.Vars(httpReq)) @@ -260,7 +260,7 @@ func Setup( }, )).Methods(http.MethodPost) - v1fedmux.Handle("/backfill/{roomID}/", common.MakeFedAPI( + v1fedmux.Handle("/backfill/{roomID}", common.MakeFedAPI( "federation_backfill", cfg.Matrix.ServerName, keys, func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest) util.JSONResponse { vars, err := common.URLDecodeMapValues(mux.Vars(httpReq)) diff --git a/mediaapi/routing/download.go b/mediaapi/routing/download.go index 38c436367..80ad8418d 100644 --- a/mediaapi/routing/download.go +++ b/mediaapi/routing/download.go @@ -55,7 +55,7 @@ type downloadRequest struct { Logger *log.Entry } -// Download implements /download amd /thumbnail +// Download implements GET /download and GET /thumbnail // Files from this server (i.e. origin == cfg.ServerName) are served directly // Files from remote servers (i.e. origin != cfg.ServerName) are cached locally. // If they are present in the cache, they are served directly. @@ -107,14 +107,6 @@ func Download( } // request validation - if req.Method != http.MethodGet { - dReq.jsonErrorResponse(w, util.JSONResponse{ - Code: http.StatusMethodNotAllowed, - JSON: jsonerror.Unknown("request method must be GET"), - }) - return - } - if resErr := dReq.Validate(); resErr != nil { dReq.jsonErrorResponse(w, *resErr) return diff --git a/mediaapi/routing/upload.go b/mediaapi/routing/upload.go index 1051e0e03..2cb0d8757 100644 --- a/mediaapi/routing/upload.go +++ b/mediaapi/routing/upload.go @@ -48,7 +48,7 @@ type uploadResponse struct { ContentURI string `json:"content_uri"` } -// Upload implements /upload +// Upload implements POST /upload // This endpoint involves uploading potentially significant amounts of data to the homeserver. // This implementation supports a configurable maximum file size limit in bytes. If a user tries to upload more than this, they will receive an error that their upload is too large. // Uploaded files are processed piece-wise to avoid DoS attacks which would starve the server of memory. @@ -75,13 +75,6 @@ func Upload(req *http.Request, cfg *config.Dendrite, db *storage.Database, activ // all the metadata about the media being uploaded. // Returns either an uploadRequest or an error formatted as a util.JSONResponse func parseAndValidateRequest(req *http.Request, cfg *config.Dendrite) (*uploadRequest, *util.JSONResponse) { - if req.Method != http.MethodPost { - return nil, &util.JSONResponse{ - Code: http.StatusMethodNotAllowed, - JSON: jsonerror.Unknown("HTTP request method must be POST."), - } - } - r := &uploadRequest{ MediaMetadata: &types.MediaMetadata{ Origin: cfg.Matrix.ServerName, diff --git a/publicroomsapi/directory/public_rooms.go b/publicroomsapi/directory/public_rooms.go index 100e28e9b..ef7b2662e 100644 --- a/publicroomsapi/directory/public_rooms.go +++ b/publicroomsapi/directory/public_rooms.go @@ -42,8 +42,8 @@ type publicRoomRes struct { Estimate int64 `json:"total_room_count_estimate,omitempty"` } -// GetPublicRooms implements GET /publicRooms -func GetPublicRooms( +// GetPostPublicRooms implements GET and POST /publicRooms +func GetPostPublicRooms( req *http.Request, publicRoomDatabase *storage.PublicRoomsServerDatabase, ) util.JSONResponse { var limit int16 @@ -89,6 +89,7 @@ func GetPublicRooms( // fillPublicRoomsReq fills the Limit, Since and Filter attributes of a GET or POST request // on /publicRooms by parsing the incoming HTTP request +// Filter is only filled for POST requests func fillPublicRoomsReq(httpReq *http.Request, request *publicRoomReq) *util.JSONResponse { if httpReq.Method == http.MethodGet { limit, err := strconv.Atoi(httpReq.FormValue("limit")) diff --git a/publicroomsapi/routing/routing.go b/publicroomsapi/routing/routing.go index 3a1c9eb58..422414bc2 100644 --- a/publicroomsapi/routing/routing.go +++ b/publicroomsapi/routing/routing.go @@ -64,7 +64,7 @@ func Setup(apiMux *mux.Router, deviceDB *devices.Database, publicRoomsDB *storag ).Methods(http.MethodPut, http.MethodOptions) r0mux.Handle("/publicRooms", common.MakeExternalAPI("public_rooms", func(req *http.Request) util.JSONResponse { - return directory.GetPublicRooms(req, publicRoomsDB) + return directory.GetPostPublicRooms(req, publicRoomsDB) }), ).Methods(http.MethodGet, http.MethodPost, http.MethodOptions) } diff --git a/testfile b/testfile index 529854b18..3251396dc 100644 --- a/testfile +++ b/testfile @@ -148,4 +148,6 @@ Typing events appear in initial sync Typing events appear in incremental sync Typing events appear in gapped sync Can add tag -Can remove tag \ No newline at end of file +Can remove tag +Inbound federation of state requires event_id as a mandatory paramater +Inbound federation of state_ids requires event_id as a mandatory paramater