flush peer respect value on disconnect
[oweals/gnunet.git] / src / fs / gnunet-service-fs_cp.c
index e901af25eb2b9b35253a6bdacae304c78e40acba..91102af6e10703b26b33ea9ef517f8b42fd4839d 100644 (file)
@@ -1514,6 +1514,32 @@ GSF_peer_update_responder_peer_ (struct GSF_ConnectedPeer *cp,
 }
 
 
+/**
+ * Write peer-respect information to a file - flush the buffer entry!
+ *
+ * @param cls unused
+ * @param key peer identity
+ * @param value the 'struct GSF_ConnectedPeer' to flush
+ * @return GNUNET_OK to continue iteration
+ */
+static int
+flush_respect (void *cls, const struct GNUNET_PeerIdentity * key, void *value)
+{
+  struct GSF_ConnectedPeer *cp = value;
+  struct GNUNET_PeerIdentity pid;
+
+  if (cp->ppd.respect == cp->disk_respect)
+    return GNUNET_OK;           /* unchanged */
+  GNUNET_assert (0 != cp->ppd.pid);
+  GNUNET_PEER_resolve (cp->ppd.pid, &pid);
+  GNUNET_PEERSTORE_store (peerstore, "fs", &pid, "respect", &cp->ppd.respect,
+                          sizeof (cp->ppd.respect),
+                          GNUNET_TIME_UNIT_FOREVER_ABS,
+                          GNUNET_PEERSTORE_STOREOPTION_REPLACE, NULL, NULL);
+  return GNUNET_OK;
+}
+
+
 /**
  * A peer disconnected from us.  Tear down the connected peer
  * record.
@@ -1533,6 +1559,7 @@ GSF_peer_disconnect_handler_ (void *cls,
   if (NULL == cp)
     return;                     /* must have been disconnect from core with
                                  * 'peer' == my_id, ignore */
+  flush_respect (NULL, peer, cp);
   GNUNET_assert (GNUNET_YES ==
                  GNUNET_CONTAINER_multipeermap_remove (cp_map,
                                                        peer,
@@ -1759,32 +1786,6 @@ GSF_block_peer_migration_ (struct GSF_ConnectedPeer *cp,
 }
 
 
-/**
- * Write peer-respect information to a file - flush the buffer entry!
- *
- * @param cls unused
- * @param key peer identity
- * @param value the 'struct GSF_ConnectedPeer' to flush
- * @return GNUNET_OK to continue iteration
- */
-static int
-flush_respect (void *cls, const struct GNUNET_PeerIdentity * key, void *value)
-{
-  struct GSF_ConnectedPeer *cp = value;
-  struct GNUNET_PeerIdentity pid;
-
-  if (cp->ppd.respect == cp->disk_respect)
-    return GNUNET_OK;           /* unchanged */
-  GNUNET_assert (0 != cp->ppd.pid);
-  GNUNET_PEER_resolve (cp->ppd.pid, &pid);
-  GNUNET_PEERSTORE_store (peerstore, "fs", &pid, "respect", &cp->ppd.respect,
-                          sizeof (cp->ppd.respect),
-                          GNUNET_TIME_UNIT_FOREVER_ABS,
-                          GNUNET_PEERSTORE_STOREOPTION_REPLACE, NULL, NULL);
-  return GNUNET_OK;
-}
-
-
 /**
  * Notify core about a preference we have for the given peer
  * (to allocate more resources towards it).  The change will