Skip to content

Commit

Permalink
feat(sni_sniffer): normalize address
Browse files Browse the repository at this point in the history
  • Loading branch information
spacemeowx2 committed Aug 31, 2023
1 parent 76fc51f commit 60a49d5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions rd-interface/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,18 @@ impl Address {
}
}

/// parse domain first, if it can be parsed as IP address,
/// then return it, otherwise return the original domain.
pub fn into_normalized(self) -> Address {
match self {
Address::SocketAddr(_) => self,
Address::Domain(d, p) => match strip_brackets(&d).parse::<IpAddr>() {
Ok(ip) => Address::SocketAddr(SocketAddr::new(ip, p)),
Err(_) => Address::Domain(d, p),

Check warning on line 267 in rd-interface/src/address.rs

View check run for this annotation

Codecov / codecov/patch

rd-interface/src/address.rs#L262-L267

Added lines #L262 - L267 were not covered by tests
},
}
}

/// Returns true if the address is domain.
pub fn is_domain(&self) -> bool {
match self {
Expand Down
2 changes: 1 addition & 1 deletion rd-std/src/sniffer/sni_sniffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ impl rd_interface::ITcpStream for SnifferTcp {
let future = spawn(connect_send(
param.net.clone(),
param.ctx.clone(),
Address::Domain(sni, addr.port()),
Address::Domain(sni, addr.port()).into_normalized(),
replace(&mut param.buffer, Vec::new()),

Check warning on line 193 in rd-std/src/sniffer/sni_sniffer.rs

View check run for this annotation

Codecov / codecov/patch

rd-std/src/sniffer/sni_sniffer.rs#L181-L193

Added lines #L181 - L193 were not covered by tests
));
self.state = State::Connecting { future };
Expand Down

0 comments on commit 60a49d5

Please sign in to comment.