aboutsummaryrefslogtreecommitdiff
path: root/src/regex
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2013-02-12 15:01:21 +0000
committerBart Polot <bart@net.in.tum.de>2013-02-12 15:01:21 +0000
commit458349a5fedd8cd8efece9756ddf9eecbaf60501 (patch)
treedf787f201a5ead67ed7eab47af68d45de3aec197 /src/regex
parenta0e7a98ec923164fb1e47d6a8302b0a2bdb41133 (diff)
downloadgnunet-458349a5fedd8cd8efece9756ddf9eecbaf60501.tar.gz
gnunet-458349a5fedd8cd8efece9756ddf9eecbaf60501.zip
- start the announcing daemon AFTER the testbed connect phase
Diffstat (limited to 'src/regex')
-rw-r--r--src/regex/Makefile.am2
-rw-r--r--src/regex/gnunet-regex-profiler.c266
2 files changed, 249 insertions, 19 deletions
diff --git a/src/regex/Makefile.am b/src/regex/Makefile.am
index 1203897ba..e526b9977 100644
--- a/src/regex/Makefile.am
+++ b/src/regex/Makefile.am
@@ -98,11 +98,13 @@ gnunet_regex_profiler_SOURCES = \
98 gnunet-regex-profiler.c 98 gnunet-regex-profiler.c
99gnunet_regex_profiler_LDADD = \ 99gnunet_regex_profiler_LDADD = \
100 $(top_builddir)/src/util/libgnunetutil.la \ 100 $(top_builddir)/src/util/libgnunetutil.la \
101 $(top_builddir)/src/arm/libgnunetarm.la \
101 $(top_builddir)/src/dht/libgnunetdht.la \ 102 $(top_builddir)/src/dht/libgnunetdht.la \
102 $(top_builddir)/src/testbed/libgnunettestbed.la \ 103 $(top_builddir)/src/testbed/libgnunettestbed.la \
103 $(top_builddir)/src/regex/libgnunetregex.la \ 104 $(top_builddir)/src/regex/libgnunetregex.la \
104 $(top_builddir)/src/statistics/libgnunetstatistics.la 105 $(top_builddir)/src/statistics/libgnunetstatistics.la
105gnunet_regex_profiler_DEPENDENCIES = \ 106gnunet_regex_profiler_DEPENDENCIES = \
107 $(top_builddir)/src/arm/libgnunetarm.la \
106 $(top_builddir)/src/dht/libgnunetdht.la \ 108 $(top_builddir)/src/dht/libgnunetdht.la \
107 libgnunetregex.la 109 libgnunetregex.la
108 110
diff --git a/src/regex/gnunet-regex-profiler.c b/src/regex/gnunet-regex-profiler.c
index 658037c91..14f9933cb 100644
--- a/src/regex/gnunet-regex-profiler.c
+++ b/src/regex/gnunet-regex-profiler.c
@@ -32,6 +32,7 @@
32#include "gnunet_applications.h" 32#include "gnunet_applications.h"
33#include "gnunet_util_lib.h" 33#include "gnunet_util_lib.h"
34#include "gnunet_regex_lib.h" 34#include "gnunet_regex_lib.h"
35#include "gnunet_arm_service.h"
35#include "gnunet_dht_service.h" 36#include "gnunet_dht_service.h"
36#include "gnunet_testbed_service.h" 37#include "gnunet_testbed_service.h"
37 38
@@ -149,7 +150,12 @@ struct RegexPeer
149 int search_str_matched; 150 int search_str_matched;
150 151
151 /** 152 /**
152 * Peer's dht handle. 153 * Peer's ARM handle.
154 */
155 struct GNUNET_ARM_Handle *arm_handle;
156
157 /**
158 * Peer's DHT handle.
153 */ 159 */
154 struct GNUNET_DHT_Handle *dht_handle; 160 struct GNUNET_DHT_Handle *dht_handle;
155 161
@@ -159,9 +165,9 @@ struct RegexPeer
159 struct GNUNET_REGEX_search_handle *search_handle; 165 struct GNUNET_REGEX_search_handle *search_handle;
160 166
161 /** 167 /**
162 * Testbed operation handle for the dht service. 168 * Testbed operation handle for the ARM and DHT services.
163 */ 169 */
164 struct GNUNET_TESTBED_Operation *dht_op_handle; 170 struct GNUNET_TESTBED_Operation *op_handle;
165 171
166 /** 172 /**
167 * Peers's statistics handle. 173 * Peers's statistics handle.
@@ -519,8 +525,8 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
519 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Unable to write to file!\n"); 525 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Unable to write to file!\n");
520 } 526 }
521 527
522 if (NULL != peers[peer_cnt].dht_op_handle) 528 if (NULL != peers[peer_cnt].op_handle)
523 GNUNET_TESTBED_operation_done (peers[peer_cnt].dht_op_handle); 529 GNUNET_TESTBED_operation_done (peers[peer_cnt].op_handle);
524 if (NULL != peers[peer_cnt].stats_op_handle) 530 if (NULL != peers[peer_cnt].stats_op_handle)
525 GNUNET_TESTBED_operation_done (peers[peer_cnt].stats_op_handle); 531 GNUNET_TESTBED_operation_done (peers[peer_cnt].stats_op_handle);
526 } 532 }
@@ -862,8 +868,8 @@ regex_found_handler (void *cls,
862 } 868 }
863 } 869 }
864 870
865 GNUNET_TESTBED_operation_done (peer->dht_op_handle); 871 GNUNET_TESTBED_operation_done (peer->op_handle);
866 peer->dht_op_handle = NULL; 872 peer->op_handle = NULL;
867 873
868 if (peers_found == num_search_strings) 874 if (peers_found == num_search_strings)
869 { 875 {
@@ -932,7 +938,7 @@ do_connect_by_string (void *cls,
932 938
933 /* First connect to mesh service, then search for string. Next 939 /* First connect to mesh service, then search for string. Next
934 connect will be in mesh_connect_cb */ 940 connect will be in mesh_connect_cb */
935 peers[0].dht_op_handle = 941 peers[0].op_handle =
936 GNUNET_TESTBED_service_connect (NULL, 942 GNUNET_TESTBED_service_connect (NULL,
937 peers[0].peer_handle, 943 peers[0].peer_handle,
938 "dht", 944 "dht",
@@ -968,7 +974,7 @@ find_next_string (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
968 * dont connect to a new dht for each peer, we might want to seach for n 974 * dont connect to a new dht for each peer, we might want to seach for n
969 * strings on m peers where n > m 975 * strings on m peers where n > m
970 */ 976 */
971 peers[next_p].dht_op_handle = 977 peers[next_p].op_handle =
972 GNUNET_TESTBED_service_connect (NULL, 978 GNUNET_TESTBED_service_connect (NULL,
973 peers[next_p].peer_handle, 979 peers[next_p].peer_handle,
974 "dht", 980 "dht",
@@ -979,6 +985,232 @@ find_next_string (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
979 &peers[next_p]); 985 &peers[next_p]);
980} 986}
981 987
988
989/**
990 * ARM connect adapter. Opens a connection to the ARM service.
991 *
992 * @param cls Closure (peer).
993 * @param cfg Configuration handle.
994 *
995 * @return
996 */
997static void *
998arm_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
999{
1000 struct RegexPeer *peer = cls;
1001
1002 peer->arm_handle = GNUNET_ARM_connect (cfg, NULL);
1003
1004 return peer->arm_handle;
1005}
1006
1007
1008/**
1009 * Adapter function called to destroy a connection to the ARM service.
1010 *
1011 * @param cls Closure (peer).
1012 * @param op_result Service handle returned from the connect adapter.
1013 */
1014static void
1015arm_da (void *cls, void *op_result)
1016{
1017 struct RegexPeer *peer = (struct RegexPeer *) cls;
1018
1019 GNUNET_assert (peer->arm_handle == op_result);
1020
1021 if (NULL != peer->arm_handle)
1022 {
1023 GNUNET_ARM_disconnect (peer->arm_handle);
1024 peer->arm_handle = NULL;
1025 }
1026}
1027
1028
1029/**
1030 * Start announcing the next regex in the DHT.
1031 *
1032 * @param cls Index of the next peer in the peers array.
1033 * @param tc TaskContext.
1034 */
1035void
1036announce_next_regex (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
1037
1038
1039/**
1040 * Callback function invoked when ARM peration is complete: deamon is started.
1041 *
1042 * @param cls Closure (RegexPeer).
1043 * @param result Outcome of the operation.
1044 */
1045static void
1046arm_start_cb (void *cls, enum GNUNET_ARM_ProcessStatus result)
1047{
1048 struct RegexPeer *peer = (struct RegexPeer *) cls;
1049 static unsigned int peer_cnt;
1050 unsigned int next_p;
1051
1052 switch (result)
1053 {
1054 /**
1055 * Service is currently being started (due to client request).
1056 */
1057 case GNUNET_ARM_PROCESS_STARTING:
1058 GNUNET_TESTBED_operation_done (peer->op_handle);
1059 peer->op_handle = NULL;
1060
1061 if (peer_cnt < (num_peers - 1))
1062 {
1063 next_p = (++peer_cnt % num_peers);
1064 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
1065 &announce_next_regex,
1066 (void *) (long) next_p);
1067 }
1068 else
1069 {
1070 printf ("All daemons started. Waiting %s to start string searches\n",
1071 GNUNET_STRINGS_relative_time_to_string (search_delay,
1072 GNUNET_NO));
1073 fflush (stdout);
1074 GNUNET_SCHEDULER_add_delayed (search_delay,
1075 do_connect_by_string,
1076 NULL);
1077 }
1078 break;
1079
1080 /**
1081 * Service name is unknown to ARM.
1082 */
1083 case GNUNET_ARM_PROCESS_UNKNOWN:
1084 /**
1085 * Service is now down (due to client request).
1086 */
1087 case GNUNET_ARM_PROCESS_DOWN:
1088 /**
1089 * Service is already running.
1090 */
1091 case GNUNET_ARM_PROCESS_ALREADY_RUNNING:
1092 /**
1093 * Service is already being stopped by some other client.
1094 */
1095 case GNUNET_ARM_PROCESS_ALREADY_STOPPING:
1096 /**
1097 * Service is already down (no action taken)
1098 */
1099 case GNUNET_ARM_PROCESS_ALREADY_DOWN:
1100 /**
1101 * ARM is currently being shut down (no more process starts)
1102 */
1103 case GNUNET_ARM_PROCESS_SHUTDOWN:
1104 /**
1105 * Error in communication with ARM
1106 */
1107 case GNUNET_ARM_PROCESS_COMMUNICATION_ERROR:
1108 /**
1109 * Timeout in communication with ARM
1110 */
1111 case GNUNET_ARM_PROCESS_COMMUNICATION_TIMEOUT:
1112 /**
1113 * Failure to perform operation
1114 */
1115 case GNUNET_ARM_PROCESS_FAILURE:
1116 default:
1117 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "ARM returned %d\n", result);
1118 GNUNET_abort ();
1119 }
1120}
1121
1122
1123/**
1124 * ARM connect callback. Called when we are connected to the arm service for
1125 * the peer in 'cls'. If successfull we start the regex deamon to start
1126 * announcing the regex of this peer.
1127 *
1128 * @param cls internal peer id.
1129 * @param op operation handle.
1130 * @param ca_result connect adapter result.
1131 * @param emsg error message.
1132 */
1133static void
1134arm_connect_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
1135 void *ca_result, const char *emsg)
1136{
1137 struct RegexPeer *peer = (struct RegexPeer *) cls;
1138
1139 if (NULL != emsg || NULL == op || NULL == ca_result)
1140 {
1141 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "ARM connect failed: %s\n", emsg);
1142 GNUNET_abort ();
1143 }
1144
1145 GNUNET_assert (NULL != peer->arm_handle);
1146 GNUNET_assert (peer->op_handle == op);
1147 GNUNET_assert (peer->arm_handle == ca_result);
1148
1149 GNUNET_ARM_start_service (ca_result, "regexprofiler",
1150 GNUNET_OS_INHERIT_STD_NONE,
1151 GNUNET_TIME_UNIT_FOREVER_REL,
1152 &arm_start_cb,
1153 peer);
1154}
1155
1156
1157/**
1158 * Task to start the daemons on each peer so that the regexes are announced
1159 * into the DHT.
1160 *
1161 * @param cls NULL
1162 * @param tc the task context
1163 */
1164static void
1165do_announce (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1166{
1167 printf ("Starting announce.\n");
1168 fflush (stdout);
1169
1170 /* First connect to arm service, then announce. Next
1171 announce will be in arm_connect_cb */
1172 peers[0].op_handle =
1173 GNUNET_TESTBED_service_connect (NULL,
1174 peers[0].peer_handle,
1175 "arm",
1176 &arm_connect_cb,
1177 &peers[0],
1178 &arm_ca,
1179 &arm_da,
1180 &peers[0]);
1181
1182}
1183
1184
1185/**
1186 * Start announcing the next regex in the DHT.
1187 *
1188 * @param cls Index of the next peer in the peers array.
1189 * @param tc TaskContext.
1190 */
1191void
1192announce_next_regex (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1193{
1194 long next_p = (long) cls;
1195
1196 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
1197 return;
1198
1199 printf ("Starting daemon %ld\n", next_p);
1200 fflush (stdout);
1201
1202 peers[next_p].op_handle =
1203 GNUNET_TESTBED_service_connect (NULL,
1204 peers[next_p].peer_handle,
1205 "arm",
1206 &arm_connect_cb,
1207 &peers[next_p],
1208 &arm_ca,
1209 &arm_da,
1210 &peers[next_p]);
1211}
1212
1213
982/** 1214/**
983 * DHT connect callback. Called when we are connected to the dht service for 1215 * DHT connect callback. Called when we are connected to the dht service for
984 * the peer in 'cls'. If successfull we connect to the stats service of this 1216 * the peer in 'cls'. If successfull we connect to the stats service of this
@@ -1004,7 +1236,7 @@ dht_connect_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
1004 } 1236 }
1005 1237
1006 GNUNET_assert (NULL != peer->dht_handle); 1238 GNUNET_assert (NULL != peer->dht_handle);
1007 GNUNET_assert (peer->dht_op_handle == op); 1239 GNUNET_assert (peer->op_handle == op);
1008 GNUNET_assert (peer->dht_handle == ca_result); 1240 GNUNET_assert (peer->dht_handle == ca_result);
1009 1241
1010 peer->search_str_matched = GNUNET_NO; 1242 peer->search_str_matched = GNUNET_NO;
@@ -1155,7 +1387,7 @@ peer_churn_cb (void *cls, const char *emsg)
1155 if (++started_peers == num_peers) 1387 if (++started_peers == num_peers)
1156 { 1388 {
1157 prof_time = GNUNET_TIME_absolute_get_duration (prof_start_time); 1389 prof_time = GNUNET_TIME_absolute_get_duration (prof_start_time);
1158 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1390 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1159 "All peers started successfully in %s\n", 1391 "All peers started successfully in %s\n",
1160 GNUNET_STRINGS_relative_time_to_string (prof_time, GNUNET_NO)); 1392 GNUNET_STRINGS_relative_time_to_string (prof_time, GNUNET_NO));
1161 result = GNUNET_OK; 1393 result = GNUNET_OK;
@@ -1216,7 +1448,7 @@ peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg)
1216 if (++created_peers == num_peers) 1448 if (++created_peers == num_peers)
1217 { 1449 {
1218 prof_time = GNUNET_TIME_absolute_get_duration (prof_start_time); 1450 prof_time = GNUNET_TIME_absolute_get_duration (prof_start_time);
1219 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1451 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1220 "All peers created successfully in %s\n", 1452 "All peers created successfully in %s\n",
1221 GNUNET_STRINGS_relative_time_to_string (prof_time, GNUNET_NO)); 1453 GNUNET_STRINGS_relative_time_to_string (prof_time, GNUNET_NO));
1222 /* Now peers are to be started */ 1454 /* Now peers are to be started */
@@ -1444,18 +1676,14 @@ controller_event_cb (void *cls,
1444 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Unable to write to file!\n"); 1676 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Unable to write to file!\n");
1445 } 1677 }
1446 1678
1447 printf ("\nWaiting %s before starting to search.\n", 1679 printf ("\nWaiting %s before starting to announce.\n",
1448 GNUNET_STRINGS_relative_time_to_string (search_delay, GNUNET_YES)); 1680 GNUNET_STRINGS_relative_time_to_string (search_delay, GNUNET_NO));
1449 fflush (stdout); 1681 fflush (stdout);
1450 1682
1451 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1452 "Waiting %s before starting to search.\n",
1453 GNUNET_STRINGS_relative_time_to_string (search_delay, GNUNET_NO));
1454
1455 state = STATE_SEARCH_REGEX; 1683 state = STATE_SEARCH_REGEX;
1456 1684
1457 search_task = GNUNET_SCHEDULER_add_delayed (search_delay, 1685 search_task = GNUNET_SCHEDULER_add_delayed (search_delay,
1458 &do_connect_by_string, NULL); 1686 &do_announce, NULL);
1459 } 1687 }
1460 } 1688 }
1461 break; 1689 break;