33 #include <ibrcommon/data/BLOB.h>
40 #include <ibrcommon/Logger.h>
41 #include <ibrcommon/thread/RWLock.h>
42 #include <ibrcommon/thread/MutexLock.h>
54 #ifdef IBRDTN_SUPPORT_BSP
59 #ifdef IBRDTN_SUPPORT_COMPRESSION
63 using namespace dtn::data;
64 using namespace dtn::utils;
80 bool BundleCore::forwarding =
true;
88 BundleCore::BundleCore()
89 : _clock(1), _storage(NULL), _seeker(NULL), _router(NULL), _globally_connected(false)
97 BundleCore::~BundleCore()
128 ibrcommon::LinkManager::getInstance().removeEventListener(
this);
144 IBRCOMMON_LOGGER_TAG(BundleCore::TAG, info) <<
"Local node name: " << config.getNodename() << IBRCOMMON_LOGGER_ENDL;
176 if (transit_limit > 0)
183 if (config.getNetwork().doForwarding())
185 IBRCOMMON_LOGGER_TAG(BundleCore::TAG, info) <<
"Forwarding of bundles enabled." << IBRCOMMON_LOGGER_ENDL;
190 IBRCOMMON_LOGGER_TAG(BundleCore::TAG, info) <<
"Forwarding of bundles disabled." << IBRCOMMON_LOGGER_ENDL;
194 const std::set<ibrcommon::vinterface> &global_nets = config.getNetwork().getInternetDevices();
197 ibrcommon::LinkManager::getInstance().removeEventListener(
this);
200 for (std::set<ibrcommon::vinterface>::const_iterator iter = global_nets.begin(); iter != global_nets.end(); ++iter)
202 ibrcommon::LinkManager::getInstance().addEventListener(*iter,
this);
206 check_connection_state();
209 reload_filter_tables();
231 throw ibrcommon::Exception(
"router not set");
239 if (_storage == NULL)
241 throw ibrcommon::Exception(
"No bundle storage is set! Use BundleCore::setStorage() to set a storage.");
250 throw ibrcommon::Exception(
"No bundle seeker is set! Use BundleCore::setSeeker() to set a seeker.");
262 return _connectionmanager;
282 return _globally_connected;
299 bool delivered =
false;
310 custody.
read(payload);
312 getStorage().releaseCustody(bundle.
source, custody.bundleid);
314 IBRCOMMON_LOGGER_DEBUG_TAG(
"BundleCore", 5) <<
"custody released for " << bundle.
toString() << IBRCOMMON_LOGGER_ENDL;
356 IBRCOMMON_LOGGER_TAG(
"BundleCore", notice) <<
"singleton bundle delivered: " << meta.
toString() << IBRCOMMON_LOGGER_ENDL;
392 storage.
remove(purge.bundle);
400 IBRCOMMON_LOGGER_DEBUG_TAG(
"BundleCore", 35) <<
"bundle rejected: bundle has expired (" << obj.toString() <<
")" << IBRCOMMON_LOGGER_ENDL;
410 IBRCOMMON_LOGGER_DEBUG_TAG(
"BundleCore", 35) <<
"lifetime of bundle rejected: " << obj.toString() << IBRCOMMON_LOGGER_ENDL;
424 IBRCOMMON_LOGGER_TAG(
"BundleCore", warning) <<
"timestamp of bundle rejected: " << obj.toString() << IBRCOMMON_LOGGER_ENDL;
433 ibrcommon::MutexLock l(_filter_mutex);
443 IBRCOMMON_LOGGER_TAG(
"BundleCore", warning) <<
"bundle rejected: bundle has expired (" << p.toString() <<
")" << IBRCOMMON_LOGGER_ENDL;
453 IBRCOMMON_LOGGER_TAG(
"BundleCore", warning) <<
"non-local bundle rejected: " << p.toString() << IBRCOMMON_LOGGER_ENDL;
464 IBRCOMMON_LOGGER_TAG(
"BundleCore", warning) <<
"lifetime of bundle rejected: " << p.toString() << IBRCOMMON_LOGGER_ENDL;
478 IBRCOMMON_LOGGER_TAG(
"BundleCore", warning) <<
"timestamp of bundle rejected: " << p.toString() << IBRCOMMON_LOGGER_ENDL;
484 if (getRouter().isKnown(p))
493 ibrcommon::MutexLock l(_filter_mutex);
504 IBRCOMMON_LOGGER_TAG(
"BundleCore", warning) <<
"bundle rejected: block size of " << size.toString() <<
" is too big" << IBRCOMMON_LOGGER_ENDL;
512 ibrcommon::MutexLock l(_filter_mutex);
525 IBRCOMMON_LOGGER_TAG(
"BundleCore", warning) <<
"foreign bundle " << bundle.toString() <<
" rejected: block size of " << size.toString() <<
" is too big" << IBRCOMMON_LOGGER_ENDL;
538 IBRCOMMON_LOGGER_TAG(
"BundleCore", warning) <<
"bundle " << bundle.toString() <<
" rejected: block size of " << size.toString() <<
" is too big" << IBRCOMMON_LOGGER_ENDL;
548 ibrcommon::MutexLock l(_filter_mutex);
556 if (b.destination.isNone())
558 IBRCOMMON_LOGGER_TAG(
"BundleCore", warning) <<
"bundle rejected: the destination is null" << IBRCOMMON_LOGGER_ENDL;
565 IBRCOMMON_LOGGER_TAG(
"BundleCore", warning) <<
"bundle rejected: bundle has expired (" << b.toString() <<
")" << IBRCOMMON_LOGGER_ENDL;
586 }
catch (
const std::bad_cast&) { }
593 ibrcommon::MutexLock l(_filter_mutex);
600 ibrcommon::MutexLock l(_filter_mutex);
605 return _table_input.
filter(context, bundle);
608 return _table_output.
filter(context, bundle);
611 return _table_routing.
filter(context, bundle);
619 ibrcommon::MutexLock l(_filter_mutex);
624 return _table_input.
evaluate(context);
627 return _table_output.
evaluate(context);
630 return _table_routing.
evaluate(context);
656 #ifdef IBRDTN_SUPPORT_BSP
664 IBRCOMMON_LOGGER_TAG(
"BundleCore", warning) <<
"No key available for decryption of bundle." << IBRCOMMON_LOGGER_ENDL;
668 IBRCOMMON_LOGGER_TAG(
"BundleCore", warning) <<
"Decryption of bundle failed: " << ex.what() << IBRCOMMON_LOGGER_ENDL;
678 #ifdef IBRDTN_SUPPORT_COMPRESSION
684 }
catch (
const ibrcommon::Exception &ex) {
685 IBRCOMMON_LOGGER_TAG(
"BundleCore", warning) <<
"Decompression of bundle failed: " << ex.what() << IBRCOMMON_LOGGER_ENDL;
701 if (global_nets.find(evt.getInterface()) != global_nets.end()) {
702 check_connection_state();
714 #ifdef IBRDTN_SUPPORT_COMPRESSION
722 }
catch (
const ibrcommon::Exception &ex) {
723 IBRCOMMON_LOGGER_TAG(TAG, warning) <<
"compression of bundle failed: " << ex.what() << IBRCOMMON_LOGGER_ENDL;
728 #ifdef IBRDTN_SUPPORT_BSP
738 IBRCOMMON_LOGGER_TAG(TAG, warning) <<
"No key available for encrypt process." << IBRCOMMON_LOGGER_ENDL;
740 IBRCOMMON_LOGGER_TAG(TAG, warning) <<
"Encryption of bundle failed." << IBRCOMMON_LOGGER_ENDL;
753 IBRCOMMON_LOGGER_TAG(TAG, warning) <<
"No key available for sign process." << IBRCOMMON_LOGGER_ENDL;
766 std::list<dtn::data::Bundle> fragments;
771 for (std::list<dtn::data::Bundle>::iterator it = fragments.begin(); it != fragments.end(); ++it)
792 if (val == _globally_connected)
return;
800 _globally_connected = val;
803 void BundleCore::check_connection_state() throw ()
807 if (!global_nets.empty()) {
809 for (std::set<ibrcommon::vinterface>::const_iterator iter = global_nets.begin(); iter != global_nets.end(); ++iter)
811 const ibrcommon::vinterface &iface = (*iter);
812 if (!iface.getAddresses(ibrcommon::vaddress::SCOPE_GLOBAL).empty()) {
820 void BundleCore::reload_filter_tables() throw ()
822 ibrcommon::RWLock l(_filter_mutex);
824 _table_input.
clear();
825 _table_output.
clear();
826 _table_routing.
clear();
827 _table_validation.
clear();
838 (
new LogFilter(ibrcommon::LogLevel::warning,
"bundle rejected due to missing authentication"))->append(
844 (
new LogFilter(ibrcommon::LogLevel::warning,
"can not apply authentication due to missing key"))
852 (
new LogFilter(ibrcommon::LogLevel::warning,
"bundle rejected due to missing signature"))->append(
861 (
new LogFilter(ibrcommon::LogLevel::warning,
"bundle rejected due to missing encryption"))->append(
871 (
new LogFilter(ibrcommon::LogLevel::warning,
"bundle rejected due to invalid authentication"))->append(
877 (
new LogFilter(ibrcommon::LogLevel::warning,
"bundle rejected due to invalid signature"))->append(
static Configuration & getInstance(bool reset=false)
std::string toString() const
static void inject(const dtn::data::EID &source, dtn::data::Bundle &bundle)
virtual ACTION evaluate(const FilterContext &context) const
virtual const std::string getName() const
static dtn::data::Length foreign_blocksizelimit
static dtn::data::Length max_timestamp_future
void raiseEvent(const dtn::routing::QueueBundleEvent &evt)
static dtn::data::EID local
const Configuration::Security & getSecurity() const
static void add(EventReceiver< E > *receiver)
bool get(ProcFlags flag) const
static void split(const dtn::data::Bundle &bundle, const dtn::data::Length &maxPayloadLength, std::list< dtn::data::Bundle > &fragments)
virtual void read(const dtn::data::PayloadBlock &p)
bool sameHost(const std::string &other) const
virtual void componentDown()
dtn::routing::BaseRouter & getRouter() const
void setSeeker(dtn::storage::BundleSeeker *seeker)
void setGloballyConnected(bool val)
void setBundle(const dtn::data::Bundle &data)
static void extract(dtn::data::Bundle &b)
static void remove(const EventReceiver< E > *receiver)
void addRoute(const dtn::data::EID &destination, const dtn::data::EID &nexthop, const dtn::data::Timeout timeout=0)
static const dtn::data::block_t BLOCK_TYPE
void setRouter(dtn::routing::BaseRouter *router)
virtual void componentUp()
void sign(dtn::data::Bundle &bundle) const
dtn::net::ConnectionManager & getConnectionManager()
static void raiseEvent(CHANGE_TYPE type)
bool isGloballyConnected() const
dtn::net::DiscoveryAgent & getDiscoveryAgent()
BundleFilter::ACTION filter(BundleFilter::TABLE table, const FilterContext &context, dtn::data::Bundle &bundle) const
static dtn::data::Length blocksizelimit
BundleFilter::ACTION evaluate(BundleFilter::TABLE table, const FilterContext &context) const
dtn::storage::BundleSeeker & getSeeker()
const Configuration::Network & getNetwork() const
virtual void remove(const dtn::data::BundleID &id)=0
bool get(FLAGS flag) const
dtn::data::Size getLimit(const std::string &) const
void eventNotify(const ibrcommon::LinkEvent &evt)
virtual void validate(const dtn::data::PrimaryBlock &obj) const
static void compress(dtn::data::Bundle &b, COMPRESS_ALGS alg)
virtual void initialize()
void append(const dtn::data::EID &eid)
static dtn::data::Size max_bundles_in_transit
static void raise(const Action a)
block_list::const_iterator const_iterator
static SecurityManager & getInstance()
void setMetaBundle(const dtn::data::MetaBundle &data)
void append(BundleFilter *filter)
void setBlock(const dtn::data::Block &block, const dtn::data::Number &size)
static dtn::data::Timestamp getTime()
static const dtn::data::block_t BLOCK_TYPE
block_list::iterator iterator
void removeRoute(const dtn::data::EID &destination, const dtn::data::EID &nexthop)
void setStorage(dtn::storage::BundleStorage *storage)
void encrypt(dtn::data::Bundle &bundle) const
static void processBlocks(dtn::data::Bundle &b)
virtual void onConfigurationChanged(const dtn::daemon::Configuration &conf)
virtual ACTION filter(const FilterContext &context, dtn::data::Bundle &bundle) const
static double getRating()
iterator find(block_t blocktype)
static void raise(const dtn::data::MetaBundle &bundle, EventBundleAction action, dtn::data::StatusReportBlock::REASON_CODE reason=dtn::data::StatusReportBlock::NO_ADDITIONAL_INFORMATION)
static void raise(const dtn::data::MetaBundle &meta, REASON_CODE reason=DELIVERED)
dtn::storage::BundleStorage & getStorage()
const block_t & getType() const
static dtn::data::Length max_lifetime
static bool isExpired(const dtn::data::Timestamp ×tamp, const dtn::data::Number &lifetime)
void decrypt(dtn::data::Bundle &bundle) const
void set(FLAGS flag, bool value)
static void raise(const dtn::data::EID &peer, const dtn::data::Bundle &bundle, const bool local=false)
static BundleCore & getInstance()
void setPrimaryBlock(const dtn::data::PrimaryBlock &data)
std::set< ibrcommon::vinterface > getInternetDevices() const