even nicer indentation, thanks to LRN's indent patch
[oweals/gnunet.git] / src / fs / gnunet-service-fs_pr.h
index ee5124a9056b6bcc4feea0065b47e4959d305d63..b68989be7a22613e373312f25a2e62e44ece5999 100644 (file)
  * Options for pending requests (bits to be ORed).
  */
 enum GSF_PendingRequestOptions
-  {
+{
     /**
      * 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_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)
+};
+
+
+/**
+ * Public data (in the sense of not encapsulated within
+ * 'gnunet-service-fs_pr', not in the sense of network-wide
+ * known) associated with each pending request.
+ */
+struct GSF_PendingRequestData
+{
+
+  /**
+   * Primary query hash for this request.
+   */
+  GNUNET_HashCode query;
+
+  /**
+   * 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.
+   */
+  struct GNUNET_TIME_Absolute ttl;
+
+  /**
+   * When did we start with the request.
+   */
+  struct GNUNET_TIME_Absolute start_time;
+
+  /**
+   * Desired anonymity level.
+   */
+  uint32_t anonymity_level;
+
+  /**
+   * Priority that this request (still) has for us.
+   */
+  uint32_t priority;
+
+  /**
+   * Priority that this request (originally) had for us.
+   */
+  uint32_t original_priority;
+
+  /**
+   * Options for the request.
+   */
+  enum GSF_PendingRequestOptions options;
+
+  /**
+   * Type of the requested block.
+   */
+  enum GNUNET_BLOCK_Type type;
+
+  /**
+   * Number of results we have found for this request so far.
+   */
+  unsigned int results_found;
+
+  /**
+   * Is the 'target' value set to a valid peer identity?
+   */
+  int has_target;
+
+};
 
 
 /**
@@ -75,14 +158,25 @@ enum GSF_PendingRequestOptions
  * 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 type type of the block
  * @param data response data, NULL on request expiration
  * @param data_len number of bytes in data
  */
-typedef void (*GSF_PendingRequestReplyHandler)(void *cls,
-                                              struct GSF_PendingRequest *pr,
-                                              const void *data,
-                                              size_t data_len);
+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,
+                                                enum GNUNET_BLOCK_Type type,
+                                                const void *data,
+                                                size_t data_len);
 
 
 /**
@@ -93,10 +187,14 @@ typedef void (*GSF_PendingRequestReplyHandler)(void *cls,
  * @param query key for the lookup
  * @param namespace namespace to lookup, NULL for no namespace
  * @param target preferred target for the request, NULL for none
- * @param bf bloom filter for known replies, can be NULL
+ * @param bf_data raw data for bloom filter for known replies, can be NULL
+ * @param bf_size number of bytes in bf_data
  * @param mingle mingle value for bf
  * @param anonymity_level desired anonymity level
  * @param priority maximum outgoing cummulative request priority to use
+ * @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 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
@@ -105,18 +203,17 @@ 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,
-                            struct GNUNET_CONTAINER_BloomFilter *bf,
-                            int32_t mingle,
-                            uint32_t anonymity_level,
-                            uint32_t priority,
-                            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,
+                             const GNUNET_HashCode * replies_seen,
+                             unsigned int replies_seen_count,
+                             GSF_PendingRequestReplyHandler rh, void *rh_cls);
 
 
 /**
@@ -129,28 +226,32 @@ 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);
 
 
 /**
- * Get the query for a given pending request.
- *
- * @param pr the request
- * @return pointer to the query (only valid as long as pr is valid)
+ * Obtain the public data associated with a pending request
+ * 
+ * @param pr pending request
+ * @return associated public data
  */
-const GNUNET_HashCode *
-GSF_pending_request_get_query_ (const struct GSF_PendingRequest *pr);
+struct GSF_PendingRequestData *
+GSF_pending_request_get_data_ (struct GSF_PendingRequest *pr);
 
 
 /**
- * Get the type of a given pending request.
- *
- * @param pr the request
- * @return query type
+ * 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 pra another pending request
+ * @return GNUNET_OK if the requests are compatible
  */
-enum GNUNET_BLOCK_Type
-GSF_pending_request_get_type_ (const struct GSF_PendingRequest *pr);
+int
+GSF_pending_request_is_compatible_ (struct GSF_PendingRequest *pra,
+                                    struct GSF_PendingRequest *prb);
 
 
 /**
@@ -160,33 +261,35 @@ GSF_pending_request_get_type_ (const struct GSF_PendingRequest *pr);
  * @param pr request to generate the message for
  * @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) or used
+ * @return number of bytes needed (if buf_size too small) or used
  */
 size_t
 GSF_pending_request_get_message_ (struct GSF_PendingRequest *pr,
-                                 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);
 
 
 /**
  * Signature of function called on each request.
+ * (Note: 'subtype' of GNUNET_CONTAINER_HashMapIterator).
  *
  * @param cls closure
  * @param key query for the request
  * @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);
 
 
 /**
@@ -196,8 +299,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);
 
 
 /**
@@ -206,16 +308,51 @@ GSF_iterate_pending_requests_ (GSF_PendingRequestIterator it,
  * this content and possibly passes it on (to local clients or other
  * peers).  Does NOT perform migration (content caching at this peer).
  *
- * @param other the other peer involved (sender or receiver, NULL
+ * @param cp the other peer involved (sender or receiver, NULL
  *        for loopback messages where we are both sender and receiver)
  * @param message the actual message
- * @return how valueable was the content to us (0 for not at all),
+ * @return GNUNET_OK if the message was well-formed,
  *         GNUNET_SYSERR if the message was malformed (close connection,
  *         do not cache under any circumstances)
  */
 int
-GSF_handle_p2p_content_ (const struct GNUNET_PeerIdentity *other,
-                        const struct GNUNET_MessageHeader *message);
+GSF_handle_p2p_content_ (struct GSF_ConnectedPeer *cp,
+                         const struct GNUNET_MessageHeader *message);
+
+
+/**
+ * Consider looking up the data in the DHT (anonymity-level permitting).
+ *
+ * @param pr the pending request to process
+ */
+void
+GSF_dht_lookup_ (struct GSF_PendingRequest *pr);
+
+
+/**
+ * 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 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);
 
 
 /**