Skip to content

Commit

Permalink
Merge pull request #144 from morgenroth/fixes/1.0.x
Browse files Browse the repository at this point in the history
A bunch of cherry-picked fixes
  • Loading branch information
morgenroth committed Feb 23, 2015
2 parents e63bc34 + f2b277d commit 9caef80
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 42 deletions.
7 changes: 5 additions & 2 deletions ibrcommon/ibrcommon/data/BloomFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,13 +291,16 @@ namespace ibrcommon

void BloomFilter::load(const cell_type* data, size_t len)
{
if (len < table_size_)
if (len == (table_size_ / bits_per_char))
{
std::copy(data, data + len, bit_table_);
}
else
{
std::copy(data, data + table_size_, bit_table_);
table_size_ = len * bits_per_char;
delete[] bit_table_;
bit_table_ = new cell_type[len];
std::copy(data, data + len, bit_table_);
}

_itemcount = 0;
Expand Down
16 changes: 4 additions & 12 deletions ibrcommon/tests/unittests/BloomFilterTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,23 +118,15 @@ void BloomFilterTest::testLoad()
ibrcommon::BloomFilter Filter(8196,2);
const ibrcommon::cell_type* cad1;
const ibrcommon::cell_type* cad2;
cad1 = (const ibrcommon::cell_type*)"Hello World";
Filter.load(cad1, sizeof(cad1));
cad1 = (const ibrcommon::cell_type*)"Hello World\0";
Filter.load(cad1, 12);
cad2 = Filter.table();
int i = 0;
bool dif;
while (cad1[i] != 0 && cad2[i] != 0)
{
if (cad1[i] == cad2[i])
{
dif = true ;
}
else
{
dif= false;
}
i++;
CPPUNIT_ASSERT_EQUAL(true,dif);
i++;
CPPUNIT_ASSERT_EQUAL(cad1[i], cad2[i]);
}
}

Expand Down
3 changes: 2 additions & 1 deletion ibrdtn/daemon/debian/ibrdtnd.logrotate
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
compress
delaycompress
notifempty
create 640 dtnd adm
su dtnd daemon
create 640 dtnd daemon
sharedscripts
postrotate
/etc/init.d/ibrdtnd reload > /dev/null
Expand Down
60 changes: 33 additions & 27 deletions ibrdtn/daemon/src/routing/prophet/ProphetRoutingExtension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -617,42 +617,48 @@ namespace dtn

void ProphetRoutingExtension::updateNeighbor(const dtn::data::EID &neighbor, const DeliveryPredictabilityMap& neighbor_dp_map)
{
// update the encounter on every routing handshake
ibrcommon::MutexLock l(_deliveryPredictabilityMap);
bool shouldPush = false;

// remember the size of the map before it is altered
const size_t numOfItems = _deliveryPredictabilityMap.size();
{
// update the encounter on every routing handshake
ibrcommon::MutexLock l(_deliveryPredictabilityMap);

// age the local predictability map
age();
// remember the size of the map before it is altered
const size_t numOfItems = _deliveryPredictabilityMap.size();

/**
* Calculate new value for this encounter
*/
try {
float neighbor_dp = _deliveryPredictabilityMap.get(neighbor);
// age the local predictability map
age();

if (neighbor_dp < _p_first_threshold)
{
neighbor_dp = _p_encounter_first;
}
else
{
neighbor_dp += (1 - _delta - neighbor_dp) * p_encounter(neighbor);
/**
* Calculate new value for this encounter
*/
try {
float neighbor_dp = _deliveryPredictabilityMap.get(neighbor);

if (neighbor_dp < _p_first_threshold)
{
neighbor_dp = _p_encounter_first;
}
else
{
neighbor_dp += (1 - _delta - neighbor_dp) * p_encounter(neighbor);
}

_deliveryPredictabilityMap.set(neighbor, neighbor_dp);
} catch (const DeliveryPredictabilityMap::ValueNotFoundException&) {
_deliveryPredictabilityMap.set(neighbor, _p_encounter_first);
}

_deliveryPredictabilityMap.set(neighbor, neighbor_dp);
} catch (const DeliveryPredictabilityMap::ValueNotFoundException&) {
_deliveryPredictabilityMap.set(neighbor, _p_encounter_first);
}
_ageMap[neighbor] = dtn::utils::Clock::getMonotonicTimestamp();

_ageMap[neighbor] = dtn::utils::Clock::getMonotonicTimestamp();
/* update the dp_map */
_deliveryPredictabilityMap.update(neighbor, neighbor_dp_map, _p_encounter_first);

/* update the dp_map */
_deliveryPredictabilityMap.update(neighbor, neighbor_dp_map, _p_encounter_first);
// if the number of items has been increased by additional neighbors
shouldPush = numOfItems < _deliveryPredictabilityMap.size();
}

// if the number of items has been increased by additional neighbors
if (numOfItems < _deliveryPredictabilityMap.size())
if (shouldPush)
{
// then push a notification to all neighbors
(**this).pushHandshakeUpdated(NodeHandshakeItem::DELIVERY_PREDICTABILITY_MAP);
Expand Down
19 changes: 19 additions & 0 deletions ibrdtn/daemon/tests/unittests/BundleSetTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,25 @@ void BundleSetTest::persistanceTest()
CPPUNIT_ASSERT_EQUAL(num_bundles,size_after);
}

void BundleSetTest::sizeTest()
{
BundleSet src(NULL, 12000);
genbundles(src,100,10,15);

BundleSet dst;
genbundles(dst,100,10,15);

CPPUNIT_ASSERT(src.getBloomFilter().size() != dst.getBloomFilter().size());

std::stringstream ss;
ss << src;
ss.clear();

ss >> dst;

CPPUNIT_ASSERT_EQUAL(src.getBloomFilter().size(), dst.getBloomFilter().size());
}

void BundleSetTest::genbundles(dtn::data::BundleSet &l, int number, int offset, int max)
{
int range = max - offset;
Expand Down
2 changes: 2 additions & 0 deletions ibrdtn/daemon/tests/unittests/BundleSetTest.hh
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class BundleSetTest : public CppUnit::TestFixture {
void namingTest();
void performanceTest();
void persistanceTest();
void sizeTest();

void setUp();
void tearDown();
Expand All @@ -84,6 +85,7 @@ class BundleSetTest : public CppUnit::TestFixture {
CPPUNIT_TEST_ALL_STORAGES(namingTest);
CPPUNIT_TEST_ALL_STORAGES(performanceTest);
CPPUNIT_TEST_ALL_STORAGES(persistanceTest);
CPPUNIT_TEST_ALL_STORAGES(sizeTest);
CPPUNIT_TEST_SUITE_END();

static size_t testCounter;
Expand Down

0 comments on commit 9caef80

Please sign in to comment.