Skip to content

Commit

Permalink
Remove defaults for ProtocolConfigValidator
Browse files Browse the repository at this point in the history
  • Loading branch information
th4s committed Sep 11, 2024
1 parent 227ab87 commit 48f3d97
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 32 deletions.
30 changes: 12 additions & 18 deletions crates/common/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand All @@ -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(
Expand Down
6 changes: 5 additions & 1 deletion crates/examples/twitter/twitter_dm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 0 additions & 3 deletions crates/notary/client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
}

Expand Down
1 change: 0 additions & 1 deletion crates/verifier/src/tls/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
13 changes: 4 additions & 9 deletions crates/wasm/src/verifier/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,16 @@ use tsify_next::Tsify;
#[tsify(from_wasm_abi)]
pub struct VerifierConfig {
pub id: String,
pub max_sent_data: Option<usize>,
pub max_received_data: Option<usize>,
pub max_sent_data: usize,
pub max_received_data: usize,
}

impl From<VerifierConfig> 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();

Expand Down

0 comments on commit 48f3d97

Please sign in to comment.