From 48f3d9743be6c79592aedaa84a1f6846add22603 Mon Sep 17 00:00:00 2001 From: th4s Date: Wed, 11 Sep 2024 11:28:38 +0200 Subject: [PATCH] Remove defaults for `ProtocolConfigValidator` --- crates/common/src/config.rs | 30 +++++++++++---------------- crates/examples/twitter/twitter_dm.rs | 6 +++++- crates/notary/client/src/client.rs | 3 --- crates/verifier/src/tls/config.rs | 1 - crates/wasm/src/verifier/config.rs | 13 ++++-------- 5 files changed, 21 insertions(+), 32 deletions(-) diff --git a/crates/common/src/config.rs b/crates/common/src/config.rs index dca4f0752..1ae074d03 100644 --- a/crates/common/src/config.rs +++ b/crates/common/src/config.rs @@ -7,11 +7,6 @@ use std::error::Error; use crate::Role; -/// Default for the maximum number of bytes that can be sent (4KB). -pub const DEFAULT_MAX_SENT_LIMIT: usize = 1 << 12; -/// Default for the maximum number of bytes that can be received (16KB). -pub const DEFAULT_MAX_RECV_LIMIT: usize = 1 << 14; - // Extra cushion room, eg. for sharing J0 blocks. const EXTRA_OTS: usize = 16384; @@ -109,22 +104,14 @@ impl ProtocolConfig { #[derive(derive_builder::Builder, Clone, Debug)] pub struct ProtocolConfigValidator { /// Maximum number of bytes that can be sent. - #[builder(default = "DEFAULT_MAX_SENT_LIMIT")] max_sent_data: usize, /// Maximum number of bytes that can be received. - #[builder(default = "DEFAULT_MAX_RECV_LIMIT")] max_recv_data: usize, /// Version that is being run by checker. #[builder(setter(skip), default = "VERSION.clone()")] version: Version, } -impl Default for ProtocolConfigValidator { - fn default() -> Self { - Self::builder().build().unwrap() - } -} - impl ProtocolConfigValidator { /// Creates a new builder for `ProtocolConfigValidator`. pub fn builder() -> ProtocolConfigValidatorBuilder { @@ -280,16 +267,23 @@ mod test { use super::*; use rstest::{fixture, rstest}; + const TEST_MAX_SENT_LIMIT: usize = 1 << 12; + const TEST_MAX_RECV_LIMIT: usize = 1 << 14; + #[fixture] #[once] fn config_validator() -> ProtocolConfigValidator { - ProtocolConfigValidator::builder().build().unwrap() + ProtocolConfigValidator::builder() + .max_sent_data(TEST_MAX_SENT_LIMIT) + .max_recv_data(TEST_MAX_RECV_LIMIT) + .build() + .unwrap() } #[rstest] - #[case::same_max_sent_recv_data(DEFAULT_MAX_SENT_LIMIT, DEFAULT_MAX_RECV_LIMIT)] - #[case::smaller_max_sent_data(1 << 11, DEFAULT_MAX_RECV_LIMIT)] - #[case::smaller_max_recv_data(DEFAULT_MAX_SENT_LIMIT, 1 << 13)] + #[case::same_max_sent_recv_data(TEST_MAX_SENT_LIMIT, TEST_MAX_RECV_LIMIT)] + #[case::smaller_max_sent_data(1 << 11, TEST_MAX_RECV_LIMIT)] + #[case::smaller_max_recv_data(TEST_MAX_SENT_LIMIT, 1 << 13)] #[case::smaller_max_sent_recv_data(1 << 7, 1 << 9)] fn test_check_success( config_validator: &ProtocolConfigValidator, @@ -306,7 +300,7 @@ mod test { } #[rstest] - #[case::bigger_max_sent_data(1 << 13, DEFAULT_MAX_RECV_LIMIT)] + #[case::bigger_max_sent_data(1 << 13, TEST_MAX_RECV_LIMIT)] #[case::bigger_max_recv_data(1 << 10, 1 << 16)] #[case::bigger_max_sent_recv_data(1 << 14, 1 << 21)] fn test_check_fail( diff --git a/crates/examples/twitter/twitter_dm.rs b/crates/examples/twitter/twitter_dm.rs index 11313b818..ed87f3542 100644 --- a/crates/examples/twitter/twitter_dm.rs +++ b/crates/examples/twitter/twitter_dm.rs @@ -54,7 +54,11 @@ async fn main() { .unwrap(); // Send requests for configuration and notarization to the notary server. - let notarization_request = NotarizationRequest::builder().build().unwrap(); + let notarization_request = NotarizationRequest::builder() + .max_sent_data(MAX_SENT_DATA) + .max_recv_data(MAX_RECV_DATA) + .build() + .unwrap(); let Accepted { io: notary_connection, diff --git a/crates/notary/client/src/client.rs b/crates/notary/client/src/client.rs index 1ff07388d..4db0dce6a 100644 --- a/crates/notary/client/src/client.rs +++ b/crates/notary/client/src/client.rs @@ -12,7 +12,6 @@ use std::{ sync::Arc, task::{Context, Poll}, }; -use tlsn_common::config::{DEFAULT_MAX_RECV_LIMIT, DEFAULT_MAX_SENT_LIMIT}; use tokio::{ io::{AsyncRead, AsyncWrite, ReadBuf}, net::TcpStream, @@ -30,10 +29,8 @@ use crate::error::{ClientError, ErrorKind}; #[derive(Debug, Clone, derive_builder::Builder)] pub struct NotarizationRequest { /// Maximum number of bytes that can be sent. - #[builder(default = "DEFAULT_MAX_SENT_LIMIT")] max_sent_data: usize, /// Maximum number of bytes that can be received. - #[builder(default = "DEFAULT_MAX_RECV_LIMIT")] max_recv_data: usize, } diff --git a/crates/verifier/src/tls/config.rs b/crates/verifier/src/tls/config.rs index a1cedb254..2b05c3b4a 100644 --- a/crates/verifier/src/tls/config.rs +++ b/crates/verifier/src/tls/config.rs @@ -12,7 +12,6 @@ use tlsn_core::proof::default_cert_verifier; pub struct VerifierConfig { #[builder(setter(into))] id: String, - #[builder(default)] protocol_config_validator: ProtocolConfigValidator, #[builder( pattern = "owned", diff --git a/crates/wasm/src/verifier/config.rs b/crates/wasm/src/verifier/config.rs index 1300ba636..7e95f9f18 100644 --- a/crates/wasm/src/verifier/config.rs +++ b/crates/wasm/src/verifier/config.rs @@ -6,21 +6,16 @@ use tsify_next::Tsify; #[tsify(from_wasm_abi)] pub struct VerifierConfig { pub id: String, - pub max_sent_data: Option, - pub max_received_data: Option, + pub max_sent_data: usize, + pub max_received_data: usize, } impl From for tlsn_verifier::tls::VerifierConfig { fn from(value: VerifierConfig) -> Self { let mut builder = ProtocolConfigValidator::builder(); - if let Some(value) = value.max_sent_data { - builder.max_sent_data(value); - } - - if let Some(value) = value.max_received_data { - builder.max_recv_data(value); - } + builder.max_sent_data(value.max_sent_data); + builder.max_recv_data(value.max_received_data); let config_validator = builder.build().unwrap();