-
Notifications
You must be signed in to change notification settings - Fork 84
Cronvoy: Map EM Errors to Cronet API Errors (#1594) #2568
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
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
103654c
Cronvoy: map EnvoyMobile Errors to cronet errors (#1549)
colibie 3805787
Merge branch 'envoyproxy:main' into cronvoy_errors
colibie b32e44b
[cronvoy] resolve PR comments
colibie 935327a
Merge branch 'main' of github.com:colibie/envoy-mobile into cronvoy_e…
colibie edbb3d8
[cronvoy] attempt to fix conflict
colibie 34d40a8
Merge branch 'main' of github.com:colibie/envoy-mobile into cronvoy_e…
colibie c197fb4
cronvoy: changing from hexString to int
colibie b5599fb
cronvoy: remove long conversion to hexString or int
colibie f5f7dc5
cronvoy: fix grammar
colibie d7a0d6a
cronvoy: refactor
colibie ac1877e
cronvoy: format
colibie dcaeeaa
cronvoy: change javadoc working
colibie e5d5085
Kick CI
colibie 59b7099
Kick CI
colibie 445d3ce
move test-read filter to test/ folder
colibie 24e1137
Merge branch 'main' into cronvoy_errors
colibie 8678bde
most test-only test read filter to test component
colibie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| package org.chromium.net.impl; | ||
|
|
||
| import android.util.Log; | ||
| import androidx.annotation.LongDef; | ||
| import java.lang.annotation.Retention; | ||
| import java.lang.annotation.RetentionPolicy; | ||
| import java.util.Collections; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
| import org.chromium.net.NetworkException; | ||
|
|
||
| /** | ||
| * Handles mapping of the error codes that exist in the Cronvoy space. That is, | ||
| * from Envoymobile error to Chromium neterror and finally to the public Network Exception. | ||
| */ | ||
| public class Errors { | ||
| private static final Map<Long, NetError> ENVOYMOBILE_ERROR_TO_NET_ERROR = buildErrorMap(); | ||
|
|
||
| /**Subset of errors defined in | ||
| * https://github.com/envoyproxy/envoy/blob/main/envoy/stream_info/stream_info.h */ | ||
| @LongDef(flag = true, | ||
| value = {EnvoyMobileError.DNS_RESOLUTION_FAILED, EnvoyMobileError.DURATION_TIMEOUT, | ||
| EnvoyMobileError.STREAM_IDLE_TIMEOUT, | ||
| EnvoyMobileError.UPSTREAM_CONNECTION_FAILURE, | ||
| EnvoyMobileError.UPSTREAM_CONNECTION_TERMINATION, | ||
| EnvoyMobileError.UPSTREAM_REMOTE_RESET}) | ||
| @Retention(RetentionPolicy.SOURCE) | ||
| public @interface EnvoyMobileError { | ||
| long DNS_RESOLUTION_FAILED = 0x4000000; | ||
| long DURATION_TIMEOUT = 0x400000; | ||
| long STREAM_IDLE_TIMEOUT = 0x10000; | ||
| long UPSTREAM_CONNECTION_FAILURE = 0x20; | ||
| long UPSTREAM_CONNECTION_TERMINATION = 0x40; | ||
| long UPSTREAM_REMOTE_RESET = 0x10; | ||
| } | ||
|
|
||
| /** Subset of errors defined in chromium/src/net/base/net_error_list.h */ | ||
| public enum NetError { | ||
| ERR_NETWORK_CHANGED(-21), | ||
| ERR_HTTP2_PING_FAILED(-352), | ||
| ERR_QUIC_PROTOCOL_ERROR(-356), | ||
| ERR_QUIC_HANDSHAKE_FAILED(-358), | ||
| ERR_NAME_NOT_RESOLVED(-105), | ||
| ERR_INTERNET_DISCONNECTED(-106), | ||
| ERR_TIMED_OUT(-7), | ||
| ERR_CONNECTION_CLOSED(-100), | ||
| ERR_CONNECTION_TIMED_OUT(-118), | ||
| ERR_CONNECTION_REFUSED(-102), | ||
| ERR_CONNECTION_RESET(-101), | ||
| ERR_ADDRESS_UNREACHABLE(-109), | ||
| ERR_OTHER(-1000); | ||
|
|
||
| private final int errorCode; | ||
|
|
||
| NetError(int errorCode) { this.errorCode = errorCode; } | ||
|
|
||
| public int getErrorCode() { return errorCode; } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "net::" + name(); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Maps Envoymobile's errorcode to chromium's net errorcode | ||
| * @param responseFlag envoymobile's finalStreamIntel responseFlag | ||
| * @return the NetError that the EnvoyMobileError maps to | ||
| */ | ||
| public static NetError mapEnvoyMobileErrorToNetError(long responseFlag) { | ||
| /* Todo(https://github.com/envoyproxy/envoy-mobile/issues/1594): | ||
| * if (EnvoyMobileError.DNS_RESOLUTION_FAILED || EnvoyMobileError.UPSTREAM_CONNECTION_FAILURE) | ||
| * && NetworkChangeNotifier.isOffline return NetError.ERR_INTERNET_DISCONNECTED | ||
| * | ||
| * if negotiated_protocol is quic return QUIC_PROTOCOL_FAILED | ||
| */ | ||
| return ENVOYMOBILE_ERROR_TO_NET_ERROR.getOrDefault(responseFlag, NetError.ERR_OTHER); | ||
| } | ||
|
|
||
| /** | ||
| * Maps chromium's net errorcode to Cronet API errorcode | ||
| * @return the corresponding NetworkException errorcode | ||
| */ | ||
| public static int mapNetErrorToCronetApiErrorCode(NetError netError) { | ||
| switch (netError) { | ||
| case ERR_NAME_NOT_RESOLVED: | ||
| return NetworkException.ERROR_HOSTNAME_NOT_RESOLVED; | ||
| case ERR_TIMED_OUT: | ||
| return NetworkException.ERROR_TIMED_OUT; | ||
| case ERR_CONNECTION_CLOSED: | ||
| return NetworkException.ERROR_CONNECTION_CLOSED; | ||
| case ERR_CONNECTION_RESET: | ||
| return NetworkException.ERROR_CONNECTION_RESET; | ||
| case ERR_CONNECTION_REFUSED: | ||
| return NetworkException.ERROR_CONNECTION_REFUSED; | ||
| case ERR_OTHER: | ||
| return NetworkException.ERROR_OTHER; | ||
| case ERR_INTERNET_DISCONNECTED: | ||
| return NetworkException.ERROR_INTERNET_DISCONNECTED; | ||
| case ERR_NETWORK_CHANGED: | ||
| return NetworkException.ERROR_NETWORK_CHANGED; | ||
| case ERR_QUIC_PROTOCOL_ERROR: | ||
| return NetworkException.ERROR_QUIC_PROTOCOL_FAILED; | ||
| } | ||
| Log.e(CronetUrlRequestContext.LOG_TAG, "Unknown error code: " + netError); | ||
| return NetworkException.ERROR_OTHER; | ||
| } | ||
|
|
||
| /** | ||
| * Returns {@code true} if the error may contain QUIC specific errorcode | ||
| */ | ||
| public static boolean isQuicException(int javaError) { | ||
| return javaError == NetworkException.ERROR_QUIC_PROTOCOL_FAILED || | ||
| javaError == NetworkException.ERROR_NETWORK_CHANGED; | ||
| } | ||
|
|
||
| private static Map<Long, NetError> buildErrorMap() { | ||
| Map<Long, NetError> errorMap = new HashMap<>(); | ||
| errorMap.put(EnvoyMobileError.DNS_RESOLUTION_FAILED, NetError.ERR_NAME_NOT_RESOLVED); | ||
| errorMap.put(EnvoyMobileError.DURATION_TIMEOUT, NetError.ERR_TIMED_OUT); | ||
| errorMap.put(EnvoyMobileError.STREAM_IDLE_TIMEOUT, NetError.ERR_TIMED_OUT); | ||
| errorMap.put(EnvoyMobileError.UPSTREAM_CONNECTION_TERMINATION, NetError.ERR_CONNECTION_CLOSED); | ||
| errorMap.put(EnvoyMobileError.UPSTREAM_REMOTE_RESET, NetError.ERR_CONNECTION_RESET); | ||
| errorMap.put(EnvoyMobileError.UPSTREAM_CONNECTION_FAILURE, NetError.ERR_CONNECTION_REFUSED); | ||
| return Collections.unmodifiableMap(errorMap); | ||
| } | ||
|
|
||
| private Errors() {} | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| load( | ||
| "@envoy//bazel:envoy_build_system.bzl", | ||
| "envoy_cc_extension", | ||
| "envoy_package", | ||
| "envoy_proto_library", | ||
| ) | ||
|
|
||
| licenses(["notice"]) # Apache 2 | ||
|
|
||
| envoy_package() | ||
|
|
||
| envoy_proto_library( | ||
| name = "filter", | ||
| srcs = ["filter.proto"], | ||
| deps = [ | ||
| "@envoy_api//envoy/config/common/matcher/v3:pkg", | ||
| ], | ||
| ) | ||
|
|
||
| envoy_cc_extension( | ||
| name = "test_read_filter_lib", | ||
| srcs = ["filter.cc"], | ||
| hdrs = ["filter.h"], | ||
| repository = "@envoy", | ||
| deps = [ | ||
| "filter_cc_proto", | ||
| "@envoy//source/common/http:utility_lib", | ||
| "@envoy//source/common/stream_info:stream_info_lib", | ||
| "@envoy//source/extensions/filters/http/common:pass_through_filter_lib", | ||
| ], | ||
| ) | ||
|
|
||
| envoy_cc_extension( | ||
| name = "config", | ||
| srcs = ["config.cc"], | ||
| hdrs = ["config.h"], | ||
| repository = "@envoy", | ||
| deps = [ | ||
| ":test_read_filter_lib", | ||
| "@envoy//source/extensions/filters/http/common:factory_base_lib", | ||
| ], | ||
| ) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.