Turn on 'unparam' linting (#216)

* Turn on 'unparam' linting

* Increase deadline

* Fix mediaapi integeration test
main
Erik Johnston 2017-09-07 12:50:39 +01:00 committed by GitHub
parent ea80ffb3af
commit fad997303b
19 changed files with 68 additions and 64 deletions

View File

@ -1,6 +1,7 @@
{ {
"Vendor": true, "Vendor": true,
"Cyclo": 12, "Cyclo": 12,
"Deadline": "60s",
"Enable": [ "Enable": [
"vetshadow", "vetshadow",
"gotype", "gotype",
@ -12,6 +13,7 @@
"aligncheck", "aligncheck",
"ineffassign", "ineffassign",
"gas", "gas",
"misspell" "misspell",
"unparam"
] ]
} }

View File

@ -30,7 +30,6 @@ import (
// DirectoryRoom looks up a room alias // DirectoryRoom looks up a room alias
func DirectoryRoom( func DirectoryRoom(
req *http.Request, req *http.Request,
device *authtypes.Device,
roomAlias string, roomAlias string,
federation *gomatrixserverlib.FederationClient, federation *gomatrixserverlib.FederationClient,
cfg *config.Dendrite, cfg *config.Dendrite,
@ -150,7 +149,6 @@ func RemoveLocalAlias(
req *http.Request, req *http.Request,
device *authtypes.Device, device *authtypes.Device,
alias string, alias string,
cfg *config.Dendrite,
aliasAPI api.RoomserverAliasAPI, aliasAPI api.RoomserverAliasAPI,
) util.JSONResponse { ) util.JSONResponse {
queryReq := api.RemoveRoomAliasRequest{ queryReq := api.RemoveRoomAliasRequest{

View File

@ -18,7 +18,6 @@ import (
"net/http" "net/http"
"github.com/matrix-org/dendrite/clientapi/auth/authtypes" "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/httputil"
"github.com/matrix-org/dendrite/clientapi/jsonerror" "github.com/matrix-org/dendrite/clientapi/jsonerror"
"github.com/matrix-org/dendrite/common/config" "github.com/matrix-org/dendrite/common/config"
@ -34,7 +33,7 @@ type response struct {
// GetMemberships implements GET /rooms/{roomId}/members // GetMemberships implements GET /rooms/{roomId}/members
func GetMemberships( func GetMemberships(
req *http.Request, device *authtypes.Device, roomID string, joinedOnly bool, req *http.Request, device *authtypes.Device, roomID string, joinedOnly bool,
accountDB *accounts.Database, cfg config.Dendrite, cfg config.Dendrite,
queryAPI api.RoomserverQueryAPI, queryAPI api.RoomserverQueryAPI,
) util.JSONResponse { ) util.JSONResponse {
queryReq := api.QueryMembershipsForRoomRequest{ queryReq := api.QueryMembershipsForRoomRequest{

View File

@ -146,7 +146,7 @@ func SetAvatarURL(
AvatarURL: r.AvatarURL, AvatarURL: r.AvatarURL,
} }
events, err := buildMembershipEvents(memberships, accountDB, newProfile, userID, cfg, queryAPI) events, err := buildMembershipEvents(memberships, newProfile, userID, cfg, queryAPI)
if err != nil { if err != nil {
return httputil.LogThenError(req, err) return httputil.LogThenError(req, err)
} }
@ -238,7 +238,7 @@ func SetDisplayName(
AvatarURL: oldProfile.AvatarURL, AvatarURL: oldProfile.AvatarURL,
} }
events, err := buildMembershipEvents(memberships, accountDB, newProfile, userID, cfg, queryAPI) events, err := buildMembershipEvents(memberships, newProfile, userID, cfg, queryAPI)
if err != nil { if err != nil {
return httputil.LogThenError(req, err) return httputil.LogThenError(req, err)
} }
@ -258,7 +258,7 @@ func SetDisplayName(
} }
func buildMembershipEvents( func buildMembershipEvents(
memberships []authtypes.Membership, db *accounts.Database, memberships []authtypes.Membership,
newProfile authtypes.Profile, userID string, cfg *config.Dendrite, newProfile authtypes.Profile, userID string, cfg *config.Dendrite,
queryAPI api.RoomserverQueryAPI, queryAPI api.RoomserverQueryAPI,
) ([]gomatrixserverlib.Event, error) { ) ([]gomatrixserverlib.Event, error) {

View File

@ -40,7 +40,7 @@ const pathPrefixUnstable = "/_matrix/client/unstable"
// Setup registers HTTP handlers with the given ServeMux. It also supplies the given http.Client // Setup registers HTTP handlers with the given ServeMux. It also supplies the given http.Client
// to clients which need to make outbound HTTP requests. // to clients which need to make outbound HTTP requests.
func Setup( func Setup(
apiMux *mux.Router, httpClient *http.Client, cfg config.Dendrite, apiMux *mux.Router, cfg config.Dendrite,
producer *producers.RoomserverProducer, queryAPI api.RoomserverQueryAPI, producer *producers.RoomserverProducer, queryAPI api.RoomserverQueryAPI,
aliasAPI api.RoomserverAliasAPI, aliasAPI api.RoomserverAliasAPI,
accountDB *accounts.Database, accountDB *accounts.Database,
@ -121,7 +121,7 @@ func Setup(
r0mux.Handle("/directory/room/{roomAlias}", r0mux.Handle("/directory/room/{roomAlias}",
common.MakeAuthAPI("directory_room", deviceDB, func(req *http.Request, device *authtypes.Device) util.JSONResponse { common.MakeAuthAPI("directory_room", deviceDB, func(req *http.Request, device *authtypes.Device) util.JSONResponse {
vars := mux.Vars(req) 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") ).Methods("GET")
@ -135,7 +135,7 @@ func Setup(
r0mux.Handle("/directory/room/{roomAlias}", r0mux.Handle("/directory/room/{roomAlias}",
common.MakeAuthAPI("directory_room", deviceDB, func(req *http.Request, device *authtypes.Device) util.JSONResponse { common.MakeAuthAPI("directory_room", deviceDB, func(req *http.Request, device *authtypes.Device) util.JSONResponse {
vars := mux.Vars(req) vars := mux.Vars(req)
return readers.RemoveLocalAlias(req, device, vars["roomAlias"], &cfg, aliasAPI) return readers.RemoveLocalAlias(req, device, vars["roomAlias"], aliasAPI)
}), }),
).Methods("DELETE") ).Methods("DELETE")
@ -315,14 +315,14 @@ func Setup(
r0mux.Handle("/rooms/{roomID}/members", r0mux.Handle("/rooms/{roomID}/members",
common.MakeAuthAPI("rooms_members", deviceDB, func(req *http.Request, device *authtypes.Device) util.JSONResponse { common.MakeAuthAPI("rooms_members", deviceDB, func(req *http.Request, device *authtypes.Device) util.JSONResponse {
vars := mux.Vars(req) 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", r0mux.Handle("/rooms/{roomID}/joined_members",
common.MakeAuthAPI("rooms_members", deviceDB, func(req *http.Request, device *authtypes.Device) util.JSONResponse { common.MakeAuthAPI("rooms_members", deviceDB, func(req *http.Request, device *authtypes.Device) util.JSONResponse {
vars := mux.Vars(req) 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)
}), }),
) )

View File

@ -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 { if err != nil {
resErr := httputil.LogThenError(req, err) resErr := httputil.LogThenError(req, err)
return &resErr return &resErr
@ -142,7 +142,7 @@ func CheckAndProcessInvite(
// Returns a representation of the response for both cases. // Returns a representation of the response for both cases.
// Returns an error if a check or a request failed. // Returns an error if a check or a request failed.
func queryIDServer( func queryIDServer(
req *http.Request, db *accounts.Database, cfg config.Dendrite, db *accounts.Database, cfg config.Dendrite,
device *authtypes.Device, body *MembershipRequest, roomID string, device *authtypes.Device, body *MembershipRequest, roomID string,
) (lookupRes *idServerLookupResponse, storeInviteRes *idServerStoreInviteResponse, err error) { ) (lookupRes *idServerLookupResponse, storeInviteRes *idServerStoreInviteResponse, err error) {
// Lookup the 3PID // Lookup the 3PID
@ -165,7 +165,7 @@ func queryIDServer(
if lookupRes.NotBefore > now || now > lookupRes.NotAfter { if lookupRes.NotBefore > now || now > lookupRes.NotAfter {
// If the current timestamp isn't in the time frame in which the association // If the current timestamp isn't in the time frame in which the association
// is known to be valid, re-run the query // 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 // Check the request signatures and send an error if one isn't valid

View File

@ -3,6 +3,7 @@ package writers
import ( import (
"fmt" "fmt"
"net/http" "net/http"
"time"
log "github.com/Sirupsen/logrus" log "github.com/Sirupsen/logrus"
"github.com/matrix-org/dendrite/clientapi/auth" "github.com/matrix-org/dendrite/clientapi/auth"
@ -120,7 +121,7 @@ func Register(req *http.Request, accountDB *accounts.Database, deviceDB *devices
Code: 401, Code: 401,
// TODO: Hard-coded 'dummy' auth for now with a bogus session ID. // TODO: Hard-coded 'dummy' auth for now with a bogus session ID.
// Server admins should be able to change things around (eg enable captcha) // 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}}, {[]authtypes.LoginType{authtypes.LoginTypeDummy}},
}), }),
} }

View File

@ -40,7 +40,7 @@ type sendEventResponse struct {
func SendEvent( func SendEvent(
req *http.Request, req *http.Request,
device *authtypes.Device, device *authtypes.Device,
roomID, eventType, txnID string, stateKey *string, roomID, eventType, _ string, stateKey *string,
cfg config.Dendrite, cfg config.Dendrite,
queryAPI api.RoomserverQueryAPI, queryAPI api.RoomserverQueryAPI,
producer *producers.RoomserverProducer, producer *producers.RoomserverProducer,

View File

@ -117,7 +117,7 @@ func main() {
api := mux.NewRouter() api := mux.NewRouter()
routing.Setup( routing.Setup(
api, http.DefaultClient, *cfg, roomserverProducer, api, *cfg, roomserverProducer,
queryAPI, aliasAPI, accountDB, deviceDB, federation, keyRing, queryAPI, aliasAPI, accountDB, deviceDB, federation, keyRing,
userUpdateProducer, syncProducer, userUpdateProducer, syncProducer,
) )

View File

@ -54,7 +54,7 @@ func main() {
log.Info("Starting media API server on ", cfg.Listen.MediaAPI) log.Info("Starting media API server on ", cfg.Listen.MediaAPI)
api := mux.NewRouter() api := mux.NewRouter()
routing.Setup(api, http.DefaultClient, cfg, db) routing.Setup(api, cfg, db)
common.SetupHTTPAPI(http.DefaultServeMux, api) common.SetupHTTPAPI(http.DefaultServeMux, api)
log.Fatal(http.ListenAndServe(string(cfg.Listen.MediaAPI), nil)) log.Fatal(http.ListenAndServe(string(cfg.Listen.MediaAPI), nil))

View File

@ -318,13 +318,13 @@ func (m *monolith) setupConsumers() {
func (m *monolith) setupAPIs() { func (m *monolith) setupAPIs() {
clientapi_routing.Setup( 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.queryAPI, m.aliasAPI, m.accountDB, m.deviceDB, m.federation, m.keyRing,
m.userUpdateProducer, m.syncProducer, m.userUpdateProducer, m.syncProducer,
) )
mediaapi_routing.Setup( 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( syncapi_routing.Setup(m.api, syncapi_sync.NewRequestPool(

View File

@ -65,6 +65,10 @@ var thumbnailSizes = (`
const serverType = "media-api" 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 testDatabaseTemplate = "dbname=%s sslmode=disable binary_parameters=yes"
var timeout time.Duration var timeout time.Duration
@ -81,10 +85,11 @@ func startMediaAPI(suffix string, dynamicThumbnails bool) (*exec.Cmd, chan error
database := fmt.Sprintf(testDatabaseTemplate, testDatabaseName+suffix) database := fmt.Sprintf(testDatabaseTemplate, testDatabaseName+suffix)
cfg, nextPort, err := test.MakeConfig(dir, kafkaURI, database, "localhost", port) cfg, nextPort, err := test.MakeConfig(dir, kafkaURI, database, "localhost", port)
cfg.Matrix.ServerName = gomatrixserverlib.ServerName(proxyAddr)
if err != nil { if err != nil {
panic(err) panic(err)
} }
cfg.Matrix.ServerName = gomatrixserverlib.ServerName(proxyAddr)
cfg.Media.DynamicThumbnails = dynamicThumbnails
if err = yaml.Unmarshal([]byte(thumbnailSizes), &cfg.Media.ThumbnailSizes); err != nil { if err = yaml.Unmarshal([]byte(thumbnailSizes), &cfg.Media.ThumbnailSizes); err != nil {
panic(err) panic(err)
} }
@ -142,46 +147,46 @@ func main() {
server1Cmd, server1CmdChan, _, server1ProxyCmd, _, server1ProxyAddr, server1Dir := startMediaAPI("1", false) server1Cmd, server1CmdChan, _, server1ProxyCmd, _, server1ProxyAddr, server1Dir := startMediaAPI("1", false)
defer cleanUpServer(server1Cmd, server1Dir) defer cleanUpServer(server1Cmd, server1Dir)
defer server1ProxyCmd.Process.Kill() defer server1ProxyCmd.Process.Kill()
testDownload(server1ProxyAddr, server1ProxyAddr, "doesnotexist", "", 404, server1CmdChan) testDownload(server1ProxyAddr, server1ProxyAddr, "doesnotexist", 404, server1CmdChan)
// upload a JPEG file // upload a JPEG file
testUpload(server1ProxyAddr, testJPEG, "image/jpeg", `{ testUpload(
"content_uri": "mxc://localhost:18001/1VuVy8u_hmDllD8BrcY0deM34Bl7SPJeY9J6BkMmpx0" server1ProxyAddr, testJPEG,
}`, 200, server1CmdChan) )
// download that JPEG file // download that JPEG file
testDownload(server1ProxyAddr, "localhost:18001", "1VuVy8u_hmDllD8BrcY0deM34Bl7SPJeY9J6BkMmpx0", "", 200, server1CmdChan) testDownload(server1ProxyAddr, testOrigin, testMediaID, 200, server1CmdChan)
// thumbnail that JPEG file // 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 // create server2 with dynamic thumbnail generation
server2Cmd, server2CmdChan, _, server2ProxyCmd, _, server2ProxyAddr, server2Dir := startMediaAPI("2", true) server2Cmd, server2CmdChan, _, server2ProxyCmd, _, server2ProxyAddr, server2Dir := startMediaAPI("2", true)
defer cleanUpServer(server2Cmd, server2Dir) defer cleanUpServer(server2Cmd, server2Dir)
defer server2ProxyCmd.Process.Kill() defer server2ProxyCmd.Process.Kill()
testDownload(server2ProxyAddr, server2ProxyAddr, "doesnotexist", "", 404, server2CmdChan) testDownload(server2ProxyAddr, server2ProxyAddr, "doesnotexist", 404, server2CmdChan)
// pre-generated thumbnail that JPEG file via server2 // 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 // 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 // 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 // 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 := []string{host, "_matrix/media/v1", endpoint}
pathComponents = append(pathComponents, components...) 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) fmt.Printf("==TESTING== upload %v to %v\n", filePath, host)
file, err := os.Open(filePath) file, err := os.Open(filePath)
defer file.Close() defer file.Close()
@ -197,18 +202,19 @@ func testUpload(host, filePath, contentType, wantedBody string, wantedStatusCode
req, err := http.NewRequest( req, err := http.NewRequest(
"POST", "POST",
getMediaURI("https://", host, "upload", "?filename="+filename, nil), getMediaURI(host, "upload", "?filename="+filename, nil),
file, file,
) )
if err != nil { if err != nil {
panic(err) panic(err)
} }
req.ContentLength = fileSize 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{ testReq := &test.Request{
Req: req, Req: req,
WantedStatusCode: wantedStatusCode, WantedStatusCode: 200,
WantedBody: test.CanonicalJSONInput([]string{wantedBody})[0], WantedBody: test.CanonicalJSONInput([]string{wantedBody})[0],
} }
if err := testReq.Do(); err != nil { 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) 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( req, err := http.NewRequest(
"GET", "GET",
getMediaURI("https://", host, "download", "", []string{ getMediaURI(host, "download", "", []string{
origin, origin,
mediaID, mediaID,
}), }),
@ -232,21 +238,21 @@ func testDownload(host, origin, mediaID, wantedBody string, wantedStatusCode int
testReq := &test.Request{ testReq := &test.Request{
Req: req, Req: req,
WantedStatusCode: wantedStatusCode, 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) 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) query := fmt.Sprintf("?width=%v&height=%v", width, height)
if resizeMethod != "" { if resizeMethod != "" {
query += "&method=" + resizeMethod query += "&method=" + resizeMethod
} }
req, err := http.NewRequest( req, err := http.NewRequest(
"GET", "GET",
getMediaURI("https://", host, "thumbnail", query, []string{ getMediaURI(host, "thumbnail", query, []string{
origin, testOrigin,
mediaID, testMediaID,
}), }),
nil, nil,
) )
@ -255,8 +261,8 @@ func testThumbnail(width, height int, resizeMethod, host, origin, mediaID, wante
} }
testReq := &test.Request{ testReq := &test.Request{
Req: req, Req: req,
WantedStatusCode: wantedStatusCode, WantedStatusCode: 200,
WantedBody: test.CanonicalJSONInput([]string{wantedBody})[0], 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)
} }

View File

@ -15,7 +15,6 @@
package readers package readers
import ( import (
"net/http"
"time" "time"
"github.com/matrix-org/dendrite/common/config" "github.com/matrix-org/dendrite/common/config"
@ -26,7 +25,6 @@ import (
// GetEvent returns the requested event // GetEvent returns the requested event
func GetEvent( func GetEvent(
httpReq *http.Request,
request *gomatrixserverlib.FederationRequest, request *gomatrixserverlib.FederationRequest,
cfg config.Dendrite, cfg config.Dendrite,
query api.RoomserverQueryAPI, query api.RoomserverQueryAPI,

View File

@ -16,17 +16,17 @@ package readers
import ( import (
"encoding/json" "encoding/json"
"time"
"github.com/matrix-org/dendrite/common/config" "github.com/matrix-org/dendrite/common/config"
"github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/util" "github.com/matrix-org/util"
"golang.org/x/crypto/ed25519" "golang.org/x/crypto/ed25519"
"net/http"
"time"
) )
// LocalKeys returns the local keys for the server. // LocalKeys returns the local keys for the server.
// See https://matrix.org/docs/spec/server_server/unstable.html#publishing-keys // 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)) keys, err := localKeys(cfg, time.Now().Add(cfg.Matrix.KeyValidityPeriod))
if err != nil { if err != nil {
return util.ErrorResponse(err) return util.ErrorResponse(err)

View File

@ -47,7 +47,7 @@ func Setup(
v1fedmux := apiMux.PathPrefix(pathPrefixV1Federation).Subrouter() v1fedmux := apiMux.PathPrefix(pathPrefixV1Federation).Subrouter()
localKeys := common.MakeAPI("localkeys", func(req *http.Request) util.JSONResponse { 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 // 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 { func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest) util.JSONResponse {
vars := mux.Vars(httpReq) vars := mux.Vars(httpReq)
return readers.GetEvent( return readers.GetEvent(
httpReq, request, cfg, query, time.Now(), keys, vars["eventID"], request, cfg, query, time.Now(), keys, vars["eventID"],
) )
}, },
)) ))

View File

@ -150,7 +150,7 @@ func createTempFileWriter(absBasePath config.Path) (*bufio.Writer, *os.File, typ
if err != nil { if err != nil {
return nil, nil, "", fmt.Errorf("Failed to create temp dir: %q", err) 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 { if err != nil {
return nil, nil, "", fmt.Errorf("Failed to create file writer: %q", err) 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 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. // The caller should flush the writer before closing the file.
// Returns the file handle as it needs to be closed when writing is complete // 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) { func createFileWriter(directory types.Path) (*bufio.Writer, *os.File, error) {
filePath := filepath.Join(string(directory), string(filename)) filePath := filepath.Join(string(directory), "content")
file, err := os.Create(filePath) file, err := os.Create(filePath)
if err != nil { if err != nil {
return nil, nil, fmt.Errorf("Failed to create file: %v", err) return nil, nil, fmt.Errorf("Failed to create file: %v", err)

View File

@ -31,7 +31,7 @@ import (
const pathPrefixR0 = "/_matrix/media/v1" const pathPrefixR0 = "/_matrix/media/v1"
// Setup registers the media API HTTP handlers // 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() r0mux := apiMux.PathPrefix(pathPrefixR0).Subrouter()
activeThumbnailGeneration := &types.ActiveThumbnailGeneration{ activeThumbnailGeneration := &types.ActiveThumbnailGeneration{

View File

@ -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'. // RecentEventsInRoom returns the most recent events in the given room, up to a maximum of 'limit'.
func (s *outputRoomEventsStatements) selectRecentEvents( 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) { ) ([]streamEvent, error) {
rows, err := s.selectRecentEventsStmt.Query(roomID, fromPos, toPos, limit) rows, err := s.selectRecentEventsStmt.Query(roomID, fromPos, toPos, limit)
if err != nil { if err != nil {

View File

@ -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. // function does not wait for data to be available on the stream.
func (n *Notifier) fetchUserStream(userID string, makeIfNotExists bool) *UserStream { func (n *Notifier) fetchUserStream(userID string, makeIfNotExists bool) *UserStream {
stream, ok := n.userStreams[userID] stream, ok := n.userStreams[userID]
if !ok { if !ok && makeIfNotExists {
// TODO: Unbounded growth of streams (1 per user) // TODO: Unbounded growth of streams (1 per user)
stream = NewUserStream(userID) stream = NewUserStream(userID)
n.userStreams[userID] = stream n.userStreams[userID] = stream