char *buf;
ssize_t size_read;
char *iter_buf;
- const char *str_repr;
+ char *str_repr;
const struct GNUNET_PeerIdentity *peer;
if (0 == strncmp ("DISABLE", filename_valid_peers, 7))
buf = GNUNET_malloc (file_size);
size_read = GNUNET_DISK_file_read (fh, buf, file_size);
GNUNET_assert (size_read == file_size);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Restoring %" PRIu32 " peers from file `%s'\n",
+ num_peers,
+ filename_valid_peers);
for (iter_buf = buf; iter_buf < buf + file_size - 1; iter_buf += 53)
{
str_repr = GNUNET_strndup (iter_buf, 53);
peer = s2i_full (str_repr);
+ GNUNET_free (str_repr);
add_valid_peer (peer);
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Restored valid peer %s from disk\n",
GNUNET_i2s_full (peer));
}
+ iter_buf = NULL;
+ GNUNET_free (buf);
LOG (GNUNET_ERROR_TYPE_DEBUG,
"num_peers: %" PRIu32 ", _size (valid_peers): %u\n",
num_peers,
GNUNET_CONTAINER_multipeermap_size (valid_peers));
- GNUNET_assert (num_peers == GNUNET_CONTAINER_multipeermap_size (valid_peers));
+ if (num_peers != GNUNET_CONTAINER_multipeermap_size (valid_peers))
+ {
+ LOG (GNUNET_ERROR_TYPE_WARNING,
+ "Number of restored peers does not match file size. Have probably duplicates.\n");
+ }
GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh));
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Restored %u valid peers from disk\n",
- num_peers);
+ GNUNET_CONTAINER_multipeermap_size (valid_peers));
}
/**
- * @brief Remove unecessary data
+ * @brief Check if peer is removable.
*
- * If the other peer is not intending to send messages, we have messages pending
- * to be sent to this peer and we are not waiting for a reply, remove the
- * information about it (its #PeerContext).
+ * Check if
+ * - a recv channel exists
+ * - there are pending messages
+ * - there is no pending pull reply
*
- * @param peer the peer to clean
- * @return #GNUNET_YES if peer was removed
- * #GNUNET_NO otherwise
+ * @param peer the peer in question
+ * @return #GNUNET_YES if peer is removable
+ * #GNUNET_NO if peer is NOT removable
+ * #GNUNET_SYSERR if peer is not known
*/
int
-Peers_clean_peer (const struct GNUNET_PeerIdentity *peer)
+Peers_check_removable (const struct GNUNET_PeerIdentity *peer)
{
struct PeerContext *peer_ctx;
- // TODO actually remove unnecessary data
-
if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (peer_map, peer))
{
- return GNUNET_NO;
+ return GNUNET_SYSERR;
}
peer_ctx = get_peer_ctx (peer);
{
return GNUNET_NO;
}
- Peers_remove_peer (peer);
return GNUNET_YES;
}
}
if (NULL != peer_ctx->send_channel)
{
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Destroying send channel\n");
GNUNET_CADET_channel_destroy (peer_ctx->send_channel);
peer_ctx->send_channel = NULL;
}
if (NULL != peer_ctx->recv_channel)
{
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Destroying recv channel\n");
GNUNET_CADET_channel_destroy (peer_ctx->recv_channel);
peer_ctx->recv_channel = NULL;
}