Send workers, Batch/AES encryption

This commit is contained in:
Amin.MasterkinG
2026-04-20 19:02:14 +03:30
parent e06c766ca9
commit abb764bce8
5 changed files with 285 additions and 0 deletions
+31
View File
@@ -17,6 +17,7 @@ import (
type Config struct {
AESEncryptionKey string
RelayURL string
SOCKSHost string
SOCKSPort int
SOCKSAuth bool
@@ -27,6 +28,8 @@ type Config struct {
MaxPacketsPerBatch int
MaxBatchBytes int
WorkerCount int
HTTPRequestTimeoutMS int
WorkerPollIntervalMS int
MaxQueueBytesPerSOCKS int
}
@@ -39,6 +42,8 @@ func Load(path string) (Config, error) {
MaxPacketsPerBatch: 32,
MaxBatchBytes: 256 * 1024,
WorkerCount: 4,
HTTPRequestTimeoutMS: 15000,
WorkerPollIntervalMS: 200,
MaxQueueBytesPerSOCKS: 1024 * 1024,
}
@@ -66,6 +71,8 @@ func Load(path string) (Config, error) {
switch key {
case "AES_ENCRYPTION_KEY":
cfg.AESEncryptionKey = trimString(value)
case "RELAY_URL":
cfg.RelayURL = trimString(value)
case "SOCKS_HOST":
cfg.SOCKSHost = trimString(value)
case "SOCKS_PORT":
@@ -110,6 +117,18 @@ func Load(path string) (Config, error) {
return Config{}, fmt.Errorf("parse WORKER_COUNT: %w", err)
}
cfg.WorkerCount = count
case "HTTP_REQUEST_TIMEOUT_MS":
timeout, err := strconv.Atoi(value)
if err != nil {
return Config{}, fmt.Errorf("parse HTTP_REQUEST_TIMEOUT_MS: %w", err)
}
cfg.HTTPRequestTimeoutMS = timeout
case "WORKER_POLL_INTERVAL_MS":
interval, err := strconv.Atoi(value)
if err != nil {
return Config{}, fmt.Errorf("parse WORKER_POLL_INTERVAL_MS: %w", err)
}
cfg.WorkerPollIntervalMS = interval
case "MAX_QUEUE_BYTES_PER_SOCKS":
size, err := strconv.Atoi(value)
if err != nil {
@@ -130,6 +149,12 @@ func Load(path string) (Config, error) {
if cfg.SOCKSPort < 1 || cfg.SOCKSPort > 65535 {
return Config{}, fmt.Errorf("invalid SOCKS_PORT: %d", cfg.SOCKSPort)
}
if strings.TrimSpace(cfg.RelayURL) == "" {
return Config{}, fmt.Errorf("RELAY_URL is required")
}
if strings.TrimSpace(cfg.AESEncryptionKey) == "" {
return Config{}, fmt.Errorf("AES_ENCRYPTION_KEY is required")
}
if cfg.MaxChunkSize < 1 {
return Config{}, fmt.Errorf("invalid MAX_CHUNK_SIZE: %d", cfg.MaxChunkSize)
@@ -146,6 +171,12 @@ func Load(path string) (Config, error) {
if cfg.WorkerCount < 1 {
return Config{}, fmt.Errorf("invalid WORKER_COUNT: %d", cfg.WorkerCount)
}
if cfg.HTTPRequestTimeoutMS < 1 {
return Config{}, fmt.Errorf("invalid HTTP_REQUEST_TIMEOUT_MS: %d", cfg.HTTPRequestTimeoutMS)
}
if cfg.WorkerPollIntervalMS < 1 {
return Config{}, fmt.Errorf("invalid WORKER_POLL_INTERVAL_MS: %d", cfg.WorkerPollIntervalMS)
}
if cfg.MaxQueueBytesPerSOCKS < cfg.MaxChunkSize {
return Config{}, fmt.Errorf("MAX_QUEUE_BYTES_PER_SOCKS must be >= MAX_CHUNK_SIZE")