Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion zebra-rpc/src/indexer/server.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! A tonic RPC server for Zebra's indexer API.

use std::net::SocketAddr;
use std::{net::SocketAddr, time::Duration};

use tokio::task::JoinHandle;
use tonic::transport::{server::TcpIncoming, Server};
Expand All @@ -11,6 +11,19 @@ use zebra_state::ReadState;

use crate::{indexer::indexer_server::IndexerServer, server::OPENED_RPC_ENDPOINT_MSG};

/// Maximum concurrent HTTP/2 streams per connection.
///
/// The primary clients (Zaino and Zallet) each open 1-2 streams via
/// `init_read_state_with_syncer`. 20 provides generous headroom while
/// bounding resource usage from untrusted clients.
const MAX_CONCURRENT_STREAMS: u32 = 20;

/// Interval between HTTP/2 keepalive pings sent to detect dead connections.
const HTTP2_KEEPALIVE_INTERVAL: Duration = Duration::from_secs(30);

/// Timeout for HTTP/2 keepalive pings before the connection is closed.
const HTTP2_KEEPALIVE_TIMEOUT: Duration = Duration::from_secs(10);

type ServerTask = JoinHandle<Result<(), BoxError>>;

/// Indexer RPC service.
Expand Down Expand Up @@ -56,6 +69,9 @@ where

let server_task: JoinHandle<Result<(), BoxError>> = tokio::spawn(async move {
Server::builder()
.max_concurrent_streams(Some(MAX_CONCURRENT_STREAMS))
.http2_keepalive_interval(Some(HTTP2_KEEPALIVE_INTERVAL))
.http2_keepalive_timeout(Some(HTTP2_KEEPALIVE_TIMEOUT))
.add_service(reflection_service)
.add_service(IndexerServer::new(indexer_service))
.serve_with_incoming(TcpIncoming::from(tcp_listener))
Expand Down
Loading