display socket multicast

This commit is contained in:
asxalex 2024-07-16 15:11:58 +08:00
parent 49d8ca9375
commit 8e05cb0ce0
2 changed files with 21 additions and 5 deletions

View File

@ -315,10 +315,10 @@ async fn run_edge_loop(eee: &'static Node, cancel: CancellationToken) {
let cancel2 = cancel.clone();
let cancel = cancel.clone();
tokio::spawn(async move {
loop_socket_v4(eee, &eee.udp_sock_v4, cancel).await;
loop_socket_v4(eee, &eee.udp_sock_v4, cancel, false).await;
});
tokio::spawn(async move {
loop_socket_v4(eee, &eee.udp_sock_multicast, cancel2).await;
loop_socket_v4(eee, &eee.udp_sock_multicast, cancel2, true).await;
});
}
@ -349,16 +349,23 @@ async fn send_stun_request(eee: &Node) {
}
}
async fn loop_socket_v4(eee: &Node, socket: &Socket, cancel: CancellationToken) {
async fn loop_socket_v4(
eee: &Node,
socket: &Socket,
cancel: CancellationToken,
is_multicast_sock: bool,
) {
debug!("loop sock v4");
loop {
tokio::select! {
_ = cancel.cancelled() => {
break;
}
_ = read_and_parse_packet(eee, socket,Some(Duration::from_secs(10))) => { }
_ = read_and_parse_packet(eee, socket, Some(Duration::from_secs(10)), is_multicast_sock) => { }
_ = tokio::time::sleep(Duration::from_secs(10)) => {
if !is_multicast_sock {
send_stun_request(eee).await;
}
/*
let req = SdlStunRequest {
cookie: 0,

View File

@ -29,6 +29,7 @@ pub async fn read_and_parse_packet(
eee: &Node,
sock: &Socket,
timeout: Option<Duration>,
is_multicast_sock: bool,
// cancel: CancellationToken,
) -> Result<()> {
let mut buf = vec![0; 3000];
@ -59,6 +60,14 @@ pub async fn read_and_parse_packet(
}
Ok((size, from)) => {
// size > 0
if is_multicast_sock {
println!(
"xxxx got packet from multicast sock from {}",
from.to_string()
);
}
buf.truncate(size);
match handle_packet(eee, from, &buf).await {
Ok(_) => {}