<commit_before>package main

import (
	pkgErrors "errors"
	"flag"
	"fmt"
	"net"
	"net/http"
	"os"
	"strconv"

	"github.com/juju/errors"
	"github.com/peer-calls/peer-calls/server"
	"github.com/peer-calls/peer-calls/server/logger"
	"github.com/peer-calls/peer-calls/server/sfu"
)

const gitDescribe string = "v0.0.0"

func configure(log logger.Logger, args []string) (net.Listener, *server.StartStopper, error) {
	flags := flag.NewFlagSet("peer-calls", flag.ExitOnError)

	var configFilename string

	flags.StringVar(&configFilename, "c", "", "Config file to use")

	if err := flags.Parse(args); err != nil {
		return nil, nil, errors.Annotate(err, "parse flags")
	}

	configFiles := []string{}
	if configFilename != "" {
		configFiles = append(configFiles, configFilename)
	}
	c, err := server.ReadConfig(configFiles)
	if err != nil {
		return nil, nil, errors.Annotate(err, "read config")
	}

	log.Info(fmt.Sprintf("Using config: %+v", c), nil)
	// rooms := server.NewAdapterRoomManager(newAdapter.NewAdapter)
	tracks := sfu.NewTracksManager(log, c.Network.SFU.JitterBuffer)

	roomManagerFactory := server.NewRoomManagerFactory(server.RoomManagerFactoryParams{
		AdapterFactory: server.NewAdapterFactory(log, c.Store),
		Log:            log,
		TracksManager:  tracks,
	})
	rooms, _ := roomManagerFactory.NewRoomManager(c.Network)

	mux := server.NewMux(log, c.BaseURL, gitDescribe, c.Network, c.ICEServers, rooms, tracks, c.Prometheus)
	l, err := net.Listen("tcp", net.JoinHostPort(c.BindHost, strconv.Itoa(c.BindPort)))
	if err != nil {
		return nil, nil, errors.Annotate(err, "listen")
	}
	startStopper := server.NewStartStopper(server.ServerParams{
		TLSCertFile: c.TLS.Cert,
		TLSKeyFile:  c.TLS.Key,
	}, mux)
	return l, startStopper, nil
}

func start(args []string) (addr *net.TCPAddr, stop func() error, errChan <-chan error) {
	log := logger.New().
		WithConfig(
			logger.NewConfig(logger.ConfigMap{
				"**:sdp":     logger.LevelDisabled,
				"**:ws":      logger.LevelDisabled,
				"**:nack":    logger.LevelDisabled,
				"**:pion:**": logger.LevelWarn,
				"":           logger.LevelInfo,
			}),
		).
		WithConfig(logger.NewConfigFromString(os.Getenv("PEERCALLS_LOG"))). // FIXME use wildcards here
		WithFormatter(server.NewLogFormatter()).
		WithNamespaceAppended("main")

	ch := make(chan error, 1)
	l, startStopper, err := configure(log, args)
	if err != nil {
		ch <- errors.Annotate(err, "configure")
		close(ch)<commit_msg>Silence signaller and negotiator in logs<commit_after>package main

import (
	pkgErrors "errors"
	"flag"
	"fmt"
	"net"
	"net/http"
	"os"
	"strconv"

	"github.com/juju/errors"
	"github.com/peer-calls/peer-calls/server"
	"github.com/peer-calls/peer-calls/server/logger"
	"github.com/peer-calls/peer-calls/server/sfu"
)

const gitDescribe string = "v0.0.0"

func configure(log logger.Logger, args []string) (net.Listener, *server.StartStopper, error) {
	flags := flag.NewFlagSet("peer-calls", flag.ExitOnError)

	var configFilename string

	flags.StringVar(&configFilename, "c", "", "Config file to use")

	if err := flags.Parse(args); err != nil {
		return nil, nil, errors.Annotate(err, "parse flags")
	}

	configFiles := []string{}
	if configFilename != "" {
		configFiles = append(configFiles, configFilename)
	}
	c, err := server.ReadConfig(configFiles)
	if err != nil {
		return nil, nil, errors.Annotate(err, "read config")
	}

	log.Info(fmt.Sprintf("Using config: %+v", c), nil)
	// rooms := server.NewAdapterRoomManager(newAdapter.NewAdapter)
	tracks := sfu.NewTracksManager(log, c.Network.SFU.JitterBuffer)

	roomManagerFactory := server.NewRoomManagerFactory(server.RoomManagerFactoryParams{
		AdapterFactory: server.NewAdapterFactory(log, c.Store),
		Log:            log,
		TracksManager:  tracks,
	})
	rooms, _ := roomManagerFactory.NewRoomManager(c.Network)

	mux := server.NewMux(log, c.BaseURL, gitDescribe, c.Network, c.ICEServers, rooms, tracks, c.Prometheus)
	l, err := net.Listen("tcp", net.JoinHostPort(c.BindHost, strconv.Itoa(c.BindPort)))
	if err != nil {
		return nil, nil, errors.Annotate(err, "listen")
	}
	startStopper := server.NewStartStopper(server.ServerParams{
		TLSCertFile: c.TLS.Cert,
		TLSKeyFile:  c.TLS.Key,
	}, mux)
	return l, startStopper, nil
}

func start(args []string) (addr *net.TCPAddr, stop func() error, errChan <-chan error) {
	log := logger.New().
		WithConfig(
			logger.NewConfig(logger.ConfigMap{
				"**:sdp":          logger.LevelError,
				"**:ws":           logger.LevelError,
				"**:nack":         logger.LevelError,
				"**:signaller:**": logger.LevelError,
				"**:pion:**":      logger.LevelWarn,
				"":                logger.LevelInfo,
			}),
		).
		WithConfig(logger.NewConfigFromString(os.Getenv("PEERCALLS_LOG"))). // FIXME use wildcards here
		WithFormatter(server.NewLogFormatter()).
		WithNamespaceAppended("main")

	ch := make(chan error, 1)
	l, startStopper, err := configure(log, args)
	if err != nil {
		ch <- errors.Annotate(err, "configure")
		close(ch)
{'fraction_non_alphanumeric': 0.15757697725900582, 'fraction_numerical': 0.0016099818877037633, 'mean_word_length': 4.287234042553192, 'pattern_counts': {'":': 11, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6040231', 'n_tokens_mistral': 1839, 'n_tokens_neox': 1753, 'n_words': 346}