diff options
author | Bart Polot <bart@net.in.tum.de> | 2013-04-11 13:50:06 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2013-04-11 13:50:06 +0000 |
commit | 91a834246d29ad61784de62f6a56551138394ccc (patch) | |
tree | b3f44c9edae6607870ac30b063de0fa0bdd3af51 /src | |
parent | 4ca291d0b3ab06a76dc02b046984a261fbc3bfac (diff) | |
download | gnunet-91a834246d29ad61784de62f6a56551138394ccc.tar.gz gnunet-91a834246d29ad61784de62f6a56551138394ccc.zip |
- use GNUNET_TESTBED_peer_manage_service instad of manually connecting to ARM
Diffstat (limited to 'src')
-rw-r--r-- | src/regex/gnunet-regex-profiler.c | 218 |
1 files changed, 52 insertions, 166 deletions
diff --git a/src/regex/gnunet-regex-profiler.c b/src/regex/gnunet-regex-profiler.c index 9ecdea7e5..eb65b8995 100644 --- a/src/regex/gnunet-regex-profiler.c +++ b/src/regex/gnunet-regex-profiler.c | |||
@@ -154,11 +154,6 @@ struct RegexPeer | |||
154 | int search_str_matched; | 154 | int search_str_matched; |
155 | 155 | ||
156 | /** | 156 | /** |
157 | * Peer's ARM handle. | ||
158 | */ | ||
159 | struct GNUNET_ARM_Handle *arm_handle; | ||
160 | |||
161 | /** | ||
162 | * Peer's DHT handle. | 157 | * Peer's DHT handle. |
163 | */ | 158 | */ |
164 | struct GNUNET_DHT_Handle *dht_handle; | 159 | struct GNUNET_DHT_Handle *dht_handle; |
@@ -169,7 +164,7 @@ struct RegexPeer | |||
169 | struct GNUNET_REGEX_search_handle *search_handle; | 164 | struct GNUNET_REGEX_search_handle *search_handle; |
170 | 165 | ||
171 | /** | 166 | /** |
172 | * Testbed operation handle for the ARM and DHT services. | 167 | * Testbed operation handle for DHT. |
173 | */ | 168 | */ |
174 | struct GNUNET_TESTBED_Operation *op_handle; | 169 | struct GNUNET_TESTBED_Operation *op_handle; |
175 | 170 | ||
@@ -192,6 +187,11 @@ struct RegexPeer | |||
192 | * Operation timeout | 187 | * Operation timeout |
193 | */ | 188 | */ |
194 | GNUNET_SCHEDULER_TaskIdentifier timeout; | 189 | GNUNET_SCHEDULER_TaskIdentifier timeout; |
190 | |||
191 | /** | ||
192 | * Deamon start | ||
193 | */ | ||
194 | struct GNUNET_TESTBED_Operation *daemon_op; | ||
195 | }; | 195 | }; |
196 | 196 | ||
197 | 197 | ||
@@ -991,171 +991,58 @@ find_string (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
991 | } | 991 | } |
992 | 992 | ||
993 | 993 | ||
994 | /** | ||
995 | * ARM connect adapter. Opens a connection to the ARM service. | ||
996 | * | ||
997 | * @param cls Closure (peer). | ||
998 | * @param cfg Configuration handle. | ||
999 | * | ||
1000 | * @return | ||
1001 | */ | ||
1002 | static void * | ||
1003 | arm_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
1004 | { | ||
1005 | struct RegexPeer *peer = cls; | ||
1006 | |||
1007 | peer->arm_handle = GNUNET_ARM_connect (cfg, NULL, NULL); | ||
1008 | |||
1009 | return peer->arm_handle; | ||
1010 | } | ||
1011 | 994 | ||
1012 | 995 | ||
1013 | /** | 996 | /** |
1014 | * Adapter function called to destroy a connection to the ARM service. | 997 | * Callback called when testbed has started the daemon we asked for. |
1015 | * | 998 | * |
1016 | * @param cls Closure (peer). | 999 | * @param cls NULL |
1017 | * @param op_result Service handle returned from the connect adapter. | 1000 | * @param op the operation handle |
1018 | */ | 1001 | * @param emsg NULL on success; otherwise an error description |
1019 | static void | ||
1020 | arm_da (void *cls, void *op_result) | ||
1021 | { | ||
1022 | struct RegexPeer *peer = (struct RegexPeer *) cls; | ||
1023 | |||
1024 | GNUNET_assert (peer->arm_handle == op_result); | ||
1025 | |||
1026 | if (NULL != peer->arm_handle) | ||
1027 | { | ||
1028 | GNUNET_ARM_disconnect_and_free (peer->arm_handle); | ||
1029 | peer->arm_handle = NULL; | ||
1030 | } | ||
1031 | } | ||
1032 | |||
1033 | /** | ||
1034 | * Finish and free the operation used to start the regex daemon. | ||
1035 | * operation_done calls ARM_disconnect, which cannot happen inside an | ||
1036 | * ARM callback. | ||
1037 | * | ||
1038 | * @param cls Closure (Peer info) | ||
1039 | * @param tc TaskContext | ||
1040 | */ | ||
1041 | static void | ||
1042 | arm_op_done (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
1043 | { | ||
1044 | struct RegexPeer *peer = (struct RegexPeer *) cls; | ||
1045 | |||
1046 | GNUNET_TESTBED_operation_done (peer->op_handle); | ||
1047 | peer->op_handle = NULL; | ||
1048 | } | ||
1049 | |||
1050 | |||
1051 | /** | ||
1052 | * Callback called when arm has started the daemon we asked for. | ||
1053 | * | ||
1054 | * @param cls Closure (). | ||
1055 | * @param arm Arm handle. | ||
1056 | * @param rs Status of the request. | ||
1057 | * @param service Service we asked to start (deamon). | ||
1058 | * @param result Result of the request. | ||
1059 | */ | 1002 | */ |
1060 | static void | 1003 | static void |
1061 | arm_start_cb (void *cls, struct GNUNET_ARM_Handle *arm, | 1004 | daemon_started (void *cls, struct GNUNET_TESTBED_Operation *op, |
1062 | enum GNUNET_ARM_RequestStatus rs, const char *service, | 1005 | const char *emsg) |
1063 | enum GNUNET_ARM_Result result) | ||
1064 | { | 1006 | { |
1065 | struct RegexPeer *peer = (struct RegexPeer *) cls; | 1007 | struct RegexPeer *peer = (struct RegexPeer *) cls; |
1008 | unsigned long search_peer; | ||
1009 | unsigned int i; | ||
1010 | unsigned int me; | ||
1066 | 1011 | ||
1067 | if (rs != GNUNET_ARM_REQUEST_SENT_OK) | 1012 | GNUNET_TESTBED_operation_done (peer->daemon_op); |
1013 | me = peer - peers; | ||
1014 | if (NULL != emsg) | ||
1068 | { | 1015 | { |
1069 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "ARM request was not sent: %u\n", rs); | 1016 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1017 | "Failed to start/stop daemon at peer %u: %s\n", me, emsg); | ||
1070 | GNUNET_abort (); | 1018 | GNUNET_abort (); |
1071 | } | 1019 | } |
1072 | switch (result) | ||
1073 | { | ||
1074 | /** | ||
1075 | * Asked to start it, but it's already starting. | ||
1076 | */ | ||
1077 | case GNUNET_ARM_RESULT_IS_STARTING_ALREADY: | ||
1078 | GNUNET_break (0); /* Shouldn't be starting, however it's not fatal. */ | ||
1079 | /* fallthrough */ | ||
1080 | |||
1081 | /** | ||
1082 | * Service is currently being started (due to client request). | ||
1083 | */ | ||
1084 | case GNUNET_ARM_RESULT_STARTING: | ||
1085 | GNUNET_SCHEDULER_add_now (&arm_op_done, peer); | ||
1086 | |||
1087 | { | ||
1088 | unsigned long search_peer; | ||
1089 | unsigned int i; | ||
1090 | unsigned int me; | ||
1091 | |||
1092 | me = peer - peers; | ||
1093 | |||
1094 | /* Find a peer to look for a string matching the regex announced */ | ||
1095 | search_peer = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | ||
1096 | num_peers); | ||
1097 | for (i = 0; peers[search_peer].search_str != NULL; i++) | ||
1098 | { | ||
1099 | search_peer = (search_peer + 1) % num_peers; | ||
1100 | if (i > num_peers) | ||
1101 | GNUNET_abort (); /* we ran out of peers, must be a bug */ | ||
1102 | } | ||
1103 | peers[search_peer].search_str = search_strings[me]; | ||
1104 | peers[search_peer].search_str_matched = GNUNET_NO; | ||
1105 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply( | ||
1106 | reannounce_period_max, | ||
1107 | 2), | ||
1108 | &find_string, | ||
1109 | (void *) search_peer); | ||
1110 | } | ||
1111 | if (next_search >= num_peers && | ||
1112 | GNUNET_SCHEDULER_NO_TASK == search_timeout_task) | ||
1113 | { | ||
1114 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "All daemons started.\n"); | ||
1115 | /* FIXME start GLOBAL timeout to abort experiment */ | ||
1116 | search_timeout_task = GNUNET_SCHEDULER_add_delayed (search_timeout_time, | ||
1117 | &search_timeout, | ||
1118 | NULL); | ||
1119 | } | ||
1120 | break; | ||
1121 | 1020 | ||
1122 | default: | 1021 | /* Find a peer to look for a string matching the regex announced */ |
1123 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "ARM returned %d\n", result); | 1022 | search_peer = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, |
1124 | GNUNET_abort (); | 1023 | num_peers); |
1024 | for (i = 0; peers[search_peer].search_str != NULL; i++) | ||
1025 | { | ||
1026 | search_peer = (search_peer + 1) % num_peers; | ||
1027 | if (i > num_peers) | ||
1028 | GNUNET_abort (); /* we ran out of peers, must be a bug */ | ||
1125 | } | 1029 | } |
1126 | } | 1030 | peers[search_peer].search_str = search_strings[me]; |
1127 | 1031 | peers[search_peer].search_str_matched = GNUNET_NO; | |
1128 | /** | 1032 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply( |
1129 | * ARM connect callback. Called when we are connected to the arm service for | 1033 | reannounce_period_max, |
1130 | * the peer in 'cls'. If successfull we start the regex deamon to start | 1034 | 2), |
1131 | * announcing the regex of this peer. | 1035 | &find_string, |
1132 | * | 1036 | (void *) search_peer); |
1133 | * @param cls internal peer id. | 1037 | if (next_search >= num_peers && |
1134 | * @param op operation handle. | 1038 | GNUNET_SCHEDULER_NO_TASK == search_timeout_task) |
1135 | * @param ca_result connect adapter result. | ||
1136 | * @param emsg error message. | ||
1137 | */ | ||
1138 | static void | ||
1139 | arm_connect_cb (void *cls, struct GNUNET_TESTBED_Operation *op, | ||
1140 | void *ca_result, const char *emsg) | ||
1141 | { | ||
1142 | struct RegexPeer *peer = (struct RegexPeer *) cls; | ||
1143 | |||
1144 | if (NULL != emsg || NULL == op || NULL == ca_result) | ||
1145 | { | 1039 | { |
1146 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "ARM connect failed: %s\n", emsg); | 1040 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "All daemons started.\n"); |
1147 | GNUNET_abort (); | 1041 | /* FIXME start GLOBAL timeout to abort experiment */ |
1042 | search_timeout_task = GNUNET_SCHEDULER_add_delayed (search_timeout_time, | ||
1043 | &search_timeout, | ||
1044 | NULL); | ||
1148 | } | 1045 | } |
1149 | |||
1150 | GNUNET_assert (NULL != peer->arm_handle); | ||
1151 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[]%p - ()%p\n", peer->op_handle, op); | ||
1152 | GNUNET_assert (peer->op_handle == op); | ||
1153 | GNUNET_assert (peer->arm_handle == ca_result); | ||
1154 | |||
1155 | GNUNET_ARM_request_service_start (ca_result, "regexprofiler", | ||
1156 | GNUNET_OS_INHERIT_STD_NONE, | ||
1157 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
1158 | arm_start_cb, cls); | ||
1159 | } | 1046 | } |
1160 | 1047 | ||
1161 | 1048 | ||
@@ -1192,22 +1079,21 @@ do_announce (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1192 | static void | 1079 | static void |
1193 | announce_next_regex (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 1080 | announce_next_regex (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
1194 | { | 1081 | { |
1082 | struct RegexPeer *peer; | ||
1083 | |||
1195 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) || | 1084 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) || |
1196 | next_search >= num_peers) | 1085 | next_search >= num_peers) |
1197 | return; | 1086 | return; |
1198 | 1087 | ||
1199 | /* First connect to arm service, then announce. Next | ||
1200 | * a nnounce will be in arm_connect_cb */ | ||
1201 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Starting daemon %u\n", next_search); | 1088 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Starting daemon %u\n", next_search); |
1202 | peers[next_search].op_handle = | 1089 | peer = &peers[next_search]; |
1203 | GNUNET_TESTBED_service_connect (NULL, | 1090 | peer->daemon_op = |
1204 | peers[next_search].peer_handle, | 1091 | GNUNET_TESTBED_peer_manage_service (NULL, |
1205 | "arm", | 1092 | peer->peer_handle, |
1206 | &arm_connect_cb, | 1093 | "regexprofiler", |
1207 | &peers[next_search], | 1094 | &daemon_started, |
1208 | &arm_ca, | 1095 | peer, |
1209 | &arm_da, | 1096 | 1); |
1210 | &peers[next_search]); | ||
1211 | next_search++; | 1097 | next_search++; |
1212 | parallel_searches++; | 1098 | parallel_searches++; |
1213 | } | 1099 | } |