Skip to content

Commit

Permalink
native_tls: minor fix
Browse files Browse the repository at this point in the history
  • Loading branch information
e1732a364fed committed Jan 1, 2099
1 parent 231ee37 commit fcb60be
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
9 changes: 6 additions & 3 deletions crates/ruci-tls/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,12 @@ impl Client {
let new_c = connector
.connect(
ServerName::try_from(
self.server_domain
.clone()
.unwrap_or(a.clone().unwrap_or_default().get_name().unwrap_or_default()),
self.server_domain.clone().unwrap_or(
a.clone()
.unwrap_or_default()
.get_name_or_ip_string()
.unwrap_or_default(),
),
)
.expect("domain string to serverName ok"),
conn,
Expand Down
16 changes: 12 additions & 4 deletions rucimp/src/map/native_tls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use ruci::{

use macro_map::*;
use tokio_native_tls::{native_tls::Identity, TlsAcceptor, TlsConnector};
use tracing::debug;

use crate::utils::FileSource;

Expand Down Expand Up @@ -156,12 +157,19 @@ impl map::Map for Client {
TlsConnector::from(b.build().unwrap())
};

if self.config.host.is_none() {
debug!("host: {:?}", params.a);
}
let r = connector
.connect(
self.config
.host
.as_ref()
.unwrap_or(&params.a.clone().unwrap().get_name().unwrap()),
self.config.host.as_ref().unwrap_or(
&params
.a
.clone()
.unwrap_or_default()
.get_name_or_ip_string()
.unwrap_or_default(),
),
conn,
)
.await;
Expand Down
14 changes: 14 additions & 0 deletions src/net/addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,20 @@ impl Addr {
_ => None,
}
}

/// used for get a domain
pub fn get_name_or_ip_string(&self) -> Option<String> {
let on = self.get_name();
if on.is_none() {
Some(match &self.addr {
NetAddr::Socket(so) => so.ip().to_string(),
NetAddr::Name(n, _) => n.clone(),
NetAddr::NameAndSocket(_, ip, _) => ip.to_string(),
})
} else {
on
}
}
pub fn get_port(&self) -> u16 {
match &self.addr {
NetAddr::Name(_, p) => *p,
Expand Down

0 comments on commit fcb60be

Please sign in to comment.