Update startup logic for HTTP mode

This commit is contained in:
Neil Alexander 2021-11-02 17:08:46 +00:00
parent 60af5bee47
commit 51ba578f96
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944

View file

@ -109,22 +109,15 @@ func main() {
federationsender.AddInternalRoutes(base.InternalAPIMux, fsAPI) federationsender.AddInternalRoutes(base.InternalAPIMux, fsAPI)
fsAPI = base.FederationSenderHTTPClient() fsAPI = base.FederationSenderHTTPClient()
} }
// The underlying roomserver implementation needs to be able to call the fedsender.
// This is different to rsAPI which can be the http client which doesn't need this dependency
rsImpl.SetFederationSenderAPI(fsAPI)
keyAPI := keyserver.NewInternalAPI(base, &base.Cfg.KeyServer, fsAPI) keyImpl := keyserver.NewInternalAPI(base, &base.Cfg.KeyServer, fsAPI)
userAPI := userapi.NewInternalAPI(accountDB, &cfg.UserAPI, cfg.Derived.ApplicationServices, keyAPI) keyAPI := keyImpl
// The appservice might try to create a new service account on startup, which will fail if running in httpapi mode
// since there won't be an userapi endpoint yet, so move this before switching to httpapi mode.
asAPI := appservice.NewInternalAPI(base, userAPI, rsAPI)
if base.UseHTTPAPIs { if base.UseHTTPAPIs {
appservice.AddInternalRoutes(base.InternalAPIMux, asAPI) keyserver.AddInternalRoutes(base.InternalAPIMux, keyAPI)
asAPI = base.AppserviceHTTPClient() keyAPI = base.KeyServerHTTPClient()
} }
rsAPI.SetAppserviceAPI(asAPI)
userAPI := userapi.NewInternalAPI(accountDB, &cfg.UserAPI, cfg.Derived.ApplicationServices, keyAPI)
if base.UseHTTPAPIs { if base.UseHTTPAPIs {
userapi.AddInternalRoutes(base.InternalAPIMux, userAPI) userapi.AddInternalRoutes(base.InternalAPIMux, userAPI)
userAPI = base.UserAPIClient() userAPI = base.UserAPIClient()
@ -134,14 +127,20 @@ func main() {
Impl: userAPI, Impl: userAPI,
} }
} }
keyAPI.SetUserAPI(userAPI)
// needs to be after the SetUserAPI call above asAPI := appservice.NewInternalAPI(base, userAPI, rsAPI)
if base.UseHTTPAPIs { if base.UseHTTPAPIs {
keyserver.AddInternalRoutes(base.InternalAPIMux, keyAPI) appservice.AddInternalRoutes(base.InternalAPIMux, asAPI)
keyAPI = base.KeyServerHTTPClient() asAPI = base.AppserviceHTTPClient()
} }
// The underlying roomserver implementation needs to be able to call the fedsender.
// This is different to rsAPI which can be the http client which doesn't need this
// dependency. Other components also need updating after their dependencies are up.
rsImpl.SetFederationSenderAPI(fsAPI)
rsImpl.SetAppserviceAPI(asAPI)
keyImpl.SetUserAPI(userAPI)
eduInputAPI := eduserver.NewInternalAPI( eduInputAPI := eduserver.NewInternalAPI(
base, cache.New(), userAPI, base, cache.New(), userAPI,
) )