mirror of
https://github.com/strukturag/nextcloud-spreed-signaling
synced 2026-03-14 14:35:44 +01:00
Move logging code to separate package.
This commit is contained in:
parent
67b557349d
commit
62587796ce
77 changed files with 482 additions and 297 deletions
|
|
@ -30,6 +30,10 @@ component_management:
|
|||
name: internal
|
||||
paths:
|
||||
- internal/**
|
||||
- component_id: module_log
|
||||
name: log
|
||||
paths:
|
||||
- log/**
|
||||
- component_id: module_proxy
|
||||
name: proxy
|
||||
paths:
|
||||
|
|
|
|||
|
|
@ -24,6 +24,8 @@ package signaling
|
|||
import (
|
||||
"context"
|
||||
"sync"
|
||||
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
type AsyncBackendRoomEventListener interface {
|
||||
|
|
@ -69,7 +71,7 @@ func NewAsyncEvents(ctx context.Context, url string) (AsyncEvents, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
return NewAsyncEventsNats(LoggerFromContext(ctx), client)
|
||||
return NewAsyncEventsNats(log.LoggerFromContext(ctx), client)
|
||||
}
|
||||
|
||||
type asyncBackendRoomSubscriber struct {
|
||||
|
|
|
|||
|
|
@ -27,6 +27,8 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/nats-io/nats.go"
|
||||
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
func GetSubjectForBackendRoomId(roomId string, backend *Backend) string {
|
||||
|
|
@ -60,7 +62,7 @@ func GetSubjectForSessionId(sessionId PublicSessionId, backend *Backend) string
|
|||
type asyncSubscriberNats struct {
|
||||
key string
|
||||
client NatsClient
|
||||
logger Logger
|
||||
logger log.Logger
|
||||
|
||||
receiver chan *nats.Msg
|
||||
closeChan chan struct{}
|
||||
|
|
@ -69,7 +71,7 @@ type asyncSubscriberNats struct {
|
|||
processMessage func(*nats.Msg)
|
||||
}
|
||||
|
||||
func newAsyncSubscriberNats(logger Logger, key string, client NatsClient) (*asyncSubscriberNats, error) {
|
||||
func newAsyncSubscriberNats(logger log.Logger, key string, client NatsClient) (*asyncSubscriberNats, error) {
|
||||
receiver := make(chan *nats.Msg, 64)
|
||||
sub, err := client.Subscribe(key, receiver)
|
||||
if err != nil {
|
||||
|
|
@ -117,7 +119,7 @@ type asyncBackendRoomSubscriberNats struct {
|
|||
asyncBackendRoomSubscriber
|
||||
}
|
||||
|
||||
func newAsyncBackendRoomSubscriberNats(logger Logger, key string, client NatsClient) (*asyncBackendRoomSubscriberNats, error) {
|
||||
func newAsyncBackendRoomSubscriberNats(logger log.Logger, key string, client NatsClient) (*asyncBackendRoomSubscriberNats, error) {
|
||||
sub, err := newAsyncSubscriberNats(logger, key, client)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -146,7 +148,7 @@ type asyncRoomSubscriberNats struct {
|
|||
*asyncSubscriberNats
|
||||
}
|
||||
|
||||
func newAsyncRoomSubscriberNats(logger Logger, key string, client NatsClient) (*asyncRoomSubscriberNats, error) {
|
||||
func newAsyncRoomSubscriberNats(logger log.Logger, key string, client NatsClient) (*asyncRoomSubscriberNats, error) {
|
||||
sub, err := newAsyncSubscriberNats(logger, key, client)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -175,7 +177,7 @@ type asyncUserSubscriberNats struct {
|
|||
asyncUserSubscriber
|
||||
}
|
||||
|
||||
func newAsyncUserSubscriberNats(logger Logger, key string, client NatsClient) (*asyncUserSubscriberNats, error) {
|
||||
func newAsyncUserSubscriberNats(logger log.Logger, key string, client NatsClient) (*asyncUserSubscriberNats, error) {
|
||||
sub, err := newAsyncSubscriberNats(logger, key, client)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -204,7 +206,7 @@ type asyncSessionSubscriberNats struct {
|
|||
asyncSessionSubscriber
|
||||
}
|
||||
|
||||
func newAsyncSessionSubscriberNats(logger Logger, key string, client NatsClient) (*asyncSessionSubscriberNats, error) {
|
||||
func newAsyncSessionSubscriberNats(logger log.Logger, key string, client NatsClient) (*asyncSessionSubscriberNats, error) {
|
||||
sub, err := newAsyncSubscriberNats(logger, key, client)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -231,7 +233,7 @@ func (s *asyncSessionSubscriberNats) doProcessMessage(msg *nats.Msg) {
|
|||
type asyncEventsNats struct {
|
||||
mu sync.Mutex
|
||||
client NatsClient
|
||||
logger Logger // +checklocksignore
|
||||
logger log.Logger // +checklocksignore
|
||||
|
||||
// +checklocks:mu
|
||||
backendRoomSubscriptions map[string]*asyncBackendRoomSubscriberNats
|
||||
|
|
@ -243,7 +245,7 @@ type asyncEventsNats struct {
|
|||
sessionSubscriptions map[string]*asyncSessionSubscriberNats
|
||||
}
|
||||
|
||||
func NewAsyncEventsNats(logger Logger, client NatsClient) (AsyncEvents, error) {
|
||||
func NewAsyncEventsNats(logger log.Logger, client NatsClient) (AsyncEvents, error) {
|
||||
events := &asyncEventsNats{
|
||||
client: client,
|
||||
logger: logger,
|
||||
|
|
|
|||
|
|
@ -29,6 +29,8 @@ import (
|
|||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
@ -54,8 +56,8 @@ func getAsyncEventsForTest(t *testing.T) AsyncEvents {
|
|||
}
|
||||
|
||||
func getRealAsyncEventsForTest(t *testing.T) AsyncEvents {
|
||||
logger := NewLoggerForTest(t)
|
||||
ctx := NewLoggerContext(t.Context(), logger)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
ctx := log.NewLoggerContext(t.Context(), logger)
|
||||
server, _ := startLocalNatsServer(t)
|
||||
events, err := NewAsyncEvents(ctx, server.ClientURL())
|
||||
if err != nil {
|
||||
|
|
@ -65,8 +67,8 @@ func getRealAsyncEventsForTest(t *testing.T) AsyncEvents {
|
|||
}
|
||||
|
||||
func getLoopbackAsyncEventsForTest(t *testing.T) AsyncEvents {
|
||||
logger := NewLoggerForTest(t)
|
||||
ctx := NewLoggerContext(t.Context(), logger)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
ctx := log.NewLoggerContext(t.Context(), logger)
|
||||
events, err := NewAsyncEvents(ctx, NatsLoopbackUrl)
|
||||
if err != nil {
|
||||
require.NoError(t, err)
|
||||
|
|
|
|||
|
|
@ -32,6 +32,8 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/dlintw/goconf"
|
||||
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
@ -57,7 +59,7 @@ type BackendClient struct {
|
|||
}
|
||||
|
||||
func NewBackendClient(ctx context.Context, config *goconf.ConfigFile, maxConcurrentRequestsPerHost int, version string, etcdClient *EtcdClient) (*BackendClient, error) {
|
||||
logger := LoggerFromContext(ctx)
|
||||
logger := log.LoggerFromContext(ctx)
|
||||
backends, err := NewBackendConfiguration(logger, config, etcdClient)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -118,7 +120,7 @@ func isOcsRequest(u *url.URL) bool {
|
|||
// PerformJSONRequest sends a JSON POST request to the given url and decodes
|
||||
// the result into "response".
|
||||
func (b *BackendClient) PerformJSONRequest(ctx context.Context, u *url.URL, request any, response any) error {
|
||||
logger := LoggerFromContext(ctx)
|
||||
logger := log.LoggerFromContext(ctx)
|
||||
if u == nil {
|
||||
return fmt.Errorf("no url passed to perform JSON request %+v", request)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,6 +34,8 @@ import (
|
|||
"github.com/gorilla/mux"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
func returnOCS(t *testing.T, w http.ResponseWriter, body []byte) {
|
||||
|
|
@ -66,8 +68,8 @@ func returnOCS(t *testing.T, w http.ResponseWriter, body []byte) {
|
|||
|
||||
func TestPostOnRedirect(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
ctx := NewLoggerContext(t.Context(), logger)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
ctx := log.NewLoggerContext(t.Context(), logger)
|
||||
require := require.New(t)
|
||||
r := mux.NewRouter()
|
||||
r.HandleFunc("/ocs/v2.php/one", func(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
@ -114,8 +116,8 @@ func TestPostOnRedirect(t *testing.T) {
|
|||
|
||||
func TestPostOnRedirectDifferentHost(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
ctx := NewLoggerContext(t.Context(), logger)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
ctx := log.NewLoggerContext(t.Context(), logger)
|
||||
require := require.New(t)
|
||||
r := mux.NewRouter()
|
||||
r.HandleFunc("/ocs/v2.php/one", func(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
@ -151,8 +153,8 @@ func TestPostOnRedirectDifferentHost(t *testing.T) {
|
|||
|
||||
func TestPostOnRedirectStatusFound(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
ctx := NewLoggerContext(t.Context(), logger)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
ctx := log.NewLoggerContext(t.Context(), logger)
|
||||
require := require.New(t)
|
||||
assert := assert.New(t)
|
||||
r := mux.NewRouter()
|
||||
|
|
@ -194,8 +196,8 @@ func TestPostOnRedirectStatusFound(t *testing.T) {
|
|||
|
||||
func TestHandleThrottled(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
ctx := NewLoggerContext(t.Context(), logger)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
ctx := log.NewLoggerContext(t.Context(), logger)
|
||||
require := require.New(t)
|
||||
assert := assert.New(t)
|
||||
r := mux.NewRouter()
|
||||
|
|
|
|||
|
|
@ -30,8 +30,10 @@ import (
|
|||
"sync"
|
||||
|
||||
"github.com/dlintw/goconf"
|
||||
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/api"
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/internal"
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -255,11 +257,11 @@ var (
|
|||
defaultBackendStats = &prometheusBackendStats{}
|
||||
)
|
||||
|
||||
func NewBackendConfiguration(logger Logger, config *goconf.ConfigFile, etcdClient *EtcdClient) (*BackendConfiguration, error) {
|
||||
func NewBackendConfiguration(logger log.Logger, config *goconf.ConfigFile, etcdClient *EtcdClient) (*BackendConfiguration, error) {
|
||||
return NewBackendConfigurationWithStats(logger, config, etcdClient, nil)
|
||||
}
|
||||
|
||||
func NewBackendConfigurationWithStats(logger Logger, config *goconf.ConfigFile, etcdClient *EtcdClient, stats BackendStorageStats) (*BackendConfiguration, error) {
|
||||
func NewBackendConfigurationWithStats(logger log.Logger, config *goconf.ConfigFile, etcdClient *EtcdClient, stats BackendStorageStats) (*BackendConfiguration, error) {
|
||||
backendType, _ := config.GetString("backend", "backendtype")
|
||||
if backendType == "" {
|
||||
backendType = DefaultBackendType
|
||||
|
|
|
|||
|
|
@ -32,6 +32,8 @@ import (
|
|||
"github.com/dlintw/goconf"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
func testUrls(t *testing.T, config *BackendConfiguration, valid_urls []string, invalid_urls []string) {
|
||||
|
|
@ -106,7 +108,7 @@ func (s *mockBackendStats) DecBackends() {
|
|||
|
||||
func TestIsUrlAllowed_Compat(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
// Old-style configuration
|
||||
valid_urls := []string{
|
||||
"http://domain.invalid",
|
||||
|
|
@ -128,7 +130,7 @@ func TestIsUrlAllowed_Compat(t *testing.T) {
|
|||
|
||||
func TestIsUrlAllowed_CompatForceHttps(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
// Old-style configuration, force HTTPS
|
||||
valid_urls := []string{
|
||||
"https://domain.invalid",
|
||||
|
|
@ -149,7 +151,7 @@ func TestIsUrlAllowed_CompatForceHttps(t *testing.T) {
|
|||
|
||||
func TestIsUrlAllowed(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
valid_urls := [][]string{
|
||||
{"https://domain.invalid/foo", string(testBackendSecret) + "-foo"},
|
||||
{"https://domain.invalid/foo/", string(testBackendSecret) + "-foo"},
|
||||
|
|
@ -194,7 +196,7 @@ func TestIsUrlAllowed(t *testing.T) {
|
|||
|
||||
func TestIsUrlAllowed_EmptyAllowlist(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
valid_urls := []string{}
|
||||
invalid_urls := []string{
|
||||
"http://domain.invalid",
|
||||
|
|
@ -211,7 +213,7 @@ func TestIsUrlAllowed_EmptyAllowlist(t *testing.T) {
|
|||
|
||||
func TestIsUrlAllowed_AllowAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
valid_urls := []string{
|
||||
"http://domain.invalid",
|
||||
"https://domain.invalid",
|
||||
|
|
@ -257,7 +259,7 @@ func TestBackendReloadNoChange(t *testing.T) {
|
|||
t.Parallel()
|
||||
stats := &mockBackendStats{}
|
||||
|
||||
logger := NewLoggerForTest(t)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
require := require.New(t)
|
||||
assert := assert.New(t)
|
||||
original_config := goconf.NewConfigFile()
|
||||
|
|
@ -293,7 +295,7 @@ func TestBackendReloadChangeExistingURL(t *testing.T) {
|
|||
t.Parallel()
|
||||
stats := &mockBackendStats{}
|
||||
|
||||
logger := NewLoggerForTest(t)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
require := require.New(t)
|
||||
assert := assert.New(t)
|
||||
original_config := goconf.NewConfigFile()
|
||||
|
|
@ -334,7 +336,7 @@ func TestBackendReloadChangeSecret(t *testing.T) {
|
|||
t.Parallel()
|
||||
stats := &mockBackendStats{}
|
||||
|
||||
logger := NewLoggerForTest(t)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
require := require.New(t)
|
||||
assert := assert.New(t)
|
||||
original_config := goconf.NewConfigFile()
|
||||
|
|
@ -371,7 +373,7 @@ func TestBackendReloadAddBackend(t *testing.T) {
|
|||
t.Parallel()
|
||||
stats := &mockBackendStats{}
|
||||
|
||||
logger := NewLoggerForTest(t)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
require := require.New(t)
|
||||
assert := assert.New(t)
|
||||
original_config := goconf.NewConfigFile()
|
||||
|
|
@ -412,7 +414,7 @@ func TestBackendReloadRemoveHost(t *testing.T) {
|
|||
t.Parallel()
|
||||
stats := &mockBackendStats{}
|
||||
|
||||
logger := NewLoggerForTest(t)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
require := require.New(t)
|
||||
assert := assert.New(t)
|
||||
original_config := goconf.NewConfigFile()
|
||||
|
|
@ -450,7 +452,7 @@ func TestBackendReloadRemoveBackendFromSharedHost(t *testing.T) {
|
|||
t.Parallel()
|
||||
stats := &mockBackendStats{}
|
||||
|
||||
logger := NewLoggerForTest(t)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
require := require.New(t)
|
||||
assert := assert.New(t)
|
||||
original_config := goconf.NewConfigFile()
|
||||
|
|
@ -504,7 +506,7 @@ func TestBackendConfiguration_EtcdCompat(t *testing.T) {
|
|||
t.Parallel()
|
||||
stats := &mockBackendStats{}
|
||||
|
||||
logger := NewLoggerForTest(t)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
require := require.New(t)
|
||||
assert := assert.New(t)
|
||||
etcd, client := NewEtcdClientForTest(t)
|
||||
|
|
@ -621,7 +623,7 @@ func TestBackendConfiguration_EtcdCompat(t *testing.T) {
|
|||
|
||||
func TestBackendCommonSecret(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
require := require.New(t)
|
||||
assert := assert.New(t)
|
||||
u1, err := url.Parse("http://domain1.invalid")
|
||||
|
|
@ -664,7 +666,7 @@ func TestBackendChangeUrls(t *testing.T) {
|
|||
t.Parallel()
|
||||
stats := &mockBackendStats{}
|
||||
|
||||
logger := NewLoggerForTest(t)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
require := require.New(t)
|
||||
assert := assert.New(t)
|
||||
u1, err := url.Parse("http://domain1.invalid/")
|
||||
|
|
@ -754,7 +756,7 @@ func TestBackendConfiguration_EtcdChangeUrls(t *testing.T) {
|
|||
t.Parallel()
|
||||
stats := &mockBackendStats{}
|
||||
|
||||
logger := NewLoggerForTest(t)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
require := require.New(t)
|
||||
assert := assert.New(t)
|
||||
etcd, client := NewEtcdClientForTest(t)
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ import (
|
|||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/api"
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -62,7 +63,7 @@ const (
|
|||
)
|
||||
|
||||
type BackendServer struct {
|
||||
logger Logger
|
||||
logger log.Logger
|
||||
hub *Hub
|
||||
events AsyncEvents
|
||||
roomSessions RoomSessions
|
||||
|
|
@ -83,7 +84,7 @@ type BackendServer struct {
|
|||
}
|
||||
|
||||
func NewBackendServer(ctx context.Context, config *goconf.ConfigFile, hub *Hub, version string) (*BackendServer, error) {
|
||||
logger := LoggerFromContext(ctx)
|
||||
logger := log.LoggerFromContext(ctx)
|
||||
turnapikey, _ := GetStringOptionWithEnv(config, "turn", "apikey")
|
||||
turnsecret, _ := GetStringOptionWithEnv(config, "turn", "secret")
|
||||
turnservers, _ := config.GetString("turn", "servers")
|
||||
|
|
@ -316,7 +317,7 @@ func (b *BackendServer) parseRequestBody(f func(context.Context, http.ResponseWr
|
|||
}
|
||||
defer b.buffers.Put(body)
|
||||
|
||||
ctx := NewLoggerContext(r.Context(), b.logger)
|
||||
ctx := log.NewLoggerContext(r.Context(), b.logger)
|
||||
f(ctx, w, r, body.Bytes())
|
||||
}
|
||||
}
|
||||
|
|
@ -367,7 +368,7 @@ func (b *BackendServer) sendRoomDisinvite(roomid string, backend *Backend, reaso
|
|||
}
|
||||
|
||||
timeout := time.Second
|
||||
ctx := NewLoggerContext(context.Background(), b.logger)
|
||||
ctx := log.NewLoggerContext(context.Background(), b.logger)
|
||||
ctx, cancel := context.WithTimeout(ctx, timeout)
|
||||
defer cancel()
|
||||
var wg sync.WaitGroup
|
||||
|
|
@ -497,7 +498,7 @@ func (b *BackendServer) sendRoomIncall(roomid string, backend *Backend, request
|
|||
if !request.InCall.All {
|
||||
timeout := time.Second
|
||||
|
||||
ctx := NewLoggerContext(context.Background(), b.logger)
|
||||
ctx := log.NewLoggerContext(context.Background(), b.logger)
|
||||
ctx, cancel := context.WithTimeout(ctx, timeout)
|
||||
defer cancel()
|
||||
var cache ConcurrentMap[RoomSessionId, PublicSessionId]
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/api"
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
@ -99,8 +100,8 @@ func CreateBackendServerForTestFromConfig(t *testing.T, config *goconf.ConfigFil
|
|||
config.AddOption("clients", "internalsecret", string(testInternalSecret))
|
||||
config.AddOption("geoip", "url", "none")
|
||||
events := getAsyncEventsForTest(t)
|
||||
logger := NewLoggerForTest(t)
|
||||
ctx := NewLoggerContext(t.Context(), logger)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
ctx := log.NewLoggerContext(t.Context(), logger)
|
||||
hub, err := NewHub(ctx, config, events, nil, nil, nil, r, "no-version")
|
||||
require.NoError(err)
|
||||
b, err := NewBackendServer(ctx, config, hub, "no-version")
|
||||
|
|
@ -161,8 +162,8 @@ func CreateBackendServerWithClusteringForTestFromConfig(t *testing.T, config1 *g
|
|||
config1.AddOption("clients", "internalsecret", string(testInternalSecret))
|
||||
config1.AddOption("geoip", "url", "none")
|
||||
|
||||
logger := NewLoggerForTest(t)
|
||||
ctx := NewLoggerContext(t.Context(), logger)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
ctx := log.NewLoggerContext(t.Context(), logger)
|
||||
|
||||
events1, err := NewAsyncEvents(ctx, nats.ClientURL())
|
||||
require.NoError(err)
|
||||
|
|
@ -394,8 +395,8 @@ func TestBackendServer_RoomInvite(t *testing.T) {
|
|||
for _, backend := range eventBackendsForTest {
|
||||
t.Run(backend, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
ctx := NewLoggerContext(t.Context(), logger)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
ctx := log.NewLoggerContext(t.Context(), logger)
|
||||
RunTestBackendServer_RoomInvite(ctx, t)
|
||||
})
|
||||
}
|
||||
|
|
@ -462,8 +463,8 @@ func TestBackendServer_RoomDisinvite(t *testing.T) {
|
|||
for _, backend := range eventBackendsForTest {
|
||||
t.Run(backend, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
ctx := NewLoggerContext(t.Context(), logger)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
ctx := log.NewLoggerContext(t.Context(), logger)
|
||||
RunTestBackendServer_RoomDisinvite(ctx, t)
|
||||
})
|
||||
}
|
||||
|
|
@ -541,8 +542,8 @@ func RunTestBackendServer_RoomDisinvite(ctx context.Context, t *testing.T) {
|
|||
|
||||
func TestBackendServer_RoomDisinviteDifferentRooms(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
ctx := NewLoggerContext(t.Context(), logger)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
ctx := log.NewLoggerContext(t.Context(), logger)
|
||||
require := require.New(t)
|
||||
assert := assert.New(t)
|
||||
_, _, _, hub, _, server := CreateBackendServerForTest(t)
|
||||
|
|
@ -624,8 +625,8 @@ func TestBackendServer_RoomUpdate(t *testing.T) {
|
|||
for _, backend := range eventBackendsForTest {
|
||||
t.Run(backend, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
ctx := NewLoggerContext(t.Context(), logger)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
ctx := log.NewLoggerContext(t.Context(), logger)
|
||||
RunTestBackendServer_RoomUpdate(ctx, t)
|
||||
})
|
||||
}
|
||||
|
|
@ -694,8 +695,8 @@ func TestBackendServer_RoomDelete(t *testing.T) {
|
|||
for _, backend := range eventBackendsForTest {
|
||||
t.Run(backend, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
ctx := NewLoggerContext(t.Context(), logger)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
ctx := log.NewLoggerContext(t.Context(), logger)
|
||||
RunTestBackendServer_RoomDelete(ctx, t)
|
||||
})
|
||||
}
|
||||
|
|
@ -761,8 +762,8 @@ func TestBackendServer_ParticipantsUpdatePermissions(t *testing.T) {
|
|||
for _, subtest := range clusteredTests {
|
||||
t.Run(subtest, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
ctx := NewLoggerContext(t.Context(), logger)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
ctx := log.NewLoggerContext(t.Context(), logger)
|
||||
require := require.New(t)
|
||||
assert := assert.New(t)
|
||||
var hub1 *Hub
|
||||
|
|
@ -858,8 +859,8 @@ func TestBackendServer_ParticipantsUpdatePermissions(t *testing.T) {
|
|||
|
||||
func TestBackendServer_ParticipantsUpdateEmptyPermissions(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
ctx := NewLoggerContext(t.Context(), logger)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
ctx := log.NewLoggerContext(t.Context(), logger)
|
||||
require := require.New(t)
|
||||
assert := assert.New(t)
|
||||
_, _, _, hub, _, server := CreateBackendServerForTest(t)
|
||||
|
|
@ -923,8 +924,8 @@ func TestBackendServer_ParticipantsUpdateEmptyPermissions(t *testing.T) {
|
|||
|
||||
func TestBackendServer_ParticipantsUpdateTimeout(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
ctx := NewLoggerContext(t.Context(), logger)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
ctx := log.NewLoggerContext(t.Context(), logger)
|
||||
require := require.New(t)
|
||||
assert := assert.New(t)
|
||||
_, _, _, hub, _, server := CreateBackendServerForTest(t)
|
||||
|
|
@ -1086,8 +1087,8 @@ func TestBackendServer_InCallAll(t *testing.T) {
|
|||
for _, subtest := range clusteredTests {
|
||||
t.Run(subtest, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
ctx := NewLoggerContext(t.Context(), logger)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
ctx := log.NewLoggerContext(t.Context(), logger)
|
||||
require := require.New(t)
|
||||
assert := assert.New(t)
|
||||
var hub1 *Hub
|
||||
|
|
@ -1258,8 +1259,8 @@ func TestBackendServer_InCallAll(t *testing.T) {
|
|||
|
||||
func TestBackendServer_RoomMessage(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
ctx := NewLoggerContext(t.Context(), logger)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
ctx := log.NewLoggerContext(t.Context(), logger)
|
||||
require := require.New(t)
|
||||
assert := assert.New(t)
|
||||
_, _, _, hub, _, server := CreateBackendServerForTest(t)
|
||||
|
|
@ -1428,8 +1429,8 @@ func Test_IsNumeric(t *testing.T) {
|
|||
|
||||
func TestBackendServer_DialoutNoSipBridge(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
ctx := NewLoggerContext(t.Context(), logger)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
ctx := log.NewLoggerContext(t.Context(), logger)
|
||||
require := require.New(t)
|
||||
assert := assert.New(t)
|
||||
_, _, _, hub, _, server := CreateBackendServerForTest(t)
|
||||
|
|
@ -1472,8 +1473,8 @@ func TestBackendServer_DialoutNoSipBridge(t *testing.T) {
|
|||
|
||||
func TestBackendServer_DialoutAccepted(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
ctx := NewLoggerContext(t.Context(), logger)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
ctx := log.NewLoggerContext(t.Context(), logger)
|
||||
require := require.New(t)
|
||||
assert := assert.New(t)
|
||||
_, _, _, hub, _, server := CreateBackendServerForTest(t)
|
||||
|
|
@ -1559,8 +1560,8 @@ func TestBackendServer_DialoutAccepted(t *testing.T) {
|
|||
|
||||
func TestBackendServer_DialoutAcceptedCompat(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
ctx := NewLoggerContext(t.Context(), logger)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
ctx := log.NewLoggerContext(t.Context(), logger)
|
||||
require := require.New(t)
|
||||
assert := assert.New(t)
|
||||
_, _, _, hub, _, server := CreateBackendServerForTest(t)
|
||||
|
|
@ -1646,8 +1647,8 @@ func TestBackendServer_DialoutAcceptedCompat(t *testing.T) {
|
|||
|
||||
func TestBackendServer_DialoutRejected(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
ctx := NewLoggerContext(t.Context(), logger)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
ctx := log.NewLoggerContext(t.Context(), logger)
|
||||
require := require.New(t)
|
||||
assert := assert.New(t)
|
||||
_, _, _, hub, _, server := CreateBackendServerForTest(t)
|
||||
|
|
@ -1731,8 +1732,8 @@ func TestBackendServer_DialoutRejected(t *testing.T) {
|
|||
|
||||
func TestBackendServer_DialoutFirstFailed(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
ctx := NewLoggerContext(t.Context(), logger)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
ctx := log.NewLoggerContext(t.Context(), logger)
|
||||
require := require.New(t)
|
||||
assert := assert.New(t)
|
||||
_, _, _, hub, _, server := CreateBackendServerForTest(t)
|
||||
|
|
|
|||
|
|
@ -31,12 +31,14 @@ import (
|
|||
|
||||
"github.com/dlintw/goconf"
|
||||
clientv3 "go.etcd.io/etcd/client/v3"
|
||||
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
type backendStorageEtcd struct {
|
||||
backendStorageCommon
|
||||
|
||||
logger Logger
|
||||
logger log.Logger
|
||||
etcdClient *EtcdClient
|
||||
keyPrefix string
|
||||
keyInfos map[string]*BackendInformationEtcd
|
||||
|
|
@ -49,7 +51,7 @@ type backendStorageEtcd struct {
|
|||
closeFunc context.CancelFunc
|
||||
}
|
||||
|
||||
func NewBackendStorageEtcd(logger Logger, config *goconf.ConfigFile, etcdClient *EtcdClient, stats BackendStorageStats) (BackendStorage, error) {
|
||||
func NewBackendStorageEtcd(logger log.Logger, config *goconf.ConfigFile, etcdClient *EtcdClient, stats BackendStorageStats) (BackendStorage, error) {
|
||||
if etcdClient == nil || !etcdClient.IsConfigured() {
|
||||
return nil, errors.New("no etcd endpoints configured")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,6 +27,8 @@ import (
|
|||
"github.com/dlintw/goconf"
|
||||
"github.com/stretchr/testify/require"
|
||||
"go.etcd.io/etcd/server/v3/embed"
|
||||
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
func (s *backendStorageEtcd) getWakeupChannelForTesting() <-chan struct{} {
|
||||
|
|
@ -53,7 +55,7 @@ func (tl *testListener) EtcdClientCreated(client *EtcdClient) {
|
|||
}
|
||||
|
||||
func Test_BackendStorageEtcdNoLeak(t *testing.T) { // nolint:paralleltest
|
||||
logger := NewLoggerForTest(t)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
ensureNoGoroutinesLeak(t, func(t *testing.T) {
|
||||
etcd, client := NewEtcdClientForTest(t)
|
||||
tl := &testListener{
|
||||
|
|
|
|||
|
|
@ -27,14 +27,16 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/dlintw/goconf"
|
||||
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/api"
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/internal"
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
type backendStorageStatic struct {
|
||||
backendStorageCommon
|
||||
|
||||
logger Logger
|
||||
logger log.Logger
|
||||
backendsById map[string]*Backend
|
||||
|
||||
// Deprecated
|
||||
|
|
@ -43,7 +45,7 @@ type backendStorageStatic struct {
|
|||
compatBackend *Backend
|
||||
}
|
||||
|
||||
func NewBackendStorageStatic(logger Logger, config *goconf.ConfigFile, stats BackendStorageStats) (BackendStorage, error) {
|
||||
func NewBackendStorageStatic(logger log.Logger, config *goconf.ConfigFile, stats BackendStorageStats) (BackendStorage, error) {
|
||||
allowAll, _ := config.GetBool("backend", "allowall")
|
||||
allowHttp, _ := config.GetBool("backend", "allowhttp")
|
||||
commonSecret, _ := GetStringOptionWithEnv(config, "backend", "secret")
|
||||
|
|
@ -295,7 +297,7 @@ func getConfiguredBackendIDs(backendIds string) (ids []string) {
|
|||
return ids
|
||||
}
|
||||
|
||||
func getConfiguredHosts(logger Logger, backendIds string, config *goconf.ConfigFile, commonSecret string) (hosts map[string][]*Backend) {
|
||||
func getConfiguredHosts(logger log.Logger, backendIds string, config *goconf.ConfigFile, commonSecret string) (hosts map[string][]*Backend) {
|
||||
hosts = make(map[string][]*Backend)
|
||||
seenUrls := make(map[string]string)
|
||||
for _, id := range getConfiguredBackendIDs(backendIds) {
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ import (
|
|||
"github.com/pquerna/cachecontrol/cacheobject"
|
||||
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/api"
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -117,7 +118,7 @@ func (e *capabilitiesEntry) errorIfMustRevalidate(err error) (bool, error) {
|
|||
}
|
||||
|
||||
func (e *capabilitiesEntry) update(ctx context.Context, u *url.URL, now time.Time) (bool, error) {
|
||||
logger := LoggerFromContext(ctx)
|
||||
logger := log.LoggerFromContext(ctx)
|
||||
e.mu.Lock()
|
||||
defer e.mu.Unlock()
|
||||
|
||||
|
|
@ -351,7 +352,7 @@ func (c *Capabilities) loadCapabilities(ctx context.Context, u *url.URL) (api.St
|
|||
}
|
||||
|
||||
func (c *Capabilities) HasCapabilityFeature(ctx context.Context, u *url.URL, feature string) bool {
|
||||
logger := LoggerFromContext(ctx)
|
||||
logger := log.LoggerFromContext(ctx)
|
||||
caps, _, err := c.loadCapabilities(ctx, u)
|
||||
if err != nil {
|
||||
logger.Printf("Could not get capabilities for %s: %s", u, err)
|
||||
|
|
@ -378,7 +379,7 @@ func (c *Capabilities) HasCapabilityFeature(ctx context.Context, u *url.URL, fea
|
|||
}
|
||||
|
||||
func (c *Capabilities) getConfigGroup(ctx context.Context, u *url.URL, group string) (api.StringMap, bool, bool) {
|
||||
logger := LoggerFromContext(ctx)
|
||||
logger := log.LoggerFromContext(ctx)
|
||||
caps, cached, err := c.loadCapabilities(ctx, u)
|
||||
if err != nil {
|
||||
logger.Printf("Could not get capabilities for %s: %s", u, err)
|
||||
|
|
@ -429,7 +430,7 @@ func (c *Capabilities) GetIntegerConfig(ctx context.Context, u *url.URL, group,
|
|||
case float64:
|
||||
return int(value), cached, true
|
||||
default:
|
||||
logger := LoggerFromContext(ctx)
|
||||
logger := log.LoggerFromContext(ctx)
|
||||
logger.Printf("Invalid config value for \"%s\" received from %s: %+v", key, u, value)
|
||||
}
|
||||
|
||||
|
|
@ -451,7 +452,7 @@ func (c *Capabilities) GetStringConfig(ctx context.Context, u *url.URL, group, k
|
|||
case string:
|
||||
return value, cached, true
|
||||
default:
|
||||
logger := LoggerFromContext(ctx)
|
||||
logger := log.LoggerFromContext(ctx)
|
||||
logger.Printf("Invalid config value for \"%s\" received from %s: %+v", key, u, value)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/api"
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
func NewCapabilitiesForTestWithCallback(t *testing.T, callback func(*CapabilitiesResponse, http.ResponseWriter) error) (*url.URL, *Capabilities) {
|
||||
|
|
@ -176,8 +177,8 @@ func SetCapabilitiesGetNow(t *testing.T, capabilities *Capabilities, f func() ti
|
|||
|
||||
func TestCapabilities(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
ctx := NewLoggerContext(t.Context(), logger)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
ctx := log.NewLoggerContext(t.Context(), logger)
|
||||
assert := assert.New(t)
|
||||
url, capabilities := NewCapabilitiesForTest(t)
|
||||
|
||||
|
|
@ -220,8 +221,8 @@ func TestCapabilities(t *testing.T) {
|
|||
|
||||
func TestInvalidateCapabilities(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
ctx := NewLoggerContext(t.Context(), logger)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
ctx := log.NewLoggerContext(t.Context(), logger)
|
||||
assert := assert.New(t)
|
||||
var called atomic.Uint32
|
||||
url, capabilities := NewCapabilitiesForTestWithCallback(t, func(cr *CapabilitiesResponse, w http.ResponseWriter) error {
|
||||
|
|
@ -281,8 +282,8 @@ func TestInvalidateCapabilities(t *testing.T) {
|
|||
|
||||
func TestCapabilitiesNoCache(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
ctx := NewLoggerContext(t.Context(), logger)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
ctx := log.NewLoggerContext(t.Context(), logger)
|
||||
assert := assert.New(t)
|
||||
var called atomic.Uint32
|
||||
url, capabilities := NewCapabilitiesForTestWithCallback(t, func(cr *CapabilitiesResponse, w http.ResponseWriter) error {
|
||||
|
|
@ -326,8 +327,8 @@ func TestCapabilitiesNoCache(t *testing.T) {
|
|||
|
||||
func TestCapabilitiesShortCache(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
ctx := NewLoggerContext(t.Context(), logger)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
ctx := log.NewLoggerContext(t.Context(), logger)
|
||||
assert := assert.New(t)
|
||||
var called atomic.Uint32
|
||||
url, capabilities := NewCapabilitiesForTestWithCallback(t, func(cr *CapabilitiesResponse, w http.ResponseWriter) error {
|
||||
|
|
@ -381,8 +382,8 @@ func TestCapabilitiesShortCache(t *testing.T) {
|
|||
|
||||
func TestCapabilitiesNoCacheETag(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
ctx := NewLoggerContext(t.Context(), logger)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
ctx := log.NewLoggerContext(t.Context(), logger)
|
||||
assert := assert.New(t)
|
||||
var called atomic.Uint32
|
||||
url, capabilities := NewCapabilitiesForTestWithCallback(t, func(cr *CapabilitiesResponse, w http.ResponseWriter) error {
|
||||
|
|
@ -423,8 +424,8 @@ func TestCapabilitiesNoCacheETag(t *testing.T) {
|
|||
|
||||
func TestCapabilitiesCacheNoMustRevalidate(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
ctx := NewLoggerContext(t.Context(), logger)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
ctx := log.NewLoggerContext(t.Context(), logger)
|
||||
assert := assert.New(t)
|
||||
var called atomic.Uint32
|
||||
url, capabilities := NewCapabilitiesForTestWithCallback(t, func(cr *CapabilitiesResponse, w http.ResponseWriter) error {
|
||||
|
|
@ -464,8 +465,8 @@ func TestCapabilitiesCacheNoMustRevalidate(t *testing.T) {
|
|||
|
||||
func TestCapabilitiesNoCacheNoMustRevalidate(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
ctx := NewLoggerContext(t.Context(), logger)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
ctx := log.NewLoggerContext(t.Context(), logger)
|
||||
assert := assert.New(t)
|
||||
var called atomic.Uint32
|
||||
url, capabilities := NewCapabilitiesForTestWithCallback(t, func(cr *CapabilitiesResponse, w http.ResponseWriter) error {
|
||||
|
|
@ -505,8 +506,8 @@ func TestCapabilitiesNoCacheNoMustRevalidate(t *testing.T) {
|
|||
|
||||
func TestCapabilitiesNoCacheMustRevalidate(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
ctx := NewLoggerContext(t.Context(), logger)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
ctx := log.NewLoggerContext(t.Context(), logger)
|
||||
assert := assert.New(t)
|
||||
var called atomic.Uint32
|
||||
url, capabilities := NewCapabilitiesForTestWithCallback(t, func(cr *CapabilitiesResponse, w http.ResponseWriter) error {
|
||||
|
|
@ -544,8 +545,8 @@ func TestCapabilitiesNoCacheMustRevalidate(t *testing.T) {
|
|||
|
||||
func TestConcurrentExpired(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
ctx := NewLoggerContext(t.Context(), logger)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
ctx := log.NewLoggerContext(t.Context(), logger)
|
||||
assert := assert.New(t)
|
||||
var called atomic.Uint32
|
||||
url, capabilities := NewCapabilitiesForTestWithCallback(t, func(cr *CapabilitiesResponse, w http.ResponseWriter) error {
|
||||
|
|
|
|||
|
|
@ -28,10 +28,12 @@ import (
|
|||
"os"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
type CertificateReloader struct {
|
||||
logger Logger
|
||||
logger log.Logger
|
||||
|
||||
certFile string
|
||||
certWatcher *FileWatcher
|
||||
|
|
@ -44,7 +46,7 @@ type CertificateReloader struct {
|
|||
reloadCounter atomic.Uint64
|
||||
}
|
||||
|
||||
func NewCertificateReloader(logger Logger, certFile string, keyFile string) (*CertificateReloader, error) {
|
||||
func NewCertificateReloader(logger log.Logger, certFile string, keyFile string) (*CertificateReloader, error) {
|
||||
pair, err := tls.LoadX509KeyPair(certFile, keyFile)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not load certificate / key: %w", err)
|
||||
|
|
@ -108,7 +110,7 @@ func (r *CertificateReloader) GetReloadCounter() uint64 {
|
|||
}
|
||||
|
||||
type CertPoolReloader struct {
|
||||
logger Logger
|
||||
logger log.Logger
|
||||
|
||||
certFile string
|
||||
certWatcher *FileWatcher
|
||||
|
|
@ -132,7 +134,7 @@ func loadCertPool(filename string) (*x509.CertPool, error) {
|
|||
return pool, nil
|
||||
}
|
||||
|
||||
func NewCertPoolReloader(logger Logger, certFile string) (*CertPoolReloader, error) {
|
||||
func NewCertPoolReloader(logger log.Logger, certFile string) (*CertPoolReloader, error) {
|
||||
pool, err := loadCertPool(certFile)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
|||
|
|
@ -36,6 +36,8 @@ import (
|
|||
|
||||
"github.com/gorilla/websocket"
|
||||
"github.com/mailru/easyjson"
|
||||
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -121,7 +123,7 @@ type ClientGeoIpHandler interface {
|
|||
}
|
||||
|
||||
type Client struct {
|
||||
logger Logger
|
||||
logger log.Logger
|
||||
ctx context.Context
|
||||
conn *websocket.Conn
|
||||
addr string
|
||||
|
|
@ -164,7 +166,7 @@ func NewClient(ctx context.Context, conn *websocket.Conn, remoteAddress string,
|
|||
}
|
||||
|
||||
func (c *Client) SetConn(ctx context.Context, conn *websocket.Conn, remoteAddress string, handler ClientHandler) {
|
||||
c.logger = LoggerFromContext(ctx)
|
||||
c.logger = log.LoggerFromContext(ctx)
|
||||
c.ctx = ctx
|
||||
c.conn = conn
|
||||
c.addr = remoteAddress
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ import (
|
|||
"github.com/pion/sdp/v3"
|
||||
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/api"
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
@ -55,7 +56,7 @@ const (
|
|||
type ResponseHandlerFunc func(message *ClientMessage) bool
|
||||
|
||||
type ClientSession struct {
|
||||
logger Logger
|
||||
logger log.Logger
|
||||
hub *Hub
|
||||
events AsyncEvents
|
||||
privateId PrivateSessionId
|
||||
|
|
@ -120,7 +121,7 @@ type ClientSession struct {
|
|||
}
|
||||
|
||||
func NewClientSession(hub *Hub, privateId PrivateSessionId, publicId PublicSessionId, data *SessionIdData, backend *Backend, hello *HelloClientMessage, auth *BackendClientAuthResponse) (*ClientSession, error) {
|
||||
ctx := NewLoggerContext(context.Background(), hub.logger)
|
||||
ctx := log.NewLoggerContext(context.Background(), hub.logger)
|
||||
ctx, closeFunc := context.WithCancel(ctx)
|
||||
s := &ClientSession{
|
||||
logger: hub.logger,
|
||||
|
|
@ -551,7 +552,7 @@ func (s *ClientSession) doUnsubscribeRoomEvents(notify bool) {
|
|||
if notify && room != nil && s.roomSessionId != "" && !s.roomSessionId.IsFederated() {
|
||||
// Notify
|
||||
go func(sid RoomSessionId) {
|
||||
ctx := NewLoggerContext(context.Background(), s.logger)
|
||||
ctx := log.NewLoggerContext(context.Background(), s.logger)
|
||||
request := NewBackendClientRoomRequest(room.Id(), s.userId, sid)
|
||||
request.Room.UpdateFromSession(s)
|
||||
request.Room.Action = "leave"
|
||||
|
|
|
|||
|
|
@ -26,18 +26,20 @@ import (
|
|||
"runtime"
|
||||
"runtime/debug"
|
||||
"sync"
|
||||
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
// DeferredExecutor will asynchronously execute functions while maintaining
|
||||
// their order.
|
||||
type DeferredExecutor struct {
|
||||
logger Logger
|
||||
logger log.Logger
|
||||
queue chan func()
|
||||
closed chan struct{}
|
||||
closeOnce sync.Once
|
||||
}
|
||||
|
||||
func NewDeferredExecutor(logger Logger, queueSize int) *DeferredExecutor {
|
||||
func NewDeferredExecutor(logger log.Logger, queueSize int) *DeferredExecutor {
|
||||
if queueSize < 0 {
|
||||
queueSize = 0
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,11 +26,13 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
func TestDeferredExecutor_MultiClose(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
e := NewDeferredExecutor(logger, 0)
|
||||
defer e.waitForStop()
|
||||
|
||||
|
|
@ -41,7 +43,7 @@ func TestDeferredExecutor_MultiClose(t *testing.T) {
|
|||
func TestDeferredExecutor_QueueSize(t *testing.T) {
|
||||
t.Parallel()
|
||||
SynctestTest(t, func(t *testing.T) {
|
||||
logger := NewLoggerForTest(t)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
e := NewDeferredExecutor(logger, 0)
|
||||
defer e.waitForStop()
|
||||
defer e.Close()
|
||||
|
|
@ -64,7 +66,7 @@ func TestDeferredExecutor_QueueSize(t *testing.T) {
|
|||
|
||||
func TestDeferredExecutor_Order(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
e := NewDeferredExecutor(logger, 64)
|
||||
defer e.waitForStop()
|
||||
defer e.Close()
|
||||
|
|
@ -93,7 +95,7 @@ func TestDeferredExecutor_Order(t *testing.T) {
|
|||
|
||||
func TestDeferredExecutor_CloseFromFunc(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
e := NewDeferredExecutor(logger, 64)
|
||||
defer e.waitForStop()
|
||||
|
||||
|
|
@ -108,7 +110,7 @@ func TestDeferredExecutor_CloseFromFunc(t *testing.T) {
|
|||
|
||||
func TestDeferredExecutor_DeferAfterClose(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
e := NewDeferredExecutor(logger, 64)
|
||||
defer e.waitForStop()
|
||||
|
||||
|
|
@ -121,7 +123,7 @@ func TestDeferredExecutor_DeferAfterClose(t *testing.T) {
|
|||
|
||||
func TestDeferredExecutor_WaitForStopTwice(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
e := NewDeferredExecutor(logger, 64)
|
||||
defer e.waitForStop()
|
||||
|
||||
|
|
|
|||
|
|
@ -30,6 +30,8 @@ import (
|
|||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -156,7 +158,7 @@ func (e *dnsMonitorEntry) runCallbacks(all []net.IP, add []net.IP, keep []net.IP
|
|||
type DnsMonitorLookupFunc func(hostname string) ([]net.IP, error)
|
||||
|
||||
type DnsMonitor struct {
|
||||
logger Logger
|
||||
logger log.Logger
|
||||
interval time.Duration
|
||||
lookupFunc DnsMonitorLookupFunc
|
||||
|
||||
|
|
@ -175,7 +177,7 @@ type DnsMonitor struct {
|
|||
checkHostnames func()
|
||||
}
|
||||
|
||||
func NewDnsMonitor(logger Logger, interval time.Duration, lookupFunc DnsMonitorLookupFunc) (*DnsMonitor, error) {
|
||||
func NewDnsMonitor(logger log.Logger, interval time.Duration, lookupFunc DnsMonitorLookupFunc) (*DnsMonitor, error) {
|
||||
if interval < 0 {
|
||||
interval = defaultDnsMonitorInterval
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,6 +33,8 @@ import (
|
|||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
type mockDnsLookup struct {
|
||||
|
|
@ -84,7 +86,7 @@ func newDnsMonitorForTest(t *testing.T, interval time.Duration, lookup *mockDnsL
|
|||
t.Helper()
|
||||
require := require.New(t)
|
||||
|
||||
logger := NewLoggerForTest(t)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
var lookupFunc DnsMonitorLookupFunc
|
||||
if lookup != nil {
|
||||
lookupFunc = lookup.lookup
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ import (
|
|||
"google.golang.org/grpc/connectivity"
|
||||
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/internal"
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
type EtcdClientListener interface {
|
||||
|
|
@ -52,7 +53,7 @@ type EtcdClientWatcher interface {
|
|||
}
|
||||
|
||||
type EtcdClient struct {
|
||||
logger Logger
|
||||
logger log.Logger
|
||||
compatSection string
|
||||
|
||||
mu sync.Mutex
|
||||
|
|
@ -61,7 +62,7 @@ type EtcdClient struct {
|
|||
listeners map[EtcdClientListener]bool
|
||||
}
|
||||
|
||||
func NewEtcdClient(logger Logger, config *goconf.ConfigFile, compatSection string) (*EtcdClient, error) {
|
||||
func NewEtcdClient(logger log.Logger, config *goconf.ConfigFile, compatSection string) (*EtcdClient, error) {
|
||||
result := &EtcdClient{
|
||||
logger: logger,
|
||||
compatSection: compatSection,
|
||||
|
|
|
|||
|
|
@ -45,6 +45,8 @@ import (
|
|||
"go.etcd.io/etcd/server/v3/lease"
|
||||
"go.uber.org/zap"
|
||||
"go.uber.org/zap/zaptest"
|
||||
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
@ -154,7 +156,7 @@ func NewEtcdClientForTest(t *testing.T) (*embed.Etcd, *EtcdClient) {
|
|||
config.AddOption("etcd", "endpoints", etcd.Config().ListenClientUrls[0].String())
|
||||
config.AddOption("etcd", "loglevel", "error")
|
||||
|
||||
logger := NewLoggerForTest(t)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
client, err := NewEtcdClient(logger, config, "")
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
|
|
@ -173,7 +175,7 @@ func NewEtcdClientWithTLSForTest(t *testing.T) (*embed.Etcd, *EtcdClient) {
|
|||
config.AddOption("etcd", "clientcert", certfile)
|
||||
config.AddOption("etcd", "cacert", certfile)
|
||||
|
||||
logger := NewLoggerForTest(t)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
client, err := NewEtcdClient(logger, config, "")
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
|
|
@ -198,8 +200,8 @@ func DeleteEtcdValue(etcd *embed.Etcd, key string) {
|
|||
|
||||
func Test_EtcdClient_Get(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
ctx := NewLoggerContext(t.Context(), logger)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
ctx := log.NewLoggerContext(t.Context(), logger)
|
||||
assert := assert.New(t)
|
||||
require := require.New(t)
|
||||
etcd, client := NewEtcdClientForTest(t)
|
||||
|
|
@ -245,8 +247,8 @@ func Test_EtcdClient_Get(t *testing.T) {
|
|||
|
||||
func Test_EtcdClientTLS_Get(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
ctx := NewLoggerContext(t.Context(), logger)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
ctx := log.NewLoggerContext(t.Context(), logger)
|
||||
assert := assert.New(t)
|
||||
require := require.New(t)
|
||||
etcd, client := NewEtcdClientWithTLSForTest(t)
|
||||
|
|
@ -292,8 +294,8 @@ func Test_EtcdClientTLS_Get(t *testing.T) {
|
|||
|
||||
func Test_EtcdClient_GetPrefix(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
ctx := NewLoggerContext(t.Context(), logger)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
ctx := log.NewLoggerContext(t.Context(), logger)
|
||||
assert := assert.New(t)
|
||||
etcd, client := NewEtcdClientForTest(t)
|
||||
|
||||
|
|
@ -404,8 +406,8 @@ func (l *EtcdClientTestListener) EtcdKeyDeleted(client *EtcdClient, key string,
|
|||
|
||||
func Test_EtcdClient_Watch(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
ctx := NewLoggerContext(t.Context(), logger)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
ctx := log.NewLoggerContext(t.Context(), logger)
|
||||
assert := assert.New(t)
|
||||
etcd, client := NewEtcdClientForTest(t)
|
||||
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ import (
|
|||
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/api"
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/internal"
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -77,7 +78,7 @@ func getCloudUrl(s string) string {
|
|||
}
|
||||
|
||||
type FederationClient struct {
|
||||
logger Logger
|
||||
logger log.Logger
|
||||
hub *Hub
|
||||
session *ClientSession
|
||||
message atomic.Pointer[ClientMessage]
|
||||
|
|
@ -363,7 +364,7 @@ func (c *FederationClient) reconnect() {
|
|||
return
|
||||
}
|
||||
|
||||
ctx := NewLoggerContext(context.Background(), c.logger)
|
||||
ctx := log.NewLoggerContext(context.Background(), c.logger)
|
||||
ctx, cancel := context.WithTimeout(ctx, time.Duration(c.hub.federationTimeout))
|
||||
defer cancel()
|
||||
|
||||
|
|
|
|||
|
|
@ -32,6 +32,8 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/fsnotify/fsnotify"
|
||||
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -41,7 +43,7 @@ const (
|
|||
type FileWatcherCallback func(filename string)
|
||||
|
||||
type FileWatcher struct {
|
||||
logger Logger
|
||||
logger log.Logger
|
||||
filename string
|
||||
target string
|
||||
callback FileWatcherCallback
|
||||
|
|
@ -52,7 +54,7 @@ type FileWatcher struct {
|
|||
closeFunc context.CancelFunc
|
||||
}
|
||||
|
||||
func NewFileWatcher(logger Logger, filename string, callback FileWatcherCallback, deduplicate time.Duration) (*FileWatcher, error) {
|
||||
func NewFileWatcher(logger log.Logger, filename string, callback FileWatcherCallback, deduplicate time.Duration) (*FileWatcher, error) {
|
||||
watcher, err := fsnotify.NewWatcher()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
|||
|
|
@ -29,6 +29,8 @@ import (
|
|||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
@ -39,7 +41,7 @@ func TestFileWatcher_NotExist(t *testing.T) {
|
|||
t.Parallel()
|
||||
assert := assert.New(t)
|
||||
tmpdir := t.TempDir()
|
||||
logger := NewLoggerForTest(t)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
if w, err := NewFileWatcher(logger, path.Join(tmpdir, "test.txt"), func(filename string) {}, defaultDeduplicateWatchEvents); !assert.ErrorIs(err, os.ErrNotExist) {
|
||||
if w != nil {
|
||||
assert.NoError(w.Close())
|
||||
|
|
@ -55,7 +57,7 @@ func TestFileWatcher_File(t *testing.T) { // nolint:paralleltest
|
|||
filename := path.Join(tmpdir, "test.txt")
|
||||
require.NoError(os.WriteFile(filename, []byte("Hello world!"), 0644))
|
||||
|
||||
logger := NewLoggerForTest(t)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
modified := make(chan struct{})
|
||||
w, err := NewFileWatcher(logger, filename, func(filename string) {
|
||||
modified <- struct{}{}
|
||||
|
|
@ -98,7 +100,7 @@ func TestFileWatcher_CurrentDir(t *testing.T) { // nolint:paralleltest
|
|||
filename := path.Join(tmpdir, "test.txt")
|
||||
require.NoError(os.WriteFile(filename, []byte("Hello world!"), 0644))
|
||||
|
||||
logger := NewLoggerForTest(t)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
modified := make(chan struct{})
|
||||
w, err := NewFileWatcher(logger, "./"+path.Base(filename), func(filename string) {
|
||||
modified <- struct{}{}
|
||||
|
|
@ -140,7 +142,7 @@ func TestFileWatcher_Rename(t *testing.T) {
|
|||
filename := path.Join(tmpdir, "test.txt")
|
||||
require.NoError(os.WriteFile(filename, []byte("Hello world!"), 0644))
|
||||
|
||||
logger := NewLoggerForTest(t)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
modified := make(chan struct{})
|
||||
w, err := NewFileWatcher(logger, filename, func(filename string) {
|
||||
modified <- struct{}{}
|
||||
|
|
@ -184,7 +186,7 @@ func TestFileWatcher_Symlink(t *testing.T) {
|
|||
filename := path.Join(tmpdir, "symlink.txt")
|
||||
require.NoError(os.Symlink(sourceFilename, filename))
|
||||
|
||||
logger := NewLoggerForTest(t)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
modified := make(chan struct{})
|
||||
w, err := NewFileWatcher(logger, filename, func(filename string) {
|
||||
modified <- struct{}{}
|
||||
|
|
@ -219,7 +221,7 @@ func TestFileWatcher_ChangeSymlinkTarget(t *testing.T) {
|
|||
filename := path.Join(tmpdir, "symlink.txt")
|
||||
require.NoError(os.Symlink(sourceFilename1, filename))
|
||||
|
||||
logger := NewLoggerForTest(t)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
modified := make(chan struct{})
|
||||
w, err := NewFileWatcher(logger, filename, func(filename string) {
|
||||
modified <- struct{}{}
|
||||
|
|
@ -256,7 +258,7 @@ func TestFileWatcher_OtherSymlink(t *testing.T) {
|
|||
filename := path.Join(tmpdir, "symlink.txt")
|
||||
require.NoError(os.Symlink(sourceFilename1, filename))
|
||||
|
||||
logger := NewLoggerForTest(t)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
modified := make(chan struct{})
|
||||
w, err := NewFileWatcher(logger, filename, func(filename string) {
|
||||
modified <- struct{}{}
|
||||
|
|
@ -287,7 +289,7 @@ func TestFileWatcher_RenameSymlinkTarget(t *testing.T) {
|
|||
filename := path.Join(tmpdir, "test.txt")
|
||||
require.NoError(os.Symlink(sourceFilename1, filename))
|
||||
|
||||
logger := NewLoggerForTest(t)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
modified := make(chan struct{})
|
||||
w, err := NewFileWatcher(logger, filename, func(filename string) {
|
||||
modified <- struct{}{}
|
||||
|
|
@ -341,7 +343,7 @@ func TestFileWatcher_UpdateSymlinkFolder(t *testing.T) {
|
|||
filename := path.Join(tmpdir, "test.txt")
|
||||
require.NoError(os.Symlink("data/test.txt", filename))
|
||||
|
||||
logger := NewLoggerForTest(t)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
modified := make(chan struct{})
|
||||
w, err := NewFileWatcher(logger, filename, func(filename string) {
|
||||
modified <- struct{}{}
|
||||
|
|
|
|||
10
geoip.go
10
geoip.go
|
|
@ -38,6 +38,8 @@ import (
|
|||
|
||||
"github.com/dlintw/goconf"
|
||||
"github.com/oschwald/maxminddb-golang"
|
||||
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
@ -57,7 +59,7 @@ func GetGeoIpDownloadUrl(license string) string {
|
|||
}
|
||||
|
||||
type GeoLookup struct {
|
||||
logger Logger
|
||||
logger log.Logger
|
||||
url string
|
||||
isFile bool
|
||||
client http.Client
|
||||
|
|
@ -68,7 +70,7 @@ type GeoLookup struct {
|
|||
reader atomic.Pointer[maxminddb.Reader]
|
||||
}
|
||||
|
||||
func NewGeoLookupFromUrl(logger Logger, url string) (*GeoLookup, error) {
|
||||
func NewGeoLookupFromUrl(logger log.Logger, url string) (*GeoLookup, error) {
|
||||
geoip := &GeoLookup{
|
||||
logger: logger,
|
||||
url: url,
|
||||
|
|
@ -76,7 +78,7 @@ func NewGeoLookupFromUrl(logger Logger, url string) (*GeoLookup, error) {
|
|||
return geoip, nil
|
||||
}
|
||||
|
||||
func NewGeoLookupFromFile(logger Logger, filename string) (*GeoLookup, error) {
|
||||
func NewGeoLookupFromFile(logger log.Logger, filename string) (*GeoLookup, error) {
|
||||
geoip := &GeoLookup{
|
||||
logger: logger,
|
||||
url: filename,
|
||||
|
|
@ -273,7 +275,7 @@ func IsValidContinent(continent string) bool {
|
|||
}
|
||||
|
||||
func LoadGeoIPOverrides(ctx context.Context, config *goconf.ConfigFile, ignoreErrors bool) (map[*net.IPNet]string, error) {
|
||||
logger := LoggerFromContext(ctx)
|
||||
logger := log.LoggerFromContext(ctx)
|
||||
options, _ := GetStringOptions(config, "geoip-overrides", true)
|
||||
if len(options) == 0 {
|
||||
return nil, nil
|
||||
|
|
|
|||
|
|
@ -35,6 +35,8 @@ import (
|
|||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
func testGeoLookupReader(t *testing.T, reader *GeoLookup) {
|
||||
|
|
@ -77,7 +79,7 @@ func GetGeoIpUrlForTest(t *testing.T) string {
|
|||
|
||||
func TestGeoLookup(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
require := require.New(t)
|
||||
reader, err := NewGeoLookupFromUrl(logger, GetGeoIpUrlForTest(t))
|
||||
require.NoError(err)
|
||||
|
|
@ -90,7 +92,7 @@ func TestGeoLookup(t *testing.T) {
|
|||
|
||||
func TestGeoLookupCaching(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
require := require.New(t)
|
||||
reader, err := NewGeoLookupFromUrl(logger, GetGeoIpUrlForTest(t))
|
||||
require.NoError(err)
|
||||
|
|
@ -131,7 +133,7 @@ func TestGeoLookupContinent(t *testing.T) {
|
|||
|
||||
func TestGeoLookupCloseEmpty(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
reader, err := NewGeoLookupFromUrl(logger, "ignore-url")
|
||||
require.NoError(t, err)
|
||||
reader.Close()
|
||||
|
|
@ -139,7 +141,7 @@ func TestGeoLookupCloseEmpty(t *testing.T) {
|
|||
|
||||
func TestGeoLookupFromFile(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
require := require.New(t)
|
||||
geoIpUrl := GetGeoIpUrlForTest(t)
|
||||
|
||||
|
|
|
|||
|
|
@ -42,6 +42,8 @@ import (
|
|||
"google.golang.org/grpc/metadata"
|
||||
"google.golang.org/grpc/resolver"
|
||||
status "google.golang.org/grpc/status"
|
||||
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -78,7 +80,7 @@ func newGrpcClientImpl(conn grpc.ClientConnInterface) *grpcClientImpl {
|
|||
}
|
||||
|
||||
type GrpcClient struct {
|
||||
logger Logger
|
||||
logger log.Logger
|
||||
ip net.IP
|
||||
rawTarget string
|
||||
target string
|
||||
|
|
@ -127,7 +129,7 @@ func (r *customIpResolver) Close() {
|
|||
// Noop
|
||||
}
|
||||
|
||||
func NewGrpcClient(logger Logger, target string, ip net.IP, opts ...grpc.DialOption) (*GrpcClient, error) {
|
||||
func NewGrpcClient(logger log.Logger, target string, ip net.IP, opts ...grpc.DialOption) (*GrpcClient, error) {
|
||||
var conn *grpc.ClientConn
|
||||
var err error
|
||||
if ip != nil {
|
||||
|
|
@ -370,7 +372,7 @@ type ProxySessionReceiver interface {
|
|||
}
|
||||
|
||||
type SessionProxy struct {
|
||||
logger Logger
|
||||
logger log.Logger
|
||||
sessionId PublicSessionId
|
||||
receiver ProxySessionReceiver
|
||||
|
||||
|
|
@ -450,7 +452,7 @@ type grpcClientsList struct {
|
|||
type GrpcClients struct {
|
||||
mu sync.RWMutex
|
||||
version string
|
||||
logger Logger
|
||||
logger log.Logger
|
||||
|
||||
// +checklocks:mu
|
||||
clientsMap map[string]*grpcClientsList
|
||||
|
|
@ -482,7 +484,7 @@ func NewGrpcClients(ctx context.Context, config *goconf.ConfigFile, etcdClient *
|
|||
closeCtx, closeFunc := context.WithCancel(context.Background())
|
||||
result := &GrpcClients{
|
||||
version: version,
|
||||
logger: LoggerFromContext(ctx),
|
||||
logger: log.LoggerFromContext(ctx),
|
||||
dnsMonitor: dnsMonitor,
|
||||
etcdClient: etcdClient,
|
||||
initializedCtx: initializedCtx,
|
||||
|
|
|
|||
|
|
@ -36,6 +36,8 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"go.etcd.io/etcd/server/v3/embed"
|
||||
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
func (c *GrpcClients) getWakeupChannelForTesting() <-chan struct{} {
|
||||
|
|
@ -53,8 +55,8 @@ func (c *GrpcClients) getWakeupChannelForTesting() <-chan struct{} {
|
|||
|
||||
func NewGrpcClientsForTestWithConfig(t *testing.T, config *goconf.ConfigFile, etcdClient *EtcdClient, lookup *mockDnsLookup) (*GrpcClients, *DnsMonitor) {
|
||||
dnsMonitor := newDnsMonitorForTest(t, time.Hour, lookup) // will be updated manually
|
||||
logger := NewLoggerForTest(t)
|
||||
ctx := NewLoggerContext(t.Context(), logger)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
ctx := log.NewLoggerContext(t.Context(), logger)
|
||||
client, err := NewGrpcClients(ctx, config, etcdClient, dnsMonitor, "0.0.0")
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
|
|
@ -79,7 +81,7 @@ func NewGrpcClientsWithEtcdForTest(t *testing.T, etcd *embed.Etcd, lookup *mockD
|
|||
config.AddOption("grpc", "targettype", "etcd")
|
||||
config.AddOption("grpc", "targetprefix", "/grpctargets")
|
||||
|
||||
logger := NewLoggerForTest(t)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
etcdClient, err := NewEtcdClient(logger, config, "")
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
|
|
@ -111,8 +113,8 @@ func waitForEvent(ctx context.Context, t *testing.T, ch <-chan struct{}) {
|
|||
}
|
||||
|
||||
func Test_GrpcClients_EtcdInitial(t *testing.T) { // nolint:paralleltest
|
||||
logger := NewLoggerForTest(t)
|
||||
ctx := NewLoggerContext(t.Context(), logger)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
ctx := log.NewLoggerContext(t.Context(), logger)
|
||||
ensureNoGoroutinesLeak(t, func(t *testing.T) {
|
||||
_, addr1 := NewGrpcServerForTest(t)
|
||||
_, addr2 := NewGrpcServerForTest(t)
|
||||
|
|
@ -134,8 +136,8 @@ func Test_GrpcClients_EtcdInitial(t *testing.T) { // nolint:paralleltest
|
|||
|
||||
func Test_GrpcClients_EtcdUpdate(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
ctx := NewLoggerContext(t.Context(), logger)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
ctx := log.NewLoggerContext(t.Context(), logger)
|
||||
assert := assert.New(t)
|
||||
etcd := NewEtcdForTest(t)
|
||||
client, _ := NewGrpcClientsWithEtcdForTest(t, etcd, nil)
|
||||
|
|
@ -181,8 +183,8 @@ func Test_GrpcClients_EtcdUpdate(t *testing.T) {
|
|||
|
||||
func Test_GrpcClients_EtcdIgnoreSelf(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
ctx := NewLoggerContext(t.Context(), logger)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
ctx := log.NewLoggerContext(t.Context(), logger)
|
||||
assert := assert.New(t)
|
||||
etcd := NewEtcdForTest(t)
|
||||
client, _ := NewGrpcClientsWithEtcdForTest(t, etcd, nil)
|
||||
|
|
@ -220,8 +222,8 @@ func Test_GrpcClients_EtcdIgnoreSelf(t *testing.T) {
|
|||
}
|
||||
|
||||
func Test_GrpcClients_DnsDiscovery(t *testing.T) { // nolint:paralleltest
|
||||
logger := NewLoggerForTest(t)
|
||||
ctx := NewLoggerContext(t.Context(), logger)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
ctx := log.NewLoggerContext(t.Context(), logger)
|
||||
ensureNoGoroutinesLeak(t, func(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
require := require.New(t)
|
||||
|
|
|
|||
|
|
@ -30,6 +30,8 @@ import (
|
|||
"github.com/dlintw/goconf"
|
||||
"google.golang.org/grpc/credentials"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
type reloadableCredentials struct {
|
||||
|
|
@ -133,7 +135,7 @@ func (c *reloadableCredentials) Close() {
|
|||
}
|
||||
}
|
||||
|
||||
func NewReloadableCredentials(logger Logger, config *goconf.ConfigFile, server bool) (credentials.TransportCredentials, error) {
|
||||
func NewReloadableCredentials(logger log.Logger, config *goconf.ConfigFile, server bool) (credentials.TransportCredentials, error) {
|
||||
var prefix string
|
||||
var caPrefix string
|
||||
if server {
|
||||
|
|
|
|||
|
|
@ -32,6 +32,8 @@ import (
|
|||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/metadata"
|
||||
"google.golang.org/grpc/status"
|
||||
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -48,7 +50,7 @@ func getMD(md metadata.MD, key string) string {
|
|||
|
||||
// remoteGrpcClient is a remote client connecting from a GRPC proxy to a Hub.
|
||||
type remoteGrpcClient struct {
|
||||
logger Logger
|
||||
logger log.Logger
|
||||
hub *Hub
|
||||
client RpcSessions_ProxySessionServer
|
||||
|
||||
|
|
|
|||
|
|
@ -37,6 +37,8 @@ import (
|
|||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/credentials"
|
||||
status "google.golang.org/grpc/status"
|
||||
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
@ -73,7 +75,7 @@ type GrpcServer struct {
|
|||
UnimplementedRpcMcuServer
|
||||
UnimplementedRpcSessionsServer
|
||||
|
||||
logger Logger
|
||||
logger log.Logger
|
||||
version string
|
||||
creds credentials.TransportCredentials
|
||||
conn *grpc.Server
|
||||
|
|
@ -93,7 +95,7 @@ func NewGrpcServer(ctx context.Context, config *goconf.ConfigFile, version strin
|
|||
}
|
||||
}
|
||||
|
||||
logger := LoggerFromContext(ctx)
|
||||
logger := log.LoggerFromContext(ctx)
|
||||
creds, err := NewReloadableCredentials(logger, config, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
|||
|
|
@ -41,6 +41,8 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials"
|
||||
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
func (s *GrpcServer) WaitForCertificateReload(ctx context.Context, counter uint64) error {
|
||||
|
|
@ -62,8 +64,8 @@ func (s *GrpcServer) WaitForCertPoolReload(ctx context.Context, counter uint64)
|
|||
}
|
||||
|
||||
func NewGrpcServerForTestWithConfig(t *testing.T, config *goconf.ConfigFile) (server *GrpcServer, addr string) {
|
||||
logger := NewLoggerForTest(t)
|
||||
ctx := NewLoggerContext(t.Context(), logger)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
ctx := log.NewLoggerContext(t.Context(), logger)
|
||||
for port := 50000; port < 50100; port++ {
|
||||
addr = net.JoinHostPort("127.0.0.1", strconv.Itoa(port))
|
||||
config.AddOption("grpc", "listen", addr)
|
||||
|
|
@ -169,7 +171,7 @@ func Test_GrpcServer_ReloadCerts(t *testing.T) {
|
|||
|
||||
func Test_GrpcServer_ReloadCA(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
require := require.New(t)
|
||||
serverKey, err := rsa.GenerateKey(rand.Reader, 1024)
|
||||
require.NoError(err)
|
||||
|
|
|
|||
13
hub.go
13
hub.go
|
|
@ -52,6 +52,7 @@ import (
|
|||
"github.com/gorilla/websocket"
|
||||
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/api"
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
@ -139,7 +140,7 @@ func init() {
|
|||
|
||||
type Hub struct {
|
||||
version string
|
||||
logger Logger
|
||||
logger log.Logger
|
||||
events AsyncEvents
|
||||
upgrader websocket.Upgrader
|
||||
sessionIds *SessionIdCodec
|
||||
|
|
@ -220,7 +221,7 @@ type Hub struct {
|
|||
}
|
||||
|
||||
func NewHub(ctx context.Context, config *goconf.ConfigFile, events AsyncEvents, rpcServer *GrpcServer, rpcClients *GrpcClients, etcdClient *EtcdClient, r *mux.Router, version string) (*Hub, error) {
|
||||
logger := LoggerFromContext(ctx)
|
||||
logger := log.LoggerFromContext(ctx)
|
||||
hashKey, _ := GetStringOptionWithEnv(config, "sessions", "hashkey")
|
||||
switch len(hashKey) {
|
||||
case 32:
|
||||
|
|
@ -1270,7 +1271,7 @@ func (h *Hub) tryProxyResume(c HandlerClient, resumeId PrivateSessionId, message
|
|||
}
|
||||
|
||||
func (h *Hub) processHello(client HandlerClient, message *ClientMessage) {
|
||||
ctx := NewLoggerContext(client.Context(), h.logger)
|
||||
ctx := log.NewLoggerContext(client.Context(), h.logger)
|
||||
resumeId := message.Hello.ResumeId
|
||||
if resumeId != "" {
|
||||
throttle, err := h.throttler.CheckBruteforce(ctx, client.RemoteAddr(), "HelloResume")
|
||||
|
|
@ -1576,7 +1577,7 @@ func (h *Hub) processHelloInternal(client HandlerClient, message *ClientMessage)
|
|||
return
|
||||
}
|
||||
|
||||
ctx := NewLoggerContext(client.Context(), h.logger)
|
||||
ctx := log.NewLoggerContext(client.Context(), h.logger)
|
||||
throttle, err := h.throttler.CheckBruteforce(ctx, client.RemoteAddr(), "HelloInternal")
|
||||
if err == ErrBruteforceDetected {
|
||||
client.SendMessage(message.NewErrorServerMessage(TooManyRequests))
|
||||
|
|
@ -1944,7 +1945,7 @@ func (h *Hub) publishFederatedSessions() (int, *sync.WaitGroup) {
|
|||
return 0, &wg
|
||||
}
|
||||
count := 0
|
||||
ctx := NewLoggerContext(context.Background(), h.logger)
|
||||
ctx := log.NewLoggerContext(context.Background(), h.logger)
|
||||
for roomId, entries := range rooms {
|
||||
for u, e := range entries {
|
||||
wg.Add(1)
|
||||
|
|
@ -3128,7 +3129,7 @@ func (h *Hub) serveWs(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
ctx := NewLoggerContext(r.Context(), h.logger)
|
||||
ctx := log.NewLoggerContext(r.Context(), h.logger)
|
||||
if conn.Subprotocol() == JanusEventsSubprotocol {
|
||||
RunJanusEventsHandler(ctx, h.mcu, conn, addr, agent)
|
||||
return
|
||||
|
|
|
|||
13
hub_test.go
13
hub_test.go
|
|
@ -54,6 +54,7 @@ import (
|
|||
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/api"
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/internal"
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -151,8 +152,8 @@ func getTestConfigWithMultipleUrls(server *httptest.Server) (*goconf.ConfigFile,
|
|||
}
|
||||
|
||||
func CreateHubForTestWithConfig(t *testing.T, getConfigFunc func(*httptest.Server) (*goconf.ConfigFile, error)) (*Hub, AsyncEvents, *mux.Router, *httptest.Server) {
|
||||
logger := NewLoggerForTest(t)
|
||||
ctx := NewLoggerContext(t.Context(), logger)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
ctx := log.NewLoggerContext(t.Context(), logger)
|
||||
require := require.New(t)
|
||||
r := mux.NewRouter()
|
||||
registerBackendHandler(t, r)
|
||||
|
|
@ -202,8 +203,8 @@ func CreateHubWithMultipleUrlsForTest(t *testing.T) (*Hub, AsyncEvents, *mux.Rou
|
|||
}
|
||||
|
||||
func CreateClusteredHubsForTestWithConfig(t *testing.T, getConfigFunc func(*httptest.Server) (*goconf.ConfigFile, error)) (*Hub, *Hub, *mux.Router, *mux.Router, *httptest.Server, *httptest.Server) {
|
||||
logger := NewLoggerForTest(t)
|
||||
ctx := NewLoggerContext(t.Context(), logger)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
ctx := log.NewLoggerContext(t.Context(), logger)
|
||||
require := require.New(t)
|
||||
assert := assert.New(t)
|
||||
r1 := mux.NewRouter()
|
||||
|
|
@ -5200,8 +5201,8 @@ func TestGeoipOverrides(t *testing.T) {
|
|||
|
||||
func TestDialoutStatus(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
ctx := NewLoggerContext(t.Context(), logger)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
ctx := log.NewLoggerContext(t.Context(), logger)
|
||||
require := require.New(t)
|
||||
assert := assert.New(t)
|
||||
_, _, _, hub, _, server := CreateBackendServerForTest(t)
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package signaling
|
||||
package log
|
||||
|
||||
import (
|
||||
"context"
|
||||
68
log/logging_test.go
Normal file
68
log/logging_test.go
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
/**
|
||||
* Standalone signaling server for the Nextcloud Spreed app.
|
||||
* Copyright (C) 2025 struktur AG
|
||||
*
|
||||
* @author Joachim Bauch <bauch@struktur.de>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package log
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestGlobalLogger(t *testing.T) {
|
||||
t.Parallel()
|
||||
assert := assert.New(t)
|
||||
|
||||
defer func() {
|
||||
if err := recover(); assert.NotNil(err) {
|
||||
assert.Equal("accessed global logger", err)
|
||||
}
|
||||
}()
|
||||
|
||||
logger := LoggerFromContext(t.Context())
|
||||
assert.Fail("should have paniced", "got logger %+v", logger)
|
||||
}
|
||||
|
||||
func TestLoggerContext(t *testing.T) {
|
||||
t.Parallel()
|
||||
assert := assert.New(t)
|
||||
|
||||
testLogger := NewLoggerForTest(t)
|
||||
testLogger.Printf("Hello %s!", "world")
|
||||
|
||||
ctx := NewLoggerContext(t.Context(), testLogger)
|
||||
logger2 := LoggerFromContext(ctx)
|
||||
assert.Equal(testLogger, logger2)
|
||||
}
|
||||
|
||||
func TestNilLoggerContext(t *testing.T) {
|
||||
t.Parallel()
|
||||
assert := assert.New(t)
|
||||
|
||||
defer func() {
|
||||
if err := recover(); assert.NotNil(err) {
|
||||
assert.Equal("logger is nil", err)
|
||||
}
|
||||
}()
|
||||
|
||||
ctx := NewLoggerContext(t.Context(), nil)
|
||||
assert.Fail("should have paniced", "got context %+v", ctx)
|
||||
}
|
||||
|
|
@ -19,7 +19,7 @@
|
|||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package signaling
|
||||
package log
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
|
@ -21,7 +21,7 @@
|
|||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package signaling
|
||||
package log
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
|
@ -21,7 +21,7 @@
|
|||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package signaling
|
||||
package log
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
|
@ -30,6 +30,7 @@ import (
|
|||
"github.com/dlintw/goconf"
|
||||
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/api"
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -81,7 +82,7 @@ type McuSettings interface {
|
|||
}
|
||||
|
||||
type mcuCommonSettings struct {
|
||||
logger Logger
|
||||
logger log.Logger
|
||||
|
||||
maxStreamBitrate api.AtomicBandwidth
|
||||
maxScreenBitrate api.AtomicBandwidth
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ import (
|
|||
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/api"
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/internal"
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -107,7 +108,7 @@ func convertIntValue(value any) (uint64, error) {
|
|||
}
|
||||
}
|
||||
|
||||
func getPluginIntValue(logger Logger, data janus.PluginData, pluginName string, key string) uint64 {
|
||||
func getPluginIntValue(logger log.Logger, data janus.PluginData, pluginName string, key string) uint64 {
|
||||
val := getPluginValue(data, pluginName, key)
|
||||
if val == nil {
|
||||
return 0
|
||||
|
|
@ -156,7 +157,7 @@ type mcuJanusSettings struct {
|
|||
func newMcuJanusSettings(ctx context.Context, config *goconf.ConfigFile) (*mcuJanusSettings, error) {
|
||||
settings := &mcuJanusSettings{
|
||||
mcuCommonSettings: mcuCommonSettings{
|
||||
logger: LoggerFromContext(ctx),
|
||||
logger: log.LoggerFromContext(ctx),
|
||||
},
|
||||
}
|
||||
if err := settings.load(config); err != nil {
|
||||
|
|
@ -229,7 +230,7 @@ func (s *prometheusJanusStats) DecSubscriber(streamType StreamType) {
|
|||
}
|
||||
|
||||
type mcuJanus struct {
|
||||
logger Logger
|
||||
logger log.Logger
|
||||
|
||||
url string
|
||||
mu sync.Mutex
|
||||
|
|
@ -278,7 +279,7 @@ func NewMcuJanus(ctx context.Context, url string, config *goconf.ConfigFile) (Mc
|
|||
}
|
||||
|
||||
mcu := &mcuJanus{
|
||||
logger: LoggerFromContext(ctx),
|
||||
logger: log.LoggerFromContext(ctx),
|
||||
url: url,
|
||||
settings: settings,
|
||||
stats: &prometheusJanusStats{},
|
||||
|
|
|
|||
|
|
@ -31,10 +31,11 @@ import (
|
|||
"github.com/notedit/janus-go"
|
||||
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/api"
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
type mcuJanusClient struct {
|
||||
logger Logger
|
||||
logger log.Logger
|
||||
mcu *mcuJanus
|
||||
listener McuListener
|
||||
mu sync.Mutex
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ import (
|
|||
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/api"
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/internal"
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -620,7 +621,7 @@ func (h *handleStats) LostRemote(media string, lost uint64) {
|
|||
type JanusEventsHandler struct {
|
||||
mu sync.Mutex
|
||||
|
||||
logger Logger
|
||||
logger log.Logger
|
||||
ctx context.Context
|
||||
mcu McuEventHandler
|
||||
// +checklocks:mu
|
||||
|
|
@ -654,7 +655,7 @@ func RunJanusEventsHandler(ctx context.Context, mcu Mcu, conn *websocket.Conn, a
|
|||
|
||||
client, err := NewJanusEventsHandler(ctx, m, conn, addr, agent)
|
||||
if err != nil {
|
||||
logger := LoggerFromContext(ctx)
|
||||
logger := log.LoggerFromContext(ctx)
|
||||
logger.Printf("Could not create Janus events handler for %s: %s", addr, err)
|
||||
conn.WriteControl(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseInternalServerErr, "error creating handler"), deadline) // nolint
|
||||
return
|
||||
|
|
@ -665,7 +666,7 @@ func RunJanusEventsHandler(ctx context.Context, mcu Mcu, conn *websocket.Conn, a
|
|||
|
||||
func NewJanusEventsHandler(ctx context.Context, mcu McuEventHandler, conn *websocket.Conn, addr string, agent string) (*JanusEventsHandler, error) {
|
||||
handler := &JanusEventsHandler{
|
||||
logger: LoggerFromContext(ctx),
|
||||
logger: log.LoggerFromContext(ctx),
|
||||
ctx: ctx,
|
||||
mcu: mcu,
|
||||
conn: conn,
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/api"
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
type TestJanusEventsServerHandler struct {
|
||||
|
|
@ -66,8 +67,8 @@ func (h *TestJanusEventsServerHandler) ServeHTTP(w http.ResponseWriter, r *http.
|
|||
if host, _, err := net.SplitHostPort(addr); err == nil {
|
||||
addr = host
|
||||
}
|
||||
logger := NewLoggerForTest(h.t)
|
||||
ctx := NewLoggerContext(r.Context(), logger)
|
||||
logger := log.NewLoggerForTest(h.t)
|
||||
ctx := log.NewLoggerContext(r.Context(), logger)
|
||||
RunJanusEventsHandler(ctx, h.mcu, conn, addr, r.Header.Get("User-Agent"))
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/api"
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
func TestMcuJanusStats(t *testing.T) {
|
||||
|
|
@ -594,8 +595,8 @@ func newMcuJanusForTesting(t *testing.T) (*mcuJanus, *TestJanusGateway) {
|
|||
if strings.Contains(t.Name(), "Filter") {
|
||||
config.AddOption("mcu", "blockedcandidates", "192.0.0.0/24, 192.168.0.0/16")
|
||||
}
|
||||
logger := NewLoggerForTest(t)
|
||||
ctx := NewLoggerContext(t.Context(), logger)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
ctx := log.NewLoggerContext(t.Context(), logger)
|
||||
mcu, err := NewMcuJanus(ctx, "", config)
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
|
|
|
|||
15
mcu_proxy.go
15
mcu_proxy.go
|
|
@ -47,6 +47,7 @@ import (
|
|||
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/api"
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/internal"
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -79,7 +80,7 @@ type McuProxy interface {
|
|||
}
|
||||
|
||||
type mcuProxyPubSubCommon struct {
|
||||
logger Logger
|
||||
logger log.Logger
|
||||
|
||||
sid string
|
||||
streamType StreamType
|
||||
|
|
@ -149,7 +150,7 @@ type mcuProxyPublisher struct {
|
|||
settings NewPublisherSettings
|
||||
}
|
||||
|
||||
func newMcuProxyPublisher(logger Logger, id PublicSessionId, sid string, streamType StreamType, maxBitrate api.Bandwidth, settings NewPublisherSettings, proxyId string, conn *mcuProxyConnection, listener McuListener) *mcuProxyPublisher {
|
||||
func newMcuProxyPublisher(logger log.Logger, id PublicSessionId, sid string, streamType StreamType, maxBitrate api.Bandwidth, settings NewPublisherSettings, proxyId string, conn *mcuProxyConnection, listener McuListener) *mcuProxyPublisher {
|
||||
return &mcuProxyPublisher{
|
||||
mcuProxyPubSubCommon: mcuProxyPubSubCommon{
|
||||
logger: logger,
|
||||
|
|
@ -243,7 +244,7 @@ type mcuProxySubscriber struct {
|
|||
publisherConn *mcuProxyConnection
|
||||
}
|
||||
|
||||
func newMcuProxySubscriber(logger Logger, publisherId PublicSessionId, sid string, streamType StreamType, maxBitrate api.Bandwidth, proxyId string, conn *mcuProxyConnection, listener McuListener, publisherConn *mcuProxyConnection) *mcuProxySubscriber {
|
||||
func newMcuProxySubscriber(logger log.Logger, publisherId PublicSessionId, sid string, streamType StreamType, maxBitrate api.Bandwidth, proxyId string, conn *mcuProxyConnection, listener McuListener, publisherConn *mcuProxyConnection) *mcuProxySubscriber {
|
||||
return &mcuProxySubscriber{
|
||||
mcuProxyPubSubCommon: mcuProxyPubSubCommon{
|
||||
logger: logger,
|
||||
|
|
@ -344,7 +345,7 @@ func (s *mcuProxySubscriber) ProcessEvent(msg *EventProxyServerMessage) {
|
|||
type mcuProxyCallback func(response *ProxyServerMessage)
|
||||
|
||||
type mcuProxyConnection struct {
|
||||
logger Logger
|
||||
logger log.Logger
|
||||
proxy *mcuProxy
|
||||
rawUrl string
|
||||
url *url.URL
|
||||
|
|
@ -1449,7 +1450,7 @@ type mcuProxySettings struct {
|
|||
func newMcuProxySettings(ctx context.Context, config *goconf.ConfigFile) (McuSettings, error) {
|
||||
settings := &mcuProxySettings{
|
||||
mcuCommonSettings: mcuCommonSettings{
|
||||
logger: LoggerFromContext(ctx),
|
||||
logger: log.LoggerFromContext(ctx),
|
||||
},
|
||||
}
|
||||
if err := settings.load(config); err != nil {
|
||||
|
|
@ -1481,7 +1482,7 @@ func (s *mcuProxySettings) Reload(config *goconf.ConfigFile) {
|
|||
}
|
||||
|
||||
type mcuProxy struct {
|
||||
logger Logger
|
||||
logger log.Logger
|
||||
urlType string
|
||||
tokenId string
|
||||
tokenKey *rsa.PrivateKey
|
||||
|
|
@ -1510,7 +1511,7 @@ type mcuProxy struct {
|
|||
}
|
||||
|
||||
func NewMcuProxy(ctx context.Context, config *goconf.ConfigFile, etcdClient *EtcdClient, rpcClients *GrpcClients, dnsMonitor *DnsMonitor) (Mcu, error) {
|
||||
logger := LoggerFromContext(ctx)
|
||||
logger := log.LoggerFromContext(ctx)
|
||||
urlType, _ := config.GetString("mcu", "urltype")
|
||||
if urlType == "" {
|
||||
urlType = proxyUrlTypeStatic
|
||||
|
|
|
|||
|
|
@ -48,6 +48,8 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"go.etcd.io/etcd/server/v3/embed"
|
||||
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -889,8 +891,8 @@ func newMcuProxyForTestWithOptions(t *testing.T, options proxyTestOptions, idx i
|
|||
etcdConfig.AddOption("etcd", "endpoints", options.etcd.Config().ListenClientUrls[0].String())
|
||||
etcdConfig.AddOption("etcd", "loglevel", "error")
|
||||
|
||||
logger := NewLoggerForTest(t)
|
||||
ctx := NewLoggerContext(t.Context(), logger)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
ctx := log.NewLoggerContext(t.Context(), logger)
|
||||
etcdClient, err := NewEtcdClient(logger, etcdConfig, "")
|
||||
require.NoError(err)
|
||||
t.Cleanup(func() {
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ import (
|
|||
"github.com/dlintw/goconf"
|
||||
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/api"
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
@ -188,7 +189,7 @@ func (c *TestMCUClient) MaxBitrate() api.Bandwidth {
|
|||
|
||||
func (c *TestMCUClient) Close(ctx context.Context) {
|
||||
if c.closed.CompareAndSwap(false, true) {
|
||||
logger := NewLoggerForTest(c.t)
|
||||
logger := log.NewLoggerForTest(c.t)
|
||||
logger.Printf("Close MCU client %s", c.id)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,6 +33,8 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/nats-io/nats.go"
|
||||
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -63,13 +65,13 @@ func GetEncodedSubject(prefix string, suffix string) string {
|
|||
}
|
||||
|
||||
type natsClient struct {
|
||||
logger Logger
|
||||
logger log.Logger
|
||||
conn *nats.Conn
|
||||
closed chan struct{}
|
||||
}
|
||||
|
||||
func NewNatsClient(ctx context.Context, url string, options ...nats.Option) (NatsClient, error) {
|
||||
logger := LoggerFromContext(ctx)
|
||||
logger := log.LoggerFromContext(ctx)
|
||||
if url == ":loopback:" {
|
||||
logger.Printf("WARNING: events url %s is deprecated, please use %s instead", url, NatsLoopbackUrl)
|
||||
url = NatsLoopbackUrl
|
||||
|
|
|
|||
|
|
@ -29,10 +29,12 @@ import (
|
|||
"sync"
|
||||
|
||||
"github.com/nats-io/nats.go"
|
||||
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
type LoopbackNatsClient struct {
|
||||
logger Logger
|
||||
logger log.Logger
|
||||
|
||||
mu sync.Mutex
|
||||
closed chan struct{}
|
||||
|
|
@ -46,7 +48,7 @@ type LoopbackNatsClient struct {
|
|||
incoming list.List
|
||||
}
|
||||
|
||||
func NewLoopbackNatsClient(logger Logger) (NatsClient, error) {
|
||||
func NewLoopbackNatsClient(logger log.Logger) (NatsClient, error) {
|
||||
client := &LoopbackNatsClient{
|
||||
logger: logger,
|
||||
closed: make(chan struct{}),
|
||||
|
|
|
|||
|
|
@ -28,6 +28,8 @@ import (
|
|||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
func (c *LoopbackNatsClient) waitForSubscriptionsEmpty(ctx context.Context, t *testing.T) {
|
||||
|
|
@ -52,7 +54,7 @@ func (c *LoopbackNatsClient) waitForSubscriptionsEmpty(ctx context.Context, t *t
|
|||
}
|
||||
|
||||
func CreateLoopbackNatsClientForTest(t *testing.T) NatsClient {
|
||||
logger := NewLoggerForTest(t)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
result, err := NewLoopbackNatsClient(logger)
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
|
|
|
|||
|
|
@ -33,6 +33,8 @@ import (
|
|||
|
||||
"github.com/nats-io/nats-server/v2/server"
|
||||
natsserver "github.com/nats-io/nats-server/v2/test"
|
||||
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
func startLocalNatsServer(t *testing.T) (*server.Server, int) {
|
||||
|
|
@ -56,8 +58,8 @@ func startLocalNatsServerPort(t *testing.T, port int) (*server.Server, int) {
|
|||
func CreateLocalNatsClientForTest(t *testing.T, options ...nats.Option) (*server.Server, int, NatsClient) {
|
||||
t.Helper()
|
||||
server, port := startLocalNatsServer(t)
|
||||
logger := NewLoggerForTest(t)
|
||||
ctx := NewLoggerContext(t.Context(), logger)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
ctx := log.NewLoggerContext(t.Context(), logger)
|
||||
result, err := NewNatsClient(ctx, server.ClientURL(), options...)
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ import (
|
|||
"github.com/gorilla/mux"
|
||||
|
||||
signaling "github.com/strukturag/nextcloud-spreed-signaling"
|
||||
signalinglog "github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
@ -72,7 +73,7 @@ func main() {
|
|||
defer stop()
|
||||
|
||||
logger := log.Default()
|
||||
stopCtx = signaling.NewLoggerContext(stopCtx, logger)
|
||||
stopCtx = signalinglog.NewLoggerContext(stopCtx, logger)
|
||||
|
||||
logger.Printf("Starting up version %s/%s as pid %d", version, runtime.Version(), os.Getpid())
|
||||
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ import (
|
|||
"github.com/gorilla/websocket"
|
||||
|
||||
signaling "github.com/strukturag/nextcloud-spreed-signaling"
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -61,7 +62,7 @@ var (
|
|||
)
|
||||
|
||||
type RemoteConnection struct {
|
||||
logger signaling.Logger
|
||||
logger log.Logger
|
||||
mu sync.Mutex
|
||||
p *ProxyServer
|
||||
url *url.URL
|
||||
|
|
|
|||
|
|
@ -51,6 +51,7 @@ import (
|
|||
|
||||
signaling "github.com/strukturag/nextcloud-spreed-signaling"
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/api"
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -109,7 +110,7 @@ type ProxyServer struct {
|
|||
welcomeMsg *signaling.WelcomeServerMessage
|
||||
config *goconf.ConfigFile
|
||||
mcuTimeout time.Duration
|
||||
logger signaling.Logger
|
||||
logger log.Logger
|
||||
|
||||
url string
|
||||
mcu signaling.Mcu
|
||||
|
|
@ -188,7 +189,7 @@ func GetLocalIP() (string, error) {
|
|||
return "", nil
|
||||
}
|
||||
|
||||
func getTargetBandwidths(logger signaling.Logger, config *goconf.ConfigFile) (api.Bandwidth, api.Bandwidth) {
|
||||
func getTargetBandwidths(logger log.Logger, config *goconf.ConfigFile) (api.Bandwidth, api.Bandwidth) {
|
||||
maxIncomingValue, _ := config.GetInt("bandwidth", "incoming")
|
||||
if maxIncomingValue < 0 {
|
||||
maxIncomingValue = 0
|
||||
|
|
@ -215,7 +216,7 @@ func getTargetBandwidths(logger signaling.Logger, config *goconf.ConfigFile) (ap
|
|||
}
|
||||
|
||||
func NewProxyServer(ctx context.Context, r *mux.Router, version string, config *goconf.ConfigFile) (*ProxyServer, error) {
|
||||
logger := signaling.LoggerFromContext(ctx)
|
||||
logger := log.LoggerFromContext(ctx)
|
||||
hashKey := make([]byte, 64)
|
||||
if _, err := rand.Read(hashKey); err != nil {
|
||||
return nil, fmt.Errorf("could not generate random hash key: %s", err)
|
||||
|
|
@ -677,7 +678,7 @@ func (s *ProxyServer) proxyHandler(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
ctx := signaling.NewLoggerContext(r.Context(), s.logger)
|
||||
ctx := log.NewLoggerContext(r.Context(), s.logger)
|
||||
if conn.Subprotocol() == signaling.JanusEventsSubprotocol {
|
||||
agent := r.Header.Get("User-Agent")
|
||||
signaling.RunJanusEventsHandler(ctx, s.mcu, conn, addr, agent)
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@ import (
|
|||
|
||||
signaling "github.com/strukturag/nextcloud-spreed-signaling"
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/api"
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -138,8 +139,8 @@ func newProxyServerForTest(t *testing.T) (*ProxyServer, *rsa.PrivateKey, *httpte
|
|||
config := goconf.NewConfigFile()
|
||||
config.AddOption("tokens", TokenIdForTest, pubkey.Name())
|
||||
|
||||
logger := signaling.NewLoggerForTest(t)
|
||||
ctx := signaling.NewLoggerContext(t.Context(), logger)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
ctx := log.NewLoggerContext(t.Context(), logger)
|
||||
proxy, err = NewProxyServer(ctx, r, "0.0", config)
|
||||
require.NoError(err)
|
||||
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ import (
|
|||
|
||||
signaling "github.com/strukturag/nextcloud-spreed-signaling"
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/api"
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -45,7 +46,7 @@ type remotePublisherData struct {
|
|||
}
|
||||
|
||||
type ProxySession struct {
|
||||
logger signaling.Logger
|
||||
logger log.Logger
|
||||
proxy *ProxyServer
|
||||
id signaling.PublicSessionId
|
||||
sid uint64
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ import (
|
|||
"github.com/golang-jwt/jwt/v5"
|
||||
|
||||
signaling "github.com/strukturag/nextcloud-spreed-signaling"
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -46,14 +47,14 @@ type tokenCacheEntry struct {
|
|||
}
|
||||
|
||||
type tokensEtcd struct {
|
||||
logger signaling.Logger
|
||||
logger log.Logger
|
||||
client *signaling.EtcdClient
|
||||
|
||||
tokenFormats atomic.Value
|
||||
tokenCache *signaling.LruCache[*tokenCacheEntry]
|
||||
}
|
||||
|
||||
func NewProxyTokensEtcd(logger signaling.Logger, config *goconf.ConfigFile) (ProxyTokens, error) {
|
||||
func NewProxyTokensEtcd(logger log.Logger, config *goconf.ConfigFile) (ProxyTokens, error) {
|
||||
client, err := signaling.NewEtcdClient(logger, config, "tokens")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ import (
|
|||
"go.uber.org/zap"
|
||||
"go.uber.org/zap/zaptest"
|
||||
|
||||
signaling "github.com/strukturag/nextcloud-spreed-signaling"
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
@ -118,7 +118,7 @@ func newTokensEtcdForTesting(t *testing.T) (*tokensEtcd, *embed.Etcd) {
|
|||
cfg.AddOption("etcd", "endpoints", etcd.Config().ListenClientUrls[0].String())
|
||||
cfg.AddOption("tokens", "keyformat", "/%s, /testing/%s/key")
|
||||
|
||||
logger := signaling.NewLoggerForTest(t)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
tokens, err := NewProxyTokensEtcd(logger, cfg)
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
|
|
|
|||
|
|
@ -31,14 +31,15 @@ import (
|
|||
"github.com/golang-jwt/jwt/v5"
|
||||
|
||||
signaling "github.com/strukturag/nextcloud-spreed-signaling"
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
type tokensStatic struct {
|
||||
logger signaling.Logger
|
||||
logger log.Logger
|
||||
tokenKeys atomic.Value
|
||||
}
|
||||
|
||||
func NewProxyTokensStatic(logger signaling.Logger, config *goconf.ConfigFile) (ProxyTokens, error) {
|
||||
func NewProxyTokensStatic(logger log.Logger, config *goconf.ConfigFile) (ProxyTokens, error) {
|
||||
result := &tokensStatic{
|
||||
logger: logger,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,10 +30,12 @@ import (
|
|||
|
||||
"github.com/dlintw/goconf"
|
||||
clientv3 "go.etcd.io/etcd/client/v3"
|
||||
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
type proxyConfigEtcd struct {
|
||||
logger Logger
|
||||
logger log.Logger
|
||||
mu sync.Mutex
|
||||
proxy McuProxy // +checklocksignore: Only written to from constructor.
|
||||
|
||||
|
|
@ -48,7 +50,7 @@ type proxyConfigEtcd struct {
|
|||
closeFunc context.CancelFunc
|
||||
}
|
||||
|
||||
func NewProxyConfigEtcd(logger Logger, config *goconf.ConfigFile, etcdClient *EtcdClient, proxy McuProxy) (ProxyConfig, error) {
|
||||
func NewProxyConfigEtcd(logger log.Logger, config *goconf.ConfigFile, etcdClient *EtcdClient, proxy McuProxy) (ProxyConfig, error) {
|
||||
if !etcdClient.IsConfigured() {
|
||||
return nil, errors.New("no etcd endpoints configured")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,6 +30,8 @@ import (
|
|||
"github.com/dlintw/goconf"
|
||||
"github.com/stretchr/testify/require"
|
||||
"go.etcd.io/etcd/server/v3/embed"
|
||||
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
type TestProxyInformationEtcd struct {
|
||||
|
|
@ -43,7 +45,7 @@ func newProxyConfigEtcd(t *testing.T, proxy McuProxy) (*embed.Etcd, ProxyConfig)
|
|||
etcd, client := NewEtcdClientForTest(t)
|
||||
cfg := goconf.NewConfigFile()
|
||||
cfg.AddOption("mcu", "keyprefix", "proxies/")
|
||||
logger := NewLoggerForTest(t)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
p, err := NewProxyConfigEtcd(logger, cfg, client, proxy)
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
|
|
|
|||
|
|
@ -29,6 +29,8 @@ import (
|
|||
"sync"
|
||||
|
||||
"github.com/dlintw/goconf"
|
||||
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
type ipList struct {
|
||||
|
|
@ -39,7 +41,7 @@ type ipList struct {
|
|||
}
|
||||
|
||||
type proxyConfigStatic struct {
|
||||
logger Logger
|
||||
logger log.Logger
|
||||
mu sync.Mutex
|
||||
proxy McuProxy
|
||||
|
||||
|
|
@ -51,7 +53,7 @@ type proxyConfigStatic struct {
|
|||
connectionsMap map[string]*ipList
|
||||
}
|
||||
|
||||
func NewProxyConfigStatic(logger Logger, config *goconf.ConfigFile, proxy McuProxy, dnsMonitor *DnsMonitor) (ProxyConfig, error) {
|
||||
func NewProxyConfigStatic(logger log.Logger, config *goconf.ConfigFile, proxy McuProxy, dnsMonitor *DnsMonitor) (ProxyConfig, error) {
|
||||
result := &proxyConfigStatic{
|
||||
logger: logger,
|
||||
proxy: proxy,
|
||||
|
|
|
|||
|
|
@ -29,6 +29,8 @@ import (
|
|||
|
||||
"github.com/dlintw/goconf"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
func newProxyConfigStatic(t *testing.T, proxy McuProxy, dns bool, lookup *mockDnsLookup, urls ...string) (ProxyConfig, *DnsMonitor) {
|
||||
|
|
@ -38,7 +40,7 @@ func newProxyConfigStatic(t *testing.T, proxy McuProxy, dns bool, lookup *mockDn
|
|||
cfg.AddOption("mcu", "dnsdiscovery", "true")
|
||||
}
|
||||
dnsMonitor := newDnsMonitorForTest(t, time.Hour, lookup) // will be updated manually
|
||||
logger := NewLoggerForTest(t)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
p, err := NewProxyConfigStatic(logger, cfg, proxy, dnsMonitor)
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
|
|
|
|||
|
|
@ -27,10 +27,12 @@ import (
|
|||
"errors"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
type RemoteSession struct {
|
||||
logger Logger
|
||||
logger log.Logger
|
||||
hub *Hub
|
||||
client *Client
|
||||
remoteClient *GrpcClient
|
||||
|
|
|
|||
9
room.go
9
room.go
|
|
@ -36,6 +36,7 @@ import (
|
|||
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/api"
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/internal"
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -64,7 +65,7 @@ func init() {
|
|||
|
||||
type Room struct {
|
||||
id string
|
||||
logger Logger
|
||||
logger log.Logger
|
||||
hub *Hub
|
||||
events AsyncEvents
|
||||
backend *Backend
|
||||
|
|
@ -619,7 +620,7 @@ func (r *Room) getClusteredInternalSessionsRLocked() (internal map[PublicSession
|
|||
|
||||
r.mu.RUnlock()
|
||||
defer r.mu.RLock()
|
||||
ctx := NewLoggerContext(context.Background(), r.logger)
|
||||
ctx := log.NewLoggerContext(context.Background(), r.logger)
|
||||
ctx, cancel := context.WithTimeout(ctx, time.Second)
|
||||
defer cancel()
|
||||
|
||||
|
|
@ -1103,7 +1104,7 @@ func (r *Room) publishActiveSessions() (int, *sync.WaitGroup) {
|
|||
return 0, &wg
|
||||
}
|
||||
var count int
|
||||
ctx := NewLoggerContext(context.Background(), r.logger)
|
||||
ctx := log.NewLoggerContext(context.Background(), r.logger)
|
||||
for u, e := range entries {
|
||||
wg.Add(1)
|
||||
count += len(e)
|
||||
|
|
@ -1285,7 +1286,7 @@ func (r *Room) fetchInitialTransientData() {
|
|||
return
|
||||
}
|
||||
|
||||
ctx := NewLoggerContext(context.Background(), r.logger)
|
||||
ctx := log.NewLoggerContext(context.Background(), r.logger)
|
||||
ctx, cancel := context.WithTimeout(ctx, time.Second)
|
||||
defer cancel()
|
||||
|
||||
|
|
|
|||
|
|
@ -27,6 +27,8 @@ import (
|
|||
"slices"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
type pingEntries struct {
|
||||
|
|
@ -121,7 +123,7 @@ func (p *RoomPing) publishEntries(ctx context.Context, entries *pingEntries, tim
|
|||
if !found || limit <= 0 {
|
||||
// Limit disabled while waiting for the next iteration, fallback to sending
|
||||
// one request per room.
|
||||
logger := LoggerFromContext(ctx)
|
||||
logger := log.LoggerFromContext(ctx)
|
||||
for roomId, e := range entries.entries {
|
||||
ctx2, cancel2 := context.WithTimeout(context.WithoutCancel(ctx), timeout)
|
||||
defer cancel2()
|
||||
|
|
@ -167,7 +169,7 @@ func (p *RoomPing) sendPingsDirect(ctx context.Context, roomId string, url *url.
|
|||
}
|
||||
|
||||
func (p *RoomPing) sendPingsCombined(ctx context.Context, url *url.URL, entries []BackendPingEntry, limit int, timeout time.Duration) {
|
||||
logger := LoggerFromContext(ctx)
|
||||
logger := log.LoggerFromContext(ctx)
|
||||
for tosend := range slices.Chunk(entries, limit) {
|
||||
subCtx, cancel := context.WithTimeout(ctx, timeout)
|
||||
defer cancel()
|
||||
|
|
|
|||
|
|
@ -30,6 +30,8 @@ import (
|
|||
"github.com/gorilla/mux"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
func NewRoomPingForTest(ctx context.Context, t *testing.T) (*url.URL, *RoomPing) {
|
||||
|
|
@ -59,8 +61,8 @@ func NewRoomPingForTest(ctx context.Context, t *testing.T) (*url.URL, *RoomPing)
|
|||
|
||||
func TestSingleRoomPing(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
ctx := NewLoggerContext(t.Context(), logger)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
ctx := log.NewLoggerContext(t.Context(), logger)
|
||||
assert := assert.New(t)
|
||||
u, ping := NewRoomPingForTest(ctx, t)
|
||||
|
||||
|
|
@ -103,8 +105,8 @@ func TestSingleRoomPing(t *testing.T) {
|
|||
|
||||
func TestMultiRoomPing(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
ctx := NewLoggerContext(t.Context(), logger)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
ctx := log.NewLoggerContext(t.Context(), logger)
|
||||
assert := assert.New(t)
|
||||
u, ping := NewRoomPingForTest(ctx, t)
|
||||
|
||||
|
|
@ -143,8 +145,8 @@ func TestMultiRoomPing(t *testing.T) {
|
|||
|
||||
func TestMultiRoomPing_Separate(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
ctx := NewLoggerContext(t.Context(), logger)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
ctx := log.NewLoggerContext(t.Context(), logger)
|
||||
assert := assert.New(t)
|
||||
u, ping := NewRoomPingForTest(ctx, t)
|
||||
|
||||
|
|
@ -179,8 +181,8 @@ func TestMultiRoomPing_Separate(t *testing.T) {
|
|||
|
||||
func TestMultiRoomPing_DeleteRoom(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
ctx := NewLoggerContext(t.Context(), logger)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
ctx := log.NewLoggerContext(t.Context(), logger)
|
||||
assert := assert.New(t)
|
||||
u, ping := NewRoomPingForTest(ctx, t)
|
||||
|
||||
|
|
|
|||
22
room_test.go
22
room_test.go
|
|
@ -34,6 +34,8 @@ import (
|
|||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
func TestRoom_InCall(t *testing.T) {
|
||||
|
|
@ -77,8 +79,8 @@ func TestRoom_InCall(t *testing.T) {
|
|||
|
||||
func TestRoom_Update(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
ctx := NewLoggerContext(t.Context(), logger)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
ctx := log.NewLoggerContext(t.Context(), logger)
|
||||
require := require.New(t)
|
||||
assert := assert.New(t)
|
||||
hub, _, router, server := CreateHubForTest(t)
|
||||
|
|
@ -172,8 +174,8 @@ loop:
|
|||
|
||||
func TestRoom_Delete(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
ctx := NewLoggerContext(t.Context(), logger)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
ctx := log.NewLoggerContext(t.Context(), logger)
|
||||
require := require.New(t)
|
||||
assert := assert.New(t)
|
||||
hub, _, router, server := CreateHubForTest(t)
|
||||
|
|
@ -270,8 +272,8 @@ loop:
|
|||
|
||||
func TestRoom_RoomJoinFeatures(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
ctx := NewLoggerContext(t.Context(), logger)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
ctx := log.NewLoggerContext(t.Context(), logger)
|
||||
require := require.New(t)
|
||||
assert := assert.New(t)
|
||||
hub, _, router, server := CreateHubForTest(t)
|
||||
|
|
@ -308,8 +310,8 @@ func TestRoom_RoomJoinFeatures(t *testing.T) {
|
|||
|
||||
func TestRoom_RoomSessionData(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
ctx := NewLoggerContext(t.Context(), logger)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
ctx := log.NewLoggerContext(t.Context(), logger)
|
||||
require := require.New(t)
|
||||
assert := assert.New(t)
|
||||
hub, _, router, server := CreateHubForTest(t)
|
||||
|
|
@ -352,8 +354,8 @@ func TestRoom_RoomSessionData(t *testing.T) {
|
|||
|
||||
func TestRoom_InCallAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
ctx := NewLoggerContext(t.Context(), logger)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
ctx := log.NewLoggerContext(t.Context(), logger)
|
||||
require := require.New(t)
|
||||
assert := assert.New(t)
|
||||
hub, _, router, server := CreateHubForTest(t)
|
||||
|
|
|
|||
|
|
@ -26,6 +26,8 @@ import (
|
|||
"errors"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
type BuiltinRoomSessions struct {
|
||||
|
|
@ -116,7 +118,7 @@ func (r *BuiltinRoomSessions) LookupSessionId(ctx context.Context, roomSessionId
|
|||
|
||||
var wg sync.WaitGroup
|
||||
var result atomic.Value
|
||||
logger := LoggerFromContext(ctx)
|
||||
logger := log.LoggerFromContext(ctx)
|
||||
for _, client := range clients {
|
||||
wg.Add(1)
|
||||
go func(client *GrpcClient) {
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ import (
|
|||
"github.com/nats-io/nats.go"
|
||||
|
||||
signaling "github.com/strukturag/nextcloud-spreed-signaling"
|
||||
signalinglog "github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
@ -93,7 +94,7 @@ func createTLSListener(addr string, certFile, keyFile string) (net.Listener, err
|
|||
}
|
||||
|
||||
type Listeners struct {
|
||||
logger signaling.Logger // +checklocksignore
|
||||
logger signalinglog.Logger // +checklocksignore
|
||||
mu sync.Mutex
|
||||
// +checklocks:mu
|
||||
listeners []net.Listener
|
||||
|
|
@ -134,7 +135,7 @@ func main() {
|
|||
defer stop()
|
||||
|
||||
logger := log.Default()
|
||||
stopCtx = signaling.NewLoggerContext(stopCtx, logger)
|
||||
stopCtx = signalinglog.NewLoggerContext(stopCtx, logger)
|
||||
|
||||
if *cpuprofile != "" {
|
||||
f, err := os.Create(*cpuprofile)
|
||||
|
|
|
|||
|
|
@ -28,6 +28,8 @@ import (
|
|||
"strconv"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -276,7 +278,7 @@ func (t *memoryThrottler) CheckBruteforce(ctx context.Context, client string, ac
|
|||
if l >= maxBruteforceAttempts {
|
||||
delta := now.Sub(entries[l-maxBruteforceAttempts].ts)
|
||||
if delta <= maxBruteforceDurationThreshold {
|
||||
logger := LoggerFromContext(ctx)
|
||||
logger := log.LoggerFromContext(ctx)
|
||||
logger.Printf("Detected bruteforce attempt on \"%s\" from %s", action, client)
|
||||
statsThrottleBruteforceTotal.WithLabelValues(action).Inc()
|
||||
return doThrottle, ErrBruteforceDetected
|
||||
|
|
@ -301,7 +303,7 @@ func (t *memoryThrottler) throttle(ctx context.Context, client string, action st
|
|||
}
|
||||
count := t.addEntry(client, action, entry)
|
||||
delay := t.getDelay(count - 1)
|
||||
logger := LoggerFromContext(ctx)
|
||||
logger := log.LoggerFromContext(ctx)
|
||||
logger.Printf("Failed attempt on \"%s\" from %s, throttling by %s", action, client, delay)
|
||||
statsThrottleDelayedTotal.WithLabelValues(action, strconv.FormatInt(delay.Milliseconds(), 10)).Inc()
|
||||
t.doDelay(ctx, delay)
|
||||
|
|
|
|||
|
|
@ -28,6 +28,8 @@ import (
|
|||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
func newMemoryThrottlerForTest(t *testing.T) Throttler {
|
||||
|
|
@ -72,8 +74,8 @@ func TestThrottler(t *testing.T) {
|
|||
assert := assert.New(t)
|
||||
th := newMemoryThrottlerForTest(t)
|
||||
|
||||
logger := NewLoggerForTest(t)
|
||||
ctx := NewLoggerContext(t.Context(), logger)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
ctx := log.NewLoggerContext(t.Context(), logger)
|
||||
|
||||
throttle1, err := th.CheckBruteforce(ctx, "192.168.0.1", "action1")
|
||||
assert.NoError(err)
|
||||
|
|
@ -107,8 +109,8 @@ func TestThrottlerIPv6(t *testing.T) {
|
|||
assert := assert.New(t)
|
||||
th := newMemoryThrottlerForTest(t)
|
||||
|
||||
logger := NewLoggerForTest(t)
|
||||
ctx := NewLoggerContext(t.Context(), logger)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
ctx := log.NewLoggerContext(t.Context(), logger)
|
||||
|
||||
// Make sure full /64 subnets are throttled for IPv6.
|
||||
throttle1, err := th.CheckBruteforce(ctx, "2001:db8:abcd:0012::1", "action1")
|
||||
|
|
@ -145,8 +147,8 @@ func TestThrottler_Bruteforce(t *testing.T) {
|
|||
assert := assert.New(t)
|
||||
th := newMemoryThrottlerForTest(t)
|
||||
|
||||
logger := NewLoggerForTest(t)
|
||||
ctx := NewLoggerContext(t.Context(), logger)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
ctx := log.NewLoggerContext(t.Context(), logger)
|
||||
|
||||
delay := 100 * time.Millisecond
|
||||
for range maxBruteforceAttempts {
|
||||
|
|
@ -174,8 +176,8 @@ func TestThrottler_Cleanup(t *testing.T) {
|
|||
th, ok := throttler.(*memoryThrottler)
|
||||
require.True(t, ok, "required memoryThrottler, got %T", throttler)
|
||||
|
||||
logger := NewLoggerForTest(t)
|
||||
ctx := NewLoggerContext(t.Context(), logger)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
ctx := log.NewLoggerContext(t.Context(), logger)
|
||||
|
||||
throttle1, err := th.CheckBruteforce(ctx, "192.168.0.1", "action1")
|
||||
assert.NoError(err)
|
||||
|
|
@ -229,8 +231,8 @@ func TestThrottler_ExpirePartial(t *testing.T) {
|
|||
assert := assert.New(t)
|
||||
th := newMemoryThrottlerForTest(t)
|
||||
|
||||
logger := NewLoggerForTest(t)
|
||||
ctx := NewLoggerContext(t.Context(), logger)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
ctx := log.NewLoggerContext(t.Context(), logger)
|
||||
|
||||
throttle1, err := th.CheckBruteforce(ctx, "192.168.0.1", "action1")
|
||||
assert.NoError(err)
|
||||
|
|
@ -262,8 +264,8 @@ func TestThrottler_ExpireAll(t *testing.T) {
|
|||
assert := assert.New(t)
|
||||
th := newMemoryThrottlerForTest(t)
|
||||
|
||||
logger := NewLoggerForTest(t)
|
||||
ctx := NewLoggerContext(t.Context(), logger)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
ctx := log.NewLoggerContext(t.Context(), logger)
|
||||
|
||||
throttle1, err := th.CheckBruteforce(ctx, "192.168.0.1", "action1")
|
||||
assert.NoError(err)
|
||||
|
|
@ -295,8 +297,8 @@ func TestThrottler_Negative(t *testing.T) {
|
|||
assert := assert.New(t)
|
||||
th := newMemoryThrottlerForTest(t)
|
||||
|
||||
logger := NewLoggerForTest(t)
|
||||
ctx := NewLoggerContext(t.Context(), logger)
|
||||
logger := log.NewLoggerForTest(t)
|
||||
ctx := log.NewLoggerContext(t.Context(), logger)
|
||||
|
||||
delay := 100 * time.Millisecond
|
||||
for range maxBruteforceAttempts * 10 {
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ import (
|
|||
"sync/atomic"
|
||||
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/api"
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/log"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -37,7 +38,7 @@ const (
|
|||
)
|
||||
|
||||
type VirtualSession struct {
|
||||
logger Logger
|
||||
logger log.Logger
|
||||
hub *Hub
|
||||
session *ClientSession
|
||||
privateId PrivateSessionId
|
||||
|
|
@ -192,7 +193,7 @@ func (s *VirtualSession) CloseWithFeedback(session Session, message *ClientMessa
|
|||
}
|
||||
|
||||
func (s *VirtualSession) notifyBackendRemoved(room *Room, session Session, message *ClientMessage) {
|
||||
ctx := NewLoggerContext(context.Background(), s.logger)
|
||||
ctx := log.NewLoggerContext(context.Background(), s.logger)
|
||||
ctx, cancel := context.WithTimeout(ctx, s.hub.backendTimeout)
|
||||
defer cancel()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue