nym-client: using the new Sphinx max packet length constant

This commit is contained in:
Dave Hrycyszyn
2020-01-24 12:52:16 +00:00
parent 8510924ebb
commit 5c1559dd78
2 changed files with 12 additions and 10 deletions
+10
View File
@@ -95,6 +95,16 @@ impl ClientRequest {
mut input_tx: mpsc::UnboundedSender<InputMessage>,
) -> ServerResponse {
trace!("sending to: {:?}, msg: {:?}", recipient_address, msg);
if msg.len() > sphinx::constants::MAXIMUM_PLAINTEXT_LENGTH {
return ServerResponse::Error {
message: format!(
"too long message. Sent {} bytes while the maximum is {}",
msg.len(),
sphinx::constants::MAXIMUM_PLAINTEXT_LENGTH
)
.to_string(),
};
}
let dummy_surb = [0; 16];
let input_msg = InputMessage(Destination::new(recipient_address, dummy_surb), msg);
input_tx.send(input_msg).await.unwrap();
+2 -10
View File
@@ -188,20 +188,12 @@ impl ClientRequest {
mut input_tx: mpsc::UnboundedSender<InputMessage>,
) -> ServerResponse {
let message_bytes = msg.into_bytes();
// TODO: wait until 0.4.0 release to replace those constants with newly exposed
// sphinx::constants::MAXIMUM_PLAINTEXT_LENGTH
// we can't do it now for compatibility reasons as most recent sphinx revision
// has breaking changes due to packet format changes
let maximum_plaintext_length = sphinx::constants::PAYLOAD_SIZE
- sphinx::constants::SECURITY_PARAMETER
- sphinx::constants::DESTINATION_ADDRESS_LENGTH
- 1;
if message_bytes.len() > maximum_plaintext_length {
if message_bytes.len() > sphinx::constants::MAXIMUM_PLAINTEXT_LENGTH {
return ServerResponse::Error {
message: format!(
"too long message. Sent {} bytes while the maximum is {}",
message_bytes.len(),
maximum_plaintext_length
sphinx::constants::MAXIMUM_PLAINTEXT_LENGTH
)
.to_string(),
};