/*
This file is part of GNUnet.
(C) 2009, 2010 Christian Grothoff (and other contributing authors)
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
by the Free Software Foundation; either version 3, or (at your
option) any later version.
GNUnet is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNUnet; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
/**
* @file fs/fs_publish.c
* @brief publish a file or directory in GNUnet
* @see https://gnunet.org/encoding
* @author Krista Bennett
* @author Christian Grothoff
*/
#include "platform.h"
#include "gnunet_constants.h"
#include "gnunet_signatures.h"
#include "gnunet_util_lib.h"
#include "gnunet_fs_service.h"
#include "fs_api.h"
#include "fs_tree.h"
/**
* Fill in all of the generic fields for
* a publish event and call the callback.
*
* @param pi structure to fill in
* @param pc overall publishing context
* @param p file information for the file being published
* @param offset where in the file are we so far
* @return value returned from callback
*/
void *
GNUNET_FS_publish_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
struct GNUNET_FS_PublishContext *pc,
const struct GNUNET_FS_FileInformation *p,
uint64_t offset)
{
pi->value.publish.pc = pc;
pi->value.publish.fi = p;
pi->value.publish.cctx = p->client_info;
pi->value.publish.pctx = (NULL == p->dir) ? NULL : p->dir->client_info;
pi->value.publish.filename = p->filename;
pi->value.publish.size =
(p->is_directory == GNUNET_YES) ? p->data.dir.dir_size : p->data.file.file_size;
pi->value.publish.eta =
GNUNET_TIME_calculate_eta (p->start_time, offset, pi->value.publish.size);
pi->value.publish.completed = offset;
pi->value.publish.duration =
GNUNET_TIME_absolute_get_duration (p->start_time);
pi->value.publish.anonymity = p->bo.anonymity_level;
return pc->h->upcb (pc->h->upcb_cls, pi);
}
/**
* Cleanup the publish context, we're done with it.
*
* @param pc struct to clean up
*/
static void
publish_cleanup (struct GNUNET_FS_PublishContext *pc)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up publish context (done!)\n");
if (pc->fhc != NULL)
{
GNUNET_CRYPTO_hash_file_cancel (pc->fhc);
pc->fhc = NULL;
}
GNUNET_FS_file_information_destroy (pc->fi, NULL, NULL);
if (pc->namespace != NULL)
{
GNUNET_FS_namespace_delete (pc->namespace, GNUNET_NO);
pc->namespace = N