Skip to content

Commit

Permalink
comments: inline clarifications (#77)
Browse files Browse the repository at this point in the history
Signed-off-by: Jose Nino <jnino@lyft.com>

Description: inline comment pass prior to release. This is my pass at #37.
Signed-off-by: JP Simard <jp@jpsim.com>
  • Loading branch information
junr03 authored and jpsim committed Nov 29, 2022
1 parent e319d4f commit f2d8391
Show file tree
Hide file tree
Showing 13 changed files with 35 additions and 0 deletions.
4 changes: 4 additions & 0 deletions mobile/.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ build \
--xcode_version=10.2.1 \
--incompatible_bzl_disallow_load_after_statement=false

# Manual Stamping is necessary in order to get versioning information in the ios
# static framework.
# More information on stamping can be found here:
# https://github.com/envoyproxy/envoy/tree/master/bazel#enabling-optional-features
build:ios --define=manual_stamp=manual_stamp

build:android --fat_apk_cpu=x86,x86_64,armeabi-v7a,arm64-v8a
2 changes: 2 additions & 0 deletions mobile/dist/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ envoy_package()

# NOTE: You must first build the top-level targets //:ios_dist and //:android_dist to use the
# artifacts referenced here.
# You can also download the distributables referenced here from envoy-mobile's releases page:
# https://github.com/lyft/envoy-mobile/releases

aar_import(
name = "envoy_mobile_android",
Expand Down
3 changes: 3 additions & 0 deletions mobile/examples/common/config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Envoy config used by the example applications.
# More information about Envoy's config can be found at:
# https://www.envoyproxy.io/docs/envoy/latest/configuration/configuration
static_resources:
listeners:
- address:
Expand Down
2 changes: 2 additions & 0 deletions mobile/examples/java/hello_world/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
android:versionCode="1"
android:versionName="0.1">
<uses-permission android:name="android.permission.INTERNET"/>
<!-- This permission is needed in order to allow the application
to initiate DNS resolution via c-ares. -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

<uses-sdk
Expand Down
3 changes: 3 additions & 0 deletions mobile/examples/java/hello_world/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

// Load an envoy config, and run envoy on a separate thread.
Envoy envoy = new Envoy();
envoy.load();
String config = null;
Expand All @@ -59,6 +60,7 @@ protected void onCreate(Bundle savedInstanceState) {
recyclerView.addItemDecoration(dividerItemDecoration);
thread.start();

// Run a request loop until the application exits.
final Handler handler = new Handler(thread.getLooper());
handler.postDelayed(new Runnable() {
@Override
Expand All @@ -83,6 +85,7 @@ protected void onDestroy() {

private Response makeRequest() throws IOException {
URL url = new URL(ENDPOINT);
// Open connection to the envoy thread listening locally on port 9001.
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
int status = connection.getResponseCode();
if (status != 200) {
Expand Down
1 change: 1 addition & 0 deletions mobile/examples/java/hello_world/Response.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.envoyproxy.envoymobile.helloenvoy;

// Response is a class to handle HTTP responses.
public class Response {
public final String title;
public final String header;
Expand Down
3 changes: 3 additions & 0 deletions mobile/examples/kotlin/hello_world/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class MainActivity : Activity() {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

// Load an envoy config, and run envoy on a separate thread.
val envoy = Envoy()
envoy.load()
envoy.run(baseContext, loadEnvoyConfig(baseContext, R.raw.config))
Expand All @@ -44,6 +45,7 @@ class MainActivity : Activity() {
thread.start()
val handler = Handler(thread.looper)

// Run a request loop until the application exits.
handler.postDelayed(object : Runnable {
override fun run() {
try {
Expand All @@ -66,6 +68,7 @@ class MainActivity : Activity() {

private fun makeRequest(): Response {
val url = URL(ENDPOINT)
// Open connection to the envoy thread listening locally on port 9001
val connection = url.openConnection() as HttpURLConnection
val status = connection.responseCode
if (status != 200) {
Expand Down
1 change: 1 addition & 0 deletions mobile/examples/kotlin/hello_world/Response.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
package io.envoyproxy.envoymobile.helloenvoykotlin

// Response is a class to handle HTTP responses.
class Response(val title: String, val header: String)
1 change: 1 addition & 0 deletions mobile/examples/objective-c/hello_world/ViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ - (void)startRequests {

- (void)performRequest {
NSURLSession* session = [NSURLSession sharedSession];
// Note that the request is sent to the envoy thread listening locally on port 9001.
NSURL* url = [NSURL URLWithString:_ENDPOINT];
NSURLRequest* request = [NSURLRequest requestWithURL:url];
NSLog(@"Starting request to '%@'", url.path);
Expand Down
1 change: 1 addition & 0 deletions mobile/examples/swift/hello_world/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ final class ViewController: UITableViewController {
}

private func performRequest() {
// Note that the request is sent to the envoy thread listening locally on port 9001.
let request = URLRequest(url: kURL)
NSLog("Starting request to '\(kURL.path)")
let task = URLSession.shared.dataTask(with: request) { [weak self] data, response, error in
Expand Down
4 changes: 4 additions & 0 deletions mobile/library/common/jni_interface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved) {
return -1;
}

// c-ares jvm init is necessary in order to let c-ares perform DNS resolution in Envoy.
// More information can be found at:
// https://c-ares.haxx.se/ares_library_init_android.html
ares_library_init_jvm(vm);
return JNI_VERSION_1_6;
}
Expand All @@ -27,6 +30,7 @@ extern "C" JNIEXPORT jint JNICALL
Java_io_envoyproxy_envoymobile_Envoy_initialize(JNIEnv* env,
jobject, // this
jobject connectivity_manager) {
// See note above about c-ares.
return ares_library_init_android(connectivity_manager);
}

Expand Down
9 changes: 9 additions & 0 deletions mobile/library/common/main_interface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ extern "C" int run_envoy(const char* config) {
char* envoy_argv[] = {strdup("envoy"), strdup("--config-yaml"), strdup(config), nullptr};

// Ensure static factory registration occurs on time.
// Envoy's static factory registration happens when main is run.
// However, when compiled as a library, there is no guarantee that such registration will happen
// before the names are needed.
// The following calls ensure that registration happens before the entities are needed.
// Note that as more registrations are needed, explicit initialization calls will need to be added
// here.
Envoy::Extensions::HttpFilters::RouterFilter::forceRegisterRouterFilterConfig();
Envoy::Extensions::NetworkFilters::HttpConnectionManager::
forceRegisterHttpConnectionManagerFilterConfigFactory();
Expand All @@ -31,6 +37,9 @@ extern "C" int run_envoy(const char* config) {
// Initialize the server's main context under a try/catch loop and simply
// return EXIT_FAILURE as needed. Whatever code in the initialization path
// that fails is expected to log an error message so the user can diagnose.
// Note that in the Android examples logging will not be seen.
// This is a known problem, and will be addressed by:
// https://github.com/lyft/envoy-mobile/issues/34
try {
main_common = std::make_unique<Envoy::MainCommon>(3, envoy_argv);
} catch (const Envoy::NoServingException& e) {
Expand Down
1 change: 1 addition & 0 deletions mobile/library/java/io/envoyproxy/envoymobile/Envoy.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import java.io.*;

// Wrapper class that allows for easy calling of Envoy's JNI interface in native Java.
public class Envoy {

public void load() { System.loadLibrary("envoy_jni"); }
Expand Down

0 comments on commit f2d8391

Please sign in to comment.