Skip to content

Commit

Permalink
cleanup and additional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
teschmitt committed Feb 27, 2024
1 parent e15e6b7 commit 230babd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
18 changes: 4 additions & 14 deletions core/dtn7/src/core/application_agent.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use bp7::{Bundle, EndpointID};
use enum_dispatch::enum_dispatch;
use log::{debug, error, trace};
use log::{debug, trace};
use std::collections::VecDeque;
use std::fmt::Debug;
use tokio::sync::mpsc::Sender;

use crate::dtnd::ws::BundleDelivery;
use crate::store_remove;
use crate::store_remove_if_singleton_bundle;
//use crate::dtnd::ws::WsAASession;

#[enum_dispatch]
Expand Down Expand Up @@ -47,7 +47,7 @@ impl ApplicationAgent for SimpleApplicationAgent {
if addr.try_send(BundleDelivery(bundle.clone())).is_err() {
self.bundles.push_back(bundle.clone());
} else {
remove_singleton_bundle_from_store(&bundle);
store_remove_if_singleton_bundle(bundle);
}
} else {
// save in temp buffer for delivery
Expand All @@ -57,7 +57,7 @@ impl ApplicationAgent for SimpleApplicationAgent {
fn pop(&mut self) -> Option<Bundle> {
let bundle = self.bundles.pop_front();
if let Some(bndl) = bundle.as_ref() {
remove_singleton_bundle_from_store(bndl);
store_remove_if_singleton_bundle(bndl);
};
bundle
}
Expand All @@ -84,13 +84,3 @@ impl SimpleApplicationAgent {
}
}
}

/// Removes a bundle from the store if its destination is a singleton endpoint
fn remove_singleton_bundle_from_store(bundle: &Bundle) {
if !bundle.primary.destination.is_non_singleton() {
debug!("Removing bundle with singleton destination from store");
if let Err(e) = store_remove(&bundle.id()) {
error!("Error while removing bundle from store: {:?}", e);
}
}
}
10 changes: 10 additions & 0 deletions core/dtn7/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,16 @@ pub fn store_remove(bid: &str) -> Result<()> {
Ok(())
}

/// Removes a bundle from the store if its destination is a singleton endpoint
fn store_remove_if_singleton_bundle(bundle: &Bundle) {
if !bundle.primary.destination.is_non_singleton() {
debug!("Removing bundle with singleton destination from store");
if let Err(e) = store_remove(&bundle.id()) {
error!("Error while removing bundle from store: {:?}", e);
}
}
}

pub fn store_update_metadata(bp: &BundlePack) -> Result<()> {
(*STORE.lock()).update_metadata(bp)
}
Expand Down
9 changes: 5 additions & 4 deletions tests/local_ping_echo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ $BINS/examples/dtnping -d 'dtn://node1/echo' -c 6 -t 500ms
RC=$?
echo "RET: $RC"

echo -n "Bundles in store on node 1: "
NUM_BUNDLES=$($BINS/dtnquery bundles | grep "dtn://" | wc -l | awk '{print $1}')
echo -n $NUM_BUNDLES
NUM_DELETED=$($BINS/dtnquery store | grep -o "Deleted" | wc -l | awk '{print $1}')

EXPECTED_BUNDLES=0
EXPECTED_DELETED=12

echo " / $EXPECTED_BUNDLES"
if [ "$NUM_BUNDLES" = "$EXPECTED_BUNDLES" ]; then
echo "Bundles in store on node 1: : $NUM_BUNDLES / $EXPECTED_BUNDLES"
echo "Bundles marked as Deleted in store on node 1: : $NUM_DELETED / $EXPECTED_DELETED"
if [ "$NUM_BUNDLES" = "$EXPECTED_BUNDLES" ] && [ "$NUM_DELETED" = "$EXPECTED_DELETED" ]; then
echo "Correct number of bundles in store!"
else
echo "Incorrect number of bundles in store!"
Expand Down

0 comments on commit 230babd

Please sign in to comment.