dtn::BundlePayload Class Reference

#include <BundlePayload.h>

Inheritance diagram for dtn::BundlePayload:

oasys::SerializableObject oasys::Logger

List of all members.


Detailed Description

The representation of a bundle payload.

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 40 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 { FORCE_COPY = 0x2 }
 Valid flags to read_data. More...

Public Member Functions

 BundlePayload (oasys::SpinLock *lock)
virtual ~BundlePayload ()
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.
void set_data (const std::string &data)
 Set the payload data and length.
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 copy_file (oasys::FileIOClient *dst)
 Copy (or link) the payload to the given file client object.
bool replace_with_file (const char *path)
 Replace the underlying file with a hard link to the given path or a copy of the file contents if the link can't be created.
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 size_t mem_threshold_ = 16384
 maximum bundle size to keep in memory
static bool test_no_remove_ = false
 test: don't rm payload files

Protected Member Functions

void pin_file ()
void unpin_file ()
void internal_write (const u_char *bp, size_t offset, size_t len)

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
oasys::FileIOClient file_
 file handle
size_t cur_offset_
 cache of current fd position
size_t base_offset_
 for fragments, offset into the file (todo)
oasys::SpinLocklock_
 the lock for the given bundle

Member Enumeration Documentation

enum dtn::BundlePayload::location_t

Options for payload location state.

Enumerator:
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 48 of file BundlePayload.h.

enum dtn::BundlePayload::read_data_flags_t

Valid flags to read_data.

Enumerator:
FORCE_COPY  Always copy payload, even for in-memory bundles.

Definition at line 141 of file BundlePayload.h.


Constructor & Destructor Documentation

dtn::BundlePayload::BundlePayload ( oasys::SpinLock lock  ) 

Definition at line 36 of file BundlePayload.cc.

dtn::BundlePayload::~BundlePayload (  )  [virtual]

Definition at line 115 of file BundlePayload.cc.

References file_, oasys::FileIOClient::is_open(), location_, NODATA, oasys::FileIOClient::path(), oasys::FdIOClient::set_fd(), test_no_remove_, and oasys::FileIOClient::unlink().


Member Function Documentation

void dtn::BundlePayload::init ( int  bundleid,
location_t  location = UNDETERMINED 
)

Actual payload initialization function.

Definition at line 45 of file BundlePayload.cc.

References errno, oasys::FdIOClient::fd(), fd, file_, location_, log_crit, log_err, oasys::Logger::logpath_, oasys::Logger::logpathf(), NODATA, oasys::FileIOClient::open(), oasys::FileIOClient::path(), dtn::BundleStore::payload_dir(), dtn::BundleStore::payload_fdcache(), and unpin_file().

Referenced by dtn::Bundle::Bundle().

void dtn::BundlePayload::init_from_store ( int  bundleid  ) 

Initialization when re-reading the database.

Definition at line 90 of file BundlePayload.cc.

References DISK, errno, oasys::FdIOClient::fd(), fd, file_, location_, log_crit, oasys::Logger::logpath_, oasys::Logger::logpathf(), oasys::FileIOClient::open(), oasys::FileIOClient::path(), dtn::BundleStore::payload_dir(), dtn::BundleStore::payload_fdcache(), and unpin_file().

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 137 of file BundlePayload.cc.

References ASSERT, DISK, ExamineDump::l, length_, location_, lock_, mem_threshold_, MEMORY, and UNDETERMINED.

Referenced by dtn::PayloadBlockProcessor::consume(), dtn::FragmentManager::create_fragment(), dtn::BundleCommand::exec(), dtnsim::TrAgent::send_bundle(), dtnsim::SimConvergenceLayer::send_bundle(), and set_data().

void dtn::BundlePayload::truncate ( size_t  len  ) 

Truncate the payload.

Used for reactive fragmentation.

Definition at line 190 of file BundlePayload.cc.

References ASSERT, cur_offset_, data_, file_, ExamineDump::l, length_, location_, lock_, MEMORY, pin_file(), rcvd_length_, oasys::FileIOClient::truncate(), and unpin_file().

Referenced by dtn::FragmentManager::try_to_convert_to_fragment().

size_t dtn::BundlePayload::length (  )  const [inline]

The payload length.

Definition at line 80 of file BundlePayload.h.

References length_.

Referenced by dtn::BundleRouter::accept_bundle(), dtn::FragmentManager::check_completed(), dtn::PayloadBlockProcessor::consume(), copy_file(), dtn::FragmentManager::create_fragment(), dtn::FragmentManager::delete_fragment(), dtnsim::SimRegistration::deliver_bundle(), dtn::PingRegistration::deliver_bundle(), dtn::LoggingRegistration::deliver_bundle(), dtn::LinkStateRouter::LSRegistration::deliver_bundle(), dtn::AdminRegistration::deliver_bundle(), dtn::ProphetTLV::deserialize(), dtn::Bundle::durable_size(), dtn::BundleCommand::exec(), dtn::BundleDaemon::find_duplicate(), dtn::Bundle::format(), dtn::Bundle::format_verbose(), dtn::PayloadBlockProcessor::generate(), dtn::get_payload_str(), dtn::BundleDaemon::handle_bundle_delivered(), dtn::APIClient::handle_recv(), dtn::BundleSz::operator()(), dtn::AnnounceBundle::parse_announce_bundle(), dtn::BundleStatusReport::parse_status_report(), dtn::FragmentManager::proactively_fragment(), dtn::UDPConvergenceLayer::Receiver::process_data(), dtn::FragmentManager::process_for_reassembly(), dtn::PayloadBlockProcessor::produce(), dtnsim::SimConvergenceLayer::send_bundle(), dtn::FileConvergenceLayer::send_bundle(), dtn::FragmentManager::try_to_convert_to_fragment(), dtn::FragmentManager::try_to_reactively_fragment(), and write_data().

location_t dtn::BundlePayload::location (  )  const [inline]

The payload location.

Definition at line 85 of file BundlePayload.h.

References location_.

Referenced by dtn::PayloadBlockProcessor::consume(), dtn::APIClient::handle_recv(), and dtnsim::SimConvergenceLayer::send_bundle().

void dtn::BundlePayload::set_data ( const u_char *  bp,
size_t  len 
)

Set the payload data and length.

Definition at line 318 of file BundlePayload.cc.

References ASSERT, base_offset_, internal_write(), ExamineDump::l, lock_, pin_file(), rcvd_length_, set_length(), and unpin_file().

Referenced by dtn::AnnounceBundle::create_announce_bundle(), dtn::ProphetTLV::create_bundle(), dtn::CustodySignal::create_custody_signal(), dtn::BundleStatusReport::create_status_report(), dtn::BundleCommand::exec(), dtn::BundleDaemon::handle_bundle_inject(), dtn::LinkStateRouter::send_announcement(), and set_data().

void dtn::BundlePayload::set_data ( const std::string &  data  )  [inline]

Set the payload data and length.

Definition at line 95 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.

Definition at line 332 of file BundlePayload.cc.

References ASSERT, base_offset_, cur_offset_, file_, internal_write(), ExamineDump::l, length_, lock_, oasys::FileIOClient::lseek(), pin_file(), rcvd_length_, and unpin_file().

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.

Definition at line 351 of file BundlePayload.cc.

References ASSERT, base_offset_, internal_write(), ExamineDump::l, length_, lock_, pin_file(), and unpin_file().

Referenced by dtn::PayloadBlockProcessor::consume(), 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.

Definition at line 363 of file BundlePayload.cc.

References ASSERT, file_, internal_write(), ExamineDump::l, length(), length_, lock_, log_debug, oasys::FileIOClient::path(), pin_file(), read_data(), and unpin_file().

void dtn::BundlePayload::copy_file ( oasys::FileIOClient dst  ) 

Copy (or link) the payload to the given file client object.

Definition at line 212 of file BundlePayload.cc.

References oasys::FileIOClient::copy_contents(), file_, length(), oasys::FileIOClient::lseek(), pin_file(), and unpin_file().

Referenced by dtn::APIClient::handle_recv().

bool dtn::BundlePayload::replace_with_file ( const char *  path  ) 

Replace the underlying file with a hard link to the given path or a copy of the file contents if the link can't be created.

Definition at line 222 of file BundlePayload.cc.

References oasys::FileIOClient::close(), oasys::FileIOClient::copy_contents(), errno, fd, file_, log_debug, log_err, oasys::FileIOClient::open(), oasys::FileIOClient::path(), pin_file(), oasys::FileIOClient::set_path(), src, oasys::FileIOClient::unlink(), and unpin_file().

const u_char* dtn::BundlePayload::memory_data (  )  [inline]

Get a pointer to the in-memory data buffer.

Definition at line 132 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 391 of file BundlePayload.cc.

References ASSERT, cur_offset_, data_, file_, FORCE_COPY, ExamineDump::l, length_, location_, lock_, oasys::FileIOClient::lseek(), MEMORY, pin_file(), rcvd_length_, oasys::FdIOClient::readall(), and unpin_file().

Referenced by dtn::LoggingRegistration::deliver_bundle(), dtn::LinkStateRouter::LSRegistration::deliver_bundle(), dtn::AdminRegistration::deliver_bundle(), dtn::ProphetTLV::deserialize(), dtn::BundleProtocol::get_admin_type(), dtn::get_payload_str(), dtn::APIClient::handle_recv(), dtn::AnnounceBundle::parse_announce_bundle(), dtn::BundleStatusReport::parse_status_report(), dtn::PayloadBlockProcessor::produce(), read_data(), and write_data().

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 163 of file BundlePayload.h.

References read_data().

void dtn::BundlePayload::serialize ( oasys::SerializeAction a  )  [virtual]

Virtual from SerializableObject.

Implements oasys::SerializableObject.

Definition at line 128 of file BundlePayload.cc.

References base_offset_, length_, oasys::SerializeAction::process(), and rcvd_length_.

void dtn::BundlePayload::pin_file (  )  [protected]

Definition at line 157 of file BundlePayload.cc.

References ASSERT, cur_offset_, errno, oasys::FdIOClient::fd(), fd, file_, log_err, oasys::FileIOClient::path(), dtn::BundleStore::payload_fdcache(), and oasys::FileIOClient::reopen().

Referenced by append_data(), copy_file(), read_data(), replace_with_file(), set_data(), truncate(), and write_data().

void dtn::BundlePayload::unpin_file (  )  [protected]

Definition at line 183 of file BundlePayload.cc.

References file_, and oasys::FileIOClient::path().

Referenced by append_data(), copy_file(), init(), init_from_store(), read_data(), replace_with_file(), set_data(), truncate(), and write_data().

void dtn::BundlePayload::internal_write ( const u_char *  bp,
size_t  offset,
size_t  len 
) [protected]

Definition at line 262 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().


Member Data Documentation

size_t dtn::BundlePayload::mem_threshold_ = 16384 [static]

maximum bundle size to keep in memory

Definition at line 179 of file BundlePayload.h.

Referenced by dtn::ParamCommand::ParamCommand(), and set_length().

bool dtn::BundlePayload::test_no_remove_ = false [static]

test: don't rm payload files

Definition at line 180 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 187 of file BundlePayload.h.

Referenced by init(), init_from_store(), internal_write(), location(), memory_data(), read_data(), set_length(), truncate(), and ~BundlePayload().

std::string dtn::BundlePayload::data_ [protected]

the actual payload data if in memory

Definition at line 188 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 189 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 190 of file BundlePayload.h.

Referenced by append_data(), internal_write(), read_data(), serialize(), set_data(), and truncate().

oasys::FileIOClient dtn::BundlePayload::file_ [protected]

file handle

Definition at line 191 of file BundlePayload.h.

Referenced by append_data(), copy_file(), init(), init_from_store(), internal_write(), pin_file(), read_data(), replace_with_file(), truncate(), unpin_file(), write_data(), and ~BundlePayload().

size_t dtn::BundlePayload::cur_offset_ [protected]

cache of current fd position

Definition at line 192 of file BundlePayload.h.

Referenced by append_data(), internal_write(), pin_file(), read_data(), and truncate().

size_t dtn::BundlePayload::base_offset_ [protected]

for fragments, offset into the file (todo)

Definition at line 193 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 194 of file BundlePayload.h.

Referenced by append_data(), internal_write(), read_data(), set_data(), set_length(), truncate(), and write_data().


The documentation for this class was generated from the following files:
Generated on Sat Sep 8 08:43:44 2007 for DTN Reference Implementation by  doxygen 1.5.3