[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r11538 - gnunet/src/transport
From: |
gnunet |
Subject: |
[GNUnet-SVN] r11538 - gnunet/src/transport |
Date: |
Thu, 27 May 2010 16:48:56 +0200 |
Author: wachs
Date: 2010-05-27 16:48:56 +0200 (Thu, 27 May 2010)
New Revision: 11538
Modified:
gnunet/src/transport/test_plugin_transport_http.c
Log:
cleaning up the testcase
Modified: gnunet/src/transport/test_plugin_transport_http.c
===================================================================
--- gnunet/src/transport/test_plugin_transport_http.c 2010-05-27 13:57:41 UTC
(rev 11537)
+++ gnunet/src/transport/test_plugin_transport_http.c 2010-05-27 14:48:56 UTC
(rev 11538)
@@ -52,9 +52,14 @@
/**
* How long until we give up on transmitting the message?
*/
-#define STAT_INTERVALL GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_SECONDS, 10)
+#define TEST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
20)
/**
+ * How long between recieve and send?
+ */
+#define WAIT_INTERVALL GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_SECONDS, 1)
+
+/**
* Our public key.
*/
/* static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded my_public_key; */
@@ -114,8 +119,6 @@
static GNUNET_SCHEDULER_TaskIdentifier ti_send;
-static unsigned int timeout_count;
-static unsigned int recieved;
const struct GNUNET_PeerIdentity * p;
/**
@@ -123,10 +126,56 @@
*/
static int fail;
-//static int done;
+/**
+ * Recieved message already returned to sender?
+ */
+static int sent;
-pid_t pid;
+/**
+ * Shutdown testcase
+ */
+static void
+shutdown_clean ()
+{
+ if (ti_send != GNUNET_SCHEDULER_NO_TASK)
+ {
+ GNUNET_SCHEDULER_cancel(sched,ti_send);
+ ti_send = GNUNET_SCHEDULER_NO_TASK;
+ }
+ if (ti_timeout != GNUNET_SCHEDULER_NO_TASK)
+ {
+ GNUNET_SCHEDULER_cancel(sched,ti_timeout);
+ ti_timeout = GNUNET_SCHEDULER_NO_TASK;
+ }
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Unloading http plugin\n");
+ GNUNET_assert (NULL == GNUNET_PLUGIN_unload
("libgnunet_plugin_transport_http", api));
+
+ GNUNET_SCHEDULER_shutdown(sched);
+ /* FIXME: */ fail = GNUNET_NO;
+ return;
+}
+
+/**
+ * Continuation called after plugin send message
+ * @cls closure
+ * @target target
+ * @result GNUNET_OK or GNUNET_SYSERR
+ */
+static void task_send_cont (void *cls,
+ const struct GNUNET_PeerIdentity * target,
+ int result)
+{
+ fail = GNUNET_NO;
+ shutdown_clean();
+}
+
+/**
+ * Task sending recieved message back to peer
+ * @cls closure
+ * @tc task context
+ */
static void
task_send (void *cls,
const struct GNUNET_SCHEDULER_TaskContext *tc)
@@ -135,16 +184,20 @@
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
return;
+ if (GNUNET_YES==sent)
+ return;
+
struct GNUNET_MessageHeader * msg = cls;
unsigned int len = ntohs(msg->size);
const char * msgc = (const char *) msg;
- api->send(api->cls,p,msgc, len, 0, TIMEOUT, NULL,NULL, 0, GNUNET_NO, NULL,
NULL);
+ api->send(api->cls,p,msgc, len, 0, TIMEOUT, NULL,NULL, 0, GNUNET_NO,
&task_send_cont, NULL);
+ sent = GNUNET_YES;
}
/**
- * Initialize Environment for this plugin
+ * Recieves messages from plugin, in real world transport
*/
static struct GNUNET_TIME_Relative
receive (void *cls,
@@ -157,13 +210,11 @@
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testcase recieved new message from
peer `%s' with type %u and length %u\n",
GNUNET_i2s(peer),ntohs(message->type),ntohs(message->size));
-
-
- recieved = GNUNET_YES;
+ /* take recieved message and send it back to peer */
p = peer;
void * c = (void *) message;
+ ti_send =GNUNET_SCHEDULER_add_delayed (sched, WAIT_INTERVALL, &task_send, c);
- ti_send =GNUNET_SCHEDULER_add_delayed (sched, STAT_INTERVALL, &task_send, c);
return GNUNET_TIME_UNIT_ZERO;
}
@@ -178,35 +229,9 @@
}
/**
- * Simple example test that invokes
- * the check_address function of the plugin.
+ * Setup plugin environment
*/
-/* FIXME: won't work on IPv6 enabled systems where IPv4 mapping
- * isn't enabled (eg. FreeBSD > 4)[TESTING]
-WEAKRANDOM = YES
- */
static void
-shutdown_clean ()
-{
-/* if (stat_get_handle != NULL)
- {
- GNUNET_STATISTICS_get_cancel(stat_get_handle);
- }*/
-
- /* if ( NULL!=stats )GNUNET_STATISTICS_destroy (stats, GNUNET_YES); */
- if (ti_timeout != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel(sched,ti_timeout);
- ti_timeout = GNUNET_SCHEDULER_NO_TASK;
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Unloading http plugin\n");
- GNUNET_assert (NULL == GNUNET_PLUGIN_unload
("libgnunet_plugin_transport_http", api));
-
- GNUNET_SCHEDULER_shutdown(sched);
- /* FIXME: */ fail = GNUNET_NO;
- return;
-}
-
-static void
setup_plugin_environment ()
{
env.cfg = cfg;
@@ -219,46 +244,9 @@
env.max_connections = max_connect_per_transport;
}
-#if 0
-static int
-process_stat (void *cls,
- const char *subsystem,
- const char *name,
- uint64_t value,
- int is_persistent)
-{
- stat_get_handle = NULL;
- if (value==1)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown, plugin failed \n");
- fail = GNUNET_YES;
- shutdown_clean();
- return GNUNET_YES;
- }
- if (value==2)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown, plugin not failed \n");
- shutdown_clean();
- return GNUNET_YES;
- }
- return GNUNET_YES;
-}
-#endif
-#if 0
-static void
-cont_func (void *cls, int success)
-{
- stat_get_handle = NULL;
-}
-#endif
-
-
-
/**
- * Task that checks if we should try to download a hostlist.
- * If so, we initiate the download, otherwise we schedule
- * this task again for a later time.
+ * Task shutting down testcase if it a timeout occurs
*/
static void
task_timeout (void *cls,
@@ -268,225 +256,13 @@
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
return;
- if ( timeout_count > 1 )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testcase timeout\n", timeout_count);
- fail = GNUNET_YES;
- shutdown_clean();
- return;
- }
- timeout_count++;
-
-/* stat_get_handle = GNUNET_STATISTICS_get (stats,
- "http-transport",
- gettext_noop("shutdown"),
- GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_SECONDS, 2),
- &cont_func,
- &process_stat,
- NULL);*/
-
- ti_timeout = GNUNET_SCHEDULER_add_delayed (sched, STAT_INTERVALL,
&task_timeout, NULL);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testcase timeout\n");
+ fail = GNUNET_YES;
+ shutdown_clean();
return;
}
-#if 0
-static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *stream)
-{
- size_t retcode;
-
- /* in real-world cases, this would probably get this data differently
- as this fread() stuff is exactly what the library already would do
- by default internally */
- retcode = fread(ptr, size, nmemb, stream);
-
- fprintf(stderr, "*** We read %d bytes from file\n", (int) retcode);
-
- return retcode;
-}
-#endif
-
-struct CBC
-{
- char *buf;
- size_t pos;
- size_t size;
-};
-
-#if 0
-static size_t
-putBuffer (void *stream, size_t size, size_t nmemb, void *ptr)
-{
- size_t len;
-
- struct CBC * cbc = ptr;
-
- len = strlen(cbc->buf);
-
- if (( cbc->pos == len) && (len < (size * nmemb)))
- return 0;
- memcpy(stream, cbc->buf, len+1);
- cbc->pos = len;
- return len;
-}
-#endif
-
-#if 0
-static int execute (char * url)
-{
- done = 0;
- CURLM *multi_handle;
- CURL *curl_handle;
- CURLMsg *msg;
- int msgs_left;
- FILE * hd_src ;
- int hd ;
- struct stat file_info;
- int still_running;
- char buf[2048];
- struct CBC cbc;
-
- char *file = "curl.c";
-
- cbc.buf = buf;
- cbc.size = 2048;
- cbc.pos = 0;
-
- const char * txt = "Hello World!";
- memcpy(cbc.buf,txt,strlen(txt)+1);
- //fprintf(stderr,"%s %u\n",src,strlen(src));
-
- /* get the file size of the local file */
- hd = open(file, O_RDONLY) ;
- fstat(hd, &file_info);
- close(hd) ;
-
- /* get a FILE * of the same file, could also be made with
- fdopen() from the previous descriptor, but hey this is just
- an example! */
- hd_src = fopen(file, "rb");
- //printf("size: %u \n", (curl_off_t) file_info.st_size);
-
- /* get a curl handle */
- curl_handle = curl_easy_init();
- if( NULL == curl_handle)
- {
- printf("easy_init failed \n");
- return 0;
- }
- curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, 1L);
- //curl_easy_setopt (curl_handle, CURLOPT_WRITEFUNCTION, ©Buffer);
- //curl_easy_setopt (curl_handle, CURLOPT_WRITEDATA, &cbc);
- curl_easy_setopt (curl_handle, CURLOPT_READFUNCTION, &putBuffer);
- curl_easy_setopt (curl_handle, CURLOPT_READDATA, &cbc);
- curl_easy_setopt(curl_handle, CURLOPT_UPLOAD, 1L);
- curl_easy_setopt(curl_handle, CURLOPT_PUT, 1L);
- curl_easy_setopt(curl_handle, CURLOPT_URL, url);
- curl_easy_setopt(curl_handle, CURLOPT_INFILESIZE_LARGE, (curl_off_t)
strlen(txt));
-
- //curl_easy_setopt(curl_handle, CURLOPT_INFILESIZE_LARGE,
(curl_off_t)file_info.st_size);
-
- multi_handle = curl_multi_init();
- curl_multi_add_handle(multi_handle, curl_handle);
-
- while(CURLM_CALL_MULTI_PERFORM ==
- curl_multi_perform(multi_handle, &still_running));
-
- while(still_running)
- {
- struct timeval timeout;
- int rc; /* select() return code */
-
- fd_set fdread;
- fd_set fdwrite;
- fd_set fdexcep;
- int maxfd = -1;
-
- FD_ZERO(&fdread);
- FD_ZERO(&fdwrite);
- FD_ZERO(&fdexcep);
-
- /* set a suitable timeout to play around with */
- timeout.tv_sec = 1;
- timeout.tv_usec = 0;
-
- /* get file descriptors from the transfers */
- curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd);
-
- /* In a real-world program you OF COURSE check the return code of the
- function calls. On success, the value of maxfd is guaranteed to be
- greater or equal than -1. We call select(maxfd + 1, ...), specially
in
- case of (maxfd == -1), we call select(0, ...), which is basically
equal
- to sleep. */
-
- rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
-
- switch(rc)
- {
- case -1:
- /* select error */
- break;
- case 0:
- /* timeout, do something else */
- break;
- default:
- /* one or more of curl's file descriptors say there's data to read
- or write */
- while(CURLM_CALL_MULTI_PERFORM ==
- curl_multi_perform(multi_handle, &still_running));
- break;
- }
- }
-
- /* See how the transfers went */
- while ((msg = curl_multi_info_read(multi_handle, &msgs_left))) {
- if (msg->msg == CURLMSG_DONE) {
- int idx, found = 0;
-
- /* Find out which handle this message is about */
- for (idx=0; idx<1; idx++) {
- found = (msg->easy_handle == curl_handle);
- if(found)
- break;
- }
-
- switch (idx) {
- case 0:
- printf("HTTP transfer completed with status %d\n", msg->data.result);
- break;
- }
- }
- }
-
- curl_multi_cleanup(multi_handle);
-
- curl_easy_cleanup(curl_handle);
-
- fclose(hd_src); /* close the local file */
- return 0;
-}
-#endif
-
-#if 0
/**
- * Task that checks if we should try to download a hostlist.
- * If so, we initiate the download, otherwise we schedule
- * this task again for a later time.
- */
-static void
-task_download (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
- ti_download = GNUNET_SCHEDULER_NO_TASK;
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
-
- execute
("http://localhost:12389/Q7BO0ELEHAT8JNENQ90112G0TACH2H2HIR4IJ2JQ28U6FV14CK44EVP26FVAEALO7HIRJFLFE6709RP6IITM64B0FU7J4RA8KPNDKN8");
-
- return;
-}
-#endif
-
-/**
* Runs the test.
*
* @param cls closure
@@ -505,17 +281,6 @@
char *keyfile;
unsigned long long tneigh;
- /* settings up statistics */
-/* stats = GNUNET_STATISTICS_create (sched, "http-transport", cfg);
- if (NULL == stats)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to retrieve statistics handle\n"));
- fail = GNUNET_YES;
- shutdown_clean();
- return ;
- }*/
-
/* parse configuration */
if ((GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_number (c,
@@ -562,11 +327,8 @@
return;
}
- ti_timeout = GNUNET_SCHEDULER_add_delayed (sched, STAT_INTERVALL,
&task_timeout, NULL);
- //ti_download = GNUNET_SCHEDULER_add_now (sched, &task_download, NULL);
-
+ ti_timeout = GNUNET_SCHEDULER_add_delayed (sched, TEST_TIMEOUT,
&task_timeout, NULL);
return;
-
}
@@ -604,20 +366,7 @@
"WARNING",
#endif
NULL);
-/* GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Starting statistics service\n");
- pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-statistics",
- "gnunet-service-statistics",
- "-L", "DEBUG",
- "-c", "test_plugin_transport_data_http.conf",
NULL);
- fail = GNUNET_NO;
- if (pid==-1 )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Failed to start statistics
service\n");
- fail = GNUNET_YES;
- return fail;
- }*/
-
ret = (GNUNET_OK ==
GNUNET_PROGRAM_run (5,
argv_prog,
@@ -626,15 +375,6 @@
GNUNET_DISK_directory_remove ("/tmp/test_plugin_transport_http");
-
-/* if (0 != PLIBC_KILL (pid, SIGTERM))
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_DEBUG, "Failed to kill statistics
service");
- fail = GNUNET_YES;
- }
- if (GNUNET_OS_process_wait(pid) != GNUNET_OK)
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Killed statistics service\n");*/
return fail;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r11538 - gnunet/src/transport,
gnunet <=