refactor: standardize logging on zap across all packages

Replace all fmt.Printf/Println and log.Printf/Fatal with structured
zap.Logger calls to eliminate inconsistent logging (anti-pattern #12).

- network/crypt_conn: inject logger via NewCryptConn, replace 6 fmt calls
- signserver/session: use existing s.logger for debug packet dumps
- entranceserver: use s.logger for inbound/outbound debug logging
- api/utils: accept logger param in verifyPath, replace fmt.Println
- api/endpoints: use s.logger for screenshot path diagnostics
- config: replace log.Fatal with error return in getOutboundIP4
- deltacomp: replace log.Printf with zap.L() global logger
This commit is contained in:
Houmgaor
2026-02-20 18:59:12 +01:00
parent e5133e5dcf
commit 06cb3afa57
15 changed files with 134 additions and 117 deletions

View File

@@ -2,9 +2,9 @@ package network
import (
"bytes"
"errors"
_config "erupe-ce/config"
"erupe-ce/network/crypto"
"errors"
"io"
"net"
"testing"
@@ -54,7 +54,7 @@ func (m *mockConn) SetWriteDeadline(t time.Time) error { return nil }
func TestNewCryptConn(t *testing.T) {
mockConn := newMockConn(nil)
cc := NewCryptConn(mockConn, _config.ZZ)
cc := NewCryptConn(mockConn, _config.ZZ, nil)
if cc == nil {
t.Fatal("NewCryptConn() returned nil")
@@ -111,7 +111,7 @@ func TestCryptConn_SendPacket(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
mockConn := newMockConn(nil)
cc := NewCryptConn(mockConn, _config.ZZ)
cc := NewCryptConn(mockConn, _config.ZZ, nil)
err := cc.SendPacket(tt.data)
if err != nil {
@@ -155,7 +155,7 @@ func TestCryptConn_SendPacket(t *testing.T) {
func TestCryptConn_SendPacket_MultiplePackets(t *testing.T) {
mockConn := newMockConn(nil)
cc := NewCryptConn(mockConn, _config.ZZ)
cc := NewCryptConn(mockConn, _config.ZZ, nil)
// Send first packet
err := cc.SendPacket([]byte{0x01, 0x02})
@@ -190,7 +190,7 @@ func TestCryptConn_SendPacket_MultiplePackets(t *testing.T) {
func TestCryptConn_SendPacket_KeyRotation(t *testing.T) {
mockConn := newMockConn(nil)
cc := NewCryptConn(mockConn, _config.ZZ)
cc := NewCryptConn(mockConn, _config.ZZ, nil)
initialKey := cc.sendKeyRot
@@ -209,7 +209,7 @@ func TestCryptConn_SendPacket_KeyRotation(t *testing.T) {
func TestCryptConn_SendPacket_WriteError(t *testing.T) {
mockConn := newMockConn(nil)
mockConn.writeErr = errors.New("write error")
cc := NewCryptConn(mockConn, _config.ZZ)
cc := NewCryptConn(mockConn, _config.ZZ, nil)
err := cc.SendPacket([]byte{0x01, 0x02, 0x03})
// Note: Current implementation doesn't return write error
@@ -244,7 +244,7 @@ func TestCryptConn_ReadPacket_Success(t *testing.T) {
packet := append(headerBytes, encryptedData...)
mockConn := newMockConn(packet)
cc := NewCryptConn(mockConn, _config.Z1)
cc := NewCryptConn(mockConn, _config.Z1, nil)
// Set the key to match what we used for encryption
cc.readKeyRot = key
@@ -290,7 +290,7 @@ func TestCryptConn_ReadPacket_KeyRotation(t *testing.T) {
packet := append(headerBytes, encryptedData...)
mockConn := newMockConn(packet)
cc := NewCryptConn(mockConn, _config.Z1)
cc := NewCryptConn(mockConn, _config.Z1, nil)
cc.readKeyRot = key
result, err := cc.ReadPacket()
@@ -330,7 +330,7 @@ func TestCryptConn_ReadPacket_NoKeyRotation(t *testing.T) {
packet := append(headerBytes, encryptedData...)
mockConn := newMockConn(packet)
cc := NewCryptConn(mockConn, _config.Z1)
cc := NewCryptConn(mockConn, _config.Z1, nil)
cc.readKeyRot = key
originalKeyRot := cc.readKeyRot
@@ -352,7 +352,7 @@ func TestCryptConn_ReadPacket_NoKeyRotation(t *testing.T) {
func TestCryptConn_ReadPacket_HeaderReadError(t *testing.T) {
mockConn := newMockConn([]byte{0x01, 0x02}) // Only 2 bytes, header needs 14
cc := NewCryptConn(mockConn, _config.ZZ)
cc := NewCryptConn(mockConn, _config.ZZ, nil)
_, err := cc.ReadPacket()
if err == nil {
@@ -368,7 +368,7 @@ func TestCryptConn_ReadPacket_InvalidHeader(t *testing.T) {
// Create invalid header data (wrong endianness or malformed)
invalidHeader := []byte{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}
mockConn := newMockConn(invalidHeader)
cc := NewCryptConn(mockConn, _config.ZZ)
cc := NewCryptConn(mockConn, _config.ZZ, nil)
_, err := cc.ReadPacket()
if err == nil {
@@ -395,7 +395,7 @@ func TestCryptConn_ReadPacket_BodyReadError(t *testing.T) {
packet := append(headerBytes, incompleteBody...)
mockConn := newMockConn(packet)
cc := NewCryptConn(mockConn, _config.Z1)
cc := NewCryptConn(mockConn, _config.Z1, nil)
_, err := cc.ReadPacket()
if err == nil {
@@ -425,7 +425,7 @@ func TestCryptConn_ReadPacket_ChecksumMismatch(t *testing.T) {
packet := append(headerBytes, encryptedData...)
mockConn := newMockConn(packet)
cc := NewCryptConn(mockConn, _config.Z1)
cc := NewCryptConn(mockConn, _config.Z1, nil)
cc.readKeyRot = key
_, err := cc.ReadPacket()