/**
* Context for sending replies.
*/
- struct GNUNET_CONNECTION_TransmitHandle *th;
+ struct GNUNET_SERVER_TransmitHandle *th;
};
cr->kill_task = GNUNET_SCHEDULER_NO_TASK;
lc = cr->lc;
GNUNET_CONTAINER_DLL_remove (lc->cr_head, lc->cr_tail, cr);
- GSF_pending_request_cancel_ (cr->pr, GNUNET_NO);
+ GSF_pending_request_cancel_ (cr->pr, GNUNET_YES);
GNUNET_STATISTICS_update (GSF_stats,
- gettext_noop ("# client searches active"),
- -1, GNUNET_NO);
+ gettext_noop ("# client searches active"), -1,
+ GNUNET_NO);
GNUNET_free (cr);
}
* Handle a reply to a pending request. Also called if a request
* expires (then with data == NULL). The handler may be called
* many times (depending on the request type), but will not be
- * called during or after a call to GSF_pending_request_cancel
+ * called during or after a call to GSF_pending_request_cancel
* and will also not be called anymore after a call signalling
* expiration.
*
* @param eval evaluation of the result
* @param pr handle to the original pending request
* @param reply_anonymity_level anonymity level for the reply, UINT32_MAX for "unknown"
- * @param expiration when does 'data' expire?
+ * @param expiration when does 'data' expire?
+ * @param last_transmission when was the last time we've tried to download this block? (FOREVER if unknown)
* @param type type of the block
* @param data response data, NULL on request expiration
* @param data_len number of bytes in data
*/
static void
-client_response_handler (void *cls,
- enum GNUNET_BLOCK_EvaluationResult eval,
+client_response_handler (void *cls, enum GNUNET_BLOCK_EvaluationResult eval,
struct GSF_PendingRequest *pr,
uint32_t reply_anonymity_level,
struct GNUNET_TIME_Absolute expiration,
- enum GNUNET_BLOCK_Type type,
- const void *data, size_t data_len)
+ struct GNUNET_TIME_Absolute last_transmission,
+ enum GNUNET_BLOCK_Type type, const void *data,
+ size_t data_len)
{
struct ClientRequest *cr = cls;
struct GSF_LocalClient *lc;
- struct PutMessage *pm;
+ struct ClientPutMessage *pm;
const struct GSF_PendingRequestData *prd;
size_t msize;
GNUNET_NO);
GNUNET_assert (pr == cr->pr);
lc = cr->lc;
- msize = sizeof (struct PutMessage) + data_len;
+ msize = sizeof (struct ClientPutMessage) + data_len;
{
- char buf[msize];
+ char buf[msize] GNUNET_ALIGN;
- pm = (struct PutMessage *) buf;
+ pm = (struct ClientPutMessage *) buf;
pm->header.type = htons (GNUNET_MESSAGE_TYPE_FS_PUT);
pm->header.size = htons (msize);
pm->type = htonl (type);
pm->expiration = GNUNET_TIME_absolute_hton (expiration);
+ pm->last_transmission = GNUNET_TIME_absolute_hton (last_transmission);
+ pm->num_transmissions = htonl (prd->num_transmissions);
+ pm->respect_offered = htonl (prd->respect_offered);
memcpy (&pm[1], data, data_len);
GSF_local_client_transmit_ (lc, &pm->header);
}
-#if DEBUG_FS_CLIENT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Queued reply to query `%s' for local client\n",
GNUNET_h2s (&prd->query), (unsigned int) prd->type);
-#endif
if (eval != GNUNET_BLOCK_EVALUATION_OK_LAST)
return;
- cr->kill_task = GNUNET_SCHEDULER_add_now (&client_request_destroy, cr);
+ if (GNUNET_SCHEDULER_NO_TASK != cr->kill_task)
+ cr->kill_task = GNUNET_SCHEDULER_add_now (&client_request_destroy, cr);
}
/**
* Handle START_SEARCH-message (search request from local client).
+ * Only responsible for creating the request entry itself and setting
+ * up reply callback and cancellation on client disconnect. Does NOT
+ * execute the actual request strategy (planning).
*
* @param client identification of the client
* @param message the actual message
- * @return pending request handle for the request, NULL on error
+ * @param prptr where to store the pending request handle for the request
+ * @return GNUNET_YES to start local processing,
+ * GNUNET_NO to not (yet) start local processing,
+ * GNUNET_SYSERR on error
*/
-struct GSF_PendingRequest *
+int
GSF_local_client_start_search_handler_ (struct GNUNET_SERVER_Client *client,
const struct GNUNET_MessageHeader
- *message)
+ *message,
+ struct GSF_PendingRequest **prptr)
{
- static GNUNET_HashCode all_zeros;
+ static struct GNUNET_HashCode all_zeros;
const struct SearchMessage *sm;
struct GSF_LocalClient *lc;
struct ClientRequest *cr;
msize = ntohs (message->size);
if ((msize < sizeof (struct SearchMessage)) ||
- (0 != (msize - sizeof (struct SearchMessage)) % sizeof (GNUNET_HashCode)))
+ (0 != (msize - sizeof (struct SearchMessage)) % sizeof (struct GNUNET_HashCode)))
{
GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return NULL;
+ *prptr = NULL;
+ return GNUNET_SYSERR;
}
GNUNET_STATISTICS_update (GSF_stats,
- gettext_noop ("# client searches received"),
- 1, GNUNET_NO);
- sc = (msize - sizeof (struct SearchMessage)) / sizeof (GNUNET_HashCode);
+ gettext_noop ("# client searches received"), 1,
+ GNUNET_NO);
+ sc = (msize - sizeof (struct SearchMessage)) / sizeof (struct GNUNET_HashCode);
sm = (const struct SearchMessage *) message;
type = ntohl (sm->type);
-#if DEBUG_FS_CLIENT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received request for `%s' of type %u from local client\n",
GNUNET_h2s (&sm->query), (unsigned int) type);
-#endif
lc = GSF_local_client_lookup_ (client);
-
+ cr = NULL;
/* detect duplicate KBLOCK requests */
if ((type == GNUNET_BLOCK_TYPE_FS_KBLOCK) ||
(type == GNUNET_BLOCK_TYPE_FS_NBLOCK) || (type == GNUNET_BLOCK_TYPE_ANY))
{
- /* FIXME: this does currently not work to filter duplicate
- * results from *local* datastore since the local store is
- * queried before we continue to process additional
- * messages from the client! -- fix protocol? */
cr = lc->cr_head;
while (cr != NULL)
{
prd = GSF_pending_request_get_data_ (cr->pr);
- if ((0 != memcmp (&prd->query,
- &sm->query,
- sizeof (GNUNET_HashCode))) && (prd->type == type))
+ /* only unify with queries that hae not yet started local processing
+ (SEARCH_MESSAGE_OPTION_CONTINUED was always set) and that have a
+ matching query and type */
+ if ((GNUNET_YES != prd->has_started) &&
+ (0 != memcmp (&prd->query, &sm->query, sizeof (struct GNUNET_HashCode))) &&
+ (prd->type == type))
break;
cr = cr->next;
}
- if (cr != NULL)
- {
-#if DEBUG_FS_CLIENT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Have existing request, merging content-seen lists.\n");
-#endif
- GSF_pending_request_update_ (cr->pr,
- (const GNUNET_HashCode *) &sm[1], sc);
- GNUNET_STATISTICS_update (GSF_stats,
- gettext_noop
- ("# client searches updated (merged content seen list)"),
- 1, GNUNET_NO);
- GNUNET_SERVER_receive_done (client, GNUNET_OK);
- return NULL;
- }
}
-
- GNUNET_STATISTICS_update (GSF_stats,
- gettext_noop ("# client searches active"),
- 1, GNUNET_NO);
- cr = GNUNET_malloc (sizeof (struct ClientRequest));
- cr->lc = lc;
- GNUNET_CONTAINER_DLL_insert (lc->cr_head, lc->cr_tail, cr);
- options = GSF_PRO_LOCAL_REQUEST;
- if (0 != (1 & ntohl (sm->options)))
- options |= GSF_PRO_LOCAL_ONLY;
- cr->pr = GSF_pending_request_create_ (options, type, &sm->query, (type == GNUNET_BLOCK_TYPE_FS_SBLOCK) ? &sm->target /* namespace */
- : NULL,
- (0 != memcmp (&sm->target,
- &all_zeros,
- sizeof (GNUNET_HashCode)))
- ? (const struct GNUNET_PeerIdentity *)
- &sm->target : NULL, NULL, 0,
- 0 /* bf */ ,
- ntohl (sm->anonymity_level),
- 0 /* priority */ ,
- 0 /* ttl */ ,
- 0 /* sender PID */ ,
- (const GNUNET_HashCode *) &sm[1], sc,
- &client_response_handler, cr);
- return cr->pr;
+ if (cr != NULL)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Have existing request, merging content-seen lists.\n");
+ GSF_pending_request_update_ (cr->pr, (const struct GNUNET_HashCode *) &sm[1], sc);
+ GNUNET_STATISTICS_update (GSF_stats,
+ gettext_noop
+ ("# client searches updated (merged content seen list)"),
+ 1, GNUNET_NO);
+ }
+ else
+ {
+ GNUNET_STATISTICS_update (GSF_stats,
+ gettext_noop ("# client searches active"), 1,
+ GNUNET_NO);
+ cr = GNUNET_malloc (sizeof (struct ClientRequest));
+ cr->lc = lc;
+ GNUNET_CONTAINER_DLL_insert (lc->cr_head, lc->cr_tail, cr);
+ options = GSF_PRO_LOCAL_REQUEST;
+ if (0 != (SEARCH_MESSAGE_OPTION_LOOPBACK_ONLY & ntohl (sm->options)))
+ options |= GSF_PRO_LOCAL_ONLY;
+ cr->pr = GSF_pending_request_create_ (options, type, &sm->query, (type == GNUNET_BLOCK_TYPE_FS_SBLOCK) ? &sm->target /* namespace */
+ : NULL,
+ (0 !=
+ memcmp (&sm->target, &all_zeros,
+ sizeof (struct GNUNET_HashCode)))
+ ? (const struct GNUNET_PeerIdentity *)
+ &sm->target : NULL, NULL, 0,
+ 0 /* bf */ ,
+ ntohl (sm->anonymity_level),
+ 0 /* priority */ ,
+ 0 /* ttl */ ,
+ 0 /* sender PID */ ,
+ 0 /* origin PID */ ,
+ (const struct GNUNET_HashCode *) &sm[1], sc,
+ &client_response_handler, cr);
+ }
+ *prptr = cr->pr;
+ return (0 !=
+ (SEARCH_MESSAGE_OPTION_CONTINUED & ntohl (sm->options))) ? GNUNET_NO :
+ GNUNET_YES;
}
GNUNET_free (res);
}
if (NULL != res)
- lc->th = GNUNET_SERVER_notify_transmit_ready (lc->client,
- res->msize,
- GNUNET_TIME_UNIT_FOREVER_REL,
- &transmit_to_client, lc);
+ lc->th =
+ GNUNET_SERVER_notify_transmit_ready (lc->client, res->msize,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ &transmit_to_client, lc);
return msize;
}
memcpy (&res[1], msg, msize);
GNUNET_CONTAINER_DLL_insert_tail (lc->res_head, lc->res_tail, res);
if (NULL == lc->th)
- lc->th = GNUNET_SERVER_notify_transmit_ready (lc->client,
- msize,
- GNUNET_TIME_UNIT_FOREVER_REL,
- &transmit_to_client, lc);
+ lc->th =
+ GNUNET_SERVER_notify_transmit_ready (lc->client, msize,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ &transmit_to_client, lc);
}
while (NULL != (cr = pos->cr_head))
{
GNUNET_CONTAINER_DLL_remove (pos->cr_head, pos->cr_tail, cr);
- GSF_pending_request_cancel_ (cr->pr, GNUNET_NO);
+ GSF_pending_request_cancel_ (cr->pr, GNUNET_YES);
GNUNET_STATISTICS_update (GSF_stats,
- gettext_noop ("# client searches active"),
- -1, GNUNET_NO);
+ gettext_noop ("# client searches active"), -1,
+ GNUNET_NO);
if (GNUNET_SCHEDULER_NO_TASK != cr->kill_task)
GNUNET_SCHEDULER_cancel (cr->kill_task);
GNUNET_free (cr);
}
if (pos->th != NULL)
{
- GNUNET_CONNECTION_notify_transmit_ready_cancel (pos->th);
+ GNUNET_SERVER_notify_transmit_ready_cancel (pos->th);
pos->th = NULL;
}
GSF_handle_local_client_disconnect_ (pos);