File size: 2,548 Bytes
3374e90
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3587b18
 
 
 
3374e90
 
 
 
3587b18
3374e90
 
 
 
 
 
 
3587b18
3374e90
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
use bex_types::engine_types::LogLevel;
use std::path::PathBuf;

#[derive(Debug, Clone)]
pub struct EngineConfig {
    pub data_dir: PathBuf,
    pub host_version: String,
    pub user_agent: String,
    pub http_timeout_ms: u32,
    pub memory_limit_mb: u32,
    pub fuel_per_call: u64,
    pub fuel_compute_heavy: u64,
    pub fuel_io_heavy: u64,
    pub call_timeout_ms: u32,
    pub max_response_bytes: u64,
    pub max_concurrent_calls: usize,
    pub log_level: LogLevel,
    pub epoch_interval_ms: u64,
    pub circuit_breaker_threshold: u32,
    pub circuit_breaker_cooldown_ms: u64,
    pub http_pool_idle_timeout_ms: u64,
    pub http_pool_max_idle_per_host: usize,
    // JS Pool configuration
    pub js_initial_workers: usize,
    pub js_max_workers: usize,
    pub js_memory_limit_mb: u32,
    pub js_timeout_ms: u32,
    pub js_context_idle_ttl_secs: u64,
    pub js_worker_idle_ttl_secs: u64,
    pub js_max_stack_bytes: usize,
}

impl Default for EngineConfig {
    fn default() -> Self {
        let cpu_count = std::thread::available_parallelism()
            .map(|n| n.get())
            .unwrap_or(2);
        Self {
            data_dir: PathBuf::from("./bex"),
            host_version: "1.0.0".into(),
            // CRITICAL: Use a real browser User-Agent, NOT "BexEngine/6.0"
            // The old "BexEngine/6.0" was immediately flagged by Cloudflare
            user_agent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36".into(),
            http_timeout_ms: 30_000,   // Increased from 15s — some CF challenges take time
            memory_limit_mb: 64,
            fuel_per_call: 500_000_000,
            fuel_compute_heavy: 1_000_000_000,
            fuel_io_heavy: 100_000_000,
            call_timeout_ms: 30_000,   // Increased from 15s for CF challenge pages
            max_response_bytes: 10 * 1024 * 1024,
            max_concurrent_calls: 32,
            log_level: LogLevel::Info,
            epoch_interval_ms: 50,
            circuit_breaker_threshold: 5,
            circuit_breaker_cooldown_ms: 30_000,
            http_pool_idle_timeout_ms: 90_000,
            http_pool_max_idle_per_host: 8,  // Increased for better connection reuse
            js_initial_workers: 2,
            js_max_workers: cpu_count.min(4),
            js_memory_limit_mb: 32,
            js_timeout_ms: 10_000,
            js_context_idle_ttl_secs: 300,
            js_worker_idle_ttl_secs: 120,
            js_max_stack_bytes: 512 * 1024,
        }
    }
}