From 25cd2dd1c925fa0c1eeb27a3cd71e668344102ad Mon Sep 17 00:00:00 2001 From: Kegsay Date: Thu, 11 Jun 2020 15:07:16 +0100 Subject: [PATCH] Remove unused internal APIs (#1117) --- federationapi/routing/send_test.go | 9 -------- federationapi/routing/state.go | 13 +----------- federationsender/api/api.go | 22 ++----------------- federationsender/internal/query.go | 10 --------- federationsender/inthttp/client.go | 14 ------------ federationsender/inthttp/server.go | 14 ------------ roomserver/api/api.go | 7 ------ roomserver/api/query.go | 17 --------------- roomserver/internal/query.go | 34 ------------------------------ roomserver/inthttp/client.go | 14 ------------ roomserver/inthttp/server.go | 14 ------------ 11 files changed, 3 insertions(+), 165 deletions(-) diff --git a/federationapi/routing/send_test.go b/federationapi/routing/send_test.go index b81f1c00..9081a870 100644 --- a/federationapi/routing/send_test.go +++ b/federationapi/routing/send_test.go @@ -181,15 +181,6 @@ func (t *testRoomserverAPI) QueryMembershipsForRoom( return fmt.Errorf("not implemented") } -// Query a list of invite event senders for a user in a room. -func (t *testRoomserverAPI) QueryInvitesForUser( - ctx context.Context, - request *api.QueryInvitesForUserRequest, - response *api.QueryInvitesForUserResponse, -) error { - return fmt.Errorf("not implemented") -} - // Query whether a server is allowed to see an event func (t *testRoomserverAPI) QueryServerAllowedToSeeEvent( ctx context.Context, diff --git a/federationapi/routing/state.go b/federationapi/routing/state.go index f90c494c..04a18904 100644 --- a/federationapi/routing/state.go +++ b/federationapi/routing/state.go @@ -107,15 +107,13 @@ func getState( return nil, &util.JSONResponse{Code: http.StatusNotFound, JSON: nil} } - authEventIDs := getIDsFromEventRef(event.AuthEvents()) - var response api.QueryStateAndAuthChainResponse err := rsAPI.QueryStateAndAuthChain( ctx, &api.QueryStateAndAuthChainRequest{ RoomID: roomID, PrevEventIDs: []string{eventID}, - AuthEventIDs: authEventIDs, + AuthEventIDs: event.AuthEventIDs(), }, &response, ) @@ -134,15 +132,6 @@ func getState( }, nil } -func getIDsFromEventRef(events []gomatrixserverlib.EventReference) []string { - IDs := make([]string, len(events)) - for i := range events { - IDs[i] = events[i].EventID - } - - return IDs -} - func getIDsFromEvent(events []gomatrixserverlib.Event) []string { IDs := make([]string, len(events)) for i := range events { diff --git a/federationsender/api/api.go b/federationsender/api/api.go index d8251b54..02c76258 100644 --- a/federationsender/api/api.go +++ b/federationsender/api/api.go @@ -15,14 +15,6 @@ type FederationSenderInternalAPI interface { request *PerformDirectoryLookupRequest, response *PerformDirectoryLookupResponse, ) error - // Query the joined hosts and the membership events accounting for their participation in a room. - // Note that if a server has multiple users in the room, it will have multiple entries in the returned slice. - // See `QueryJoinedHostServerNamesInRoom` for a de-duplicated version. - QueryJoinedHostsInRoom( - ctx context.Context, - request *QueryJoinedHostsInRoomRequest, - response *QueryJoinedHostsInRoomResponse, - ) error // Query the server names of the joined hosts in a room. // Unlike QueryJoinedHostsInRoom, this function returns a de-duplicated slice // containing only the server names (without information for membership events). @@ -88,22 +80,12 @@ type PerformServersAliveRequest struct { type PerformServersAliveResponse struct { } -// QueryJoinedHostsInRoomRequest is a request to QueryJoinedHostsInRoom -type QueryJoinedHostsInRoomRequest struct { - RoomID string `json:"room_id"` -} - -// QueryJoinedHostsInRoomResponse is a response to QueryJoinedHostsInRoom -type QueryJoinedHostsInRoomResponse struct { - JoinedHosts []types.JoinedHost `json:"joined_hosts"` -} - -// QueryJoinedHostServerNamesRequest is a request to QueryJoinedHostServerNames +// QueryJoinedHostServerNamesInRoomRequest is a request to QueryJoinedHostServerNames type QueryJoinedHostServerNamesInRoomRequest struct { RoomID string `json:"room_id"` } -// QueryJoinedHostServerNamesResponse is a response to QueryJoinedHostServerNames +// QueryJoinedHostServerNamesInRoomResponse is a response to QueryJoinedHostServerNames type QueryJoinedHostServerNamesInRoomResponse struct { ServerNames []gomatrixserverlib.ServerName `json:"server_names"` } diff --git a/federationsender/internal/query.go b/federationsender/internal/query.go index 88dd50a6..253400a2 100644 --- a/federationsender/internal/query.go +++ b/federationsender/internal/query.go @@ -7,16 +7,6 @@ import ( "github.com/matrix-org/gomatrixserverlib" ) -// QueryJoinedHostsInRoom implements api.FederationSenderInternalAPI -func (f *FederationSenderInternalAPI) QueryJoinedHostsInRoom( - ctx context.Context, - request *api.QueryJoinedHostsInRoomRequest, - response *api.QueryJoinedHostsInRoomResponse, -) (err error) { - response.JoinedHosts, err = f.db.GetJoinedHosts(ctx, request.RoomID) - return -} - // QueryJoinedHostServerNamesInRoom implements api.FederationSenderInternalAPI func (f *FederationSenderInternalAPI) QueryJoinedHostServerNamesInRoom( ctx context.Context, diff --git a/federationsender/inthttp/client.go b/federationsender/inthttp/client.go index 8b3a106d..1e243c60 100644 --- a/federationsender/inthttp/client.go +++ b/federationsender/inthttp/client.go @@ -12,7 +12,6 @@ import ( // HTTP paths for the internal HTTP API const ( - FederationSenderQueryJoinedHostsInRoomPath = "/federationsender/queryJoinedHostsInRoom" FederationSenderQueryJoinedHostServerNamesInRoomPath = "/federationsender/queryJoinedHostServerNamesInRoom" FederationSenderPerformDirectoryLookupRequestPath = "/federationsender/performDirectoryLookup" @@ -73,19 +72,6 @@ func (h *httpFederationSenderInternalAPI) QueryJoinedHostServerNamesInRoom( return internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response) } -// QueryJoinedHostsInRoom implements FederationSenderInternalAPI -func (h *httpFederationSenderInternalAPI) QueryJoinedHostsInRoom( - ctx context.Context, - request *api.QueryJoinedHostsInRoomRequest, - response *api.QueryJoinedHostsInRoomResponse, -) error { - span, ctx := opentracing.StartSpanFromContext(ctx, "QueryJoinedHostsInRoom") - defer span.Finish() - - apiURL := h.federationSenderURL + FederationSenderQueryJoinedHostsInRoomPath - return internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response) -} - // Handle an instruction to make_join & send_join with a remote server. func (h *httpFederationSenderInternalAPI) PerformJoin( ctx context.Context, diff --git a/federationsender/inthttp/server.go b/federationsender/inthttp/server.go index c94a1429..a9076661 100644 --- a/federationsender/inthttp/server.go +++ b/federationsender/inthttp/server.go @@ -12,20 +12,6 @@ import ( // AddRoutes adds the FederationSenderInternalAPI handlers to the http.ServeMux. func AddRoutes(intAPI api.FederationSenderInternalAPI, internalAPIMux *mux.Router) { - internalAPIMux.Handle( - FederationSenderQueryJoinedHostsInRoomPath, - internal.MakeInternalAPI("QueryJoinedHostsInRoom", func(req *http.Request) util.JSONResponse { - var request api.QueryJoinedHostsInRoomRequest - var response api.QueryJoinedHostsInRoomResponse - if err := json.NewDecoder(req.Body).Decode(&request); err != nil { - return util.ErrorResponse(err) - } - if err := intAPI.QueryJoinedHostsInRoom(req.Context(), &request, &response); err != nil { - return util.ErrorResponse(err) - } - return util.JSONResponse{Code: http.StatusOK, JSON: &response} - }), - ) internalAPIMux.Handle( FederationSenderQueryJoinedHostServerNamesInRoomPath, internal.MakeInternalAPI("QueryJoinedHostServerNamesInRoom", func(req *http.Request) util.JSONResponse { diff --git a/roomserver/api/api.go b/roomserver/api/api.go index aefe55bc..3a2ad059 100644 --- a/roomserver/api/api.go +++ b/roomserver/api/api.go @@ -65,13 +65,6 @@ type RoomserverInternalAPI interface { response *QueryMembershipsForRoomResponse, ) error - // Query a list of invite event senders for a user in a room. - QueryInvitesForUser( - ctx context.Context, - request *QueryInvitesForUserRequest, - response *QueryInvitesForUserResponse, - ) error - // Query whether a server is allowed to see an event QueryServerAllowedToSeeEvent( ctx context.Context, diff --git a/roomserver/api/query.go b/roomserver/api/query.go index dc005c77..c9a46ae9 100644 --- a/roomserver/api/query.go +++ b/roomserver/api/query.go @@ -140,23 +140,6 @@ type QueryMembershipsForRoomResponse struct { HasBeenInRoom bool `json:"has_been_in_room"` } -// QueryInvitesForUserRequest is a request to QueryInvitesForUser -type QueryInvitesForUserRequest struct { - // The room ID to look up invites in. - RoomID string `json:"room_id"` - // The User ID to look up invites for. - TargetUserID string `json:"target_user_id"` -} - -// QueryInvitesForUserResponse is a response to QueryInvitesForUser -// This is used when accepting an invite or rejecting a invite to tell which -// remote matrix servers to contact. -type QueryInvitesForUserResponse struct { - // A list of matrix user IDs for each sender of an active invite targeting - // the requested user ID. - InviteSenderUserIDs []string `json:"invite_sender_user_ids"` -} - // QueryServerAllowedToSeeEventRequest is a request to QueryServerAllowedToSeeEvent type QueryServerAllowedToSeeEventRequest struct { // The event ID to look up invites in. diff --git a/roomserver/internal/query.go b/roomserver/internal/query.go index 9fb67e7e..aea93388 100644 --- a/roomserver/internal/query.go +++ b/roomserver/internal/query.go @@ -353,40 +353,6 @@ func getMembershipsAtState( return events, nil } -// QueryInvitesForUser implements api.RoomserverInternalAPI -func (r *RoomserverInternalAPI) QueryInvitesForUser( - ctx context.Context, - request *api.QueryInvitesForUserRequest, - response *api.QueryInvitesForUserResponse, -) error { - roomNID, err := r.DB.RoomNID(ctx, request.RoomID) - if err != nil { - return err - } - - targetUserNIDs, err := r.DB.EventStateKeyNIDs(ctx, []string{request.TargetUserID}) - if err != nil { - return err - } - targetUserNID := targetUserNIDs[request.TargetUserID] - - senderUserNIDs, err := r.DB.GetInvitesForUser(ctx, roomNID, targetUserNID) - if err != nil { - return err - } - - senderUserIDs, err := r.DB.EventStateKeys(ctx, senderUserNIDs) - if err != nil { - return err - } - - for _, senderUserID := range senderUserIDs { - response.InviteSenderUserIDs = append(response.InviteSenderUserIDs, senderUserID) - } - - return nil -} - // QueryServerAllowedToSeeEvent implements api.RoomserverInternalAPI func (r *RoomserverInternalAPI) QueryServerAllowedToSeeEvent( ctx context.Context, diff --git a/roomserver/inthttp/client.go b/roomserver/inthttp/client.go index 5cc2537e..6f5e882e 100644 --- a/roomserver/inthttp/client.go +++ b/roomserver/inthttp/client.go @@ -33,7 +33,6 @@ const ( RoomserverQueryEventsByIDPath = "/roomserver/queryEventsByID" RoomserverQueryMembershipForUserPath = "/roomserver/queryMembershipForUser" RoomserverQueryMembershipsForRoomPath = "/roomserver/queryMembershipsForRoom" - RoomserverQueryInvitesForUserPath = "/roomserver/queryInvitesForUser" RoomserverQueryServerAllowedToSeeEventPath = "/roomserver/queryServerAllowedToSeeEvent" RoomserverQueryMissingEventsPath = "/roomserver/queryMissingEvents" RoomserverQueryStateAndAuthChainPath = "/roomserver/queryStateAndAuthChain" @@ -236,19 +235,6 @@ func (h *httpRoomserverInternalAPI) QueryMembershipsForRoom( return internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response) } -// QueryInvitesForUser implements RoomserverQueryAPI -func (h *httpRoomserverInternalAPI) QueryInvitesForUser( - ctx context.Context, - request *api.QueryInvitesForUserRequest, - response *api.QueryInvitesForUserResponse, -) error { - span, ctx := opentracing.StartSpanFromContext(ctx, "QueryInvitesForUser") - defer span.Finish() - - apiURL := h.roomserverURL + RoomserverQueryInvitesForUserPath - return internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response) -} - // QueryServerAllowedToSeeEvent implements RoomserverQueryAPI func (h *httpRoomserverInternalAPI) QueryServerAllowedToSeeEvent( ctx context.Context, diff --git a/roomserver/inthttp/server.go b/roomserver/inthttp/server.go index 9a58a30b..3a13ce37 100644 --- a/roomserver/inthttp/server.go +++ b/roomserver/inthttp/server.go @@ -122,20 +122,6 @@ func AddRoutes(r api.RoomserverInternalAPI, internalAPIMux *mux.Router) { return util.JSONResponse{Code: http.StatusOK, JSON: &response} }), ) - internalAPIMux.Handle( - RoomserverQueryInvitesForUserPath, - internal.MakeInternalAPI("queryInvitesForUser", func(req *http.Request) util.JSONResponse { - var request api.QueryInvitesForUserRequest - var response api.QueryInvitesForUserResponse - if err := json.NewDecoder(req.Body).Decode(&request); err != nil { - return util.ErrorResponse(err) - } - if err := r.QueryInvitesForUser(req.Context(), &request, &response); err != nil { - return util.ErrorResponse(err) - } - return util.JSONResponse{Code: http.StatusOK, JSON: &response} - }), - ) internalAPIMux.Handle( RoomserverQueryServerAllowedToSeeEventPath, internal.MakeInternalAPI("queryServerAllowedToSeeEvent", func(req *http.Request) util.JSONResponse {