trying to fix #3576
[oweals/gnunet.git] / src / fs / gnunet-service-fs_cp.h
index a2cc5232cc907067b5b120fc901ecb6130ca1567..6b5fb4b0cb3611db267215bd30a27a5e4eb6d46e 100644 (file)
 #include "gnunet-service-fs.h"
 
 
+/**
+ * Maximum number of outgoing messages we queue per peer.
+ *
+ * Performance measurements for 2 peer setup for 50 MB file
+ * (with MAX_DATASTORE_QUEUE = 1 and RETRY_PROBABILITY_INV = 1):
+ *
+ *   2: 1700 kb/s, 1372 kb/s
+ *   8: 2117 kb/s, 1284 kb/s, 1112 kb/s
+ *  16: 3500 kb/s, 3200 kb/s, 3388 kb/s
+ *  32: 3441 kb/s, 3163 kb/s, 3277 kb/s
+ * 128: 1700 kb/s; 2010 kb/s, 3383 kb/s, 1156 kb/s
+ *
+ * Conclusion: 16 seems to be a pretty good value (stable
+ * and high performance, no excessive memory use).
+ */
+#define MAX_QUEUE_PER_PEER 16
+
+/**
+ * Length of the P2P success tracker.  Note that having a very long
+ * list can also hurt performance.
+ */
+#define P2P_SUCCESS_LIST_SIZE 8
+
+/**
+ * Length of the CS-2-P success tracker.  Note that
+ * having a very long list can also hurt performance.
+ */
+#define CS2P_SUCCESS_LIST_SIZE 8
+
+
 /**
  * Performance data kept for a peer.
  */
@@ -62,6 +92,13 @@ struct GSF_PeerPerformanceData
    */
   struct GNUNET_TIME_Relative avg_reply_delay;
 
+  /**
+   * If we get content we already have from this peer, for how
+   * long do we block him?  Adjusted based on the fraction of
+   * redundant data we receive, between 1s and 1h.
+   */
+  struct GNUNET_TIME_Relative migration_delay;
+
   /**
    * Point in time until which this peer does not want us to migrate content
    * to it.
@@ -96,9 +133,9 @@ struct GSF_PeerPerformanceData
   GNUNET_PEER_Id pid;
 
   /**
-   * Trust rating for this peer
+   * Respect rating for this peer
    */
-  uint32_t trust;
+  uint32_t respect;
 
   /**
    * Number of pending queries (replies are not counted)
@@ -110,10 +147,6 @@ struct GSF_PeerPerformanceData
    */
   unsigned int pending_replies;
 
-  /**
-   * How many of the last blocks from migration were duplicates?
-   */
-  unsigned int migration_duplication;
 };
 
 
@@ -156,6 +189,16 @@ typedef void (*GSF_PeerReserveCallback) (void *cls,
                                          int success);
 
 
+/**
+ * Function called after the creation of a connected peer record is complete.
+ *
+ * @param cls closure
+ * @param cp handle to the newly created connected peer record
+ */
+typedef void (*GSF_ConnectedPeerCreationCallback) (void *cls,
+                                                   struct GSF_ConnectedPeer *cp);
+
+
 /**
  * Handle to cancel a transmission request.
  */
@@ -167,14 +210,13 @@ struct GSF_PeerTransmitHandle;
  * records.
  *
  * @param peer identity of peer that connected
- * @param atsi performance data for the connection
- * @param atsi_count number of records in 'atsi'
- * @return handle to connected peer entry
+ * @param creation_cb callback function when the record is created.
+ * @param creation_cb_cls closure for @creation_cb
  */
-struct GSF_ConnectedPeer *
+void
 GSF_peer_connect_handler_ (const struct GNUNET_PeerIdentity *peer,
-                           const struct GNUNET_ATS_Information *atsi,
-                           unsigned int atsi_count);
+                           GSF_ConnectedPeerCreationCallback creation_cb,
+                           void *creation_cb_cls);
 
 
 /**
@@ -187,6 +229,17 @@ struct GSF_ConnectedPeer *
 GSF_peer_get_ (const struct GNUNET_PeerIdentity *peer);
 
 
+/**
+ * Update the latency information kept for the given peer.
+ *
+ * @param id peer record to update
+ * @param latency current latency value
+ */
+void
+GSF_update_peer_latency_ (const struct GNUNET_PeerIdentity *id,
+                         struct GNUNET_TIME_Relative latency);
+
+
 /**
  * Transmit a message to the given peer as soon as possible.
  * If the peer disconnects before the transmission can happen,
@@ -261,17 +314,13 @@ GSF_peer_update_responder_peer_ (struct GSF_ConnectedPeer *cp,
  * @param other the other peer involved (sender or receiver, NULL
  *        for loopback messages where we are both sender and receiver)
  * @param message the actual message
- * @param atsi performance information
- * @param atsi_count number of records in 'atsi'
  * @return GNUNET_OK to keep the connection open,
  *         GNUNET_SYSERR to close it (signal serious error)
  */
 int
 GSF_handle_p2p_migration_stop_ (void *cls,
                                 const struct GNUNET_PeerIdentity *other,
-                                const struct GNUNET_MessageHeader *message,
-                                const struct GNUNET_ATS_Information *atsi,
-                                unsigned int atsi_count);
+                                const struct GNUNET_MessageHeader *message);
 
 
 /**
@@ -309,7 +358,7 @@ GSF_get_peer_performance_data_ (struct GSF_ConnectedPeer *cp);
  */
 void
 GSF_block_peer_migration_ (struct GSF_ConnectedPeer *cp,
-                           struct GNUNET_TIME_Relative block_time);
+                           struct GNUNET_TIME_Absolute block_time);
 
 
 /**
@@ -351,7 +400,7 @@ GSF_connected_peer_change_preference_ (struct GSF_ConnectedPeer *cp,
 /**
  * Obtain the identity of a connected peer.
  *
- * @param cp peer to reserve bandwidth from
+ * @param cp peer to get identity of
  * @param id identity to set (written to)
  */
 void
@@ -359,6 +408,17 @@ GSF_connected_peer_get_identity_ (const struct GSF_ConnectedPeer *cp,
                                   struct GNUNET_PeerIdentity *id);
 
 
+/**
+ * Obtain the identity of a connected peer.
+ *
+ * @param cp peer to get identity of
+ * @return reference to peer identity, valid until peer disconnects (!)
+ */
+const struct GNUNET_PeerIdentity *
+GSF_connected_peer_get_identity2_ (const struct GSF_ConnectedPeer *cp);
+
+
+
 /**
  * Iterate over all connected peers.
  *