diff options
-rw-r--r-- | apps/higet/CMakeLists.txt | 5 | ||||
-rw-r--r-- | apps/http-proxy/CMakeLists.txt | 5 | ||||
-rw-r--r-- | apps/http-proxy/src/IcnReceiver.cc | 39 | ||||
-rw-r--r-- | apps/http-proxy/src/IcnReceiver.h | 11 | ||||
-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-- | utils/CMakeLists.txt | 5 |
10 files changed, 103 insertions, 13 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/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/src/IcnReceiver.cc b/apps/http-proxy/src/IcnReceiver.cc index fc6837a2c..d4e922c11 100644 --- a/apps/http-proxy/src/IcnReceiver.cc +++ b/apps/http-proxy/src/IcnReceiver.cc @@ -126,20 +126,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 +183,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..ea4eeb010 100644 --- a/apps/http-proxy/src/IcnReceiver.h +++ b/apps/http-proxy/src/IcnReceiver.h @@ -28,6 +28,10 @@ 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, @@ -63,8 +67,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/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) |