krystv's picture
Upload crates/bex-core/src/config.rs
3587b18 verified
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,
}
}
}