display socket multicast
This commit is contained in:
parent
49d8ca9375
commit
8e05cb0ce0
@ -315,10 +315,10 @@ async fn run_edge_loop(eee: &'static Node, cancel: CancellationToken) {
|
|||||||
let cancel2 = cancel.clone();
|
let cancel2 = cancel.clone();
|
||||||
let cancel = cancel.clone();
|
let cancel = cancel.clone();
|
||||||
tokio::spawn(async move {
|
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 {
|
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");
|
debug!("loop sock v4");
|
||||||
loop {
|
loop {
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
_ = cancel.cancelled() => {
|
_ = cancel.cancelled() => {
|
||||||
break;
|
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)) => {
|
_ = tokio::time::sleep(Duration::from_secs(10)) => {
|
||||||
send_stun_request(eee).await;
|
if !is_multicast_sock {
|
||||||
|
send_stun_request(eee).await;
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
let req = SdlStunRequest {
|
let req = SdlStunRequest {
|
||||||
cookie: 0,
|
cookie: 0,
|
||||||
|
|||||||
@ -29,6 +29,7 @@ pub async fn read_and_parse_packet(
|
|||||||
eee: &Node,
|
eee: &Node,
|
||||||
sock: &Socket,
|
sock: &Socket,
|
||||||
timeout: Option<Duration>,
|
timeout: Option<Duration>,
|
||||||
|
is_multicast_sock: bool,
|
||||||
// cancel: CancellationToken,
|
// cancel: CancellationToken,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let mut buf = vec![0; 3000];
|
let mut buf = vec![0; 3000];
|
||||||
@ -59,6 +60,14 @@ pub async fn read_and_parse_packet(
|
|||||||
}
|
}
|
||||||
Ok((size, from)) => {
|
Ok((size, from)) => {
|
||||||
// size > 0
|
// size > 0
|
||||||
|
|
||||||
|
if is_multicast_sock {
|
||||||
|
println!(
|
||||||
|
"xxxx got packet from multicast sock from {}",
|
||||||
|
from.to_string()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
buf.truncate(size);
|
buf.truncate(size);
|
||||||
match handle_packet(eee, from, &buf).await {
|
match handle_packet(eee, from, &buf).await {
|
||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user