Skip to content

Commit

Permalink
Check if agent id is available before forwarding it locally and persi…
Browse files Browse the repository at this point in the history
…st if not
  • Loading branch information
EpicKiwi committed Dec 14, 2024
1 parent 4127873 commit fa72ed8
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 5 deletions.
12 changes: 11 additions & 1 deletion components/ud3tn/agent_manager.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
// SPDX-License-Identifier: BSD-3-Clause OR Apache-2.0
#include "ud3tn/agent_manager.h"
#include "platform/posix/hal_types.h"
#include "ud3tn/bundle.h"
#include "ud3tn/eid.h"

#include "agents/config_agent.h"
#include "agents/application_agent.h"
#include "archipel-core/bundle_restore.h"

#include "platform/hal_io.h"

Expand All @@ -25,10 +27,12 @@ static struct agent_list **agent_search_ptr(struct agent_list **al_ptr,
static struct agent_list *agent_entry_node;
static struct agent_list *rpc_ag_entry_node;
static const char *local_eid;
static QueueIdentifier_t bundle_restore_queue;

void agent_manager_init(const char *const ud3tn_local_eid)
void agent_manager_init(const char *const ud3tn_local_eid, QueueIdentifier_t restore_queue)
{
local_eid = ud3tn_local_eid;
bundle_restore_queue = restore_queue;
}

int agent_register(struct agent agent, const bool is_subscriber)
Expand Down Expand Up @@ -78,6 +82,8 @@ int agent_register(struct agent agent, const bool is_subscriber)
agent.sink_identifier
);

bundle_restore_for_destination(bundle_restore_queue, local_eid);

return 0;
}

Expand Down Expand Up @@ -108,6 +114,10 @@ int agent_deregister(const char *sink_identifier, const bool is_subscriber)
return 0;
}

bool is_agent_available(const char *agent_id) {
return agent_search(&agent_entry_node, agent_id) != NULL;
}

int agent_forward(const char *sink_identifier, struct bundle_adu data,
const void *bp_context)
{
Expand Down
20 changes: 18 additions & 2 deletions components/ud3tn/bundle_processor.c
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,23 @@ static enum bundle_handling_result handle_unknown_block_flags(
static void bundle_deliver_local(
struct bp_context *const ctx, struct bundle *bundle)
{
const char* agent_id = get_agent_id(ctx, bundle->destination);

/* Check if there is an agent available to process this bundle */
if(!HAS_FLAG(bundle->proc_flags, BUNDLE_FLAG_ADMINISTRATIVE_RECORD) &&
!is_agent_available(agent_id)){

enum ud3tn_result result = hal_store_bundle(ctx->store, bundle);
if(result != UD3TN_OK) {
LOGF_ERROR("BundleProcessor: Failed to persist bundle %p, dropping.", bundle);
} else {
LOGF_INFO("BundleProcessor: Persisted bundle %p for later dispatch", bundle);
bundle_free(bundle);
return;
}

}

bundle_rem_rc(bundle, BUNDLE_RET_CONSTRAINT_DISPATCH_PENDING, 0);

/* Check and record knowledge of bundle */
Expand All @@ -740,8 +757,7 @@ static void bundle_deliver_local(
);
}

if (!HAS_FLAG(bundle->proc_flags, BUNDLE_FLAG_ADMINISTRATIVE_RECORD) &&
get_agent_id(ctx, bundle->destination) == NULL) {
if (!HAS_FLAG(bundle->proc_flags, BUNDLE_FLAG_ADMINISTRATIVE_RECORD) && agent_id == NULL) {
// If it is no admin. record and we have no agent to deliver
// it to, drop it.
LOGF_INFO(
Expand Down
5 changes: 4 additions & 1 deletion components/ud3tn/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,10 @@ void start_tasks(const struct ud3tn_cmdline_options *const opt)

// NOTE: Must be called before launching the BP which calls the function
// to register agents from its thread.
agent_manager_init(bundle_agent_interface.local_eid);
agent_manager_init(
bundle_agent_interface.local_eid,
bundle_restore_task_config->restore_queue
);

const enum ud3tn_result bp_task_result = hal_task_create(
bundle_processor_task,
Expand Down
10 changes: 9 additions & 1 deletion include/ud3tn/agent_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#define AGENT_MANAGER_H_INCLUDED

#include "ud3tn/bundle.h"
#include "platform/hal_types.h"

#include <stddef.h>
#include <stdint.h>
Expand All @@ -25,7 +26,7 @@ struct agent_list {
*
* @not_thread_safe
*/
void agent_manager_init(const char *const ud3tn_local_eid);
void agent_manager_init(const char *const ud3tn_local_eid, QueueIdentifier_t restore_queue);

/**
* @brief agent_forward Invoke the callback associated with the specified
Expand Down Expand Up @@ -63,4 +64,11 @@ int agent_register(struct agent agent, bool is_subscriber);
*/
int agent_deregister(const char *sink_identifier, bool is_subscriber);

/**
* @brief Check if named agent is currently registered
* @param agent_id identifier of agent to check presence
* @return true if agent is registered, false if not
*/
bool is_agent_available(const char *agent_id);

#endif /* AGENT_MANAGER_H_INCLUDED */

0 comments on commit fa72ed8

Please sign in to comment.