0

Issue

I have a client that needs to send the following custom data structure to an API:

#[derive(Serialize, Deserialize)]
pub struct FheSum {
    pub server_keys: ServerKey,
    pub value1: FheUint8,
    pub value2: FheUint8,
}

The code for the client is the following:

let fhe_post: FheSum = FheSum {
        server_keys: server_keys.to_owned(),
        value1: value_api.to_owned(),
        value2: value_api_2.to_owned(),
};

let client = reqwest::blocking::Client::builder()
        .timeout(None)
        .build().unwrap();

let response = client
        .post("http://127.0.0.1:8000/computesum")
        .json(&fhe_post)
        .send().unwrap();
    
let response_json: Result<FheSumResult, reqwest::Error> = response.json();

match response_json {
        Ok(j) => {
            let result_api: u8 = FheUint8::decrypt(&j.result, &client_keys);
            println!("Final Result: {}", result_api)
        },
        Err(e) => println!("{:}", e),
};

In the API, I have the following definition of an HttpServer:

HttpServer::new(|| {
        let json_cfg = actix_web::web::JsonConfig::default()
        .limit(std::usize::MAX);
        
        App::new()
        .app_data(json_cfg)
        .service(integers::computesum)
    })
    .client_disconnect_timeout(std::time::Duration::from_secs(3000))
    .client_request_timeout(std::time::Duration::from_secs(3000))
    .max_connection_rate(std::usize::MAX)
    .bind(("127.0.0.1", 8000))?
    .run()
    .await

And the associated endpoint the client is trying to access:

#[post("/computesum")]
pub async fn computesum(req: Json<FheSum>) -> HttpResponse {
    let req: FheSum = req.into_inner();
    let recovered: FheSum = FheSum::new(
        req.server_keys,
        req.value1,
        req.value2,
    );

    set_server_key(recovered.server_keys);

    let result_api_enc: FheSumResult = FheSumResult::new(recovered.value1 + recovered.value2);

    HttpResponse::Ok()
        .content_type(ContentType::json())
        .json(&result_api_enc)
}

Problem

The structs are the same in both the client and the server. This code works when using common data types such as Strings. The issue is when using this data structures. The memory occupied, obtained with mem::size_of_val which returns the size in bytes, is the following:

Size 1: 2488
Size 2: 32
Size 3: 32

The result has been obtained in bytes, so, given the limit established in the HttpServer, this shouldn't be an issue. Timeouts have also been set at much higher values than commonly needed. Even with this changes, the client always shows Killed, and doesn't display the answer from the server, not giving any clues on what the problem might be.

The client is killing the process before being able to process the server's response. I want to find a way to send these custom data types to the HTTP server without the connection closing before the operation has finished.

I have already tried different libraries for the client such as the acw crate, apart from reqwest and the result is the same. I have also tried not using reqwest in blocking mode, and the error persists.

Patricia
  • 1
  • 3

0 Answers0