Skip to content

Commit b4f26ae

Browse files
authored
H2B: More incremental progres (#149)
* Start implementing streams * Progress * Day 3, still no one has figured out I have no idea what I'm doing * Error handling and logging * Missed h1 -> h2 renames * Use aws_http_stream_destroy instead of h2 specific function * Delete h2 connection since it's not good * Mike's LOGF idea * h2 stream interface updates * Initial h2_connection * Implement simple get_next_stream_id * Add simple h2_connection setup * Add h2_decoder framework * Move h1 connection functions to h1_connection.h * Disable H2 support (for now) * Decoder use calloc * CI Fixes * Remove unnecessary error info for end of range * Sorry mr MSVC * Add overflow detection to next_stream_id * Anther MSVC fix * PR feedback * Replace AWS_ERROR_HTTP_PARSE with PROTOCOL_ERROR * Split thread and synced data * next_stream_id, and sync it, correct it to 31 bits * lol oops * Return UNKNOWN for invalid enum value * What even is a peer * sacrifice a goat to the CI gods * CI fixes, and remove bad window updater
1 parent 12d1de3 commit b4f26ae

19 files changed

+956
-66
lines changed

include/aws/http/http.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
enum aws_http_errors {
2424
AWS_ERROR_HTTP_UNKNOWN = 0x0800,
25-
AWS_ERROR_HTTP_PARSE,
2625
AWS_ERROR_HTTP_INVALID_HEADER_FIELD,
2726
AWS_ERROR_HTTP_INVALID_HEADER_NAME,
2827
AWS_ERROR_HTTP_INVALID_HEADER_VALUE,
@@ -47,6 +46,8 @@ enum aws_http_errors {
4746
AWS_ERROR_HTTP_SERVER_CLOSED,
4847
AWS_ERROR_HTTP_PROXY_TLS_CONNECT_FAILED,
4948
AWS_ERROR_HTTP_CONNECTION_MANAGER_SHUTTING_DOWN,
49+
AWS_ERROR_HTTP_PROTOCOL_ERROR,
50+
AWS_ERROR_HTTP_STREAM_CLOSED,
5051

5152
AWS_ERROR_HTTP_END_RANGE = 0x0C00,
5253
};

include/aws/http/private/connection_impl.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -123,16 +123,6 @@ struct aws_http_client_bootstrap {
123123

124124
AWS_EXTERN_C_BEGIN
125125

126-
AWS_HTTP_API
127-
struct aws_http_connection *aws_http_connection_new_http1_1_server(
128-
struct aws_allocator *allocator,
129-
size_t initial_window_size);
130-
131-
AWS_HTTP_API
132-
struct aws_http_connection *aws_http_connection_new_http1_1_client(
133-
struct aws_allocator *allocator,
134-
size_t initial_window_size);
135-
136126
AWS_HTTP_API
137127
void aws_http_connection_set_system_vtable(const struct aws_http_connection_system_vtable *system_vtable);
138128

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#ifndef AWS_HTTP_H1_CONNECTION_H
2+
#define AWS_HTTP_H1_CONNECTION_H
3+
4+
/*
5+
* Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License").
8+
* You may not use this file except in compliance with the License.
9+
* A copy of the License is located at
10+
*
11+
* http://aws.amazon.com/apache2.0
12+
*
13+
* or in the "license" file accompanying this file. This file is distributed
14+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
15+
* express or implied. See the License for the specific language governing
16+
* permissions and limitations under the License.
17+
*/
18+
19+
#include <aws/http/private/connection_impl.h>
20+
21+
AWS_EXTERN_C_BEGIN
22+
23+
AWS_HTTP_API
24+
struct aws_http_connection *aws_http_connection_new_http1_1_server(
25+
struct aws_allocator *allocator,
26+
size_t initial_window_size);
27+
28+
AWS_HTTP_API
29+
struct aws_http_connection *aws_http_connection_new_http1_1_client(
30+
struct aws_allocator *allocator,
31+
size_t initial_window_size);
32+
33+
AWS_EXTERN_C_END
34+
35+
#endif /* AWS_HTTP_H1_CONNECTION_H */
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#ifndef AWS_HTTP_H2_CONNECTION_H
2+
#define AWS_HTTP_H2_CONNECTION_H
3+
4+
/*
5+
* Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License").
8+
* You may not use this file except in compliance with the License.
9+
* A copy of the License is located at
10+
*
11+
* http://aws.amazon.com/apache2.0
12+
*
13+
* or in the "license" file accompanying this file. This file is distributed
14+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
15+
* express or implied. See the License for the specific language governing
16+
* permissions and limitations under the License.
17+
*/
18+
19+
#include <aws/common/atomics.h>
20+
#include <aws/common/mutex.h>
21+
22+
#include <aws/http/private/connection_impl.h>
23+
24+
struct aws_h2_connection {
25+
struct aws_http_connection base;
26+
27+
/* Only the event-loop thread may touch this data */
28+
struct {
29+
struct aws_h2_decoder *decoder;
30+
} thread_data;
31+
32+
/* Any thread may touch this data, but the lock must be held */
33+
struct {
34+
struct aws_mutex lock;
35+
36+
/* Refers to the next stream id to vend */
37+
uint32_t next_stream_id;
38+
} synced_data;
39+
};
40+
41+
AWS_EXTERN_C_BEGIN
42+
43+
AWS_HTTP_API
44+
struct aws_http_connection *aws_http_connection_new_http2_server(
45+
struct aws_allocator *allocator,
46+
size_t initial_window_size);
47+
48+
AWS_HTTP_API
49+
struct aws_http_connection *aws_http_connection_new_http2_client(
50+
struct aws_allocator *allocator,
51+
size_t initial_window_size);
52+
53+
AWS_HTTP_API
54+
uint32_t aws_h2_connection_get_next_stream_id(struct aws_h2_connection *connection);
55+
56+
AWS_EXTERN_C_END
57+
58+
#endif /* AWS_HTTP_H2_CONNECTION_H */
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#ifndef AWS_HTTP_H2_DECODER_H
2+
#define AWS_HTTP_H2_DECODER_H
3+
4+
/*
5+
* Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License").
8+
* You may not use this file except in compliance with the License.
9+
* A copy of the License is located at
10+
*
11+
* http://aws.amazon.com/apache2.0
12+
*
13+
* or in the "license" file accompanying this file. This file is distributed
14+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
15+
* express or implied. See the License for the specific language governing
16+
* permissions and limitations under the License.
17+
*/
18+
19+
#include <aws/http/private/http_impl.h>
20+
21+
/**
22+
* Structure used to initialize an `aws_h2_decoder`.
23+
*/
24+
struct aws_h2_decoder_params {
25+
struct aws_allocator *alloc;
26+
void *user_data;
27+
struct aws_http_decoder_vtable vtable;
28+
};
29+
30+
struct aws_h2_decoder;
31+
32+
AWS_EXTERN_C_BEGIN
33+
34+
AWS_HTTP_API struct aws_h2_decoder *aws_h2_decoder_new(struct aws_h2_decoder_params *params);
35+
AWS_HTTP_API void aws_h2_decoder_destroy(struct aws_h2_decoder *decoder);
36+
AWS_HTTP_API int aws_h2_decode(struct aws_h2_decoder *decoder, struct aws_byte_cursor *data);
37+
38+
AWS_HTTP_API void aws_h2_decoder_set_logging_id(struct aws_h2_decoder *decoder, void *id);
39+
40+
AWS_EXTERN_C_END
41+
42+
#endif /* AWS_HTTP_H2_DECODER_H */

include/aws/http/private/h2_frames.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,9 @@ struct aws_h2_frame_decoder {
252252

253253
AWS_EXTERN_C_BEGIN
254254

255+
AWS_HTTP_API
256+
const char *aws_h2_frame_type_to_str(enum aws_h2_frame_type type);
257+
255258
/* Internal methods exposed for testing purposes only */
256259
AWS_HTTP_API
257260
int aws_h2_frame_header_block_init(struct aws_h2_frame_header_block *header_block, struct aws_allocator *allocator);
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#ifndef AWS_HTTP_H2_STREAM_H
2+
#define AWS_HTTP_H2_STREAM_H
3+
4+
/*
5+
* Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License").
8+
* You may not use this file except in compliance with the License.
9+
* A copy of the License is located at
10+
*
11+
* http://aws.amazon.com/apache2.0
12+
*
13+
* or in the "license" file accompanying this file. This file is distributed
14+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
15+
* express or implied. See the License for the specific language governing
16+
* permissions and limitations under the License.
17+
*/
18+
19+
#include <aws/http/private/h2_frames.h>
20+
#include <aws/http/private/request_response_impl.h>
21+
22+
#include <aws/common/mutex.h>
23+
24+
enum aws_h2_stream_state {
25+
AWS_H2_STREAM_STATE_IDLE,
26+
AWS_H2_STREAM_STATE_RESERVED_LOCAL,
27+
AWS_H2_STREAM_STATE_RESERVED_REMOTE,
28+
AWS_H2_STREAM_STATE_OPEN,
29+
AWS_H2_STREAM_STATE_HALF_CLOSED_LOCAL,
30+
AWS_H2_STREAM_STATE_HALF_CLOSED_REMOTE,
31+
AWS_H2_STREAM_STATE_CLOSED,
32+
33+
AWS_H2_STREAM_STATE_COUNT,
34+
};
35+
36+
struct aws_h2_stream {
37+
struct aws_http_stream base;
38+
39+
const uint32_t id;
40+
41+
/* Only the event-loop thread may touch this data */
42+
struct {
43+
bool expects_continuation;
44+
enum aws_h2_stream_state state;
45+
uint64_t window_size; /* #TODO try to figure out how this actually works, and then implement it */
46+
} thread_data;
47+
48+
/* Any thread may touch this data, but the lock must be held */
49+
struct {
50+
struct aws_mutex lock;
51+
52+
} synced_data;
53+
};
54+
55+
struct aws_h2_stream;
56+
57+
AWS_EXTERN_C_BEGIN
58+
59+
AWS_HTTP_API
60+
const char *aws_h2_stream_state_to_str(enum aws_h2_stream_state state);
61+
62+
AWS_HTTP_API
63+
struct aws_h2_stream *aws_h1_stream_new_request(
64+
struct aws_http_connection *client_connection,
65+
const struct aws_http_make_request_options *options);
66+
67+
AWS_HTTP_API
68+
int aws_h2_stream_handle_frame(struct aws_h2_stream *stream, struct aws_h2_frame_decoder *decoder);
69+
70+
AWS_EXTERN_C_END
71+
72+
#endif /* AWS_HTTP_H2_STREAM_H */

source/connection.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
* permissions and limitations under the License.
1414
*/
1515

16-
#include <aws/http/private/connection_impl.h>
16+
#include <aws/http/private/h1_connection.h>
17+
#include <aws/http/private/h2_connection.h>
1718
#include <aws/http/private/proxy_impl.h>
1819

1920
#include <aws/common/hash_table.h>
@@ -147,6 +148,14 @@ static struct aws_http_connection *s_connection_new(
147148
connection = aws_http_connection_new_http1_1_client(alloc, initial_window_size);
148149
}
149150
break;
151+
case AWS_HTTP_VERSION_2:
152+
AWS_FATAL_ASSERT(false && "H2 is not currently supported"); /* lol nice try */
153+
if (is_server) {
154+
connection = aws_http_connection_new_http2_server(alloc, initial_window_size);
155+
} else {
156+
connection = aws_http_connection_new_http2_client(alloc, initial_window_size);
157+
}
158+
break;
150159
default:
151160
AWS_LOGF_ERROR(
152161
AWS_LS_HTTP_CONNECTION,

0 commit comments

Comments
 (0)