mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
2e3d5f87db
- added PartialEq to StreamError for test purposes (only yet!) - removed async_recv example as it's no longer for any use. It was created before the COMPLETE REWRITE in order to verify that my own async interface on top of mio works. However it's now guaranteed by async-std and futures. no need for a special test - remove uvth from dependencies and replace it with a `FnOnce` - fix ALL clippy (network) lints - basic fix for a channel drop scenario: TODO: this needs some further fixes up to know only destruction of participant by api was covered correctly. we had an issue when the underlying channels got dropped. So now we have a participant without channels. We need to buffer the requests and try to reopen a channel ASAP! If no channel could be reopened we need to close the Participant, while a) leaving the BParticipant in takt, knowing that it only waits for a propper close by scheduler b) close the BParticipant gracefully. Notifying the scheduler to remove its stuff (either scheduler schould detect a stopped BParticipant or BParticipant will send Scheduler it's own destruction, and then Scheduler just does the same like when API forces a close) Keep the Participant alive and wait for the api to acces BParticipant to notice it's closed and then wait for a disconnect which isn't doing anything as it was already cleaned up in the background
94 lines
2.8 KiB
Rust
94 lines
2.8 KiB
Rust
use lazy_static::*;
|
|
use std::{
|
|
net::SocketAddr,
|
|
sync::{
|
|
atomic::{AtomicU16, Ordering},
|
|
Arc,
|
|
},
|
|
thread,
|
|
time::Duration,
|
|
};
|
|
use tracing::*;
|
|
use tracing_subscriber::EnvFilter;
|
|
use veloren_network::{Address, Network, Participant, Pid, Stream, PROMISES_NONE};
|
|
|
|
#[allow(dead_code)]
|
|
pub fn setup(tracing: bool, mut sleep: u64) -> (u64, u64) {
|
|
if tracing {
|
|
sleep += 1000
|
|
}
|
|
if sleep > 0 {
|
|
thread::sleep(Duration::from_millis(sleep));
|
|
}
|
|
|
|
let _subscriber = if tracing {
|
|
let filter = EnvFilter::from_default_env()
|
|
.add_directive("trace".parse().unwrap())
|
|
.add_directive("async_std::task::block_on=warn".parse().unwrap())
|
|
.add_directive("veloren_network::tests=trace".parse().unwrap())
|
|
.add_directive("veloren_network::controller=trace".parse().unwrap())
|
|
.add_directive("veloren_network::channel=trace".parse().unwrap())
|
|
.add_directive("veloren_network::message=trace".parse().unwrap())
|
|
.add_directive("veloren_network::metrics=trace".parse().unwrap())
|
|
.add_directive("veloren_network::types=trace".parse().unwrap());
|
|
|
|
Some(
|
|
tracing_subscriber::FmtSubscriber::builder()
|
|
// all spans/events with a level higher than TRACE (e.g, info, warn, etc.)
|
|
// will be written to stdout.
|
|
.with_max_level(Level::TRACE)
|
|
.with_env_filter(filter)
|
|
// sets this to be the default, global subscriber for this application.
|
|
.try_init(),
|
|
)
|
|
} else {
|
|
None
|
|
};
|
|
|
|
(0, 0)
|
|
}
|
|
|
|
#[allow(dead_code)]
|
|
pub async fn network_participant_stream(
|
|
addr: Address,
|
|
) -> (
|
|
Network,
|
|
Arc<Participant>,
|
|
Stream,
|
|
Network,
|
|
Arc<Participant>,
|
|
Stream,
|
|
) {
|
|
let (n_a, f_a) = Network::new(Pid::fake(1), None);
|
|
std::thread::spawn(f_a);
|
|
let (n_b, f_b) = Network::new(Pid::fake(2), None);
|
|
std::thread::spawn(f_b);
|
|
|
|
n_a.listen(addr.clone()).await.unwrap();
|
|
let p1_b = n_b.connect(addr).await.unwrap();
|
|
let p1_a = n_a.connected().await.unwrap();
|
|
|
|
let s1_a = p1_a.open(10, PROMISES_NONE).await.unwrap();
|
|
let s1_b = p1_b.opened().await.unwrap();
|
|
|
|
(n_a, p1_a, s1_a, n_b, p1_b, s1_b)
|
|
}
|
|
|
|
#[allow(dead_code)]
|
|
pub fn tcp() -> veloren_network::Address {
|
|
lazy_static! {
|
|
static ref PORTS: AtomicU16 = AtomicU16::new(5000);
|
|
}
|
|
let port = PORTS.fetch_add(1, Ordering::Relaxed);
|
|
veloren_network::Address::Tcp(SocketAddr::from(([127, 0, 0, 1], port)))
|
|
}
|
|
|
|
#[allow(dead_code)]
|
|
pub fn udp() -> veloren_network::Address {
|
|
lazy_static! {
|
|
static ref PORTS: AtomicU16 = AtomicU16::new(5000);
|
|
}
|
|
let port = PORTS.fetch_add(1, Ordering::Relaxed);
|
|
veloren_network::Address::Udp(SocketAddr::from(([127, 0, 0, 1], port)))
|
|
}
|