59 static size_t HTTPConvergenceLayer_callback_read(
void *ptr,
size_t size,
size_t nmemb,
void *s)
62 std::istream *stream =
static_cast<std::istream*
>(s);
64 if (stream->eof())
return 0;
66 char *buffer =
static_cast<char*
>(ptr);
68 stream->read(buffer, (size * nmemb));
69 retcode = stream->gcount();
82 static size_t HTTPConvergenceLayer_callback_write(
void *ptr,
size_t size,
size_t nmemb,
void *s)
84 std::ostream *stream =
static_cast<std::ostream*
>(s);
85 char *buffer =
static_cast<char*
>(ptr);
87 if (!stream->good())
return 0;
89 stream->write(buffer, (size * nmemb));
92 return (size * nmemb);
103 : _server(server), _push_iob(NULL),
_running(true)
105 curl_global_init(CURL_GLOBAL_ALL);
115 curl_global_cleanup();
153 while(_stream.good())
163 if (ret != BundleFilter::ACCEPT)
continue;
167 }
catch (
const ibrcommon::Exception &ex) {
168 IBRCOMMON_LOGGER_DEBUG_TAG(
"HTTPConvergenceLayer", 10) <<
"http error: " << ex.what() << IBRCOMMON_LOGGER_ENDL;
173 }
catch (
const ibrcommon::ThreadException &e) {
174 std::cerr <<
"error: " << e.what() << std::endl;
198 std::string url_send;
215 if (ret != BundleFilter::ACCEPT) {
221 ibrcommon::BLOB::Reference ref = ibrcommon::BLOB::create();
223 ibrcommon::BLOB::iostream io = ref.iostream();
227 ibrcommon::BLOB::iostream io = ref.iostream();
228 size_t length = io.
size();
242 curl_up = curl_easy_init();
246 curl_easy_setopt(curl_up, CURLOPT_READFUNCTION, HTTPConvergenceLayer_callback_read);
249 curl_easy_setopt(curl_up, CURLOPT_UPLOAD, 1L);
252 curl_easy_setopt(curl_up, CURLOPT_PUT, 1L);
255 curl_easy_setopt(curl_up, CURLOPT_CONNECTTIMEOUT, 0);
259 curl_easy_setopt(curl_up, CURLOPT_URL, url_send.c_str());
262 curl_easy_setopt(curl_up, CURLOPT_READDATA, &(*io));
266 curl_easy_setopt(curl_up, CURLOPT_INFILESIZE_LARGE,
270 res = curl_easy_perform(curl_up);
275 curl_easy_getinfo (curl_up, CURLINFO_RESPONSE_CODE, &http_code);
291 curl_easy_cleanup(curl_up);
338 curl_down = curl_easy_init();
342 curl_easy_setopt(curl_down, CURLOPT_URL, url.c_str());
345 curl_easy_setopt(curl_down, CURLOPT_CONNECTTIMEOUT, 0);
348 curl_easy_setopt(curl_down, CURLOPT_NOPROGRESS, 1L);
359 ibrcommon::MutexLock l(_push_iob_mutex);
360 _push_iob =
new ibrcommon::iobuffer();
363 std::auto_ptr<ibrcommon::iobuffer> auto_kill(_push_iob);
364 std::ostream os(_push_iob);
368 curl_easy_setopt(curl_down, CURLOPT_WRITEFUNCTION, HTTPConvergenceLayer_callback_write);
371 curl_easy_setopt(curl_down, CURLOPT_WRITEDATA, &os);
375 curl_easy_perform(curl_down);
378 ibrcommon::MutexLock l(_push_iob_mutex);
380 _push_iob->finalize();
392 IBRCOMMON_LOGGER_DEBUG_TAG(
"HTTPConvergenceLayer", 10) <<
"http error: " <<
"Couldn't connect to server ... wait " <<
CONN_TIMEOUT/1000 <<
"s until retry" << IBRCOMMON_LOGGER_ENDL;
396 curl_easy_cleanup(curl_down);
418 ibrcommon::MutexLock l(_push_iob_mutex);
419 if (_push_iob != NULL)
421 _push_iob->finalize();
432 return "HTTPConvergenceLayer";
const int CURL_PARTIAL_FILE
static dtn::data::EID local
HTTPConvergenceLayer(const std::string &server)
void setBundle(const dtn::data::Bundle &data)
virtual void componentUp()
dtn::core::Node::Protocol getDiscoveryProtocol() const
BundleFilter::ACTION filter(BundleFilter::TABLE table, const FilterContext &context, dtn::data::Bundle &bundle) const
virtual ~HTTPConvergenceLayer()
void setProtocol(const dtn::core::Node::Protocol &protocol)
virtual void componentRun()
virtual void componentDown()
void queue(const dtn::core::Node &n, const dtn::net::BundleTransfer &job)
virtual const std::string getName() const
virtual dtn::data::Bundle get(const dtn::data::BundleID &id)=0
void abort(const TransferAbortedEvent::AbortReason reason)
const dtn::data::MetaBundle & getBundle() const
std::string getString() const
virtual ~DownloadThread()
dtn::storage::BundleStorage & getStorage()
DownloadThread(ibrcommon::iobuffer &buf)
static void raise(const dtn::data::EID &peer, const dtn::data::Bundle &bundle, const bool local=false)
static BundleCore & getInstance()