-eliminate printing warning on MAGIC missmatch (#2138)
[oweals/gnunet.git] / src / fs / gnunet-service-fs_pr.h
index b59cbc541e94015b8b5ed560050fe2315148666c..92827f76bb053a9da6eb99e4665c6bf921d9f404 100644 (file)
  * Options for pending requests (bits to be ORed).
  */
 enum GSF_PendingRequestOptions
-  {
+{
+
+  /**
+   * No special options (P2P-default).
+   */
+  GSF_PRO_DEFAULTS = 0,
+
     /**
      * Request must only be processed locally.
      */
-    GSF_PRO_LOCAL_ONLY = 1,
-    
+  GSF_PRO_LOCAL_ONLY = 1,
+
     /**
      * Request must only be forwarded (no routing)
      */
-    GSF_PRO_FORWARD_ONLY = 2,
+  GSF_PRO_FORWARD_ONLY = 2,
 
     /**
      * Request persists indefinitely (no expiration).
      */
-    GSF_PRO_REQUEST_EXPIRES = 4,
+  GSF_PRO_REQUEST_NEVER_EXPIRES = 4,
 
     /**
      * Request is allowed to refresh bloomfilter and change mingle value.
      */
-    GSF_PRO_BLOOMFILTER_FULL_REFRESH = 8,
+  GSF_PRO_BLOOMFILTER_FULL_REFRESH = 8,
 
     /**
      * Request priority is allowed to be exceeded.
      */
-    GSF_PRO_PRIORITY_UNLIMITED = 16,
+  GSF_PRO_PRIORITY_UNLIMITED = 16,
 
     /**
      * Option mask for typical local requests.
      */
-    GSF_PRO_LOCAL_REQUEST = (GSF_PRO_BLOOMFILTER_FULL_REFRESH | GSF_PRO_PRIORITY_UNLIMITED)
-
-  };
+  GSF_PRO_LOCAL_REQUEST =
+      (GSF_PRO_BLOOMFILTER_FULL_REFRESH | GSF_PRO_PRIORITY_UNLIMITED | GSF_PRO_REQUEST_NEVER_EXPIRES)
+};
 
 
 /**
@@ -84,13 +90,23 @@ struct GSF_PendingRequestData
    * Namespace to query, only set if the type is SBLOCK.
    */
   GNUNET_HashCode namespace;
-                       
+
   /**
    * Identity of a peer hosting the content, only set if
    * 'has_target' is GNUNET_YES.
    */
   struct GNUNET_PeerIdentity target;
 
+  /**
+   * Fields for the plan module to track a DLL with the request.
+   */
+  struct GSF_RequestPlanReference *rpr_head;
+
+  /**
+   * Fields for the plan module to track a DLL with the request.
+   */
+  struct GSF_RequestPlanReference *rpr_tail;
+
   /**
    * Current TTL for the request.
    */
@@ -120,7 +136,7 @@ struct GSF_PendingRequestData
    * Options for the request.
    */
   enum GSF_PendingRequestOptions options;
-  
+
   /**
    * Type of the requested block.
    */
@@ -136,6 +152,12 @@ struct GSF_PendingRequestData
    */
   int has_target;
 
+  /**
+   * Has this request been started yet (local/p2p operations)?  Or are
+   * we still constructing it?
+   */
+  int has_started;
+
 };
 
 
@@ -143,29 +165,37 @@ struct GSF_PendingRequestData
  * 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 cls user-specified closure
+ * @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 last_transmission the last time we've tried to get 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
- * @param more GNUNET_YES if the request remains active (may call
- *             this function again), GNUNET_NO if the request is
- *             finished (client must not call GSF_pending_request_cancel_)
  */
-typedef void (*GSF_PendingRequestReplyHandler)(void *cls,
-                                              struct GSF_PendingRequest *pr,
-                                              struct GNUNET_TIME_Absolute expiration,
-                                              const void *data,
-                                              size_t data_len,
-                                              int more);
+typedef void (*GSF_PendingRequestReplyHandler) (void *cls,
+                                                enum
+                                                GNUNET_BLOCK_EvaluationResult
+                                                eval,
+                                                struct GSF_PendingRequest * pr,
+                                                uint32_t reply_anonymity_level,
+                                                struct GNUNET_TIME_Absolute
+                                                expiration,
+                                                struct GNUNET_TIME_Absolute
+                                                last_transmission,
+                                                enum GNUNET_BLOCK_Type type,
+                                                const void *data,
+                                                size_t data_len);
 
 
 /**
- * Create a new pending request.  
+ * Create a new pending request.
  *
  * @param options request options
  * @param type type of the block that is being requested
@@ -180,6 +210,7 @@ typedef void (*GSF_PendingRequestReplyHandler)(void *cls,
  * @param ttl current time-to-live for the request
  * @param sender_pid peer ID to use for the sender when forwarding, 0 for none;
  *                   reference counter is taken over by this function
+ * @param origin_pid peer ID of origin of query (do not loop back)
  * @param replies_seen hash codes of known local replies
  * @param replies_seen_count size of the 'replies_seen' array
  * @param rh handle to call when we get a reply
@@ -188,21 +219,18 @@ typedef void (*GSF_PendingRequestReplyHandler)(void *cls,
  */
 struct GSF_PendingRequest *
 GSF_pending_request_create_ (enum GSF_PendingRequestOptions options,
-                            enum GNUNET_BLOCK_Type type,
-                            const GNUNET_HashCode *query,
-                            const GNUNET_HashCode *namespace,
-                            const struct GNUNET_PeerIdentity *target,
-                            const char *bf_data,
-                            size_t bf_size,
-                            uint32_t mingle,
-                            uint32_t anonymity_level,
-                            uint32_t priority,
-                            int32_t ttl,
-                            GNUNET_PEER_Id sender_pid,
-                            const GNUNET_HashCode *replies_seen,
-                            unsigned int replies_seen_count,
-                            GSF_PendingRequestReplyHandler rh,
-                            void *rh_cls);
+                             enum GNUNET_BLOCK_Type type,
+                             const GNUNET_HashCode * query,
+                             const GNUNET_HashCode * namespace,
+                             const struct GNUNET_PeerIdentity *target,
+                             const char *bf_data, size_t bf_size,
+                             uint32_t mingle, uint32_t anonymity_level,
+                             uint32_t priority, int32_t ttl,
+                             GNUNET_PEER_Id sender_pid,
+                             GNUNET_PEER_Id origin_pid,
+                             const GNUNET_HashCode * replies_seen,
+                             unsigned int replies_seen_count,
+                             GSF_PendingRequestReplyHandler rh, void *rh_cls);
 
 
 /**
@@ -215,13 +243,13 @@ GSF_pending_request_create_ (enum GSF_PendingRequestOptions options,
  */
 void
 GSF_pending_request_update_ (struct GSF_PendingRequest *pr,
-                            const GNUNET_HashCode *replies_seen,
-                            unsigned int replies_seen_count);
+                             const GNUNET_HashCode * replies_seen,
+                             unsigned int replies_seen_count);
 
 
 /**
  * Obtain the public data associated with a pending request
- * 
+ *
  * @param pr pending request
  * @return associated public data
  */
@@ -229,30 +257,42 @@ struct GSF_PendingRequestData *
 GSF_pending_request_get_data_ (struct GSF_PendingRequest *pr);
 
 
+/**
+ * Test if two pending requests are compatible (would generate
+ * the same query modulo filters and should thus be processed
+ * jointly).
+ *
+ * @param pra a pending request
+ * @param prb another pending request
+ * @return GNUNET_OK if the requests are compatible
+ */
+int
+GSF_pending_request_is_compatible_ (struct GSF_PendingRequest *pra,
+                                    struct GSF_PendingRequest *prb);
+
+
 /**
  * Generate the message corresponding to the given pending request for
  * transmission to other peers (or at least determine its size).
  *
  * @param pr request to generate the message for
- * @param do_route are we routing the reply
  * @param buf_size number of bytes available in buf
  * @param buf where to copy the message (can be NULL)
  * @return number of bytes needed (if buf_size too small) or used
  */
 size_t
 GSF_pending_request_get_message_ (struct GSF_PendingRequest *pr,
-                                 int do_route,
-                                 size_t buf_size,
-                                 void *buf);
+                                  size_t buf_size, void *buf);
 
 
 /**
  * Explicitly cancel a pending request.
  *
  * @param pr request to cancel
+ * @param full_cleanup fully purge the request
  */
 void
-GSF_pending_request_cancel_ (struct GSF_PendingRequest *pr);
+GSF_pending_request_cancel_ (struct GSF_PendingRequest *pr, int full_cleanup);
 
 
 /**
@@ -264,9 +304,9 @@ GSF_pending_request_cancel_ (struct GSF_PendingRequest *pr);
  * @param pr handle to the pending request
  * @return GNUNET_YES to continue to iterate
  */
-typedef int (*GSF_PendingRequestIterator)(void *cls,
-                                         const GNUNET_HashCode *key,
-                                         struct GSF_PendingRequest *pr);
+typedef int (*GSF_PendingRequestIterator) (void *cls,
+                                           const GNUNET_HashCode * key,
+                                           struct GSF_PendingRequest * pr);
 
 
 /**
@@ -276,8 +316,7 @@ typedef int (*GSF_PendingRequestIterator)(void *cls,
  * @param cls closure for it
  */
 void
-GSF_iterate_pending_requests_ (GSF_PendingRequestIterator it,
-                              void *cls);
+GSF_iterate_pending_requests_ (GSF_PendingRequestIterator it, void *cls);
 
 
 /**
@@ -295,39 +334,59 @@ GSF_iterate_pending_requests_ (GSF_PendingRequestIterator it,
  */
 int
 GSF_handle_p2p_content_ (struct GSF_ConnectedPeer *cp,
-                        const struct GNUNET_MessageHeader *message);
+                         const struct GNUNET_MessageHeader *message);
 
 
 /**
- * Iterator called on each result obtained for a DHT
- * operation that expects a reply
+ * Consider looking up the data in the DHT (anonymity-level permitting).
  *
- * @param cls closure, the 'struct GSF_PendingRequest *'.
- * @param exp when will this value expire
- * @param key key of the result
- * @param get_path NULL-terminated array of pointers
- *                 to the peers on reverse GET path (or NULL if not recorded)
- * @param put_path NULL-terminated array of pointers
- *                 to the peers on the PUT path (or NULL if not recorded)
- * @param type type of the result
- * @param size number of bytes in data
- * @param data pointer to the result data
+ * @param pr the pending request to process
  */
 void
-GSF_handle_dht_reply_ (void *cls,
-                      struct GNUNET_TIME_Absolute exp,
-                      const GNUNET_HashCode * key,
-                      const struct GNUNET_PeerIdentity * const *get_path,
-                      const struct GNUNET_PeerIdentity * const *put_path,
-                      enum GNUNET_BLOCK_Type type,
-                      size_t size,
-                      const void *data);
+GSF_dht_lookup_ (struct GSF_PendingRequest *pr);
 
 
 /**
- * Setup the subsystem.
+ * Function to be called after we're done processing
+ * replies from the local lookup.
+ *
+ * @param cls closure
+ * @param pr the pending request we were processing
+ * @param result final datastore lookup result
+ */
+typedef void (*GSF_LocalLookupContinuation) (void *cls,
+                                             struct GSF_PendingRequest * pr,
+                                             enum GNUNET_BLOCK_EvaluationResult
+                                             result);
+
+
+/**
+ * Look up the request in the local datastore.
  *
- * @param cfg configuration to use
+ * @param pr the pending request to process
+ * @param cont function to call at the end
+ * @param cont_cls closure for cont
+ */
+void
+GSF_local_lookup_ (struct GSF_PendingRequest *pr,
+                   GSF_LocalLookupContinuation cont, void *cont_cls);
+
+
+/**
+ * Is the given target a legitimate peer for forwarding the given request?
+ *
+ * @param pr request
+ * @param target
+ * @return GNUNET_YES if this request could be forwarded to the given peer
+ */
+int
+GSF_pending_request_test_target_ (struct GSF_PendingRequest *pr,
+                                  const struct GNUNET_PeerIdentity *target);
+
+
+
+/**
+ * Setup the subsystem.
  */
 void
 GSF_pending_request_init_ (void);