mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-04-25 11:02:12 +00:00
Fix ping test in request-response. (#1702)
The codec impl did not check that it actually read any bytes in `read_request` and `read_response`. The used `read_one` function does not error on EOF either, so instead of signalling connection loss the codec could produce empty `Ping` or `Pong` messages.
This commit is contained in:
parent
0d26f50304
commit
7d47ada077
@ -356,8 +356,11 @@ impl RequestResponseCodec for PingCodec {
|
|||||||
T: AsyncRead + Unpin + Send
|
T: AsyncRead + Unpin + Send
|
||||||
{
|
{
|
||||||
read_one(io, 1024)
|
read_one(io, 1024)
|
||||||
.map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))
|
.map(|res| match res {
|
||||||
.map_ok(Ping)
|
Err(e) => Err(io::Error::new(io::ErrorKind::InvalidData, e)),
|
||||||
|
Ok(vec) if vec.is_empty() => Err(io::ErrorKind::UnexpectedEof.into()),
|
||||||
|
Ok(vec) => Ok(Ping(vec))
|
||||||
|
})
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -367,8 +370,11 @@ impl RequestResponseCodec for PingCodec {
|
|||||||
T: AsyncRead + Unpin + Send
|
T: AsyncRead + Unpin + Send
|
||||||
{
|
{
|
||||||
read_one(io, 1024)
|
read_one(io, 1024)
|
||||||
.map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))
|
.map(|res| match res {
|
||||||
.map_ok(Pong)
|
Err(e) => Err(io::Error::new(io::ErrorKind::InvalidData, e)),
|
||||||
|
Ok(vec) if vec.is_empty() => Err(io::ErrorKind::UnexpectedEof.into()),
|
||||||
|
Ok(vec) => Ok(Pong(vec))
|
||||||
|
})
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user