gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r28031 - gnunet/src/include


From: gnunet
Subject: [GNUnet-SVN] r28031 - gnunet/src/include
Date: Mon, 15 Jul 2013 09:25:13 +0200

Author: tg
Date: 2013-07-15 09:25:13 +0200 (Mon, 15 Jul 2013)
New Revision: 28031

Added:
   gnunet/src/include/gnunet_env_lib.h
Removed:
   gnunet/src/include/gnunet_psyc_lib.h
Modified:
   gnunet/src/include/gnunet_psyc_service.h
   gnunet/src/include/gnunet_social_service.h
Log:
PSYC/social: use an Environment for setting variables / state operations

Copied: gnunet/src/include/gnunet_env_lib.h (from rev 28030, 
gnunet/src/include/gnunet_psyc_lib.h)
===================================================================
--- gnunet/src/include/gnunet_env_lib.h                         (rev 0)
+++ gnunet/src/include/gnunet_env_lib.h 2013-07-15 07:25:13 UTC (rev 28031)
@@ -0,0 +1,262 @@
+/*
+     This file is part of GNUnet.
+     (C) 2013 Christian Grothoff (and other contributing authors)
+
+     GNUnet is free software; you can redistribute it and/or modify
+     it under the terms of the GNU General Public License as published
+     by the Free Software Foundation; either version 3, or (at your
+     option) any later version.
+
+     GNUnet is distributed in the hope that it will be useful, but
+     WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+     General Public License for more details.
+
+     You should have received a copy of the GNU General Public License
+     along with GNUnet; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+     Boston, MA 02111-1307, USA.
+*/
+
+/** 
+ * @file include/gnunet_env_lib.h
+ * @brief Library providing operations for the @e environment of PSYC and 
Social messages,
+ *        and for (de)serializing variable values.
+ * @author Gabor X Toth
+ */
+
+
+/** 
+ * Possible operations on PSYC state (persistent) and transient variables (per 
message).
+ */
+enum GNUNET_ENV_Operator
+{ 
+  /**
+   * Set value of a transient variable.
+   */
+  GNUNET_ENV_OP_SET = ':',
+
+  /**
+   * Assign value for a persistent state variable.
+   *
+   * If an assigned value is NULL, the variable is deleted.
+   */
+  GNUNET_ENV_OP_ASSIGN = '=',
+
+  /**
+   * Augment state variable.
+   *
+   * Used for appending strings, adding numbers, and adding new items to a 
list or dictionary.
+   */
+  GNUNET_ENV_OP_AUGMENT = '+',
+
+  /**
+   * Diminish state variable.
+   *
+   * Used for subtracting numbers, and removing items from a list or 
dictionary.
+   */
+  GNUNET_ENV_OP_DIMINISH = '-',
+
+  /**
+   * Update state variable.
+   *
+   * Used for modifying a single item of a list or dictionary.
+   */
+  GNUNET_ENV_OP_UPDATE = '@',
+};
+
+
+/**
+ * PSYC variable types.
+ */
+enum GNUNET_ENV_Type
+{
+  GNUNET_ENV_TYPE_DATA = 0,
+  GNUNET_ENV_TYPE_NUMBER,
+  GNUNET_ENV_TYPE_LIST,
+  GNUNET_ENV_TYPE_DICT
+};
+
+
+/**
+ * PSYC state modifier.
+ */
+struct GNUNET_ENV_Modifier {
+  /**
+   * State operation.
+   */
+  GNUNET_ENV_Operator oper;
+
+  /**
+   * Variable name.
+   */
+  const char *name;
+
+  /**
+   * Size of @a value.
+   */
+  size_t value_size;
+
+  /**
+   * Value of variable.
+   */
+  const void *value;
+};
+
+
+/**
+ * Environment for a message.
+ *
+ * Contains modifiers.
+ */
+struct GNUNET_ENV_Environment;
+
+
+/** 
+ * Create an environment.
+ * 
+ * @return A newly allocated environment.
+ */
+struct GNUNET_ENV_Environment *
+GNUNET_ENV_environment_create ();
+
+
+/** 
+ * Add an operation on a variable to the environment.
+ *
+ * @param env The environment.
+ * @param oper Operation to perform.
+ * @param name Name of the variable.
+ * @param value_size Size of @a value.
+ * @param value Value of the variable.
+ * 
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR on error.
+ */
+int
+GNUNET_ENV_environment_operation (struct GNUNET_ENV_Environment *env,
+                                  enum GNUNET_ENV_Operator oper,
+                                  const char *name,
+                                  size_t value_size, const void *value);
+
+
+/** 
+ * Get all modifiers in the environment.
+ *
+ * @param env The environment.
+ * @param[out] modifiers_length Set to the number of returned modifiers.
+ * 
+ * @return Array of modifiers.
+ */
+struct GNUNET_ENV_Modifier *
+GNUNET_ENV_environment_get_modifiers (const struct GNUNET_ENV_Environment *env,
+                                      size_t *modifiers_length);
+
+
+/** 
+ * Add list of modifiers to the environment.
+ *
+ * @param env The environment.
+ * @param modifiers_length Number of @a modifiers.
+ * @param modifiers Array of modifiers to add.
+ * 
+ * @return 
+ */
+int
+GNUNET_ENV_environment_set_modifiers (const struct GNUNET_ENV_Environment *env,
+                                      size_t modifiers_length,
+                                      const struct GNUNET_ENV_Modifier 
*modifiers);
+
+
+/** 
+ * Destroy an environment.
+ *
+ * @param env The environment to destroy.
+ */
+void
+GNUNET_ENV_environment_destroy (struct GNUNET_ENV_Environment *env);
+
+
+/** 
+ * Get the type of variable.
+ *
+ * @param name Name of the variable.
+ * 
+ * @return Variable type.
+ */
+enum GNUNET_ENV_Type
+GNUNET_ENV_var_get_type (char *name);
+
+
+/** 
+ * Get the variable's value as an integer.
+ *
+ * @param size Size of value.
+ * @param value Raw value of variable.
+ * @param[out] number Value converted to a 64-bit integer. 
+ *
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR if an error occurred (e.g. 
the value is invalid).
+ */
+int
+GNUNET_ENV_value_to_number (size_t size, const void *value, int64_t *number);
+
+
+/** 
+ * Get the variable's value as a list.
+ *
+ * @param size Size of value.
+ * @param value Raw value of variable.
+ * @param[out] list A newly created list holding the elements.
+ *
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR if an error occurred (e.g. 
the value is invalid).
+ */
+int
+GNUNET_ENV_value_to_list (size_t size, const void *value, 
GNUNET_CONTAINER_SList **list);
+
+
+/** 
+ * Get the variable's value as a dictionary.
+ *
+ * @param size Size of value.
+ * @param value Raw value of variable.
+ * @param[out] dict A newly created hashmap holding the elements of the 
dictionary.
+ *
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR if an error occurred (e.g. 
the value is invalid).
+ */
+int
+GNUNET_ENV_value_to_dict (size_t size, const void *value, 
GNUNET_CONTAINER_MultiHashMap **dict);
+
+
+/** 
+ * Create a PSYC variable value from an integer.
+ *
+ * @param number The number to convert.
+ * @param[out] value_size Size of returned value.
+ * 
+ * @return A newly allocated value or NULL on error.
+ */
+void *
+GNUNET_ENV_value_from_number (int64_t number, size_t *value_size);
+
+
+/** 
+ * Create a PSYC variable value from a list.
+ *
+ * @param list The list to convert.
+ * @param[out] value_size Size of returned value.
+ * 
+ * @return A newly allocated value or NULL on error.
+ */
+void *
+GNUNET_ENV_value_from_list (GNUNET_CONTAINER_SList *list, size_t *value_size);
+
+
+/** 
+ * Create a PSYC variable value from a dictionary.
+ *
+ * @param dict The dict to convert.
+ * @param[out] value_size Size of returned value.
+ * 
+ * @return A newly allocated value or NULL on error.
+ */
+void *
+GNUNET_ENV_value_from_dict (GNUNET_CONTAINER_MultiHashMap *dict, size_t 
*value_size);

Deleted: gnunet/src/include/gnunet_psyc_lib.h
===================================================================
--- gnunet/src/include/gnunet_psyc_lib.h        2013-07-15 07:25:11 UTC (rev 
28030)
+++ gnunet/src/include/gnunet_psyc_lib.h        2013-07-15 07:25:13 UTC (rev 
28031)
@@ -1,190 +0,0 @@
-/*
-     This file is part of GNUnet.
-     (C) 2013 Christian Grothoff (and other contributing authors)
-
-     GNUnet is free software; you can redistribute it and/or modify
-     it under the terms of the GNU General Public License as published
-     by the Free Software Foundation; either version 3, or (at your
-     option) any later version.
-
-     GNUnet is distributed in the hope that it will be useful, but
-     WITHOUT ANY WARRANTY; without even the implied warranty of
-     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-     General Public License for more details.
-
-     You should have received a copy of the GNU General Public License
-     along with GNUnet; see the file COPYING.  If not, write to the
-     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-     Boston, MA 02111-1307, USA.
-*/
-
-/** 
- * @file include/gnunet_psyc_lib.h
- * @brief Library for common PSYC functionality:
- *        types, variable (de)serialization.
- * @author Gabor X Toth
- */
-
-
-/** 
- * Possible operations on PSYC state (persistent) and transient variables (per 
message).
- */
-enum GNUNET_PSYC_Operator
-{ 
-  /**
-   * Set value of a transient variable.
-   */
-  GNUNET_PSYC_OP_SET = ':',
-
-  /**
-   * Assign value for a persistent state variable.
-   *
-   * If an assigned value is NULL, the variable is deleted.
-   */
-  GNUNET_PSYC_OP_ASSIGN = '=',
-
-  /**
-   * Augment state variable.
-   *
-   * Used for appending strings, adding numbers, and adding new items to a 
list or dictionary.
-   */
-  GNUNET_PSYC_OP_AUGMENT = '+',
-
-  /**
-   * Diminish state variable.
-   *
-   * Used for subtracting numbers, and removing items from a list or 
dictionary.
-   */
-  GNUNET_PSYC_OP_DIMINISH = '-',
-
-  /**
-   * Update state variable.
-   *
-   * Used for modifying a single item of a list or dictionary.
-   */
-  GNUNET_PSYC_OP_UPDATE = '@',
-};
-
-
-/**
- * PSYC variable types.
- */
-enum GNUNET_PSYC_Type
-{
-  GNUNET_PSYC_TYPE_DATA = 0,
-  GNUNET_PSYC_TYPE_NUMBER,
-  GNUNET_PSYC_TYPE_LIST,
-  GNUNET_PSYC_TYPE_DICT
-};
-
-
-/**
- * PSYC state modifier.
- */
-struct GNUNET_PSYC_Modifier {
-  /**
-   * State operation.
-   */
-  GNUNET_PSYC_Operator oper;
-
-  /**
-   * Variable name.
-   */
-  const char *name;
-
-  /**
-   * Size of @a value.
-   */
-  size_t value_size;
-
-  /**
-   * Value of variable.
-   */
-  const void *value;
-};
-
-
-/** 
- * Get the type of variable.
- *
- * @param name Name of the variable.
- * 
- * @return Variable type.
- */
-enum GNUNET_PSYC_Type
-GNUNET_PSYC_var_get_type (char *name);
-
-
-/** 
- * Get the variable's value as an integer.
- *
- * @param size Size of value.
- * @param value Raw value of variable.
- * @param[out] number Value converted to a 64-bit integer. 
- *
- * @return #GNUNET_OK on success, #GNUNET_SYSERR if an error occurred (e.g. 
the value is invalid).
- */
-int
-GNUNET_PSYC_value_to_number (size_t size, const void *value, int64_t *number);
-
-
-/** 
- * Get the variable's value as a list.
- *
- * @param size Size of value.
- * @param value Raw value of variable.
- * @param[out] list A newly created list holding the elements.
- *
- * @return #GNUNET_OK on success, #GNUNET_SYSERR if an error occurred (e.g. 
the value is invalid).
- */
-int
-GNUNET_PSYC_value_to_list (size_t size, const void *value, 
GNUNET_CONTAINER_SList **list);
-
-
-/** 
- * Get the variable's value as a dictionary.
- *
- * @param size Size of value.
- * @param value Raw value of variable.
- * @param[out] dict A newly created hashmap holding the elements of the 
dictionary.
- *
- * @return #GNUNET_OK on success, #GNUNET_SYSERR if an error occurred (e.g. 
the value is invalid).
- */
-int
-GNUNET_PSYC_value_to_dict (size_t size, const void *value, 
GNUNET_CONTAINER_MultiHashMap **dict);
-
-
-/** 
- * Create a PSYC variable value from an integer.
- *
- * @param number The number to convert.
- * @param[out] value_size Size of returned value.
- * 
- * @return A newly allocated value or NULL on error.
- */
-void *
-GNUNET_PSYC_value_from_number (int64_t number, size_t *value_size);
-
-
-/** 
- * Create a PSYC variable value from a list.
- *
- * @param list The list to convert.
- * @param[out] value_size Size of returned value.
- * 
- * @return A newly allocated value or NULL on error.
- */
-void *
-GNUNET_PSYC_value_from_list (GNUNET_CONTAINER_SList *list, size_t *value_size);
-
-
-/** 
- * Create a PSYC variable value from a dictionary.
- *
- * @param dict The dict to convert.
- * @param[out] value_size Size of returned value.
- * 
- * @return A newly allocated value or NULL on error.
- */
-void *
-GNUNET_PSYC_value_from_dict (GNUNET_CONTAINER_MultiHashMap *dict, size_t 
*value_size);

Modified: gnunet/src/include/gnunet_psyc_service.h
===================================================================
--- gnunet/src/include/gnunet_psyc_service.h    2013-07-15 07:25:11 UTC (rev 
28030)
+++ gnunet/src/include/gnunet_psyc_service.h    2013-07-15 07:25:13 UTC (rev 
28031)
@@ -151,7 +151,7 @@
  *        specific than the registered method name due to try-and-slice 
matching).
  *        FIXME: no try-and-slice for methods defined here.
  * @param header_length Number of modifiers in header.
- * @param header Modifiers present in the message.
+ * @param header Modifiers present in the message. FIXME: use environment 
instead?
  * @param data_offset Byte offset of @a data in the overall data of the method.
  * @param data_size Number of bytes in @a data.
  * @param data Data stream given to the method (might not be zero-terminated 
@@ -163,7 +163,7 @@
                                  uint64_t message_id,
                                  const char *method_name,
                                   size_t header_length,
-                                  GNUNET_PSYC_Modifier *header,                
                 
+                                  GNUNET_PSYC_Modifier *header,
                                  uint64_t data_offset,
                                  size_t data_size,
                                  const void *data,
@@ -224,6 +224,7 @@
  * @param is_admitted #GNUNET_YES if joining is approved,
  *        #GNUNET_NO if it is disapproved
  * @param method_name Method name for the message transmitted with the 
response.
+ * @param env Environment: transient variables for the message.
  * @param data_size Size of @a data.
  * @param data Data of the message.
  */
@@ -231,6 +232,7 @@
 GNUNET_PSYC_join_decision (struct GNUNET_PSYC_JoinHandle *jh,
                            int is_admitted,
                            const char *method_name,
+                           const struct GNUNET_ENV_Environment *env,
                            size_t data_size,
                            const void *data);
 
@@ -290,32 +292,6 @@
 
 
 /** 
- * Modify channel state (or set a transient variable).
- *
- * The state of a channel must fit into the memory of each member (and the
- * channel); large values that require streaming must only be passed as the
- * stream arguments to methods.  State modifications might not be transmitted 
to
- * group members until the next call to GNUNET_PSYC_channel_transmit().
- * Variable updates must be given just before the call to the respective method
- * that needs the variables.
- *
- * @param channel Handle to the PSYC group / channel.
- * @param oper Kind of update operation (add, remove, replace, delete).
- * @param name Name of the state or transient variable to modify.
- * @param value_size Number of bytes in @a value.
- * @param value Value of state variable.
- * @return #GNUNET_OK on success, #GNUNET_SYSERR on internal error
- *        (i.e. state too large).
- */
-int
-GNUNET_PSYC_channel_state_modify (struct GNUNET_PSYC_Channel *channel,
-                                 enum GNUNET_PSYC_Operator oper,
-                                 const char *name,
-                                 size_t value_size,
-                                 const void *value);
-
-
-/** 
  * Function called to provide data for a transmission via PSYC.
  *
  * Note that returning #GNUNET_OK or #GNUNET_SYSERR (but not #GNUNET_NO)
@@ -352,6 +328,7 @@
  * @param increment_group_generation #GNUNET_YES if we need to increment
  *        the group generation counter after transmitting this message.
  * @param method_name Which method should be invoked.
+ * @param env Environment: state operations and transient variables for the 
message.
  * @param notify Function to call to obtain the arguments.
  * @param notify_cls Closure for @a notify.
  * @return Transmission handle, NULL on error (i.e. more than one request 
queued).
@@ -360,6 +337,7 @@
 GNUNET_PSYC_channel_transmit (struct GNUNET_PSYC_Channel *channel,
                               int increment_group_generation,
                               const char *method_name,
+                              const struct GNUNET_ENV_Environment *env,
                               GNUNET_PSYC_ChannelReadyNotify notify,
                               void *notify_cls);
 
@@ -544,6 +522,7 @@
  *
  * @param member Membership handle.
  * @param method_name Which (PSYC) method should be invoked (on host).
+ * @param env Environment: transient variables for the message.
  * @param notify Function to call when we are allowed to transmit (to get 
data).
  * @param notify_cls Closure for @a notify.
  * @return Transmission handle, NULL on error (i.e. more than one request 
queued).
@@ -551,32 +530,12 @@
 struct GNUNET_PSYC_MemberTransmitHandle *
 GNUNET_PSYC_member_to_origin (struct GNUNET_PSYC_Member *member,
                               const char *method_name,
+                              const struct GNUNET_ENV_Environment *env,
                               GNUNET_PSYC_MemberReadyNotify notify,
                               void *notify_cls);
 
 
 /** 
- * Set a (temporary, ":") variable for the next message being transmitted
- * via GNUNET_PSYC_member_to_origin().
- *
- * If GNUNET_PSYC_member_to_origin() is called and then cancelled, all
- * variables that were set using this function will be unset (lost/forgotten).
- * To clear a variable state after setting it, you can also call this function
- * again with NULL/0 for the @a value.
- *
- * @param member Membership handle.
- * @param name Name of the variable to set.
- * @param value_size Number of bytes in @a value.
- * @param value Value to set for the given variable.
- */
-uint64_t
-GNUNET_PSYC_member_variable_set (struct GNUNET_PSYC_Member *member,
-                                 const char *name,
-                                 size_t value_size,
-                                 const void *value);
-
-
-/** 
  * Abort transmission request to origin.
  *
  * @param th Handle of the request that is being aborted.

Modified: gnunet/src/include/gnunet_social_service.h
===================================================================
--- gnunet/src/include/gnunet_social_service.h  2013-07-15 07:25:11 UTC (rev 
28030)
+++ gnunet/src/include/gnunet_social_service.h  2013-07-15 07:25:13 UTC (rev 
28031)
@@ -85,7 +85,7 @@
  *                   (unique only in combination with the given sender for
  *                    this channel).
  * @param header_length Number of modifiers in header.
- * @param header Modifiers present in the message.
+ * @param header Modifiers present in the message. FIXME: use environment 
instead?
  * @param data_offset Byte offset of @a data in the overall data of the method.
  * @param data_size Number of bytes in @a data.
  * @param data Data stream given to the method (might not be zero-terminated 
@@ -323,28 +323,7 @@
                               GNUNET_TIME_Relative expiration_time);
 
 
-
 /** 
- * (Re)decorate the home by changing objects in it.
- *
- * If the operation is #GNUNET_PSYC_OP_SET then the decoration only
- * applies to the next announcement by the home owner.
- *
- * @param home The home to decorate.
- * @param operation Operation to perform on the object.
- * @param object_name Name of the object to modify.
- * @param object_value_size Size of the given @a object_value.
- * @param object_value Value to use for the modification.
- */
-void
-GNUNET_SOCIAL_home_decorate (struct GNUNET_SOCIAL_Home *home,
-                            enum GNUNET_PSYC_Operator operation,
-                            const char *object_name,
-                            size_t object_value_size,
-                            const void *object_value);
-
-
-/** 
  * Handle for an announcement request.
  */
 struct GNUNET_SOCIAL_Announcement;
@@ -365,6 +344,7 @@
 struct GNUNET_SOCIAL_Announcement *
 GNUNET_SOCIAL_home_announce (struct GNUNET_SOCIAL_Home *home,
                              const char *method_name,
+                             const struct GNUNET_ENV_Environment *env,
                              GNUNET_PSYC_OriginReadyNotify notify,
                              void *notify_cls);
 
@@ -429,6 +409,7 @@
 GNUNET_SOCIAL_place_enter (const struct GNUNET_CONFIGURATION_Handle *cfg,
                            struct GNUNET_SOCIAL_Ego *ego,
                            char *address,
+                           const struct GNUNET_ENV_Environment *env,
                            size_t msg_size,
                            const void *msg,
                            struct GNUNET_SOCIAL_Slicer *slicer);
@@ -451,6 +432,7 @@
                            struct GNUNET_HashCode *crypto_address,
                            struct GNUNET_PeerIdentity *peer,
                            struct GNUNET_SOCIAL_Slicer *slicer,
+                           const struct GNUNET_ENV_Environment *env,
                            size_t msg_size,
                            const void *msg);
 
@@ -542,24 +524,6 @@
 
 
 /** 
- * Frame the (next) talk by setting some variables for it.
- *
- * FIXME: use a TalkFrame struct instead that can be passed to
- * place_talk, nym_talk and home_reject_entry.
- *
- * @param place Place to talk in.
- * @param variable_name Name of variable to set.
- * @param value_size Number of bytes in @a value.
- * @param value Value of variable.
- */
-void
-GNUNET_SOCIAL_place_frame_talk (struct GNUNET_SOCIAL_Place *place,
-                               const char *variable_name,
-                               size_t value_size,
-                               const void *value);
-
-
-/** 
  * A talk request.
  */
 struct GNUNET_SOCIAL_TalkRequest;
@@ -577,6 +541,7 @@
 struct GNUNET_SOCIAL_TalkRequest *
 GNUNET_SOCIAL_place_talk (struct GNUNET_SOCIAL_Place *place,
                          const char *method_name,
+                          const struct GNUNET_ENV_Environment *env,
                          GNUNET_PSYC_OriginReadyNotify cb,
                          void *cb_cls);
 




reply via email to

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