snake_cased replySURBs (#322)

This commit is contained in:
Jędrzej Stuczyński
2020-09-08 13:11:22 +01:00
committed by GitHub
parent 80d01f1f75
commit ae40b0d857
10 changed files with 24 additions and 29 deletions
@@ -207,7 +207,7 @@ impl ReceivedMessagesBuffer {
// TODO: perhaps having to say it doesn't have a surb an indication the type should be changed?
Some(ReconstructedMessage {
message: reply_msg,
reply_SURB: None,
reply_surb: None,
})
}
}
@@ -43,7 +43,6 @@ func makeSendRequest(recipient []byte, message []byte, withReplySurb bool) []byt
out = append(out, messageLen...)
out = append(out, message...)
fmt.Println("first send req: ", out[:10])
return out
}
@@ -103,13 +103,13 @@ func sendWithReply() {
}
// use the received surb to send an anonymous reply!
replySURB := receivedMessageJson["replySURB"]
replySurb := receivedMessageJson["replySurb"]
replyMessage := "hello from reply SURB!"
reply, err := json.Marshal(map[string]interface{}{
"type": "reply",
"message": replyMessage,
"replySURB": replySURB,
"replySurb": replySurb,
})
if err != nil {
panic(err)
@@ -55,13 +55,13 @@ async def send_text_with_reply():
print("received '{}' from the mix network".format(received_message))
# use the received surb to send an anonymous reply!
reply_surb = received_message["replySURB"]
reply_surb = received_message["replySurb"]
reply_message = "hello from reply SURB!"
reply = json.dumps({
"type": "reply",
"message": reply_message,
"replySURB": reply_surb
"replySurb": reply_surb
})
print("sending '{}' (using reply SURB!) over the mix network...".format(reply_message))
@@ -57,7 +57,7 @@ async fn send_file_with_reply() {
let reply_message = b"hello from reply SURB! - thanks for sending me the file!".to_vec();
let reply_request = ClientRequest::Reply {
message: reply_message.clone(),
reply_surb: received.reply_SURB.unwrap(),
reply_surb: received.reply_surb.unwrap(),
};
println!(
@@ -54,7 +54,7 @@ async fn send_text_with_reply() {
let reply_request = json!({
"type": "reply",
"message": reply_message,
"replySURB": response["replySURB"]
"replySurb": response["replySurb"]
});
println!(
@@ -50,7 +50,7 @@ impl ServerResponse {
// RECEIVED_RESPONSE_TAG || with_reply || (surb_len || surb) || msg_len || msg
fn serialize_received(reconstructed_message: ReconstructedMessage) -> Vec<u8> {
let message_len_bytes = (reconstructed_message.message.len() as u64).to_be_bytes();
if let Some(reply_surb) = reconstructed_message.reply_SURB {
if let Some(reply_surb) = reconstructed_message.reply_surb {
let reply_surb_bytes = reply_surb.to_bytes();
let surb_len_bytes = (reply_surb_bytes.len() as u64).to_be_bytes();
@@ -141,7 +141,7 @@ impl ServerResponse {
Ok(ServerResponse::Received(ReconstructedMessage {
message: message.to_vec(),
reply_SURB: Some(reply_surb),
reply_surb: Some(reply_surb),
}))
} else {
let message_len =
@@ -160,7 +160,7 @@ impl ServerResponse {
Ok(ServerResponse::Received(ReconstructedMessage {
message: message.to_vec(),
reply_SURB: None,
reply_surb: None,
}))
}
}
@@ -341,7 +341,7 @@ mod tests {
let received_with_surb = ServerResponse::Received(ReconstructedMessage {
message: b"foomp".to_vec(),
reply_SURB: Some(ReplySURB::from_base58_string(reply_surb_string).unwrap()),
reply_surb: Some(ReplySURB::from_base58_string(reply_surb_string).unwrap()),
});
let bytes = received_with_surb.serialize();
let recovered = ServerResponse::deserialize(&bytes).unwrap();
@@ -349,7 +349,7 @@ mod tests {
ServerResponse::Received(reconstructed) => {
assert_eq!(reconstructed.message, b"foomp".to_vec());
assert_eq!(
reconstructed.reply_SURB.unwrap().to_base58_string(),
reconstructed.reply_surb.unwrap().to_base58_string(),
reply_surb_string
)
}
@@ -358,14 +358,14 @@ mod tests {
let received_without_surb = ServerResponse::Received(ReconstructedMessage {
message: b"foomp".to_vec(),
reply_SURB: None,
reply_surb: None,
});
let bytes = received_without_surb.serialize();
let recovered = ServerResponse::deserialize(&bytes).unwrap();
match recovered {
ServerResponse::Received(reconstructed) => {
assert_eq!(reconstructed.message, b"foomp".to_vec());
assert!(reconstructed.reply_SURB.is_none())
assert!(reconstructed.reply_surb.is_none())
}
_ => unreachable!(),
}
@@ -23,7 +23,6 @@ use std::convert::{TryFrom, TryInto};
// local text equivalent of `ClientRequest` for easier serialization + deserialization with serde
// TODO: figure out if there's an easy way to avoid defining it
#[allow(non_snake_case)]
#[derive(Serialize, Deserialize, Debug)]
#[serde(tag = "type", rename_all = "camelCase")]
pub(super) enum ClientRequestText {
@@ -37,7 +36,7 @@ pub(super) enum ClientRequestText {
#[serde(rename_all = "camelCase")]
Reply {
message: String,
reply_SURB: String,
reply_surb: String,
},
}
@@ -73,10 +72,10 @@ impl TryInto<ClientRequest> for ClientRequestText {
ClientRequestText::SelfAddress => Ok(ClientRequest::SelfAddress),
ClientRequestText::Reply {
message,
reply_SURB,
reply_surb,
} => {
let message_bytes = message.into_bytes();
let reply_surb = ReplySURB::from_base58_string(reply_SURB).map_err(|err| {
let reply_surb = ReplySURB::from_base58_string(reply_surb).map_err(|err| {
Self::Error::new(ErrorKind::MalformedRequest, err.to_string())
})?;
@@ -92,14 +91,13 @@ impl TryInto<ClientRequest> for ClientRequestText {
// local text equivalent of `ServerResponse` for easier serialization + deserialization with serde
// TODO: figure out if there's an easy way to avoid defining it
#[allow(non_snake_case)]
#[derive(Serialize, Deserialize, Debug)]
#[serde(tag = "type", rename_all = "camelCase")]
pub(super) enum ServerResponseText {
#[serde(rename_all = "camelCase")]
Received {
message: String,
reply_SURB: Option<String>,
reply_surb: Option<String>,
},
SelfAddress {
address: String,
@@ -137,8 +135,8 @@ impl From<ServerResponse> for ServerResponseText {
// TODO: ask DH what is more appropriate, lossy utf8 conversion or returning error and then
// pure binary later
message: String::from_utf8_lossy(&reconstructed.message).into_owned(),
reply_SURB: reconstructed
.reply_SURB
reply_surb: reconstructed
.reply_surb
.map(|reply_surb| reply_surb.to_base58_string()),
}
}
+1 -1
View File
@@ -40,7 +40,7 @@ impl MixnetResponseListener {
async fn on_message(&self, reconstructed_message: ReconstructedMessage) {
let raw_message = reconstructed_message.message;
if reconstructed_message.reply_SURB.is_some() {
if reconstructed_message.reply_surb.is_some() {
warn!("this message had a surb - we didn't do anything with it");
}
+3 -5
View File
@@ -21,14 +21,13 @@ use nymsphinx_chunking::reconstruction::MessageReconstructor;
use nymsphinx_params::{PacketEncryptionAlgorithm, PacketHkdfAlgorithm, DEFAULT_NUM_MIX_HOPS};
// TODO: should this live in this file?
#[allow(non_snake_case)]
#[derive(Debug)]
pub struct ReconstructedMessage {
/// The actual plaintext message that was received.
pub message: Vec<u8>,
/// Optional ReplySURB to allow for an anonymous reply to the sender.
pub reply_SURB: Option<ReplySURB>,
pub reply_surb: Option<ReplySURB>,
}
#[derive(Debug)]
@@ -157,9 +156,8 @@ impl MessageReceiver {
fragment: Fragment,
) -> Result<Option<(ReconstructedMessage, Vec<i32>)>, MessageRecoveryError> {
if let Some((mut message, used_sets)) = self.reconstructor.insert_new_fragment(fragment) {
#[allow(non_snake_case)]
// Split message into plaintext and reply-SURB
let reply_SURB = match self.recover_reply_surb_from_message(&mut message) {
let reply_surb = match self.recover_reply_surb_from_message(&mut message) {
Ok(reply_surb) => reply_surb,
Err(_) => {
return Err(MessageRecoveryError::MalformedReconstructedMessage(
@@ -178,7 +176,7 @@ impl MessageReceiver {
Ok(Some((
ReconstructedMessage {
message,
reply_SURB,
reply_surb,
},
used_sets,
)))