diff --git a/.github/ISSUE_TEMPLATE/BUG_REPORT.md b/.github/ISSUE_TEMPLATE/BUG_REPORT.md index f40c56609..a3b8c0754 100644 --- a/.github/ISSUE_TEMPLATE/BUG_REPORT.md +++ b/.github/ISSUE_TEMPLATE/BUG_REPORT.md @@ -17,7 +17,6 @@ see: https://www.matrix.org/security-disclosure-policy/ ### Background information - **Dendrite version or git SHA**: -- **Monolith or Polylith?**: - **SQLite3 or Postgres?**: - **Running in Docker?**: - **`go version`**: diff --git a/.github/workflows/dendrite.yml b/.github/workflows/dendrite.yml index 2dc5f74c0..b9db66b2c 100644 --- a/.github/workflows/dendrite.yml +++ b/.github/workflows/dendrite.yml @@ -261,6 +261,7 @@ jobs: uses: codecov/codecov-action@v3 with: flags: unittests + fail_ci_if_error: true # run database upgrade tests upgrade_test: @@ -317,19 +318,9 @@ jobs: - label: SQLite Cgo cgo: 1 - - label: SQLite native, full HTTP APIs - api: full-http - - - label: SQLite Cgo, full HTTP APIs - api: full-http - cgo: 1 - - label: PostgreSQL postgres: postgres - - label: PostgreSQL, full HTTP APIs - postgres: postgres - api: full-http container: image: matrixdotorg/sytest-dendrite volumes: @@ -338,7 +329,6 @@ jobs: - /root/.cache/go-mod:/gopath/pkg/mod env: POSTGRES: ${{ matrix.postgres && 1}} - API: ${{ matrix.api && 1 }} SYTEST_BRANCH: ${{ github.head_ref }} CGO_ENABLED: ${{ matrix.cgo && 1 }} steps: @@ -390,22 +380,9 @@ jobs: - label: SQLite Cgo cgo: 1 - - label: SQLite native, full HTTP APIs - api: full-http - cgo: 0 - - - label: SQLite Cgo, full HTTP APIs - api: full-http - cgo: 1 - - label: PostgreSQL postgres: Postgres cgo: 0 - - - label: PostgreSQL, full HTTP APIs - postgres: Postgres - api: full-http - cgo: 0 steps: # Env vars are set file a file given by $GITHUB_PATH. We need both Go 1.17 and GOPATH on env to run Complement. # See https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#adding-a-system-path @@ -447,7 +424,7 @@ jobs: (wget -O - "https://github.com/matrix-org/complement/archive/$BRANCH_NAME.tar.gz" | tar -xz --strip-components=1 -C complement) && break done # Build initial Dendrite image - - run: docker build --build-arg=CGO=${{ matrix.cgo }} -t complement-dendrite:${{ matrix.postgres }}${{ matrix.api }}${{ matrix.cgo }} -f build/scripts/Complement${{ matrix.postgres }}.Dockerfile . + - run: docker build --build-arg=CGO=${{ matrix.cgo }} -t complement-dendrite:${{ matrix.postgres }}${{ matrix.cgo }} -f build/scripts/Complement${{ matrix.postgres }}.Dockerfile . working-directory: dendrite env: DOCKER_BUILDKIT: 1 @@ -459,8 +436,7 @@ jobs: shell: bash name: Run Complement Tests env: - COMPLEMENT_BASE_IMAGE: complement-dendrite:${{ matrix.postgres }}${{ matrix.api }}${{ matrix.cgo }} - COMPLEMENT_DENDRITE_API: ${{ matrix.api && 1 }} + COMPLEMENT_BASE_IMAGE: complement-dendrite:${{ matrix.postgres }}${{ matrix.cgo }} COMPLEMENT_SHARE_ENV_PREFIX: COMPLEMENT_DENDRITE_ working-directory: complement diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 2e17539d8..e7ffea438 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -98,86 +98,6 @@ jobs: with: sarif_file: "trivy-results.sarif" - polylith: - name: Polylith image - runs-on: ubuntu-latest - permissions: - contents: read - packages: write - security-events: write # To upload Trivy sarif files - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Get release tag & build flags - if: github.event_name == 'release' # Only for GitHub releases - run: | - echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV - echo "BUILD=$(git rev-parse --short HEAD || \"\")" >> $GITHUB_ENV - BRANCH=$(git symbolic-ref --short HEAD | tr -d \/) - [ ${BRANCH} == "main" ] && BRANCH="" - echo "BRANCH=${BRANCH}" >> $GITHUB_ENV - - name: Set up QEMU - uses: docker/setup-qemu-action@v1 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - name: Login to Docker Hub - uses: docker/login-action@v2 - with: - username: ${{ env.DOCKER_HUB_USER }} - password: ${{ secrets.DOCKER_TOKEN }} - - name: Login to GitHub Containers - uses: docker/login-action@v2 - with: - registry: ghcr.io - username: ${{ github.repository_owner }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Build main polylith image - if: github.ref_name == 'main' - id: docker_build_polylith - uses: docker/build-push-action@v3 - with: - cache-from: type=gha - cache-to: type=gha,mode=max - context: . - build-args: FLAGS=-X github.com/matrix-org/dendrite/internal.branch=${{ env.BRANCH }} -X github.com/matrix-org/dendrite/internal.build=${{ env.BUILD }} - target: polylith - platforms: ${{ env.PLATFORMS }} - push: true - tags: | - ${{ env.DOCKER_NAMESPACE }}/dendrite-polylith:${{ github.ref_name }} - ghcr.io/${{ env.GHCR_NAMESPACE }}/dendrite-polylith:${{ github.ref_name }} - - - name: Build release polylith image - if: github.event_name == 'release' # Only for GitHub releases - id: docker_build_polylith_release - uses: docker/build-push-action@v3 - with: - cache-from: type=gha - cache-to: type=gha,mode=max - context: . - build-args: FLAGS=-X github.com/matrix-org/dendrite/internal.branch=${{ env.BRANCH }} -X github.com/matrix-org/dendrite/internal.build=${{ env.BUILD }} - target: polylith - platforms: ${{ env.PLATFORMS }} - push: true - tags: | - ${{ env.DOCKER_NAMESPACE }}/dendrite-polylith:latest - ${{ env.DOCKER_NAMESPACE }}/dendrite-polylith:${{ env.RELEASE_VERSION }} - ghcr.io/${{ env.GHCR_NAMESPACE }}/dendrite-polylith:latest - ghcr.io/${{ env.GHCR_NAMESPACE }}/dendrite-polylith:${{ env.RELEASE_VERSION }} - - - name: Run Trivy vulnerability scanner - uses: aquasecurity/trivy-action@master - with: - image-ref: ghcr.io/${{ env.GHCR_NAMESPACE }}/dendrite-polylith:${{ github.ref_name }} - format: "sarif" - output: "trivy-results.sarif" - - - name: Upload Trivy scan results to GitHub Security tab - uses: github/codeql-action/upload-sarif@v2 - with: - sarif_file: "trivy-results.sarif" - demo-pinecone: name: Pinecone demo image runs-on: ubuntu-latest diff --git a/.github/workflows/schedules.yaml b/.github/workflows/schedules.yaml index fa2304c1f..b8bda57c5 100644 --- a/.github/workflows/schedules.yaml +++ b/.github/workflows/schedules.yaml @@ -24,19 +24,8 @@ jobs: - label: SQLite Cgo cgo: 1 - - label: SQLite native, full HTTP APIs - api: full-http - - - label: SQLite Cgo, full HTTP APIs - api: full-http - cgo: 1 - - label: PostgreSQL postgres: postgres - - - label: PostgreSQL, full HTTP APIs - postgres: postgres - api: full-http container: image: matrixdotorg/sytest-dendrite:latest volumes: @@ -45,7 +34,6 @@ jobs: - /root/.cache/go-mod:/gopath/pkg/mod env: POSTGRES: ${{ matrix.postgres && 1}} - API: ${{ matrix.api && 1 }} SYTEST_BRANCH: ${{ github.head_ref }} RACE_DETECTION: 1 COVER: 1 @@ -125,22 +113,9 @@ jobs: - label: SQLite Cgo cgo: 1 - - label: SQLite native, full HTTP APIs - api: full-http - cgo: 0 - - - label: SQLite Cgo, full HTTP APIs - api: full-http - cgo: 1 - - label: PostgreSQL postgres: Postgres cgo: 0 - - - label: PostgreSQL, full HTTP APIs - postgres: Postgres - api: full-http - cgo: 0 steps: # Env vars are set file a file given by $GITHUB_PATH. We need both Go 1.17 and GOPATH on env to run Complement. # See https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#adding-a-system-path @@ -182,7 +157,7 @@ jobs: (wget -O - "https://github.com/matrix-org/complement/archive/$BRANCH_NAME.tar.gz" | tar -xz --strip-components=1 -C complement) && break done # Build initial Dendrite image - - run: docker build --build-arg=CGO=${{ matrix.cgo }} -t complement-dendrite:${{ matrix.postgres }}${{ matrix.api }}${{ matrix.cgo }} -f build/scripts/Complement${{ matrix.postgres }}.Dockerfile . + - run: docker build --build-arg=CGO=${{ matrix.cgo }} -t complement-dendrite:${{ matrix.postgres }}${{ matrix.cgo }} -f build/scripts/Complement${{ matrix.postgres }}.Dockerfile . working-directory: dendrite env: DOCKER_BUILDKIT: 1 @@ -203,8 +178,7 @@ jobs: shell: bash name: Run Complement Tests env: - COMPLEMENT_BASE_IMAGE: complement-dendrite:${{ matrix.postgres }}${{ matrix.api }}${{ matrix.cgo }} - COMPLEMENT_DENDRITE_API: ${{ matrix.api && 1 }} + COMPLEMENT_BASE_IMAGE: complement-dendrite:${{ matrix.postgres }}${{ matrix.cgo }} COMPLEMENT_SHARE_ENV_PREFIX: COMPLEMENT_DENDRITE_ COMPLEMENT_DENDRITE_COVER: 1 COMPLEMENT_POST_TEST_SCRIPT: /tmp/posttest.sh diff --git a/Dockerfile b/Dockerfile index 6da555c04..7a6883d62 100644 --- a/Dockerfile +++ b/Dockerfile @@ -34,19 +34,6 @@ LABEL org.opencontainers.image.licenses="Apache-2.0" LABEL org.opencontainers.image.documentation="https://matrix-org.github.io/dendrite/" LABEL org.opencontainers.image.vendor="The Matrix.org Foundation C.I.C." -# -# Builds the polylith image and only contains the polylith binary -# -FROM dendrite-base AS polylith -LABEL org.opencontainers.image.title="Dendrite (Polylith)" - -COPY --from=build /out/dendrite-polylith-multi /usr/bin/ - -VOLUME /etc/dendrite -WORKDIR /etc/dendrite - -ENTRYPOINT ["/usr/bin/dendrite-polylith-multi"] - # # Builds the monolith image and contains all required binaries # diff --git a/README.md b/README.md index 148f8c493..ba6960f35 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,6 @@ This does not mean: - Dendrite is ready for massive homeserver deployments. There is no sharding of microservices (although it is possible to run them on separate machines) and there is no high-availability/clustering support. Currently, we expect Dendrite to function well for small (10s/100s of users) homeserver deployments as well as P2P Matrix nodes in-browser or on mobile devices. -In the future, we will be able to scale up to gigantic servers (equivalent to `matrix.org`) via polylith mode. If you have further questions, please take a look at [our FAQ](docs/FAQ.md) or join us in: diff --git a/appservice/appservice.go b/appservice/appservice.go index 753850de7..b950a8219 100644 --- a/appservice/appservice.go +++ b/appservice/appservice.go @@ -21,14 +21,12 @@ import ( "sync" "time" - "github.com/gorilla/mux" "github.com/sirupsen/logrus" "github.com/matrix-org/gomatrixserverlib" appserviceAPI "github.com/matrix-org/dendrite/appservice/api" "github.com/matrix-org/dendrite/appservice/consumers" - "github.com/matrix-org/dendrite/appservice/inthttp" "github.com/matrix-org/dendrite/appservice/query" roomserverAPI "github.com/matrix-org/dendrite/roomserver/api" "github.com/matrix-org/dendrite/setup/base" @@ -36,11 +34,6 @@ import ( userapi "github.com/matrix-org/dendrite/userapi/api" ) -// AddInternalRoutes registers HTTP handlers for internal API calls -func AddInternalRoutes(router *mux.Router, queryAPI appserviceAPI.AppServiceInternalAPI, enableMetrics bool) { - inthttp.AddRoutes(queryAPI, router, enableMetrics) -} - // NewInternalAPI returns a concerete implementation of the internal API. Callers // can call functions directly on the returned API or via an HTTP interface using AddInternalRoutes. func NewInternalAPI( diff --git a/appservice/appservice_test.go b/appservice/appservice_test.go index 83c551fea..9e9940cd3 100644 --- a/appservice/appservice_test.go +++ b/appservice/appservice_test.go @@ -10,12 +10,8 @@ import ( "strings" "testing" - "github.com/gorilla/mux" - "github.com/matrix-org/dendrite/appservice" "github.com/matrix-org/dendrite/appservice/api" - "github.com/matrix-org/dendrite/appservice/inthttp" - "github.com/matrix-org/dendrite/internal/httputil" "github.com/matrix-org/dendrite/roomserver" "github.com/matrix-org/dendrite/setup/config" "github.com/matrix-org/dendrite/test" @@ -132,23 +128,7 @@ func TestAppserviceInternalAPI(t *testing.T) { usrAPI := userapi.NewInternalAPI(base, &base.Cfg.UserAPI, nil, nil, rsAPI, nil) asAPI := appservice.NewInternalAPI(base, usrAPI, rsAPI) - // Finally execute the tests - t.Run("HTTP API", func(t *testing.T) { - router := mux.NewRouter().PathPrefix(httputil.InternalPathPrefix).Subrouter() - appservice.AddInternalRoutes(router, asAPI, base.EnableMetrics) - apiURL, cancel := test.ListenAndServe(t, router, false) - defer cancel() - - asHTTPApi, err := inthttp.NewAppserviceClient(apiURL, &http.Client{}) - if err != nil { - t.Fatalf("failed to create HTTP client: %s", err) - } - runCases(t, asHTTPApi) - }) - - t.Run("Monolith", func(t *testing.T) { - runCases(t, asAPI) - }) + runCases(t, asAPI) }) } diff --git a/appservice/inthttp/client.go b/appservice/inthttp/client.go deleted file mode 100644 index f7f164877..000000000 --- a/appservice/inthttp/client.go +++ /dev/null @@ -1,84 +0,0 @@ -package inthttp - -import ( - "context" - "errors" - "net/http" - - "github.com/matrix-org/dendrite/appservice/api" - "github.com/matrix-org/dendrite/internal/httputil" -) - -// HTTP paths for the internal HTTP APIs -const ( - AppServiceRoomAliasExistsPath = "/appservice/RoomAliasExists" - AppServiceUserIDExistsPath = "/appservice/UserIDExists" - AppServiceLocationsPath = "/appservice/locations" - AppServiceUserPath = "/appservice/users" - AppServiceProtocolsPath = "/appservice/protocols" -) - -// httpAppServiceQueryAPI contains the URL to an appservice query API and a -// reference to a httpClient used to reach it -type httpAppServiceQueryAPI struct { - appserviceURL string - httpClient *http.Client -} - -// NewAppserviceClient creates a AppServiceQueryAPI implemented by talking -// to a HTTP POST API. -// If httpClient is nil an error is returned -func NewAppserviceClient( - appserviceURL string, - httpClient *http.Client, -) (api.AppServiceInternalAPI, error) { - if httpClient == nil { - return nil, errors.New("NewRoomserverAliasAPIHTTP: httpClient is ") - } - return &httpAppServiceQueryAPI{appserviceURL, httpClient}, nil -} - -// RoomAliasExists implements AppServiceQueryAPI -func (h *httpAppServiceQueryAPI) RoomAliasExists( - ctx context.Context, - request *api.RoomAliasExistsRequest, - response *api.RoomAliasExistsResponse, -) error { - return httputil.CallInternalRPCAPI( - "RoomAliasExists", h.appserviceURL+AppServiceRoomAliasExistsPath, - h.httpClient, ctx, request, response, - ) -} - -// UserIDExists implements AppServiceQueryAPI -func (h *httpAppServiceQueryAPI) UserIDExists( - ctx context.Context, - request *api.UserIDExistsRequest, - response *api.UserIDExistsResponse, -) error { - return httputil.CallInternalRPCAPI( - "UserIDExists", h.appserviceURL+AppServiceUserIDExistsPath, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpAppServiceQueryAPI) Locations(ctx context.Context, request *api.LocationRequest, response *api.LocationResponse) error { - return httputil.CallInternalRPCAPI( - "ASLocation", h.appserviceURL+AppServiceLocationsPath, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpAppServiceQueryAPI) User(ctx context.Context, request *api.UserRequest, response *api.UserResponse) error { - return httputil.CallInternalRPCAPI( - "ASUser", h.appserviceURL+AppServiceUserPath, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpAppServiceQueryAPI) Protocols(ctx context.Context, request *api.ProtocolRequest, response *api.ProtocolResponse) error { - return httputil.CallInternalRPCAPI( - "ASProtocols", h.appserviceURL+AppServiceProtocolsPath, - h.httpClient, ctx, request, response, - ) -} diff --git a/appservice/inthttp/server.go b/appservice/inthttp/server.go deleted file mode 100644 index b70fad673..000000000 --- a/appservice/inthttp/server.go +++ /dev/null @@ -1,36 +0,0 @@ -package inthttp - -import ( - "github.com/gorilla/mux" - - "github.com/matrix-org/dendrite/appservice/api" - "github.com/matrix-org/dendrite/internal/httputil" -) - -// AddRoutes adds the AppServiceQueryAPI handlers to the http.ServeMux. -func AddRoutes(a api.AppServiceInternalAPI, internalAPIMux *mux.Router, enableMetrics bool) { - internalAPIMux.Handle( - AppServiceRoomAliasExistsPath, - httputil.MakeInternalRPCAPI("AppserviceRoomAliasExists", enableMetrics, a.RoomAliasExists), - ) - - internalAPIMux.Handle( - AppServiceUserIDExistsPath, - httputil.MakeInternalRPCAPI("AppserviceUserIDExists", enableMetrics, a.UserIDExists), - ) - - internalAPIMux.Handle( - AppServiceProtocolsPath, - httputil.MakeInternalRPCAPI("AppserviceProtocols", enableMetrics, a.Protocols), - ) - - internalAPIMux.Handle( - AppServiceLocationsPath, - httputil.MakeInternalRPCAPI("AppserviceLocations", enableMetrics, a.Locations), - ) - - internalAPIMux.Handle( - AppServiceUserPath, - httputil.MakeInternalRPCAPI("AppserviceUser", enableMetrics, a.User), - ) -} diff --git a/build/docker/README.md b/build/docker/README.md index 7eb20d88f..d8abd6538 100644 --- a/build/docker/README.md +++ b/build/docker/README.md @@ -5,7 +5,6 @@ These are Docker images for Dendrite! They can be found on Docker Hub: - [matrixdotorg/dendrite-monolith](https://hub.docker.com/r/matrixdotorg/dendrite-monolith) for monolith deployments -- [matrixdotorg/dendrite-polylith](https://hub.docker.com/r/matrixdotorg/dendrite-polylith) for polylith deployments ## Dockerfiles @@ -15,7 +14,6 @@ repository, run: ``` docker build . --target monolith -t matrixdotorg/dendrite-monolith -docker build . --target polylith -t matrixdotorg/dendrite-monolith docker build . --target demo-pinecone -t matrixdotorg/dendrite-demo-pinecone docker build . --target demo-yggdrasil -t matrixdotorg/dendrite-demo-yggdrasil ``` @@ -25,7 +23,6 @@ docker build . --target demo-yggdrasil -t matrixdotorg/dendrite-demo-yggdrasil There are two sample `docker-compose` files: - `docker-compose.monolith.yml` which runs a monolith Dendrite deployment -- `docker-compose.polylith.yml` which runs a polylith Dendrite deployment ## Configuration @@ -51,7 +48,7 @@ docker run --rm --entrypoint="" \ The key files will now exist in your current working directory, and can be mounted into place. -## Starting Dendrite as a monolith deployment +## Starting Dendrite Create your config based on the [`dendrite-sample.monolith.yaml`](https://github.com/matrix-org/dendrite/blob/main/dendrite-sample.monolith.yaml) sample configuration file. @@ -61,16 +58,6 @@ Then start the deployment: docker-compose -f docker-compose.monolith.yml up ``` -## Starting Dendrite as a polylith deployment - -Create your config based on the [`dendrite-sample.polylith.yaml`](https://github.com/matrix-org/dendrite/blob/main/dendrite-sample.polylith.yaml) sample configuration file. - -Then start the deployment: - -``` -docker-compose -f docker-compose.polylith.yml up -``` - ## Building the images The `build/docker/images-build.sh` script will build the base image, followed by diff --git a/build/docker/docker-compose.polylith.yml b/build/docker/docker-compose.polylith.yml deleted file mode 100644 index de0ab0aa2..000000000 --- a/build/docker/docker-compose.polylith.yml +++ /dev/null @@ -1,143 +0,0 @@ -version: "3.4" -services: - postgres: - hostname: postgres - image: postgres:14 - restart: always - volumes: - - ./postgres/create_db.sh:/docker-entrypoint-initdb.d/20-create_db.sh - # To persist your PostgreSQL databases outside of the Docker image, - # to prevent data loss, modify the following ./path_to path: - - ./path_to/postgresql:/var/lib/postgresql/data - environment: - POSTGRES_PASSWORD: itsasecret - POSTGRES_USER: dendrite - healthcheck: - test: ["CMD-SHELL", "pg_isready -U dendrite"] - interval: 5s - timeout: 5s - retries: 5 - networks: - - internal - - jetstream: - hostname: jetstream - image: nats:latest - command: | - --jetstream - --store_dir /var/lib/nats - --cluster_name Dendrite - volumes: - # To persist your NATS JetStream streams outside of the Docker image, - # prevent data loss, modify the following ./path_to path: - - ./path_to/nats:/var/lib/nats - networks: - - internal - - client_api: - hostname: client_api - image: matrixdotorg/dendrite-polylith:latest - command: clientapi - volumes: - - ./config:/etc/dendrite - depends_on: - - jetstream - - postgres - networks: - - internal - restart: unless-stopped - - media_api: - hostname: media_api - image: matrixdotorg/dendrite-polylith:latest - command: mediaapi - volumes: - - ./config:/etc/dendrite - - ./media:/var/dendrite/media - networks: - - internal - restart: unless-stopped - - sync_api: - hostname: sync_api - image: matrixdotorg/dendrite-polylith:latest - command: syncapi - volumes: - - ./config:/etc/dendrite - depends_on: - - jetstream - - postgres - networks: - - internal - restart: unless-stopped - - room_server: - hostname: room_server - image: matrixdotorg/dendrite-polylith:latest - command: roomserver - volumes: - - ./config:/etc/dendrite - depends_on: - - jetstream - - postgres - networks: - - internal - restart: unless-stopped - - federation_api: - hostname: federation_api - image: matrixdotorg/dendrite-polylith:latest - command: federationapi - volumes: - - ./config:/etc/dendrite - depends_on: - - jetstream - - postgres - networks: - - internal - restart: unless-stopped - - key_server: - hostname: key_server - image: matrixdotorg/dendrite-polylith:latest - command: keyserver - volumes: - - ./config:/etc/dendrite - depends_on: - - jetstream - - postgres - networks: - - internal - restart: unless-stopped - - user_api: - hostname: user_api - image: matrixdotorg/dendrite-polylith:latest - command: userapi - volumes: - - ./config:/etc/dendrite - depends_on: - - jetstream - - postgres - networks: - - internal - restart: unless-stopped - - appservice_api: - hostname: appservice_api - image: matrixdotorg/dendrite-polylith:latest - command: appservice - volumes: - - ./config:/etc/dendrite - networks: - - internal - depends_on: - - jetstream - - postgres - - room_server - - user_api - restart: unless-stopped - -networks: - internal: - attachable: true diff --git a/build/docker/images-build.sh b/build/docker/images-build.sh index d97a701ed..bf227968f 100755 --- a/build/docker/images-build.sh +++ b/build/docker/images-build.sh @@ -7,6 +7,5 @@ TAG=${1:-latest} echo "Building tag '${TAG}'" docker build . --target monolith -t matrixdotorg/dendrite-monolith:${TAG} -docker build . --target polylith -t matrixdotorg/dendrite-monolith:${TAG} docker build . --target demo-pinecone -t matrixdotorg/dendrite-demo-pinecone:${TAG} docker build . --target demo-yggdrasil -t matrixdotorg/dendrite-demo-yggdrasil:${TAG} \ No newline at end of file diff --git a/build/docker/images-pull.sh b/build/docker/images-pull.sh index f3f98ce7c..7772ca747 100755 --- a/build/docker/images-pull.sh +++ b/build/docker/images-pull.sh @@ -5,4 +5,3 @@ TAG=${1:-latest} echo "Pulling tag '${TAG}'" docker pull matrixdotorg/dendrite-monolith:${TAG} -docker pull matrixdotorg/dendrite-polylith:${TAG} \ No newline at end of file diff --git a/build/docker/images-push.sh b/build/docker/images-push.sh index 248fdee2b..d166d355a 100755 --- a/build/docker/images-push.sh +++ b/build/docker/images-push.sh @@ -5,4 +5,3 @@ TAG=${1:-latest} echo "Pushing tag '${TAG}'" docker push matrixdotorg/dendrite-monolith:${TAG} -docker push matrixdotorg/dendrite-polylith:${TAG} \ No newline at end of file diff --git a/build/gobind-yggdrasil/monolith.go b/build/gobind-yggdrasil/monolith.go index 8c2d0a006..1e28dade9 100644 --- a/build/gobind-yggdrasil/monolith.go +++ b/build/gobind-yggdrasil/monolith.go @@ -127,8 +127,8 @@ func (m *DendriteMonolith) Start() { cfg := &config.Dendrite{} cfg.Defaults(config.DefaultOpts{ - Generate: true, - Monolithic: true, + Generate: true, + SingleDatabase: true, }) cfg.Global.ServerName = gomatrixserverlib.ServerName(hex.EncodeToString(pk)) cfg.Global.PrivateKey = sk diff --git a/clientapi/routing/auth_fallback_test.go b/clientapi/routing/auth_fallback_test.go index 0d77f9a01..534581bdd 100644 --- a/clientapi/routing/auth_fallback_test.go +++ b/clientapi/routing/auth_fallback_test.go @@ -22,7 +22,7 @@ func Test_AuthFallback(t *testing.T) { for _, wantErr := range []bool{false, true} { t.Run(fmt.Sprintf("useHCaptcha(%v) - recaptchaEnabled(%v) - wantErr(%v)", useHCaptcha, recaptchaEnabled, wantErr), func(t *testing.T) { // Set the defaults for each test - base.Cfg.ClientAPI.Defaults(config.DefaultOpts{Generate: true, Monolithic: true}) + base.Cfg.ClientAPI.Defaults(config.DefaultOpts{Generate: true, SingleDatabase: true}) base.Cfg.ClientAPI.RecaptchaEnabled = recaptchaEnabled base.Cfg.ClientAPI.RecaptchaPublicKey = "pub" base.Cfg.ClientAPI.RecaptchaPrivateKey = "priv" @@ -33,7 +33,7 @@ func Test_AuthFallback(t *testing.T) { base.Cfg.ClientAPI.RecaptchaSitekeyClass = "h-captcha" } cfgErrs := &config.ConfigErrors{} - base.Cfg.ClientAPI.Verify(cfgErrs, true) + base.Cfg.ClientAPI.Verify(cfgErrs) if len(*cfgErrs) > 0 { t.Fatalf("(hCaptcha=%v) unexpected config errors: %s", useHCaptcha, cfgErrs.Error()) } diff --git a/clientapi/routing/leaveroom.go b/clientapi/routing/leaveroom.go index 86414afca..a71661851 100644 --- a/clientapi/routing/leaveroom.go +++ b/clientapi/routing/leaveroom.go @@ -18,7 +18,6 @@ import ( "net/http" "github.com/matrix-org/dendrite/clientapi/jsonerror" - "github.com/matrix-org/dendrite/internal/httputil" roomserverAPI "github.com/matrix-org/dendrite/roomserver/api" "github.com/matrix-org/dendrite/userapi/api" "github.com/matrix-org/util" @@ -45,15 +44,6 @@ func LeaveRoomByID( JSON: jsonerror.LeaveServerNoticeError(), } } - switch e := err.(type) { - case httputil.InternalAPIError: - if e.Message == jsonerror.LeaveServerNoticeError().Error() { - return util.JSONResponse{ - Code: http.StatusForbidden, - JSON: jsonerror.LeaveServerNoticeError(), - } - } - } return util.JSONResponse{ Code: http.StatusBadRequest, JSON: jsonerror.Unknown(err.Error()), diff --git a/clientapi/routing/register.go b/clientapi/routing/register.go index be2b192b2..ff6a0900e 100644 --- a/clientapi/routing/register.go +++ b/clientapi/routing/register.go @@ -31,8 +31,6 @@ import ( "time" "github.com/matrix-org/dendrite/internal" - internalHTTPUtil "github.com/matrix-org/dendrite/internal/httputil" - "github.com/matrix-org/dendrite/internal/sqlutil" "github.com/tidwall/gjson" "github.com/matrix-org/dendrite/internal/eventutil" @@ -861,16 +859,6 @@ func completeRegistration( JSON: jsonerror.UserInUse("Desired user ID is already taken."), } } - switch e := err.(type) { - case internalHTTPUtil.InternalAPIError: - conflictErr := &userapi.ErrorConflict{Message: sqlutil.ErrUserExists.Error()} - if e.Message == conflictErr.Error() { - return util.JSONResponse{ - Code: http.StatusBadRequest, - JSON: jsonerror.UserInUse("Desired user ID is already taken."), - } - } - } return util.JSONResponse{ Code: http.StatusInternalServerError, JSON: jsonerror.Unknown("failed to create account: " + err.Error()), diff --git a/clientapi/routing/register_test.go b/clientapi/routing/register_test.go index bccc1b79b..670c392bf 100644 --- a/clientapi/routing/register_test.go +++ b/clientapi/routing/register_test.go @@ -201,8 +201,8 @@ func TestValidationOfApplicationServices(t *testing.T) { // Set up a config fakeConfig := &config.Dendrite{} fakeConfig.Defaults(config.DefaultOpts{ - Generate: true, - Monolithic: true, + Generate: true, + SingleDatabase: true, }) fakeConfig.Global.ServerName = "localhost" fakeConfig.ClientAPI.Derived.ApplicationServices = []config.ApplicationService{fakeApplicationService} diff --git a/cmd/dendrite-demo-pinecone/monolith/monolith.go b/cmd/dendrite-demo-pinecone/monolith/monolith.go index 6f1c69a78..9808ab857 100644 --- a/cmd/dendrite-demo-pinecone/monolith/monolith.go +++ b/cmd/dendrite-demo-pinecone/monolith/monolith.go @@ -80,8 +80,8 @@ type P2PMonolith struct { func GenerateDefaultConfig(sk ed25519.PrivateKey, storageDir string, cacheDir string, dbPrefix string) *config.Dendrite { cfg := config.Dendrite{} cfg.Defaults(config.DefaultOpts{ - Generate: true, - Monolithic: true, + Generate: true, + SingleDatabase: true, }) cfg.Global.PrivateKey = sk cfg.Global.JetStream.StoragePath = config.Path(fmt.Sprintf("%s/", filepath.Join(cacheDir, dbPrefix))) diff --git a/cmd/dendrite-demo-yggdrasil/main.go b/cmd/dendrite-demo-yggdrasil/main.go index 3ea4a08b0..3bef8394c 100644 --- a/cmd/dendrite-demo-yggdrasil/main.go +++ b/cmd/dendrite-demo-yggdrasil/main.go @@ -117,8 +117,8 @@ func main() { cfg = setup.ParseFlags(true) } else { cfg.Defaults(config.DefaultOpts{ - Generate: true, - Monolithic: true, + Generate: true, + SingleDatabase: true, }) cfg.Global.PrivateKey = sk cfg.Global.JetStream.StoragePath = config.Path(filepath.Join(*instanceDir, *instanceName)) diff --git a/cmd/dendrite-monolith-server/main.go b/cmd/dendrite-monolith-server/main.go index 6836b6426..0c040f30b 100644 --- a/cmd/dendrite-monolith-server/main.go +++ b/cmd/dendrite-monolith-server/main.go @@ -34,38 +34,18 @@ import ( ) var ( - httpBindAddr = flag.String("http-bind-address", ":8008", "The HTTP listening port for the server") - httpsBindAddr = flag.String("https-bind-address", ":8448", "The HTTPS listening port for the server") - apiBindAddr = flag.String("api-bind-address", "localhost:18008", "The HTTP listening port for the internal HTTP APIs (if -api is enabled)") - certFile = flag.String("tls-cert", "", "The PEM formatted X509 certificate to use for TLS") - keyFile = flag.String("tls-key", "", "The PEM private key to use for TLS") - enableHTTPAPIs = flag.Bool("api", false, "Use HTTP APIs instead of short-circuiting (warning: exposes API endpoints!)") - traceInternal = os.Getenv("DENDRITE_TRACE_INTERNAL") == "1" + httpBindAddr = flag.String("http-bind-address", ":8008", "The HTTP listening port for the server") + httpsBindAddr = flag.String("https-bind-address", ":8448", "The HTTPS listening port for the server") + certFile = flag.String("tls-cert", "", "The PEM formatted X509 certificate to use for TLS") + keyFile = flag.String("tls-key", "", "The PEM private key to use for TLS") + traceInternal = os.Getenv("DENDRITE_TRACE_INTERNAL") == "1" ) func main() { cfg := setup.ParseFlags(true) httpAddr := config.HTTPAddress("http://" + *httpBindAddr) httpsAddr := config.HTTPAddress("https://" + *httpsBindAddr) - httpAPIAddr := httpAddr options := []basepkg.BaseDendriteOptions{} - if *enableHTTPAPIs { - logrus.Warnf("DANGER! The -api option is enabled, exposing internal APIs on %q!", *apiBindAddr) - httpAPIAddr = config.HTTPAddress("http://" + *apiBindAddr) - // If the HTTP APIs are enabled then we need to update the Listen - // statements in the configuration so that we know where to find - // the API endpoints. They'll listen on the same port as the monolith - // itself. - cfg.AppServiceAPI.InternalAPI.Connect = httpAPIAddr - cfg.ClientAPI.InternalAPI.Connect = httpAPIAddr - cfg.FederationAPI.InternalAPI.Connect = httpAPIAddr - cfg.KeyServer.InternalAPI.Connect = httpAPIAddr - cfg.MediaAPI.InternalAPI.Connect = httpAPIAddr - cfg.RoomServer.InternalAPI.Connect = httpAPIAddr - cfg.SyncAPI.InternalAPI.Connect = httpAPIAddr - cfg.UserAPI.InternalAPI.Connect = httpAPIAddr - options = append(options, basepkg.UseHTTPAPIs) - } base := basepkg.NewBaseDendrite(cfg, "Monolith", options...) defer base.Close() // nolint: errcheck @@ -75,10 +55,6 @@ func main() { rsImpl := roomserver.NewInternalAPI(base) // call functions directly on the impl unless running in HTTP mode rsAPI := rsImpl - if base.UseHTTPAPIs { - roomserver.AddInternalRoutes(base.InternalAPIMux, rsImpl, base.EnableMetrics) - rsAPI = base.RoomserverHTTPClient() - } if traceInternal { rsAPI = &api.RoomserverInternalAPITrace{ Impl: rsAPI, @@ -88,41 +64,22 @@ func main() { fsAPI := federationapi.NewInternalAPI( base, federation, rsAPI, base.Caches, nil, false, ) - fsImplAPI := fsAPI - if base.UseHTTPAPIs { - federationapi.AddInternalRoutes(base.InternalAPIMux, fsAPI, base.EnableMetrics) - fsAPI = base.FederationAPIHTTPClient() - } + keyRing := fsAPI.KeyRing() keyImpl := keyserver.NewInternalAPI(base, &base.Cfg.KeyServer, fsAPI, rsAPI) keyAPI := keyImpl - if base.UseHTTPAPIs { - keyserver.AddInternalRoutes(base.InternalAPIMux, keyAPI, base.EnableMetrics) - keyAPI = base.KeyServerHTTPClient() - } pgClient := base.PushGatewayHTTPClient() - userImpl := userapi.NewInternalAPI(base, &cfg.UserAPI, cfg.Derived.ApplicationServices, keyAPI, rsAPI, pgClient) - userAPI := userImpl - if base.UseHTTPAPIs { - userapi.AddInternalRoutes(base.InternalAPIMux, userAPI, base.EnableMetrics) - userAPI = base.UserAPIClient() - } + userAPI := userapi.NewInternalAPI(base, &cfg.UserAPI, cfg.Derived.ApplicationServices, keyAPI, rsAPI, pgClient) + if traceInternal { userAPI = &uapi.UserInternalAPITrace{ Impl: userAPI, } } - // TODO: This should use userAPI, not userImpl, but the appservice setup races with - // the listeners and panics at startup if it tries to create appservice accounts - // before the listeners are up. - asAPI := appservice.NewInternalAPI(base, userImpl, rsAPI) - if base.UseHTTPAPIs { - appservice.AddInternalRoutes(base.InternalAPIMux, asAPI, base.EnableMetrics) - asAPI = base.AppserviceHTTPClient() - } + asAPI := appservice.NewInternalAPI(base, userAPI, rsAPI) // The underlying roomserver implementation needs to be able to call the fedsender. // This is different to rsAPI which can be the http client which doesn't need this @@ -141,7 +98,7 @@ func main() { AppserviceAPI: asAPI, // always use the concrete impl here even in -http mode because adding public routes // must be done on the concrete impl not an HTTP client else fedapi will call itself - FederationAPI: fsImplAPI, + FederationAPI: fsAPI, RoomserverAPI: rsAPI, UserAPI: userAPI, KeyAPI: keyAPI, @@ -156,20 +113,12 @@ func main() { // Expose the matrix APIs directly rather than putting them under a /api path. go func() { - base.SetupAndServeHTTP( - httpAPIAddr, // internal API - httpAddr, // external API - nil, nil, // TLS settings - ) + base.SetupAndServeHTTP(httpAddr, nil, nil) }() // Handle HTTPS if certificate and key are provided if *certFile != "" && *keyFile != "" { go func() { - base.SetupAndServeHTTP( - basepkg.NoListener, // internal API - httpsAddr, // external API - certFile, keyFile, // TLS settings - ) + base.SetupAndServeHTTP(httpsAddr, certFile, keyFile) }() } diff --git a/cmd/dendrite-polylith-multi/main.go b/cmd/dendrite-polylith-multi/main.go deleted file mode 100644 index c6a560b19..000000000 --- a/cmd/dendrite-polylith-multi/main.go +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright 2020 The Matrix.org Foundation C.I.C. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package main - -import ( - "flag" - "os" - "strings" - - "github.com/matrix-org/dendrite/cmd/dendrite-polylith-multi/personalities" - "github.com/matrix-org/dendrite/setup" - "github.com/matrix-org/dendrite/setup/base" - "github.com/matrix-org/dendrite/setup/config" - "github.com/sirupsen/logrus" -) - -type entrypoint func(base *base.BaseDendrite, cfg *config.Dendrite) - -func main() { - cfg := setup.ParseFlags(false) - - component := "" - if flag.NFlag() > 0 { - component = flag.Arg(0) // ./dendrite-polylith-multi --config=... clientapi - } else if len(os.Args) > 1 { - component = os.Args[1] // ./dendrite-polylith-multi clientapi - } - - components := map[string]entrypoint{ - "appservice": personalities.Appservice, - "clientapi": personalities.ClientAPI, - "federationapi": personalities.FederationAPI, - "keyserver": personalities.KeyServer, - "mediaapi": personalities.MediaAPI, - "roomserver": personalities.RoomServer, - "syncapi": personalities.SyncAPI, - "userapi": personalities.UserAPI, - } - - start, ok := components[component] - if !ok { - if component == "" { - logrus.Errorf("No component specified") - logrus.Info("The first argument on the command line must be the name of the component to run") - } else { - logrus.Errorf("Unknown component %q specified", component) - } - - var list []string - for c := range components { - list = append(list, c) - } - logrus.Infof("Valid components: %s", strings.Join(list, ", ")) - - os.Exit(1) - } - - logrus.Infof("Starting %q component", component) - - base := base.NewBaseDendrite(cfg, component, base.PolylithMode) // TODO - defer base.Close() // nolint: errcheck - - go start(base, cfg) - base.WaitForShutdown() -} diff --git a/cmd/dendrite-polylith-multi/personalities/appservice.go b/cmd/dendrite-polylith-multi/personalities/appservice.go deleted file mode 100644 index 0547d57f0..000000000 --- a/cmd/dendrite-polylith-multi/personalities/appservice.go +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2020 The Matrix.org Foundation C.I.C. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package personalities - -import ( - "github.com/matrix-org/dendrite/appservice" - "github.com/matrix-org/dendrite/setup/base" - basepkg "github.com/matrix-org/dendrite/setup/base" - "github.com/matrix-org/dendrite/setup/config" -) - -func Appservice(base *base.BaseDendrite, cfg *config.Dendrite) { - userAPI := base.UserAPIClient() - rsAPI := base.RoomserverHTTPClient() - - intAPI := appservice.NewInternalAPI(base, userAPI, rsAPI) - appservice.AddInternalRoutes(base.InternalAPIMux, intAPI, base.EnableMetrics) - - base.SetupAndServeHTTP( - base.Cfg.AppServiceAPI.InternalAPI.Listen, // internal listener - basepkg.NoListener, // external listener - nil, nil, - ) -} diff --git a/cmd/dendrite-polylith-multi/personalities/clientapi.go b/cmd/dendrite-polylith-multi/personalities/clientapi.go deleted file mode 100644 index a5d69d07c..000000000 --- a/cmd/dendrite-polylith-multi/personalities/clientapi.go +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright 2020 The Matrix.org Foundation C.I.C. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package personalities - -import ( - "github.com/matrix-org/dendrite/clientapi" - "github.com/matrix-org/dendrite/internal/transactions" - basepkg "github.com/matrix-org/dendrite/setup/base" - "github.com/matrix-org/dendrite/setup/config" -) - -func ClientAPI(base *basepkg.BaseDendrite, cfg *config.Dendrite) { - federation := base.CreateFederationClient() - - asQuery := base.AppserviceHTTPClient() - rsAPI := base.RoomserverHTTPClient() - fsAPI := base.FederationAPIHTTPClient() - userAPI := base.UserAPIClient() - keyAPI := base.KeyServerHTTPClient() - - clientapi.AddPublicRoutes( - base, federation, rsAPI, asQuery, - transactions.New(), fsAPI, userAPI, userAPI, - keyAPI, nil, - ) - - base.SetupAndServeHTTP( - base.Cfg.ClientAPI.InternalAPI.Listen, - base.Cfg.ClientAPI.ExternalAPI.Listen, - nil, nil, - ) -} diff --git a/cmd/dendrite-polylith-multi/personalities/federationapi.go b/cmd/dendrite-polylith-multi/personalities/federationapi.go deleted file mode 100644 index 48da42fbf..000000000 --- a/cmd/dendrite-polylith-multi/personalities/federationapi.go +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright 2020 The Matrix.org Foundation C.I.C. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package personalities - -import ( - "github.com/matrix-org/dendrite/federationapi" - basepkg "github.com/matrix-org/dendrite/setup/base" - "github.com/matrix-org/dendrite/setup/config" -) - -func FederationAPI(base *basepkg.BaseDendrite, cfg *config.Dendrite) { - userAPI := base.UserAPIClient() - federation := base.CreateFederationClient() - rsAPI := base.RoomserverHTTPClient() - keyAPI := base.KeyServerHTTPClient() - fsAPI := federationapi.NewInternalAPI(base, federation, rsAPI, base.Caches, nil, true) - keyRing := fsAPI.KeyRing() - - federationapi.AddPublicRoutes( - base, - userAPI, federation, keyRing, - rsAPI, fsAPI, keyAPI, nil, - ) - - federationapi.AddInternalRoutes(base.InternalAPIMux, fsAPI, base.EnableMetrics) - - base.SetupAndServeHTTP( - base.Cfg.FederationAPI.InternalAPI.Listen, - base.Cfg.FederationAPI.ExternalAPI.Listen, - nil, nil, - ) -} diff --git a/cmd/dendrite-polylith-multi/personalities/keyserver.go b/cmd/dendrite-polylith-multi/personalities/keyserver.go deleted file mode 100644 index ad0bd0e54..000000000 --- a/cmd/dendrite-polylith-multi/personalities/keyserver.go +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2020 The Matrix.org Foundation C.I.C. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package personalities - -import ( - "github.com/matrix-org/dendrite/keyserver" - basepkg "github.com/matrix-org/dendrite/setup/base" - "github.com/matrix-org/dendrite/setup/config" -) - -func KeyServer(base *basepkg.BaseDendrite, cfg *config.Dendrite) { - fsAPI := base.FederationAPIHTTPClient() - rsAPI := base.RoomserverHTTPClient() - intAPI := keyserver.NewInternalAPI(base, &base.Cfg.KeyServer, fsAPI, rsAPI) - intAPI.SetUserAPI(base.UserAPIClient()) - - keyserver.AddInternalRoutes(base.InternalAPIMux, intAPI, base.EnableMetrics) - - base.SetupAndServeHTTP( - base.Cfg.KeyServer.InternalAPI.Listen, // internal listener - basepkg.NoListener, // external listener - nil, nil, - ) -} diff --git a/cmd/dendrite-polylith-multi/personalities/mediaapi.go b/cmd/dendrite-polylith-multi/personalities/mediaapi.go deleted file mode 100644 index 69d5fd5a8..000000000 --- a/cmd/dendrite-polylith-multi/personalities/mediaapi.go +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2020 The Matrix.org Foundation C.I.C. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package personalities - -import ( - "github.com/matrix-org/dendrite/mediaapi" - basepkg "github.com/matrix-org/dendrite/setup/base" - "github.com/matrix-org/dendrite/setup/config" -) - -func MediaAPI(base *basepkg.BaseDendrite, cfg *config.Dendrite) { - userAPI := base.UserAPIClient() - client := base.CreateClient() - - mediaapi.AddPublicRoutes( - base, userAPI, client, - ) - - base.SetupAndServeHTTP( - base.Cfg.MediaAPI.InternalAPI.Listen, - base.Cfg.MediaAPI.ExternalAPI.Listen, - nil, nil, - ) -} diff --git a/cmd/dendrite-polylith-multi/personalities/roomserver.go b/cmd/dendrite-polylith-multi/personalities/roomserver.go deleted file mode 100644 index 974559bd2..000000000 --- a/cmd/dendrite-polylith-multi/personalities/roomserver.go +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2020 The Matrix.org Foundation C.I.C. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package personalities - -import ( - "github.com/matrix-org/dendrite/roomserver" - basepkg "github.com/matrix-org/dendrite/setup/base" - "github.com/matrix-org/dendrite/setup/config" -) - -func RoomServer(base *basepkg.BaseDendrite, cfg *config.Dendrite) { - asAPI := base.AppserviceHTTPClient() - fsAPI := base.FederationAPIHTTPClient() - rsAPI := roomserver.NewInternalAPI(base) - rsAPI.SetFederationAPI(fsAPI, fsAPI.KeyRing()) - rsAPI.SetAppserviceAPI(asAPI) - roomserver.AddInternalRoutes(base.InternalAPIMux, rsAPI, base.EnableMetrics) - - base.SetupAndServeHTTP( - base.Cfg.RoomServer.InternalAPI.Listen, // internal listener - basepkg.NoListener, // external listener - nil, nil, - ) -} diff --git a/cmd/dendrite-polylith-multi/personalities/syncapi.go b/cmd/dendrite-polylith-multi/personalities/syncapi.go deleted file mode 100644 index 41637fe1d..000000000 --- a/cmd/dendrite-polylith-multi/personalities/syncapi.go +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright 2020 The Matrix.org Foundation C.I.C. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package personalities - -import ( - basepkg "github.com/matrix-org/dendrite/setup/base" - "github.com/matrix-org/dendrite/setup/config" - "github.com/matrix-org/dendrite/syncapi" -) - -func SyncAPI(base *basepkg.BaseDendrite, cfg *config.Dendrite) { - userAPI := base.UserAPIClient() - - rsAPI := base.RoomserverHTTPClient() - - syncapi.AddPublicRoutes( - base, - userAPI, rsAPI, - base.KeyServerHTTPClient(), - ) - - base.SetupAndServeHTTP( - base.Cfg.SyncAPI.InternalAPI.Listen, - base.Cfg.SyncAPI.ExternalAPI.Listen, - nil, nil, - ) -} diff --git a/cmd/dendrite-polylith-multi/personalities/userapi.go b/cmd/dendrite-polylith-multi/personalities/userapi.go deleted file mode 100644 index 1bc88cb5f..000000000 --- a/cmd/dendrite-polylith-multi/personalities/userapi.go +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2020 The Matrix.org Foundation C.I.C. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package personalities - -import ( - basepkg "github.com/matrix-org/dendrite/setup/base" - "github.com/matrix-org/dendrite/setup/config" - "github.com/matrix-org/dendrite/userapi" -) - -func UserAPI(base *basepkg.BaseDendrite, cfg *config.Dendrite) { - userAPI := userapi.NewInternalAPI( - base, &cfg.UserAPI, cfg.Derived.ApplicationServices, - base.KeyServerHTTPClient(), base.RoomserverHTTPClient(), - base.PushGatewayHTTPClient(), - ) - - userapi.AddInternalRoutes(base.InternalAPIMux, userAPI, base.EnableMetrics) - - base.SetupAndServeHTTP( - base.Cfg.UserAPI.InternalAPI.Listen, // internal listener - basepkg.NoListener, // external listener - nil, nil, - ) -} diff --git a/cmd/generate-config/main.go b/cmd/generate-config/main.go index 56a145653..b0707be11 100644 --- a/cmd/generate-config/main.go +++ b/cmd/generate-config/main.go @@ -18,7 +18,6 @@ func main() { dbURI := flag.String("db", "", "The DB URI to use for all components (PostgreSQL only)") dirPath := flag.String("dir", "./", "The folder to use for paths (like SQLite databases, media storage)") normalise := flag.String("normalise", "", "Normalise an existing configuration file by adding new/missing options and defaults") - polylith := flag.Bool("polylith", false, "Generate a config that makes sense for polylith deployments") flag.Parse() var cfg *config.Dendrite @@ -27,14 +26,14 @@ func main() { Version: config.Version, } cfg.Defaults(config.DefaultOpts{ - Generate: true, - Monolithic: !*polylith, + Generate: true, + SingleDatabase: true, }) if *serverName != "" { cfg.Global.ServerName = gomatrixserverlib.ServerName(*serverName) } uri := config.DataSource(*dbURI) - if *polylith || uri.IsSQLite() || uri == "" { + if uri.IsSQLite() || uri == "" { for name, db := range map[string]*config.DatabaseOptions{ "federationapi": &cfg.FederationAPI.Database, "keyserver": &cfg.KeyServer.Database, @@ -43,6 +42,7 @@ func main() { "roomserver": &cfg.RoomServer.Database, "syncapi": &cfg.SyncAPI.Database, "userapi": &cfg.UserAPI.AccountDatabase, + "relayapi": &cfg.RelayAPI.Database, } { if uri == "" { path := filepath.Join(*dirPath, fmt.Sprintf("dendrite_%s.db", name)) @@ -96,7 +96,7 @@ func main() { } } else { var err error - if cfg, err = config.Load(*normalise, !*polylith); err != nil { + if cfg, err = config.Load(*normalise); err != nil { panic(err) } } diff --git a/dendrite-sample.polylith.yaml b/dendrite-sample.polylith.yaml deleted file mode 100644 index ecc3f4051..000000000 --- a/dendrite-sample.polylith.yaml +++ /dev/null @@ -1,417 +0,0 @@ -# This is the Dendrite configuration file. -# -# The configuration is split up into sections - each Dendrite component has a -# configuration section, in addition to the "global" section which applies to -# all components. - -# The version of the configuration file. -version: 2 - -# Global Matrix configuration. This configuration applies to all components. -global: - # The domain name of this homeserver. - server_name: localhost - - # The path to the signing private key file, used to sign requests and events. - # Note that this is NOT the same private key as used for TLS! To generate a - # signing key, use "./bin/generate-keys --private-key matrix_key.pem". - private_key: matrix_key.pem - - # The paths and expiry timestamps (as a UNIX timestamp in millisecond precision) - # to old signing keys that were formerly in use on this domain name. These - # keys will not be used for federation request or event signing, but will be - # provided to any other homeserver that asks when trying to verify old events. - old_private_keys: - # If the old private key file is available: - # - private_key: old_matrix_key.pem - # expired_at: 1601024554498 - # If only the public key (in base64 format) and key ID are known: - # - public_key: mn59Kxfdq9VziYHSBzI7+EDPDcBS2Xl7jeUdiiQcOnM= - # key_id: ed25519:mykeyid - # expired_at: 1601024554498 - - # How long a remote server can cache our server signing key before requesting it - # again. Increasing this number will reduce the number of requests made by other - # servers for our key but increases the period that a compromised key will be - # considered valid by other homeservers. - key_validity_period: 168h0m0s - - # Configuration for in-memory caches. Caches can often improve performance by - # keeping frequently accessed items (like events, identifiers etc.) in memory - # rather than having to read them from the database. - cache: - # The estimated maximum size for the global cache in bytes, or in terabytes, - # gigabytes, megabytes or kilobytes when the appropriate 'tb', 'gb', 'mb' or - # 'kb' suffix is specified. Note that this is not a hard limit, nor is it a - # memory limit for the entire process. A cache that is too small may ultimately - # provide little or no benefit. - max_size_estimated: 1gb - - # The maximum amount of time that a cache entry can live for in memory before - # it will be evicted and/or refreshed from the database. Lower values result in - # easier admission of new cache entries but may also increase database load in - # comparison to higher values, so adjust conservatively. Higher values may make - # it harder for new items to make it into the cache, e.g. if new rooms suddenly - # become popular. - max_age: 1h - - # The server name to delegate server-server communications to, with optional port - # e.g. localhost:443 - well_known_server_name: "" - - # The server name to delegate client-server communications to, with optional port - # e.g. localhost:443 - well_known_client_name: "" - - # Lists of domains that the server will trust as identity servers to verify third - # party identifiers such as phone numbers and email addresses. - trusted_third_party_id_servers: - - matrix.org - - vector.im - - # Disables federation. Dendrite will not be able to communicate with other servers - # in the Matrix federation and the federation API will not be exposed. - disable_federation: false - - # Configures the handling of presence events. Inbound controls whether we receive - # presence events from other servers, outbound controls whether we send presence - # events for our local users to other servers. - presence: - enable_inbound: false - enable_outbound: false - - # Configures phone-home statistics reporting. These statistics contain the server - # name, number of active users and some information on your deployment config. - # We use this information to understand how Dendrite is being used in the wild. - report_stats: - enabled: false - endpoint: https://matrix.org/report-usage-stats/push - - # Server notices allows server admins to send messages to all users on the server. - server_notices: - enabled: false - # The local part, display name and avatar URL (as a mxc:// URL) for the user that - # will send the server notices. These are visible to all users on the deployment. - local_part: "_server" - display_name: "Server Alerts" - avatar_url: "" - # The room name to be used when sending server notices. This room name will - # appear in user clients. - room_name: "Server Alerts" - - # Configuration for NATS JetStream - jetstream: - # A list of NATS Server addresses to connect to. If none are specified, an - # internal NATS server will be started automatically when running Dendrite in - # monolith mode. For polylith deployments, it is required to specify the address - # of at least one NATS Server node. - addresses: - - hostname:4222 - - # Disable the validation of TLS certificates of NATS. This is - # not recommended in production since it may allow NATS traffic - # to be sent to an insecure endpoint. - disable_tls_validation: false - - # The prefix to use for stream names for this homeserver - really only useful - # if you are running more than one Dendrite server on the same NATS deployment. - topic_prefix: Dendrite - - # Configuration for Prometheus metric collection. - metrics: - enabled: false - basic_auth: - username: metrics - password: metrics - - # Optional DNS cache. The DNS cache may reduce the load on DNS servers if there - # is no local caching resolver available for use. - dns_cache: - enabled: false - cache_size: 256 - cache_lifetime: "5m" # 5 minutes; https://pkg.go.dev/time@master#ParseDuration - -# Configuration for the Appservice API. -app_service_api: - internal_api: - listen: http://[::]:7777 # The listen address for incoming API requests - connect: http://app_service_api:7777 # The connect address for other components to use - - # Disable the validation of TLS certificates of appservices. This is - # not recommended in production since it may allow appservice traffic - # to be sent to an insecure endpoint. - disable_tls_validation: false - - # Appservice configuration files to load into this homeserver. - config_files: - # - /path/to/appservice_registration.yaml - -# Configuration for the Client API. -client_api: - internal_api: - listen: http://[::]:7771 # The listen address for incoming API requests - connect: http://client_api:7771 # The connect address for other components to use - external_api: - listen: http://[::]:8071 - - # Prevents new users from being able to register on this homeserver, except when - # using the registration shared secret below. - registration_disabled: true - - # Prevents new guest accounts from being created. Guest registration is also - # disabled implicitly by setting 'registration_disabled' above. - guests_disabled: true - - # If set, allows registration by anyone who knows the shared secret, regardless - # of whether registration is otherwise disabled. - registration_shared_secret: "" - - # Whether to require reCAPTCHA for registration. If you have enabled registration - # then this is HIGHLY RECOMMENDED to reduce the risk of your homeserver being used - # for coordinated spam attacks. - enable_registration_captcha: false - - # Settings for ReCAPTCHA. - recaptcha_public_key: "" - recaptcha_private_key: "" - recaptcha_bypass_secret: "" - - # To use hcaptcha.com instead of ReCAPTCHA, set the following parameters, otherwise just keep them empty. - # recaptcha_siteverify_api: "https://hcaptcha.com/siteverify" - # recaptcha_api_js_url: "https://js.hcaptcha.com/1/api.js" - # recaptcha_form_field: "h-captcha-response" - # recaptcha_sitekey_class: "h-captcha" - - - # TURN server information that this homeserver should send to clients. - turn: - turn_user_lifetime: "5m" - turn_uris: - # - turn:turn.server.org?transport=udp - # - turn:turn.server.org?transport=tcp - turn_shared_secret: "" - # If your TURN server requires static credentials, then you will need to enter - # them here instead of supplying a shared secret. Note that these credentials - # will be visible to clients! - # turn_username: "" - # turn_password: "" - - # Settings for rate-limited endpoints. Rate limiting kicks in after the threshold - # number of "slots" have been taken by requests from a specific host. Each "slot" - # will be released after the cooloff time in milliseconds. Server administrators - # and appservice users are exempt from rate limiting by default. - rate_limiting: - enabled: true - threshold: 20 - cooloff_ms: 500 - exempt_user_ids: - # - "@user:domain.com" - -# Configuration for the Federation API. -federation_api: - internal_api: - listen: http://[::]:7772 # The listen address for incoming API requests - connect: http://federation_api:7772 # The connect address for other components to use - external_api: - listen: http://[::]:8072 - database: - connection_string: postgresql://username:password@hostname/dendrite_federationapi?sslmode=disable - max_open_conns: 10 - max_idle_conns: 2 - conn_max_lifetime: -1 - - # How many times we will try to resend a failed transaction to a specific server. The - # backoff is 2**x seconds, so 1 = 2 seconds, 2 = 4 seconds, 3 = 8 seconds etc. Once - # the max retries are exceeded, Dendrite will no longer try to send transactions to - # that server until it comes back to life and connects to us again. - send_max_retries: 16 - - # Disable the validation of TLS certificates of remote federated homeservers. Do not - # enable this option in production as it presents a security risk! - disable_tls_validation: false - - # Disable HTTP keepalives, which also prevents connection reuse. Dendrite will typically - # keep HTTP connections open to remote hosts for 5 minutes as they can be reused much - # more quickly than opening new connections each time. Disabling keepalives will close - # HTTP connections immediately after a successful request but may result in more CPU and - # memory being used on TLS handshakes for each new connection instead. - disable_http_keepalives: false - - # Perspective keyservers to use as a backup when direct key fetches fail. This may - # be required to satisfy key requests for servers that are no longer online when - # joining some rooms. - key_perspectives: - - server_name: matrix.org - keys: - - key_id: ed25519:auto - public_key: Noi6WqcDj0QmPxCNQqgezwTlBKrfqehY1u2FyWP9uYw - - key_id: ed25519:a_RXGa - public_key: l8Hft5qXKn1vfHrg3p4+W8gELQVo8N13JkluMfmn2sQ - - # This option will control whether Dendrite will prefer to look up keys directly - # or whether it should try perspective servers first, using direct fetches as a - # last resort. - prefer_direct_fetch: false - -# Configuration for the Key Server (for end-to-end encryption). -key_server: - internal_api: - listen: http://[::]:7779 # The listen address for incoming API requests - connect: http://key_server:7779 # The connect address for other components to use - database: - connection_string: postgresql://username:password@hostname/dendrite_keyserver?sslmode=disable - max_open_conns: 10 - max_idle_conns: 2 - conn_max_lifetime: -1 - -# Configuration for the Media API. -media_api: - internal_api: - listen: http://[::]:7774 # The listen address for incoming API requests - connect: http://media_api:7774 # The connect address for other components to use - external_api: - listen: http://[::]:8074 - database: - connection_string: postgresql://username:password@hostname/dendrite_mediaapi?sslmode=disable - max_open_conns: 5 - max_idle_conns: 2 - conn_max_lifetime: -1 - - # Storage path for uploaded media. May be relative or absolute. - base_path: ./media_store - - # The maximum allowed file size (in bytes) for media uploads to this homeserver - # (0 = unlimited). If using a reverse proxy, ensure it allows requests at least - #this large (e.g. the client_max_body_size setting in nginx). - max_file_size_bytes: 10485760 - - # Whether to dynamically generate thumbnails if needed. - dynamic_thumbnails: false - - # The maximum number of simultaneous thumbnail generators to run. - max_thumbnail_generators: 10 - - # A list of thumbnail sizes to be generated for media content. - thumbnail_sizes: - - width: 32 - height: 32 - method: crop - - width: 96 - height: 96 - method: crop - - width: 640 - height: 480 - method: scale - -# Configuration for enabling experimental MSCs on this homeserver. -mscs: - mscs: - # - msc2836 # (Threading, see https://github.com/matrix-org/matrix-doc/pull/2836) - # - msc2946 # (Spaces Summary, see https://github.com/matrix-org/matrix-doc/pull/2946) - database: - connection_string: postgresql://username:password@hostname/dendrite_mscs?sslmode=disable - max_open_conns: 5 - max_idle_conns: 2 - conn_max_lifetime: -1 - -# Configuration for the Room Server. -room_server: - internal_api: - listen: http://[::]:7770 # The listen address for incoming API requests - connect: http://room_server:7770 # The connect address for other components to use - database: - connection_string: postgresql://username:password@hostname/dendrite_roomserver?sslmode=disable - max_open_conns: 10 - max_idle_conns: 2 - conn_max_lifetime: -1 - -# Configuration for the Sync API. -sync_api: - internal_api: - listen: http://[::]:7773 # The listen address for incoming API requests - connect: http://sync_api:7773 # The connect address for other components to use - external_api: - listen: http://[::]:8073 - database: - connection_string: postgresql://username:password@hostname/dendrite_syncapi?sslmode=disable - max_open_conns: 10 - max_idle_conns: 2 - conn_max_lifetime: -1 - - # Configuration for the full-text search engine. - search: - # Whether or not search is enabled. - enabled: false - - # The path where the search index will be created in. - index_path: "./searchindex" - - # The language most likely to be used on the server - used when indexing, to - # ensure the returned results match expectations. A full list of possible languages - # can be found at https://github.com/blevesearch/bleve/tree/master/analysis/lang - language: "en" - - # This option controls which HTTP header to inspect to find the real remote IP - # address of the client. This is likely required if Dendrite is running behind - # a reverse proxy server. - # real_ip_header: X-Real-IP - -# Configuration for the User API. -user_api: - internal_api: - listen: http://[::]:7781 # The listen address for incoming API requests - connect: http://user_api:7781 # The connect address for other components to use - account_database: - connection_string: postgresql://username:password@hostname/dendrite_userapi?sslmode=disable - max_open_conns: 10 - max_idle_conns: 2 - conn_max_lifetime: -1 - - # The cost when hashing passwords on registration/login. Default: 10. Min: 4, Max: 31 - # See https://pkg.go.dev/golang.org/x/crypto/bcrypt for more information. - # Setting this lower makes registration/login consume less CPU resources at the cost - # of security should the database be compromised. Setting this higher makes registration/login - # consume more CPU resources but makes it harder to brute force password hashes. This value - # can be lowered if performing tests or on embedded Dendrite instances (e.g WASM builds). - bcrypt_cost: 10 - - # The length of time that a token issued for a relying party from - # /_matrix/client/r0/user/{userId}/openid/request_token endpoint - # is considered to be valid in milliseconds. - # The default lifetime is 3600000ms (60 minutes). - # openid_token_lifetime_ms: 3600000 - - # Users who register on this homeserver will automatically be joined to the rooms listed under "auto_join_rooms" option. - # By default, any room aliases included in this list will be created as a publicly joinable room - # when the first user registers for the homeserver. If the room already exists, - # make certain it is a publicly joinable room, i.e. the join rule of the room must be set to 'public'. - # As Spaces are just rooms under the hood, Space aliases may also be used. - auto_join_rooms: - # - "#main:matrix.org" - -# Configuration for Opentracing. -# See https://github.com/matrix-org/dendrite/tree/master/docs/tracing for information on -# how this works and how to set it up. -tracing: - enabled: false - jaeger: - serviceName: "" - disabled: false - rpc_metrics: false - tags: [] - sampler: null - reporter: null - headers: null - baggage_restrictions: null - throttler: null - -# Logging configuration. The "std" logging type controls the logs being sent to -# stdout. The "file" logging type controls logs being written to a log folder on -# the disk. Supported log levels are "debug", "info", "warn", "error". -logging: - - type: std - level: info - - type: file - level: info - params: - path: ./logs diff --git a/dendrite-sample.monolith.yaml b/dendrite-sample.yaml similarity index 99% rename from dendrite-sample.monolith.yaml rename to dendrite-sample.yaml index d86e9da94..50663ef00 100644 --- a/dendrite-sample.monolith.yaml +++ b/dendrite-sample.yaml @@ -38,7 +38,7 @@ global: # Global database connection pool, for PostgreSQL monolith deployments only. If # this section is populated then you can omit the "database" blocks in all other - # sections. For polylith deployments, or monolith deployments using SQLite databases, + # sections. For monolith deployments using SQLite databases, # you must configure the "database" block for each component instead. database: connection_string: postgresql://username:password@hostname/dendrite?sslmode=disable diff --git a/federationapi/federationapi.go b/federationapi/federationapi.go index ed9a545d6..108039167 100644 --- a/federationapi/federationapi.go +++ b/federationapi/federationapi.go @@ -17,14 +17,12 @@ package federationapi import ( "time" - "github.com/gorilla/mux" "github.com/sirupsen/logrus" "github.com/matrix-org/dendrite/federationapi/api" federationAPI "github.com/matrix-org/dendrite/federationapi/api" "github.com/matrix-org/dendrite/federationapi/consumers" "github.com/matrix-org/dendrite/federationapi/internal" - "github.com/matrix-org/dendrite/federationapi/inthttp" "github.com/matrix-org/dendrite/federationapi/producers" "github.com/matrix-org/dendrite/federationapi/queue" "github.com/matrix-org/dendrite/federationapi/statistics" @@ -41,12 +39,6 @@ import ( "github.com/matrix-org/dendrite/federationapi/routing" ) -// AddInternalRoutes registers HTTP handlers for the internal API. Invokes functions -// on the given input API. -func AddInternalRoutes(router *mux.Router, intAPI api.FederationInternalAPI, enableMetrics bool) { - inthttp.AddRoutes(intAPI, router, enableMetrics) -} - // AddPublicRoutes sets up and registers HTTP handlers on the base API muxes for the FederationAPI component. func AddPublicRoutes( base *base.BaseDendrite, diff --git a/federationapi/federationapi_keys_test.go b/federationapi/federationapi_keys_test.go index cc03cdece..8e56b846c 100644 --- a/federationapi/federationapi_keys_test.go +++ b/federationapi/federationapi_keys_test.go @@ -77,8 +77,8 @@ func TestMain(m *testing.M) { // API to work. cfg := &config.Dendrite{} cfg.Defaults(config.DefaultOpts{ - Generate: true, - Monolithic: true, + Generate: true, + SingleDatabase: true, }) cfg.Global.ServerName = gomatrixserverlib.ServerName(s.name) cfg.Global.PrivateKey = testPriv diff --git a/federationapi/federationapi_test.go b/federationapi/federationapi_test.go index 7009230cc..01c251c2a 100644 --- a/federationapi/federationapi_test.go +++ b/federationapi/federationapi_test.go @@ -266,8 +266,8 @@ func TestRoomsV3URLEscapeDoNot404(t *testing.T) { _, privKey, _ := ed25519.GenerateKey(nil) cfg := &config.Dendrite{} cfg.Defaults(config.DefaultOpts{ - Generate: true, - Monolithic: true, + Generate: true, + SingleDatabase: true, }) cfg.Global.KeyID = gomatrixserverlib.KeyID("ed25519:auto") cfg.Global.ServerName = gomatrixserverlib.ServerName("localhost") diff --git a/federationapi/internal/perform.go b/federationapi/internal/perform.go index b9684f767..dadb2b2b3 100644 --- a/federationapi/internal/perform.go +++ b/federationapi/internal/perform.go @@ -121,8 +121,6 @@ func (r *FederationInternalAPI) PerformJoin( var httpErr gomatrix.HTTPError if ok := errors.As(lastErr, &httpErr); ok { httpErr.Message = string(httpErr.Contents) - // Clear the wrapped error, else serialising to JSON (in polylith mode) will fail - httpErr.WrappedError = nil response.LastError = &httpErr } else { response.LastError = &gomatrix.HTTPError{ @@ -391,8 +389,6 @@ func (r *FederationInternalAPI) PerformOutboundPeek( var httpErr gomatrix.HTTPError if ok := errors.As(lastErr, &httpErr); ok { httpErr.Message = string(httpErr.Contents) - // Clear the wrapped error, else serialising to JSON (in polylith mode) will fail - httpErr.WrappedError = nil response.LastError = &httpErr } else { response.LastError = &gomatrix.HTTPError{ diff --git a/federationapi/inthttp/client.go b/federationapi/inthttp/client.go deleted file mode 100644 index 00e069d1e..000000000 --- a/federationapi/inthttp/client.go +++ /dev/null @@ -1,548 +0,0 @@ -package inthttp - -import ( - "context" - "errors" - "net/http" - - "github.com/matrix-org/dendrite/federationapi/api" - "github.com/matrix-org/dendrite/internal/caching" - "github.com/matrix-org/dendrite/internal/httputil" - "github.com/matrix-org/gomatrix" - "github.com/matrix-org/gomatrixserverlib" -) - -// HTTP paths for the internal HTTP API -const ( - FederationAPIQueryJoinedHostServerNamesInRoomPath = "/federationapi/queryJoinedHostServerNamesInRoom" - FederationAPIQueryServerKeysPath = "/federationapi/queryServerKeys" - - FederationAPIPerformDirectoryLookupRequestPath = "/federationapi/performDirectoryLookup" - FederationAPIPerformJoinRequestPath = "/federationapi/performJoinRequest" - FederationAPIPerformLeaveRequestPath = "/federationapi/performLeaveRequest" - FederationAPIPerformInviteRequestPath = "/federationapi/performInviteRequest" - FederationAPIPerformOutboundPeekRequestPath = "/federationapi/performOutboundPeekRequest" - FederationAPIPerformBroadcastEDUPath = "/federationapi/performBroadcastEDU" - FederationAPIPerformWakeupServers = "/federationapi/performWakeupServers" - FederationAPIQueryRelayServers = "/federationapi/queryRelayServers" - FederationAPIAddRelayServers = "/federationapi/addRelayServers" - FederationAPIRemoveRelayServers = "/federationapi/removeRelayServers" - - FederationAPIGetUserDevicesPath = "/federationapi/client/getUserDevices" - FederationAPIClaimKeysPath = "/federationapi/client/claimKeys" - FederationAPIQueryKeysPath = "/federationapi/client/queryKeys" - FederationAPIBackfillPath = "/federationapi/client/backfill" - FederationAPILookupStatePath = "/federationapi/client/lookupState" - FederationAPILookupStateIDsPath = "/federationapi/client/lookupStateIDs" - FederationAPILookupMissingEventsPath = "/federationapi/client/lookupMissingEvents" - FederationAPIGetEventPath = "/federationapi/client/getEvent" - FederationAPILookupServerKeysPath = "/federationapi/client/lookupServerKeys" - FederationAPIEventRelationshipsPath = "/federationapi/client/msc2836eventRelationships" - FederationAPISpacesSummaryPath = "/federationapi/client/msc2946spacesSummary" - FederationAPIGetEventAuthPath = "/federationapi/client/getEventAuth" - - FederationAPIInputPublicKeyPath = "/federationapi/inputPublicKey" - FederationAPIQueryPublicKeyPath = "/federationapi/queryPublicKey" -) - -// NewFederationAPIClient creates a FederationInternalAPI implemented by talking to a HTTP POST API. -// If httpClient is nil an error is returned -func NewFederationAPIClient(federationSenderURL string, httpClient *http.Client, cache caching.ServerKeyCache) (api.FederationInternalAPI, error) { - if httpClient == nil { - return nil, errors.New("NewFederationInternalAPIHTTP: httpClient is ") - } - return &httpFederationInternalAPI{ - federationAPIURL: federationSenderURL, - httpClient: httpClient, - cache: cache, - }, nil -} - -type httpFederationInternalAPI struct { - federationAPIURL string - httpClient *http.Client - cache caching.ServerKeyCache -} - -// Handle an instruction to make_leave & send_leave with a remote server. -func (h *httpFederationInternalAPI) PerformLeave( - ctx context.Context, - request *api.PerformLeaveRequest, - response *api.PerformLeaveResponse, -) error { - return httputil.CallInternalRPCAPI( - "PerformLeave", h.federationAPIURL+FederationAPIPerformLeaveRequestPath, - h.httpClient, ctx, request, response, - ) -} - -// Handle sending an invite to a remote server. -func (h *httpFederationInternalAPI) PerformInvite( - ctx context.Context, - request *api.PerformInviteRequest, - response *api.PerformInviteResponse, -) error { - return httputil.CallInternalRPCAPI( - "PerformInvite", h.federationAPIURL+FederationAPIPerformInviteRequestPath, - h.httpClient, ctx, request, response, - ) -} - -// Handle starting a peek on a remote server. -func (h *httpFederationInternalAPI) PerformOutboundPeek( - ctx context.Context, - request *api.PerformOutboundPeekRequest, - response *api.PerformOutboundPeekResponse, -) error { - return httputil.CallInternalRPCAPI( - "PerformOutboundPeek", h.federationAPIURL+FederationAPIPerformOutboundPeekRequestPath, - h.httpClient, ctx, request, response, - ) -} - -// QueryJoinedHostServerNamesInRoom implements FederationInternalAPI -func (h *httpFederationInternalAPI) QueryJoinedHostServerNamesInRoom( - ctx context.Context, - request *api.QueryJoinedHostServerNamesInRoomRequest, - response *api.QueryJoinedHostServerNamesInRoomResponse, -) error { - return httputil.CallInternalRPCAPI( - "QueryJoinedHostServerNamesInRoom", h.federationAPIURL+FederationAPIQueryJoinedHostServerNamesInRoomPath, - h.httpClient, ctx, request, response, - ) -} - -// Handle an instruction to make_join & send_join with a remote server. -func (h *httpFederationInternalAPI) PerformJoin( - ctx context.Context, - request *api.PerformJoinRequest, - response *api.PerformJoinResponse, -) { - if err := httputil.CallInternalRPCAPI( - "PerformJoinRequest", h.federationAPIURL+FederationAPIPerformJoinRequestPath, - h.httpClient, ctx, request, response, - ); err != nil { - response.LastError = &gomatrix.HTTPError{ - Message: err.Error(), - Code: 0, - WrappedError: err, - } - } -} - -// Handle an instruction to make_join & send_join with a remote server. -func (h *httpFederationInternalAPI) PerformDirectoryLookup( - ctx context.Context, - request *api.PerformDirectoryLookupRequest, - response *api.PerformDirectoryLookupResponse, -) error { - return httputil.CallInternalRPCAPI( - "PerformDirectoryLookup", h.federationAPIURL+FederationAPIPerformDirectoryLookupRequestPath, - h.httpClient, ctx, request, response, - ) -} - -// Handle an instruction to broadcast an EDU to all servers in rooms we are joined to. -func (h *httpFederationInternalAPI) PerformBroadcastEDU( - ctx context.Context, - request *api.PerformBroadcastEDURequest, - response *api.PerformBroadcastEDUResponse, -) error { - return httputil.CallInternalRPCAPI( - "PerformBroadcastEDU", h.federationAPIURL+FederationAPIPerformBroadcastEDUPath, - h.httpClient, ctx, request, response, - ) -} - -// Handle an instruction to remove the respective servers from being blacklisted. -func (h *httpFederationInternalAPI) PerformWakeupServers( - ctx context.Context, - request *api.PerformWakeupServersRequest, - response *api.PerformWakeupServersResponse, -) error { - return httputil.CallInternalRPCAPI( - "PerformWakeupServers", h.federationAPIURL+FederationAPIPerformWakeupServers, - h.httpClient, ctx, request, response, - ) -} - -type getUserDevices struct { - S gomatrixserverlib.ServerName - Origin gomatrixserverlib.ServerName - UserID string -} - -func (h *httpFederationInternalAPI) GetUserDevices( - ctx context.Context, origin, s gomatrixserverlib.ServerName, userID string, -) (gomatrixserverlib.RespUserDevices, error) { - return httputil.CallInternalProxyAPI[getUserDevices, gomatrixserverlib.RespUserDevices, *api.FederationClientError]( - "GetUserDevices", h.federationAPIURL+FederationAPIGetUserDevicesPath, h.httpClient, - ctx, &getUserDevices{ - S: s, - Origin: origin, - UserID: userID, - }, - ) -} - -type claimKeys struct { - S gomatrixserverlib.ServerName - Origin gomatrixserverlib.ServerName - OneTimeKeys map[string]map[string]string -} - -func (h *httpFederationInternalAPI) ClaimKeys( - ctx context.Context, origin, s gomatrixserverlib.ServerName, oneTimeKeys map[string]map[string]string, -) (gomatrixserverlib.RespClaimKeys, error) { - return httputil.CallInternalProxyAPI[claimKeys, gomatrixserverlib.RespClaimKeys, *api.FederationClientError]( - "ClaimKeys", h.federationAPIURL+FederationAPIClaimKeysPath, h.httpClient, - ctx, &claimKeys{ - S: s, - Origin: origin, - OneTimeKeys: oneTimeKeys, - }, - ) -} - -type queryKeys struct { - S gomatrixserverlib.ServerName - Origin gomatrixserverlib.ServerName - Keys map[string][]string -} - -func (h *httpFederationInternalAPI) QueryKeys( - ctx context.Context, origin, s gomatrixserverlib.ServerName, keys map[string][]string, -) (gomatrixserverlib.RespQueryKeys, error) { - return httputil.CallInternalProxyAPI[queryKeys, gomatrixserverlib.RespQueryKeys, *api.FederationClientError]( - "QueryKeys", h.federationAPIURL+FederationAPIQueryKeysPath, h.httpClient, - ctx, &queryKeys{ - S: s, - Origin: origin, - Keys: keys, - }, - ) -} - -type backfill struct { - S gomatrixserverlib.ServerName - Origin gomatrixserverlib.ServerName - RoomID string - Limit int - EventIDs []string -} - -func (h *httpFederationInternalAPI) Backfill( - ctx context.Context, origin, s gomatrixserverlib.ServerName, roomID string, limit int, eventIDs []string, -) (gomatrixserverlib.Transaction, error) { - return httputil.CallInternalProxyAPI[backfill, gomatrixserverlib.Transaction, *api.FederationClientError]( - "Backfill", h.federationAPIURL+FederationAPIBackfillPath, h.httpClient, - ctx, &backfill{ - S: s, - Origin: origin, - RoomID: roomID, - Limit: limit, - EventIDs: eventIDs, - }, - ) -} - -type lookupState struct { - S gomatrixserverlib.ServerName - Origin gomatrixserverlib.ServerName - RoomID string - EventID string - RoomVersion gomatrixserverlib.RoomVersion -} - -func (h *httpFederationInternalAPI) LookupState( - ctx context.Context, origin, s gomatrixserverlib.ServerName, roomID, eventID string, roomVersion gomatrixserverlib.RoomVersion, -) (gomatrixserverlib.RespState, error) { - return httputil.CallInternalProxyAPI[lookupState, gomatrixserverlib.RespState, *api.FederationClientError]( - "LookupState", h.federationAPIURL+FederationAPILookupStatePath, h.httpClient, - ctx, &lookupState{ - S: s, - Origin: origin, - RoomID: roomID, - EventID: eventID, - RoomVersion: roomVersion, - }, - ) -} - -type lookupStateIDs struct { - S gomatrixserverlib.ServerName - Origin gomatrixserverlib.ServerName - RoomID string - EventID string -} - -func (h *httpFederationInternalAPI) LookupStateIDs( - ctx context.Context, origin, s gomatrixserverlib.ServerName, roomID, eventID string, -) (gomatrixserverlib.RespStateIDs, error) { - return httputil.CallInternalProxyAPI[lookupStateIDs, gomatrixserverlib.RespStateIDs, *api.FederationClientError]( - "LookupStateIDs", h.federationAPIURL+FederationAPILookupStateIDsPath, h.httpClient, - ctx, &lookupStateIDs{ - S: s, - Origin: origin, - RoomID: roomID, - EventID: eventID, - }, - ) -} - -type lookupMissingEvents struct { - S gomatrixserverlib.ServerName - Origin gomatrixserverlib.ServerName - RoomID string - Missing gomatrixserverlib.MissingEvents - RoomVersion gomatrixserverlib.RoomVersion -} - -func (h *httpFederationInternalAPI) LookupMissingEvents( - ctx context.Context, origin, s gomatrixserverlib.ServerName, roomID string, - missing gomatrixserverlib.MissingEvents, roomVersion gomatrixserverlib.RoomVersion, -) (res gomatrixserverlib.RespMissingEvents, err error) { - return httputil.CallInternalProxyAPI[lookupMissingEvents, gomatrixserverlib.RespMissingEvents, *api.FederationClientError]( - "LookupMissingEvents", h.federationAPIURL+FederationAPILookupMissingEventsPath, h.httpClient, - ctx, &lookupMissingEvents{ - S: s, - Origin: origin, - RoomID: roomID, - Missing: missing, - RoomVersion: roomVersion, - }, - ) -} - -type getEvent struct { - S gomatrixserverlib.ServerName - Origin gomatrixserverlib.ServerName - EventID string -} - -func (h *httpFederationInternalAPI) GetEvent( - ctx context.Context, origin, s gomatrixserverlib.ServerName, eventID string, -) (gomatrixserverlib.Transaction, error) { - return httputil.CallInternalProxyAPI[getEvent, gomatrixserverlib.Transaction, *api.FederationClientError]( - "GetEvent", h.federationAPIURL+FederationAPIGetEventPath, h.httpClient, - ctx, &getEvent{ - S: s, - Origin: origin, - EventID: eventID, - }, - ) -} - -type getEventAuth struct { - S gomatrixserverlib.ServerName - Origin gomatrixserverlib.ServerName - RoomVersion gomatrixserverlib.RoomVersion - RoomID string - EventID string -} - -func (h *httpFederationInternalAPI) GetEventAuth( - ctx context.Context, origin, s gomatrixserverlib.ServerName, - roomVersion gomatrixserverlib.RoomVersion, roomID, eventID string, -) (gomatrixserverlib.RespEventAuth, error) { - return httputil.CallInternalProxyAPI[getEventAuth, gomatrixserverlib.RespEventAuth, *api.FederationClientError]( - "GetEventAuth", h.federationAPIURL+FederationAPIGetEventAuthPath, h.httpClient, - ctx, &getEventAuth{ - S: s, - Origin: origin, - RoomVersion: roomVersion, - RoomID: roomID, - EventID: eventID, - }, - ) -} - -func (h *httpFederationInternalAPI) QueryServerKeys( - ctx context.Context, req *api.QueryServerKeysRequest, res *api.QueryServerKeysResponse, -) error { - return httputil.CallInternalRPCAPI( - "QueryServerKeys", h.federationAPIURL+FederationAPIQueryServerKeysPath, - h.httpClient, ctx, req, res, - ) -} - -type lookupServerKeys struct { - S gomatrixserverlib.ServerName - KeyRequests map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.Timestamp -} - -func (h *httpFederationInternalAPI) LookupServerKeys( - ctx context.Context, s gomatrixserverlib.ServerName, keyRequests map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.Timestamp, -) ([]gomatrixserverlib.ServerKeys, error) { - return httputil.CallInternalProxyAPI[lookupServerKeys, []gomatrixserverlib.ServerKeys, *api.FederationClientError]( - "LookupServerKeys", h.federationAPIURL+FederationAPILookupServerKeysPath, h.httpClient, - ctx, &lookupServerKeys{ - S: s, - KeyRequests: keyRequests, - }, - ) -} - -type eventRelationships struct { - S gomatrixserverlib.ServerName - Origin gomatrixserverlib.ServerName - Req gomatrixserverlib.MSC2836EventRelationshipsRequest - RoomVer gomatrixserverlib.RoomVersion -} - -func (h *httpFederationInternalAPI) MSC2836EventRelationships( - ctx context.Context, origin, s gomatrixserverlib.ServerName, r gomatrixserverlib.MSC2836EventRelationshipsRequest, - roomVersion gomatrixserverlib.RoomVersion, -) (res gomatrixserverlib.MSC2836EventRelationshipsResponse, err error) { - return httputil.CallInternalProxyAPI[eventRelationships, gomatrixserverlib.MSC2836EventRelationshipsResponse, *api.FederationClientError]( - "MSC2836EventRelationships", h.federationAPIURL+FederationAPIEventRelationshipsPath, h.httpClient, - ctx, &eventRelationships{ - S: s, - Origin: origin, - Req: r, - RoomVer: roomVersion, - }, - ) -} - -type spacesReq struct { - S gomatrixserverlib.ServerName - Origin gomatrixserverlib.ServerName - SuggestedOnly bool - RoomID string -} - -func (h *httpFederationInternalAPI) MSC2946Spaces( - ctx context.Context, origin, dst gomatrixserverlib.ServerName, roomID string, suggestedOnly bool, -) (res gomatrixserverlib.MSC2946SpacesResponse, err error) { - return httputil.CallInternalProxyAPI[spacesReq, gomatrixserverlib.MSC2946SpacesResponse, *api.FederationClientError]( - "MSC2836EventRelationships", h.federationAPIURL+FederationAPISpacesSummaryPath, h.httpClient, - ctx, &spacesReq{ - S: dst, - Origin: origin, - SuggestedOnly: suggestedOnly, - RoomID: roomID, - }, - ) -} - -func (s *httpFederationInternalAPI) KeyRing() *gomatrixserverlib.KeyRing { - // This is a bit of a cheat - we tell gomatrixserverlib that this API is - // both the key database and the key fetcher. While this does have the - // rather unfortunate effect of preventing gomatrixserverlib from handling - // key fetchers directly, we can at least reimplement this behaviour on - // the other end of the API. - return &gomatrixserverlib.KeyRing{ - KeyDatabase: s, - KeyFetchers: []gomatrixserverlib.KeyFetcher{}, - } -} - -func (s *httpFederationInternalAPI) FetcherName() string { - return "httpServerKeyInternalAPI" -} - -func (s *httpFederationInternalAPI) StoreKeys( - _ context.Context, - results map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.PublicKeyLookupResult, -) error { - // Run in a background context - we don't want to stop this work just - // because the caller gives up waiting. - ctx := context.Background() - request := api.InputPublicKeysRequest{ - Keys: make(map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.PublicKeyLookupResult), - } - response := api.InputPublicKeysResponse{} - for req, res := range results { - request.Keys[req] = res - s.cache.StoreServerKey(req, res) - } - return s.InputPublicKeys(ctx, &request, &response) -} - -func (s *httpFederationInternalAPI) FetchKeys( - _ context.Context, - requests map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.Timestamp, -) (map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.PublicKeyLookupResult, error) { - // Run in a background context - we don't want to stop this work just - // because the caller gives up waiting. - ctx := context.Background() - result := make(map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.PublicKeyLookupResult) - request := api.QueryPublicKeysRequest{ - Requests: make(map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.Timestamp), - } - response := api.QueryPublicKeysResponse{ - Results: make(map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.PublicKeyLookupResult), - } - for req, ts := range requests { - if res, ok := s.cache.GetServerKey(req, ts); ok { - result[req] = res - continue - } - request.Requests[req] = ts - } - err := s.QueryPublicKeys(ctx, &request, &response) - if err != nil { - return nil, err - } - for req, res := range response.Results { - result[req] = res - s.cache.StoreServerKey(req, res) - } - return result, nil -} - -func (h *httpFederationInternalAPI) InputPublicKeys( - ctx context.Context, - request *api.InputPublicKeysRequest, - response *api.InputPublicKeysResponse, -) error { - return httputil.CallInternalRPCAPI( - "InputPublicKey", h.federationAPIURL+FederationAPIInputPublicKeyPath, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpFederationInternalAPI) QueryPublicKeys( - ctx context.Context, - request *api.QueryPublicKeysRequest, - response *api.QueryPublicKeysResponse, -) error { - return httputil.CallInternalRPCAPI( - "QueryPublicKeys", h.federationAPIURL+FederationAPIQueryPublicKeyPath, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpFederationInternalAPI) P2PQueryRelayServers( - ctx context.Context, - request *api.P2PQueryRelayServersRequest, - response *api.P2PQueryRelayServersResponse, -) error { - return httputil.CallInternalRPCAPI( - "QueryRelayServers", h.federationAPIURL+FederationAPIQueryRelayServers, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpFederationInternalAPI) P2PAddRelayServers( - ctx context.Context, - request *api.P2PAddRelayServersRequest, - response *api.P2PAddRelayServersResponse, -) error { - return httputil.CallInternalRPCAPI( - "AddRelayServers", h.federationAPIURL+FederationAPIAddRelayServers, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpFederationInternalAPI) P2PRemoveRelayServers( - ctx context.Context, - request *api.P2PRemoveRelayServersRequest, - response *api.P2PRemoveRelayServersResponse, -) error { - return httputil.CallInternalRPCAPI( - "RemoveRelayServers", h.federationAPIURL+FederationAPIRemoveRelayServers, - h.httpClient, ctx, request, response, - ) -} diff --git a/federationapi/inthttp/server.go b/federationapi/inthttp/server.go deleted file mode 100644 index 9068dc400..000000000 --- a/federationapi/inthttp/server.go +++ /dev/null @@ -1,257 +0,0 @@ -package inthttp - -import ( - "context" - "encoding/json" - "net/http" - "net/url" - - "github.com/gorilla/mux" - "github.com/matrix-org/gomatrix" - "github.com/matrix-org/gomatrixserverlib" - "github.com/matrix-org/util" - - "github.com/matrix-org/dendrite/federationapi/api" - "github.com/matrix-org/dendrite/internal/httputil" -) - -// AddRoutes adds the FederationInternalAPI handlers to the http.ServeMux. -// nolint:gocyclo -func AddRoutes(intAPI api.FederationInternalAPI, internalAPIMux *mux.Router, enableMetrics bool) { - internalAPIMux.Handle( - FederationAPIQueryJoinedHostServerNamesInRoomPath, - httputil.MakeInternalRPCAPI("FederationAPIQueryJoinedHostServerNamesInRoom", enableMetrics, intAPI.QueryJoinedHostServerNamesInRoom), - ) - - internalAPIMux.Handle( - FederationAPIPerformInviteRequestPath, - httputil.MakeInternalRPCAPI("FederationAPIPerformInvite", enableMetrics, intAPI.PerformInvite), - ) - - internalAPIMux.Handle( - FederationAPIPerformLeaveRequestPath, - httputil.MakeInternalRPCAPI("FederationAPIPerformLeave", enableMetrics, intAPI.PerformLeave), - ) - - internalAPIMux.Handle( - FederationAPIPerformDirectoryLookupRequestPath, - httputil.MakeInternalRPCAPI("FederationAPIPerformDirectoryLookupRequest", enableMetrics, intAPI.PerformDirectoryLookup), - ) - - internalAPIMux.Handle( - FederationAPIPerformBroadcastEDUPath, - httputil.MakeInternalRPCAPI("FederationAPIPerformBroadcastEDU", enableMetrics, intAPI.PerformBroadcastEDU), - ) - - internalAPIMux.Handle( - FederationAPIPerformWakeupServers, - httputil.MakeInternalRPCAPI("FederationAPIPerformWakeupServers", enableMetrics, intAPI.PerformWakeupServers), - ) - - internalAPIMux.Handle( - FederationAPIPerformJoinRequestPath, - httputil.MakeInternalRPCAPI( - "FederationAPIPerformJoinRequest", enableMetrics, - func(ctx context.Context, req *api.PerformJoinRequest, res *api.PerformJoinResponse) error { - intAPI.PerformJoin(ctx, req, res) - return nil - }, - ), - ) - - internalAPIMux.Handle( - FederationAPIGetUserDevicesPath, - httputil.MakeInternalProxyAPI( - "FederationAPIGetUserDevices", enableMetrics, - func(ctx context.Context, req *getUserDevices) (*gomatrixserverlib.RespUserDevices, error) { - res, err := intAPI.GetUserDevices(ctx, req.Origin, req.S, req.UserID) - return &res, federationClientError(err) - }, - ), - ) - - internalAPIMux.Handle( - FederationAPIClaimKeysPath, - httputil.MakeInternalProxyAPI( - "FederationAPIClaimKeys", enableMetrics, - func(ctx context.Context, req *claimKeys) (*gomatrixserverlib.RespClaimKeys, error) { - res, err := intAPI.ClaimKeys(ctx, req.Origin, req.S, req.OneTimeKeys) - return &res, federationClientError(err) - }, - ), - ) - - internalAPIMux.Handle( - FederationAPIQueryKeysPath, - httputil.MakeInternalProxyAPI( - "FederationAPIQueryKeys", enableMetrics, - func(ctx context.Context, req *queryKeys) (*gomatrixserverlib.RespQueryKeys, error) { - res, err := intAPI.QueryKeys(ctx, req.Origin, req.S, req.Keys) - return &res, federationClientError(err) - }, - ), - ) - - internalAPIMux.Handle( - FederationAPIBackfillPath, - httputil.MakeInternalProxyAPI( - "FederationAPIBackfill", enableMetrics, - func(ctx context.Context, req *backfill) (*gomatrixserverlib.Transaction, error) { - res, err := intAPI.Backfill(ctx, req.Origin, req.S, req.RoomID, req.Limit, req.EventIDs) - return &res, federationClientError(err) - }, - ), - ) - - internalAPIMux.Handle( - FederationAPILookupStatePath, - httputil.MakeInternalProxyAPI( - "FederationAPILookupState", enableMetrics, - func(ctx context.Context, req *lookupState) (*gomatrixserverlib.RespState, error) { - res, err := intAPI.LookupState(ctx, req.Origin, req.S, req.RoomID, req.EventID, req.RoomVersion) - return &res, federationClientError(err) - }, - ), - ) - - internalAPIMux.Handle( - FederationAPILookupStateIDsPath, - httputil.MakeInternalProxyAPI( - "FederationAPILookupStateIDs", enableMetrics, - func(ctx context.Context, req *lookupStateIDs) (*gomatrixserverlib.RespStateIDs, error) { - res, err := intAPI.LookupStateIDs(ctx, req.Origin, req.S, req.RoomID, req.EventID) - return &res, federationClientError(err) - }, - ), - ) - - internalAPIMux.Handle( - FederationAPILookupMissingEventsPath, - httputil.MakeInternalProxyAPI( - "FederationAPILookupMissingEvents", enableMetrics, - func(ctx context.Context, req *lookupMissingEvents) (*gomatrixserverlib.RespMissingEvents, error) { - res, err := intAPI.LookupMissingEvents(ctx, req.Origin, req.S, req.RoomID, req.Missing, req.RoomVersion) - return &res, federationClientError(err) - }, - ), - ) - - internalAPIMux.Handle( - FederationAPIGetEventPath, - httputil.MakeInternalProxyAPI( - "FederationAPIGetEvent", enableMetrics, - func(ctx context.Context, req *getEvent) (*gomatrixserverlib.Transaction, error) { - res, err := intAPI.GetEvent(ctx, req.Origin, req.S, req.EventID) - return &res, federationClientError(err) - }, - ), - ) - - internalAPIMux.Handle( - FederationAPIGetEventAuthPath, - httputil.MakeInternalProxyAPI( - "FederationAPIGetEventAuth", enableMetrics, - func(ctx context.Context, req *getEventAuth) (*gomatrixserverlib.RespEventAuth, error) { - res, err := intAPI.GetEventAuth(ctx, req.Origin, req.S, req.RoomVersion, req.RoomID, req.EventID) - return &res, federationClientError(err) - }, - ), - ) - - internalAPIMux.Handle( - FederationAPIQueryServerKeysPath, - httputil.MakeInternalRPCAPI("FederationAPIQueryServerKeys", enableMetrics, intAPI.QueryServerKeys), - ) - - internalAPIMux.Handle( - FederationAPILookupServerKeysPath, - httputil.MakeInternalProxyAPI( - "FederationAPILookupServerKeys", enableMetrics, - func(ctx context.Context, req *lookupServerKeys) (*[]gomatrixserverlib.ServerKeys, error) { - res, err := intAPI.LookupServerKeys(ctx, req.S, req.KeyRequests) - return &res, federationClientError(err) - }, - ), - ) - - internalAPIMux.Handle( - FederationAPIEventRelationshipsPath, - httputil.MakeInternalProxyAPI( - "FederationAPIMSC2836EventRelationships", enableMetrics, - func(ctx context.Context, req *eventRelationships) (*gomatrixserverlib.MSC2836EventRelationshipsResponse, error) { - res, err := intAPI.MSC2836EventRelationships(ctx, req.Origin, req.S, req.Req, req.RoomVer) - return &res, federationClientError(err) - }, - ), - ) - - internalAPIMux.Handle( - FederationAPISpacesSummaryPath, - httputil.MakeInternalProxyAPI( - "FederationAPIMSC2946SpacesSummary", enableMetrics, - func(ctx context.Context, req *spacesReq) (*gomatrixserverlib.MSC2946SpacesResponse, error) { - res, err := intAPI.MSC2946Spaces(ctx, req.Origin, req.S, req.RoomID, req.SuggestedOnly) - return &res, federationClientError(err) - }, - ), - ) - - // TODO: Look at this shape - internalAPIMux.Handle(FederationAPIQueryPublicKeyPath, - httputil.MakeInternalAPI("FederationAPIQueryPublicKeys", enableMetrics, func(req *http.Request) util.JSONResponse { - request := api.QueryPublicKeysRequest{} - response := api.QueryPublicKeysResponse{} - if err := json.NewDecoder(req.Body).Decode(&request); err != nil { - return util.MessageResponse(http.StatusBadRequest, err.Error()) - } - keys, err := intAPI.FetchKeys(req.Context(), request.Requests) - if err != nil { - return util.ErrorResponse(err) - } - response.Results = keys - return util.JSONResponse{Code: http.StatusOK, JSON: &response} - }), - ) - - // TODO: Look at this shape - internalAPIMux.Handle(FederationAPIInputPublicKeyPath, - httputil.MakeInternalAPI("FederationAPIInputPublicKeys", enableMetrics, func(req *http.Request) util.JSONResponse { - request := api.InputPublicKeysRequest{} - response := api.InputPublicKeysResponse{} - if err := json.NewDecoder(req.Body).Decode(&request); err != nil { - return util.MessageResponse(http.StatusBadRequest, err.Error()) - } - if err := intAPI.StoreKeys(req.Context(), request.Keys); err != nil { - return util.ErrorResponse(err) - } - return util.JSONResponse{Code: http.StatusOK, JSON: &response} - }), - ) -} - -func federationClientError(err error) error { - switch ferr := err.(type) { - case nil: - return nil - case api.FederationClientError: - return &ferr - case *api.FederationClientError: - return ferr - case gomatrix.HTTPError: - return &api.FederationClientError{ - Code: ferr.Code, - } - case *url.Error: // e.g. certificate error, unable to connect - return &api.FederationClientError{ - Err: ferr.Error(), - Code: 400, - } - default: - // We don't know what exactly failed, but we probably don't - // want to retry the request immediately in the device list updater - return &api.FederationClientError{ - Err: err.Error(), - Code: 400, - } - } -} diff --git a/go.mod b/go.mod index 25f022707..f3009326a 100644 --- a/go.mod +++ b/go.mod @@ -46,7 +46,6 @@ require ( golang.org/x/crypto v0.5.0 golang.org/x/image v0.1.0 golang.org/x/mobile v0.0.0-20221020085226-b36e6246172e - golang.org/x/net v0.5.0 golang.org/x/term v0.4.0 gopkg.in/h2non/bimg.v1 v1.1.9 gopkg.in/yaml.v2 v2.4.0 @@ -123,6 +122,7 @@ require ( go.etcd.io/bbolt v1.3.6 // indirect golang.org/x/exp v0.0.0-20221031165847-c99f073a8326 // indirect golang.org/x/mod v0.6.0 // indirect + golang.org/x/net v0.5.0 // indirect golang.org/x/sys v0.4.0 // indirect golang.org/x/text v0.6.0 // indirect golang.org/x/time v0.1.0 // indirect diff --git a/internal/httputil/internalapi.go b/internal/httputil/internalapi.go deleted file mode 100644 index 22f436e38..000000000 --- a/internal/httputil/internalapi.go +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright 2022 The Matrix.org Foundation C.I.C. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package httputil - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "reflect" - - "github.com/matrix-org/util" - "github.com/opentracing/opentracing-go" -) - -type InternalAPIError struct { - Type string - Message string -} - -func (e InternalAPIError) Error() string { - return fmt.Sprintf("internal API returned %q error: %s", e.Type, e.Message) -} - -func MakeInternalRPCAPI[reqtype, restype any](metricsName string, enableMetrics bool, f func(context.Context, *reqtype, *restype) error) http.Handler { - return MakeInternalAPI(metricsName, enableMetrics, func(req *http.Request) util.JSONResponse { - var request reqtype - var response restype - if err := json.NewDecoder(req.Body).Decode(&request); err != nil { - return util.MessageResponse(http.StatusBadRequest, err.Error()) - } - if err := f(req.Context(), &request, &response); err != nil { - return util.JSONResponse{ - Code: http.StatusInternalServerError, - JSON: &InternalAPIError{ - Type: reflect.TypeOf(err).String(), - Message: fmt.Sprintf("%s", err), - }, - } - } - return util.JSONResponse{ - Code: http.StatusOK, - JSON: &response, - } - }) -} - -func MakeInternalProxyAPI[reqtype, restype any](metricsName string, enableMetrics bool, f func(context.Context, *reqtype) (*restype, error)) http.Handler { - return MakeInternalAPI(metricsName, enableMetrics, func(req *http.Request) util.JSONResponse { - var request reqtype - if err := json.NewDecoder(req.Body).Decode(&request); err != nil { - return util.MessageResponse(http.StatusBadRequest, err.Error()) - } - response, err := f(req.Context(), &request) - if err != nil { - return util.JSONResponse{ - Code: http.StatusInternalServerError, - JSON: err, - } - } - return util.JSONResponse{ - Code: http.StatusOK, - JSON: response, - } - }) -} - -func CallInternalRPCAPI[reqtype, restype any](name, url string, client *http.Client, ctx context.Context, request *reqtype, response *restype) error { - span, ctx := opentracing.StartSpanFromContext(ctx, name) - defer span.Finish() - - return PostJSON[reqtype, restype, InternalAPIError](ctx, span, client, url, request, response) -} - -func CallInternalProxyAPI[reqtype, restype any, errtype error](name, url string, client *http.Client, ctx context.Context, request *reqtype) (restype, error) { - span, ctx := opentracing.StartSpanFromContext(ctx, name) - defer span.Finish() - - var response restype - return response, PostJSON[reqtype, restype, errtype](ctx, span, client, url, request, &response) -} diff --git a/internal/log.go b/internal/log.go index 9e8656c5b..8fe98f20c 100644 --- a/internal/log.go +++ b/internal/log.go @@ -129,9 +129,9 @@ func checkFileHookParams(params map[string]interface{}) { } // Add a new FSHook to the logger. Each component will log in its own file -func setupFileHook(hook config.LogrusHook, level logrus.Level, componentName string) { +func setupFileHook(hook config.LogrusHook, level logrus.Level) { dirPath := (hook.Params["path"]).(string) - fullPath := filepath.Join(dirPath, componentName+".log") + fullPath := filepath.Join(dirPath, "dendrite.log") if err := os.MkdirAll(path.Dir(fullPath), os.ModePerm); err != nil { logrus.Fatalf("Couldn't create directory %s: %q", path.Dir(fullPath), err) diff --git a/internal/log_unix.go b/internal/log_unix.go index 859427041..3f15063d1 100644 --- a/internal/log_unix.go +++ b/internal/log_unix.go @@ -31,7 +31,7 @@ import ( // SetupHookLogging configures the logging hooks defined in the configuration. // If something fails here it means that the logging was improperly configured, // so we just exit with the error -func SetupHookLogging(hooks []config.LogrusHook, componentName string) { +func SetupHookLogging(hooks []config.LogrusHook) { levelLogAddedMu.Lock() defer levelLogAddedMu.Unlock() for _, hook := range hooks { @@ -50,10 +50,10 @@ func SetupHookLogging(hooks []config.LogrusHook, componentName string) { switch hook.Type { case "file": checkFileHookParams(hook.Params) - setupFileHook(hook, level, componentName) + setupFileHook(hook, level) case "syslog": checkSyslogHookParams(hook.Params) - setupSyslogHook(hook, level, componentName) + setupSyslogHook(hook, level) case "std": setupStdLogHook(level) default: @@ -94,8 +94,8 @@ func setupStdLogHook(level logrus.Level) { stdLevelLogAdded[level] = true } -func setupSyslogHook(hook config.LogrusHook, level logrus.Level, componentName string) { - syslogHook, err := lSyslog.NewSyslogHook(hook.Params["protocol"].(string), hook.Params["address"].(string), syslog.LOG_INFO, componentName) +func setupSyslogHook(hook config.LogrusHook, level logrus.Level) { + syslogHook, err := lSyslog.NewSyslogHook(hook.Params["protocol"].(string), hook.Params["address"].(string), syslog.LOG_INFO, "dendrite") if err == nil { logrus.AddHook(&logLevelHook{level, syslogHook}) } diff --git a/internal/log_windows.go b/internal/log_windows.go index 39562328c..e1f0098a1 100644 --- a/internal/log_windows.go +++ b/internal/log_windows.go @@ -22,7 +22,7 @@ import ( // SetupHookLogging configures the logging hooks defined in the configuration. // If something fails here it means that the logging was improperly configured, // so we just exit with the error -func SetupHookLogging(hooks []config.LogrusHook, componentName string) { +func SetupHookLogging(hooks []config.LogrusHook) { logrus.SetReportCaller(true) for _, hook := range hooks { // Check we received a proper logging level @@ -40,7 +40,7 @@ func SetupHookLogging(hooks []config.LogrusHook, componentName string) { switch hook.Type { case "file": checkFileHookParams(hook.Params) - setupFileHook(hook, level, componentName) + setupFileHook(hook, level) default: logrus.Fatalf("Unrecognised logging hook type: %s", hook.Type) } diff --git a/internal/transactionrequest_test.go b/internal/transactionrequest_test.go index dd1bd3502..fac2872c1 100644 --- a/internal/transactionrequest_test.go +++ b/internal/transactionrequest_test.go @@ -198,8 +198,8 @@ func TestProcessTransactionRequestPDUSendFail(t *testing.T) { func createTransactionWithEDU(ctx *process.ProcessContext, edus []gomatrixserverlib.EDU) (TxnReq, nats.JetStreamContext, *config.Dendrite) { cfg := &config.Dendrite{} cfg.Defaults(config.DefaultOpts{ - Generate: true, - Monolithic: true, + Generate: true, + SingleDatabase: true, }) cfg.Global.JetStream.InMemory = true natsInstance := &jetstream.NATSInstance{} diff --git a/keyserver/inthttp/client.go b/keyserver/inthttp/client.go deleted file mode 100644 index 75d537d9c..000000000 --- a/keyserver/inthttp/client.go +++ /dev/null @@ -1,186 +0,0 @@ -// Copyright 2020 The Matrix.org Foundation C.I.C. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package inthttp - -import ( - "context" - "errors" - "net/http" - - "github.com/matrix-org/dendrite/internal/httputil" - "github.com/matrix-org/dendrite/keyserver/api" - userapi "github.com/matrix-org/dendrite/userapi/api" -) - -// HTTP paths for the internal HTTP APIs -const ( - InputDeviceListUpdatePath = "/keyserver/inputDeviceListUpdate" - PerformUploadKeysPath = "/keyserver/performUploadKeys" - PerformClaimKeysPath = "/keyserver/performClaimKeys" - PerformDeleteKeysPath = "/keyserver/performDeleteKeys" - PerformUploadDeviceKeysPath = "/keyserver/performUploadDeviceKeys" - PerformUploadDeviceSignaturesPath = "/keyserver/performUploadDeviceSignatures" - QueryKeysPath = "/keyserver/queryKeys" - QueryKeyChangesPath = "/keyserver/queryKeyChanges" - QueryOneTimeKeysPath = "/keyserver/queryOneTimeKeys" - QueryDeviceMessagesPath = "/keyserver/queryDeviceMessages" - QuerySignaturesPath = "/keyserver/querySignatures" - PerformMarkAsStalePath = "/keyserver/markAsStale" -) - -// NewKeyServerClient creates a KeyInternalAPI implemented by talking to a HTTP POST API. -// If httpClient is nil an error is returned -func NewKeyServerClient( - apiURL string, - httpClient *http.Client, -) (api.KeyInternalAPI, error) { - if httpClient == nil { - return nil, errors.New("NewKeyServerClient: httpClient is ") - } - return &httpKeyInternalAPI{ - apiURL: apiURL, - httpClient: httpClient, - }, nil -} - -type httpKeyInternalAPI struct { - apiURL string - httpClient *http.Client -} - -func (h *httpKeyInternalAPI) SetUserAPI(i userapi.KeyserverUserAPI) { - // no-op: doesn't need it -} - -func (h *httpKeyInternalAPI) PerformClaimKeys( - ctx context.Context, - request *api.PerformClaimKeysRequest, - response *api.PerformClaimKeysResponse, -) error { - return httputil.CallInternalRPCAPI( - "PerformClaimKeys", h.apiURL+PerformClaimKeysPath, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpKeyInternalAPI) PerformDeleteKeys( - ctx context.Context, - request *api.PerformDeleteKeysRequest, - response *api.PerformDeleteKeysResponse, -) error { - return httputil.CallInternalRPCAPI( - "PerformDeleteKeys", h.apiURL+PerformDeleteKeysPath, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpKeyInternalAPI) PerformUploadKeys( - ctx context.Context, - request *api.PerformUploadKeysRequest, - response *api.PerformUploadKeysResponse, -) error { - return httputil.CallInternalRPCAPI( - "PerformUploadKeys", h.apiURL+PerformUploadKeysPath, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpKeyInternalAPI) QueryKeys( - ctx context.Context, - request *api.QueryKeysRequest, - response *api.QueryKeysResponse, -) error { - return httputil.CallInternalRPCAPI( - "QueryKeys", h.apiURL+QueryKeysPath, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpKeyInternalAPI) QueryOneTimeKeys( - ctx context.Context, - request *api.QueryOneTimeKeysRequest, - response *api.QueryOneTimeKeysResponse, -) error { - return httputil.CallInternalRPCAPI( - "QueryOneTimeKeys", h.apiURL+QueryOneTimeKeysPath, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpKeyInternalAPI) QueryDeviceMessages( - ctx context.Context, - request *api.QueryDeviceMessagesRequest, - response *api.QueryDeviceMessagesResponse, -) error { - return httputil.CallInternalRPCAPI( - "QueryDeviceMessages", h.apiURL+QueryDeviceMessagesPath, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpKeyInternalAPI) QueryKeyChanges( - ctx context.Context, - request *api.QueryKeyChangesRequest, - response *api.QueryKeyChangesResponse, -) error { - return httputil.CallInternalRPCAPI( - "QueryKeyChanges", h.apiURL+QueryKeyChangesPath, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpKeyInternalAPI) PerformUploadDeviceKeys( - ctx context.Context, - request *api.PerformUploadDeviceKeysRequest, - response *api.PerformUploadDeviceKeysResponse, -) error { - return httputil.CallInternalRPCAPI( - "PerformUploadDeviceKeys", h.apiURL+PerformUploadDeviceKeysPath, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpKeyInternalAPI) PerformUploadDeviceSignatures( - ctx context.Context, - request *api.PerformUploadDeviceSignaturesRequest, - response *api.PerformUploadDeviceSignaturesResponse, -) error { - return httputil.CallInternalRPCAPI( - "PerformUploadDeviceSignatures", h.apiURL+PerformUploadDeviceSignaturesPath, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpKeyInternalAPI) QuerySignatures( - ctx context.Context, - request *api.QuerySignaturesRequest, - response *api.QuerySignaturesResponse, -) error { - return httputil.CallInternalRPCAPI( - "QuerySignatures", h.apiURL+QuerySignaturesPath, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpKeyInternalAPI) PerformMarkAsStaleIfNeeded( - ctx context.Context, - request *api.PerformMarkAsStaleRequest, - response *struct{}, -) error { - return httputil.CallInternalRPCAPI( - "MarkAsStale", h.apiURL+PerformMarkAsStalePath, - h.httpClient, ctx, request, response, - ) -} diff --git a/keyserver/inthttp/server.go b/keyserver/inthttp/server.go deleted file mode 100644 index 443269f73..000000000 --- a/keyserver/inthttp/server.go +++ /dev/null @@ -1,79 +0,0 @@ -// Copyright 2020 The Matrix.org Foundation C.I.C. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package inthttp - -import ( - "github.com/gorilla/mux" - - "github.com/matrix-org/dendrite/internal/httputil" - "github.com/matrix-org/dendrite/keyserver/api" -) - -func AddRoutes(internalAPIMux *mux.Router, s api.KeyInternalAPI, enableMetrics bool) { - internalAPIMux.Handle( - PerformClaimKeysPath, - httputil.MakeInternalRPCAPI("KeyserverPerformClaimKeys", enableMetrics, s.PerformClaimKeys), - ) - - internalAPIMux.Handle( - PerformDeleteKeysPath, - httputil.MakeInternalRPCAPI("KeyserverPerformDeleteKeys", enableMetrics, s.PerformDeleteKeys), - ) - - internalAPIMux.Handle( - PerformUploadKeysPath, - httputil.MakeInternalRPCAPI("KeyserverPerformUploadKeys", enableMetrics, s.PerformUploadKeys), - ) - - internalAPIMux.Handle( - PerformUploadDeviceKeysPath, - httputil.MakeInternalRPCAPI("KeyserverPerformUploadDeviceKeys", enableMetrics, s.PerformUploadDeviceKeys), - ) - - internalAPIMux.Handle( - PerformUploadDeviceSignaturesPath, - httputil.MakeInternalRPCAPI("KeyserverPerformUploadDeviceSignatures", enableMetrics, s.PerformUploadDeviceSignatures), - ) - - internalAPIMux.Handle( - QueryKeysPath, - httputil.MakeInternalRPCAPI("KeyserverQueryKeys", enableMetrics, s.QueryKeys), - ) - - internalAPIMux.Handle( - QueryOneTimeKeysPath, - httputil.MakeInternalRPCAPI("KeyserverQueryOneTimeKeys", enableMetrics, s.QueryOneTimeKeys), - ) - - internalAPIMux.Handle( - QueryDeviceMessagesPath, - httputil.MakeInternalRPCAPI("KeyserverQueryDeviceMessages", enableMetrics, s.QueryDeviceMessages), - ) - - internalAPIMux.Handle( - QueryKeyChangesPath, - httputil.MakeInternalRPCAPI("KeyserverQueryKeyChanges", enableMetrics, s.QueryKeyChanges), - ) - - internalAPIMux.Handle( - QuerySignaturesPath, - httputil.MakeInternalRPCAPI("KeyserverQuerySignatures", enableMetrics, s.QuerySignatures), - ) - - internalAPIMux.Handle( - PerformMarkAsStalePath, - httputil.MakeInternalRPCAPI("KeyserverMarkAsStale", enableMetrics, s.PerformMarkAsStaleIfNeeded), - ) -} diff --git a/keyserver/keyserver.go b/keyserver/keyserver.go index 275576773..2d143682d 100644 --- a/keyserver/keyserver.go +++ b/keyserver/keyserver.go @@ -15,7 +15,6 @@ package keyserver import ( - "github.com/gorilla/mux" "github.com/sirupsen/logrus" rsapi "github.com/matrix-org/dendrite/roomserver/api" @@ -24,7 +23,6 @@ import ( "github.com/matrix-org/dendrite/keyserver/api" "github.com/matrix-org/dendrite/keyserver/consumers" "github.com/matrix-org/dendrite/keyserver/internal" - "github.com/matrix-org/dendrite/keyserver/inthttp" "github.com/matrix-org/dendrite/keyserver/producers" "github.com/matrix-org/dendrite/keyserver/storage" "github.com/matrix-org/dendrite/setup/base" @@ -32,12 +30,6 @@ import ( "github.com/matrix-org/dendrite/setup/jetstream" ) -// AddInternalRoutes registers HTTP handlers for the internal API. Invokes functions -// on the given input API. -func AddInternalRoutes(router *mux.Router, intAPI api.KeyInternalAPI, enableMetrics bool) { - inthttp.AddRoutes(router, intAPI, enableMetrics) -} - // NewInternalAPI returns a concerete implementation of the internal API. Callers // can call functions directly on the returned API or via an HTTP interface using AddInternalRoutes. func NewInternalAPI( diff --git a/roomserver/inthttp/client.go b/roomserver/inthttp/client.go deleted file mode 100644 index 556a137ba..000000000 --- a/roomserver/inthttp/client.go +++ /dev/null @@ -1,575 +0,0 @@ -package inthttp - -import ( - "context" - "errors" - "net/http" - - "github.com/matrix-org/gomatrixserverlib" - - asAPI "github.com/matrix-org/dendrite/appservice/api" - fsInputAPI "github.com/matrix-org/dendrite/federationapi/api" - "github.com/matrix-org/dendrite/internal/caching" - "github.com/matrix-org/dendrite/internal/httputil" - "github.com/matrix-org/dendrite/roomserver/api" - userapi "github.com/matrix-org/dendrite/userapi/api" -) - -const ( - // Alias operations - RoomserverSetRoomAliasPath = "/roomserver/setRoomAlias" - RoomserverGetRoomIDForAliasPath = "/roomserver/GetRoomIDForAlias" - RoomserverGetAliasesForRoomIDPath = "/roomserver/GetAliasesForRoomID" - RoomserverGetCreatorIDForAliasPath = "/roomserver/GetCreatorIDForAlias" - RoomserverRemoveRoomAliasPath = "/roomserver/removeRoomAlias" - - // Input operations - RoomserverInputRoomEventsPath = "/roomserver/inputRoomEvents" - - // Perform operations - RoomserverPerformInvitePath = "/roomserver/performInvite" - RoomserverPerformPeekPath = "/roomserver/performPeek" - RoomserverPerformUnpeekPath = "/roomserver/performUnpeek" - RoomserverPerformRoomUpgradePath = "/roomserver/performRoomUpgrade" - RoomserverPerformJoinPath = "/roomserver/performJoin" - RoomserverPerformLeavePath = "/roomserver/performLeave" - RoomserverPerformBackfillPath = "/roomserver/performBackfill" - RoomserverPerformPublishPath = "/roomserver/performPublish" - RoomserverPerformInboundPeekPath = "/roomserver/performInboundPeek" - RoomserverPerformForgetPath = "/roomserver/performForget" - RoomserverPerformAdminEvacuateRoomPath = "/roomserver/performAdminEvacuateRoom" - RoomserverPerformAdminEvacuateUserPath = "/roomserver/performAdminEvacuateUser" - RoomserverPerformAdminDownloadStatePath = "/roomserver/performAdminDownloadState" - RoomserverPerformAdminPurgeRoomPath = "/roomserver/performAdminPurgeRoom" - - // Query operations - RoomserverQueryLatestEventsAndStatePath = "/roomserver/queryLatestEventsAndState" - RoomserverQueryStateAfterEventsPath = "/roomserver/queryStateAfterEvents" - RoomserverQueryEventsByIDPath = "/roomserver/queryEventsByID" - RoomserverQueryMembershipForUserPath = "/roomserver/queryMembershipForUser" - RoomserverQueryMembershipsForRoomPath = "/roomserver/queryMembershipsForRoom" - RoomserverQueryServerJoinedToRoomPath = "/roomserver/queryServerJoinedToRoomPath" - RoomserverQueryServerAllowedToSeeEventPath = "/roomserver/queryServerAllowedToSeeEvent" - RoomserverQueryMissingEventsPath = "/roomserver/queryMissingEvents" - RoomserverQueryStateAndAuthChainPath = "/roomserver/queryStateAndAuthChain" - RoomserverQueryRoomVersionCapabilitiesPath = "/roomserver/queryRoomVersionCapabilities" - RoomserverQueryRoomVersionForRoomPath = "/roomserver/queryRoomVersionForRoom" - RoomserverQueryPublishedRoomsPath = "/roomserver/queryPublishedRooms" - RoomserverQueryCurrentStatePath = "/roomserver/queryCurrentState" - RoomserverQueryRoomsForUserPath = "/roomserver/queryRoomsForUser" - RoomserverQueryBulkStateContentPath = "/roomserver/queryBulkStateContent" - RoomserverQuerySharedUsersPath = "/roomserver/querySharedUsers" - RoomserverQueryKnownUsersPath = "/roomserver/queryKnownUsers" - RoomserverQueryServerBannedFromRoomPath = "/roomserver/queryServerBannedFromRoom" - RoomserverQueryAuthChainPath = "/roomserver/queryAuthChain" - RoomserverQueryRestrictedJoinAllowed = "/roomserver/queryRestrictedJoinAllowed" - RoomserverQueryMembershipAtEventPath = "/roomserver/queryMembershipAtEvent" - RoomserverQueryLeftMembersPath = "/roomserver/queryLeftMembers" -) - -type httpRoomserverInternalAPI struct { - roomserverURL string - httpClient *http.Client - cache caching.RoomVersionCache -} - -// NewRoomserverClient creates a RoomserverInputAPI implemented by talking to a HTTP POST API. -// If httpClient is nil an error is returned -func NewRoomserverClient( - roomserverURL string, - httpClient *http.Client, - cache caching.RoomVersionCache, -) (api.RoomserverInternalAPI, error) { - if httpClient == nil { - return nil, errors.New("NewRoomserverInternalAPIHTTP: httpClient is ") - } - return &httpRoomserverInternalAPI{ - roomserverURL: roomserverURL, - httpClient: httpClient, - cache: cache, - }, nil -} - -// SetFederationInputAPI no-ops in HTTP client mode as there is no chicken/egg scenario -func (h *httpRoomserverInternalAPI) SetFederationAPI(fsAPI fsInputAPI.RoomserverFederationAPI, keyRing *gomatrixserverlib.KeyRing) { -} - -// SetAppserviceAPI no-ops in HTTP client mode as there is no chicken/egg scenario -func (h *httpRoomserverInternalAPI) SetAppserviceAPI(asAPI asAPI.AppServiceInternalAPI) { -} - -// SetUserAPI no-ops in HTTP client mode as there is no chicken/egg scenario -func (h *httpRoomserverInternalAPI) SetUserAPI(userAPI userapi.RoomserverUserAPI) { -} - -// SetRoomAlias implements RoomserverAliasAPI -func (h *httpRoomserverInternalAPI) SetRoomAlias( - ctx context.Context, - request *api.SetRoomAliasRequest, - response *api.SetRoomAliasResponse, -) error { - return httputil.CallInternalRPCAPI( - "SetRoomAlias", h.roomserverURL+RoomserverSetRoomAliasPath, - h.httpClient, ctx, request, response, - ) -} - -// GetRoomIDForAlias implements RoomserverAliasAPI -func (h *httpRoomserverInternalAPI) GetRoomIDForAlias( - ctx context.Context, - request *api.GetRoomIDForAliasRequest, - response *api.GetRoomIDForAliasResponse, -) error { - return httputil.CallInternalRPCAPI( - "GetRoomIDForAlias", h.roomserverURL+RoomserverGetRoomIDForAliasPath, - h.httpClient, ctx, request, response, - ) -} - -// GetAliasesForRoomID implements RoomserverAliasAPI -func (h *httpRoomserverInternalAPI) GetAliasesForRoomID( - ctx context.Context, - request *api.GetAliasesForRoomIDRequest, - response *api.GetAliasesForRoomIDResponse, -) error { - return httputil.CallInternalRPCAPI( - "GetAliasesForRoomID", h.roomserverURL+RoomserverGetAliasesForRoomIDPath, - h.httpClient, ctx, request, response, - ) -} - -// RemoveRoomAlias implements RoomserverAliasAPI -func (h *httpRoomserverInternalAPI) RemoveRoomAlias( - ctx context.Context, - request *api.RemoveRoomAliasRequest, - response *api.RemoveRoomAliasResponse, -) error { - return httputil.CallInternalRPCAPI( - "RemoveRoomAlias", h.roomserverURL+RoomserverRemoveRoomAliasPath, - h.httpClient, ctx, request, response, - ) -} - -// InputRoomEvents implements RoomserverInputAPI -func (h *httpRoomserverInternalAPI) InputRoomEvents( - ctx context.Context, - request *api.InputRoomEventsRequest, - response *api.InputRoomEventsResponse, -) error { - if err := httputil.CallInternalRPCAPI( - "InputRoomEvents", h.roomserverURL+RoomserverInputRoomEventsPath, - h.httpClient, ctx, request, response, - ); err != nil { - response.ErrMsg = err.Error() - } - return nil -} - -func (h *httpRoomserverInternalAPI) PerformInvite( - ctx context.Context, - request *api.PerformInviteRequest, - response *api.PerformInviteResponse, -) error { - return httputil.CallInternalRPCAPI( - "PerformInvite", h.roomserverURL+RoomserverPerformInvitePath, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpRoomserverInternalAPI) PerformJoin( - ctx context.Context, - request *api.PerformJoinRequest, - response *api.PerformJoinResponse, -) error { - return httputil.CallInternalRPCAPI( - "PerformJoin", h.roomserverURL+RoomserverPerformJoinPath, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpRoomserverInternalAPI) PerformPeek( - ctx context.Context, - request *api.PerformPeekRequest, - response *api.PerformPeekResponse, -) error { - return httputil.CallInternalRPCAPI( - "PerformPeek", h.roomserverURL+RoomserverPerformPeekPath, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpRoomserverInternalAPI) PerformInboundPeek( - ctx context.Context, - request *api.PerformInboundPeekRequest, - response *api.PerformInboundPeekResponse, -) error { - return httputil.CallInternalRPCAPI( - "PerformInboundPeek", h.roomserverURL+RoomserverPerformInboundPeekPath, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpRoomserverInternalAPI) PerformUnpeek( - ctx context.Context, - request *api.PerformUnpeekRequest, - response *api.PerformUnpeekResponse, -) error { - return httputil.CallInternalRPCAPI( - "PerformUnpeek", h.roomserverURL+RoomserverPerformUnpeekPath, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpRoomserverInternalAPI) PerformRoomUpgrade( - ctx context.Context, - request *api.PerformRoomUpgradeRequest, - response *api.PerformRoomUpgradeResponse, -) error { - return httputil.CallInternalRPCAPI( - "PerformRoomUpgrade", h.roomserverURL+RoomserverPerformRoomUpgradePath, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpRoomserverInternalAPI) PerformLeave( - ctx context.Context, - request *api.PerformLeaveRequest, - response *api.PerformLeaveResponse, -) error { - return httputil.CallInternalRPCAPI( - "PerformLeave", h.roomserverURL+RoomserverPerformLeavePath, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpRoomserverInternalAPI) PerformPublish( - ctx context.Context, - request *api.PerformPublishRequest, - response *api.PerformPublishResponse, -) error { - return httputil.CallInternalRPCAPI( - "PerformPublish", h.roomserverURL+RoomserverPerformPublishPath, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpRoomserverInternalAPI) PerformAdminEvacuateRoom( - ctx context.Context, - request *api.PerformAdminEvacuateRoomRequest, - response *api.PerformAdminEvacuateRoomResponse, -) error { - return httputil.CallInternalRPCAPI( - "PerformAdminEvacuateRoom", h.roomserverURL+RoomserverPerformAdminEvacuateRoomPath, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpRoomserverInternalAPI) PerformAdminDownloadState( - ctx context.Context, - request *api.PerformAdminDownloadStateRequest, - response *api.PerformAdminDownloadStateResponse, -) error { - return httputil.CallInternalRPCAPI( - "PerformAdminDownloadState", h.roomserverURL+RoomserverPerformAdminDownloadStatePath, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpRoomserverInternalAPI) PerformAdminEvacuateUser( - ctx context.Context, - request *api.PerformAdminEvacuateUserRequest, - response *api.PerformAdminEvacuateUserResponse, -) error { - return httputil.CallInternalRPCAPI( - "PerformAdminEvacuateUser", h.roomserverURL+RoomserverPerformAdminEvacuateUserPath, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpRoomserverInternalAPI) PerformAdminPurgeRoom( - ctx context.Context, - request *api.PerformAdminPurgeRoomRequest, - response *api.PerformAdminPurgeRoomResponse, -) error { - return httputil.CallInternalRPCAPI( - "PerformAdminPurgeRoom", h.roomserverURL+RoomserverPerformAdminPurgeRoomPath, - h.httpClient, ctx, request, response, - ) -} - -// QueryLatestEventsAndState implements RoomserverQueryAPI -func (h *httpRoomserverInternalAPI) QueryLatestEventsAndState( - ctx context.Context, - request *api.QueryLatestEventsAndStateRequest, - response *api.QueryLatestEventsAndStateResponse, -) error { - return httputil.CallInternalRPCAPI( - "QueryLatestEventsAndState", h.roomserverURL+RoomserverQueryLatestEventsAndStatePath, - h.httpClient, ctx, request, response, - ) -} - -// QueryStateAfterEvents implements RoomserverQueryAPI -func (h *httpRoomserverInternalAPI) QueryStateAfterEvents( - ctx context.Context, - request *api.QueryStateAfterEventsRequest, - response *api.QueryStateAfterEventsResponse, -) error { - return httputil.CallInternalRPCAPI( - "QueryStateAfterEvents", h.roomserverURL+RoomserverQueryStateAfterEventsPath, - h.httpClient, ctx, request, response, - ) -} - -// QueryEventsByID implements RoomserverQueryAPI -func (h *httpRoomserverInternalAPI) QueryEventsByID( - ctx context.Context, - request *api.QueryEventsByIDRequest, - response *api.QueryEventsByIDResponse, -) error { - return httputil.CallInternalRPCAPI( - "QueryEventsByID", h.roomserverURL+RoomserverQueryEventsByIDPath, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpRoomserverInternalAPI) QueryPublishedRooms( - ctx context.Context, - request *api.QueryPublishedRoomsRequest, - response *api.QueryPublishedRoomsResponse, -) error { - return httputil.CallInternalRPCAPI( - "QueryPublishedRooms", h.roomserverURL+RoomserverQueryPublishedRoomsPath, - h.httpClient, ctx, request, response, - ) -} - -// QueryMembershipForUser implements RoomserverQueryAPI -func (h *httpRoomserverInternalAPI) QueryMembershipForUser( - ctx context.Context, - request *api.QueryMembershipForUserRequest, - response *api.QueryMembershipForUserResponse, -) error { - return httputil.CallInternalRPCAPI( - "QueryMembershipForUser", h.roomserverURL+RoomserverQueryMembershipForUserPath, - h.httpClient, ctx, request, response, - ) -} - -// QueryMembershipsForRoom implements RoomserverQueryAPI -func (h *httpRoomserverInternalAPI) QueryMembershipsForRoom( - ctx context.Context, - request *api.QueryMembershipsForRoomRequest, - response *api.QueryMembershipsForRoomResponse, -) error { - return httputil.CallInternalRPCAPI( - "QueryMembershipsForRoom", h.roomserverURL+RoomserverQueryMembershipsForRoomPath, - h.httpClient, ctx, request, response, - ) -} - -// QueryMembershipsForRoom implements RoomserverQueryAPI -func (h *httpRoomserverInternalAPI) QueryServerJoinedToRoom( - ctx context.Context, - request *api.QueryServerJoinedToRoomRequest, - response *api.QueryServerJoinedToRoomResponse, -) error { - return httputil.CallInternalRPCAPI( - "QueryServerJoinedToRoom", h.roomserverURL+RoomserverQueryServerJoinedToRoomPath, - h.httpClient, ctx, request, response, - ) -} - -// QueryServerAllowedToSeeEvent implements RoomserverQueryAPI -func (h *httpRoomserverInternalAPI) QueryServerAllowedToSeeEvent( - ctx context.Context, - request *api.QueryServerAllowedToSeeEventRequest, - response *api.QueryServerAllowedToSeeEventResponse, -) (err error) { - return httputil.CallInternalRPCAPI( - "QueryServerAllowedToSeeEvent", h.roomserverURL+RoomserverQueryServerAllowedToSeeEventPath, - h.httpClient, ctx, request, response, - ) -} - -// QueryMissingEvents implements RoomServerQueryAPI -func (h *httpRoomserverInternalAPI) QueryMissingEvents( - ctx context.Context, - request *api.QueryMissingEventsRequest, - response *api.QueryMissingEventsResponse, -) error { - return httputil.CallInternalRPCAPI( - "QueryMissingEvents", h.roomserverURL+RoomserverQueryMissingEventsPath, - h.httpClient, ctx, request, response, - ) -} - -// QueryStateAndAuthChain implements RoomserverQueryAPI -func (h *httpRoomserverInternalAPI) QueryStateAndAuthChain( - ctx context.Context, - request *api.QueryStateAndAuthChainRequest, - response *api.QueryStateAndAuthChainResponse, -) error { - return httputil.CallInternalRPCAPI( - "QueryStateAndAuthChain", h.roomserverURL+RoomserverQueryStateAndAuthChainPath, - h.httpClient, ctx, request, response, - ) -} - -// PerformBackfill implements RoomServerQueryAPI -func (h *httpRoomserverInternalAPI) PerformBackfill( - ctx context.Context, - request *api.PerformBackfillRequest, - response *api.PerformBackfillResponse, -) error { - return httputil.CallInternalRPCAPI( - "PerformBackfill", h.roomserverURL+RoomserverPerformBackfillPath, - h.httpClient, ctx, request, response, - ) -} - -// QueryRoomVersionCapabilities implements RoomServerQueryAPI -func (h *httpRoomserverInternalAPI) QueryRoomVersionCapabilities( - ctx context.Context, - request *api.QueryRoomVersionCapabilitiesRequest, - response *api.QueryRoomVersionCapabilitiesResponse, -) error { - return httputil.CallInternalRPCAPI( - "QueryRoomVersionCapabilities", h.roomserverURL+RoomserverQueryRoomVersionCapabilitiesPath, - h.httpClient, ctx, request, response, - ) -} - -// QueryRoomVersionForRoom implements RoomServerQueryAPI -func (h *httpRoomserverInternalAPI) QueryRoomVersionForRoom( - ctx context.Context, - request *api.QueryRoomVersionForRoomRequest, - response *api.QueryRoomVersionForRoomResponse, -) error { - if roomVersion, ok := h.cache.GetRoomVersion(request.RoomID); ok { - response.RoomVersion = roomVersion - return nil - } - err := httputil.CallInternalRPCAPI( - "QueryRoomVersionForRoom", h.roomserverURL+RoomserverQueryRoomVersionForRoomPath, - h.httpClient, ctx, request, response, - ) - if err == nil { - h.cache.StoreRoomVersion(request.RoomID, response.RoomVersion) - } - return err -} - -func (h *httpRoomserverInternalAPI) QueryCurrentState( - ctx context.Context, - request *api.QueryCurrentStateRequest, - response *api.QueryCurrentStateResponse, -) error { - return httputil.CallInternalRPCAPI( - "QueryCurrentState", h.roomserverURL+RoomserverQueryCurrentStatePath, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpRoomserverInternalAPI) QueryRoomsForUser( - ctx context.Context, - request *api.QueryRoomsForUserRequest, - response *api.QueryRoomsForUserResponse, -) error { - return httputil.CallInternalRPCAPI( - "QueryRoomsForUser", h.roomserverURL+RoomserverQueryRoomsForUserPath, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpRoomserverInternalAPI) QueryBulkStateContent( - ctx context.Context, - request *api.QueryBulkStateContentRequest, - response *api.QueryBulkStateContentResponse, -) error { - return httputil.CallInternalRPCAPI( - "QueryBulkStateContent", h.roomserverURL+RoomserverQueryBulkStateContentPath, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpRoomserverInternalAPI) QuerySharedUsers( - ctx context.Context, - request *api.QuerySharedUsersRequest, - response *api.QuerySharedUsersResponse, -) error { - return httputil.CallInternalRPCAPI( - "QuerySharedUsers", h.roomserverURL+RoomserverQuerySharedUsersPath, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpRoomserverInternalAPI) QueryKnownUsers( - ctx context.Context, - request *api.QueryKnownUsersRequest, - response *api.QueryKnownUsersResponse, -) error { - return httputil.CallInternalRPCAPI( - "QueryKnownUsers", h.roomserverURL+RoomserverQueryKnownUsersPath, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpRoomserverInternalAPI) QueryAuthChain( - ctx context.Context, - request *api.QueryAuthChainRequest, - response *api.QueryAuthChainResponse, -) error { - return httputil.CallInternalRPCAPI( - "QueryAuthChain", h.roomserverURL+RoomserverQueryAuthChainPath, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpRoomserverInternalAPI) QueryServerBannedFromRoom( - ctx context.Context, - request *api.QueryServerBannedFromRoomRequest, - response *api.QueryServerBannedFromRoomResponse, -) error { - return httputil.CallInternalRPCAPI( - "QueryServerBannedFromRoom", h.roomserverURL+RoomserverQueryServerBannedFromRoomPath, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpRoomserverInternalAPI) QueryRestrictedJoinAllowed( - ctx context.Context, - request *api.QueryRestrictedJoinAllowedRequest, - response *api.QueryRestrictedJoinAllowedResponse, -) error { - return httputil.CallInternalRPCAPI( - "QueryRestrictedJoinAllowed", h.roomserverURL+RoomserverQueryRestrictedJoinAllowed, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpRoomserverInternalAPI) PerformForget( - ctx context.Context, - request *api.PerformForgetRequest, - response *api.PerformForgetResponse, -) error { - return httputil.CallInternalRPCAPI( - "PerformForget", h.roomserverURL+RoomserverPerformForgetPath, - h.httpClient, ctx, request, response, - ) - -} - -func (h *httpRoomserverInternalAPI) QueryMembershipAtEvent(ctx context.Context, request *api.QueryMembershipAtEventRequest, response *api.QueryMembershipAtEventResponse) error { - return httputil.CallInternalRPCAPI( - "QueryMembershiptAtEvent", h.roomserverURL+RoomserverQueryMembershipAtEventPath, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpRoomserverInternalAPI) QueryLeftUsers(ctx context.Context, request *api.QueryLeftUsersRequest, response *api.QueryLeftUsersResponse) error { - return httputil.CallInternalRPCAPI( - "RoomserverQueryLeftMembers", h.roomserverURL+RoomserverQueryLeftMembersPath, - h.httpClient, ctx, request, response, - ) -} diff --git a/roomserver/inthttp/server.go b/roomserver/inthttp/server.go deleted file mode 100644 index f3a51b0b1..000000000 --- a/roomserver/inthttp/server.go +++ /dev/null @@ -1,216 +0,0 @@ -package inthttp - -import ( - "github.com/gorilla/mux" - - "github.com/matrix-org/dendrite/internal/httputil" - "github.com/matrix-org/dendrite/roomserver/api" -) - -// AddRoutes adds the RoomserverInternalAPI handlers to the http.ServeMux. -// nolint: gocyclo -func AddRoutes(r api.RoomserverInternalAPI, internalAPIMux *mux.Router, enableMetrics bool) { - internalAPIMux.Handle( - RoomserverInputRoomEventsPath, - httputil.MakeInternalRPCAPI("RoomserverInputRoomEvents", enableMetrics, r.InputRoomEvents), - ) - - internalAPIMux.Handle( - RoomserverPerformInvitePath, - httputil.MakeInternalRPCAPI("RoomserverPerformInvite", enableMetrics, r.PerformInvite), - ) - - internalAPIMux.Handle( - RoomserverPerformJoinPath, - httputil.MakeInternalRPCAPI("RoomserverPerformJoin", enableMetrics, r.PerformJoin), - ) - - internalAPIMux.Handle( - RoomserverPerformLeavePath, - httputil.MakeInternalRPCAPI("RoomserverPerformLeave", enableMetrics, r.PerformLeave), - ) - - internalAPIMux.Handle( - RoomserverPerformPeekPath, - httputil.MakeInternalRPCAPI("RoomserverPerformPeek", enableMetrics, r.PerformPeek), - ) - - internalAPIMux.Handle( - RoomserverPerformInboundPeekPath, - httputil.MakeInternalRPCAPI("RoomserverPerformInboundPeek", enableMetrics, r.PerformInboundPeek), - ) - - internalAPIMux.Handle( - RoomserverPerformUnpeekPath, - httputil.MakeInternalRPCAPI("RoomserverPerformUnpeek", enableMetrics, r.PerformUnpeek), - ) - - internalAPIMux.Handle( - RoomserverPerformRoomUpgradePath, - httputil.MakeInternalRPCAPI("RoomserverPerformRoomUpgrade", enableMetrics, r.PerformRoomUpgrade), - ) - - internalAPIMux.Handle( - RoomserverPerformPublishPath, - httputil.MakeInternalRPCAPI("RoomserverPerformPublish", enableMetrics, r.PerformPublish), - ) - - internalAPIMux.Handle( - RoomserverPerformAdminEvacuateRoomPath, - httputil.MakeInternalRPCAPI("RoomserverPerformAdminEvacuateRoom", enableMetrics, r.PerformAdminEvacuateRoom), - ) - - internalAPIMux.Handle( - RoomserverPerformAdminEvacuateUserPath, - httputil.MakeInternalRPCAPI("RoomserverPerformAdminEvacuateUser", enableMetrics, r.PerformAdminEvacuateUser), - ) - - internalAPIMux.Handle( - RoomserverPerformAdminPurgeRoomPath, - httputil.MakeInternalRPCAPI("RoomserverPerformAdminPurgeRoom", enableMetrics, r.PerformAdminPurgeRoom), - ) - - internalAPIMux.Handle( - RoomserverPerformAdminDownloadStatePath, - httputil.MakeInternalRPCAPI("RoomserverPerformAdminDownloadState", enableMetrics, r.PerformAdminDownloadState), - ) - - internalAPIMux.Handle( - RoomserverQueryPublishedRoomsPath, - httputil.MakeInternalRPCAPI("RoomserverQueryPublishedRooms", enableMetrics, r.QueryPublishedRooms), - ) - - internalAPIMux.Handle( - RoomserverQueryLatestEventsAndStatePath, - httputil.MakeInternalRPCAPI("RoomserverQueryLatestEventsAndState", enableMetrics, r.QueryLatestEventsAndState), - ) - - internalAPIMux.Handle( - RoomserverQueryStateAfterEventsPath, - httputil.MakeInternalRPCAPI("RoomserverQueryStateAfterEvents", enableMetrics, r.QueryStateAfterEvents), - ) - - internalAPIMux.Handle( - RoomserverQueryEventsByIDPath, - httputil.MakeInternalRPCAPI("RoomserverQueryEventsByID", enableMetrics, r.QueryEventsByID), - ) - - internalAPIMux.Handle( - RoomserverQueryMembershipForUserPath, - httputil.MakeInternalRPCAPI("RoomserverQueryMembershipForUser", enableMetrics, r.QueryMembershipForUser), - ) - - internalAPIMux.Handle( - RoomserverQueryMembershipsForRoomPath, - httputil.MakeInternalRPCAPI("RoomserverQueryMembershipsForRoom", enableMetrics, r.QueryMembershipsForRoom), - ) - - internalAPIMux.Handle( - RoomserverQueryServerJoinedToRoomPath, - httputil.MakeInternalRPCAPI("RoomserverQueryServerJoinedToRoom", enableMetrics, r.QueryServerJoinedToRoom), - ) - - internalAPIMux.Handle( - RoomserverQueryServerAllowedToSeeEventPath, - httputil.MakeInternalRPCAPI("RoomserverQueryServerAllowedToSeeEvent", enableMetrics, r.QueryServerAllowedToSeeEvent), - ) - - internalAPIMux.Handle( - RoomserverQueryMissingEventsPath, - httputil.MakeInternalRPCAPI("RoomserverQueryMissingEvents", enableMetrics, r.QueryMissingEvents), - ) - - internalAPIMux.Handle( - RoomserverQueryStateAndAuthChainPath, - httputil.MakeInternalRPCAPI("RoomserverQueryStateAndAuthChain", enableMetrics, r.QueryStateAndAuthChain), - ) - - internalAPIMux.Handle( - RoomserverPerformBackfillPath, - httputil.MakeInternalRPCAPI("RoomserverPerformBackfill", enableMetrics, r.PerformBackfill), - ) - - internalAPIMux.Handle( - RoomserverPerformForgetPath, - httputil.MakeInternalRPCAPI("RoomserverPerformForget", enableMetrics, r.PerformForget), - ) - - internalAPIMux.Handle( - RoomserverQueryRoomVersionCapabilitiesPath, - httputil.MakeInternalRPCAPI("RoomserverQueryRoomVersionCapabilities", enableMetrics, r.QueryRoomVersionCapabilities), - ) - - internalAPIMux.Handle( - RoomserverQueryRoomVersionForRoomPath, - httputil.MakeInternalRPCAPI("RoomserverQueryRoomVersionForRoom", enableMetrics, r.QueryRoomVersionForRoom), - ) - - internalAPIMux.Handle( - RoomserverSetRoomAliasPath, - httputil.MakeInternalRPCAPI("RoomserverSetRoomAlias", enableMetrics, r.SetRoomAlias), - ) - - internalAPIMux.Handle( - RoomserverGetRoomIDForAliasPath, - httputil.MakeInternalRPCAPI("RoomserverGetRoomIDForAlias", enableMetrics, r.GetRoomIDForAlias), - ) - - internalAPIMux.Handle( - RoomserverGetAliasesForRoomIDPath, - httputil.MakeInternalRPCAPI("RoomserverGetAliasesForRoomID", enableMetrics, r.GetAliasesForRoomID), - ) - - internalAPIMux.Handle( - RoomserverRemoveRoomAliasPath, - httputil.MakeInternalRPCAPI("RoomserverRemoveRoomAlias", enableMetrics, r.RemoveRoomAlias), - ) - - internalAPIMux.Handle( - RoomserverQueryCurrentStatePath, - httputil.MakeInternalRPCAPI("RoomserverQueryCurrentState", enableMetrics, r.QueryCurrentState), - ) - - internalAPIMux.Handle( - RoomserverQueryRoomsForUserPath, - httputil.MakeInternalRPCAPI("RoomserverQueryRoomsForUser", enableMetrics, r.QueryRoomsForUser), - ) - - internalAPIMux.Handle( - RoomserverQueryBulkStateContentPath, - httputil.MakeInternalRPCAPI("RoomserverQueryBulkStateContent", enableMetrics, r.QueryBulkStateContent), - ) - - internalAPIMux.Handle( - RoomserverQuerySharedUsersPath, - httputil.MakeInternalRPCAPI("RoomserverQuerySharedUsers", enableMetrics, r.QuerySharedUsers), - ) - - internalAPIMux.Handle( - RoomserverQueryKnownUsersPath, - httputil.MakeInternalRPCAPI("RoomserverQueryKnownUsers", enableMetrics, r.QueryKnownUsers), - ) - - internalAPIMux.Handle( - RoomserverQueryServerBannedFromRoomPath, - httputil.MakeInternalRPCAPI("RoomserverQueryServerBannedFromRoom", enableMetrics, r.QueryServerBannedFromRoom), - ) - - internalAPIMux.Handle( - RoomserverQueryAuthChainPath, - httputil.MakeInternalRPCAPI("RoomserverQueryAuthChain", enableMetrics, r.QueryAuthChain), - ) - - internalAPIMux.Handle( - RoomserverQueryRestrictedJoinAllowed, - httputil.MakeInternalRPCAPI("RoomserverQueryRestrictedJoinAllowed", enableMetrics, r.QueryRestrictedJoinAllowed), - ) - internalAPIMux.Handle( - RoomserverQueryMembershipAtEventPath, - httputil.MakeInternalRPCAPI("RoomserverQueryMembershipAtEventPath", enableMetrics, r.QueryMembershipAtEvent), - ) - - internalAPIMux.Handle( - RoomserverQueryLeftMembersPath, - httputil.MakeInternalRPCAPI("RoomserverQueryLeftMembersPath", enableMetrics, r.QueryLeftUsers), - ) -} diff --git a/roomserver/roomserver.go b/roomserver/roomserver.go index 0f6b48bf9..c5c51b255 100644 --- a/roomserver/roomserver.go +++ b/roomserver/roomserver.go @@ -15,22 +15,14 @@ package roomserver import ( - "github.com/gorilla/mux" "github.com/sirupsen/logrus" "github.com/matrix-org/dendrite/roomserver/api" "github.com/matrix-org/dendrite/roomserver/internal" - "github.com/matrix-org/dendrite/roomserver/inthttp" "github.com/matrix-org/dendrite/roomserver/storage" "github.com/matrix-org/dendrite/setup/base" ) -// AddInternalRoutes registers HTTP handlers for the internal API. Invokes functions -// on the given input API. -func AddInternalRoutes(router *mux.Router, intAPI api.RoomserverInternalAPI, enableMetrics bool) { - inthttp.AddRoutes(intAPI, router, enableMetrics) -} - // NewInternalAPI returns a concerete implementation of the internal API. Callers // can call functions directly on the returned API or via an HTTP interface using AddInternalRoutes. func NewInternalAPI( diff --git a/roomserver/roomserver_test.go b/roomserver/roomserver_test.go index 3ec2560d6..9e64617f9 100644 --- a/roomserver/roomserver_test.go +++ b/roomserver/roomserver_test.go @@ -2,13 +2,10 @@ package roomserver_test import ( "context" - "net/http" "reflect" "testing" "time" - "github.com/gorilla/mux" - "github.com/matrix-org/dendrite/internal/httputil" "github.com/matrix-org/dendrite/setup/base" "github.com/matrix-org/dendrite/userapi" @@ -22,7 +19,6 @@ import ( "github.com/matrix-org/dendrite/roomserver" "github.com/matrix-org/dendrite/roomserver/api" - "github.com/matrix-org/dendrite/roomserver/inthttp" "github.com/matrix-org/dendrite/roomserver/storage" "github.com/matrix-org/dendrite/test" "github.com/matrix-org/dendrite/test/testrig" @@ -207,24 +203,10 @@ func Test_QueryLeftUsers(t *testing.T) { } } - t.Run("HTTP API", func(t *testing.T) { - router := mux.NewRouter().PathPrefix(httputil.InternalPathPrefix).Subrouter() - roomserver.AddInternalRoutes(router, rsAPI, false) - apiURL, cancel := test.ListenAndServe(t, router, false) - defer cancel() - httpAPI, err := inthttp.NewRoomserverClient(apiURL, &http.Client{Timeout: time.Second * 5}, nil) - if err != nil { - t.Fatalf("failed to create HTTP client") - } - testCase(httpAPI) - }) - t.Run("Monolith", func(t *testing.T) { - testCase(rsAPI) - // also test tracing - traceAPI := &api.RoomserverInternalAPITrace{Impl: rsAPI} - testCase(traceAPI) - }) - + testCase(rsAPI) + // also test tracing + traceAPI := &api.RoomserverInternalAPITrace{Impl: rsAPI} + testCase(traceAPI) }) } diff --git a/setup/base/base.go b/setup/base/base.go index 6ea68119d..72bb2b536 100644 --- a/setup/base/base.go +++ b/setup/base/base.go @@ -17,7 +17,6 @@ package base import ( "bytes" "context" - "crypto/tls" "database/sql" "embed" "encoding/json" @@ -38,8 +37,6 @@ import ( "github.com/matrix-org/gomatrixserverlib" "github.com/prometheus/client_golang/prometheus/promhttp" "go.uber.org/atomic" - "golang.org/x/net/http2" - "golang.org/x/net/http2/h2c" "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/internal/caching" @@ -53,19 +50,9 @@ import ( "github.com/sirupsen/logrus" - appserviceAPI "github.com/matrix-org/dendrite/appservice/api" - asinthttp "github.com/matrix-org/dendrite/appservice/inthttp" - federationAPI "github.com/matrix-org/dendrite/federationapi/api" - federationIntHTTP "github.com/matrix-org/dendrite/federationapi/inthttp" - keyserverAPI "github.com/matrix-org/dendrite/keyserver/api" - keyinthttp "github.com/matrix-org/dendrite/keyserver/inthttp" - roomserverAPI "github.com/matrix-org/dendrite/roomserver/api" - rsinthttp "github.com/matrix-org/dendrite/roomserver/inthttp" "github.com/matrix-org/dendrite/setup/config" "github.com/matrix-org/dendrite/setup/jetstream" "github.com/matrix-org/dendrite/setup/process" - userapi "github.com/matrix-org/dendrite/userapi/api" - userapiinthttp "github.com/matrix-org/dendrite/userapi/inthttp" ) //go:embed static/*.gotmpl @@ -78,7 +65,6 @@ var staticContent embed.FS // Must be closed when shutting down. type BaseDendrite struct { *process.ProcessContext - componentName string tracerCloser io.Closer PublicClientAPIMux *mux.Router PublicFederationAPIMux *mux.Router @@ -90,8 +76,6 @@ type BaseDendrite struct { DendriteAdminMux *mux.Router SynapseAdminMux *mux.Router NATS *jetstream.NATSInstance - UseHTTPAPIs bool - apiHttpClient *http.Client Cfg *config.Dendrite Caches *caching.Caches DNSCache *gomatrixserverlib.DNSCache @@ -111,8 +95,6 @@ type BaseDendriteOptions int const ( DisableMetrics BaseDendriteOptions = iota - UseHTTPAPIs - PolylithMode ) // NewBaseDendrite creates a new instance to be used by a component. @@ -120,23 +102,16 @@ const ( // of the compontent running, e.g. "SyncAPI" func NewBaseDendrite(cfg *config.Dendrite, componentName string, options ...BaseDendriteOptions) *BaseDendrite { platformSanityChecks() - useHTTPAPIs := false enableMetrics := true - isMonolith := true for _, opt := range options { switch opt { case DisableMetrics: enableMetrics = false - case UseHTTPAPIs: - useHTTPAPIs = true - case PolylithMode: - isMonolith = false - useHTTPAPIs = true } } configErrors := &config.ConfigErrors{} - cfg.Verify(configErrors, isMonolith) + cfg.Verify(configErrors) if len(*configErrors) > 0 { for _, err := range *configErrors { logrus.Errorf("Configuration error: %s", err) @@ -145,7 +120,7 @@ func NewBaseDendrite(cfg *config.Dendrite, componentName string, options ...Base } internal.SetupStdLogging() - internal.SetupHookLogging(cfg.Logging, componentName) + internal.SetupHookLogging(cfg.Logging) internal.SetupPprof() logrus.Infof("Dendrite version %s", internal.VersionString()) @@ -160,8 +135,7 @@ func NewBaseDendrite(cfg *config.Dendrite, componentName string, options ...Base } var fts *fulltext.Search - isSyncOrMonolith := componentName == "syncapi" || isMonolith - if cfg.SyncAPI.Fulltext.Enabled && isSyncOrMonolith { + if cfg.SyncAPI.Fulltext.Enabled { fts, err = fulltext.New(cfg.SyncAPI.Fulltext) if err != nil { logrus.WithError(err).Panicf("failed to create full text") @@ -196,32 +170,12 @@ func NewBaseDendrite(cfg *config.Dendrite, componentName string, options ...Base ) } - apiClient := http.Client{ - Timeout: time.Minute * 10, - Transport: &http2.Transport{ - AllowHTTP: true, - DialTLS: func(network, addr string, _ *tls.Config) (net.Conn, error) { - // Ordinarily HTTP/2 would expect TLS, but the remote listener is - // H2C-enabled (HTTP/2 without encryption). Overriding the DialTLS - // function with a plain Dial allows us to trick the HTTP client - // into establishing a HTTP/2 connection without TLS. - // TODO: Eventually we will want to look at authenticating and - // encrypting these internal HTTP APIs, at which point we will have - // to reconsider H2C and change all this anyway. - return net.Dial(network, addr) - }, - }, - } - // If we're in monolith mode, we'll set up a global pool of database // connections. A component is welcome to use this pool if they don't // have a separate database config of their own. var db *sql.DB var writer sqlutil.Writer if cfg.Global.DatabaseOptions.ConnectionString != "" { - if !isMonolith { - logrus.Panic("Using a global database connection pool is not supported in polylith deployments") - } if cfg.Global.DatabaseOptions.ConnectionString.IsSQLite() { logrus.Panic("Using a global database connection pool is not supported with SQLite databases") } @@ -246,8 +200,6 @@ func NewBaseDendrite(cfg *config.Dendrite, componentName string, options ...Base return &BaseDendrite{ ProcessContext: process.NewProcessContext(), - componentName: componentName, - UseHTTPAPIs: useHTTPAPIs, tracerCloser: closer, Cfg: cfg, Caches: caching.NewRistrettoCache(cfg.Global.Cache.EstimatedMaxSize, cfg.Global.Cache.MaxAge, enableMetrics), @@ -262,7 +214,6 @@ func NewBaseDendrite(cfg *config.Dendrite, componentName string, options ...Base DendriteAdminMux: mux.NewRouter().SkipClean(true).PathPrefix(httputil.DendriteAdminPathPrefix).Subrouter().UseEncodedPath(), SynapseAdminMux: mux.NewRouter().SkipClean(true).PathPrefix(httputil.SynapseAdminPathPrefix).Subrouter().UseEncodedPath(), NATS: &jetstream.NATSInstance{}, - apiHttpClient: &apiClient, Database: db, // set if monolith with global connection pool only DatabaseWriter: writer, // set if monolith with global connection pool only EnableMetrics: enableMetrics, @@ -300,52 +251,6 @@ func (b *BaseDendrite) DatabaseConnection(dbProperties *config.DatabaseOptions, return nil, nil, fmt.Errorf("no database connections configured") } -// AppserviceHTTPClient returns the AppServiceInternalAPI for hitting the appservice component over HTTP. -func (b *BaseDendrite) AppserviceHTTPClient() appserviceAPI.AppServiceInternalAPI { - a, err := asinthttp.NewAppserviceClient(b.Cfg.AppServiceURL(), b.apiHttpClient) - if err != nil { - logrus.WithError(err).Panic("CreateHTTPAppServiceAPIs failed") - } - return a -} - -// RoomserverHTTPClient returns RoomserverInternalAPI for hitting the roomserver over HTTP. -func (b *BaseDendrite) RoomserverHTTPClient() roomserverAPI.RoomserverInternalAPI { - rsAPI, err := rsinthttp.NewRoomserverClient(b.Cfg.RoomServerURL(), b.apiHttpClient, b.Caches) - if err != nil { - logrus.WithError(err).Panic("RoomserverHTTPClient failed", b.apiHttpClient) - } - return rsAPI -} - -// UserAPIClient returns UserInternalAPI for hitting the userapi over HTTP. -func (b *BaseDendrite) UserAPIClient() userapi.UserInternalAPI { - userAPI, err := userapiinthttp.NewUserAPIClient(b.Cfg.UserAPIURL(), b.apiHttpClient) - if err != nil { - logrus.WithError(err).Panic("UserAPIClient failed", b.apiHttpClient) - } - return userAPI -} - -// FederationAPIHTTPClient returns FederationInternalAPI for hitting -// the federation API server over HTTP -func (b *BaseDendrite) FederationAPIHTTPClient() federationAPI.FederationInternalAPI { - f, err := federationIntHTTP.NewFederationAPIClient(b.Cfg.FederationAPIURL(), b.apiHttpClient, b.Caches) - if err != nil { - logrus.WithError(err).Panic("FederationAPIHTTPClient failed", b.apiHttpClient) - } - return f -} - -// KeyServerHTTPClient returns KeyInternalAPI for hitting the key server over HTTP -func (b *BaseDendrite) KeyServerHTTPClient() keyserverAPI.KeyInternalAPI { - f, err := keyinthttp.NewKeyServerClient(b.Cfg.KeyServerURL(), b.apiHttpClient) - if err != nil { - logrus.WithError(err).Panic("KeyServerHTTPClient failed", b.apiHttpClient) - } - return f -} - // PushGatewayHTTPClient returns a new client for interacting with (external) Push Gateways. func (b *BaseDendrite) PushGatewayHTTPClient() pushgateway.Client { return pushgateway.NewHTTPClient(b.Cfg.UserAPI.PushGatewayDisableTLSValidation) @@ -445,17 +350,15 @@ func (b *BaseDendrite) ConfigureAdminEndpoints() { // SetupAndServeHTTP sets up the HTTP server to serve endpoints registered on // ApiMux under /api/ and adds a prometheus handler under /metrics. func (b *BaseDendrite) SetupAndServeHTTP( - internalHTTPAddr, externalHTTPAddr config.HTTPAddress, + externalHTTPAddr config.HTTPAddress, certFile, keyFile *string, ) { // Manually unlocked right before actually serving requests, // as we don't return from this method (defer doesn't work). b.startupLock.Lock() - internalAddr, _ := internalHTTPAddr.Address() externalAddr, _ := externalHTTPAddr.Address() externalRouter := mux.NewRouter().SkipClean(true).UseEncodedPath() - internalRouter := externalRouter externalServ := &http.Server{ Addr: string(externalAddr), @@ -465,25 +368,6 @@ func (b *BaseDendrite) SetupAndServeHTTP( return b.ProcessContext.Context() }, } - internalServ := externalServ - - if internalAddr != NoListener && externalAddr != internalAddr { - // H2C allows us to accept HTTP/2 connections without TLS - // encryption. Since we don't currently require any form of - // authentication or encryption on these internal HTTP APIs, - // H2C gives us all of the advantages of HTTP/2 (such as - // stream multiplexing and avoiding head-of-line blocking) - // without enabling TLS. - internalH2S := &http2.Server{} - internalRouter = mux.NewRouter().SkipClean(true).UseEncodedPath() - internalServ = &http.Server{ - Addr: string(internalAddr), - Handler: h2c.NewHandler(internalRouter, internalH2S), - BaseContext: func(_ net.Listener) context.Context { - return b.ProcessContext.Context() - }, - } - } b.configureHTTPErrors() @@ -492,9 +376,9 @@ func (b *BaseDendrite) SetupAndServeHTTP( http.Redirect(w, r, httputil.PublicStaticPath, http.StatusFound) }) - internalRouter.PathPrefix(httputil.InternalPathPrefix).Handler(b.InternalAPIMux) + externalRouter.PathPrefix(httputil.DendriteAdminPathPrefix).Handler(b.InternalAPIMux) if b.Cfg.Global.Metrics.Enabled { - internalRouter.Handle("/metrics", httputil.WrapHandlerInBasicAuth(promhttp.Handler(), b.Cfg.Global.Metrics.BasicAuth)) + externalRouter.Handle("/metrics", httputil.WrapHandlerInBasicAuth(promhttp.Handler(), b.Cfg.Global.Metrics.BasicAuth)) } b.ConfigureAdminEndpoints() @@ -528,7 +412,7 @@ func (b *BaseDendrite) SetupAndServeHTTP( }) federationHandler = sentryHandler.Handle(b.PublicFederationAPIMux) } - internalRouter.PathPrefix(httputil.DendriteAdminPathPrefix).Handler(b.DendriteAdminMux) + externalRouter.PathPrefix(httputil.DendriteAdminPathPrefix).Handler(b.DendriteAdminMux) externalRouter.PathPrefix(httputil.PublicClientPathPrefix).Handler(clientHandler) if !b.Cfg.Global.DisableFederation { externalRouter.PathPrefix(httputil.PublicKeyPathPrefix).Handler(b.PublicKeyAPIMux) @@ -540,38 +424,11 @@ func (b *BaseDendrite) SetupAndServeHTTP( externalRouter.PathPrefix(httputil.PublicStaticPath).Handler(b.PublicStaticMux) b.startupLock.Unlock() - if internalAddr != NoListener && internalAddr != externalAddr { - go func() { - var internalShutdown atomic.Bool // RegisterOnShutdown can be called more than once - logrus.Infof("Starting internal %s listener on %s", b.componentName, internalServ.Addr) - b.ProcessContext.ComponentStarted() - internalServ.RegisterOnShutdown(func() { - if internalShutdown.CompareAndSwap(false, true) { - b.ProcessContext.ComponentFinished() - logrus.Infof("Stopped internal HTTP listener") - } - }) - if certFile != nil && keyFile != nil { - if err := internalServ.ListenAndServeTLS(*certFile, *keyFile); err != nil { - if err != http.ErrServerClosed { - logrus.WithError(err).Fatal("failed to serve HTTPS") - } - } - } else { - if err := internalServ.ListenAndServe(); err != nil { - if err != http.ErrServerClosed { - logrus.WithError(err).Fatal("failed to serve HTTP") - } - } - } - logrus.Infof("Stopped internal %s listener on %s", b.componentName, internalServ.Addr) - }() - } if externalAddr != NoListener { go func() { var externalShutdown atomic.Bool // RegisterOnShutdown can be called more than once - logrus.Infof("Starting external %s listener on %s", b.componentName, externalServ.Addr) + logrus.Infof("Starting external listener on %s", externalServ.Addr) b.ProcessContext.ComponentStarted() externalServ.RegisterOnShutdown(func() { if externalShutdown.CompareAndSwap(false, true) { @@ -592,7 +449,7 @@ func (b *BaseDendrite) SetupAndServeHTTP( } } } - logrus.Infof("Stopped external %s listener on %s", b.componentName, externalServ.Addr) + logrus.Infof("Stopped external listener on %s", externalServ.Addr) }() } @@ -600,7 +457,6 @@ func (b *BaseDendrite) SetupAndServeHTTP( <-b.ProcessContext.WaitForShutdown() logrus.Infof("Stopping HTTP listeners") - _ = internalServ.Shutdown(context.Background()) _ = externalServ.Shutdown(context.Background()) logrus.Infof("Stopped HTTP listeners") } diff --git a/setup/base/base_test.go b/setup/base/base_test.go index 61cb530a9..d906294c0 100644 --- a/setup/base/base_test.go +++ b/setup/base/base_test.go @@ -35,7 +35,7 @@ func TestLandingPage(t *testing.T) { s.Close() // start base with the listener and wait for it to be started - go b.SetupAndServeHTTP("", config.HTTPAddress(s.URL), nil, nil) + go b.SetupAndServeHTTP(config.HTTPAddress(s.URL), nil, nil) time.Sleep(time.Millisecond * 10) // When hitting /, we should be redirected to /_matrix/static, which should contain the landing page diff --git a/setup/config/config.go b/setup/config/config.go index 2b38cd512..85b86bfba 100644 --- a/setup/config/config.go +++ b/setup/config/config.go @@ -79,8 +79,6 @@ type Dendrite struct { // Any information derived from the configuration options for later use. Derived Derived `yaml:"-"` - - IsMonolith bool `yaml:"-"` } // TODO: Kill Derived @@ -191,7 +189,7 @@ type ConfigErrors []string // Load a yaml config file for a server run as multiple processes or as a monolith. // Checks the config to ensure that it is valid. -func Load(configPath string, monolith bool) (*Dendrite, error) { +func Load(configPath string) (*Dendrite, error) { configData, err := os.ReadFile(configPath) if err != nil { return nil, err @@ -202,28 +200,26 @@ func Load(configPath string, monolith bool) (*Dendrite, error) { } // Pass the current working directory and os.ReadFile so that they can // be mocked in the tests - return loadConfig(basePath, configData, os.ReadFile, monolith) + return loadConfig(basePath, configData, os.ReadFile) } func loadConfig( basePath string, configData []byte, readFile func(string) ([]byte, error), - monolithic bool, ) (*Dendrite, error) { var c Dendrite c.Defaults(DefaultOpts{ - Generate: false, - Monolithic: monolithic, + Generate: false, + SingleDatabase: true, }) - c.IsMonolith = monolithic var err error if err = yaml.Unmarshal(configData, &c); err != nil { return nil, err } - if err = c.check(monolithic); err != nil { + if err = c.check(); err != nil { return nil, err } @@ -333,8 +329,8 @@ func (config *Dendrite) Derive() error { } type DefaultOpts struct { - Generate bool - Monolithic bool + Generate bool + SingleDatabase bool } // SetDefaults sets default config values if they are not explicitly set. @@ -355,9 +351,9 @@ func (c *Dendrite) Defaults(opts DefaultOpts) { c.Wiring() } -func (c *Dendrite) Verify(configErrs *ConfigErrors, isMonolith bool) { +func (c *Dendrite) Verify(configErrs *ConfigErrors) { type verifiable interface { - Verify(configErrs *ConfigErrors, isMonolith bool) + Verify(configErrs *ConfigErrors) } for _, c := range []verifiable{ &c.Global, &c.ClientAPI, &c.FederationAPI, @@ -365,7 +361,7 @@ func (c *Dendrite) Verify(configErrs *ConfigErrors, isMonolith bool) { &c.SyncAPI, &c.UserAPI, &c.AppServiceAPI, &c.RelayAPI, &c.MSCs, } { - c.Verify(configErrs, isMonolith) + c.Verify(configErrs) } } @@ -461,7 +457,7 @@ func (config *Dendrite) checkLogging(configErrs *ConfigErrors) { // check returns an error type containing all errors found within the config // file. -func (config *Dendrite) check(_ bool) error { // monolithic +func (config *Dendrite) check() error { // monolithic var configErrs ConfigErrors if config.Version != Version { @@ -528,51 +524,6 @@ func readKeyPEM(path string, data []byte, enforceKeyIDFormat bool) (gomatrixserv } } -// AppServiceURL returns a HTTP URL for where the appservice component is listening. -func (config *Dendrite) AppServiceURL() string { - // Hard code the appservice server to talk HTTP for now. - // If we support HTTPS we need to think of a practical way to do certificate validation. - // People setting up servers shouldn't need to get a certificate valid for the public - // internet for an internal API. - return string(config.AppServiceAPI.InternalAPI.Connect) -} - -// FederationAPIURL returns an HTTP URL for where the federation API is listening. -func (config *Dendrite) FederationAPIURL() string { - // Hard code the federationapi to talk HTTP for now. - // If we support HTTPS we need to think of a practical way to do certificate validation. - // People setting up servers shouldn't need to get a certificate valid for the public - // internet for an internal API. - return string(config.FederationAPI.InternalAPI.Connect) -} - -// RoomServerURL returns an HTTP URL for where the roomserver is listening. -func (config *Dendrite) RoomServerURL() string { - // Hard code the roomserver to talk HTTP for now. - // If we support HTTPS we need to think of a practical way to do certificate validation. - // People setting up servers shouldn't need to get a certificate valid for the public - // internet for an internal API. - return string(config.RoomServer.InternalAPI.Connect) -} - -// UserAPIURL returns an HTTP URL for where the userapi is listening. -func (config *Dendrite) UserAPIURL() string { - // Hard code the userapi to talk HTTP for now. - // If we support HTTPS we need to think of a practical way to do certificate validation. - // People setting up servers shouldn't need to get a certificate valid for the public - // internet for an internal API. - return string(config.UserAPI.InternalAPI.Connect) -} - -// KeyServerURL returns an HTTP URL for where the key server is listening. -func (config *Dendrite) KeyServerURL() string { - // Hard code the key server to talk HTTP for now. - // If we support HTTPS we need to think of a practical way to do certificate validation. - // People setting up servers shouldn't need to get a certificate valid for the public - // internet for an internal API. - return string(config.KeyServer.InternalAPI.Connect) -} - // SetupTracing configures the opentracing using the supplied configuration. func (config *Dendrite) SetupTracing(serviceName string) (closer io.Closer, err error) { if !config.Tracing.Enabled { diff --git a/setup/config/config_appservice.go b/setup/config/config_appservice.go index bd21826fe..37e20a978 100644 --- a/setup/config/config_appservice.go +++ b/setup/config/config_appservice.go @@ -22,15 +22,13 @@ import ( "strings" log "github.com/sirupsen/logrus" - yaml "gopkg.in/yaml.v2" + "gopkg.in/yaml.v2" ) type AppServiceAPI struct { Matrix *Global `yaml:"-"` Derived *Derived `yaml:"-"` // TODO: Nuke Derived from orbit - InternalAPI InternalAPIOptions `yaml:"internal_api,omitempty"` - // DisableTLSValidation disables the validation of X.509 TLS certs // on appservice endpoints. This is not recommended in production! DisableTLSValidation bool `yaml:"disable_tls_validation"` @@ -39,18 +37,9 @@ type AppServiceAPI struct { } func (c *AppServiceAPI) Defaults(opts DefaultOpts) { - if !opts.Monolithic { - c.InternalAPI.Listen = "http://localhost:7777" - c.InternalAPI.Connect = "http://localhost:7777" - } } -func (c *AppServiceAPI) Verify(configErrs *ConfigErrors, isMonolith bool) { - if isMonolith { // polylith required configs below - return - } - checkURL(configErrs, "app_service_api.internal_api.listen", string(c.InternalAPI.Listen)) - checkURL(configErrs, "app_service_api.internal_api.connect", string(c.InternalAPI.Connect)) +func (c *AppServiceAPI) Verify(configErrs *ConfigErrors) { } // ApplicationServiceNamespace is the namespace that a specific application diff --git a/setup/config/config_clientapi.go b/setup/config/config_clientapi.go index 1deba6bb5..b6c74a75f 100644 --- a/setup/config/config_clientapi.go +++ b/setup/config/config_clientapi.go @@ -9,9 +9,6 @@ type ClientAPI struct { Matrix *Global `yaml:"-"` Derived *Derived `yaml:"-"` // TODO: Nuke Derived from orbit - InternalAPI InternalAPIOptions `yaml:"internal_api,omitempty"` - ExternalAPI ExternalAPIOptions `yaml:"external_api,omitempty"` - // If set disables new users from registering (except via shared // secrets) RegistrationDisabled bool `yaml:"registration_disabled"` @@ -58,11 +55,6 @@ type ClientAPI struct { } func (c *ClientAPI) Defaults(opts DefaultOpts) { - if !opts.Monolithic { - c.InternalAPI.Listen = "http://localhost:7771" - c.InternalAPI.Connect = "http://localhost:7771" - c.ExternalAPI.Listen = "http://[::]:8071" - } c.RegistrationSharedSecret = "" c.RecaptchaPublicKey = "" c.RecaptchaPrivateKey = "" @@ -74,7 +66,7 @@ func (c *ClientAPI) Defaults(opts DefaultOpts) { c.RateLimiting.Defaults() } -func (c *ClientAPI) Verify(configErrs *ConfigErrors, isMonolith bool) { +func (c *ClientAPI) Verify(configErrs *ConfigErrors) { c.TURN.Verify(configErrs) c.RateLimiting.Verify(configErrs) if c.RecaptchaEnabled { @@ -108,12 +100,6 @@ func (c *ClientAPI) Verify(configErrs *ConfigErrors, isMonolith bool) { ) } } - if isMonolith { // polylith required configs below - return - } - checkURL(configErrs, "client_api.internal_api.listen", string(c.InternalAPI.Listen)) - checkURL(configErrs, "client_api.internal_api.connect", string(c.InternalAPI.Connect)) - checkURL(configErrs, "client_api.external_api.listen", string(c.ExternalAPI.Listen)) } type TURN struct { diff --git a/setup/config/config_federationapi.go b/setup/config/config_federationapi.go index cd7d90562..ecfcfd455 100644 --- a/setup/config/config_federationapi.go +++ b/setup/config/config_federationapi.go @@ -5,9 +5,6 @@ import "github.com/matrix-org/gomatrixserverlib" type FederationAPI struct { Matrix *Global `yaml:"-"` - InternalAPI InternalAPIOptions `yaml:"internal_api,omitempty"` - ExternalAPI ExternalAPIOptions `yaml:"external_api,omitempty"` - // The database stores information used by the federation destination queues to // send transactions to remote servers. Database DatabaseOptions `yaml:"database,omitempty"` @@ -42,12 +39,6 @@ type FederationAPI struct { } func (c *FederationAPI) Defaults(opts DefaultOpts) { - if !opts.Monolithic { - c.InternalAPI.Listen = "http://localhost:7772" - c.InternalAPI.Connect = "http://localhost:7772" - c.ExternalAPI.Listen = "http://[::]:8072" - c.Database.Defaults(10) - } c.FederationMaxRetries = 16 c.P2PFederationRetriesUntilAssumedOffline = 1 c.DisableTLSValidation = false @@ -68,22 +59,16 @@ func (c *FederationAPI) Defaults(opts DefaultOpts) { }, }, } - if !opts.Monolithic { + if !opts.SingleDatabase { c.Database.ConnectionString = "file:federationapi.db" } } } -func (c *FederationAPI) Verify(configErrs *ConfigErrors, isMonolith bool) { - if isMonolith { // polylith required configs below - return - } +func (c *FederationAPI) Verify(configErrs *ConfigErrors) { if c.Matrix.DatabaseOptions.ConnectionString == "" { checkNotEmpty(configErrs, "federation_api.database.connection_string", string(c.Database.ConnectionString)) } - checkURL(configErrs, "federation_api.external_api.listen", string(c.ExternalAPI.Listen)) - checkURL(configErrs, "federation_api.internal_api.listen", string(c.InternalAPI.Listen)) - checkURL(configErrs, "federation_api.internal_api.connect", string(c.InternalAPI.Connect)) } // The config for setting a proxy to use for server->server requests diff --git a/setup/config/config_global.go b/setup/config/config_global.go index 804eb1a2d..bb3a86abd 100644 --- a/setup/config/config_global.go +++ b/setup/config/config_global.go @@ -38,7 +38,6 @@ type Global struct { // component does not specify any database options of its own, then this pool of // connections will be used instead. This way we don't have to manage connection // counts on a per-component basis, but can instead do it for the entire monolith. - // In a polylith deployment, this will be ignored. DatabaseOptions DatabaseOptions `yaml:"database,omitempty"` // The server name to delegate server-server communications to, with optional port @@ -93,7 +92,7 @@ func (c *Global) Defaults(opts DefaultOpts) { } } c.KeyValidityPeriod = time.Hour * 24 * 7 - if opts.Monolithic { + if opts.SingleDatabase { c.DatabaseOptions.Defaults(90) } c.JetStream.Defaults(opts) @@ -105,7 +104,7 @@ func (c *Global) Defaults(opts DefaultOpts) { c.Cache.Defaults() } -func (c *Global) Verify(configErrs *ConfigErrors, isMonolith bool) { +func (c *Global) Verify(configErrs *ConfigErrors) { checkNotEmpty(configErrs, "global.server_name", string(c.ServerName)) checkNotEmpty(configErrs, "global.private_key", string(c.PrivateKeyPath)) @@ -113,13 +112,13 @@ func (c *Global) Verify(configErrs *ConfigErrors, isMonolith bool) { v.Verify(configErrs) } - c.JetStream.Verify(configErrs, isMonolith) - c.Metrics.Verify(configErrs, isMonolith) - c.Sentry.Verify(configErrs, isMonolith) - c.DNSCache.Verify(configErrs, isMonolith) - c.ServerNotices.Verify(configErrs, isMonolith) - c.ReportStats.Verify(configErrs, isMonolith) - c.Cache.Verify(configErrs, isMonolith) + c.JetStream.Verify(configErrs) + c.Metrics.Verify(configErrs) + c.Sentry.Verify(configErrs) + c.DNSCache.Verify(configErrs) + c.ServerNotices.Verify(configErrs) + c.ReportStats.Verify(configErrs) + c.Cache.Verify(configErrs) } func (c *Global) IsLocalServerName(serverName gomatrixserverlib.ServerName) bool { @@ -267,7 +266,7 @@ func (c *Metrics) Defaults(opts DefaultOpts) { } } -func (c *Metrics) Verify(configErrs *ConfigErrors, isMonolith bool) { +func (c *Metrics) Verify(configErrs *ConfigErrors) { } // ServerNotices defines the configuration used for sending server notices @@ -293,7 +292,7 @@ func (c *ServerNotices) Defaults(opts DefaultOpts) { } } -func (c *ServerNotices) Verify(errors *ConfigErrors, isMonolith bool) {} +func (c *ServerNotices) Verify(errors *ConfigErrors) {} type Cache struct { EstimatedMaxSize DataUnit `yaml:"max_size_estimated"` @@ -305,7 +304,7 @@ func (c *Cache) Defaults() { c.MaxAge = time.Hour } -func (c *Cache) Verify(errors *ConfigErrors, isMonolith bool) { +func (c *Cache) Verify(errors *ConfigErrors) { checkPositive(errors, "max_size_estimated", int64(c.EstimatedMaxSize)) } @@ -323,7 +322,7 @@ func (c *ReportStats) Defaults() { c.Endpoint = "https://matrix.org/report-usage-stats/push" } -func (c *ReportStats) Verify(configErrs *ConfigErrors, isMonolith bool) { +func (c *ReportStats) Verify(configErrs *ConfigErrors) { if c.Enabled { checkNotEmpty(configErrs, "global.report_stats.endpoint", c.Endpoint) } @@ -344,7 +343,7 @@ func (c *Sentry) Defaults() { c.Enabled = false } -func (c *Sentry) Verify(configErrs *ConfigErrors, isMonolith bool) { +func (c *Sentry) Verify(configErrs *ConfigErrors) { } type DatabaseOptions struct { @@ -397,7 +396,7 @@ func (c *DNSCacheOptions) Defaults() { c.CacheLifetime = time.Minute * 5 } -func (c *DNSCacheOptions) Verify(configErrs *ConfigErrors, isMonolith bool) { +func (c *DNSCacheOptions) Verify(configErrs *ConfigErrors) { checkPositive(configErrs, "cache_size", int64(c.CacheSize)) checkPositive(configErrs, "cache_lifetime", int64(c.CacheLifetime)) } diff --git a/setup/config/config_jetstream.go b/setup/config/config_jetstream.go index ef8bf014b..b8abed25c 100644 --- a/setup/config/config_jetstream.go +++ b/setup/config/config_jetstream.go @@ -41,11 +41,4 @@ func (c *JetStream) Defaults(opts DefaultOpts) { } } -func (c *JetStream) Verify(configErrs *ConfigErrors, isMonolith bool) { - if isMonolith { // polylith required configs below - return - } - // If we are running in a polylith deployment then we need at least - // one NATS JetStream server to talk to. - checkNotZero(configErrs, "global.jetstream.addresses", int64(len(c.Addresses))) -} +func (c *JetStream) Verify(configErrs *ConfigErrors) {} diff --git a/setup/config/config_keyserver.go b/setup/config/config_keyserver.go index dca9ca9f5..64710d957 100644 --- a/setup/config/config_keyserver.go +++ b/setup/config/config_keyserver.go @@ -3,31 +3,19 @@ package config type KeyServer struct { Matrix *Global `yaml:"-"` - InternalAPI InternalAPIOptions `yaml:"internal_api,omitempty"` - Database DatabaseOptions `yaml:"database,omitempty"` } func (c *KeyServer) Defaults(opts DefaultOpts) { - if !opts.Monolithic { - c.InternalAPI.Listen = "http://localhost:7779" - c.InternalAPI.Connect = "http://localhost:7779" - c.Database.Defaults(10) - } if opts.Generate { - if !opts.Monolithic { + if !opts.SingleDatabase { c.Database.ConnectionString = "file:keyserver.db" } } } -func (c *KeyServer) Verify(configErrs *ConfigErrors, isMonolith bool) { - if isMonolith { // polylith required configs below - return - } +func (c *KeyServer) Verify(configErrs *ConfigErrors) { if c.Matrix.DatabaseOptions.ConnectionString == "" { checkNotEmpty(configErrs, "key_server.database.connection_string", string(c.Database.ConnectionString)) } - checkURL(configErrs, "key_server.internal_api.listen", string(c.InternalAPI.Listen)) - checkURL(configErrs, "key_server.internal_api.connect", string(c.InternalAPI.Connect)) } diff --git a/setup/config/config_mediaapi.go b/setup/config/config_mediaapi.go index 53a8219eb..030bc3754 100644 --- a/setup/config/config_mediaapi.go +++ b/setup/config/config_mediaapi.go @@ -7,9 +7,6 @@ import ( type MediaAPI struct { Matrix *Global `yaml:"-"` - InternalAPI InternalAPIOptions `yaml:"internal_api,omitempty"` - ExternalAPI ExternalAPIOptions `yaml:"external_api,omitempty"` - // The MediaAPI database stores information about files uploaded and downloaded // by local users. It is only accessed by the MediaAPI. Database DatabaseOptions `yaml:"database,omitempty"` @@ -39,12 +36,6 @@ type MediaAPI struct { var DefaultMaxFileSizeBytes = FileSizeBytes(10485760) func (c *MediaAPI) Defaults(opts DefaultOpts) { - if !opts.Monolithic { - c.InternalAPI.Listen = "http://localhost:7774" - c.InternalAPI.Connect = "http://localhost:7774" - c.ExternalAPI.Listen = "http://[::]:8074" - c.Database.Defaults(5) - } c.MaxFileSizeBytes = DefaultMaxFileSizeBytes c.MaxThumbnailGenerators = 10 if opts.Generate { @@ -65,14 +56,14 @@ func (c *MediaAPI) Defaults(opts DefaultOpts) { ResizeMethod: "scale", }, } - if !opts.Monolithic { + if !opts.SingleDatabase { c.Database.ConnectionString = "file:mediaapi.db" } c.BasePath = "./media_store" } } -func (c *MediaAPI) Verify(configErrs *ConfigErrors, isMonolith bool) { +func (c *MediaAPI) Verify(configErrs *ConfigErrors) { checkNotEmpty(configErrs, "media_api.base_path", string(c.BasePath)) checkPositive(configErrs, "media_api.max_file_size_bytes", int64(c.MaxFileSizeBytes)) checkPositive(configErrs, "media_api.max_thumbnail_generators", int64(c.MaxThumbnailGenerators)) @@ -81,13 +72,8 @@ func (c *MediaAPI) Verify(configErrs *ConfigErrors, isMonolith bool) { checkPositive(configErrs, fmt.Sprintf("media_api.thumbnail_sizes[%d].width", i), int64(size.Width)) checkPositive(configErrs, fmt.Sprintf("media_api.thumbnail_sizes[%d].height", i), int64(size.Height)) } - if isMonolith { // polylith required configs below - return - } + if c.Matrix.DatabaseOptions.ConnectionString == "" { checkNotEmpty(configErrs, "media_api.database.connection_string", string(c.Database.ConnectionString)) } - checkURL(configErrs, "media_api.internal_api.listen", string(c.InternalAPI.Listen)) - checkURL(configErrs, "media_api.internal_api.connect", string(c.InternalAPI.Connect)) - checkURL(configErrs, "media_api.external_api.listen", string(c.ExternalAPI.Listen)) } diff --git a/setup/config/config_mscs.go b/setup/config/config_mscs.go index 6d5ff39a5..21d4b4da0 100644 --- a/setup/config/config_mscs.go +++ b/setup/config/config_mscs.go @@ -14,11 +14,8 @@ type MSCs struct { } func (c *MSCs) Defaults(opts DefaultOpts) { - if !opts.Monolithic { - c.Database.Defaults(5) - } if opts.Generate { - if !opts.Monolithic { + if !opts.SingleDatabase { c.Database.ConnectionString = "file:mscs.db" } } @@ -34,10 +31,7 @@ func (c *MSCs) Enabled(msc string) bool { return false } -func (c *MSCs) Verify(configErrs *ConfigErrors, isMonolith bool) { - if isMonolith { // polylith required configs below - return - } +func (c *MSCs) Verify(configErrs *ConfigErrors) { if c.Matrix.DatabaseOptions.ConnectionString == "" { checkNotEmpty(configErrs, "mscs.database.connection_string", string(c.Database.ConnectionString)) } diff --git a/setup/config/config_relayapi.go b/setup/config/config_relayapi.go index 5a6b093d4..ba7b78082 100644 --- a/setup/config/config_relayapi.go +++ b/setup/config/config_relayapi.go @@ -17,36 +17,21 @@ package config type RelayAPI struct { Matrix *Global `yaml:"-"` - InternalAPI InternalAPIOptions `yaml:"internal_api,omitempty"` - ExternalAPI ExternalAPIOptions `yaml:"external_api,omitempty"` - // The database stores information used by the relay queue to // forward transactions to remote servers. Database DatabaseOptions `yaml:"database,omitempty"` } func (c *RelayAPI) Defaults(opts DefaultOpts) { - if !opts.Monolithic { - c.InternalAPI.Listen = "http://localhost:7775" - c.InternalAPI.Connect = "http://localhost:7775" - c.ExternalAPI.Listen = "http://[::]:8075" - c.Database.Defaults(10) - } if opts.Generate { - if !opts.Monolithic { + if !opts.SingleDatabase { c.Database.ConnectionString = "file:relayapi.db" } } } -func (c *RelayAPI) Verify(configErrs *ConfigErrors, isMonolith bool) { - if isMonolith { // polylith required configs below - return - } +func (c *RelayAPI) Verify(configErrs *ConfigErrors) { if c.Matrix.DatabaseOptions.ConnectionString == "" { checkNotEmpty(configErrs, "relay_api.database.connection_string", string(c.Database.ConnectionString)) } - checkURL(configErrs, "relay_api.external_api.listen", string(c.ExternalAPI.Listen)) - checkURL(configErrs, "relay_api.internal_api.listen", string(c.InternalAPI.Listen)) - checkURL(configErrs, "relay_api.internal_api.connect", string(c.InternalAPI.Connect)) } diff --git a/setup/config/config_roomserver.go b/setup/config/config_roomserver.go index 5e3b7f2ec..319c2419c 100644 --- a/setup/config/config_roomserver.go +++ b/setup/config/config_roomserver.go @@ -3,31 +3,19 @@ package config type RoomServer struct { Matrix *Global `yaml:"-"` - InternalAPI InternalAPIOptions `yaml:"internal_api,omitempty"` - Database DatabaseOptions `yaml:"database,omitempty"` } func (c *RoomServer) Defaults(opts DefaultOpts) { - if !opts.Monolithic { - c.InternalAPI.Listen = "http://localhost:7770" - c.InternalAPI.Connect = "http://localhost:7770" - c.Database.Defaults(20) - } if opts.Generate { - if !opts.Monolithic { + if !opts.SingleDatabase { c.Database.ConnectionString = "file:roomserver.db" } } } -func (c *RoomServer) Verify(configErrs *ConfigErrors, isMonolith bool) { - if isMonolith { // polylith required configs below - return - } +func (c *RoomServer) Verify(configErrs *ConfigErrors) { if c.Matrix.DatabaseOptions.ConnectionString == "" { checkNotEmpty(configErrs, "room_server.database.connection_string", string(c.Database.ConnectionString)) } - checkURL(configErrs, "room_server.internal_api.listen", string(c.InternalAPI.Listen)) - checkURL(configErrs, "room_server.internal_ap.connect", string(c.InternalAPI.Connect)) } diff --git a/setup/config/config_syncapi.go b/setup/config/config_syncapi.go index a87da3732..756f4cfb3 100644 --- a/setup/config/config_syncapi.go +++ b/setup/config/config_syncapi.go @@ -3,9 +3,6 @@ package config type SyncAPI struct { Matrix *Global `yaml:"-"` - InternalAPI InternalAPIOptions `yaml:"internal_api,omitempty"` - ExternalAPI ExternalAPIOptions `yaml:"external_api,omitempty"` - Database DatabaseOptions `yaml:"database,omitempty"` RealIPHeader string `yaml:"real_ip_header"` @@ -14,31 +11,19 @@ type SyncAPI struct { } func (c *SyncAPI) Defaults(opts DefaultOpts) { - if !opts.Monolithic { - c.InternalAPI.Listen = "http://localhost:7773" - c.InternalAPI.Connect = "http://localhost:7773" - c.ExternalAPI.Listen = "http://localhost:8073" - c.Database.Defaults(20) - } c.Fulltext.Defaults(opts) if opts.Generate { - if !opts.Monolithic { + if !opts.SingleDatabase { c.Database.ConnectionString = "file:syncapi.db" } } } -func (c *SyncAPI) Verify(configErrs *ConfigErrors, isMonolith bool) { - c.Fulltext.Verify(configErrs, isMonolith) - if isMonolith { // polylith required configs below - return - } +func (c *SyncAPI) Verify(configErrs *ConfigErrors) { + c.Fulltext.Verify(configErrs) if c.Matrix.DatabaseOptions.ConnectionString == "" { checkNotEmpty(configErrs, "sync_api.database", string(c.Database.ConnectionString)) } - checkURL(configErrs, "sync_api.internal_api.listen", string(c.InternalAPI.Listen)) - checkURL(configErrs, "sync_api.internal_api.connect", string(c.InternalAPI.Connect)) - checkURL(configErrs, "sync_api.external_api.listen", string(c.ExternalAPI.Listen)) } type Fulltext struct { @@ -54,7 +39,7 @@ func (f *Fulltext) Defaults(opts DefaultOpts) { f.Language = "en" } -func (f *Fulltext) Verify(configErrs *ConfigErrors, isMonolith bool) { +func (f *Fulltext) Verify(configErrs *ConfigErrors) { if !f.Enabled { return } diff --git a/setup/config/config_test.go b/setup/config/config_test.go index ffbf4c3c5..79407f30d 100644 --- a/setup/config/config_test.go +++ b/setup/config/config_test.go @@ -30,14 +30,13 @@ func TestLoadConfigRelative(t *testing.T) { "/my/config/dir/matrix_key.pem": testKey, "/my/config/dir/tls_cert.pem": testCert, }.readFile, - false, ) if err != nil { t.Error("failed to load config:", err) } configErrors := &ConfigErrors{} - cfg.Verify(configErrors, false) + cfg.Verify(configErrors) if len(*configErrors) > 0 { for _, err := range *configErrors { logrus.Errorf("Configuration error: %s", err) @@ -81,9 +80,6 @@ global: jetstream: addresses: ["test"] app_service_api: - internal_api: - listen: http://localhost:7777 - connect: http://localhost:7777 database: connection_string: file:appservice.db max_open_conns: 100 @@ -91,11 +87,6 @@ app_service_api: conn_max_lifetime: -1 config_files: [] client_api: - internal_api: - listen: http://localhost:7771 - connect: http://localhost:7771 - external_api: - listen: http://[::]:8071 registration_disabled: true registration_shared_secret: "" enable_registration_captcha: false @@ -109,38 +100,16 @@ client_api: turn_shared_secret: "" turn_username: "" turn_password: "" -current_state_server: - internal_api: - listen: http://localhost:7782 - connect: http://localhost:7782 - database: - connection_string: file:currentstate.db - max_open_conns: 100 - max_idle_conns: 2 - conn_max_lifetime: -1 federation_api: - internal_api: - listen: http://localhost:7772 - connect: http://localhost:7772 - external_api: - listen: http://[::]:8072 database: connection_string: file:federationapi.db key_server: - internal_api: - listen: http://localhost:7779 - connect: http://localhost:7779 database: connection_string: file:keyserver.db max_open_conns: 100 max_idle_conns: 2 conn_max_lifetime: -1 media_api: - internal_api: - listen: http://localhost:7774 - connect: http://localhost:7774 - external_api: - listen: http://[::]:8074 database: connection_string: file:mediaapi.db max_open_conns: 100 @@ -161,18 +130,12 @@ media_api: height: 480 method: scale room_server: - internal_api: - listen: http://localhost:7770 - connect: http://localhost:7770 database: connection_string: file:roomserver.db max_open_conns: 100 max_idle_conns: 2 conn_max_lifetime: -1 server_key_api: - internal_api: - listen: http://localhost:7780 - connect: http://localhost:7780 database: connection_string: file:serverkeyapi.db max_open_conns: 100 @@ -186,18 +149,12 @@ server_key_api: - key_id: ed25519:a_RXGa public_key: l8Hft5qXKn1vfHrg3p4+W8gELQVo8N13JkluMfmn2sQ sync_api: - internal_api: - listen: http://localhost:7773 - connect: http://localhost:7773 database: connection_string: file:syncapi.db max_open_conns: 100 max_idle_conns: 2 conn_max_lifetime: -1 user_api: - internal_api: - listen: http://localhost:7781 - connect: http://localhost:7781 account_database: connection_string: file:userapi_accounts.db max_open_conns: 100 @@ -209,11 +166,6 @@ user_api: max_idle_conns: 2 conn_max_lifetime: -1 relay_api: - internal_api: - listen: http://localhost:7775 - connect: http://localhost:7775 - external_api: - listen: http://[::]:8075 database: connection_string: file:relayapi.db mscs: diff --git a/setup/config/config_userapi.go b/setup/config/config_userapi.go index f8ad41d93..e64a3910c 100644 --- a/setup/config/config_userapi.go +++ b/setup/config/config_userapi.go @@ -5,8 +5,6 @@ import "golang.org/x/crypto/bcrypt" type UserAPI struct { Matrix *Global `yaml:"-"` - InternalAPI InternalAPIOptions `yaml:"internal_api,omitempty"` - // The cost when hashing passwords. BCryptCost int `yaml:"bcrypt_cost"` @@ -28,28 +26,18 @@ type UserAPI struct { const DefaultOpenIDTokenLifetimeMS = 3600000 // 60 minutes func (c *UserAPI) Defaults(opts DefaultOpts) { - if !opts.Monolithic { - c.InternalAPI.Listen = "http://localhost:7781" - c.InternalAPI.Connect = "http://localhost:7781" - c.AccountDatabase.Defaults(10) - } c.BCryptCost = bcrypt.DefaultCost c.OpenIDTokenLifetimeMS = DefaultOpenIDTokenLifetimeMS if opts.Generate { - if !opts.Monolithic { + if !opts.SingleDatabase { c.AccountDatabase.ConnectionString = "file:userapi_accounts.db" } } } -func (c *UserAPI) Verify(configErrs *ConfigErrors, isMonolith bool) { +func (c *UserAPI) Verify(configErrs *ConfigErrors) { checkPositive(configErrs, "user_api.openid_token_lifetime_ms", c.OpenIDTokenLifetimeMS) - if isMonolith { // polylith required configs below - return - } if c.Matrix.DatabaseOptions.ConnectionString == "" { checkNotEmpty(configErrs, "user_api.account_database.connection_string", string(c.AccountDatabase.ConnectionString)) } - checkURL(configErrs, "user_api.internal_api.listen", string(c.InternalAPI.Listen)) - checkURL(configErrs, "user_api.internal_api.connect", string(c.InternalAPI.Connect)) } diff --git a/setup/flags.go b/setup/flags.go index a9dac61a1..869caa280 100644 --- a/setup/flags.go +++ b/setup/flags.go @@ -43,7 +43,7 @@ func ParseFlags(monolith bool) *config.Dendrite { logrus.Fatal("--config must be supplied") } - cfg, err := config.Load(*configPath, monolith) + cfg, err := config.Load(*configPath) if err != nil { logrus.Fatalf("Invalid config file: %s", err) diff --git a/setup/mscs/msc2836/msc2836_test.go b/setup/mscs/msc2836/msc2836_test.go index 0388fcc53..7d9552683 100644 --- a/setup/mscs/msc2836/msc2836_test.go +++ b/setup/mscs/msc2836/msc2836_test.go @@ -548,8 +548,8 @@ func injectEvents(t *testing.T, userAPI userapi.UserInternalAPI, rsAPI roomserve t.Helper() cfg := &config.Dendrite{} cfg.Defaults(config.DefaultOpts{ - Generate: true, - Monolithic: true, + Generate: true, + SingleDatabase: true, }) cfg.Global.ServerName = "localhost" cfg.MSCs.Database.ConnectionString = "file:msc2836_test.db" diff --git a/syncapi/internal/history_visibility.go b/syncapi/internal/history_visibility.go index 87c59e03e..ee695f0f5 100644 --- a/syncapi/internal/history_visibility.go +++ b/syncapi/internal/history_visibility.go @@ -33,8 +33,7 @@ func init() { } // calculateHistoryVisibilityDuration stores the time it takes to -// calculate the history visibility. In polylith mode the roundtrip -// to the roomserver is included in this time. +// calculate the history visibility. var calculateHistoryVisibilityDuration = prometheus.NewHistogramVec( prometheus.HistogramOpts{ Namespace: "dendrite", diff --git a/test/testrig/base.go b/test/testrig/base.go index dfc0d8aaf..34f219c5f 100644 --- a/test/testrig/base.go +++ b/test/testrig/base.go @@ -28,24 +28,24 @@ import ( func CreateBaseDendrite(t *testing.T, dbType test.DBType) (*base.BaseDendrite, func()) { var cfg config.Dendrite cfg.Defaults(config.DefaultOpts{ - Generate: false, - Monolithic: true, + Generate: false, + SingleDatabase: true, }) cfg.Global.JetStream.InMemory = true cfg.FederationAPI.KeyPerspectives = nil switch dbType { case test.DBTypePostgres: cfg.Global.Defaults(config.DefaultOpts{ // autogen a signing key - Generate: true, - Monolithic: true, + Generate: true, + SingleDatabase: true, }) cfg.MediaAPI.Defaults(config.DefaultOpts{ // autogen a media path - Generate: true, - Monolithic: true, + Generate: true, + SingleDatabase: true, }) cfg.SyncAPI.Fulltext.Defaults(config.DefaultOpts{ // use in memory fts - Generate: true, - Monolithic: true, + Generate: true, + SingleDatabase: true, }) cfg.Global.ServerName = "test" // use a distinct prefix else concurrent postgres/sqlite runs will clash since NATS will use @@ -66,8 +66,8 @@ func CreateBaseDendrite(t *testing.T, dbType test.DBType) (*base.BaseDendrite, f } case test.DBTypeSQLite: cfg.Defaults(config.DefaultOpts{ - Generate: true, - Monolithic: true, + Generate: true, + SingleDatabase: true, }) cfg.Global.ServerName = "test" @@ -102,8 +102,8 @@ func Base(cfg *config.Dendrite) (*base.BaseDendrite, nats.JetStreamContext, *nat if cfg == nil { cfg = &config.Dendrite{} cfg.Defaults(config.DefaultOpts{ - Generate: true, - Monolithic: true, + Generate: true, + SingleDatabase: true, }) } cfg.Global.JetStream.InMemory = true diff --git a/userapi/inthttp/client.go b/userapi/inthttp/client.go deleted file mode 100644 index 51b0fe3ef..000000000 --- a/userapi/inthttp/client.go +++ /dev/null @@ -1,454 +0,0 @@ -// Copyright 2020 The Matrix.org Foundation C.I.C. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package inthttp - -import ( - "context" - "errors" - "net/http" - - "github.com/matrix-org/dendrite/internal/httputil" - "github.com/matrix-org/dendrite/userapi/api" -) - -// HTTP paths for the internal HTTP APIs -const ( - InputAccountDataPath = "/userapi/inputAccountData" - - PerformDeviceCreationPath = "/userapi/performDeviceCreation" - PerformAccountCreationPath = "/userapi/performAccountCreation" - PerformPasswordUpdatePath = "/userapi/performPasswordUpdate" - PerformDeviceDeletionPath = "/userapi/performDeviceDeletion" - PerformLastSeenUpdatePath = "/userapi/performLastSeenUpdate" - PerformDeviceUpdatePath = "/userapi/performDeviceUpdate" - PerformAccountDeactivationPath = "/userapi/performAccountDeactivation" - PerformOpenIDTokenCreationPath = "/userapi/performOpenIDTokenCreation" - PerformKeyBackupPath = "/userapi/performKeyBackup" - PerformPusherSetPath = "/pushserver/performPusherSet" - PerformPusherDeletionPath = "/pushserver/performPusherDeletion" - PerformPushRulesPutPath = "/pushserver/performPushRulesPut" - PerformSetAvatarURLPath = "/userapi/performSetAvatarURL" - PerformSetDisplayNamePath = "/userapi/performSetDisplayName" - PerformForgetThreePIDPath = "/userapi/performForgetThreePID" - PerformSaveThreePIDAssociationPath = "/userapi/performSaveThreePIDAssociation" - - QueryKeyBackupPath = "/userapi/queryKeyBackup" - QueryProfilePath = "/userapi/queryProfile" - QueryAccessTokenPath = "/userapi/queryAccessToken" - QueryDevicesPath = "/userapi/queryDevices" - QueryAccountDataPath = "/userapi/queryAccountData" - QueryDeviceInfosPath = "/userapi/queryDeviceInfos" - QuerySearchProfilesPath = "/userapi/querySearchProfiles" - QueryOpenIDTokenPath = "/userapi/queryOpenIDToken" - QueryPushersPath = "/pushserver/queryPushers" - QueryPushRulesPath = "/pushserver/queryPushRules" - QueryNotificationsPath = "/pushserver/queryNotifications" - QueryNumericLocalpartPath = "/userapi/queryNumericLocalpart" - QueryAccountAvailabilityPath = "/userapi/queryAccountAvailability" - QueryAccountByPasswordPath = "/userapi/queryAccountByPassword" - QueryLocalpartForThreePIDPath = "/userapi/queryLocalpartForThreePID" - QueryThreePIDsForLocalpartPath = "/userapi/queryThreePIDsForLocalpart" - QueryAccountByLocalpartPath = "/userapi/queryAccountType" -) - -// NewUserAPIClient creates a UserInternalAPI implemented by talking to a HTTP POST API. -// If httpClient is nil an error is returned -func NewUserAPIClient( - apiURL string, - httpClient *http.Client, -) (api.UserInternalAPI, error) { - if httpClient == nil { - return nil, errors.New("NewUserAPIClient: httpClient is ") - } - return &httpUserInternalAPI{ - apiURL: apiURL, - httpClient: httpClient, - }, nil -} - -type httpUserInternalAPI struct { - apiURL string - httpClient *http.Client -} - -func (h *httpUserInternalAPI) InputAccountData(ctx context.Context, req *api.InputAccountDataRequest, res *api.InputAccountDataResponse) error { - return httputil.CallInternalRPCAPI( - "InputAccountData", h.apiURL+InputAccountDataPath, - h.httpClient, ctx, req, res, - ) -} - -func (h *httpUserInternalAPI) PerformAccountCreation( - ctx context.Context, - request *api.PerformAccountCreationRequest, - response *api.PerformAccountCreationResponse, -) error { - return httputil.CallInternalRPCAPI( - "PerformAccountCreation", h.apiURL+PerformAccountCreationPath, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpUserInternalAPI) PerformPasswordUpdate( - ctx context.Context, - request *api.PerformPasswordUpdateRequest, - response *api.PerformPasswordUpdateResponse, -) error { - return httputil.CallInternalRPCAPI( - "PerformPasswordUpdate", h.apiURL+PerformPasswordUpdatePath, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpUserInternalAPI) PerformDeviceCreation( - ctx context.Context, - request *api.PerformDeviceCreationRequest, - response *api.PerformDeviceCreationResponse, -) error { - return httputil.CallInternalRPCAPI( - "PerformDeviceCreation", h.apiURL+PerformDeviceCreationPath, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpUserInternalAPI) PerformDeviceDeletion( - ctx context.Context, - request *api.PerformDeviceDeletionRequest, - response *api.PerformDeviceDeletionResponse, -) error { - return httputil.CallInternalRPCAPI( - "PerformDeviceDeletion", h.apiURL+PerformDeviceDeletionPath, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpUserInternalAPI) PerformLastSeenUpdate( - ctx context.Context, - request *api.PerformLastSeenUpdateRequest, - response *api.PerformLastSeenUpdateResponse, -) error { - return httputil.CallInternalRPCAPI( - "PerformLastSeen", h.apiURL+PerformLastSeenUpdatePath, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpUserInternalAPI) PerformDeviceUpdate( - ctx context.Context, - request *api.PerformDeviceUpdateRequest, - response *api.PerformDeviceUpdateResponse, -) error { - return httputil.CallInternalRPCAPI( - "PerformDeviceUpdate", h.apiURL+PerformDeviceUpdatePath, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpUserInternalAPI) PerformAccountDeactivation( - ctx context.Context, - request *api.PerformAccountDeactivationRequest, - response *api.PerformAccountDeactivationResponse, -) error { - return httputil.CallInternalRPCAPI( - "PerformAccountDeactivation", h.apiURL+PerformAccountDeactivationPath, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpUserInternalAPI) PerformOpenIDTokenCreation( - ctx context.Context, - request *api.PerformOpenIDTokenCreationRequest, - response *api.PerformOpenIDTokenCreationResponse, -) error { - return httputil.CallInternalRPCAPI( - "PerformOpenIDTokenCreation", h.apiURL+PerformOpenIDTokenCreationPath, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpUserInternalAPI) QueryProfile( - ctx context.Context, - request *api.QueryProfileRequest, - response *api.QueryProfileResponse, -) error { - return httputil.CallInternalRPCAPI( - "QueryProfile", h.apiURL+QueryProfilePath, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpUserInternalAPI) QueryDeviceInfos( - ctx context.Context, - request *api.QueryDeviceInfosRequest, - response *api.QueryDeviceInfosResponse, -) error { - return httputil.CallInternalRPCAPI( - "QueryDeviceInfos", h.apiURL+QueryDeviceInfosPath, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpUserInternalAPI) QueryAccessToken( - ctx context.Context, - request *api.QueryAccessTokenRequest, - response *api.QueryAccessTokenResponse, -) error { - return httputil.CallInternalRPCAPI( - "QueryAccessToken", h.apiURL+QueryAccessTokenPath, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpUserInternalAPI) QueryDevices( - ctx context.Context, - request *api.QueryDevicesRequest, - response *api.QueryDevicesResponse, -) error { - return httputil.CallInternalRPCAPI( - "QueryDevices", h.apiURL+QueryDevicesPath, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpUserInternalAPI) QueryAccountData( - ctx context.Context, - request *api.QueryAccountDataRequest, - response *api.QueryAccountDataResponse, -) error { - return httputil.CallInternalRPCAPI( - "QueryAccountData", h.apiURL+QueryAccountDataPath, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpUserInternalAPI) QuerySearchProfiles( - ctx context.Context, - request *api.QuerySearchProfilesRequest, - response *api.QuerySearchProfilesResponse, -) error { - return httputil.CallInternalRPCAPI( - "QuerySearchProfiles", h.apiURL+QuerySearchProfilesPath, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpUserInternalAPI) QueryOpenIDToken( - ctx context.Context, - request *api.QueryOpenIDTokenRequest, - response *api.QueryOpenIDTokenResponse, -) error { - return httputil.CallInternalRPCAPI( - "QueryOpenIDToken", h.apiURL+QueryOpenIDTokenPath, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpUserInternalAPI) PerformKeyBackup( - ctx context.Context, - request *api.PerformKeyBackupRequest, - response *api.PerformKeyBackupResponse, -) error { - return httputil.CallInternalRPCAPI( - "PerformKeyBackup", h.apiURL+PerformKeyBackupPath, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpUserInternalAPI) QueryKeyBackup( - ctx context.Context, - request *api.QueryKeyBackupRequest, - response *api.QueryKeyBackupResponse, -) error { - return httputil.CallInternalRPCAPI( - "QueryKeyBackup", h.apiURL+QueryKeyBackupPath, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpUserInternalAPI) QueryNotifications( - ctx context.Context, - request *api.QueryNotificationsRequest, - response *api.QueryNotificationsResponse, -) error { - return httputil.CallInternalRPCAPI( - "QueryNotifications", h.apiURL+QueryNotificationsPath, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpUserInternalAPI) PerformPusherSet( - ctx context.Context, - request *api.PerformPusherSetRequest, - response *struct{}, -) error { - return httputil.CallInternalRPCAPI( - "PerformPusherSet", h.apiURL+PerformPusherSetPath, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpUserInternalAPI) PerformPusherDeletion( - ctx context.Context, - request *api.PerformPusherDeletionRequest, - response *struct{}, -) error { - return httputil.CallInternalRPCAPI( - "PerformPusherDeletion", h.apiURL+PerformPusherDeletionPath, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpUserInternalAPI) QueryPushers( - ctx context.Context, - request *api.QueryPushersRequest, - response *api.QueryPushersResponse, -) error { - return httputil.CallInternalRPCAPI( - "QueryPushers", h.apiURL+QueryPushersPath, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpUserInternalAPI) PerformPushRulesPut( - ctx context.Context, - request *api.PerformPushRulesPutRequest, - response *struct{}, -) error { - return httputil.CallInternalRPCAPI( - "PerformPushRulesPut", h.apiURL+PerformPushRulesPutPath, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpUserInternalAPI) QueryPushRules( - ctx context.Context, - request *api.QueryPushRulesRequest, - response *api.QueryPushRulesResponse, -) error { - return httputil.CallInternalRPCAPI( - "QueryPushRules", h.apiURL+QueryPushRulesPath, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpUserInternalAPI) SetAvatarURL( - ctx context.Context, - request *api.PerformSetAvatarURLRequest, - response *api.PerformSetAvatarURLResponse, -) error { - return httputil.CallInternalRPCAPI( - "SetAvatarURL", h.apiURL+PerformSetAvatarURLPath, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpUserInternalAPI) QueryNumericLocalpart( - ctx context.Context, - request *api.QueryNumericLocalpartRequest, - response *api.QueryNumericLocalpartResponse, -) error { - return httputil.CallInternalRPCAPI( - "QueryNumericLocalpart", h.apiURL+QueryNumericLocalpartPath, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpUserInternalAPI) QueryAccountAvailability( - ctx context.Context, - request *api.QueryAccountAvailabilityRequest, - response *api.QueryAccountAvailabilityResponse, -) error { - return httputil.CallInternalRPCAPI( - "QueryAccountAvailability", h.apiURL+QueryAccountAvailabilityPath, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpUserInternalAPI) QueryAccountByPassword( - ctx context.Context, - request *api.QueryAccountByPasswordRequest, - response *api.QueryAccountByPasswordResponse, -) error { - return httputil.CallInternalRPCAPI( - "QueryAccountByPassword", h.apiURL+QueryAccountByPasswordPath, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpUserInternalAPI) SetDisplayName( - ctx context.Context, - request *api.PerformUpdateDisplayNameRequest, - response *api.PerformUpdateDisplayNameResponse, -) error { - return httputil.CallInternalRPCAPI( - "SetDisplayName", h.apiURL+PerformSetDisplayNamePath, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpUserInternalAPI) QueryLocalpartForThreePID( - ctx context.Context, - request *api.QueryLocalpartForThreePIDRequest, - response *api.QueryLocalpartForThreePIDResponse, -) error { - return httputil.CallInternalRPCAPI( - "QueryLocalpartForThreePID", h.apiURL+QueryLocalpartForThreePIDPath, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpUserInternalAPI) QueryThreePIDsForLocalpart( - ctx context.Context, - request *api.QueryThreePIDsForLocalpartRequest, - response *api.QueryThreePIDsForLocalpartResponse, -) error { - return httputil.CallInternalRPCAPI( - "QueryThreePIDsForLocalpart", h.apiURL+QueryThreePIDsForLocalpartPath, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpUserInternalAPI) PerformForgetThreePID( - ctx context.Context, - request *api.PerformForgetThreePIDRequest, - response *struct{}, -) error { - return httputil.CallInternalRPCAPI( - "PerformForgetThreePID", h.apiURL+PerformForgetThreePIDPath, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpUserInternalAPI) PerformSaveThreePIDAssociation( - ctx context.Context, - request *api.PerformSaveThreePIDAssociationRequest, - response *struct{}, -) error { - return httputil.CallInternalRPCAPI( - "PerformSaveThreePIDAssociation", h.apiURL+PerformSaveThreePIDAssociationPath, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpUserInternalAPI) QueryAccountByLocalpart( - ctx context.Context, - req *api.QueryAccountByLocalpartRequest, - res *api.QueryAccountByLocalpartResponse, -) error { - return httputil.CallInternalRPCAPI( - "QueryAccountByLocalpart", h.apiURL+QueryAccountByLocalpartPath, - h.httpClient, ctx, req, res, - ) -} diff --git a/userapi/inthttp/client_logintoken.go b/userapi/inthttp/client_logintoken.go deleted file mode 100644 index 211b1b7a1..000000000 --- a/userapi/inthttp/client_logintoken.go +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright 2021 The Matrix.org Foundation C.I.C. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package inthttp - -import ( - "context" - - "github.com/matrix-org/dendrite/internal/httputil" - "github.com/matrix-org/dendrite/userapi/api" -) - -const ( - PerformLoginTokenCreationPath = "/userapi/performLoginTokenCreation" - PerformLoginTokenDeletionPath = "/userapi/performLoginTokenDeletion" - QueryLoginTokenPath = "/userapi/queryLoginToken" -) - -func (h *httpUserInternalAPI) PerformLoginTokenCreation( - ctx context.Context, - request *api.PerformLoginTokenCreationRequest, - response *api.PerformLoginTokenCreationResponse, -) error { - return httputil.CallInternalRPCAPI( - "PerformLoginTokenCreation", h.apiURL+PerformLoginTokenCreationPath, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpUserInternalAPI) PerformLoginTokenDeletion( - ctx context.Context, - request *api.PerformLoginTokenDeletionRequest, - response *api.PerformLoginTokenDeletionResponse, -) error { - return httputil.CallInternalRPCAPI( - "PerformLoginTokenDeletion", h.apiURL+PerformLoginTokenDeletionPath, - h.httpClient, ctx, request, response, - ) -} - -func (h *httpUserInternalAPI) QueryLoginToken( - ctx context.Context, - request *api.QueryLoginTokenRequest, - response *api.QueryLoginTokenResponse, -) error { - return httputil.CallInternalRPCAPI( - "QueryLoginToken", h.apiURL+QueryLoginTokenPath, - h.httpClient, ctx, request, response, - ) -} diff --git a/userapi/inthttp/server.go b/userapi/inthttp/server.go deleted file mode 100644 index b40b507c2..000000000 --- a/userapi/inthttp/server.go +++ /dev/null @@ -1,197 +0,0 @@ -// Copyright 2020 The Matrix.org Foundation C.I.C. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package inthttp - -import ( - "github.com/gorilla/mux" - - "github.com/matrix-org/dendrite/internal/httputil" - "github.com/matrix-org/dendrite/userapi/api" -) - -// nolint: gocyclo -func AddRoutes(internalAPIMux *mux.Router, s api.UserInternalAPI, enableMetrics bool) { - addRoutesLoginToken(internalAPIMux, s, enableMetrics) - - internalAPIMux.Handle( - PerformAccountCreationPath, - httputil.MakeInternalRPCAPI("UserAPIPerformAccountCreation", enableMetrics, s.PerformAccountCreation), - ) - - internalAPIMux.Handle( - PerformPasswordUpdatePath, - httputil.MakeInternalRPCAPI("UserAPIPerformPasswordUpdate", enableMetrics, s.PerformPasswordUpdate), - ) - - internalAPIMux.Handle( - PerformDeviceCreationPath, - httputil.MakeInternalRPCAPI("UserAPIPerformDeviceCreation", enableMetrics, s.PerformDeviceCreation), - ) - - internalAPIMux.Handle( - PerformLastSeenUpdatePath, - httputil.MakeInternalRPCAPI("UserAPIPerformLastSeenUpdate", enableMetrics, s.PerformLastSeenUpdate), - ) - - internalAPIMux.Handle( - PerformDeviceUpdatePath, - httputil.MakeInternalRPCAPI("UserAPIPerformDeviceUpdate", enableMetrics, s.PerformDeviceUpdate), - ) - - internalAPIMux.Handle( - PerformDeviceDeletionPath, - httputil.MakeInternalRPCAPI("UserAPIPerformDeviceDeletion", enableMetrics, s.PerformDeviceDeletion), - ) - - internalAPIMux.Handle( - PerformAccountDeactivationPath, - httputil.MakeInternalRPCAPI("UserAPIPerformAccountDeactivation", enableMetrics, s.PerformAccountDeactivation), - ) - - internalAPIMux.Handle( - PerformOpenIDTokenCreationPath, - httputil.MakeInternalRPCAPI("UserAPIPerformOpenIDTokenCreation", enableMetrics, s.PerformOpenIDTokenCreation), - ) - - internalAPIMux.Handle( - QueryProfilePath, - httputil.MakeInternalRPCAPI("UserAPIQueryProfile", enableMetrics, s.QueryProfile), - ) - - internalAPIMux.Handle( - QueryAccessTokenPath, - httputil.MakeInternalRPCAPI("UserAPIQueryAccessToken", enableMetrics, s.QueryAccessToken), - ) - - internalAPIMux.Handle( - QueryDevicesPath, - httputil.MakeInternalRPCAPI("UserAPIQueryDevices", enableMetrics, s.QueryDevices), - ) - - internalAPIMux.Handle( - QueryAccountDataPath, - httputil.MakeInternalRPCAPI("UserAPIQueryAccountData", enableMetrics, s.QueryAccountData), - ) - - internalAPIMux.Handle( - QueryDeviceInfosPath, - httputil.MakeInternalRPCAPI("UserAPIQueryDeviceInfos", enableMetrics, s.QueryDeviceInfos), - ) - - internalAPIMux.Handle( - QuerySearchProfilesPath, - httputil.MakeInternalRPCAPI("UserAPIQuerySearchProfiles", enableMetrics, s.QuerySearchProfiles), - ) - - internalAPIMux.Handle( - QueryOpenIDTokenPath, - httputil.MakeInternalRPCAPI("UserAPIQueryOpenIDToken", enableMetrics, s.QueryOpenIDToken), - ) - - internalAPIMux.Handle( - InputAccountDataPath, - httputil.MakeInternalRPCAPI("UserAPIInputAccountData", enableMetrics, s.InputAccountData), - ) - - internalAPIMux.Handle( - QueryKeyBackupPath, - httputil.MakeInternalRPCAPI("UserAPIQueryKeyBackup", enableMetrics, s.QueryKeyBackup), - ) - - internalAPIMux.Handle( - PerformKeyBackupPath, - httputil.MakeInternalRPCAPI("UserAPIPerformKeyBackup", enableMetrics, s.PerformKeyBackup), - ) - - internalAPIMux.Handle( - QueryNotificationsPath, - httputil.MakeInternalRPCAPI("UserAPIQueryNotifications", enableMetrics, s.QueryNotifications), - ) - - internalAPIMux.Handle( - PerformPusherSetPath, - httputil.MakeInternalRPCAPI("UserAPIPerformPusherSet", enableMetrics, s.PerformPusherSet), - ) - - internalAPIMux.Handle( - PerformPusherDeletionPath, - httputil.MakeInternalRPCAPI("UserAPIPerformPusherDeletion", enableMetrics, s.PerformPusherDeletion), - ) - - internalAPIMux.Handle( - QueryPushersPath, - httputil.MakeInternalRPCAPI("UserAPIQueryPushers", enableMetrics, s.QueryPushers), - ) - - internalAPIMux.Handle( - PerformPushRulesPutPath, - httputil.MakeInternalRPCAPI("UserAPIPerformPushRulesPut", enableMetrics, s.PerformPushRulesPut), - ) - - internalAPIMux.Handle( - QueryPushRulesPath, - httputil.MakeInternalRPCAPI("UserAPIQueryPushRules", enableMetrics, s.QueryPushRules), - ) - - internalAPIMux.Handle( - PerformSetAvatarURLPath, - httputil.MakeInternalRPCAPI("UserAPIPerformSetAvatarURL", enableMetrics, s.SetAvatarURL), - ) - - internalAPIMux.Handle( - QueryNumericLocalpartPath, - httputil.MakeInternalRPCAPI("UserAPIQueryNumericLocalpart", enableMetrics, s.QueryNumericLocalpart), - ) - - internalAPIMux.Handle( - QueryAccountAvailabilityPath, - httputil.MakeInternalRPCAPI("UserAPIQueryAccountAvailability", enableMetrics, s.QueryAccountAvailability), - ) - - internalAPIMux.Handle( - QueryAccountByPasswordPath, - httputil.MakeInternalRPCAPI("UserAPIQueryAccountByPassword", enableMetrics, s.QueryAccountByPassword), - ) - - internalAPIMux.Handle( - PerformSetDisplayNamePath, - httputil.MakeInternalRPCAPI("UserAPISetDisplayName", enableMetrics, s.SetDisplayName), - ) - - internalAPIMux.Handle( - QueryLocalpartForThreePIDPath, - httputil.MakeInternalRPCAPI("UserAPIQueryLocalpartForThreePID", enableMetrics, s.QueryLocalpartForThreePID), - ) - - internalAPIMux.Handle( - QueryThreePIDsForLocalpartPath, - httputil.MakeInternalRPCAPI("UserAPIQueryThreePIDsForLocalpart", enableMetrics, s.QueryThreePIDsForLocalpart), - ) - - internalAPIMux.Handle( - PerformForgetThreePIDPath, - httputil.MakeInternalRPCAPI("UserAPIPerformForgetThreePID", enableMetrics, s.PerformForgetThreePID), - ) - - internalAPIMux.Handle( - PerformSaveThreePIDAssociationPath, - httputil.MakeInternalRPCAPI("UserAPIPerformSaveThreePIDAssociation", enableMetrics, s.PerformSaveThreePIDAssociation), - ) - - internalAPIMux.Handle( - QueryAccountByLocalpartPath, - httputil.MakeInternalRPCAPI("AccountByLocalpart", enableMetrics, s.QueryAccountByLocalpart), - ) -} diff --git a/userapi/inthttp/server_logintoken.go b/userapi/inthttp/server_logintoken.go deleted file mode 100644 index dc116428b..000000000 --- a/userapi/inthttp/server_logintoken.go +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2021 The Matrix.org Foundation C.I.C. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package inthttp - -import ( - "github.com/gorilla/mux" - - "github.com/matrix-org/dendrite/internal/httputil" - "github.com/matrix-org/dendrite/userapi/api" -) - -// addRoutesLoginToken adds routes for all login token API calls. -func addRoutesLoginToken(internalAPIMux *mux.Router, s api.UserInternalAPI, enableMetrics bool) { - internalAPIMux.Handle( - PerformLoginTokenCreationPath, - httputil.MakeInternalRPCAPI("UserAPIPerformLoginTokenCreation", enableMetrics, s.PerformLoginTokenCreation), - ) - - internalAPIMux.Handle( - PerformLoginTokenDeletionPath, - httputil.MakeInternalRPCAPI("UserAPIPerformLoginTokenDeletion", enableMetrics, s.PerformLoginTokenDeletion), - ) - - internalAPIMux.Handle( - QueryLoginTokenPath, - httputil.MakeInternalRPCAPI("UserAPIQueryLoginToken", enableMetrics, s.QueryLoginToken), - ) -} diff --git a/userapi/userapi.go b/userapi/userapi.go index 183ca3123..2dd81d759 100644 --- a/userapi/userapi.go +++ b/userapi/userapi.go @@ -17,7 +17,6 @@ package userapi import ( "time" - "github.com/gorilla/mux" "github.com/sirupsen/logrus" "github.com/matrix-org/dendrite/internal/pushgateway" @@ -29,18 +28,11 @@ import ( "github.com/matrix-org/dendrite/userapi/api" "github.com/matrix-org/dendrite/userapi/consumers" "github.com/matrix-org/dendrite/userapi/internal" - "github.com/matrix-org/dendrite/userapi/inthttp" "github.com/matrix-org/dendrite/userapi/producers" "github.com/matrix-org/dendrite/userapi/storage" "github.com/matrix-org/dendrite/userapi/util" ) -// AddInternalRoutes registers HTTP handlers for the internal API. Invokes functions -// on the given input API. -func AddInternalRoutes(router *mux.Router, intAPI api.UserInternalAPI, enableMetrics bool) { - inthttp.AddRoutes(router, intAPI, enableMetrics) -} - // NewInternalAPI returns a concerete implementation of the internal API. Callers // can call functions directly on the returned API or via an HTTP interface using AddInternalRoutes. func NewInternalAPI( diff --git a/userapi/userapi_test.go b/userapi/userapi_test.go index dada56de4..a9e882836 100644 --- a/userapi/userapi_test.go +++ b/userapi/userapi_test.go @@ -17,23 +17,18 @@ package userapi_test import ( "context" "fmt" - "net/http" "reflect" "testing" "time" - "github.com/gorilla/mux" "github.com/matrix-org/gomatrixserverlib" "golang.org/x/crypto/bcrypt" - "github.com/matrix-org/dendrite/internal/httputil" "github.com/matrix-org/dendrite/setup/config" "github.com/matrix-org/dendrite/test" "github.com/matrix-org/dendrite/test/testrig" - "github.com/matrix-org/dendrite/userapi" "github.com/matrix-org/dendrite/userapi/api" "github.com/matrix-org/dendrite/userapi/internal" - "github.com/matrix-org/dendrite/userapi/inthttp" "github.com/matrix-org/dendrite/userapi/storage" ) @@ -142,20 +137,7 @@ func TestQueryProfile(t *testing.T) { t.Fatalf("failed to set display name: %s", err) } - t.Run("HTTP API", func(t *testing.T) { - router := mux.NewRouter().PathPrefix(httputil.InternalPathPrefix).Subrouter() - userapi.AddInternalRoutes(router, userAPI, false) - apiURL, cancel := test.ListenAndServe(t, router, false) - defer cancel() - httpAPI, err := inthttp.NewUserAPIClient(apiURL, &http.Client{}) - if err != nil { - t.Fatalf("failed to create HTTP client") - } - runCases(httpAPI, true) - }) - t.Run("Monolith", func(t *testing.T) { - runCases(userAPI, false) - }) + runCases(userAPI, false) }) } @@ -347,24 +329,8 @@ func TestQueryAccountByLocalpart(t *testing.T) { } } - t.Run("Monolith", func(t *testing.T) { - testCases(t, intAPI) - // also test tracing - testCases(t, &api.UserInternalAPITrace{Impl: intAPI}) - }) - - t.Run("HTTP API", func(t *testing.T) { - router := mux.NewRouter().PathPrefix(httputil.InternalPathPrefix).Subrouter() - userapi.AddInternalRoutes(router, intAPI, false) - apiURL, cancel := test.ListenAndServe(t, router, false) - defer cancel() - - userHTTPApi, err := inthttp.NewUserAPIClient(apiURL, &http.Client{Timeout: time.Second * 5}) - if err != nil { - t.Fatalf("failed to create HTTP client: %s", err) - } - testCases(t, userHTTPApi) - - }) + testCases(t, intAPI) + // also test tracing + testCases(t, &api.UserInternalAPITrace{Impl: intAPI}) }) } diff --git a/userapi/util/phonehomestats.go b/userapi/util/phonehomestats.go index 42c8f5d7c..21035e045 100644 --- a/userapi/util/phonehomestats.go +++ b/userapi/util/phonehomestats.go @@ -55,7 +55,7 @@ func StartPhoneHomeCollector(startTime time.Time, cfg *config.Dendrite, statsDB serverName: cfg.Global.ServerName, cfg: cfg, db: statsDB, - isMonolith: cfg.IsMonolith, + isMonolith: true, client: &http.Client{ Timeout: time.Second * 30, Transport: http.DefaultTransport,