Skip to content
This repository has been archived by the owner on Nov 25, 2024. It is now read-only.

Commit

Permalink
Fix #1655 by re-adding the appservice alias query (#1660)
Browse files Browse the repository at this point in the history
  • Loading branch information
neilalexander authored Dec 18, 2020
1 parent 65ff5c9 commit fac71ed
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 11 deletions.
4 changes: 2 additions & 2 deletions appservice/api/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ package api
import (
"context"
"database/sql"
"errors"

"github.com/matrix-org/dendrite/clientapi/auth/authtypes"
"github.com/matrix-org/dendrite/internal/eventutil"
"github.com/matrix-org/dendrite/userapi/storage/accounts"
"github.com/matrix-org/gomatrixserverlib"
)
Expand Down Expand Up @@ -109,7 +109,7 @@ func RetrieveUserProfile(

// If no user exists, return
if !userResp.UserIDExists {
return nil, eventutil.ErrProfileNoExists
return nil, errors.New("no known profile for given user ID")
}

// Try to query the user from the local database again
Expand Down
1 change: 1 addition & 0 deletions build/gobind/monolith.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ func (m *DendriteMonolith) Start() {
)

asAPI := appservice.NewInternalAPI(base, userAPI, rsAPI)
rsAPI.SetAppserviceAPI(asAPI)

ygg.SetSessionFunc(func(address string) {
req := &api.PerformServersAliveRequest{
Expand Down
1 change: 1 addition & 0 deletions cmd/dendrite-demo-libp2p/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ func main() {
&base.Base, cache.New(), userAPI,
)
asAPI := appservice.NewInternalAPI(&base.Base, userAPI, rsAPI)
rsAPI.SetAppserviceAPI(asAPI)
fsAPI := federationsender.NewInternalAPI(
&base.Base, federation, rsAPI, keyRing,
)
Expand Down
1 change: 1 addition & 0 deletions cmd/dendrite-demo-yggdrasil/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ func main() {
)

asAPI := appservice.NewInternalAPI(base, userAPI, rsAPI)
rsAPI.SetAppserviceAPI(asAPI)
fsAPI := federationsender.NewInternalAPI(
base, federation, rsAPI, keyRing,
)
Expand Down
1 change: 1 addition & 0 deletions cmd/dendrite-monolith-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ func main() {
appservice.AddInternalRoutes(base.InternalAPIMux, asAPI)
asAPI = base.AppserviceHTTPClient()
}
rsAPI.SetAppserviceAPI(asAPI)

monolith := setup.Monolith{
Config: base.Cfg,
Expand Down
2 changes: 2 additions & 0 deletions cmd/dendrite-polylith-multi/personalities/roomserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ func RoomServer(base *setup.BaseDendrite, cfg *config.Dendrite) {
serverKeyAPI := base.SigningKeyServerHTTPClient()
keyRing := serverKeyAPI.KeyRing()

asAPI := base.AppserviceHTTPClient()
fsAPI := base.FederationSenderHTTPClient()
rsAPI := roomserver.NewInternalAPI(base, keyRing)
rsAPI.SetFederationSenderAPI(fsAPI)
rsAPI.SetAppserviceAPI(asAPI)
roomserver.AddInternalRoutes(base.InternalAPIMux, rsAPI)

base.SetupAndServeHTTP(
Expand Down
1 change: 1 addition & 0 deletions cmd/dendritejs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ func main() {
asQuery := appservice.NewInternalAPI(
base, userAPI, rsAPI,
)
rsAPI.SetAppserviceAPI(asQuery)
fedSenderAPI := federationsender.NewInternalAPI(base, federation, rsAPI, &keyRing)
rsAPI.SetFederationSenderAPI(fedSenderAPI)
p2pPublicRoomProvider := NewLibP2PPublicRoomsProvider(node, fedSenderAPI, federation)
Expand Down
2 changes: 2 additions & 0 deletions roomserver/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package api
import (
"context"

asAPI "github.com/matrix-org/dendrite/appservice/api"
fsAPI "github.com/matrix-org/dendrite/federationsender/api"
)

Expand All @@ -11,6 +12,7 @@ type RoomserverInternalAPI interface {
// needed to avoid chicken and egg scenario when setting up the
// interdependencies between the roomserver and other input APIs
SetFederationSenderAPI(fsAPI fsAPI.FederationSenderInternalAPI)
SetAppserviceAPI(asAPI asAPI.AppServiceQueryAPI)

InputRoomEvents(
ctx context.Context,
Expand Down
5 changes: 5 additions & 0 deletions roomserver/api/api_trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"

asAPI "github.com/matrix-org/dendrite/appservice/api"
fsAPI "github.com/matrix-org/dendrite/federationsender/api"
"github.com/matrix-org/util"
)
Expand All @@ -19,6 +20,10 @@ func (t *RoomserverInternalAPITrace) SetFederationSenderAPI(fsAPI fsAPI.Federati
t.Impl.SetFederationSenderAPI(fsAPI)
}

func (t *RoomserverInternalAPITrace) SetAppserviceAPI(asAPI asAPI.AppServiceQueryAPI) {
t.Impl.SetAppserviceAPI(asAPI)
}

func (t *RoomserverInternalAPITrace) InputRoomEvents(
ctx context.Context,
req *InputRoomEventsRequest,
Expand Down
16 changes: 7 additions & 9 deletions roomserver/internal/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (

"github.com/matrix-org/dendrite/roomserver/api"
"github.com/matrix-org/gomatrixserverlib"

asAPI "github.com/matrix-org/dendrite/appservice/api"
)

// RoomserverInternalAPIDatabase has the storage APIs needed to implement the alias API.
Expand Down Expand Up @@ -90,17 +92,13 @@ func (r *RoomserverInternalAPI) GetRoomIDForAlias(
return err
}

/*
TODO: Why is this here? It creates an unnecessary dependency
from the roomserver to the appservice component, which should be
altogether optional.
if r.asAPI != nil { // appservice component is wired in
if roomID == "" {
// No room found locally, try our application services by making a call to
// the appservice component
aliasReq := appserviceAPI.RoomAliasExistsRequest{Alias: request.Alias}
var aliasResp appserviceAPI.RoomAliasExistsResponse
if err = r.AppserviceAPI.RoomAliasExists(ctx, &aliasReq, &aliasResp); err != nil {
aliasReq := asAPI.RoomAliasExistsRequest{Alias: request.Alias}
var aliasResp asAPI.RoomAliasExistsResponse
if err = r.asAPI.RoomAliasExists(ctx, &aliasReq, &aliasResp); err != nil {
return err
}

Expand All @@ -111,7 +109,7 @@ func (r *RoomserverInternalAPI) GetRoomIDForAlias(
}
}
}
*/
}

response.RoomID = roomID
return nil
Expand Down
6 changes: 6 additions & 0 deletions roomserver/internal/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"

"github.com/Shopify/sarama"
asAPI "github.com/matrix-org/dendrite/appservice/api"
fsAPI "github.com/matrix-org/dendrite/federationsender/api"
"github.com/matrix-org/dendrite/internal/caching"
"github.com/matrix-org/dendrite/roomserver/acls"
Expand Down Expand Up @@ -35,6 +36,7 @@ type RoomserverInternalAPI struct {
ServerName gomatrixserverlib.ServerName
KeyRing gomatrixserverlib.JSONVerifier
fsAPI fsAPI.FederationSenderInternalAPI
asAPI asAPI.AppServiceQueryAPI
OutputRoomEventTopic string // Kafka topic for new output room events
PerspectiveServerNames []gomatrixserverlib.ServerName
}
Expand Down Expand Up @@ -126,6 +128,10 @@ func (r *RoomserverInternalAPI) SetFederationSenderAPI(fsAPI fsAPI.FederationSen
}
}

func (r *RoomserverInternalAPI) SetAppserviceAPI(asAPI asAPI.AppServiceQueryAPI) {
r.asAPI = asAPI
}

func (r *RoomserverInternalAPI) PerformInvite(
ctx context.Context,
req *api.PerformInviteRequest,
Expand Down
5 changes: 5 additions & 0 deletions roomserver/inthttp/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"net/http"

asAPI "github.com/matrix-org/dendrite/appservice/api"
fsInputAPI "github.com/matrix-org/dendrite/federationsender/api"
"github.com/matrix-org/dendrite/internal/caching"
"github.com/matrix-org/dendrite/internal/httputil"
Expand Down Expand Up @@ -84,6 +85,10 @@ func NewRoomserverClient(
func (h *httpRoomserverInternalAPI) SetFederationSenderAPI(fsAPI fsInputAPI.FederationSenderInternalAPI) {
}

// SetAppserviceAPI no-ops in HTTP client mode as there is no chicken/egg scenario
func (h *httpRoomserverInternalAPI) SetAppserviceAPI(asAPI asAPI.AppServiceQueryAPI) {
}

// SetRoomAlias implements RoomserverAliasAPI
func (h *httpRoomserverInternalAPI) SetRoomAlias(
ctx context.Context,
Expand Down

0 comments on commit fac71ed

Please sign in to comment.