tor_proto/crypto/cell/
bench_utils.rs1pub use super::ClientLayer;
3pub use super::CryptInit;
4pub use super::InboundClientCrypt;
5pub use super::InboundClientLayer;
6pub use super::InboundRelayLayer;
7pub use super::OutboundClientCrypt;
8pub use super::OutboundClientLayer;
9pub use super::OutboundRelayLayer;
10pub use super::RelayCellBody;
11pub use super::RelayLayer;
12#[cfg(feature = "counter-galois-onion")]
13pub use super::cgo::bench_utils as cgo;
14pub use super::tor1::bench_utils as tor1;
15use super::*;
16
17pub const BENCH_CHAN_CMD: ChanCmd = ChanCmd::RELAY;
19
20impl InboundClientCrypt {
21 pub fn add_layer_from_pair<F, B>(&mut self, pair: impl ClientLayer<F, B>)
23 where
24 F: OutboundClientLayer,
25 B: InboundClientLayer + Send + 'static,
26 {
27 let (_, inbound, _) = pair.split_client_layer();
28 self.add_layer(Box::new(inbound));
29 }
30}
31
32impl OutboundClientCrypt {
33 pub fn add_layer_from_pair<F, B>(&mut self, pair: impl ClientLayer<F, B>)
35 where
36 F: OutboundClientLayer + Send + 'static,
37 B: InboundClientLayer,
38 {
39 let (outbound, _, _) = pair.split_client_layer();
40 self.add_layer(Box::new(outbound));
41 }
42}
43
44pub fn circuit_encrypt_inbound<F, B>(
46 cmd: ChanCmd,
47 cell: &mut RelayCellBody,
48 relay_states: Vec<impl RelayLayer<F, B>>,
49) where
50 F: OutboundRelayLayer,
51 B: InboundRelayLayer,
52{
53 for (i, state) in relay_states.into_iter().rev().enumerate() {
54 let (_, mut inbound, _) = state.split_relay_layer();
55 if i == 0 {
56 inbound.originate(cmd, cell);
57 } else {
58 inbound.encrypt_inbound(cmd, cell);
59 }
60 }
61}