From d6a6b27c5ca59013c076d58af2d2a6d4d5be4771 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Wed, 29 Jul 2020 13:21:43 +0100 Subject: [PATCH] Further tweaks --- currentstateserver/currentstateserver_test.go | 12 ++++++------ internal/config/config_federationsender.go | 13 +++++++++---- internal/config/config_test.go | 2 +- internal/setup/base.go | 16 +++++++--------- 4 files changed, 23 insertions(+), 20 deletions(-) diff --git a/currentstateserver/currentstateserver_test.go b/currentstateserver/currentstateserver_test.go index 1cdeb56d1..41e70fd14 100644 --- a/currentstateserver/currentstateserver_test.go +++ b/currentstateserver/currentstateserver_test.go @@ -92,11 +92,11 @@ func MustWriteOutputEvent(t *testing.T, producer sarama.SyncProducer, out *rooms } func MustMakeInternalAPI(t *testing.T) (api.CurrentStateInternalAPI, sarama.SyncProducer) { - cfg := &config.CurrentStateServer{ - Matrix: &config.Global{}, - } - cfg.Matrix.Kafka.Topics.OutputRoomEvent = config.Topic(kafkaTopic) - cfg.Database = config.DataSource("file::memory:") + cfg := &config.Dendrite{} + cfg.Defaults() + cfg.Global.ServerName = "kaer.morhen" + cfg.Global.Kafka.Topics.OutputRoomEvent = config.Topic(kafkaTopic) + cfg.CurrentStateServer.Database = config.DataSource("file::memory:") db, err := sqlutil.Open(sqlutil.SQLiteDriverName(), "file::memory:", nil) if err != nil { t.Fatalf("Failed to open naffka database: %s", err) @@ -109,7 +109,7 @@ func MustMakeInternalAPI(t *testing.T) (api.CurrentStateInternalAPI, sarama.Sync if err != nil { t.Fatalf("Failed to create naffka consumer: %s", err) } - return NewInternalAPI(cfg, naff), naff + return NewInternalAPI(&cfg.CurrentStateServer, naff), naff } func TestQueryCurrentState(t *testing.T) { diff --git a/internal/config/config_federationsender.go b/internal/config/config_federationsender.go index 693fcdf10..dff76d63c 100644 --- a/internal/config/config_federationsender.go +++ b/internal/config/config_federationsender.go @@ -17,7 +17,7 @@ type FederationSender struct { // The default value is 16 if not specified, which is circa 18 hours. FederationMaxRetries uint32 `yaml:"federation_max_retries"` - Proxy Proxy `yaml:"proxy"` + Proxy Proxy `yaml:"proxy_outbound"` } func (c *FederationSender) Defaults() { @@ -27,6 +27,8 @@ func (c *FederationSender) Defaults() { c.DatabaseOptions.Defaults() c.FederationMaxRetries = 16 + + c.Proxy.Defaults() } func (c *FederationSender) Verify(configErrs *configErrors) { @@ -37,6 +39,8 @@ func (c *FederationSender) Verify(configErrs *configErrors) { // The config for setting a proxy to use for server->server requests type Proxy struct { + // Is the proxy enabled? + Enabled bool `yaml:"enabled"` // The protocol for the proxy (http / https / socks5) Protocol string `yaml:"protocol"` // The host where the proxy is listening @@ -46,9 +50,10 @@ type Proxy struct { } func (c *Proxy) Defaults() { - c.Protocol = "" - c.Host = "" - c.Port = 0 + c.Enabled = false + c.Protocol = "http" + c.Host = "localhost" + c.Port = 8080 } func (c *Proxy) Verify(configErrs *configErrors) { diff --git a/internal/config/config_test.go b/internal/config/config_test.go index 1a611be12..84af7dd7f 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -36,7 +36,7 @@ const testConfig = ` version: 1 global: server_name: localhost - private_key: matrix.pem + private_key: matrix_key.pem key_validity_period: 168h0m0s trusted_third_party_id_servers: [] kafka: diff --git a/internal/setup/base.go b/internal/setup/base.go index 0999803b7..a47330b54 100644 --- a/internal/setup/base.go +++ b/internal/setup/base.go @@ -16,6 +16,7 @@ package setup import ( "database/sql" + "fmt" "io" "net/http" "net/url" @@ -107,15 +108,12 @@ func NewBaseDendrite(cfg *config.Dendrite, componentName string, useHTTPAPIs boo } client := http.Client{Timeout: HTTPClientTimeout} - // TODO: fix this - /* - if cfg.Proxy != nil { - client.Transport = &http.Transport{Proxy: http.ProxyURL(&url.URL{ - Scheme: cfg.Proxy.Protocol, - Host: fmt.Sprintf("%s:%d", cfg.Proxy.Host, cfg.Proxy.Port), - })} - } - */ + if cfg.FederationSender.Proxy.Enabled { + client.Transport = &http.Transport{Proxy: http.ProxyURL(&url.URL{ + Scheme: cfg.FederationSender.Proxy.Protocol, + Host: fmt.Sprintf("%s:%d", cfg.FederationSender.Proxy.Host, cfg.FederationSender.Proxy.Port), + })} + } // Ideally we would only use SkipClean on routes which we know can allow '/' but due to // https://github.com/gorilla/mux/issues/460 we have to attach this at the top router.