|
@@ -5,13 +5,14 @@ use mgen::{log, updater::Updater, HandshakeRef, MessageHeader, SerializedMessage
|
|
use futures::future::try_join_all;
|
|
use futures::future::try_join_all;
|
|
use rand_xoshiro::{rand_core::SeedableRng, Xoshiro256PlusPlus};
|
|
use rand_xoshiro::{rand_core::SeedableRng, Xoshiro256PlusPlus};
|
|
use serde::Deserialize;
|
|
use serde::Deserialize;
|
|
|
|
+use std::hash::{Hash, Hasher};
|
|
use std::result::Result;
|
|
use std::result::Result;
|
|
use std::sync::Arc;
|
|
use std::sync::Arc;
|
|
use tokio::io::{split, AsyncWriteExt, ReadHalf, WriteHalf};
|
|
use tokio::io::{split, AsyncWriteExt, ReadHalf, WriteHalf};
|
|
use tokio::net::TcpStream;
|
|
use tokio::net::TcpStream;
|
|
use tokio::spawn;
|
|
use tokio::spawn;
|
|
use tokio::sync::mpsc;
|
|
use tokio::sync::mpsc;
|
|
-use tokio::time::Duration;
|
|
+use tokio::time::{sleep, Duration};
|
|
use tokio_rustls::{client::TlsStream, TlsConnector};
|
|
use tokio_rustls::{client::TlsStream, TlsConnector};
|
|
|
|
|
|
mod messenger;
|
|
mod messenger;
|
|
@@ -293,6 +294,7 @@ async fn socket_updater(
|
|
let tls_server_str = str_params.target.split(':').next().unwrap();
|
|
let tls_server_str = str_params.target.split(':').next().unwrap();
|
|
let tls_server_name =
|
|
let tls_server_name =
|
|
tokio_rustls::rustls::ServerName::try_from(tls_server_str).expect("invalid server name");
|
|
tokio_rustls::rustls::ServerName::try_from(tls_server_str).expect("invalid server name");
|
|
|
|
+
|
|
loop {
|
|
loop {
|
|
let stream: TcpStream = match connect(&str_params).await {
|
|
let stream: TcpStream = match connect(&str_params).await {
|
|
Ok(stream) => stream,
|
|
Ok(stream) => stream,
|
|
@@ -395,6 +397,15 @@ async fn manage_conversation(
|
|
|
|
|
|
/// Spawns all other threads for this conversation.
|
|
/// Spawns all other threads for this conversation.
|
|
async fn spawn_threads(config: FullConfig) -> Result<(), MessengerError> {
|
|
async fn spawn_threads(config: FullConfig) -> Result<(), MessengerError> {
|
|
|
|
+ // without noise during Shadow's bootstrap period, we can overload the SOMAXCONN of the server,
|
|
|
|
+ // so we wait a small(ish) pseudorandom amount of time to spread things out
|
|
|
|
+ let mut hasher = rustc_hash::FxHasher::default();
|
|
|
|
+ config.user.hash(&mut hasher);
|
|
|
|
+ config.group.hash(&mut hasher);
|
|
|
|
+ let hash = hasher.finish() % 10_000;
|
|
|
|
+ log!("{},{},waiting,{}", config.user, config.group, hash);
|
|
|
|
+ sleep(Duration::from_millis(hash)).await;
|
|
|
|
+
|
|
let message_server_params = SocksParams {
|
|
let message_server_params = SocksParams {
|
|
socks: config.socks.clone(),
|
|
socks: config.socks.clone(),
|
|
target: config.message_server.clone(),
|
|
target: config.message_server.clone(),
|