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 regex::Regex;
use tonic::transport::Certificate;
use tonic::transport::Channel;
use tonic::transport::ClientTlsConfig;
use tonic::transport::Identity;
use tonic::transport::{Certificate, Endpoint};
use crate::internal_err;
use crate::Result;
@ -77,27 +77,40 @@ impl SecurityManager {
where
Factory: FnOnce(Channel) -> Client,
{
let addr = "http://".to_string() + &SCHEME_REG.replace(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)?
.tcp_keepalive(Some(Duration::from_secs(10)))
.keep_alive_timeout(Duration::from_secs(3));
Ok(factory(ch))
}
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()
.ca_certificate(Certificate::from_pem(&self.ca))
.identity(Identity::from_pem(
&self.cert,
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::ops::Bound;
use std::u8;
#[allow(unused_imports)]
#[cfg(test)]

View File

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

View File

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

View File

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