Use DestroyReason for Truncated messages.

This commit is contained in:
Nick Mathewson 2020-10-19 13:38:15 -04:00
parent e83d8ec3c2
commit 2bd30f2db3
2 changed files with 6 additions and 8 deletions

View File

@ -4,7 +4,7 @@
//! cells.
use super::RelayCmd;
use crate::chancell::msg::{TAP_C_HANDSHAKE_LEN, TAP_S_HANDSHAKE_LEN};
use crate::chancell::msg::{DestroyReason, TAP_C_HANDSHAKE_LEN, TAP_S_HANDSHAKE_LEN};
use crate::chancell::CELL_DATA_LEN;
use caret::caret_int;
use std::net::{IpAddr, Ipv4Addr};
@ -664,13 +664,11 @@ impl Body for Extended2 {
#[derive(Debug, Clone)]
pub struct Truncated {
/// Reason for which this circuit was truncated.
reason: u8,
reason: DestroyReason,
}
impl Truncated {
/// Construct a new truncated message.
///
/// TODO: add an enum for reasons. XXXXM3
pub fn new(reason: u8) -> Self {
pub fn new(reason: DestroyReason) -> Self {
Truncated { reason }
}
}
@ -680,11 +678,11 @@ impl Body for Truncated {
}
fn decode_from_reader(r: &mut Reader<'_>) -> Result<Self> {
Ok(Truncated {
reason: r.take_u8()?,
reason: r.take_u8()?.into(),
})
}
fn encode_onto(self, w: &mut Vec<u8>) {
w.write_u8(self.reason);
w.write_u8(self.reason.into());
}
}

View File

@ -197,7 +197,7 @@ fn test_truncated() {
let cmd = RelayCmd::TRUNCATED;
assert_eq!(Into::<u8>::into(cmd), 9_u8);
msg(cmd, "08", &msg::Truncated::new(8).into());
msg(cmd, "08", &msg::Truncated::new(8.into()).into());
}
/* For circuit padding: