diff options
Diffstat (limited to 'libtransport/src/http/client_connection.cc')
-rw-r--r-- | libtransport/src/http/client_connection.cc | 74 |
1 files changed, 24 insertions, 50 deletions
diff --git a/libtransport/src/http/client_connection.cc b/libtransport/src/http/client_connection.cc index 7a3a636fe..05fa3e335 100644 --- a/libtransport/src/http/client_connection.cc +++ b/libtransport/src/http/client_connection.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2020 Cisco and/or its affiliates. + * Copyright (c) 2021 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,14 +13,12 @@ * limitations under the License. */ +#include <glog/logging.h> +#include <hicn/transport/core/asio_wrapper.h> #include <hicn/transport/core/content_object.h> #include <hicn/transport/core/interest.h> #include <hicn/transport/http/client_connection.h> #include <hicn/transport/utils/hash.h> -#include <hicn/transport/utils/log.h> - -#include <asio.hpp> -#include <asio/steady_timer.hpp> #define DEFAULT_BETA 0.99 #define DEFAULT_GAMMA 0.07 @@ -43,12 +41,6 @@ class HTTPClientConnection::Implementation read_buffer_(nullptr), response_(std::make_shared<HTTPResponse>()), timer_(nullptr) { - consumer_.setSocketOption( - ConsumerCallbacksOptions::CONTENT_OBJECT_TO_VERIFY, - (ConsumerContentObjectVerificationCallback)std::bind( - &Implementation::verifyData, this, std::placeholders::_1, - std::placeholders::_2)); - consumer_.setSocketOption(ConsumerCallbacksOptions::READ_CALLBACK, this); consumer_.connect(); @@ -83,13 +75,10 @@ class HTTPClientConnection::Implementation success_callback_ = [this, method = std::move(method), url = std::move(url), start = std::move(start)](std::size_t size) -> void { auto end = std::chrono::steady_clock::now(); - TRANSPORT_LOGI( - "%s %s [%s] duration: %llu [usec] %zu [bytes]\n", - method_map[method].c_str(), url.c_str(), name_.str().c_str(), - (unsigned long long) - std::chrono::duration_cast<std::chrono::microseconds>(end - start) - .count(), - size); + LOG(INFO) << method_map[method].c_str() << " " << url.c_str() << " [" + << name_.str() << "] duration: " + << utils::SteadyTime::getDurationUs(start, end).count() + << " [usec] " << size << " [bytes]"; }; sendRequestGetReply(ipv6_first_word); @@ -115,7 +104,7 @@ class HTTPClientConnection::Implementation HTTPClientConnection &setTimeout(const std::chrono::seconds &timeout) { timer_->cancel(); timer_->expires_from_now(timeout); - timer_->async_wait([this](std::error_code ec) { + timer_->async_wait([this](const std::error_code &ec) { if (!ec) { consumer_.stop(); } @@ -124,10 +113,10 @@ class HTTPClientConnection::Implementation return *http_client_; } - HTTPClientConnection &setCertificate(const std::string &cert_path) { - if (consumer_.setSocketOption(GeneralTransportOptions::CERTIFICATE, - cert_path) == SOCKET_OPTION_NOT_SET) { - throw errors::RuntimeException("Error setting the certificate."); + HTTPClientConnection &setVerifier(std::shared_ptr<auth::Verifier> verifier) { + if (consumer_.setSocketOption(GeneralTransportOptions::VERIFIER, + verifier) == SOCKET_OPTION_NOT_SET) { + throw errors::RuntimeException("Error setting the verifier."); } return *http_client_; @@ -156,18 +145,14 @@ class HTTPClientConnection::Implementation name_ << ipv6_first_word << ":"; - for (uint16_t *word = (uint16_t *)&locator_hash; - std::size_t(word) < - (std::size_t(&locator_hash) + sizeof(locator_hash)); - word++) { - name_ << ":" << std::hex << *word; + uint16_t *word = (uint16_t *)(&locator_hash); + for (std::size_t i = 0; i < sizeof(locator_hash) / 2; i++) { + name_ << ":" << std::hex << word[i]; } - for (uint16_t *word = (uint16_t *)&request_hash; - std::size_t(word) < - (std::size_t(&request_hash) + sizeof(request_hash)); - word++) { - name_ << ":" << std::hex << *word; + word = (uint16_t *)(&request_hash); + for (std::size_t i = 0; i < sizeof(request_hash) / 2; i++) { + name_ << ":" << std::hex << word[i]; } name_ << "|0"; @@ -177,17 +162,6 @@ class HTTPClientConnection::Implementation consumer_.stop(); } - bool verifyData(interface::ConsumerSocket &c, - const core::ContentObject &contentObject) { - if (contentObject.getPayloadType() == PayloadType::CONTENT_OBJECT) { - TRANSPORT_LOGI("VERIFY CONTENT\n"); - } else if (contentObject.getPayloadType() == PayloadType::MANIFEST) { - TRANSPORT_LOGI("VERIFY MANIFEST\n"); - } - - return true; - } - void processLeavingInterest(interface::ConsumerSocket &c, const core::Interest &interest) { if (interest.payloadSize() == 0) { @@ -219,9 +193,9 @@ class HTTPClientConnection::Implementation } } - void readError(const std::error_code ec) noexcept override { - TRANSPORT_LOGE("Error %s during download of %s", ec.message().c_str(), - current_url_.c_str()); + void readError(const std::error_code &ec) noexcept override { + LOG(ERROR) << "Error " << ec.message() << " during download of " + << current_url_.c_str(); if (read_bytes_callback_) { read_bytes_callback_->onError(ec); } @@ -307,9 +281,9 @@ HTTPClientConnection &HTTPClientConnection::setTimeout( return implementation_->setTimeout(timeout); } -HTTPClientConnection &HTTPClientConnection::setCertificate( - const std::string &cert_path) { - return implementation_->setCertificate(cert_path); +HTTPClientConnection &HTTPClientConnection::setVerifier( + std::shared_ptr<auth::Verifier> verifier) { + return implementation_->setVerifier(verifier); } } // namespace http |