add tls support to client (#8)

This commit is contained in:
Kirill Fomichev 2022-11-21 12:44:56 -03:00 committed by GitHub
parent 7ba8c653aa
commit 42dd0a9244
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 103 additions and 19 deletions

64
Cargo.lock generated
View File

@ -571,6 +571,16 @@ version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc"
[[package]]
name = "core-foundation"
version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146"
dependencies = [
"core-foundation-sys",
"libc",
]
[[package]]
name = "core-foundation-sys"
version = "0.8.3"
@ -1652,6 +1662,12 @@ version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5"
[[package]]
name = "openssl-probe"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf"
[[package]]
name = "os_str_bytes"
version = "6.3.0"
@ -2148,6 +2164,18 @@ dependencies = [
"webpki",
]
[[package]]
name = "rustls-native-certs"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0167bac7a9f490495f3c33013e7722b53cb087ecbe082fb0c6387c96f634ea50"
dependencies = [
"openssl-probe",
"rustls-pemfile",
"schannel",
"security-framework",
]
[[package]]
name = "rustls-pemfile"
version = "1.0.1"
@ -2169,6 +2197,16 @@ version = "1.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09"
[[package]]
name = "schannel"
version = "0.1.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "88d6731146462ea25d9244b2ed5fd1d716d25c52e4d54aa4fb0f3c4e9854dbe2"
dependencies = [
"lazy_static",
"windows-sys 0.36.1",
]
[[package]]
name = "scopeguard"
version = "1.1.0"
@ -2191,6 +2229,29 @@ dependencies = [
"untrusted",
]
[[package]]
name = "security-framework"
version = "2.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2bc1bb97804af6631813c55739f771071e0f2ed33ee20b68c86ec505d906356c"
dependencies = [
"bitflags",
"core-foundation",
"core-foundation-sys",
"libc",
"security-framework-sys",
]
[[package]]
name = "security-framework-sys"
version = "2.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0160a13a177a45bfb43ce71c01580998474f556ad854dcbca936dd2841a5c556"
dependencies = [
"core-foundation-sys",
"libc",
]
[[package]]
name = "semver"
version = "1.0.14"
@ -3008,7 +3069,10 @@ dependencies = [
"pin-project",
"prost",
"prost-derive",
"rustls-native-certs",
"rustls-pemfile",
"tokio",
"tokio-rustls",
"tokio-stream",
"tokio-util",
"tower",

View File

@ -25,7 +25,7 @@ solana-sdk = "=1.13.4"
solana-transaction-status = "=1.13.4"
tokio = { version = "1.21.2", features = ["rt-multi-thread", "macros", "time"] }
tokio-stream = "0.1.11"
tonic = { version = "0.8.2", features = ["gzip"] }
tonic = { version = "0.8.2", features = ["gzip", "tls", "tls-roots"] }
[build-dependencies]
anyhow = "1.0.62"

View File

@ -7,7 +7,10 @@ use {
SubscribeRequestFilterTransactions,
},
std::collections::HashMap,
tonic::Request,
tonic::{
transport::{channel::ClientTlsConfig, Endpoint, Uri},
Request,
},
};
#[derive(Debug, Parser)]
@ -21,13 +24,13 @@ struct Args {
/// Subscribe on accounts updates
accounts: bool,
#[clap(short, long)]
#[clap(long)]
/// Filter by Account Pubkey
account: Vec<String>,
accounts_account: Vec<String>,
#[clap(short, long)]
#[clap(long)]
/// Filter by Owner Pubkey
owner: Vec<String>,
accounts_owner: Vec<String>,
#[clap(long)]
/// Subscribe on slots updates
@ -37,13 +40,21 @@ struct Args {
/// Subscribe on transactions updates
transactions: bool,
#[clap(short, long)]
#[clap(long)]
/// Filter vote transactions
vote: Option<bool>,
transactions_vote: Option<bool>,
#[clap(short, long)]
#[clap(long)]
/// Filter failed transactions
failed: Option<bool>,
transactions_failed: Option<bool>,
#[clap(long)]
/// Filter included account in transactions
transactions_account_include: Vec<String>,
#[clap(long)]
/// Filter excluded account in transactions
transactions_account_exclude: Vec<String>,
#[clap(long)]
/// Subscribe on block updates
@ -59,8 +70,8 @@ async fn main() -> anyhow::Result<()> {
accounts.insert(
"client".to_owned(),
SubscribeRequestFilterAccounts {
account: args.account,
owner: args.owner,
account: args.accounts_account,
owner: args.accounts_owner,
},
);
}
@ -75,10 +86,10 @@ async fn main() -> anyhow::Result<()> {
transactions.insert(
"client".to_string(),
SubscribeRequestFilterTransactions {
vote: args.vote,
failed: args.failed,
account_include: vec![],
account_exclude: vec![],
vote: args.transactions_vote,
failed: args.transactions_failed,
account_include: args.transactions_account_include,
account_exclude: args.transactions_account_exclude,
},
);
}
@ -88,13 +99,22 @@ async fn main() -> anyhow::Result<()> {
blocks.insert("client".to_owned(), SubscribeRequestFilterBlocks {});
}
let mut client = GeyserClient::connect(args.endpoint).await?;
let request = Request::new(SubscribeRequest {
let mut endpoint = Endpoint::from_shared(args.endpoint.clone())?;
let uri: Uri = args.endpoint.parse()?;
if uri.scheme_str() == Some("https") {
endpoint = endpoint.tls_config(ClientTlsConfig::new())?;
}
let mut client = GeyserClient::connect(endpoint).await?;
let request = SubscribeRequest {
slots,
accounts,
transactions,
blocks,
});
};
println!("Going to send request: {:?}", request);
let request = Request::new(request);
let response = client.subscribe(request).await?;
let mut stream = response.into_inner();