Merge branch 'master' into minor

This commit is contained in:
Nick Cameron 2019-06-04 14:14:16 +12:00 committed by GitHub
commit cc3002c924
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 6 deletions

View File

@ -18,6 +18,7 @@ integration-tests = []
name = "tikv_client"
[dependencies]
regex = "1"
failure = "0.1"
futures-preview = { version = "0.3.0-alpha.15", features = ["compat"] }
grpcio = { version = "0.5.0-alpha", features = [ "secure", "prost-codec" ], default-features = false }

View File

@ -95,7 +95,7 @@ pub enum ErrorKind {
}
impl Fail for Error {
fn cause(&self) -> Option<&Fail> {
fn cause(&self) -> Option<&dyn Fail> {
self.inner.cause()
}

View File

@ -9,10 +9,16 @@ use std::{
};
use grpcio::{Channel, ChannelBuilder, ChannelCredentialsBuilder, Environment};
use lazy_static::*;
use log::*;
use regex::Regex;
use crate::Result;
lazy_static! {
static ref SCHEME_REG: Regex = Regex::new(r"^\s*(https?://)").unwrap();
}
fn check_pem_file(tag: &str, path: &Path) -> Result<File> {
File::open(path)
.map_err(|e| internal_err!("failed to open {} to load {}: {:?}", path.display(), tag, e))
@ -65,21 +71,21 @@ impl SecurityManager {
Factory: FnOnce(Channel) -> Client,
{
info!("connect to rpc server at endpoint: {:?}", addr);
let addr = addr
.trim_start_matches("http://")
.trim_start_matches("https://");
let addr = SCHEME_REG.replace(addr, "");
let cb = ChannelBuilder::new(env)
.keepalive_time(Duration::from_secs(10))
.keepalive_timeout(Duration::from_secs(3));
let channel = if self.ca.is_empty() {
cb.connect(addr)
cb.connect(&addr)
} else {
let cred = ChannelCredentialsBuilder::new()
.root_cert(self.ca.clone())
.cert(self.cert.clone(), load_pem_file("private key", &self.key)?)
.build();
cb.secure_connect(addr, cred)
cb.secure_connect(&addr, cred)
};
Ok(factory(channel))