[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r6613 - GNUnet/src/applications/fs/gap
From: |
gnunet |
Subject: |
[GNUnet-SVN] r6613 - GNUnet/src/applications/fs/gap |
Date: |
Mon, 24 Mar 2008 21:15:24 -0600 (MDT) |
Author: grothoff
Date: 2008-03-24 21:15:24 -0600 (Mon, 24 Mar 2008)
New Revision: 6613
Modified:
GNUnet/src/applications/fs/gap/fs.c
GNUnet/src/applications/fs/gap/querymanager.c
GNUnet/src/applications/fs/gap/shared.c
GNUnet/src/applications/fs/gap/shared.h
Log:
fixing large-file downloads of indexed content
Modified: GNUnet/src/applications/fs/gap/fs.c
===================================================================
--- GNUnet/src/applications/fs/gap/fs.c 2008-03-24 15:34:34 UTC (rev 6612)
+++ GNUnet/src/applications/fs/gap/fs.c 2008-03-25 03:15:24 UTC (rev 6613)
@@ -407,13 +407,8 @@
value, void *closure, unsigned long long uid)
{
struct FPPClosure *cls = closure;
- struct GNUNET_ClientHandle *sock = cls->sock;
+ GNUNET_HashCode hc;
struct ResponseList *rl;
- const DBlock *dblock;
- CS_fs_reply_content_MESSAGE *msg;
- unsigned int size;
- GNUNET_DatastoreValue *enc;
- const GNUNET_DatastoreValue *use;
unsigned int type;
int ret;
@@ -422,37 +417,22 @@
cls->have_more = GNUNET_YES;
return GNUNET_SYSERR;
}
- cls->processed++;
- size = ntohl (value->size) - sizeof (GNUNET_DatastoreValue);
- dblock = (const DBlock *) &value[1];
- enc = NULL;
- if ((ntohl (dblock->type) == GNUNET_ECRS_BLOCKTYPE_ONDEMAND) &&
- (GNUNET_OK != GNUNET_FS_ONDEMAND_get_indexed_content (value,
- key, &enc)))
- return GNUNET_OK; /* data corrupt, continue to search */
- if (enc == NULL)
- use = value;
- else
- use = enc;
- size = ntohl (use->size) - sizeof (GNUNET_DatastoreValue);
- dblock = (const DBlock *) &use[1];
- msg = GNUNET_malloc (sizeof (CS_fs_reply_content_MESSAGE) + size);
- msg->header.type = htons (GNUNET_CS_PROTO_GAP_RESULT);
- msg->header.size = htons (sizeof (CS_fs_reply_content_MESSAGE) + size);
- msg->anonymityLevel = use->anonymityLevel;
- msg->expirationTime = use->expirationTime;
- memcpy (&msg[1], dblock, size);
- type = ntohl (dblock->type);
- GNUNET_free_non_null (enc);
- ret = coreAPI->cs_send_to_client (sock, &msg->header,
- GNUNET_NO);
- GNUNET_free (msg);
+ type = ntohl(((const DBlock*) &value[1])->type);
+ ret = GNUNET_FS_HELPER_send_to_client(coreAPI,
+ key,
+ value,
+ cls->sock,
+ NULL,
+ &hc);
if (ret == GNUNET_NO)
+ return GNUNET_NO; /* delete + continue */
+ cls->processed++;
+ if (ret != GNUNET_OK)
cls->have_more = GNUNET_YES; /* switch to async processing */
if ((type == GNUNET_ECRS_BLOCKTYPE_DATA) || (ret != GNUNET_OK))
- return GNUNET_SYSERR; /* unique response or client can take no more
*/
+ return GNUNET_SYSERR; /* unique response or client can take no more
*/
rl = GNUNET_malloc (sizeof (struct ResponseList));
- GNUNET_hash (dblock, size, &rl->hash);
+ rl->hash = hc;
rl->next = cls->seen;
cls->seen = rl;
return GNUNET_OK;
Modified: GNUnet/src/applications/fs/gap/querymanager.c
===================================================================
--- GNUnet/src/applications/fs/gap/querymanager.c 2008-03-24 15:34:34 UTC
(rev 6612)
+++ GNUnet/src/applications/fs/gap/querymanager.c 2008-03-25 03:15:24 UTC
(rev 6613)
@@ -289,13 +289,15 @@
msg->anonymityLevel = htonl (0); /* unknown */
msg->expirationTime = GNUNET_htonll (expirationTime);
memcpy (&msg[1], data, size);
- coreAPI->cs_send_to_client (client,
- &msg->header,
- (rl->type != GNUNET_ECRS_BLOCKTYPE_DATA)
- ? GNUNET_NO : GNUNET_YES);
+ ret = coreAPI->cs_send_to_client (client,
+ &msg->header,
+ (rl->type != GNUNET_ECRS_BLOCKTYPE_DATA)
+ ? GNUNET_NO : GNUNET_YES);
+ GNUNET_free (msg);
+ if (ret != GNUNET_OK)
+ return GNUNET_NO;
if (stats != NULL)
stats->change (stat_gap_client_response_sent, 1);
- GNUNET_free (msg);
/* update *value */
*value += 1 + rl->value;
@@ -469,32 +471,21 @@
value, void *closure, unsigned long long uid)
{
struct HMClosure *cls = closure;
- const DBlock *dblock;
GNUNET_HashCode hc;
- CS_fs_reply_content_MESSAGE *msg;
- unsigned int size;
int ret;
- size = ntohl (value->size) - sizeof (GNUNET_DatastoreValue);
- dblock = (const DBlock *) &value[1];
- if (GNUNET_OK == GNUNET_FS_SHARED_test_valid_new_response (cls->request,
- key,
- size,
- dblock, &hc))
+ ret = GNUNET_FS_HELPER_send_to_client(coreAPI,
+ key, value,
+ cls->request->response_client,
+ cls->request,
+ &hc);
+ if (ret != GNUNET_OK)
{
- msg = GNUNET_malloc (sizeof (CS_fs_reply_content_MESSAGE) + size);
- msg->header.type = htons (GNUNET_CS_PROTO_GAP_RESULT);
- msg->header.size = htons (sizeof (CS_fs_reply_content_MESSAGE) + size);
- msg->anonymityLevel = value->anonymityLevel;
- msg->expirationTime = value->expirationTime;
- memcpy (&msg[1], dblock, size);
- ret = coreAPI->cs_send_to_client (cls->request->response_client,
- &msg->header, GNUNET_YES);
- GNUNET_free (msg);
- if (ret != GNUNET_OK)
- return GNUNET_SYSERR; /* client can take no more */
- GNUNET_FS_SHARED_mark_response_seen (cls->request, &hc);
+ /* client can take no more right now */
+ cls->have_more = GNUNET_YES;
+ return ret; /* NO: delete, SYSERR: abort */
}
+ GNUNET_FS_SHARED_mark_response_seen (cls->request, &hc);
cls->processed++;
if (cls->processed > MAX_ASYNC_PROCESSED)
{
Modified: GNUnet/src/applications/fs/gap/shared.c
===================================================================
--- GNUnet/src/applications/fs/gap/shared.c 2008-03-24 15:34:34 UTC (rev
6612)
+++ GNUnet/src/applications/fs/gap/shared.c 2008-03-25 03:15:24 UTC (rev
6613)
@@ -27,6 +27,7 @@
#include "platform.h"
#include "gnunet_protocols.h"
#include "shared.h"
+#include "ondemand.h"
#include "fs.h"
/**
@@ -218,5 +219,75 @@
return ttl_in;
}
+/**
+ * Send a response to a local client.
+ *
+ * @param request used to check if the response is new and
+ * unique, maybe NULL (skip test in that case)
+ * @param hc set to hash of the message by this function
+ *
+ * @return GNUNET_OK on success,
+ * GNUNET_NO if the block should be deleted
+ * GNUNET_SYSERR to retry later
+ */
+int
+GNUNET_FS_HELPER_send_to_client(GNUNET_CoreAPIForPlugins * coreAPI,
+ const GNUNET_HashCode * key,
+ const GNUNET_DatastoreValue * value,
+ struct GNUNET_ClientHandle * client,
+ struct RequestList * request,
+ GNUNET_HashCode * hc)
+{
+ const DBlock *dblock;
+ CS_fs_reply_content_MESSAGE *msg;
+ unsigned int size;
+ GNUNET_DatastoreValue *enc;
+ const GNUNET_DatastoreValue *use;
+ int ret;
+ size = ntohl (value->size) - sizeof (GNUNET_DatastoreValue);
+ dblock = (const DBlock *) &value[1];
+ enc = NULL;
+ if ((ntohl (dblock->type) == GNUNET_ECRS_BLOCKTYPE_ONDEMAND) &&
+ (GNUNET_OK != GNUNET_FS_ONDEMAND_get_indexed_content (value,
+ key, &enc)))
+ {
+ return GNUNET_NO; /* data corrupt: delete block! */
+ }
+ if (enc == NULL)
+ use = value;
+ else
+ use = enc;
+ size = ntohl (use->size) - sizeof (GNUNET_DatastoreValue);
+ dblock = (const DBlock *) &use[1];
+ if (request != NULL)
+ {
+ if (GNUNET_OK != GNUNET_FS_SHARED_test_valid_new_response (request,
+ key,
+ size,
+ dblock, hc))
+ {
+ GNUNET_free_non_null (enc);
+ return GNUNET_SYSERR; /* duplicate or invalid */
+ }
+ }
+ else
+ {
+ GNUNET_hash (dblock, size, hc);
+ }
+ msg = GNUNET_malloc (sizeof (CS_fs_reply_content_MESSAGE) + size);
+ msg->header.type = htons (GNUNET_CS_PROTO_GAP_RESULT);
+ msg->header.size = htons (sizeof (CS_fs_reply_content_MESSAGE) + size);
+ msg->anonymityLevel = use->anonymityLevel;
+ msg->expirationTime = use->expirationTime;
+ memcpy (&msg[1], dblock, size);
+ GNUNET_free_non_null (enc);
+ ret = coreAPI->cs_send_to_client (client, &msg->header,
+ GNUNET_NO);
+ GNUNET_free (msg);
+ if (ret == GNUNET_OK)
+ return GNUNET_OK;
+ return GNUNET_SYSERR;
+}
+
/* end of shared.c */
Modified: GNUnet/src/applications/fs/gap/shared.h
===================================================================
--- GNUnet/src/applications/fs/gap/shared.h 2008-03-24 15:34:34 UTC (rev
6612)
+++ GNUnet/src/applications/fs/gap/shared.h 2008-03-25 03:15:24 UTC (rev
6613)
@@ -27,6 +27,7 @@
#define SHARED_H
#include "gnunet_util.h"
+#include "gnunet_core.h"
#include "ecrs_core.h"
#include "pid_table.h"
#include "gap.h"
@@ -362,4 +363,25 @@
*/
int GNUNET_FS_HELPER_bound_ttl (int ttl_in, unsigned int prio);
+
+/**
+ * Send a response to a local client.
+ *
+ * @param request used to check if the response is new and
+ * unique, maybe NULL (skip test in that case)
+ * @param hc set to hash of the message by this function
+ *
+ * @return GNUNET_OK on success,
+ * GNUNET_NO on temporary failure,
+ * GNUNET_SYSERR on serious error
+ */
+int
+GNUNET_FS_HELPER_send_to_client(GNUNET_CoreAPIForPlugins * coreAPI,
+ const GNUNET_HashCode * key,
+ const GNUNET_DatastoreValue * value,
+ struct GNUNET_ClientHandle * client,
+ struct RequestList * request,
+ GNUNET_HashCode * hc);
+
+
#endif
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r6613 - GNUnet/src/applications/fs/gap,
gnunet <=