11//! A tonic RPC server for Zebra's indexer API.
22
3- use std:: net:: SocketAddr ;
3+ use std:: { net:: SocketAddr , time :: Duration } ;
44
55use tokio:: task:: JoinHandle ;
66use tonic:: transport:: { server:: TcpIncoming , Server } ;
@@ -11,6 +11,19 @@ use zebra_state::ReadState;
1111
1212use crate :: { indexer:: indexer_server:: IndexerServer , server:: OPENED_RPC_ENDPOINT_MSG } ;
1313
14+ /// Maximum concurrent HTTP/2 streams per connection.
15+ ///
16+ /// The primary clients (Zaino and Zallet) each open 1-2 streams via
17+ /// `init_read_state_with_syncer`. 20 provides generous headroom while
18+ /// bounding resource usage from untrusted clients.
19+ const MAX_CONCURRENT_STREAMS : u32 = 20 ;
20+
21+ /// Interval between HTTP/2 keepalive pings sent to detect dead connections.
22+ const HTTP2_KEEPALIVE_INTERVAL : Duration = Duration :: from_secs ( 30 ) ;
23+
24+ /// Timeout for HTTP/2 keepalive pings before the connection is closed.
25+ const HTTP2_KEEPALIVE_TIMEOUT : Duration = Duration :: from_secs ( 10 ) ;
26+
1427type ServerTask = JoinHandle < Result < ( ) , BoxError > > ;
1528
1629/// Indexer RPC service.
5669
5770 let server_task: JoinHandle < Result < ( ) , BoxError > > = tokio:: spawn ( async move {
5871 Server :: builder ( )
72+ . max_concurrent_streams ( Some ( MAX_CONCURRENT_STREAMS ) )
73+ . http2_keepalive_interval ( Some ( HTTP2_KEEPALIVE_INTERVAL ) )
74+ . http2_keepalive_timeout ( Some ( HTTP2_KEEPALIVE_TIMEOUT ) )
5975 . add_service ( reflection_service)
6076 . add_service ( IndexerServer :: new ( indexer_service) )
6177 . serve_with_incoming ( TcpIncoming :: from ( tcp_listener) )
0 commit comments