Skip to content

Add (http2|spdy)_string_utils_impl to QUICHE platform implementation.#6198

Merged
htuch merged 12 commits intoenvoyproxy:masterfrom
wu-bin:h2_platform_string_utils_impl
Mar 20, 2019
Merged

Add (http2|spdy)_string_utils_impl to QUICHE platform implementation.#6198
htuch merged 12 commits intoenvoyproxy:masterfrom
wu-bin:h2_platform_string_utils_impl

Conversation

@wu-bin
Copy link
Copy Markdown
Contributor

@wu-bin wu-bin commented Mar 6, 2019

Description:

Add (http2|spdy)_string_utils_impl to QUICHE platform implementation.

Enabled their existing test in QUICHE.

Risk Level: minimal: code not used yet
Testing:

bazel test test/extensions/quic_listeners/quiche/platform:quic_platform_test --test_output=all --define quiche=enabled --experimental_remap_main_repo

bazel test @com_googlesource_quiche//:spdy_platform_test --test_output=all --define quiche=enabled

bazel test @com_googlesource_quiche//:http2_platform_test --test_output=all --define quiche=enabled

Docs Changes: none
Release Notes: none
[Optional Fixes #Issue]
[Optional Deprecated:]

wu-bin added 3 commits March 6, 2019 09:33
Signed-off-by: Bin Wu <wub@google.com>
…g_utils_impl

Signed-off-by: Bin Wu <wub@google.com>
assert_lib.

Signed-off-by: Bin Wu <wub@google.com>
@wu-bin
Copy link
Copy Markdown
Contributor Author

wu-bin commented Mar 6, 2019

/assign @mpwarres

# "quiche/spdy/platform/api/spdy_mem_slice.h",
# "quiche/spdy/platform/api/spdy_string_utils.h",
],
] + envoy_select_quiche(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is envoy_select_quiche needed here? My understanding from when it was first introduced was that it was only needed to avoid compiling targets depending on QUICHE under @envoy//test/..., and that for non-test targets, the omission of QUICHE from source/extensions/extensions_build_config.bzl would keep them from being compiled (e.g. see this comment). Did this turn out to not be the case?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have used to put everything(hdrs, srcs, deps) that depends on envoy into envoy_select_quiche. Last time I tried, I think ci still fails without it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, got it, SG. Separately, I'll look into if there's anything that can be done to reduce that need, but that's orthogonal to this CL. (And I'm finding it affects the flags_impl CL as well.)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For my education, why is this header file special vs. others in quich/spdy/platform/api etc.?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file depends on "string_utils_lib" which depends on envoy's "//source/common/common:assert_lib".
Other files in this library does not depend on envoy.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how that dependency is reflected in this code though; where is the line that expresses this dependency?

Also, can you fix the bracket style as per previous comments.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

quiche/spdy/platform/api/spdy_string_utils.h includes source/extensions/quic_listeners/quiche/platform/spdy_string_utils_impl.h, which is provided by build rule "spdy_platform_impl_lib", which depends on "string_utils_lib".

Fixed all single element lists in bazel/external/quiche.BUILD and source/extensions/quic_listeners/quiche/platform/BUILD.


namespace http2 {

std::string Http2HexDumpImpl(absl::string_view data) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's code that's identical to this in QuicTextUtilsImpl::HexDump(), and also later on in SpdyHexDumpImpl. How about having a single copy, in (say) some platform/string_utils.cc file, that all platform impls then delegate to?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea! Done.

return 0;
}

bool SpdyHexDecodeToUInt32Impl(absl::string_view data, uint32_t* out) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can absl::HexStringToBytes() be used here?

wu-bin added 2 commits March 13, 2019 09:48
…g_utils_impl

Signed-off-by: Bin Wu <wub@google.com>
from quic/spdy/http2 platform impls.

Signed-off-by: Bin Wu <wub@google.com>
Copy link
Copy Markdown
Contributor Author

@wu-bin wu-bin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Mike for the review. I have added a single string_utils_lib and used it from quic/spdy/http2 string apis.

# "quiche/spdy/platform/api/spdy_mem_slice.h",
# "quiche/spdy/platform/api/spdy_string_utils.h",
],
] + envoy_select_quiche(
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have used to put everything(hdrs, srcs, deps) that depends on envoy into envoy_select_quiche. Last time I tried, I think ci still fails without it.


namespace http2 {

std::string Http2HexDumpImpl(absl::string_view data) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea! Done.

wu-bin added 2 commits March 13, 2019 13:08
Signed-off-by: Bin Wu <wub@google.com>
Signed-off-by: Bin Wu <wub@google.com>
mpwarres
mpwarres previously approved these changes Mar 13, 2019
Copy link
Copy Markdown
Contributor

@mpwarres mpwarres left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

/assign @alyssawilk

# "quiche/spdy/platform/api/spdy_mem_slice.h",
# "quiche/spdy/platform/api/spdy_string_utils.h",
],
] + envoy_select_quiche(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, got it, SG. Separately, I'll look into if there's anything that can be done to reduce that need, but that's orthogonal to this CL. (And I'm finding it affects the flags_impl CL as well.)

@htuch htuch self-assigned this Mar 18, 2019
Copy link
Copy Markdown
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, a couple of comments. Thanks

# "quiche/spdy/platform/api/spdy_mem_slice.h",
# "quiche/spdy/platform/api/spdy_string_utils.h",
],
] + envoy_select_quiche(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For my education, why is this header file special vs. others in quich/spdy/platform/api etc.?

"//source/common/http:utility_lib",
]),
deps =
envoy_select_quiche([
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: please stick to normal Bazel style and have deps = envoy_select_quiche(... with no line break.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


envoy_cc_library(
name = "string_utils_lib",
srcs = [
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: single line lists should just be srcs = ["string_utils.c"], for conciseness.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment thread source/extensions/quic_listeners/quiche/platform/string_utils.cc
wu-bin added 2 commits March 19, 2019 09:15
…g_utils_impl

Signed-off-by: Bin Wu <wub@google.com>
Signed-off-by: Bin Wu <wub@google.com>
Copy link
Copy Markdown
Contributor Author

@wu-bin wu-bin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review!

# "quiche/spdy/platform/api/spdy_mem_slice.h",
# "quiche/spdy/platform/api/spdy_string_utils.h",
],
] + envoy_select_quiche(
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file depends on "string_utils_lib" which depends on envoy's "//source/common/common:assert_lib".
Other files in this library does not depend on envoy.


envoy_cc_library(
name = "string_utils_lib",
srcs = [
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

"//source/common/http:utility_lib",
]),
deps =
envoy_select_quiche([
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment thread source/extensions/quic_listeners/quiche/platform/string_utils.cc
output. Use it in quiche::Base64Encode.

Signed-off-by: Bin Wu <wub@google.com>
# "quiche/spdy/platform/api/spdy_mem_slice.h",
# "quiche/spdy/platform/api/spdy_string_utils.h",
],
] + envoy_select_quiche(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how that dependency is reflected in this code though; where is the line that expresses this dependency?

Also, can you fix the bracket style as per previous comments.

Comment thread bazel/external/quiche.BUILD Outdated
envoy_cc_test(
name = "http2_platform_test",
srcs = envoy_select_quiche(
[
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please merge make the use of brackets match other places in Envoy. Prefer compact style as with google3 C++ and BUILD files.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Envoy::Base64::encode(reinterpret_cast<const char*>(data), data_len, /*add_padding=*/false);
}

std::string HexDump(absl::string_view data) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They can not be used since they are not hexdump, rather they are equivalent to absl's HexStringToBytes and BytesToHexString functions.

I could move the body of HexDump to common/hex.cc and use it from here, the caveat is that the format of its output must not change, because quiche unit test expects the same output format(example) from all platforms' implementations. Do you prefer to do it that way?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these only test functions? I don't mind adding them if they are only used for this, but should then have some comments or change their name. I think a few things:

  • It's helpful to have these kinds of utils, so it would be nice to have them around in Envoy.
  • It would ideally have a bunch of tests to ensure they behave as intended
    *I'd prefer we did this as much as possible as pure C++, to avoid any of the evil of C string and buffer management.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the offline chat, Harvey. I have

  1. Changed the visibility of "string_utils_lib" to private.
  2. Opened Cleanup BUILD visibility for quiche build rules. #6319 to cleanup the visibility of other quiche build rules.


// Pad with leading zeros.
std::string data_padded(8u, '0');
memcpy(&data_padded[8u - data.size()], data.data(), data.size());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a major aversion to any use of memcpy or C string utilities unless absolutely needed. This is scary from a security perspective.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to string::insert instead.


// TODO(danzh): Fill out SpdyMemSliceImpl.
//
// SpdyMemSliceImpl wraps a reference counted MemSlice and only provides partial
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does absl or C++14 give us this? Where is the implementation?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a header file included by spdy_string_utils.h. I add it to make this PR compile. @danzh2010 is working on the implementation in a separate PR.

@htuch htuch added the waiting label Mar 19, 2019
Signed-off-by: Bin Wu <wub@google.com>
Copy link
Copy Markdown
Contributor Author

@wu-bin wu-bin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Harvey, PTAL.


// TODO(danzh): Fill out SpdyMemSliceImpl.
//
// SpdyMemSliceImpl wraps a reference counted MemSlice and only provides partial
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a header file included by spdy_string_utils.h. I add it to make this PR compile. @danzh2010 is working on the implementation in a separate PR.

Envoy::Base64::encode(reinterpret_cast<const char*>(data), data_len, /*add_padding=*/false);
}

std::string HexDump(absl::string_view data) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They can not be used since they are not hexdump, rather they are equivalent to absl's HexStringToBytes and BytesToHexString functions.

I could move the body of HexDump to common/hex.cc and use it from here, the caveat is that the format of its output must not change, because quiche unit test expects the same output format(example) from all platforms' implementations. Do you prefer to do it that way?

# "quiche/spdy/platform/api/spdy_mem_slice.h",
# "quiche/spdy/platform/api/spdy_string_utils.h",
],
] + envoy_select_quiche(
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

quiche/spdy/platform/api/spdy_string_utils.h includes source/extensions/quic_listeners/quiche/platform/spdy_string_utils_impl.h, which is provided by build rule "spdy_platform_impl_lib", which depends on "string_utils_lib".

Fixed all single element lists in bazel/external/quiche.BUILD and source/extensions/quic_listeners/quiche/platform/BUILD.

Comment thread bazel/external/quiche.BUILD Outdated
envoy_cc_test(
name = "http2_platform_test",
srcs = envoy_select_quiche(
[
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


// Pad with leading zeros.
std::string data_padded(8u, '0');
memcpy(&data_padded[8u - data.size()], data.data(), data.size());
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to string::insert instead.

Signed-off-by: Bin Wu <wub@google.com>
@wu-bin
Copy link
Copy Markdown
Contributor Author

wu-bin commented Mar 20, 2019

/retest

@repokitteh-read-only
Copy link
Copy Markdown

🔨 rebuilding ci/circleci: tsan (failed build)

🐱

Caused by: a #6198 (comment) was created by @wu-bin.

see: more, trace.

Copy link
Copy Markdown
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@htuch htuch merged commit 36f39c7 into envoyproxy:master Mar 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants