1use crate::{ChanTarget, CircTarget, EncodedLinkSpec, HasAddrs, HasChanMethod, HasRelayIds};
5
6#[derive(Clone, Debug)]
13pub struct VerbatimLinkSpecCircTarget<T> {
14 target: T,
16 linkspecs: Vec<EncodedLinkSpec>,
18}
19
20impl<T> VerbatimLinkSpecCircTarget<T> {
21 pub fn new(target: T, linkspecs: Vec<EncodedLinkSpec>) -> Self {
30 Self { target, linkspecs }
31 }
32}
33
34impl<T: HasRelayIds> HasRelayIds for VerbatimLinkSpecCircTarget<T> {
38 fn identity(&self, key_type: crate::RelayIdType) -> Option<crate::RelayIdRef<'_>> {
39 self.target.identity(key_type)
40 }
41}
42impl<T: HasAddrs> HasAddrs for VerbatimLinkSpecCircTarget<T> {
43 fn addrs(&self) -> &[std::net::SocketAddr] {
44 self.target.addrs()
45 }
46}
47impl<T: HasChanMethod> HasChanMethod for VerbatimLinkSpecCircTarget<T> {
48 fn chan_method(&self) -> crate::ChannelMethod {
49 self.target.chan_method()
50 }
51}
52impl<T: ChanTarget> ChanTarget for VerbatimLinkSpecCircTarget<T> {}
53impl<T: CircTarget> CircTarget for VerbatimLinkSpecCircTarget<T> {
54 fn linkspecs(&self) -> tor_bytes::EncodeResult<Vec<EncodedLinkSpec>> {
55 Ok(self.linkspecs.clone())
56 }
57
58 fn ntor_onion_key(&self) -> &tor_llcrypto::pk::curve25519::PublicKey {
59 self.target.ntor_onion_key()
60 }
61
62 fn protovers(&self) -> &tor_protover::Protocols {
63 self.target.protovers()
64 }
65}
66
67#[cfg(test)]
68mod test {
69 #![allow(clippy::bool_assert_comparison)]
71 #![allow(clippy::clone_on_copy)]
72 #![allow(clippy::dbg_macro)]
73 #![allow(clippy::mixed_attributes_style)]
74 #![allow(clippy::print_stderr)]
75 #![allow(clippy::print_stdout)]
76 #![allow(clippy::single_char_pattern)]
77 #![allow(clippy::unwrap_used)]
78 #![allow(clippy::unchecked_duration_subtraction)]
79 #![allow(clippy::useless_vec)]
80 #![allow(clippy::needless_pass_by_value)]
81 use crate::OwnedCircTarget;
84
85 use super::*;
86 #[test]
87 fn verbatim_linkspecs() {
88 let mut builder = OwnedCircTarget::builder();
89 builder
90 .chan_target()
91 .addrs(vec!["127.0.0.1:11".parse().unwrap()])
92 .ed_identity([42; 32].into())
93 .rsa_identity([45; 20].into());
94 let inner = builder
95 .ntor_onion_key([99; 32].into())
96 .protocols("FlowCtrl=7".parse().unwrap())
97 .build()
98 .unwrap();
99 let weird_linkspecs = vec![EncodedLinkSpec::new(
100 77.into(),
101 b"mysterious whisper".to_vec(),
102 )];
103 let wrapped = VerbatimLinkSpecCircTarget::new(inner.clone(), weird_linkspecs.clone());
104
105 assert_eq!(wrapped.addrs(), inner.addrs());
106 assert!(wrapped.same_relay_ids(&inner));
107 assert_eq!(wrapped.ntor_onion_key(), inner.ntor_onion_key());
108 assert_eq!(wrapped.protovers(), inner.protovers());
109
110 assert_ne!(inner.linkspecs().unwrap(), weird_linkspecs);
111 assert_eq!(wrapped.linkspecs().unwrap(), weird_linkspecs);
112 }
113}