2017-06-16 16:52:03 +01:00
|
|
|
// Copyright 2017 Vector Creations Ltd
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"encoding/pem"
|
|
|
|
"fmt"
|
2017-09-28 17:00:23 +01:00
|
|
|
"io"
|
2022-08-05 10:26:59 +01:00
|
|
|
"os"
|
2017-06-16 16:52:03 +01:00
|
|
|
"path/filepath"
|
2018-02-08 11:02:48 +00:00
|
|
|
"regexp"
|
2017-06-16 16:52:03 +01:00
|
|
|
"strings"
|
2017-07-18 13:40:03 +01:00
|
|
|
|
2017-11-29 09:43:03 +00:00
|
|
|
"github.com/matrix-org/dendrite/clientapi/auth/authtypes"
|
2017-07-18 13:40:03 +01:00
|
|
|
"github.com/matrix-org/gomatrixserverlib"
|
2023-04-19 15:50:33 +01:00
|
|
|
"github.com/matrix-org/gomatrixserverlib/spec"
|
2017-11-16 10:12:02 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
2017-07-18 13:40:03 +01:00
|
|
|
"golang.org/x/crypto/ed25519"
|
2022-12-23 13:11:11 +00:00
|
|
|
"gopkg.in/yaml.v2"
|
2017-09-28 17:00:23 +01:00
|
|
|
|
|
|
|
jaegerconfig "github.com/uber/jaeger-client-go/config"
|
|
|
|
jaegermetrics "github.com/uber/jaeger-lib/metrics"
|
2017-06-16 16:52:03 +01:00
|
|
|
)
|
|
|
|
|
2020-09-23 11:07:57 +01:00
|
|
|
// keyIDRegexp defines allowable characters in Key IDs.
|
|
|
|
var keyIDRegexp = regexp.MustCompile("^ed25519:[a-zA-Z0-9_]+$")
|
|
|
|
|
2017-06-16 16:52:03 +01:00
|
|
|
// Version is the current version of the config format.
|
|
|
|
// This will change whenever we make breaking changes to the config format.
|
2022-01-05 17:44:49 +00:00
|
|
|
const Version = 2
|
2017-06-16 16:52:03 +01:00
|
|
|
|
|
|
|
// Dendrite contains all the config used by a dendrite process.
|
|
|
|
// Relative paths are resolved relative to the current working directory
|
|
|
|
type Dendrite struct {
|
|
|
|
// The version of the configuration file.
|
|
|
|
// If the version in a file doesn't match the current dendrite config
|
|
|
|
// version then we can give a clear error message telling the user
|
|
|
|
// to update their config file to the current version.
|
|
|
|
// The version of the file should only be different if there has
|
|
|
|
// been a breaking change to the config file format.
|
2017-07-05 13:10:28 +01:00
|
|
|
Version int `yaml:"version"`
|
2017-06-16 16:52:03 +01:00
|
|
|
|
2021-11-24 10:45:23 +00:00
|
|
|
Global Global `yaml:"global"`
|
|
|
|
AppServiceAPI AppServiceAPI `yaml:"app_service_api"`
|
|
|
|
ClientAPI ClientAPI `yaml:"client_api"`
|
|
|
|
FederationAPI FederationAPI `yaml:"federation_api"`
|
|
|
|
KeyServer KeyServer `yaml:"key_server"`
|
|
|
|
MediaAPI MediaAPI `yaml:"media_api"`
|
|
|
|
RoomServer RoomServer `yaml:"room_server"`
|
|
|
|
SyncAPI SyncAPI `yaml:"sync_api"`
|
|
|
|
UserAPI UserAPI `yaml:"user_api"`
|
2023-01-23 17:55:12 +00:00
|
|
|
RelayAPI RelayAPI `yaml:"relay_api"`
|
2017-09-28 17:00:23 +01:00
|
|
|
|
2020-11-19 11:34:59 +00:00
|
|
|
MSCs MSCs `yaml:"mscs"`
|
|
|
|
|
2017-09-28 17:00:23 +01:00
|
|
|
// The config for tracing the dendrite servers.
|
|
|
|
Tracing struct {
|
Add peer-to-peer support into Dendrite via libp2p and fetch (#880)
* Use a fork of pq which supports userCurrent on wasm
* Use sqlite3_js driver when running in JS
* Add cmd/dendritejs to pull in sqlite3_js driver for wasm only
* Update to latest go-sqlite-js version
* Replace prometheus with a stub. sigh
* Hard-code a config and don't use opentracing
* Latest go-sqlite3-js version
* Generate a key for now
* Listen for fetch traffic rather than HTTP
* Latest hacks for js
* libp2p support
* More libp2p
* Fork gjson to allow us to enforce auth checks as before
Previously, all events would come down redacted because the hash
checks would fail. They would fail because sjson.DeleteBytes didn't
remove keys not used for hashing. This didn't work because of a build
tag which included a file which no-oped the index returned.
See https://github.com/tidwall/gjson/issues/157
When it's resolved, let's go back to mainline.
* Use gjson@1.6.0 as it fixes https://github.com/tidwall/gjson/issues/157
* Use latest gomatrixserverlib for sig checks
* Fix a bug which could cause exclude_from_sync to not be set
Caused when sending events over federation.
* Use query variadic to make lookups actually work!
* Latest gomatrixserverlib
* Add notes on getting p2p up and running
Partly so I don't forget myself!
* refactor: Move p2p specific stuff to cmd/dendritejs
This is important or else the normal build of dendrite will fail
because the p2p libraries depend on syscall/js which doesn't work
on normal builds.
Also, clean up main.go to read a bit better.
* Update ho-http-js-libp2p to return errors from RoundTrip
* Add an LRU cache around the key DB
We actually need this for P2P because otherwise we can *segfault*
with things like: "runtime: unexpected return pc for runtime.handleEvent"
where the event is a `syscall/js` event, caused by spamming sql.js
caused by "Checking event signatures for 14 events of room state" which
hammers the key DB repeatedly in quick succession.
Using a cache fixes this, though the underlying cause is probably a bug
in the version of Go I'm on (1.13.7)
* breaking: Add Tracing.Enabled to toggle whether we do opentracing
Defaults to false, which is why this is a breaking change. We need
this flag because WASM builds cannot do opentracing.
* Start adding conditional builds for wasm to handle lib/pq
The general idea here is to have the wasm build have a `NewXXXDatabase`
that doesn't import any postgres package and hence we never import
`lib/pq`, which doesn't work under WASM (undefined `userCurrent`).
* Remove lib/pq for wasm for syncapi
* Add conditional building to remaining storage APIs
* Update build script to set env vars correctly for dendritejs
* sqlite bug fixes
* Docs
* Add a no-op main for dendritejs when not building under wasm
* Use the real prometheus, even for WASM
Instead, the dendrite-sw.js must mock out `process.pid` and
`fs.stat` - which must invoke the callback with an error (e.g `EINVAL`)
in order for it to work:
```
global.process = {
pid: 1,
};
global.fs.stat = function(path, cb) {
cb({
code: "EINVAL",
});
}
```
* Linting
2020-03-06 10:23:55 +00:00
|
|
|
// Set to true to enable tracer hooks. If false, no tracing is set up.
|
|
|
|
Enabled bool `yaml:"enabled"`
|
2017-09-28 17:00:23 +01:00
|
|
|
// The config for the jaeger opentracing reporter.
|
|
|
|
Jaeger jaegerconfig.Configuration `yaml:"jaeger"`
|
2017-12-19 17:00:44 +00:00
|
|
|
} `yaml:"tracing"`
|
|
|
|
|
2018-04-10 13:21:20 +01:00
|
|
|
// The config for logging informations. Each hook will be added to logrus.
|
|
|
|
Logging []LogrusHook `yaml:"logging"`
|
|
|
|
|
2017-11-29 09:43:03 +00:00
|
|
|
// Any information derived from the configuration options for later use.
|
2020-08-10 14:18:04 +01:00
|
|
|
Derived Derived `yaml:"-"`
|
|
|
|
}
|
2017-12-19 17:00:44 +00:00
|
|
|
|
2020-08-10 14:18:04 +01:00
|
|
|
// TODO: Kill Derived
|
|
|
|
type Derived struct {
|
|
|
|
Registration struct {
|
|
|
|
// Flows is a slice of flows, which represent one possible way that the client can authenticate a request.
|
|
|
|
// http://matrix.org/docs/spec/HEAD/client_server/r0.3.0.html#user-interactive-authentication-api
|
|
|
|
// As long as the generated flows only rely on config file options,
|
|
|
|
// we can generate them on startup and store them until needed
|
|
|
|
Flows []authtypes.Flow `json:"flows"`
|
|
|
|
|
|
|
|
// Params that need to be returned to the client during
|
|
|
|
// registration in order to complete registration stages.
|
|
|
|
Params map[string]interface{} `json:"params"`
|
|
|
|
}
|
2018-02-08 11:02:48 +00:00
|
|
|
|
2020-08-10 14:18:04 +01:00
|
|
|
// Application services parsed from their config files
|
|
|
|
// The paths of which were given above in the main config file
|
|
|
|
ApplicationServices []ApplicationService
|
|
|
|
|
|
|
|
// Meta-regexes compiled from all exclusive application service
|
|
|
|
// Regexes.
|
|
|
|
//
|
|
|
|
// When a user registers, we check that their username does not match any
|
|
|
|
// exclusive application service namespaces
|
|
|
|
ExclusiveApplicationServicesUsernameRegexp *regexp.Regexp
|
|
|
|
// When a user creates a room alias, we check that it isn't already
|
|
|
|
// reserved by an application service
|
|
|
|
ExclusiveApplicationServicesAliasRegexp *regexp.Regexp
|
|
|
|
// Note: An Exclusive Regex for room ID isn't necessary as we aren't blocking
|
|
|
|
// servers from creating RoomIDs in exclusive application service namespaces
|
2017-06-16 16:52:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// A Path on the filesystem.
|
|
|
|
type Path string
|
|
|
|
|
|
|
|
// A DataSource for opening a postgresql database using lib/pq.
|
|
|
|
type DataSource string
|
|
|
|
|
2020-08-10 14:18:04 +01:00
|
|
|
func (d DataSource) IsSQLite() bool {
|
|
|
|
return strings.HasPrefix(string(d), "file:")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d DataSource) IsPostgres() bool {
|
|
|
|
// commented line may not always be true?
|
|
|
|
// return strings.HasPrefix(string(d), "postgres:")
|
|
|
|
return !d.IsSQLite()
|
|
|
|
}
|
|
|
|
|
2017-06-16 16:52:03 +01:00
|
|
|
// A Topic in kafka.
|
|
|
|
type Topic string
|
|
|
|
|
|
|
|
// FileSizeBytes is a file size in bytes
|
|
|
|
type FileSizeBytes int64
|
|
|
|
|
|
|
|
// ThumbnailSize contains a single thumbnail size configuration
|
|
|
|
type ThumbnailSize struct {
|
|
|
|
// Maximum width of the thumbnail image
|
|
|
|
Width int `yaml:"width"`
|
|
|
|
// Maximum height of the thumbnail image
|
|
|
|
Height int `yaml:"height"`
|
|
|
|
// ResizeMethod is one of crop or scale.
|
|
|
|
// crop scales to fill the requested dimensions and crops the excess.
|
|
|
|
// scale scales to fit the requested dimensions and one dimension may be smaller than requested.
|
|
|
|
ResizeMethod string `yaml:"method,omitempty"`
|
|
|
|
}
|
|
|
|
|
2018-04-10 13:21:20 +01:00
|
|
|
// LogrusHook represents a single logrus hook. At this point, only parsing and
|
|
|
|
// verification of the proper values for type and level are done.
|
|
|
|
// Validity/integrity checks on the parameters are done when configuring logrus.
|
|
|
|
type LogrusHook struct {
|
|
|
|
// The type of hook, currently only "file" is supported.
|
|
|
|
Type string `yaml:"type"`
|
|
|
|
|
|
|
|
// The level of the logs to produce. Will output only this level and above.
|
|
|
|
Level string `yaml:"level"`
|
|
|
|
|
|
|
|
// The parameters for this hook.
|
|
|
|
Params map[string]interface{} `yaml:"params"`
|
|
|
|
}
|
|
|
|
|
2020-08-10 14:18:04 +01:00
|
|
|
// ConfigErrors stores problems encountered when parsing a config file.
|
2018-04-10 13:21:20 +01:00
|
|
|
// It implements the error interface.
|
2020-08-10 14:18:04 +01:00
|
|
|
type ConfigErrors []string
|
2018-04-10 13:21:20 +01:00
|
|
|
|
2020-06-05 09:28:15 +01:00
|
|
|
// Load a yaml config file for a server run as multiple processes or as a monolith.
|
2017-08-16 13:36:41 +01:00
|
|
|
// Checks the config to ensure that it is valid.
|
2023-02-14 11:47:47 +00:00
|
|
|
func Load(configPath string) (*Dendrite, error) {
|
2022-08-05 10:26:59 +01:00
|
|
|
configData, err := os.ReadFile(configPath)
|
2017-06-16 16:52:03 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
basePath, err := filepath.Abs(".")
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2022-08-05 10:26:59 +01:00
|
|
|
// Pass the current working directory and os.ReadFile so that they can
|
2017-06-16 16:52:03 +01:00
|
|
|
// be mocked in the tests
|
2023-02-14 11:47:47 +00:00
|
|
|
return loadConfig(basePath, configData, os.ReadFile)
|
2017-06-16 16:52:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func loadConfig(
|
|
|
|
basePath string,
|
|
|
|
configData []byte,
|
|
|
|
readFile func(string) ([]byte, error),
|
|
|
|
) (*Dendrite, error) {
|
2020-08-10 14:18:04 +01:00
|
|
|
var c Dendrite
|
2022-09-01 14:15:41 +01:00
|
|
|
c.Defaults(DefaultOpts{
|
2023-02-14 11:47:47 +00:00
|
|
|
Generate: false,
|
|
|
|
SingleDatabase: true,
|
2022-09-01 14:15:41 +01:00
|
|
|
})
|
2020-08-10 14:18:04 +01:00
|
|
|
|
2017-06-16 16:52:03 +01:00
|
|
|
var err error
|
2020-08-10 14:18:04 +01:00
|
|
|
if err = yaml.Unmarshal(configData, &c); err != nil {
|
2017-06-16 16:52:03 +01:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2023-02-14 11:47:47 +00:00
|
|
|
if err = c.check(); err != nil {
|
2017-06-16 16:52:03 +01:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2020-08-10 14:18:04 +01:00
|
|
|
privateKeyPath := absPath(basePath, c.Global.PrivateKeyPath)
|
2022-08-31 10:41:32 +01:00
|
|
|
if c.Global.KeyID, c.Global.PrivateKey, err = LoadMatrixKey(privateKeyPath, readFile); err != nil {
|
2023-01-06 14:44:10 +00:00
|
|
|
return nil, fmt.Errorf("failed to load private_key: %w", err)
|
2017-06-16 16:52:03 +01:00
|
|
|
}
|
|
|
|
|
2022-11-15 15:05:23 +00:00
|
|
|
for _, v := range c.Global.VirtualHosts {
|
|
|
|
if v.KeyValidityPeriod == 0 {
|
|
|
|
v.KeyValidityPeriod = c.Global.KeyValidityPeriod
|
|
|
|
}
|
2022-11-18 13:24:02 +00:00
|
|
|
if v.PrivateKeyPath == "" || v.PrivateKey == nil || v.KeyID == "" {
|
2022-11-15 15:05:23 +00:00
|
|
|
v.KeyID = c.Global.KeyID
|
|
|
|
v.PrivateKey = c.Global.PrivateKey
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
privateKeyPath := absPath(basePath, v.PrivateKeyPath)
|
|
|
|
if v.KeyID, v.PrivateKey, err = LoadMatrixKey(privateKeyPath, readFile); err != nil {
|
2023-01-06 14:44:10 +00:00
|
|
|
return nil, fmt.Errorf("failed to load private_key for virtualhost %s: %w", v.ServerName, err)
|
2022-11-15 15:05:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-06 11:56:00 +01:00
|
|
|
for _, key := range c.Global.OldVerifyKeys {
|
|
|
|
switch {
|
|
|
|
case key.PrivateKeyPath != "":
|
|
|
|
var oldPrivateKeyData []byte
|
|
|
|
oldPrivateKeyPath := absPath(basePath, key.PrivateKeyPath)
|
|
|
|
oldPrivateKeyData, err = readFile(oldPrivateKeyPath)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("failed to read %q: %w", oldPrivateKeyPath, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// NOTSPEC: Ordinarily we should enforce key ID formatting, but since there are
|
|
|
|
// a number of private keys out there with non-compatible symbols in them due
|
|
|
|
// to lack of validation in Synapse, we won't enforce that for old verify keys.
|
|
|
|
keyID, privateKey, perr := readKeyPEM(oldPrivateKeyPath, oldPrivateKeyData, false)
|
|
|
|
if perr != nil {
|
|
|
|
return nil, fmt.Errorf("failed to parse %q: %w", oldPrivateKeyPath, perr)
|
|
|
|
}
|
|
|
|
|
|
|
|
key.KeyID = keyID
|
|
|
|
key.PrivateKey = privateKey
|
2023-04-19 15:50:33 +01:00
|
|
|
key.PublicKey = spec.Base64Bytes(privateKey.Public().(ed25519.PublicKey))
|
2022-10-06 11:56:00 +01:00
|
|
|
|
|
|
|
case key.KeyID == "":
|
|
|
|
return nil, fmt.Errorf("'key_id' must be specified if 'public_key' is specified")
|
|
|
|
|
|
|
|
case len(key.PublicKey) == ed25519.PublicKeySize:
|
|
|
|
continue
|
|
|
|
|
|
|
|
case len(key.PublicKey) > 0:
|
|
|
|
return nil, fmt.Errorf("the supplied 'public_key' is the wrong length")
|
|
|
|
|
|
|
|
default:
|
|
|
|
return nil, fmt.Errorf("either specify a 'private_key' path or supply both 'public_key' and 'key_id'")
|
2020-09-25 10:58:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-10 14:18:04 +01:00
|
|
|
c.MediaAPI.AbsBasePath = Path(absPath(basePath, c.MediaAPI.BasePath))
|
2017-06-16 16:52:03 +01:00
|
|
|
|
2017-11-29 09:43:03 +00:00
|
|
|
// Generate data from config options
|
2020-08-10 14:18:04 +01:00
|
|
|
err = c.Derive()
|
2017-12-19 17:00:44 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2017-11-29 09:43:03 +00:00
|
|
|
|
2020-08-10 14:18:04 +01:00
|
|
|
c.Wiring()
|
|
|
|
return &c, nil
|
2017-06-16 16:52:03 +01:00
|
|
|
}
|
|
|
|
|
2022-08-31 10:41:32 +01:00
|
|
|
func LoadMatrixKey(privateKeyPath string, readFile func(string) ([]byte, error)) (gomatrixserverlib.KeyID, ed25519.PrivateKey, error) {
|
|
|
|
privateKeyData, err := readFile(privateKeyPath)
|
|
|
|
if err != nil {
|
|
|
|
return "", nil, err
|
|
|
|
}
|
|
|
|
return readKeyPEM(privateKeyPath, privateKeyData, true)
|
|
|
|
}
|
|
|
|
|
Add peer-to-peer support into Dendrite via libp2p and fetch (#880)
* Use a fork of pq which supports userCurrent on wasm
* Use sqlite3_js driver when running in JS
* Add cmd/dendritejs to pull in sqlite3_js driver for wasm only
* Update to latest go-sqlite-js version
* Replace prometheus with a stub. sigh
* Hard-code a config and don't use opentracing
* Latest go-sqlite3-js version
* Generate a key for now
* Listen for fetch traffic rather than HTTP
* Latest hacks for js
* libp2p support
* More libp2p
* Fork gjson to allow us to enforce auth checks as before
Previously, all events would come down redacted because the hash
checks would fail. They would fail because sjson.DeleteBytes didn't
remove keys not used for hashing. This didn't work because of a build
tag which included a file which no-oped the index returned.
See https://github.com/tidwall/gjson/issues/157
When it's resolved, let's go back to mainline.
* Use gjson@1.6.0 as it fixes https://github.com/tidwall/gjson/issues/157
* Use latest gomatrixserverlib for sig checks
* Fix a bug which could cause exclude_from_sync to not be set
Caused when sending events over federation.
* Use query variadic to make lookups actually work!
* Latest gomatrixserverlib
* Add notes on getting p2p up and running
Partly so I don't forget myself!
* refactor: Move p2p specific stuff to cmd/dendritejs
This is important or else the normal build of dendrite will fail
because the p2p libraries depend on syscall/js which doesn't work
on normal builds.
Also, clean up main.go to read a bit better.
* Update ho-http-js-libp2p to return errors from RoundTrip
* Add an LRU cache around the key DB
We actually need this for P2P because otherwise we can *segfault*
with things like: "runtime: unexpected return pc for runtime.handleEvent"
where the event is a `syscall/js` event, caused by spamming sql.js
caused by "Checking event signatures for 14 events of room state" which
hammers the key DB repeatedly in quick succession.
Using a cache fixes this, though the underlying cause is probably a bug
in the version of Go I'm on (1.13.7)
* breaking: Add Tracing.Enabled to toggle whether we do opentracing
Defaults to false, which is why this is a breaking change. We need
this flag because WASM builds cannot do opentracing.
* Start adding conditional builds for wasm to handle lib/pq
The general idea here is to have the wasm build have a `NewXXXDatabase`
that doesn't import any postgres package and hence we never import
`lib/pq`, which doesn't work under WASM (undefined `userCurrent`).
* Remove lib/pq for wasm for syncapi
* Add conditional building to remaining storage APIs
* Update build script to set env vars correctly for dendritejs
* sqlite bug fixes
* Docs
* Add a no-op main for dendritejs when not building under wasm
* Use the real prometheus, even for WASM
Instead, the dendrite-sw.js must mock out `process.pid` and
`fs.stat` - which must invoke the callback with an error (e.g `EINVAL`)
in order for it to work:
```
global.process = {
pid: 1,
};
global.fs.stat = function(path, cb) {
cb({
code: "EINVAL",
});
}
```
* Linting
2020-03-06 10:23:55 +00:00
|
|
|
// Derive generates data that is derived from various values provided in
|
2017-11-29 09:43:03 +00:00
|
|
|
// the config file.
|
Add peer-to-peer support into Dendrite via libp2p and fetch (#880)
* Use a fork of pq which supports userCurrent on wasm
* Use sqlite3_js driver when running in JS
* Add cmd/dendritejs to pull in sqlite3_js driver for wasm only
* Update to latest go-sqlite-js version
* Replace prometheus with a stub. sigh
* Hard-code a config and don't use opentracing
* Latest go-sqlite3-js version
* Generate a key for now
* Listen for fetch traffic rather than HTTP
* Latest hacks for js
* libp2p support
* More libp2p
* Fork gjson to allow us to enforce auth checks as before
Previously, all events would come down redacted because the hash
checks would fail. They would fail because sjson.DeleteBytes didn't
remove keys not used for hashing. This didn't work because of a build
tag which included a file which no-oped the index returned.
See https://github.com/tidwall/gjson/issues/157
When it's resolved, let's go back to mainline.
* Use gjson@1.6.0 as it fixes https://github.com/tidwall/gjson/issues/157
* Use latest gomatrixserverlib for sig checks
* Fix a bug which could cause exclude_from_sync to not be set
Caused when sending events over federation.
* Use query variadic to make lookups actually work!
* Latest gomatrixserverlib
* Add notes on getting p2p up and running
Partly so I don't forget myself!
* refactor: Move p2p specific stuff to cmd/dendritejs
This is important or else the normal build of dendrite will fail
because the p2p libraries depend on syscall/js which doesn't work
on normal builds.
Also, clean up main.go to read a bit better.
* Update ho-http-js-libp2p to return errors from RoundTrip
* Add an LRU cache around the key DB
We actually need this for P2P because otherwise we can *segfault*
with things like: "runtime: unexpected return pc for runtime.handleEvent"
where the event is a `syscall/js` event, caused by spamming sql.js
caused by "Checking event signatures for 14 events of room state" which
hammers the key DB repeatedly in quick succession.
Using a cache fixes this, though the underlying cause is probably a bug
in the version of Go I'm on (1.13.7)
* breaking: Add Tracing.Enabled to toggle whether we do opentracing
Defaults to false, which is why this is a breaking change. We need
this flag because WASM builds cannot do opentracing.
* Start adding conditional builds for wasm to handle lib/pq
The general idea here is to have the wasm build have a `NewXXXDatabase`
that doesn't import any postgres package and hence we never import
`lib/pq`, which doesn't work under WASM (undefined `userCurrent`).
* Remove lib/pq for wasm for syncapi
* Add conditional building to remaining storage APIs
* Update build script to set env vars correctly for dendritejs
* sqlite bug fixes
* Docs
* Add a no-op main for dendritejs when not building under wasm
* Use the real prometheus, even for WASM
Instead, the dendrite-sw.js must mock out `process.pid` and
`fs.stat` - which must invoke the callback with an error (e.g `EINVAL`)
in order for it to work:
```
global.process = {
pid: 1,
};
global.fs.stat = function(path, cb) {
cb({
code: "EINVAL",
});
}
```
* Linting
2020-03-06 10:23:55 +00:00
|
|
|
func (config *Dendrite) Derive() error {
|
2017-11-29 09:43:03 +00:00
|
|
|
// Determine registrations flows based off config values
|
|
|
|
|
|
|
|
config.Derived.Registration.Params = make(map[string]interface{})
|
|
|
|
|
|
|
|
// TODO: Add email auth type
|
|
|
|
// TODO: Add MSISDN auth type
|
|
|
|
|
2020-08-10 14:18:04 +01:00
|
|
|
if config.ClientAPI.RecaptchaEnabled {
|
|
|
|
config.Derived.Registration.Params[authtypes.LoginTypeRecaptcha] = map[string]string{"public_key": config.ClientAPI.RecaptchaPublicKey}
|
2022-12-23 13:11:11 +00:00
|
|
|
config.Derived.Registration.Flows = []authtypes.Flow{
|
|
|
|
{Stages: []authtypes.LoginType{authtypes.LoginTypeRecaptcha}},
|
|
|
|
}
|
2017-12-05 16:16:14 +00:00
|
|
|
} else {
|
2022-12-23 13:11:11 +00:00
|
|
|
config.Derived.Registration.Flows = []authtypes.Flow{
|
|
|
|
{Stages: []authtypes.LoginType{authtypes.LoginTypeDummy}},
|
|
|
|
}
|
2017-12-05 16:16:14 +00:00
|
|
|
}
|
2017-12-19 17:00:44 +00:00
|
|
|
|
|
|
|
// Load application service configuration files
|
2020-08-10 14:18:04 +01:00
|
|
|
if err := loadAppServices(&config.AppServiceAPI, &config.Derived); err != nil {
|
2017-12-19 17:00:44 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2017-11-29 09:43:03 +00:00
|
|
|
}
|
|
|
|
|
2022-09-01 14:15:41 +01:00
|
|
|
type DefaultOpts struct {
|
2023-02-14 11:47:47 +00:00
|
|
|
Generate bool
|
|
|
|
SingleDatabase bool
|
2022-09-01 14:15:41 +01:00
|
|
|
}
|
|
|
|
|
Add peer-to-peer support into Dendrite via libp2p and fetch (#880)
* Use a fork of pq which supports userCurrent on wasm
* Use sqlite3_js driver when running in JS
* Add cmd/dendritejs to pull in sqlite3_js driver for wasm only
* Update to latest go-sqlite-js version
* Replace prometheus with a stub. sigh
* Hard-code a config and don't use opentracing
* Latest go-sqlite3-js version
* Generate a key for now
* Listen for fetch traffic rather than HTTP
* Latest hacks for js
* libp2p support
* More libp2p
* Fork gjson to allow us to enforce auth checks as before
Previously, all events would come down redacted because the hash
checks would fail. They would fail because sjson.DeleteBytes didn't
remove keys not used for hashing. This didn't work because of a build
tag which included a file which no-oped the index returned.
See https://github.com/tidwall/gjson/issues/157
When it's resolved, let's go back to mainline.
* Use gjson@1.6.0 as it fixes https://github.com/tidwall/gjson/issues/157
* Use latest gomatrixserverlib for sig checks
* Fix a bug which could cause exclude_from_sync to not be set
Caused when sending events over federation.
* Use query variadic to make lookups actually work!
* Latest gomatrixserverlib
* Add notes on getting p2p up and running
Partly so I don't forget myself!
* refactor: Move p2p specific stuff to cmd/dendritejs
This is important or else the normal build of dendrite will fail
because the p2p libraries depend on syscall/js which doesn't work
on normal builds.
Also, clean up main.go to read a bit better.
* Update ho-http-js-libp2p to return errors from RoundTrip
* Add an LRU cache around the key DB
We actually need this for P2P because otherwise we can *segfault*
with things like: "runtime: unexpected return pc for runtime.handleEvent"
where the event is a `syscall/js` event, caused by spamming sql.js
caused by "Checking event signatures for 14 events of room state" which
hammers the key DB repeatedly in quick succession.
Using a cache fixes this, though the underlying cause is probably a bug
in the version of Go I'm on (1.13.7)
* breaking: Add Tracing.Enabled to toggle whether we do opentracing
Defaults to false, which is why this is a breaking change. We need
this flag because WASM builds cannot do opentracing.
* Start adding conditional builds for wasm to handle lib/pq
The general idea here is to have the wasm build have a `NewXXXDatabase`
that doesn't import any postgres package and hence we never import
`lib/pq`, which doesn't work under WASM (undefined `userCurrent`).
* Remove lib/pq for wasm for syncapi
* Add conditional building to remaining storage APIs
* Update build script to set env vars correctly for dendritejs
* sqlite bug fixes
* Docs
* Add a no-op main for dendritejs when not building under wasm
* Use the real prometheus, even for WASM
Instead, the dendrite-sw.js must mock out `process.pid` and
`fs.stat` - which must invoke the callback with an error (e.g `EINVAL`)
in order for it to work:
```
global.process = {
pid: 1,
};
global.fs.stat = function(path, cb) {
cb({
code: "EINVAL",
});
}
```
* Linting
2020-03-06 10:23:55 +00:00
|
|
|
// SetDefaults sets default config values if they are not explicitly set.
|
2022-09-01 14:15:41 +01:00
|
|
|
func (c *Dendrite) Defaults(opts DefaultOpts) {
|
2022-01-05 17:44:49 +00:00
|
|
|
c.Version = Version
|
2020-08-10 14:18:04 +01:00
|
|
|
|
2022-09-01 14:15:41 +01:00
|
|
|
c.Global.Defaults(opts)
|
|
|
|
c.ClientAPI.Defaults(opts)
|
|
|
|
c.FederationAPI.Defaults(opts)
|
|
|
|
c.KeyServer.Defaults(opts)
|
|
|
|
c.MediaAPI.Defaults(opts)
|
|
|
|
c.RoomServer.Defaults(opts)
|
|
|
|
c.SyncAPI.Defaults(opts)
|
|
|
|
c.UserAPI.Defaults(opts)
|
|
|
|
c.AppServiceAPI.Defaults(opts)
|
2023-01-23 17:55:12 +00:00
|
|
|
c.RelayAPI.Defaults(opts)
|
2022-09-01 14:15:41 +01:00
|
|
|
c.MSCs.Defaults(opts)
|
2020-08-10 14:18:04 +01:00
|
|
|
c.Wiring()
|
|
|
|
}
|
|
|
|
|
2023-02-14 11:47:47 +00:00
|
|
|
func (c *Dendrite) Verify(configErrs *ConfigErrors) {
|
2020-08-10 14:18:04 +01:00
|
|
|
type verifiable interface {
|
2023-02-14 11:47:47 +00:00
|
|
|
Verify(configErrs *ConfigErrors)
|
2020-08-10 14:18:04 +01:00
|
|
|
}
|
|
|
|
for _, c := range []verifiable{
|
2022-03-29 13:14:35 +01:00
|
|
|
&c.Global, &c.ClientAPI, &c.FederationAPI,
|
2020-08-10 14:18:04 +01:00
|
|
|
&c.KeyServer, &c.MediaAPI, &c.RoomServer,
|
2021-11-24 10:45:23 +00:00
|
|
|
&c.SyncAPI, &c.UserAPI,
|
2023-01-23 17:55:12 +00:00
|
|
|
&c.AppServiceAPI, &c.RelayAPI, &c.MSCs,
|
2020-08-10 14:18:04 +01:00
|
|
|
} {
|
2023-02-14 11:47:47 +00:00
|
|
|
c.Verify(configErrs)
|
2020-08-10 14:18:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Dendrite) Wiring() {
|
2022-01-05 17:44:49 +00:00
|
|
|
c.Global.JetStream.Matrix = &c.Global
|
2020-08-10 14:18:04 +01:00
|
|
|
c.ClientAPI.Matrix = &c.Global
|
|
|
|
c.FederationAPI.Matrix = &c.Global
|
|
|
|
c.KeyServer.Matrix = &c.Global
|
|
|
|
c.MediaAPI.Matrix = &c.Global
|
|
|
|
c.RoomServer.Matrix = &c.Global
|
|
|
|
c.SyncAPI.Matrix = &c.Global
|
|
|
|
c.UserAPI.Matrix = &c.Global
|
|
|
|
c.AppServiceAPI.Matrix = &c.Global
|
2023-01-23 17:55:12 +00:00
|
|
|
c.RelayAPI.Matrix = &c.Global
|
2020-11-19 11:34:59 +00:00
|
|
|
c.MSCs.Matrix = &c.Global
|
2020-08-10 14:18:04 +01:00
|
|
|
|
|
|
|
c.ClientAPI.Derived = &c.Derived
|
|
|
|
c.AppServiceAPI.Derived = &c.Derived
|
2021-01-18 13:09:28 +00:00
|
|
|
c.ClientAPI.MSCs = &c.MSCs
|
2017-06-16 16:52:03 +01:00
|
|
|
}
|
|
|
|
|
2018-04-10 13:21:20 +01:00
|
|
|
// Error returns a string detailing how many errors were contained within a
|
|
|
|
// configErrors type.
|
2020-08-10 14:18:04 +01:00
|
|
|
func (errs ConfigErrors) Error() string {
|
2018-04-10 13:21:20 +01:00
|
|
|
if len(errs) == 1 {
|
|
|
|
return errs[0]
|
2017-06-16 16:52:03 +01:00
|
|
|
}
|
|
|
|
return fmt.Sprintf(
|
2018-04-10 13:21:20 +01:00
|
|
|
"%s (and %d other problems)", errs[0], len(errs)-1,
|
2017-06-16 16:52:03 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2018-04-10 13:21:20 +01:00
|
|
|
// Add appends an error to the list of errors in this configErrors.
|
|
|
|
// It is a wrapper to the builtin append and hides pointers from
|
|
|
|
// the client code.
|
|
|
|
// This method is safe to use with an uninitialized configErrors because
|
|
|
|
// if it is nil, it will be properly allocated.
|
2020-08-10 14:18:04 +01:00
|
|
|
func (errs *ConfigErrors) Add(str string) {
|
2018-04-10 13:21:20 +01:00
|
|
|
*errs = append(*errs, str)
|
|
|
|
}
|
2017-06-16 16:52:03 +01:00
|
|
|
|
2018-04-10 13:21:20 +01:00
|
|
|
// checkNotEmpty verifies the given value is not empty in the configuration.
|
|
|
|
// If it is, adds an error to the list.
|
2020-08-10 14:18:04 +01:00
|
|
|
func checkNotEmpty(configErrs *ConfigErrors, key, value string) {
|
2018-04-10 13:21:20 +01:00
|
|
|
if value == "" {
|
|
|
|
configErrs.Add(fmt.Sprintf("missing config key %q", key))
|
2017-06-16 16:52:03 +01:00
|
|
|
}
|
2018-04-10 13:21:20 +01:00
|
|
|
}
|
2017-06-16 16:52:03 +01:00
|
|
|
|
2018-04-10 13:21:20 +01:00
|
|
|
// checkPositive verifies the given value is positive (zero included)
|
|
|
|
// in the configuration. If it is not, adds an error to the list.
|
2020-08-10 14:18:04 +01:00
|
|
|
func checkPositive(configErrs *ConfigErrors, key string, value int64) {
|
2018-04-10 13:21:20 +01:00
|
|
|
if value < 0 {
|
|
|
|
configErrs.Add(fmt.Sprintf("invalid value for config key %q: %d", key, value))
|
2017-06-16 16:52:03 +01:00
|
|
|
}
|
2018-04-10 13:21:20 +01:00
|
|
|
}
|
2017-06-16 16:52:03 +01:00
|
|
|
|
2018-04-10 13:21:20 +01:00
|
|
|
// checkLogging verifies the parameters logging.* are valid.
|
2020-08-10 14:18:04 +01:00
|
|
|
func (config *Dendrite) checkLogging(configErrs *ConfigErrors) {
|
2018-04-10 13:21:20 +01:00
|
|
|
for _, logrusHook := range config.Logging {
|
|
|
|
checkNotEmpty(configErrs, "logging.type", string(logrusHook.Type))
|
|
|
|
checkNotEmpty(configErrs, "logging.level", string(logrusHook.Level))
|
2017-08-16 13:36:41 +01:00
|
|
|
}
|
2018-04-10 13:21:20 +01:00
|
|
|
}
|
2017-06-16 16:52:03 +01:00
|
|
|
|
2018-04-10 13:21:20 +01:00
|
|
|
// check returns an error type containing all errors found within the config
|
|
|
|
// file.
|
2023-02-14 11:47:47 +00:00
|
|
|
func (config *Dendrite) check() error { // monolithic
|
2020-08-10 14:18:04 +01:00
|
|
|
var configErrs ConfigErrors
|
2018-04-10 13:21:20 +01:00
|
|
|
|
|
|
|
if config.Version != Version {
|
|
|
|
configErrs.Add(fmt.Sprintf(
|
2022-01-05 17:44:49 +00:00
|
|
|
"config version is %q, expected %q - this means that the format of the configuration "+
|
|
|
|
"file has changed in some significant way, so please revisit the sample config "+
|
|
|
|
"and ensure you are not missing any important options that may have been added "+
|
|
|
|
"or changed recently!",
|
|
|
|
config.Version, Version,
|
2018-04-10 13:21:20 +01:00
|
|
|
))
|
|
|
|
return configErrs
|
2017-06-16 16:52:03 +01:00
|
|
|
}
|
|
|
|
|
2018-04-10 13:21:20 +01:00
|
|
|
config.checkLogging(&configErrs)
|
|
|
|
|
|
|
|
// Due to how Golang manages its interface types, this condition is not redundant.
|
2019-06-19 14:05:03 +01:00
|
|
|
// In order to get the proper behaviour, it is necessary to return an explicit nil
|
2018-04-10 13:21:20 +01:00
|
|
|
// and not a nil configErrors.
|
|
|
|
// This is because the following equalities hold:
|
|
|
|
// error(nil) == nil
|
|
|
|
// error(configErrors(nil)) != nil
|
|
|
|
if configErrs != nil {
|
|
|
|
return configErrs
|
|
|
|
}
|
2017-06-16 16:52:03 +01:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-11-29 09:43:03 +00:00
|
|
|
// absPath returns the absolute path for a given relative or absolute path.
|
2017-06-16 16:52:03 +01:00
|
|
|
func absPath(dir string, path Path) string {
|
|
|
|
if filepath.IsAbs(string(path)) {
|
|
|
|
// filepath.Join cleans the path so we should clean the absolute paths as well for consistency.
|
|
|
|
return filepath.Clean(string(path))
|
|
|
|
}
|
|
|
|
return filepath.Join(dir, string(path))
|
|
|
|
}
|
|
|
|
|
2020-09-25 10:58:53 +01:00
|
|
|
func readKeyPEM(path string, data []byte, enforceKeyIDFormat bool) (gomatrixserverlib.KeyID, ed25519.PrivateKey, error) {
|
2017-06-16 16:52:03 +01:00
|
|
|
for {
|
|
|
|
var keyBlock *pem.Block
|
|
|
|
keyBlock, data = pem.Decode(data)
|
|
|
|
if data == nil {
|
|
|
|
return "", nil, fmt.Errorf("no matrix private key PEM data in %q", path)
|
|
|
|
}
|
2018-03-03 12:18:28 +00:00
|
|
|
if keyBlock == nil {
|
|
|
|
return "", nil, fmt.Errorf("keyBlock is nil %q", path)
|
|
|
|
}
|
2017-06-16 16:52:03 +01:00
|
|
|
if keyBlock.Type == "MATRIX PRIVATE KEY" {
|
|
|
|
keyID := keyBlock.Headers["Key-ID"]
|
|
|
|
if keyID == "" {
|
|
|
|
return "", nil, fmt.Errorf("missing key ID in PEM data in %q", path)
|
|
|
|
}
|
|
|
|
if !strings.HasPrefix(keyID, "ed25519:") {
|
|
|
|
return "", nil, fmt.Errorf("key ID %q doesn't start with \"ed25519:\" in %q", keyID, path)
|
|
|
|
}
|
2020-09-25 10:58:53 +01:00
|
|
|
if enforceKeyIDFormat && !keyIDRegexp.MatchString(keyID) {
|
2020-09-23 11:07:57 +01:00
|
|
|
return "", nil, fmt.Errorf("key ID %q in %q contains illegal characters (use a-z, A-Z, 0-9 and _ only)", keyID, path)
|
|
|
|
}
|
2017-06-16 16:52:03 +01:00
|
|
|
_, privKey, err := ed25519.GenerateKey(bytes.NewReader(keyBlock.Bytes))
|
|
|
|
if err != nil {
|
|
|
|
return "", nil, err
|
|
|
|
}
|
|
|
|
return gomatrixserverlib.KeyID(keyID), privKey, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-28 17:00:23 +01:00
|
|
|
// SetupTracing configures the opentracing using the supplied configuration.
|
2023-02-14 11:47:47 +00:00
|
|
|
func (config *Dendrite) SetupTracing() (closer io.Closer, err error) {
|
Add peer-to-peer support into Dendrite via libp2p and fetch (#880)
* Use a fork of pq which supports userCurrent on wasm
* Use sqlite3_js driver when running in JS
* Add cmd/dendritejs to pull in sqlite3_js driver for wasm only
* Update to latest go-sqlite-js version
* Replace prometheus with a stub. sigh
* Hard-code a config and don't use opentracing
* Latest go-sqlite3-js version
* Generate a key for now
* Listen for fetch traffic rather than HTTP
* Latest hacks for js
* libp2p support
* More libp2p
* Fork gjson to allow us to enforce auth checks as before
Previously, all events would come down redacted because the hash
checks would fail. They would fail because sjson.DeleteBytes didn't
remove keys not used for hashing. This didn't work because of a build
tag which included a file which no-oped the index returned.
See https://github.com/tidwall/gjson/issues/157
When it's resolved, let's go back to mainline.
* Use gjson@1.6.0 as it fixes https://github.com/tidwall/gjson/issues/157
* Use latest gomatrixserverlib for sig checks
* Fix a bug which could cause exclude_from_sync to not be set
Caused when sending events over federation.
* Use query variadic to make lookups actually work!
* Latest gomatrixserverlib
* Add notes on getting p2p up and running
Partly so I don't forget myself!
* refactor: Move p2p specific stuff to cmd/dendritejs
This is important or else the normal build of dendrite will fail
because the p2p libraries depend on syscall/js which doesn't work
on normal builds.
Also, clean up main.go to read a bit better.
* Update ho-http-js-libp2p to return errors from RoundTrip
* Add an LRU cache around the key DB
We actually need this for P2P because otherwise we can *segfault*
with things like: "runtime: unexpected return pc for runtime.handleEvent"
where the event is a `syscall/js` event, caused by spamming sql.js
caused by "Checking event signatures for 14 events of room state" which
hammers the key DB repeatedly in quick succession.
Using a cache fixes this, though the underlying cause is probably a bug
in the version of Go I'm on (1.13.7)
* breaking: Add Tracing.Enabled to toggle whether we do opentracing
Defaults to false, which is why this is a breaking change. We need
this flag because WASM builds cannot do opentracing.
* Start adding conditional builds for wasm to handle lib/pq
The general idea here is to have the wasm build have a `NewXXXDatabase`
that doesn't import any postgres package and hence we never import
`lib/pq`, which doesn't work under WASM (undefined `userCurrent`).
* Remove lib/pq for wasm for syncapi
* Add conditional building to remaining storage APIs
* Update build script to set env vars correctly for dendritejs
* sqlite bug fixes
* Docs
* Add a no-op main for dendritejs when not building under wasm
* Use the real prometheus, even for WASM
Instead, the dendrite-sw.js must mock out `process.pid` and
`fs.stat` - which must invoke the callback with an error (e.g `EINVAL`)
in order for it to work:
```
global.process = {
pid: 1,
};
global.fs.stat = function(path, cb) {
cb({
code: "EINVAL",
});
}
```
* Linting
2020-03-06 10:23:55 +00:00
|
|
|
if !config.Tracing.Enabled {
|
2022-08-05 10:26:59 +01:00
|
|
|
return io.NopCloser(bytes.NewReader([]byte{})), nil
|
Add peer-to-peer support into Dendrite via libp2p and fetch (#880)
* Use a fork of pq which supports userCurrent on wasm
* Use sqlite3_js driver when running in JS
* Add cmd/dendritejs to pull in sqlite3_js driver for wasm only
* Update to latest go-sqlite-js version
* Replace prometheus with a stub. sigh
* Hard-code a config and don't use opentracing
* Latest go-sqlite3-js version
* Generate a key for now
* Listen for fetch traffic rather than HTTP
* Latest hacks for js
* libp2p support
* More libp2p
* Fork gjson to allow us to enforce auth checks as before
Previously, all events would come down redacted because the hash
checks would fail. They would fail because sjson.DeleteBytes didn't
remove keys not used for hashing. This didn't work because of a build
tag which included a file which no-oped the index returned.
See https://github.com/tidwall/gjson/issues/157
When it's resolved, let's go back to mainline.
* Use gjson@1.6.0 as it fixes https://github.com/tidwall/gjson/issues/157
* Use latest gomatrixserverlib for sig checks
* Fix a bug which could cause exclude_from_sync to not be set
Caused when sending events over federation.
* Use query variadic to make lookups actually work!
* Latest gomatrixserverlib
* Add notes on getting p2p up and running
Partly so I don't forget myself!
* refactor: Move p2p specific stuff to cmd/dendritejs
This is important or else the normal build of dendrite will fail
because the p2p libraries depend on syscall/js which doesn't work
on normal builds.
Also, clean up main.go to read a bit better.
* Update ho-http-js-libp2p to return errors from RoundTrip
* Add an LRU cache around the key DB
We actually need this for P2P because otherwise we can *segfault*
with things like: "runtime: unexpected return pc for runtime.handleEvent"
where the event is a `syscall/js` event, caused by spamming sql.js
caused by "Checking event signatures for 14 events of room state" which
hammers the key DB repeatedly in quick succession.
Using a cache fixes this, though the underlying cause is probably a bug
in the version of Go I'm on (1.13.7)
* breaking: Add Tracing.Enabled to toggle whether we do opentracing
Defaults to false, which is why this is a breaking change. We need
this flag because WASM builds cannot do opentracing.
* Start adding conditional builds for wasm to handle lib/pq
The general idea here is to have the wasm build have a `NewXXXDatabase`
that doesn't import any postgres package and hence we never import
`lib/pq`, which doesn't work under WASM (undefined `userCurrent`).
* Remove lib/pq for wasm for syncapi
* Add conditional building to remaining storage APIs
* Update build script to set env vars correctly for dendritejs
* sqlite bug fixes
* Docs
* Add a no-op main for dendritejs when not building under wasm
* Use the real prometheus, even for WASM
Instead, the dendrite-sw.js must mock out `process.pid` and
`fs.stat` - which must invoke the callback with an error (e.g `EINVAL`)
in order for it to work:
```
global.process = {
pid: 1,
};
global.fs.stat = function(path, cb) {
cb({
code: "EINVAL",
});
}
```
* Linting
2020-03-06 10:23:55 +00:00
|
|
|
}
|
2017-09-28 17:00:23 +01:00
|
|
|
return config.Tracing.Jaeger.InitGlobalTracer(
|
2023-02-14 11:47:47 +00:00
|
|
|
"Dendrite",
|
2017-09-28 17:00:23 +01:00
|
|
|
jaegerconfig.Logger(logrusLogger{logrus.StandardLogger()}),
|
|
|
|
jaegerconfig.Metrics(jaegermetrics.NullFactory),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// logrusLogger is a small wrapper that implements jaeger.Logger using logrus.
|
|
|
|
type logrusLogger struct {
|
|
|
|
l *logrus.Logger
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l logrusLogger) Error(msg string) {
|
|
|
|
l.l.Error(msg)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l logrusLogger) Infof(msg string, args ...interface{}) {
|
|
|
|
l.l.Infof(msg, args...)
|
|
|
|
}
|