fix compile error
This commit is contained in:
parent
65eef2b579
commit
4071f803f7
@ -505,16 +505,17 @@ async fn direct_server(server: ServerPtr) -> ResultType<()> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_multicast_socket() -> ResultType<FramedSocket> {
|
pub fn create_multicast_socket() -> ResultType<(FramedSocket, SocketAddr)> {
|
||||||
let port = (RENDEZVOUS_PORT + 3) as u16;
|
let port = (RENDEZVOUS_PORT + 3) as u16;
|
||||||
udp::bind_multicast(
|
let maddr = SocketAddrV4::new([239, 255, 42, 98].into(), port);
|
||||||
&SocketAddrV4::new([0, 0, 0, 0].into(), port),
|
Ok((
|
||||||
&SocketAddrV4::new([239, 255, 42, 98].into(), port),
|
udp::bind_multicast(&SocketAddrV4::new([0, 0, 0, 0].into(), port), &maddr)?,
|
||||||
)
|
SocketAddr::V4(maddr),
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn lan_discovery() -> ResultType<()> {
|
async fn lan_discovery() -> ResultType<()> {
|
||||||
let mut socket = create_multicast_socket()?;
|
let (mut socket, maddr) = create_multicast_socket()?;
|
||||||
loop {
|
loop {
|
||||||
select! {
|
select! {
|
||||||
Some(Ok((bytes, _))) = socket.next() => {
|
Some(Ok((bytes, _))) = socket.next() => {
|
||||||
@ -523,17 +524,22 @@ async fn lan_discovery() -> ResultType<()> {
|
|||||||
Some(rendezvous_message::Union::peer_discovery(p)) => {
|
Some(rendezvous_message::Union::peer_discovery(p)) => {
|
||||||
if p.cmd == "ping" {
|
if p.cmd == "ping" {
|
||||||
let mut msg_out = Message::new();
|
let mut msg_out = Message::new();
|
||||||
|
let mac = if let Ok(Some(mac)) = mac_address::get_mac_address() {
|
||||||
|
mac.to_string()
|
||||||
|
} else {
|
||||||
|
"".to_owned()
|
||||||
|
};
|
||||||
let peer = PeerDiscovery {
|
let peer = PeerDiscovery {
|
||||||
cmd: "pong".to_owned,
|
cmd: "pong".to_owned(),
|
||||||
mac: hbb_common::mac_address::get_mac_address()?,
|
mac,
|
||||||
id: Config::get_id(),
|
id: Config::get_id(),
|
||||||
hostname: whoami::hostname(),
|
hostname: whoami::hostname(),
|
||||||
username: crate::platform::get_active_username(),
|
username: crate::platform::get_active_username(),
|
||||||
platform: whoami::platform().to_string(),
|
platform: whoami::platform().to_string(),
|
||||||
...Default::default(),
|
..Default::default()
|
||||||
};
|
};
|
||||||
msg_out.set_peer_discovery(peer);
|
msg_out.set_peer_discovery(peer);
|
||||||
socket.send(&msg_out).await?;
|
socket.send(&msg_out, maddr).await?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
@ -542,5 +548,4 @@ async fn lan_discovery() -> ResultType<()> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user