48 const std::string SimpleBundleStorage::TAG =
"SimpleBundleStorage";
51 :
BundleStorage(maxsize), _datastore(*this, workdir, buffer_limit), _metastore(this)
64 _pending_bundles.erase(hash);
85 _pending_bundles.erase(hash);
156 _metastore.
store(meta, bundle_size);
162 }
catch (
const std::exception&) {
224 }
catch (
const std::bad_cast&) { }
229 return "SimpleBundleStorage";
235 return _metastore.
empty();
247 return _metastore.
size();
263 size_t items_added = 0;
268 for (
MetaStorage::const_iterator iter = _metastore.begin(); (iter != _metastore.end()) && ((cb.limit() == 0) || (items_added < cb.limit())); ++iter)
275 if ( cb.shouldAdd(meta) )
305 pending_map::iterator it = _pending_bundles.find(hash);
307 if (_pending_bundles.end() != it)
322 }
catch (
const std::exception &ex) {
382 __store(ca_bundle, bundle_size);
385 __store(bundle, bundle_size);
433 std::auto_ptr<BundleContainer> bc(
new BundleContainer(bundle));
441 _pending_bundles[hash] = bundle;
449 _metastore.
store(meta, bundle_size);
453 _datastore.
store(hash, bc.get());
482 _datastore.remove(hash);
491 eventBundleRemoved(b);
494 SimpleBundleStorage::BundleContainer::BundleContainer(
const dtn::data::Bundle &b)
498 SimpleBundleStorage::BundleContainer::~BundleContainer()
501 std::string SimpleBundleStorage::BundleContainer::getId()
const
503 return createId(_bundle);
508 std::stringstream ss_hash, ss_raw;
511 int c = 0xff & ss_raw.get();
512 while (ss_raw.good())
514 ss_hash << std::hex << std::setw( 2 ) << std::setfill(
'0' ) << c;
515 c = 0xff & ss_raw.get();
518 return ss_hash.str();
521 std::ostream& SimpleBundleStorage::BundleContainer::serialize(std::ostream &stream)
530 s << _bundle; stream.flush();
535 std::stringstream ss; ss <<
"Output stream went bad [" << std::strerror(errno) <<
"]";
540 if (static_cast<std::streamoff>(size) > stream.tellp())
542 std::stringstream ss; ss <<
"Not all data were written [" << stream.tellp() <<
" of " << size <<
" bytes]";