mirror of
https://github.com/Gouryella/drip.git
synced 2026-02-26 14:21:17 +00:00
- Reduce inspection intervals and cooling times to improve response speed - Added burst load handling mechanism to support batch expansion. - Introduced the GetSessionStats method to retrieve detailed statistics for each session. - Create data sessions concurrently to accelerate scaling. - Added a ping loop keep-alive mechanism for each session. feat(server): Enhance tunnel management and security restrictions - Implement IP-based tunnel number and registration frequency limits - Add a rate limiter to prevent malicious registration behavior. - Improved shutdown process to ensure proper exit of cleanup coroutines. - Introduce atomic operations to tunnel connections to improve concurrency performance - Track client IP addresses for access control perf(server): Improves HTTP request processing performance and resource reuse. - Use sync.Pool to reuse bufio.Writer to reduce GC pressure. - Enable TCP_NODELAY to improve response speed - Adjust HTTP server timeout configuration to balance performance and security refactor(proxy): Optimizes the stream open timeout control logic - Use context to control timeouts and avoid goroutine leaks. - Ensure that established connections are properly closed upon timeout. docs(test): Upgrade one-click test scripts to Go test service - Replace Python's built-in server with a high-performance Go implementation - Update dependency checks: Use Go instead of Python 3 - Enhanced startup log output for easier debugging chore(shared): Enhances the security and consistency of the ID generator. - Remove the timestamp fallback scheme and uniformly adopt crypto/rand. - Added TryGenerateID to provide a non-panic error handling method. - Define the maximum frame size explicitly and add comments to explain it. style(frame): Reduce memory allocation and optimize read performance - Use an array on the stack instead of heap allocation to read the frame header. - Reduced maximum frame size from 10MB to 1MB to decrease DoS risk.
37 lines
983 B
Go
37 lines
983 B
Go
package utils
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"encoding/hex"
|
|
"fmt"
|
|
)
|
|
|
|
// GenerateID generates a cryptographically secure random unique ID (32 hex chars).
|
|
// Panics if crypto/rand fails - this indicates a critical system issue.
|
|
func GenerateID() string {
|
|
b := make([]byte, 16)
|
|
if _, err := rand.Read(b); err != nil {
|
|
panic(fmt.Sprintf("crypto/rand failed: %v", err))
|
|
}
|
|
return hex.EncodeToString(b)
|
|
}
|
|
|
|
// GenerateShortID generates a cryptographically secure shorter random ID (8 hex chars).
|
|
// Panics if crypto/rand fails.
|
|
func GenerateShortID() string {
|
|
b := make([]byte, 4)
|
|
if _, err := rand.Read(b); err != nil {
|
|
panic(fmt.Sprintf("crypto/rand failed: %v", err))
|
|
}
|
|
return hex.EncodeToString(b)
|
|
}
|
|
|
|
// TryGenerateID returns an ID or error (for cases where panic is not desired).
|
|
func TryGenerateID() (string, error) {
|
|
b := make([]byte, 16)
|
|
if _, err := rand.Read(b); err != nil {
|
|
return "", fmt.Errorf("crypto/rand failed: %w", err)
|
|
}
|
|
return hex.EncodeToString(b), nil
|
|
}
|