fix crash bugs (#64)

This commit is contained in:
Sijie.Sun 2024-04-29 21:02:05 +08:00 committed by GitHub
parent 6595c2837e
commit 70dee329d1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 28 additions and 10 deletions

View File

@ -135,6 +135,20 @@ impl PeerConn {
*need_retry = true;
let rsp = rsp?;
let Some(peer_mgr_hdr) = rsp.peer_manager_header() else {
return Err(Error::WaitRespError(format!(
"unexpected packet: {:?}, cannot decode peer manager hdr",
rsp
)));
};
if peer_mgr_hdr.packet_type != PacketType::HandShake as u8 {
return Err(Error::WaitRespError(format!(
"unexpected packet type: {:?}",
peer_mgr_hdr.packet_type
)));
}
let rsp = HandshakeRequest::decode(rsp.payload()).map_err(|e| {
Error::WaitRespError(format!("decode handshake response error: {:?}", e))
})?;

View File

@ -302,8 +302,9 @@ Endpoint = {listenr_addr} # should be the public ip of the vpn server
async fn list_clients(&self) -> Vec<String> {
self.inner
.as_ref()
.unwrap()
.wg_peer_ip_table
.and_then(|w| {
Some(
w.wg_peer_ip_table
.iter()
.map(|x| {
x.value()
@ -312,6 +313,9 @@ Endpoint = {listenr_addr} # should be the public ip of the vpn server
.map(|x| x.to_string())
.unwrap_or_default()
})
.collect()
.collect(),
)
})
.unwrap_or_default()
}
}