transport-testing.c | transport-testing.c | |||
---|---|---|---|---|
skipping to change at line 72 | skipping to change at line 72 | |||
while (t != NULL) | while (t != NULL) | |||
{ | { | |||
if (0 == memcmp (&t->id, peer, sizeof (struct GNUNET_PeerIdentity))) | if (0 == memcmp (&t->id, peer, sizeof (struct GNUNET_PeerIdentity))) | |||
break; | break; | |||
t = t->next; | t = t->next; | |||
} | } | |||
return t; | return t; | |||
} | } | |||
struct ConnectingContext * | static struct ConnectingContext * | |||
find_connecting_context (struct GNUNET_TRANSPORT_TESTING_handle *tth, | find_connecting_context (struct GNUNET_TRANSPORT_TESTING_handle *tth, | |||
struct PeerContext *p1, struct PeerContext *p2) | struct PeerContext *p1, struct PeerContext *p2) | |||
{ | { | |||
GNUNET_assert (tth != NULL); | GNUNET_assert (tth != NULL); | |||
struct ConnectingContext *cc = tth->cc_head; | struct ConnectingContext *cc = tth->cc_head; | |||
while (cc != NULL) | while (cc != NULL) | |||
{ | { | |||
if ((cc->p1 == p1) && (cc->p2 == p2)) | if ((cc->p1 == p1) && (cc->p2 == p2)) | |||
break; | break; | |||
skipping to change at line 308 | skipping to change at line 308 | |||
GNUNET_DISK_file_write (fn, hostkey, HOSTKEYFILESIZE)); | GNUNET_DISK_file_write (fn, hostkey, HOSTKEYFILESIZE)); | |||
GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fn)); | GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fn)); | |||
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing", | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing", | |||
"Wrote hostkey to file: `%s' \n", p->hostkeyfile); | "Wrote hostkey to file: `%s' \n", p->hostkeyfile); | |||
} | } | |||
p->arm_proc = | p->arm_proc = | |||
GNUNET_OS_start_process (GNUNET_YES, | GNUNET_OS_start_process (GNUNET_YES, | |||
NULL, NULL, "gnunet-service-arm", | NULL, NULL, "gnunet-service-arm", | |||
"gnunet-service-arm", "-c", cfgname, | "gnunet-service-arm", "-c", cfgname, | |||
#if VERBOSE_PEERS | ||||
"-L", "DEBUG", | ||||
#else | ||||
"-L", "ERROR", | "-L", "ERROR", | |||
#endif | ||||
NULL); | NULL); | |||
p->no = peer_id; | p->no = peer_id; | |||
p->tth = tth; | p->tth = tth; | |||
p->nc = nc; | p->nc = nc; | |||
p->nd = nd; | p->nd = nd; | |||
p->rec = rec; | p->rec = rec; | |||
p->start_cb = start_cb; | p->start_cb = start_cb; | |||
if (cb_cls != NULL) | if (cb_cls != NULL) | |||
p->cb_cls = cb_cls; | p->cb_cls = cb_cls; | |||
skipping to change at line 362 | skipping to change at line 358 | |||
restart_cb, void *cb_cls) | restart_cb, void *cb_cls) | |||
{ | { | |||
struct GNUNET_DISK_FileHandle *fn; | struct GNUNET_DISK_FileHandle *fn; | |||
GNUNET_assert (tth != NULL); | GNUNET_assert (tth != NULL); | |||
GNUNET_assert (p != NULL); | GNUNET_assert (p != NULL); | |||
GNUNET_assert (p->hostkeyfile != NULL); | GNUNET_assert (p->hostkeyfile != NULL); | |||
GNUNET_assert (p->servicehome != NULL); | GNUNET_assert (p->servicehome != NULL); | |||
/* shutdown */ | /* shutdown */ | |||
#if VERBOSE | ||||
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing", | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing", | |||
"Stopping peer %u (`%s')\n", p->no, GNUNET_i2s (&p->id)) ; | "Stopping peer %u (`%s')\n", p->no, GNUNET_i2s (&p->id)) ; | |||
#endif | ||||
if (p->ghh != NULL) | if (p->ghh != NULL) | |||
GNUNET_TRANSPORT_get_hello_cancel (p->ghh); | GNUNET_TRANSPORT_get_hello_cancel (p->ghh); | |||
p->ghh = NULL; | p->ghh = NULL; | |||
if (p->th != NULL) | if (p->th != NULL) | |||
GNUNET_TRANSPORT_disconnect (p->th); | GNUNET_TRANSPORT_disconnect (p->th); | |||
if (NULL != p->arm_proc) | if (NULL != p->arm_proc) | |||
{ | { | |||
if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) | if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) | |||
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | |||
GNUNET_OS_process_wait (p->arm_proc); | GNUNET_OS_process_wait (p->arm_proc); | |||
GNUNET_OS_process_close (p->arm_proc); | GNUNET_OS_process_destroy (p->arm_proc); | |||
p->arm_proc = NULL; | p->arm_proc = NULL; | |||
} | } | |||
if (p->hello != NULL) | if (p->hello != NULL) | |||
GNUNET_free (p->hello); | GNUNET_free (p->hello); | |||
p->hello = NULL; | p->hello = NULL; | |||
if (p->cfg != NULL) | if (p->cfg != NULL) | |||
GNUNET_CONFIGURATION_destroy (p->cfg); | GNUNET_CONFIGURATION_destroy (p->cfg); | |||
p->cfg = NULL; | p->cfg = NULL; | |||
/* start */ | /* start */ | |||
#if VERBOSE | ||||
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing", | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing", | |||
"Restarting peer %u (`%s')\n", p->no, GNUNET_i2s (&p->id )); | "Restarting peer %u (`%s')\n", p->no, GNUNET_i2s (&p->id )); | |||
#endif | ||||
sleep (5); // YUCK! | sleep (5); // YUCK! | |||
if (GNUNET_DISK_file_test (cfgname) == GNUNET_NO) | if (GNUNET_DISK_file_test (cfgname) == GNUNET_NO) | |||
{ | { | |||
GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "transport-testing", | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "transport-testing", | |||
"File not found: `%s' \n", cfgname); | "File not found: `%s' \n", cfgname); | |||
goto fail; | goto fail; | |||
} | } | |||
p->cfg = GNUNET_CONFIGURATION_create (); | p->cfg = GNUNET_CONFIGURATION_create (); | |||
skipping to change at line 424 | skipping to change at line 415 | |||
GNUNET_DISK_PERM_USER_WRITE); | GNUNET_DISK_PERM_USER_WRITE); | |||
if (fn == NULL) | if (fn == NULL) | |||
goto fail; | goto fail; | |||
if (GNUNET_OK != GNUNET_DISK_file_close (fn)) | if (GNUNET_OK != GNUNET_DISK_file_close (fn)) | |||
goto fail; | goto fail; | |||
p->arm_proc = | p->arm_proc = | |||
GNUNET_OS_start_process (GNUNET_YES, | GNUNET_OS_start_process (GNUNET_YES, | |||
NULL, NULL, "gnunet-service-arm", | NULL, NULL, "gnunet-service-arm", | |||
"gnunet-service-arm", "-c", cfgname, | "gnunet-service-arm", "-c", cfgname, | |||
#if VERBOSE_PEERS | ||||
"-L", "DEBUG", | ||||
#else | ||||
"-L", "ERROR", | "-L", "ERROR", | |||
#endif | ||||
NULL); | NULL); | |||
p->th = | p->th = | |||
GNUNET_TRANSPORT_connect (p->cfg, NULL, p, ¬ify_receive, | GNUNET_TRANSPORT_connect (p->cfg, NULL, p, ¬ify_receive, | |||
¬ify_connect, ¬ify_disconnect); | ¬ify_connect, ¬ify_disconnect); | |||
GNUNET_assert (p->th != NULL); | GNUNET_assert (p->th != NULL); | |||
p->start_cb = restart_cb; | p->start_cb = restart_cb; | |||
p->cb_cls = cb_cls; | p->cb_cls = cb_cls; | |||
skipping to change at line 461 | skipping to change at line 448 | |||
/** | /** | |||
* shutdown the given peer | * shutdown the given peer | |||
* @param tth testing handle | * @param tth testing handle | |||
* @param p the peer | * @param p the peer | |||
*/ | */ | |||
void | void | |||
GNUNET_TRANSPORT_TESTING_stop_peer (struct GNUNET_TRANSPORT_TESTING_handle *tth, | GNUNET_TRANSPORT_TESTING_stop_peer (struct GNUNET_TRANSPORT_TESTING_handle *tth, | |||
struct PeerContext *p) | struct PeerContext *p) | |||
{ | { | |||
GNUNET_assert (p != NULL); | GNUNET_assert (p != NULL); | |||
if (p->ghh != NULL) | if (p->ghh != NULL) | |||
{ | ||||
GNUNET_TRANSPORT_get_hello_cancel (p->ghh); | GNUNET_TRANSPORT_get_hello_cancel (p->ghh); | |||
p->ghh = NULL; | p->ghh = NULL; | |||
} | ||||
if (p->th != NULL) | if (p->th != NULL) | |||
GNUNET_TRANSPORT_disconnect (p->th); | GNUNET_TRANSPORT_disconnect (p->th); | |||
if (NULL != p->arm_proc) | if (NULL != p->arm_proc) | |||
{ | { | |||
if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) | if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) | |||
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | |||
GNUNET_OS_process_wait (p->arm_proc); | GNUNET_OS_process_wait (p->arm_proc); | |||
GNUNET_OS_process_close (p->arm_proc); | GNUNET_OS_process_destroy (p->arm_proc); | |||
p->arm_proc = NULL; | p->arm_proc = NULL; | |||
} | } | |||
if (p->hostkeyfile != NULL) | if (p->hostkeyfile != NULL) | |||
{ | { | |||
GNUNET_DISK_directory_remove (p->hostkeyfile); | GNUNET_DISK_directory_remove (p->hostkeyfile); | |||
GNUNET_free (p->hostkeyfile); | GNUNET_free (p->hostkeyfile); | |||
} | } | |||
if (p->servicehome != NULL) | if (p->servicehome != NULL) | |||
{ | { | |||
GNUNET_DISK_directory_remove (p->servicehome); | GNUNET_DISK_directory_remove (p->servicehome); | |||
GNUNET_free (p->servicehome); | GNUNET_free (p->servicehome); | |||
} | } | |||
if (p->hello != NULL) | if (p->hello != NULL) | |||
{ | ||||
GNUNET_free (p->hello); | GNUNET_free (p->hello); | |||
p->hello = NULL; | p->hello = NULL; | |||
} | ||||
if (p->cfg != NULL) | if (p->cfg != NULL) | |||
{ | ||||
GNUNET_CONFIGURATION_destroy (p->cfg); | GNUNET_CONFIGURATION_destroy (p->cfg); | |||
p->cfg = NULL; | p->cfg = NULL; | |||
} | ||||
GNUNET_CONTAINER_DLL_remove (tth->p_head, tth->p_tail, p); | GNUNET_CONTAINER_DLL_remove (tth->p_head, tth->p_tail, p); | |||
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing", | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing", | |||
"Peer %u (`%s') stopped \n", p->no, | "Peer %u (`%s') stopped \n", p->no, | |||
GNUNET_i2s (&p->id)); | GNUNET_i2s (&p->id)); | |||
GNUNET_free (p); | GNUNET_free (p); | |||
p = NULL; | ||||
} | } | |||
/** | /** | |||
* Connect the given peers and call the callback when both peers report the | * Connect the given peers and call the callback when both peers report the | |||
* inbound connection. Remarks: start_peer's notify_connect callback can be called | * inbound connection. Remarks: start_peer's notify_connect callback can be called | |||
* before. | * before. | |||
* | * | |||
* @param tth transport testing handle | * @param tth transport testing handle | |||
* @param p1 peer 1 | * @param p1 peer 1 | |||
* @param p2 peer 2 | * @param p2 peer 2 | |||
skipping to change at line 534 | skipping to change at line 516 | |||
GNUNET_TRANSPORT_TESTING_connect_cb cb, | GNUNET_TRANSPORT_TESTING_connect_cb cb, | |||
void *cls) | void *cls) | |||
{ | { | |||
GNUNET_assert (tth != NULL); | GNUNET_assert (tth != NULL); | |||
struct ConnectingContext *cc = | struct ConnectingContext *cc = | |||
GNUNET_malloc (sizeof (struct ConnectingContext)); | GNUNET_malloc (sizeof (struct ConnectingContext)); | |||
GNUNET_assert (p1 != NULL); | GNUNET_assert (p1 != NULL); | |||
GNUNET_assert (p2 != NULL); | GNUNET_assert (p2 != NULL); | |||
cc->p1 = p1; | cc->p1 = p1; | |||
cc->p2 = p2; | cc->p2 = p2; | |||
cc->cb = cb; | cc->cb = cb; | |||
if (cls != NULL) | if (cls != NULL) | |||
cc->cb_cls = cls; | cc->cb_cls = cls; | |||
else | else | |||
cc->cb_cls = cc; | cc->cb_cls = cc; | |||
cc->th_p1 = p1->th; | cc->th_p1 = p1->th; | |||
cc->th_p2 = p2->th; | cc->th_p2 = p2->th; | |||
GNUNET_assert (cc->th_p1 != NULL); | GNUNET_assert (cc->th_p1 != NULL); | |||
GNUNET_assert (cc->th_p2 != NULL); | GNUNET_assert (cc->th_p2 != NULL); | |||
GNUNET_CONTAINER_DLL_insert (tth->cc_head, tth->cc_tail, cc); | GNUNET_CONTAINER_DLL_insert (tth->cc_head, tth->cc_tail, cc); | |||
cc->tct = GNUNET_SCHEDULER_add_now (&try_connect, cc); | cc->tct = GNUNET_SCHEDULER_add_now (&try_connect, cc); | |||
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing", | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing", | |||
"New connect request %X\n", cc); | "New connect request %X\n", cc); | |||
return cc; | return cc; | |||
} | } | |||
/** | /** | |||
* Cancel the request to connect two peers | * Cancel the request to connect two peers | |||
* Tou MUST cancel the request if you stop the peers before the peers conne cted succesfully | * Tou MUST cancel the request if you stop the peers before the peers conne cted succesfully | |||
skipping to change at line 659 | skipping to change at line 635 | |||
/* Check hostkey file size, read entire thing into memory */ | /* Check hostkey file size, read entire thing into memory */ | |||
fd = GNUNET_DISK_file_open (hostkeys_file, GNUNET_DISK_OPEN_READ, | fd = GNUNET_DISK_file_open (hostkeys_file, GNUNET_DISK_OPEN_READ, | |||
GNUNET_DISK_PERM_NONE); | GNUNET_DISK_PERM_NONE); | |||
if (NULL == fd) | if (NULL == fd) | |||
{ | { | |||
GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", hostkeys_f ile); | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", hostkeys_f ile); | |||
GNUNET_free (tth); | GNUNET_free (tth); | |||
return NULL; | return NULL; | |||
} | } | |||
if (GNUNET_YES != GNUNET_DISK_file_size (hostkeys_file, &fs, GNUNET_YES )) | if (GNUNET_OK != GNUNET_DISK_file_size (hostkeys_file, &fs, GNUNET_YES, GNUNET_YES)) | |||
fs = 0; | fs = 0; | |||
if (0 != (fs % HOSTKEYFILESIZE)) | if (0 != (fs % HOSTKEYFILESIZE)) | |||
{ | { | |||
GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "transport-testing", | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "transport-testing", | |||
"File size %llu seems incorrect for hostkeys...\n", fs); | "File size %llu seems incorrect for hostkeys...\n", fs); | |||
} | } | |||
else | else | |||
{ | { | |||
total_hostkeys = fs / HOSTKEYFILESIZE; | total_hostkeys = fs / HOSTKEYFILESIZE; | |||
skipping to change at line 776 | skipping to change at line 752 | |||
split = strstr (src, "."); | split = strstr (src, "."); | |||
if (split != NULL) | if (split != NULL) | |||
{ | { | |||
split[0] = '\0'; | split[0] = '\0'; | |||
} | } | |||
GNUNET_asprintf (dest, "%s", src); | GNUNET_asprintf (dest, "%s", src); | |||
GNUNET_free (src); | GNUNET_free (src); | |||
} | } | |||
/** | /** | |||
* Extracts the plugin anme from an absolute file name and the test name | * Extracts the plugin name from an absolute file name and the test name | |||
* | ||||
* @param file absolute file name | * @param file absolute file name | |||
* @param test test name | * @param test test name | |||
* @param dest where to store result | * @param dest where to store result | |||
*/ | */ | |||
void | void | |||
GNUNET_TRANSPORT_TESTING_get_test_plugin_name (const char *file, | GNUNET_TRANSPORT_TESTING_get_test_plugin_name (const char *file, | |||
const char *test, char **des t) | const char *test, char **des t) | |||
{ | { | |||
char *filename; | ||||
char *dotexe; | ||||
char *e = extract_filename (file); | char *e = extract_filename (file); | |||
char *t = extract_filename (test); | char *t = extract_filename (test); | |||
char *filename = NULL; | if (NULL == e) | |||
char *dotexe; | ||||
if (e == NULL) | ||||
goto fail; | goto fail; | |||
/* remove "lt-" */ | /* remove "lt-" */ | |||
filename = strstr (e, "tes"); | filename = strstr (e, "tes"); | |||
if (filename == NULL) | if (NULL == filename) | |||
goto fail; | goto fail; | |||
/* remove ".exe" */ | /* remove ".exe" */ | |||
if (NULL != (dotexe = strstr (filename, ".exe"))) | if (NULL != (dotexe = strstr (filename, ".exe"))) | |||
dotexe[0] = '\0'; | dotexe[0] = '\0'; | |||
/* find last _ */ | /* find last _ */ | |||
filename = strstr (filename, t); | filename = strstr (filename, t); | |||
if (filename == NULL) | if (NULL == filename) | |||
goto fail; | goto fail; | |||
/* copy plugin */ | /* copy plugin */ | |||
filename += strlen (t); | filename += strlen (t); | |||
filename++; | if ('\0' != *filename) | |||
filename++; | ||||
GNUNET_asprintf (dest, "%s", filename); | GNUNET_asprintf (dest, "%s", filename); | |||
goto suc; | goto suc; | |||
fail: | fail: | |||
(*dest) = NULL; | (*dest) = NULL; | |||
suc: | suc: | |||
GNUNET_free (t); | GNUNET_free (t); | |||
GNUNET_free (e); | GNUNET_free (e); | |||
} | } | |||
/** | /** | |||
* This function takes the filename (e.g. argv[0), removes a "lt-"-prefix a nd | * This function takes the filename (e.g. argv[0), removes a "lt-"-prefix a nd | |||
* if existing ".exe"-prefix and adds the peer-number | * if existing ".exe"-prefix and adds the peer-number | |||
* | * | |||
* @param file filename of the test, e.g. argv[0] | * @param file filename of the test, e.g. argv[0] | |||
* @param dest where to write the filename | * @param dest where to write the filename | |||
* @param count peer number | * @param count peer number | |||
*/ | */ | |||
void | void | |||
GNUNET_TRANSPORT_TESTING_get_config_name (const char *file, char **dest, | GNUNET_TRANSPORT_TESTING_get_config_name (const char *file, char **dest, | |||
int count) | int count) | |||
{ | { | |||
char *filename = extract_filename (file); | char *filename = extract_filename (file); | |||
char *backup = filename; | char *backup = filename; | |||
char *dotexe; | char *dotexe; | |||
if (filename == NULL) | if (NULL == filename) | |||
goto fail; | goto fail; | |||
/* remove "lt-" */ | /* remove "lt-" */ | |||
filename = strstr (filename, "tes"); | filename = strstr (filename, "tes"); | |||
if (filename == NULL) | if (NULL == filename) | |||
goto fail; | goto fail; | |||
/* remove ".exe" */ | /* remove ".exe" */ | |||
if (NULL != (dotexe = strstr (filename, ".exe"))) | if (NULL != (dotexe = strstr (filename, ".exe"))) | |||
dotexe[0] = '\0'; | dotexe[0] = '\0'; | |||
GNUNET_asprintf (dest, "%s_peer%u.conf", filename, count); | ||||
goto suc; | GNUNET_free (backup); | |||
return; | ||||
fail: | fail: | |||
(*dest) = NULL; | (*dest) = NULL; | |||
return; | ||||
suc: | ||||
/* create cfg filename */ | ||||
GNUNET_asprintf (dest, "%s_peer%u.conf", filename, count); | ||||
GNUNET_free (backup); | GNUNET_free (backup); | |||
} | } | |||
/* end of transport_testing.h */ | /* end of transport-testing.c */ | |||
End of changes. 50 change blocks. | ||||
62 lines changed or deleted | 27 lines changed or added | |||
This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/ |