Skip to content
This repository has been archived by the owner on Feb 7, 2025. It is now read-only.

Commit

Permalink
#21 #20 #18 #17 + code improve
Browse files Browse the repository at this point in the history
  • Loading branch information
dedok committed Nov 13, 2012
1 parent 8df55a5 commit 105f8a6
Show file tree
Hide file tree
Showing 11 changed files with 179 additions and 122 deletions.
30 changes: 26 additions & 4 deletions release note.txt
Original file line number Diff line number Diff line change
@@ -1,23 +1,43 @@
torrent to http (t2h) release note

*-----------------------------------------------------*
version 1.4.1.2

libcommon
--added new http transport based on mongoose;
--added new http transport implementation based on libmongoose(embedded by me in t2h);
--fixed hang connection in http transport;
--added uri specs validator(for wrong slashes);
--fixed infinity loop in common::notification_unit::execution_loop;
--performance tuning of notification_model;
--fixed hang in t2h_core::details::file_info_buffer(buffer for files information)::wait_avaliable_bytes;

http_core
--update Partial-Content handling, buffered sending of http body;
--added workaraund for vlc web-straming;
--added more strong file information sync with torrent_core;
--add Date/ETag headers to Partial-Content reply;
--
--fixed crash under Windwos in file_info::on_add_file;
--performance tuning;
--added workaraund for libtorrent(1.6.3)
issue: pieces migth not write to file at the momemt of event came from libtorrent session;

torrent_core
--fixed wrong piece length calculation;
--fixed avaliable bytes calculation for on_progress notification(for case avaliable bytes > file size);
--performance tuning;

settings manager
--update defaults values/keys;

*-----------------------------------------------------*
version 1.2.9.6

libcommon
--fixed crash inside notification_unit(copy_pending_notifications at std::list::erase call) under Windows;
--fixed crash inside notification_unit(notify_recv at std::list::erase call) under Windows;
--fixed crash inside systemlogger api;

*-----------------------------------------------------*
version 1.2.9.5

libcommon
Expand All @@ -29,6 +49,7 @@ tests
settings manager
--update default value for hc_max_sync_timeout(120 sec)

*-----------------------------------------------------*
version 1.2.9.2

http core
Expand Down Expand Up @@ -58,7 +79,8 @@ tests
--add http request test;
--add http server test;
--add notification center test;


*-----------------------------------------------------*
version 1.0.1.1

http core
Expand All @@ -80,4 +102,4 @@ settings_manager(settings)
full_model
--fixed crash on NULL value return from get_torrent_files();



2 changes: 1 addition & 1 deletion src/apps/full_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void dispatch_text_command(char const * ibuf, std::size_t ibuf_size, bool & exit
int main(int argc, char ** argv)
{
sig_state.sig_exit = false;
std::cin.get();

try
{
#if defined(UNIX) || defined(__APPLE__)
Expand Down
47 changes: 30 additions & 17 deletions src/common/network/details/http_mongoose_transport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@ static inline bool mon_is_range_request(
{
BOOST_ASSERT(ri != NULL);

if (strcmp(ri->http_version, "1.1") != 0 && strcmp(ri->request_method, "GET") != 0)
if (strcmp(ri->http_version, "1.1") != 0)
return false;

if (strcmp(ri->request_method, "GET") != 0)
return false;

char const * range_header = mg_get_header(conn, "Range");
if (range_header)
return utility::http_translate_range_header(rheader, range_header);

char const * accept_header = mg_get_header(conn, "Accept");
if (accept_header)
return utility::http_translate_accept_header(rheader, range_header);
Expand Down Expand Up @@ -68,7 +71,7 @@ static void * mongoose_completion_routine(enum mg_event event, struct mg_connect
}

/* mics helpers */
static void * http_stok_reply(
static void * http_stock_reply(
struct mg_connection * conn,
http_transport_event_handler::operation_status status,
http_transport_event_handler_ptr far_handler,
Expand Down Expand Up @@ -105,41 +108,53 @@ static void * far_handler_on_range_request(

http_transport_event_handler::http_data pcd;
std::string const uri = utility::http_normalize_uri_c(ri->uri);
far_handler->on_get_partial_content_headers(pcd, rheader.bstart_1, rheader.bend_1, uri.c_str());
if (pcd.op_status != http_transport_event_handler::ok)
return http_stok_reply(conn, pcd.op_status, far_handler, ri);

far_handler->on_get_partial_content_headers(pcd, rheader.bstart_1, rheader.bend_1, uri.c_str());
if (pcd.op_status != http_transport_event_handler::ok)
return http_stock_reply(conn, pcd.op_status, far_handler, ri);

if (mg_write(conn, pcd.reply_header.c_str(), pcd.reply_header.size()) > 0) {
bool has_data = true;
pcd.seek_offset_pos = rheader.bstart_1;
for (boost::int64_t bytes_writed = 0;;) {
has_data =
far_handler->on_get_content_body(pcd, rheader.bstart_1, rheader.bend_1, bytes_writed, uri.c_str());
for (boost::int64_t bytes_writed = 0;;)
{
has_data = far_handler->on_get_content_body(pcd,
rheader.bstart_1,
rheader.bend_1,
bytes_writed,
uri.c_str());

if (pcd.op_status != http_transport_event_handler::ok)
return http_stock_reply(conn, pcd.op_status, far_handler, ri);

if ((bytes_writed = mg_write(conn, &pcd.io_buffer.at(0), pcd.last_readed)) <= 0) {
LC_WARNING("writing body data failed, for uri '%s'", uri.c_str())
far_handler->error(http_transport_event_handler::write_op_error, uri.c_str());
break;
} // if
if (!has_data)

if (!has_data)
break;
} // read & send loop
return NOT_NULL;
}

LC_WARNING("writing header data failed, for uri '%s'", uri.c_str())
return NULL;
return NOT_NULL;
}

static void * far_handler_on_head_request(
transport_context_ptr far_handler, struct mg_connection * conn, struct mg_request_info const * ri)
{
BOOST_ASSERT(ri != NULL);
// TODO impl this
return NULL;
}

static void * far_handler_on_content_request(
transport_context_ptr far_handler, struct mg_connection * conn, struct mg_request_info const * ri)
{
BOOST_ASSERT(ri != NULL);
// TODO impl this
return NULL;
}

Expand Down Expand Up @@ -233,19 +248,18 @@ void * http_mongoose_transport::dispatch_http_message(

switch (event)
{
case MG_NEW_REQUEST :
case MG_NEW_REQUEST :
if (mon_is_range_request(conn, ri, rheader))
return far_handler_on_range_request(http_context_, conn, ri, rheader);
else if(mon_is_head_request(conn, ri))
return far_handler_on_head_request(http_context_, conn, ri);
else if (mon_is_content_requst(conn, ri))
return far_handler_on_content_request(http_context_, conn, ri);
break;

case MG_HTTP_ERROR :
LC_WARNING("error detected, code '%i', for uri '%s'", (long) ri->ev_data, ri->uri)
return NULL;

case MG_REQUEST_COMPLETE :
return NULL;

Expand All @@ -254,7 +268,6 @@ void * http_mongoose_transport::dispatch_http_message(
} // switch

STD_EXCEPTION_HANDLE_END

return NULL;
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/common/setting_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ ADD_KEY_TYPE(tc_port_end, "", "", true)
// torrent core keys, with some defaults values
ADD_KEY_TYPE(cores_sync_timeout, "260", "", false)
ADD_KEY_TYPE(max_size_for_reply, "102400", "", false)
ADD_KEY_TYPE(tc_max_alert_wait_time, "15", "", false)
ADD_KEY_TYPE(tc_max_alert_wait_time, "10", "", false)
ADD_KEY_TYPE(tc_max_partial_download_size, "5242880", "", false)
ADD_KEY_TYPE(tc_root, "", "doc_root", false)
ADD_KEY_TYPE(tc_futures_timeout, "10", "", false)
Expand Down
93 changes: 44 additions & 49 deletions src/core/http_server/details/file_info_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
#include "core_notification_center.hpp"
#include "file_info_buffer_realtime_updater.hpp"

#include <boost/thread.hpp>
#include <boost/date_time/posix_time/posix_time_io.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>

#define T2H_DEEP_DEBUG
#define HCORE_FIB_UPDATER_NAME "hcore_notification_recv";

namespace t2h_core { namespace details {
Expand Down Expand Up @@ -37,54 +37,42 @@ file_info_buffer::file_info_buffer()
file_info_buffer::~file_info_buffer()
{
core_notification_center()->remove_notification_receiver(updater_.recv_name);
boost::mutex::scoped_lock guard(lock_);
guard.unlock();
waiter_.notify_one();
}

bool file_info_buffer::wait_avaliable_bytes(
std::string const & file_path, boost::int64_t avaliable_bytes, std::size_t secs)
{
/* */
using boost::posix_time::seconds;

bool state = false;
hc_file_info_ptr finfo;

if ((finfo = get_info(file_path)))
{
if (finfo->avaliable_bytes >= avaliable_bytes) {
#if defined(T2H_DEEP_DEBUG)
HCORE_TRACE("for path '%s', bytes avaliable '%i', bytes requested '%i'",
finfo->file_path.c_str(), finfo->avaliable_bytes, avaliable_bytes)
#endif // T2H_DEEP_DEBUG
return true;
}
boost::unique_lock<boost::mutex> guard(finfo->waiter_lock);
for (boost::system_time timeout;
;
timeout = boost::get_system_time() + seconds(secs))
{

if ((finfo = get_info(file_path))) {
boost::mutex::scoped_lock guard(lock_);
for (;;) {
if (finfo->avaliable_bytes >= avaliable_bytes) {
#if defined(T2H_DEEP_DEBUG)
HCORE_TRACE("for path '%s', bytes avaliable '%i', bytes requested '%i'",
finfo->file_path.c_str(), finfo->avaliable_bytes, avaliable_bytes)
HCORE_TRACE("wait bytes for path '%s' finished", finfo->file_path.c_str())
#endif // T2H_DEEP_DEBUG
if (finfo->avaliable_bytes >= avaliable_bytes) {
state = true;
break;
return true;
}

if (!(state = finfo->waiter.timed_wait(guard, timeout))) {
#if defined(T2H_DEEP_DEBUG)
HCORE_WARNING("for path '%s' waiting bytes failed", finfo->file_path.c_str())
#endif // T2H_DEEP_DEBUG
break;
boost::system_time timeout = boost::get_system_time() + seconds(secs);
if (!waiter_.timed_wait(guard, timeout)) {
HCORE_WARNING("wait bytes for path '%s' failed", finfo->file_path.c_str())
return false;
}
} // wait loop
} // state

return state;
HCORE_WARNING("finfo not valid for path '%s'", file_path.c_str())
return false;
}

void file_info_buffer::remove_info(std::string const & path)
{
boost::lock_guard<boost::mutex> guard(lock_);
boost::mutex::scoped_lock guard(lock_);
infos_type::iterator found = infos_.find(path);
if (found != infos_.end()) {
#if defined(T2H_DEEP_DEBUG)
Expand All @@ -96,37 +84,45 @@ void file_info_buffer::remove_info(std::string const & path)

void file_info_buffer::update_info(hc_file_info_ptr info)
{
boost::lock_guard<boost::mutex> guard(lock_);
BOOST_ASSERT(info != NULL);
boost::mutex::scoped_lock guard(lock_);

infos_type::iterator found = infos_.find(info->file_path);
if (found != infos_.end()) {
if (found == infos_.end()) {
HCORE_WARNING("update info failed, item not found", info->file_path.c_str())
return;
}
#if defined(T2H_DEEP_DEBUG)
HCORE_TRACE("updating existing file info entry '%s', bytes avaliable '"SL_SSIZE_T"'",
info->file_path.c_str(), info->avaliable_bytes)
HCORE_TRACE("updating existing file info entry '%s', bytes avaliable '"SL_SSIZE_T"'",
info->file_path.c_str(), info->avaliable_bytes)
#endif // T2H_DEEP_DEBUG
found->second->file_size = info->file_size;
found->second->avaliable_bytes = info->avaliable_bytes;
found->second->waiter.notify_all();
}
found->second->file_size = info->file_size;
found->second->avaliable_bytes = info->avaliable_bytes;
guard.unlock();
waiter_.notify_one();
}

void file_info_buffer::update_info(std::string const & file_path, boost::int64_t avaliable_bytes)
{
boost::lock_guard<boost::mutex> guard(lock_);
boost::mutex::scoped_lock guard(lock_);

infos_type::iterator found = infos_.find(file_path);
if (found != infos_.end()) {
if (found == infos_.end()) {
HCORE_WARNING("update info failed, item not found", file_path.c_str())
return;
}
#if defined(T2H_DEEP_DEBUG)
HCORE_TRACE("updating existing file info entry '%s', bytes avaliable '"SL_SSIZE_T"'",
found->second->file_path.c_str(), avaliable_bytes)
HCORE_TRACE("updating existing item '%s', bytes avaliable '"SL_SSIZE_T"'",
found->second->file_path.c_str(), avaliable_bytes)
#endif // T2H_DEEP_DEBUG

found->second->avaliable_bytes = avaliable_bytes;
found->second->waiter.notify_all();
}
found->second->avaliable_bytes = avaliable_bytes;
guard.unlock();
waiter_.notify_one();
}

hc_file_info_ptr file_info_buffer::get_info(std::string const & path) const
{
boost::lock_guard<boost::mutex> guard(lock_);
boost::mutex::scoped_lock guard(lock_);
infos_type::const_iterator found = infos_.find(path);
if (found != infos_.end())
return found->second;
Expand All @@ -140,4 +136,3 @@ hc_file_info_ptr file_info_buffer::get_info(std::string const & path) const
} } // namespace t2h_core, details

#undef HCORE_FIB_UPDATER_NAME

Loading

0 comments on commit 105f8a6

Please sign in to comment.