diff options
-rw-r--r-- | apps/higet/CMakeLists.txt | 5 | ||||
-rw-r--r-- | apps/higet/higet.cc | 21 | ||||
-rw-r--r-- | apps/http-proxy/CMakeLists.txt | 5 | ||||
-rw-r--r-- | apps/http-proxy/main.cc | 19 | ||||
-rw-r--r-- | apps/http-proxy/src/IcnReceiver.cc | 54 | ||||
-rw-r--r-- | apps/http-proxy/src/IcnReceiver.h | 14 | ||||
-rw-r--r-- | apps/http-server/CMakeLists.txt | 5 | ||||
-rw-r--r-- | apps/http-server/http-server.cc | 30 | ||||
-rw-r--r-- | libtransport/src/hicn/transport/core/content_object.cc | 6 | ||||
-rw-r--r-- | libtransport/src/hicn/transport/core/interest.cc | 5 | ||||
-rw-r--r-- | libtransport/src/hicn/transport/core/packet.cc | 5 | ||||
-rw-r--r-- | libtransport/src/hicn/transport/http/client_connection.cc | 16 | ||||
-rw-r--r-- | libtransport/src/hicn/transport/http/client_connection.h | 9 | ||||
-rw-r--r-- | libtransport/src/hicn/transport/protocols/raaqm.cc | 1 | ||||
-rw-r--r-- | utils/CMakeLists.txt | 5 |
15 files changed, 154 insertions, 46 deletions
diff --git a/apps/higet/CMakeLists.txt b/apps/higet/CMakeLists.txt index 8c7188c49..747760f00 100644 --- a/apps/higet/CMakeLists.txt +++ b/apps/higet/CMakeLists.txt @@ -22,6 +22,11 @@ set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules" ) +if (NOT CMAKE_BUILD_TYPE) + message(STATUS "No build type selected, default to Release") + set(CMAKE_BUILD_TYPE "Release") +endif () + list(APPEND APPS_SRC higet.cc ) diff --git a/apps/higet/higet.cc b/apps/higet/higet.cc index 7662c1a2b..fa19528f8 100644 --- a/apps/higet/higet.cc +++ b/apps/higet/higet.cc @@ -31,6 +31,7 @@ typedef struct { std::string file_name; bool print_headers; std::string producer_certificate; + std::string ipv6_first_word; } Configuration; void processResponse(Configuration &conf, @@ -90,6 +91,9 @@ void usage(char *program_name) { << std::endl; std::cerr << "-S = print server response" << std::endl; + std::cerr << "-P = first word of the ipv6 name of " + "the response" + << std::endl; std::cerr << "example:" << std::endl; std::cerr << "\t" << program_name << " -O - http://origin/index.html" << std::endl; @@ -106,11 +110,12 @@ int main(int argc, char **argv) { conf.file_name = ""; conf.print_headers = false; conf.producer_certificate = ""; + conf.ipv6_first_word = "b001"; std::string name("http://webserver/sintel/mpd"); int opt; - while ((opt = getopt(argc, argv, "O:Sc:")) != -1) { + while ((opt = getopt(argc, argv, "O:Sc:P:")) != -1) { switch (opt) { case 'O': conf.file_name = optarg; @@ -121,6 +126,9 @@ int main(int argc, char **argv) { case 'c': conf.producer_certificate = optarg; break; + case 'P': + conf.ipv6_first_word = optarg; + break; case 'h': default: usage(argv[0]); @@ -128,11 +136,10 @@ int main(int argc, char **argv) { } } - if (argv[optind] == 0) { - std::cerr << "Using default name " << name << std::endl; - } else { - name = argv[optind]; - } + name = argv[optind]; + + std::cerr << "Using name " << name << " and name first word " + << conf.ipv6_first_word << std::endl; if (conf.file_name.empty()) { conf.file_name = name.substr(1 + name.find_last_of("/")); @@ -149,7 +156,7 @@ int main(int argc, char **argv) { t1 = std::chrono::system_clock::now(); - connection.get(name, headers); + connection.get(name, headers, {}, nullptr, nullptr, conf.ipv6_first_word); processResponse(conf, connection.response()); #ifdef _WIN32 diff --git a/apps/http-proxy/CMakeLists.txt b/apps/http-proxy/CMakeLists.txt index 010a2c2b6..85c044d58 100644 --- a/apps/http-proxy/CMakeLists.txt +++ b/apps/http-proxy/CMakeLists.txt @@ -19,6 +19,11 @@ set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules/" ) +if (NOT CMAKE_BUILD_TYPE) + message(STATUS "No build type selected, default to Release") + set(CMAKE_BUILD_TYPE "Release") +endif () + find_package(Threads REQUIRED) include_directories( SYSTEM diff --git a/apps/http-proxy/main.cc b/apps/http-proxy/main.cc index a7020298b..8dfaec77e 100644 --- a/apps/http-proxy/main.cc +++ b/apps/http-proxy/main.cc @@ -19,10 +19,11 @@ using namespace transport; int usage(char* program) { std::cerr << "ICN Plugin not loaded!" << std::endl; - std::cerr << "USAGE: " << program << "\n" - << "[HTTP_PREFIX] -a [SERVER_IP_ADDRESS] " - "-p [SERVER_PORT] -c [CACHE_SIZE] -m [MTU]" - << std::endl; + std::cerr + << "USAGE: " << program << "\n" + << "[HTTP_PREFIX] -a [SERVER_IP_ADDRESS] " + "-p [SERVER_PORT] -c [CACHE_SIZE] -m [MTU] -P [FIRST_IPv6_WORD_HEX]" + << std::endl; return -1; } @@ -32,9 +33,10 @@ int main(int argc, char** argv) { std::string port("80"); std::string cache_size("50000"); std::string mtu("1500"); + std::string first_ipv6_word("b001"); int opt; - while ((opt = getopt(argc, argv, "a:p:c:m:")) != -1) { + while ((opt = getopt(argc, argv, "a:p:c:m:P:")) != -1) { switch (opt) { case 'a': ip_address = optarg; @@ -48,6 +50,9 @@ int main(int argc, char** argv) { case 'm': mtu = optarg; break; + case 'P': + first_ipv6_word = optarg; + break; case 'h': default: return usage(argv[0]); @@ -63,9 +68,9 @@ int main(int argc, char** argv) { std::cout << "Connecting to " << ip_address << " port " << port << " Cache size " << cache_size << " Prefix " << prefix << " MTU " - << mtu << std::endl; + << mtu << " IPv6 first word " << first_ipv6_word << std::endl; transport::AsyncConsumerProducer proxy(prefix, ip_address, port, cache_size, - mtu); + mtu, first_ipv6_word); proxy.run(); diff --git a/apps/http-proxy/src/IcnReceiver.cc b/apps/http-proxy/src/IcnReceiver.cc index fc6837a2c..18553d84b 100644 --- a/apps/http-proxy/src/IcnReceiver.cc +++ b/apps/http-proxy/src/IcnReceiver.cc @@ -24,7 +24,8 @@ namespace transport { -core::Prefix generatePrefix(const std::string& prefix_url) { +core::Prefix generatePrefix(const std::string& prefix_url, + std::string& first_ipv6_word) { const char* str = prefix_url.c_str(); uint16_t pos = 0; @@ -39,7 +40,7 @@ core::Prefix generatePrefix(const std::string& prefix_url) { uint32_t locator_hash = utils::hash::fnv32_buf(str, strlen(str)); std::stringstream stream; - stream << std::hex << http::default_values::ipv6_first_word << ":0"; + stream << first_ipv6_word << ":0"; for (uint16_t* word = (uint16_t*)&locator_hash; std::size_t(word) < (std::size_t(&locator_hash) + sizeof(locator_hash)); @@ -52,12 +53,10 @@ core::Prefix generatePrefix(const std::string& prefix_url) { return core::Prefix(stream.str(), 64); } -AsyncConsumerProducer::AsyncConsumerProducer(const std::string& prefix, - std::string& ip_address, - std::string& port, - std::string& cache_size, - std::string& mtu) - : prefix_(generatePrefix(prefix)), +AsyncConsumerProducer::AsyncConsumerProducer( + const std::string& prefix, std::string& ip_address, std::string& port, + std::string& cache_size, std::string& mtu, std::string& first_ipv6_word) + : prefix_(generatePrefix(prefix, first_ipv6_word)), producer_socket_(), ip_address_(ip_address), port_(port), @@ -126,20 +125,37 @@ void AsyncConsumerProducer::doReceive() { void AsyncConsumerProducer::manageIncomingInterest( core::Name& name, core::Packet::MemBufPtr& packet, utils::MemBuf* payload) { - // auto seg = name.getSuffix(); + auto seg = name.getSuffix(); name.setSuffix(0); auto _it = chunk_number_map_.find(name); auto _end = chunk_number_map_.end(); if (_it != _end) { - return; + if (_it->second.second) { + // Content is in production + return; + } + + 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); + return; + } } bool is_mpd = HTTPMessageFastParser::isMpdRequest(payload->data(), payload->length()); - chunk_number_map_.emplace(name, 0); - response_name_queue_.emplace(std::move(name), is_mpd ? 1000 : 10000); + auto pair = chunk_number_map_.emplace(name, std::pair<uint32_t, bool>(0, 0)); + if (!pair.second) { + pair.first->second.first = 0; + } + + pair.first->second.second = true; + + response_name_queue_.emplace(std::move(name), is_mpd ? 1000 : 100000); connector_.send(payload, [packet = std::move(packet)]() {}); } @@ -166,17 +182,23 @@ void AsyncConsumerProducer::publishContent(const uint8_t* data, const interface::Name& name = options.getName(); - start_suffix = chunk_number_map_[name]; + 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; + abort(); + } + + start_suffix = it->second.first; if (headers) { request_counter_++; } - - chunk_number_map_[name] += + it->second.first += producer_socket_.produce(name, data, size, is_last, start_suffix); if (is_last) { - chunk_number_map_.erase(name); + it->second.second = false; response_name_queue_.pop(); } } diff --git a/apps/http-proxy/src/IcnReceiver.h b/apps/http-proxy/src/IcnReceiver.h index 61ca4333a..67f615ad7 100644 --- a/apps/http-proxy/src/IcnReceiver.h +++ b/apps/http-proxy/src/IcnReceiver.h @@ -28,10 +28,15 @@ namespace transport { class AsyncConsumerProducer { + using SegmentProductionPair = std::pair<uint32_t, bool>; + using ResponseInfoMap = std::unordered_map<core::Name, SegmentProductionPair>; + using RequestQueue = std::queue<interface::PublicationOptions>; + public: explicit AsyncConsumerProducer(const std::string& prefix, std::string& ip_address, std::string& port, - std::string& cache_size, std::string& mtu); + std::string& cache_size, std::string& mtu, + std::string& first_ipv6_word); void start(); @@ -63,8 +68,11 @@ class AsyncConsumerProducer { // std::unordered_map<core::Name, std::shared_ptr<ATSConnector>> // connection_map_; ATSConnector connector_; - std::unordered_map<core::Name, uint32_t> chunk_number_map_; - std::queue<interface::PublicationOptions> response_name_queue_; + + // ResponseInfoMap --> max_seq_number + bool indicating whether request is in + // production + ResponseInfoMap chunk_number_map_; + RequestQueue response_name_queue_; }; } // namespace transport diff --git a/apps/http-server/CMakeLists.txt b/apps/http-server/CMakeLists.txt index 65dcc9a98..743176136 100644 --- a/apps/http-server/CMakeLists.txt +++ b/apps/http-server/CMakeLists.txt @@ -20,6 +20,11 @@ list(APPEND LIBRARIES ${CURL_LIBRARY} ) +if (NOT CMAKE_BUILD_TYPE) + message(STATUS "No build type selected, default to Release") + set(CMAKE_BUILD_TYPE "Release") +endif () + set(LIB_SOURCE_FILES http-server/http_server.cc http-server/response.cc diff --git a/apps/http-server/http-server.cc b/apps/http-server/http-server.cc index 9d3eac5b8..f5fabf56f 100644 --- a/apps/http-server/http-server.cc +++ b/apps/http-server/http-server.cc @@ -287,12 +287,40 @@ int main(int argc, char **argv) { response->setResponseLifetime(response_lifetime); - if (_isDirectory(path.c_str())) { + if (!_isDirectory(path.c_str())) { // Check if path is within web_root_path if (distance(web_root_path.begin(), web_root_path.end()) <= distance(path.begin(), path.end()) && equal(web_root_path.begin(), web_root_path.end(), path.begin())) { + if (_isRegularFile(path.c_str())) { + auto ifs = make_shared<ifstream>(); + ifs->open(path, ifstream::in | ios::binary); + + if (*ifs) { + // read and send 15 MB at a time + streamsize buffer_size = 15 * 1024 * 1024; + auto buffer = make_shared<vector<char>>(buffer_size); + + ifs->seekg(0, ios::end); + auto length = ifs->tellg(); + ifs->seekg(0, ios::beg); + + response->setResponseLength(length); + *response << "HTTP/1.0 200 OK\r\nContent-Length: " << length + << "\r\n\r\n"; + + default_resource_send(server, response, ifs, buffer, length); + + return; + } + } + } + } else { + if (distance(web_root_path.begin(), web_root_path.end()) <= + distance(path.begin(), path.end()) && + equal(web_root_path.begin(), web_root_path.end(), path.begin())) { path += "index.html"; + std::cout << "path: "<< path <<endl; if (_isRegularFile(path.c_str())) { auto ifs = make_shared<ifstream>(); ifs->open(path, ifstream::in | ios::binary); diff --git a/libtransport/src/hicn/transport/core/content_object.cc b/libtransport/src/hicn/transport/core/content_object.cc index 107ab8567..764d753cd 100644 --- a/libtransport/src/hicn/transport/core/content_object.cc +++ b/libtransport/src/hicn/transport/core/content_object.cc @@ -33,6 +33,7 @@ namespace core { ContentObject::ContentObject(const Name &name, Packet::Format format) : Packet(format) { + if (TRANSPORT_EXPECT_FALSE( hicn_data_set_name(format, packet_start_, name.getStructReference()) < 0)) { @@ -46,8 +47,13 @@ ContentObject::ContentObject(const Name &name, Packet::Format format) } } +#ifdef __ANDROID__ +ContentObject::ContentObject(hicn_format_t format) + : ContentObject(Name("0::0|0"), format) {} +#else ContentObject::ContentObject(hicn_format_t format) : ContentObject(Packet::base_name, format) {} +#endif ContentObject::ContentObject(const Name &name, hicn_format_t format, const uint8_t *payload, std::size_t size) diff --git a/libtransport/src/hicn/transport/core/interest.cc b/libtransport/src/hicn/transport/core/interest.cc index bd7b57422..e7d47d565 100644 --- a/libtransport/src/hicn/transport/core/interest.cc +++ b/libtransport/src/hicn/transport/core/interest.cc @@ -44,7 +44,12 @@ Interest::Interest(const Name &interest_name, Packet::Format format) } } + +#ifdef __ANDROID__ +Interest::Interest(hicn_format_t format) : Interest(Name("0::0|0"), format) {} +#else Interest::Interest(hicn_format_t format) : Interest(base_name, format) {} +#endif Interest::Interest(const uint8_t *buffer, std::size_t size) : Packet(buffer, size) { diff --git a/libtransport/src/hicn/transport/core/packet.cc b/libtransport/src/hicn/transport/core/packet.cc index 954266664..04ec74660 100644 --- a/libtransport/src/hicn/transport/core/packet.cc +++ b/libtransport/src/hicn/transport/core/packet.cc @@ -29,7 +29,7 @@ namespace transport { namespace core { -const core::Name Packet::base_name("0::0|0"); + const core::Name Packet::base_name("0::0|0"); Packet::Packet(Format format) : packet_(utils::MemBuf::create(getHeaderSizeFromFormat(format, 256)) @@ -37,7 +37,8 @@ Packet::Packet(Format format) packet_start_(reinterpret_cast<hicn_header_t *>(packet_->writableData())), header_head_(packet_.get()), payload_head_(nullptr), - format_(format) { + format_(format){ + if (hicn_packet_init_header(format, packet_start_) < 0) { throw errors::RuntimeException("Unexpected error initializing the packet."); } diff --git a/libtransport/src/hicn/transport/http/client_connection.cc b/libtransport/src/hicn/transport/http/client_connection.cc index fadf0ae44..32269d49d 100644 --- a/libtransport/src/hicn/transport/http/client_connection.cc +++ b/libtransport/src/hicn/transport/http/client_connection.cc @@ -47,15 +47,16 @@ HTTPClientConnection::HTTPClientConnection() HTTPClientConnection::RC HTTPClientConnection::get( const std::string &url, HTTPHeaders headers, HTTPPayload payload, - std::shared_ptr<HTTPResponse> response, ReadBytesCallback *callback) { - return sendRequest(url, HTTPMethod::GET, headers, payload, response, - callback); + std::shared_ptr<HTTPResponse> response, ReadBytesCallback *callback, + std::string ipv6_first_word) { + return sendRequest(url, HTTPMethod::GET, headers, payload, response, callback, + ipv6_first_word); } HTTPClientConnection::RC HTTPClientConnection::sendRequest( const std::string &url, HTTPMethod method, HTTPHeaders headers, HTTPPayload payload, std::shared_ptr<HTTPResponse> response, - ReadBytesCallback *callback) { + ReadBytesCallback *callback, std::string ipv6_first_word) { current_url_ = url; read_bytes_callback_ = callback; if (!response) { @@ -82,12 +83,13 @@ HTTPClientConnection::RC HTTPClientConnection::sendRequest( return response; }; - sendRequestGetReply(request, response); + sendRequestGetReply(request, response, ipv6_first_word); return return_code_; } void HTTPClientConnection::sendRequestGetReply( - const HTTPRequest &request, std::shared_ptr<HTTPResponse> &response) { + const HTTPRequest &request, std::shared_ptr<HTTPResponse> &response, + std::string &ipv6_first_word) { const std::string &request_string = request.getRequestString(); const std::string &locator = request.getLocator(); @@ -107,7 +109,7 @@ void HTTPClientConnection::sendRequestGetReply( // Factor hicn name using hash name_.str(""); - name_ << std::hex << http::default_values::ipv6_first_word << ":"; + name_ << ipv6_first_word << ":"; for (uint16_t *word = (uint16_t *)&locator_hash; std::size_t(word) < (std::size_t(&locator_hash) + sizeof(locator_hash)); diff --git a/libtransport/src/hicn/transport/http/client_connection.h b/libtransport/src/hicn/transport/http/client_connection.h index d0624702f..5bcf9c4c7 100644 --- a/libtransport/src/hicn/transport/http/client_connection.h +++ b/libtransport/src/hicn/transport/http/client_connection.h @@ -49,12 +49,14 @@ class HTTPClientConnection : public ConsumerSocket::ReadCallback { RC get(const std::string &url, HTTPHeaders headers = {}, HTTPPayload payload = {}, std::shared_ptr<HTTPResponse> response = nullptr, - ReadBytesCallback *callback = nullptr); + ReadBytesCallback *callback = nullptr, + std::string ipv6_first_word = "b001"); RC sendRequest(const std::string &url, HTTPMethod method, HTTPHeaders headers = {}, HTTPPayload payload = {}, std::shared_ptr<HTTPResponse> response = nullptr, - ReadBytesCallback *callback = nullptr); + ReadBytesCallback *callback = nullptr, + std::string ipv6_first_word = "b001"); HTTPResponse response(); @@ -68,7 +70,8 @@ class HTTPClientConnection : public ConsumerSocket::ReadCallback { private: void sendRequestGetReply(const HTTPRequest &request, - std::shared_ptr<HTTPResponse> &response); + std::shared_ptr<HTTPResponse> &response, + std::string &ipv6_first_word); bool verifyData(interface::ConsumerSocket &c, const core::ContentObject &contentObject); diff --git a/libtransport/src/hicn/transport/protocols/raaqm.cc b/libtransport/src/hicn/transport/protocols/raaqm.cc index 8960e08fa..574693c51 100644 --- a/libtransport/src/hicn/transport/protocols/raaqm.cc +++ b/libtransport/src/hicn/transport/protocols/raaqm.cc @@ -105,6 +105,7 @@ void RaaqmTransportProtocol::reset() { std::queue<Interest::Ptr> empty; std::swap(interest_to_retransmit_, empty); current_window_size_ = 1; + stats_.reset(); // Reset reassembly component BaseReassembly::reset(); diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt index c78110949..2f7b3bb12 100644 --- a/utils/CMakeLists.txt +++ b/utils/CMakeLists.txt @@ -22,6 +22,11 @@ set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules" ) +if (NOT CMAKE_BUILD_TYPE) + message(STATUS "No build type selected, default to Release") + set(CMAKE_BUILD_TYPE "Release") +endif () + include(BuildMacros) include(WindowsMacros) |