cqlsh_rs/driver/
proxy_address_translator.rs1use std::net::SocketAddr;
9
10use async_trait::async_trait;
11use scylla::errors::TranslationError;
12use scylla::policies::address_translator::{AddressTranslator, UntranslatedPeer};
13
14#[derive(Debug, Clone)]
20pub struct ProxyAddressTranslator {
21 proxy_address: SocketAddr,
23}
24
25impl ProxyAddressTranslator {
26 pub fn new(proxy_address: SocketAddr) -> Self {
28 Self { proxy_address }
29 }
30}
31
32#[async_trait]
33impl AddressTranslator for ProxyAddressTranslator {
34 async fn translate_address(
35 &self,
36 _untranslated_peer: &UntranslatedPeer,
37 ) -> Result<SocketAddr, TranslationError> {
38 Ok(self.proxy_address)
39 }
40}
41
42#[cfg(test)]
43mod tests {
44 use super::*;
45 use std::net::{IpAddr, Ipv4Addr};
46
47 fn sock(ip: [u8; 4], port: u16) -> SocketAddr {
48 SocketAddr::new(IpAddr::V4(Ipv4Addr::new(ip[0], ip[1], ip[2], ip[3])), port)
49 }
50
51 #[test]
52 fn creates_with_correct_address() {
53 let proxy_addr = sock([18, 208, 144, 200], 9042);
54 let translator = ProxyAddressTranslator::new(proxy_addr);
55 assert_eq!(translator.proxy_address, proxy_addr);
56 }
57}