Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Temporary HTTP/2 proof of concept PR #8471

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
9 changes: 8 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ else()
if (WAMR_BUILD_TARGET MATCHES "X86_.*" OR WAMR_BUILD_TARGET STREQUAL "AMD_64")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ftrapv -D_FORTIFY_SOURCE=2")
endif ()
endif()
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector-strong --param ssp-buffer-size=4")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,-z,noexecstack,-z,relro,-z,now")
endif()
endif()

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D__FLB_FILENAME__=__FILE__")
Expand Down Expand Up @@ -172,6 +172,7 @@ option(FLB_IN_FLUENTBIT_METRICS "Enable Fluent Bit metrics plugin"
option(FLB_IN_FORWARD "Enable Forward input plugin" Yes)
option(FLB_IN_HEALTH "Enable Health input plugin" Yes)
option(FLB_IN_HTTP "Enable HTTP input plugin" Yes)
option(FLB_IN_HTTP2 "Enable HTTP2 input plugin" Yes)
option(FLB_IN_MEM "Enable Memory input plugin" Yes)
option(FLB_IN_KUBERNETES_EVENTS "Enable Kubernetes Events plugin" Yes)
option(FLB_IN_KAFKA "Enable Kafka input plugin" Yes)
Expand Down Expand Up @@ -562,6 +563,12 @@ add_subdirectory(${FLB_PATH_LIB_CMETRICS} EXCLUDE_FROM_ALL)
# CTraces
add_subdirectory(${FLB_PATH_LIB_CTRACES} EXCLUDE_FROM_ALL)

# Nghttp2 options
set(ENABLE_LIB_ONLY ON)
set(ENABLE_STATIC_LIB ON)

add_subdirectory(${FLB_PATH_LIB_NGHTTP2})

# C-Ares (DNS library)
FLB_OPTION(CARES_STATIC ON)
FLB_OPTION(CARES_SHARED OFF)
Expand Down
4 changes: 4 additions & 0 deletions cmake/headers.cmake
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ include_directories(

${CMAKE_CURRENT_BINARY_DIR}/lib/monkey/include/
${CMAKE_CURRENT_BINARY_DIR}/lib/monkey/include/monkey/

${CMAKE_CURRENT_BINARY_DIR}/lib/nghttp2
${CMAKE_CURRENT_BINARY_DIR}/lib/nghttp2/lib/includes/
${FLB_PATH_ROOT_SOURCE}/${FLB_PATH_LIB_NGHTTP2}/lib/includes/
)

if(FLB_IN_KAFKA OR FLB_OUT_KAFKA)
Expand Down
1 change: 1 addition & 0 deletions cmake/libraries.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ set(FLB_PATH_LIB_CTRACES "lib/ctraces")
set(FLB_PATH_LIB_CO "lib/flb_libco")
set(FLB_PATH_LIB_RBTREE "lib/rbtree")
set(FLB_PATH_LIB_MSGPACK "lib/msgpack-c")
set(FLB_PATH_LIB_NGHTTP2 "lib/nghttp2")
set(FLB_PATH_LIB_AVRO "lib/avro")
set(FLB_PATH_LIB_CHUNKIO "lib/chunkio")
set(FLB_PATH_LIB_LUAJIT "lib/luajit-3065c9")
Expand Down
4 changes: 2 additions & 2 deletions include/fluent-bit/flb_http_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
#define FLB_HTTP_HEADER_CONNECTION "Connection"
#define FLB_HTTP_HEADER_KA "keep-alive"

struct flb_http_response {
struct flb_http_client_response {
int status; /* HTTP response status */
int content_length; /* Content length set by headers */
int chunked_encoding; /* Chunked transfer encoding ? */
Expand Down Expand Up @@ -131,7 +131,7 @@ struct flb_http_client {
struct flb_http_proxy proxy;

/* Response */
struct flb_http_response resp;
struct flb_http_client_response resp;

/* Reference to Callback context */
void *cb_ctx;
Expand Down
162 changes: 162 additions & 0 deletions include/fluent-bit/flb_http_common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */

/* Fluent Bit
* ==========
* Copyright (C) 2015-2022 The Fluent Bit Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef FLB_HTTP_COMMON
#define FLB_HTTP_COMMON

#include <fluent-bit/flb_hash_table.h>

#include <cfl/cfl_list.h>
#include <cfl/cfl_sds.h>

#define HTTP_PROTOCOL_AUTODETECT -1
#define HTTP_PROTOCOL_HTTP0 0
#define HTTP_PROTOCOL_HTTP1 1
#define HTTP_PROTOCOL_HTTP2 2

#define HTTP_PROTOCOL_VERSION_09 MK_HTTP_PROTOCOL_09
#define HTTP_PROTOCOL_VERSION_10 MK_HTTP_PROTOCOL_10
#define HTTP_PROTOCOL_VERSION_11 MK_HTTP_PROTOCOL_11
#define HTTP_PROTOCOL_VERSION_20 MK_HTTP_PROTOCOL_20

#define HTTP_METHOD_GET MK_METHOD_GET
#define HTTP_METHOD_POST MK_METHOD_POST
#define HTTP_METHOD_HEAD MK_METHOD_HEAD
#define HTTP_METHOD_PUT MK_METHOD_PUT
#define HTTP_METHOD_DELETE MK_METHOD_DELETE
#define HTTP_METHOD_OPTIONS MK_METHOD_OPTIONS
#define HTTP_METHOD_UNKNOWN MK_METHOD_UNKNOWN

#define HTTP_STREAM_ROLE_SERVER 0
#define HTTP_STREAM_ROLE_CLIENT 1

#define HTTP_STREAM_STATUS_RECEIVING_HEADERS 0
#define HTTP_STREAM_STATUS_RECEIVING_DATA 1
#define HTTP_STREAM_STATUS_READY 2
#define HTTP_STREAM_STATUS_PROCESSING 3
#define HTTP_STREAM_STATUS_CLOSED 4
#define HTTP_STREAM_STATUS_ERROR 5

struct flb_http_stream;
struct flb_http_server_session;

struct flb_http_request {
int protocol_version;
int method;
cfl_sds_t path;
cfl_sds_t host;
cfl_sds_t query_string;
struct flb_hash_table *headers;
size_t content_length;
char *content_type;
cfl_sds_t body;

struct flb_http_stream *stream;

struct cfl_list _head;
};

struct flb_http_response {
int status;
cfl_sds_t message;
struct flb_hash_table *headers;
struct flb_hash_table *trailer_headers;
size_t content_length;
cfl_sds_t body;
size_t body_read_offset;

struct flb_http_stream *stream;
};

struct flb_http_stream {
int32_t id;
int role;
int status;

struct flb_http_request request;
struct flb_http_response response;

void *parent;
void *user_data;

int releasable;
struct cfl_list _head;
};

/* HTTP REQUEST */

int flb_http_request_init(struct flb_http_request *request);

void flb_http_request_destroy(struct flb_http_request *request);

char *flb_http_request_get_header(struct flb_http_request *request,
char *name);

int flb_http_request_set_header(struct flb_http_request *request,
char *name, size_t name_length,
char *value, size_t value_length);

int flb_http_request_unset_header(struct flb_http_request *request,
char *name);

/* HTTP RESPONSE */

int flb_http_response_init(struct flb_http_response *response);

void flb_http_response_destroy(struct flb_http_response *response);

struct flb_http_response *flb_http_response_begin(
struct flb_http_server_session *session,
void *stream);

int flb_http_response_commit(struct flb_http_response *response);

int flb_http_response_set_header(struct flb_http_response *response,
char *name, size_t name_length,
char *value, size_t value_length);

int flb_http_response_set_trailer_header(struct flb_http_response *response,
char *name, size_t name_length,
char *value, size_t value_length);

int flb_http_response_set_status(struct flb_http_response *response,
int status);

int flb_http_response_set_message(struct flb_http_response *response,
char *message);

int flb_http_response_set_body(struct flb_http_response *response,
unsigned char *body, size_t body_length);

/* HTTP STREAM */

int flb_http_stream_init(struct flb_http_stream *stream,
void *parent,
int32_t stream_id,
int role,
void *user_data);

struct flb_http_stream *flb_http_stream_create(void *parent,
int32_t stream_id,
int role,
void *user_data);

void flb_http_stream_destroy(struct flb_http_stream *stream);

#endif
2 changes: 2 additions & 0 deletions include/fluent-bit/flb_input.h
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,8 @@ struct flb_input_instance *flb_input_new(struct flb_config *config,
struct flb_input_instance *flb_input_get_instance(struct flb_config *config,
int ins_id);

struct mk_event_loop *flb_input_get_event_loop(struct flb_input_instance *ins);

int flb_input_set_property(struct flb_input_instance *ins,
const char *k, const char *v);
const char *flb_input_get_property(const char *key,
Expand Down
13 changes: 8 additions & 5 deletions include/fluent-bit/flb_network.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,15 @@ struct flb_net_setup {
/* dns resolver : LEGACY or ASYNC */
char *dns_resolver;

/* prioritize ipv4 results when trying to establish a connection*/
/* prioritize ipv4 results when trying to establish a connection */
int dns_prefer_ipv4;

/* prioritize ipv6 results when trying to establish a connection*/
/* prioritize ipv6 results when trying to establish a connection */
int dns_prefer_ipv6;

/* allow this port to be shared */
int share_port;

/* maximum number of allowed active TCP connections */
int max_worker_connections;
};
Expand Down Expand Up @@ -165,10 +168,10 @@ flb_sockfd_t flb_net_udp_connect(const char *host, unsigned long port,
char *source_addr);

int flb_net_tcp_fd_connect(flb_sockfd_t fd, const char *host, unsigned long port);
flb_sockfd_t flb_net_server(const char *port, const char *listen_addr);
flb_sockfd_t flb_net_server_udp(const char *port, const char *listen_addr);
flb_sockfd_t flb_net_server(const char *port, const char *listen_addr, int share_port);
flb_sockfd_t flb_net_server_udp(const char *port, const char *listen_addr, int share_port);
flb_sockfd_t flb_net_server_unix(const char *listen_path, int stream_mode,
int backlog);
int backlog, int share_port);
int flb_net_bind(flb_sockfd_t fd, const struct sockaddr *addr,
socklen_t addrlen, int backlog);
int flb_net_bind_udp(flb_sockfd_t fd, const struct sockaddr *addr,
Expand Down
Loading
Loading