mirror of
https://github.com/Mezeporta/Erupe.git
synced 2026-03-22 07:32:32 +01:00
perf(channelserver): cache rengoku_data.bin at startup
Load and validate rengoku_data.bin once during server initialization instead of reading it from disk on every client request. The file is static ECD-encrypted config data (~4.9 KB) that never changes at runtime. Validation checks file size and ECD magic bytes, logging a warning if the file is missing or invalid so misconfiguration is caught before any client connects.
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
package channelserver
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -727,3 +730,65 @@ func TestFindObjectByChar(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// --- loadRengokuBinary tests ---
|
||||
|
||||
func TestLoadRengokuBinary_ValidECD(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
// Build a minimal valid ECD file: magic + some payload
|
||||
data := make([]byte, 16)
|
||||
binary.LittleEndian.PutUint32(data[:4], ecdMagic)
|
||||
if err := os.WriteFile(filepath.Join(dir, "rengoku_data.bin"), data, 0644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
logger, _ := zap.NewDevelopment()
|
||||
result := loadRengokuBinary(dir, logger)
|
||||
|
||||
if result == nil {
|
||||
t.Fatal("Expected non-nil result for valid ECD file")
|
||||
}
|
||||
if len(result) != 16 {
|
||||
t.Errorf("len = %d, want 16", len(result))
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadRengokuBinary_MissingFile(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
logger, _ := zap.NewDevelopment()
|
||||
result := loadRengokuBinary(dir, logger)
|
||||
|
||||
if result != nil {
|
||||
t.Errorf("Expected nil for missing file, got %d bytes", len(result))
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadRengokuBinary_TooSmall(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
if err := os.WriteFile(filepath.Join(dir, "rengoku_data.bin"), []byte{0x65, 0x63}, 0644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
logger, _ := zap.NewDevelopment()
|
||||
result := loadRengokuBinary(dir, logger)
|
||||
|
||||
if result != nil {
|
||||
t.Errorf("Expected nil for too-small file, got %d bytes", len(result))
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadRengokuBinary_BadMagic(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
data := make([]byte, 16)
|
||||
binary.LittleEndian.PutUint32(data[:4], 0xDEADBEEF)
|
||||
if err := os.WriteFile(filepath.Join(dir, "rengoku_data.bin"), data, 0644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
logger, _ := zap.NewDevelopment()
|
||||
result := loadRengokuBinary(dir, logger)
|
||||
|
||||
if result != nil {
|
||||
t.Errorf("Expected nil for bad magic, got %d bytes", len(result))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user