mirror of
https://github.com/0glabs/0g-storage-node.git
synced 2025-11-03 08:07:27 +00:00
add reflection
This commit is contained in:
parent
a4b0bc1dac
commit
cb18ffd6c3
2
.gitignore
vendored
2
.gitignore
vendored
@ -7,3 +7,5 @@ tests/tmp/**
|
||||
.vscode/*.json
|
||||
/0g-storage-contracts-dev
|
||||
/run/.env
|
||||
|
||||
**.bin
|
||||
|
||||
14
Cargo.lock
generated
14
Cargo.lock
generated
@ -7015,6 +7015,7 @@ dependencies = [
|
||||
"tokio",
|
||||
"tonic 0.9.2",
|
||||
"tonic-build",
|
||||
"tonic-reflection",
|
||||
"tracing",
|
||||
]
|
||||
|
||||
@ -8385,6 +8386,19 @@ dependencies = [
|
||||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tonic-reflection"
|
||||
version = "0.9.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0543d7092032041fbeac1f2c84304537553421a11a623c2301b12ef0264862c7"
|
||||
dependencies = [
|
||||
"prost 0.11.9",
|
||||
"prost-types 0.11.9",
|
||||
"tokio",
|
||||
"tokio-stream",
|
||||
"tonic 0.9.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tower"
|
||||
version = "0.4.13"
|
||||
|
||||
@ -32,6 +32,7 @@ parking_lot = "0.12.3"
|
||||
tonic = { version = "0.9.2", features = ["transport"] }
|
||||
prost = "0.11.9"
|
||||
prost-types = "0.11.9"
|
||||
tonic-reflection = "0.9.2"
|
||||
|
||||
[build-dependencies]
|
||||
tonic-build = "0.9.2"
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
// Compile proto/my_service.proto
|
||||
tonic_build::compile_protos("proto/zgs_grpc.proto")?;
|
||||
tonic_build::configure()
|
||||
.file_descriptor_set_path("proto/zgs_grpc_descriptor.bin")
|
||||
.compile(&["proto/zgs_grpc.proto"], &["proto"])?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -34,6 +34,9 @@ pub use admin::RpcClient as ZgsAdminRpcClient;
|
||||
pub use config::Config as RPCConfig;
|
||||
pub use miner::RpcClient as ZgsMinerRpcClient;
|
||||
pub use zgs::RpcClient as ZgsRPCClient;
|
||||
// bring in the reflection-builder
|
||||
use tonic_reflection::server::Builder as ReflectionBuilder;
|
||||
|
||||
|
||||
pub mod zgs_grpc_proto {
|
||||
tonic::include_proto!("zgs_grpc");
|
||||
@ -43,6 +46,8 @@ mod zgs_grpc;
|
||||
|
||||
use tonic::transport::Server;
|
||||
|
||||
const DESCRIPTOR_SET: &[u8] = include_bytes!("../proto/zgs_grpc_descriptor.bin");
|
||||
|
||||
/// A wrapper around all the items required to spawn the HTTP server.
|
||||
///
|
||||
/// The server will gracefully handle the case where any fields are `None`.
|
||||
@ -146,9 +151,14 @@ async fn run_server_public_private(
|
||||
|
||||
pub async fn run_grpc_server(ctx: Context) -> Result<(), Box<dyn Error>> {
|
||||
let grpc_addr = ctx.config.listen_address_grpc;
|
||||
let reflection = ReflectionBuilder::configure()
|
||||
.register_encoded_file_descriptor_set(DESCRIPTOR_SET)
|
||||
.build()?;
|
||||
|
||||
let server = ZgsGrpcServiceServer::new(ZgsGrpcServiceImpl { ctx });
|
||||
Server::builder()
|
||||
.add_service(server)
|
||||
.add_service(reflection)
|
||||
.serve(grpc_addr)
|
||||
.await?;
|
||||
Ok(())
|
||||
|
||||
Loading…
Reference in New Issue
Block a user