Further tweaks

This commit is contained in:
Neil Alexander 2020-07-29 13:21:43 +01:00
parent 65cae7a8f4
commit d6a6b27c5c
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944
4 changed files with 23 additions and 20 deletions

View file

@ -92,11 +92,11 @@ func MustWriteOutputEvent(t *testing.T, producer sarama.SyncProducer, out *rooms
} }
func MustMakeInternalAPI(t *testing.T) (api.CurrentStateInternalAPI, sarama.SyncProducer) { func MustMakeInternalAPI(t *testing.T) (api.CurrentStateInternalAPI, sarama.SyncProducer) {
cfg := &config.CurrentStateServer{ cfg := &config.Dendrite{}
Matrix: &config.Global{}, cfg.Defaults()
} cfg.Global.ServerName = "kaer.morhen"
cfg.Matrix.Kafka.Topics.OutputRoomEvent = config.Topic(kafkaTopic) cfg.Global.Kafka.Topics.OutputRoomEvent = config.Topic(kafkaTopic)
cfg.Database = config.DataSource("file::memory:") cfg.CurrentStateServer.Database = config.DataSource("file::memory:")
db, err := sqlutil.Open(sqlutil.SQLiteDriverName(), "file::memory:", nil) db, err := sqlutil.Open(sqlutil.SQLiteDriverName(), "file::memory:", nil)
if err != nil { if err != nil {
t.Fatalf("Failed to open naffka database: %s", err) 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 { if err != nil {
t.Fatalf("Failed to create naffka consumer: %s", err) 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) { func TestQueryCurrentState(t *testing.T) {

View file

@ -17,7 +17,7 @@ type FederationSender struct {
// The default value is 16 if not specified, which is circa 18 hours. // The default value is 16 if not specified, which is circa 18 hours.
FederationMaxRetries uint32 `yaml:"federation_max_retries"` FederationMaxRetries uint32 `yaml:"federation_max_retries"`
Proxy Proxy `yaml:"proxy"` Proxy Proxy `yaml:"proxy_outbound"`
} }
func (c *FederationSender) Defaults() { func (c *FederationSender) Defaults() {
@ -27,6 +27,8 @@ func (c *FederationSender) Defaults() {
c.DatabaseOptions.Defaults() c.DatabaseOptions.Defaults()
c.FederationMaxRetries = 16 c.FederationMaxRetries = 16
c.Proxy.Defaults()
} }
func (c *FederationSender) Verify(configErrs *configErrors) { 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 // The config for setting a proxy to use for server->server requests
type Proxy struct { type Proxy struct {
// Is the proxy enabled?
Enabled bool `yaml:"enabled"`
// The protocol for the proxy (http / https / socks5) // The protocol for the proxy (http / https / socks5)
Protocol string `yaml:"protocol"` Protocol string `yaml:"protocol"`
// The host where the proxy is listening // The host where the proxy is listening
@ -46,9 +50,10 @@ type Proxy struct {
} }
func (c *Proxy) Defaults() { func (c *Proxy) Defaults() {
c.Protocol = "" c.Enabled = false
c.Host = "" c.Protocol = "http"
c.Port = 0 c.Host = "localhost"
c.Port = 8080
} }
func (c *Proxy) Verify(configErrs *configErrors) { func (c *Proxy) Verify(configErrs *configErrors) {

View file

@ -36,7 +36,7 @@ const testConfig = `
version: 1 version: 1
global: global:
server_name: localhost server_name: localhost
private_key: matrix.pem private_key: matrix_key.pem
key_validity_period: 168h0m0s key_validity_period: 168h0m0s
trusted_third_party_id_servers: [] trusted_third_party_id_servers: []
kafka: kafka:

View file

@ -16,6 +16,7 @@ package setup
import ( import (
"database/sql" "database/sql"
"fmt"
"io" "io"
"net/http" "net/http"
"net/url" "net/url"
@ -107,15 +108,12 @@ func NewBaseDendrite(cfg *config.Dendrite, componentName string, useHTTPAPIs boo
} }
client := http.Client{Timeout: HTTPClientTimeout} client := http.Client{Timeout: HTTPClientTimeout}
// TODO: fix this if cfg.FederationSender.Proxy.Enabled {
/*
if cfg.Proxy != nil {
client.Transport = &http.Transport{Proxy: http.ProxyURL(&url.URL{ client.Transport = &http.Transport{Proxy: http.ProxyURL(&url.URL{
Scheme: cfg.Proxy.Protocol, Scheme: cfg.FederationSender.Proxy.Protocol,
Host: fmt.Sprintf("%s:%d", cfg.Proxy.Host, cfg.Proxy.Port), 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 // 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. // https://github.com/gorilla/mux/issues/460 we have to attach this at the top router.