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 rateOnce sync.Once
func SetRateLimit(cfg *config.ServerConfig) {
func SetupRateLimiter(cfg *config.ServerConfig) {
rateLimiter := NewRateLimiter(
rate.Limit(cfg.RateLimit.WsLimit),
cfg.RateLimit.WsBurst,

View File

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

View File

@ -25,7 +25,7 @@ func main() {
utils.EnsureFileExists("relay_metadata.json", "app/static/examples/relay_metadata.example.json")
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)
signal.Notify(signalChan, syscall.SIGINT, syscall.SIGTERM)
@ -39,15 +39,15 @@ func main() {
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)
if err != nil {
log.Fatal("Error initializing database: ", err)
}
config.SetRateLimit(cfg)
config.SetSizeLimit(cfg)
config.SetupRateLimiter(cfg)
config.SetupSizeLimiter(cfg)
config.ClearTemporaryBans()

View File

@ -16,7 +16,7 @@ import (
)
func HandleEvent(ws *websocket.Conn, message []interface{}) {
config.LimitedGoRoutine(func() {
utils.LimitedGoRoutine(func() {
if len(message) != 2 {
fmt.Println("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
func HandleReq(ws *websocket.Conn, message []interface{}, subscriptions map[string][]relay.Filter) {
config.LimitedGoRoutine(func() {
utils.LimitedGoRoutine(func() {
if len(message) < 3 {
fmt.Println("Invalid REQ message format")
response.SendClosed(ws, "", "invalid: invalid REQ message format")

View File

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

View File

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