gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r34062 - in gnunet/src: include psyc psycstore


From: gnunet
Subject: [GNUnet-SVN] r34062 - in gnunet/src: include psyc psycstore
Date: Sun, 27 Jul 2014 15:17:04 +0200

Author: tg
Date: 2014-07-27 15:17:03 +0200 (Sun, 27 Jul 2014)
New Revision: 34062

Modified:
   gnunet/src/include/gnunet_protocols.h
   gnunet/src/include/gnunet_psycstore_service.h
   gnunet/src/psyc/gnunet-service-psyc.c
   gnunet/src/psyc/psyc.h
   gnunet/src/psyc/psyc_api.c
   gnunet/src/psyc/test_psyc.c
   gnunet/src/psycstore/gnunet-service-psycstore.c
   gnunet/src/psycstore/psycstore.h
   gnunet/src/psycstore/psycstore_api.c
Log:
psyc: membership store

Modified: gnunet/src/include/gnunet_protocols.h
===================================================================
--- gnunet/src/include/gnunet_protocols.h       2014-07-27 11:35:49 UTC (rev 
34061)
+++ gnunet/src/include/gnunet_protocols.h       2014-07-27 13:17:03 UTC (rev 
34062)
@@ -2152,11 +2152,10 @@
 #define GNUNET_MESSAGE_TYPE_PSYC_JOIN_DECISION 688
 
 
-/** C->S: request to remove channel slave from the membership database. */
-#define GNUNET_MESSAGE_TYPE_PSYC_CHANNEL_SLAVE_ADD 689
+/** C->S: request to add/remove channel slave in the membership database. */
+#define GNUNET_MESSAGE_TYPE_PSYC_CHANNEL_MEMBERSHIP_STORE 689
 
-/** C->S: request to add channel slave to the membership database */
-#define GNUNET_MESSAGE_TYPE_PSYC_CHANNEL_SLAVE_RM 690
+/* 690 */
 
 /** S<--C: PSYC message which contains one or more message parts. */
 #define GNUNET_MESSAGE_TYPE_PSYC_MESSAGE 691

Modified: gnunet/src/include/gnunet_psycstore_service.h
===================================================================
--- gnunet/src/include/gnunet_psycstore_service.h       2014-07-27 11:35:49 UTC 
(rev 34061)
+++ gnunet/src/include/gnunet_psycstore_service.h       2014-07-27 13:17:03 UTC 
(rev 34062)
@@ -121,18 +121,27 @@
  * Store join/leave events for a PSYC channel in order to be able to answer
  * membership test queries later.
  *
- * @param h Handle for the PSYCstore.
- * @param channel_key The channel where the event happened.
- * @param slave_key Public key of joining/leaving slave.
- * @param did_join #GNUNET_YES on join, #GNUNET_NO on part.
- * @param announced_at ID of the message that announced the membership change.
- * @param effective_since Message ID this membership change is in effect since.
+ * @param h
+ *        Handle for the PSYCstore.
+ * @param channel_key
+ *        The channel where the event happened.
+ * @param slave_key
+ *        Public key of joining/leaving slave.
+ * @param did_join
+ *        #GNUNET_YES on join, #GNUNET_NO on part.
+ * @param announced_at
+ *        ID of the message that announced the membership change.
+ * @param effective_since
+ *        Message ID this membership change is in effect since.
  *        For joins it is <= announced_at, for parts it is always 0.
- * @param group_generation In case of a part, the last group generation the
- *        slave has access to.  It has relevance when a larger message have
- *        fragments with different group generations.
- * @param rcb Callback to call with the result of the storage operation.
- * @param rcb_cls Closure for the callback.
+ * @param group_generation
+ *        In case of a part, the last group generation the slave has access to.
+ *        It has relevance when a larger message have fragments with different
+ *        group generations.
+ * @param rcb
+ *        Callback to call with the result of the storage operation.
+ * @param rcb_cls
+ *        Closure for the callback.
  *
  * @return Operation handle that can be used to cancel the operation.
  */
@@ -156,16 +165,22 @@
  * is also used when handling join requests to determine whether the slave is
  * currently admitted to the channel.
  *
- * @param h Handle for the PSYCstore.
- * @param channel_key The channel we are interested in.
- * @param slave_key Public key of slave whose membership to check.
- * @param message_id Message ID for which to do the membership test.
- * @param group_generation Group generation of the fragment of the message to
- *        test.  It has relevance if the message consists of multiple fragments
- *        with different group generations.
- *        FIXME: not needed if there are no overlapping messages.
- * @param rcb Callback to call with the test result.
- * @param rcb_cls Closure for the callback.
+ * @param h
+ *        Handle for the PSYCstore.
+ * @param channel_key
+ *        The channel we are interested in.
+ * @param slave_key
+ *        Public key of slave whose membership to check.
+ * @param message_id
+ *        Message ID for which to do the membership test.
+ * @param group_generation
+ *        Group generation of the fragment of the message to test.
+ *        It has relevance if the message consists of multiple fragments with
+ *        different group generations.
+ * @param rcb
+ *        Callback to call with the test result.
+ * @param rcb_cls
+ *        Closure for the callback.
  *
  * @return Operation handle that can be used to cancel the operation.
  */

Modified: gnunet/src/psyc/gnunet-service-psyc.c
===================================================================
--- gnunet/src/psyc/gnunet-service-psyc.c       2014-07-27 11:35:49 UTC (rev 
34061)
+++ gnunet/src/psyc/gnunet-service-psyc.c       2014-07-27 13:17:03 UTC (rev 
34062)
@@ -2048,24 +2048,46 @@
 
 
 /**
- * Client requests to add a slave to the membership database.
+ * Received result of GNUNET_PSYCSTORE_membership_store()
  */
 static void
-client_recv_slave_add (void *cls, struct GNUNET_SERVER_Client *client,
-                       const struct GNUNET_MessageHeader *msg)
+store_recv_membership_store_result (void *cls, int64_t result, const char 
*err_msg)
 {
-
+  struct GNUNET_MULTICAST_MembershipTestHandle *mth = cls;
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "%p GNUNET_PSYCSTORE_membership_store() returned %" PRId64 " 
(%s)\n",
+              mth, result, err_msg);
+  /* FIXME: send result to client */
 }
 
 
 /**
- * Client requests to remove a slave from the membership database.
+ * Client requests to add/remove a slave in the membership database.
  */
 static void
-client_recv_slave_remove (void *cls, struct GNUNET_SERVER_Client *client,
-                          const struct GNUNET_MessageHeader *msg)
+client_recv_membership_store (void *cls, struct GNUNET_SERVER_Client *client,
+                              const struct GNUNET_MessageHeader *msg)
 {
+  struct Channel *
+    chn = GNUNET_SERVER_client_get_user_context (client, struct Channel);
+  GNUNET_assert (NULL != chn);
 
+  const struct ChannelMembershipStoreRequest *
+    req = (const struct ChannelMembershipStoreRequest *) msg;
+
+  uint64_t announced_at = GNUNET_ntohll (req->announced_at);
+  uint64_t effective_since = GNUNET_ntohll (req->effective_since);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "%p Received membership store request from client.\n", chn);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "%p did_join: %u, announced_at: %" PRIu64 ", effective_since: %" 
PRIu64 "\n",
+              chn, req->did_join, announced_at, effective_since);
+
+  GNUNET_PSYCSTORE_membership_store (store, &chn->pub_key, &req->slave_key,
+                                     req->did_join, announced_at, 
effective_since,
+                                     0, /* FIXME: group_generation */
+                                     &store_recv_membership_store_result, chn);
+  GNUNET_SERVER_receive_done (client, GNUNET_OK);
 }
 
 
@@ -2115,12 +2137,9 @@
   { &client_recv_psyc_message, NULL,
     GNUNET_MESSAGE_TYPE_PSYC_MESSAGE, 0 },
 
-  { &client_recv_slave_add, NULL,
-    GNUNET_MESSAGE_TYPE_PSYC_CHANNEL_SLAVE_ADD, 0 },
+  { &client_recv_membership_store, NULL,
+    GNUNET_MESSAGE_TYPE_PSYC_CHANNEL_MEMBERSHIP_STORE, 0 },
 
-  { &client_recv_slave_remove, NULL,
-    GNUNET_MESSAGE_TYPE_PSYC_CHANNEL_SLAVE_RM, 0 },
-
   { &client_recv_story_request, NULL,
     GNUNET_MESSAGE_TYPE_PSYC_STORY_REQUEST, 0 },
 

Modified: gnunet/src/psyc/psyc.h
===================================================================
--- gnunet/src/psyc/psyc.h      2014-07-27 11:35:49 UTC (rev 34061)
+++ gnunet/src/psyc/psyc.h      2014-07-27 13:17:03 UTC (rev 34062)
@@ -105,35 +105,22 @@
 };
 
 
-struct ChannelSlaveAddRequest
+struct ChannelMembershipStoreRequest
 {
   /**
-   * Type: GNUNET_MESSAGE_TYPE_PSYC_CHANNEL_SLAVE_ADD
+   * Type: GNUNET_MESSAGE_TYPE_PSYC_CHANNEL_MEMBERSHIP_STORE
    */
   struct GNUNET_MessageHeader header;
 
   uint32_t reserved;
 
-  struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key;
+  struct GNUNET_CRYPTO_EcdsaPublicKey slave_key;
 
   uint64_t announced_at;
 
   uint64_t effective_since;
-};
 
-
-struct ChannelSlaveRemoveRequest
-{
-  /**
-   * Type: GNUNET_MESSAGE_TYPE_PSYC_CHANNEL_SLAVE_RM
-   */
-  struct GNUNET_MessageHeader header;
-
-  uint32_t reserved;
-
-  struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key;
-
-  uint64_t announced_at;
+  uint8_t did_join;
 };
 
 

Modified: gnunet/src/psyc/psyc_api.c
===================================================================
--- gnunet/src/psyc/psyc_api.c  2014-07-27 11:35:49 UTC (rev 34061)
+++ gnunet/src/psyc/psyc_api.c  2014-07-27 13:17:03 UTC (rev 34062)
@@ -810,12 +810,14 @@
                                uint64_t announced_at,
                                uint64_t effective_since)
 {
-  struct ChannelSlaveAddRequest *add = GNUNET_malloc (sizeof (*add));
-  add->header.type = htons (GNUNET_MESSAGE_TYPE_PSYC_CHANNEL_SLAVE_ADD);
-  add->header.size = htons (sizeof (*add));
-  add->announced_at = GNUNET_htonll (announced_at);
-  add->effective_since = GNUNET_htonll (effective_since);
-  GNUNET_CLIENT_MANAGER_transmit (chn->client, &add->header);
+  struct ChannelMembershipStoreRequest *req = GNUNET_malloc (sizeof (*req));
+  req->header.type = htons (GNUNET_MESSAGE_TYPE_PSYC_CHANNEL_MEMBERSHIP_STORE);
+  req->header.size = htons (sizeof (*req));
+  req->slave_key = *slave_key;
+  req->announced_at = GNUNET_htonll (announced_at);
+  req->effective_since = GNUNET_htonll (effective_since);
+  req->did_join = GNUNET_YES;
+  GNUNET_CLIENT_MANAGER_transmit (chn->client, &req->header);
 }
 
 
@@ -845,11 +847,13 @@
                                   const struct GNUNET_CRYPTO_EcdsaPublicKey 
*slave_key,
                                   uint64_t announced_at)
 {
-  struct ChannelSlaveRemoveRequest *rm = GNUNET_malloc (sizeof (*rm));
-  rm->header.type = htons (GNUNET_MESSAGE_TYPE_PSYC_CHANNEL_SLAVE_RM);
-  rm->header.size = htons (sizeof (*rm));
-  rm->announced_at = GNUNET_htonll (announced_at);
-  GNUNET_CLIENT_MANAGER_transmit (chn->client, &rm->header);
+  struct ChannelMembershipStoreRequest *req = GNUNET_malloc (sizeof (*req));
+  req->header.type = htons (GNUNET_MESSAGE_TYPE_PSYC_CHANNEL_MEMBERSHIP_STORE);
+  req->header.size = htons (sizeof (*req));
+  req->slave_key = *slave_key;
+  req->announced_at = GNUNET_htonll (announced_at);
+  req->did_join = GNUNET_NO;
+  GNUNET_CLIENT_MANAGER_transmit (chn->client, &req->header);
 }
 
 

Modified: gnunet/src/psyc/test_psyc.c
===================================================================
--- gnunet/src/psyc/test_psyc.c 2014-07-27 11:35:49 UTC (rev 34061)
+++ gnunet/src/psyc/test_psyc.c 2014-07-27 13:17:03 UTC (rev 34062)
@@ -413,21 +413,9 @@
 
 
 void
-join_decision_cb (void *cls,
-                  const struct GNUNET_PSYC_JoinDecisionMessage *dcsn,
-                  int is_admitted,
-                  const struct GNUNET_PSYC_Message *join_msg)
+slave_transmit ()
 {
-  GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-              "Slave got join decision: %d\n", is_admitted);
 
-  if (GNUNET_YES != is_admitted)
-  { /* First join request is refused, retry. */
-    GNUNET_assert (1 == join_req_count);
-    slave_join ();
-    return;
-  }
-
   GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Slave sending request to master.\n");
 
   test = TEST_SLAVE_TRANSMIT;
@@ -450,6 +438,26 @@
 
 
 void
+join_decision_cb (void *cls,
+                  const struct GNUNET_PSYC_JoinDecisionMessage *dcsn,
+                  int is_admitted,
+                  const struct GNUNET_PSYC_Message *join_msg)
+{
+  GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+              "Slave got join decision: %d\n", is_admitted);
+
+  if (GNUNET_YES != is_admitted)
+  { /* First join request is refused, retry. */
+    GNUNET_assert (1 == join_req_count);
+    slave_join ();
+    return;
+  }
+
+  slave_transmit ();
+}
+
+
+void
 join_request_cb (void *cls,
                  const struct GNUNET_PSYC_JoinRequestMessage *req,
                  const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
@@ -465,6 +473,11 @@
   /* Reject first request */
   int is_admitted = (0 < join_req_count++) ? GNUNET_YES : GNUNET_NO;
   GNUNET_PSYC_join_decision (jh, is_admitted, 0, NULL, NULL);
+
+  /* Membership store */
+  struct GNUNET_PSYC_Channel *chn = GNUNET_PSYC_master_get_channel (mst);
+  GNUNET_PSYC_channel_slave_add (chn, slave_key, 2, 2);
+  GNUNET_PSYC_channel_slave_remove (chn, &slave_pub_key, 2);
 }
 
 

Modified: gnunet/src/psycstore/gnunet-service-psycstore.c
===================================================================
--- gnunet/src/psycstore/gnunet-service-psycstore.c     2014-07-27 11:35:49 UTC 
(rev 34061)
+++ gnunet/src/psycstore/gnunet-service-psycstore.c     2014-07-27 13:17:03 UTC 
(rev 34062)
@@ -240,7 +240,7 @@
     (const struct MembershipStoreRequest *) msg;
 
   int ret = db->membership_store (db->cls, &req->channel_key, &req->slave_key,
-                                  ntohl (req->did_join),
+                                  req->did_join,
                                   GNUNET_ntohll (req->announced_at),
                                   GNUNET_ntohll (req->effective_since),
                                   GNUNET_ntohll (req->group_generation));

Modified: gnunet/src/psycstore/psycstore.h
===================================================================
--- gnunet/src/psycstore/psycstore.h    2014-07-27 11:35:49 UTC (rev 34061)
+++ gnunet/src/psycstore/psycstore.h    2014-07-27 13:17:03 UTC (rev 34062)
@@ -177,10 +177,10 @@
    */
   struct GNUNET_CRYPTO_EcdsaPublicKey slave_key;
 
-  uint64_t announced_at GNUNET_PACKED;
-  uint64_t effective_since GNUNET_PACKED;
-  uint64_t group_generation GNUNET_PACKED;
-  int did_join GNUNET_PACKED;
+  uint64_t announced_at;
+  uint64_t effective_since;
+  uint64_t group_generation;
+  uint8_t did_join;
 };
 
 

Modified: gnunet/src/psycstore/psycstore_api.c
===================================================================
--- gnunet/src/psycstore/psycstore_api.c        2014-07-27 11:35:49 UTC (rev 
34061)
+++ gnunet/src/psycstore/psycstore_api.c        2014-07-27 13:17:03 UTC (rev 
34062)
@@ -638,18 +638,27 @@
  * Store join/leave events for a PSYC channel in order to be able to answer
  * membership test queries later.
  *
- * @param h Handle for the PSYCstore.
- * @param channel_key The channel where the event happened.
- * @param slave_key Public key of joining/leaving slave.
- * @param did_join #GNUNET_YES on join, #GNUNET_NO on part.
- * @param announced_at ID of the message that announced the membership change.
- * @param effective_since Message ID this membership change is in effect since.
+ * @param h
+ *        Handle for the PSYCstore.
+ * @param channel_key
+ *        The channel where the event happened.
+ * @param slave_key
+ *        Public key of joining/leaving slave.
+ * @param did_join
+ *        #GNUNET_YES on join, #GNUNET_NO on part.
+ * @param announced_at
+ *        ID of the message that announced the membership change.
+ * @param effective_since
+ *        Message ID this membership change is in effect since.
  *        For joins it is <= announced_at, for parts it is always 0.
- * @param group_generation In case of a part, the last group generation the
- *        slave has access to.  It has relevance when a larger message have
- *        fragments with different group generations.
- * @param rcb Callback to call with the result of the storage operation.
- * @param rcb_cls Closure for the callback.
+ * @param group_generation
+ *        In case of a part, the last group generation the slave has access to.
+ *        It has relevance when a larger message have fragments with different
+ *        group generations.
+ * @param rcb
+ *        Callback to call with the result of the storage operation.
+ * @param rcb_cls
+ *        Closure for the callback.
  *
  * @return Operation handle that can be used to cancel the operation.
  */
@@ -667,6 +676,7 @@
   GNUNET_assert (NULL != h);
   GNUNET_assert (NULL != channel_key);
   GNUNET_assert (NULL != slave_key);
+  GNUNET_assert (GNUNET_YES == did_join || GNUNET_NO == did_join);
   GNUNET_assert (did_join
                  ? effective_since <= announced_at
                  : effective_since == 0);
@@ -684,7 +694,7 @@
   req->header.size = htons (sizeof (*req));
   req->channel_key = *channel_key;
   req->slave_key = *slave_key;
-  req->did_join = htonl (did_join);
+  req->did_join = did_join;
   req->announced_at = GNUNET_htonll (announced_at);
   req->effective_since = GNUNET_htonll (effective_since);
   req->group_generation = GNUNET_htonll (group_generation);
@@ -707,15 +717,22 @@
  * is also used when handling join requests to determine whether the slave is
  * currently admitted to the channel.
  *
- * @param h Handle for the PSYCstore.
- * @param channel_key The channel we are interested in.
- * @param slave_key Public key of slave whose membership to check.
- * @param message_id Message ID for which to do the membership test.
- * @param group_generation Group generation of the fragment of the message to
- *        test.  It has relevance if the message consists of multiple fragments
- *        with different group generations.
- * @param rcb Callback to call with the test result.
- * @param rcb_cls Closure for the callback.
+ * @param h
+ *        Handle for the PSYCstore.
+ * @param channel_key
+ *        The channel we are interested in.
+ * @param slave_key
+ *        Public key of slave whose membership to check.
+ * @param message_id
+ *        Message ID for which to do the membership test.
+ * @param group_generation
+ *        Group generation of the fragment of the message to test.
+ *        It has relevance if the message consists of multiple fragments with
+ *        different group generations.
+ * @param rcb
+ *        Callback to call with the test result.
+ * @param rcb_cls
+ *        Closure for the callback.
  *
  * @return Operation handle that can be used to cancel the operation.
  */




reply via email to

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