Function libp2p::core::upgrade::read_length_prefixed
source ยท pub async fn read_length_prefixed(
socket: &mut (impl AsyncRead + Unpin),
max_size: usize,
) -> Result<Vec<u8>, Error>
Expand description
Reads a length-prefixed message from the given socket.
The max_size
parameter is the maximum size in bytes of the message that we accept. This is
necessary in order to avoid DoS attacks where the remote sends us a message of several
gigabytes.
Note: Assumes that a variable-length prefix indicates the length of the message. This is compatible with what
write_length_prefixed
does.