[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r11576 - gnunet/src/transport
From: |
gnunet |
Subject: |
[GNUnet-SVN] r11576 - gnunet/src/transport |
Date: |
Mon, 31 May 2010 17:28:34 +0200 |
Author: wachs
Date: 2010-05-31 17:28:34 +0200 (Mon, 31 May 2010)
New Revision: 11576
Modified:
gnunet/src/transport/plugin_transport_http.c
gnunet/src/transport/test_plugin_transport_http.c
Log:
Modified: gnunet/src/transport/plugin_transport_http.c
===================================================================
--- gnunet/src/transport/plugin_transport_http.c 2010-05-31 13:21:05 UTC
(rev 11575)
+++ gnunet/src/transport/plugin_transport_http.c 2010-05-31 15:28:34 UTC
(rev 11576)
@@ -330,7 +330,7 @@
/**
* Finds a http session in our linked list using libcurl handle as a key
* Needed when sending data with libcurl to differentiate between sessions
- * @param peer peeridentity
+ * @param handle peeridentity
* @return http session corresponding to peer identity
*/
static struct Session * find_session_by_curlhandle( CURL* handle )
@@ -351,7 +351,7 @@
* Create a new session
*
* @param address address the peer is using
- * @peer peer identity
+ * @param peer identity
* @return created session object
*/
static struct Session * create_session (struct sockaddr_in *address, const
struct GNUNET_PeerIdentity *peer)
@@ -747,7 +747,7 @@
* Callback method used with libcurl
* Method is called when libcurl needs to read data during sending
* @param stream pointer where to write data
- * @param size_t size of an individual element
+ * @param size size of an individual element
* @param nmemb count of elements that can be written to the buffer
* @param ptr source pointer, passed to the libcurl handle
* @return bytes written to stream
@@ -776,7 +776,7 @@
* Callback method used with libcurl
* Method is called when libcurl needs to write data during sending
* @param stream pointer where to write data
-* @param size_t size of an individual element
+* @param size size of an individual element
* @param nmemb count of elements that can be written to the buffer
* @param ptr destination pointer, passed to the libcurl handle
* @return bytes read from stream
@@ -796,7 +796,7 @@
/**
* Function setting up file descriptors and scheduling task to run
- * @param ses session to send data to
+ * @param session session to send data to
* @return bytes sent to peer
*/
static size_t send_prepare(struct Session* session );
@@ -991,7 +991,7 @@
* @param priority how important is the message
* @param msgbuf the message to transmit
* @param msgbuf_size number of bytes in 'msgbuf'
- * @param timeout when should we time out
+ * @param to when should we time out
* @param session which session must be used (or NULL for "any")
* @param addr the address to use (can be NULL if the plugin
* is "on its own" (i.e. re-use existing TCP connection))
@@ -1143,10 +1143,42 @@
GNUNET_TRANSPORT_AddressStringCallback
asc, void *asc_cls)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"HTTP Plugin:
http_plugin_address_pretty_printer\n");
+ const struct IPv4HttpAddress *t4;
+ const struct IPv6HttpAddress *t6;
+ struct sockaddr_in a4;
+ struct sockaddr_in6 a6;
+ char * address;
+ char * ret;
+ unsigned int port;
+ if (addrlen == sizeof (struct IPv6HttpAddress))
+ {
+ address = GNUNET_malloc (INET6_ADDRSTRLEN);
+ t6 = addr;
+ a6.sin6_addr = t6->ipv6_addr;
+ inet_ntop(AF_INET6, &(a6.sin6_addr),address,INET6_ADDRSTRLEN);
+ port = ntohs(t6->u6_port);
+ }
+ else if (addrlen == sizeof (struct IPv4HttpAddress))
+ {
+ address = GNUNET_malloc (INET_ADDRSTRLEN);
+ t4 = addr;
+ a4.sin_addr.s_addr = t4->ipv4_addr;
+ inet_ntop(AF_INET, &(a4.sin_addr),address,INET_ADDRSTRLEN);
+ port = ntohs(t4->u_port);
+ }
+ else
+ {
+ /* invalid address */
+ GNUNET_break_op (0);
+ asc (asc_cls, NULL);
+ return;
+ }
- asc (asc_cls, NULL);
+ ret = GNUNET_malloc(strlen(address) +14);
+ GNUNET_asprintf(&ret,"http://%s:%u/",address,port);
+ GNUNET_free (address);
+ asc (asc_cls, ret);
}
@@ -1192,9 +1224,40 @@
const void *addr,
size_t addrlen)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"HTTP Plugin:
http_plugin_address_to_string\n");
- GNUNET_break (0);
- return NULL;
+ const struct IPv4HttpAddress *t4;
+ const struct IPv6HttpAddress *t6;
+ struct sockaddr_in a4;
+ struct sockaddr_in6 a6;
+ char * address;
+ char * ret;
+ unsigned int port;
+
+ if (addrlen == sizeof (struct IPv6HttpAddress))
+ {
+ address = GNUNET_malloc (INET6_ADDRSTRLEN);
+ t6 = addr;
+ a6.sin6_addr = t6->ipv6_addr;
+ inet_ntop(AF_INET6, &(a6.sin6_addr),address,INET6_ADDRSTRLEN);
+ port = ntohs(t6->u6_port);
+ }
+ else if (addrlen == sizeof (struct IPv4HttpAddress))
+ {
+ address = GNUNET_malloc (INET_ADDRSTRLEN);
+ t4 = addr;
+ a4.sin_addr.s_addr = t4->ipv4_addr;
+ inet_ntop(AF_INET, &(a4.sin_addr),address,INET_ADDRSTRLEN);
+ port = ntohs(t4->u_port);
+ }
+ else
+ {
+ /* invalid address */
+ return NULL;
+ }
+
+ ret = GNUNET_malloc(strlen(address) +6);
+ GNUNET_asprintf(&ret,"%s:%u",address,port);
+ GNUNET_free (address);
+ return ret;
}
/**
Modified: gnunet/src/transport/test_plugin_transport_http.c
===================================================================
--- gnunet/src/transport/test_plugin_transport_http.c 2010-05-31 13:21:05 UTC
(rev 11575)
+++ gnunet/src/transport/test_plugin_transport_http.c 2010-05-31 15:28:34 UTC
(rev 11576)
@@ -116,12 +116,33 @@
*/
static GNUNET_SCHEDULER_TaskIdentifier ti_timeout;
-
static GNUNET_SCHEDULER_TaskIdentifier ti_send;
const struct GNUNET_PeerIdentity * p;
+/**
+ * Struct for plugin addresses
+ */
+struct Plugin_Address
+{
+ /**
+ * Next field for linked list
+ */
+ struct Plugin_Address * next;
+ /**
+ * buffer containing data to send
+ */
+ void * addr;
+
+ /**
+ * amount of data to sent
+ */
+ size_t addrlen;
+};
+
+struct Plugin_Address * addr_head;
+
/**
* Did the test pass or fail?
*/
@@ -134,6 +155,21 @@
/**
* Did the test pass or fail?
*/
+static int fail_pretty_printer;
+
+/**
+ * Did the test pass or fail?
+ */
+static int fail_pretty_printer_count;
+
+/**
+ * Did the test pass or fail?
+ */
+static int fail_addr_to_str;
+
+/**
+ * Did the test pass or fail?
+ */
static int fail;
/**
@@ -158,7 +194,6 @@
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));
@@ -278,8 +313,9 @@
{
char * address = NULL;
unsigned int port;
+ struct Plugin_Address * pl_addr;
+ struct Plugin_Address * cur;
-
if (addrlen == (sizeof (struct IPv4HttpAddress)))
{
address = GNUNET_malloc (INET_ADDRSTRLEN);
@@ -294,8 +330,28 @@
port = ntohs(((struct IPv6HttpAddress *) addr)->u6_port);
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Transport plugin notification for
address: `%s':%u\n"),address,port);
+
+ pl_addr = GNUNET_malloc (sizeof (struct Plugin_Address) );
+ pl_addr->addrlen = addrlen;
+ pl_addr->addr = GNUNET_malloc(addrlen);
+ memcpy(pl_addr->addr,addr,addrlen);
+ pl_addr->next = NULL;
+
+ if ( NULL == addr_head)
+ {
+ addr_head = pl_addr;
+ }
+ else
+ {
+ cur = addr_head;
+ while (NULL != cur->next)
+ {
+ cur = cur->next;
+ }
+ cur->next = pl_addr;
+ }
+
fail_notify_address_count++;
-
fail_notify_address = GNUNET_NO;
}
@@ -333,7 +389,16 @@
return;
}
+static void pretty_printer_cb (void *cls,
+ const char *address)
+{
+ if (NULL==address)
+ return;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Plugin returned: `%s'\n",address);
+ fail_pretty_printer_count++;
+}
+
/**
* Runs the test.
*
@@ -352,7 +417,16 @@
cfg = c;
char *keyfile;
unsigned long long tneigh;
+ struct Plugin_Address * cur;
+ struct Plugin_Address * tmp;
+ const char * addr_str;
+ unsigned int count_str_addr;
+ fail_pretty_printer = GNUNET_YES;
+ fail_notify_address = GNUNET_YES;
+ fail_addr_to_str = GNUNET_YES;
+ addr_head = NULL;
+ count_str_addr = 0;
/* parse configuration */
if ((GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_number (c,
@@ -403,18 +477,36 @@
ti_timeout = GNUNET_SCHEDULER_add_delayed (sched, TEST_TIMEOUT,
&task_timeout, NULL);
/* testing plugin functionality */
+ GNUNET_assert (0!=fail_notify_address_count);
GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Transport plugin returned %u
addresses to connect to\n"), fail_notify_address_count);
- /* testing finished, shutting down */
+ /* testing pretty printer with all addresses obtained from the plugin*/
+ while (addr_head != NULL)
+ {
+ cur = addr_head;
- if (fail_notify_address == GNUNET_NO)
- fail = 0;
+
api->address_pretty_printer(NULL,"http",cur->addr,cur->addrlen,GNUNET_NO,TEST_TIMEOUT,&pretty_printer_cb,NULL);
+ addr_str = api->address_to_string(NULL,cur->addr,cur->addrlen);
+ GNUNET_assert (NULL != addr_str);
+ count_str_addr++;
+ tmp = addr_head->next;
+ GNUNET_free (addr_head->addr);
+ GNUNET_free (addr_head);
+ GNUNET_free ((char *) addr_str);
+ addr_head=tmp;
+ }
+ GNUNET_assert (fail_pretty_printer_count==fail_notify_address_count);
+ GNUNET_assert (fail_pretty_printer_count==count_str_addr);
+ fail_pretty_printer=GNUNET_NO;
+ fail_addr_to_str=GNUNET_NO;
-
+ /* testing finished, shutting down */
+ if ((fail_notify_address == GNUNET_NO) && (fail_pretty_printer == GNUNET_NO)
&& (fail_addr_to_str == GNUNET_NO) )
+ fail = 0;
+ else
+ fail = 1;
shutdown_clean();
-
-
return;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r11576 - gnunet/src/transport,
gnunet <=