Skip to content

Add support for proxies #9

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

Closed
wants to merge 6 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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 67 additions & 32 deletions common/ConfigCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
#define SDK_CONFIG_ENDPOINT_HTTPS_PORT_KEY "https_port"
#define SDK_CONFIG_ENDPOINT_GREENGRASS_DISCOVERY_PORT_KEY "greengrass_discovery_port"

#define SDK_CONFIG_PROXY_KEY "proxy"
#define SDK_CONFIG_PROXY_PORT_KEY "proxy_port"
#define SDK_CONFIG_PROXY_USER_NAME_KEY "proxy_user_name"
#define SDK_CONFIG_PROXY_PASSWORD_KEY "proxy_password"

// TLS Settings
#define SDK_CONFIG_ROOT_CA_RELATIVE_KEY "root_ca_relative_path"
#define SDK_CONFIG_DEVICE_CERT_RELATIVE_KEY "device_certificate_relative_path"
Expand Down Expand Up @@ -73,36 +78,42 @@
#define DISCOVER_ACTION_TIMEOUT_MSECS_KEY "discover_action_timeout_msecs"

namespace awsiotsdk {
util::JsonDocument ConfigCommon::sdk_config_json_;
util::JsonDocument ConfigCommon::sdk_config_json_;

uint16_t ConfigCommon::endpoint_mqtt_port_;
uint16_t ConfigCommon::endpoint_https_port_;
uint16_t ConfigCommon::endpoint_greengrass_discovery_port_;

util::String ConfigCommon::endpoint_;
util::String ConfigCommon::root_ca_path_;
util::String ConfigCommon::client_cert_path_;
util::String ConfigCommon::client_key_path_;
util::String ConfigCommon::base_client_id_;
util::String ConfigCommon::thing_name_;
util::String ConfigCommon::aws_region_;
util::String ConfigCommon::aws_access_key_id_;
util::String ConfigCommon::aws_secret_access_key_;
util::String ConfigCommon::aws_session_token_;

std::chrono::milliseconds ConfigCommon::mqtt_command_timeout_;
std::chrono::milliseconds ConfigCommon::tls_handshake_timeout_;
std::chrono::milliseconds ConfigCommon::tls_read_timeout_;
std::chrono::milliseconds ConfigCommon::tls_write_timeout_;
std::chrono::milliseconds ConfigCommon::discover_action_timeout_;
std::chrono::seconds ConfigCommon::keep_alive_timeout_secs_;

bool ConfigCommon::is_clean_session_;
std::chrono::seconds ConfigCommon::minimum_reconnect_interval_;
std::chrono::seconds ConfigCommon::maximum_reconnect_interval_;
size_t ConfigCommon::max_pending_acks_;
size_t ConfigCommon::maximum_outgoing_action_queue_length_;
uint32_t ConfigCommon::action_processing_rate_hz_;
util::String ConfigCommon::endpoint_;

uint16_t ConfigCommon::proxy_port_;
util::String ConfigCommon::proxy_;
util::String ConfigCommon::proxy_user_name_;
util::String ConfigCommon::proxy_password_;

util::String ConfigCommon::root_ca_path_;
util::String ConfigCommon::client_cert_path_;
util::String ConfigCommon::client_key_path_;
util::String ConfigCommon::base_client_id_;
util::String ConfigCommon::thing_name_;
util::String ConfigCommon::aws_region_;
util::String ConfigCommon::aws_access_key_id_;
util::String ConfigCommon::aws_secret_access_key_;
util::String ConfigCommon::aws_session_token_;

std::chrono::milliseconds ConfigCommon::mqtt_command_timeout_;
std::chrono::milliseconds ConfigCommon::tls_handshake_timeout_;
std::chrono::milliseconds ConfigCommon::tls_read_timeout_;
std::chrono::milliseconds ConfigCommon::tls_write_timeout_;
std::chrono::milliseconds ConfigCommon::discover_action_timeout_;
std::chrono::seconds ConfigCommon::keep_alive_timeout_secs_;

bool ConfigCommon::is_clean_session_;
std::chrono::seconds ConfigCommon::minimum_reconnect_interval_;
std::chrono::seconds ConfigCommon::maximum_reconnect_interval_;
size_t ConfigCommon::max_pending_acks_;
size_t ConfigCommon::maximum_outgoing_action_queue_length_;
uint32_t ConfigCommon::action_processing_rate_hz_;

void ConfigCommon::LogParseError(const ResponseCode &response_code,
const util::JsonDocument &config,
Expand All @@ -114,12 +125,12 @@ namespace awsiotsdk {
static_cast<unsigned int>(util::JsonParser::GetParseErrorOffset(sdk_config_json_)));
}

util::String ConfigCommon::GetCurrentPath() {
util::String ConfigCommon::GetCurrentPath() {
char current_wd[MAX_PATH_LENGTH_ + 1];
return (getcwd(current_wd, sizeof(current_wd)) ? std::string(current_wd) : std::string(""));
}
}

ResponseCode ConfigCommon::InitializeCommon(const util::String &config_file_relative_path) {
ResponseCode ConfigCommon::InitializeCommon(const util::String &config_file_relative_path) {
util::String config_file_absolute_path = GetCurrentPath();
if (0 == config_file_absolute_path.length()) {
return ResponseCode::FILE_OPEN_ERROR;
Expand Down Expand Up @@ -150,25 +161,49 @@ namespace awsiotsdk {
}

rc = util::JsonParser::GetUint16Value(sdk_config_json_, SDK_CONFIG_ENDPOINT_MQTT_PORT_KEY, endpoint_mqtt_port_);
if (ResponseCode::SUCCESS != rc) {
if(ResponseCode::SUCCESS != rc) {
LogParseError(rc, sdk_config_json_, SDK_CONFIG_ENDPOINT_MQTT_PORT_KEY);
return rc;
}

rc = util::JsonParser::GetUint16Value(sdk_config_json_,
SDK_CONFIG_ENDPOINT_HTTPS_PORT_KEY,
endpoint_https_port_);
if (ResponseCode::SUCCESS != rc) {
if(ResponseCode::SUCCESS != rc) {
LogParseError(rc, sdk_config_json_, SDK_CONFIG_ENDPOINT_HTTPS_PORT_KEY);
return rc;
}

rc = util::JsonParser::GetUint16Value(sdk_config_json_, SDK_CONFIG_ENDPOINT_GREENGRASS_DISCOVERY_PORT_KEY,
endpoint_greengrass_discovery_port_);
if (ResponseCode::SUCCESS != rc) {
if(ResponseCode::SUCCESS != rc) {
LogParseError(rc, sdk_config_json_, SDK_CONFIG_ENDPOINT_GREENGRASS_DISCOVERY_PORT_KEY);
return rc;
}

rc = util::JsonParser::GetStringValue(sdk_config_json_, SDK_CONFIG_PROXY_KEY, proxy_);
if (ResponseCode::SUCCESS != rc) {
LogParseError(rc, sdk_config_json_, SDK_CONFIG_PROXY_KEY);
return rc;
}

rc = util::JsonParser::GetUint16Value(sdk_config_json_, SDK_CONFIG_PROXY_PORT_KEY, proxy_port_);
if (ResponseCode::SUCCESS != rc) {
LogParseError(rc, sdk_config_json_, SDK_CONFIG_PROXY_PORT_KEY);
return rc;
}

rc = util::JsonParser::GetStringValue(sdk_config_json_, SDK_CONFIG_PROXY_USER_NAME_KEY, proxy_user_name_);
if (ResponseCode::SUCCESS != rc) {
LogParseError(rc, sdk_config_json_, SDK_CONFIG_PROXY_USER_NAME_KEY);
return rc;
}

rc = util::JsonParser::GetStringValue(sdk_config_json_, SDK_CONFIG_PROXY_PASSWORD_KEY, proxy_password_);
if (ResponseCode::SUCCESS != rc) {
LogParseError(rc, sdk_config_json_, SDK_CONFIG_PROXY_PASSWORD_KEY);
return rc;
}

rc = util::JsonParser::GetStringValue(sdk_config_json_, SDK_CONFIG_ROOT_CA_RELATIVE_KEY, temp_str);
if (ResponseCode::SUCCESS != rc) {
Expand Down Expand Up @@ -331,4 +366,4 @@ namespace awsiotsdk {

return rc;
}
}
}
60 changes: 33 additions & 27 deletions common/ConfigCommon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,44 +28,50 @@
#include "util/JsonParser.hpp"

namespace awsiotsdk {
class ConfigCommon {
protected:
static util::JsonDocument sdk_config_json_;
class ConfigCommon {
protected:
static util::JsonDocument sdk_config_json_;

static void LogParseError(const ResponseCode& response_code, const util::JsonDocument& config, util::String key);
public:
public:
static uint16_t endpoint_mqtt_port_;
static uint16_t endpoint_https_port_;
static uint16_t endpoint_greengrass_discovery_port_;

static util::String endpoint_;
static util::String root_ca_path_;
static util::String client_cert_path_;
static util::String client_key_path_;
static util::String base_client_id_;
static util::String thing_name_;
static util::String aws_region_;
static util::String aws_access_key_id_;
static util::String aws_secret_access_key_;
static util::String aws_session_token_;
static util::String endpoint_;

static std::chrono::milliseconds mqtt_command_timeout_;
static std::chrono::milliseconds tls_handshake_timeout_;
static std::chrono::milliseconds tls_read_timeout_;
static std::chrono::milliseconds tls_write_timeout_;
static uint16_t proxy_port_;
static util::String proxy_;
static util::String proxy_user_name_;
static util::String proxy_password_;

static util::String root_ca_path_;
static util::String client_cert_path_;
static util::String client_key_path_;
static util::String base_client_id_;
static util::String thing_name_;
static util::String aws_region_;
static util::String aws_access_key_id_;
static util::String aws_secret_access_key_;
static util::String aws_session_token_;

static std::chrono::milliseconds mqtt_command_timeout_;
static std::chrono::milliseconds tls_handshake_timeout_;
static std::chrono::milliseconds tls_read_timeout_;
static std::chrono::milliseconds tls_write_timeout_;
static std::chrono::milliseconds discover_action_timeout_;
static std::chrono::seconds keep_alive_timeout_secs_;
static std::chrono::seconds keep_alive_timeout_secs_;

static bool is_clean_session_;
static std::chrono::seconds minimum_reconnect_interval_;
static std::chrono::seconds maximum_reconnect_interval_;
static size_t max_pending_acks_;
static size_t maximum_outgoing_action_queue_length_;
static uint32_t action_processing_rate_hz_;
static bool is_clean_session_;
static std::chrono::seconds minimum_reconnect_interval_;
static std::chrono::seconds maximum_reconnect_interval_;
static size_t max_pending_acks_;
static size_t maximum_outgoing_action_queue_length_;
static uint32_t action_processing_rate_hz_;

static ResponseCode InitializeCommon(const util::String &config_file_path);
static ResponseCode InitializeCommon(const util::String &config_file_path);
static util::String GetCurrentPath();
};
};
}


4 changes: 4 additions & 0 deletions common/SampleConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"mqtt_port": 8883,
"https_port": 443,
"greengrass_discovery_port": 8443,
"proxy": "",
"proxy_port": 8080,
"proxy_user_name": "",
"proxy_password": "",
"root_ca_relative_path": "certs/rootCA.crt",
"device_certificate_relative_path": "certs/cert.pem",
"device_private_key_relative_path": "certs/privkey.pem",
Expand Down
35 changes: 35 additions & 0 deletions include/ProxyType.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file 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.
*/

/**
* @file ProxyType.hpp
* @brief Strongly typed enumeration of available proxy types used by the SDK
*
* Contains the proxy types used by the SDK
*/

#pragma once

namespace awsiotsdk {
/**
* @brief Proxy Type enum class
*
* Strongly typed enumeration of available proxy types used by the SDK
*/
enum class ProxyType {
NONE = 0,
HTTP = 1
};
}
Loading