aboutsummaryrefslogtreecommitdiffstats
path: root/apps/http-proxy/src/icn_receiver.cc
diff options
context:
space:
mode:
Diffstat (limited to 'apps/http-proxy/src/icn_receiver.cc')
-rw-r--r--apps/http-proxy/src/icn_receiver.cc48
1 files changed, 23 insertions, 25 deletions
diff --git a/apps/http-proxy/src/icn_receiver.cc b/apps/http-proxy/src/icn_receiver.cc
index ea8ac7191..c8904aa95 100644
--- a/apps/http-proxy/src/icn_receiver.cc
+++ b/apps/http-proxy/src/icn_receiver.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019 Cisco and/or its affiliates.
+ * Copyright (c) 2021-2022 Cisco and/or its affiliates.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
@@ -13,13 +13,13 @@
* limitations under the License.
*/
+#include <hicn/apps/utils/logger.h>
#include <hicn/http-proxy/http_1x_message_fast_parser.h>
#include <hicn/http-proxy/icn_receiver.h>
#include <hicn/http-proxy/utils.h>
#include <hicn/transport/core/interest.h>
#include <hicn/transport/http/default_values.h>
#include <hicn/transport/utils/hash.h>
-#include <hicn/transport/utils/log.h>
#include <functional>
#include <memory>
@@ -33,18 +33,15 @@ AsyncConsumerProducer::AsyncConsumerProducer(
const std::string& mtu, const std::string& content_lifetime, bool manifest)
: prefix_(core::Prefix(generatePrefix(prefix, first_ipv6_word), 64)),
io_service_(io_service),
- external_io_service_(true),
- producer_socket_(),
ip_address_(origin_address),
port_(origin_port),
- cache_size_(std::stoul(cache_size)),
- mtu_(std::stoul(mtu)),
- request_counter_(0),
+ cache_size_((uint32_t)std::stoul(cache_size)),
+ mtu_((uint32_t)std::stoul(mtu)),
connector_(io_service_, ip_address_, port_,
std::bind(&AsyncConsumerProducer::publishContent, this,
std::placeholders::_1, std::placeholders::_2,
std::placeholders::_3, std::placeholders::_4),
- [this](asio::ip::tcp::socket& socket) -> bool {
+ [this]([[maybe_unused]] const asio::ip::tcp::socket& socket) {
std::queue<interface::PublicationOptions> empty;
std::swap(response_name_queue_, empty);
@@ -55,28 +52,28 @@ AsyncConsumerProducer::AsyncConsumerProducer(
interface::GeneralTransportOptions::OUTPUT_BUFFER_SIZE, cache_size_);
if (ret != SOCKET_OPTION_SET) {
- TRANSPORT_LOG_WARNING << "Warning: output buffer size has not been set.";
+ LoggerWarn() << "Warning: output buffer size has not been set.";
}
ret = producer_socket_.setSocketOption(
- interface::GeneralTransportOptions::MAKE_MANIFEST, manifest);
+ interface::GeneralTransportOptions::MANIFEST_MAX_CAPACITY, manifest);
if (ret != SOCKET_OPTION_SET) {
- TRANSPORT_LOG_WARNING << "Warning: impossible to enable signatures.";
+ LoggerWarn() << "Warning: impossible to enable signatures.";
}
ret = producer_socket_.setSocketOption(
interface::GeneralTransportOptions::DATA_PACKET_SIZE, mtu_);
if (ret != SOCKET_OPTION_SET) {
- TRANSPORT_LOG_WARNING << "Warning: mtu has not been set.";
+ LoggerWarn() << "Warning: mtu has not been set.";
}
producer_socket_.registerPrefix(prefix_);
}
void AsyncConsumerProducer::start() {
- TRANSPORT_LOG_INFO << "Starting listening";
+ LoggerInfo() << "Starting listening";
doReceive();
}
@@ -90,8 +87,8 @@ void AsyncConsumerProducer::run() {
void AsyncConsumerProducer::stop() {
io_service_.post([this]() {
- TRANSPORT_LOG_INFO << "Number of requests processed by plugin: "
- << request_counter_;
+ LoggerInfo() << "Number of requests processed by plugin: "
+ << request_counter_;
producer_socket_.stop();
connector_.close();
});
@@ -100,7 +97,7 @@ void AsyncConsumerProducer::stop() {
void AsyncConsumerProducer::doReceive() {
producer_socket_.setSocketOption(
interface::ProducerCallbacksOptions::CACHE_MISS,
- [this](interface::ProducerSocket& producer,
+ [this]([[maybe_unused]] const interface::ProducerSocket& producer,
interface::Interest& interest) {
if (interest.payloadSize() > 0) {
// Interest may contain http request
@@ -112,6 +109,7 @@ void AsyncConsumerProducer::doReceive() {
});
producer_socket_.connect();
+ producer_socket_.start();
}
void AsyncConsumerProducer::manageIncomingInterest(
@@ -128,9 +126,9 @@ void AsyncConsumerProducer::manageIncomingInterest(
if (seg >= _it->second.first) {
// TRANSPORT_LOGD(
- // "Ignoring interest with name %s for a content object which does not "
- // "exist. (Request: %u, max: %u)",
- // name.toString().c_str(), (uint32_t)seg, (uint32_t)_it->second.first);
+ // "Ignoring interest with name %s for a content object which does not
+ // " "exist. (Request: %u, max: %u)", name.toString().c_str(),
+ // (uint32_t)seg, (uint32_t)_it->second.first);
return;
}
}
@@ -148,7 +146,8 @@ void AsyncConsumerProducer::manageIncomingInterest(
response_name_queue_.emplace(std::move(name),
is_mpd ? 1000 : default_content_lifetime_);
- connector_.send(payload, [packet = std::move(packet)]() {});
+ connector_.send(payload,
+ [packet = std::move(packet)]() { /*nothing to do*/ });
}
void AsyncConsumerProducer::publishContent(const uint8_t* data,
@@ -157,26 +156,25 @@ void AsyncConsumerProducer::publishContent(const uint8_t* data,
uint32_t start_suffix = 0;
if (response_name_queue_.empty()) {
- std::cerr << "Aborting due tue empty request queue" << std::endl;
+ LoggerErr() << "Aborting due tue empty request queue";
abort();
}
- interface::PublicationOptions& options = response_name_queue_.front();
+ const interface::PublicationOptions& options = response_name_queue_.front();
int ret = producer_socket_.setSocketOption(
interface::GeneralTransportOptions::CONTENT_OBJECT_EXPIRY_TIME,
options.getLifetime());
if (TRANSPORT_EXPECT_FALSE(ret != SOCKET_OPTION_SET)) {
- TRANSPORT_LOG_WARNING << "Warning: content object lifetime has not been set.";
+ LoggerWarn() << "Warning: content object lifetime has not been set.";
}
const interface::Name& name = options.getName();
auto it = chunk_number_map_.find(name);
if (it == chunk_number_map_.end()) {
- std::cerr << "Aborting due to response not found in ResposeInfo map."
- << std::endl;
+ LoggerErr() << "Aborting due to response not found in ResposeInfo map.";
abort();
}