Do not crash if key is NULL.
[oweals/gnunet.git] / src / fs / gnunet-service-fs_pr.h
index c8ea5b47fae92be84632b7ce6dfbacce6ba42dd9..309565d7e55927fec9351931c945a159393beaf3 100644 (file)
  */
 enum GSF_PendingRequestOptions
 {
+
+  /**
+   * No special options (P2P-default).
+   */
+  GSF_PRO_DEFAULTS = 0,
+
     /**
      * Request must only be processed locally.
      */
@@ -47,7 +53,7 @@ enum GSF_PendingRequestOptions
     /**
      * 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.
@@ -63,7 +69,7 @@ enum GSF_PendingRequestOptions
      * Option mask for typical local requests.
      */
   GSF_PRO_LOCAL_REQUEST =
-      (GSF_PRO_BLOOMFILTER_FULL_REFRESH | GSF_PRO_PRIORITY_UNLIMITED)
+      (GSF_PRO_BLOOMFILTER_FULL_REFRESH | GSF_PRO_PRIORITY_UNLIMITED | GSF_PRO_REQUEST_NEVER_EXPIRES)
 };
 
 
@@ -78,28 +84,23 @@ 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;
+  struct GNUNET_HashCode query;
 
   /**
-   * Identity of a peer hosting the content, only set if
-   * 'has_target' is GNUNET_YES.
+   * Identity of a peer hosting the content, otherwise NULl.
+   * Allocated after struct only if needed. Do not free!
    */
-  struct GNUNET_PeerIdentity target;
+  const struct GNUNET_PeerIdentity *target;
 
   /**
    * Fields for the plan module to track a DLL with the request.
    */
-  struct GSF_RequestPlanReference *rpr_head;
+  struct GSF_PendingRequestPlanBijection *pr_head;
 
   /**
    * Fields for the plan module to track a DLL with the request.
    */
-  struct GSF_RequestPlanReference *rpr_tail;
+  struct GSF_PendingRequestPlanBijection *pr_tail;
 
   /**
    * Current TTL for the request.
@@ -126,6 +127,22 @@ struct GSF_PendingRequestData
    */
   uint32_t original_priority;
 
+  /**
+   * Counter for how often this request has been transmitted (estimate,
+   * because we might have the same request pending for multiple clients,
+   * and of course because a transmission may have failed at a lower
+   * layer).
+   */
+  uint32_t num_transmissions;
+
+  /**
+   * How much respect did we (in total) offer for this request so far (estimate,
+   * because we might have the same request pending for multiple clients,
+   * and of course because a transmission may have failed at a lower
+   * layer).
+   */
+  uint32_t respect_offered;
+
   /**
    * Options for the request.
    */
@@ -142,9 +159,10 @@ struct GSF_PendingRequestData
   unsigned int results_found;
 
   /**
-   * Is the 'target' value set to a valid peer identity?
+   * Has this request been started yet (local/p2p operations)?  Or are
+   * we still constructing it?
    */
-  int has_target;
+  int has_started;
 
 };
 
@@ -162,6 +180,7 @@ struct GSF_PendingRequestData
  * @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
@@ -174,6 +193,8 @@ typedef void (*GSF_PendingRequestReplyHandler) (void *cls,
                                                 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);
@@ -185,7 +206,6 @@ typedef void (*GSF_PendingRequestReplyHandler) (void *cls,
  * @param options request options
  * @param type type of the block that is being requested
  * @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_data raw data for bloom filter for known replies, can be NULL
  * @param bf_size number of bytes in bf_data
@@ -195,6 +215,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
@@ -204,14 +225,14 @@ 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_HashCode * query,
                              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,
+                             GNUNET_PEER_Id origin_pid,
+                             const struct GNUNET_HashCode * replies_seen,
                              unsigned int replies_seen_count,
                              GSF_PendingRequestReplyHandler rh, void *rh_cls);
 
@@ -226,7 +247,7 @@ GSF_pending_request_create_ (enum GSF_PendingRequestOptions options,
  */
 void
 GSF_pending_request_update_ (struct GSF_PendingRequest *pr,
-                             const GNUNET_HashCode * replies_seen,
+                             const struct GNUNET_HashCode * replies_seen,
                              unsigned int replies_seen_count);
 
 
@@ -288,7 +309,7 @@ GSF_pending_request_cancel_ (struct GSF_PendingRequest *pr, int full_cleanup);
  * @return GNUNET_YES to continue to iterate
  */
 typedef int (*GSF_PendingRequestIterator) (void *cls,
-                                           const GNUNET_HashCode * key,
+                                           const struct GNUNET_HashCode * key,
                                            struct GSF_PendingRequest * pr);
 
 
@@ -329,6 +350,15 @@ void
 GSF_dht_lookup_ (struct GSF_PendingRequest *pr);
 
 
+/**
+ * Consider downloading via cadet (if possible)
+ *
+ * @param pr the pending request to process
+ */
+void
+GSF_cadet_lookup_ (struct GSF_PendingRequest *pr);
+
+
 /**
  * Function to be called after we're done processing
  * replies from the local lookup.
@@ -355,6 +385,19 @@ 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.
  */