Skip to content

Commit

Permalink
fix wrong unwrap
Browse files Browse the repository at this point in the history
  • Loading branch information
giangndm committed Oct 9, 2024
1 parent 4be7975 commit f663637
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/quic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn configure_server(priv_key: PrivatePkcs8KeyDer<'static>, cert: CertificateDer<
let cert_chain = vec![cert];

let mut server_config = ServerConfig::with_single_cert(cert_chain, priv_key.into())?;
let transport_config = Arc::get_mut(&mut server_config.transport).unwrap();
let transport_config = Arc::get_mut(&mut server_config.transport).expect("should get mut");
transport_config.max_concurrent_uni_streams(0_u8.into());
transport_config.max_idle_timeout(Some(Duration::from_secs(5).try_into().expect("Should config timeout")));

Expand Down
2 changes: 1 addition & 1 deletion src/service/alias_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ mod test {
Self {
internal: AliasServiceInternal {
local: HashMap::new(),
cache: LruCache::new(LRU_CACHE_SIZE.try_into().unwrap()),
cache: LruCache::new(LRU_CACHE_SIZE.try_into().expect("should create NoneZeroUsize")),
find_reqs: HashMap::new(),
outs: VecDeque::new(),
},
Expand Down
10 changes: 5 additions & 5 deletions src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@ impl<Item: DeserializeOwned + Debug> Decoder for BincodeCodec<Item> {
pub async fn wait_object<R: AsyncRead + Unpin, O: DeserializeOwned, const MAX_SIZE: usize>(reader: &mut R) -> anyhow::Result<O> {
let mut len_buf = [0; 2];
let mut data_buf = [0; MAX_SIZE];
reader.read_exact(&mut len_buf).await.unwrap();
reader.read_exact(&mut len_buf).await?;
let handshake_len = u16::from_be_bytes([len_buf[0], len_buf[1]]) as usize;
if handshake_len > data_buf.len() {
return Err(anyhow!("packet to big {} vs {MAX_SIZE}", data_buf.len()));
}

reader.read_exact(&mut data_buf[0..handshake_len]).await.unwrap();
reader.read_exact(&mut data_buf[0..handshake_len]).await?;

Ok(bincode::deserialize(&data_buf[0..handshake_len]).unwrap())
Ok(bincode::deserialize(&data_buf[0..handshake_len])?)
}

pub async fn write_object<W: AsyncWrite + Send + Unpin, O: Serialize, const MAX_SIZE: usize>(writer: &mut W, object: &O) -> anyhow::Result<()> {
Expand All @@ -112,7 +112,7 @@ pub async fn write_object<W: AsyncWrite + Send + Unpin, O: Serialize, const MAX_
}
let len_buf = (data_buf.len() as u16).to_be_bytes();

writer.write_all(&len_buf).await.unwrap();
writer.write_all(&data_buf).await.unwrap();
writer.write_all(&len_buf).await?;
writer.write_all(&data_buf).await?;
Ok(())
}
6 changes: 3 additions & 3 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ async fn create_node(advertise: bool, peer_id: u64, seeds: Vec<PeerAddress>) ->
let cert = CertificateDer::from(DEFAULT_CLUSTER_CERT.to_vec());

let addr = {
let socket = UdpSocket::bind("127.0.0.1:0").unwrap();
socket.local_addr().unwrap()
let socket = UdpSocket::bind("127.0.0.1:0").expect("should bind");
socket.local_addr().expect("should get local")
};
let peer_id = PeerId::from(peer_id);
(
Expand All @@ -34,7 +34,7 @@ async fn create_node(advertise: bool, peer_id: u64, seeds: Vec<PeerAddress>) ->
seeds,
})
.await
.unwrap(),
.expect("should create network"),
(peer_id, addr.into()).into(),
)
}
4 changes: 2 additions & 2 deletions src/tests/visualization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ async fn discovery_new_node() {
tokio::time::sleep(Duration::from_secs(1)).await;

let mut events = vec![
tokio::time::timeout(Duration::from_secs(3), service2.recv()).await.unwrap().unwrap(),
tokio::time::timeout(Duration::from_secs(3), service2.recv()).await.unwrap().unwrap(),
tokio::time::timeout(Duration::from_secs(3), service2.recv()).await.expect("").expect(""),
tokio::time::timeout(Duration::from_secs(3), service2.recv()).await.expect("").expect(""),
];

for event in events.iter_mut() {
Expand Down

0 comments on commit f663637

Please sign in to comment.