use crate::networking::{Quorum, RetryStrategy, Strategy};
pub use ant_bootstrap::{
Bootstrap, BootstrapConfig, InitialPeersConfig, error::Error as BootstrapError,
};
use ant_evm::EvmNetwork;
use evmlib::contract::payment_vault::MAX_TRANSFERS_PER_TRANSACTION;
use std::{num::NonZero, sync::LazyLock};
pub(crate) static CHUNK_UPLOAD_BATCH_SIZE: LazyLock<usize> = LazyLock::new(|| {
let batch_size = std::env::var("CHUNK_UPLOAD_BATCH_SIZE")
.ok()
.and_then(|s| s.parse().ok())
.unwrap_or(1);
info!("Chunk upload batch size: {}", batch_size);
batch_size
});
pub static CHUNK_DOWNLOAD_BATCH_SIZE: LazyLock<usize> = LazyLock::new(|| {
let batch_size = std::env::var("CHUNK_DOWNLOAD_BATCH_SIZE")
.ok()
.and_then(|s| s.parse().ok())
.unwrap_or(1);
info!("Chunk download batch size: {}", batch_size);
batch_size
});
pub static MAX_IN_MEMORY_DOWNLOAD_SIZE: LazyLock<usize> = LazyLock::new(|| {
let size = std::env::var("MAX_IN_MEMORY_DOWNLOAD_SIZE")
.ok()
.and_then(|s| s.parse().ok())
.unwrap_or(20);
info!("Max in memory download size: {}", size);
size
});
pub static FILE_UPLOAD_BATCH_SIZE: LazyLock<usize> = LazyLock::new(|| {
let batch_size = std::env::var("FILE_UPLOAD_BATCH_SIZE")
.ok()
.and_then(|s| s.parse().ok())
.unwrap_or(1);
info!("File upload batch size: {}", batch_size);
batch_size
});
pub static FILE_ENCRYPT_BATCH_SIZE: LazyLock<usize> = LazyLock::new(|| {
let batch_size = std::env::var("FILE_ENCRYPT_BATCH_SIZE")
.ok()
.and_then(|s| s.parse().ok())
.unwrap_or(
std::thread::available_parallelism()
.map(|n| n.get())
.unwrap_or(1)
* 8,
);
info!("File encryption batch size: {}", batch_size);
batch_size
});
pub static IN_MEMORY_ENCRYPTION_MAX_SIZE: LazyLock<usize> = LazyLock::new(|| {
let max_size = std::env::var("IN_MEMORY_ENCRYPTION_MAX_SIZE")
.ok()
.and_then(|s| s.parse().ok())
.unwrap_or(10_000_000);
info!(
"IN_MEMORY_ENCRYPTION_MAX_SIZE (from that threshold, the file will be encrypted in a stream): {}",
max_size
);
max_size
});
pub(crate) static UPLOAD_FLOW_BATCH_SIZE: LazyLock<usize> = LazyLock::new(|| {
let batch_size = std::env::var("UPLOAD_FLOW_BATCH_SIZE")
.ok()
.and_then(|s| s.parse().ok())
.unwrap_or(MAX_TRANSFERS_PER_TRANSACTION / 3);
info!("Upload flow batch size: {}", batch_size);
batch_size
});
#[derive(Debug, Clone, Default)]
pub struct ClientConfig {
pub bootstrap_config: BootstrapConfig,
pub evm_network: EvmNetwork,
pub network_id: Option<u8>,
pub strategy: ClientOperatingStrategy,
}
#[derive(Debug, Clone)]
pub struct ClientOperatingStrategy {
pub chunks: Strategy,
pub graph_entry: Strategy,
pub pointer: Strategy,
pub scratchpad: Strategy,
pub chunk_cache_enabled: bool,
pub chunk_cache_dir: Option<std::path::PathBuf>,
}
impl ClientOperatingStrategy {
pub fn new() -> Self {
Default::default()
}
}
impl Default for ClientOperatingStrategy {
fn default() -> Self {
let two = NonZero::new(2).expect("2 is non 0");
Self {
chunks: Strategy {
put_quorum: Quorum::N(two),
put_retry: RetryStrategy::Balanced,
verification_quorum: Quorum::N(two),
get_quorum: Quorum::One, get_retry: RetryStrategy::None, },
graph_entry: Strategy {
put_quorum: Quorum::Majority,
put_retry: RetryStrategy::Balanced,
verification_quorum: Quorum::N(two),
get_quorum: Quorum::N(two), get_retry: RetryStrategy::Quick,
},
pointer: Strategy {
put_quorum: Quorum::Majority,
put_retry: RetryStrategy::Balanced,
verification_quorum: Quorum::N(two),
get_quorum: Quorum::Majority, get_retry: RetryStrategy::Quick,
},
scratchpad: Strategy {
put_quorum: Quorum::Majority,
put_retry: RetryStrategy::Balanced,
verification_quorum: Quorum::N(two),
get_quorum: Quorum::Majority, get_retry: RetryStrategy::Quick,
},
chunk_cache_enabled: true,
chunk_cache_dir: None,
}
}
}