#define GNUNET_MESSAGE_TYPE_PEERSTORE_STORE 820
/**
- * Store result message
+ * Iteration request
*/
-#define GNUNET_MESSAGE_TYPE_PEERSTORE_STORE_RESULT_OK 821
+#define GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE 821
/**
- * Iteration request
+ * Iteration record message
*/
-#define GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE 823
+#define GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_RECORD 822
/**
- * Iteration response messages
+ * Iteration end message
*/
-#define GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_RECORD 824
-#define GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_END 825
+#define GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_END 823
/**
* Watch request
*/
-#define GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH 826
+#define GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH 824
/**
* Watch response
*/
-#define GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_RECORD 827
+#define GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_RECORD 825
/**
* Watch cancel request
*/
-#define GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_CANCEL 828
+#define GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_CANCEL 826
/*******************************************************************************
* SOCIAL message types
struct GNUNET_PEERSTORE_Record *record,
char *emsg)
{
- struct GNUNET_SERVER_TransmitContext *tc = cls;
+ struct GNUNET_SERVER_Client *client = cls;
struct StoreRecordMessage *srm;
srm = PEERSTORE_create_record_message(record->sub_system,
record->value_size,
record->expiry,
GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_RECORD);
- GNUNET_SERVER_transmit_context_append_message(tc, (const struct GNUNET_MessageHeader *)srm);
+ GNUNET_SERVER_notification_context_unicast(nc, client, (struct GNUNET_MessageHeader *)srm, GNUNET_NO);
return GNUNET_YES;
}
record->expiry,
GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_RECORD);
GNUNET_SERVER_notification_context_unicast(nc, client,
- (const struct GNUNET_MessageHeader *)srm, GNUNET_YES);
+ (const struct GNUNET_MessageHeader *)srm, GNUNET_NO);
return GNUNET_YES;
}
/**
* Given a new record, notifies watchers
*
- * @cls closure, a 'struct GNUNET_PEERSTORE_Record *'
- * @tc unused
+ * @param record changed record to update watchers with
*/
-void watch_notifier (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+void watch_notifier (struct GNUNET_PEERSTORE_Record *record)
{
- struct GNUNET_PEERSTORE_Record *record = cls;
struct GNUNET_HashCode keyhash;
GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Sending update to any watchers.\n");
const struct GNUNET_MessageHeader *message)
{
struct GNUNET_PEERSTORE_Record *record;
- struct GNUNET_SERVER_TransmitContext *tc;
+ struct GNUNET_MessageHeader *endmsg;
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received an iterate request from client.\n");
record = PEERSTORE_parse_record_message(message);
GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
return;
}
- tc = GNUNET_SERVER_transmit_context_create (client);
+ GNUNET_SERVER_notification_context_add(nc, client);
if(GNUNET_OK == db->iterate_records(db->cls,
record->sub_system,
record->peer,
record->key,
&record_iterator,
- tc))
+ client))
{
- GNUNET_SERVER_transmit_context_append_data(tc, NULL, 0, GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_END);
- GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
+ endmsg = GNUNET_new(struct GNUNET_MessageHeader);
+ endmsg->size = htons(sizeof(struct GNUNET_MessageHeader));
+ endmsg->type = htons(GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_END);
+ GNUNET_SERVER_notification_context_unicast(nc, client, endmsg, GNUNET_NO);
}
else
{
- GNUNET_free(tc);
GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
}
GNUNET_free(record); /* FIXME: destroy record */
const struct GNUNET_MessageHeader *message)
{
struct GNUNET_PEERSTORE_Record *record;
- struct GNUNET_SERVER_TransmitContext *tc;
record = PEERSTORE_parse_record_message(message);
if(NULL == record)
GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
return;
}
- tc = GNUNET_SERVER_transmit_context_create (client);
- GNUNET_SERVER_transmit_context_append_data(tc, NULL, 0, GNUNET_MESSAGE_TYPE_PEERSTORE_STORE_RESULT_OK);
- GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
- GNUNET_SCHEDULER_add_continuation(&watch_notifier, record, -1);
+ GNUNET_SERVER_receive_done(client, GNUNET_OK);
+ watch_notifier(record);
}
/**
*/
void *cont_cls;
- /**
- * #GNUNET_YES / #GNUNET_NO
- * if sent, cannot be canceled
- */
- int request_sent;
-
};
/**
/******************* DECLARATIONS *********************/
/******************************************************************************/
-/**
- * When a response for store request is received
- *
- * @param cls a 'struct GNUNET_PEERSTORE_StoreContext *'
- * @param msg message received, NULL on timeout or fatal error
- */
-void handle_store_result (void *cls, const struct GNUNET_MessageHeader *msg);
-
/**
* When a response for iterate request is received
*
* MQ message handlers
*/
static const struct GNUNET_MQ_MessageHandler mq_handlers[] = {
- {&handle_store_result, GNUNET_MESSAGE_TYPE_PEERSTORE_STORE_RESULT_OK, sizeof(struct GNUNET_MessageHeader)},
{&handle_iterate_result, GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_RECORD, 0},
{&handle_iterate_result, GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_END, sizeof(struct GNUNET_MessageHeader)},
{&handle_watch_result, GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_RECORD, 0},
/******************* STORE FUNCTIONS *********************/
/******************************************************************************/
-/**
- * When a response for store request is received
- *
- * @param cls a 'struct GNUNET_PEERSTORE_Handle *'
- * @param msg message received, NULL on timeout or fatal error
- */
-void handle_store_result (void *cls, const struct GNUNET_MessageHeader *msg)
-{
- struct GNUNET_PEERSTORE_Handle *h = cls;
- struct GNUNET_PEERSTORE_StoreContext *sc;
- GNUNET_PEERSTORE_Continuation cont;
- void *cont_cls;
-
- sc = h->store_head;
- if(NULL == sc)
- {
- LOG(GNUNET_ERROR_TYPE_ERROR, "Unexpected store response, this should not happen.\n");
- reconnect(h);
- return;
- }
- cont = sc->cont;
- cont_cls = sc->cont_cls;
- GNUNET_CONTAINER_DLL_remove(h->store_head, h->store_tail, sc);
- GNUNET_free(sc);
- if(NULL == msg) /* Connection error */
- {
- if(NULL != cont)
- cont(cont_cls, GNUNET_SYSERR);
- reconnect(h);
- return;
- }
- if(NULL != cont) /* Run continuation */
- cont(cont_cls, GNUNET_OK);
-
-}
-
/**
* Callback after MQ envelope is sent
*
void store_request_sent (void *cls)
{
struct GNUNET_PEERSTORE_StoreContext *sc = cls;
+ GNUNET_PEERSTORE_Continuation cont;
+ void *cont_cls;
- sc->request_sent = GNUNET_YES;
sc->ev = NULL;
+ cont = sc->cont;
+ cont_cls = sc->cont_cls;
+ GNUNET_PEERSTORE_store_cancel(sc);
+ if(NULL != cont)
+ cont(cont_cls, GNUNET_OK);
}
/**
{
LOG(GNUNET_ERROR_TYPE_DEBUG,
"Canceling store request.\n");
- if(GNUNET_NO == sc->request_sent)
+ if(NULL != sc->ev)
{
- if(NULL != sc->ev)
- {
- GNUNET_MQ_send_cancel(sc->ev);
- sc->ev = NULL;
- }
- GNUNET_CONTAINER_DLL_remove(sc->h->store_head, sc->h->store_tail, sc);
- GNUNET_free(sc);
- }
- else
- { /* request already sent, will have to wait for response */
- sc->cont = NULL;
+ GNUNET_MQ_send_cancel(sc->ev);
+ sc->ev = NULL;
}
-
+ GNUNET_CONTAINER_DLL_remove(sc->h->store_head, sc->h->store_tail, sc);
+ GNUNET_free(sc);
}
/**
sc->cont = cont;
sc->cont_cls = cont_cls;
sc->h = h;
- sc->request_sent = GNUNET_NO;
GNUNET_CONTAINER_DLL_insert(h->store_head, h->store_tail, sc);
GNUNET_MQ_notify_sent(ev, &store_request_sent, sc);
GNUNET_MQ_send(h->mq, ev);
NULL);
}
-int iterator (void *cls, const struct GNUNET_HashCode *key, void *value)
-{
- struct GNUNET_CONTAINER_MultiHashMap *map = cls;
- uint32_t *x = value;
-
- printf("Received value: %d\n", *x);
- if(*x == 2)
- GNUNET_CONTAINER_multihashmap_remove(map, key, value);
- return GNUNET_YES;
-}
-
int
main (int argc, char *argv[])
{