[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r11545 - gnunet/src/transport
From: |
gnunet |
Subject: |
[GNUnet-SVN] r11545 - gnunet/src/transport |
Date: |
Fri, 28 May 2010 11:21:10 +0200 |
Author: wachs
Date: 2010-05-28 11:21:09 +0200 (Fri, 28 May 2010)
New Revision: 11545
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-28 07:08:33 UTC
(rev 11544)
+++ gnunet/src/transport/plugin_transport_http.c 2010-05-28 09:21:09 UTC
(rev 11545)
@@ -69,11 +69,31 @@
*/
struct Plugin;
-struct CBC
+/**
+ * Message to send using http
+ */
+struct HTTP_Message
{
+ /**
+ * Next field for linked list
+ */
+ struct HTTP_Message * next;
+
+ /**
+ * buffer containing data to send
+ */
char *buf;
+
+ /**
+ * amount of data already sent
+ */
size_t pos;
+
+ /**
+ * amount of data to sent
+ */
size_t size;
+
size_t len;
};
@@ -164,7 +184,7 @@
*/
struct GNUNET_CRYPTO_HashAsciiEncoded hash;
- struct CBC cbc;
+ struct HTTP_Message * pending_outbound_msg;;
CURL *curl_handle;
};
@@ -244,26 +264,7 @@
*/
static struct GNUNET_CRYPTO_HashAsciiEncoded my_ascii_hash_ident;
-static char buf[2048];
-
/**
- * Message-Packet header.
- */
-struct HTTPMessage
-{
- /**
- * size of the message, in bytes, including this header.
- */
- struct GNUNET_MessageHeader header;
-
- /**
- * What is the identity of the sender (GNUNET_hash of public key)
- */
- struct GNUNET_PeerIdentity sender;
-
-};
-
-/**
* Finds a http session in our linked list using peer identity as a key
* @param peer peeridentity
* @return http session corresponding to peer identity
@@ -645,19 +646,63 @@
return;
}
+/**
+ * Removes a message from the linked list of messages
+ */
+
+static int remove_http_message(struct Session * ses, struct HTTP_Message * msg)
+{
+ struct HTTP_Message * cur;
+ struct HTTP_Message * next;
+
+ cur = ses->pending_outbound_msg;
+ next = NULL;
+
+ if (cur == NULL)
+ return GNUNET_SYSERR;
+
+ if (cur == msg)
+ {
+ ses->pending_outbound_msg = cur->next;
+ GNUNET_free (cur->buf);
+ GNUNET_free (cur);
+ return GNUNET_OK;
+ }
+
+ while (cur->next!=msg)
+ {
+ if (cur->next != NULL)
+ cur = cur->next;
+ else
+ return GNUNET_SYSERR;
+ }
+
+ cur->next = cur->next->next;
+ GNUNET_free (cur->next->buf);
+ GNUNET_free (cur->next);
+ return GNUNET_OK;
+
+
+}
+
static size_t send_read_callback(void *stream, size_t size, size_t nmemb, void
*ptr)
{
- struct Session * ses = ptr;
- struct CBC * cbc = &(ses->cbc);
+ struct Session * ses = ptr;
+ struct HTTP_Message * msg = ses->pending_outbound_msg;
+ unsigned int bytes_sent;
- if (cbc->len > (size * nmemb))
+ bytes_sent = 0;
+ if (msg->len > (size * nmemb))
return CURL_READFUNC_ABORT;
- if (( cbc->pos == cbc->len) && (cbc->len < (size * nmemb)))
- return 0;
- memcpy(stream, cbc->buf, cbc->len);
- cbc->pos = cbc->len;
- return cbc->len;
+ if (( msg->pos < msg->len) && (msg->len < (size * nmemb)))
+ {
+ memcpy(stream, msg->buf, msg->len);
+ msg->pos = msg->len;
+ bytes_sent = msg->len;
+ }
+
+ return bytes_sent;
}
@@ -707,12 +752,15 @@
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Send to %s completed.\n", cs->ip);
- /* Calling transmit continuation */
- if ( NULL != cs->transmit_cont)
- cs->transmit_cont (NULL,&cs->sender,GNUNET_OK);
+ if (GNUNET_OK != remove_http_message(cs,
cs->pending_outbound_msg))
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Message removed
from session `%s'", GNUNET_i2s(&cs->sender));
curl_easy_cleanup(cs->curl_handle);
cs->curl_handle=NULL;
+
+ /* Calling transmit continuation */
+ if ( NULL != cs->transmit_cont)
+ cs->transmit_cont (NULL,&cs->sender,GNUNET_OK);
}
return;
default:
@@ -825,6 +873,8 @@
{
struct Session* ses;
struct Session* ses_temp;
+ struct HTTP_Message * msg;
+ struct HTTP_Message * tmp;
int bytes_sent = 0;
CURLMcode mret;
char * url;
@@ -877,16 +927,48 @@
if ( NULL != cont)
ses->transmit_cont = cont;
- (ses->cbc).len = msgbuf_size;
- (ses->cbc).buf = buf;
- memcpy(ses->cbc.buf,msgbuf,msgbuf_size);
+ /* setting up message */
+ msg = GNUNET_malloc (sizeof (struct HTTP_Message));
+ msg->next = NULL;
+ msg->len = msgbuf_size;
+ msg->pos = 0;
+ msg->buf = GNUNET_malloc (msgbuf_size);
+ memcpy (msg->buf,msgbuf, msgbuf_size);
+ /* insert created message in list of pending messages */
+
+ if (ses->pending_outbound_msg == NULL)
+ {
+ ses->pending_outbound_msg = msg;
+ }
+ tmp = ses->pending_outbound_msg;
+ while ( NULL != tmp->next)
+ {
+ tmp = tmp->next;
+ }
+ if ( tmp != msg)
+ tmp->next = msg;
+
+ struct HTTP_Message * msg2 = GNUNET_malloc (sizeof (struct HTTP_Message));
+
+ if (ses->pending_outbound_msg == NULL)
+ {
+ ses->pending_outbound_msg = msg2;
+ }
+ tmp = ses->pending_outbound_msg;
+ while ( NULL != tmp->next)
+ {
+ tmp = tmp->next;
+ }
+ if ( tmp != msg2)
+ tmp->next = msg2;
+
/* curl_easy_setopt(ses->curl_handle, CURLOPT_VERBOSE, 1L); */
curl_easy_setopt(ses->curl_handle, CURLOPT_URL, url);
curl_easy_setopt(ses->curl_handle, CURLOPT_PUT, 1L);
curl_easy_setopt(ses->curl_handle, CURLOPT_READFUNCTION, send_read_callback);
curl_easy_setopt(ses->curl_handle, CURLOPT_READDATA, ses);
- curl_easy_setopt(ses->curl_handle, CURLOPT_INFILESIZE_LARGE, (curl_off_t)
(ses->cbc).len);
+ curl_easy_setopt(ses->curl_handle, CURLOPT_INFILESIZE_LARGE, (curl_off_t)
msg->len);
curl_easy_setopt(ses->curl_handle, CURLOPT_TIMEOUT, (timeout.value / 1000 ));
curl_easy_setopt(ses->curl_handle, CURLOPT_CONNECTTIMEOUT,
HTTP_CONNECT_TIMEOUT);
Modified: gnunet/src/transport/test_plugin_transport_http.c
===================================================================
--- gnunet/src/transport/test_plugin_transport_http.c 2010-05-28 07:08:33 UTC
(rev 11544)
+++ gnunet/src/transport/test_plugin_transport_http.c 2010-05-28 09:21:09 UTC
(rev 11545)
@@ -52,7 +52,7 @@
/**
* How long until we give up on transmitting the message?
*/
-#define TEST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
5)
+#define TEST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
20)
/**
* How long between recieve and send?
@@ -153,7 +153,8 @@
GNUNET_assert (NULL == GNUNET_PLUGIN_unload
("libgnunet_plugin_transport_http", api));
GNUNET_SCHEDULER_shutdown(sched);
- /* FIXME: */ fail = GNUNET_NO;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Exiting testcase\n");
+ exit(fail);
return;
}
@@ -263,6 +264,7 @@
return;
}
+
/**
* Runs the test.
*
@@ -329,6 +331,10 @@
}
ti_timeout = GNUNET_SCHEDULER_add_delayed (sched, TEST_TIMEOUT,
&task_timeout, NULL);
+
+
+
+
return;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r11545 - gnunet/src/transport,
gnunet <=