GRPC Core  9.0.0
Data Structures | Namespaces | Macros | Functions | Variables
chttp2_transport.cc File Reference
#include <grpc/support/port_platform.h>
#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
#include <inttypes.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <grpc/slice_buffer.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>
#include "src/core/ext/transport/chttp2/transport/context_list.h"
#include "src/core/ext/transport/chttp2/transport/frame_data.h"
#include "src/core/ext/transport/chttp2/transport/internal.h"
#include "src/core/ext/transport/chttp2/transport/varint.h"
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/compression/stream_compression.h"
#include "src/core/lib/debug/stats.h"
#include "src/core/lib/gpr/env.h"
#include "src/core/lib/gprpp/memory.h"
#include "src/core/lib/http/parser.h"
#include "src/core/lib/iomgr/executor.h"
#include "src/core/lib/iomgr/iomgr.h"
#include "src/core/lib/iomgr/timer.h"
#include "src/core/lib/profiling/timers.h"
#include "src/core/lib/slice/slice_internal.h"
#include "src/core/lib/slice/slice_string_helpers.h"
#include "src/core/lib/transport/error_utils.h"
#include "src/core/lib/transport/http2_errors.h"
#include "src/core/lib/transport/static_metadata.h"
#include "src/core/lib/transport/status_conversion.h"
#include "src/core/lib/transport/timeout_encoding.h"
#include "src/core/lib/transport/transport.h"
#include "src/core/lib/transport/transport_impl.h"
#include "src/core/lib/uri/uri_parser.h"

Data Structures

struct  cancel_stream_cb_args
 

Namespaces

 grpc_core
 Round Robin Policy.
 

Macros

#define DEFAULT_CONNECTION_WINDOW_TARGET   (1024 * 1024)
 
#define MAX_WINDOW   0x7fffffffu
 
#define MAX_WRITE_BUFFER_SIZE   (64 * 1024 * 1024)
 
#define DEFAULT_MAX_HEADER_LIST_SIZE   (8 * 1024)
 
#define DEFAULT_CLIENT_KEEPALIVE_TIME_MS   INT_MAX
 
#define DEFAULT_CLIENT_KEEPALIVE_TIMEOUT_MS   20000 /* 20 seconds */
 
#define DEFAULT_SERVER_KEEPALIVE_TIME_MS   7200000 /* 2 hours */
 
#define DEFAULT_SERVER_KEEPALIVE_TIMEOUT_MS   20000 /* 20 seconds */
 
#define DEFAULT_KEEPALIVE_PERMIT_WITHOUT_CALLS   false
 
#define KEEPALIVE_TIME_BACKOFF_MULTIPLIER   2
 
#define DEFAULT_MIN_SENT_PING_INTERVAL_WITHOUT_DATA_MS   300000 /* 5 minutes */
 
#define DEFAULT_MIN_RECV_PING_INTERVAL_WITHOUT_DATA_MS   300000 /* 5 minutes */
 
#define DEFAULT_MAX_PINGS_BETWEEN_DATA   2
 
#define DEFAULT_MAX_PING_STRIKES   2
 
#define DEFAULT_MAX_PENDING_INDUCED_FRAMES   10000
 
#define MAX_CLIENT_STREAM_ID   0x7fffffffu
 
#define CLOSURE_BARRIER_MAY_COVER_WRITE   (1 << 0)
 
#define CLOSURE_BARRIER_FIRST_REF_BIT   (1 << 16)
 

Functions

void grpc_chttp2_stream_ref (grpc_chttp2_stream *s, const char *reason)
 
void grpc_chttp2_stream_unref (grpc_chttp2_stream *s, const char *reason)
 
grpc_chttp2_streamgrpc_chttp2_parsing_accept_stream (grpc_chttp2_transport *t, uint32_t id)
 
void grpc_chttp2_initiate_write (grpc_chttp2_transport *t, grpc_chttp2_initiate_write_reason reason)
 Transport writing call flow: grpc_chttp2_initiate_write() is called anywhere that we know bytes need to go out on the wire. More...
 
void grpc_chttp2_mark_stream_writable (grpc_chttp2_transport *t, grpc_chttp2_stream *s)
 add a ref to the stream and add it to the writable list; ref will be dropped in writing.c More...
 
void grpc_chttp2_add_incoming_goaway (grpc_chttp2_transport *t, uint32_t goaway_error, uint32_t last_stream_id, const grpc_slice &goaway_text)
 
void grpc_chttp2_complete_closure_step (grpc_chttp2_transport *t, grpc_chttp2_stream *, grpc_closure **pclosure, grpc_error *error, const char *desc)
 
void grpc_chttp2_retry_initiate_ping (void *tp, grpc_error *error)
 
void grpc_chttp2_ack_ping (grpc_chttp2_transport *t, uint64_t id)
 
void grpc_chttp2_add_ping_strike (grpc_chttp2_transport *t)
 Add a new ping strike to ping_recv_state.ping_strikes. More...
 
void grpc_chttp2_maybe_complete_recv_initial_metadata (grpc_chttp2_transport *, grpc_chttp2_stream *s)
 
void grpc_chttp2_maybe_complete_recv_message (grpc_chttp2_transport *, grpc_chttp2_stream *s)
 
void grpc_chttp2_maybe_complete_recv_trailing_metadata (grpc_chttp2_transport *t, grpc_chttp2_stream *s)
 
void grpc_chttp2_cancel_stream (grpc_chttp2_transport *t, grpc_chttp2_stream *s, grpc_error *due_to_error)
 
void grpc_chttp2_fake_status (grpc_chttp2_transport *t, grpc_chttp2_stream *s, grpc_error *error)
 
void grpc_chttp2_fail_pending_writes (grpc_chttp2_transport *t, grpc_chttp2_stream *s, grpc_error *error)
 
void grpc_chttp2_mark_stream_closed (grpc_chttp2_transport *t, grpc_chttp2_stream *s, int close_reads, int close_writes, grpc_error *error)
 
void grpc_chttp2_act_on_flowctl_action (const grpc_core::chttp2::FlowControlAction &action, grpc_chttp2_transport *t, grpc_chttp2_stream *s)
 
void grpc_chttp2_config_default_keepalive_args (grpc_channel_args *args, bool is_client)
 Set the default keepalive configurations, must only be called at initialization. More...
 
const char * grpc_chttp2_initiate_write_reason_string (grpc_chttp2_initiate_write_reason reason)
 
grpc_core::RefCountedPtr< grpc_core::channelz::SocketNodegrpc_chttp2_transport_get_socket_node (grpc_transport *transport)
 
grpc_transportgrpc_create_chttp2_transport (const grpc_channel_args *channel_args, grpc_endpoint *ep, bool is_client, grpc_resource_user *resource_user)
 
void grpc_chttp2_transport_start_reading (grpc_transport *transport, grpc_slice_buffer *read_buffer, grpc_closure *notify_on_receive_settings)
 Takes ownership of read_buffer, which (if non-NULL) contains leftover bytes previously read from the endpoint (e.g., by handshakers). More...
 

Variables

grpc_core::TraceFlag grpc_http_trace (false, "http")
 
grpc_core::DebugOnlyTraceFlag grpc_trace_chttp2_refcount (false, "chttp2_refcount")
 
bool g_flow_control_enabled = true
 

Macro Definition Documentation

◆ CLOSURE_BARRIER_FIRST_REF_BIT

#define CLOSURE_BARRIER_FIRST_REF_BIT   (1 << 16)

◆ CLOSURE_BARRIER_MAY_COVER_WRITE

#define CLOSURE_BARRIER_MAY_COVER_WRITE   (1 << 0)

◆ DEFAULT_CLIENT_KEEPALIVE_TIME_MS

#define DEFAULT_CLIENT_KEEPALIVE_TIME_MS   INT_MAX

◆ DEFAULT_CLIENT_KEEPALIVE_TIMEOUT_MS

#define DEFAULT_CLIENT_KEEPALIVE_TIMEOUT_MS   20000 /* 20 seconds */

◆ DEFAULT_CONNECTION_WINDOW_TARGET

#define DEFAULT_CONNECTION_WINDOW_TARGET   (1024 * 1024)

◆ DEFAULT_KEEPALIVE_PERMIT_WITHOUT_CALLS

#define DEFAULT_KEEPALIVE_PERMIT_WITHOUT_CALLS   false

◆ DEFAULT_MAX_HEADER_LIST_SIZE

#define DEFAULT_MAX_HEADER_LIST_SIZE   (8 * 1024)

◆ DEFAULT_MAX_PENDING_INDUCED_FRAMES

#define DEFAULT_MAX_PENDING_INDUCED_FRAMES   10000

◆ DEFAULT_MAX_PING_STRIKES

#define DEFAULT_MAX_PING_STRIKES   2

◆ DEFAULT_MAX_PINGS_BETWEEN_DATA

#define DEFAULT_MAX_PINGS_BETWEEN_DATA   2

◆ DEFAULT_MIN_RECV_PING_INTERVAL_WITHOUT_DATA_MS

#define DEFAULT_MIN_RECV_PING_INTERVAL_WITHOUT_DATA_MS   300000 /* 5 minutes */

◆ DEFAULT_MIN_SENT_PING_INTERVAL_WITHOUT_DATA_MS

#define DEFAULT_MIN_SENT_PING_INTERVAL_WITHOUT_DATA_MS   300000 /* 5 minutes */

◆ DEFAULT_SERVER_KEEPALIVE_TIME_MS

#define DEFAULT_SERVER_KEEPALIVE_TIME_MS   7200000 /* 2 hours */

◆ DEFAULT_SERVER_KEEPALIVE_TIMEOUT_MS

#define DEFAULT_SERVER_KEEPALIVE_TIMEOUT_MS   20000 /* 20 seconds */

◆ KEEPALIVE_TIME_BACKOFF_MULTIPLIER

#define KEEPALIVE_TIME_BACKOFF_MULTIPLIER   2

◆ MAX_CLIENT_STREAM_ID

#define MAX_CLIENT_STREAM_ID   0x7fffffffu

◆ MAX_WINDOW

#define MAX_WINDOW   0x7fffffffu

◆ MAX_WRITE_BUFFER_SIZE

#define MAX_WRITE_BUFFER_SIZE   (64 * 1024 * 1024)

Function Documentation

◆ grpc_chttp2_ack_ping()

void grpc_chttp2_ack_ping ( grpc_chttp2_transport t,
uint64_t  id 
)

◆ grpc_chttp2_act_on_flowctl_action()

void grpc_chttp2_act_on_flowctl_action ( const grpc_core::chttp2::FlowControlAction action,
grpc_chttp2_transport t,
grpc_chttp2_stream s 
)

◆ grpc_chttp2_add_incoming_goaway()

void grpc_chttp2_add_incoming_goaway ( grpc_chttp2_transport t,
uint32_t  goaway_error,
uint32_t  last_stream_id,
const grpc_slice goaway_text 
)

◆ grpc_chttp2_add_ping_strike()

void grpc_chttp2_add_ping_strike ( grpc_chttp2_transport t)

Add a new ping strike to ping_recv_state.ping_strikes.

If ping_recv_state.ping_strikes > ping_policy.max_ping_strikes, it sends GOAWAY with error code ENHANCE_YOUR_CALM and additional debug data resembling "too_many_pings" followed by immediately closing the connection.

◆ grpc_chttp2_cancel_stream()

void grpc_chttp2_cancel_stream ( grpc_chttp2_transport t,
grpc_chttp2_stream s,
grpc_error due_to_error 
)

◆ grpc_chttp2_complete_closure_step()

void grpc_chttp2_complete_closure_step ( grpc_chttp2_transport t,
grpc_chttp2_stream s,
grpc_closure **  pclosure,
grpc_error error,
const char *  desc 
)

◆ grpc_chttp2_config_default_keepalive_args()

void grpc_chttp2_config_default_keepalive_args ( grpc_channel_args args,
bool  is_client 
)

Set the default keepalive configurations, must only be called at initialization.

◆ grpc_chttp2_fail_pending_writes()

void grpc_chttp2_fail_pending_writes ( grpc_chttp2_transport t,
grpc_chttp2_stream s,
grpc_error error 
)

◆ grpc_chttp2_fake_status()

void grpc_chttp2_fake_status ( grpc_chttp2_transport t,
grpc_chttp2_stream s,
grpc_error error 
)

◆ grpc_chttp2_initiate_write()

void grpc_chttp2_initiate_write ( grpc_chttp2_transport t,
grpc_chttp2_initiate_write_reason  reason 
)

Transport writing call flow: grpc_chttp2_initiate_write() is called anywhere that we know bytes need to go out on the wire.

If no other write has been started, a task is enqueued onto our workqueue. When that task executes, it obtains the global lock, and gathers the data to write. The global lock is dropped and we do the syscall to write. After writing, a follow-up check is made to see if another round of writing should be performed.

The actual call chain is documented in the implementation of this function.

◆ grpc_chttp2_initiate_write_reason_string()

const char* grpc_chttp2_initiate_write_reason_string ( grpc_chttp2_initiate_write_reason  reason)

◆ grpc_chttp2_mark_stream_closed()

void grpc_chttp2_mark_stream_closed ( grpc_chttp2_transport t,
grpc_chttp2_stream s,
int  close_reads,
int  close_writes,
grpc_error error 
)

◆ grpc_chttp2_mark_stream_writable()

void grpc_chttp2_mark_stream_writable ( grpc_chttp2_transport t,
grpc_chttp2_stream s 
)

add a ref to the stream and add it to the writable list; ref will be dropped in writing.c

◆ grpc_chttp2_maybe_complete_recv_initial_metadata()

void grpc_chttp2_maybe_complete_recv_initial_metadata ( grpc_chttp2_transport t,
grpc_chttp2_stream s 
)

◆ grpc_chttp2_maybe_complete_recv_message()

void grpc_chttp2_maybe_complete_recv_message ( grpc_chttp2_transport t,
grpc_chttp2_stream s 
)

◆ grpc_chttp2_maybe_complete_recv_trailing_metadata()

void grpc_chttp2_maybe_complete_recv_trailing_metadata ( grpc_chttp2_transport t,
grpc_chttp2_stream s 
)

◆ grpc_chttp2_parsing_accept_stream()

grpc_chttp2_stream* grpc_chttp2_parsing_accept_stream ( grpc_chttp2_transport t,
uint32_t  id 
)

◆ grpc_chttp2_retry_initiate_ping()

void grpc_chttp2_retry_initiate_ping ( void *  tp,
grpc_error error 
)

◆ grpc_chttp2_stream_ref()

void grpc_chttp2_stream_ref ( grpc_chttp2_stream s,
const char *  reason 
)

◆ grpc_chttp2_stream_unref()

void grpc_chttp2_stream_unref ( grpc_chttp2_stream s,
const char *  reason 
)

◆ grpc_chttp2_transport_get_socket_node()

grpc_core::RefCountedPtr<grpc_core::channelz::SocketNode> grpc_chttp2_transport_get_socket_node ( grpc_transport transport)

◆ grpc_chttp2_transport_start_reading()

void grpc_chttp2_transport_start_reading ( grpc_transport transport,
grpc_slice_buffer read_buffer,
grpc_closure notify_on_receive_settings 
)

Takes ownership of read_buffer, which (if non-NULL) contains leftover bytes previously read from the endpoint (e.g., by handshakers).

If non-null, notify_on_receive_settings will be scheduled when HTTP/2 settings are received from the peer.

◆ grpc_create_chttp2_transport()

grpc_transport* grpc_create_chttp2_transport ( const grpc_channel_args channel_args,
grpc_endpoint ep,
bool  is_client,
grpc_resource_user resource_user 
)

Variable Documentation

◆ g_flow_control_enabled

bool g_flow_control_enabled = true

◆ grpc_http_trace

grpc_core::TraceFlag grpc_http_trace(false, "http") ( false  ,
"http"   
)

◆ grpc_trace_chttp2_refcount

grpc_core::DebugOnlyTraceFlag grpc_trace_chttp2_refcount(false, "chttp2_refcount") ( false  ,
"chttp2_refcount"   
)