Resolving the TLS url issue (#459)

* resolving the url issue

Signed-off-by: limbooverlambda <schakra1@gmail.com>

* fix formatting

Signed-off-by: limbooverlambda <schakra1@gmail.com>

* make check fixes

Signed-off-by: limbooverlambda <schakra1@gmail.com>

---------

Signed-off-by: limbooverlambda <schakra1@gmail.com>
This commit is contained in:
limbooverlambda 2024-06-26 18:52:33 -07:00 committed by GitHub
parent 54fd72001b
commit ec8dbccaa3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 32 additions and 22 deletions

View File

@ -8,10 +8,10 @@ use std::time::Duration;
use log::info; use log::info;
use regex::Regex; use regex::Regex;
use tonic::transport::Certificate;
use tonic::transport::Channel; use tonic::transport::Channel;
use tonic::transport::ClientTlsConfig; use tonic::transport::ClientTlsConfig;
use tonic::transport::Identity; use tonic::transport::Identity;
use tonic::transport::{Certificate, Endpoint};
use crate::internal_err; use crate::internal_err;
use crate::Result; use crate::Result;
@ -77,27 +77,40 @@ impl SecurityManager {
where where
Factory: FnOnce(Channel) -> Client, Factory: FnOnce(Channel) -> Client,
{ {
let addr = "http://".to_string() + &SCHEME_REG.replace(addr, "");
info!("connect to rpc server at endpoint: {:?}", addr); info!("connect to rpc server at endpoint: {:?}", addr);
let channel = if !self.ca.is_empty() {
self.tls_channel(addr).await?
} else {
self.default_channel(addr).await?
};
let ch = channel.connect().await?;
let mut builder = Channel::from_shared(addr)? Ok(factory(ch))
.tcp_keepalive(Some(Duration::from_secs(10))) }
.keep_alive_timeout(Duration::from_secs(3));
if !self.ca.is_empty() { async fn tls_channel(&self, addr: &str) -> Result<Endpoint> {
let addr = "https://".to_string() + &SCHEME_REG.replace(addr, "");
let builder = self.endpoint(addr.to_string())?;
let tls = ClientTlsConfig::new() let tls = ClientTlsConfig::new()
.ca_certificate(Certificate::from_pem(&self.ca)) .ca_certificate(Certificate::from_pem(&self.ca))
.identity(Identity::from_pem( .identity(Identity::from_pem(
&self.cert, &self.cert,
load_pem_file("private key", &self.key)?, load_pem_file("private key", &self.key)?,
)); ));
builder = builder.tls_config(tls)?; let builder = builder.tls_config(tls)?;
}; Ok(builder)
}
let ch = builder.connect().await?; async fn default_channel(&self, addr: &str) -> Result<Endpoint> {
let addr = "http://".to_string() + &SCHEME_REG.replace(addr, "");
self.endpoint(addr)
}
Ok(factory(ch)) fn endpoint(&self, addr: String) -> Result<Endpoint> {
let endpoint = Channel::from_shared(addr)?
.tcp_keepalive(Some(Duration::from_secs(10)))
.keep_alive_timeout(Duration::from_secs(3));
Ok(endpoint)
} }
} }

View File

@ -2,7 +2,6 @@
use std::fmt; use std::fmt;
use std::ops::Bound; use std::ops::Bound;
use std::u8;
#[allow(unused_imports)] #[allow(unused_imports)]
#[cfg(test)] #[cfg(test)]

View File

@ -1,6 +1,5 @@
// Copyright 2019 TiKV Project Authors. Licensed under Apache-2.0. // Copyright 2019 TiKV Project Authors. Licensed under Apache-2.0.
use std::fmt; use std::fmt;
use std::u8;
mod bound_range; mod bound_range;
pub mod codec; pub mod codec;

View File

@ -3,7 +3,6 @@
use core::ops::Range; use core::ops::Range;
use std::str::FromStr; use std::str::FromStr;
use std::sync::Arc; use std::sync::Arc;
use std::u32;
use futures::StreamExt; use futures::StreamExt;
use log::debug; use log::debug;

View File

@ -252,7 +252,7 @@ pub fn new_prewrite_request(
req.start_version = start_version; req.start_version = start_version;
req.lock_ttl = lock_ttl; req.lock_ttl = lock_ttl;
// FIXME: Lite resolve lock is currently disabled // FIXME: Lite resolve lock is currently disabled
req.txn_size = std::u64::MAX; req.txn_size = u64::MAX;
req req
} }