Compare commits
No commits in common. "7a0880fc02adc53772e792f9faf06a4933f78743" and "0bb702f312d65c83761a04b827f6fcd5e4ff7704" have entirely different histories.
7a0880fc02
...
0bb702f312
|
@ -9,29 +9,23 @@ pub async fn client <I : Iterator <Item=String>> (mut args: I) -> Result <(), Ap
|
||||||
use rand::RngCore;
|
use rand::RngCore;
|
||||||
|
|
||||||
let common_params = app_common::Params::default ();
|
let common_params = app_common::Params::default ();
|
||||||
let mut bind_addrs = vec! [];
|
let mut bind_addr = "0.0.0.0".to_string ();
|
||||||
|
|
||||||
while let Some (arg) = args.next () {
|
while let Some (arg) = args.next () {
|
||||||
match arg.as_str () {
|
match arg.as_str () {
|
||||||
"--bind-addr" => {
|
"--bind-addr" => {
|
||||||
bind_addrs.push (match args.next () {
|
bind_addr = match args.next () {
|
||||||
None => return Err (CliArgError::MissingArgumentValue (arg).into ()),
|
None => return Err (CliArgError::MissingArgumentValue (arg).into ()),
|
||||||
Some (x) => Ipv4Addr::from_str (&x)?
|
Some (x) => x
|
||||||
});
|
};
|
||||||
},
|
},
|
||||||
_ => return Err (CliArgError::UnrecognizedArgument (arg).into ()),
|
_ => return Err (CliArgError::UnrecognizedArgument (arg).into ()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if bind_addrs.is_empty () {
|
let socket = UdpSocket::bind (&format! ("{}:0", bind_addr)).await?;
|
||||||
bind_addrs = get_ips ()?;
|
|
||||||
}
|
|
||||||
|
|
||||||
let socket = UdpSocket::bind (SocketAddrV4::new (Ipv4Addr::UNSPECIFIED, 0)).await?;
|
socket.join_multicast_v4 (common_params.multicast_addr, Ipv4Addr::from_str (&bind_addr)?)?;
|
||||||
|
|
||||||
for bind_addr in bind_addrs {
|
|
||||||
socket.join_multicast_v4 (common_params.multicast_addr, bind_addr)?;
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut idem_id = [0u8; 8];
|
let mut idem_id = [0u8; 8];
|
||||||
rand::thread_rng ().fill_bytes (&mut idem_id);
|
rand::thread_rng ().fill_bytes (&mut idem_id);
|
||||||
|
|
|
@ -12,13 +12,28 @@ pub async fn server <I: Iterator <Item=String>> (args: I) -> Result <(), AppErro
|
||||||
{
|
{
|
||||||
let params = configure (args)?;
|
let params = configure (args)?;
|
||||||
|
|
||||||
let socket = UdpSocket::bind (SocketAddrV4::new (Ipv4Addr::UNSPECIFIED, params.common.server_port)).await?;
|
// This was too hard to do in a functional style
|
||||||
|
let mut tasks = vec! [];
|
||||||
|
|
||||||
for bind_addr in ¶ms.bind_addrs {
|
for bind_addr in ¶ms.bind_addrs {
|
||||||
|
let socket = match UdpSocket::bind (SocketAddrV4::new (Ipv4Addr::UNSPECIFIED, params.common.server_port)).await {
|
||||||
|
Err (e) => {
|
||||||
|
println! ("Error binding socket: {:?}", e);
|
||||||
|
continue;
|
||||||
|
},
|
||||||
|
Ok (x) => x,
|
||||||
|
};
|
||||||
|
|
||||||
socket.join_multicast_v4 (params.common.multicast_addr, *bind_addr)?;
|
socket.join_multicast_v4 (params.common.multicast_addr, *bind_addr)?;
|
||||||
|
|
||||||
|
dbg! (bind_addr);
|
||||||
|
|
||||||
|
tasks.push (tokio::spawn (serve_interface (params.clone (), socket)));
|
||||||
}
|
}
|
||||||
|
|
||||||
serve_interface (params, socket).await?;
|
for task in tasks {
|
||||||
|
task.await??;
|
||||||
|
}
|
||||||
|
|
||||||
Ok (())
|
Ok (())
|
||||||
}
|
}
|
||||||
|
@ -53,7 +68,7 @@ fn configure <I: Iterator <Item=String>> (mut args: I) -> Result <Params, AppErr
|
||||||
}
|
}
|
||||||
|
|
||||||
if bind_addrs.is_empty () {
|
if bind_addrs.is_empty () {
|
||||||
println! ("No bind addresses given, auto-detecting all local IPs");
|
println! ("No bind addresses found, auto-detecting all local IPs");
|
||||||
bind_addrs = get_ips ()?;
|
bind_addrs = get_ips ()?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,10 +80,7 @@ fn configure <I: Iterator <Item=String>> (mut args: I) -> Result <Params, AppErr
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn serve_interface (
|
async fn serve_interface (params: Params, socket: UdpSocket)
|
||||||
params: Params,
|
|
||||||
socket: UdpSocket,
|
|
||||||
)
|
|
||||||
-> Result <(), AppError>
|
-> Result <(), AppError>
|
||||||
{
|
{
|
||||||
let mut recent_idem_ids = Vec::with_capacity (32);
|
let mut recent_idem_ids = Vec::with_capacity (32);
|
||||||
|
|
Loading…
Reference in New Issue