From 619ece0c5cd920fa53843bec7211716578377b6a Mon Sep 17 00:00:00 2001 From: Adit Sachde <23707194+aditsachde@users.noreply.github.com> Date: Sun, 22 Sep 2019 15:00:23 -0400 Subject: [PATCH] Allow fallback if bind not specified Allows fallback to listen block if bind block not specified --- cmd/dendrite-appservice-server/main.go | 6 +++- cmd/dendrite-client-api-server/main.go | 6 +++- cmd/dendrite-federation-api-server/main.go | 6 +++- cmd/dendrite-federation-sender-server/main.go | 6 +++- cmd/dendrite-media-api-server/main.go | 6 +++- cmd/dendrite-public-rooms-api-server/main.go | 6 +++- cmd/dendrite-room-server/main.go | 6 +++- cmd/dendrite-sync-api-server/main.go | 6 +++- cmd/dendrite-typing-server/main.go | 6 +++- common/config/config.go | 29 ++++++++++--------- 10 files changed, 60 insertions(+), 23 deletions(-) diff --git a/cmd/dendrite-appservice-server/main.go b/cmd/dendrite-appservice-server/main.go index c3e34a190..648d0b97e 100644 --- a/cmd/dendrite-appservice-server/main.go +++ b/cmd/dendrite-appservice-server/main.go @@ -35,5 +35,9 @@ func main() { base, accountDB, deviceDB, federation, alias, query, cache, ) - base.SetupAndServeHTTP(string(base.Cfg.Bind.FederationSender)) + if base.Cfg.Bind.AppServiceAPI != "" { + base.SetupAndServeHTTP(string(base.Cfg.Bind.AppServiceAPI)) + } else { + base.SetupAndServeHTTP(string(base.Cfg.Listen.AppServiceAPI)) + } } diff --git a/cmd/dendrite-client-api-server/main.go b/cmd/dendrite-client-api-server/main.go index ebbd6572f..239549e90 100644 --- a/cmd/dendrite-client-api-server/main.go +++ b/cmd/dendrite-client-api-server/main.go @@ -44,5 +44,9 @@ func main() { alias, input, query, typingInputAPI, asQuery, transactions.New(), ) - base.SetupAndServeHTTP(string(base.Cfg.Bind.ClientAPI)) + if base.Cfg.Bind.ClientAPI != "" { + base.SetupAndServeHTTP(string(base.Cfg.Bind.ClientAPI)) + } else { + base.SetupAndServeHTTP(string(base.Cfg.Listen.ClientAPI)) + } } diff --git a/cmd/dendrite-federation-api-server/main.go b/cmd/dendrite-federation-api-server/main.go index e83907cab..d38f7134a 100644 --- a/cmd/dendrite-federation-api-server/main.go +++ b/cmd/dendrite-federation-api-server/main.go @@ -39,5 +39,9 @@ func main() { alias, input, query, asQuery, ) - base.SetupAndServeHTTP(string(base.Cfg.Bind.FederationAPI)) + if base.Cfg.Bind.FederationAPI != "" { + base.SetupAndServeHTTP(string(base.Cfg.Bind.FederationAPI)) + } else { + base.SetupAndServeHTTP(string(base.Cfg.Listen.FederationAPI)) + } } diff --git a/cmd/dendrite-federation-sender-server/main.go b/cmd/dendrite-federation-sender-server/main.go index b3d59912d..cf1d73112 100644 --- a/cmd/dendrite-federation-sender-server/main.go +++ b/cmd/dendrite-federation-sender-server/main.go @@ -32,5 +32,9 @@ func main() { base, federation, query, ) - base.SetupAndServeHTTP(string(base.Cfg.Bind.FederationSender)) + if base.Cfg.Bind.FederationSender != "" { + base.SetupAndServeHTTP(string(base.Cfg.Bind.FederationSender)) + } else { + base.SetupAndServeHTTP(string(base.Cfg.Listen.FederationSender)) + } } diff --git a/cmd/dendrite-media-api-server/main.go b/cmd/dendrite-media-api-server/main.go index 0c49d0814..6d8ada452 100644 --- a/cmd/dendrite-media-api-server/main.go +++ b/cmd/dendrite-media-api-server/main.go @@ -28,5 +28,9 @@ func main() { mediaapi.SetupMediaAPIComponent(base, deviceDB) - base.SetupAndServeHTTP(string(base.Cfg.Bind.MediaAPI)) + if base.Cfg.Bind.MediaAPI != "" { + base.SetupAndServeHTTP(string(base.Cfg.Bind.MediaAPI)) + } else { + base.SetupAndServeHTTP(string(base.Cfg.Listen.MediaAPI)) + } } diff --git a/cmd/dendrite-public-rooms-api-server/main.go b/cmd/dendrite-public-rooms-api-server/main.go index e6cd0e638..daa88e678 100644 --- a/cmd/dendrite-public-rooms-api-server/main.go +++ b/cmd/dendrite-public-rooms-api-server/main.go @@ -28,5 +28,9 @@ func main() { publicroomsapi.SetupPublicRoomsAPIComponent(base, deviceDB) - base.SetupAndServeHTTP(string(base.Cfg.Bind.PublicRoomsAPI)) + if base.Cfg.Bind.PublicRoomsAPI != "" { + base.SetupAndServeHTTP(string(base.Cfg.Bind.PublicRoomsAPI)) + } else { + base.SetupAndServeHTTP(string(base.Cfg.Listen.PublicRoomsAPI)) + } } diff --git a/cmd/dendrite-room-server/main.go b/cmd/dendrite-room-server/main.go index 8846510ed..c14391685 100644 --- a/cmd/dendrite-room-server/main.go +++ b/cmd/dendrite-room-server/main.go @@ -28,5 +28,9 @@ func main() { roomserver.SetupRoomServerComponent(base) - base.SetupAndServeHTTP(string(base.Cfg.Bind.RoomServer)) + if base.Cfg.Bind.RoomServer != "" { + base.SetupAndServeHTTP(string(base.Cfg.Bind.RoomServer)) + } else { + base.SetupAndServeHTTP(string(base.Cfg.Listen.RoomServer)) + } } diff --git a/cmd/dendrite-sync-api-server/main.go b/cmd/dendrite-sync-api-server/main.go index f7f8107a3..54f04471b 100644 --- a/cmd/dendrite-sync-api-server/main.go +++ b/cmd/dendrite-sync-api-server/main.go @@ -31,5 +31,9 @@ func main() { syncapi.SetupSyncAPIComponent(base, deviceDB, accountDB, query) - base.SetupAndServeHTTP(string(base.Cfg.Bind.SyncAPI)) + if base.Cfg.Bind.SyncAPI != "" { + base.SetupAndServeHTTP(string(base.Cfg.Bind.SyncAPI)) + } else { + base.SetupAndServeHTTP(string(base.Cfg.Listen.SyncAPI)) + } } diff --git a/cmd/dendrite-typing-server/main.go b/cmd/dendrite-typing-server/main.go index a2fdb3096..53a8fdf0d 100644 --- a/cmd/dendrite-typing-server/main.go +++ b/cmd/dendrite-typing-server/main.go @@ -32,5 +32,9 @@ func main() { typingserver.SetupTypingServerComponent(base, cache.NewTypingCache()) - base.SetupAndServeHTTP(string(base.Cfg.Bind.TypingServer)) + if base.Cfg.Bind.TypingServer != "" { + base.SetupAndServeHTTP(string(base.Cfg.Bind.TypingServer)) + } else { + base.SetupAndServeHTTP(string(base.Cfg.Listen.TypingServer)) + } } diff --git a/common/config/config.go b/common/config/config.go index 18b976830..17b3b5455 100644 --- a/common/config/config.go +++ b/common/config/config.go @@ -194,6 +194,21 @@ type Dendrite struct { Password string `yaml:"turn_password"` } `yaml:"turn"` + // The internal addresses the components will listen on. + // These should not be exposed externally as they expose metrics and debugging APIs. + // Falls back to addresses listed in Listen if not specified + Bind struct { + MediaAPI Address `yaml:"media_api"` + ClientAPI Address `yaml:"client_api"` + FederationAPI Address `yaml:"federation_api"` + AppServiceAPI Address `yaml:"appservice_api"` + SyncAPI Address `yaml:"sync_api"` + RoomServer Address `yaml:"room_server"` + FederationSender Address `yaml:"federation_sender"` + PublicRoomsAPI Address `yaml:"public_rooms_api"` + TypingServer Address `yaml:"typing_server"` + } `yaml:"bind"` + // The addresses for talking to other microservices. Listen struct { MediaAPI Address `yaml:"media_api"` @@ -207,20 +222,6 @@ type Dendrite struct { TypingServer Address `yaml:"typing_server"` } `yaml:"listen"` - // The internal addresses the components will listen on. - // These should not be exposed externally as they expose metrics and debugging APIs. - Bind struct { - MediaAPI Address `yaml:"media_api"` - ClientAPI Address `yaml:"client_api"` - FederationAPI Address `yaml:"federation_api"` - AppServiceAPI Address `yaml:"appservice_api"` - SyncAPI Address `yaml:"sync_api"` - RoomServer Address `yaml:"room_server"` - FederationSender Address `yaml:"federation_sender"` - PublicRoomsAPI Address `yaml:"public_rooms_api"` - TypingServer Address `yaml:"typing_server"` - } `yaml:"bind"` - // The config for tracing the dendrite servers. Tracing struct { // The config for the jaeger opentracing reporter.