diff --git a/ccnl-ext-nfn.c b/ccnl-ext-nfn.c index bf6de774f845..d625e29a678a 100644 --- a/ccnl-ext-nfn.c +++ b/ccnl-ext-nfn.c @@ -38,7 +38,7 @@ ccnl_nfn_count_required_thunks(char *str) tok += 4; ++num; } - DEBUGMSG(99, "Number of required Thunks is: %d\n", num); + DEBUGMSG(99, "Number of required Thunks is: %d\n", num); return num; } @@ -65,6 +65,11 @@ ccnl_nfn_continue_computation(struct ccnl_relay_s *ccnl, int configid){ } } + + if(!config->start_request){ + //this is not the node to continue the computation + return; + } if(config->thunk && CCNL_NOW() > config->endtime){ DEBUGMSG(49, "NFN: Exit computation: timeout when resolving thunk\n"); DBL_LINKED_LIST_REMOVE(configuration_list, config); @@ -111,12 +116,17 @@ ccnl_nfn(struct ccnl_relay_s *ccnl, struct ccnl_buf_s *orig, struct ccnl_prefix_s *original_prefix; ccnl_nfn_copy_prefix(prefix, &original_prefix); int thunk_request = 0; + int start_request = 0; int num_of_required_thunks = 0; if(!memcmp(prefix->comp[prefix->compcnt-2], "THUNK", 5)) { thunk_request = 1; } + else if(!memcmp(prefix->comp[prefix->compcnt-2], "USETHUNK", 8)){ + thunk_request = 1; + start_request = 1; + } char str[CCNL_MAX_PACKET_SIZE]; int i, len = 0; @@ -138,7 +148,7 @@ ccnl_nfn(struct ccnl_relay_s *ccnl, struct ccnl_buf_s *orig, ++numOfRunningComputations; restart: - res = Krivine_reduction(ccnl, str, thunk_request, + res = Krivine_reduction(ccnl, str, thunk_request, start_request, num_of_required_thunks, &config, original_prefix); //stores result if computed diff --git a/krivine-common.c b/krivine-common.c index fe262dfd08a7..0461625a4f3f 100644 --- a/krivine-common.c +++ b/krivine-common.c @@ -54,7 +54,7 @@ new_machine_state(int thunk_request, int num_of_required_thunks){ } struct configuration_s * -new_config(char *prog, struct environment_s *global_dict, int thunk_request, +new_config(char *prog, struct environment_s *global_dict, int thunk_request, int start_request, int num_of_required_thunks, struct ccnl_prefix_s *prefix, int configid){ struct configuration_s *ret = malloc(sizeof(struct configuration_s)); ret->prog = prog; @@ -64,6 +64,7 @@ new_config(char *prog, struct environment_s *global_dict, int thunk_request, ret->global_dict = global_dict; ret->fox_state = new_machine_state(thunk_request, num_of_required_thunks); ret->configid = configid; + ret->start_request = start_request; ret->prefix = prefix; ret->thunk = 0; ret->thunk_time = NFN_DEFAULT_WAITING_TIME; diff --git a/krivine-common.h b/krivine-common.h index b399f715ed28..eddf1e1ecdaf 100644 --- a/krivine-common.h +++ b/krivine-common.h @@ -56,6 +56,7 @@ struct fox_machine_state_s{ struct configuration_s{ int configid; + int start_request; char *prog; struct stack_s *result_stack; struct stack_s *argument_stack; diff --git a/krivine.c b/krivine.c index fb000070dfb7..082542d8d3f4 100644 --- a/krivine.c +++ b/krivine.c @@ -908,7 +908,7 @@ setup_global_environment(struct environment_s **env){ unsigned char * Krivine_reduction(struct ccnl_relay_s *ccnl, char *expression, int thunk_request, - int num_of_required_thunks, struct configuration_s **config, + int start_request, int num_of_required_thunks, struct configuration_s **config, struct ccnl_prefix_s *prefix){ DEBUGMSG(99, "Krivine_reduction()\n"); int steps = 0; @@ -923,12 +923,16 @@ Krivine_reduction(struct ccnl_relay_s *ccnl, char *expression, int thunk_request prog = malloc(len*sizeof(char)); sprintf(prog, "CLOSURE(halt);RESOLVENAME(%s)", expression); if(!*config){ - *config = new_config(prog, global_dict, thunk_request, + DEBUGMSG(99, "PREFIX %s", ccnl_prefix_to_path2(prefix)); + *config = new_config(prog, global_dict, thunk_request, start_request, num_of_required_thunks, prefix, configid); DBL_LINKED_LIST_ADD(configuration_list, *config); restart = 0; --configid; } + if(num_of_required_thunks == 0){ + ccnl_nfn_reply_thunk(ccnl, *config); + } DEBUGMSG(99, "Prog: %s\n", (*config)->prog); while ((*config)->prog && !halt && (*config)->prog != 1){