Compare commits

..

No commits in common. "ca43645ef113ff48ff646bd315c19748503a2ed1" and "6737718f08dfc8c2057d8933b9c2bbf707432271" have entirely different histories.

7 changed files with 13 additions and 13 deletions

View File

@ -32,7 +32,7 @@ type RateLimiter struct {
var rateLimiterInstance *RateLimiter var rateLimiterInstance *RateLimiter
var rateOnce sync.Once var rateOnce sync.Once
func SetRateLimit(cfg *config.ServerConfig) { func SetupRateLimiter(cfg *config.ServerConfig) {
rateLimiter := NewRateLimiter( rateLimiter := NewRateLimiter(
rate.Limit(cfg.RateLimit.WsLimit), rate.Limit(cfg.RateLimit.WsLimit),
cfg.RateLimit.WsBurst, cfg.RateLimit.WsBurst,

View File

@ -12,13 +12,13 @@ type SizeLimiter struct {
mu sync.RWMutex mu sync.RWMutex
} }
func SetSizeLimit(cfg *config.ServerConfig) { func SetupSizeLimiter(cfg *config.ServerConfig) {
sizeLimiter := NewSizeLimiter(cfg.RateLimit.MaxEventSize) sizeLimiter := NewSizeLimiter(cfg.RateLimit.MaxEventSize)
for _, kindSizeLimit := range cfg.RateLimit.KindSizeLimits { for _, kindSizeLimit := range cfg.RateLimit.KindSizeLimits {
sizeLimiter.AddKindSizeLimit(kindSizeLimit.Kind, kindSizeLimit.MaxSize) sizeLimiter.AddKindSizeLimit(kindSizeLimit.Kind, kindSizeLimit.MaxSize)
} }
SizeLimit(sizeLimiter) SetSizeLimiter(sizeLimiter)
} }
func NewSizeLimiter(globalMaxSize int) *SizeLimiter { func NewSizeLimiter(globalMaxSize int) *SizeLimiter {
@ -35,7 +35,7 @@ func GetSizeLimiter() *SizeLimiter {
return sizeLimiterInstance return sizeLimiterInstance
} }
func SizeLimit(sl *SizeLimiter) { func SetSizeLimiter(sl *SizeLimiter) {
sizeOnce.Do(func() { sizeOnce.Do(func() {
sizeLimiterInstance = sl sizeLimiterInstance = sl
}) })

View File

@ -25,7 +25,7 @@ func main() {
utils.EnsureFileExists("relay_metadata.json", "app/static/examples/relay_metadata.example.json") utils.EnsureFileExists("relay_metadata.json", "app/static/examples/relay_metadata.example.json")
restartChan := make(chan struct{}) restartChan := make(chan struct{})
go config.WatchConfigFile("config.yml", restartChan) // Critical goroutine go utils.WatchConfigFile("config.yml", restartChan) // Critical goroutine
signalChan := make(chan os.Signal, 1) signalChan := make(chan os.Signal, 1)
signal.Notify(signalChan, syscall.SIGINT, syscall.SIGTERM) signal.Notify(signalChan, syscall.SIGINT, syscall.SIGTERM)
@ -39,15 +39,15 @@ func main() {
log.Fatal("Error loading config: ", err) log.Fatal("Error loading config: ", err)
} }
config.SetResourceLimit(&cfg.ResourceLimits) // Apply limits once before starting the server utils.ApplyResourceLimits(&cfg.ResourceLimits) // Apply limits once before starting the server
client, err := db.InitDB(cfg) client, err := db.InitDB(cfg)
if err != nil { if err != nil {
log.Fatal("Error initializing database: ", err) log.Fatal("Error initializing database: ", err)
} }
config.SetRateLimit(cfg) config.SetupRateLimiter(cfg)
config.SetSizeLimit(cfg) config.SetupSizeLimiter(cfg)
config.ClearTemporaryBans() config.ClearTemporaryBans()

View File

@ -16,7 +16,7 @@ import (
) )
func HandleEvent(ws *websocket.Conn, message []interface{}) { func HandleEvent(ws *websocket.Conn, message []interface{}) {
config.LimitedGoRoutine(func() { utils.LimitedGoRoutine(func() {
if len(message) != 2 { if len(message) != 2 {
fmt.Println("Invalid EVENT message format") fmt.Println("Invalid EVENT message format")
response.SendNotice(ws, "", "Invalid EVENT message format") response.SendNotice(ws, "", "Invalid EVENT message format")

View File

@ -17,7 +17,7 @@ var subscriptions = make(map[string]relay.Subscription)
var mu sync.Mutex // Protect concurrent access to subscriptions map var mu sync.Mutex // Protect concurrent access to subscriptions map
func HandleReq(ws *websocket.Conn, message []interface{}, subscriptions map[string][]relay.Filter) { func HandleReq(ws *websocket.Conn, message []interface{}, subscriptions map[string][]relay.Filter) {
config.LimitedGoRoutine(func() { utils.LimitedGoRoutine(func() {
if len(message) < 3 { if len(message) < 3 {
fmt.Println("Invalid REQ message format") fmt.Println("Invalid REQ message format")
response.SendClosed(ws, "", "invalid: invalid REQ message format") response.SendClosed(ws, "", "invalid: invalid REQ message format")

View File

@ -1,4 +1,4 @@
package config package utils
import ( import (
"log" "log"
@ -17,7 +17,7 @@ var (
goroutineQueueMutex sync.Mutex goroutineQueueMutex sync.Mutex
) )
func SetResourceLimit(cfg *configTypes.ResourceLimits) { func ApplyResourceLimits(cfg *configTypes.ResourceLimits) {
// Set CPU cores // Set CPU cores
runtime.GOMAXPROCS(cfg.CPUCores) runtime.GOMAXPROCS(cfg.CPUCores)

View File

@ -1,4 +1,4 @@
package config package utils
import ( import (
"fmt" "fmt"