use super::ProxyConfig;
pub(super) fn connection_identity(config: &ProxyConfig) -> Vec<u8> {
let mut identity = Vec::new();
identity.extend_from_slice(config.uri.as_str().as_bytes());
identity.push(0);
if let Some(auth) = config.auth.as_ref() {
use std::hash::{Hash, Hasher};
let header = auth.header_value();
let mut first = std::collections::hash_map::DefaultHasher::new();
0u8.hash(&mut first);
header.hash(&mut first);
let mut second = std::collections::hash_map::DefaultHasher::new();
1u8.hash(&mut second);
header.hash(&mut second);
identity.extend_from_slice(&first.finish().to_le_bytes());
identity.extend_from_slice(&second.finish().to_le_bytes());
}
identity.push(0);
for (name, value) in config.proxy_headers.iter() {
identity.extend_from_slice(name.as_str().as_bytes());
identity.push(b':');
identity.extend_from_slice(value.as_bytes());
identity.push(0);
}
identity.extend_from_slice(
config
.proxy_tls_config
.as_ref()
.map_or(0u64, crate::tls::TlsConfig::connection_identity)
.to_ne_bytes()
.as_slice(),
);
identity.push(0);
if let Some(addresses) = config.resolved_addresses.as_ref() {
for address in addresses.iter() {
identity.extend_from_slice(address.to_string().as_bytes());
identity.push(0);
}
}
identity
}