rustrust-tokiorust-futureslibp2p

libp2p request_reponse UnexpectedEof error


I am working with rust-libp2p and I'm using libp2p request_reponse, but I found out that the send_reponse method from the network behaviour doesn't actually send when the file is large(43 MB in my case). I don't know if this is from request_response or if it is my implementation, but it works fine for smaller files.

This is the error I get Io(Custom { kind: UnexpectedEof, error: Eof { name: "u8", expect: Small(1) } }) whenever I try to receive the file from request_response::Message::Response event.


Solution

  • From the error, I figured not everything was sent when I called request_response.send_response().

    To fix this I had to set the max request size and response size when defining the request_reponse Behaviour so it can accept and send larger files.

    let codec = cbor::codec::Codec::default()
                    .set_request_size_maximum(u64::MAX) // specify max file size
                    .set_response_size_maximum(u64::MAX);
    
    let request_response = request_response::cbor::Behaviour::with_codec(
                        codec,
                        [(
                            StreamProtocol::new("/file-exchange/1"),
                            ProtocolSupport::Full,
                        )],
                        request_response::Config::default(),
                    );