aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorNeil Alexander <neilalexander@users.noreply.github.com>2020-08-13 12:16:37 +0100
committerGitHub <noreply@github.com>2020-08-13 12:16:37 +0100
commit9677a95afc529d1766d487db46965266c6fbaa6a (patch)
treed98ccf518a3f8386054f93be4138988def9848be /cmd
parent820c56c165ec8f0409d23cd151a7ff89fbe09ffa (diff)
API setup refactoring (#1266)
* Start HTTP endpoint refactoring * Update SetupAndServeHTTP * Fix builds * Don't set up external listener if no address configured * TLS HTTP setup * Break apart client/federation/key/media muxes * Tweaks * Fix P2P demos * Fix media API routing * Review comments @Kegsay * Update sample config * Fix gobind build * Fix External -> Public in federation API test
Diffstat (limited to 'cmd')
-rw-r--r--cmd/dendrite-appservice-server/main.go7
-rw-r--r--cmd/dendrite-client-api-server/main.go9
-rw-r--r--cmd/dendrite-current-state-server/main.go7
-rw-r--r--cmd/dendrite-demo-libp2p/main.go28
-rw-r--r--cmd/dendrite-demo-yggdrasil/main.go29
-rw-r--r--cmd/dendrite-edu-server/main.go7
-rw-r--r--cmd/dendrite-federation-api-server/main.go10
-rw-r--r--cmd/dendrite-federation-sender-server/main.go7
-rw-r--r--cmd/dendrite-key-server/main.go7
-rw-r--r--cmd/dendrite-media-api-server/main.go9
-rw-r--r--cmd/dendrite-monolith-server/main.go69
-rw-r--r--cmd/dendrite-room-server/main.go7
-rw-r--r--cmd/dendrite-server-key-api-server/main.go6
-rw-r--r--cmd/dendrite-sync-api-server/main.go15
-rw-r--r--cmd/dendrite-user-api-server/main.go6
-rw-r--r--cmd/dendritejs/main.go27
-rw-r--r--cmd/generate-keys/main.go5
-rw-r--r--cmd/mediaapi-integration-tests/main.go2
-rw-r--r--cmd/roomserver-integration-tests/main.go2
-rw-r--r--cmd/syncserver-integration-tests/main.go3
20 files changed, 160 insertions, 102 deletions
diff --git a/cmd/dendrite-appservice-server/main.go b/cmd/dendrite-appservice-server/main.go
index 632b45e6..72b243e2 100644
--- a/cmd/dendrite-appservice-server/main.go
+++ b/cmd/dendrite-appservice-server/main.go
@@ -30,6 +30,9 @@ func main() {
intAPI := appservice.NewInternalAPI(base, userAPI, rsAPI)
appservice.AddInternalRoutes(base.InternalAPIMux, intAPI)
- base.SetupAndServeHTTP(string(base.Cfg.AppServiceAPI.Bind), string(base.Cfg.AppServiceAPI.Listen))
-
+ base.SetupAndServeHTTP(
+ base.Cfg.AppServiceAPI.InternalAPI.Listen,
+ setup.NoExternalListener,
+ nil, nil,
+ )
}
diff --git a/cmd/dendrite-client-api-server/main.go b/cmd/dendrite-client-api-server/main.go
index 2b6c39b6..4961b34e 100644
--- a/cmd/dendrite-client-api-server/main.go
+++ b/cmd/dendrite-client-api-server/main.go
@@ -39,10 +39,13 @@ func main() {
keyAPI := base.KeyServerHTTPClient()
clientapi.AddPublicRoutes(
- base.PublicAPIMux, &base.Cfg.ClientAPI, base.KafkaProducer, deviceDB, accountDB, federation,
+ base.PublicClientAPIMux, &base.Cfg.ClientAPI, base.KafkaProducer, deviceDB, accountDB, federation,
rsAPI, eduInputAPI, asQuery, stateAPI, transactions.New(), fsAPI, userAPI, keyAPI, nil,
)
- base.SetupAndServeHTTP(string(base.Cfg.ClientAPI.Bind), string(base.Cfg.ClientAPI.Listen))
-
+ base.SetupAndServeHTTP(
+ base.Cfg.ClientAPI.InternalAPI.Listen,
+ base.Cfg.ClientAPI.ExternalAPI.Listen,
+ nil, nil,
+ )
}
diff --git a/cmd/dendrite-current-state-server/main.go b/cmd/dendrite-current-state-server/main.go
index a8c0813f..594bfcf9 100644
--- a/cmd/dendrite-current-state-server/main.go
+++ b/cmd/dendrite-current-state-server/main.go
@@ -28,6 +28,9 @@ func main() {
currentstateserver.AddInternalRoutes(base.InternalAPIMux, stateAPI)
- base.SetupAndServeHTTP(string(base.Cfg.CurrentStateServer.Bind), string(base.Cfg.CurrentStateServer.Listen))
-
+ base.SetupAndServeHTTP(
+ base.Cfg.CurrentStateServer.InternalAPI.Listen,
+ setup.NoExternalListener,
+ nil, nil,
+ )
}
diff --git a/cmd/dendrite-demo-libp2p/main.go b/cmd/dendrite-demo-libp2p/main.go
index e3035547..18c85b3b 100644
--- a/cmd/dendrite-demo-libp2p/main.go
+++ b/cmd/dendrite-demo-libp2p/main.go
@@ -23,6 +23,7 @@ import (
"os"
"time"
+ "github.com/gorilla/mux"
gostream "github.com/libp2p/go-libp2p-gostream"
p2phttp "github.com/libp2p/go-libp2p-http"
p2pdisc "github.com/libp2p/go-libp2p/p2p/discovery"
@@ -190,21 +191,28 @@ func main() {
KeyAPI: keyAPI,
ExtPublicRoomsProvider: provider,
}
- monolith.AddAllPublicRoutes(base.Base.PublicAPIMux)
-
- httputil.SetupHTTPAPI(
- base.Base.BaseMux,
- base.Base.PublicAPIMux,
- base.Base.InternalAPIMux,
- &cfg.Global,
- base.Base.UseHTTPAPIs,
+ monolith.AddAllPublicRoutes(
+ base.Base.PublicClientAPIMux,
+ base.Base.PublicFederationAPIMux,
+ base.Base.PublicKeyAPIMux,
+ base.Base.PublicMediaAPIMux,
)
+ httpRouter := mux.NewRouter()
+ httpRouter.PathPrefix(httputil.InternalPathPrefix).Handler(base.Base.InternalAPIMux)
+ httpRouter.PathPrefix(httputil.PublicClientPathPrefix).Handler(base.Base.PublicClientAPIMux)
+ httpRouter.PathPrefix(httputil.PublicMediaPathPrefix).Handler(base.Base.PublicMediaAPIMux)
+
+ libp2pRouter := mux.NewRouter()
+ libp2pRouter.PathPrefix(httputil.PublicFederationPathPrefix).Handler(base.Base.PublicFederationAPIMux)
+ libp2pRouter.PathPrefix(httputil.PublicKeyPathPrefix).Handler(base.Base.PublicKeyAPIMux)
+ libp2pRouter.PathPrefix(httputil.PublicMediaPathPrefix).Handler(base.Base.PublicMediaAPIMux)
+
// Expose the matrix APIs directly rather than putting them under a /api path.
go func() {
httpBindAddr := fmt.Sprintf(":%d", *instancePort)
logrus.Info("Listening on ", httpBindAddr)
- logrus.Fatal(http.ListenAndServe(httpBindAddr, base.Base.BaseMux))
+ logrus.Fatal(http.ListenAndServe(httpBindAddr, httpRouter))
}()
// Expose the matrix APIs also via libp2p
if base.LibP2P != nil {
@@ -217,7 +225,7 @@ func main() {
defer func() {
logrus.Fatal(listener.Close())
}()
- logrus.Fatal(http.Serve(listener, base.Base.BaseMux))
+ logrus.Fatal(http.Serve(listener, libp2pRouter))
}()
}
diff --git a/cmd/dendrite-demo-yggdrasil/main.go b/cmd/dendrite-demo-yggdrasil/main.go
index 33ed1542..43bbe94f 100644
--- a/cmd/dendrite-demo-yggdrasil/main.go
+++ b/cmd/dendrite-demo-yggdrasil/main.go
@@ -23,6 +23,7 @@ import (
"net/http"
"time"
+ "github.com/gorilla/mux"
"github.com/matrix-org/dendrite/appservice"
"github.com/matrix-org/dendrite/cmd/dendrite-demo-yggdrasil/embed"
"github.com/matrix-org/dendrite/cmd/dendrite-demo-yggdrasil/signing"
@@ -132,7 +133,7 @@ func main() {
rsComponent.SetFederationSenderAPI(fsAPI)
- embed.Embed(base.BaseMux, *instancePort, "Yggdrasil Demo")
+ embed.Embed(base.PublicClientAPIMux, *instancePort, "Yggdrasil Demo")
monolith := setup.Monolith{
Config: base.Cfg,
@@ -155,16 +156,22 @@ func main() {
ygg, fsAPI, federation,
),
}
- monolith.AddAllPublicRoutes(base.PublicAPIMux)
-
- httputil.SetupHTTPAPI(
- base.BaseMux,
- base.PublicAPIMux,
- base.InternalAPIMux,
- &cfg.Global,
- base.UseHTTPAPIs,
+ monolith.AddAllPublicRoutes(
+ base.PublicClientAPIMux,
+ base.PublicFederationAPIMux,
+ base.PublicKeyAPIMux,
+ base.PublicMediaAPIMux,
)
+ httpRouter := mux.NewRouter()
+ httpRouter.PathPrefix(httputil.InternalPathPrefix).Handler(base.InternalAPIMux)
+ httpRouter.PathPrefix(httputil.PublicClientPathPrefix).Handler(base.PublicClientAPIMux)
+ httpRouter.PathPrefix(httputil.PublicMediaPathPrefix).Handler(base.PublicMediaAPIMux)
+
+ yggRouter := mux.NewRouter()
+ yggRouter.PathPrefix(httputil.PublicFederationPathPrefix).Handler(base.PublicFederationAPIMux)
+ yggRouter.PathPrefix(httputil.PublicMediaPathPrefix).Handler(base.PublicMediaAPIMux)
+
// Build both ends of a HTTP multiplex.
httpServer := &http.Server{
Addr: ":0",
@@ -175,7 +182,7 @@ func main() {
BaseContext: func(_ net.Listener) context.Context {
return context.Background()
},
- Handler: base.BaseMux,
+ Handler: yggRouter,
}
go func() {
@@ -185,7 +192,7 @@ func main() {
go func() {
httpBindAddr := fmt.Sprintf(":%d", *instancePort)
logrus.Info("Listening on ", httpBindAddr)
- logrus.Fatal(http.ListenAndServe(httpBindAddr, base.BaseMux))
+ logrus.Fatal(http.ListenAndServe(httpBindAddr, httpRouter))
}()
go func() {
logrus.Info("Sending wake-up message to known nodes")
diff --git a/cmd/dendrite-edu-server/main.go b/cmd/dendrite-edu-server/main.go
index d3e4e0a0..e0956619 100644
--- a/cmd/dendrite-edu-server/main.go
+++ b/cmd/dendrite-edu-server/main.go
@@ -33,6 +33,9 @@ func main() {
intAPI := eduserver.NewInternalAPI(base, cache.New(), base.UserAPIClient())
eduserver.AddInternalRoutes(base.InternalAPIMux, intAPI)
- base.SetupAndServeHTTP(string(base.Cfg.EDUServer.Bind), string(base.Cfg.EDUServer.Listen))
-
+ base.SetupAndServeHTTP(
+ base.Cfg.EDUServer.InternalAPI.Listen,
+ setup.NoExternalListener,
+ nil, nil,
+ )
}
diff --git a/cmd/dendrite-federation-api-server/main.go b/cmd/dendrite-federation-api-server/main.go
index 3b12a295..4181ee0c 100644
--- a/cmd/dendrite-federation-api-server/main.go
+++ b/cmd/dendrite-federation-api-server/main.go
@@ -33,10 +33,14 @@ func main() {
keyAPI := base.KeyServerHTTPClient()
federationapi.AddPublicRoutes(
- base.PublicAPIMux, &base.Cfg.FederationAPI, userAPI, federation, keyRing,
+ base.PublicFederationAPIMux, base.PublicKeyAPIMux,
+ &base.Cfg.FederationAPI, userAPI, federation, keyRing,
rsAPI, fsAPI, base.EDUServerClient(), base.CurrentStateAPIClient(), keyAPI,
)
- base.SetupAndServeHTTP(string(base.Cfg.FederationAPI.Bind), string(base.Cfg.FederationAPI.Listen))
-
+ base.SetupAndServeHTTP(
+ base.Cfg.FederationAPI.InternalAPI.Listen,
+ base.Cfg.FederationAPI.ExternalAPI.Listen,
+ nil, nil,
+ )
}
diff --git a/cmd/dendrite-federation-sender-server/main.go b/cmd/dendrite-federation-sender-server/main.go
index 152c798a..36906019 100644
--- a/cmd/dendrite-federation-sender-server/main.go
+++ b/cmd/dendrite-federation-sender-server/main.go
@@ -35,6 +35,9 @@ func main() {
)
federationsender.AddInternalRoutes(base.InternalAPIMux, fsAPI)
- base.SetupAndServeHTTP(string(base.Cfg.FederationSender.Bind), string(base.Cfg.FederationSender.Listen))
-
+ base.SetupAndServeHTTP(
+ base.Cfg.FederationSender.InternalAPI.Listen,
+ setup.NoExternalListener,
+ nil, nil,
+ )
}
diff --git a/cmd/dendrite-key-server/main.go b/cmd/dendrite-key-server/main.go
index f3110a1e..2110b216 100644
--- a/cmd/dendrite-key-server/main.go
+++ b/cmd/dendrite-key-server/main.go
@@ -29,6 +29,9 @@ func main() {
keyserver.AddInternalRoutes(base.InternalAPIMux, intAPI)
- base.SetupAndServeHTTP(string(base.Cfg.KeyServer.Bind), string(base.Cfg.KeyServer.Listen))
-
+ base.SetupAndServeHTTP(
+ base.Cfg.KeyServer.InternalAPI.Listen,
+ setup.NoExternalListener,
+ nil, nil,
+ )
}
diff --git a/cmd/dendrite-media-api-server/main.go b/cmd/dendrite-media-api-server/main.go
index 1bbb62bd..f442abfa 100644
--- a/cmd/dendrite-media-api-server/main.go
+++ b/cmd/dendrite-media-api-server/main.go
@@ -28,8 +28,11 @@ func main() {
userAPI := base.UserAPIClient()
client := gomatrixserverlib.NewClient(cfg.FederationSender.DisableTLSValidation)
- mediaapi.AddPublicRoutes(base.PublicAPIMux, &base.Cfg.MediaAPI, userAPI, client)
-
- base.SetupAndServeHTTP(string(base.Cfg.MediaAPI.Bind), string(base.Cfg.MediaAPI.Listen))
+ mediaapi.AddPublicRoutes(base.PublicMediaAPIMux, &base.Cfg.MediaAPI, userAPI, client)
+ base.SetupAndServeHTTP(
+ base.Cfg.MediaAPI.InternalAPI.Listen,
+ base.Cfg.MediaAPI.ExternalAPI.Listen,
+ nil, nil,
+ )
}
diff --git a/cmd/dendrite-monolith-server/main.go b/cmd/dendrite-monolith-server/main.go
index 8f98cdd0..bf752708 100644
--- a/cmd/dendrite-monolith-server/main.go
+++ b/cmd/dendrite-monolith-server/main.go
@@ -16,7 +16,6 @@ package main
import (
"flag"
- "net/http"
"os"
"github.com/matrix-org/dendrite/appservice"
@@ -25,7 +24,6 @@ import (
"github.com/matrix-org/dendrite/eduserver/cache"
"github.com/matrix-org/dendrite/federationsender"
"github.com/matrix-org/dendrite/internal/config"
- "github.com/matrix-org/dendrite/internal/httputil"
"github.com/matrix-org/dendrite/internal/setup"
"github.com/matrix-org/dendrite/keyserver"
"github.com/matrix-org/dendrite/roomserver"
@@ -33,8 +31,6 @@ import (
"github.com/matrix-org/dendrite/serverkeyapi"
"github.com/matrix-org/dendrite/userapi"
"github.com/matrix-org/gomatrixserverlib"
-
- "github.com/sirupsen/logrus"
)
var (
@@ -48,23 +44,25 @@ var (
func main() {
cfg := setup.ParseFlags(true)
+ httpAddr := config.HTTPAddress("http://" + *httpBindAddr)
+ httpsAddr := config.HTTPAddress("https://" + *httpsBindAddr)
+
if *enableHTTPAPIs {
// If the HTTP APIs are enabled then we need to update the Listen
// statements in the configuration so that we know where to find
// the API endpoints. They'll listen on the same port as the monolith
// itself.
- addr := config.Address(*httpBindAddr)
- cfg.AppServiceAPI.Listen = addr
- cfg.ClientAPI.Listen = addr
- cfg.CurrentStateServer.Listen = addr
- cfg.EDUServer.Listen = addr
- cfg.FederationAPI.Listen = addr
- cfg.FederationSender.Listen = addr
- cfg.KeyServer.Listen = addr
- cfg.MediaAPI.Listen = addr
- cfg.RoomServer.Listen = addr
- cfg.ServerKeyAPI.Listen = addr
- cfg.SyncAPI.Listen = addr
+ cfg.AppServiceAPI.InternalAPI.Connect = httpAddr
+ cfg.ClientAPI.InternalAPI.Connect = httpAddr
+ cfg.CurrentStateServer.InternalAPI.Connect = httpAddr
+ cfg.EDUServer.InternalAPI.Connect = httpAddr
+ cfg.FederationAPI.InternalAPI.Connect = httpAddr
+ cfg.FederationSender.InternalAPI.Connect = httpAddr
+ cfg.KeyServer.InternalAPI.Connect = httpAddr
+ cfg.MediaAPI.InternalAPI.Connect = httpAddr
+ cfg.RoomServer.InternalAPI.Connect = httpAddr
+ cfg.ServerKeyAPI.InternalAPI.Connect = httpAddr
+ cfg.SyncAPI.InternalAPI.Connect = httpAddr
}
base := setup.NewBaseDendrite(cfg, "Monolith", *enableHTTPAPIs)
@@ -147,38 +145,29 @@ func main() {
UserAPI: userAPI,
KeyAPI: keyAPI,
}
- monolith.AddAllPublicRoutes(base.PublicAPIMux)
-
- httputil.SetupHTTPAPI(
- base.BaseMux,
- base.PublicAPIMux,
- base.InternalAPIMux,
- &cfg.Global,
- base.UseHTTPAPIs,
+ monolith.AddAllPublicRoutes(
+ base.PublicClientAPIMux,
+ base.PublicFederationAPIMux,
+ base.PublicKeyAPIMux,
+ base.PublicMediaAPIMux,
)
// Expose the matrix APIs directly rather than putting them under a /api path.
go func() {
- serv := http.Server{
- Addr: *httpBindAddr,
- WriteTimeout: setup.HTTPServerTimeout,
- Handler: base.BaseMux,
- }
-
- logrus.Info("Listening on ", serv.Addr)
- logrus.Fatal(serv.ListenAndServe())
+ base.SetupAndServeHTTP(
+ config.HTTPAddress(httpAddr), // internal API
+ config.HTTPAddress(httpAddr), // external API
+ nil, nil, // TLS settings
+ )
}()
// Handle HTTPS if certificate and key are provided
if *certFile != "" && *keyFile != "" {
go func() {
- serv := http.Server{
- Addr: *httpsBindAddr,
- WriteTimeout: setup.HTTPServerTimeout,
- Handler: base.BaseMux,
- }
-
- logrus.Info("Listening on ", serv.Addr)
- logrus.Fatal(serv.ListenAndServeTLS(*certFile, *keyFile))
+ base.SetupAndServeHTTP(
+ config.HTTPAddress(httpsAddr), // internal API
+ config.HTTPAddress(httpsAddr), // external API
+ certFile, keyFile, // TLS settings
+ )
}()
}
diff --git a/cmd/dendrite-room-server/main.go b/cmd/dendrite-room-server/main.go
index e1d4b16b..0d587e6e 100644
--- a/cmd/dendrite-room-server/main.go
+++ b/cmd/dendrite-room-server/main.go
@@ -33,6 +33,9 @@ func main() {
rsAPI.SetFederationSenderAPI(fsAPI)
roomserver.AddInternalRoutes(base.InternalAPIMux, rsAPI)
- base.SetupAndServeHTTP(string(base.Cfg.RoomServer.Bind), string(base.Cfg.RoomServer.Listen))
-
+ base.SetupAndServeHTTP(
+ base.Cfg.RoomServer.InternalAPI.Listen,
+ setup.NoExternalListener,
+ nil, nil,
+ )
}
diff --git a/cmd/dendrite-server-key-api-server/main.go b/cmd/dendrite-server-key-api-server/main.go
index 36f34890..1ad4ede2 100644
--- a/cmd/dendrite-server-key-api-server/main.go
+++ b/cmd/dendrite-server-key-api-server/main.go
@@ -29,5 +29,9 @@ func main() {
intAPI := serverkeyapi.NewInternalAPI(&base.Cfg.ServerKeyAPI, federation, base.Caches)
serverkeyapi.AddInternalRoutes(base.InternalAPIMux, intAPI, base.Caches)
- base.SetupAndServeHTTP(string(base.Cfg.ServerKeyAPI.Bind), string(base.Cfg.ServerKeyAPI.Listen))
+ base.SetupAndServeHTTP(
+ base.Cfg.ServerKeyAPI.InternalAPI.Listen,
+ setup.NoExternalListener,
+ nil, nil,
+ )
}
diff --git a/cmd/dendrite-sync-api-server/main.go b/cmd/dendrite-sync-api-server/main.go
index c25f8ec1..ec53af6e 100644
--- a/cmd/dendrite-sync-api-server/main.go
+++ b/cmd/dendrite-sync-api-server/main.go
@@ -30,9 +30,14 @@ func main() {
rsAPI := base.RoomserverHTTPClient()
syncapi.AddPublicRoutes(
- base.PublicAPIMux, base.KafkaConsumer, userAPI, rsAPI, base.KeyServerHTTPClient(), base.CurrentStateAPIClient(),
- federation, &cfg.SyncAPI)
-
- base.SetupAndServeHTTP(string(base.Cfg.SyncAPI.Bind), string(base.Cfg.SyncAPI.Listen))
-
+ base.PublicClientAPIMux, base.KafkaConsumer, userAPI, rsAPI,
+ base.KeyServerHTTPClient(), base.CurrentStateAPIClient(),
+ federation, &cfg.SyncAPI,
+ )
+
+ base.SetupAndServeHTTP(
+ base.Cfg.SyncAPI.InternalAPI.Listen,
+ setup.NoExternalListener,
+ nil, nil,
+ )
}
diff --git a/cmd/dendrite-user-api-server/main.go b/cmd/dendrite-user-api-server/main.go
index 22b6255e..c21525e6 100644
--- a/cmd/dendrite-user-api-server/main.go
+++ b/cmd/dendrite-user-api-server/main.go
@@ -31,5 +31,9 @@ func main() {
userapi.AddInternalRoutes(base.InternalAPIMux, userAPI)
- base.SetupAndServeHTTP(string(base.Cfg.UserAPI.Bind), string(base.Cfg.UserAPI.Listen))
+ base.SetupAndServeHTTP(
+ base.Cfg.UserAPI.InternalAPI.Listen,
+ setup.NoExternalListener,
+ nil, nil,
+ )
}
diff --git a/cmd/dendritejs/main.go b/cmd/dendritejs/main.go
index f350a938..ada48cd8 100644
--- a/cmd/dendritejs/main.go
+++ b/cmd/dendritejs/main.go
@@ -21,6 +21,7 @@ import (
"fmt"
"syscall/js"
+ "github.com/gorilla/mux"
"github.com/matrix-org/dendrite/appservice"
"github.com/matrix-org/dendrite/currentstateserver"
"github.com/matrix-org/dendrite/eduserver"
@@ -234,22 +235,28 @@ func main() {
//ServerKeyAPI: serverKeyAPI,
ExtPublicRoomsProvider: p2pPublicRoomProvider,
}
- monolith.AddAllPublicRoutes(base.PublicAPIMux)
-
- httputil.SetupHTTPAPI(
- base.BaseMux,
- base.PublicAPIMux,
- base.InternalAPIMux,
- &cfg.Global,
- base.UseHTTPAPIs,
+ monolith.AddAllPublicRoutes(
+ base.PublicClientAPIMux,
+ base.PublicFederationAPIMux,
+ base.PublicKeyAPIMux,
+ base.PublicMediaAPIMux,
)
+ httpRouter := mux.NewRouter()
+ httpRouter.PathPrefix(httputil.InternalPathPrefix).Handler(base.InternalAPIMux)
+ httpRouter.PathPrefix(httputil.PublicClientPathPrefix).Handler(base.PublicClientAPIMux)
+ httpRouter.PathPrefix(httputil.PublicMediaPathPrefix).Handler(base.PublicMediaAPIMux)
+
+ libp2pRouter := mux.NewRouter()
+ libp2pRouter.PathPrefix(httputil.PublicFederationPathPrefix).Handler(base.PublicFederationAPIMux)
+ libp2pRouter.PathPrefix(httputil.PublicMediaPathPrefix).Handler(base.PublicMediaAPIMux)
+
// Expose the matrix APIs via libp2p-js - for federation traffic
if node != nil {
go func() {
logrus.Info("Listening on libp2p-js host ID ", node.Id)
s := JSServer{
- Mux: base.BaseMux,
+ Mux: libp2pRouter,
}
s.ListenAndServe("p2p")
}()
@@ -259,7 +266,7 @@ func main() {
go func() {
logrus.Info("Listening for service-worker fetch traffic")
s := JSServer{
- Mux: base.BaseMux,
+ Mux: httpRouter,
}
s.ListenAndServe("fetch")
}()
diff --git a/cmd/generate-keys/main.go b/cmd/generate-keys/main.go
index ceeca567..743109f1 100644
--- a/cmd/generate-keys/main.go
+++ b/cmd/generate-keys/main.go
@@ -45,6 +45,11 @@ func main() {
flag.Parse()
+ if *tlsCertFile == "" && *tlsKeyFile == "" && *privateKeyFile == "" {
+ flag.Usage()
+ return
+ }
+
if *tlsCertFile != "" || *tlsKeyFile != "" {
if *tlsCertFile == "" || *tlsKeyFile == "" {
log.Fatal("Zero or both of --tls-key and --tls-cert must be supplied")
diff --git a/cmd/mediaapi-integration-tests/main.go b/cmd/mediaapi-integration-tests/main.go
index 4c584979..8a5a0d54 100644
--- a/cmd/mediaapi-integration-tests/main.go
+++ b/cmd/mediaapi-integration-tests/main.go
@@ -120,7 +120,7 @@ func startMediaAPI(suffix string, dynamicThumbnails bool) (*exec.Cmd, chan error
serverArgs,
)
- fmt.Printf("==TESTSERVER== STARTED %v -> %v : %v\n", proxyAddr, cfg.MediaAPI.Listen, dir)
+ fmt.Printf("==TESTSERVER== STARTED %v -> %v : %v\n", proxyAddr, cfg.MediaAPI.InternalAPI.Listen, dir)
return cmd, cmdChan, proxyCmd, proxyAddr, dir
}
diff --git a/cmd/roomserver-integration-tests/main.go b/cmd/roomserver-integration-tests/main.go
index a9c88ae1..43574778 100644
--- a/cmd/roomserver-integration-tests/main.go
+++ b/cmd/roomserver-integration-tests/main.go
@@ -278,7 +278,7 @@ func testRoomserver(input []string, wantOutput []string, checkQueries func(api.R
cmd.Args = []string{"dendrite-room-server", "--config", filepath.Join(dir, test.ConfigFile)}
gotOutput, err := runAndReadFromTopic(cmd, cfg.RoomServerURL()+"/metrics", doInput, outputTopic, len(wantOutput), func() {
- queryAPI, _ := inthttp.NewRoomserverClient("http://"+string(cfg.RoomServer.Listen), &http.Client{Timeout: timeoutHTTP}, cache)
+ queryAPI, _ := inthttp.NewRoomserverClient("http://"+string(cfg.RoomServer.InternalAPI.Connect), &http.Client{Timeout: timeoutHTTP}, cache)
checkQueries(queryAPI)
})
if err != nil {
diff --git a/cmd/syncserver-integration-tests/main.go b/cmd/syncserver-integration-tests/main.go
index bba8fd96..a11dd2a0 100644
--- a/cmd/syncserver-integration-tests/main.go
+++ b/cmd/syncserver-integration-tests/main.go
@@ -133,7 +133,8 @@ func startSyncServer() (*exec.Cmd, chan error) {
}
// TODO use the address assigned by the config generator rather than clobbering.
cfg.Global.ServerName = "localhost"
- cfg.SyncAPI.Listen = config.Address(syncserverAddr)
+ cfg.SyncAPI.InternalAPI.Listen = config.HTTPAddress("http://" + syncserverAddr)
+ cfg.SyncAPI.InternalAPI.Connect = cfg.SyncAPI.InternalAPI.Listen
if err := test.WriteConfig(cfg, dir); err != nil {
panic(err)