#include <BundlePayload.h>
Inheritance diagram for dtn::BundlePayload:
This is abstracted into a separate class to allow the daemon to separately manage the serialization of header information from the payload.
Note that this implementation doesn't support payloads larger than 4GB. XXX/demmer fix this.
Definition at line 61 of file BundlePayload.h.
Public Types | |
enum | location_t { MEMORY = 1, DISK = 2, UNDETERMINED = 3, NODATA = 4 } |
Options for payload location state. More... | |
enum | read_data_flags_t { KEEP_FILE_OPEN = 0x1, FORCE_COPY = 0x2 } |
Valid flags to read_data. More... | |
Public Member Functions | |
BundlePayload (oasys::SpinLock *lock) | |
Constructor. | |
virtual | ~BundlePayload () |
Destructor. | |
void | init (int bundleid, location_t location=UNDETERMINED) |
Actual payload initialization function. | |
void | init_from_store (int bundleid) |
Initialization when re-reading the database. | |
void | set_length (size_t len, location_t location=UNDETERMINED) |
Set the payload length in preparation for filling in with data. | |
void | truncate (size_t len) |
Truncate the payload. | |
size_t | length () const |
The payload length. | |
location_t | location () const |
The payload location. | |
void | set_data (const u_char *bp, size_t len) |
Set the payload data and length, closing the payload file after it's been written to. | |
void | set_data (const std::string &data) |
Set the payload data, closing the payload file after it's been written to. | |
void | append_data (const u_char *bp, size_t len) |
Append a chunk of payload data. | |
void | write_data (const u_char *bp, size_t offset, size_t len) |
Write a chunk of payload data at the specified offset. | |
void | write_data (BundlePayload *src, size_t src_offset, size_t len, size_t dst_offset) |
Writes len bytes of payload data from from another payload at the given src_offset to the given dst_offset. | |
void | reopen_file () |
Reopen the payload file. | |
void | close_file () |
Close the payload file. | |
bool | is_file_open () |
Return the file state. | |
void | copy_file (oasys::FileIOClient *dst) |
Copy (or link) the payload to the given path. | |
const u_char * | memory_data () |
Get a pointer to the in-memory data buffer. | |
const u_char * | read_data (size_t offset, size_t len, u_char *buf, int flags=0) |
Return a pointer to a chunk of payload data. | |
const u_char * | read_data (size_t offset, size_t len, u_char *buf, int flags=0) const |
Since read_data doesn't really change anything of substance in the payload class (just the internal bookkeeping fields), we define a "const" variant that just casts itself away and calls the normal variant. | |
virtual void | serialize (oasys::SerializeAction *a) |
Virtual from SerializableObject. | |
Static Public Attributes | |
static std::string | payloaddir_ |
directory to store payload files | |
static size_t | mem_threshold_ |
maximum bundle size to keep in memory | |
static bool | test_no_remove_ |
test: don't rm payload files | |
Protected Member Functions | |
void | internal_write (const u_char *bp, size_t offset, size_t len) |
Internal write helper function. | |
Protected Attributes | |
location_t | location_ |
location of the data (disk or memory) | |
std::string | data_ |
the actual payload data if in memory | |
size_t | length_ |
the payload length | |
size_t | rcvd_length_ |
the payload length we actually have | |
std::string | fname_ |
payload file name | |
oasys::FileIOClient * | file_ |
file handle if on disk | |
size_t | cur_offset_ |
cache of current fd position | |
size_t | base_offset_ |
for fragments, offset into the file (todo) | |
oasys::SpinLock * | lock_ |
the lock for the given bundle |
Options for payload location state.
MEMORY | |
DISK | copy of the payload kept in memory |
UNDETERMINED | payload only kept on disk |
NODATA | determine MEMORY or DISK based on threshold |
Definition at line 69 of file BundlePayload.h.
Valid flags to read_data.
KEEP_FILE_OPEN | Don't close file after read. |
FORCE_COPY | Always copy payload, even for in-memory bundles. |
Definition at line 175 of file BundlePayload.h.
dtn::BundlePayload::BundlePayload | ( | oasys::SpinLock * | lock | ) |
dtn::BundlePayload::~BundlePayload | ( | ) | [virtual] |
Destructor.
Definition at line 130 of file BundlePayload.cc.
References file_, test_no_remove_, and oasys::FileIOClient::unlink().
void dtn::BundlePayload::init | ( | int | bundleid, | |
location_t | location = UNDETERMINED | |||
) |
Actual payload initialization function.
Definition at line 71 of file BundlePayload.cc.
References oasys::StringBuffer::c_str(), errno, file_, location_, log_crit, log_err, oasys::Logger::logpath_, oasys::Logger::logpathf(), NODATA, oasys::FileIOClient::open(), and payloaddir_.
Referenced by dtn::Bundle::Bundle(), and dtnsim::TrAgent::send_bundle().
void dtn::BundlePayload::init_from_store | ( | int | bundleid | ) |
Initialization when re-reading the database.
Definition at line 109 of file BundlePayload.cc.
References oasys::StringBuffer::c_str(), oasys::FileIOClient::close(), DISK, errno, file_, location_, log_crit, oasys::Logger::logpathf(), oasys::FileIOClient::open(), and payloaddir_.
Referenced by dtn::Bundle::serialize().
void dtn::BundlePayload::set_length | ( | size_t | len, | |
location_t | location = UNDETERMINED | |||
) |
Set the payload length in preparation for filling in with data.
Optionally also force-sets the location, or leaves it based on configured parameters.
Definition at line 158 of file BundlePayload.cc.
References ASSERT, DISK, ExamineDump::l, length_, location_, lock_, mem_threshold_, MEMORY, and UNDETERMINED.
Referenced by dtn::FragmentManager::create_fragment(), dtn::BundleCommand::exec(), dtn::APIClient::handle_send(), dtn::BundleProtocol::parse_header_blocks(), dtnsim::TrAgent::send_bundle(), and set_data().
void dtn::BundlePayload::truncate | ( | size_t | len | ) |
Truncate the payload.
Used for reactive fragmentation.
Definition at line 179 of file BundlePayload.cc.
References ASSERT, close_file(), cur_offset_, data_, file_, ExamineDump::l, length_, location_, lock_, MEMORY, rcvd_length_, reopen_file(), and oasys::FileIOClient::truncate().
Referenced by dtn::FragmentManager::convert_to_fragment().
size_t dtn::BundlePayload::length | ( | ) | const [inline] |
The payload length.
Definition at line 101 of file BundlePayload.h.
References length_.
Referenced by dtn::BundleReceivedEvent::BundleReceivedEvent(), dtn::FragmentManager::check_completed(), dtn::FragmentManager::convert_to_fragment(), copy_file(), dtn::FragmentManager::create_fragment(), dtnsim::SimRegistration::deliver_bundle(), dtn::LoggingRegistration::deliver_bundle(), dtn::LinkStateRouter::LSRegistration::deliver_bundle(), dtn::AdminRegistration::deliver_bundle(), dtn::BundleCommand::exec(), dtn::BundleDaemon::find_duplicate(), dtn::Bundle::format(), dtn::BundleProtocol::format_bundle(), dtn::BundleProtocol::format_header_blocks(), dtn::Bundle::format_verbose(), dtn::BundleProtocol::formatted_length(), dtn::BundleDaemon::generate_custody_signal(), dtn::BundleDaemon::generate_status_report(), dtn::BundleProtocol::get_payload_block_len(), dtn::get_payload_str(), dtn::BluetoothConvergenceLayer::Connection::handle_ack(), dtn::BundleDaemon::handle_bundle_delivered(), dtn::BundleDaemon::handle_bundle_received(), dtn::APIClient::handle_recv(), dtn::AnnounceBundle::parse_announce_bundle(), dtn::BundleProtocol::parse_bundle(), dtn::BundleProtocol::parse_header_blocks(), dtn::FragmentManager::proactively_fragment(), dtn::UDPConvergenceLayer::Receiver::process_data(), dtn::FragmentManager::process_for_reassembly(), dtn::BluetoothConvergenceLayer::Connection::recv_bundle(), dtn::UDPConvergenceLayer::Sender::send_bundle(), dtnsim::SimConvergenceLayer::send_bundle(), dtn::FileConvergenceLayer::send_bundle(), dtn::BluetoothConvergenceLayer::Connection::send_bundle(), dtn::StreamConvergenceLayer::Connection::send_next_segment(), and dtn::FragmentManager::try_to_reactively_fragment().
location_t dtn::BundlePayload::location | ( | ) | const [inline] |
The payload location.
Definition at line 106 of file BundlePayload.h.
References location_.
Referenced by dtn::APIClient::handle_recv().
void dtn::BundlePayload::set_data | ( | const u_char * | bp, | |
size_t | len | |||
) |
Set the payload data and length, closing the payload file after it's been written to.
Definition at line 305 of file BundlePayload.cc.
References ASSERT, base_offset_, close_file(), internal_write(), ExamineDump::l, lock_, rcvd_length_, reopen_file(), and set_length().
Referenced by dtn::AnnounceBundle::create_announce_bundle(), dtn::CustodySignal::create_custody_signal(), dtn::BundleStatusReport::create_status_report(), dtn::BundleCommand::exec(), dtn::APIClient::handle_send(), dtn::BundleProtocol::parse_bundle(), dtn::UDPConvergenceLayer::Receiver::process_data(), dtn::LinkStateRouter::send_announcement(), and set_data().
void dtn::BundlePayload::set_data | ( | const std::string & | data | ) | [inline] |
Set the payload data, closing the payload file after it's been written to.
Definition at line 118 of file BundlePayload.h.
References set_data().
void dtn::BundlePayload::append_data | ( | const u_char * | bp, | |
size_t | len | |||
) |
Append a chunk of payload data.
Assumes that the length was previously set. Keeps the payload file open.
Definition at line 322 of file BundlePayload.cc.
References ASSERT, base_offset_, cur_offset_, file_, internal_write(), oasys::FileIOClient::is_open(), ExamineDump::l, length_, lock_, oasys::FileIOClient::lseek(), and rcvd_length_.
Referenced by dtn::BundleCommand::exec(), dtn::APIClient::handle_send(), and dtn::BluetoothConvergenceLayer::Connection::recv_bundle().
void dtn::BundlePayload::write_data | ( | const u_char * | bp, | |
size_t | offset, | |||
size_t | len | |||
) |
Write a chunk of payload data at the specified offset.
Keeps the payload file open.
Definition at line 343 of file BundlePayload.cc.
References ASSERT, base_offset_, file_, internal_write(), oasys::FileIOClient::is_open(), ExamineDump::l, length_, and lock_.
Referenced by dtn::FragmentManager::create_fragment(), and dtn::BundleCommand::exec().
void dtn::BundlePayload::write_data | ( | BundlePayload * | src, | |
size_t | src_offset, | |||
size_t | len, | |||
size_t | dst_offset | |||
) |
Writes len bytes of payload data from from another payload at the given src_offset to the given dst_offset.
Keeps the payload file open.
Definition at line 359 of file BundlePayload.cc.
References ASSERT, file_, internal_write(), oasys::FileIOClient::is_open(), KEEP_FILE_OPEN, ExamineDump::l, length_, lock_, log_debug, oasys::FileIOClient::path(), and src.
void dtn::BundlePayload::reopen_file | ( | ) |
Reopen the payload file.
Definition at line 203 of file BundlePayload.cc.
References cur_offset_, errno, file_, oasys::FileIOClient::is_open(), log_err, oasys::FileIOClient::path(), and oasys::FileIOClient::reopen().
Referenced by copy_file(), dtn::APIClient::handle_send(), read_data(), set_data(), and truncate().
void dtn::BundlePayload::close_file | ( | ) |
Close the payload file.
Definition at line 220 of file BundlePayload.cc.
References oasys::FileIOClient::close(), file_, and oasys::FileIOClient::is_open().
Referenced by copy_file(), dtn::FragmentManager::create_fragment(), dtn::BundleCommand::exec(), dtn::BundleDaemon::handle_bundle_received(), dtn::APIClient::handle_send(), dtn::FragmentManager::proactively_fragment(), read_data(), set_data(), truncate(), and dtn::FragmentManager::try_to_reactively_fragment().
bool dtn::BundlePayload::is_file_open | ( | ) | [inline] |
Return the file state.
Definition at line 156 of file BundlePayload.h.
References file_, and oasys::FileIOClient::is_open().
Referenced by copy_file(), and dtn::BundleDaemon::handle_bundle_received().
void dtn::BundlePayload::copy_file | ( | oasys::FileIOClient * | dst | ) |
Copy (or link) the payload to the given path.
Definition at line 231 of file BundlePayload.cc.
References close_file(), oasys::FileIOClient::copy_contents(), file_, is_file_open(), length(), oasys::FileIOClient::lseek(), and reopen_file().
Referenced by dtn::APIClient::handle_recv().
const u_char* dtn::BundlePayload::memory_data | ( | ) | [inline] |
Get a pointer to the in-memory data buffer.
Definition at line 166 of file BundlePayload.h.
References ASSERT, data_, location_, and MEMORY.
Referenced by dtn::APIClient::handle_recv().
const u_char * dtn::BundlePayload::read_data | ( | size_t | offset, | |
size_t | len, | |||
u_char * | buf, | |||
int | flags = 0 | |||
) |
Return a pointer to a chunk of payload data.
For in-memory bundles, this will just be a pointer to the data buffer (unless the FORCE_COPY flag is set).
Otherwise, it will call read() into the supplied buffer (which must be >= len).
Definition at line 389 of file BundlePayload.cc.
References ASSERT, close_file(), cur_offset_, data_, file_, FORCE_COPY, KEEP_FILE_OPEN, ExamineDump::l, length_, location_, lock_, oasys::FileIOClient::lseek(), MEMORY, rcvd_length_, oasys::FdIOClient::readall(), and reopen_file().
Referenced by dtn::LoggingRegistration::deliver_bundle(), dtn::LinkStateRouter::LSRegistration::deliver_bundle(), dtn::AdminRegistration::deliver_bundle(), dtn::BundleProtocol::format_bundle(), dtn::BundleProtocol::get_admin_type(), dtn::get_payload_str(), dtn::APIClient::handle_recv(), dtn::AnnounceBundle::parse_announce_bundle(), read_data(), and dtn::UDPConvergenceLayer::Sender::send_bundle().
const u_char* dtn::BundlePayload::read_data | ( | size_t | offset, | |
size_t | len, | |||
u_char * | buf, | |||
int | flags = 0 | |||
) | const [inline] |
Since read_data doesn't really change anything of substance in the payload class (just the internal bookkeeping fields), we define a "const" variant that just casts itself away and calls the normal variant.
Definition at line 198 of file BundlePayload.h.
References read_data().
void dtn::BundlePayload::serialize | ( | oasys::SerializeAction * | a | ) | [virtual] |
Virtual from SerializableObject.
Implements oasys::SerializableObject.
Definition at line 144 of file BundlePayload.cc.
References base_offset_, fname_, length_, oasys::SerializeAction::process(), and rcvd_length_.
void dtn::BundlePayload::internal_write | ( | const u_char * | bp, | |
size_t | offset, | |||
size_t | len | |||
) | [protected] |
Internal write helper function.
Definition at line 248 of file BundlePayload.cc.
References ASSERT, cur_offset_, data_, file_, oasys::Lock::is_locked_by_me(), oasys::FileIOClient::is_open(), length_, location_, lock_, oasys::FileIOClient::lseek(), MEMORY, NODATA, rcvd_length_, UNDETERMINED, and oasys::FdIOClient::writeall().
Referenced by append_data(), set_data(), and write_data().
std::string dtn::BundlePayload::payloaddir_ [static] |
directory to store payload files
Definition at line 213 of file BundlePayload.h.
Referenced by init(), dtn::DTNServer::init_datastore(), init_from_store(), and dtn::StorageCommand::StorageCommand().
size_t dtn::BundlePayload::mem_threshold_ [static] |
maximum bundle size to keep in memory
Definition at line 214 of file BundlePayload.h.
Referenced by dtn::ParamCommand::ParamCommand(), and set_length().
bool dtn::BundlePayload::test_no_remove_ [static] |
test: don't rm payload files
Definition at line 215 of file BundlePayload.h.
Referenced by dtn::ParamCommand::ParamCommand(), and ~BundlePayload().
location_t dtn::BundlePayload::location_ [protected] |
location of the data (disk or memory)
Definition at line 220 of file BundlePayload.h.
Referenced by init(), init_from_store(), internal_write(), location(), memory_data(), read_data(), set_length(), and truncate().
std::string dtn::BundlePayload::data_ [protected] |
the actual payload data if in memory
Definition at line 221 of file BundlePayload.h.
Referenced by internal_write(), memory_data(), read_data(), and truncate().
size_t dtn::BundlePayload::length_ [protected] |
the payload length
Definition at line 222 of file BundlePayload.h.
Referenced by append_data(), internal_write(), length(), read_data(), serialize(), set_length(), truncate(), and write_data().
size_t dtn::BundlePayload::rcvd_length_ [protected] |
the payload length we actually have
Definition at line 223 of file BundlePayload.h.
Referenced by append_data(), internal_write(), read_data(), serialize(), set_data(), and truncate().
std::string dtn::BundlePayload::fname_ [protected] |
oasys::FileIOClient* dtn::BundlePayload::file_ [protected] |
file handle if on disk
Definition at line 225 of file BundlePayload.h.
Referenced by append_data(), close_file(), copy_file(), init(), init_from_store(), internal_write(), is_file_open(), read_data(), reopen_file(), truncate(), write_data(), and ~BundlePayload().
size_t dtn::BundlePayload::cur_offset_ [protected] |
cache of current fd position
Definition at line 226 of file BundlePayload.h.
Referenced by append_data(), internal_write(), read_data(), reopen_file(), and truncate().
size_t dtn::BundlePayload::base_offset_ [protected] |
for fragments, offset into the file (todo)
Definition at line 227 of file BundlePayload.h.
Referenced by append_data(), serialize(), set_data(), and write_data().
oasys::SpinLock* dtn::BundlePayload::lock_ [protected] |
the lock for the given bundle
Definition at line 228 of file BundlePayload.h.
Referenced by append_data(), internal_write(), read_data(), set_data(), set_length(), truncate(), and write_data().