diff --git a/appservice/api/query.go b/appservice/api/query.go index afd5c5d76..4a4e31a99 100644 --- a/appservice/api/query.go +++ b/appservice/api/query.go @@ -27,8 +27,8 @@ import ( "github.com/matrix-org/dendrite/clientapi/auth/storage/accounts" "github.com/matrix-org/gomatrixserverlib" - "github.com/matrix-org/dendrite/common" - commonHTTP "github.com/matrix-org/dendrite/common/http" + "github.com/matrix-org/dendrite/internal" + internalHTTP "github.com/matrix-org/dendrite/internal/http" opentracing "github.com/opentracing/opentracing-go" ) @@ -119,7 +119,7 @@ func (h *httpAppServiceQueryAPI) RoomAliasExists( defer span.Finish() apiURL := h.appserviceURL + AppServiceRoomAliasExistsPath - return commonHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response) + return internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response) } // UserIDExists implements AppServiceQueryAPI @@ -132,7 +132,7 @@ func (h *httpAppServiceQueryAPI) UserIDExists( defer span.Finish() apiURL := h.appserviceURL + AppServiceUserIDExistsPath - return commonHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response) + return internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response) } // RetrieveUserProfile is a wrapper that queries both the local database and @@ -165,7 +165,7 @@ func RetrieveUserProfile( // If no user exists, return if !userResp.UserIDExists { - return nil, common.ErrProfileNoExists + return nil, internal.ErrProfileNoExists } // Try to query the user from the local database again diff --git a/appservice/appservice.go b/appservice/appservice.go index 3a1c4677a..3c67ce9c1 100644 --- a/appservice/appservice.go +++ b/appservice/appservice.go @@ -29,9 +29,9 @@ import ( "github.com/matrix-org/dendrite/appservice/workers" "github.com/matrix-org/dendrite/clientapi/auth/storage/accounts" "github.com/matrix-org/dendrite/clientapi/auth/storage/devices" - "github.com/matrix-org/dendrite/common/basecomponent" - "github.com/matrix-org/dendrite/common/config" - "github.com/matrix-org/dendrite/common/transactions" + "github.com/matrix-org/dendrite/internal/basecomponent" + "github.com/matrix-org/dendrite/internal/config" + "github.com/matrix-org/dendrite/internal/transactions" roomserverAPI "github.com/matrix-org/dendrite/roomserver/api" "github.com/matrix-org/gomatrixserverlib" "github.com/sirupsen/logrus" diff --git a/appservice/consumers/roomserver.go b/appservice/consumers/roomserver.go index b7f689249..bb4df7906 100644 --- a/appservice/consumers/roomserver.go +++ b/appservice/consumers/roomserver.go @@ -21,8 +21,8 @@ import ( "github.com/matrix-org/dendrite/appservice/storage" "github.com/matrix-org/dendrite/appservice/types" "github.com/matrix-org/dendrite/clientapi/auth/storage/accounts" - "github.com/matrix-org/dendrite/common" - "github.com/matrix-org/dendrite/common/config" + "github.com/matrix-org/dendrite/internal" + "github.com/matrix-org/dendrite/internal/config" "github.com/matrix-org/dendrite/roomserver/api" "github.com/matrix-org/gomatrixserverlib" @@ -32,7 +32,7 @@ import ( // OutputRoomEventConsumer consumes events that originated in the room server. type OutputRoomEventConsumer struct { - roomServerConsumer *common.ContinualConsumer + roomServerConsumer *internal.ContinualConsumer db accounts.Database asDB storage.Database rsAPI api.RoomserverInternalAPI @@ -50,7 +50,7 @@ func NewOutputRoomEventConsumer( rsAPI api.RoomserverInternalAPI, workerStates []types.ApplicationServiceWorkerState, ) *OutputRoomEventConsumer { - consumer := common.ContinualConsumer{ + consumer := internal.ContinualConsumer{ Topic: string(cfg.Kafka.Topics.OutputRoomEvent), Consumer: kafkaConsumer, PartitionStore: store, diff --git a/appservice/query/query.go b/appservice/query/query.go index fde3ab09c..a61997b42 100644 --- a/appservice/query/query.go +++ b/appservice/query/query.go @@ -24,8 +24,8 @@ import ( "time" "github.com/matrix-org/dendrite/appservice/api" - "github.com/matrix-org/dendrite/common" - "github.com/matrix-org/dendrite/common/config" + "github.com/matrix-org/dendrite/internal" + "github.com/matrix-org/dendrite/internal/config" "github.com/matrix-org/util" opentracing "github.com/opentracing/opentracing-go" log "github.com/sirupsen/logrus" @@ -185,7 +185,7 @@ func makeHTTPClient() *http.Client { func (a *AppServiceQueryAPI) SetupHTTP(servMux *http.ServeMux) { servMux.Handle( api.AppServiceRoomAliasExistsPath, - common.MakeInternalAPI("appserviceRoomAliasExists", func(req *http.Request) util.JSONResponse { + internal.MakeInternalAPI("appserviceRoomAliasExists", func(req *http.Request) util.JSONResponse { var request api.RoomAliasExistsRequest var response api.RoomAliasExistsResponse if err := json.NewDecoder(req.Body).Decode(&request); err != nil { @@ -199,7 +199,7 @@ func (a *AppServiceQueryAPI) SetupHTTP(servMux *http.ServeMux) { ) servMux.Handle( api.AppServiceUserIDExistsPath, - common.MakeInternalAPI("appserviceUserIDExists", func(req *http.Request) util.JSONResponse { + internal.MakeInternalAPI("appserviceUserIDExists", func(req *http.Request) util.JSONResponse { var request api.UserIDExistsRequest var response api.UserIDExistsResponse if err := json.NewDecoder(req.Body).Decode(&request); err != nil { diff --git a/appservice/routing/routing.go b/appservice/routing/routing.go index 9f59e05f7..ac1ff32ea 100644 --- a/appservice/routing/routing.go +++ b/appservice/routing/routing.go @@ -19,9 +19,9 @@ import ( "github.com/gorilla/mux" "github.com/matrix-org/dendrite/clientapi/auth/storage/accounts" - "github.com/matrix-org/dendrite/common" - "github.com/matrix-org/dendrite/common/config" - "github.com/matrix-org/dendrite/common/transactions" + "github.com/matrix-org/dendrite/internal" + "github.com/matrix-org/dendrite/internal/config" + "github.com/matrix-org/dendrite/internal/transactions" "github.com/matrix-org/dendrite/roomserver/api" "github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/util" @@ -45,7 +45,7 @@ func Setup( appMux := apiMux.PathPrefix(pathPrefixApp).Subrouter() appMux.Handle("/alias", - common.MakeExternalAPI("alias", func(req *http.Request) util.JSONResponse { + internal.MakeExternalAPI("alias", func(req *http.Request) util.JSONResponse { // TODO: Implement return util.JSONResponse{ Code: http.StatusOK, @@ -54,7 +54,7 @@ func Setup( }), ).Methods(http.MethodGet, http.MethodOptions) appMux.Handle("/user", - common.MakeExternalAPI("user", func(req *http.Request) util.JSONResponse { + internal.MakeExternalAPI("user", func(req *http.Request) util.JSONResponse { // TODO: Implement return util.JSONResponse{ Code: http.StatusOK, diff --git a/appservice/storage/postgres/storage.go b/appservice/storage/postgres/storage.go index 475db6fc2..aeead6ed3 100644 --- a/appservice/storage/postgres/storage.go +++ b/appservice/storage/postgres/storage.go @@ -21,7 +21,7 @@ import ( // Import postgres database driver _ "github.com/lib/pq" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/internal/sqlutil" "github.com/matrix-org/gomatrixserverlib" ) @@ -34,7 +34,7 @@ type Database struct { } // NewDatabase opens a new database -func NewDatabase(dataSourceName string, dbProperties common.DbProperties) (*Database, error) { +func NewDatabase(dataSourceName string, dbProperties internal.DbProperties) (*Database, error) { var result Database var err error if result.db, err = sqlutil.Open("postgres", dataSourceName, dbProperties); err != nil { diff --git a/appservice/storage/sqlite3/storage.go b/appservice/storage/sqlite3/storage.go index 0b0590f6d..275c66526 100644 --- a/appservice/storage/sqlite3/storage.go +++ b/appservice/storage/sqlite3/storage.go @@ -20,7 +20,7 @@ import ( "database/sql" // Import SQLite database driver - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/internal/sqlutil" "github.com/matrix-org/gomatrixserverlib" _ "github.com/mattn/go-sqlite3" @@ -37,7 +37,7 @@ type Database struct { func NewDatabase(dataSourceName string) (*Database, error) { var result Database var err error - if result.db, err = sqlutil.Open(common.SQLiteDriverName(), dataSourceName, nil); err != nil { + if result.db, err = sqlutil.Open(internal.SQLiteDriverName(), dataSourceName, nil); err != nil { return nil, err } if err = result.prepare(); err != nil { diff --git a/appservice/storage/storage.go b/appservice/storage/storage.go index bf0a9b0c8..51ba1de53 100644 --- a/appservice/storage/storage.go +++ b/appservice/storage/storage.go @@ -21,12 +21,12 @@ import ( "github.com/matrix-org/dendrite/appservice/storage/postgres" "github.com/matrix-org/dendrite/appservice/storage/sqlite3" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" ) // NewDatabase opens a new Postgres or Sqlite database (based on dataSourceName scheme) // and sets DB connection parameters -func NewDatabase(dataSourceName string, dbProperties common.DbProperties) (Database, error) { +func NewDatabase(dataSourceName string, dbProperties internal.DbProperties) (Database, error) { uri, err := url.Parse(dataSourceName) if err != nil { return postgres.NewDatabase(dataSourceName, dbProperties) diff --git a/appservice/storage/storage_wasm.go b/appservice/storage/storage_wasm.go index ff0330ae0..a6144b435 100644 --- a/appservice/storage/storage_wasm.go +++ b/appservice/storage/storage_wasm.go @@ -19,12 +19,12 @@ import ( "net/url" "github.com/matrix-org/dendrite/appservice/storage/sqlite3" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" ) func NewDatabase( dataSourceName string, - dbProperties common.DbProperties, // nolint:unparam + dbProperties internal.DbProperties, // nolint:unparam ) (Database, error) { uri, err := url.Parse(dataSourceName) if err != nil { diff --git a/appservice/types/types.go b/appservice/types/types.go index aac731550..b6386df67 100644 --- a/appservice/types/types.go +++ b/appservice/types/types.go @@ -15,7 +15,7 @@ package types import ( "sync" - "github.com/matrix-org/dendrite/common/config" + "github.com/matrix-org/dendrite/internal/config" ) const ( diff --git a/appservice/workers/transaction_scheduler.go b/appservice/workers/transaction_scheduler.go index 10c7ef911..208056192 100644 --- a/appservice/workers/transaction_scheduler.go +++ b/appservice/workers/transaction_scheduler.go @@ -25,7 +25,7 @@ import ( "github.com/matrix-org/dendrite/appservice/storage" "github.com/matrix-org/dendrite/appservice/types" - "github.com/matrix-org/dendrite/common/config" + "github.com/matrix-org/dendrite/internal/config" "github.com/matrix-org/gomatrixserverlib" log "github.com/sirupsen/logrus" ) diff --git a/docker/Dockerfile b/build/docker/Dockerfile similarity index 100% rename from docker/Dockerfile rename to build/docker/Dockerfile diff --git a/docker/README.md b/build/docker/README.md similarity index 100% rename from docker/README.md rename to build/docker/README.md diff --git a/docker/build.sh b/build/docker/build.sh similarity index 100% rename from docker/build.sh rename to build/docker/build.sh diff --git a/docker/dendrite-docker.yml b/build/docker/dendrite-docker.yml similarity index 100% rename from docker/dendrite-docker.yml rename to build/docker/dendrite-docker.yml diff --git a/docker/docker-compose.yml b/build/docker/docker-compose.yml similarity index 100% rename from docker/docker-compose.yml rename to build/docker/docker-compose.yml diff --git a/docker/hub/Dockerfile b/build/docker/hub/Dockerfile similarity index 100% rename from docker/hub/Dockerfile rename to build/docker/hub/Dockerfile diff --git a/docker/hub/Dockerfile.component b/build/docker/hub/Dockerfile.component similarity index 100% rename from docker/hub/Dockerfile.component rename to build/docker/hub/Dockerfile.component diff --git a/docker/hub/README.md b/build/docker/hub/README.md similarity index 100% rename from docker/hub/README.md rename to build/docker/hub/README.md diff --git a/docker/hub/config/dendrite-config.yaml b/build/docker/hub/config/dendrite-config.yaml similarity index 100% rename from docker/hub/config/dendrite-config.yaml rename to build/docker/hub/config/dendrite-config.yaml diff --git a/docker/hub/docker-compose.deps.yml b/build/docker/hub/docker-compose.deps.yml similarity index 100% rename from docker/hub/docker-compose.deps.yml rename to build/docker/hub/docker-compose.deps.yml diff --git a/docker/hub/docker-compose.monolith.yml b/build/docker/hub/docker-compose.monolith.yml similarity index 100% rename from docker/hub/docker-compose.monolith.yml rename to build/docker/hub/docker-compose.monolith.yml diff --git a/docker/hub/docker-compose.polylith.yml b/build/docker/hub/docker-compose.polylith.yml similarity index 100% rename from docker/hub/docker-compose.polylith.yml rename to build/docker/hub/docker-compose.polylith.yml diff --git a/docker/hub/images-build.sh b/build/docker/hub/images-build.sh similarity index 100% rename from docker/hub/images-build.sh rename to build/docker/hub/images-build.sh diff --git a/docker/hub/images-push.sh b/build/docker/hub/images-push.sh similarity index 100% rename from docker/hub/images-push.sh rename to build/docker/hub/images-push.sh diff --git a/docker/postgres/create_db.sh b/build/docker/postgres/create_db.sh similarity index 100% rename from docker/postgres/create_db.sh rename to build/docker/postgres/create_db.sh diff --git a/docker/services/client-api-proxy.sh b/build/docker/services/client-api-proxy.sh similarity index 100% rename from docker/services/client-api-proxy.sh rename to build/docker/services/client-api-proxy.sh diff --git a/docker/services/client-api.sh b/build/docker/services/client-api.sh similarity index 100% rename from docker/services/client-api.sh rename to build/docker/services/client-api.sh diff --git a/docker/services/edu-server.sh b/build/docker/services/edu-server.sh similarity index 100% rename from docker/services/edu-server.sh rename to build/docker/services/edu-server.sh diff --git a/docker/services/federation-api-proxy.sh b/build/docker/services/federation-api-proxy.sh similarity index 100% rename from docker/services/federation-api-proxy.sh rename to build/docker/services/federation-api-proxy.sh diff --git a/docker/services/federation-api.sh b/build/docker/services/federation-api.sh similarity index 100% rename from docker/services/federation-api.sh rename to build/docker/services/federation-api.sh diff --git a/docker/services/federation-sender.sh b/build/docker/services/federation-sender.sh similarity index 100% rename from docker/services/federation-sender.sh rename to build/docker/services/federation-sender.sh diff --git a/docker/services/key-server.sh b/build/docker/services/key-server.sh similarity index 100% rename from docker/services/key-server.sh rename to build/docker/services/key-server.sh diff --git a/docker/services/media-api.sh b/build/docker/services/media-api.sh similarity index 100% rename from docker/services/media-api.sh rename to build/docker/services/media-api.sh diff --git a/docker/services/monolith.sh b/build/docker/services/monolith.sh similarity index 100% rename from docker/services/monolith.sh rename to build/docker/services/monolith.sh diff --git a/docker/services/public-rooms-api.sh b/build/docker/services/public-rooms-api.sh similarity index 100% rename from docker/services/public-rooms-api.sh rename to build/docker/services/public-rooms-api.sh diff --git a/docker/services/room-server.sh b/build/docker/services/room-server.sh similarity index 100% rename from docker/services/room-server.sh rename to build/docker/services/room-server.sh diff --git a/docker/services/sync-api.sh b/build/docker/services/sync-api.sh similarity index 100% rename from docker/services/sync-api.sh rename to build/docker/services/sync-api.sh diff --git a/scripts/README.md b/build/scripts/README.md similarity index 100% rename from scripts/README.md rename to build/scripts/README.md diff --git a/scripts/build-test-lint.sh b/build/scripts/build-test-lint.sh similarity index 100% rename from scripts/build-test-lint.sh rename to build/scripts/build-test-lint.sh diff --git a/scripts/find-lint.sh b/build/scripts/find-lint.sh similarity index 98% rename from scripts/find-lint.sh rename to build/scripts/find-lint.sh index c9663e4e8..7e37e1548 100755 --- a/scripts/find-lint.sh +++ b/build/scripts/find-lint.sh @@ -14,7 +14,7 @@ set -eux -cd `dirname $0`/.. +cd `dirname $0`/../.. args="" if [ ${1:-""} = "fast" ] diff --git a/scripts/install-local-kafka.sh b/build/scripts/install-local-kafka.sh similarity index 100% rename from scripts/install-local-kafka.sh rename to build/scripts/install-local-kafka.sh diff --git a/clientapi/auth/auth.go b/clientapi/auth/auth.go index 87a2f6677..3482e5018 100644 --- a/clientapi/auth/auth.go +++ b/clientapi/auth/auth.go @@ -28,7 +28,7 @@ import ( "github.com/matrix-org/dendrite/clientapi/auth/authtypes" "github.com/matrix-org/dendrite/clientapi/jsonerror" "github.com/matrix-org/dendrite/clientapi/userutil" - "github.com/matrix-org/dendrite/common/config" + "github.com/matrix-org/dendrite/internal/config" "github.com/matrix-org/util" ) diff --git a/clientapi/auth/storage/accounts/interface.go b/clientapi/auth/storage/accounts/interface.go index a5052b047..a860f809d 100644 --- a/clientapi/auth/storage/accounts/interface.go +++ b/clientapi/auth/storage/accounts/interface.go @@ -19,12 +19,12 @@ import ( "errors" "github.com/matrix-org/dendrite/clientapi/auth/authtypes" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/gomatrixserverlib" ) type Database interface { - common.PartitionStorer + internal.PartitionStorer GetAccountByPassword(ctx context.Context, localpart, plaintextPassword string) (*authtypes.Account, error) GetProfileByLocalpart(ctx context.Context, localpart string) (*authtypes.Profile, error) SetAvatarURL(ctx context.Context, localpart string, avatarURL string) error diff --git a/clientapi/auth/storage/accounts/postgres/account_data_table.go b/clientapi/auth/storage/accounts/postgres/account_data_table.go index 9198a7440..2e044b367 100644 --- a/clientapi/auth/storage/accounts/postgres/account_data_table.go +++ b/clientapi/auth/storage/accounts/postgres/account_data_table.go @@ -18,7 +18,7 @@ import ( "context" "database/sql" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/gomatrixserverlib" ) @@ -92,7 +92,7 @@ func (s *accountDataStatements) selectAccountData( if err != nil { return } - defer common.CloseAndLogIfError(ctx, rows, "selectAccountData: rows.close() failed") + defer internal.CloseAndLogIfError(ctx, rows, "selectAccountData: rows.close() failed") global = []gomatrixserverlib.ClientEvent{} rooms = make(map[string][]gomatrixserverlib.ClientEvent) diff --git a/clientapi/auth/storage/accounts/postgres/membership_table.go b/clientapi/auth/storage/accounts/postgres/membership_table.go index 04e9095e9..d006e916a 100644 --- a/clientapi/auth/storage/accounts/postgres/membership_table.go +++ b/clientapi/auth/storage/accounts/postgres/membership_table.go @@ -18,7 +18,7 @@ import ( "context" "database/sql" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/lib/pq" "github.com/matrix-org/dendrite/clientapi/auth/authtypes" @@ -127,7 +127,7 @@ func (s *membershipStatements) selectMembershipsByLocalpart( memberships = []authtypes.Membership{} - defer common.CloseAndLogIfError(ctx, rows, "selectMembershipsByLocalpart: rows.close() failed") + defer internal.CloseAndLogIfError(ctx, rows, "selectMembershipsByLocalpart: rows.close() failed") for rows.Next() { var m authtypes.Membership m.Localpart = localpart diff --git a/clientapi/auth/storage/accounts/postgres/storage.go b/clientapi/auth/storage/accounts/postgres/storage.go index 7e2073ec0..4a1832674 100644 --- a/clientapi/auth/storage/accounts/postgres/storage.go +++ b/clientapi/auth/storage/accounts/postgres/storage.go @@ -21,7 +21,7 @@ import ( "strconv" "github.com/matrix-org/dendrite/clientapi/auth/authtypes" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/internal/sqlutil" "github.com/matrix-org/gomatrixserverlib" "golang.org/x/crypto/bcrypt" @@ -33,7 +33,7 @@ import ( // Database represents an account database type Database struct { db *sql.DB - common.PartitionOffsetStatements + internal.PartitionOffsetStatements accounts accountsStatements profiles profilesStatements memberships membershipStatements @@ -44,13 +44,13 @@ type Database struct { } // NewDatabase creates a new accounts and profiles database -func NewDatabase(dataSourceName string, dbProperties common.DbProperties, serverName gomatrixserverlib.ServerName) (*Database, error) { +func NewDatabase(dataSourceName string, dbProperties internal.DbProperties, serverName gomatrixserverlib.ServerName) (*Database, error) { var db *sql.DB var err error if db, err = sqlutil.Open("postgres", dataSourceName, dbProperties); err != nil { return nil, err } - partitions := common.PartitionOffsetStatements{} + partitions := internal.PartitionOffsetStatements{} if err = partitions.Prepare(db, "account"); err != nil { return nil, err } @@ -123,7 +123,7 @@ func (d *Database) SetDisplayName( // CreateGuestAccount makes a new guest account and creates an empty profile // for this account. func (d *Database) CreateGuestAccount(ctx context.Context) (acc *authtypes.Account, err error) { - err = common.WithTransaction(d.db, func(txn *sql.Tx) error { + err = internal.WithTransaction(d.db, func(txn *sql.Tx) error { var numLocalpart int64 numLocalpart, err = d.accounts.selectNewNumericLocalpart(ctx, txn) if err != nil { @@ -142,7 +142,7 @@ func (d *Database) CreateGuestAccount(ctx context.Context) (acc *authtypes.Accou func (d *Database) CreateAccount( ctx context.Context, localpart, plaintextPassword, appserviceID string, ) (acc *authtypes.Account, err error) { - err = common.WithTransaction(d.db, func(txn *sql.Tx) error { + err = internal.WithTransaction(d.db, func(txn *sql.Tx) error { acc, err = d.createAccount(ctx, txn, localpart, plaintextPassword, appserviceID) return err }) @@ -163,7 +163,7 @@ func (d *Database) createAccount( } } if err := d.profiles.insertProfile(ctx, txn, localpart); err != nil { - if common.IsUniqueConstraintViolationErr(err) { + if internal.IsUniqueConstraintViolationErr(err) { return nil, nil } return nil, err @@ -210,7 +210,7 @@ func (d *Database) removeMembershipsByEventIDs( func (d *Database) UpdateMemberships( ctx context.Context, eventsToAdd []gomatrixserverlib.Event, idsToRemove []string, ) error { - return common.WithTransaction(d.db, func(txn *sql.Tx) error { + return internal.WithTransaction(d.db, func(txn *sql.Tx) error { if err := d.removeMembershipsByEventIDs(ctx, txn, idsToRemove); err != nil { return err } @@ -297,7 +297,7 @@ func (d *Database) newMembership( func (d *Database) SaveAccountData( ctx context.Context, localpart, roomID, dataType, content string, ) error { - return common.WithTransaction(d.db, func(txn *sql.Tx) error { + return internal.WithTransaction(d.db, func(txn *sql.Tx) error { return d.accountDatas.insertAccountData(ctx, txn, localpart, roomID, dataType, content) }) } @@ -348,7 +348,7 @@ var Err3PIDInUse = errors.New("This third-party identifier is already in use") func (d *Database) SaveThreePIDAssociation( ctx context.Context, threepid, localpart, medium string, ) (err error) { - return common.WithTransaction(d.db, func(txn *sql.Tx) error { + return internal.WithTransaction(d.db, func(txn *sql.Tx) error { user, err := d.threepids.selectLocalpartForThreePID( ctx, txn, threepid, medium, ) diff --git a/clientapi/auth/storage/accounts/postgres/threepid_table.go b/clientapi/auth/storage/accounts/postgres/threepid_table.go index 851b4a90b..0b12b5c5b 100644 --- a/clientapi/auth/storage/accounts/postgres/threepid_table.go +++ b/clientapi/auth/storage/accounts/postgres/threepid_table.go @@ -18,7 +18,7 @@ import ( "context" "database/sql" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/clientapi/auth/authtypes" ) @@ -82,7 +82,7 @@ func (s *threepidStatements) prepare(db *sql.DB) (err error) { func (s *threepidStatements) selectLocalpartForThreePID( ctx context.Context, txn *sql.Tx, threepid string, medium string, ) (localpart string, err error) { - stmt := common.TxStmt(txn, s.selectLocalpartForThreePIDStmt) + stmt := internal.TxStmt(txn, s.selectLocalpartForThreePIDStmt) err = stmt.QueryRowContext(ctx, threepid, medium).Scan(&localpart) if err == sql.ErrNoRows { return "", nil @@ -117,7 +117,7 @@ func (s *threepidStatements) selectThreePIDsForLocalpart( func (s *threepidStatements) insertThreePID( ctx context.Context, txn *sql.Tx, threepid, medium, localpart string, ) (err error) { - stmt := common.TxStmt(txn, s.insertThreePIDStmt) + stmt := internal.TxStmt(txn, s.insertThreePIDStmt) _, err = stmt.ExecContext(ctx, threepid, medium, localpart) return } diff --git a/clientapi/auth/storage/accounts/sqlite3/membership_table.go b/clientapi/auth/storage/accounts/sqlite3/membership_table.go index bd9838b6b..90e16fb01 100644 --- a/clientapi/auth/storage/accounts/sqlite3/membership_table.go +++ b/clientapi/auth/storage/accounts/sqlite3/membership_table.go @@ -20,7 +20,7 @@ import ( "strings" "github.com/matrix-org/dendrite/clientapi/auth/authtypes" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" ) const membershipSchema = ` @@ -95,7 +95,7 @@ func (s *membershipStatements) insertMembership( func (s *membershipStatements) deleteMembershipsByEventIDs( ctx context.Context, txn *sql.Tx, eventIDs []string, ) (err error) { - sqlStr := strings.Replace(deleteMembershipsByEventIDsSQL, "($1)", common.QueryVariadic(len(eventIDs)), 1) + sqlStr := strings.Replace(deleteMembershipsByEventIDsSQL, "($1)", internal.QueryVariadic(len(eventIDs)), 1) iEventIDs := make([]interface{}, len(eventIDs)) for i, e := range eventIDs { iEventIDs[i] = e @@ -125,7 +125,7 @@ func (s *membershipStatements) selectMembershipsByLocalpart( memberships = []authtypes.Membership{} - defer common.CloseAndLogIfError(ctx, rows, "selectMembershipsByLocalpart: rows.close() failed") + defer internal.CloseAndLogIfError(ctx, rows, "selectMembershipsByLocalpart: rows.close() failed") for rows.Next() { var m authtypes.Membership m.Localpart = localpart diff --git a/clientapi/auth/storage/accounts/sqlite3/storage.go b/clientapi/auth/storage/accounts/sqlite3/storage.go index 30a93e7ed..7dec87294 100644 --- a/clientapi/auth/storage/accounts/sqlite3/storage.go +++ b/clientapi/auth/storage/accounts/sqlite3/storage.go @@ -22,7 +22,7 @@ import ( "sync" "github.com/matrix-org/dendrite/clientapi/auth/authtypes" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/internal/sqlutil" "github.com/matrix-org/gomatrixserverlib" "golang.org/x/crypto/bcrypt" @@ -34,7 +34,7 @@ import ( // Database represents an account database type Database struct { db *sql.DB - common.PartitionOffsetStatements + internal.PartitionOffsetStatements accounts accountsStatements profiles profilesStatements memberships membershipStatements @@ -50,10 +50,10 @@ type Database struct { func NewDatabase(dataSourceName string, serverName gomatrixserverlib.ServerName) (*Database, error) { var db *sql.DB var err error - if db, err = sqlutil.Open(common.SQLiteDriverName(), dataSourceName, nil); err != nil { + if db, err = sqlutil.Open(internal.SQLiteDriverName(), dataSourceName, nil); err != nil { return nil, err } - partitions := common.PartitionOffsetStatements{} + partitions := internal.PartitionOffsetStatements{} if err = partitions.Prepare(db, "account"); err != nil { return nil, err } @@ -126,7 +126,7 @@ func (d *Database) SetDisplayName( // CreateGuestAccount makes a new guest account and creates an empty profile // for this account. func (d *Database) CreateGuestAccount(ctx context.Context) (acc *authtypes.Account, err error) { - err = common.WithTransaction(d.db, func(txn *sql.Tx) error { + err = internal.WithTransaction(d.db, func(txn *sql.Tx) error { // We need to lock so we sequentially create numeric localparts. If we don't, two calls to // this function will cause the same number to be selected and one will fail with 'database is locked' // when the first txn upgrades to a write txn. @@ -152,7 +152,7 @@ func (d *Database) CreateGuestAccount(ctx context.Context) (acc *authtypes.Accou func (d *Database) CreateAccount( ctx context.Context, localpart, plaintextPassword, appserviceID string, ) (acc *authtypes.Account, err error) { - err = common.WithTransaction(d.db, func(txn *sql.Tx) error { + err = internal.WithTransaction(d.db, func(txn *sql.Tx) error { acc, err = d.createAccount(ctx, txn, localpart, plaintextPassword, appserviceID) return err }) @@ -172,7 +172,7 @@ func (d *Database) createAccount( } } if err := d.profiles.insertProfile(ctx, txn, localpart); err != nil { - if common.IsUniqueConstraintViolationErr(err) { + if internal.IsUniqueConstraintViolationErr(err) { return nil, nil } return nil, err @@ -219,7 +219,7 @@ func (d *Database) removeMembershipsByEventIDs( func (d *Database) UpdateMemberships( ctx context.Context, eventsToAdd []gomatrixserverlib.Event, idsToRemove []string, ) error { - return common.WithTransaction(d.db, func(txn *sql.Tx) error { + return internal.WithTransaction(d.db, func(txn *sql.Tx) error { if err := d.removeMembershipsByEventIDs(ctx, txn, idsToRemove); err != nil { return err } @@ -306,7 +306,7 @@ func (d *Database) newMembership( func (d *Database) SaveAccountData( ctx context.Context, localpart, roomID, dataType, content string, ) error { - return common.WithTransaction(d.db, func(txn *sql.Tx) error { + return internal.WithTransaction(d.db, func(txn *sql.Tx) error { return d.accountDatas.insertAccountData(ctx, txn, localpart, roomID, dataType, content) }) } @@ -357,7 +357,7 @@ var Err3PIDInUse = errors.New("This third-party identifier is already in use") func (d *Database) SaveThreePIDAssociation( ctx context.Context, threepid, localpart, medium string, ) (err error) { - return common.WithTransaction(d.db, func(txn *sql.Tx) error { + return internal.WithTransaction(d.db, func(txn *sql.Tx) error { user, err := d.threepids.selectLocalpartForThreePID( ctx, txn, threepid, medium, ) diff --git a/clientapi/auth/storage/accounts/sqlite3/threepid_table.go b/clientapi/auth/storage/accounts/sqlite3/threepid_table.go index 29ee4c3d0..f78a5ffcd 100644 --- a/clientapi/auth/storage/accounts/sqlite3/threepid_table.go +++ b/clientapi/auth/storage/accounts/sqlite3/threepid_table.go @@ -18,7 +18,7 @@ import ( "context" "database/sql" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/clientapi/auth/authtypes" ) @@ -82,7 +82,7 @@ func (s *threepidStatements) prepare(db *sql.DB) (err error) { func (s *threepidStatements) selectLocalpartForThreePID( ctx context.Context, txn *sql.Tx, threepid string, medium string, ) (localpart string, err error) { - stmt := common.TxStmt(txn, s.selectLocalpartForThreePIDStmt) + stmt := internal.TxStmt(txn, s.selectLocalpartForThreePIDStmt) err = stmt.QueryRowContext(ctx, threepid, medium).Scan(&localpart) if err == sql.ErrNoRows { return "", nil @@ -97,7 +97,7 @@ func (s *threepidStatements) selectThreePIDsForLocalpart( if err != nil { return } - defer common.CloseAndLogIfError(ctx, rows, "selectThreePIDsForLocalpart: rows.close() failed") + defer internal.CloseAndLogIfError(ctx, rows, "selectThreePIDsForLocalpart: rows.close() failed") threepids = []authtypes.ThreePID{} for rows.Next() { @@ -117,7 +117,7 @@ func (s *threepidStatements) selectThreePIDsForLocalpart( func (s *threepidStatements) insertThreePID( ctx context.Context, txn *sql.Tx, threepid, medium, localpart string, ) (err error) { - stmt := common.TxStmt(txn, s.insertThreePIDStmt) + stmt := internal.TxStmt(txn, s.insertThreePIDStmt) _, err = stmt.ExecContext(ctx, threepid, medium, localpart) return } diff --git a/clientapi/auth/storage/accounts/storage.go b/clientapi/auth/storage/accounts/storage.go index 394cc5e16..37126b30b 100644 --- a/clientapi/auth/storage/accounts/storage.go +++ b/clientapi/auth/storage/accounts/storage.go @@ -21,13 +21,13 @@ import ( "github.com/matrix-org/dendrite/clientapi/auth/storage/accounts/postgres" "github.com/matrix-org/dendrite/clientapi/auth/storage/accounts/sqlite3" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/gomatrixserverlib" ) // NewDatabase opens a new Postgres or Sqlite database (based on dataSourceName scheme) // and sets postgres connection parameters -func NewDatabase(dataSourceName string, dbProperties common.DbProperties, serverName gomatrixserverlib.ServerName) (Database, error) { +func NewDatabase(dataSourceName string, dbProperties internal.DbProperties, serverName gomatrixserverlib.ServerName) (Database, error) { uri, err := url.Parse(dataSourceName) if err != nil { return postgres.NewDatabase(dataSourceName, dbProperties, serverName) diff --git a/clientapi/auth/storage/accounts/storage_wasm.go b/clientapi/auth/storage/accounts/storage_wasm.go index 61f9d6997..81e77cf79 100644 --- a/clientapi/auth/storage/accounts/storage_wasm.go +++ b/clientapi/auth/storage/accounts/storage_wasm.go @@ -19,13 +19,13 @@ import ( "net/url" "github.com/matrix-org/dendrite/clientapi/auth/storage/accounts/sqlite3" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/gomatrixserverlib" ) func NewDatabase( dataSourceName string, - dbProperties common.DbProperties, // nolint:unparam + dbProperties internal.DbProperties, // nolint:unparam serverName gomatrixserverlib.ServerName, ) (Database, error) { uri, err := url.Parse(dataSourceName) diff --git a/clientapi/auth/storage/devices/postgres/devices_table.go b/clientapi/auth/storage/devices/postgres/devices_table.go index ee5591706..67d573f95 100644 --- a/clientapi/auth/storage/devices/postgres/devices_table.go +++ b/clientapi/auth/storage/devices/postgres/devices_table.go @@ -22,7 +22,7 @@ import ( "github.com/lib/pq" "github.com/matrix-org/dendrite/clientapi/auth/authtypes" "github.com/matrix-org/dendrite/clientapi/userutil" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/gomatrixserverlib" ) @@ -137,7 +137,7 @@ func (s *devicesStatements) insertDevice( ) (*authtypes.Device, error) { createdTimeMS := time.Now().UnixNano() / 1000000 var sessionID int64 - stmt := common.TxStmt(txn, s.insertDeviceStmt) + stmt := internal.TxStmt(txn, s.insertDeviceStmt) if err := stmt.QueryRowContext(ctx, id, localpart, accessToken, createdTimeMS, displayName).Scan(&sessionID); err != nil { return nil, err } @@ -153,7 +153,7 @@ func (s *devicesStatements) insertDevice( func (s *devicesStatements) deleteDevice( ctx context.Context, txn *sql.Tx, id, localpart string, ) error { - stmt := common.TxStmt(txn, s.deleteDeviceStmt) + stmt := internal.TxStmt(txn, s.deleteDeviceStmt) _, err := stmt.ExecContext(ctx, id, localpart) return err } @@ -163,7 +163,7 @@ func (s *devicesStatements) deleteDevice( func (s *devicesStatements) deleteDevices( ctx context.Context, txn *sql.Tx, localpart string, devices []string, ) error { - stmt := common.TxStmt(txn, s.deleteDevicesStmt) + stmt := internal.TxStmt(txn, s.deleteDevicesStmt) _, err := stmt.ExecContext(ctx, localpart, pq.Array(devices)) return err } @@ -173,7 +173,7 @@ func (s *devicesStatements) deleteDevices( func (s *devicesStatements) deleteDevicesByLocalpart( ctx context.Context, txn *sql.Tx, localpart string, ) error { - stmt := common.TxStmt(txn, s.deleteDevicesByLocalpartStmt) + stmt := internal.TxStmt(txn, s.deleteDevicesByLocalpartStmt) _, err := stmt.ExecContext(ctx, localpart) return err } @@ -181,7 +181,7 @@ func (s *devicesStatements) deleteDevicesByLocalpart( func (s *devicesStatements) updateDeviceName( ctx context.Context, txn *sql.Tx, localpart, deviceID string, displayName *string, ) error { - stmt := common.TxStmt(txn, s.updateDeviceNameStmt) + stmt := internal.TxStmt(txn, s.updateDeviceNameStmt) _, err := stmt.ExecContext(ctx, displayName, localpart, deviceID) return err } @@ -226,7 +226,7 @@ func (s *devicesStatements) selectDevicesByLocalpart( if err != nil { return devices, err } - defer common.CloseAndLogIfError(ctx, rows, "selectDevicesByLocalpart: rows.close() failed") + defer internal.CloseAndLogIfError(ctx, rows, "selectDevicesByLocalpart: rows.close() failed") for rows.Next() { var dev authtypes.Device diff --git a/clientapi/auth/storage/devices/postgres/storage.go b/clientapi/auth/storage/devices/postgres/storage.go index 57c268df8..e54e7c5d7 100644 --- a/clientapi/auth/storage/devices/postgres/storage.go +++ b/clientapi/auth/storage/devices/postgres/storage.go @@ -21,7 +21,7 @@ import ( "encoding/base64" "github.com/matrix-org/dendrite/clientapi/auth/authtypes" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/internal/sqlutil" "github.com/matrix-org/gomatrixserverlib" ) @@ -36,7 +36,7 @@ type Database struct { } // NewDatabase creates a new device database -func NewDatabase(dataSourceName string, dbProperties common.DbProperties, serverName gomatrixserverlib.ServerName) (*Database, error) { +func NewDatabase(dataSourceName string, dbProperties internal.DbProperties, serverName gomatrixserverlib.ServerName) (*Database, error) { var db *sql.DB var err error if db, err = sqlutil.Open("postgres", dataSourceName, dbProperties); err != nil { @@ -83,7 +83,7 @@ func (d *Database) CreateDevice( displayName *string, ) (dev *authtypes.Device, returnErr error) { if deviceID != nil { - returnErr = common.WithTransaction(d.db, func(txn *sql.Tx) error { + returnErr = internal.WithTransaction(d.db, func(txn *sql.Tx) error { var err error // Revoke existing tokens for this device if err = d.devices.deleteDevice(ctx, txn, *deviceID, localpart); err != nil { @@ -103,7 +103,7 @@ func (d *Database) CreateDevice( return } - returnErr = common.WithTransaction(d.db, func(txn *sql.Tx) error { + returnErr = internal.WithTransaction(d.db, func(txn *sql.Tx) error { var err error dev, err = d.devices.insertDevice(ctx, txn, newDeviceID, localpart, accessToken, displayName) return err @@ -133,7 +133,7 @@ func generateDeviceID() (string, error) { func (d *Database) UpdateDevice( ctx context.Context, localpart, deviceID string, displayName *string, ) error { - return common.WithTransaction(d.db, func(txn *sql.Tx) error { + return internal.WithTransaction(d.db, func(txn *sql.Tx) error { return d.devices.updateDeviceName(ctx, txn, localpart, deviceID, displayName) }) } @@ -145,7 +145,7 @@ func (d *Database) UpdateDevice( func (d *Database) RemoveDevice( ctx context.Context, deviceID, localpart string, ) error { - return common.WithTransaction(d.db, func(txn *sql.Tx) error { + return internal.WithTransaction(d.db, func(txn *sql.Tx) error { if err := d.devices.deleteDevice(ctx, txn, deviceID, localpart); err != sql.ErrNoRows { return err } @@ -160,7 +160,7 @@ func (d *Database) RemoveDevice( func (d *Database) RemoveDevices( ctx context.Context, localpart string, devices []string, ) error { - return common.WithTransaction(d.db, func(txn *sql.Tx) error { + return internal.WithTransaction(d.db, func(txn *sql.Tx) error { if err := d.devices.deleteDevices(ctx, txn, localpart, devices); err != sql.ErrNoRows { return err } @@ -174,7 +174,7 @@ func (d *Database) RemoveDevices( func (d *Database) RemoveAllDevices( ctx context.Context, localpart string, ) error { - return common.WithTransaction(d.db, func(txn *sql.Tx) error { + return internal.WithTransaction(d.db, func(txn *sql.Tx) error { if err := d.devices.deleteDevicesByLocalpart(ctx, txn, localpart); err != sql.ErrNoRows { return err } diff --git a/clientapi/auth/storage/devices/sqlite3/devices_table.go b/clientapi/auth/storage/devices/sqlite3/devices_table.go index f69810b7d..6ffc1646f 100644 --- a/clientapi/auth/storage/devices/sqlite3/devices_table.go +++ b/clientapi/auth/storage/devices/sqlite3/devices_table.go @@ -20,7 +20,7 @@ import ( "strings" "time" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/clientapi/auth/authtypes" "github.com/matrix-org/dendrite/clientapi/userutil" @@ -128,8 +128,8 @@ func (s *devicesStatements) insertDevice( ) (*authtypes.Device, error) { createdTimeMS := time.Now().UnixNano() / 1000000 var sessionID int64 - countStmt := common.TxStmt(txn, s.selectDevicesCountStmt) - insertStmt := common.TxStmt(txn, s.insertDeviceStmt) + countStmt := internal.TxStmt(txn, s.selectDevicesCountStmt) + insertStmt := internal.TxStmt(txn, s.insertDeviceStmt) if err := countStmt.QueryRowContext(ctx).Scan(&sessionID); err != nil { return nil, err } @@ -148,7 +148,7 @@ func (s *devicesStatements) insertDevice( func (s *devicesStatements) deleteDevice( ctx context.Context, txn *sql.Tx, id, localpart string, ) error { - stmt := common.TxStmt(txn, s.deleteDeviceStmt) + stmt := internal.TxStmt(txn, s.deleteDeviceStmt) _, err := stmt.ExecContext(ctx, id, localpart) return err } @@ -156,12 +156,12 @@ func (s *devicesStatements) deleteDevice( func (s *devicesStatements) deleteDevices( ctx context.Context, txn *sql.Tx, localpart string, devices []string, ) error { - orig := strings.Replace(deleteDevicesSQL, "($1)", common.QueryVariadic(len(devices)), 1) + orig := strings.Replace(deleteDevicesSQL, "($1)", internal.QueryVariadic(len(devices)), 1) prep, err := s.db.Prepare(orig) if err != nil { return err } - stmt := common.TxStmt(txn, prep) + stmt := internal.TxStmt(txn, prep) params := make([]interface{}, len(devices)+1) params[0] = localpart for i, v := range devices { @@ -175,7 +175,7 @@ func (s *devicesStatements) deleteDevices( func (s *devicesStatements) deleteDevicesByLocalpart( ctx context.Context, txn *sql.Tx, localpart string, ) error { - stmt := common.TxStmt(txn, s.deleteDevicesByLocalpartStmt) + stmt := internal.TxStmt(txn, s.deleteDevicesByLocalpartStmt) _, err := stmt.ExecContext(ctx, localpart) return err } @@ -183,7 +183,7 @@ func (s *devicesStatements) deleteDevicesByLocalpart( func (s *devicesStatements) updateDeviceName( ctx context.Context, txn *sql.Tx, localpart, deviceID string, displayName *string, ) error { - stmt := common.TxStmt(txn, s.updateDeviceNameStmt) + stmt := internal.TxStmt(txn, s.updateDeviceNameStmt) _, err := stmt.ExecContext(ctx, displayName, localpart, deviceID) return err } diff --git a/clientapi/auth/storage/devices/sqlite3/storage.go b/clientapi/auth/storage/devices/sqlite3/storage.go index b69d6278c..5cd894517 100644 --- a/clientapi/auth/storage/devices/sqlite3/storage.go +++ b/clientapi/auth/storage/devices/sqlite3/storage.go @@ -21,7 +21,7 @@ import ( "encoding/base64" "github.com/matrix-org/dendrite/clientapi/auth/authtypes" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/internal/sqlutil" "github.com/matrix-org/gomatrixserverlib" @@ -41,7 +41,7 @@ type Database struct { func NewDatabase(dataSourceName string, serverName gomatrixserverlib.ServerName) (*Database, error) { var db *sql.DB var err error - if db, err = sqlutil.Open(common.SQLiteDriverName(), dataSourceName, nil); err != nil { + if db, err = sqlutil.Open(internal.SQLiteDriverName(), dataSourceName, nil); err != nil { return nil, err } d := devicesStatements{} @@ -85,7 +85,7 @@ func (d *Database) CreateDevice( displayName *string, ) (dev *authtypes.Device, returnErr error) { if deviceID != nil { - returnErr = common.WithTransaction(d.db, func(txn *sql.Tx) error { + returnErr = internal.WithTransaction(d.db, func(txn *sql.Tx) error { var err error // Revoke existing tokens for this device if err = d.devices.deleteDevice(ctx, txn, *deviceID, localpart); err != nil { @@ -105,7 +105,7 @@ func (d *Database) CreateDevice( return } - returnErr = common.WithTransaction(d.db, func(txn *sql.Tx) error { + returnErr = internal.WithTransaction(d.db, func(txn *sql.Tx) error { var err error dev, err = d.devices.insertDevice(ctx, txn, newDeviceID, localpart, accessToken, displayName) return err @@ -135,7 +135,7 @@ func generateDeviceID() (string, error) { func (d *Database) UpdateDevice( ctx context.Context, localpart, deviceID string, displayName *string, ) error { - return common.WithTransaction(d.db, func(txn *sql.Tx) error { + return internal.WithTransaction(d.db, func(txn *sql.Tx) error { return d.devices.updateDeviceName(ctx, txn, localpart, deviceID, displayName) }) } @@ -147,7 +147,7 @@ func (d *Database) UpdateDevice( func (d *Database) RemoveDevice( ctx context.Context, deviceID, localpart string, ) error { - return common.WithTransaction(d.db, func(txn *sql.Tx) error { + return internal.WithTransaction(d.db, func(txn *sql.Tx) error { if err := d.devices.deleteDevice(ctx, txn, deviceID, localpart); err != sql.ErrNoRows { return err } @@ -162,7 +162,7 @@ func (d *Database) RemoveDevice( func (d *Database) RemoveDevices( ctx context.Context, localpart string, devices []string, ) error { - return common.WithTransaction(d.db, func(txn *sql.Tx) error { + return internal.WithTransaction(d.db, func(txn *sql.Tx) error { if err := d.devices.deleteDevices(ctx, txn, localpart, devices); err != sql.ErrNoRows { return err } @@ -176,7 +176,7 @@ func (d *Database) RemoveDevices( func (d *Database) RemoveAllDevices( ctx context.Context, localpart string, ) error { - return common.WithTransaction(d.db, func(txn *sql.Tx) error { + return internal.WithTransaction(d.db, func(txn *sql.Tx) error { if err := d.devices.deleteDevicesByLocalpart(ctx, txn, localpart); err != sql.ErrNoRows { return err } diff --git a/clientapi/auth/storage/devices/storage.go b/clientapi/auth/storage/devices/storage.go index ec47a3272..c132598bd 100644 --- a/clientapi/auth/storage/devices/storage.go +++ b/clientapi/auth/storage/devices/storage.go @@ -21,13 +21,13 @@ import ( "github.com/matrix-org/dendrite/clientapi/auth/storage/devices/postgres" "github.com/matrix-org/dendrite/clientapi/auth/storage/devices/sqlite3" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/gomatrixserverlib" ) // NewDatabase opens a new Postgres or Sqlite database (based on dataSourceName scheme) // and sets postgres connection parameters -func NewDatabase(dataSourceName string, dbProperties common.DbProperties, serverName gomatrixserverlib.ServerName) (Database, error) { +func NewDatabase(dataSourceName string, dbProperties internal.DbProperties, serverName gomatrixserverlib.ServerName) (Database, error) { uri, err := url.Parse(dataSourceName) if err != nil { return postgres.NewDatabase(dataSourceName, dbProperties, serverName) diff --git a/clientapi/auth/storage/devices/storage_wasm.go b/clientapi/auth/storage/devices/storage_wasm.go index e25b7c640..14c19e74b 100644 --- a/clientapi/auth/storage/devices/storage_wasm.go +++ b/clientapi/auth/storage/devices/storage_wasm.go @@ -19,13 +19,13 @@ import ( "net/url" "github.com/matrix-org/dendrite/clientapi/auth/storage/devices/sqlite3" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/gomatrixserverlib" ) func NewDatabase( dataSourceName string, - dbProperties common.DbProperties, // nolint:unparam + dbProperties internal.DbProperties, // nolint:unparam serverName gomatrixserverlib.ServerName, ) (Database, error) { uri, err := url.Parse(dataSourceName) diff --git a/clientapi/clientapi.go b/clientapi/clientapi.go index f81e0242c..66317e92e 100644 --- a/clientapi/clientapi.go +++ b/clientapi/clientapi.go @@ -21,10 +21,10 @@ import ( "github.com/matrix-org/dendrite/clientapi/consumers" "github.com/matrix-org/dendrite/clientapi/producers" "github.com/matrix-org/dendrite/clientapi/routing" - "github.com/matrix-org/dendrite/common/basecomponent" - "github.com/matrix-org/dendrite/common/transactions" eduServerAPI "github.com/matrix-org/dendrite/eduserver/api" federationSenderAPI "github.com/matrix-org/dendrite/federationsender/api" + "github.com/matrix-org/dendrite/internal/basecomponent" + "github.com/matrix-org/dendrite/internal/transactions" roomserverAPI "github.com/matrix-org/dendrite/roomserver/api" "github.com/matrix-org/gomatrixserverlib" "github.com/sirupsen/logrus" diff --git a/clientapi/consumers/roomserver.go b/clientapi/consumers/roomserver.go index d0c91e88f..bd8ac1dcd 100644 --- a/clientapi/consumers/roomserver.go +++ b/clientapi/consumers/roomserver.go @@ -19,8 +19,8 @@ import ( "encoding/json" "github.com/matrix-org/dendrite/clientapi/auth/storage/accounts" - "github.com/matrix-org/dendrite/common" - "github.com/matrix-org/dendrite/common/config" + "github.com/matrix-org/dendrite/internal" + "github.com/matrix-org/dendrite/internal/config" "github.com/matrix-org/dendrite/roomserver/api" "github.com/matrix-org/gomatrixserverlib" @@ -31,7 +31,7 @@ import ( // OutputRoomEventConsumer consumes events that originated in the room server. type OutputRoomEventConsumer struct { rsAPI api.RoomserverInternalAPI - rsConsumer *common.ContinualConsumer + rsConsumer *internal.ContinualConsumer db accounts.Database serverName string } @@ -44,7 +44,7 @@ func NewOutputRoomEventConsumer( rsAPI api.RoomserverInternalAPI, ) *OutputRoomEventConsumer { - consumer := common.ContinualConsumer{ + consumer := internal.ContinualConsumer{ Topic: string(cfg.Kafka.Topics.OutputRoomEvent), Consumer: kafkaConsumer, PartitionStore: store, diff --git a/clientapi/producers/syncapi.go b/clientapi/producers/syncapi.go index 0a446e2f5..244a61dc2 100644 --- a/clientapi/producers/syncapi.go +++ b/clientapi/producers/syncapi.go @@ -17,7 +17,7 @@ package producers import ( "encoding/json" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/Shopify/sarama" ) @@ -32,7 +32,7 @@ type SyncAPIProducer struct { func (p *SyncAPIProducer) SendData(userID string, roomID string, dataType string) error { var m sarama.ProducerMessage - data := common.AccountData{ + data := internal.AccountData{ RoomID: roomID, Type: dataType, } diff --git a/clientapi/producers/userupdate.go b/clientapi/producers/userupdate.go index 426b6d509..02e1700fd 100644 --- a/clientapi/producers/userupdate.go +++ b/clientapi/producers/userupdate.go @@ -26,7 +26,7 @@ type UserUpdateProducer struct { Producer sarama.SyncProducer } -// TODO: Move this struct to `common` so the components that consume the topic +// TODO: Move this struct to `internal` so the components that consume the topic // can use it when parsing incoming messages type profileUpdate struct { Updated string `json:"updated"` // Which attribute is updated (can be either `avatar_url` or `displayname`) diff --git a/clientapi/routing/auth_fallback.go b/clientapi/routing/auth_fallback.go index 8cb6b3d9b..b7f2cd6d3 100644 --- a/clientapi/routing/auth_fallback.go +++ b/clientapi/routing/auth_fallback.go @@ -20,7 +20,7 @@ import ( "github.com/matrix-org/dendrite/clientapi/auth/authtypes" "github.com/matrix-org/dendrite/clientapi/jsonerror" - "github.com/matrix-org/dendrite/common/config" + "github.com/matrix-org/dendrite/internal/config" "github.com/matrix-org/util" ) diff --git a/clientapi/routing/createroom.go b/clientapi/routing/createroom.go index f789ae100..1b4ff184f 100644 --- a/clientapi/routing/createroom.go +++ b/clientapi/routing/createroom.go @@ -31,8 +31,8 @@ import ( "github.com/matrix-org/dendrite/clientapi/jsonerror" "github.com/matrix-org/dendrite/clientapi/producers" "github.com/matrix-org/dendrite/clientapi/threepid" - "github.com/matrix-org/dendrite/common" - "github.com/matrix-org/dendrite/common/config" + "github.com/matrix-org/dendrite/internal" + "github.com/matrix-org/dendrite/internal/config" "github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/util" log "github.com/sirupsen/logrus" @@ -99,7 +99,7 @@ func (r createRoomRequest) Validate() *util.JSONResponse { // Validate creation_content fields defined in the spec by marshalling the // creation_content map into bytes and then unmarshalling the bytes into - // common.CreateContent. + // internal.CreateContent. creationContentBytes, err := json.Marshal(r.CreationContent) if err != nil { @@ -280,25 +280,25 @@ func createRoom( eventsToMake := []fledglingEvent{ {"m.room.create", "", r.CreationContent}, {"m.room.member", userID, membershipContent}, - {"m.room.power_levels", "", common.InitialPowerLevelsContent(userID)}, + {"m.room.power_levels", "", internal.InitialPowerLevelsContent(userID)}, {"m.room.join_rules", "", gomatrixserverlib.JoinRuleContent{JoinRule: joinRules}}, - {"m.room.history_visibility", "", common.HistoryVisibilityContent{HistoryVisibility: historyVisibility}}, + {"m.room.history_visibility", "", internal.HistoryVisibilityContent{HistoryVisibility: historyVisibility}}, } if roomAlias != "" { // TODO: bit of a chicken and egg problem here as the alias doesn't exist and cannot until we have made the room. // This means we might fail creating the alias but say the canonical alias is something that doesn't exist. // m.room.aliases is handled when we call roomserver.SetRoomAlias - eventsToMake = append(eventsToMake, fledglingEvent{"m.room.canonical_alias", "", common.CanonicalAlias{Alias: roomAlias}}) + eventsToMake = append(eventsToMake, fledglingEvent{"m.room.canonical_alias", "", internal.CanonicalAlias{Alias: roomAlias}}) } if r.GuestCanJoin { - eventsToMake = append(eventsToMake, fledglingEvent{"m.room.guest_access", "", common.GuestAccessContent{GuestAccess: "can_join"}}) + eventsToMake = append(eventsToMake, fledglingEvent{"m.room.guest_access", "", internal.GuestAccessContent{GuestAccess: "can_join"}}) } eventsToMake = append(eventsToMake, r.InitialState...) if r.Name != "" { - eventsToMake = append(eventsToMake, fledglingEvent{"m.room.name", "", common.NameContent{Name: r.Name}}) + eventsToMake = append(eventsToMake, fledglingEvent{"m.room.name", "", internal.NameContent{Name: r.Name}}) } if r.Topic != "" { - eventsToMake = append(eventsToMake, fledglingEvent{"m.room.topic", "", common.TopicContent{Topic: r.Topic}}) + eventsToMake = append(eventsToMake, fledglingEvent{"m.room.topic", "", internal.TopicContent{Topic: r.Topic}}) } // TODO: invite events // TODO: 3pid invite events diff --git a/clientapi/routing/directory.go b/clientapi/routing/directory.go index a0a60a47a..b1dfb56fb 100644 --- a/clientapi/routing/directory.go +++ b/clientapi/routing/directory.go @@ -21,8 +21,8 @@ import ( "github.com/matrix-org/dendrite/clientapi/auth/authtypes" "github.com/matrix-org/dendrite/clientapi/httputil" "github.com/matrix-org/dendrite/clientapi/jsonerror" - "github.com/matrix-org/dendrite/common/config" federationSenderAPI "github.com/matrix-org/dendrite/federationsender/api" + "github.com/matrix-org/dendrite/internal/config" roomserverAPI "github.com/matrix-org/dendrite/roomserver/api" "github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/util" diff --git a/clientapi/routing/getevent.go b/clientapi/routing/getevent.go index bf49968de..3ca9d1b62 100644 --- a/clientapi/routing/getevent.go +++ b/clientapi/routing/getevent.go @@ -19,7 +19,7 @@ import ( "github.com/matrix-org/dendrite/clientapi/auth/authtypes" "github.com/matrix-org/dendrite/clientapi/jsonerror" - "github.com/matrix-org/dendrite/common/config" + "github.com/matrix-org/dendrite/internal/config" "github.com/matrix-org/dendrite/roomserver/api" "github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/util" diff --git a/clientapi/routing/joinroom.go b/clientapi/routing/joinroom.go index 2a2fce185..500df337a 100644 --- a/clientapi/routing/joinroom.go +++ b/clientapi/routing/joinroom.go @@ -72,7 +72,7 @@ func JoinRoomByIDOrAlias( return util.JSONResponse{ Code: http.StatusOK, - // TODO: Put the response struct somewhere common. + // TODO: Put the response struct somewhere internal. JSON: struct { RoomID string `json:"room_id"` }{joinReq.RoomIDOrAlias}, diff --git a/clientapi/routing/login.go b/clientapi/routing/login.go index 21b947200..c0042fa95 100644 --- a/clientapi/routing/login.go +++ b/clientapi/routing/login.go @@ -26,7 +26,7 @@ import ( "github.com/matrix-org/dendrite/clientapi/httputil" "github.com/matrix-org/dendrite/clientapi/jsonerror" "github.com/matrix-org/dendrite/clientapi/userutil" - "github.com/matrix-org/dendrite/common/config" + "github.com/matrix-org/dendrite/internal/config" "github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/util" ) diff --git a/clientapi/routing/membership.go b/clientapi/routing/membership.go index 0a56eec57..cd0ce7328 100644 --- a/clientapi/routing/membership.go +++ b/clientapi/routing/membership.go @@ -27,8 +27,8 @@ import ( "github.com/matrix-org/dendrite/clientapi/jsonerror" "github.com/matrix-org/dendrite/clientapi/producers" "github.com/matrix-org/dendrite/clientapi/threepid" - "github.com/matrix-org/dendrite/common" - "github.com/matrix-org/dendrite/common/config" + "github.com/matrix-org/dendrite/internal" + "github.com/matrix-org/dendrite/internal/config" "github.com/matrix-org/dendrite/roomserver/api" roomserverAPI "github.com/matrix-org/dendrite/roomserver/api" "github.com/matrix-org/gomatrixserverlib" @@ -97,7 +97,7 @@ func SendMembership( Code: http.StatusBadRequest, JSON: jsonerror.BadJSON(err.Error()), } - } else if err == common.ErrRoomNoExists { + } else if err == internal.ErrRoomNoExists { return util.JSONResponse{ Code: http.StatusNotFound, JSON: jsonerror.NotFound(err.Error()), @@ -190,7 +190,7 @@ func buildMembershipEvent( return nil, err } - return common.BuildEvent(ctx, &builder, cfg, evTime, rsAPI, nil) + return internal.BuildEvent(ctx, &builder, cfg, evTime, rsAPI, nil) } // loadProfile lookups the profile of a given user from the database and returns @@ -271,7 +271,7 @@ func checkAndProcessThreepid( Code: http.StatusBadRequest, JSON: jsonerror.NotTrusted(body.IDServer), } - } else if err == common.ErrRoomNoExists { + } else if err == internal.ErrRoomNoExists { return inviteStored, &util.JSONResponse{ Code: http.StatusNotFound, JSON: jsonerror.NotFound(err.Error()), diff --git a/clientapi/routing/memberships.go b/clientapi/routing/memberships.go index f5d9bc4c5..095a85c08 100644 --- a/clientapi/routing/memberships.go +++ b/clientapi/routing/memberships.go @@ -21,7 +21,7 @@ import ( "github.com/matrix-org/dendrite/clientapi/auth/authtypes" "github.com/matrix-org/dendrite/clientapi/jsonerror" - "github.com/matrix-org/dendrite/common/config" + "github.com/matrix-org/dendrite/internal/config" "github.com/matrix-org/dendrite/roomserver/api" "github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/util" diff --git a/clientapi/routing/profile.go b/clientapi/routing/profile.go index b51533e45..1c1ee8036 100644 --- a/clientapi/routing/profile.go +++ b/clientapi/routing/profile.go @@ -25,8 +25,8 @@ import ( "github.com/matrix-org/dendrite/clientapi/httputil" "github.com/matrix-org/dendrite/clientapi/jsonerror" "github.com/matrix-org/dendrite/clientapi/producers" - "github.com/matrix-org/dendrite/common" - "github.com/matrix-org/dendrite/common/config" + "github.com/matrix-org/dendrite/internal" + "github.com/matrix-org/dendrite/internal/config" "github.com/matrix-org/dendrite/roomserver/api" "github.com/matrix-org/gomatrixserverlib" @@ -43,7 +43,7 @@ func GetProfile( ) util.JSONResponse { profile, err := getProfile(req.Context(), accountDB, cfg, userID, asAPI, federation) if err != nil { - if err == common.ErrProfileNoExists { + if err == internal.ErrProfileNoExists { return util.JSONResponse{ Code: http.StatusNotFound, JSON: jsonerror.NotFound("The user does not exist or does not have a profile"), @@ -56,7 +56,7 @@ func GetProfile( return util.JSONResponse{ Code: http.StatusOK, - JSON: common.ProfileResponse{ + JSON: internal.ProfileResponse{ AvatarURL: profile.AvatarURL, DisplayName: profile.DisplayName, }, @@ -71,7 +71,7 @@ func GetAvatarURL( ) util.JSONResponse { profile, err := getProfile(req.Context(), accountDB, cfg, userID, asAPI, federation) if err != nil { - if err == common.ErrProfileNoExists { + if err == internal.ErrProfileNoExists { return util.JSONResponse{ Code: http.StatusNotFound, JSON: jsonerror.NotFound("The user does not exist or does not have a profile"), @@ -84,7 +84,7 @@ func GetAvatarURL( return util.JSONResponse{ Code: http.StatusOK, - JSON: common.AvatarURL{ + JSON: internal.AvatarURL{ AvatarURL: profile.AvatarURL, }, } @@ -105,7 +105,7 @@ func SetAvatarURL( changedKey := "avatar_url" - var r common.AvatarURL + var r internal.AvatarURL if resErr := httputil.UnmarshalJSONRequest(req, &r); resErr != nil { return *resErr } @@ -185,7 +185,7 @@ func GetDisplayName( ) util.JSONResponse { profile, err := getProfile(req.Context(), accountDB, cfg, userID, asAPI, federation) if err != nil { - if err == common.ErrProfileNoExists { + if err == internal.ErrProfileNoExists { return util.JSONResponse{ Code: http.StatusNotFound, JSON: jsonerror.NotFound("The user does not exist or does not have a profile"), @@ -198,7 +198,7 @@ func GetDisplayName( return util.JSONResponse{ Code: http.StatusOK, - JSON: common.DisplayName{ + JSON: internal.DisplayName{ DisplayName: profile.DisplayName, }, } @@ -219,7 +219,7 @@ func SetDisplayName( changedKey := "displayname" - var r common.DisplayName + var r internal.DisplayName if resErr := httputil.UnmarshalJSONRequest(req, &r); resErr != nil { return *resErr } @@ -294,7 +294,7 @@ func SetDisplayName( // getProfile gets the full profile of a user by querying the database or a // remote homeserver. // Returns an error when something goes wrong or specifically -// common.ErrProfileNoExists when the profile doesn't exist. +// internal.ErrProfileNoExists when the profile doesn't exist. func getProfile( ctx context.Context, accountDB accounts.Database, cfg *config.Dendrite, userID string, @@ -311,7 +311,7 @@ func getProfile( if fedErr != nil { if x, ok := fedErr.(gomatrix.HTTPError); ok { if x.Code == http.StatusNotFound { - return nil, common.ErrProfileNoExists + return nil, internal.ErrProfileNoExists } } @@ -366,7 +366,7 @@ func buildMembershipEvents( return nil, err } - event, err := common.BuildEvent(ctx, &builder, cfg, evTime, rsAPI, nil) + event, err := internal.BuildEvent(ctx, &builder, cfg, evTime, rsAPI, nil) if err != nil { return nil, err } diff --git a/clientapi/routing/register.go b/clientapi/routing/register.go index b67e68e19..40a2862f8 100644 --- a/clientapi/routing/register.go +++ b/clientapi/routing/register.go @@ -32,7 +32,7 @@ import ( "sync" "time" - "github.com/matrix-org/dendrite/common/config" + "github.com/matrix-org/dendrite/internal/config" "github.com/matrix-org/dendrite/clientapi/auth" "github.com/matrix-org/dendrite/clientapi/auth/authtypes" @@ -41,7 +41,7 @@ import ( "github.com/matrix-org/dendrite/clientapi/httputil" "github.com/matrix-org/dendrite/clientapi/jsonerror" "github.com/matrix-org/dendrite/clientapi/userutil" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/gomatrixserverlib/tokens" "github.com/matrix-org/util" @@ -136,7 +136,7 @@ type registerRequest struct { DeviceID *string `json:"device_id"` // Prevent this user from logging in - InhibitLogin common.WeakBoolean `json:"inhibit_login"` + InhibitLogin internal.WeakBoolean `json:"inhibit_login"` // Application Services place Type in the root of their registration // request, whereas clients place it in the authDict struct. @@ -811,7 +811,7 @@ func completeRegistration( accountDB accounts.Database, deviceDB devices.Database, username, password, appserviceID string, - inhibitLogin common.WeakBoolean, + inhibitLogin internal.WeakBoolean, displayName, deviceID *string, ) util.JSONResponse { if username == "" { diff --git a/clientapi/routing/register_test.go b/clientapi/routing/register_test.go index 6fcf0bc39..a44389f94 100644 --- a/clientapi/routing/register_test.go +++ b/clientapi/routing/register_test.go @@ -19,7 +19,7 @@ import ( "testing" "github.com/matrix-org/dendrite/clientapi/auth/authtypes" - "github.com/matrix-org/dendrite/common/config" + "github.com/matrix-org/dendrite/internal/config" ) var ( diff --git a/clientapi/routing/routing.go b/clientapi/routing/routing.go index f8cdcf5b8..377881cb6 100644 --- a/clientapi/routing/routing.go +++ b/clientapi/routing/routing.go @@ -27,10 +27,10 @@ import ( "github.com/matrix-org/dendrite/clientapi/auth/storage/devices" "github.com/matrix-org/dendrite/clientapi/jsonerror" "github.com/matrix-org/dendrite/clientapi/producers" - "github.com/matrix-org/dendrite/common" - "github.com/matrix-org/dendrite/common/config" - "github.com/matrix-org/dendrite/common/transactions" federationSenderAPI "github.com/matrix-org/dendrite/federationsender/api" + "github.com/matrix-org/dendrite/internal" + "github.com/matrix-org/dendrite/internal/config" + "github.com/matrix-org/dendrite/internal/transactions" roomserverAPI "github.com/matrix-org/dendrite/roomserver/api" "github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/util" @@ -63,7 +63,7 @@ func Setup( ) { apiMux.Handle("/_matrix/client/versions", - common.MakeExternalAPI("versions", func(req *http.Request) util.JSONResponse { + internal.MakeExternalAPI("versions", func(req *http.Request) util.JSONResponse { return util.JSONResponse{ Code: http.StatusOK, JSON: struct { @@ -89,13 +89,13 @@ func Setup( } r0mux.Handle("/createRoom", - common.MakeAuthAPI("createRoom", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { + internal.MakeAuthAPI("createRoom", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { return CreateRoom(req, device, cfg, producer, accountDB, rsAPI, asAPI) }), ).Methods(http.MethodPost, http.MethodOptions) r0mux.Handle("/join/{roomIDOrAlias}", - common.MakeAuthAPI(gomatrixserverlib.Join, authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { - vars, err := common.URLDecodeMapValues(mux.Vars(req)) + internal.MakeAuthAPI(gomatrixserverlib.Join, authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { + vars, err := internal.URLDecodeMapValues(mux.Vars(req)) if err != nil { return util.ErrorResponse(err) } @@ -105,13 +105,13 @@ func Setup( }), ).Methods(http.MethodPost, http.MethodOptions) r0mux.Handle("/joined_rooms", - common.MakeAuthAPI("joined_rooms", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { + internal.MakeAuthAPI("joined_rooms", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { return GetJoinedRooms(req, device, accountDB) }), ).Methods(http.MethodGet, http.MethodOptions) r0mux.Handle("/rooms/{roomID}/leave", - common.MakeAuthAPI("membership", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { - vars, err := common.URLDecodeMapValues(mux.Vars(req)) + internal.MakeAuthAPI("membership", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { + vars, err := internal.URLDecodeMapValues(mux.Vars(req)) if err != nil { return util.ErrorResponse(err) } @@ -121,8 +121,8 @@ func Setup( }), ).Methods(http.MethodPost, http.MethodOptions) r0mux.Handle("/rooms/{roomID}/{membership:(?:join|kick|ban|unban|invite)}", - common.MakeAuthAPI("membership", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { - vars, err := common.URLDecodeMapValues(mux.Vars(req)) + internal.MakeAuthAPI("membership", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { + vars, err := internal.URLDecodeMapValues(mux.Vars(req)) if err != nil { return util.ErrorResponse(err) } @@ -130,8 +130,8 @@ func Setup( }), ).Methods(http.MethodPost, http.MethodOptions) r0mux.Handle("/rooms/{roomID}/send/{eventType}", - common.MakeAuthAPI("send_message", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { - vars, err := common.URLDecodeMapValues(mux.Vars(req)) + internal.MakeAuthAPI("send_message", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { + vars, err := internal.URLDecodeMapValues(mux.Vars(req)) if err != nil { return util.ErrorResponse(err) } @@ -139,8 +139,8 @@ func Setup( }), ).Methods(http.MethodPost, http.MethodOptions) r0mux.Handle("/rooms/{roomID}/send/{eventType}/{txnID}", - common.MakeAuthAPI("send_message", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { - vars, err := common.URLDecodeMapValues(mux.Vars(req)) + internal.MakeAuthAPI("send_message", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { + vars, err := internal.URLDecodeMapValues(mux.Vars(req)) if err != nil { return util.ErrorResponse(err) } @@ -150,8 +150,8 @@ func Setup( }), ).Methods(http.MethodPut, http.MethodOptions) r0mux.Handle("/rooms/{roomID}/event/{eventID}", - common.MakeAuthAPI("rooms_get_event", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { - vars, err := common.URLDecodeMapValues(mux.Vars(req)) + internal.MakeAuthAPI("rooms_get_event", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { + vars, err := internal.URLDecodeMapValues(mux.Vars(req)) if err != nil { return util.ErrorResponse(err) } @@ -159,24 +159,24 @@ func Setup( }), ).Methods(http.MethodGet, http.MethodOptions) - r0mux.Handle("/rooms/{roomID}/state", common.MakeAuthAPI("room_state", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { - vars, err := common.URLDecodeMapValues(mux.Vars(req)) + r0mux.Handle("/rooms/{roomID}/state", internal.MakeAuthAPI("room_state", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { + vars, err := internal.URLDecodeMapValues(mux.Vars(req)) if err != nil { return util.ErrorResponse(err) } return OnIncomingStateRequest(req.Context(), rsAPI, vars["roomID"]) })).Methods(http.MethodGet, http.MethodOptions) - r0mux.Handle("/rooms/{roomID}/state/{type}", common.MakeAuthAPI("room_state", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { - vars, err := common.URLDecodeMapValues(mux.Vars(req)) + r0mux.Handle("/rooms/{roomID}/state/{type}", internal.MakeAuthAPI("room_state", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { + vars, err := internal.URLDecodeMapValues(mux.Vars(req)) if err != nil { return util.ErrorResponse(err) } return OnIncomingStateTypeRequest(req.Context(), rsAPI, vars["roomID"], vars["type"], "") })).Methods(http.MethodGet, http.MethodOptions) - r0mux.Handle("/rooms/{roomID}/state/{type}/{stateKey}", common.MakeAuthAPI("room_state", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { - vars, err := common.URLDecodeMapValues(mux.Vars(req)) + r0mux.Handle("/rooms/{roomID}/state/{type}/{stateKey}", internal.MakeAuthAPI("room_state", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { + vars, err := internal.URLDecodeMapValues(mux.Vars(req)) if err != nil { return util.ErrorResponse(err) } @@ -184,8 +184,8 @@ func Setup( })).Methods(http.MethodGet, http.MethodOptions) r0mux.Handle("/rooms/{roomID}/state/{eventType:[^/]+/?}", - common.MakeAuthAPI("send_message", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { - vars, err := common.URLDecodeMapValues(mux.Vars(req)) + internal.MakeAuthAPI("send_message", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { + vars, err := internal.URLDecodeMapValues(mux.Vars(req)) if err != nil { return util.ErrorResponse(err) } @@ -200,8 +200,8 @@ func Setup( ).Methods(http.MethodPut, http.MethodOptions) r0mux.Handle("/rooms/{roomID}/state/{eventType}/{stateKey}", - common.MakeAuthAPI("send_message", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { - vars, err := common.URLDecodeMapValues(mux.Vars(req)) + internal.MakeAuthAPI("send_message", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { + vars, err := internal.URLDecodeMapValues(mux.Vars(req)) if err != nil { return util.ErrorResponse(err) } @@ -210,21 +210,21 @@ func Setup( }), ).Methods(http.MethodPut, http.MethodOptions) - r0mux.Handle("/register", common.MakeExternalAPI("register", func(req *http.Request) util.JSONResponse { + r0mux.Handle("/register", internal.MakeExternalAPI("register", func(req *http.Request) util.JSONResponse { return Register(req, accountDB, deviceDB, cfg) })).Methods(http.MethodPost, http.MethodOptions) - v1mux.Handle("/register", common.MakeExternalAPI("register", func(req *http.Request) util.JSONResponse { + v1mux.Handle("/register", internal.MakeExternalAPI("register", func(req *http.Request) util.JSONResponse { return LegacyRegister(req, accountDB, deviceDB, cfg) })).Methods(http.MethodPost, http.MethodOptions) - r0mux.Handle("/register/available", common.MakeExternalAPI("registerAvailable", func(req *http.Request) util.JSONResponse { + r0mux.Handle("/register/available", internal.MakeExternalAPI("registerAvailable", func(req *http.Request) util.JSONResponse { return RegisterAvailable(req, cfg, accountDB) })).Methods(http.MethodGet, http.MethodOptions) r0mux.Handle("/directory/room/{roomAlias}", - common.MakeExternalAPI("directory_room", func(req *http.Request) util.JSONResponse { - vars, err := common.URLDecodeMapValues(mux.Vars(req)) + internal.MakeExternalAPI("directory_room", func(req *http.Request) util.JSONResponse { + vars, err := internal.URLDecodeMapValues(mux.Vars(req)) if err != nil { return util.ErrorResponse(err) } @@ -233,8 +233,8 @@ func Setup( ).Methods(http.MethodGet, http.MethodOptions) r0mux.Handle("/directory/room/{roomAlias}", - common.MakeAuthAPI("directory_room", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { - vars, err := common.URLDecodeMapValues(mux.Vars(req)) + internal.MakeAuthAPI("directory_room", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { + vars, err := internal.URLDecodeMapValues(mux.Vars(req)) if err != nil { return util.ErrorResponse(err) } @@ -243,8 +243,8 @@ func Setup( ).Methods(http.MethodPut, http.MethodOptions) r0mux.Handle("/directory/room/{roomAlias}", - common.MakeAuthAPI("directory_room", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { - vars, err := common.URLDecodeMapValues(mux.Vars(req)) + internal.MakeAuthAPI("directory_room", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { + vars, err := internal.URLDecodeMapValues(mux.Vars(req)) if err != nil { return util.ErrorResponse(err) } @@ -253,20 +253,20 @@ func Setup( ).Methods(http.MethodDelete, http.MethodOptions) r0mux.Handle("/logout", - common.MakeAuthAPI("logout", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { + internal.MakeAuthAPI("logout", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { return Logout(req, deviceDB, device) }), ).Methods(http.MethodPost, http.MethodOptions) r0mux.Handle("/logout/all", - common.MakeAuthAPI("logout", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { + internal.MakeAuthAPI("logout", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { return LogoutAll(req, deviceDB, device) }), ).Methods(http.MethodPost, http.MethodOptions) r0mux.Handle("/rooms/{roomID}/typing/{userID}", - common.MakeAuthAPI("rooms_typing", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { - vars, err := common.URLDecodeMapValues(mux.Vars(req)) + internal.MakeAuthAPI("rooms_typing", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { + vars, err := internal.URLDecodeMapValues(mux.Vars(req)) if err != nil { return util.ErrorResponse(err) } @@ -275,7 +275,7 @@ func Setup( ).Methods(http.MethodPut, http.MethodOptions) r0mux.Handle("/account/whoami", - common.MakeAuthAPI("whoami", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { + internal.MakeAuthAPI("whoami", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { return Whoami(req, device) }), ).Methods(http.MethodGet, http.MethodOptions) @@ -283,20 +283,20 @@ func Setup( // Stub endpoints required by Riot r0mux.Handle("/login", - common.MakeExternalAPI("login", func(req *http.Request) util.JSONResponse { + internal.MakeExternalAPI("login", func(req *http.Request) util.JSONResponse { return Login(req, accountDB, deviceDB, cfg) }), ).Methods(http.MethodGet, http.MethodPost, http.MethodOptions) r0mux.Handle("/auth/{authType}/fallback/web", - common.MakeHTMLAPI("auth_fallback", func(w http.ResponseWriter, req *http.Request) *util.JSONResponse { + internal.MakeHTMLAPI("auth_fallback", func(w http.ResponseWriter, req *http.Request) *util.JSONResponse { vars := mux.Vars(req) return AuthFallback(w, req, vars["authType"], cfg) }), ).Methods(http.MethodGet, http.MethodPost, http.MethodOptions) r0mux.Handle("/pushrules/", - common.MakeExternalAPI("push_rules", func(req *http.Request) util.JSONResponse { + internal.MakeExternalAPI("push_rules", func(req *http.Request) util.JSONResponse { // TODO: Implement push rules API res := json.RawMessage(`{ "global": { @@ -315,8 +315,8 @@ func Setup( ).Methods(http.MethodGet, http.MethodOptions) r0mux.Handle("/user/{userId}/filter", - common.MakeAuthAPI("put_filter", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { - vars, err := common.URLDecodeMapValues(mux.Vars(req)) + internal.MakeAuthAPI("put_filter", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { + vars, err := internal.URLDecodeMapValues(mux.Vars(req)) if err != nil { return util.ErrorResponse(err) } @@ -325,8 +325,8 @@ func Setup( ).Methods(http.MethodPost, http.MethodOptions) r0mux.Handle("/user/{userId}/filter/{filterId}", - common.MakeAuthAPI("get_filter", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { - vars, err := common.URLDecodeMapValues(mux.Vars(req)) + internal.MakeAuthAPI("get_filter", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { + vars, err := internal.URLDecodeMapValues(mux.Vars(req)) if err != nil { return util.ErrorResponse(err) } @@ -337,8 +337,8 @@ func Setup( // Riot user settings r0mux.Handle("/profile/{userID}", - common.MakeExternalAPI("profile", func(req *http.Request) util.JSONResponse { - vars, err := common.URLDecodeMapValues(mux.Vars(req)) + internal.MakeExternalAPI("profile", func(req *http.Request) util.JSONResponse { + vars, err := internal.URLDecodeMapValues(mux.Vars(req)) if err != nil { return util.ErrorResponse(err) } @@ -347,8 +347,8 @@ func Setup( ).Methods(http.MethodGet, http.MethodOptions) r0mux.Handle("/profile/{userID}/avatar_url", - common.MakeExternalAPI("profile_avatar_url", func(req *http.Request) util.JSONResponse { - vars, err := common.URLDecodeMapValues(mux.Vars(req)) + internal.MakeExternalAPI("profile_avatar_url", func(req *http.Request) util.JSONResponse { + vars, err := internal.URLDecodeMapValues(mux.Vars(req)) if err != nil { return util.ErrorResponse(err) } @@ -357,8 +357,8 @@ func Setup( ).Methods(http.MethodGet, http.MethodOptions) r0mux.Handle("/profile/{userID}/avatar_url", - common.MakeAuthAPI("profile_avatar_url", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { - vars, err := common.URLDecodeMapValues(mux.Vars(req)) + internal.MakeAuthAPI("profile_avatar_url", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { + vars, err := internal.URLDecodeMapValues(mux.Vars(req)) if err != nil { return util.ErrorResponse(err) } @@ -369,8 +369,8 @@ func Setup( // PUT requests, so we need to allow this method r0mux.Handle("/profile/{userID}/displayname", - common.MakeExternalAPI("profile_displayname", func(req *http.Request) util.JSONResponse { - vars, err := common.URLDecodeMapValues(mux.Vars(req)) + internal.MakeExternalAPI("profile_displayname", func(req *http.Request) util.JSONResponse { + vars, err := internal.URLDecodeMapValues(mux.Vars(req)) if err != nil { return util.ErrorResponse(err) } @@ -379,8 +379,8 @@ func Setup( ).Methods(http.MethodGet, http.MethodOptions) r0mux.Handle("/profile/{userID}/displayname", - common.MakeAuthAPI("profile_displayname", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { - vars, err := common.URLDecodeMapValues(mux.Vars(req)) + internal.MakeAuthAPI("profile_displayname", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { + vars, err := internal.URLDecodeMapValues(mux.Vars(req)) if err != nil { return util.ErrorResponse(err) } @@ -391,32 +391,32 @@ func Setup( // PUT requests, so we need to allow this method r0mux.Handle("/account/3pid", - common.MakeAuthAPI("account_3pid", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { + internal.MakeAuthAPI("account_3pid", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { return GetAssociated3PIDs(req, accountDB, device) }), ).Methods(http.MethodGet, http.MethodOptions) r0mux.Handle("/account/3pid", - common.MakeAuthAPI("account_3pid", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { + internal.MakeAuthAPI("account_3pid", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { return CheckAndSave3PIDAssociation(req, accountDB, device, cfg) }), ).Methods(http.MethodPost, http.MethodOptions) unstableMux.Handle("/account/3pid/delete", - common.MakeAuthAPI("account_3pid", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { + internal.MakeAuthAPI("account_3pid", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { return Forget3PID(req, accountDB) }), ).Methods(http.MethodPost, http.MethodOptions) r0mux.Handle("/{path:(?:account/3pid|register)}/email/requestToken", - common.MakeExternalAPI("account_3pid_request_token", func(req *http.Request) util.JSONResponse { + internal.MakeExternalAPI("account_3pid_request_token", func(req *http.Request) util.JSONResponse { return RequestEmailToken(req, accountDB, cfg) }), ).Methods(http.MethodPost, http.MethodOptions) // Riot logs get flooded unless this is handled r0mux.Handle("/presence/{userID}/status", - common.MakeExternalAPI("presence", func(req *http.Request) util.JSONResponse { + internal.MakeExternalAPI("presence", func(req *http.Request) util.JSONResponse { // TODO: Set presence (probably the responsibility of a presence server not clientapi) return util.JSONResponse{ Code: http.StatusOK, @@ -426,13 +426,13 @@ func Setup( ).Methods(http.MethodPut, http.MethodOptions) r0mux.Handle("/voip/turnServer", - common.MakeAuthAPI("turn_server", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { + internal.MakeAuthAPI("turn_server", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { return RequestTurnServer(req, device, cfg) }), ).Methods(http.MethodGet, http.MethodOptions) r0mux.Handle("/thirdparty/protocols", - common.MakeExternalAPI("thirdparty_protocols", func(req *http.Request) util.JSONResponse { + internal.MakeExternalAPI("thirdparty_protocols", func(req *http.Request) util.JSONResponse { // TODO: Return the third party protcols return util.JSONResponse{ Code: http.StatusOK, @@ -442,7 +442,7 @@ func Setup( ).Methods(http.MethodGet, http.MethodOptions) r0mux.Handle("/rooms/{roomID}/initialSync", - common.MakeExternalAPI("rooms_initial_sync", func(req *http.Request) util.JSONResponse { + internal.MakeExternalAPI("rooms_initial_sync", func(req *http.Request) util.JSONResponse { // TODO: Allow people to peek into rooms. return util.JSONResponse{ Code: http.StatusForbidden, @@ -452,8 +452,8 @@ func Setup( ).Methods(http.MethodGet, http.MethodOptions) r0mux.Handle("/user/{userID}/account_data/{type}", - common.MakeAuthAPI("user_account_data", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { - vars, err := common.URLDecodeMapValues(mux.Vars(req)) + internal.MakeAuthAPI("user_account_data", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { + vars, err := internal.URLDecodeMapValues(mux.Vars(req)) if err != nil { return util.ErrorResponse(err) } @@ -462,8 +462,8 @@ func Setup( ).Methods(http.MethodPut, http.MethodOptions) r0mux.Handle("/user/{userID}/rooms/{roomID}/account_data/{type}", - common.MakeAuthAPI("user_account_data", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { - vars, err := common.URLDecodeMapValues(mux.Vars(req)) + internal.MakeAuthAPI("user_account_data", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { + vars, err := internal.URLDecodeMapValues(mux.Vars(req)) if err != nil { return util.ErrorResponse(err) } @@ -472,8 +472,8 @@ func Setup( ).Methods(http.MethodPut, http.MethodOptions) r0mux.Handle("/user/{userID}/account_data/{type}", - common.MakeAuthAPI("user_account_data", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { - vars, err := common.URLDecodeMapValues(mux.Vars(req)) + internal.MakeAuthAPI("user_account_data", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { + vars, err := internal.URLDecodeMapValues(mux.Vars(req)) if err != nil { return util.ErrorResponse(err) } @@ -482,8 +482,8 @@ func Setup( ).Methods(http.MethodGet) r0mux.Handle("/user/{userID}/rooms/{roomID}/account_data/{type}", - common.MakeAuthAPI("user_account_data", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { - vars, err := common.URLDecodeMapValues(mux.Vars(req)) + internal.MakeAuthAPI("user_account_data", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { + vars, err := internal.URLDecodeMapValues(mux.Vars(req)) if err != nil { return util.ErrorResponse(err) } @@ -492,8 +492,8 @@ func Setup( ).Methods(http.MethodGet) r0mux.Handle("/rooms/{roomID}/members", - common.MakeAuthAPI("rooms_members", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { - vars, err := common.URLDecodeMapValues(mux.Vars(req)) + internal.MakeAuthAPI("rooms_members", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { + vars, err := internal.URLDecodeMapValues(mux.Vars(req)) if err != nil { return util.ErrorResponse(err) } @@ -502,8 +502,8 @@ func Setup( ).Methods(http.MethodGet, http.MethodOptions) r0mux.Handle("/rooms/{roomID}/joined_members", - common.MakeAuthAPI("rooms_members", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { - vars, err := common.URLDecodeMapValues(mux.Vars(req)) + internal.MakeAuthAPI("rooms_members", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { + vars, err := internal.URLDecodeMapValues(mux.Vars(req)) if err != nil { return util.ErrorResponse(err) } @@ -512,21 +512,21 @@ func Setup( ).Methods(http.MethodGet, http.MethodOptions) r0mux.Handle("/rooms/{roomID}/read_markers", - common.MakeExternalAPI("rooms_read_markers", func(req *http.Request) util.JSONResponse { + internal.MakeExternalAPI("rooms_read_markers", func(req *http.Request) util.JSONResponse { // TODO: return the read_markers. return util.JSONResponse{Code: http.StatusOK, JSON: struct{}{}} }), ).Methods(http.MethodPost, http.MethodOptions) r0mux.Handle("/devices", - common.MakeAuthAPI("get_devices", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { + internal.MakeAuthAPI("get_devices", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { return GetDevicesByLocalpart(req, deviceDB, device) }), ).Methods(http.MethodGet, http.MethodOptions) r0mux.Handle("/devices/{deviceID}", - common.MakeAuthAPI("get_device", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { - vars, err := common.URLDecodeMapValues(mux.Vars(req)) + internal.MakeAuthAPI("get_device", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { + vars, err := internal.URLDecodeMapValues(mux.Vars(req)) if err != nil { return util.ErrorResponse(err) } @@ -535,8 +535,8 @@ func Setup( ).Methods(http.MethodGet, http.MethodOptions) r0mux.Handle("/devices/{deviceID}", - common.MakeAuthAPI("device_data", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { - vars, err := common.URLDecodeMapValues(mux.Vars(req)) + internal.MakeAuthAPI("device_data", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { + vars, err := internal.URLDecodeMapValues(mux.Vars(req)) if err != nil { return util.ErrorResponse(err) } @@ -545,8 +545,8 @@ func Setup( ).Methods(http.MethodPut, http.MethodOptions) r0mux.Handle("/devices/{deviceID}", - common.MakeAuthAPI("delete_device", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { - vars, err := common.URLDecodeMapValues(mux.Vars(req)) + internal.MakeAuthAPI("delete_device", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { + vars, err := internal.URLDecodeMapValues(mux.Vars(req)) if err != nil { return util.ErrorResponse(err) } @@ -555,14 +555,14 @@ func Setup( ).Methods(http.MethodDelete, http.MethodOptions) r0mux.Handle("/delete_devices", - common.MakeAuthAPI("delete_devices", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { + internal.MakeAuthAPI("delete_devices", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { return DeleteDevices(req, deviceDB, device) }), ).Methods(http.MethodPost, http.MethodOptions) // Stub implementations for sytest r0mux.Handle("/events", - common.MakeExternalAPI("events", func(req *http.Request) util.JSONResponse { + internal.MakeExternalAPI("events", func(req *http.Request) util.JSONResponse { return util.JSONResponse{Code: http.StatusOK, JSON: map[string]interface{}{ "chunk": []interface{}{}, "start": "", @@ -572,7 +572,7 @@ func Setup( ).Methods(http.MethodGet, http.MethodOptions) r0mux.Handle("/initialSync", - common.MakeExternalAPI("initial_sync", func(req *http.Request) util.JSONResponse { + internal.MakeExternalAPI("initial_sync", func(req *http.Request) util.JSONResponse { return util.JSONResponse{Code: http.StatusOK, JSON: map[string]interface{}{ "end": "", }} @@ -580,8 +580,8 @@ func Setup( ).Methods(http.MethodGet, http.MethodOptions) r0mux.Handle("/user/{userId}/rooms/{roomId}/tags", - common.MakeAuthAPI("get_tags", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { - vars, err := common.URLDecodeMapValues(mux.Vars(req)) + internal.MakeAuthAPI("get_tags", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { + vars, err := internal.URLDecodeMapValues(mux.Vars(req)) if err != nil { return util.ErrorResponse(err) } @@ -590,8 +590,8 @@ func Setup( ).Methods(http.MethodGet, http.MethodOptions) r0mux.Handle("/user/{userId}/rooms/{roomId}/tags/{tag}", - common.MakeAuthAPI("put_tag", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { - vars, err := common.URLDecodeMapValues(mux.Vars(req)) + internal.MakeAuthAPI("put_tag", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { + vars, err := internal.URLDecodeMapValues(mux.Vars(req)) if err != nil { return util.ErrorResponse(err) } @@ -600,8 +600,8 @@ func Setup( ).Methods(http.MethodPut, http.MethodOptions) r0mux.Handle("/user/{userId}/rooms/{roomId}/tags/{tag}", - common.MakeAuthAPI("delete_tag", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { - vars, err := common.URLDecodeMapValues(mux.Vars(req)) + internal.MakeAuthAPI("delete_tag", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { + vars, err := internal.URLDecodeMapValues(mux.Vars(req)) if err != nil { return util.ErrorResponse(err) } @@ -610,7 +610,7 @@ func Setup( ).Methods(http.MethodDelete, http.MethodOptions) r0mux.Handle("/capabilities", - common.MakeAuthAPI("capabilities", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { + internal.MakeAuthAPI("capabilities", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { return GetCapabilities(req, rsAPI) }), ).Methods(http.MethodGet) diff --git a/clientapi/routing/sendevent.go b/clientapi/routing/sendevent.go index 7280dcd94..aa7317094 100644 --- a/clientapi/routing/sendevent.go +++ b/clientapi/routing/sendevent.go @@ -21,9 +21,9 @@ import ( "github.com/matrix-org/dendrite/clientapi/httputil" "github.com/matrix-org/dendrite/clientapi/jsonerror" "github.com/matrix-org/dendrite/clientapi/producers" - "github.com/matrix-org/dendrite/common" - "github.com/matrix-org/dendrite/common/config" - "github.com/matrix-org/dendrite/common/transactions" + "github.com/matrix-org/dendrite/internal" + "github.com/matrix-org/dendrite/internal/config" + "github.com/matrix-org/dendrite/internal/transactions" "github.com/matrix-org/dendrite/roomserver/api" "github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/util" @@ -148,14 +148,14 @@ func generateSendEvent( } var queryRes api.QueryLatestEventsAndStateResponse - e, err := common.BuildEvent(req.Context(), &builder, cfg, evTime, rsAPI, &queryRes) - if err == common.ErrRoomNoExists { + e, err := internal.BuildEvent(req.Context(), &builder, cfg, evTime, rsAPI, &queryRes) + if err == internal.ErrRoomNoExists { return nil, &util.JSONResponse{ Code: http.StatusNotFound, JSON: jsonerror.NotFound("Room does not exist"), } } else if err != nil { - util.GetLogger(req.Context()).WithError(err).Error("common.BuildEvent failed") + util.GetLogger(req.Context()).WithError(err).Error("internal.BuildEvent failed") resErr := jsonerror.InternalServerError() return nil, &resErr } diff --git a/clientapi/routing/threepid.go b/clientapi/routing/threepid.go index fed9ae32e..49a9f3047 100644 --- a/clientapi/routing/threepid.go +++ b/clientapi/routing/threepid.go @@ -22,7 +22,7 @@ import ( "github.com/matrix-org/dendrite/clientapi/httputil" "github.com/matrix-org/dendrite/clientapi/jsonerror" "github.com/matrix-org/dendrite/clientapi/threepid" - "github.com/matrix-org/dendrite/common/config" + "github.com/matrix-org/dendrite/internal/config" "github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/util" diff --git a/clientapi/routing/voip.go b/clientapi/routing/voip.go index c1fd741c9..212d9b0a4 100644 --- a/clientapi/routing/voip.go +++ b/clientapi/routing/voip.go @@ -24,7 +24,7 @@ import ( "github.com/matrix-org/dendrite/clientapi/auth/authtypes" "github.com/matrix-org/dendrite/clientapi/jsonerror" - "github.com/matrix-org/dendrite/common/config" + "github.com/matrix-org/dendrite/internal/config" "github.com/matrix-org/gomatrix" "github.com/matrix-org/util" ) diff --git a/clientapi/threepid/invites.go b/clientapi/threepid/invites.go index 5e7e4f2b4..8fed99565 100644 --- a/clientapi/threepid/invites.go +++ b/clientapi/threepid/invites.go @@ -27,8 +27,8 @@ import ( "github.com/matrix-org/dendrite/clientapi/auth/authtypes" "github.com/matrix-org/dendrite/clientapi/auth/storage/accounts" "github.com/matrix-org/dendrite/clientapi/producers" - "github.com/matrix-org/dendrite/common" - "github.com/matrix-org/dendrite/common/config" + "github.com/matrix-org/dendrite/internal" + "github.com/matrix-org/dendrite/internal/config" "github.com/matrix-org/dendrite/roomserver/api" "github.com/matrix-org/gomatrixserverlib" ) @@ -354,7 +354,7 @@ func emit3PIDInviteEvent( } queryRes := api.QueryLatestEventsAndStateResponse{} - event, err := common.BuildEvent(ctx, builder, cfg, evTime, rsAPI, &queryRes) + event, err := internal.BuildEvent(ctx, builder, cfg, evTime, rsAPI, &queryRes) if err != nil { return err } diff --git a/clientapi/threepid/threepid.go b/clientapi/threepid/threepid.go index a7f26c295..bffe31adc 100644 --- a/clientapi/threepid/threepid.go +++ b/clientapi/threepid/threepid.go @@ -24,7 +24,7 @@ import ( "strconv" "strings" - "github.com/matrix-org/dendrite/common/config" + "github.com/matrix-org/dendrite/internal/config" ) // EmailAssociationRequest represents the request defined at https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-register-email-requesttoken diff --git a/cmd/dendrite-appservice-server/main.go b/cmd/dendrite-appservice-server/main.go index faf9ade31..a508be3b4 100644 --- a/cmd/dendrite-appservice-server/main.go +++ b/cmd/dendrite-appservice-server/main.go @@ -16,8 +16,8 @@ package main import ( "github.com/matrix-org/dendrite/appservice" - "github.com/matrix-org/dendrite/common/basecomponent" - "github.com/matrix-org/dendrite/common/transactions" + "github.com/matrix-org/dendrite/internal/basecomponent" + "github.com/matrix-org/dendrite/internal/transactions" ) func main() { diff --git a/cmd/dendrite-client-api-server/main.go b/cmd/dendrite-client-api-server/main.go index d4ab9e42f..0815be799 100644 --- a/cmd/dendrite-client-api-server/main.go +++ b/cmd/dendrite-client-api-server/main.go @@ -16,11 +16,11 @@ package main import ( "github.com/matrix-org/dendrite/clientapi" - "github.com/matrix-org/dendrite/common/basecomponent" - "github.com/matrix-org/dendrite/common/keydb" - "github.com/matrix-org/dendrite/common/transactions" "github.com/matrix-org/dendrite/eduserver" "github.com/matrix-org/dendrite/eduserver/cache" + "github.com/matrix-org/dendrite/internal/basecomponent" + "github.com/matrix-org/dendrite/internal/keydb" + "github.com/matrix-org/dendrite/internal/transactions" ) func main() { diff --git a/cmd/dendrite-demo-libp2p/main.go b/cmd/dendrite-demo-libp2p/main.go index 0ff610a5b..a04a28e06 100644 --- a/cmd/dendrite-demo-libp2p/main.go +++ b/cmd/dendrite-demo-libp2p/main.go @@ -32,13 +32,13 @@ import ( "github.com/matrix-org/dendrite/clientapi" "github.com/matrix-org/dendrite/clientapi/producers" "github.com/matrix-org/dendrite/cmd/dendrite-demo-libp2p/storage" - "github.com/matrix-org/dendrite/common" - "github.com/matrix-org/dendrite/common/config" - "github.com/matrix-org/dendrite/common/keydb" - "github.com/matrix-org/dendrite/common/transactions" "github.com/matrix-org/dendrite/eduserver" "github.com/matrix-org/dendrite/federationapi" "github.com/matrix-org/dendrite/federationsender" + "github.com/matrix-org/dendrite/internal" + "github.com/matrix-org/dendrite/internal/config" + "github.com/matrix-org/dendrite/internal/keydb" + "github.com/matrix-org/dendrite/internal/transactions" "github.com/matrix-org/dendrite/mediaapi" "github.com/matrix-org/dendrite/publicroomsapi" "github.com/matrix-org/dendrite/roomserver" @@ -178,7 +178,7 @@ func main() { publicroomsapi.SetupPublicRoomsAPIComponent(&base.Base, deviceDB, publicRoomsDB, rsAPI, federation, nil) // Check this later syncapi.SetupSyncAPIComponent(&base.Base, deviceDB, accountDB, rsAPI, federation, &cfg) - httpHandler := common.WrapHandlerInCORS(base.Base.APIMux) + httpHandler := internal.WrapHandlerInCORS(base.Base.APIMux) // Set up the API endpoints we handle. /metrics is for prometheus, and is // not wrapped by CORS, while everything else is diff --git a/cmd/dendrite-demo-libp2p/mdnslistener.go b/cmd/dendrite-demo-libp2p/mdnslistener.go index 3fefbec2c..c05c94d59 100644 --- a/cmd/dendrite-demo-libp2p/mdnslistener.go +++ b/cmd/dendrite-demo-libp2p/mdnslistener.go @@ -21,7 +21,7 @@ import ( "github.com/libp2p/go-libp2p-core/host" "github.com/libp2p/go-libp2p-core/peer" - "github.com/matrix-org/dendrite/common/keydb" + "github.com/matrix-org/dendrite/internal/keydb" "github.com/matrix-org/gomatrixserverlib" ) diff --git a/cmd/dendrite-demo-libp2p/p2pdendrite.go b/cmd/dendrite-demo-libp2p/p2pdendrite.go index 831b5d7f4..b7c5c66b0 100644 --- a/cmd/dendrite-demo-libp2p/p2pdendrite.go +++ b/cmd/dendrite-demo-libp2p/p2pdendrite.go @@ -22,7 +22,7 @@ import ( pstore "github.com/libp2p/go-libp2p-core/peerstore" record "github.com/libp2p/go-libp2p-record" - "github.com/matrix-org/dendrite/common/basecomponent" + "github.com/matrix-org/dendrite/internal/basecomponent" "github.com/libp2p/go-libp2p" circuit "github.com/libp2p/go-libp2p-circuit" @@ -34,7 +34,7 @@ import ( pubsub "github.com/libp2p/go-libp2p-pubsub" "github.com/matrix-org/gomatrixserverlib" - "github.com/matrix-org/dendrite/common/config" + "github.com/matrix-org/dendrite/internal/config" ) // P2PDendrite is a Peer-to-Peer variant of BaseDendrite. diff --git a/cmd/dendrite-edu-server/main.go b/cmd/dendrite-edu-server/main.go index 98b05e649..66e17e577 100644 --- a/cmd/dendrite-edu-server/main.go +++ b/cmd/dendrite-edu-server/main.go @@ -15,9 +15,9 @@ package main import ( _ "net/http/pprof" - "github.com/matrix-org/dendrite/common/basecomponent" "github.com/matrix-org/dendrite/eduserver" "github.com/matrix-org/dendrite/eduserver/cache" + "github.com/matrix-org/dendrite/internal/basecomponent" "github.com/sirupsen/logrus" ) diff --git a/cmd/dendrite-federation-api-server/main.go b/cmd/dendrite-federation-api-server/main.go index b37570201..be97bc9a0 100644 --- a/cmd/dendrite-federation-api-server/main.go +++ b/cmd/dendrite-federation-api-server/main.go @@ -16,11 +16,11 @@ package main import ( "github.com/matrix-org/dendrite/clientapi/producers" - "github.com/matrix-org/dendrite/common/basecomponent" - "github.com/matrix-org/dendrite/common/keydb" "github.com/matrix-org/dendrite/eduserver" "github.com/matrix-org/dendrite/eduserver/cache" "github.com/matrix-org/dendrite/federationapi" + "github.com/matrix-org/dendrite/internal/basecomponent" + "github.com/matrix-org/dendrite/internal/keydb" ) func main() { diff --git a/cmd/dendrite-federation-sender-server/main.go b/cmd/dendrite-federation-sender-server/main.go index c9bf6688f..b6af8deb7 100644 --- a/cmd/dendrite-federation-sender-server/main.go +++ b/cmd/dendrite-federation-sender-server/main.go @@ -15,9 +15,9 @@ package main import ( - "github.com/matrix-org/dendrite/common/basecomponent" - "github.com/matrix-org/dendrite/common/keydb" "github.com/matrix-org/dendrite/federationsender" + "github.com/matrix-org/dendrite/internal/basecomponent" + "github.com/matrix-org/dendrite/internal/keydb" ) func main() { diff --git a/cmd/dendrite-key-server/main.go b/cmd/dendrite-key-server/main.go index aca666fad..17fee2c64 100644 --- a/cmd/dendrite-key-server/main.go +++ b/cmd/dendrite-key-server/main.go @@ -15,7 +15,7 @@ package main import ( - "github.com/matrix-org/dendrite/common/basecomponent" + "github.com/matrix-org/dendrite/internal/basecomponent" "github.com/matrix-org/dendrite/keyserver" ) diff --git a/cmd/dendrite-media-api-server/main.go b/cmd/dendrite-media-api-server/main.go index cfb32173d..1a51717a7 100644 --- a/cmd/dendrite-media-api-server/main.go +++ b/cmd/dendrite-media-api-server/main.go @@ -15,7 +15,7 @@ package main import ( - "github.com/matrix-org/dendrite/common/basecomponent" + "github.com/matrix-org/dendrite/internal/basecomponent" "github.com/matrix-org/dendrite/mediaapi" ) diff --git a/cmd/dendrite-monolith-server/main.go b/cmd/dendrite-monolith-server/main.go index 23959152e..6d3a479ac 100644 --- a/cmd/dendrite-monolith-server/main.go +++ b/cmd/dendrite-monolith-server/main.go @@ -21,14 +21,14 @@ import ( "github.com/matrix-org/dendrite/appservice" "github.com/matrix-org/dendrite/clientapi" "github.com/matrix-org/dendrite/clientapi/producers" - "github.com/matrix-org/dendrite/common" - "github.com/matrix-org/dendrite/common/basecomponent" - "github.com/matrix-org/dendrite/common/keydb" - "github.com/matrix-org/dendrite/common/transactions" "github.com/matrix-org/dendrite/eduserver" "github.com/matrix-org/dendrite/eduserver/cache" "github.com/matrix-org/dendrite/federationapi" "github.com/matrix-org/dendrite/federationsender" + "github.com/matrix-org/dendrite/internal" + "github.com/matrix-org/dendrite/internal/basecomponent" + "github.com/matrix-org/dendrite/internal/keydb" + "github.com/matrix-org/dendrite/internal/transactions" "github.com/matrix-org/dendrite/keyserver" "github.com/matrix-org/dendrite/mediaapi" "github.com/matrix-org/dendrite/publicroomsapi" @@ -91,12 +91,12 @@ func main() { publicroomsapi.SetupPublicRoomsAPIComponent(base, deviceDB, publicRoomsDB, rsAPI, federation, nil) syncapi.SetupSyncAPIComponent(base, deviceDB, accountDB, rsAPI, federation, cfg) - httpHandler := common.WrapHandlerInCORS(base.APIMux) + httpHandler := internal.WrapHandlerInCORS(base.APIMux) // Set up the API endpoints we handle. /metrics is for prometheus, and is // not wrapped by CORS, while everything else is if cfg.Metrics.Enabled { - http.Handle("/metrics", common.WrapHandlerInBasicAuth(promhttp.Handler(), cfg.Metrics.BasicAuth)) + http.Handle("/metrics", internal.WrapHandlerInBasicAuth(promhttp.Handler(), cfg.Metrics.BasicAuth)) } http.Handle("/", httpHandler) diff --git a/cmd/dendrite-public-rooms-api-server/main.go b/cmd/dendrite-public-rooms-api-server/main.go index 0eb2fcb57..cf9d09c11 100644 --- a/cmd/dendrite-public-rooms-api-server/main.go +++ b/cmd/dendrite-public-rooms-api-server/main.go @@ -15,7 +15,7 @@ package main import ( - "github.com/matrix-org/dendrite/common/basecomponent" + "github.com/matrix-org/dendrite/internal/basecomponent" "github.com/matrix-org/dendrite/publicroomsapi" "github.com/matrix-org/dendrite/publicroomsapi/storage" "github.com/sirupsen/logrus" diff --git a/cmd/dendrite-room-server/main.go b/cmd/dendrite-room-server/main.go index 4d450bd47..31cf4a042 100644 --- a/cmd/dendrite-room-server/main.go +++ b/cmd/dendrite-room-server/main.go @@ -15,8 +15,8 @@ package main import ( - "github.com/matrix-org/dendrite/common/basecomponent" - "github.com/matrix-org/dendrite/common/keydb" + "github.com/matrix-org/dendrite/internal/basecomponent" + "github.com/matrix-org/dendrite/internal/keydb" "github.com/matrix-org/dendrite/roomserver" ) diff --git a/cmd/dendrite-sync-api-server/main.go b/cmd/dendrite-sync-api-server/main.go index 7aadd6a7b..5a1a80dfd 100644 --- a/cmd/dendrite-sync-api-server/main.go +++ b/cmd/dendrite-sync-api-server/main.go @@ -15,7 +15,7 @@ package main import ( - "github.com/matrix-org/dendrite/common/basecomponent" + "github.com/matrix-org/dendrite/internal/basecomponent" "github.com/matrix-org/dendrite/syncapi" ) diff --git a/cmd/dendritejs/main.go b/cmd/dendritejs/main.go index 5bdf18efa..2609c74cd 100644 --- a/cmd/dendritejs/main.go +++ b/cmd/dendritejs/main.go @@ -25,14 +25,14 @@ import ( "github.com/matrix-org/dendrite/appservice" "github.com/matrix-org/dendrite/clientapi" "github.com/matrix-org/dendrite/clientapi/producers" - "github.com/matrix-org/dendrite/common" - "github.com/matrix-org/dendrite/common/basecomponent" - "github.com/matrix-org/dendrite/common/config" - "github.com/matrix-org/dendrite/common/transactions" "github.com/matrix-org/dendrite/eduserver" "github.com/matrix-org/dendrite/eduserver/cache" "github.com/matrix-org/dendrite/federationapi" "github.com/matrix-org/dendrite/federationsender" + "github.com/matrix-org/dendrite/internal" + "github.com/matrix-org/dendrite/internal/basecomponent" + "github.com/matrix-org/dendrite/internal/config" + "github.com/matrix-org/dendrite/internal/transactions" "github.com/matrix-org/dendrite/mediaapi" "github.com/matrix-org/dendrite/publicroomsapi" "github.com/matrix-org/dendrite/publicroomsapi/storage" @@ -227,7 +227,7 @@ func main() { publicroomsapi.SetupPublicRoomsAPIComponent(base, deviceDB, publicRoomsDB, rsAPI, federation, p2pPublicRoomProvider) syncapi.SetupSyncAPIComponent(base, deviceDB, accountDB, rsAPI, federation, cfg) - httpHandler := common.WrapHandlerInCORS(base.APIMux) + httpHandler := internal.WrapHandlerInCORS(base.APIMux) http.Handle("/", httpHandler) diff --git a/cmd/generate-keys/main.go b/cmd/generate-keys/main.go index b807c2673..ceeca5672 100644 --- a/cmd/generate-keys/main.go +++ b/cmd/generate-keys/main.go @@ -20,7 +20,7 @@ import ( "log" "os" - "github.com/matrix-org/dendrite/common/test" + "github.com/matrix-org/dendrite/internal/test" ) const usage = `Usage: %s diff --git a/cmd/mediaapi-integration-tests/main.go b/cmd/mediaapi-integration-tests/main.go index fd6982fd3..e6ce14d28 100644 --- a/cmd/mediaapi-integration-tests/main.go +++ b/cmd/mediaapi-integration-tests/main.go @@ -24,7 +24,7 @@ import ( "path/filepath" "time" - "github.com/matrix-org/dendrite/common/test" + "github.com/matrix-org/dendrite/internal/test" "github.com/matrix-org/gomatrixserverlib" "gopkg.in/yaml.v2" ) diff --git a/cmd/roomserver-integration-tests/main.go b/cmd/roomserver-integration-tests/main.go index 7126405e5..126053bac 100644 --- a/cmd/roomserver-integration-tests/main.go +++ b/cmd/roomserver-integration-tests/main.go @@ -28,8 +28,8 @@ import ( "net/http" - "github.com/matrix-org/dendrite/common/caching" - "github.com/matrix-org/dendrite/common/test" + "github.com/matrix-org/dendrite/internal/caching" + "github.com/matrix-org/dendrite/internal/test" "github.com/matrix-org/dendrite/roomserver/api" "github.com/matrix-org/gomatrixserverlib" ) diff --git a/cmd/syncserver-integration-tests/main.go b/cmd/syncserver-integration-tests/main.go index d14e854c3..cfe8cc165 100644 --- a/cmd/syncserver-integration-tests/main.go +++ b/cmd/syncserver-integration-tests/main.go @@ -24,8 +24,8 @@ import ( "path/filepath" "time" - "github.com/matrix-org/dendrite/common/config" - "github.com/matrix-org/dendrite/common/test" + "github.com/matrix-org/dendrite/internal/config" + "github.com/matrix-org/dendrite/internal/test" "github.com/matrix-org/dendrite/roomserver/api" "github.com/matrix-org/gomatrixserverlib" ) diff --git a/eduserver/api/input.go b/eduserver/api/input.go index be2d4c56a..999a5b41a 100644 --- a/eduserver/api/input.go +++ b/eduserver/api/input.go @@ -18,7 +18,7 @@ import ( "errors" "net/http" - commonHTTP "github.com/matrix-org/dendrite/common/http" + internalHTTP "github.com/matrix-org/dendrite/internal/http" "github.com/matrix-org/gomatrixserverlib" opentracing "github.com/opentracing/opentracing-go" ) @@ -80,5 +80,5 @@ func (h *httpEDUServerInputAPI) InputTypingEvent( defer span.Finish() apiURL := h.eduServerURL + EDUServerInputTypingEventPath - return commonHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response) + return internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response) } diff --git a/eduserver/cache/cache_test.go b/eduserver/cache/cache_test.go index 8a1b6f797..d1b2f8bd5 100644 --- a/eduserver/cache/cache_test.go +++ b/eduserver/cache/cache_test.go @@ -16,7 +16,7 @@ import ( "testing" "time" - "github.com/matrix-org/dendrite/common/test" + "github.com/matrix-org/dendrite/internal/test" ) func TestEDUCache(t *testing.T) { diff --git a/eduserver/eduserver.go b/eduserver/eduserver.go index 2a209364a..cba60b8ea 100644 --- a/eduserver/eduserver.go +++ b/eduserver/eduserver.go @@ -15,10 +15,10 @@ package eduserver import ( "net/http" - "github.com/matrix-org/dendrite/common/basecomponent" "github.com/matrix-org/dendrite/eduserver/api" "github.com/matrix-org/dendrite/eduserver/cache" "github.com/matrix-org/dendrite/eduserver/input" + "github.com/matrix-org/dendrite/internal/basecomponent" ) // SetupEDUServerComponent sets up and registers HTTP handlers for the diff --git a/eduserver/input/input.go b/eduserver/input/input.go index 6a4a4bb4e..50837154a 100644 --- a/eduserver/input/input.go +++ b/eduserver/input/input.go @@ -19,9 +19,9 @@ import ( "time" "github.com/Shopify/sarama" - "github.com/matrix-org/dendrite/common" "github.com/matrix-org/dendrite/eduserver/api" "github.com/matrix-org/dendrite/eduserver/cache" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/util" ) @@ -92,7 +92,7 @@ func (t *EDUServerInputAPI) sendEvent(ite *api.InputTypingEvent) error { // SetupHTTP adds the EDUServerInputAPI handlers to the http.ServeMux. func (t *EDUServerInputAPI) SetupHTTP(servMux *http.ServeMux) { servMux.Handle(api.EDUServerInputTypingEventPath, - common.MakeInternalAPI("inputTypingEvents", func(req *http.Request) util.JSONResponse { + internal.MakeInternalAPI("inputTypingEvents", func(req *http.Request) util.JSONResponse { var request api.InputTypingEventRequest var response api.InputTypingEventResponse if err := json.NewDecoder(req.Body).Decode(&request); err != nil { diff --git a/federationapi/federationapi.go b/federationapi/federationapi.go index d458b8537..9e3411403 100644 --- a/federationapi/federationapi.go +++ b/federationapi/federationapi.go @@ -18,8 +18,8 @@ import ( appserviceAPI "github.com/matrix-org/dendrite/appservice/api" "github.com/matrix-org/dendrite/clientapi/auth/storage/accounts" "github.com/matrix-org/dendrite/clientapi/auth/storage/devices" - "github.com/matrix-org/dendrite/common/basecomponent" federationSenderAPI "github.com/matrix-org/dendrite/federationsender/api" + "github.com/matrix-org/dendrite/internal/basecomponent" roomserverAPI "github.com/matrix-org/dendrite/roomserver/api" // TODO: Are we really wanting to pull in the producer from clientapi diff --git a/federationapi/routing/backfill.go b/federationapi/routing/backfill.go index 0d3893de3..10bc62630 100644 --- a/federationapi/routing/backfill.go +++ b/federationapi/routing/backfill.go @@ -22,7 +22,7 @@ import ( "time" "github.com/matrix-org/dendrite/clientapi/jsonerror" - "github.com/matrix-org/dendrite/common/config" + "github.com/matrix-org/dendrite/internal/config" "github.com/matrix-org/dendrite/roomserver/api" "github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/util" diff --git a/federationapi/routing/invite.go b/federationapi/routing/invite.go index 064abe7e9..05efe5872 100644 --- a/federationapi/routing/invite.go +++ b/federationapi/routing/invite.go @@ -21,7 +21,7 @@ import ( "github.com/matrix-org/dendrite/clientapi/jsonerror" "github.com/matrix-org/dendrite/clientapi/producers" - "github.com/matrix-org/dendrite/common/config" + "github.com/matrix-org/dendrite/internal/config" roomserverVersion "github.com/matrix-org/dendrite/roomserver/version" "github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/util" diff --git a/federationapi/routing/join.go b/federationapi/routing/join.go index 3533bbba8..617a6cab0 100644 --- a/federationapi/routing/join.go +++ b/federationapi/routing/join.go @@ -22,8 +22,8 @@ import ( "github.com/matrix-org/dendrite/clientapi/jsonerror" "github.com/matrix-org/dendrite/clientapi/producers" - "github.com/matrix-org/dendrite/common" - "github.com/matrix-org/dendrite/common/config" + "github.com/matrix-org/dendrite/internal" + "github.com/matrix-org/dendrite/internal/config" "github.com/matrix-org/dendrite/roomserver/api" "github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/util" @@ -96,14 +96,14 @@ func MakeJoin( queryRes := api.QueryLatestEventsAndStateResponse{ RoomVersion: verRes.RoomVersion, } - event, err := common.BuildEvent(httpReq.Context(), &builder, cfg, time.Now(), rsAPI, &queryRes) - if err == common.ErrRoomNoExists { + event, err := internal.BuildEvent(httpReq.Context(), &builder, cfg, time.Now(), rsAPI, &queryRes) + if err == internal.ErrRoomNoExists { return util.JSONResponse{ Code: http.StatusNotFound, JSON: jsonerror.NotFound("Room does not exist"), } } else if err != nil { - util.GetLogger(httpReq.Context()).WithError(err).Error("common.BuildEvent failed") + util.GetLogger(httpReq.Context()).WithError(err).Error("internal.BuildEvent failed") return jsonerror.InternalServerError() } diff --git a/federationapi/routing/keys.go b/federationapi/routing/keys.go index 3eb88567d..79cc1f82c 100644 --- a/federationapi/routing/keys.go +++ b/federationapi/routing/keys.go @@ -19,7 +19,7 @@ import ( "net/http" "time" - "github.com/matrix-org/dendrite/common/config" + "github.com/matrix-org/dendrite/internal/config" "github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/util" "golang.org/x/crypto/ed25519" diff --git a/federationapi/routing/leave.go b/federationapi/routing/leave.go index bab3fd0b5..bd226d7ee 100644 --- a/federationapi/routing/leave.go +++ b/federationapi/routing/leave.go @@ -18,8 +18,8 @@ import ( "github.com/matrix-org/dendrite/clientapi/jsonerror" "github.com/matrix-org/dendrite/clientapi/producers" - "github.com/matrix-org/dendrite/common" - "github.com/matrix-org/dendrite/common/config" + "github.com/matrix-org/dendrite/internal" + "github.com/matrix-org/dendrite/internal/config" "github.com/matrix-org/dendrite/roomserver/api" "github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/util" @@ -70,14 +70,14 @@ func MakeLeave( } var queryRes api.QueryLatestEventsAndStateResponse - event, err := common.BuildEvent(httpReq.Context(), &builder, cfg, time.Now(), rsAPI, &queryRes) - if err == common.ErrRoomNoExists { + event, err := internal.BuildEvent(httpReq.Context(), &builder, cfg, time.Now(), rsAPI, &queryRes) + if err == internal.ErrRoomNoExists { return util.JSONResponse{ Code: http.StatusNotFound, JSON: jsonerror.NotFound("Room does not exist"), } } else if err != nil { - util.GetLogger(httpReq.Context()).WithError(err).Error("common.BuildEvent failed") + util.GetLogger(httpReq.Context()).WithError(err).Error("internal.BuildEvent failed") return jsonerror.InternalServerError() } diff --git a/federationapi/routing/profile.go b/federationapi/routing/profile.go index 9a81c1b33..832849845 100644 --- a/federationapi/routing/profile.go +++ b/federationapi/routing/profile.go @@ -21,8 +21,8 @@ import ( appserviceAPI "github.com/matrix-org/dendrite/appservice/api" "github.com/matrix-org/dendrite/clientapi/auth/storage/accounts" "github.com/matrix-org/dendrite/clientapi/jsonerror" - "github.com/matrix-org/dendrite/common" - "github.com/matrix-org/dendrite/common/config" + "github.com/matrix-org/dendrite/internal" + "github.com/matrix-org/dendrite/internal/config" "github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/util" ) @@ -72,11 +72,11 @@ func GetProfile( if field != "" { switch field { case "displayname": - res = common.DisplayName{ + res = internal.DisplayName{ DisplayName: profile.DisplayName, } case "avatar_url": - res = common.AvatarURL{ + res = internal.AvatarURL{ AvatarURL: profile.AvatarURL, } default: @@ -84,7 +84,7 @@ func GetProfile( res = jsonerror.InvalidArgumentValue("The request body did not contain an allowed value of argument 'field'. Allowed values are either: 'avatar_url', 'displayname'.") } } else { - res = common.ProfileResponse{ + res = internal.ProfileResponse{ AvatarURL: profile.AvatarURL, DisplayName: profile.DisplayName, } diff --git a/federationapi/routing/query.go b/federationapi/routing/query.go index c58690c63..39fd6d2ee 100644 --- a/federationapi/routing/query.go +++ b/federationapi/routing/query.go @@ -19,8 +19,8 @@ import ( "net/http" "github.com/matrix-org/dendrite/clientapi/jsonerror" - "github.com/matrix-org/dendrite/common/config" federationSenderAPI "github.com/matrix-org/dendrite/federationsender/api" + "github.com/matrix-org/dendrite/internal/config" roomserverAPI "github.com/matrix-org/dendrite/roomserver/api" "github.com/matrix-org/gomatrix" "github.com/matrix-org/gomatrixserverlib" diff --git a/federationapi/routing/routing.go b/federationapi/routing/routing.go index 67f3a957c..c368c16c4 100644 --- a/federationapi/routing/routing.go +++ b/federationapi/routing/routing.go @@ -22,9 +22,9 @@ import ( "github.com/matrix-org/dendrite/clientapi/auth/storage/accounts" "github.com/matrix-org/dendrite/clientapi/auth/storage/devices" "github.com/matrix-org/dendrite/clientapi/producers" - "github.com/matrix-org/dendrite/common" - "github.com/matrix-org/dendrite/common/config" federationSenderAPI "github.com/matrix-org/dendrite/federationsender/api" + "github.com/matrix-org/dendrite/internal" + "github.com/matrix-org/dendrite/internal/config" roomserverAPI "github.com/matrix-org/dendrite/roomserver/api" "github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/util" @@ -58,7 +58,7 @@ func Setup( v1fedmux := apiMux.PathPrefix(pathPrefixV1Federation).Subrouter() v2fedmux := apiMux.PathPrefix(pathPrefixV2Federation).Subrouter() - localKeys := common.MakeExternalAPI("localkeys", func(req *http.Request) util.JSONResponse { + localKeys := internal.MakeExternalAPI("localkeys", func(req *http.Request) util.JSONResponse { return LocalKeys(cfg) }) @@ -70,10 +70,10 @@ func Setup( v2keysmux.Handle("/server/", localKeys).Methods(http.MethodGet) v2keysmux.Handle("/server", localKeys).Methods(http.MethodGet) - v1fedmux.Handle("/send/{txnID}", common.MakeFedAPI( + v1fedmux.Handle("/send/{txnID}", internal.MakeFedAPI( "federation_send", cfg.Matrix.ServerName, keys, func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest) util.JSONResponse { - vars, err := common.URLDecodeMapValues(mux.Vars(httpReq)) + vars, err := internal.URLDecodeMapValues(mux.Vars(httpReq)) if err != nil { return util.ErrorResponse(err) } @@ -84,10 +84,10 @@ func Setup( }, )).Methods(http.MethodPut, http.MethodOptions) - v2fedmux.Handle("/invite/{roomID}/{eventID}", common.MakeFedAPI( + v2fedmux.Handle("/invite/{roomID}/{eventID}", internal.MakeFedAPI( "federation_invite", cfg.Matrix.ServerName, keys, func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest) util.JSONResponse { - vars, err := common.URLDecodeMapValues(mux.Vars(httpReq)) + vars, err := internal.URLDecodeMapValues(mux.Vars(httpReq)) if err != nil { return util.ErrorResponse(err) } @@ -98,16 +98,16 @@ func Setup( }, )).Methods(http.MethodPut, http.MethodOptions) - v1fedmux.Handle("/3pid/onbind", common.MakeExternalAPI("3pid_onbind", + v1fedmux.Handle("/3pid/onbind", internal.MakeExternalAPI("3pid_onbind", func(req *http.Request) util.JSONResponse { return CreateInvitesFrom3PIDInvites(req, rsAPI, asAPI, cfg, producer, federation, accountDB) }, )).Methods(http.MethodPost, http.MethodOptions) - v1fedmux.Handle("/exchange_third_party_invite/{roomID}", common.MakeFedAPI( + v1fedmux.Handle("/exchange_third_party_invite/{roomID}", internal.MakeFedAPI( "exchange_third_party_invite", cfg.Matrix.ServerName, keys, func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest) util.JSONResponse { - vars, err := common.URLDecodeMapValues(mux.Vars(httpReq)) + vars, err := internal.URLDecodeMapValues(mux.Vars(httpReq)) if err != nil { return util.ErrorResponse(err) } @@ -117,10 +117,10 @@ func Setup( }, )).Methods(http.MethodPut, http.MethodOptions) - v1fedmux.Handle("/event/{eventID}", common.MakeFedAPI( + v1fedmux.Handle("/event/{eventID}", internal.MakeFedAPI( "federation_get_event", cfg.Matrix.ServerName, keys, func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest) util.JSONResponse { - vars, err := common.URLDecodeMapValues(mux.Vars(httpReq)) + vars, err := internal.URLDecodeMapValues(mux.Vars(httpReq)) if err != nil { return util.ErrorResponse(err) } @@ -130,10 +130,10 @@ func Setup( }, )).Methods(http.MethodGet) - v1fedmux.Handle("/state/{roomID}", common.MakeFedAPI( + v1fedmux.Handle("/state/{roomID}", internal.MakeFedAPI( "federation_get_state", cfg.Matrix.ServerName, keys, func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest) util.JSONResponse { - vars, err := common.URLDecodeMapValues(mux.Vars(httpReq)) + vars, err := internal.URLDecodeMapValues(mux.Vars(httpReq)) if err != nil { return util.ErrorResponse(err) } @@ -143,10 +143,10 @@ func Setup( }, )).Methods(http.MethodGet) - v1fedmux.Handle("/state_ids/{roomID}", common.MakeFedAPI( + v1fedmux.Handle("/state_ids/{roomID}", internal.MakeFedAPI( "federation_get_state_ids", cfg.Matrix.ServerName, keys, func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest) util.JSONResponse { - vars, err := common.URLDecodeMapValues(mux.Vars(httpReq)) + vars, err := internal.URLDecodeMapValues(mux.Vars(httpReq)) if err != nil { return util.ErrorResponse(err) } @@ -156,7 +156,7 @@ func Setup( }, )).Methods(http.MethodGet) - v1fedmux.Handle("/event_auth/{roomID}/{eventID}", common.MakeFedAPI( + v1fedmux.Handle("/event_auth/{roomID}/{eventID}", internal.MakeFedAPI( "federation_get_event_auth", cfg.Matrix.ServerName, keys, func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest) util.JSONResponse { vars := mux.Vars(httpReq) @@ -166,7 +166,7 @@ func Setup( }, )).Methods(http.MethodGet) - v1fedmux.Handle("/query/directory", common.MakeFedAPI( + v1fedmux.Handle("/query/directory", internal.MakeFedAPI( "federation_query_room_alias", cfg.Matrix.ServerName, keys, func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest) util.JSONResponse { return RoomAliasToID( @@ -175,7 +175,7 @@ func Setup( }, )).Methods(http.MethodGet) - v1fedmux.Handle("/query/profile", common.MakeFedAPI( + v1fedmux.Handle("/query/profile", internal.MakeFedAPI( "federation_query_profile", cfg.Matrix.ServerName, keys, func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest) util.JSONResponse { return GetProfile( @@ -184,10 +184,10 @@ func Setup( }, )).Methods(http.MethodGet) - v1fedmux.Handle("/user/devices/{userID}", common.MakeFedAPI( + v1fedmux.Handle("/user/devices/{userID}", internal.MakeFedAPI( "federation_user_devices", cfg.Matrix.ServerName, keys, func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest) util.JSONResponse { - vars, err := common.URLDecodeMapValues(mux.Vars(httpReq)) + vars, err := internal.URLDecodeMapValues(mux.Vars(httpReq)) if err != nil { return util.ErrorResponse(err) } @@ -197,10 +197,10 @@ func Setup( }, )).Methods(http.MethodGet) - v1fedmux.Handle("/make_join/{roomID}/{eventID}", common.MakeFedAPI( + v1fedmux.Handle("/make_join/{roomID}/{eventID}", internal.MakeFedAPI( "federation_make_join", cfg.Matrix.ServerName, keys, func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest) util.JSONResponse { - vars, err := common.URLDecodeMapValues(mux.Vars(httpReq)) + vars, err := internal.URLDecodeMapValues(mux.Vars(httpReq)) if err != nil { return util.ErrorResponse(err) } @@ -226,10 +226,10 @@ func Setup( }, )).Methods(http.MethodGet) - v1fedmux.Handle("/send_join/{roomID}/{eventID}", common.MakeFedAPI( + v1fedmux.Handle("/send_join/{roomID}/{eventID}", internal.MakeFedAPI( "federation_send_join", cfg.Matrix.ServerName, keys, func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest) util.JSONResponse { - vars, err := common.URLDecodeMapValues(mux.Vars(httpReq)) + vars, err := internal.URLDecodeMapValues(mux.Vars(httpReq)) if err != nil { return util.ErrorResponse(err) } @@ -248,10 +248,10 @@ func Setup( }, )).Methods(http.MethodPut) - v2fedmux.Handle("/send_join/{roomID}/{eventID}", common.MakeFedAPI( + v2fedmux.Handle("/send_join/{roomID}/{eventID}", internal.MakeFedAPI( "federation_send_join", cfg.Matrix.ServerName, keys, func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest) util.JSONResponse { - vars, err := common.URLDecodeMapValues(mux.Vars(httpReq)) + vars, err := internal.URLDecodeMapValues(mux.Vars(httpReq)) if err != nil { return util.ErrorResponse(err) } @@ -263,10 +263,10 @@ func Setup( }, )).Methods(http.MethodPut) - v1fedmux.Handle("/make_leave/{roomID}/{eventID}", common.MakeFedAPI( + v1fedmux.Handle("/make_leave/{roomID}/{eventID}", internal.MakeFedAPI( "federation_make_leave", cfg.Matrix.ServerName, keys, func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest) util.JSONResponse { - vars, err := common.URLDecodeMapValues(mux.Vars(httpReq)) + vars, err := internal.URLDecodeMapValues(mux.Vars(httpReq)) if err != nil { return util.ErrorResponse(err) } @@ -278,10 +278,10 @@ func Setup( }, )).Methods(http.MethodGet) - v2fedmux.Handle("/send_leave/{roomID}/{eventID}", common.MakeFedAPI( + v2fedmux.Handle("/send_leave/{roomID}/{eventID}", internal.MakeFedAPI( "federation_send_leave", cfg.Matrix.ServerName, keys, func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest) util.JSONResponse { - vars, err := common.URLDecodeMapValues(mux.Vars(httpReq)) + vars, err := internal.URLDecodeMapValues(mux.Vars(httpReq)) if err != nil { return util.ErrorResponse(err) } @@ -293,17 +293,17 @@ func Setup( }, )).Methods(http.MethodPut) - v1fedmux.Handle("/version", common.MakeExternalAPI( + v1fedmux.Handle("/version", internal.MakeExternalAPI( "federation_version", func(httpReq *http.Request) util.JSONResponse { return Version() }, )).Methods(http.MethodGet) - v1fedmux.Handle("/get_missing_events/{roomID}", common.MakeFedAPI( + v1fedmux.Handle("/get_missing_events/{roomID}", internal.MakeFedAPI( "federation_get_missing_events", cfg.Matrix.ServerName, keys, func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest) util.JSONResponse { - vars, err := common.URLDecodeMapValues(mux.Vars(httpReq)) + vars, err := internal.URLDecodeMapValues(mux.Vars(httpReq)) if err != nil { return util.ErrorResponse(err) } @@ -311,10 +311,10 @@ func Setup( }, )).Methods(http.MethodPost) - v1fedmux.Handle("/backfill/{roomID}", common.MakeFedAPI( + v1fedmux.Handle("/backfill/{roomID}", internal.MakeFedAPI( "federation_backfill", cfg.Matrix.ServerName, keys, func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest) util.JSONResponse { - vars, err := common.URLDecodeMapValues(mux.Vars(httpReq)) + vars, err := internal.URLDecodeMapValues(mux.Vars(httpReq)) if err != nil { return util.ErrorResponse(err) } diff --git a/federationapi/routing/send.go b/federationapi/routing/send.go index e62855abb..6cf44018e 100644 --- a/federationapi/routing/send.go +++ b/federationapi/routing/send.go @@ -22,7 +22,7 @@ import ( "github.com/matrix-org/dendrite/clientapi/jsonerror" "github.com/matrix-org/dendrite/clientapi/producers" - "github.com/matrix-org/dendrite/common/config" + "github.com/matrix-org/dendrite/internal/config" "github.com/matrix-org/dendrite/roomserver/api" "github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/util" diff --git a/federationapi/routing/threepid.go b/federationapi/routing/threepid.go index 3c1d09e11..8053cedde 100644 --- a/federationapi/routing/threepid.go +++ b/federationapi/routing/threepid.go @@ -26,7 +26,7 @@ import ( "github.com/matrix-org/dendrite/clientapi/httputil" "github.com/matrix-org/dendrite/clientapi/jsonerror" "github.com/matrix-org/dendrite/clientapi/producers" - "github.com/matrix-org/dendrite/common/config" + "github.com/matrix-org/dendrite/internal/config" "github.com/matrix-org/dendrite/roomserver/api" roomserverAPI "github.com/matrix-org/dendrite/roomserver/api" diff --git a/federationsender/api/perform.go b/federationsender/api/perform.go index 2f643e5cf..427e70683 100644 --- a/federationsender/api/perform.go +++ b/federationsender/api/perform.go @@ -3,8 +3,8 @@ package api import ( "context" - commonHTTP "github.com/matrix-org/dendrite/common/http" "github.com/matrix-org/dendrite/federationsender/types" + internalHTTP "github.com/matrix-org/dendrite/internal/http" "github.com/matrix-org/gomatrixserverlib" "github.com/opentracing/opentracing-go" ) @@ -40,7 +40,7 @@ func (h *httpFederationSenderInternalAPI) PerformDirectoryLookup( defer span.Finish() apiURL := h.federationSenderURL + FederationSenderPerformDirectoryLookupRequestPath - return commonHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response) + return internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response) } type PerformJoinRequest struct { @@ -63,7 +63,7 @@ func (h *httpFederationSenderInternalAPI) PerformJoin( defer span.Finish() apiURL := h.federationSenderURL + FederationSenderPerformJoinRequestPath - return commonHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response) + return internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response) } type PerformLeaveRequest struct { @@ -85,5 +85,5 @@ func (h *httpFederationSenderInternalAPI) PerformLeave( defer span.Finish() apiURL := h.federationSenderURL + FederationSenderPerformLeaveRequestPath - return commonHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response) + return internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response) } diff --git a/federationsender/api/query.go b/federationsender/api/query.go index 7a58cc863..bf58d5cc9 100644 --- a/federationsender/api/query.go +++ b/federationsender/api/query.go @@ -3,8 +3,8 @@ package api import ( "context" - commonHTTP "github.com/matrix-org/dendrite/common/http" "github.com/matrix-org/dendrite/federationsender/types" + internalHTTP "github.com/matrix-org/dendrite/internal/http" "github.com/matrix-org/gomatrixserverlib" "github.com/opentracing/opentracing-go" @@ -36,7 +36,7 @@ func (h *httpFederationSenderInternalAPI) QueryJoinedHostsInRoom( defer span.Finish() apiURL := h.federationSenderURL + FederationSenderQueryJoinedHostsInRoomPath - return commonHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response) + return internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response) } // QueryJoinedHostServerNamesRequest is a request to QueryJoinedHostServerNames @@ -59,5 +59,5 @@ func (h *httpFederationSenderInternalAPI) QueryJoinedHostServerNamesInRoom( defer span.Finish() apiURL := h.federationSenderURL + FederationSenderQueryJoinedHostServerNamesInRoomPath - return commonHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response) + return internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response) } diff --git a/federationsender/consumers/eduserver.go b/federationsender/consumers/eduserver.go index 269701d77..bcebb3ce1 100644 --- a/federationsender/consumers/eduserver.go +++ b/federationsender/consumers/eduserver.go @@ -17,18 +17,18 @@ import ( "encoding/json" "github.com/Shopify/sarama" - "github.com/matrix-org/dendrite/common" - "github.com/matrix-org/dendrite/common/config" "github.com/matrix-org/dendrite/eduserver/api" "github.com/matrix-org/dendrite/federationsender/queue" "github.com/matrix-org/dendrite/federationsender/storage" + "github.com/matrix-org/dendrite/internal" + "github.com/matrix-org/dendrite/internal/config" "github.com/matrix-org/gomatrixserverlib" log "github.com/sirupsen/logrus" ) // OutputTypingEventConsumer consumes events that originate in EDU server. type OutputTypingEventConsumer struct { - consumer *common.ContinualConsumer + consumer *internal.ContinualConsumer db storage.Database queues *queue.OutgoingQueues ServerName gomatrixserverlib.ServerName @@ -41,7 +41,7 @@ func NewOutputTypingEventConsumer( queues *queue.OutgoingQueues, store storage.Database, ) *OutputTypingEventConsumer { - consumer := common.ContinualConsumer{ + consumer := internal.ContinualConsumer{ Topic: string(cfg.Kafka.Topics.OutputTypingEvent), Consumer: kafkaConsumer, PartitionStore: store, diff --git a/federationsender/consumers/roomserver.go b/federationsender/consumers/roomserver.go index 901239472..5f8a555bd 100644 --- a/federationsender/consumers/roomserver.go +++ b/federationsender/consumers/roomserver.go @@ -20,11 +20,11 @@ import ( "fmt" "github.com/Shopify/sarama" - "github.com/matrix-org/dendrite/common" - "github.com/matrix-org/dendrite/common/config" "github.com/matrix-org/dendrite/federationsender/queue" "github.com/matrix-org/dendrite/federationsender/storage" "github.com/matrix-org/dendrite/federationsender/types" + "github.com/matrix-org/dendrite/internal" + "github.com/matrix-org/dendrite/internal/config" "github.com/matrix-org/dendrite/roomserver/api" "github.com/matrix-org/gomatrixserverlib" log "github.com/sirupsen/logrus" @@ -35,7 +35,7 @@ import ( type OutputRoomEventConsumer struct { cfg *config.Dendrite rsAPI api.RoomserverInternalAPI - rsConsumer *common.ContinualConsumer + rsConsumer *internal.ContinualConsumer db storage.Database queues *queue.OutgoingQueues } @@ -48,7 +48,7 @@ func NewOutputRoomEventConsumer( store storage.Database, rsAPI api.RoomserverInternalAPI, ) *OutputRoomEventConsumer { - consumer := common.ContinualConsumer{ + consumer := internal.ContinualConsumer{ Topic: string(cfg.Kafka.Topics.OutputRoomEvent), Consumer: kafkaConsumer, PartitionStore: store, diff --git a/federationsender/federationsender.go b/federationsender/federationsender.go index 9c151a8d4..446f920c2 100644 --- a/federationsender/federationsender.go +++ b/federationsender/federationsender.go @@ -17,7 +17,6 @@ package federationsender import ( "net/http" - "github.com/matrix-org/dendrite/common/basecomponent" "github.com/matrix-org/dendrite/federationsender/api" "github.com/matrix-org/dendrite/federationsender/consumers" "github.com/matrix-org/dendrite/federationsender/internal" @@ -25,6 +24,7 @@ import ( "github.com/matrix-org/dendrite/federationsender/queue" "github.com/matrix-org/dendrite/federationsender/storage" "github.com/matrix-org/dendrite/federationsender/types" + "github.com/matrix-org/dendrite/internal/basecomponent" roomserverAPI "github.com/matrix-org/dendrite/roomserver/api" "github.com/matrix-org/gomatrixserverlib" "github.com/sirupsen/logrus" diff --git a/federationsender/internal/api.go b/federationsender/internal/api.go index 481795220..1f6d857f4 100644 --- a/federationsender/internal/api.go +++ b/federationsender/internal/api.go @@ -4,12 +4,12 @@ import ( "encoding/json" "net/http" - "github.com/matrix-org/dendrite/common" - "github.com/matrix-org/dendrite/common/config" "github.com/matrix-org/dendrite/federationsender/api" "github.com/matrix-org/dendrite/federationsender/producers" "github.com/matrix-org/dendrite/federationsender/storage" "github.com/matrix-org/dendrite/federationsender/types" + "github.com/matrix-org/dendrite/internal" + "github.com/matrix-org/dendrite/internal/config" "github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/util" ) @@ -46,7 +46,7 @@ func NewFederationSenderInternalAPI( func (f *FederationSenderInternalAPI) SetupHTTP(servMux *http.ServeMux) { servMux.Handle( api.FederationSenderQueryJoinedHostsInRoomPath, - common.MakeInternalAPI("QueryJoinedHostsInRoom", func(req *http.Request) util.JSONResponse { + internal.MakeInternalAPI("QueryJoinedHostsInRoom", func(req *http.Request) util.JSONResponse { var request api.QueryJoinedHostsInRoomRequest var response api.QueryJoinedHostsInRoomResponse if err := json.NewDecoder(req.Body).Decode(&request); err != nil { @@ -60,7 +60,7 @@ func (f *FederationSenderInternalAPI) SetupHTTP(servMux *http.ServeMux) { ) servMux.Handle( api.FederationSenderQueryJoinedHostServerNamesInRoomPath, - common.MakeInternalAPI("QueryJoinedHostServerNamesInRoom", func(req *http.Request) util.JSONResponse { + internal.MakeInternalAPI("QueryJoinedHostServerNamesInRoom", func(req *http.Request) util.JSONResponse { var request api.QueryJoinedHostServerNamesInRoomRequest var response api.QueryJoinedHostServerNamesInRoomResponse if err := json.NewDecoder(req.Body).Decode(&request); err != nil { @@ -73,7 +73,7 @@ func (f *FederationSenderInternalAPI) SetupHTTP(servMux *http.ServeMux) { }), ) servMux.Handle(api.FederationSenderPerformJoinRequestPath, - common.MakeInternalAPI("PerformJoinRequest", func(req *http.Request) util.JSONResponse { + internal.MakeInternalAPI("PerformJoinRequest", func(req *http.Request) util.JSONResponse { var request api.PerformJoinRequest var response api.PerformJoinResponse if err := json.NewDecoder(req.Body).Decode(&request); err != nil { @@ -86,7 +86,7 @@ func (f *FederationSenderInternalAPI) SetupHTTP(servMux *http.ServeMux) { }), ) servMux.Handle(api.FederationSenderPerformLeaveRequestPath, - common.MakeInternalAPI("PerformLeaveRequest", func(req *http.Request) util.JSONResponse { + internal.MakeInternalAPI("PerformLeaveRequest", func(req *http.Request) util.JSONResponse { var request api.PerformLeaveRequest var response api.PerformLeaveResponse if err := json.NewDecoder(req.Body).Decode(&request); err != nil { diff --git a/federationsender/storage/interface.go b/federationsender/storage/interface.go index ae2956475..be195382b 100644 --- a/federationsender/storage/interface.go +++ b/federationsender/storage/interface.go @@ -17,12 +17,12 @@ package storage import ( "context" - "github.com/matrix-org/dendrite/common" "github.com/matrix-org/dendrite/federationsender/types" + "github.com/matrix-org/dendrite/internal" ) type Database interface { - common.PartitionStorer + internal.PartitionStorer UpdateRoom(ctx context.Context, roomID, oldEventID, newEventID string, addHosts []types.JoinedHost, removeHosts []string) (joinedHosts []types.JoinedHost, err error) GetJoinedHosts(ctx context.Context, roomID string) ([]types.JoinedHost, error) } diff --git a/federationsender/storage/postgres/joined_hosts_table.go b/federationsender/storage/postgres/joined_hosts_table.go index b3c45abda..1b898f485 100644 --- a/federationsender/storage/postgres/joined_hosts_table.go +++ b/federationsender/storage/postgres/joined_hosts_table.go @@ -20,8 +20,8 @@ import ( "database/sql" "github.com/lib/pq" - "github.com/matrix-org/dendrite/common" "github.com/matrix-org/dendrite/federationsender/types" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/gomatrixserverlib" ) @@ -85,7 +85,7 @@ func (s *joinedHostsStatements) insertJoinedHosts( roomID, eventID string, serverName gomatrixserverlib.ServerName, ) error { - stmt := common.TxStmt(txn, s.insertJoinedHostsStmt) + stmt := internal.TxStmt(txn, s.insertJoinedHostsStmt) _, err := stmt.ExecContext(ctx, roomID, eventID, serverName) return err } @@ -93,7 +93,7 @@ func (s *joinedHostsStatements) insertJoinedHosts( func (s *joinedHostsStatements) deleteJoinedHosts( ctx context.Context, txn *sql.Tx, eventIDs []string, ) error { - stmt := common.TxStmt(txn, s.deleteJoinedHostsStmt) + stmt := internal.TxStmt(txn, s.deleteJoinedHostsStmt) _, err := stmt.ExecContext(ctx, pq.StringArray(eventIDs)) return err } @@ -101,7 +101,7 @@ func (s *joinedHostsStatements) deleteJoinedHosts( func (s *joinedHostsStatements) selectJoinedHostsWithTx( ctx context.Context, txn *sql.Tx, roomID string, ) ([]types.JoinedHost, error) { - stmt := common.TxStmt(txn, s.selectJoinedHostsStmt) + stmt := internal.TxStmt(txn, s.selectJoinedHostsStmt) return joinedHostsFromStmt(ctx, stmt, roomID) } @@ -118,7 +118,7 @@ func joinedHostsFromStmt( if err != nil { return nil, err } - defer common.CloseAndLogIfError(ctx, rows, "joinedHostsFromStmt: rows.close() failed") + defer internal.CloseAndLogIfError(ctx, rows, "joinedHostsFromStmt: rows.close() failed") var result []types.JoinedHost for rows.Next() { diff --git a/federationsender/storage/postgres/room_table.go b/federationsender/storage/postgres/room_table.go index a64424b44..c945475ba 100644 --- a/federationsender/storage/postgres/room_table.go +++ b/federationsender/storage/postgres/room_table.go @@ -19,7 +19,7 @@ import ( "context" "database/sql" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" ) const roomSchema = ` @@ -71,7 +71,7 @@ func (s *roomStatements) prepare(db *sql.DB) (err error) { func (s *roomStatements) insertRoom( ctx context.Context, txn *sql.Tx, roomID string, ) error { - _, err := common.TxStmt(txn, s.insertRoomStmt).ExecContext(ctx, roomID) + _, err := internal.TxStmt(txn, s.insertRoomStmt).ExecContext(ctx, roomID) return err } @@ -82,7 +82,7 @@ func (s *roomStatements) selectRoomForUpdate( ctx context.Context, txn *sql.Tx, roomID string, ) (string, error) { var lastEventID string - stmt := common.TxStmt(txn, s.selectRoomForUpdateStmt) + stmt := internal.TxStmt(txn, s.selectRoomForUpdateStmt) err := stmt.QueryRowContext(ctx, roomID).Scan(&lastEventID) if err != nil { return "", err @@ -95,7 +95,7 @@ func (s *roomStatements) selectRoomForUpdate( func (s *roomStatements) updateRoom( ctx context.Context, txn *sql.Tx, roomID, lastEventID string, ) error { - stmt := common.TxStmt(txn, s.updateRoomStmt) + stmt := internal.TxStmt(txn, s.updateRoomStmt) _, err := stmt.ExecContext(ctx, roomID, lastEventID) return err } diff --git a/federationsender/storage/postgres/storage.go b/federationsender/storage/postgres/storage.go index c3892ac10..a4733a20c 100644 --- a/federationsender/storage/postgres/storage.go +++ b/federationsender/storage/postgres/storage.go @@ -19,8 +19,8 @@ import ( "context" "database/sql" - "github.com/matrix-org/dendrite/common" "github.com/matrix-org/dendrite/federationsender/types" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/internal/sqlutil" ) @@ -28,12 +28,12 @@ import ( type Database struct { joinedHostsStatements roomStatements - common.PartitionOffsetStatements + internal.PartitionOffsetStatements db *sql.DB } // NewDatabase opens a new database -func NewDatabase(dataSourceName string, dbProperties common.DbProperties) (*Database, error) { +func NewDatabase(dataSourceName string, dbProperties internal.DbProperties) (*Database, error) { var result Database var err error if result.db, err = sqlutil.Open("postgres", dataSourceName, dbProperties); err != nil { @@ -70,7 +70,7 @@ func (d *Database) UpdateRoom( addHosts []types.JoinedHost, removeHosts []string, ) (joinedHosts []types.JoinedHost, err error) { - err = common.WithTransaction(d.db, func(txn *sql.Tx) error { + err = internal.WithTransaction(d.db, func(txn *sql.Tx) error { err = d.insertRoom(ctx, txn, roomID) if err != nil { return err diff --git a/federationsender/storage/sqlite3/joined_hosts_table.go b/federationsender/storage/sqlite3/joined_hosts_table.go index 466ae4991..795d33208 100644 --- a/federationsender/storage/sqlite3/joined_hosts_table.go +++ b/federationsender/storage/sqlite3/joined_hosts_table.go @@ -19,8 +19,8 @@ import ( "context" "database/sql" - "github.com/matrix-org/dendrite/common" "github.com/matrix-org/dendrite/federationsender/types" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/gomatrixserverlib" ) @@ -84,7 +84,7 @@ func (s *joinedHostsStatements) insertJoinedHosts( roomID, eventID string, serverName gomatrixserverlib.ServerName, ) error { - stmt := common.TxStmt(txn, s.insertJoinedHostsStmt) + stmt := internal.TxStmt(txn, s.insertJoinedHostsStmt) _, err := stmt.ExecContext(ctx, roomID, eventID, serverName) return err } @@ -93,7 +93,7 @@ func (s *joinedHostsStatements) deleteJoinedHosts( ctx context.Context, txn *sql.Tx, eventIDs []string, ) error { for _, eventID := range eventIDs { - stmt := common.TxStmt(txn, s.deleteJoinedHostsStmt) + stmt := internal.TxStmt(txn, s.deleteJoinedHostsStmt) if _, err := stmt.ExecContext(ctx, eventID); err != nil { return err } @@ -104,7 +104,7 @@ func (s *joinedHostsStatements) deleteJoinedHosts( func (s *joinedHostsStatements) selectJoinedHostsWithTx( ctx context.Context, txn *sql.Tx, roomID string, ) ([]types.JoinedHost, error) { - stmt := common.TxStmt(txn, s.selectJoinedHostsStmt) + stmt := internal.TxStmt(txn, s.selectJoinedHostsStmt) return joinedHostsFromStmt(ctx, stmt, roomID) } @@ -121,7 +121,7 @@ func joinedHostsFromStmt( if err != nil { return nil, err } - defer common.CloseAndLogIfError(ctx, rows, "joinedHostsFromStmt: rows.close() failed") + defer internal.CloseAndLogIfError(ctx, rows, "joinedHostsFromStmt: rows.close() failed") var result []types.JoinedHost for rows.Next() { diff --git a/federationsender/storage/sqlite3/room_table.go b/federationsender/storage/sqlite3/room_table.go index 6361400d3..4bf9ab81d 100644 --- a/federationsender/storage/sqlite3/room_table.go +++ b/federationsender/storage/sqlite3/room_table.go @@ -19,7 +19,7 @@ import ( "context" "database/sql" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" ) const roomSchema = ` @@ -71,7 +71,7 @@ func (s *roomStatements) prepare(db *sql.DB) (err error) { func (s *roomStatements) insertRoom( ctx context.Context, txn *sql.Tx, roomID string, ) error { - _, err := common.TxStmt(txn, s.insertRoomStmt).ExecContext(ctx, roomID) + _, err := internal.TxStmt(txn, s.insertRoomStmt).ExecContext(ctx, roomID) return err } @@ -82,7 +82,7 @@ func (s *roomStatements) selectRoomForUpdate( ctx context.Context, txn *sql.Tx, roomID string, ) (string, error) { var lastEventID string - stmt := common.TxStmt(txn, s.selectRoomForUpdateStmt) + stmt := internal.TxStmt(txn, s.selectRoomForUpdateStmt) err := stmt.QueryRowContext(ctx, roomID).Scan(&lastEventID) if err != nil { return "", err @@ -95,7 +95,7 @@ func (s *roomStatements) selectRoomForUpdate( func (s *roomStatements) updateRoom( ctx context.Context, txn *sql.Tx, roomID, lastEventID string, ) error { - stmt := common.TxStmt(txn, s.updateRoomStmt) + stmt := internal.TxStmt(txn, s.updateRoomStmt) _, err := stmt.ExecContext(ctx, roomID, lastEventID) return err } diff --git a/federationsender/storage/sqlite3/storage.go b/federationsender/storage/sqlite3/storage.go index 772744474..dc60ebb01 100644 --- a/federationsender/storage/sqlite3/storage.go +++ b/federationsender/storage/sqlite3/storage.go @@ -21,8 +21,8 @@ import ( _ "github.com/mattn/go-sqlite3" - "github.com/matrix-org/dendrite/common" "github.com/matrix-org/dendrite/federationsender/types" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/internal/sqlutil" ) @@ -30,7 +30,7 @@ import ( type Database struct { joinedHostsStatements roomStatements - common.PartitionOffsetStatements + internal.PartitionOffsetStatements db *sql.DB } @@ -38,7 +38,7 @@ type Database struct { func NewDatabase(dataSourceName string) (*Database, error) { var result Database var err error - if result.db, err = sqlutil.Open(common.SQLiteDriverName(), dataSourceName, nil); err != nil { + if result.db, err = sqlutil.Open(internal.SQLiteDriverName(), dataSourceName, nil); err != nil { return nil, err } if err = result.prepare(); err != nil { @@ -72,7 +72,7 @@ func (d *Database) UpdateRoom( addHosts []types.JoinedHost, removeHosts []string, ) (joinedHosts []types.JoinedHost, err error) { - err = common.WithTransaction(d.db, func(txn *sql.Tx) error { + err = internal.WithTransaction(d.db, func(txn *sql.Tx) error { err = d.insertRoom(ctx, txn, roomID) if err != nil { return err diff --git a/federationsender/storage/storage.go b/federationsender/storage/storage.go index d481e58a2..df8433eba 100644 --- a/federationsender/storage/storage.go +++ b/federationsender/storage/storage.go @@ -19,13 +19,13 @@ package storage import ( "net/url" - "github.com/matrix-org/dendrite/common" "github.com/matrix-org/dendrite/federationsender/storage/postgres" "github.com/matrix-org/dendrite/federationsender/storage/sqlite3" + "github.com/matrix-org/dendrite/internal" ) // NewDatabase opens a new database -func NewDatabase(dataSourceName string, dbProperties common.DbProperties) (Database, error) { +func NewDatabase(dataSourceName string, dbProperties internal.DbProperties) (Database, error) { uri, err := url.Parse(dataSourceName) if err != nil { return postgres.NewDatabase(dataSourceName, dbProperties) diff --git a/federationsender/storage/storage_wasm.go b/federationsender/storage/storage_wasm.go index 44d4c8060..f593fd448 100644 --- a/federationsender/storage/storage_wasm.go +++ b/federationsender/storage/storage_wasm.go @@ -18,14 +18,14 @@ import ( "fmt" "net/url" - "github.com/matrix-org/dendrite/common" "github.com/matrix-org/dendrite/federationsender/storage/sqlite3" + "github.com/matrix-org/dendrite/internal" ) // NewDatabase opens a new database func NewDatabase( dataSourceName string, - dbProperties common.DbProperties, // nolint:unparam + dbProperties internal.DbProperties, // nolint:unparam ) (Database, error) { uri, err := url.Parse(dataSourceName) if err != nil { diff --git a/common/basecomponent/base.go b/internal/basecomponent/base.go similarity index 94% rename from common/basecomponent/base.go rename to internal/basecomponent/base.go index 234de5e72..e9a375a70 100644 --- a/common/basecomponent/base.go +++ b/internal/basecomponent/base.go @@ -23,24 +23,24 @@ import ( "golang.org/x/crypto/ed25519" - "github.com/matrix-org/dendrite/common/caching" - "github.com/matrix-org/dendrite/common/keydb" - "github.com/matrix-org/dendrite/common/keydb/cache" + "github.com/matrix-org/dendrite/internal/caching" + "github.com/matrix-org/dendrite/internal/keydb" + "github.com/matrix-org/dendrite/internal/keydb/cache" "github.com/matrix-org/dendrite/internal/sqlutil" "github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/naffka" "github.com/matrix-org/dendrite/clientapi/auth/storage/accounts" "github.com/matrix-org/dendrite/clientapi/auth/storage/devices" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/Shopify/sarama" "github.com/gorilla/mux" appserviceAPI "github.com/matrix-org/dendrite/appservice/api" - "github.com/matrix-org/dendrite/common/config" eduServerAPI "github.com/matrix-org/dendrite/eduserver/api" federationSenderAPI "github.com/matrix-org/dendrite/federationsender/api" + "github.com/matrix-org/dendrite/internal/config" roomserverAPI "github.com/matrix-org/dendrite/roomserver/api" "github.com/sirupsen/logrus" @@ -73,9 +73,9 @@ const HTTPClientTimeout = time.Second * 30 // The componentName is used for logging purposes, and should be a friendly name // of the compontent running, e.g. "SyncAPI" func NewBaseDendrite(cfg *config.Dendrite, componentName string, enableHTTPAPIs bool) *BaseDendrite { - common.SetupStdLogging() - common.SetupHookLogging(cfg.Logging, componentName) - common.SetupPprof() + internal.SetupStdLogging() + internal.SetupHookLogging(cfg.Logging, componentName) + internal.SetupPprof() closer, err := cfg.SetupTracing("Dendrite" + componentName) if err != nil { @@ -221,7 +221,7 @@ func (b *BaseDendrite) SetupAndServeHTTP(bindaddr string, listenaddr string) { WriteTimeout: HTTPServerTimeout, } - common.SetupHTTPAPI(http.DefaultServeMux, common.WrapHandlerInCORS(b.APIMux), b.Cfg) + internal.SetupHTTPAPI(http.DefaultServeMux, internal.WrapHandlerInCORS(b.APIMux), b.Cfg) logrus.Infof("Starting %s server on %s", b.componentName, serv.Addr) err := serv.ListenAndServe() @@ -255,7 +255,7 @@ func setupNaffka(cfg *config.Dendrite) (sarama.Consumer, sarama.SyncProducer) { uri, err := url.Parse(string(cfg.Database.Naffka)) if err != nil || uri.Scheme == "file" { - db, err = sqlutil.Open(common.SQLiteDriverName(), string(cfg.Database.Naffka), nil) + db, err = sqlutil.Open(internal.SQLiteDriverName(), string(cfg.Database.Naffka), nil) if err != nil { logrus.WithError(err).Panic("Failed to open naffka database") } diff --git a/common/basecomponent/flags.go b/internal/basecomponent/flags.go similarity index 97% rename from common/basecomponent/flags.go rename to internal/basecomponent/flags.go index 6dcb5601a..ecef81f6b 100644 --- a/common/basecomponent/flags.go +++ b/internal/basecomponent/flags.go @@ -17,7 +17,7 @@ package basecomponent import ( "flag" - "github.com/matrix-org/dendrite/common/config" + "github.com/matrix-org/dendrite/internal/config" "github.com/sirupsen/logrus" ) diff --git a/common/caching/immutablecache.go b/internal/caching/immutablecache.go similarity index 100% rename from common/caching/immutablecache.go rename to internal/caching/immutablecache.go diff --git a/common/caching/immutableinmemorylru.go b/internal/caching/immutableinmemorylru.go similarity index 100% rename from common/caching/immutableinmemorylru.go rename to internal/caching/immutableinmemorylru.go diff --git a/common/config/appservice.go b/internal/config/appservice.go similarity index 100% rename from common/config/appservice.go rename to internal/config/appservice.go diff --git a/common/config/config.go b/internal/config/config.go similarity index 100% rename from common/config/config.go rename to internal/config/config.go diff --git a/common/config/config_test.go b/internal/config/config_test.go similarity index 100% rename from common/config/config_test.go rename to internal/config/config_test.go diff --git a/common/consumers.go b/internal/consumers.go similarity index 99% rename from common/consumers.go rename to internal/consumers.go index bc759d994..df68cbfaa 100644 --- a/common/consumers.go +++ b/internal/consumers.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package common +package internal import ( "context" diff --git a/common/eventcontent.go b/internal/eventcontent.go similarity index 99% rename from common/eventcontent.go rename to internal/eventcontent.go index e7e1a2c8b..645128369 100644 --- a/common/eventcontent.go +++ b/internal/eventcontent.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package common +package internal import "github.com/matrix-org/gomatrixserverlib" diff --git a/common/events.go b/internal/events.go similarity index 98% rename from common/events.go rename to internal/events.go index 0c8ead3a7..89c82e03b 100644 --- a/common/events.go +++ b/internal/events.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package common +package internal import ( "context" @@ -20,7 +20,7 @@ import ( "fmt" "time" - "github.com/matrix-org/dendrite/common/config" + "github.com/matrix-org/dendrite/internal/config" "github.com/matrix-org/dendrite/roomserver/api" "github.com/matrix-org/gomatrixserverlib" diff --git a/common/http/http.go b/internal/http/http.go similarity index 100% rename from common/http/http.go rename to internal/http/http.go diff --git a/common/httpapi.go b/internal/httpapi.go similarity index 99% rename from common/httpapi.go rename to internal/httpapi.go index e5324bd17..b4c53f58d 100644 --- a/common/httpapi.go +++ b/internal/httpapi.go @@ -1,4 +1,4 @@ -package common +package internal import ( "io" @@ -11,7 +11,7 @@ import ( "github.com/matrix-org/dendrite/clientapi/auth" "github.com/matrix-org/dendrite/clientapi/auth/authtypes" - "github.com/matrix-org/dendrite/common/config" + "github.com/matrix-org/dendrite/internal/config" "github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/util" opentracing "github.com/opentracing/opentracing-go" diff --git a/common/httpapi_test.go b/internal/httpapi_test.go similarity index 99% rename from common/httpapi_test.go rename to internal/httpapi_test.go index 7de7ce33c..6f159c8d6 100644 --- a/common/httpapi_test.go +++ b/internal/httpapi_test.go @@ -1,4 +1,4 @@ -package common +package internal import ( "net/http" diff --git a/common/keydb/cache/keydb.go b/internal/keydb/cache/keydb.go similarity index 94% rename from common/keydb/cache/keydb.go rename to internal/keydb/cache/keydb.go index ae929fa4c..87573ed2b 100644 --- a/common/keydb/cache/keydb.go +++ b/internal/keydb/cache/keydb.go @@ -4,8 +4,8 @@ import ( "context" "errors" - "github.com/matrix-org/dendrite/common/caching" - "github.com/matrix-org/dendrite/common/keydb" + "github.com/matrix-org/dendrite/internal/caching" + "github.com/matrix-org/dendrite/internal/keydb" "github.com/matrix-org/gomatrixserverlib" ) diff --git a/common/keydb/interface.go b/internal/keydb/interface.go similarity index 100% rename from common/keydb/interface.go rename to internal/keydb/interface.go diff --git a/common/keydb/keydb.go b/internal/keydb/keydb.go similarity index 88% rename from common/keydb/keydb.go rename to internal/keydb/keydb.go index 397d7849c..ad6d56b86 100644 --- a/common/keydb/keydb.go +++ b/internal/keydb/keydb.go @@ -21,16 +21,16 @@ import ( "golang.org/x/crypto/ed25519" - "github.com/matrix-org/dendrite/common" - "github.com/matrix-org/dendrite/common/keydb/postgres" - "github.com/matrix-org/dendrite/common/keydb/sqlite3" + "github.com/matrix-org/dendrite/internal" + "github.com/matrix-org/dendrite/internal/keydb/postgres" + "github.com/matrix-org/dendrite/internal/keydb/sqlite3" "github.com/matrix-org/gomatrixserverlib" ) // NewDatabase opens a database connection. func NewDatabase( dataSourceName string, - dbProperties common.DbProperties, + dbProperties internal.DbProperties, serverName gomatrixserverlib.ServerName, serverKey ed25519.PublicKey, serverKeyID gomatrixserverlib.KeyID, diff --git a/common/keydb/keydb_wasm.go b/internal/keydb/keydb_wasm.go similarity index 89% rename from common/keydb/keydb_wasm.go rename to internal/keydb/keydb_wasm.go index 38e595820..349381ee7 100644 --- a/common/keydb/keydb_wasm.go +++ b/internal/keydb/keydb_wasm.go @@ -20,15 +20,15 @@ import ( "golang.org/x/crypto/ed25519" - "github.com/matrix-org/dendrite/common" - "github.com/matrix-org/dendrite/common/keydb/sqlite3" + "github.com/matrix-org/dendrite/internal" + "github.com/matrix-org/dendrite/internal/keydb/sqlite3" "github.com/matrix-org/gomatrixserverlib" ) // NewDatabase opens a database connection. func NewDatabase( dataSourceName string, - dbProperties common.DbProperties, // nolint:unparam + dbProperties internal.DbProperties, // nolint:unparam serverName gomatrixserverlib.ServerName, serverKey ed25519.PublicKey, serverKeyID gomatrixserverlib.KeyID, diff --git a/common/keydb/keyring.go b/internal/keydb/keyring.go similarity index 97% rename from common/keydb/keyring.go rename to internal/keydb/keyring.go index e9cc7903e..d0b1904ed 100644 --- a/common/keydb/keyring.go +++ b/internal/keydb/keyring.go @@ -17,7 +17,7 @@ package keydb import ( "encoding/base64" - "github.com/matrix-org/dendrite/common/config" + "github.com/matrix-org/dendrite/internal/config" "github.com/matrix-org/gomatrixserverlib" "github.com/sirupsen/logrus" "golang.org/x/crypto/ed25519" diff --git a/common/keydb/postgres/keydb.go b/internal/keydb/postgres/keydb.go similarity index 97% rename from common/keydb/postgres/keydb.go rename to internal/keydb/postgres/keydb.go index a8a304376..da3a4d370 100644 --- a/common/keydb/postgres/keydb.go +++ b/internal/keydb/postgres/keydb.go @@ -21,7 +21,7 @@ import ( "golang.org/x/crypto/ed25519" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/internal/sqlutil" "github.com/matrix-org/gomatrixserverlib" ) @@ -38,7 +38,7 @@ type Database struct { // Returns an error if there was a problem talking to the database. func NewDatabase( dataSourceName string, - dbProperties common.DbProperties, + dbProperties internal.DbProperties, serverName gomatrixserverlib.ServerName, serverKey ed25519.PublicKey, serverKeyID gomatrixserverlib.KeyID, diff --git a/common/keydb/postgres/server_key_table.go b/internal/keydb/postgres/server_key_table.go similarity index 97% rename from common/keydb/postgres/server_key_table.go rename to internal/keydb/postgres/server_key_table.go index 0434eb8b1..b3c26a480 100644 --- a/common/keydb/postgres/server_key_table.go +++ b/internal/keydb/postgres/server_key_table.go @@ -19,7 +19,7 @@ import ( "context" "database/sql" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/lib/pq" "github.com/matrix-org/gomatrixserverlib" @@ -93,7 +93,7 @@ func (s *serverKeyStatements) bulkSelectServerKeys( if err != nil { return nil, err } - defer common.CloseAndLogIfError(ctx, rows, "bulkSelectServerKeys: rows.close() failed") + defer internal.CloseAndLogIfError(ctx, rows, "bulkSelectServerKeys: rows.close() failed") results := map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.PublicKeyLookupResult{} for rows.Next() { var serverName string diff --git a/common/keydb/sqlite3/keydb.go b/internal/keydb/sqlite3/keydb.go similarity index 96% rename from common/keydb/sqlite3/keydb.go rename to internal/keydb/sqlite3/keydb.go index 1ff315d7c..d1dc61c98 100644 --- a/common/keydb/sqlite3/keydb.go +++ b/internal/keydb/sqlite3/keydb.go @@ -21,7 +21,7 @@ import ( "golang.org/x/crypto/ed25519" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/internal/sqlutil" "github.com/matrix-org/gomatrixserverlib" @@ -44,7 +44,7 @@ func NewDatabase( serverKey ed25519.PublicKey, serverKeyID gomatrixserverlib.KeyID, ) (*Database, error) { - db, err := sqlutil.Open(common.SQLiteDriverName(), dataSourceName, nil) + db, err := sqlutil.Open(internal.SQLiteDriverName(), dataSourceName, nil) if err != nil { return nil, err } diff --git a/common/keydb/sqlite3/server_key_table.go b/internal/keydb/sqlite3/server_key_table.go similarity index 95% rename from common/keydb/sqlite3/server_key_table.go rename to internal/keydb/sqlite3/server_key_table.go index 883d3cd0f..ae24a14d4 100644 --- a/common/keydb/sqlite3/server_key_table.go +++ b/internal/keydb/sqlite3/server_key_table.go @@ -20,7 +20,7 @@ import ( "database/sql" "strings" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/gomatrixserverlib" ) @@ -90,7 +90,7 @@ func (s *serverKeyStatements) bulkSelectServerKeys( nameAndKeyIDs = append(nameAndKeyIDs, nameAndKeyID(request)) } - query := strings.Replace(bulkSelectServerKeysSQL, "($1)", common.QueryVariadic(len(nameAndKeyIDs)), 1) + query := strings.Replace(bulkSelectServerKeysSQL, "($1)", internal.QueryVariadic(len(nameAndKeyIDs)), 1) iKeyIDs := make([]interface{}, len(nameAndKeyIDs)) for i, v := range nameAndKeyIDs { @@ -101,7 +101,7 @@ func (s *serverKeyStatements) bulkSelectServerKeys( if err != nil { return nil, err } - defer common.CloseAndLogIfError(ctx, rows, "bulkSelectServerKeys: rows.close() failed") + defer internal.CloseAndLogIfError(ctx, rows, "bulkSelectServerKeys: rows.close() failed") results := map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.PublicKeyLookupResult{} for rows.Next() { var serverName string diff --git a/common/log.go b/internal/log.go similarity index 98% rename from common/log.go rename to internal/log.go index 60e969650..fd2b84ab9 100644 --- a/common/log.go +++ b/internal/log.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package common +package internal import ( "context" @@ -27,7 +27,7 @@ import ( "github.com/matrix-org/util" - "github.com/matrix-org/dendrite/common/config" + "github.com/matrix-org/dendrite/internal/config" "github.com/matrix-org/dugong" "github.com/sirupsen/logrus" ) diff --git a/common/partition_offset_table.go b/internal/partition_offset_table.go similarity index 99% rename from common/partition_offset_table.go rename to internal/partition_offset_table.go index aa799f8a0..8b72819b7 100644 --- a/common/partition_offset_table.go +++ b/internal/partition_offset_table.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package common +package internal import ( "context" diff --git a/common/postgres.go b/internal/postgres.go similarity index 98% rename from common/postgres.go rename to internal/postgres.go index f8daf5783..7ae40d8fd 100644 --- a/common/postgres.go +++ b/internal/postgres.go @@ -14,7 +14,7 @@ // +build !wasm -package common +package internal import "github.com/lib/pq" diff --git a/common/postgres_wasm.go b/internal/postgres_wasm.go similarity index 97% rename from common/postgres_wasm.go rename to internal/postgres_wasm.go index dcc07b31d..64d328291 100644 --- a/common/postgres_wasm.go +++ b/internal/postgres_wasm.go @@ -14,7 +14,7 @@ // +build wasm -package common +package internal // IsUniqueConstraintViolationErr no-ops for this architecture func IsUniqueConstraintViolationErr(err error) bool { diff --git a/common/routing.go b/internal/routing.go similarity index 98% rename from common/routing.go rename to internal/routing.go index cee0c162a..4462c70ca 100644 --- a/common/routing.go +++ b/internal/routing.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package common +package internal import ( "net/url" diff --git a/common/sql.go b/internal/sql.go similarity index 99% rename from common/sql.go rename to internal/sql.go index e93ff1c2f..d6a5a3086 100644 --- a/common/sql.go +++ b/internal/sql.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package common +package internal import ( "database/sql" diff --git a/internal/sqlutil/trace.go b/internal/sqlutil/trace.go index 42ac4e582..1b008e1b7 100644 --- a/internal/sqlutil/trace.go +++ b/internal/sqlutil/trace.go @@ -25,7 +25,7 @@ import ( "strings" "time" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/ngrok/sqlmw" "github.com/sirupsen/logrus" ) @@ -78,7 +78,7 @@ func (in *traceInterceptor) RowsNext(c context.Context, rows driver.Rows, dest [ // Open opens a database specified by its database driver name and a driver-specific data source name, // usually consisting of at least a database name and connection information. Includes tracing driver // if DENDRITE_TRACE_SQL=1 -func Open(driverName, dsn string, dbProperties common.DbProperties) (*sql.DB, error) { +func Open(driverName, dsn string, dbProperties internal.DbProperties) (*sql.DB, error) { if tracingEnabled { // install the wrapped driver driverName += "-trace" @@ -87,7 +87,7 @@ func Open(driverName, dsn string, dbProperties common.DbProperties) (*sql.DB, er if err != nil { return nil, err } - if driverName != common.SQLiteDriverName() && dbProperties != nil { + if driverName != internal.SQLiteDriverName() && dbProperties != nil { logrus.WithFields(logrus.Fields{ "MaxOpenConns": dbProperties.MaxOpenConns(), "MaxIdleConns": dbProperties.MaxIdleConns(), diff --git a/common/test/client.go b/internal/test/client.go similarity index 100% rename from common/test/client.go rename to internal/test/client.go diff --git a/common/test/config.go b/internal/test/config.go similarity index 99% rename from common/test/config.go rename to internal/test/config.go index f88e45125..06510c8b8 100644 --- a/common/test/config.go +++ b/internal/test/config.go @@ -27,7 +27,7 @@ import ( "path/filepath" "time" - "github.com/matrix-org/dendrite/common/config" + "github.com/matrix-org/dendrite/internal/config" "github.com/matrix-org/gomatrixserverlib" "gopkg.in/yaml.v2" ) diff --git a/common/test/kafka.go b/internal/test/kafka.go similarity index 100% rename from common/test/kafka.go rename to internal/test/kafka.go diff --git a/common/test/server.go b/internal/test/server.go similarity index 98% rename from common/test/server.go rename to internal/test/server.go index 4fdd5e638..1493dac6f 100644 --- a/common/test/server.go +++ b/internal/test/server.go @@ -21,7 +21,7 @@ import ( "path/filepath" "strings" - "github.com/matrix-org/dendrite/common/config" + "github.com/matrix-org/dendrite/internal/config" ) // Defaulting allows assignment of string variables with a fallback default value diff --git a/common/test/slice.go b/internal/test/slice.go similarity index 100% rename from common/test/slice.go rename to internal/test/slice.go diff --git a/common/transactions/transactions.go b/internal/transactions/transactions.go similarity index 100% rename from common/transactions/transactions.go rename to internal/transactions/transactions.go diff --git a/common/transactions/transactions_test.go b/internal/transactions/transactions_test.go similarity index 100% rename from common/transactions/transactions_test.go rename to internal/transactions/transactions_test.go diff --git a/common/types.go b/internal/types.go similarity index 99% rename from common/types.go rename to internal/types.go index 91765be00..be2717f39 100644 --- a/common/types.go +++ b/internal/types.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package common +package internal import ( "errors" diff --git a/keyserver/keyserver.go b/keyserver/keyserver.go index 1e0d5cb42..0f450165f 100644 --- a/keyserver/keyserver.go +++ b/keyserver/keyserver.go @@ -17,7 +17,7 @@ package keyserver import ( "github.com/matrix-org/dendrite/clientapi/auth/storage/accounts" "github.com/matrix-org/dendrite/clientapi/auth/storage/devices" - "github.com/matrix-org/dendrite/common/basecomponent" + "github.com/matrix-org/dendrite/internal/basecomponent" "github.com/matrix-org/dendrite/keyserver/routing" ) diff --git a/keyserver/routing/routing.go b/keyserver/routing/routing.go index d79ce6d40..3ca68ade4 100644 --- a/keyserver/routing/routing.go +++ b/keyserver/routing/routing.go @@ -22,8 +22,8 @@ import ( "github.com/matrix-org/dendrite/clientapi/auth/authtypes" "github.com/matrix-org/dendrite/clientapi/auth/storage/accounts" "github.com/matrix-org/dendrite/clientapi/auth/storage/devices" - "github.com/matrix-org/dendrite/common" - "github.com/matrix-org/dendrite/common/config" + "github.com/matrix-org/dendrite/internal" + "github.com/matrix-org/dendrite/internal/config" "github.com/matrix-org/util" ) @@ -49,7 +49,7 @@ func Setup( } r0mux.Handle("/keys/query", - common.MakeAuthAPI("queryKeys", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { + internal.MakeAuthAPI("queryKeys", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { return QueryKeys(req) }), ).Methods(http.MethodPost, http.MethodOptions) diff --git a/mediaapi/fileutils/fileutils.go b/mediaapi/fileutils/fileutils.go index 1de242a00..39687b9d4 100644 --- a/mediaapi/fileutils/fileutils.go +++ b/mediaapi/fileutils/fileutils.go @@ -25,7 +25,7 @@ import ( "path/filepath" "strings" - "github.com/matrix-org/dendrite/common/config" + "github.com/matrix-org/dendrite/internal/config" "github.com/matrix-org/dendrite/mediaapi/types" log "github.com/sirupsen/logrus" ) diff --git a/mediaapi/mediaapi.go b/mediaapi/mediaapi.go index 4a0f5d188..38572daf8 100644 --- a/mediaapi/mediaapi.go +++ b/mediaapi/mediaapi.go @@ -16,7 +16,7 @@ package mediaapi import ( "github.com/matrix-org/dendrite/clientapi/auth/storage/devices" - "github.com/matrix-org/dendrite/common/basecomponent" + "github.com/matrix-org/dendrite/internal/basecomponent" "github.com/matrix-org/dendrite/mediaapi/routing" "github.com/matrix-org/dendrite/mediaapi/storage" "github.com/matrix-org/gomatrixserverlib" diff --git a/mediaapi/routing/download.go b/mediaapi/routing/download.go index 75df313f6..1a025f6f0 100644 --- a/mediaapi/routing/download.go +++ b/mediaapi/routing/download.go @@ -29,7 +29,7 @@ import ( "sync" "github.com/matrix-org/dendrite/clientapi/jsonerror" - "github.com/matrix-org/dendrite/common/config" + "github.com/matrix-org/dendrite/internal/config" "github.com/matrix-org/dendrite/mediaapi/fileutils" "github.com/matrix-org/dendrite/mediaapi/storage" "github.com/matrix-org/dendrite/mediaapi/thumbnailer" diff --git a/mediaapi/routing/routing.go b/mediaapi/routing/routing.go index 71dad19b6..4f765d173 100644 --- a/mediaapi/routing/routing.go +++ b/mediaapi/routing/routing.go @@ -22,8 +22,8 @@ import ( "github.com/gorilla/mux" "github.com/matrix-org/dendrite/clientapi/auth/storage/devices" - "github.com/matrix-org/dendrite/common" - "github.com/matrix-org/dendrite/common/config" + "github.com/matrix-org/dendrite/internal" + "github.com/matrix-org/dendrite/internal/config" "github.com/matrix-org/dendrite/mediaapi/storage" "github.com/matrix-org/dendrite/mediaapi/types" "github.com/matrix-org/gomatrixserverlib" @@ -59,7 +59,7 @@ func Setup( } // TODO: Add AS support - r0mux.Handle("/upload", common.MakeAuthAPI( + r0mux.Handle("/upload", internal.MakeAuthAPI( "upload", authData, func(req *http.Request, _ *authtypes.Device) util.JSONResponse { return Upload(req, cfg, db, activeThumbnailGeneration) @@ -95,11 +95,11 @@ func makeDownloadAPI( httpHandler := func(w http.ResponseWriter, req *http.Request) { req = util.RequestWithLogging(req) - // Set common headers returned regardless of the outcome of the request + // Set internal headers returned regardless of the outcome of the request util.SetCORSHeaders(w) // Content-Type will be overridden in case of returning file data, else we respond with JSON-formatted errors w.Header().Set("Content-Type", "application/json") - vars, _ := common.URLDecodeMapValues(mux.Vars(req)) + vars, _ := internal.URLDecodeMapValues(mux.Vars(req)) Download( w, req, diff --git a/mediaapi/routing/upload.go b/mediaapi/routing/upload.go index 91a453190..022f978d6 100644 --- a/mediaapi/routing/upload.go +++ b/mediaapi/routing/upload.go @@ -24,7 +24,7 @@ import ( "strings" "github.com/matrix-org/dendrite/clientapi/jsonerror" - "github.com/matrix-org/dendrite/common/config" + "github.com/matrix-org/dendrite/internal/config" "github.com/matrix-org/dendrite/mediaapi/fileutils" "github.com/matrix-org/dendrite/mediaapi/storage" "github.com/matrix-org/dendrite/mediaapi/thumbnailer" diff --git a/mediaapi/storage/postgres/prepare.go b/mediaapi/storage/postgres/prepare.go index 090c3d17d..a2e01884e 100644 --- a/mediaapi/storage/postgres/prepare.go +++ b/mediaapi/storage/postgres/prepare.go @@ -13,7 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -// FIXME: This should be made common! +// FIXME: This should be made internal! package postgres diff --git a/mediaapi/storage/postgres/storage.go b/mediaapi/storage/postgres/storage.go index 4ddfc8fdf..72ee05cd8 100644 --- a/mediaapi/storage/postgres/storage.go +++ b/mediaapi/storage/postgres/storage.go @@ -21,7 +21,7 @@ import ( // Import the postgres database driver. _ "github.com/lib/pq" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/internal/sqlutil" "github.com/matrix-org/dendrite/mediaapi/types" "github.com/matrix-org/gomatrixserverlib" @@ -34,7 +34,7 @@ type Database struct { } // Open opens a postgres database. -func Open(dataSourceName string, dbProperties common.DbProperties) (*Database, error) { +func Open(dataSourceName string, dbProperties internal.DbProperties) (*Database, error) { var d Database var err error if d.db, err = sqlutil.Open("postgres", dataSourceName, dbProperties); err != nil { diff --git a/mediaapi/storage/postgres/thumbnail_table.go b/mediaapi/storage/postgres/thumbnail_table.go index 08bddc36f..dbc97cf22 100644 --- a/mediaapi/storage/postgres/thumbnail_table.go +++ b/mediaapi/storage/postgres/thumbnail_table.go @@ -20,7 +20,7 @@ import ( "database/sql" "time" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/mediaapi/types" "github.com/matrix-org/gomatrixserverlib" @@ -146,7 +146,7 @@ func (s *thumbnailStatements) selectThumbnails( if err != nil { return nil, err } - defer common.CloseAndLogIfError(ctx, rows, "selectThumbnails: rows.close() failed") + defer internal.CloseAndLogIfError(ctx, rows, "selectThumbnails: rows.close() failed") var thumbnails []*types.ThumbnailMetadata for rows.Next() { diff --git a/mediaapi/storage/sqlite3/prepare.go b/mediaapi/storage/sqlite3/prepare.go index a6bc24c98..8fb3b56f3 100644 --- a/mediaapi/storage/sqlite3/prepare.go +++ b/mediaapi/storage/sqlite3/prepare.go @@ -13,7 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -// FIXME: This should be made common! +// FIXME: This should be made internal! package sqlite3 diff --git a/mediaapi/storage/sqlite3/storage.go b/mediaapi/storage/sqlite3/storage.go index 8fa2e5375..6da7132d8 100644 --- a/mediaapi/storage/sqlite3/storage.go +++ b/mediaapi/storage/sqlite3/storage.go @@ -20,7 +20,7 @@ import ( "database/sql" // Import the postgres database driver. - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/internal/sqlutil" "github.com/matrix-org/dendrite/mediaapi/types" "github.com/matrix-org/gomatrixserverlib" @@ -37,7 +37,7 @@ type Database struct { func Open(dataSourceName string) (*Database, error) { var d Database var err error - if d.db, err = sqlutil.Open(common.SQLiteDriverName(), dataSourceName, nil); err != nil { + if d.db, err = sqlutil.Open(internal.SQLiteDriverName(), dataSourceName, nil); err != nil { return nil, err } if err = d.statements.prepare(d.db); err != nil { diff --git a/mediaapi/storage/sqlite3/thumbnail_table.go b/mediaapi/storage/sqlite3/thumbnail_table.go index 280fafe8d..a0956f68c 100644 --- a/mediaapi/storage/sqlite3/thumbnail_table.go +++ b/mediaapi/storage/sqlite3/thumbnail_table.go @@ -20,7 +20,7 @@ import ( "database/sql" "time" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/mediaapi/types" "github.com/matrix-org/gomatrixserverlib" @@ -136,7 +136,7 @@ func (s *thumbnailStatements) selectThumbnails( if err != nil { return nil, err } - defer common.CloseAndLogIfError(ctx, rows, "selectThumbnails: rows.close() failed") + defer internal.CloseAndLogIfError(ctx, rows, "selectThumbnails: rows.close() failed") var thumbnails []*types.ThumbnailMetadata for rows.Next() { diff --git a/mediaapi/storage/storage.go b/mediaapi/storage/storage.go index 6589c8304..2694e197d 100644 --- a/mediaapi/storage/storage.go +++ b/mediaapi/storage/storage.go @@ -19,13 +19,13 @@ package storage import ( "net/url" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/mediaapi/storage/postgres" "github.com/matrix-org/dendrite/mediaapi/storage/sqlite3" ) // Open opens a postgres database. -func Open(dataSourceName string, dbProperties common.DbProperties) (Database, error) { +func Open(dataSourceName string, dbProperties internal.DbProperties) (Database, error) { uri, err := url.Parse(dataSourceName) if err != nil { return postgres.Open(dataSourceName, dbProperties) diff --git a/mediaapi/storage/storage_wasm.go b/mediaapi/storage/storage_wasm.go index 3c39e5d31..78de2cb82 100644 --- a/mediaapi/storage/storage_wasm.go +++ b/mediaapi/storage/storage_wasm.go @@ -18,14 +18,14 @@ import ( "fmt" "net/url" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/mediaapi/storage/sqlite3" ) // Open opens a postgres database. func Open( dataSourceName string, - dbProperties common.DbProperties, // nolint:unparam + dbProperties internal.DbProperties, // nolint:unparam ) (Database, error) { uri, err := url.Parse(dataSourceName) if err != nil { diff --git a/mediaapi/thumbnailer/thumbnailer.go b/mediaapi/thumbnailer/thumbnailer.go index ebf5138c5..9a58b5bc1 100644 --- a/mediaapi/thumbnailer/thumbnailer.go +++ b/mediaapi/thumbnailer/thumbnailer.go @@ -22,7 +22,7 @@ import ( "path/filepath" "sync" - "github.com/matrix-org/dendrite/common/config" + "github.com/matrix-org/dendrite/internal/config" "github.com/matrix-org/dendrite/mediaapi/storage" "github.com/matrix-org/dendrite/mediaapi/types" log "github.com/sirupsen/logrus" diff --git a/mediaapi/thumbnailer/thumbnailer_bimg.go b/mediaapi/thumbnailer/thumbnailer_bimg.go index db6f23ace..915d576e3 100644 --- a/mediaapi/thumbnailer/thumbnailer_bimg.go +++ b/mediaapi/thumbnailer/thumbnailer_bimg.go @@ -21,7 +21,7 @@ import ( "os" "time" - "github.com/matrix-org/dendrite/common/config" + "github.com/matrix-org/dendrite/internal/config" "github.com/matrix-org/dendrite/mediaapi/storage" "github.com/matrix-org/dendrite/mediaapi/types" log "github.com/sirupsen/logrus" diff --git a/mediaapi/thumbnailer/thumbnailer_nfnt.go b/mediaapi/thumbnailer/thumbnailer_nfnt.go index 4f1e98aa0..b48551e4e 100644 --- a/mediaapi/thumbnailer/thumbnailer_nfnt.go +++ b/mediaapi/thumbnailer/thumbnailer_nfnt.go @@ -30,7 +30,7 @@ import ( "os" "time" - "github.com/matrix-org/dendrite/common/config" + "github.com/matrix-org/dendrite/internal/config" "github.com/matrix-org/dendrite/mediaapi/storage" "github.com/matrix-org/dendrite/mediaapi/types" "github.com/nfnt/resize" diff --git a/mediaapi/types/types.go b/mediaapi/types/types.go index 855e8fe27..9fa549509 100644 --- a/mediaapi/types/types.go +++ b/mediaapi/types/types.go @@ -17,7 +17,7 @@ package types import ( "sync" - "github.com/matrix-org/dendrite/common/config" + "github.com/matrix-org/dendrite/internal/config" "github.com/matrix-org/gomatrixserverlib" ) diff --git a/publicroomsapi/consumers/roomserver.go b/publicroomsapi/consumers/roomserver.go index efd093b7e..c513d3b24 100644 --- a/publicroomsapi/consumers/roomserver.go +++ b/publicroomsapi/consumers/roomserver.go @@ -19,8 +19,8 @@ import ( "encoding/json" "github.com/Shopify/sarama" - "github.com/matrix-org/dendrite/common" - "github.com/matrix-org/dendrite/common/config" + "github.com/matrix-org/dendrite/internal" + "github.com/matrix-org/dendrite/internal/config" "github.com/matrix-org/dendrite/publicroomsapi/storage" "github.com/matrix-org/dendrite/roomserver/api" "github.com/matrix-org/gomatrixserverlib" @@ -30,7 +30,7 @@ import ( // OutputRoomEventConsumer consumes events that originated in the room server. type OutputRoomEventConsumer struct { rsAPI api.RoomserverInternalAPI - rsConsumer *common.ContinualConsumer + rsConsumer *internal.ContinualConsumer db storage.Database } @@ -41,7 +41,7 @@ func NewOutputRoomEventConsumer( store storage.Database, rsAPI api.RoomserverInternalAPI, ) *OutputRoomEventConsumer { - consumer := common.ContinualConsumer{ + consumer := internal.ContinualConsumer{ Topic: string(cfg.Kafka.Topics.OutputRoomEvent), Consumer: kafkaConsumer, PartitionStore: store, diff --git a/publicroomsapi/publicroomsapi.go b/publicroomsapi/publicroomsapi.go index 6a4e65674..f767a5303 100644 --- a/publicroomsapi/publicroomsapi.go +++ b/publicroomsapi/publicroomsapi.go @@ -16,7 +16,7 @@ package publicroomsapi import ( "github.com/matrix-org/dendrite/clientapi/auth/storage/devices" - "github.com/matrix-org/dendrite/common/basecomponent" + "github.com/matrix-org/dendrite/internal/basecomponent" "github.com/matrix-org/dendrite/publicroomsapi/consumers" "github.com/matrix-org/dendrite/publicroomsapi/routing" "github.com/matrix-org/dendrite/publicroomsapi/storage" diff --git a/publicroomsapi/routing/routing.go b/publicroomsapi/routing/routing.go index 09a8eff76..39a9dcca1 100644 --- a/publicroomsapi/routing/routing.go +++ b/publicroomsapi/routing/routing.go @@ -23,7 +23,7 @@ import ( "github.com/matrix-org/dendrite/clientapi/auth" "github.com/matrix-org/dendrite/clientapi/auth/authtypes" "github.com/matrix-org/dendrite/clientapi/auth/storage/devices" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/publicroomsapi/directory" "github.com/matrix-org/dendrite/publicroomsapi/storage" "github.com/matrix-org/dendrite/publicroomsapi/types" @@ -51,8 +51,8 @@ func Setup( } r0mux.Handle("/directory/list/room/{roomID}", - common.MakeExternalAPI("directory_list", func(req *http.Request) util.JSONResponse { - vars, err := common.URLDecodeMapValues(mux.Vars(req)) + internal.MakeExternalAPI("directory_list", func(req *http.Request) util.JSONResponse { + vars, err := internal.URLDecodeMapValues(mux.Vars(req)) if err != nil { return util.ErrorResponse(err) } @@ -61,8 +61,8 @@ func Setup( ).Methods(http.MethodGet, http.MethodOptions) // TODO: Add AS support r0mux.Handle("/directory/list/room/{roomID}", - common.MakeAuthAPI("directory_list", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { - vars, err := common.URLDecodeMapValues(mux.Vars(req)) + internal.MakeAuthAPI("directory_list", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { + vars, err := internal.URLDecodeMapValues(mux.Vars(req)) if err != nil { return util.ErrorResponse(err) } @@ -70,7 +70,7 @@ func Setup( }), ).Methods(http.MethodPut, http.MethodOptions) r0mux.Handle("/publicRooms", - common.MakeExternalAPI("public_rooms", func(req *http.Request) util.JSONResponse { + internal.MakeExternalAPI("public_rooms", func(req *http.Request) util.JSONResponse { if extRoomsProvider != nil { return directory.GetPostPublicRoomsWithExternal(req, publicRoomsDB, fedClient, extRoomsProvider) } @@ -80,7 +80,7 @@ func Setup( // Federation - TODO: should this live here or in federation API? It's sure easier if it's here so here it is. apiMux.Handle("/_matrix/federation/v1/publicRooms", - common.MakeExternalAPI("federation_public_rooms", func(req *http.Request) util.JSONResponse { + internal.MakeExternalAPI("federation_public_rooms", func(req *http.Request) util.JSONResponse { return directory.GetPostPublicRooms(req, publicRoomsDB) }), ).Methods(http.MethodGet) diff --git a/publicroomsapi/storage/interface.go b/publicroomsapi/storage/interface.go index 0feca0e20..0ca6f455c 100644 --- a/publicroomsapi/storage/interface.go +++ b/publicroomsapi/storage/interface.go @@ -17,12 +17,12 @@ package storage import ( "context" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/gomatrixserverlib" ) type Database interface { - common.PartitionStorer + internal.PartitionStorer GetRoomVisibility(ctx context.Context, roomID string) (bool, error) SetRoomVisibility(ctx context.Context, visible bool, roomID string) error CountPublicRooms(ctx context.Context) (int64, error) diff --git a/publicroomsapi/storage/postgres/public_rooms_table.go b/publicroomsapi/storage/postgres/public_rooms_table.go index 7e31afd2a..39e355368 100644 --- a/publicroomsapi/storage/postgres/public_rooms_table.go +++ b/publicroomsapi/storage/postgres/public_rooms_table.go @@ -21,7 +21,7 @@ import ( "errors" "fmt" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/gomatrixserverlib" "github.com/lib/pq" @@ -205,7 +205,7 @@ func (s *publicRoomsStatements) selectPublicRooms( if err != nil { return []gomatrixserverlib.PublicRoom{}, nil } - defer common.CloseAndLogIfError(ctx, rows, "selectPublicRooms: rows.close() failed") + defer internal.CloseAndLogIfError(ctx, rows, "selectPublicRooms: rows.close() failed") rooms := []gomatrixserverlib.PublicRoom{} for rows.Next() { diff --git a/publicroomsapi/storage/postgres/storage.go b/publicroomsapi/storage/postgres/storage.go index 6242c9d54..691199a0b 100644 --- a/publicroomsapi/storage/postgres/storage.go +++ b/publicroomsapi/storage/postgres/storage.go @@ -20,7 +20,7 @@ import ( "database/sql" "encoding/json" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/internal/sqlutil" "github.com/matrix-org/gomatrixserverlib" @@ -29,14 +29,14 @@ import ( // PublicRoomsServerDatabase represents a public rooms server database. type PublicRoomsServerDatabase struct { db *sql.DB - common.PartitionOffsetStatements + internal.PartitionOffsetStatements statements publicRoomsStatements } type attributeValue interface{} // NewPublicRoomsServerDatabase creates a new public rooms server database. -func NewPublicRoomsServerDatabase(dataSourceName string, dbProperties common.DbProperties) (*PublicRoomsServerDatabase, error) { +func NewPublicRoomsServerDatabase(dataSourceName string, dbProperties internal.DbProperties) (*PublicRoomsServerDatabase, error) { var db *sql.DB var err error if db, err = sqlutil.Open("postgres", dataSourceName, dbProperties); err != nil { @@ -136,33 +136,33 @@ func (d *PublicRoomsServerDatabase) UpdateRoomFromEvent( case "m.room.aliases": return d.updateRoomAliases(ctx, event) case "m.room.canonical_alias": - var content common.CanonicalAliasContent + var content internal.CanonicalAliasContent field := &(content.Alias) attrName := "canonical_alias" return d.updateStringAttribute(ctx, attrName, event, &content, field) case "m.room.name": - var content common.NameContent + var content internal.NameContent field := &(content.Name) attrName := "name" return d.updateStringAttribute(ctx, attrName, event, &content, field) case "m.room.topic": - var content common.TopicContent + var content internal.TopicContent field := &(content.Topic) attrName := "topic" return d.updateStringAttribute(ctx, attrName, event, &content, field) case "m.room.avatar": - var content common.AvatarContent + var content internal.AvatarContent field := &(content.URL) attrName := "avatar_url" return d.updateStringAttribute(ctx, attrName, event, &content, field) case "m.room.history_visibility": - var content common.HistoryVisibilityContent + var content internal.HistoryVisibilityContent field := &(content.HistoryVisibility) attrName := "world_readable" strForTrue := "world_readable" return d.updateBooleanAttribute(ctx, attrName, event, &content, field, strForTrue) case "m.room.guest_access": - var content common.GuestAccessContent + var content internal.GuestAccessContent field := &(content.GuestAccess) attrName := "guest_can_join" strForTrue := "can_join" @@ -243,7 +243,7 @@ func (d *PublicRoomsServerDatabase) updateBooleanAttribute( func (d *PublicRoomsServerDatabase) updateRoomAliases( ctx context.Context, aliasesEvent gomatrixserverlib.Event, ) error { - var content common.AliasesContent + var content internal.AliasesContent if err := json.Unmarshal(aliasesEvent.Content(), &content); err != nil { return err } diff --git a/publicroomsapi/storage/sqlite3/public_rooms_table.go b/publicroomsapi/storage/sqlite3/public_rooms_table.go index 44679837f..7b332e175 100644 --- a/publicroomsapi/storage/sqlite3/public_rooms_table.go +++ b/publicroomsapi/storage/sqlite3/public_rooms_table.go @@ -22,7 +22,7 @@ import ( "errors" "fmt" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/gomatrixserverlib" ) @@ -193,7 +193,7 @@ func (s *publicRoomsStatements) selectPublicRooms( if err != nil { return []gomatrixserverlib.PublicRoom{}, nil } - defer common.CloseAndLogIfError(ctx, rows, "selectPublicRooms failed to close rows") + defer internal.CloseAndLogIfError(ctx, rows, "selectPublicRooms failed to close rows") rooms := []gomatrixserverlib.PublicRoom{} for rows.Next() { diff --git a/publicroomsapi/storage/sqlite3/storage.go b/publicroomsapi/storage/sqlite3/storage.go index efe35bdde..b81222dd3 100644 --- a/publicroomsapi/storage/sqlite3/storage.go +++ b/publicroomsapi/storage/sqlite3/storage.go @@ -22,7 +22,7 @@ import ( _ "github.com/mattn/go-sqlite3" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/internal/sqlutil" "github.com/matrix-org/gomatrixserverlib" @@ -31,7 +31,7 @@ import ( // PublicRoomsServerDatabase represents a public rooms server database. type PublicRoomsServerDatabase struct { db *sql.DB - common.PartitionOffsetStatements + internal.PartitionOffsetStatements statements publicRoomsStatements } @@ -41,7 +41,7 @@ type attributeValue interface{} func NewPublicRoomsServerDatabase(dataSourceName string) (*PublicRoomsServerDatabase, error) { var db *sql.DB var err error - if db, err = sqlutil.Open(common.SQLiteDriverName(), dataSourceName, nil); err != nil { + if db, err = sqlutil.Open(internal.SQLiteDriverName(), dataSourceName, nil); err != nil { return nil, err } storage := PublicRoomsServerDatabase{ @@ -138,33 +138,33 @@ func (d *PublicRoomsServerDatabase) UpdateRoomFromEvent( case "m.room.aliases": return d.updateRoomAliases(ctx, event) case "m.room.canonical_alias": - var content common.CanonicalAliasContent + var content internal.CanonicalAliasContent field := &(content.Alias) attrName := "canonical_alias" return d.updateStringAttribute(ctx, attrName, event, &content, field) case "m.room.name": - var content common.NameContent + var content internal.NameContent field := &(content.Name) attrName := "name" return d.updateStringAttribute(ctx, attrName, event, &content, field) case "m.room.topic": - var content common.TopicContent + var content internal.TopicContent field := &(content.Topic) attrName := "topic" return d.updateStringAttribute(ctx, attrName, event, &content, field) case "m.room.avatar": - var content common.AvatarContent + var content internal.AvatarContent field := &(content.URL) attrName := "avatar_url" return d.updateStringAttribute(ctx, attrName, event, &content, field) case "m.room.history_visibility": - var content common.HistoryVisibilityContent + var content internal.HistoryVisibilityContent field := &(content.HistoryVisibility) attrName := "world_readable" strForTrue := "world_readable" return d.updateBooleanAttribute(ctx, attrName, event, &content, field, strForTrue) case "m.room.guest_access": - var content common.GuestAccessContent + var content internal.GuestAccessContent field := &(content.GuestAccess) attrName := "guest_can_join" strForTrue := "can_join" @@ -245,7 +245,7 @@ func (d *PublicRoomsServerDatabase) updateBooleanAttribute( func (d *PublicRoomsServerDatabase) updateRoomAliases( ctx context.Context, aliasesEvent gomatrixserverlib.Event, ) error { - var content common.AliasesContent + var content internal.AliasesContent if err := json.Unmarshal(aliasesEvent.Content(), &content); err != nil { return err } diff --git a/publicroomsapi/storage/storage.go b/publicroomsapi/storage/storage.go index 7dcfe5633..978d9a3c9 100644 --- a/publicroomsapi/storage/storage.go +++ b/publicroomsapi/storage/storage.go @@ -19,7 +19,7 @@ package storage import ( "net/url" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/publicroomsapi/storage/postgres" "github.com/matrix-org/dendrite/publicroomsapi/storage/sqlite3" ) @@ -28,7 +28,7 @@ const schemePostgres = "postgres" const schemeFile = "file" // NewPublicRoomsServerDatabase opens a database connection. -func NewPublicRoomsServerDatabase(dataSourceName string, dbProperties common.DbProperties) (Database, error) { +func NewPublicRoomsServerDatabase(dataSourceName string, dbProperties internal.DbProperties) (Database, error) { uri, err := url.Parse(dataSourceName) if err != nil { return postgres.NewPublicRoomsServerDatabase(dataSourceName, dbProperties) diff --git a/roomserver/api/alias.go b/roomserver/api/alias.go index 488e99ab8..93975d36c 100644 --- a/roomserver/api/alias.go +++ b/roomserver/api/alias.go @@ -17,7 +17,7 @@ package api import ( "context" - commonHTTP "github.com/matrix-org/dendrite/common/http" + internalHTTP "github.com/matrix-org/dendrite/internal/http" opentracing "github.com/opentracing/opentracing-go" ) @@ -109,7 +109,7 @@ func (h *httpRoomserverInternalAPI) SetRoomAlias( defer span.Finish() apiURL := h.roomserverURL + RoomserverSetRoomAliasPath - return commonHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response) + return internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response) } // GetRoomIDForAlias implements RoomserverAliasAPI @@ -122,7 +122,7 @@ func (h *httpRoomserverInternalAPI) GetRoomIDForAlias( defer span.Finish() apiURL := h.roomserverURL + RoomserverGetRoomIDForAliasPath - return commonHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response) + return internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response) } // GetAliasesForRoomID implements RoomserverAliasAPI @@ -135,7 +135,7 @@ func (h *httpRoomserverInternalAPI) GetAliasesForRoomID( defer span.Finish() apiURL := h.roomserverURL + RoomserverGetAliasesForRoomIDPath - return commonHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response) + return internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response) } // GetCreatorIDForAlias implements RoomserverAliasAPI @@ -148,7 +148,7 @@ func (h *httpRoomserverInternalAPI) GetCreatorIDForAlias( defer span.Finish() apiURL := h.roomserverURL + RoomserverGetCreatorIDForAliasPath - return commonHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response) + return internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response) } // RemoveRoomAlias implements RoomserverAliasAPI @@ -161,5 +161,5 @@ func (h *httpRoomserverInternalAPI) RemoveRoomAlias( defer span.Finish() apiURL := h.roomserverURL + RoomserverRemoveRoomAliasPath - return commonHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response) + return internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response) } diff --git a/roomserver/api/http.go b/roomserver/api/http.go index d643526bd..8a4d72e4e 100644 --- a/roomserver/api/http.go +++ b/roomserver/api/http.go @@ -4,8 +4,8 @@ import ( "errors" "net/http" - "github.com/matrix-org/dendrite/common/caching" fsInputAPI "github.com/matrix-org/dendrite/federationsender/api" + "github.com/matrix-org/dendrite/internal/caching" ) type httpRoomserverInternalAPI struct { diff --git a/roomserver/api/input.go b/roomserver/api/input.go index 8e8fdae4e..f1eec75a8 100644 --- a/roomserver/api/input.go +++ b/roomserver/api/input.go @@ -18,7 +18,7 @@ package api import ( "context" - commonHTTP "github.com/matrix-org/dendrite/common/http" + internalHTTP "github.com/matrix-org/dendrite/internal/http" "github.com/matrix-org/gomatrixserverlib" opentracing "github.com/opentracing/opentracing-go" ) @@ -115,5 +115,5 @@ func (h *httpRoomserverInternalAPI) InputRoomEvents( defer span.Finish() apiURL := h.roomserverURL + RoomserverInputRoomEventsPath - return commonHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response) + return internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response) } diff --git a/roomserver/api/perform.go b/roomserver/api/perform.go index e60c078bc..93f36f451 100644 --- a/roomserver/api/perform.go +++ b/roomserver/api/perform.go @@ -3,7 +3,7 @@ package api import ( "context" - commonHTTP "github.com/matrix-org/dendrite/common/http" + internalHTTP "github.com/matrix-org/dendrite/internal/http" "github.com/matrix-org/gomatrixserverlib" "github.com/opentracing/opentracing-go" ) @@ -35,7 +35,7 @@ func (h *httpRoomserverInternalAPI) PerformJoin( defer span.Finish() apiURL := h.roomserverURL + RoomserverPerformJoinPath - return commonHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response) + return internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response) } type PerformLeaveRequest struct { @@ -55,5 +55,5 @@ func (h *httpRoomserverInternalAPI) PerformLeave( defer span.Finish() apiURL := h.roomserverURL + RoomserverPerformLeavePath - return commonHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response) + return internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response) } diff --git a/roomserver/api/query.go b/roomserver/api/query.go index e92d2a992..98f46c771 100644 --- a/roomserver/api/query.go +++ b/roomserver/api/query.go @@ -19,7 +19,7 @@ package api import ( "context" - commonHTTP "github.com/matrix-org/dendrite/common/http" + internalHTTP "github.com/matrix-org/dendrite/internal/http" "github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/util" opentracing "github.com/opentracing/opentracing-go" @@ -318,7 +318,7 @@ func (h *httpRoomserverInternalAPI) QueryLatestEventsAndState( defer span.Finish() apiURL := h.roomserverURL + RoomserverQueryLatestEventsAndStatePath - return commonHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response) + return internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response) } // QueryStateAfterEvents implements RoomserverQueryAPI @@ -331,7 +331,7 @@ func (h *httpRoomserverInternalAPI) QueryStateAfterEvents( defer span.Finish() apiURL := h.roomserverURL + RoomserverQueryStateAfterEventsPath - return commonHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response) + return internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response) } // QueryEventsByID implements RoomserverQueryAPI @@ -344,7 +344,7 @@ func (h *httpRoomserverInternalAPI) QueryEventsByID( defer span.Finish() apiURL := h.roomserverURL + RoomserverQueryEventsByIDPath - return commonHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response) + return internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response) } // QueryMembershipForUser implements RoomserverQueryAPI @@ -357,7 +357,7 @@ func (h *httpRoomserverInternalAPI) QueryMembershipForUser( defer span.Finish() apiURL := h.roomserverURL + RoomserverQueryMembershipForUserPath - return commonHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response) + return internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response) } // QueryMembershipsForRoom implements RoomserverQueryAPI @@ -370,7 +370,7 @@ func (h *httpRoomserverInternalAPI) QueryMembershipsForRoom( defer span.Finish() apiURL := h.roomserverURL + RoomserverQueryMembershipsForRoomPath - return commonHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response) + return internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response) } // QueryInvitesForUser implements RoomserverQueryAPI @@ -383,7 +383,7 @@ func (h *httpRoomserverInternalAPI) QueryInvitesForUser( defer span.Finish() apiURL := h.roomserverURL + RoomserverQueryInvitesForUserPath - return commonHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response) + return internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response) } // QueryServerAllowedToSeeEvent implements RoomserverQueryAPI @@ -396,7 +396,7 @@ func (h *httpRoomserverInternalAPI) QueryServerAllowedToSeeEvent( defer span.Finish() apiURL := h.roomserverURL + RoomserverQueryServerAllowedToSeeEventPath - return commonHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response) + return internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response) } // QueryMissingEvents implements RoomServerQueryAPI @@ -409,7 +409,7 @@ func (h *httpRoomserverInternalAPI) QueryMissingEvents( defer span.Finish() apiURL := h.roomserverURL + RoomserverQueryMissingEventsPath - return commonHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response) + return internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response) } // QueryStateAndAuthChain implements RoomserverQueryAPI @@ -422,7 +422,7 @@ func (h *httpRoomserverInternalAPI) QueryStateAndAuthChain( defer span.Finish() apiURL := h.roomserverURL + RoomserverQueryStateAndAuthChainPath - return commonHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response) + return internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response) } // QueryBackfill implements RoomServerQueryAPI @@ -435,7 +435,7 @@ func (h *httpRoomserverInternalAPI) QueryBackfill( defer span.Finish() apiURL := h.roomserverURL + RoomserverQueryBackfillPath - return commonHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response) + return internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response) } // QueryRoomVersionCapabilities implements RoomServerQueryAPI @@ -448,7 +448,7 @@ func (h *httpRoomserverInternalAPI) QueryRoomVersionCapabilities( defer span.Finish() apiURL := h.roomserverURL + RoomserverQueryRoomVersionCapabilitiesPath - return commonHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response) + return internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response) } // QueryRoomVersionForRoom implements RoomServerQueryAPI @@ -466,7 +466,7 @@ func (h *httpRoomserverInternalAPI) QueryRoomVersionForRoom( defer span.Finish() apiURL := h.roomserverURL + RoomserverQueryRoomVersionForRoomPath - err := commonHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response) + err := internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response) if err == nil { h.immutableCache.StoreRoomVersion(request.RoomID, response.RoomVersion) } diff --git a/roomserver/internal/api.go b/roomserver/internal/api.go index 62389c237..4d223cf36 100644 --- a/roomserver/internal/api.go +++ b/roomserver/internal/api.go @@ -6,10 +6,10 @@ import ( "sync" "github.com/Shopify/sarama" - "github.com/matrix-org/dendrite/common" - "github.com/matrix-org/dendrite/common/caching" - "github.com/matrix-org/dendrite/common/config" fsAPI "github.com/matrix-org/dendrite/federationsender/api" + "github.com/matrix-org/dendrite/internal" + "github.com/matrix-org/dendrite/internal/caching" + "github.com/matrix-org/dendrite/internal/config" "github.com/matrix-org/dendrite/roomserver/api" "github.com/matrix-org/dendrite/roomserver/storage" "github.com/matrix-org/gomatrixserverlib" @@ -34,7 +34,7 @@ type RoomserverInternalAPI struct { // nolint: gocyclo func (r *RoomserverInternalAPI) SetupHTTP(servMux *http.ServeMux) { servMux.Handle(api.RoomserverInputRoomEventsPath, - common.MakeInternalAPI("inputRoomEvents", func(req *http.Request) util.JSONResponse { + internal.MakeInternalAPI("inputRoomEvents", func(req *http.Request) util.JSONResponse { var request api.InputRoomEventsRequest var response api.InputRoomEventsResponse if err := json.NewDecoder(req.Body).Decode(&request); err != nil { @@ -47,7 +47,7 @@ func (r *RoomserverInternalAPI) SetupHTTP(servMux *http.ServeMux) { }), ) servMux.Handle(api.RoomserverPerformJoinPath, - common.MakeInternalAPI("performJoin", func(req *http.Request) util.JSONResponse { + internal.MakeInternalAPI("performJoin", func(req *http.Request) util.JSONResponse { var request api.PerformJoinRequest var response api.PerformJoinResponse if err := json.NewDecoder(req.Body).Decode(&request); err != nil { @@ -60,7 +60,7 @@ func (r *RoomserverInternalAPI) SetupHTTP(servMux *http.ServeMux) { }), ) servMux.Handle(api.RoomserverPerformLeavePath, - common.MakeInternalAPI("performLeave", func(req *http.Request) util.JSONResponse { + internal.MakeInternalAPI("performLeave", func(req *http.Request) util.JSONResponse { var request api.PerformLeaveRequest var response api.PerformLeaveResponse if err := json.NewDecoder(req.Body).Decode(&request); err != nil { @@ -74,7 +74,7 @@ func (r *RoomserverInternalAPI) SetupHTTP(servMux *http.ServeMux) { ) servMux.Handle( api.RoomserverQueryLatestEventsAndStatePath, - common.MakeInternalAPI("queryLatestEventsAndState", func(req *http.Request) util.JSONResponse { + internal.MakeInternalAPI("queryLatestEventsAndState", func(req *http.Request) util.JSONResponse { var request api.QueryLatestEventsAndStateRequest var response api.QueryLatestEventsAndStateResponse if err := json.NewDecoder(req.Body).Decode(&request); err != nil { @@ -88,7 +88,7 @@ func (r *RoomserverInternalAPI) SetupHTTP(servMux *http.ServeMux) { ) servMux.Handle( api.RoomserverQueryStateAfterEventsPath, - common.MakeInternalAPI("queryStateAfterEvents", func(req *http.Request) util.JSONResponse { + internal.MakeInternalAPI("queryStateAfterEvents", func(req *http.Request) util.JSONResponse { var request api.QueryStateAfterEventsRequest var response api.QueryStateAfterEventsResponse if err := json.NewDecoder(req.Body).Decode(&request); err != nil { @@ -102,7 +102,7 @@ func (r *RoomserverInternalAPI) SetupHTTP(servMux *http.ServeMux) { ) servMux.Handle( api.RoomserverQueryEventsByIDPath, - common.MakeInternalAPI("queryEventsByID", func(req *http.Request) util.JSONResponse { + internal.MakeInternalAPI("queryEventsByID", func(req *http.Request) util.JSONResponse { var request api.QueryEventsByIDRequest var response api.QueryEventsByIDResponse if err := json.NewDecoder(req.Body).Decode(&request); err != nil { @@ -116,7 +116,7 @@ func (r *RoomserverInternalAPI) SetupHTTP(servMux *http.ServeMux) { ) servMux.Handle( api.RoomserverQueryMembershipForUserPath, - common.MakeInternalAPI("QueryMembershipForUser", func(req *http.Request) util.JSONResponse { + internal.MakeInternalAPI("QueryMembershipForUser", func(req *http.Request) util.JSONResponse { var request api.QueryMembershipForUserRequest var response api.QueryMembershipForUserResponse if err := json.NewDecoder(req.Body).Decode(&request); err != nil { @@ -130,7 +130,7 @@ func (r *RoomserverInternalAPI) SetupHTTP(servMux *http.ServeMux) { ) servMux.Handle( api.RoomserverQueryMembershipsForRoomPath, - common.MakeInternalAPI("queryMembershipsForRoom", func(req *http.Request) util.JSONResponse { + internal.MakeInternalAPI("queryMembershipsForRoom", func(req *http.Request) util.JSONResponse { var request api.QueryMembershipsForRoomRequest var response api.QueryMembershipsForRoomResponse if err := json.NewDecoder(req.Body).Decode(&request); err != nil { @@ -144,7 +144,7 @@ func (r *RoomserverInternalAPI) SetupHTTP(servMux *http.ServeMux) { ) servMux.Handle( api.RoomserverQueryInvitesForUserPath, - common.MakeInternalAPI("queryInvitesForUser", func(req *http.Request) util.JSONResponse { + internal.MakeInternalAPI("queryInvitesForUser", func(req *http.Request) util.JSONResponse { var request api.QueryInvitesForUserRequest var response api.QueryInvitesForUserResponse if err := json.NewDecoder(req.Body).Decode(&request); err != nil { @@ -158,7 +158,7 @@ func (r *RoomserverInternalAPI) SetupHTTP(servMux *http.ServeMux) { ) servMux.Handle( api.RoomserverQueryServerAllowedToSeeEventPath, - common.MakeInternalAPI("queryServerAllowedToSeeEvent", func(req *http.Request) util.JSONResponse { + internal.MakeInternalAPI("queryServerAllowedToSeeEvent", func(req *http.Request) util.JSONResponse { var request api.QueryServerAllowedToSeeEventRequest var response api.QueryServerAllowedToSeeEventResponse if err := json.NewDecoder(req.Body).Decode(&request); err != nil { @@ -172,7 +172,7 @@ func (r *RoomserverInternalAPI) SetupHTTP(servMux *http.ServeMux) { ) servMux.Handle( api.RoomserverQueryMissingEventsPath, - common.MakeInternalAPI("queryMissingEvents", func(req *http.Request) util.JSONResponse { + internal.MakeInternalAPI("queryMissingEvents", func(req *http.Request) util.JSONResponse { var request api.QueryMissingEventsRequest var response api.QueryMissingEventsResponse if err := json.NewDecoder(req.Body).Decode(&request); err != nil { @@ -186,7 +186,7 @@ func (r *RoomserverInternalAPI) SetupHTTP(servMux *http.ServeMux) { ) servMux.Handle( api.RoomserverQueryStateAndAuthChainPath, - common.MakeInternalAPI("queryStateAndAuthChain", func(req *http.Request) util.JSONResponse { + internal.MakeInternalAPI("queryStateAndAuthChain", func(req *http.Request) util.JSONResponse { var request api.QueryStateAndAuthChainRequest var response api.QueryStateAndAuthChainResponse if err := json.NewDecoder(req.Body).Decode(&request); err != nil { @@ -200,7 +200,7 @@ func (r *RoomserverInternalAPI) SetupHTTP(servMux *http.ServeMux) { ) servMux.Handle( api.RoomserverQueryBackfillPath, - common.MakeInternalAPI("QueryBackfill", func(req *http.Request) util.JSONResponse { + internal.MakeInternalAPI("QueryBackfill", func(req *http.Request) util.JSONResponse { var request api.QueryBackfillRequest var response api.QueryBackfillResponse if err := json.NewDecoder(req.Body).Decode(&request); err != nil { @@ -214,7 +214,7 @@ func (r *RoomserverInternalAPI) SetupHTTP(servMux *http.ServeMux) { ) servMux.Handle( api.RoomserverQueryRoomVersionCapabilitiesPath, - common.MakeInternalAPI("QueryRoomVersionCapabilities", func(req *http.Request) util.JSONResponse { + internal.MakeInternalAPI("QueryRoomVersionCapabilities", func(req *http.Request) util.JSONResponse { var request api.QueryRoomVersionCapabilitiesRequest var response api.QueryRoomVersionCapabilitiesResponse if err := json.NewDecoder(req.Body).Decode(&request); err != nil { @@ -228,7 +228,7 @@ func (r *RoomserverInternalAPI) SetupHTTP(servMux *http.ServeMux) { ) servMux.Handle( api.RoomserverQueryRoomVersionForRoomPath, - common.MakeInternalAPI("QueryRoomVersionForRoom", func(req *http.Request) util.JSONResponse { + internal.MakeInternalAPI("QueryRoomVersionForRoom", func(req *http.Request) util.JSONResponse { var request api.QueryRoomVersionForRoomRequest var response api.QueryRoomVersionForRoomResponse if err := json.NewDecoder(req.Body).Decode(&request); err != nil { @@ -242,7 +242,7 @@ func (r *RoomserverInternalAPI) SetupHTTP(servMux *http.ServeMux) { ) servMux.Handle( api.RoomserverSetRoomAliasPath, - common.MakeInternalAPI("setRoomAlias", func(req *http.Request) util.JSONResponse { + internal.MakeInternalAPI("setRoomAlias", func(req *http.Request) util.JSONResponse { var request api.SetRoomAliasRequest var response api.SetRoomAliasResponse if err := json.NewDecoder(req.Body).Decode(&request); err != nil { @@ -256,7 +256,7 @@ func (r *RoomserverInternalAPI) SetupHTTP(servMux *http.ServeMux) { ) servMux.Handle( api.RoomserverGetRoomIDForAliasPath, - common.MakeInternalAPI("GetRoomIDForAlias", func(req *http.Request) util.JSONResponse { + internal.MakeInternalAPI("GetRoomIDForAlias", func(req *http.Request) util.JSONResponse { var request api.GetRoomIDForAliasRequest var response api.GetRoomIDForAliasResponse if err := json.NewDecoder(req.Body).Decode(&request); err != nil { @@ -270,7 +270,7 @@ func (r *RoomserverInternalAPI) SetupHTTP(servMux *http.ServeMux) { ) servMux.Handle( api.RoomserverGetCreatorIDForAliasPath, - common.MakeInternalAPI("GetCreatorIDForAlias", func(req *http.Request) util.JSONResponse { + internal.MakeInternalAPI("GetCreatorIDForAlias", func(req *http.Request) util.JSONResponse { var request api.GetCreatorIDForAliasRequest var response api.GetCreatorIDForAliasResponse if err := json.NewDecoder(req.Body).Decode(&request); err != nil { @@ -284,7 +284,7 @@ func (r *RoomserverInternalAPI) SetupHTTP(servMux *http.ServeMux) { ) servMux.Handle( api.RoomserverGetAliasesForRoomIDPath, - common.MakeInternalAPI("getAliasesForRoomID", func(req *http.Request) util.JSONResponse { + internal.MakeInternalAPI("getAliasesForRoomID", func(req *http.Request) util.JSONResponse { var request api.GetAliasesForRoomIDRequest var response api.GetAliasesForRoomIDResponse if err := json.NewDecoder(req.Body).Decode(&request); err != nil { @@ -298,7 +298,7 @@ func (r *RoomserverInternalAPI) SetupHTTP(servMux *http.ServeMux) { ) servMux.Handle( api.RoomserverRemoveRoomAliasPath, - common.MakeInternalAPI("removeRoomAlias", func(req *http.Request) util.JSONResponse { + internal.MakeInternalAPI("removeRoomAlias", func(req *http.Request) util.JSONResponse { var request api.RemoveRoomAliasRequest var response api.RemoveRoomAliasResponse if err := json.NewDecoder(req.Body).Decode(&request); err != nil { diff --git a/roomserver/internal/input_events.go b/roomserver/internal/input_events.go index a4167714d..3a38636f8 100644 --- a/roomserver/internal/input_events.go +++ b/roomserver/internal/input_events.go @@ -21,7 +21,7 @@ import ( "errors" "fmt" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/roomserver/api" "github.com/matrix-org/dendrite/roomserver/state" "github.com/matrix-org/dendrite/roomserver/storage" @@ -177,7 +177,7 @@ func (r *RoomserverInternalAPI) processInviteEvent( } succeeded := false defer func() { - txerr := common.EndTransaction(updater, &succeeded) + txerr := internal.EndTransaction(updater, &succeeded) if err == nil && txerr != nil { err = txerr } diff --git a/roomserver/internal/input_latest_events.go b/roomserver/internal/input_latest_events.go index d7c9a5cb6..aea85ca95 100644 --- a/roomserver/internal/input_latest_events.go +++ b/roomserver/internal/input_latest_events.go @@ -20,7 +20,7 @@ import ( "bytes" "context" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/roomserver/api" "github.com/matrix-org/dendrite/roomserver/state" "github.com/matrix-org/dendrite/roomserver/types" @@ -59,7 +59,7 @@ func (r *RoomserverInternalAPI) updateLatestEvents( } succeeded := false defer func() { - txerr := common.EndTransaction(updater, &succeeded) + txerr := internal.EndTransaction(updater, &succeeded) if err == nil && txerr != nil { err = txerr } diff --git a/roomserver/internal/perform_join.go b/roomserver/internal/perform_join.go index 8f2f84e0f..dc786b296 100644 --- a/roomserver/internal/perform_join.go +++ b/roomserver/internal/perform_join.go @@ -6,8 +6,8 @@ import ( "strings" "time" - "github.com/matrix-org/dendrite/common" fsAPI "github.com/matrix-org/dendrite/federationsender/api" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/roomserver/api" "github.com/matrix-org/gomatrixserverlib" "github.com/sirupsen/logrus" @@ -143,7 +143,7 @@ func (r *RoomserverInternalAPI) performJoinRoomByID( // TODO: Check what happens if the room exists on the server // but everyone has since left. I suspect it does the wrong thing. buildRes := api.QueryLatestEventsAndStateResponse{} - event, err := common.BuildEvent( + event, err := internal.BuildEvent( ctx, // the request context &eb, // the template join event r.Cfg, // the server configuration @@ -186,7 +186,7 @@ func (r *RoomserverInternalAPI) performJoinRoomByID( } } - case common.ErrRoomNoExists: + case internal.ErrRoomNoExists: // The room doesn't exist. First of all check if the room is a local // room. If it is then there's nothing more to do - the room just // hasn't been created yet. diff --git a/roomserver/internal/perform_leave.go b/roomserver/internal/perform_leave.go index 5d9b251c9..b60c2e99f 100644 --- a/roomserver/internal/perform_leave.go +++ b/roomserver/internal/perform_leave.go @@ -6,8 +6,8 @@ import ( "strings" "time" - "github.com/matrix-org/dendrite/common" fsAPI "github.com/matrix-org/dendrite/federationsender/api" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/roomserver/api" "github.com/matrix-org/gomatrixserverlib" ) @@ -97,7 +97,7 @@ func (r *RoomserverInternalAPI) performLeaveRoomByID( // TODO: Check what happens if the room exists on the server // but everyone has since left. I suspect it does the wrong thing. buildRes := api.QueryLatestEventsAndStateResponse{} - event, err := common.BuildEvent( + event, err := internal.BuildEvent( ctx, // the request context &eb, // the template leave event r.Cfg, // the server configuration @@ -106,7 +106,7 @@ func (r *RoomserverInternalAPI) performLeaveRoomByID( &buildRes, // the query response ) if err != nil { - return fmt.Errorf("common.BuildEvent: %w", err) + return fmt.Errorf("internal.BuildEvent: %w", err) } // Give our leave event to the roomserver input stream. The diff --git a/roomserver/internal/query_test.go b/roomserver/internal/query_test.go index 211ab5083..92e008324 100644 --- a/roomserver/internal/query_test.go +++ b/roomserver/internal/query_test.go @@ -19,7 +19,7 @@ import ( "encoding/json" "testing" - "github.com/matrix-org/dendrite/common/test" + "github.com/matrix-org/dendrite/internal/test" "github.com/matrix-org/dendrite/roomserver/types" "github.com/matrix-org/gomatrixserverlib" ) diff --git a/roomserver/roomserver.go b/roomserver/roomserver.go index aa5d223e9..07250e7ce 100644 --- a/roomserver/roomserver.go +++ b/roomserver/roomserver.go @@ -20,7 +20,7 @@ import ( "github.com/matrix-org/dendrite/roomserver/api" "github.com/matrix-org/gomatrixserverlib" - "github.com/matrix-org/dendrite/common/basecomponent" + "github.com/matrix-org/dendrite/internal/basecomponent" "github.com/matrix-org/dendrite/roomserver/internal" "github.com/matrix-org/dendrite/roomserver/storage" "github.com/sirupsen/logrus" diff --git a/roomserver/state/state.go b/roomserver/state/state.go index 9b005ee6a..d5be4a901 100644 --- a/roomserver/state/state.go +++ b/roomserver/state/state.go @@ -567,7 +567,7 @@ func (v StateResolution) CalculateAndStoreStateAfterEvents( // 3) None of the previous events were state events and they all // have the same state, so this event has exactly the same state // as the previous events. - // This should be the common case. + // This should be the internal case. metrics.algorithm = "no_change" return metrics.stop(prevState.BeforeStateSnapshotNID, nil) } diff --git a/roomserver/storage/postgres/event_json_table.go b/roomserver/storage/postgres/event_json_table.go index 616eaf318..661c44721 100644 --- a/roomserver/storage/postgres/event_json_table.go +++ b/roomserver/storage/postgres/event_json_table.go @@ -19,7 +19,7 @@ import ( "context" "database/sql" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/roomserver/types" ) @@ -88,7 +88,7 @@ func (s *eventJSONStatements) bulkSelectEventJSON( if err != nil { return nil, err } - defer common.CloseAndLogIfError(ctx, rows, "bulkSelectEventJSON: rows.close() failed") + defer internal.CloseAndLogIfError(ctx, rows, "bulkSelectEventJSON: rows.close() failed") // We know that we will only get as many results as event NIDs // because of the unique constraint on event NIDs. diff --git a/roomserver/storage/postgres/event_state_keys_table.go b/roomserver/storage/postgres/event_state_keys_table.go index 4c3496d91..b213e057b 100644 --- a/roomserver/storage/postgres/event_state_keys_table.go +++ b/roomserver/storage/postgres/event_state_keys_table.go @@ -20,7 +20,7 @@ import ( "database/sql" "github.com/lib/pq" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/roomserver/types" ) @@ -91,7 +91,7 @@ func (s *eventStateKeyStatements) insertEventStateKeyNID( ctx context.Context, txn *sql.Tx, eventStateKey string, ) (types.EventStateKeyNID, error) { var eventStateKeyNID int64 - stmt := common.TxStmt(txn, s.insertEventStateKeyNIDStmt) + stmt := internal.TxStmt(txn, s.insertEventStateKeyNIDStmt) err := stmt.QueryRowContext(ctx, eventStateKey).Scan(&eventStateKeyNID) return types.EventStateKeyNID(eventStateKeyNID), err } @@ -100,7 +100,7 @@ func (s *eventStateKeyStatements) selectEventStateKeyNID( ctx context.Context, txn *sql.Tx, eventStateKey string, ) (types.EventStateKeyNID, error) { var eventStateKeyNID int64 - stmt := common.TxStmt(txn, s.selectEventStateKeyNIDStmt) + stmt := internal.TxStmt(txn, s.selectEventStateKeyNIDStmt) err := stmt.QueryRowContext(ctx, eventStateKey).Scan(&eventStateKeyNID) return types.EventStateKeyNID(eventStateKeyNID), err } @@ -114,7 +114,7 @@ func (s *eventStateKeyStatements) bulkSelectEventStateKeyNID( if err != nil { return nil, err } - defer common.CloseAndLogIfError(ctx, rows, "bulkSelectEventStateKeyNID: rows.close() failed") + defer internal.CloseAndLogIfError(ctx, rows, "bulkSelectEventStateKeyNID: rows.close() failed") result := make(map[string]types.EventStateKeyNID, len(eventStateKeys)) for rows.Next() { @@ -139,7 +139,7 @@ func (s *eventStateKeyStatements) bulkSelectEventStateKey( if err != nil { return nil, err } - defer common.CloseAndLogIfError(ctx, rows, "bulkSelectEventStateKey: rows.close() failed") + defer internal.CloseAndLogIfError(ctx, rows, "bulkSelectEventStateKey: rows.close() failed") result := make(map[types.EventStateKeyNID]string, len(eventStateKeyNIDs)) for rows.Next() { diff --git a/roomserver/storage/postgres/event_types_table.go b/roomserver/storage/postgres/event_types_table.go index 6537a5457..2b0910e71 100644 --- a/roomserver/storage/postgres/event_types_table.go +++ b/roomserver/storage/postgres/event_types_table.go @@ -19,7 +19,7 @@ import ( "context" "database/sql" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/lib/pq" "github.com/matrix-org/dendrite/roomserver/types" @@ -27,7 +27,7 @@ import ( const eventTypesSchema = ` -- Numeric versions of the event "type"s. Event types tend to be taken from a --- small common pool. Assigning each a numeric ID should reduce the amount of +-- small internal pool. Assigning each a numeric ID should reduce the amount of -- data that needs to be stored and fetched from the database. -- It also means that many operations can work with int64 arrays rather than -- string arrays which may help reduce GC pressure. @@ -42,7 +42,7 @@ const eventTypesSchema = ` -- Picking well-known numeric IDs for the events types that require special -- attention during state conflict resolution means that we write that code -- using numeric constants. --- It also means that the numeric IDs for common event types should be +-- It also means that the numeric IDs for internal event types should be -- consistent between different instances which might make ad-hoc debugging -- easier. -- Other event types are automatically assigned numeric IDs starting from 2**16. @@ -134,7 +134,7 @@ func (s *eventTypeStatements) bulkSelectEventTypeNID( if err != nil { return nil, err } - defer common.CloseAndLogIfError(ctx, rows, "bulkSelectEventTypeNID: rows.close() failed") + defer internal.CloseAndLogIfError(ctx, rows, "bulkSelectEventTypeNID: rows.close() failed") result := make(map[string]types.EventTypeNID, len(eventTypes)) for rows.Next() { diff --git a/roomserver/storage/postgres/events_table.go b/roomserver/storage/postgres/events_table.go index ecc35f37a..c28fa8e6b 100644 --- a/roomserver/storage/postgres/events_table.go +++ b/roomserver/storage/postgres/events_table.go @@ -21,7 +21,7 @@ import ( "fmt" "github.com/lib/pq" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/roomserver/types" "github.com/matrix-org/gomatrixserverlib" ) @@ -197,7 +197,7 @@ func (s *eventStatements) bulkSelectStateEventByID( if err != nil { return nil, err } - defer common.CloseAndLogIfError(ctx, rows, "bulkSelectStateEventByID: rows.close() failed") + defer internal.CloseAndLogIfError(ctx, rows, "bulkSelectStateEventByID: rows.close() failed") // We know that we will only get as many results as event IDs // because of the unique constraint on event IDs. // So we can allocate an array of the correct size now. @@ -222,7 +222,7 @@ func (s *eventStatements) bulkSelectStateEventByID( // We don't know which ones were missing because we don't return the string IDs in the query. // However it should be possible debug this by replaying queries or entries from the input kafka logs. // If this turns out to be impossible and we do need the debug information here, it would be better - // to do it as a separate query rather than slowing down/complicating the common case. + // to do it as a separate query rather than slowing down/complicating the internal case. return nil, types.MissingEventError( fmt.Sprintf("storage: state event IDs missing from the database (%d != %d)", i, len(eventIDs)), ) @@ -240,7 +240,7 @@ func (s *eventStatements) bulkSelectStateAtEventByID( if err != nil { return nil, err } - defer common.CloseAndLogIfError(ctx, rows, "bulkSelectStateAtEventByID: rows.close() failed") + defer internal.CloseAndLogIfError(ctx, rows, "bulkSelectStateAtEventByID: rows.close() failed") results := make([]types.StateAtEvent, len(eventIDs)) i := 0 for ; rows.Next(); i++ { @@ -280,13 +280,13 @@ func (s *eventStatements) updateEventState( func (s *eventStatements) selectEventSentToOutput( ctx context.Context, txn *sql.Tx, eventNID types.EventNID, ) (sentToOutput bool, err error) { - stmt := common.TxStmt(txn, s.selectEventSentToOutputStmt) + stmt := internal.TxStmt(txn, s.selectEventSentToOutputStmt) err = stmt.QueryRowContext(ctx, int64(eventNID)).Scan(&sentToOutput) return } func (s *eventStatements) updateEventSentToOutput(ctx context.Context, txn *sql.Tx, eventNID types.EventNID) error { - stmt := common.TxStmt(txn, s.updateEventSentToOutputStmt) + stmt := internal.TxStmt(txn, s.updateEventSentToOutputStmt) _, err := stmt.ExecContext(ctx, int64(eventNID)) return err } @@ -294,7 +294,7 @@ func (s *eventStatements) updateEventSentToOutput(ctx context.Context, txn *sql. func (s *eventStatements) selectEventID( ctx context.Context, txn *sql.Tx, eventNID types.EventNID, ) (eventID string, err error) { - stmt := common.TxStmt(txn, s.selectEventIDStmt) + stmt := internal.TxStmt(txn, s.selectEventIDStmt) err = stmt.QueryRowContext(ctx, int64(eventNID)).Scan(&eventID) return } @@ -302,12 +302,12 @@ func (s *eventStatements) selectEventID( func (s *eventStatements) bulkSelectStateAtEventAndReference( ctx context.Context, txn *sql.Tx, eventNIDs []types.EventNID, ) ([]types.StateAtEventAndReference, error) { - stmt := common.TxStmt(txn, s.bulkSelectStateAtEventAndReferenceStmt) + stmt := internal.TxStmt(txn, s.bulkSelectStateAtEventAndReferenceStmt) rows, err := stmt.QueryContext(ctx, eventNIDsAsArray(eventNIDs)) if err != nil { return nil, err } - defer common.CloseAndLogIfError(ctx, rows, "bulkSelectStateAtEventAndReference: rows.close() failed") + defer internal.CloseAndLogIfError(ctx, rows, "bulkSelectStateAtEventAndReference: rows.close() failed") results := make([]types.StateAtEventAndReference, len(eventNIDs)) i := 0 for ; rows.Next(); i++ { @@ -348,7 +348,7 @@ func (s *eventStatements) bulkSelectEventReference( if err != nil { return nil, err } - defer common.CloseAndLogIfError(ctx, rows, "bulkSelectEventReference: rows.close() failed") + defer internal.CloseAndLogIfError(ctx, rows, "bulkSelectEventReference: rows.close() failed") results := make([]gomatrixserverlib.EventReference, len(eventNIDs)) i := 0 for ; rows.Next(); i++ { @@ -372,7 +372,7 @@ func (s *eventStatements) bulkSelectEventID(ctx context.Context, eventNIDs []typ if err != nil { return nil, err } - defer common.CloseAndLogIfError(ctx, rows, "bulkSelectEventID: rows.close() failed") + defer internal.CloseAndLogIfError(ctx, rows, "bulkSelectEventID: rows.close() failed") results := make(map[types.EventNID]string, len(eventNIDs)) i := 0 for ; rows.Next(); i++ { @@ -399,7 +399,7 @@ func (s *eventStatements) bulkSelectEventNID(ctx context.Context, eventIDs []str if err != nil { return nil, err } - defer common.CloseAndLogIfError(ctx, rows, "bulkSelectEventNID: rows.close() failed") + defer internal.CloseAndLogIfError(ctx, rows, "bulkSelectEventNID: rows.close() failed") results := make(map[string]types.EventNID, len(eventIDs)) for rows.Next() { var eventID string @@ -425,7 +425,7 @@ func (s *eventStatements) selectMaxEventDepth(ctx context.Context, eventNIDs []t func (s *eventStatements) selectRoomNIDForEventNID( ctx context.Context, txn *sql.Tx, eventNID types.EventNID, ) (roomNID types.RoomNID, err error) { - selectStmt := common.TxStmt(txn, s.selectRoomNIDForEventNIDStmt) + selectStmt := internal.TxStmt(txn, s.selectRoomNIDForEventNIDStmt) err = selectStmt.QueryRowContext(ctx, int64(eventNID)).Scan(&roomNID) return } diff --git a/roomserver/storage/postgres/invite_table.go b/roomserver/storage/postgres/invite_table.go index f764b1561..f0fb919e6 100644 --- a/roomserver/storage/postgres/invite_table.go +++ b/roomserver/storage/postgres/invite_table.go @@ -19,7 +19,7 @@ import ( "context" "database/sql" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/roomserver/types" ) @@ -98,7 +98,7 @@ func (s *inviteStatements) insertInviteEvent( targetUserNID, senderUserNID types.EventStateKeyNID, inviteEventJSON []byte, ) (bool, error) { - result, err := common.TxStmt(txn, s.insertInviteEventStmt).ExecContext( + result, err := internal.TxStmt(txn, s.insertInviteEventStmt).ExecContext( ctx, inviteEventID, roomNID, targetUserNID, senderUserNID, inviteEventJSON, ) if err != nil { @@ -115,12 +115,12 @@ func (s *inviteStatements) updateInviteRetired( ctx context.Context, txn *sql.Tx, roomNID types.RoomNID, targetUserNID types.EventStateKeyNID, ) ([]string, error) { - stmt := common.TxStmt(txn, s.updateInviteRetiredStmt) + stmt := internal.TxStmt(txn, s.updateInviteRetiredStmt) rows, err := stmt.QueryContext(ctx, roomNID, targetUserNID) if err != nil { return nil, err } - defer common.CloseAndLogIfError(ctx, rows, "updateInviteRetired: rows.close() failed") + defer internal.CloseAndLogIfError(ctx, rows, "updateInviteRetired: rows.close() failed") var eventIDs []string for rows.Next() { @@ -144,7 +144,7 @@ func (s *inviteStatements) selectInviteActiveForUserInRoom( if err != nil { return nil, err } - defer common.CloseAndLogIfError(ctx, rows, "selectInviteActiveForUserInRoom: rows.close() failed") + defer internal.CloseAndLogIfError(ctx, rows, "selectInviteActiveForUserInRoom: rows.close() failed") var result []types.EventStateKeyNID for rows.Next() { var senderUserNID int64 diff --git a/roomserver/storage/postgres/membership_table.go b/roomserver/storage/postgres/membership_table.go index 820ef4e71..f290a05f9 100644 --- a/roomserver/storage/postgres/membership_table.go +++ b/roomserver/storage/postgres/membership_table.go @@ -19,7 +19,7 @@ import ( "context" "database/sql" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/roomserver/types" ) @@ -138,7 +138,7 @@ func (s *membershipStatements) insertMembership( txn *sql.Tx, roomNID types.RoomNID, targetUserNID types.EventStateKeyNID, localTarget bool, ) error { - stmt := common.TxStmt(txn, s.insertMembershipStmt) + stmt := internal.TxStmt(txn, s.insertMembershipStmt) _, err := stmt.ExecContext(ctx, roomNID, targetUserNID, localTarget) return err } @@ -147,7 +147,7 @@ func (s *membershipStatements) selectMembershipForUpdate( ctx context.Context, txn *sql.Tx, roomNID types.RoomNID, targetUserNID types.EventStateKeyNID, ) (membership membershipState, err error) { - err = common.TxStmt(txn, s.selectMembershipForUpdateStmt).QueryRowContext( + err = internal.TxStmt(txn, s.selectMembershipForUpdateStmt).QueryRowContext( ctx, roomNID, targetUserNID, ).Scan(&membership) return @@ -176,7 +176,7 @@ func (s *membershipStatements) selectMembershipsFromRoom( if err != nil { return } - defer common.CloseAndLogIfError(ctx, rows, "selectMembershipsFromRoom: rows.close() failed") + defer internal.CloseAndLogIfError(ctx, rows, "selectMembershipsFromRoom: rows.close() failed") for rows.Next() { var eNID types.EventNID @@ -203,7 +203,7 @@ func (s *membershipStatements) selectMembershipsFromRoomAndMembership( if err != nil { return } - defer common.CloseAndLogIfError(ctx, rows, "selectMembershipsFromRoomAndMembership: rows.close() failed") + defer internal.CloseAndLogIfError(ctx, rows, "selectMembershipsFromRoomAndMembership: rows.close() failed") for rows.Next() { var eNID types.EventNID @@ -221,7 +221,7 @@ func (s *membershipStatements) updateMembership( senderUserNID types.EventStateKeyNID, membership membershipState, eventNID types.EventNID, ) error { - _, err := common.TxStmt(txn, s.updateMembershipStmt).ExecContext( + _, err := internal.TxStmt(txn, s.updateMembershipStmt).ExecContext( ctx, roomNID, targetUserNID, senderUserNID, membership, eventNID, ) return err diff --git a/roomserver/storage/postgres/previous_events_table.go b/roomserver/storage/postgres/previous_events_table.go index 4c21b3081..e3ad5dc80 100644 --- a/roomserver/storage/postgres/previous_events_table.go +++ b/roomserver/storage/postgres/previous_events_table.go @@ -19,7 +19,7 @@ import ( "context" "database/sql" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/roomserver/types" ) @@ -82,7 +82,7 @@ func (s *previousEventStatements) insertPreviousEvent( previousEventReferenceSHA256 []byte, eventNID types.EventNID, ) error { - stmt := common.TxStmt(txn, s.insertPreviousEventStmt) + stmt := internal.TxStmt(txn, s.insertPreviousEventStmt) _, err := stmt.ExecContext( ctx, previousEventID, previousEventReferenceSHA256, int64(eventNID), ) @@ -95,6 +95,6 @@ func (s *previousEventStatements) selectPreviousEventExists( ctx context.Context, txn *sql.Tx, eventID string, eventReferenceSHA256 []byte, ) error { var ok int64 - stmt := common.TxStmt(txn, s.selectPreviousEventExistsStmt) + stmt := internal.TxStmt(txn, s.selectPreviousEventExistsStmt) return stmt.QueryRowContext(ctx, eventID, eventReferenceSHA256).Scan(&ok) } diff --git a/roomserver/storage/postgres/room_aliases_table.go b/roomserver/storage/postgres/room_aliases_table.go index c37f383c9..c77edd0e0 100644 --- a/roomserver/storage/postgres/room_aliases_table.go +++ b/roomserver/storage/postgres/room_aliases_table.go @@ -19,7 +19,7 @@ import ( "context" "database/sql" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" ) const roomAliasesSchema = ` @@ -97,7 +97,7 @@ func (s *roomAliasesStatements) selectAliasesFromRoomID( if err != nil { return nil, err } - defer common.CloseAndLogIfError(ctx, rows, "selectAliasesFromRoomID: rows.close() failed") + defer internal.CloseAndLogIfError(ctx, rows, "selectAliasesFromRoomID: rows.close() failed") var aliases []string for rows.Next() { diff --git a/roomserver/storage/postgres/rooms_table.go b/roomserver/storage/postgres/rooms_table.go index ef5b510c9..fc64489de 100644 --- a/roomserver/storage/postgres/rooms_table.go +++ b/roomserver/storage/postgres/rooms_table.go @@ -21,7 +21,7 @@ import ( "errors" "github.com/lib/pq" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/roomserver/types" "github.com/matrix-org/gomatrixserverlib" ) @@ -103,7 +103,7 @@ func (s *roomStatements) insertRoomNID( roomID string, roomVersion gomatrixserverlib.RoomVersion, ) (types.RoomNID, error) { var roomNID int64 - stmt := common.TxStmt(txn, s.insertRoomNIDStmt) + stmt := internal.TxStmt(txn, s.insertRoomNIDStmt) err := stmt.QueryRowContext(ctx, roomID, roomVersion).Scan(&roomNID) return types.RoomNID(roomNID), err } @@ -112,7 +112,7 @@ func (s *roomStatements) selectRoomNID( ctx context.Context, txn *sql.Tx, roomID string, ) (types.RoomNID, error) { var roomNID int64 - stmt := common.TxStmt(txn, s.selectRoomNIDStmt) + stmt := internal.TxStmt(txn, s.selectRoomNIDStmt) err := stmt.QueryRowContext(ctx, roomID).Scan(&roomNID) return types.RoomNID(roomNID), err } @@ -140,7 +140,7 @@ func (s *roomStatements) selectLatestEventsNIDsForUpdate( var nids pq.Int64Array var lastEventSentNID int64 var stateSnapshotNID int64 - stmt := common.TxStmt(txn, s.selectLatestEventNIDsForUpdateStmt) + stmt := internal.TxStmt(txn, s.selectLatestEventNIDsForUpdateStmt) err := stmt.QueryRowContext(ctx, int64(roomNID)).Scan(&nids, &lastEventSentNID, &stateSnapshotNID) if err != nil { return nil, 0, 0, err @@ -160,7 +160,7 @@ func (s *roomStatements) updateLatestEventNIDs( lastEventSentNID types.EventNID, stateSnapshotNID types.StateSnapshotNID, ) error { - stmt := common.TxStmt(txn, s.updateLatestEventNIDsStmt) + stmt := internal.TxStmt(txn, s.updateLatestEventNIDsStmt) _, err := stmt.ExecContext( ctx, roomNID, @@ -175,7 +175,7 @@ func (s *roomStatements) selectRoomVersionForRoomID( ctx context.Context, txn *sql.Tx, roomID string, ) (gomatrixserverlib.RoomVersion, error) { var roomVersion gomatrixserverlib.RoomVersion - stmt := common.TxStmt(txn, s.selectRoomVersionForRoomIDStmt) + stmt := internal.TxStmt(txn, s.selectRoomVersionForRoomIDStmt) err := stmt.QueryRowContext(ctx, roomID).Scan(&roomVersion) if err == sql.ErrNoRows { return roomVersion, errors.New("room not found") @@ -187,7 +187,7 @@ func (s *roomStatements) selectRoomVersionForRoomNID( ctx context.Context, txn *sql.Tx, roomNID types.RoomNID, ) (gomatrixserverlib.RoomVersion, error) { var roomVersion gomatrixserverlib.RoomVersion - stmt := common.TxStmt(txn, s.selectRoomVersionForRoomNIDStmt) + stmt := internal.TxStmt(txn, s.selectRoomVersionForRoomNIDStmt) err := stmt.QueryRowContext(ctx, roomNID).Scan(&roomVersion) if err == sql.ErrNoRows { return roomVersion, errors.New("room not found") diff --git a/roomserver/storage/postgres/state_block_table.go b/roomserver/storage/postgres/state_block_table.go index b9246b763..38334fa9e 100644 --- a/roomserver/storage/postgres/state_block_table.go +++ b/roomserver/storage/postgres/state_block_table.go @@ -21,7 +21,7 @@ import ( "fmt" "sort" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/lib/pq" "github.com/matrix-org/dendrite/roomserver/types" @@ -31,7 +31,7 @@ import ( const stateDataSchema = ` -- The state data map. -- Designed to give enough information to run the state resolution algorithm --- without hitting the database in the common case. +-- without hitting the database in the internal case. -- TODO: Is it worth replacing the unique btree index with a covering index so -- that postgres could lookup the state using an index-only scan? -- The type and state_key are included in the index to make it easier to @@ -140,7 +140,7 @@ func (s *stateBlockStatements) bulkSelectStateBlockEntries( if err != nil { return nil, err } - defer common.CloseAndLogIfError(ctx, rows, "bulkSelectStateBlockEntries: rows.close() failed") + defer internal.CloseAndLogIfError(ctx, rows, "bulkSelectStateBlockEntries: rows.close() failed") results := make([]types.StateEntryList, len(stateBlockNIDs)) // current is a pointer to the StateEntryList to append the state entries to. @@ -199,7 +199,7 @@ func (s *stateBlockStatements) bulkSelectFilteredStateBlockEntries( if err != nil { return nil, err } - defer common.CloseAndLogIfError(ctx, rows, "bulkSelectFilteredStateBlockEntries: rows.close() failed") + defer internal.CloseAndLogIfError(ctx, rows, "bulkSelectFilteredStateBlockEntries: rows.close() failed") var results []types.StateEntryList var current types.StateEntryList diff --git a/roomserver/storage/postgres/storage.go b/roomserver/storage/postgres/storage.go index d451d6650..4d1d603e3 100644 --- a/roomserver/storage/postgres/storage.go +++ b/roomserver/storage/postgres/storage.go @@ -20,7 +20,7 @@ import ( "database/sql" "encoding/json" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/internal/sqlutil" // Import the postgres database driver. @@ -37,7 +37,7 @@ type Database struct { } // Open a postgres database. -func Open(dataSourceName string, dbProperties common.DbProperties) (*Database, error) { +func Open(dataSourceName string, dbProperties internal.DbProperties) (*Database, error) { var d Database var err error if d.db, err = sqlutil.Open("postgres", dataSourceName, dbProperties); err != nil { diff --git a/roomserver/storage/sqlite3/event_json_table.go b/roomserver/storage/sqlite3/event_json_table.go index fc661c1da..fbf35e711 100644 --- a/roomserver/storage/sqlite3/event_json_table.go +++ b/roomserver/storage/sqlite3/event_json_table.go @@ -20,7 +20,7 @@ import ( "database/sql" "strings" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/roomserver/types" ) @@ -66,7 +66,7 @@ func (s *eventJSONStatements) prepare(db *sql.DB) (err error) { func (s *eventJSONStatements) insertEventJSON( ctx context.Context, txn *sql.Tx, eventNID types.EventNID, eventJSON []byte, ) error { - _, err := common.TxStmt(txn, s.insertEventJSONStmt).ExecContext(ctx, int64(eventNID), eventJSON) + _, err := internal.TxStmt(txn, s.insertEventJSONStmt).ExecContext(ctx, int64(eventNID), eventJSON) return err } @@ -82,13 +82,13 @@ func (s *eventJSONStatements) bulkSelectEventJSON( for k, v := range eventNIDs { iEventNIDs[k] = v } - selectOrig := strings.Replace(bulkSelectEventJSONSQL, "($1)", common.QueryVariadic(len(iEventNIDs)), 1) + selectOrig := strings.Replace(bulkSelectEventJSONSQL, "($1)", internal.QueryVariadic(len(iEventNIDs)), 1) rows, err := txn.QueryContext(ctx, selectOrig, iEventNIDs...) if err != nil { return nil, err } - defer common.CloseAndLogIfError(ctx, rows, "bulkSelectEventJSON: rows.close() failed") + defer internal.CloseAndLogIfError(ctx, rows, "bulkSelectEventJSON: rows.close() failed") // We know that we will only get as many results as event NIDs // because of the unique constraint on event NIDs. diff --git a/roomserver/storage/sqlite3/event_state_keys_table.go b/roomserver/storage/sqlite3/event_state_keys_table.go index 204b4eb62..f49ebf554 100644 --- a/roomserver/storage/sqlite3/event_state_keys_table.go +++ b/roomserver/storage/sqlite3/event_state_keys_table.go @@ -20,7 +20,7 @@ import ( "database/sql" "strings" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/roomserver/types" ) @@ -110,13 +110,13 @@ func (s *eventStateKeyStatements) bulkSelectEventStateKeyNID( for k, v := range eventStateKeys { iEventStateKeys[k] = v } - selectOrig := strings.Replace(bulkSelectEventStateKeySQL, "($1)", common.QueryVariadic(len(eventStateKeys)), 1) + selectOrig := strings.Replace(bulkSelectEventStateKeySQL, "($1)", internal.QueryVariadic(len(eventStateKeys)), 1) rows, err := txn.QueryContext(ctx, selectOrig, iEventStateKeys...) if err != nil { return nil, err } - defer common.CloseAndLogIfError(ctx, rows, "bulkSelectEventStateKeyNID: rows.close() failed") + defer internal.CloseAndLogIfError(ctx, rows, "bulkSelectEventStateKeyNID: rows.close() failed") result := make(map[string]types.EventStateKeyNID, len(eventStateKeys)) for rows.Next() { var stateKey string @@ -136,13 +136,13 @@ func (s *eventStateKeyStatements) bulkSelectEventStateKey( for k, v := range eventStateKeyNIDs { iEventStateKeyNIDs[k] = v } - selectOrig := strings.Replace(bulkSelectEventStateKeyNIDSQL, "($1)", common.QueryVariadic(len(eventStateKeyNIDs)), 1) + selectOrig := strings.Replace(bulkSelectEventStateKeyNIDSQL, "($1)", internal.QueryVariadic(len(eventStateKeyNIDs)), 1) rows, err := txn.QueryContext(ctx, selectOrig, iEventStateKeyNIDs...) if err != nil { return nil, err } - defer common.CloseAndLogIfError(ctx, rows, "bulkSelectEventStateKey: rows.close() failed") + defer internal.CloseAndLogIfError(ctx, rows, "bulkSelectEventStateKey: rows.close() failed") result := make(map[types.EventStateKeyNID]string, len(eventStateKeyNIDs)) for rows.Next() { var stateKey string diff --git a/roomserver/storage/sqlite3/event_types_table.go b/roomserver/storage/sqlite3/event_types_table.go index 777f8be79..13abcd4df 100644 --- a/roomserver/storage/sqlite3/event_types_table.go +++ b/roomserver/storage/sqlite3/event_types_table.go @@ -20,7 +20,7 @@ import ( "database/sql" "strings" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/roomserver/types" ) @@ -101,8 +101,8 @@ func (s *eventTypeStatements) insertEventTypeNID( ) (types.EventTypeNID, error) { var eventTypeNID int64 var err error - insertStmt := common.TxStmt(tx, s.insertEventTypeNIDStmt) - resultStmt := common.TxStmt(tx, s.insertEventTypeNIDResultStmt) + insertStmt := internal.TxStmt(tx, s.insertEventTypeNIDStmt) + resultStmt := internal.TxStmt(tx, s.insertEventTypeNIDResultStmt) if _, err = insertStmt.ExecContext(ctx, eventType); err == nil { err = resultStmt.QueryRowContext(ctx).Scan(&eventTypeNID) } @@ -113,7 +113,7 @@ func (s *eventTypeStatements) selectEventTypeNID( ctx context.Context, tx *sql.Tx, eventType string, ) (types.EventTypeNID, error) { var eventTypeNID int64 - selectStmt := common.TxStmt(tx, s.selectEventTypeNIDStmt) + selectStmt := internal.TxStmt(tx, s.selectEventTypeNIDStmt) err := selectStmt.QueryRowContext(ctx, eventType).Scan(&eventTypeNID) return types.EventTypeNID(eventTypeNID), err } @@ -126,19 +126,19 @@ func (s *eventTypeStatements) bulkSelectEventTypeNID( for k, v := range eventTypes { iEventTypes[k] = v } - selectOrig := strings.Replace(bulkSelectEventTypeNIDSQL, "($1)", common.QueryVariadic(len(iEventTypes)), 1) + selectOrig := strings.Replace(bulkSelectEventTypeNIDSQL, "($1)", internal.QueryVariadic(len(iEventTypes)), 1) selectPrep, err := s.db.Prepare(selectOrig) if err != nil { return nil, err } /////////////// - selectStmt := common.TxStmt(tx, selectPrep) + selectStmt := internal.TxStmt(tx, selectPrep) rows, err := selectStmt.QueryContext(ctx, iEventTypes...) if err != nil { return nil, err } - defer common.CloseAndLogIfError(ctx, rows, "bulkSelectEventTypeNID: rows.close() failed") + defer internal.CloseAndLogIfError(ctx, rows, "bulkSelectEventTypeNID: rows.close() failed") result := make(map[string]types.EventTypeNID, len(eventTypes)) for rows.Next() { diff --git a/roomserver/storage/sqlite3/events_table.go b/roomserver/storage/sqlite3/events_table.go index a63596aeb..551134950 100644 --- a/roomserver/storage/sqlite3/events_table.go +++ b/roomserver/storage/sqlite3/events_table.go @@ -22,7 +22,7 @@ import ( "fmt" "strings" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/roomserver/types" "github.com/matrix-org/gomatrixserverlib" ) @@ -147,7 +147,7 @@ func (s *eventStatements) insertEvent( depth int64, ) (types.EventNID, error) { // attempt to insert: the last_row_id is the event NID - insertStmt := common.TxStmt(txn, s.insertEventStmt) + insertStmt := internal.TxStmt(txn, s.insertEventStmt) result, err := insertStmt.ExecContext( ctx, int64(roomNID), int64(eventTypeNID), int64(eventStateKeyNID), eventID, referenceSHA256, eventNIDsAsArray(authEventNIDs), depth, @@ -168,7 +168,7 @@ func (s *eventStatements) selectEvent( ) (types.EventNID, types.StateSnapshotNID, error) { var eventNID int64 var stateNID int64 - selectStmt := common.TxStmt(txn, s.selectEventStmt) + selectStmt := internal.TxStmt(txn, s.selectEventStmt) err := selectStmt.QueryRowContext(ctx, eventID).Scan(&eventNID, &stateNID) return types.EventNID(eventNID), types.StateSnapshotNID(stateNID), err } @@ -183,19 +183,19 @@ func (s *eventStatements) bulkSelectStateEventByID( for k, v := range eventIDs { iEventIDs[k] = v } - selectOrig := strings.Replace(bulkSelectStateEventByIDSQL, "($1)", common.QueryVariadic(len(iEventIDs)), 1) + selectOrig := strings.Replace(bulkSelectStateEventByIDSQL, "($1)", internal.QueryVariadic(len(iEventIDs)), 1) selectPrep, err := txn.Prepare(selectOrig) if err != nil { return nil, err } /////////////// - selectStmt := common.TxStmt(txn, selectPrep) + selectStmt := internal.TxStmt(txn, selectPrep) rows, err := selectStmt.QueryContext(ctx, iEventIDs...) if err != nil { return nil, err } - defer common.CloseAndLogIfError(ctx, rows, "bulkSelectStateEventByID: rows.close() failed") + defer internal.CloseAndLogIfError(ctx, rows, "bulkSelectStateEventByID: rows.close() failed") // We know that we will only get as many results as event IDs // because of the unique constraint on event IDs. // So we can allocate an array of the correct size now. @@ -217,7 +217,7 @@ func (s *eventStatements) bulkSelectStateEventByID( // We don't know which ones were missing because we don't return the string IDs in the query. // However it should be possible debug this by replaying queries or entries from the input kafka logs. // If this turns out to be impossible and we do need the debug information here, it would be better - // to do it as a separate query rather than slowing down/complicating the common case. + // to do it as a separate query rather than slowing down/complicating the internal case. return nil, types.MissingEventError( fmt.Sprintf("storage: state event IDs missing from the database (%d != %d)", i, len(eventIDs)), ) @@ -236,19 +236,19 @@ func (s *eventStatements) bulkSelectStateAtEventByID( for k, v := range eventIDs { iEventIDs[k] = v } - selectOrig := strings.Replace(bulkSelectStateAtEventByIDSQL, "($1)", common.QueryVariadic(len(iEventIDs)), 1) + selectOrig := strings.Replace(bulkSelectStateAtEventByIDSQL, "($1)", internal.QueryVariadic(len(iEventIDs)), 1) selectPrep, err := txn.Prepare(selectOrig) if err != nil { return nil, err } /////////////// - selectStmt := common.TxStmt(txn, selectPrep) + selectStmt := internal.TxStmt(txn, selectPrep) rows, err := selectStmt.QueryContext(ctx, iEventIDs...) if err != nil { return nil, err } - defer common.CloseAndLogIfError(ctx, rows, "bulkSelectStateAtEventByID: rows.close() failed") + defer internal.CloseAndLogIfError(ctx, rows, "bulkSelectStateAtEventByID: rows.close() failed") results := make([]types.StateAtEvent, len(eventIDs)) i := 0 for ; rows.Next(); i++ { @@ -278,7 +278,7 @@ func (s *eventStatements) bulkSelectStateAtEventByID( func (s *eventStatements) updateEventState( ctx context.Context, txn *sql.Tx, eventNID types.EventNID, stateNID types.StateSnapshotNID, ) error { - updateStmt := common.TxStmt(txn, s.updateEventStateStmt) + updateStmt := internal.TxStmt(txn, s.updateEventStateStmt) _, err := updateStmt.ExecContext(ctx, int64(stateNID), int64(eventNID)) return err } @@ -286,7 +286,7 @@ func (s *eventStatements) updateEventState( func (s *eventStatements) selectEventSentToOutput( ctx context.Context, txn *sql.Tx, eventNID types.EventNID, ) (sentToOutput bool, err error) { - selectStmt := common.TxStmt(txn, s.selectEventSentToOutputStmt) + selectStmt := internal.TxStmt(txn, s.selectEventSentToOutputStmt) err = selectStmt.QueryRowContext(ctx, int64(eventNID)).Scan(&sentToOutput) //err = s.selectEventSentToOutputStmt.QueryRowContext(ctx, int64(eventNID)).Scan(&sentToOutput) if err != nil { @@ -295,7 +295,7 @@ func (s *eventStatements) selectEventSentToOutput( } func (s *eventStatements) updateEventSentToOutput(ctx context.Context, txn *sql.Tx, eventNID types.EventNID) error { - updateStmt := common.TxStmt(txn, s.updateEventSentToOutputStmt) + updateStmt := internal.TxStmt(txn, s.updateEventSentToOutputStmt) _, err := updateStmt.ExecContext(ctx, int64(eventNID)) //_, err := s.updateEventSentToOutputStmt.ExecContext(ctx, int64(eventNID)) return err @@ -304,7 +304,7 @@ func (s *eventStatements) updateEventSentToOutput(ctx context.Context, txn *sql. func (s *eventStatements) selectEventID( ctx context.Context, txn *sql.Tx, eventNID types.EventNID, ) (eventID string, err error) { - selectStmt := common.TxStmt(txn, s.selectEventIDStmt) + selectStmt := internal.TxStmt(txn, s.selectEventIDStmt) err = selectStmt.QueryRowContext(ctx, int64(eventNID)).Scan(&eventID) return } @@ -317,14 +317,14 @@ func (s *eventStatements) bulkSelectStateAtEventAndReference( for k, v := range eventNIDs { iEventNIDs[k] = v } - selectOrig := strings.Replace(bulkSelectStateAtEventAndReferenceSQL, "($1)", common.QueryVariadic(len(iEventNIDs)), 1) + selectOrig := strings.Replace(bulkSelectStateAtEventAndReferenceSQL, "($1)", internal.QueryVariadic(len(iEventNIDs)), 1) ////////////// rows, err := txn.QueryContext(ctx, selectOrig, iEventNIDs...) if err != nil { return nil, err } - defer common.CloseAndLogIfError(ctx, rows, "bulkSelectStateAtEventAndReference: rows.close() failed") + defer internal.CloseAndLogIfError(ctx, rows, "bulkSelectStateAtEventAndReference: rows.close() failed") results := make([]types.StateAtEventAndReference, len(eventNIDs)) i := 0 for ; rows.Next(); i++ { @@ -363,19 +363,19 @@ func (s *eventStatements) bulkSelectEventReference( for k, v := range eventNIDs { iEventNIDs[k] = v } - selectOrig := strings.Replace(bulkSelectEventReferenceSQL, "($1)", common.QueryVariadic(len(iEventNIDs)), 1) + selectOrig := strings.Replace(bulkSelectEventReferenceSQL, "($1)", internal.QueryVariadic(len(iEventNIDs)), 1) selectPrep, err := txn.Prepare(selectOrig) if err != nil { return nil, err } /////////////// - selectStmt := common.TxStmt(txn, selectPrep) + selectStmt := internal.TxStmt(txn, selectPrep) rows, err := selectStmt.QueryContext(ctx, iEventNIDs...) if err != nil { return nil, err } - defer common.CloseAndLogIfError(ctx, rows, "bulkSelectEventReference: rows.close() failed") + defer internal.CloseAndLogIfError(ctx, rows, "bulkSelectEventReference: rows.close() failed") results := make([]gomatrixserverlib.EventReference, len(eventNIDs)) i := 0 for ; rows.Next(); i++ { @@ -397,19 +397,19 @@ func (s *eventStatements) bulkSelectEventID(ctx context.Context, txn *sql.Tx, ev for k, v := range eventNIDs { iEventNIDs[k] = v } - selectOrig := strings.Replace(bulkSelectEventIDSQL, "($1)", common.QueryVariadic(len(iEventNIDs)), 1) + selectOrig := strings.Replace(bulkSelectEventIDSQL, "($1)", internal.QueryVariadic(len(iEventNIDs)), 1) selectPrep, err := txn.Prepare(selectOrig) if err != nil { return nil, err } /////////////// - selectStmt := common.TxStmt(txn, selectPrep) + selectStmt := internal.TxStmt(txn, selectPrep) rows, err := selectStmt.QueryContext(ctx, iEventNIDs...) if err != nil { return nil, err } - defer common.CloseAndLogIfError(ctx, rows, "bulkSelectEventID: rows.close() failed") + defer internal.CloseAndLogIfError(ctx, rows, "bulkSelectEventID: rows.close() failed") results := make(map[types.EventNID]string, len(eventNIDs)) i := 0 for ; rows.Next(); i++ { @@ -434,19 +434,19 @@ func (s *eventStatements) bulkSelectEventNID(ctx context.Context, txn *sql.Tx, e for k, v := range eventIDs { iEventIDs[k] = v } - selectOrig := strings.Replace(bulkSelectEventNIDSQL, "($1)", common.QueryVariadic(len(iEventIDs)), 1) + selectOrig := strings.Replace(bulkSelectEventNIDSQL, "($1)", internal.QueryVariadic(len(iEventIDs)), 1) selectPrep, err := txn.Prepare(selectOrig) if err != nil { return nil, err } /////////////// - selectStmt := common.TxStmt(txn, selectPrep) + selectStmt := internal.TxStmt(txn, selectPrep) rows, err := selectStmt.QueryContext(ctx, iEventIDs...) if err != nil { return nil, err } - defer common.CloseAndLogIfError(ctx, rows, "bulkSelectEventNID: rows.close() failed") + defer internal.CloseAndLogIfError(ctx, rows, "bulkSelectEventNID: rows.close() failed") results := make(map[string]types.EventNID, len(eventIDs)) for rows.Next() { var eventID string @@ -465,7 +465,7 @@ func (s *eventStatements) selectMaxEventDepth(ctx context.Context, txn *sql.Tx, for i, v := range eventNIDs { iEventIDs[i] = v } - sqlStr := strings.Replace(selectMaxEventDepthSQL, "($1)", common.QueryVariadic(len(iEventIDs)), 1) + sqlStr := strings.Replace(selectMaxEventDepthSQL, "($1)", internal.QueryVariadic(len(iEventIDs)), 1) err := txn.QueryRowContext(ctx, sqlStr, iEventIDs...).Scan(&result) if err != nil { return 0, err @@ -476,7 +476,7 @@ func (s *eventStatements) selectMaxEventDepth(ctx context.Context, txn *sql.Tx, func (s *eventStatements) selectRoomNIDForEventNID( ctx context.Context, txn *sql.Tx, eventNID types.EventNID, ) (roomNID types.RoomNID, err error) { - selectStmt := common.TxStmt(txn, s.selectRoomNIDForEventNIDStmt) + selectStmt := internal.TxStmt(txn, s.selectRoomNIDForEventNIDStmt) err = selectStmt.QueryRowContext(ctx, int64(eventNID)).Scan(&roomNID) return } diff --git a/roomserver/storage/sqlite3/invite_table.go b/roomserver/storage/sqlite3/invite_table.go index 0ab3e6f36..a42d18a73 100644 --- a/roomserver/storage/sqlite3/invite_table.go +++ b/roomserver/storage/sqlite3/invite_table.go @@ -19,7 +19,7 @@ import ( "context" "database/sql" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/roomserver/types" ) @@ -86,7 +86,7 @@ func (s *inviteStatements) insertInviteEvent( targetUserNID, senderUserNID types.EventStateKeyNID, inviteEventJSON []byte, ) (bool, error) { - stmt := common.TxStmt(txn, s.insertInviteEventStmt) + stmt := internal.TxStmt(txn, s.insertInviteEventStmt) defer stmt.Close() // nolint: errcheck result, err := stmt.ExecContext( ctx, inviteEventID, roomNID, targetUserNID, senderUserNID, inviteEventJSON, @@ -137,7 +137,7 @@ func (s *inviteStatements) selectInviteActiveForUserInRoom( if err != nil { return nil, err } - defer common.CloseAndLogIfError(ctx, rows, "selectInviteActiveForUserInRoom: rows.close() failed") + defer internal.CloseAndLogIfError(ctx, rows, "selectInviteActiveForUserInRoom: rows.close() failed") var result []types.EventStateKeyNID for rows.Next() { var senderUserNID int64 diff --git a/roomserver/storage/sqlite3/membership_table.go b/roomserver/storage/sqlite3/membership_table.go index ca4d8fbe9..34108af43 100644 --- a/roomserver/storage/sqlite3/membership_table.go +++ b/roomserver/storage/sqlite3/membership_table.go @@ -19,7 +19,7 @@ import ( "context" "database/sql" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/roomserver/types" ) @@ -114,7 +114,7 @@ func (s *membershipStatements) insertMembership( roomNID types.RoomNID, targetUserNID types.EventStateKeyNID, localTarget bool, ) error { - stmt := common.TxStmt(txn, s.insertMembershipStmt) + stmt := internal.TxStmt(txn, s.insertMembershipStmt) _, err := stmt.ExecContext(ctx, roomNID, targetUserNID, localTarget) return err } @@ -123,7 +123,7 @@ func (s *membershipStatements) selectMembershipForUpdate( ctx context.Context, txn *sql.Tx, roomNID types.RoomNID, targetUserNID types.EventStateKeyNID, ) (membership membershipState, err error) { - stmt := common.TxStmt(txn, s.selectMembershipForUpdateStmt) + stmt := internal.TxStmt(txn, s.selectMembershipForUpdateStmt) err = stmt.QueryRowContext( ctx, roomNID, targetUserNID, ).Scan(&membership) @@ -134,7 +134,7 @@ func (s *membershipStatements) selectMembershipFromRoomAndTarget( ctx context.Context, txn *sql.Tx, roomNID types.RoomNID, targetUserNID types.EventStateKeyNID, ) (eventNID types.EventNID, membership membershipState, err error) { - selectStmt := common.TxStmt(txn, s.selectMembershipFromRoomAndTargetStmt) + selectStmt := internal.TxStmt(txn, s.selectMembershipFromRoomAndTargetStmt) err = selectStmt.QueryRowContext( ctx, roomNID, targetUserNID, ).Scan(&membership, &eventNID) @@ -147,15 +147,15 @@ func (s *membershipStatements) selectMembershipsFromRoom( ) (eventNIDs []types.EventNID, err error) { var selectStmt *sql.Stmt if localOnly { - selectStmt = common.TxStmt(txn, s.selectLocalMembershipsFromRoomStmt) + selectStmt = internal.TxStmt(txn, s.selectLocalMembershipsFromRoomStmt) } else { - selectStmt = common.TxStmt(txn, s.selectMembershipsFromRoomStmt) + selectStmt = internal.TxStmt(txn, s.selectMembershipsFromRoomStmt) } rows, err := selectStmt.QueryContext(ctx, roomNID) if err != nil { return nil, err } - defer common.CloseAndLogIfError(ctx, rows, "selectMembershipsFromRoom: rows.close() failed") + defer internal.CloseAndLogIfError(ctx, rows, "selectMembershipsFromRoom: rows.close() failed") for rows.Next() { var eNID types.EventNID @@ -173,15 +173,15 @@ func (s *membershipStatements) selectMembershipsFromRoomAndMembership( ) (eventNIDs []types.EventNID, err error) { var stmt *sql.Stmt if localOnly { - stmt = common.TxStmt(txn, s.selectLocalMembershipsFromRoomAndMembershipStmt) + stmt = internal.TxStmt(txn, s.selectLocalMembershipsFromRoomAndMembershipStmt) } else { - stmt = common.TxStmt(txn, s.selectMembershipsFromRoomAndMembershipStmt) + stmt = internal.TxStmt(txn, s.selectMembershipsFromRoomAndMembershipStmt) } rows, err := stmt.QueryContext(ctx, roomNID, membership) if err != nil { return } - defer common.CloseAndLogIfError(ctx, rows, "selectMembershipsFromRoomAndMembership: rows.close() failed") + defer internal.CloseAndLogIfError(ctx, rows, "selectMembershipsFromRoomAndMembership: rows.close() failed") for rows.Next() { var eNID types.EventNID @@ -199,7 +199,7 @@ func (s *membershipStatements) updateMembership( senderUserNID types.EventStateKeyNID, membership membershipState, eventNID types.EventNID, ) error { - stmt := common.TxStmt(txn, s.updateMembershipStmt) + stmt := internal.TxStmt(txn, s.updateMembershipStmt) _, err := stmt.ExecContext( ctx, senderUserNID, membership, eventNID, roomNID, targetUserNID, ) diff --git a/roomserver/storage/sqlite3/previous_events_table.go b/roomserver/storage/sqlite3/previous_events_table.go index 9ed64a38e..f344bda95 100644 --- a/roomserver/storage/sqlite3/previous_events_table.go +++ b/roomserver/storage/sqlite3/previous_events_table.go @@ -19,7 +19,7 @@ import ( "context" "database/sql" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/roomserver/types" ) @@ -74,7 +74,7 @@ func (s *previousEventStatements) insertPreviousEvent( previousEventReferenceSHA256 []byte, eventNID types.EventNID, ) error { - stmt := common.TxStmt(txn, s.insertPreviousEventStmt) + stmt := internal.TxStmt(txn, s.insertPreviousEventStmt) _, err := stmt.ExecContext( ctx, previousEventID, previousEventReferenceSHA256, int64(eventNID), ) @@ -87,6 +87,6 @@ func (s *previousEventStatements) selectPreviousEventExists( ctx context.Context, txn *sql.Tx, eventID string, eventReferenceSHA256 []byte, ) error { var ok int64 - stmt := common.TxStmt(txn, s.selectPreviousEventExistsStmt) + stmt := internal.TxStmt(txn, s.selectPreviousEventExistsStmt) return stmt.QueryRowContext(ctx, eventID, eventReferenceSHA256).Scan(&ok) } diff --git a/roomserver/storage/sqlite3/room_aliases_table.go b/roomserver/storage/sqlite3/room_aliases_table.go index d29833918..592ef9782 100644 --- a/roomserver/storage/sqlite3/room_aliases_table.go +++ b/roomserver/storage/sqlite3/room_aliases_table.go @@ -19,7 +19,7 @@ import ( "context" "database/sql" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" ) const roomAliasesSchema = ` @@ -77,7 +77,7 @@ func (s *roomAliasesStatements) prepare(db *sql.DB) (err error) { func (s *roomAliasesStatements) insertRoomAlias( ctx context.Context, txn *sql.Tx, alias string, roomID string, creatorUserID string, ) (err error) { - insertStmt := common.TxStmt(txn, s.insertRoomAliasStmt) + insertStmt := internal.TxStmt(txn, s.insertRoomAliasStmt) _, err = insertStmt.ExecContext(ctx, alias, roomID, creatorUserID) return } @@ -85,7 +85,7 @@ func (s *roomAliasesStatements) insertRoomAlias( func (s *roomAliasesStatements) selectRoomIDFromAlias( ctx context.Context, txn *sql.Tx, alias string, ) (roomID string, err error) { - selectStmt := common.TxStmt(txn, s.selectRoomIDFromAliasStmt) + selectStmt := internal.TxStmt(txn, s.selectRoomIDFromAliasStmt) err = selectStmt.QueryRowContext(ctx, alias).Scan(&roomID) if err == sql.ErrNoRows { return "", nil @@ -97,13 +97,13 @@ func (s *roomAliasesStatements) selectAliasesFromRoomID( ctx context.Context, txn *sql.Tx, roomID string, ) (aliases []string, err error) { aliases = []string{} - selectStmt := common.TxStmt(txn, s.selectAliasesFromRoomIDStmt) + selectStmt := internal.TxStmt(txn, s.selectAliasesFromRoomIDStmt) rows, err := selectStmt.QueryContext(ctx, roomID) if err != nil { return } - defer common.CloseAndLogIfError(ctx, rows, "selectAliasesFromRoomID: rows.close() failed") + defer internal.CloseAndLogIfError(ctx, rows, "selectAliasesFromRoomID: rows.close() failed") for rows.Next() { var alias string @@ -120,7 +120,7 @@ func (s *roomAliasesStatements) selectAliasesFromRoomID( func (s *roomAliasesStatements) selectCreatorIDFromAlias( ctx context.Context, txn *sql.Tx, alias string, ) (creatorID string, err error) { - selectStmt := common.TxStmt(txn, s.selectCreatorIDFromAliasStmt) + selectStmt := internal.TxStmt(txn, s.selectCreatorIDFromAliasStmt) err = selectStmt.QueryRowContext(ctx, alias).Scan(&creatorID) if err == sql.ErrNoRows { return "", nil @@ -131,7 +131,7 @@ func (s *roomAliasesStatements) selectCreatorIDFromAlias( func (s *roomAliasesStatements) deleteRoomAlias( ctx context.Context, txn *sql.Tx, alias string, ) (err error) { - deleteStmt := common.TxStmt(txn, s.deleteRoomAliasStmt) + deleteStmt := internal.TxStmt(txn, s.deleteRoomAliasStmt) _, err = deleteStmt.ExecContext(ctx, alias) return } diff --git a/roomserver/storage/sqlite3/rooms_table.go b/roomserver/storage/sqlite3/rooms_table.go index 427eeeb70..ea949d1e9 100644 --- a/roomserver/storage/sqlite3/rooms_table.go +++ b/roomserver/storage/sqlite3/rooms_table.go @@ -21,7 +21,7 @@ import ( "encoding/json" "errors" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/roomserver/types" "github.com/matrix-org/gomatrixserverlib" ) @@ -92,7 +92,7 @@ func (s *roomStatements) insertRoomNID( roomID string, roomVersion gomatrixserverlib.RoomVersion, ) (types.RoomNID, error) { var err error - insertStmt := common.TxStmt(txn, s.insertRoomNIDStmt) + insertStmt := internal.TxStmt(txn, s.insertRoomNIDStmt) if _, err = insertStmt.ExecContext(ctx, roomID, roomVersion); err == nil { return s.selectRoomNID(ctx, txn, roomID) } else { @@ -104,7 +104,7 @@ func (s *roomStatements) selectRoomNID( ctx context.Context, txn *sql.Tx, roomID string, ) (types.RoomNID, error) { var roomNID int64 - stmt := common.TxStmt(txn, s.selectRoomNIDStmt) + stmt := internal.TxStmt(txn, s.selectRoomNIDStmt) err := stmt.QueryRowContext(ctx, roomID).Scan(&roomNID) return types.RoomNID(roomNID), err } @@ -115,7 +115,7 @@ func (s *roomStatements) selectLatestEventNIDs( var eventNIDs []types.EventNID var nidsJSON string var stateSnapshotNID int64 - stmt := common.TxStmt(txn, s.selectLatestEventNIDsStmt) + stmt := internal.TxStmt(txn, s.selectLatestEventNIDsStmt) err := stmt.QueryRowContext(ctx, int64(roomNID)).Scan(&nidsJSON, &stateSnapshotNID) if err != nil { return nil, 0, err @@ -133,7 +133,7 @@ func (s *roomStatements) selectLatestEventsNIDsForUpdate( var nidsJSON string var lastEventSentNID int64 var stateSnapshotNID int64 - stmt := common.TxStmt(txn, s.selectLatestEventNIDsForUpdateStmt) + stmt := internal.TxStmt(txn, s.selectLatestEventNIDsForUpdateStmt) err := stmt.QueryRowContext(ctx, int64(roomNID)).Scan(&nidsJSON, &lastEventSentNID, &stateSnapshotNID) if err != nil { return nil, 0, 0, err @@ -152,7 +152,7 @@ func (s *roomStatements) updateLatestEventNIDs( lastEventSentNID types.EventNID, stateSnapshotNID types.StateSnapshotNID, ) error { - stmt := common.TxStmt(txn, s.updateLatestEventNIDsStmt) + stmt := internal.TxStmt(txn, s.updateLatestEventNIDsStmt) _, err := stmt.ExecContext( ctx, eventNIDsAsArray(eventNIDs), @@ -167,7 +167,7 @@ func (s *roomStatements) selectRoomVersionForRoomID( ctx context.Context, txn *sql.Tx, roomID string, ) (gomatrixserverlib.RoomVersion, error) { var roomVersion gomatrixserverlib.RoomVersion - stmt := common.TxStmt(txn, s.selectRoomVersionForRoomIDStmt) + stmt := internal.TxStmt(txn, s.selectRoomVersionForRoomIDStmt) err := stmt.QueryRowContext(ctx, roomID).Scan(&roomVersion) if err == sql.ErrNoRows { return roomVersion, errors.New("room not found") @@ -179,7 +179,7 @@ func (s *roomStatements) selectRoomVersionForRoomNID( ctx context.Context, txn *sql.Tx, roomNID types.RoomNID, ) (gomatrixserverlib.RoomVersion, error) { var roomVersion gomatrixserverlib.RoomVersion - stmt := common.TxStmt(txn, s.selectRoomVersionForRoomNIDStmt) + stmt := internal.TxStmt(txn, s.selectRoomVersionForRoomNIDStmt) err := stmt.QueryRowContext(ctx, roomNID).Scan(&roomVersion) if err == sql.ErrNoRows { return roomVersion, errors.New("room not found") diff --git a/roomserver/storage/sqlite3/state_block_table.go b/roomserver/storage/sqlite3/state_block_table.go index cc7c75733..861d76cf9 100644 --- a/roomserver/storage/sqlite3/state_block_table.go +++ b/roomserver/storage/sqlite3/state_block_table.go @@ -22,7 +22,7 @@ import ( "sort" "strings" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/roomserver/types" "github.com/matrix-org/util" ) @@ -127,17 +127,17 @@ func (s *stateBlockStatements) bulkSelectStateBlockEntries( for k, v := range stateBlockNIDs { nids[k] = v } - selectOrig := strings.Replace(bulkSelectStateBlockEntriesSQL, "($1)", common.QueryVariadic(len(nids)), 1) + selectOrig := strings.Replace(bulkSelectStateBlockEntriesSQL, "($1)", internal.QueryVariadic(len(nids)), 1) selectPrep, err := s.db.Prepare(selectOrig) if err != nil { return nil, err } - selectStmt := common.TxStmt(txn, selectPrep) + selectStmt := internal.TxStmt(txn, selectPrep) rows, err := selectStmt.QueryContext(ctx, nids...) if err != nil { return nil, err } - defer common.CloseAndLogIfError(ctx, rows, "bulkSelectStateBlockEntries: rows.close() failed") + defer internal.CloseAndLogIfError(ctx, rows, "bulkSelectStateBlockEntries: rows.close() failed") results := make([]types.StateEntryList, len(stateBlockNIDs)) // current is a pointer to the StateEntryList to append the state entries to. @@ -184,9 +184,9 @@ func (s *stateBlockStatements) bulkSelectFilteredStateBlockEntries( sort.Sort(tuples) eventTypeNIDArray, eventStateKeyNIDArray := tuples.typesAndStateKeysAsArrays() - sqlStatement := strings.Replace(bulkSelectFilteredStateBlockEntriesSQL, "($1)", common.QueryVariadic(len(stateBlockNIDs)), 1) - sqlStatement = strings.Replace(sqlStatement, "($2)", common.QueryVariadicOffset(len(eventTypeNIDArray), len(stateBlockNIDs)), 1) - sqlStatement = strings.Replace(sqlStatement, "($3)", common.QueryVariadicOffset(len(eventStateKeyNIDArray), len(stateBlockNIDs)+len(eventTypeNIDArray)), 1) + sqlStatement := strings.Replace(bulkSelectFilteredStateBlockEntriesSQL, "($1)", internal.QueryVariadic(len(stateBlockNIDs)), 1) + sqlStatement = strings.Replace(sqlStatement, "($2)", internal.QueryVariadicOffset(len(eventTypeNIDArray), len(stateBlockNIDs)), 1) + sqlStatement = strings.Replace(sqlStatement, "($3)", internal.QueryVariadicOffset(len(eventStateKeyNIDArray), len(stateBlockNIDs)+len(eventTypeNIDArray)), 1) var params []interface{} for _, val := range stateBlockNIDs { @@ -207,7 +207,7 @@ func (s *stateBlockStatements) bulkSelectFilteredStateBlockEntries( if err != nil { return nil, err } - defer common.CloseAndLogIfError(ctx, rows, "bulkSelectFilteredStateBlockEntries: rows.close() failed") + defer internal.CloseAndLogIfError(ctx, rows, "bulkSelectFilteredStateBlockEntries: rows.close() failed") var results []types.StateEntryList var current types.StateEntryList diff --git a/roomserver/storage/sqlite3/state_snapshot_table.go b/roomserver/storage/sqlite3/state_snapshot_table.go index f367a779b..8682627a0 100644 --- a/roomserver/storage/sqlite3/state_snapshot_table.go +++ b/roomserver/storage/sqlite3/state_snapshot_table.go @@ -22,7 +22,7 @@ import ( "fmt" "strings" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/roomserver/types" ) @@ -89,7 +89,7 @@ func (s *stateSnapshotStatements) bulkSelectStateBlockNIDs( for k, v := range stateNIDs { nids[k] = v } - selectOrig := strings.Replace(bulkSelectStateBlockNIDsSQL, "($1)", common.QueryVariadic(len(nids)), 1) + selectOrig := strings.Replace(bulkSelectStateBlockNIDsSQL, "($1)", internal.QueryVariadic(len(nids)), 1) selectStmt, err := txn.Prepare(selectOrig) if err != nil { return nil, err @@ -99,7 +99,7 @@ func (s *stateSnapshotStatements) bulkSelectStateBlockNIDs( if err != nil { return nil, err } - defer common.CloseAndLogIfError(ctx, rows, "bulkSelectStateBlockNIDs: rows.close() failed") + defer internal.CloseAndLogIfError(ctx, rows, "bulkSelectStateBlockNIDs: rows.close() failed") results := make([]types.StateBlockNIDList, len(stateNIDs)) i := 0 for ; rows.Next(); i++ { diff --git a/roomserver/storage/sqlite3/storage.go b/roomserver/storage/sqlite3/storage.go index 209922fa2..bb38f800f 100644 --- a/roomserver/storage/sqlite3/storage.go +++ b/roomserver/storage/sqlite3/storage.go @@ -24,7 +24,7 @@ import ( "github.com/matrix-org/dendrite/internal/sqlutil" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/roomserver/api" "github.com/matrix-org/dendrite/roomserver/types" "github.com/matrix-org/gomatrixserverlib" @@ -52,7 +52,7 @@ func Open(dataSourceName string) (*Database, error) { } else { return nil, errors.New("no filename or path in connect string") } - if d.db, err = sqlutil.Open(common.SQLiteDriverName(), cs, nil); err != nil { + if d.db, err = sqlutil.Open(internal.SQLiteDriverName(), cs, nil); err != nil { return nil, err } //d.db.Exec("PRAGMA journal_mode=WAL;") @@ -83,7 +83,7 @@ func (d *Database) StoreEvent( err error ) - err = common.WithTransaction(d.db, func(txn *sql.Tx) error { + err = internal.WithTransaction(d.db, func(txn *sql.Tx) error { if txnAndSessionID != nil { if err = d.statements.insertTransaction( ctx, txn, txnAndSessionID.TransactionID, @@ -242,7 +242,7 @@ func (d *Database) assignStateKeyNID( func (d *Database) StateEntriesForEventIDs( ctx context.Context, eventIDs []string, ) (se []types.StateEntry, err error) { - err = common.WithTransaction(d.db, func(txn *sql.Tx) error { + err = internal.WithTransaction(d.db, func(txn *sql.Tx) error { se, err = d.statements.bulkSelectStateEventByID(ctx, txn, eventIDs) return err }) @@ -253,7 +253,7 @@ func (d *Database) StateEntriesForEventIDs( func (d *Database) EventTypeNIDs( ctx context.Context, eventTypes []string, ) (etnids map[string]types.EventTypeNID, err error) { - err = common.WithTransaction(d.db, func(txn *sql.Tx) error { + err = internal.WithTransaction(d.db, func(txn *sql.Tx) error { etnids, err = d.statements.bulkSelectEventTypeNID(ctx, txn, eventTypes) return err }) @@ -264,7 +264,7 @@ func (d *Database) EventTypeNIDs( func (d *Database) EventStateKeyNIDs( ctx context.Context, eventStateKeys []string, ) (esknids map[string]types.EventStateKeyNID, err error) { - err = common.WithTransaction(d.db, func(txn *sql.Tx) error { + err = internal.WithTransaction(d.db, func(txn *sql.Tx) error { esknids, err = d.statements.bulkSelectEventStateKeyNID(ctx, txn, eventStateKeys) return err }) @@ -275,7 +275,7 @@ func (d *Database) EventStateKeyNIDs( func (d *Database) EventStateKeys( ctx context.Context, eventStateKeyNIDs []types.EventStateKeyNID, ) (out map[types.EventStateKeyNID]string, err error) { - err = common.WithTransaction(d.db, func(txn *sql.Tx) error { + err = internal.WithTransaction(d.db, func(txn *sql.Tx) error { out, err = d.statements.bulkSelectEventStateKey(ctx, txn, eventStateKeyNIDs) return err }) @@ -286,7 +286,7 @@ func (d *Database) EventStateKeys( func (d *Database) EventNIDs( ctx context.Context, eventIDs []string, ) (out map[string]types.EventNID, err error) { - err = common.WithTransaction(d.db, func(txn *sql.Tx) error { + err = internal.WithTransaction(d.db, func(txn *sql.Tx) error { out, err = d.statements.bulkSelectEventNID(ctx, txn, eventIDs) return err }) @@ -300,7 +300,7 @@ func (d *Database) Events( var eventJSONs []eventJSONPair var err error var results []types.Event - err = common.WithTransaction(d.db, func(txn *sql.Tx) error { + err = internal.WithTransaction(d.db, func(txn *sql.Tx) error { eventJSONs, err = d.statements.bulkSelectEventJSON(ctx, txn, eventNIDs) if err != nil || len(eventJSONs) == 0 { return nil @@ -341,7 +341,7 @@ func (d *Database) AddState( stateBlockNIDs []types.StateBlockNID, state []types.StateEntry, ) (stateNID types.StateSnapshotNID, err error) { - err = common.WithTransaction(d.db, func(txn *sql.Tx) error { + err = internal.WithTransaction(d.db, func(txn *sql.Tx) error { if len(state) > 0 { var stateBlockNID types.StateBlockNID stateBlockNID, err = d.statements.bulkInsertStateData(ctx, txn, state) @@ -363,7 +363,7 @@ func (d *Database) AddState( func (d *Database) SetState( ctx context.Context, eventNID types.EventNID, stateNID types.StateSnapshotNID, ) error { - e := common.WithTransaction(d.db, func(txn *sql.Tx) error { + e := internal.WithTransaction(d.db, func(txn *sql.Tx) error { return d.statements.updateEventState(ctx, txn, eventNID, stateNID) }) return e @@ -373,7 +373,7 @@ func (d *Database) SetState( func (d *Database) StateAtEventIDs( ctx context.Context, eventIDs []string, ) (se []types.StateAtEvent, err error) { - err = common.WithTransaction(d.db, func(txn *sql.Tx) error { + err = internal.WithTransaction(d.db, func(txn *sql.Tx) error { se, err = d.statements.bulkSelectStateAtEventByID(ctx, txn, eventIDs) return err }) @@ -384,7 +384,7 @@ func (d *Database) StateAtEventIDs( func (d *Database) StateBlockNIDs( ctx context.Context, stateNIDs []types.StateSnapshotNID, ) (sl []types.StateBlockNIDList, err error) { - err = common.WithTransaction(d.db, func(txn *sql.Tx) error { + err = internal.WithTransaction(d.db, func(txn *sql.Tx) error { sl, err = d.statements.bulkSelectStateBlockNIDs(ctx, txn, stateNIDs) return err }) @@ -395,7 +395,7 @@ func (d *Database) StateBlockNIDs( func (d *Database) StateEntries( ctx context.Context, stateBlockNIDs []types.StateBlockNID, ) (sel []types.StateEntryList, err error) { - err = common.WithTransaction(d.db, func(txn *sql.Tx) error { + err = internal.WithTransaction(d.db, func(txn *sql.Tx) error { sel, err = d.statements.bulkSelectStateBlockEntries(ctx, txn, stateBlockNIDs) return err }) @@ -406,7 +406,7 @@ func (d *Database) StateEntries( func (d *Database) SnapshotNIDFromEventID( ctx context.Context, eventID string, ) (stateNID types.StateSnapshotNID, err error) { - err = common.WithTransaction(d.db, func(txn *sql.Tx) error { + err = internal.WithTransaction(d.db, func(txn *sql.Tx) error { _, stateNID, err = d.statements.selectEvent(ctx, txn, eventID) return err }) @@ -417,7 +417,7 @@ func (d *Database) SnapshotNIDFromEventID( func (d *Database) EventIDs( ctx context.Context, eventNIDs []types.EventNID, ) (out map[types.EventNID]string, err error) { - err = common.WithTransaction(d.db, func(txn *sql.Tx) error { + err = internal.WithTransaction(d.db, func(txn *sql.Tx) error { out, err = d.statements.bulkSelectEventID(ctx, txn, eventNIDs) return err }) @@ -509,7 +509,7 @@ func (u *roomRecentEventsUpdater) CurrentStateSnapshotNID() types.StateSnapshotN // StorePreviousEvents implements types.RoomRecentEventsUpdater func (u *roomRecentEventsUpdater) StorePreviousEvents(eventNID types.EventNID, previousEventReferences []gomatrixserverlib.EventReference) error { - err := common.WithTransaction(u.d.db, func(txn *sql.Tx) error { + err := internal.WithTransaction(u.d.db, func(txn *sql.Tx) error { for _, ref := range previousEventReferences { if err := u.d.statements.insertPreviousEvent(u.ctx, txn, ref.EventID, ref.EventSHA256, eventNID); err != nil { return err @@ -522,7 +522,7 @@ func (u *roomRecentEventsUpdater) StorePreviousEvents(eventNID types.EventNID, p // IsReferenced implements types.RoomRecentEventsUpdater func (u *roomRecentEventsUpdater) IsReferenced(eventReference gomatrixserverlib.EventReference) (res bool, err error) { - err = common.WithTransaction(u.d.db, func(txn *sql.Tx) error { + err = internal.WithTransaction(u.d.db, func(txn *sql.Tx) error { err := u.d.statements.selectPreviousEventExists(u.ctx, txn, eventReference.EventID, eventReference.EventSHA256) if err == nil { res = true @@ -542,7 +542,7 @@ func (u *roomRecentEventsUpdater) SetLatestEvents( roomNID types.RoomNID, latest []types.StateAtEventAndReference, lastEventNIDSent types.EventNID, currentStateSnapshotNID types.StateSnapshotNID, ) error { - err := common.WithTransaction(u.d.db, func(txn *sql.Tx) error { + err := internal.WithTransaction(u.d.db, func(txn *sql.Tx) error { eventNIDs := make([]types.EventNID, len(latest)) for i := range latest { eventNIDs[i] = latest[i].EventNID @@ -554,7 +554,7 @@ func (u *roomRecentEventsUpdater) SetLatestEvents( // HasEventBeenSent implements types.RoomRecentEventsUpdater func (u *roomRecentEventsUpdater) HasEventBeenSent(eventNID types.EventNID) (res bool, err error) { - err = common.WithTransaction(u.d.db, func(txn *sql.Tx) error { + err = internal.WithTransaction(u.d.db, func(txn *sql.Tx) error { res, err = u.d.statements.selectEventSentToOutput(u.ctx, txn, eventNID) return err }) @@ -563,14 +563,14 @@ func (u *roomRecentEventsUpdater) HasEventBeenSent(eventNID types.EventNID) (res // MarkEventAsSent implements types.RoomRecentEventsUpdater func (u *roomRecentEventsUpdater) MarkEventAsSent(eventNID types.EventNID) error { - err := common.WithTransaction(u.d.db, func(txn *sql.Tx) error { + err := internal.WithTransaction(u.d.db, func(txn *sql.Tx) error { return u.d.statements.updateEventSentToOutput(u.ctx, txn, eventNID) }) return err } func (u *roomRecentEventsUpdater) MembershipUpdater(targetUserNID types.EventStateKeyNID, targetLocal bool) (mu types.MembershipUpdater, err error) { - err = common.WithTransaction(u.d.db, func(txn *sql.Tx) error { + err = internal.WithTransaction(u.d.db, func(txn *sql.Tx) error { mu, err = u.d.membershipUpdaterTxn(u.ctx, txn, u.roomNID, targetUserNID, targetLocal) return err }) @@ -579,7 +579,7 @@ func (u *roomRecentEventsUpdater) MembershipUpdater(targetUserNID types.EventSta // RoomNID implements query.RoomserverQueryAPIDB func (d *Database) RoomNID(ctx context.Context, roomID string) (roomNID types.RoomNID, err error) { - err = common.WithTransaction(d.db, func(txn *sql.Tx) error { + err = internal.WithTransaction(d.db, func(txn *sql.Tx) error { roomNID, err = d.statements.selectRoomNID(ctx, txn, roomID) if err == sql.ErrNoRows { roomNID = 0 @@ -611,7 +611,7 @@ func (d *Database) RoomNIDExcludingStubs(ctx context.Context, roomID string) (ro func (d *Database) LatestEventIDs( ctx context.Context, roomNID types.RoomNID, ) (references []gomatrixserverlib.EventReference, currentStateSnapshotNID types.StateSnapshotNID, depth int64, err error) { - err = common.WithTransaction(d.db, func(txn *sql.Tx) error { + err = internal.WithTransaction(d.db, func(txn *sql.Tx) error { var eventNIDs []types.EventNID eventNIDs, currentStateSnapshotNID, err = d.statements.selectLatestEventNIDs(ctx, txn, roomNID) if err != nil { @@ -773,7 +773,7 @@ func (u *membershipUpdater) IsLeave() bool { // SetToInvite implements types.MembershipUpdater func (u *membershipUpdater) SetToInvite(event gomatrixserverlib.Event) (inserted bool, err error) { - err = common.WithTransaction(u.d.db, func(txn *sql.Tx) error { + err = internal.WithTransaction(u.d.db, func(txn *sql.Tx) error { senderUserNID, err := u.d.assignStateKeyNID(u.ctx, txn, event.Sender()) if err != nil { return err @@ -798,7 +798,7 @@ func (u *membershipUpdater) SetToInvite(event gomatrixserverlib.Event) (inserted // SetToJoin implements types.MembershipUpdater func (u *membershipUpdater) SetToJoin(senderUserID string, eventID string, isUpdate bool) (inviteEventIDs []string, err error) { - err = common.WithTransaction(u.d.db, func(txn *sql.Tx) error { + err = internal.WithTransaction(u.d.db, func(txn *sql.Tx) error { senderUserNID, err := u.d.assignStateKeyNID(u.ctx, txn, senderUserID) if err != nil { return err @@ -836,7 +836,7 @@ func (u *membershipUpdater) SetToJoin(senderUserID string, eventID string, isUpd // SetToLeave implements types.MembershipUpdater func (u *membershipUpdater) SetToLeave(senderUserID string, eventID string) (inviteEventIDs []string, err error) { - err = common.WithTransaction(u.d.db, func(txn *sql.Tx) error { + err = internal.WithTransaction(u.d.db, func(txn *sql.Tx) error { senderUserNID, err := u.d.assignStateKeyNID(u.ctx, txn, senderUserID) if err != nil { return err @@ -871,7 +871,7 @@ func (u *membershipUpdater) SetToLeave(senderUserID string, eventID string) (inv func (d *Database) GetMembership( ctx context.Context, roomNID types.RoomNID, requestSenderUserID string, ) (membershipEventNID types.EventNID, stillInRoom bool, err error) { - err = common.WithTransaction(d.db, func(txn *sql.Tx) error { + err = internal.WithTransaction(d.db, func(txn *sql.Tx) error { requestSenderUserNID, err := d.assignStateKeyNID(ctx, txn, requestSenderUserID) if err != nil { return err @@ -899,7 +899,7 @@ func (d *Database) GetMembership( func (d *Database) GetMembershipEventNIDsForRoom( ctx context.Context, roomNID types.RoomNID, joinOnly bool, localOnly bool, ) (eventNIDs []types.EventNID, err error) { - err = common.WithTransaction(d.db, func(txn *sql.Tx) error { + err = internal.WithTransaction(d.db, func(txn *sql.Tx) error { if joinOnly { eventNIDs, err = d.statements.selectMembershipsFromRoomAndMembership( ctx, txn, roomNID, membershipStateJoin, localOnly, diff --git a/roomserver/storage/sqlite3/transactions_table.go b/roomserver/storage/sqlite3/transactions_table.go index 7740e5f07..d22c73845 100644 --- a/roomserver/storage/sqlite3/transactions_table.go +++ b/roomserver/storage/sqlite3/transactions_table.go @@ -19,7 +19,7 @@ import ( "context" "database/sql" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" ) const transactionsSchema = ` @@ -65,7 +65,7 @@ func (s *transactionStatements) insertTransaction( userID string, eventID string, ) (err error) { - stmt := common.TxStmt(txn, s.insertTransactionStmt) + stmt := internal.TxStmt(txn, s.insertTransactionStmt) _, err = stmt.ExecContext( ctx, transactionID, sessionID, userID, eventID, ) @@ -78,7 +78,7 @@ func (s *transactionStatements) selectTransactionEventID( sessionID int64, userID string, ) (eventID string, err error) { - stmt := common.TxStmt(txn, s.selectTransactionEventIDStmt) + stmt := internal.TxStmt(txn, s.selectTransactionEventIDStmt) err = stmt.QueryRowContext( ctx, transactionID, sessionID, userID, ).Scan(&eventID) diff --git a/roomserver/storage/storage.go b/roomserver/storage/storage.go index 99e99a008..071e2cf1d 100644 --- a/roomserver/storage/storage.go +++ b/roomserver/storage/storage.go @@ -19,13 +19,13 @@ package storage import ( "net/url" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/roomserver/storage/postgres" "github.com/matrix-org/dendrite/roomserver/storage/sqlite3" ) // Open opens a database connection. -func Open(dataSourceName string, dbProperties common.DbProperties) (Database, error) { +func Open(dataSourceName string, dbProperties internal.DbProperties) (Database, error) { uri, err := url.Parse(dataSourceName) if err != nil { return postgres.Open(dataSourceName, dbProperties) diff --git a/roomserver/storage/storage_wasm.go b/roomserver/storage/storage_wasm.go index 5fa48bc95..ef30ca593 100644 --- a/roomserver/storage/storage_wasm.go +++ b/roomserver/storage/storage_wasm.go @@ -18,14 +18,14 @@ import ( "fmt" "net/url" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/roomserver/storage/sqlite3" ) // NewPublicRoomsServerDatabase opens a database connection. func Open( dataSourceName string, - dbProperties common.DbProperties, // nolint:unparam + dbProperties internal.DbProperties, // nolint:unparam ) (Database, error) { uri, err := url.Parse(dataSourceName) if err != nil { diff --git a/roomserver/types/types.go b/roomserver/types/types.go index 74e6b0784..87a4f935c 100644 --- a/roomserver/types/types.go +++ b/roomserver/types/types.go @@ -16,7 +16,7 @@ package types import ( - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/gomatrixserverlib" ) @@ -174,7 +174,7 @@ type RoomRecentEventsUpdater interface { // It will share the same transaction as this updater. MembershipUpdater(targetUserNID EventStateKeyNID, isTargetLocalUser bool) (MembershipUpdater, error) // Implements Transaction so it can be committed or rolledback - common.Transaction + internal.Transaction } // A MembershipUpdater is used to update the membership of a user in a room. @@ -199,7 +199,7 @@ type MembershipUpdater interface { // Returns a list of invite event IDs that this state change retired. SetToLeave(senderUserID string, eventID string) (inviteEventIDs []string, err error) // Implements Transaction so it can be committed or rolledback. - common.Transaction + internal.Transaction } // A MissingEventError is an error that happened because the roomserver was diff --git a/syncapi/api/query.go b/syncapi/api/query.go index 2993829e0..6585bc093 100644 --- a/syncapi/api/query.go +++ b/syncapi/api/query.go @@ -18,7 +18,7 @@ import ( "context" "net/http" - commonHTTP "github.com/matrix-org/dendrite/common/http" + internalHTTP "github.com/matrix-org/dendrite/internal/http" "github.com/matrix-org/util" opentracing "github.com/opentracing/opentracing-go" ) @@ -80,7 +80,7 @@ func (h *httpSyncQueryAPI) QuerySync( defer span.Finish() apiURL := h.syncapiURL + SyncAPIQuerySyncPath - return commonHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response) + return internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response) } // QueryStateAfterEvents implements SyncQueryAPI @@ -93,7 +93,7 @@ func (h *httpSyncQueryAPI) QueryState( defer span.Finish() apiURL := h.syncapiURL + SyncAPIQueryStatePath - return commonHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response) + return internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response) } // QueryEventsByID implements SyncQueryAPI @@ -106,7 +106,7 @@ func (h *httpSyncQueryAPI) QueryStateType( defer span.Finish() apiURL := h.syncapiURL + SyncAPIQueryStateTypePath - return commonHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response) + return internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response) } // QueryMembershipForUser implements SyncQueryAPI @@ -119,5 +119,5 @@ func (h *httpSyncQueryAPI) QueryMessages( defer span.Finish() apiURL := h.syncapiURL + SyncAPIQueryMessagesPath - return commonHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response) + return internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response) } diff --git a/syncapi/consumers/clientapi.go b/syncapi/consumers/clientapi.go index b65d01a04..4d43e8111 100644 --- a/syncapi/consumers/clientapi.go +++ b/syncapi/consumers/clientapi.go @@ -19,8 +19,8 @@ import ( "encoding/json" "github.com/Shopify/sarama" - "github.com/matrix-org/dendrite/common" - "github.com/matrix-org/dendrite/common/config" + "github.com/matrix-org/dendrite/internal" + "github.com/matrix-org/dendrite/internal/config" "github.com/matrix-org/dendrite/syncapi/storage" "github.com/matrix-org/dendrite/syncapi/sync" "github.com/matrix-org/dendrite/syncapi/types" @@ -29,7 +29,7 @@ import ( // OutputClientDataConsumer consumes events that originated in the client API server. type OutputClientDataConsumer struct { - clientAPIConsumer *common.ContinualConsumer + clientAPIConsumer *internal.ContinualConsumer db storage.Database notifier *sync.Notifier } @@ -42,7 +42,7 @@ func NewOutputClientDataConsumer( store storage.Database, ) *OutputClientDataConsumer { - consumer := common.ContinualConsumer{ + consumer := internal.ContinualConsumer{ Topic: string(cfg.Kafka.Topics.OutputClientData), Consumer: kafkaConsumer, PartitionStore: store, @@ -67,7 +67,7 @@ func (s *OutputClientDataConsumer) Start() error { // sync stream position may race and be incorrectly calculated. func (s *OutputClientDataConsumer) onMessage(msg *sarama.ConsumerMessage) error { // Parse out the event JSON - var output common.AccountData + var output internal.AccountData if err := json.Unmarshal(msg.Value, &output); err != nil { // If the message was invalid, log it and move on to the next message in the stream log.WithError(err).Errorf("client API server output log: message parse failure") diff --git a/syncapi/consumers/eduserver.go b/syncapi/consumers/eduserver.go index ece999d59..12b1efbc0 100644 --- a/syncapi/consumers/eduserver.go +++ b/syncapi/consumers/eduserver.go @@ -18,9 +18,9 @@ import ( "encoding/json" "github.com/Shopify/sarama" - "github.com/matrix-org/dendrite/common" - "github.com/matrix-org/dendrite/common/config" "github.com/matrix-org/dendrite/eduserver/api" + "github.com/matrix-org/dendrite/internal" + "github.com/matrix-org/dendrite/internal/config" "github.com/matrix-org/dendrite/syncapi/storage" "github.com/matrix-org/dendrite/syncapi/sync" "github.com/matrix-org/dendrite/syncapi/types" @@ -29,7 +29,7 @@ import ( // OutputTypingEventConsumer consumes events that originated in the EDU server. type OutputTypingEventConsumer struct { - typingConsumer *common.ContinualConsumer + typingConsumer *internal.ContinualConsumer db storage.Database notifier *sync.Notifier } @@ -43,7 +43,7 @@ func NewOutputTypingEventConsumer( store storage.Database, ) *OutputTypingEventConsumer { - consumer := common.ContinualConsumer{ + consumer := internal.ContinualConsumer{ Topic: string(cfg.Kafka.Topics.OutputTypingEvent), Consumer: kafkaConsumer, PartitionStore: store, diff --git a/syncapi/consumers/roomserver.go b/syncapi/consumers/roomserver.go index 368420a6c..055f76603 100644 --- a/syncapi/consumers/roomserver.go +++ b/syncapi/consumers/roomserver.go @@ -20,8 +20,8 @@ import ( "fmt" "github.com/Shopify/sarama" - "github.com/matrix-org/dendrite/common" - "github.com/matrix-org/dendrite/common/config" + "github.com/matrix-org/dendrite/internal" + "github.com/matrix-org/dendrite/internal/config" "github.com/matrix-org/dendrite/roomserver/api" "github.com/matrix-org/dendrite/syncapi/storage" "github.com/matrix-org/dendrite/syncapi/sync" @@ -33,7 +33,7 @@ import ( // OutputRoomEventConsumer consumes events that originated in the room server. type OutputRoomEventConsumer struct { rsAPI api.RoomserverInternalAPI - rsConsumer *common.ContinualConsumer + rsConsumer *internal.ContinualConsumer db storage.Database notifier *sync.Notifier } @@ -47,7 +47,7 @@ func NewOutputRoomEventConsumer( rsAPI api.RoomserverInternalAPI, ) *OutputRoomEventConsumer { - consumer := common.ContinualConsumer{ + consumer := internal.ContinualConsumer{ Topic: string(cfg.Kafka.Topics.OutputRoomEvent), Consumer: kafkaConsumer, PartitionStore: store, diff --git a/syncapi/routing/messages.go b/syncapi/routing/messages.go index 88e16fe57..8c8976345 100644 --- a/syncapi/routing/messages.go +++ b/syncapi/routing/messages.go @@ -22,7 +22,7 @@ import ( "strconv" "github.com/matrix-org/dendrite/clientapi/jsonerror" - "github.com/matrix-org/dendrite/common/config" + "github.com/matrix-org/dendrite/internal/config" "github.com/matrix-org/dendrite/roomserver/api" "github.com/matrix-org/dendrite/syncapi/storage" "github.com/matrix-org/dendrite/syncapi/types" diff --git a/syncapi/routing/routing.go b/syncapi/routing/routing.go index 5a36a279f..6300b17bb 100644 --- a/syncapi/routing/routing.go +++ b/syncapi/routing/routing.go @@ -21,8 +21,8 @@ import ( "github.com/matrix-org/dendrite/clientapi/auth" "github.com/matrix-org/dendrite/clientapi/auth/authtypes" "github.com/matrix-org/dendrite/clientapi/auth/storage/devices" - "github.com/matrix-org/dendrite/common" - "github.com/matrix-org/dendrite/common/config" + "github.com/matrix-org/dendrite/internal" + "github.com/matrix-org/dendrite/internal/config" "github.com/matrix-org/dendrite/roomserver/api" "github.com/matrix-org/dendrite/syncapi/storage" "github.com/matrix-org/dendrite/syncapi/sync" @@ -52,12 +52,12 @@ func Setup( } // TODO: Add AS support for all handlers below. - r0mux.Handle("/sync", common.MakeAuthAPI("sync", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { + r0mux.Handle("/sync", internal.MakeAuthAPI("sync", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { return srp.OnIncomingSyncRequest(req, device) })).Methods(http.MethodGet, http.MethodOptions) - r0mux.Handle("/rooms/{roomID}/messages", common.MakeAuthAPI("room_messages", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { - vars, err := common.URLDecodeMapValues(mux.Vars(req)) + r0mux.Handle("/rooms/{roomID}/messages", internal.MakeAuthAPI("room_messages", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { + vars, err := internal.URLDecodeMapValues(mux.Vars(req)) if err != nil { return util.ErrorResponse(err) } diff --git a/syncapi/storage/interface.go b/syncapi/storage/interface.go index 121e94c71..3e9ff0533 100644 --- a/syncapi/storage/interface.go +++ b/syncapi/storage/interface.go @@ -19,15 +19,15 @@ import ( "time" "github.com/matrix-org/dendrite/clientapi/auth/authtypes" - "github.com/matrix-org/dendrite/common" "github.com/matrix-org/dendrite/eduserver/cache" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/roomserver/api" "github.com/matrix-org/dendrite/syncapi/types" "github.com/matrix-org/gomatrixserverlib" ) type Database interface { - common.PartitionStorer + internal.PartitionStorer // AllJoinedUsersInRooms returns a map of room ID to a list of all joined user IDs. AllJoinedUsersInRooms(ctx context.Context) (map[string][]string, error) // Events lookups a list of event by their event ID. diff --git a/syncapi/storage/postgres/account_data_table.go b/syncapi/storage/postgres/account_data_table.go index a5e0c1214..e0b87bd6d 100644 --- a/syncapi/storage/postgres/account_data_table.go +++ b/syncapi/storage/postgres/account_data_table.go @@ -20,7 +20,7 @@ import ( "database/sql" "github.com/lib/pq" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/syncapi/storage/tables" "github.com/matrix-org/dendrite/syncapi/types" "github.com/matrix-org/gomatrixserverlib" @@ -113,7 +113,7 @@ func (s *accountDataStatements) SelectAccountDataInRange( if err != nil { return } - defer common.CloseAndLogIfError(ctx, rows, "selectAccountDataInRange: rows.close() failed") + defer internal.CloseAndLogIfError(ctx, rows, "selectAccountDataInRange: rows.close() failed") for rows.Next() { var dataType string @@ -136,7 +136,7 @@ func (s *accountDataStatements) SelectMaxAccountDataID( ctx context.Context, txn *sql.Tx, ) (id int64, err error) { var nullableID sql.NullInt64 - stmt := common.TxStmt(txn, s.selectMaxAccountDataIDStmt) + stmt := internal.TxStmt(txn, s.selectMaxAccountDataIDStmt) err = stmt.QueryRowContext(ctx).Scan(&nullableID) if nullableID.Valid { id = nullableID.Int64 diff --git a/syncapi/storage/postgres/backwards_extremities_table.go b/syncapi/storage/postgres/backwards_extremities_table.go index fa498a401..71569a108 100644 --- a/syncapi/storage/postgres/backwards_extremities_table.go +++ b/syncapi/storage/postgres/backwards_extremities_table.go @@ -18,7 +18,7 @@ import ( "context" "database/sql" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/syncapi/storage/tables" ) @@ -84,7 +84,7 @@ func (s *backwardExtremitiesStatements) SelectBackwardExtremitiesForRoom( if err != nil { return } - defer common.CloseAndLogIfError(ctx, rows, "selectBackwardExtremitiesForRoom: rows.close() failed") + defer internal.CloseAndLogIfError(ctx, rows, "selectBackwardExtremitiesForRoom: rows.close() failed") bwExtrems = make(map[string][]string) for rows.Next() { diff --git a/syncapi/storage/postgres/current_room_state_table.go b/syncapi/storage/postgres/current_room_state_table.go index b6ab72215..cc0fb6b1e 100644 --- a/syncapi/storage/postgres/current_room_state_table.go +++ b/syncapi/storage/postgres/current_room_state_table.go @@ -21,7 +21,7 @@ import ( "encoding/json" "github.com/lib/pq" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/syncapi/storage/tables" "github.com/matrix-org/dendrite/syncapi/types" "github.com/matrix-org/gomatrixserverlib" @@ -142,7 +142,7 @@ func (s *currentRoomStateStatements) SelectJoinedUsers( if err != nil { return nil, err } - defer common.CloseAndLogIfError(ctx, rows, "selectJoinedUsers: rows.close() failed") + defer internal.CloseAndLogIfError(ctx, rows, "selectJoinedUsers: rows.close() failed") result := make(map[string][]string) for rows.Next() { @@ -165,12 +165,12 @@ func (s *currentRoomStateStatements) SelectRoomIDsWithMembership( userID string, membership string, // nolint: unparam ) ([]string, error) { - stmt := common.TxStmt(txn, s.selectRoomIDsWithMembershipStmt) + stmt := internal.TxStmt(txn, s.selectRoomIDsWithMembershipStmt) rows, err := stmt.QueryContext(ctx, userID, membership) if err != nil { return nil, err } - defer common.CloseAndLogIfError(ctx, rows, "selectRoomIDsWithMembership: rows.close() failed") + defer internal.CloseAndLogIfError(ctx, rows, "selectRoomIDsWithMembership: rows.close() failed") var result []string for rows.Next() { @@ -188,7 +188,7 @@ func (s *currentRoomStateStatements) SelectCurrentState( ctx context.Context, txn *sql.Tx, roomID string, stateFilter *gomatrixserverlib.StateFilter, ) ([]gomatrixserverlib.HeaderedEvent, error) { - stmt := common.TxStmt(txn, s.selectCurrentStateStmt) + stmt := internal.TxStmt(txn, s.selectCurrentStateStmt) rows, err := stmt.QueryContext(ctx, roomID, pq.StringArray(stateFilter.Senders), pq.StringArray(stateFilter.NotSenders), @@ -200,7 +200,7 @@ func (s *currentRoomStateStatements) SelectCurrentState( if err != nil { return nil, err } - defer common.CloseAndLogIfError(ctx, rows, "selectCurrentState: rows.close() failed") + defer internal.CloseAndLogIfError(ctx, rows, "selectCurrentState: rows.close() failed") return rowsToEvents(rows) } @@ -208,7 +208,7 @@ func (s *currentRoomStateStatements) SelectCurrentState( func (s *currentRoomStateStatements) DeleteRoomStateByEventID( ctx context.Context, txn *sql.Tx, eventID string, ) error { - stmt := common.TxStmt(txn, s.deleteRoomStateByEventIDStmt) + stmt := internal.TxStmt(txn, s.deleteRoomStateByEventIDStmt) _, err := stmt.ExecContext(ctx, eventID) return err } @@ -231,7 +231,7 @@ func (s *currentRoomStateStatements) UpsertRoomState( } // upsert state event - stmt := common.TxStmt(txn, s.upsertRoomStateStmt) + stmt := internal.TxStmt(txn, s.upsertRoomStateStmt) _, err = stmt.ExecContext( ctx, event.RoomID(), @@ -250,12 +250,12 @@ func (s *currentRoomStateStatements) UpsertRoomState( func (s *currentRoomStateStatements) SelectEventsWithEventIDs( ctx context.Context, txn *sql.Tx, eventIDs []string, ) ([]types.StreamEvent, error) { - stmt := common.TxStmt(txn, s.selectEventsWithEventIDsStmt) + stmt := internal.TxStmt(txn, s.selectEventsWithEventIDsStmt) rows, err := stmt.QueryContext(ctx, pq.StringArray(eventIDs)) if err != nil { return nil, err } - defer common.CloseAndLogIfError(ctx, rows, "selectEventsWithEventIDs: rows.close() failed") + defer internal.CloseAndLogIfError(ctx, rows, "selectEventsWithEventIDs: rows.close() failed") return rowsToStreamEvents(rows) } diff --git a/syncapi/storage/postgres/invites_table.go b/syncapi/storage/postgres/invites_table.go index 01f2e7f44..caa12d2f8 100644 --- a/syncapi/storage/postgres/invites_table.go +++ b/syncapi/storage/postgres/invites_table.go @@ -20,7 +20,7 @@ import ( "database/sql" "encoding/json" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/syncapi/storage/tables" "github.com/matrix-org/dendrite/syncapi/types" "github.com/matrix-org/gomatrixserverlib" @@ -119,12 +119,12 @@ func (s *inviteEventsStatements) DeleteInviteEvent( func (s *inviteEventsStatements) SelectInviteEventsInRange( ctx context.Context, txn *sql.Tx, targetUserID string, r types.Range, ) (map[string]gomatrixserverlib.HeaderedEvent, error) { - stmt := common.TxStmt(txn, s.selectInviteEventsInRangeStmt) + stmt := internal.TxStmt(txn, s.selectInviteEventsInRangeStmt) rows, err := stmt.QueryContext(ctx, targetUserID, r.Low(), r.High()) if err != nil { return nil, err } - defer common.CloseAndLogIfError(ctx, rows, "selectInviteEventsInRange: rows.close() failed") + defer internal.CloseAndLogIfError(ctx, rows, "selectInviteEventsInRange: rows.close() failed") result := map[string]gomatrixserverlib.HeaderedEvent{} for rows.Next() { var ( @@ -149,7 +149,7 @@ func (s *inviteEventsStatements) SelectMaxInviteID( ctx context.Context, txn *sql.Tx, ) (id int64, err error) { var nullableID sql.NullInt64 - stmt := common.TxStmt(txn, s.selectMaxInviteIDStmt) + stmt := internal.TxStmt(txn, s.selectMaxInviteIDStmt) err = stmt.QueryRowContext(ctx).Scan(&nullableID) if nullableID.Valid { id = nullableID.Int64 diff --git a/syncapi/storage/postgres/output_room_events_table.go b/syncapi/storage/postgres/output_room_events_table.go index 5020d1e7d..ae6dfb381 100644 --- a/syncapi/storage/postgres/output_room_events_table.go +++ b/syncapi/storage/postgres/output_room_events_table.go @@ -26,7 +26,7 @@ import ( "github.com/matrix-org/dendrite/syncapi/types" "github.com/lib/pq" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/gomatrixserverlib" log "github.com/sirupsen/logrus" ) @@ -158,7 +158,7 @@ func (s *outputRoomEventsStatements) SelectStateInRange( ctx context.Context, txn *sql.Tx, r types.Range, stateFilter *gomatrixserverlib.StateFilter, ) (map[string]map[string]bool, map[string]types.StreamEvent, error) { - stmt := common.TxStmt(txn, s.selectStateInRangeStmt) + stmt := internal.TxStmt(txn, s.selectStateInRangeStmt) rows, err := stmt.QueryContext( ctx, r.Low(), r.High(), @@ -172,7 +172,7 @@ func (s *outputRoomEventsStatements) SelectStateInRange( if err != nil { return nil, nil, err } - defer common.CloseAndLogIfError(ctx, rows, "selectStateInRange: rows.close() failed") + defer internal.CloseAndLogIfError(ctx, rows, "selectStateInRange: rows.close() failed") // Fetch all the state change events for all rooms between the two positions then loop each event and: // - Keep a cache of the event by ID (99% of state change events are for the event itself) // - For each room ID, build up an array of event IDs which represents cumulative adds/removes @@ -239,7 +239,7 @@ func (s *outputRoomEventsStatements) SelectMaxEventID( ctx context.Context, txn *sql.Tx, ) (id int64, err error) { var nullableID sql.NullInt64 - stmt := common.TxStmt(txn, s.selectMaxEventIDStmt) + stmt := internal.TxStmt(txn, s.selectMaxEventIDStmt) err = stmt.QueryRowContext(ctx).Scan(&nullableID) if nullableID.Valid { id = nullableID.Int64 @@ -275,7 +275,7 @@ func (s *outputRoomEventsStatements) InsertEvent( return } - stmt := common.TxStmt(txn, s.insertEventStmt) + stmt := internal.TxStmt(txn, s.insertEventStmt) err = stmt.QueryRowContext( ctx, event.RoomID(), @@ -303,15 +303,15 @@ func (s *outputRoomEventsStatements) SelectRecentEvents( ) ([]types.StreamEvent, error) { var stmt *sql.Stmt if onlySyncEvents { - stmt = common.TxStmt(txn, s.selectRecentEventsForSyncStmt) + stmt = internal.TxStmt(txn, s.selectRecentEventsForSyncStmt) } else { - stmt = common.TxStmt(txn, s.selectRecentEventsStmt) + stmt = internal.TxStmt(txn, s.selectRecentEventsStmt) } rows, err := stmt.QueryContext(ctx, roomID, r.Low(), r.High(), limit) if err != nil { return nil, err } - defer common.CloseAndLogIfError(ctx, rows, "selectRecentEvents: rows.close() failed") + defer internal.CloseAndLogIfError(ctx, rows, "selectRecentEvents: rows.close() failed") events, err := rowsToStreamEvents(rows) if err != nil { return nil, err @@ -333,12 +333,12 @@ func (s *outputRoomEventsStatements) SelectEarlyEvents( ctx context.Context, txn *sql.Tx, roomID string, r types.Range, limit int, ) ([]types.StreamEvent, error) { - stmt := common.TxStmt(txn, s.selectEarlyEventsStmt) + stmt := internal.TxStmt(txn, s.selectEarlyEventsStmt) rows, err := stmt.QueryContext(ctx, roomID, r.Low(), r.High(), limit) if err != nil { return nil, err } - defer common.CloseAndLogIfError(ctx, rows, "selectEarlyEvents: rows.close() failed") + defer internal.CloseAndLogIfError(ctx, rows, "selectEarlyEvents: rows.close() failed") events, err := rowsToStreamEvents(rows) if err != nil { return nil, err @@ -357,12 +357,12 @@ func (s *outputRoomEventsStatements) SelectEarlyEvents( func (s *outputRoomEventsStatements) SelectEvents( ctx context.Context, txn *sql.Tx, eventIDs []string, ) ([]types.StreamEvent, error) { - stmt := common.TxStmt(txn, s.selectEventsStmt) + stmt := internal.TxStmt(txn, s.selectEventsStmt) rows, err := stmt.QueryContext(ctx, pq.StringArray(eventIDs)) if err != nil { return nil, err } - defer common.CloseAndLogIfError(ctx, rows, "selectEvents: rows.close() failed") + defer internal.CloseAndLogIfError(ctx, rows, "selectEvents: rows.close() failed") return rowsToStreamEvents(rows) } diff --git a/syncapi/storage/postgres/output_room_events_topology_table.go b/syncapi/storage/postgres/output_room_events_topology_table.go index 9fc5f5194..ffbeece30 100644 --- a/syncapi/storage/postgres/output_room_events_topology_table.go +++ b/syncapi/storage/postgres/output_room_events_topology_table.go @@ -18,7 +18,7 @@ import ( "context" "database/sql" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/syncapi/storage/tables" "github.com/matrix-org/dendrite/syncapi/types" @@ -139,7 +139,7 @@ func (s *outputRoomEventsTopologyStatements) SelectEventIDsInRange( } else if err != nil { return } - defer common.CloseAndLogIfError(ctx, rows, "selectEventIDsInRange: rows.close() failed") + defer internal.CloseAndLogIfError(ctx, rows, "selectEventIDsInRange: rows.close() failed") // Return the IDs. var eventID string diff --git a/syncapi/storage/postgres/syncserver.go b/syncapi/storage/postgres/syncserver.go index d44f8b7e6..dc73350a2 100644 --- a/syncapi/storage/postgres/syncserver.go +++ b/syncapi/storage/postgres/syncserver.go @@ -22,8 +22,8 @@ import ( // Import the postgres database driver. _ "github.com/lib/pq" - "github.com/matrix-org/dendrite/common" "github.com/matrix-org/dendrite/eduserver/cache" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/syncapi/storage/shared" ) @@ -32,11 +32,11 @@ import ( type SyncServerDatasource struct { shared.Database db *sql.DB - common.PartitionOffsetStatements + internal.PartitionOffsetStatements } // NewDatabase creates a new sync server database -func NewDatabase(dbDataSourceName string, dbProperties common.DbProperties) (*SyncServerDatasource, error) { +func NewDatabase(dbDataSourceName string, dbProperties internal.DbProperties) (*SyncServerDatasource, error) { var d SyncServerDatasource var err error if d.db, err = sqlutil.Open("postgres", dbDataSourceName, dbProperties); err != nil { diff --git a/syncapi/storage/shared/syncserver.go b/syncapi/storage/shared/syncserver.go index 543e5b4a3..145a3dbf3 100644 --- a/syncapi/storage/shared/syncserver.go +++ b/syncapi/storage/shared/syncserver.go @@ -8,8 +8,8 @@ import ( "time" "github.com/matrix-org/dendrite/clientapi/auth/authtypes" - "github.com/matrix-org/dendrite/common" "github.com/matrix-org/dendrite/eduserver/cache" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/roomserver/api" "github.com/matrix-org/dendrite/syncapi/storage/tables" "github.com/matrix-org/dendrite/syncapi/types" @@ -106,7 +106,7 @@ func (d *Database) GetStateEvent( func (d *Database) GetStateEventsForRoom( ctx context.Context, roomID string, stateFilter *gomatrixserverlib.StateFilter, ) (stateEvents []gomatrixserverlib.HeaderedEvent, err error) { - err = common.WithTransaction(d.DB, func(txn *sql.Tx) error { + err = internal.WithTransaction(d.DB, func(txn *sql.Tx) error { stateEvents, err = d.CurrentRoomState.SelectCurrentState(ctx, txn, roomID, stateFilter) return err }) @@ -116,7 +116,7 @@ func (d *Database) GetStateEventsForRoom( func (d *Database) SyncStreamPosition(ctx context.Context) (types.StreamPosition, error) { var maxID int64 var err error - err = common.WithTransaction(d.DB, func(txn *sql.Tx) error { + err = internal.WithTransaction(d.DB, func(txn *sql.Tx) error { maxID, err = d.OutputEvents.SelectMaxEventID(ctx, txn) if err != nil { return err @@ -148,7 +148,7 @@ func (d *Database) SyncStreamPosition(ctx context.Context) (types.StreamPosition func (d *Database) AddInviteEvent( ctx context.Context, inviteEvent gomatrixserverlib.HeaderedEvent, ) (sp types.StreamPosition, err error) { - err = common.WithTransaction(d.DB, func(txn *sql.Tx) error { + err = internal.WithTransaction(d.DB, func(txn *sql.Tx) error { sp, err = d.Invites.InsertInviteEvent(ctx, txn, inviteEvent) return err }) @@ -187,7 +187,7 @@ func (d *Database) GetAccountDataInRange( func (d *Database) UpsertAccountData( ctx context.Context, userID, roomID, dataType string, ) (sp types.StreamPosition, err error) { - err = common.WithTransaction(d.DB, func(txn *sql.Tx) error { + err = internal.WithTransaction(d.DB, func(txn *sql.Tx) error { sp, err = d.AccountData.InsertAccountData(ctx, txn, userID, roomID, dataType) return err }) @@ -255,7 +255,7 @@ func (d *Database) WriteEvent( addStateEventIDs, removeStateEventIDs []string, transactionID *api.TransactionID, excludeFromSync bool, ) (pduPosition types.StreamPosition, returnErr error) { - returnErr = common.WithTransaction(d.DB, func(txn *sql.Tx) error { + returnErr = internal.WithTransaction(d.DB, func(txn *sql.Tx) error { var err error pos, err := d.OutputEvents.InsertEvent( ctx, txn, ev, addStateEventIDs, removeStateEventIDs, transactionID, excludeFromSync, @@ -355,7 +355,7 @@ func (d *Database) GetEventsInTopologicalRange( } func (d *Database) SyncPosition(ctx context.Context) (tok types.StreamingToken, err error) { - err = common.WithTransaction(d.DB, func(txn *sql.Tx) error { + err = internal.WithTransaction(d.DB, func(txn *sql.Tx) error { pos, err := d.syncPositionTx(ctx, txn) if err != nil { return err @@ -434,7 +434,7 @@ func (d *Database) addPDUDeltaToResponse( } var succeeded bool defer func() { - txerr := common.EndTransaction(txn, &succeeded) + txerr := internal.EndTransaction(txn, &succeeded) if err == nil && txerr != nil { err = txerr } @@ -588,7 +588,7 @@ func (d *Database) getResponseWithPDUsForCompleteSync( } var succeeded bool defer func() { - txerr := common.EndTransaction(txn, &succeeded) + txerr := internal.EndTransaction(txn, &succeeded) if err == nil && txerr != nil { err = txerr } diff --git a/syncapi/storage/sqlite3/account_data_table.go b/syncapi/storage/sqlite3/account_data_table.go index 435a399c3..a3c797342 100644 --- a/syncapi/storage/sqlite3/account_data_table.go +++ b/syncapi/storage/sqlite3/account_data_table.go @@ -19,7 +19,7 @@ import ( "context" "database/sql" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/syncapi/storage/tables" "github.com/matrix-org/dendrite/syncapi/types" @@ -100,7 +100,7 @@ func (s *accountDataStatements) SelectAccountDataInRange( if err != nil { return } - defer common.CloseAndLogIfError(ctx, rows, "selectAccountDataInRange: rows.close() failed") + defer internal.CloseAndLogIfError(ctx, rows, "selectAccountDataInRange: rows.close() failed") var entries int diff --git a/syncapi/storage/sqlite3/backwards_extremities_table.go b/syncapi/storage/sqlite3/backwards_extremities_table.go index c5d9cae59..e16e54a6f 100644 --- a/syncapi/storage/sqlite3/backwards_extremities_table.go +++ b/syncapi/storage/sqlite3/backwards_extremities_table.go @@ -18,7 +18,7 @@ import ( "context" "database/sql" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/syncapi/storage/tables" ) @@ -84,7 +84,7 @@ func (s *backwardExtremitiesStatements) SelectBackwardExtremitiesForRoom( if err != nil { return } - defer common.CloseAndLogIfError(ctx, rows, "selectBackwardExtremitiesForRoom: rows.close() failed") + defer internal.CloseAndLogIfError(ctx, rows, "selectBackwardExtremitiesForRoom: rows.close() failed") bwExtrems = make(map[string][]string) for rows.Next() { diff --git a/syncapi/storage/sqlite3/current_room_state_table.go b/syncapi/storage/sqlite3/current_room_state_table.go index b540fbc69..b0cf1297c 100644 --- a/syncapi/storage/sqlite3/current_room_state_table.go +++ b/syncapi/storage/sqlite3/current_room_state_table.go @@ -21,7 +21,7 @@ import ( "encoding/json" "strings" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/syncapi/storage/tables" "github.com/matrix-org/dendrite/syncapi/types" "github.com/matrix-org/gomatrixserverlib" @@ -129,7 +129,7 @@ func (s *currentRoomStateStatements) SelectJoinedUsers( if err != nil { return nil, err } - defer common.CloseAndLogIfError(ctx, rows, "selectJoinedUsers: rows.close() failed") + defer internal.CloseAndLogIfError(ctx, rows, "selectJoinedUsers: rows.close() failed") result := make(map[string][]string) for rows.Next() { @@ -152,12 +152,12 @@ func (s *currentRoomStateStatements) SelectRoomIDsWithMembership( userID string, membership string, // nolint: unparam ) ([]string, error) { - stmt := common.TxStmt(txn, s.selectRoomIDsWithMembershipStmt) + stmt := internal.TxStmt(txn, s.selectRoomIDsWithMembershipStmt) rows, err := stmt.QueryContext(ctx, userID, membership) if err != nil { return nil, err } - defer common.CloseAndLogIfError(ctx, rows, "selectRoomIDsWithMembership: rows.close() failed") + defer internal.CloseAndLogIfError(ctx, rows, "selectRoomIDsWithMembership: rows.close() failed") var result []string for rows.Next() { @@ -175,7 +175,7 @@ func (s *currentRoomStateStatements) SelectCurrentState( ctx context.Context, txn *sql.Tx, roomID string, stateFilterPart *gomatrixserverlib.StateFilter, ) ([]gomatrixserverlib.HeaderedEvent, error) { - stmt := common.TxStmt(txn, s.selectCurrentStateStmt) + stmt := internal.TxStmt(txn, s.selectCurrentStateStmt) rows, err := stmt.QueryContext(ctx, roomID, nil, // FIXME: pq.StringArray(stateFilterPart.Senders), nil, // FIXME: pq.StringArray(stateFilterPart.NotSenders), @@ -187,7 +187,7 @@ func (s *currentRoomStateStatements) SelectCurrentState( if err != nil { return nil, err } - defer common.CloseAndLogIfError(ctx, rows, "selectCurrentState: rows.close() failed") + defer internal.CloseAndLogIfError(ctx, rows, "selectCurrentState: rows.close() failed") return rowsToEvents(rows) } @@ -195,7 +195,7 @@ func (s *currentRoomStateStatements) SelectCurrentState( func (s *currentRoomStateStatements) DeleteRoomStateByEventID( ctx context.Context, txn *sql.Tx, eventID string, ) error { - stmt := common.TxStmt(txn, s.deleteRoomStateByEventIDStmt) + stmt := internal.TxStmt(txn, s.deleteRoomStateByEventIDStmt) _, err := stmt.ExecContext(ctx, eventID) return err } @@ -218,7 +218,7 @@ func (s *currentRoomStateStatements) UpsertRoomState( } // upsert state event - stmt := common.TxStmt(txn, s.upsertRoomStateStmt) + stmt := internal.TxStmt(txn, s.upsertRoomStateStmt) _, err = stmt.ExecContext( ctx, event.RoomID(), @@ -241,12 +241,12 @@ func (s *currentRoomStateStatements) SelectEventsWithEventIDs( for k, v := range eventIDs { iEventIDs[k] = v } - query := strings.Replace(selectEventsWithEventIDsSQL, "($1)", common.QueryVariadic(len(iEventIDs)), 1) + query := strings.Replace(selectEventsWithEventIDsSQL, "($1)", internal.QueryVariadic(len(iEventIDs)), 1) rows, err := txn.QueryContext(ctx, query, iEventIDs...) if err != nil { return nil, err } - defer common.CloseAndLogIfError(ctx, rows, "selectEventsWithEventIDs: rows.close() failed") + defer internal.CloseAndLogIfError(ctx, rows, "selectEventsWithEventIDs: rows.close() failed") return rowsToStreamEvents(rows) } diff --git a/syncapi/storage/sqlite3/invites_table.go b/syncapi/storage/sqlite3/invites_table.go index 9cb184f20..64b523394 100644 --- a/syncapi/storage/sqlite3/invites_table.go +++ b/syncapi/storage/sqlite3/invites_table.go @@ -20,7 +20,7 @@ import ( "database/sql" "encoding/json" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/syncapi/storage/tables" "github.com/matrix-org/dendrite/syncapi/types" "github.com/matrix-org/gomatrixserverlib" @@ -123,12 +123,12 @@ func (s *inviteEventsStatements) DeleteInviteEvent( func (s *inviteEventsStatements) SelectInviteEventsInRange( ctx context.Context, txn *sql.Tx, targetUserID string, r types.Range, ) (map[string]gomatrixserverlib.HeaderedEvent, error) { - stmt := common.TxStmt(txn, s.selectInviteEventsInRangeStmt) + stmt := internal.TxStmt(txn, s.selectInviteEventsInRangeStmt) rows, err := stmt.QueryContext(ctx, targetUserID, r.Low(), r.High()) if err != nil { return nil, err } - defer common.CloseAndLogIfError(ctx, rows, "selectInviteEventsInRange: rows.close() failed") + defer internal.CloseAndLogIfError(ctx, rows, "selectInviteEventsInRange: rows.close() failed") result := map[string]gomatrixserverlib.HeaderedEvent{} for rows.Next() { var ( @@ -153,7 +153,7 @@ func (s *inviteEventsStatements) SelectMaxInviteID( ctx context.Context, txn *sql.Tx, ) (id int64, err error) { var nullableID sql.NullInt64 - stmt := common.TxStmt(txn, s.selectMaxInviteIDStmt) + stmt := internal.TxStmt(txn, s.selectMaxInviteIDStmt) err = stmt.QueryRowContext(ctx).Scan(&nullableID) if nullableID.Valid { id = nullableID.Int64 diff --git a/syncapi/storage/sqlite3/output_room_events_table.go b/syncapi/storage/sqlite3/output_room_events_table.go index c89e007e6..4a84ecc6c 100644 --- a/syncapi/storage/sqlite3/output_room_events_table.go +++ b/syncapi/storage/sqlite3/output_room_events_table.go @@ -25,7 +25,7 @@ import ( "github.com/matrix-org/dendrite/syncapi/storage/tables" "github.com/matrix-org/dendrite/syncapi/types" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/gomatrixserverlib" log "github.com/sirupsen/logrus" ) @@ -149,7 +149,7 @@ func (s *outputRoomEventsStatements) SelectStateInRange( ctx context.Context, txn *sql.Tx, r types.Range, stateFilterPart *gomatrixserverlib.StateFilter, ) (map[string]map[string]bool, map[string]types.StreamEvent, error) { - stmt := common.TxStmt(txn, s.selectStateInRangeStmt) + stmt := internal.TxStmt(txn, s.selectStateInRangeStmt) rows, err := stmt.QueryContext( ctx, r.Low(), r.High(), @@ -236,7 +236,7 @@ func (s *outputRoomEventsStatements) SelectMaxEventID( ctx context.Context, txn *sql.Tx, ) (id int64, err error) { var nullableID sql.NullInt64 - stmt := common.TxStmt(txn, s.selectMaxEventIDStmt) + stmt := internal.TxStmt(txn, s.selectMaxEventIDStmt) err = stmt.QueryRowContext(ctx).Scan(&nullableID) if nullableID.Valid { id = nullableID.Int64 @@ -286,7 +286,7 @@ func (s *outputRoomEventsStatements) InsertEvent( return } - insertStmt := common.TxStmt(txn, s.insertEventStmt) + insertStmt := internal.TxStmt(txn, s.insertEventStmt) _, err = insertStmt.ExecContext( ctx, streamPos, @@ -313,16 +313,16 @@ func (s *outputRoomEventsStatements) SelectRecentEvents( ) ([]types.StreamEvent, error) { var stmt *sql.Stmt if onlySyncEvents { - stmt = common.TxStmt(txn, s.selectRecentEventsForSyncStmt) + stmt = internal.TxStmt(txn, s.selectRecentEventsForSyncStmt) } else { - stmt = common.TxStmt(txn, s.selectRecentEventsStmt) + stmt = internal.TxStmt(txn, s.selectRecentEventsStmt) } rows, err := stmt.QueryContext(ctx, roomID, r.Low(), r.High(), limit) if err != nil { return nil, err } - defer common.CloseAndLogIfError(ctx, rows, "selectRecentEvents: rows.close() failed") + defer internal.CloseAndLogIfError(ctx, rows, "selectRecentEvents: rows.close() failed") events, err := rowsToStreamEvents(rows) if err != nil { return nil, err @@ -342,12 +342,12 @@ func (s *outputRoomEventsStatements) SelectEarlyEvents( ctx context.Context, txn *sql.Tx, roomID string, r types.Range, limit int, ) ([]types.StreamEvent, error) { - stmt := common.TxStmt(txn, s.selectEarlyEventsStmt) + stmt := internal.TxStmt(txn, s.selectEarlyEventsStmt) rows, err := stmt.QueryContext(ctx, roomID, r.Low(), r.High(), limit) if err != nil { return nil, err } - defer common.CloseAndLogIfError(ctx, rows, "selectEarlyEvents: rows.close() failed") + defer internal.CloseAndLogIfError(ctx, rows, "selectEarlyEvents: rows.close() failed") events, err := rowsToStreamEvents(rows) if err != nil { return nil, err @@ -367,7 +367,7 @@ func (s *outputRoomEventsStatements) SelectEvents( ctx context.Context, txn *sql.Tx, eventIDs []string, ) ([]types.StreamEvent, error) { var returnEvents []types.StreamEvent - stmt := common.TxStmt(txn, s.selectEventsStmt) + stmt := internal.TxStmt(txn, s.selectEventsStmt) for _, eventID := range eventIDs { rows, err := stmt.QueryContext(ctx, eventID) if err != nil { @@ -376,7 +376,7 @@ func (s *outputRoomEventsStatements) SelectEvents( if streamEvents, err := rowsToStreamEvents(rows); err == nil { returnEvents = append(returnEvents, streamEvents...) } - common.CloseAndLogIfError(ctx, rows, "selectEvents: rows.close() failed") + internal.CloseAndLogIfError(ctx, rows, "selectEvents: rows.close() failed") } return returnEvents, nil } diff --git a/syncapi/storage/sqlite3/output_room_events_topology_table.go b/syncapi/storage/sqlite3/output_room_events_topology_table.go index 22779238c..0d727cb18 100644 --- a/syncapi/storage/sqlite3/output_room_events_topology_table.go +++ b/syncapi/storage/sqlite3/output_room_events_topology_table.go @@ -18,7 +18,7 @@ import ( "context" "database/sql" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/syncapi/storage/tables" "github.com/matrix-org/dendrite/syncapi/types" "github.com/matrix-org/gomatrixserverlib" @@ -102,7 +102,7 @@ func NewSqliteTopologyTable(db *sql.DB) (tables.Topology, error) { func (s *outputRoomEventsTopologyStatements) InsertEventInTopology( ctx context.Context, txn *sql.Tx, event *gomatrixserverlib.HeaderedEvent, pos types.StreamPosition, ) (err error) { - stmt := common.TxStmt(txn, s.insertEventInTopologyStmt) + stmt := internal.TxStmt(txn, s.insertEventInTopologyStmt) _, err = stmt.ExecContext( ctx, event.EventID(), event.Depth(), event.RoomID(), pos, ) @@ -118,9 +118,9 @@ func (s *outputRoomEventsTopologyStatements) SelectEventIDsInRange( // is requested or not. var stmt *sql.Stmt if chronologicalOrder { - stmt = common.TxStmt(txn, s.selectEventIDsInRangeASCStmt) + stmt = internal.TxStmt(txn, s.selectEventIDsInRangeASCStmt) } else { - stmt = common.TxStmt(txn, s.selectEventIDsInRangeDESCStmt) + stmt = internal.TxStmt(txn, s.selectEventIDsInRangeDESCStmt) } // Query the event IDs. @@ -149,7 +149,7 @@ func (s *outputRoomEventsTopologyStatements) SelectEventIDsInRange( func (s *outputRoomEventsTopologyStatements) SelectPositionInTopology( ctx context.Context, txn *sql.Tx, eventID string, ) (pos types.StreamPosition, spos types.StreamPosition, err error) { - stmt := common.TxStmt(txn, s.selectPositionInTopologyStmt) + stmt := internal.TxStmt(txn, s.selectPositionInTopologyStmt) err = stmt.QueryRowContext(ctx, eventID).Scan(&pos, &spos) return } @@ -157,7 +157,7 @@ func (s *outputRoomEventsTopologyStatements) SelectPositionInTopology( func (s *outputRoomEventsTopologyStatements) SelectMaxPositionInTopology( ctx context.Context, txn *sql.Tx, roomID string, ) (pos types.StreamPosition, spos types.StreamPosition, err error) { - stmt := common.TxStmt(txn, s.selectMaxPositionInTopologyStmt) + stmt := internal.TxStmt(txn, s.selectMaxPositionInTopologyStmt) err = stmt.QueryRowContext(ctx, roomID).Scan(&pos, &spos) return } diff --git a/syncapi/storage/sqlite3/stream_id_table.go b/syncapi/storage/sqlite3/stream_id_table.go index 260f7a95d..3bfe22dd0 100644 --- a/syncapi/storage/sqlite3/stream_id_table.go +++ b/syncapi/storage/sqlite3/stream_id_table.go @@ -4,7 +4,7 @@ import ( "context" "database/sql" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/syncapi/types" ) @@ -46,8 +46,8 @@ func (s *streamIDStatements) prepare(db *sql.DB) (err error) { } func (s *streamIDStatements) nextStreamID(ctx context.Context, txn *sql.Tx) (pos types.StreamPosition, err error) { - increaseStmt := common.TxStmt(txn, s.increaseStreamIDStmt) - selectStmt := common.TxStmt(txn, s.selectStreamIDStmt) + increaseStmt := internal.TxStmt(txn, s.increaseStreamIDStmt) + selectStmt := internal.TxStmt(txn, s.selectStreamIDStmt) if _, err = increaseStmt.ExecContext(ctx, "global"); err != nil { return } diff --git a/syncapi/storage/sqlite3/syncserver.go b/syncapi/storage/sqlite3/syncserver.go index e23aeca4e..8ab1d4040 100644 --- a/syncapi/storage/sqlite3/syncserver.go +++ b/syncapi/storage/sqlite3/syncserver.go @@ -25,8 +25,8 @@ import ( // Import the sqlite3 package _ "github.com/mattn/go-sqlite3" - "github.com/matrix-org/dendrite/common" "github.com/matrix-org/dendrite/eduserver/cache" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/syncapi/storage/shared" ) @@ -35,7 +35,7 @@ import ( type SyncServerDatasource struct { shared.Database db *sql.DB - common.PartitionOffsetStatements + internal.PartitionOffsetStatements streamID streamIDStatements } @@ -55,7 +55,7 @@ func NewDatabase(dataSourceName string) (*SyncServerDatasource, error) { } else { return nil, errors.New("no filename or path in connect string") } - if d.db, err = sqlutil.Open(common.SQLiteDriverName(), cs, nil); err != nil { + if d.db, err = sqlutil.Open(internal.SQLiteDriverName(), cs, nil); err != nil { return nil, err } if err = d.prepare(); err != nil { diff --git a/syncapi/storage/storage.go b/syncapi/storage/storage.go index 76a4b7a4e..a4275da0c 100644 --- a/syncapi/storage/storage.go +++ b/syncapi/storage/storage.go @@ -19,13 +19,13 @@ package storage import ( "net/url" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/syncapi/storage/postgres" "github.com/matrix-org/dendrite/syncapi/storage/sqlite3" ) // NewSyncServerDatasource opens a database connection. -func NewSyncServerDatasource(dataSourceName string, dbProperties common.DbProperties) (Database, error) { +func NewSyncServerDatasource(dataSourceName string, dbProperties internal.DbProperties) (Database, error) { uri, err := url.Parse(dataSourceName) if err != nil { return postgres.NewDatabase(dataSourceName, dbProperties) diff --git a/syncapi/storage/storage_wasm.go b/syncapi/storage/storage_wasm.go index 666179afb..a2b269a14 100644 --- a/syncapi/storage/storage_wasm.go +++ b/syncapi/storage/storage_wasm.go @@ -18,14 +18,14 @@ import ( "fmt" "net/url" - "github.com/matrix-org/dendrite/common" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/syncapi/storage/sqlite3" ) // NewPublicRoomsServerDatabase opens a database connection. func NewSyncServerDatasource( dataSourceName string, - dbProperties common.DbProperties, // nolint:unparam + dbProperties internal.DbProperties, // nolint:unparam ) (Database, error) { uri, err := url.Parse(dataSourceName) if err != nil { diff --git a/syncapi/syncapi.go b/syncapi/syncapi.go index 4219d5603..022ed7bab 100644 --- a/syncapi/syncapi.go +++ b/syncapi/syncapi.go @@ -20,8 +20,8 @@ import ( "github.com/sirupsen/logrus" "github.com/matrix-org/dendrite/clientapi/auth/storage/accounts" - "github.com/matrix-org/dendrite/common/basecomponent" - "github.com/matrix-org/dendrite/common/config" + "github.com/matrix-org/dendrite/internal/basecomponent" + "github.com/matrix-org/dendrite/internal/config" "github.com/matrix-org/dendrite/roomserver/api" "github.com/matrix-org/gomatrixserverlib"