diff --git a/linter.json b/linter.json index c2a3d80e..7c27ea6f 100644 --- a/linter.json +++ b/linter.json @@ -1,6 +1,7 @@ { "Vendor": true, "Cyclo": 12, + "Deadline": "60s", "Enable": [ "vetshadow", "gotype", @@ -12,6 +13,7 @@ "aligncheck", "ineffassign", "gas", - "misspell" + "misspell", + "unparam" ] } diff --git a/src/github.com/matrix-org/dendrite/clientapi/readers/directory.go b/src/github.com/matrix-org/dendrite/clientapi/readers/directory.go index 4c25a45c..f561b407 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/readers/directory.go +++ b/src/github.com/matrix-org/dendrite/clientapi/readers/directory.go @@ -30,7 +30,6 @@ import ( // DirectoryRoom looks up a room alias func DirectoryRoom( req *http.Request, - device *authtypes.Device, roomAlias string, federation *gomatrixserverlib.FederationClient, cfg *config.Dendrite, @@ -150,7 +149,6 @@ func RemoveLocalAlias( req *http.Request, device *authtypes.Device, alias string, - cfg *config.Dendrite, aliasAPI api.RoomserverAliasAPI, ) util.JSONResponse { queryReq := api.RemoveRoomAliasRequest{ diff --git a/src/github.com/matrix-org/dendrite/clientapi/readers/memberships.go b/src/github.com/matrix-org/dendrite/clientapi/readers/memberships.go index 530dbe73..bbd1ebc4 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/readers/memberships.go +++ b/src/github.com/matrix-org/dendrite/clientapi/readers/memberships.go @@ -18,7 +18,6 @@ import ( "net/http" "github.com/matrix-org/dendrite/clientapi/auth/authtypes" - "github.com/matrix-org/dendrite/clientapi/auth/storage/accounts" "github.com/matrix-org/dendrite/clientapi/httputil" "github.com/matrix-org/dendrite/clientapi/jsonerror" "github.com/matrix-org/dendrite/common/config" @@ -34,7 +33,7 @@ type response struct { // GetMemberships implements GET /rooms/{roomId}/members func GetMemberships( req *http.Request, device *authtypes.Device, roomID string, joinedOnly bool, - accountDB *accounts.Database, cfg config.Dendrite, + cfg config.Dendrite, queryAPI api.RoomserverQueryAPI, ) util.JSONResponse { queryReq := api.QueryMembershipsForRoomRequest{ diff --git a/src/github.com/matrix-org/dendrite/clientapi/readers/profile.go b/src/github.com/matrix-org/dendrite/clientapi/readers/profile.go index 069fb1c2..652961cb 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/readers/profile.go +++ b/src/github.com/matrix-org/dendrite/clientapi/readers/profile.go @@ -146,7 +146,7 @@ func SetAvatarURL( AvatarURL: r.AvatarURL, } - events, err := buildMembershipEvents(memberships, accountDB, newProfile, userID, cfg, queryAPI) + events, err := buildMembershipEvents(memberships, newProfile, userID, cfg, queryAPI) if err != nil { return httputil.LogThenError(req, err) } @@ -238,7 +238,7 @@ func SetDisplayName( AvatarURL: oldProfile.AvatarURL, } - events, err := buildMembershipEvents(memberships, accountDB, newProfile, userID, cfg, queryAPI) + events, err := buildMembershipEvents(memberships, newProfile, userID, cfg, queryAPI) if err != nil { return httputil.LogThenError(req, err) } @@ -258,7 +258,7 @@ func SetDisplayName( } func buildMembershipEvents( - memberships []authtypes.Membership, db *accounts.Database, + memberships []authtypes.Membership, newProfile authtypes.Profile, userID string, cfg *config.Dendrite, queryAPI api.RoomserverQueryAPI, ) ([]gomatrixserverlib.Event, error) { diff --git a/src/github.com/matrix-org/dendrite/clientapi/routing/routing.go b/src/github.com/matrix-org/dendrite/clientapi/routing/routing.go index 950202c5..58e852fe 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/routing/routing.go +++ b/src/github.com/matrix-org/dendrite/clientapi/routing/routing.go @@ -40,7 +40,7 @@ const pathPrefixUnstable = "/_matrix/client/unstable" // 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( - apiMux *mux.Router, httpClient *http.Client, cfg config.Dendrite, + apiMux *mux.Router, cfg config.Dendrite, producer *producers.RoomserverProducer, queryAPI api.RoomserverQueryAPI, aliasAPI api.RoomserverAliasAPI, accountDB *accounts.Database, @@ -121,7 +121,7 @@ func Setup( r0mux.Handle("/directory/room/{roomAlias}", common.MakeAuthAPI("directory_room", deviceDB, func(req *http.Request, device *authtypes.Device) util.JSONResponse { vars := mux.Vars(req) - return readers.DirectoryRoom(req, device, vars["roomAlias"], federation, &cfg, aliasAPI) + return readers.DirectoryRoom(req, vars["roomAlias"], federation, &cfg, aliasAPI) }), ).Methods("GET") @@ -135,7 +135,7 @@ func Setup( r0mux.Handle("/directory/room/{roomAlias}", common.MakeAuthAPI("directory_room", deviceDB, func(req *http.Request, device *authtypes.Device) util.JSONResponse { vars := mux.Vars(req) - return readers.RemoveLocalAlias(req, device, vars["roomAlias"], &cfg, aliasAPI) + return readers.RemoveLocalAlias(req, device, vars["roomAlias"], aliasAPI) }), ).Methods("DELETE") @@ -315,14 +315,14 @@ func Setup( r0mux.Handle("/rooms/{roomID}/members", common.MakeAuthAPI("rooms_members", deviceDB, func(req *http.Request, device *authtypes.Device) util.JSONResponse { vars := mux.Vars(req) - return readers.GetMemberships(req, device, vars["roomID"], false, accountDB, cfg, queryAPI) + return readers.GetMemberships(req, device, vars["roomID"], false, cfg, queryAPI) }), ) r0mux.Handle("/rooms/{roomID}/joined_members", common.MakeAuthAPI("rooms_members", deviceDB, func(req *http.Request, device *authtypes.Device) util.JSONResponse { vars := mux.Vars(req) - return readers.GetMemberships(req, device, vars["roomID"], true, accountDB, cfg, queryAPI) + return readers.GetMemberships(req, device, vars["roomID"], true, cfg, queryAPI) }), ) diff --git a/src/github.com/matrix-org/dendrite/clientapi/threepid/invites.go b/src/github.com/matrix-org/dendrite/clientapi/threepid/invites.go index 244e5f63..85f0b5dc 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/threepid/invites.go +++ b/src/github.com/matrix-org/dendrite/clientapi/threepid/invites.go @@ -97,7 +97,7 @@ func CheckAndProcessInvite( } } - lookupRes, storeInviteRes, err := queryIDServer(req, db, cfg, device, body, roomID) + lookupRes, storeInviteRes, err := queryIDServer(db, cfg, device, body, roomID) if err != nil { resErr := httputil.LogThenError(req, err) return &resErr @@ -142,7 +142,7 @@ func CheckAndProcessInvite( // Returns a representation of the response for both cases. // Returns an error if a check or a request failed. func queryIDServer( - req *http.Request, db *accounts.Database, cfg config.Dendrite, + db *accounts.Database, cfg config.Dendrite, device *authtypes.Device, body *MembershipRequest, roomID string, ) (lookupRes *idServerLookupResponse, storeInviteRes *idServerStoreInviteResponse, err error) { // Lookup the 3PID @@ -165,7 +165,7 @@ func queryIDServer( if lookupRes.NotBefore > now || now > lookupRes.NotAfter { // If the current timestamp isn't in the time frame in which the association // is known to be valid, re-run the query - return queryIDServer(req, db, cfg, device, body, roomID) + return queryIDServer(db, cfg, device, body, roomID) } // Check the request signatures and send an error if one isn't valid diff --git a/src/github.com/matrix-org/dendrite/clientapi/writers/register.go b/src/github.com/matrix-org/dendrite/clientapi/writers/register.go index d09b371d..34c9bd65 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/writers/register.go +++ b/src/github.com/matrix-org/dendrite/clientapi/writers/register.go @@ -3,6 +3,7 @@ package writers import ( "fmt" "net/http" + "time" log "github.com/Sirupsen/logrus" "github.com/matrix-org/dendrite/clientapi/auth" @@ -120,7 +121,7 @@ func Register(req *http.Request, accountDB *accounts.Database, deviceDB *devices Code: 401, // TODO: Hard-coded 'dummy' auth for now with a bogus session ID. // Server admins should be able to change things around (eg enable captcha) - JSON: newUserInteractiveResponse("totallyuniquesessionid", []authFlow{ + JSON: newUserInteractiveResponse(time.Now().String(), []authFlow{ {[]authtypes.LoginType{authtypes.LoginTypeDummy}}, }), } diff --git a/src/github.com/matrix-org/dendrite/clientapi/writers/sendevent.go b/src/github.com/matrix-org/dendrite/clientapi/writers/sendevent.go index 868700f5..9135accb 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/writers/sendevent.go +++ b/src/github.com/matrix-org/dendrite/clientapi/writers/sendevent.go @@ -40,7 +40,7 @@ type sendEventResponse struct { func SendEvent( req *http.Request, device *authtypes.Device, - roomID, eventType, txnID string, stateKey *string, + roomID, eventType, _ string, stateKey *string, cfg config.Dendrite, queryAPI api.RoomserverQueryAPI, producer *producers.RoomserverProducer, diff --git a/src/github.com/matrix-org/dendrite/cmd/dendrite-client-api-server/main.go b/src/github.com/matrix-org/dendrite/cmd/dendrite-client-api-server/main.go index 53ebdb93..630443d3 100644 --- a/src/github.com/matrix-org/dendrite/cmd/dendrite-client-api-server/main.go +++ b/src/github.com/matrix-org/dendrite/cmd/dendrite-client-api-server/main.go @@ -117,7 +117,7 @@ func main() { api := mux.NewRouter() routing.Setup( - api, http.DefaultClient, *cfg, roomserverProducer, + api, *cfg, roomserverProducer, queryAPI, aliasAPI, accountDB, deviceDB, federation, keyRing, userUpdateProducer, syncProducer, ) diff --git a/src/github.com/matrix-org/dendrite/cmd/dendrite-media-api-server/main.go b/src/github.com/matrix-org/dendrite/cmd/dendrite-media-api-server/main.go index 34a53115..51cd6017 100644 --- a/src/github.com/matrix-org/dendrite/cmd/dendrite-media-api-server/main.go +++ b/src/github.com/matrix-org/dendrite/cmd/dendrite-media-api-server/main.go @@ -54,7 +54,7 @@ func main() { log.Info("Starting media API server on ", cfg.Listen.MediaAPI) api := mux.NewRouter() - routing.Setup(api, http.DefaultClient, cfg, db) + routing.Setup(api, cfg, db) common.SetupHTTPAPI(http.DefaultServeMux, api) log.Fatal(http.ListenAndServe(string(cfg.Listen.MediaAPI), nil)) diff --git a/src/github.com/matrix-org/dendrite/cmd/dendrite-monolith-server/main.go b/src/github.com/matrix-org/dendrite/cmd/dendrite-monolith-server/main.go index 9b6422c5..dcbec023 100644 --- a/src/github.com/matrix-org/dendrite/cmd/dendrite-monolith-server/main.go +++ b/src/github.com/matrix-org/dendrite/cmd/dendrite-monolith-server/main.go @@ -318,13 +318,13 @@ func (m *monolith) setupConsumers() { func (m *monolith) setupAPIs() { clientapi_routing.Setup( - m.api, http.DefaultClient, *m.cfg, m.roomServerProducer, + m.api, *m.cfg, m.roomServerProducer, m.queryAPI, m.aliasAPI, m.accountDB, m.deviceDB, m.federation, m.keyRing, m.userUpdateProducer, m.syncProducer, ) mediaapi_routing.Setup( - m.api, http.DefaultClient, m.cfg, m.mediaAPIDB, + m.api, m.cfg, m.mediaAPIDB, ) syncapi_routing.Setup(m.api, syncapi_sync.NewRequestPool( diff --git a/src/github.com/matrix-org/dendrite/cmd/mediaapi-integration-tests/main.go b/src/github.com/matrix-org/dendrite/cmd/mediaapi-integration-tests/main.go index f0e3b0c0..6eaa9ea3 100644 --- a/src/github.com/matrix-org/dendrite/cmd/mediaapi-integration-tests/main.go +++ b/src/github.com/matrix-org/dendrite/cmd/mediaapi-integration-tests/main.go @@ -65,6 +65,10 @@ var thumbnailSizes = (` const serverType = "media-api" +const testMediaID = "1VuVy8u_hmDllD8BrcY0deM34Bl7SPJeY9J6BkMmpx0" +const testContentType = "image/jpeg" +const testOrigin = "localhost:18001" + var testDatabaseTemplate = "dbname=%s sslmode=disable binary_parameters=yes" var timeout time.Duration @@ -81,10 +85,11 @@ func startMediaAPI(suffix string, dynamicThumbnails bool) (*exec.Cmd, chan error database := fmt.Sprintf(testDatabaseTemplate, testDatabaseName+suffix) cfg, nextPort, err := test.MakeConfig(dir, kafkaURI, database, "localhost", port) - cfg.Matrix.ServerName = gomatrixserverlib.ServerName(proxyAddr) if err != nil { panic(err) } + cfg.Matrix.ServerName = gomatrixserverlib.ServerName(proxyAddr) + cfg.Media.DynamicThumbnails = dynamicThumbnails if err = yaml.Unmarshal([]byte(thumbnailSizes), &cfg.Media.ThumbnailSizes); err != nil { panic(err) } @@ -142,46 +147,46 @@ func main() { server1Cmd, server1CmdChan, _, server1ProxyCmd, _, server1ProxyAddr, server1Dir := startMediaAPI("1", false) defer cleanUpServer(server1Cmd, server1Dir) defer server1ProxyCmd.Process.Kill() - testDownload(server1ProxyAddr, server1ProxyAddr, "doesnotexist", "", 404, server1CmdChan) + testDownload(server1ProxyAddr, server1ProxyAddr, "doesnotexist", 404, server1CmdChan) // upload a JPEG file - testUpload(server1ProxyAddr, testJPEG, "image/jpeg", `{ - "content_uri": "mxc://localhost:18001/1VuVy8u_hmDllD8BrcY0deM34Bl7SPJeY9J6BkMmpx0" - }`, 200, server1CmdChan) + testUpload( + server1ProxyAddr, testJPEG, + ) // download that JPEG file - testDownload(server1ProxyAddr, "localhost:18001", "1VuVy8u_hmDllD8BrcY0deM34Bl7SPJeY9J6BkMmpx0", "", 200, server1CmdChan) + testDownload(server1ProxyAddr, testOrigin, testMediaID, 200, server1CmdChan) // thumbnail that JPEG file - testThumbnail(64, 64, "crop", server1ProxyAddr, "localhost:18001", "1VuVy8u_hmDllD8BrcY0deM34Bl7SPJeY9J6BkMmpx0", "", 200, server1CmdChan) + testThumbnail(64, 64, "crop", server1ProxyAddr, server1CmdChan) // create server2 with dynamic thumbnail generation server2Cmd, server2CmdChan, _, server2ProxyCmd, _, server2ProxyAddr, server2Dir := startMediaAPI("2", true) defer cleanUpServer(server2Cmd, server2Dir) defer server2ProxyCmd.Process.Kill() - testDownload(server2ProxyAddr, server2ProxyAddr, "doesnotexist", "", 404, server2CmdChan) + testDownload(server2ProxyAddr, server2ProxyAddr, "doesnotexist", 404, server2CmdChan) // pre-generated thumbnail that JPEG file via server2 - testThumbnail(800, 600, "scale", server2ProxyAddr, "localhost:18001", "1VuVy8u_hmDllD8BrcY0deM34Bl7SPJeY9J6BkMmpx0", "", 200, server2CmdChan) + testThumbnail(800, 600, "scale", server2ProxyAddr, server2CmdChan) // download that JPEG file via server2 - testDownload(server2ProxyAddr, "localhost:18001", "1VuVy8u_hmDllD8BrcY0deM34Bl7SPJeY9J6BkMmpx0", "", 200, server2CmdChan) + testDownload(server2ProxyAddr, testOrigin, testMediaID, 200, server2CmdChan) // dynamic thumbnail that JPEG file via server2 - testThumbnail(1920, 1080, "scale", server2ProxyAddr, "localhost:18001", "1VuVy8u_hmDllD8BrcY0deM34Bl7SPJeY9J6BkMmpx0", "", 200, server2CmdChan) + testThumbnail(1920, 1080, "scale", server2ProxyAddr, server2CmdChan) // thumbnail that JPEG file via server2 - testThumbnail(10000, 10000, "scale", server2ProxyAddr, "localhost:18001", "1VuVy8u_hmDllD8BrcY0deM34Bl7SPJeY9J6BkMmpx0", "", 200, server2CmdChan) + testThumbnail(10000, 10000, "scale", server2ProxyAddr, server2CmdChan) } -func getMediaURI(scheme, host, endpoint, query string, components []string) string { +func getMediaURI(host, endpoint, query string, components []string) string { pathComponents := []string{host, "_matrix/media/v1", endpoint} pathComponents = append(pathComponents, components...) - return scheme + path.Join(pathComponents...) + query + return "https://" + path.Join(pathComponents...) + query } -func testUpload(host, filePath, contentType, wantedBody string, wantedStatusCode int, serverCmdChan chan error) { +func testUpload(host, filePath string) { fmt.Printf("==TESTING== upload %v to %v\n", filePath, host) file, err := os.Open(filePath) defer file.Close() @@ -197,18 +202,19 @@ func testUpload(host, filePath, contentType, wantedBody string, wantedStatusCode req, err := http.NewRequest( "POST", - getMediaURI("https://", host, "upload", "?filename="+filename, nil), + getMediaURI(host, "upload", "?filename="+filename, nil), file, ) if err != nil { panic(err) } req.ContentLength = fileSize - req.Header.Set("Content-Type", contentType) + req.Header.Set("Content-Type", testContentType) + wantedBody := `{"content_uri": "mxc://localhost:18001/` + testMediaID + `"}` testReq := &test.Request{ Req: req, - WantedStatusCode: wantedStatusCode, + WantedStatusCode: 200, WantedBody: test.CanonicalJSONInput([]string{wantedBody})[0], } if err := testReq.Do(); err != nil { @@ -217,10 +223,10 @@ func testUpload(host, filePath, contentType, wantedBody string, wantedStatusCode fmt.Printf("==TESTING== upload %v to %v PASSED\n", filePath, host) } -func testDownload(host, origin, mediaID, wantedBody string, wantedStatusCode int, serverCmdChan chan error) { +func testDownload(host, origin, mediaID string, wantedStatusCode int, serverCmdChan chan error) { req, err := http.NewRequest( "GET", - getMediaURI("https://", host, "download", "", []string{ + getMediaURI(host, "download", "", []string{ origin, mediaID, }), @@ -232,21 +238,21 @@ func testDownload(host, origin, mediaID, wantedBody string, wantedStatusCode int testReq := &test.Request{ Req: req, WantedStatusCode: wantedStatusCode, - WantedBody: test.CanonicalJSONInput([]string{wantedBody})[0], + WantedBody: test.CanonicalJSONInput([]string{""})[0], } testReq.Run(fmt.Sprintf("download mxc://%v/%v from %v", origin, mediaID, host), timeout, serverCmdChan) } -func testThumbnail(width, height int, resizeMethod, host, origin, mediaID, wantedBody string, wantedStatusCode int, serverCmdChan chan error) { +func testThumbnail(width, height int, resizeMethod, host string, serverCmdChan chan error) { query := fmt.Sprintf("?width=%v&height=%v", width, height) if resizeMethod != "" { query += "&method=" + resizeMethod } req, err := http.NewRequest( "GET", - getMediaURI("https://", host, "thumbnail", query, []string{ - origin, - mediaID, + getMediaURI(host, "thumbnail", query, []string{ + testOrigin, + testMediaID, }), nil, ) @@ -255,8 +261,8 @@ func testThumbnail(width, height int, resizeMethod, host, origin, mediaID, wante } testReq := &test.Request{ Req: req, - WantedStatusCode: wantedStatusCode, - WantedBody: test.CanonicalJSONInput([]string{wantedBody})[0], + WantedStatusCode: 200, + WantedBody: test.CanonicalJSONInput([]string{""})[0], } - testReq.Run(fmt.Sprintf("thumbnail mxc://%v/%v%v from %v", origin, mediaID, query, host), timeout, serverCmdChan) + testReq.Run(fmt.Sprintf("thumbnail mxc://%v/%v%v from %v", testOrigin, testMediaID, query, host), timeout, serverCmdChan) } diff --git a/src/github.com/matrix-org/dendrite/federationapi/readers/events.go b/src/github.com/matrix-org/dendrite/federationapi/readers/events.go index e161f54c..ad3ee875 100644 --- a/src/github.com/matrix-org/dendrite/federationapi/readers/events.go +++ b/src/github.com/matrix-org/dendrite/federationapi/readers/events.go @@ -15,7 +15,6 @@ package readers import ( - "net/http" "time" "github.com/matrix-org/dendrite/common/config" @@ -26,7 +25,6 @@ import ( // GetEvent returns the requested event func GetEvent( - httpReq *http.Request, request *gomatrixserverlib.FederationRequest, cfg config.Dendrite, query api.RoomserverQueryAPI, diff --git a/src/github.com/matrix-org/dendrite/federationapi/readers/keys.go b/src/github.com/matrix-org/dendrite/federationapi/readers/keys.go index 87c9f79b..fcca201e 100644 --- a/src/github.com/matrix-org/dendrite/federationapi/readers/keys.go +++ b/src/github.com/matrix-org/dendrite/federationapi/readers/keys.go @@ -16,17 +16,17 @@ package readers import ( "encoding/json" + "time" + "github.com/matrix-org/dendrite/common/config" "github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/util" "golang.org/x/crypto/ed25519" - "net/http" - "time" ) // LocalKeys returns the local keys for the server. // See https://matrix.org/docs/spec/server_server/unstable.html#publishing-keys -func LocalKeys(req *http.Request, cfg config.Dendrite) util.JSONResponse { +func LocalKeys(cfg config.Dendrite) util.JSONResponse { keys, err := localKeys(cfg, time.Now().Add(cfg.Matrix.KeyValidityPeriod)) if err != nil { return util.ErrorResponse(err) diff --git a/src/github.com/matrix-org/dendrite/federationapi/routing/routing.go b/src/github.com/matrix-org/dendrite/federationapi/routing/routing.go index 2f753055..b4d01dab 100644 --- a/src/github.com/matrix-org/dendrite/federationapi/routing/routing.go +++ b/src/github.com/matrix-org/dendrite/federationapi/routing/routing.go @@ -47,7 +47,7 @@ func Setup( v1fedmux := apiMux.PathPrefix(pathPrefixV1Federation).Subrouter() localKeys := common.MakeAPI("localkeys", func(req *http.Request) util.JSONResponse { - return readers.LocalKeys(req, cfg) + return readers.LocalKeys(cfg) }) // Ignore the {keyID} argument as we only have a single server key so we always @@ -84,7 +84,7 @@ func Setup( func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest) util.JSONResponse { vars := mux.Vars(httpReq) return readers.GetEvent( - httpReq, request, cfg, query, time.Now(), keys, vars["eventID"], + request, cfg, query, time.Now(), keys, vars["eventID"], ) }, )) diff --git a/src/github.com/matrix-org/dendrite/mediaapi/fileutils/fileutils.go b/src/github.com/matrix-org/dendrite/mediaapi/fileutils/fileutils.go index 706afe0d..0c2ba876 100644 --- a/src/github.com/matrix-org/dendrite/mediaapi/fileutils/fileutils.go +++ b/src/github.com/matrix-org/dendrite/mediaapi/fileutils/fileutils.go @@ -150,7 +150,7 @@ func createTempFileWriter(absBasePath config.Path) (*bufio.Writer, *os.File, typ if err != nil { return nil, nil, "", fmt.Errorf("Failed to create temp dir: %q", err) } - writer, tmpFile, err := createFileWriter(tmpDir, "content") + writer, tmpFile, err := createFileWriter(tmpDir) if err != nil { return nil, nil, "", fmt.Errorf("Failed to create file writer: %q", err) } @@ -170,11 +170,11 @@ func createTempDir(baseDirectory config.Path) (types.Path, error) { return types.Path(tmpDir), nil } -// createFileWriter creates a buffered file writer with a new file at directory/filename +// createFileWriter creates a buffered file writer with a new file // The caller should flush the writer before closing the file. // Returns the file handle as it needs to be closed when writing is complete -func createFileWriter(directory types.Path, filename types.Filename) (*bufio.Writer, *os.File, error) { - filePath := filepath.Join(string(directory), string(filename)) +func createFileWriter(directory types.Path) (*bufio.Writer, *os.File, error) { + filePath := filepath.Join(string(directory), "content") file, err := os.Create(filePath) if err != nil { return nil, nil, fmt.Errorf("Failed to create file: %v", err) diff --git a/src/github.com/matrix-org/dendrite/mediaapi/routing/routing.go b/src/github.com/matrix-org/dendrite/mediaapi/routing/routing.go index 94914167..9243c912 100644 --- a/src/github.com/matrix-org/dendrite/mediaapi/routing/routing.go +++ b/src/github.com/matrix-org/dendrite/mediaapi/routing/routing.go @@ -31,7 +31,7 @@ import ( const pathPrefixR0 = "/_matrix/media/v1" // Setup registers the media API HTTP handlers -func Setup(apiMux *mux.Router, httpClient *http.Client, cfg *config.Dendrite, db *storage.Database) { +func Setup(apiMux *mux.Router, cfg *config.Dendrite, db *storage.Database) { r0mux := apiMux.PathPrefix(pathPrefixR0).Subrouter() activeThumbnailGeneration := &types.ActiveThumbnailGeneration{ diff --git a/src/github.com/matrix-org/dendrite/syncapi/storage/output_room_events_table.go b/src/github.com/matrix-org/dendrite/syncapi/storage/output_room_events_table.go index 93774d1f..2472754d 100644 --- a/src/github.com/matrix-org/dendrite/syncapi/storage/output_room_events_table.go +++ b/src/github.com/matrix-org/dendrite/syncapi/storage/output_room_events_table.go @@ -187,7 +187,7 @@ func (s *outputRoomEventsStatements) insertEvent(txn *sql.Tx, event *gomatrixser // RecentEventsInRoom returns the most recent events in the given room, up to a maximum of 'limit'. func (s *outputRoomEventsStatements) selectRecentEvents( - txn *sql.Tx, roomID string, fromPos, toPos types.StreamPosition, limit int, + _ *sql.Tx, roomID string, fromPos, toPos types.StreamPosition, limit int, ) ([]streamEvent, error) { rows, err := s.selectRecentEventsStmt.Query(roomID, fromPos, toPos, limit) if err != nil { diff --git a/src/github.com/matrix-org/dendrite/syncapi/sync/notifier.go b/src/github.com/matrix-org/dendrite/syncapi/sync/notifier.go index 49eed5eb..42007e15 100644 --- a/src/github.com/matrix-org/dendrite/syncapi/sync/notifier.go +++ b/src/github.com/matrix-org/dendrite/syncapi/sync/notifier.go @@ -168,7 +168,7 @@ func (n *Notifier) wakeupUser(userID string, newPos types.StreamPosition) { // function does not wait for data to be available on the stream. func (n *Notifier) fetchUserStream(userID string, makeIfNotExists bool) *UserStream { stream, ok := n.userStreams[userID] - if !ok { + if !ok && makeIfNotExists { // TODO: Unbounded growth of streams (1 per user) stream = NewUserStream(userID) n.userStreams[userID] = stream