This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Model multi-thread environment, where each threads can handle | |
/// a single connection at a time. | |
async fn sync_execution( | |
n_workers: usize, | |
latency_distribution: &[u64], | |
n_jobs: usize, | |
rate_limiter: LeakyBucket, | |
) -> Vec<TaskStats> { | |
let mut threads = Vec::with_capacity(n_workers); | |
// partitioning to reduce contention |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn benchmark_batched_increment( | |
repetitions: usize, | |
mut increment: usize, | |
counter: &AtomicUsize) | |
{ | |
let mut batch = 0; | |
for _ in 0..repetitions { | |
// avoiding compiler optimizations | |
// E.g. go to https://rust.godbolt.org/z/7he65h | |
// and try to comment the line #4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[derive(Deserialize, Clone)] | |
pub struct TargetConnectionConfig { | |
#[serde(with = "humantime_serde")] | |
pub dns_cache_ttl: Duration, | |
#[serde(with = "serde_regex")] | |
pub allowed_targets: Regex, | |
#[serde(with = "humantime_serde")] | |
pub connect_timeout: Duration, | |
pub relay_policy: RelayPolicy, | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[derive(Parser, Debug)] | |
#[clap(author, version, about, long_about = None)] | |
#[clap(propagate_version = true)] | |
struct Cli { | |
/// Configuration file. | |
#[clap(long)] | |
config: Option<String>, | |
/// Bind address, e.g. 0.0.0.0:8443. | |
#[clap(long)] | |
bind: String, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Stats after the relay is closed. Can be used for telemetry/monitoring. | |
#[derive(Builder, Clone, Debug, Serialize)] | |
pub struct RelayStats { | |
pub shutdown_reason: RelayShutdownReasons, | |
pub total_bytes: usize, | |
pub event_count: usize, | |
pub duration: Duration, | |
} | |
/// Statistics. No sensitive information. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[tokio::test] | |
async fn test_timed_operation_failed_io() { | |
let mut mock_connection: Mock = Builder::new() | |
.read_error(Error::from(ErrorKind::BrokenPipe)) | |
.build(); | |
let relay_policy: RelayPolicy = RelayPolicyBuilder::default() | |
.min_rate_bpm(1000) | |
.max_rate_bps(100_000) | |
.idle_timeout(Duration::from_secs(5)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[tokio::test] | |
async fn test_timed_operation_timeout() { | |
let time_duration = 1; | |
let data = b"data on the wire"; | |
let mut mock_connection: Mock = Builder::new() | |
.wait(Duration::from_secs(time_duration * 2)) | |
.read(data) | |
.build(); | |
let relay_policy: RelayPolicy = RelayPolicyBuilder::default() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let read_result = self | |
.relay_policy | |
.timed_operation(source.read(&mut buffer)) | |
.await; | |
if read_result.is_err() { | |
shutdown_reason = RelayShutdownReasons::ReaderTimeout; | |
break; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub enum EstablishTunnelResult { | |
/// Successfully connected to target. | |
Ok, | |
/// Malformed request | |
BadRequest, | |
/// Target is not allowed | |
Forbidden, | |
/// Unsupported operation, however valid for the protocol. | |
OperationNotAllowed, | |
/// The client failed to send a tunnel request timely. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// A connection tunnel. | |
/// | |
/// # Parameters | |
/// * `<H>` - proxy handshake codec for initiating a tunnel. | |
/// It extracts the request message, which contains the target, and, potentially policies. | |
/// It also takes care of encoding a response. | |
/// * `<C>` - a connection from from client. | |
/// * `<T>` - target connector. It takes result produced by the codec and establishes a connection | |
/// to a target. | |
/// |
NewerOlder