gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r33498 - in gnunet/src: include peerstore


From: gnunet
Subject: [GNUnet-SVN] r33498 - in gnunet/src: include peerstore
Date: Tue, 3 Jun 2014 15:50:37 +0200

Author: otarabai
Date: 2014-06-03 15:50:37 +0200 (Tue, 03 Jun 2014)
New Revision: 33498

Modified:
   gnunet/src/include/gnunet_protocols.h
   gnunet/src/peerstore/gnunet-service-peerstore.c
   gnunet/src/peerstore/peerstore_api.c
   gnunet/src/peerstore/test_peerstore_api.c
Log:
peerstore: fixes in watch functionality


Modified: gnunet/src/include/gnunet_protocols.h
===================================================================
--- gnunet/src/include/gnunet_protocols.h       2014-06-03 10:23:23 UTC (rev 
33497)
+++ gnunet/src/include/gnunet_protocols.h       2014-06-03 13:50:37 UTC (rev 
33498)
@@ -2477,35 +2477,34 @@
 #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

Modified: gnunet/src/peerstore/gnunet-service-peerstore.c
===================================================================
--- gnunet/src/peerstore/gnunet-service-peerstore.c     2014-06-03 10:23:23 UTC 
(rev 33497)
+++ gnunet/src/peerstore/gnunet-service-peerstore.c     2014-06-03 13:50:37 UTC 
(rev 33498)
@@ -144,7 +144,7 @@
     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,
@@ -154,7 +154,7 @@
       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;
 }
 
@@ -189,19 +189,17 @@
       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");
@@ -265,7 +263,7 @@
     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);
@@ -281,20 +279,21 @@
     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 */
@@ -312,7 +311,6 @@
     const struct GNUNET_MessageHeader *message)
 {
   struct GNUNET_PEERSTORE_Record *record;
-  struct GNUNET_SERVER_TransmitContext *tc;
 
   record = PEERSTORE_parse_record_message(message);
   if(NULL == record)
@@ -348,10 +346,8 @@
     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);
 }
 
 /**

Modified: gnunet/src/peerstore/peerstore_api.c
===================================================================
--- gnunet/src/peerstore/peerstore_api.c        2014-06-03 10:23:23 UTC (rev 
33497)
+++ gnunet/src/peerstore/peerstore_api.c        2014-06-03 13:50:37 UTC (rev 
33498)
@@ -117,12 +117,6 @@
    */
   void *cont_cls;
 
-  /**
-   * #GNUNET_YES / #GNUNET_NO
-   * if sent, cannot be canceled
-   */
-  int request_sent;
-
 };
 
 /**
@@ -227,14 +221,6 @@
 
/******************************************************************************/
 
 /**
- * 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
  *
  * @param cls a 'struct GNUNET_PEERSTORE_Handle *'
@@ -262,7 +248,6 @@
  * 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},
@@ -376,55 +361,25 @@
 
/******************************************************************************/
 
 /**
- * When a response for store request is received
+ * Callback after MQ envelope is sent
  *
- * @param cls a 'struct GNUNET_PEERSTORE_Handle *'
- * @param msg message received, NULL on timeout or fatal error
+ * @param cls a 'struct GNUNET_PEERSTORE_StoreContext *'
  */
-void handle_store_result (void *cls, const struct GNUNET_MessageHeader *msg)
+void store_request_sent (void *cls)
 {
-  struct GNUNET_PEERSTORE_Handle *h = cls;
-  struct GNUNET_PEERSTORE_StoreContext *sc;
+  struct GNUNET_PEERSTORE_StoreContext *sc = cls;
   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;
-  }
+  sc->ev = NULL;
   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 */
+  GNUNET_PEERSTORE_store_cancel(sc);
+  if(NULL != cont)
     cont(cont_cls, GNUNET_OK);
-
 }
 
 /**
- * Callback after MQ envelope is sent
- *
- * @param cls a 'struct GNUNET_PEERSTORE_StoreContext *'
- */
-void store_request_sent (void *cls)
-{
-  struct GNUNET_PEERSTORE_StoreContext *sc = cls;
-
-  sc->request_sent = GNUNET_YES;
-  sc->ev = NULL;
-}
-
-/**
  * Cancel a store request
  *
  * @param sc Store request context
@@ -434,21 +389,13 @@
 {
   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);
+    GNUNET_MQ_send_cancel(sc->ev);
+    sc->ev = NULL;
   }
-  else
-  { /* request already sent, will have to wait for response */
-    sc->cont = NULL;
-  }
-
+  GNUNET_CONTAINER_DLL_remove(sc->h->store_head, sc->h->store_tail, sc);
+  GNUNET_free(sc);
 }
 
 /**
@@ -493,7 +440,6 @@
   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);

Modified: gnunet/src/peerstore/test_peerstore_api.c
===================================================================
--- gnunet/src/peerstore/test_peerstore_api.c   2014-06-03 10:23:23 UTC (rev 
33497)
+++ gnunet/src/peerstore/test_peerstore_api.c   2014-06-03 13:50:37 UTC (rev 
33498)
@@ -129,17 +129,6 @@
       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[])
 {




reply via email to

[Prev in Thread] Current Thread [Next in Thread]