aboutsummaryrefslogtreecommitdiff
path: root/src/testing/testing.c
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2013-04-01 17:54:06 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2013-04-01 17:54:06 +0000
commit4e3864ec2681a43fb13f5d6af6093ebed5a68196 (patch)
tree62fe35f676784c78e7f7db8bbe3f1506611d11fe /src/testing/testing.c
parente1de3162b194d2c72ad66aafcf803477caa41730 (diff)
downloadgnunet-4e3864ec2681a43fb13f5d6af6093ebed5a68196.tar.gz
gnunet-4e3864ec2681a43fb13f5d6af6093ebed5a68196.zip
- only have asynchronous peer stop
Diffstat (limited to 'src/testing/testing.c')
-rw-r--r--src/testing/testing.c172
1 files changed, 52 insertions, 120 deletions
diff --git a/src/testing/testing.c b/src/testing/testing.c
index f4584db30..9d2c69ab7 100644
--- a/src/testing/testing.c
+++ b/src/testing/testing.c
@@ -186,15 +186,19 @@ struct GNUNET_TESTING_Peer
186 struct GNUNET_ARM_Handle *ah; 186 struct GNUNET_ARM_Handle *ah;
187 187
188 /** 188 /**
189 * Handle to ARM monitoring
190 */
191 struct GNUNET_ARM_MonitorHandle *mh;
192
193 /**
189 * The config of the peer 194 * The config of the peer
190 */ 195 */
191 struct GNUNET_CONFIGURATION_Handle *cfg; 196 struct GNUNET_CONFIGURATION_Handle *cfg;
192 197
193 /** 198 /**
194 * The callback to call if asynchronous functions are used for peer/service 199 * The callback to call asynchronously when a peer is stopped
195 * start/stop requests
196 */ 200 */
197 GNUNET_TESTING_PeerStatusCallback cb; 201 GNUNET_TESTING_PeerStopCallback cb;
198 202
199 /** 203 /**
200 * The closure for the above callback 204 * The closure for the above callback
@@ -518,25 +522,6 @@ GNUNET_TESTING_release_port (struct GNUNET_TESTING_System *system,
518 522
519 523
520/** 524/**
521 * Reserve a SERVICEHOME path for a peer.
522 *
523 * @param system system to use for reservation tracking
524 * @return NULL on error, otherwise fresh unique path to use
525 * as the servicehome for the peer; must be freed by the caller
526 */
527// static
528char *
529reserve_path (struct GNUNET_TESTING_System *system)
530{
531 char *reserved_path;
532
533 GNUNET_asprintf (&reserved_path,
534 "%s/%u", system->tmppath, system->path_counter++);
535 return reserved_path;
536}
537
538
539/**
540 * Testing includes a number of pre-created hostkeys for 525 * Testing includes a number of pre-created hostkeys for
541 * faster peer startup. This function can be used to 526 * faster peer startup. This function can be used to
542 * access the n-th key of those pre-created hostkeys; note 527 * access the n-th key of those pre-created hostkeys; note
@@ -984,6 +969,7 @@ GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system,
984 } 969 }
985 peer = GNUNET_malloc (sizeof (struct GNUNET_TESTING_Peer)); 970 peer = GNUNET_malloc (sizeof (struct GNUNET_TESTING_Peer));
986 peer->cfgfile = config_filename; /* Free in peer_destroy */ 971 peer->cfgfile = config_filename; /* Free in peer_destroy */
972 peer->cfg = GNUNET_CONFIGURATION_dup (cfg);
987 libexec_binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm"); 973 libexec_binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm");
988 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "arm", "PREFIX", &peer->main_binary)) 974 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "arm", "PREFIX", &peer->main_binary))
989 { 975 {
@@ -1001,46 +987,6 @@ GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system,
1001 987
1002 988
1003/** 989/**
1004 * Wrapper over GNUNET_TESTING_peer_configure() to set the
1005 * GNUNET_TESTING_PeerStatusCallback() for using functions
1006 * GNUNET_TESTING_peer_start2() and GNUNET_TESTING_peer_stop2()
1007 *
1008 * @param system system to use to coordinate resource usage
1009 * @param cfg configuration to use; will be UPDATED (to reflect needed
1010 * changes in port numbers and paths)
1011 * @param key_number number of the hostkey to use for the peer
1012 * @param id identifier for the daemon, will be set, can be NULL
1013 * @param emsg set to freshly allocated error message (set to NULL on success),
1014 * can be NULL
1015 * @param status_cb the status callback to call upon peer start and stop
1016 * @return handle to the peer, NULL on error
1017 */
1018struct GNUNET_TESTING_Peer *
1019GNUNET_TESTING_peer_configure2 (struct GNUNET_TESTING_System *system,
1020 struct GNUNET_CONFIGURATION_Handle *cfg,
1021 uint32_t key_number,
1022 struct GNUNET_PeerIdentity *id,
1023 char **emsg,
1024 GNUNET_TESTING_PeerStatusCallback status_cb,
1025 void *cls)
1026{
1027 struct GNUNET_TESTING_Peer *peer;
1028
1029 peer = GNUNET_TESTING_peer_configure (system,
1030 cfg,
1031 key_number,
1032 id,
1033 emsg);
1034 if (NULL == peer)
1035 return NULL;
1036 peer->cfg = GNUNET_CONFIGURATION_dup (cfg);
1037 peer->cb = status_cb;
1038 peer->cb_cls = cls;
1039 return peer;
1040}
1041
1042
1043/**
1044 * Obtain the peer identity from a peer handle. 990 * Obtain the peer identity from a peer handle.
1045 * 991 *
1046 * @param peer peer handle for which we want the peer's identity 992 * @param peer peer handle for which we want the peer's identity
@@ -1159,56 +1105,6 @@ GNUNET_TESTING_peer_service_stop (struct GNUNET_TESTING_Peer *peer,
1159 1105
1160 1106
1161/** 1107/**
1162 * Function called whenever we connect to or disconnect from ARM.
1163 *
1164 * @param cls closure
1165 * @param arm handle to the ARM connection
1166 * @param connected GNUNET_YES if connected, GNUNET_NO if disconnected,
1167 * GNUNET_SYSERR on error.
1168 */
1169static void
1170conn_status (void *cls, struct GNUNET_ARM_Handle *arm,
1171 int connected)
1172{
1173 struct GNUNET_TESTING_Peer *peer = cls;
1174
1175 peer->cb (peer->cb_cls, peer, connected);
1176}
1177
1178
1179/**
1180 * Start a peer asynchronously using ARM API. Peer's startup is signaled
1181 * through the GNUNET_TESTING_PeerStatusCallback() given to
1182 * GNUNET_TESTING_peer_configure2(). To use this function the peer must be
1183 * configured earlier using GNUNET_TESTING_peer_configure2();
1184 *
1185 * @param peer the peer to start
1186 * @param timeout how long to wait before giving up to start the peer
1187 * @return GNUNET_OK upon successfully giving the request to the ARM API (this
1188 * does not mean that the peer is successfully started); GNUNET_SYSERR
1189 * upon any error.
1190 */
1191int
1192GNUNET_TESTING_peer_start2 (struct GNUNET_TESTING_Peer *peer,
1193 struct GNUNET_TIME_Relative timeout)
1194{
1195 if (NULL != peer->ah)
1196 {
1197 GNUNET_break (0);
1198 return GNUNET_SYSERR;
1199 }
1200 GNUNET_assert (NULL != peer->cb);
1201 GNUNET_assert (NULL != peer->cfg);
1202 peer->ah = GNUNET_ARM_connect (peer->cfg, &conn_status, peer);
1203 if (NULL == peer->ah)
1204 return GNUNET_SYSERR;
1205 GNUNET_TESTING_peer_service_start (peer, "arm", timeout, NULL, NULL);
1206 return GNUNET_OK;
1207}
1208
1209
1210
1211/**
1212 * Sends SIGTERM to the peer's main process 1108 * Sends SIGTERM to the peer's main process
1213 * 1109 *
1214 * @param peer the handle to the peer 1110 * @param peer the handle to the peer
@@ -1270,25 +1166,59 @@ GNUNET_TESTING_peer_stop (struct GNUNET_TESTING_Peer *peer)
1270 1166
1271 1167
1272/** 1168/**
1169 * Function called whenever we connect to or disconnect from ARM.
1170 *
1171 * @param cls closure
1172 * @param arm handle to the ARM connection
1173 * @param connected GNUNET_YES if connected, GNUNET_NO if disconnected,
1174 * GNUNET_SYSERR on error.
1175 */
1176static void
1177disconn_status (void *cls, struct GNUNET_ARM_Handle *arm,
1178 int connected)
1179{
1180 struct GNUNET_TESTING_Peer *peer = cls;
1181
1182 if (GNUNET_SYSERR == connected)
1183 {
1184 peer->cb (peer->cb_cls, peer, connected);
1185 return;
1186 }
1187 if (GNUNET_YES == connected)
1188 {
1189 GNUNET_break (GNUNET_OK == GNUNET_TESTING_peer_kill (peer));
1190 return;
1191 }
1192 GNUNET_break (GNUNET_OK == GNUNET_TESTING_peer_wait (peer));
1193 GNUNET_ARM_disconnect_and_free (peer->ah);
1194 peer->ah = NULL;
1195 peer->cb (peer->cb_cls, peer, GNUNET_YES);
1196}
1197
1198
1199/**
1273 * Stop a peer asynchronously using ARM API. Peer's shutdown is signaled 1200 * Stop a peer asynchronously using ARM API. Peer's shutdown is signaled
1274 * through the GNUNET_TESTING_PeerStatusCallback() given to 1201 * through the GNUNET_TESTING_PeerStopCallback().
1275 * GNUNET_TESTING_peer_configure2(). To use this function the peer must be
1276 * configured earlier using GNUNET_TESTING_peer_configure2();
1277 * 1202 *
1278 * @param peer the peer to stop 1203 * @param peer the peer to stop
1279 * @param timeout how long to wait before giving up to stop the peer 1204 * @param cb the callback to signal peer shutdown
1205 * @param cb_cls closure for the above callback
1280 * @return GNUNET_OK upon successfully giving the request to the ARM API (this 1206 * @return GNUNET_OK upon successfully giving the request to the ARM API (this
1281 * does not mean that the peer is successfully stopped); GNUNET_SYSERR 1207 * does not mean that the peer is successfully stopped); GNUNET_SYSERR
1282 * upon any error. 1208 * upon any error.
1283 */ 1209 */
1284int 1210int
1285GNUNET_TESTING_peer_stop2 (struct GNUNET_TESTING_Peer *peer, 1211GNUNET_TESTING_peer_stop_async (struct GNUNET_TESTING_Peer *peer,
1286 struct GNUNET_TIME_Relative timeout) 1212 GNUNET_TESTING_PeerStopCallback cb,
1213 void *cb_cls)
1287{ 1214{
1215 if (NULL == peer->main_process)
1216 return GNUNET_SYSERR;
1217 peer->ah = GNUNET_ARM_connect (peer->cfg, &disconn_status, peer);
1288 if (NULL == peer->ah) 1218 if (NULL == peer->ah)
1289 return GNUNET_SYSERR; 1219 return GNUNET_SYSERR;
1290 GNUNET_assert (NULL != peer->cb); 1220 peer->cb = cb;
1291 GNUNET_TESTING_peer_service_stop (peer, "arm", timeout, NULL, NULL); 1221 peer->cb_cls = cb_cls;
1292 return GNUNET_OK; 1222 return GNUNET_OK;
1293} 1223}
1294 1224
@@ -1307,6 +1237,8 @@ GNUNET_TESTING_peer_destroy (struct GNUNET_TESTING_Peer *peer)
1307 GNUNET_TESTING_peer_stop (peer); 1237 GNUNET_TESTING_peer_stop (peer);
1308 if (NULL != peer->ah) 1238 if (NULL != peer->ah)
1309 GNUNET_ARM_disconnect_and_free (peer->ah); 1239 GNUNET_ARM_disconnect_and_free (peer->ah);
1240 if (NULL != peer->mh)
1241 GNUNET_ARM_monitor_disconnect_and_free (peer->mh);
1310 GNUNET_free (peer->cfgfile); 1242 GNUNET_free (peer->cfgfile);
1311 if (NULL != peer->cfg) 1243 if (NULL != peer->cfg)
1312 GNUNET_CONFIGURATION_destroy (peer->cfg); 1244 GNUNET_CONFIGURATION_destroy (peer->cfg);