use crate::{ChanTarget, CircTarget, EncodedLinkSpec, HasAddrs, HasChanMethod, HasRelayIds};
#[derive(Clone, Debug)]
pub struct VerbatimLinkSpecCircTarget<T> {
target: T,
linkspecs: Vec<EncodedLinkSpec>,
}
impl<T> VerbatimLinkSpecCircTarget<T> {
pub fn new(target: T, linkspecs: Vec<EncodedLinkSpec>) -> Self {
Self { target, linkspecs }
}
}
impl<T: HasRelayIds> HasRelayIds for VerbatimLinkSpecCircTarget<T> {
fn identity(&self, key_type: crate::RelayIdType) -> Option<crate::RelayIdRef<'_>> {
self.target.identity(key_type)
}
}
impl<T: HasAddrs> HasAddrs for VerbatimLinkSpecCircTarget<T> {
fn addrs(&self) -> &[std::net::SocketAddr] {
self.target.addrs()
}
}
impl<T: HasChanMethod> HasChanMethod for VerbatimLinkSpecCircTarget<T> {
fn chan_method(&self) -> crate::ChannelMethod {
self.target.chan_method()
}
}
impl<T: ChanTarget> ChanTarget for VerbatimLinkSpecCircTarget<T> {}
impl<T: CircTarget> CircTarget for VerbatimLinkSpecCircTarget<T> {
fn linkspecs(&self) -> tor_bytes::EncodeResult<Vec<EncodedLinkSpec>> {
Ok(self.linkspecs.clone())
}
fn ntor_onion_key(&self) -> &tor_llcrypto::pk::curve25519::PublicKey {
self.target.ntor_onion_key()
}
fn protovers(&self) -> &tor_protover::Protocols {
self.target.protovers()
}
}
#[cfg(test)]
mod test {
#![allow(clippy::bool_assert_comparison)]
#![allow(clippy::clone_on_copy)]
#![allow(clippy::dbg_macro)]
#![allow(clippy::mixed_attributes_style)]
#![allow(clippy::print_stderr)]
#![allow(clippy::print_stdout)]
#![allow(clippy::single_char_pattern)]
#![allow(clippy::unwrap_used)]
#![allow(clippy::unchecked_duration_subtraction)]
#![allow(clippy::useless_vec)]
#![allow(clippy::needless_pass_by_value)]
use crate::OwnedCircTarget;
use super::*;
#[test]
fn verbatim_linkspecs() {
let mut builder = OwnedCircTarget::builder();
builder
.chan_target()
.addrs(vec!["127.0.0.1:11".parse().unwrap()])
.ed_identity([42; 32].into())
.rsa_identity([45; 20].into());
let inner = builder
.ntor_onion_key([99; 32].into())
.protocols("FlowCtrl=7".parse().unwrap())
.build()
.unwrap();
let weird_linkspecs = vec![EncodedLinkSpec::new(
77.into(),
b"mysterious whisper".to_vec(),
)];
let wrapped = VerbatimLinkSpecCircTarget::new(inner.clone(), weird_linkspecs.clone());
assert_eq!(wrapped.addrs(), inner.addrs());
assert!(wrapped.same_relay_ids(&inner));
assert_eq!(wrapped.ntor_onion_key(), inner.ntor_onion_key());
assert_eq!(wrapped.protovers(), inner.protovers());
assert_ne!(inner.linkspecs().unwrap(), weird_linkspecs);
assert_eq!(wrapped.linkspecs().unwrap(), weird_linkspecs);
}
}