summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorMauro Sardara <msardara@cisco.com>2020-06-02 10:46:21 +0200
committerMauro Sardara <msardara@cisco.com>2020-06-02 10:51:15 +0200
commit15458966a342caa0912b7806a755d0d8277ca00f (patch)
tree285c712d264140c855f218bfc628db2eb173e064 /apps
parentda86027a1ca94af261a1e3f030ebc4e519ad8d83 (diff)
[HICN-610] Override hicn prefix used by http-proxy with one received
from configuration. Signed-off-by: Mauro Sardara <msardara@cisco.com> Change-Id: Ib7ec9032cf58ee1aff120ae676ce597b9428bbea Signed-off-by: Mauro Sardara <msardara@cisco.com>
Diffstat (limited to 'apps')
-rw-r--r--apps/http-proxy/src/forwarder_config.h12
-rw-r--r--apps/http-proxy/src/http_proxy.cc55
-rw-r--r--apps/http-proxy/src/http_proxy.h1
3 files changed, 36 insertions, 32 deletions
diff --git a/apps/http-proxy/src/forwarder_config.h b/apps/http-proxy/src/forwarder_config.h
index 96f275c9f..3d69c998e 100644
--- a/apps/http-proxy/src/forwarder_config.h
+++ b/apps/http-proxy/src/forwarder_config.h
@@ -157,17 +157,19 @@ class ForwarderConfig {
auto& it = results;
while (it != end) {
#else
- for (auto it = results.begin(); it != results.end();
- it++) {
+ for (auto it = results.begin(); it != results.end(); it++) {
#endif
if (it->endpoint().address().is_v4()) {
// Use this v4 address to configure the forwarder.
ret->remote_addr = it->endpoint().address().to_string();
ret->family = AF_INET;
+ std::string _prefix = ret->route_addr;
forwarder_interface_.createFaceAndRoute(
- RouteInfoPtr(ret),
- [callback = std::forward<Callback>(callback)](
- uint32_t route_id, bool result) { callback(result); });
+ RouteInfoPtr(ret), [callback = std::forward<Callback>(callback),
+ configured_prefix = std::move(_prefix)](
+ uint32_t route_id, bool result) {
+ callback(result, configured_prefix);
+ });
return true;
}
diff --git a/apps/http-proxy/src/http_proxy.cc b/apps/http-proxy/src/http_proxy.cc
index 98720d8d2..1e6dcd88f 100644
--- a/apps/http-proxy/src/http_proxy.cc
+++ b/apps/http-proxy/src/http_proxy.cc
@@ -33,12 +33,10 @@ using interface::TransportProtocolAlgorithms;
class HTTPClientConnectionCallback : interface::ConsumerSocket::ReadCallback {
public:
HTTPClientConnectionCallback(TcpReceiver& tcp_receiver,
- utils::EventThread& thread,
- const std::string& prefix,
- const std::string& ipv6_first_word)
+ utils::EventThread& thread)
: tcp_receiver_(tcp_receiver),
thread_(thread),
- prefix_hash_(generatePrefix(prefix, ipv6_first_word)),
+ prefix_hash_(tcp_receiver_.prefix_hash_),
consumer_(TransportProtocolAlgorithms::RAAQM, thread_.getIoService()),
session_(nullptr),
current_size_(0) {
@@ -221,31 +219,33 @@ class HTTPClientConnectionCallback : interface::ConsumerSocket::ReadCallback {
});
}
} else {
- tcp_receiver_.parseHicnHeader(it->second, [this](bool result) {
- const char* reply = nullptr;
- if (result) {
- reply = HTTPMessageFastParser::http_ok;
- } else {
- reply = HTTPMessageFastParser::http_failed;
- }
-
- /* Route created. Send back a 200 OK to client */
- session_->send(
- (const uint8_t*)reply, std::strlen(reply), [this, result]() {
- auto& socket = session_->socket_;
- TRANSPORT_LOGI(
- "Sent %d response to client %s:%d", result,
- socket.remote_endpoint().address().to_string().c_str(),
- socket.remote_endpoint().port());
- });
- });
+ tcp_receiver_.parseHicnHeader(
+ it->second, [this](bool result, std::string configured_prefix) {
+ const char* reply = nullptr;
+ if (result) {
+ reply = HTTPMessageFastParser::http_ok;
+ prefix_hash_ = configured_prefix;
+ } else {
+ reply = HTTPMessageFastParser::http_failed;
+ }
+
+ /* Route created. Send back a 200 OK to client */
+ session_->send(
+ (const uint8_t*)reply, std::strlen(reply), [this, result]() {
+ auto& socket = session_->socket_;
+ TRANSPORT_LOGI(
+ "Sent %d response to client %s:%d", result,
+ socket.remote_endpoint().address().to_string().c_str(),
+ socket.remote_endpoint().port());
+ });
+ });
}
}
private:
TcpReceiver& tcp_receiver_;
utils::EventThread& thread_;
- std::string prefix_hash_;
+ std::string& prefix_hash_;
ConsumerSocket consumer_;
std::unique_ptr<HTTPSession> session_;
std::deque<std::pair<std::unique_ptr<utils::MemBuf>, std::string>>
@@ -262,12 +262,13 @@ TcpReceiver::TcpReceiver(std::uint16_t port, const std::string& prefix,
std::placeholders::_1)),
prefix_(prefix),
ipv6_first_word_(ipv6_first_word),
+ prefix_hash_(generatePrefix(prefix_, ipv6_first_word_)),
forwarder_config_(thread_.getIoService(), [this](std::error_code ec) {
if (!ec) {
listener_.doAccept();
for (int i = 0; i < 10; i++) {
- http_clients_.emplace_back(new HTTPClientConnectionCallback(
- *this, thread_, prefix_, ipv6_first_word_));
+ http_clients_.emplace_back(
+ new HTTPClientConnectionCallback(*this, thread_));
}
}
}) {
@@ -283,8 +284,8 @@ void TcpReceiver::onNewConnection(asio::ip::tcp::socket&& socket) {
if (http_clients_.size() == 0) {
// Create new HTTPClientConnectionCallback
TRANSPORT_LOGD("Creating new HTTPClientConnectionCallback.");
- http_clients_.emplace_back(new HTTPClientConnectionCallback(
- *this, thread_, prefix_, ipv6_first_word_));
+ http_clients_.emplace_back(
+ new HTTPClientConnectionCallback(*this, thread_));
}
// Get new HTTPClientConnectionCallback
diff --git a/apps/http-proxy/src/http_proxy.h b/apps/http-proxy/src/http_proxy.h
index aa47d6a92..c3f183af2 100644
--- a/apps/http-proxy/src/http_proxy.h
+++ b/apps/http-proxy/src/http_proxy.h
@@ -96,6 +96,7 @@ class TcpReceiver : public Receiver {
TcpListener listener_;
std::string prefix_;
std::string ipv6_first_word_;
+ std::string prefix_hash_;
std::deque<HTTPClientConnectionCallback*> http_clients_;
std::unordered_set<HTTPClientConnectionCallback*> used_http_clients_;
ForwarderConfig forwarder_config_;