GNUnet 0.22.0
fs_publish.c File Reference

publish a file or directory in GNUnet More...

#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"
Include dependency graph for fs_publish.c:

Go to the source code of this file.

Functions

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)
 Fill in all of the generic fields for a publish event and call the callback. More...
 
static void publish_cleanup (struct GNUNET_FS_PublishContext *pc)
 Cleanup the publish context, we're done with it. More...
 
static void ds_put_cont (void *cls, int success, struct GNUNET_TIME_Absolute min_expiration, const char *msg)
 Function called by the datastore API with the result from the PUT request. More...
 
static void signal_publish_completion (struct GNUNET_FS_FileInformation *p, struct GNUNET_FS_PublishContext *pc)
 Generate the callback that signals clients that a file (or directory) has been completely published. More...
 
static void signal_publish_error (struct GNUNET_FS_FileInformation *p, struct GNUNET_FS_PublishContext *pc, const char *emsg)
 Generate the callback that signals clients that a file (or directory) has encountered a problem during publication. More...
 
static void finish_release_reserve (void *cls, int success, struct GNUNET_TIME_Absolute min_expiration, const char *msg)
 Datastore returns from reservation cancel request. More...
 
static void publish_sblocks_cont (void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg)
 We've finished publishing the SBlock as part of a larger upload. More...
 
static void publish_sblock (struct GNUNET_FS_PublishContext *pc)
 We are almost done publishing the structure, add SBlocks (if needed). More...
 
static void publish_kblocks_cont (void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg)
 We've finished publishing a KBlock as part of a larger upload. More...
 
static size_t block_reader (void *cls, uint64_t offset, size_t max, void *buf, char **emsg)
 Function called by the tree encoder to obtain a block of plaintext data (for the lowest level of the tree). More...
 
static void encode_cont (void *cls)
 The tree encoder has finished processing a file. More...
 
static void block_proc (void *cls, const struct ContentHashKey *chk, uint64_t offset, unsigned int depth, enum GNUNET_BLOCK_Type type, const void *block, uint16_t block_size)
 Function called asking for the current (encoded) block to be processed. More...
 
static void progress_proc (void *cls, uint64_t offset, const void *pt_block, size_t pt_size, unsigned int depth)
 Function called with information about our progress in computing the tree encoding. More...
 
static void publish_content (struct GNUNET_FS_PublishContext *pc)
 We are uploading a file or directory; load (if necessary) the next block into memory, encrypt it and send it to the FS service. More...
 
static int check_index_start_failed (void *cls, const struct GNUNET_MessageHeader *msg)
 Check the response from the "fs" service to our 'start index' request. More...
 
static void handle_index_start_failed (void *cls, const struct GNUNET_MessageHeader *msg)
 Process the response from the "fs" service to our 'start index' request. More...
 
static void handle_index_start_ok (void *cls, const struct GNUNET_MessageHeader *msg)
 Process the response from the "fs" service to our 'start index' request. More...
 
static void index_mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
 Generic error handler, called with the appropriate error code and the same closure specified at the creation of the message queue. More...
 
static void hash_for_index_cb (void *cls, const struct GNUNET_HashCode *res)
 Function called once the hash computation over an indexed file has completed. More...
 
static void publish_kblocks (struct GNUNET_FS_PublishContext *pc)
 We've computed the CHK/LOC URI, now publish the KSKs (if applicable). More...
 
static void handle_signature_response (void *cls, const struct ResponseLocSignatureMessage *sig)
 Process the response from the "fs" service to our LOC sign request. More...
 
static void loc_mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
 Generic error handler, called with the appropriate error code and the same closure specified at the creation of the message queue. More...
 
static void create_loc_uri (struct GNUNET_FS_PublishContext *pc)
 We're publishing without anonymity. More...
 
void GNUNET_FS_publish_main_ (void *cls)
 Main function that performs the upload. More...
 
static int fip_signal_start (void *cls, struct GNUNET_FS_FileInformation *fi, uint64_t length, struct GNUNET_FS_MetaData *meta, struct GNUNET_FS_Uri **uri, struct GNUNET_FS_BlockOptions *bo, int *do_index, void **client_info)
 Signal the FS's progress function that we are starting an upload. More...
 
static void suspend_operation (struct GNUNET_FS_FileInformation *fi, struct GNUNET_FS_PublishContext *pc)
 Actually signal the FS's progress function that we are suspending an upload. More...
 
static int fip_signal_suspend (void *cls, struct GNUNET_FS_FileInformation *fi, uint64_t length, struct GNUNET_FS_MetaData *meta, struct GNUNET_FS_Uri **uri, struct GNUNET_FS_BlockOptions *bo, int *do_index, void **client_info)
 Signal the FS's progress function that we are suspending an upload. More...
 
void GNUNET_FS_publish_signal_suspend_ (void *cls)
 Create SUSPEND event for the given publish operation and then clean up our state (without stop signal). More...
 
static void finish_reserve (void *cls, int success, struct GNUNET_TIME_Absolute min_expiration, const char *msg)
 We have gotten a reply for our space reservation request. More...
 
static uint64_t compute_contents_size (struct GNUNET_FS_FileInformation *fi)
 Calculate the total size of all of the files in the directory structure. More...
 
struct GNUNET_FS_PublishContextGNUNET_FS_publish_start (struct GNUNET_FS_Handle *h, struct GNUNET_FS_FileInformation *fi, const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns, const char *nid, const char *nuid, enum GNUNET_FS_PublishOptions options)
 Publish a file or directory. More...
 
static int fip_signal_stop (void *cls, struct GNUNET_FS_FileInformation *fi, uint64_t length, struct GNUNET_FS_MetaData *meta, struct GNUNET_FS_Uri **uri, struct GNUNET_FS_BlockOptions *bo, int *do_index, void **client_info)
 Signal the FS's progress function that we are stopping an upload. More...
 
void GNUNET_FS_publish_stop (struct GNUNET_FS_PublishContext *pc)
 Stop an upload. More...
 

Detailed Description

publish a file or directory in GNUnet

See also
https://gnunet.org/encoding
Author
Krista Bennett
Christian Grothoff

Definition in file fs_publish.c.

Function Documentation

◆ GNUNET_FS_publish_make_status_()

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 
)

Fill in all of the generic fields for a publish event and call the callback.

Parameters
pistructure to fill in
pcoverall publishing context
pfile information for the file being published
offsetwhere in the file are we so far
Returns
value returned from callback

Definition at line 48 of file fs_publish.c.

52{
53 pi->value.publish.pc = pc;
54 pi->value.publish.fi = p;
55 pi->value.publish.cctx = p->client_info;
56 pi->value.publish.pctx = (NULL == p->dir) ? NULL : p->dir->client_info;
57 pi->value.publish.filename = p->filename;
58 pi->value.publish.size =
59 (GNUNET_YES == p->is_directory) ? p->data.dir.dir_size :
60 p->data.file.file_size;
61 pi->value.publish.eta =
62 GNUNET_TIME_calculate_eta (p->start_time, offset,
63 pi->value.publish.size);
64 pi->value.publish.completed = offset;
65 pi->value.publish.duration =
67 pi->value.publish.anonymity = p->bo.anonymity_level;
68 pi->fsh = pc->h;
69 return pc->h->upcb (pc->h->upcb_cls, pi);
70}
static struct GNUNET_FS_PublishContext * pc
Handle to FS-publishing operation.
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-uri.c:38
@ GNUNET_YES
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_duration(struct GNUNET_TIME_Absolute whence)
Get the duration of an operation as the difference of the current time and the given start time "henc...
Definition: time.c:438
struct GNUNET_TIME_Relative GNUNET_TIME_calculate_eta(struct GNUNET_TIME_Absolute start, uint64_t finished, uint64_t total)
Calculate the estimate time of arrival/completion for an operation.
Definition: time.c:566
void * upcb_cls
Closure for upcb.
Definition: fs_api.h:1089
GNUNET_FS_ProgressCallback upcb
Function to call with updates on our progress.
Definition: fs_api.h:1084
struct GNUNET_FS_ProgressInfo::@21::GNUNET_FS_PublishStatusEvent publish
struct GNUNET_FS_Handle * fsh
File-sharing handle that generated the event.
union GNUNET_FS_ProgressInfo::@21 value
Values that depend on the event type.
struct GNUNET_FS_Handle * h
Handle to the global fs context.
Definition: fs_api.h:1184

References GNUNET_FS_ProgressInfo::fsh, GNUNET_TIME_absolute_get_duration(), GNUNET_TIME_calculate_eta(), GNUNET_YES, GNUNET_FS_PublishContext::h, p, pc, GNUNET_FS_ProgressInfo::publish, GNUNET_FS_Handle::upcb, GNUNET_FS_Handle::upcb_cls, and GNUNET_FS_ProgressInfo::value.

Referenced by ds_put_cont(), encode_cont(), fip_signal_resume(), fip_signal_start(), fip_signal_stop(), GNUNET_FS_publish_main_(), GNUNET_FS_publish_stop(), progress_proc(), signal_publish_completion(), signal_publish_error(), and suspend_operation().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ publish_cleanup()

static void publish_cleanup ( struct GNUNET_FS_PublishContext pc)
static

Cleanup the publish context, we're done with it.

Parameters
pcstruct to clean up

Definition at line 79 of file fs_publish.c.

80{
82 "Cleaning up publish context (done!)\n");
83 if (NULL != pc->fhc)
84 {
86 pc->fhc = NULL;
87 }
92 if (NULL != pc->dsh)
93 {
95 pc->dsh = NULL;
96 }
97 if (NULL != pc->mq)
98 {
100 pc->mq = NULL;
101 }
102 GNUNET_assert (NULL == pc->upload_task);
103 GNUNET_free (pc);
104}
void GNUNET_DATASTORE_disconnect(struct GNUNET_DATASTORE_Handle *h, int drop)
Disconnect from the datastore service (and free associated resources).
void GNUNET_FS_file_information_destroy(struct GNUNET_FS_FileInformation *fi, GNUNET_FS_FileInformationProcessor cleaner, void *cleaner_cls)
Destroy publish-structure.
#define GNUNET_log(kind,...)
void GNUNET_CRYPTO_hash_file_cancel(struct GNUNET_CRYPTO_FileHashContext *fhc)
Cancel a file hashing operation.
@ GNUNET_NO
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_free(ptr)
Wrapper around free.
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:700
struct GNUNET_DATASTORE_Handle * dsh
Connection to the datastore service.
Definition: fs_api.h:1236
struct GNUNET_CRYPTO_FileHashContext * fhc
Non-null if we are currently hashing a file.
Definition: fs_api.h:1231
char * nuid
ID for future updates, NULL if we have no namespace or no updates.
Definition: fs_api.h:1209
struct GNUNET_FS_FileInformation * fi
File-structure that is being shared.
Definition: fs_api.h:1194
struct GNUNET_MQ_Handle * mq
Our own message queue for the FS service; only briefly used when we start to index a file,...
Definition: fs_api.h:1221
char * nid
ID of the content in the namespace, NULL if we have no namespace.
Definition: fs_api.h:1204
struct GNUNET_SCHEDULER_Task * upload_task
ID of the task performing the upload.
Definition: fs_api.h:1259
char * serialization
Filename used for serializing information about this operation (should be determined using 'mktemp').
Definition: fs_api.h:1215

References GNUNET_FS_PublishContext::dsh, GNUNET_FS_PublishContext::fhc, GNUNET_FS_PublishContext::fi, GNUNET_assert, GNUNET_CRYPTO_hash_file_cancel(), GNUNET_DATASTORE_disconnect(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_FS_file_information_destroy(), GNUNET_log, GNUNET_MQ_destroy(), GNUNET_NO, GNUNET_FS_PublishContext::mq, GNUNET_FS_PublishContext::nid, GNUNET_FS_PublishContext::nuid, pc, GNUNET_FS_PublishContext::serialization, and GNUNET_FS_PublishContext::upload_task.

Referenced by GNUNET_FS_publish_signal_suspend_(), and GNUNET_FS_publish_stop().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ds_put_cont()

static void ds_put_cont ( void *  cls,
int  success,
struct GNUNET_TIME_Absolute  min_expiration,
const char *  msg 
)
static

Function called by the datastore API with the result from the PUT request.

Parameters
clsthe struct GNUNET_FS_PublishContext *
successGNUNET_OK on success
min_expirationminimum expiration time required for content to be stored
msgerror message (or NULL)

Definition at line 117 of file fs_publish.c.

121{
122 struct GNUNET_FS_PublishContext *pc = cls;
123 struct GNUNET_FS_ProgressInfo pi;
124
125 pc->qre = NULL;
126 if (GNUNET_SYSERR == success)
127 {
129 _ ("Publishing failed: %s"),
130 msg);
132 pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL;
133 pi.value.publish.specifics.error.message = pc->fi_pos->emsg;
136 if ((GNUNET_YES != pc->fi_pos->is_directory) &&
137 (NULL != pc->fi_pos->filename) &&
138 (GNUNET_YES == pc->any_done) &&
140 {
141 /* run unindex to clean up */
144 NULL);
145 }
146 return;
147 }
149 GNUNET_assert (NULL == pc->upload_task);
150 pc->upload_task =
153}
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
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)
Fill in all of the generic fields for a publish event and call the callback.
Definition: fs_publish.c:48
void GNUNET_FS_publish_main_(void *cls)
Main function that performs the upload.
Definition: fs_publish.c:1063
struct GNUNET_FS_UnindexContext * GNUNET_FS_unindex_start(struct GNUNET_FS_Handle *h, const char *filename, void *cctx)
Unindex a file.
Definition: fs_unindex.c:796
@ GNUNET_FS_STATUS_PUBLISH_ERROR
Notification that an error was encountered sharing a file structure.
@ GNUNET_SCHEDULER_PRIORITY_BACKGROUND
Run as background job (higher than idle, lower than default).
@ GNUNET_SYSERR
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_with_priority(enum GNUNET_SCHEDULER_Priority prio, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified priority.
Definition: scheduler.c:1230
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
char * filename
Name of the file or directory (must be an absolute path).
Definition: fs_api.h:302
struct GNUNET_FS_FileInformation::@52::@53 file
Data for a file.
char * emsg
Error message (non-NULL if this operation failed).
Definition: fs_api.h:297
void * client_info
Pointer kept for the client.
Definition: fs_api.h:248
union GNUNET_FS_FileInformation::@52 data
Data describing either the file or the directory.
int do_index
Should the file be indexed or inserted?
Definition: fs_api.h:339
int is_directory
Is this struct for a file or directory?
Definition: fs_api.h:391
Argument given to the progress callback with information about what is going on.
Handle for controlling a publication process.
Definition: fs_api.h:1180
struct GNUNET_FS_FileInformation * fi_pos
Current position in the file-tree for the upload.
Definition: fs_api.h:1226
int any_done
Set to GNUNET_YES if we were able to publish any block.
Definition: fs_api.h:1287
struct GNUNET_DATASTORE_QueueEntry * qre
Queue entry for reservation/unreservation.
Definition: fs_api.h:1241

References _, GNUNET_FS_PublishContext::any_done, GNUNET_FS_FileInformation::client_info, GNUNET_FS_FileInformation::data, GNUNET_FS_FileInformation::do_index, GNUNET_FS_FileInformation::emsg, GNUNET_FS_PublishContext::fi_pos, GNUNET_FS_FileInformation::file, GNUNET_FS_FileInformation::filename, GNUNET_asprintf(), GNUNET_assert, GNUNET_FS_publish_main_(), GNUNET_FS_publish_make_status_(), GNUNET_FS_STATUS_PUBLISH_ERROR, GNUNET_FS_unindex_start(), GNUNET_SCHEDULER_add_with_priority(), GNUNET_SCHEDULER_PRIORITY_BACKGROUND, GNUNET_SYSERR, GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, GNUNET_FS_PublishContext::h, GNUNET_FS_FileInformation::is_directory, msg, pc, GNUNET_FS_ProgressInfo::publish, GNUNET_FS_PublishContext::qre, GNUNET_FS_ProgressInfo::status, GNUNET_FS_PublishContext::upload_task, and GNUNET_FS_ProgressInfo::value.

Referenced by block_proc().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ signal_publish_completion()

static void signal_publish_completion ( struct GNUNET_FS_FileInformation p,
struct GNUNET_FS_PublishContext pc 
)
static

Generate the callback that signals clients that a file (or directory) has been completely published.

Parameters
pthe completed upload
pccontext of the publication

Definition at line 165 of file fs_publish.c.

167{
168 struct GNUNET_FS_ProgressInfo pi;
169
171 pi.value.publish.eta = GNUNET_TIME_UNIT_ZERO;
172 pi.value.publish.specifics.completed.chk_uri = p->chk_uri;
173 pi.value.publish.specifics.completed.sks_uri = p->sks_uri;
174 p->client_info =
176 p->data.file.file_size);
177}
@ GNUNET_FS_STATUS_PUBLISH_COMPLETED
Notification that we completed sharing a file structure.
#define GNUNET_TIME_UNIT_ZERO
Relative time zero.
enum GNUNET_FS_Status status
Specific status code (determines the event type).

References GNUNET_FS_publish_make_status_(), GNUNET_FS_STATUS_PUBLISH_COMPLETED, GNUNET_TIME_UNIT_ZERO, p, pc, GNUNET_FS_ProgressInfo::publish, GNUNET_FS_ProgressInfo::status, and GNUNET_FS_ProgressInfo::value.

Referenced by finish_release_reserve(), and publish_kblocks_cont().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ signal_publish_error()

static void signal_publish_error ( struct GNUNET_FS_FileInformation p,
struct GNUNET_FS_PublishContext pc,
const char *  emsg 
)
static

Generate the callback that signals clients that a file (or directory) has encountered a problem during publication.

Parameters
pthe upload that had trouble
pccontext of the publication
emsgerror message

Definition at line 190 of file fs_publish.c.

193{
194 struct GNUNET_FS_ProgressInfo pi;
195
196 p->emsg = GNUNET_strdup (emsg);
198 pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL;
199 pi.value.publish.specifics.error.message = emsg;
200 p->client_info = GNUNET_FS_publish_make_status_ (&pi, pc, p, 0);
201 if ((p->is_directory != GNUNET_YES) &&
202 (NULL != p->filename) &&
203 (GNUNET_YES == pc->any_done) &&
204 (p->data.file.do_index == GNUNET_YES))
205 {
206 /* run unindex to clean up */
208 p->filename,
209 NULL);
210 }
211}
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.

References GNUNET_FS_PublishContext::any_done, GNUNET_FS_publish_make_status_(), GNUNET_FS_STATUS_PUBLISH_ERROR, GNUNET_FS_unindex_start(), GNUNET_strdup, GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, GNUNET_FS_PublishContext::h, p, pc, GNUNET_FS_ProgressInfo::publish, GNUNET_FS_ProgressInfo::status, and GNUNET_FS_ProgressInfo::value.

Referenced by finish_reserve(), handle_index_start_failed(), publish_kblocks_cont(), and publish_sblocks_cont().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ finish_release_reserve()

static void finish_release_reserve ( void *  cls,
int  success,
struct GNUNET_TIME_Absolute  min_expiration,
const char *  msg 
)
static

Datastore returns from reservation cancel request.

Parameters
clsthe struct GNUNET_FS_PublishContext *
successsuccess code (not used)
min_expirationminimum expiration time required for content to be stored
msgerror message (typically NULL, not used)

Definition at line 223 of file fs_publish.c.

226{
227 struct GNUNET_FS_PublishContext *pc = cls;
228
229 pc->qre = NULL;
231 "Releasing reserve done!\n");
235}
void GNUNET_FS_publish_sync_(struct GNUNET_FS_PublishContext *pc)
Synchronize this publishing struct with its mirror on disk.
Definition: fs_api.c:1753
static void signal_publish_completion(struct GNUNET_FS_FileInformation *p, struct GNUNET_FS_PublishContext *pc)
Generate the callback that signals clients that a file (or directory) has been completely published.
Definition: fs_publish.c:165
int all_done
Set to GNUNET_YES if all processing has completed.
Definition: fs_api.h:1292

References GNUNET_FS_PublishContext::all_done, GNUNET_FS_PublishContext::fi, GNUNET_ERROR_TYPE_DEBUG, GNUNET_FS_publish_sync_(), GNUNET_log, GNUNET_YES, pc, GNUNET_FS_PublishContext::qre, and signal_publish_completion().

Referenced by publish_sblocks_cont().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ publish_sblocks_cont()

static void publish_sblocks_cont ( void *  cls,
const struct GNUNET_FS_Uri uri,
const char *  emsg 
)
static

We've finished publishing the SBlock as part of a larger upload.

Check the result and complete the larger upload.

Parameters
clsthe struct GNUNET_FS_PublishContext * of the larger upload
uriURI of the published SBlock
emsgNULL on success, otherwise error message

Definition at line 247 of file fs_publish.c.

250{
251 struct GNUNET_FS_PublishContext *pc = cls;
252
253 pc->sks_pc = NULL;
254 if (NULL != emsg)
255 {
256 signal_publish_error (pc->fi, pc, emsg);
258 return;
259 }
260 if (NULL != uri)
261 {
262 /* sks publication, remember namespace URI */
264 }
265 GNUNET_assert (pc->qre == NULL);
266 if ((pc->dsh != NULL) && (pc->rid != 0))
267 {
268 pc->qre =
269 GNUNET_DATASTORE_release_reserve (pc->dsh, pc->rid, UINT_MAX, UINT_MAX,
271 }
272 else
273 {
275 }
276}
static void finish_release_reserve(void *cls, int success, struct GNUNET_TIME_Absolute min_expiration, const char *msg)
Datastore returns from reservation cancel request.
Definition: fs_publish.c:223
static void signal_publish_error(struct GNUNET_FS_FileInformation *p, struct GNUNET_FS_PublishContext *pc, const char *emsg)
Generate the callback that signals clients that a file (or directory) has encountered a problem durin...
Definition: fs_publish.c:190
static struct GNUNET_FS_Uri * uri
Value of URI provided on command-line (when not publishing a file but just creating UBlocks to refer ...
struct GNUNET_DATASTORE_QueueEntry * GNUNET_DATASTORE_release_reserve(struct GNUNET_DATASTORE_Handle *h, uint32_t rid, unsigned int queue_priority, unsigned int max_queue_size, GNUNET_DATASTORE_ContinuationWithStatus cont, void *cont_cls)
Signal that all of the data for which a reservation was made has been stored and that whatever excess...
struct GNUNET_FS_Uri * GNUNET_FS_uri_dup(const struct GNUNET_FS_Uri *uri)
Duplicate URI.
Definition: fs_uri.c:987
@ GNUNET_OK
#define GNUNET_TIME_UNIT_ZERO_ABS
Absolute time zero.
struct GNUNET_FS_Uri * sks_uri
SKS URI for this file or directory.
Definition: fs_api.h:270
int rid
Space reservation ID with datastore service for this upload.
Definition: fs_api.h:1281
struct GNUNET_FS_PublishSksContext * sks_pc
Context for SKS publishing operation that is part of this publishing operation (NULL if not active).
Definition: fs_api.h:1247

References GNUNET_FS_PublishContext::dsh, GNUNET_FS_PublishContext::fi, finish_release_reserve(), GNUNET_assert, GNUNET_DATASTORE_release_reserve(), GNUNET_FS_publish_sync_(), GNUNET_FS_uri_dup(), GNUNET_OK, GNUNET_TIME_UNIT_ZERO_ABS, pc, GNUNET_FS_PublishContext::qre, GNUNET_FS_PublishContext::rid, signal_publish_error(), GNUNET_FS_PublishContext::sks_pc, GNUNET_FS_FileInformation::sks_uri, and uri.

Referenced by publish_sblock().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ publish_sblock()

static void publish_sblock ( struct GNUNET_FS_PublishContext pc)
static

We are almost done publishing the structure, add SBlocks (if needed).

Parameters
pcoverall upload data

Definition at line 286 of file fs_publish.c.

287{
288 if (NULL != pc->ns)
290 pc->ns,
291 pc->nid,
292 pc->nuid,
293 pc->fi->meta,
294 pc->fi->chk_uri,
295 &pc->fi->bo,
296 pc->options,
298 else
299 publish_sblocks_cont (pc, NULL, NULL);
300}
static void publish_sblocks_cont(void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg)
We've finished publishing the SBlock as part of a larger upload.
Definition: fs_publish.c:247
struct GNUNET_FS_PublishSksContext * GNUNET_FS_publish_sks(struct GNUNET_FS_Handle *h, const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns, const char *identifier, const char *update, const struct GNUNET_FS_MetaData *meta, const struct GNUNET_FS_Uri *uri, const struct GNUNET_FS_BlockOptions *bo, enum GNUNET_FS_PublishOptions options, GNUNET_FS_PublishContinuation cont, void *cont_cls)
Publish an SBlock on GNUnet.
Definition: fs_namespace.c:432
struct GNUNET_FS_BlockOptions bo
Block options for the file.
Definition: fs_api.h:275
struct GNUNET_FS_MetaData * meta
Metadata to use for the file.
Definition: fs_api.h:253
struct GNUNET_FS_Uri * chk_uri
CHK for this file or directory.
Definition: fs_api.h:264
enum GNUNET_FS_PublishOptions options
Options for publishing.
Definition: fs_api.h:1275
struct GNUNET_CRYPTO_EcdsaPrivateKey * ns
Namespace that we are publishing in, NULL if we have no namespace.
Definition: fs_api.h:1199

References GNUNET_FS_FileInformation::bo, GNUNET_FS_FileInformation::chk_uri, GNUNET_FS_PublishContext::fi, GNUNET_FS_publish_sks(), GNUNET_FS_PublishContext::h, GNUNET_FS_FileInformation::meta, GNUNET_FS_PublishContext::nid, GNUNET_FS_PublishContext::ns, GNUNET_FS_PublishContext::nuid, GNUNET_FS_PublishContext::options, pc, publish_sblocks_cont(), and GNUNET_FS_PublishContext::sks_pc.

Referenced by GNUNET_FS_publish_main_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ publish_kblocks_cont()

static void publish_kblocks_cont ( void *  cls,
const struct GNUNET_FS_Uri uri,
const char *  emsg 
)
static

We've finished publishing a KBlock as part of a larger upload.

Check the result and continue the larger upload.

Parameters
clsthe struct GNUNET_FS_PublishContext * of the larger upload
uriURI of the published blocks
emsgNULL on success, otherwise error message

Definition at line 313 of file fs_publish.c.

316{
317 struct GNUNET_FS_PublishContext *pc = cls;
319
320 pc->ksk_pc = NULL;
321 if (NULL != emsg)
322 {
324 "Error uploading KSK blocks: %s\n",
325 emsg);
329 GNUNET_assert (NULL == pc->upload_task);
330 pc->upload_task =
334 pc);
335 return;
336 }
338 "KSK blocks published, moving on to next file\n");
339 if (NULL != p->dir)
341 /* move on to next file */
342 if (NULL != p->next)
343 pc->fi_pos = p->next;
344 else
345 pc->fi_pos = p->dir;
347 GNUNET_assert (NULL == pc->upload_task);
348 pc->upload_task =
351}
void GNUNET_FS_file_information_sync_(struct GNUNET_FS_FileInformation *fi)
Create a temporary file on disk to store the current state of fi in.
Definition: fs_api.c:1328
Information for a file or directory that is about to be published.
Definition: fs_api.h:228
struct GNUNET_FS_PublishKskContext * ksk_pc
Context for KSK publishing operation that is part of this publishing operation (NULL if not active).
Definition: fs_api.h:1253

References GNUNET_FS_FileInformation::emsg, GNUNET_FS_PublishContext::fi_pos, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_FS_file_information_sync_(), GNUNET_FS_publish_main_(), GNUNET_FS_publish_sync_(), GNUNET_log, GNUNET_SCHEDULER_add_with_priority(), GNUNET_SCHEDULER_PRIORITY_BACKGROUND, GNUNET_FS_PublishContext::ksk_pc, p, pc, signal_publish_completion(), signal_publish_error(), and GNUNET_FS_PublishContext::upload_task.

Referenced by publish_kblocks().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ block_reader()

static size_t block_reader ( void *  cls,
uint64_t  offset,
size_t  max,
void *  buf,
char **  emsg 
)
static

Function called by the tree encoder to obtain a block of plaintext data (for the lowest level of the tree).

Parameters
clsour publishing context
offsetidentifies which block to get
max(maximum) number of bytes to get; returning fewer will also cause errors
bufwhere to copy the plaintext buffer
emsglocation to store an error message (on error)
Returns
number of bytes copied to buf, 0 on error

Definition at line 368 of file fs_publish.c.

373{
374 struct GNUNET_FS_PublishContext *pc = cls;
376 const char *dd;
377 size_t pt_size;
378
379 p = pc->fi_pos;
380 if (GNUNET_YES == p->is_directory)
381 {
382 pt_size = GNUNET_MIN (max, p->data.dir.dir_size - offset);
383 dd = p->data.dir.dir_data;
384 GNUNET_memcpy (buf, &dd[offset], pt_size);
385 }
386 else
387 {
388 if (UINT64_MAX == offset)
389 {
390 if (&GNUNET_FS_data_reader_file_ == p->data.file.reader)
391 {
392 /* force closing the file to avoid keeping too many files open */
393 p->data.file.reader (p->data.file.reader_cls, offset, 0, NULL, NULL);
394 }
395 return 0;
396 }
397 pt_size = GNUNET_MIN (max, p->data.file.file_size - offset);
398 if (0 == pt_size)
399 return 0; /* calling reader with pt_size==0
400 * might free buf, so don't! */
401 if (pt_size !=
402 p->data.file.reader (p->data.file.reader_cls, offset, pt_size, buf,
403 emsg))
404 return 0;
405 }
406 return pt_size;
407}
size_t GNUNET_FS_data_reader_file_(void *cls, uint64_t offset, size_t max, void *buf, char **emsg)
Function that provides data by reading from a file.
Definition: fs_api.c:447
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_MIN(a, b)
#define max(x, y)

References GNUNET_FS_FileInformation::emsg, GNUNET_FS_PublishContext::fi_pos, GNUNET_FS_data_reader_file_(), GNUNET_memcpy, GNUNET_MIN, GNUNET_YES, max, p, and pc.

Referenced by publish_content().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ encode_cont()

static void encode_cont ( void *  cls)
static

The tree encoder has finished processing a file.

Call it's finish method and deal with the final result.

Parameters
clsour publishing context

Definition at line 418 of file fs_publish.c.

419{
420 struct GNUNET_FS_PublishContext *pc = cls;
422 struct GNUNET_FS_ProgressInfo pi;
423 char *emsg;
424 uint64_t flen;
425
427 "Finished with tree encoder\n");
428 p = pc->fi_pos;
429 p->chk_uri = GNUNET_FS_tree_encoder_get_uri (p->te);
431 GNUNET_FS_tree_encoder_finish (p->te, &emsg);
432 p->te = NULL;
433 if (NULL != emsg)
434 {
436 "Error during tree walk: %s\n",
437 emsg);
438 GNUNET_asprintf (&p->emsg,
439 _ ("Publishing failed: %s"),
440 emsg);
441 GNUNET_free (emsg);
443 pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL;
444 pi.value.publish.specifics.error.message = p->emsg;
445 p->client_info = GNUNET_FS_publish_make_status_ (&pi, pc, p, 0);
446 }
447 else
448 {
449 /* final progress event */
450 GNUNET_assert (NULL != p->chk_uri);
451 flen = GNUNET_FS_uri_chk_get_file_size (p->chk_uri);
453 pi.value.publish.specifics.progress.data = NULL;
454 pi.value.publish.specifics.progress.offset = flen;
455 pi.value.publish.specifics.progress.data_len = 0;
456 pi.value.publish.specifics.progress.depth = GNUNET_FS_compute_depth (flen);
457 p->client_info = GNUNET_FS_publish_make_status_ (&pi, pc, p, flen);
458 }
459 /* continue with main */ /* continue with main */
460 GNUNET_assert (NULL == pc->upload_task);
461 pc->upload_task =
464}
unsigned int GNUNET_FS_compute_depth(uint64_t flen)
Compute the depth of the CHK tree.
Definition: fs_tree.c:125
void GNUNET_FS_tree_encoder_finish(struct GNUNET_FS_TreeEncoder *te, char **emsg)
Clean up a tree encoder and return information about possible errors.
Definition: fs_tree.c:432
struct GNUNET_FS_Uri * GNUNET_FS_tree_encoder_get_uri(struct GNUNET_FS_TreeEncoder *te)
Get the resulting URI from the encoding.
Definition: fs_tree.c:413
uint64_t GNUNET_FS_uri_chk_get_file_size(const struct GNUNET_FS_Uri *uri)
What is the size of the file that this URI refers to?
Definition: fs_uri.c:1360
@ GNUNET_FS_STATUS_PUBLISH_PROGRESS
Notification that we are making progress sharing a file structure.

References _, GNUNET_FS_PublishContext::fi_pos, GNUNET_asprintf(), GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_FS_compute_depth(), GNUNET_FS_file_information_sync_(), GNUNET_FS_publish_main_(), GNUNET_FS_publish_make_status_(), GNUNET_FS_STATUS_PUBLISH_ERROR, GNUNET_FS_STATUS_PUBLISH_PROGRESS, GNUNET_FS_tree_encoder_finish(), GNUNET_FS_tree_encoder_get_uri(), GNUNET_FS_uri_chk_get_file_size(), GNUNET_log, GNUNET_SCHEDULER_add_with_priority(), GNUNET_SCHEDULER_PRIORITY_BACKGROUND, GNUNET_TIME_UNIT_FOREVER_REL, p, pc, GNUNET_FS_ProgressInfo::publish, GNUNET_FS_ProgressInfo::status, GNUNET_FS_PublishContext::upload_task, and GNUNET_FS_ProgressInfo::value.

Referenced by publish_content().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ block_proc()

static void block_proc ( void *  cls,
const struct ContentHashKey chk,
uint64_t  offset,
unsigned int  depth,
enum GNUNET_BLOCK_Type  type,
const void *  block,
uint16_t  block_size 
)
static

Function called asking for the current (encoded) block to be processed.

After processing the client should either call GNUNET_FS_tree_encoder_next or (on error) GNUNET_FS_tree_encoder_finish.

Parameters
clsclosure
chkcontent hash key for the block
offsetoffset of the block in the file
depthdepth of the block in the file, 0 for DBLOCK
typetype of the block (IBLOCK or DBLOCK)
blockthe (encrypted) block
block_sizesize of block (in bytes)

Definition at line 482 of file fs_publish.c.

489{
490 struct GNUNET_FS_PublishContext *pc = cls;
492 struct OnDemandBlock odb;
493
494 p = pc->fi_pos;
495 if (NULL == pc->dsh)
496 {
498 "Waiting for datastore connection\n");
499 GNUNET_assert (NULL == pc->upload_task);
500 pc->upload_task =
503 return;
504 }
505
506 if ((GNUNET_YES != p->is_directory) &&
507 (GNUNET_YES == p->data.file.do_index) &&
509 {
511 "Indexing block `%s' for offset %llu with index size %u\n",
512 GNUNET_h2s (&chk->query),
513 (unsigned long long) offset,
514 (unsigned int) sizeof(struct OnDemandBlock));
515 odb.offset = GNUNET_htonll (offset);
516 odb.file_id = p->data.file.file_id;
517 GNUNET_assert (pc->qre == NULL);
518 pc->qre =
520 (p->is_directory == GNUNET_YES) ? 0 : pc->rid,
521 &chk->query,
522 sizeof(struct OnDemandBlock),
523 &odb,
525 p->bo.content_priority,
526 p->bo.anonymity_level,
527 p->bo.replication_level,
528 p->bo.expiration_time,
529 -2, 1,
530 &ds_put_cont, pc);
531 return;
532 }
534 "Publishing block `%s' for offset %llu with size %u\n",
535 GNUNET_h2s (&chk->query),
536 (unsigned long long) offset,
537 (unsigned int) block_size);
538 GNUNET_assert (pc->qre == NULL);
539 pc->qre =
540 GNUNET_DATASTORE_put (pc->dsh, (p->is_directory == GNUNET_YES) ? 0 :
541 pc->rid,
542 &chk->query,
543 block_size,
544 block,
545 type,
546 p->bo.content_priority,
547 p->bo.anonymity_level,
548 p->bo.replication_level,
549 p->bo.expiration_time,
550 -2, 1,
552 pc);
553}
static void ds_put_cont(void *cls, int success, struct GNUNET_TIME_Absolute min_expiration, const char *msg)
Function called by the datastore API with the result from the PUT request.
Definition: fs_publish.c:117
static uint32_t type
Type string converted to DNS type value.
struct GNUNET_DATASTORE_QueueEntry * GNUNET_DATASTORE_put(struct GNUNET_DATASTORE_Handle *h, uint32_t rid, const struct GNUNET_HashCode *key, size_t size, const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority, uint32_t anonymity, uint32_t replication, struct GNUNET_TIME_Absolute expiration, unsigned int queue_priority, unsigned int max_queue_size, GNUNET_DATASTORE_ContinuationWithStatus cont, void *cont_cls)
Store an item in the datastore.
uint64_t GNUNET_htonll(uint64_t n)
Convert unsigned 64-bit integer to network byte order.
Definition: common_endian.c:37
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
@ GNUNET_BLOCK_TYPE_FS_DBLOCK
Data block (leaf) in the CHK tree.
@ GNUNET_BLOCK_TYPE_FS_ONDEMAND
Type of a block representing a block to be encoded on demand from disk.
struct GNUNET_HashCode query
Hash of the encrypted content, used for querying.
Definition: fs.h:64
index block (indexing a DBlock that can be obtained directly from reading the plaintext file)
Definition: block_fs.h:86
uint64_t offset
At which offset should we be able to find this on-demand encoded block? (in NBO)
Definition: block_fs.h:98

References ds_put_cont(), GNUNET_FS_PublishContext::dsh, GNUNET_FS_PublishContext::fi_pos, OnDemandBlock::file_id, GNUNET_assert, GNUNET_BLOCK_TYPE_FS_DBLOCK, GNUNET_BLOCK_TYPE_FS_ONDEMAND, GNUNET_DATASTORE_put(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_FS_publish_main_(), GNUNET_h2s(), GNUNET_htonll(), GNUNET_log, GNUNET_SCHEDULER_add_with_priority(), GNUNET_SCHEDULER_PRIORITY_BACKGROUND, GNUNET_YES, OnDemandBlock::offset, p, pc, GNUNET_FS_PublishContext::qre, ContentHashKey::query, GNUNET_FS_PublishContext::rid, type, and GNUNET_FS_PublishContext::upload_task.

Referenced by publish_content().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ progress_proc()

static void progress_proc ( void *  cls,
uint64_t  offset,
const void *  pt_block,
size_t  pt_size,
unsigned int  depth 
)
static

Function called with information about our progress in computing the tree encoding.

Parameters
clsclosure
offsetwhere are we in the file
pt_blockplaintext of the currently processed block
pt_sizesize of pt_block
depthdepth of the block in the tree, 0 for DBLOCK

Definition at line 567 of file fs_publish.c.

571{
572 struct GNUNET_FS_PublishContext *pc = cls;
574 struct GNUNET_FS_FileInformation *par;
575 struct GNUNET_FS_ProgressInfo pi;
576
577 p = pc->fi_pos;
579 pi.value.publish.specifics.progress.data = pt_block;
580 pi.value.publish.specifics.progress.offset = offset;
581 pi.value.publish.specifics.progress.data_len = pt_size;
582 pi.value.publish.specifics.progress.depth = depth;
583 p->client_info = GNUNET_FS_publish_make_status_ (&pi, pc, p, offset);
584 if ((0 != depth) ||
585 (GNUNET_YES == p->is_directory))
586 return;
587 while (NULL != (par = p->dir))
588 {
589 p = par;
591 p->data.dir.contents_completed += pt_size;
593 pi.value.publish.specifics.progress_directory.completed =
594 p->data.dir.contents_completed;
595 pi.value.publish.specifics.progress_directory.total =
596 p->data.dir.contents_size;
597 pi.value.publish.specifics.progress_directory.eta =
598 GNUNET_TIME_calculate_eta (p->start_time,
599 p
600 ->data.dir.contents_completed,
601 p
602 ->data.dir.contents_size);
603 p->client_info = GNUNET_FS_publish_make_status_ (&pi, pc, p, 0);
604 }
605}
@ GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY
Notification that we are making progress sharing a directory.
unsigned int depth
Depth of the given block in the tree; 0 would be the lowest level (DBLOCKs).
uint64_t offset
At what offset in the file is "data"?

References GNUNET_FS_ProgressInfo::depth, GNUNET_FS_PublishContext::fi_pos, GNUNET_assert, GNUNET_FS_publish_make_status_(), GNUNET_FS_STATUS_PUBLISH_PROGRESS, GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY, GNUNET_TIME_calculate_eta(), GNUNET_YES, GNUNET_FS_FileInformation::is_directory, GNUNET_FS_ProgressInfo::offset, p, pc, GNUNET_FS_ProgressInfo::publish, GNUNET_FS_ProgressInfo::status, and GNUNET_FS_ProgressInfo::value.

Referenced by publish_content().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ publish_content()

static void publish_content ( struct GNUNET_FS_PublishContext pc)
static

We are uploading a file or directory; load (if necessary) the next block into memory, encrypt it and send it to the FS service.

Then continue with the main task.

Parameters
pcoverall upload data

Definition at line 616 of file fs_publish.c.

617{
619 char *emsg;
621 struct GNUNET_FS_FileInformation *dirpos;
622 void *raw_data;
623 uint64_t size;
624
625 p = pc->fi_pos;
626 GNUNET_assert (NULL != p);
627 if (NULL == p->te)
628 {
629 if (GNUNET_YES == p->is_directory)
630 {
631 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating directory\n");
633 dirpos = p->data.dir.entries;
634 while (NULL != dirpos)
635 {
636 if (GNUNET_YES == dirpos->is_directory)
637 {
638 raw_data = dirpos->data.dir.dir_data;
639 dirpos->data.dir.dir_data = NULL;
640 }
641 else
642 {
643 raw_data = NULL;
644 if ((dirpos->data.file.file_size < MAX_INLINE_SIZE) &&
645 (dirpos->data.file.file_size > 0))
646 {
647 raw_data = GNUNET_malloc (dirpos->data.file.file_size);
648 emsg = NULL;
649 if (dirpos->data.file.file_size !=
650 dirpos->data.file.reader (dirpos->data.file.reader_cls, 0,
651 dirpos->data.file.file_size, raw_data,
652 &emsg))
653 {
655 GNUNET_free (raw_data);
656 raw_data = NULL;
657 }
658 dirpos->data.file.reader (dirpos->data.file.reader_cls, UINT64_MAX,
659 0, 0, NULL);
660 }
661 }
663 raw_data);
664 GNUNET_free (raw_data);
665 dirpos = dirpos->next;
666 }
667 GNUNET_free (p->data.dir.dir_data);
668 p->data.dir.dir_data = NULL;
669 p->data.dir.dir_size = 0;
670 GNUNET_FS_directory_builder_finish (db, &p->data.dir.dir_size,
671 &p->data.dir.dir_data);
673 }
674 size = (GNUNET_YES == p->is_directory) ? p->data.dir.dir_size :
675 p->data.file.file_size;
677 "Creating tree encoder\n");
678 p->te =
681 &encode_cont);
682 }
684 "Processing next block from tree\n");
686}
#define MAX_INLINE_SIZE
Maximum size for a file to be considered for inlining in a directory.
Definition: fs_api.h:50
static void encode_cont(void *cls)
The tree encoder has finished processing a file.
Definition: fs_publish.c:418
static void progress_proc(void *cls, uint64_t offset, const void *pt_block, size_t pt_size, unsigned int depth)
Function called with information about our progress in computing the tree encoding.
Definition: fs_publish.c:567
static size_t block_reader(void *cls, uint64_t offset, size_t max, void *buf, char **emsg)
Function called by the tree encoder to obtain a block of plaintext data (for the lowest level of the ...
Definition: fs_publish.c:368
static void block_proc(void *cls, const struct ContentHashKey *chk, uint64_t offset, unsigned int depth, enum GNUNET_BLOCK_Type type, const void *block, uint16_t block_size)
Function called asking for the current (encoded) block to be processed.
Definition: fs_publish.c:482
void GNUNET_FS_tree_encoder_next(struct GNUNET_FS_TreeEncoder *te)
Encrypt the next block of the file (and call proc and progress accordingly; or of course "cont" if we...
Definition: fs_tree.c:320
struct GNUNET_FS_TreeEncoder * GNUNET_FS_tree_encoder_create(struct GNUNET_FS_Handle *h, uint64_t size, void *cls, GNUNET_FS_DataReader reader, GNUNET_FS_TreeBlockProcessor proc, GNUNET_FS_TreeProgressCallback progress, GNUNET_SCHEDULER_TaskCallback cont)
Initialize a tree encoder.
Definition: fs_tree.c:258
static struct GNUNET_FS_DirectoryBuilder * db
int GNUNET_FS_directory_builder_finish(struct GNUNET_FS_DirectoryBuilder *bld, size_t *rsize, void **rdata)
Finish building the directory.
Definition: fs_directory.c:578
struct GNUNET_FS_DirectoryBuilder * GNUNET_FS_directory_builder_create(const struct GNUNET_FS_MetaData *mdir)
Create a directory builder.
Definition: fs_directory.c:366
void GNUNET_FS_directory_builder_add(struct GNUNET_FS_DirectoryBuilder *bld, const struct GNUNET_FS_Uri *uri, const struct GNUNET_FS_MetaData *md, const void *data)
Add an entry to a directory.
Definition: fs_directory.c:392
#define GNUNET_malloc(size)
Wrapper around malloc.
static unsigned int size
Size of the "table".
Definition: peer.c:68
Internal state of a directory builder.
Definition: fs_directory.c:342
GNUNET_FS_DataReader reader
Function that can be used to read the data for the file.
Definition: fs_api.h:317
uint64_t file_size
Size of the file (in bytes).
Definition: fs_api.h:334
struct GNUNET_FS_FileInformation * next
Files in a directory are kept as a linked list.
Definition: fs_api.h:232
void * dir_data
Pointer to the data for the directory (or NULL if not available).
Definition: fs_api.h:374
void * reader_cls
Closure for reader.
Definition: fs_api.h:322
struct GNUNET_FS_FileInformation * dir
If this is a file in a directory, "dir" refers to the directory; otherwise NULL.
Definition: fs_api.h:238

References block_proc(), block_reader(), GNUNET_FS_FileInformation::chk_uri, GNUNET_FS_FileInformation::data, db, GNUNET_FS_FileInformation::dir, GNUNET_FS_FileInformation::dir_data, GNUNET_FS_FileInformation::emsg, encode_cont(), GNUNET_FS_PublishContext::fi_pos, GNUNET_FS_FileInformation::file, GNUNET_FS_FileInformation::file_size, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_FS_directory_builder_add(), GNUNET_FS_directory_builder_create(), GNUNET_FS_directory_builder_finish(), GNUNET_FS_file_information_sync_(), GNUNET_FS_tree_encoder_create(), GNUNET_FS_tree_encoder_next(), GNUNET_log, GNUNET_malloc, GNUNET_YES, GNUNET_FS_PublishContext::h, GNUNET_FS_FileInformation::is_directory, MAX_INLINE_SIZE, GNUNET_FS_FileInformation::meta, GNUNET_FS_FileInformation::next, p, pc, progress_proc(), GNUNET_FS_FileInformation::reader, GNUNET_FS_FileInformation::reader_cls, and size.

Referenced by GNUNET_FS_publish_main_(), handle_index_start_ok(), hash_for_index_cb(), and index_mq_error_handler().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_index_start_failed()

static int check_index_start_failed ( void *  cls,
const struct GNUNET_MessageHeader msg 
)
static

Check the response from the "fs" service to our 'start index' request.

Parameters
clsclosure (of type struct GNUNET_FS_PublishContext *)
msgthe response we got

Definition at line 697 of file fs_publish.c.

699{
700 size_t msize = ntohs (msg->size) - sizeof(*msg);
701 const char *emsg = (const char *) &msg[1];
702
703 if (emsg[msize - 1] != '\0')
704 {
705 GNUNET_break (0);
706 return GNUNET_SYSERR;
707 }
708 return GNUNET_OK;
709}
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.

References GNUNET_FS_FileInformation::emsg, GNUNET_break, GNUNET_OK, GNUNET_SYSERR, msg, and GNUNET_MessageHeader::size.

◆ handle_index_start_failed()

static void handle_index_start_failed ( void *  cls,
const struct GNUNET_MessageHeader msg 
)
static

Process the response from the "fs" service to our 'start index' request.

Parameters
clsclosure (of type struct GNUNET_FS_PublishContext *)
msgthe response we got

Definition at line 720 of file fs_publish.c.

722{
723 struct GNUNET_FS_PublishContext *pc = cls;
725 const char *emsg = (const char *) &msg[1];
726 char *msgtxt;
727
729 pc->mq = NULL;
730 p = pc->fi_pos;
731 GNUNET_asprintf (&msgtxt,
732 _ ("Can not index file `%s': %s.\n"),
733 p->filename,
734 gettext (emsg));
736 pc,
737 msgtxt);
738 GNUNET_free (msgtxt);
741}
#define gettext(Msgid)
Definition: gettext.h:50

References _, GNUNET_FS_FileInformation::emsg, GNUNET_FS_PublishContext::fi_pos, gettext, GNUNET_asprintf(), GNUNET_free, GNUNET_FS_file_information_sync_(), GNUNET_FS_publish_sync_(), GNUNET_MQ_destroy(), GNUNET_FS_PublishContext::mq, msg, p, pc, and signal_publish_error().

Here is the call graph for this function:

◆ handle_index_start_ok()

static void handle_index_start_ok ( void *  cls,
const struct GNUNET_MessageHeader msg 
)
static

Process the response from the "fs" service to our 'start index' request.

Parameters
clsclosure (of type struct GNUNET_FS_PublishContext *)
msgthe response we got

Definition at line 752 of file fs_publish.c.

754{
755 struct GNUNET_FS_PublishContext *pc = cls;
757
759 pc->mq = NULL;
760 p = pc->fi_pos;
761 p->data.file.index_start_confirmed = GNUNET_YES;
764}
static void publish_content(struct GNUNET_FS_PublishContext *pc)
We are uploading a file or directory; load (if necessary) the next block into memory,...
Definition: fs_publish.c:616

References GNUNET_FS_PublishContext::fi_pos, GNUNET_FS_file_information_sync_(), GNUNET_MQ_destroy(), GNUNET_YES, GNUNET_FS_PublishContext::mq, p, pc, and publish_content().

Here is the call graph for this function:

◆ index_mq_error_handler()

static void index_mq_error_handler ( void *  cls,
enum GNUNET_MQ_Error  error 
)
static

Generic error handler, called with the appropriate error code and the same closure specified at the creation of the message queue.

Not every message queue implementation supports an error handler.

Parameters
clsclosure with the struct GNUNET_FS_PublishContext *
errorerror code

Definition at line 776 of file fs_publish.c.

778{
779 struct GNUNET_FS_PublishContext *pc = cls;
781
782 if (NULL != pc->mq)
783 {
785 pc->mq = NULL;
786 }
787 p = pc->fi_pos;
789 _ ("Can not index file `%s': %s. Will try to insert instead.\n"),
790 p->filename,
791 _ ("error on index-start request to `fs' service"));
792 p->data.file.do_index = GNUNET_NO;
795}
@ GNUNET_ERROR_TYPE_WARNING

References _, GNUNET_FS_PublishContext::fi_pos, GNUNET_ERROR_TYPE_WARNING, GNUNET_FS_file_information_sync_(), GNUNET_log, GNUNET_MQ_destroy(), GNUNET_NO, GNUNET_FS_PublishContext::mq, p, pc, and publish_content().

Referenced by hash_for_index_cb().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hash_for_index_cb()

static void hash_for_index_cb ( void *  cls,
const struct GNUNET_HashCode res 
)
static

Function called once the hash computation over an indexed file has completed.

Parameters
clsclosure, our publishing context
resresulting hash, NULL on error

Definition at line 806 of file fs_publish.c.

808{
809 struct GNUNET_FS_PublishContext *pc = cls;
811 GNUNET_MQ_hd_fixed_size (index_start_ok,
814 pc),
815 GNUNET_MQ_hd_var_size (index_start_failed,
818 pc),
820 };
822 struct GNUNET_MQ_Envelope *env;
823 struct IndexStartMessage *ism;
824 size_t slen;
825 uint64_t dev;
826 uint64_t ino;
827 char *fn;
828
829 pc->fhc = NULL;
830 p = pc->fi_pos;
831 if (NULL == res)
832 {
834 _ (
835 "Can not index file `%s': %s. Will try to insert instead.\n"),
836 p->filename,
837 _ ("failed to compute hash"));
838 p->data.file.do_index = GNUNET_NO;
841 return;
842 }
843 if (GNUNET_YES == p->data.file.index_start_confirmed)
844 {
846 return;
847 }
848 fn = GNUNET_STRINGS_filename_expand (p->filename);
849 GNUNET_assert (fn != NULL);
850 slen = strlen (fn) + 1;
851 if (slen >=
853 {
855 _
856 ("Can not index file `%s': %s. Will try to insert instead.\n"),
857 fn, _ ("filename too long"));
858 GNUNET_free (fn);
859 p->data.file.do_index = GNUNET_NO;
862 return;
863 }
865 "Hash of indexed file `%s' is `%s'\n",
866 p->filename,
867 GNUNET_h2s (res));
869 {
870 p->data.file.file_id = *res;
871 p->data.file.have_hash = GNUNET_YES;
872 p->data.file.index_start_confirmed = GNUNET_YES;
875 GNUNET_free (fn);
876 return;
877 }
879 "fs",
880 handlers,
882 pc);
883 if (NULL == pc->mq)
884 {
886 _ (
887 "Can not index file `%s': %s. Will try to insert instead.\n"),
888 p->filename,
889 _ ("could not connect to `fs' service"));
890 p->data.file.do_index = GNUNET_NO;
892 GNUNET_free (fn);
893 return;
894 }
895 if (p->data.file.have_hash != GNUNET_YES)
896 {
897 p->data.file.file_id = *res;
898 p->data.file.have_hash = GNUNET_YES;
900 }
902 slen,
904 if (GNUNET_OK ==
906 &dev,
907 &ino))
908 {
909 ism->device = GNUNET_htonll (dev);
910 ism->inode = GNUNET_htonll (ino);
911 }
912 else
913 {
915 _ ("Failed to get file identifiers for `%s'\n"),
916 p->filename);
917 }
918 ism->file_id = *res;
919 GNUNET_memcpy (&ism[1],
920 fn,
921 slen);
922 GNUNET_free (fn);
924 env);
925}
struct GNUNET_MQ_MessageHandlers handlers[]
Definition: 003.c:1
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
static void index_mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
Generic error handler, called with the appropriate error code and the same closure specified at the c...
Definition: fs_publish.c:776
static char * res
Currently read line or NULL on EOF.
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message,...
struct GNUNET_MQ_Handle * GNUNET_CLIENT_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *service_name, const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_ErrorHandler error_handler, void *error_handler_cls)
Create a message queue to connect to a GNUnet service.
Definition: client.c:1060
enum GNUNET_GenericReturnValue GNUNET_DISK_file_get_identifiers(const char *filename, uint64_t *dev, uint64_t *ino)
Obtain some unique identifiers for the given file that can be used to identify it in the local system...
Definition: disk.c:241
@ GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY
Simulate publishing.
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:305
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
Definition: gnunet_mq_lib.h:63
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
#define GNUNET_MESSAGE_TYPE_FS_INDEX_START
Message sent by fs client to start indexing.
#define GNUNET_MESSAGE_TYPE_FS_INDEX_START_FAILED
Response to a request for start indexing that refuses.
#define GNUNET_MESSAGE_TYPE_FS_INDEX_START_OK
Affirmative response to a request for start indexing.
char * GNUNET_STRINGS_filename_expand(const char *fil)
Complete filename (a la shell) from abbrevition.
Definition: strings.c:504
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
Definition: fs_api.h:1074
Message handler for a specific message type.
Header for all communications.
Message sent from a GNUnet (fs) publishing activity to the gnunet-fs-service to initiate indexing of ...
Definition: fs.h:153
uint64_t inode
Inode of the file on the given device, as seen by the client ("st_ino" field from "struct stat").
Definition: fs.h:179
struct GNUNET_HashCode file_id
Hash of the file that we would like to index.
Definition: fs.h:184
uint64_t device
ID of device containing the file, as seen by the client.
Definition: fs.h:171

References _, GNUNET_FS_Handle::cfg, IndexStartMessage::device, env, GNUNET_FS_PublishContext::fhc, GNUNET_FS_PublishContext::fi_pos, IndexStartMessage::file_id, GNUNET_assert, GNUNET_CLIENT_connect(), GNUNET_DISK_file_get_identifiers(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_FS_file_information_sync_(), GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY, GNUNET_h2s(), GNUNET_htonll(), GNUNET_log, GNUNET_MAX_MESSAGE_SIZE, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_FS_INDEX_START, GNUNET_MESSAGE_TYPE_FS_INDEX_START_FAILED, GNUNET_MESSAGE_TYPE_FS_INDEX_START_OK, GNUNET_MQ_handler_end, GNUNET_MQ_hd_fixed_size, GNUNET_MQ_hd_var_size, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), GNUNET_NO, GNUNET_OK, GNUNET_STRINGS_filename_expand(), GNUNET_YES, GNUNET_FS_PublishContext::h, handlers, index_mq_error_handler(), IndexStartMessage::inode, GNUNET_FS_PublishContext::mq, GNUNET_FS_PublishContext::options, p, pc, publish_content(), and res.

Referenced by GNUNET_FS_publish_main_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ publish_kblocks()

static void publish_kblocks ( struct GNUNET_FS_PublishContext pc)
static

We've computed the CHK/LOC URI, now publish the KSKs (if applicable).

Parameters
pcpublishing context to do this for

Definition at line 934 of file fs_publish.c.

935{
937
938 p = pc->fi_pos;
939 /* upload of "p" complete, publish KBlocks! */
940 if (NULL != p->keywords)
941 {
943 p->keywords,
944 p->meta,
945 p->chk_uri,
946 &p->bo,
947 pc->options,
949 pc);
950 }
951 else
952 {
953 publish_kblocks_cont (pc, p->chk_uri, NULL);
954 }
955}
static void publish_kblocks_cont(void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg)
We've finished publishing a KBlock as part of a larger upload.
Definition: fs_publish.c:313
struct GNUNET_FS_PublishKskContext * GNUNET_FS_publish_ksk(struct GNUNET_FS_Handle *h, const struct GNUNET_FS_Uri *ksk_uri, const struct GNUNET_FS_MetaData *meta, const struct GNUNET_FS_Uri *uri, const struct GNUNET_FS_BlockOptions *bo, enum GNUNET_FS_PublishOptions options, GNUNET_FS_PublishContinuation cont, void *cont_cls)
Publish a KBlock on GNUnet.

References GNUNET_FS_PublishContext::fi_pos, GNUNET_FS_publish_ksk(), GNUNET_FS_PublishContext::h, GNUNET_FS_PublishContext::ksk_pc, GNUNET_FS_PublishContext::options, p, pc, and publish_kblocks_cont().

Referenced by create_loc_uri(), GNUNET_FS_publish_main_(), handle_signature_response(), and loc_mq_error_handler().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ handle_signature_response()

static void handle_signature_response ( void *  cls,
const struct ResponseLocSignatureMessage sig 
)
static

Process the response from the "fs" service to our LOC sign request.

Parameters
clsclosure (of type struct GNUNET_FS_PublishContext *)
sigthe response we got

Definition at line 965 of file fs_publish.c.

967{
968 struct GNUNET_FS_PublishContext *pc = cls;
970
971 p = pc->fi_pos;
972 p->chk_uri->type = GNUNET_FS_URI_LOC;
973 /* p->data.loc.fi kept from CHK before */
974 p->chk_uri->data.loc.peer = sig->peer;
975 p->chk_uri->data.loc.expirationTime
977 p->chk_uri->data.loc.contentSignature = sig->signature;
981}
@ GNUNET_FS_URI_LOC
Location (chk with identity of hosting peer).
Definition: fs_api.h:159
static void publish_kblocks(struct GNUNET_FS_PublishContext *pc)
We've computed the CHK/LOC URI, now publish the KSKs (if applicable).
Definition: fs_publish.c:934
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition: time.c:739
struct GNUNET_CRYPTO_EddsaSignature signature
The requested signature.
Definition: fs.h:130
struct GNUNET_PeerIdentity peer
Identity of the peer sharing the file.
Definition: fs.h:135
struct GNUNET_TIME_AbsoluteNBO expiration_time
Expiration time that was actually used (rounded!).
Definition: fs.h:125

References ResponseLocSignatureMessage::expiration_time, GNUNET_FS_PublishContext::fi_pos, GNUNET_FS_file_information_sync_(), GNUNET_FS_publish_sync_(), GNUNET_FS_URI_LOC, GNUNET_TIME_absolute_ntoh(), p, pc, ResponseLocSignatureMessage::peer, publish_kblocks(), and ResponseLocSignatureMessage::signature.

Here is the call graph for this function:

◆ loc_mq_error_handler()

static void loc_mq_error_handler ( void *  cls,
enum GNUNET_MQ_Error  error 
)
static

Generic error handler, called with the appropriate error code and the same closure specified at the creation of the message queue.

Not every message queue implementation supports an error handler.

Parameters
clsclosure with the struct GNUNET_FS_PublishContext *
errorerror code

Definition at line 993 of file fs_publish.c.

995{
996 struct GNUNET_FS_PublishContext *pc = cls;
997
998 if (NULL != pc->mq)
999 {
1001 pc->mq = NULL;
1002 }
1004 _ ("Can not create LOC URI. Will continue with CHK instead.\n"));
1006}

References _, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_MQ_destroy(), GNUNET_FS_PublishContext::mq, pc, and publish_kblocks().

Referenced by create_loc_uri().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ create_loc_uri()

static void create_loc_uri ( struct GNUNET_FS_PublishContext pc)
static

We're publishing without anonymity.

Contact the FS service to create a signed LOC URI for further processing, then continue with KSKs.

Parameters
pcthe publishing context do to this for

Definition at line 1017 of file fs_publish.c.

1018{
1020 GNUNET_MQ_hd_fixed_size (signature_response,
1023 pc),
1025 };
1026 struct GNUNET_MQ_Envelope *env;
1027 struct RequestLocSignatureMessage *req;
1029
1030 if (NULL != pc->mq)
1033 "fs",
1034 handlers,
1036 pc);
1037 if (NULL == pc->mq)
1038 {
1040 _ (
1041 "Can not create LOC URI. Will continue with CHK instead.\n"));
1043 return;
1044 }
1045 p = pc->fi_pos;
1046 env = GNUNET_MQ_msg (req,
1049 req->expiration_time = GNUNET_TIME_absolute_hton (p->bo.expiration_time);
1050 req->chk = p->chk_uri->data.chk.chk;
1051 req->file_length = GNUNET_htonll (p->chk_uri->data.chk.file_length);
1053 env);
1054}
static void loc_mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
Generic error handler, called with the appropriate error code and the same closure specified at the c...
Definition: fs_publish.c:993
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:78
#define GNUNET_MESSAGE_TYPE_FS_REQUEST_LOC_SIGN
Message sent by fs client to request LOC signature.
#define GNUNET_MESSAGE_TYPE_FS_REQUEST_LOC_SIGNATURE
Reply sent by fs service with LOC signature.
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:640
#define GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT
Signature by which a peer affirms that it is providing a certain bit of content for use in LOCation U...
Message sent from a GNUnet (fs) publishing activity to sign a LOC URI.
Definition: fs.h:76
uint64_t file_length
Size of the shared file (to be signed).
Definition: fs.h:101
uint32_t purpose
Requested signature purpose.
Definition: fs.h:86
struct GNUNET_TIME_AbsoluteNBO expiration_time
Requested expiration time.
Definition: fs.h:91
struct ContentHashKey chk
Information about the shared file (to be signed).
Definition: fs.h:96
Message sent from the service with the signed LOC URI.
Definition: fs.h:109

References _, GNUNET_FS_Handle::cfg, RequestLocSignatureMessage::chk, env, RequestLocSignatureMessage::expiration_time, GNUNET_FS_PublishContext::fi_pos, RequestLocSignatureMessage::file_length, GNUNET_CLIENT_connect(), GNUNET_ERROR_TYPE_WARNING, GNUNET_htonll(), GNUNET_log, GNUNET_MESSAGE_TYPE_FS_REQUEST_LOC_SIGN, GNUNET_MESSAGE_TYPE_FS_REQUEST_LOC_SIGNATURE, GNUNET_MQ_destroy(), GNUNET_MQ_handler_end, GNUNET_MQ_hd_fixed_size, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT, GNUNET_TIME_absolute_hton(), GNUNET_FS_PublishContext::h, handlers, loc_mq_error_handler(), GNUNET_FS_PublishContext::mq, p, pc, publish_kblocks(), and RequestLocSignatureMessage::purpose.

Referenced by GNUNET_FS_publish_main_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_FS_publish_main_()

void GNUNET_FS_publish_main_ ( void *  cls)

Main function that performs the upload.

Parameters
clsstruct GNUNET_FS_PublishContext * identifies the upload

Definition at line 1063 of file fs_publish.c.

1064{
1065 struct GNUNET_FS_PublishContext *pc = cls;
1066 struct GNUNET_FS_ProgressInfo pi;
1068 char *fn;
1069
1070 pc->upload_task = NULL;
1071 p = pc->fi_pos;
1072 if (NULL == p)
1073 {
1075 "Publishing complete, now publishing SKS and KSK blocks.\n");
1076 /* upload of entire hierarchy complete,
1077 * publish namespace entries */
1080 return;
1081 }
1082 /* find starting position */
1083 while ((GNUNET_YES == p->is_directory) &&
1084 (NULL != p->data.dir.entries) &&
1085 (NULL == p->emsg) &&
1086 (NULL == p->data.dir.entries->chk_uri))
1087 {
1088 p = p->data.dir.entries;
1089 pc->fi_pos = p;
1091 }
1092 /* abort on error */
1093 if (NULL != p->emsg)
1094 {
1096 "Error uploading: %s\n",
1097 p->emsg);
1098 /* error with current file, abort all
1099 * related files as well! */
1100 while (NULL != p->dir)
1101 {
1104 p = p->dir;
1105 if (fn != NULL)
1106 {
1107 GNUNET_asprintf (&p->emsg,
1108 _ ("Recursive upload failed at `%s': %s"),
1109 fn,
1110 p->emsg);
1111 GNUNET_free (fn);
1112 }
1113 else
1114 {
1115 GNUNET_asprintf (&p->emsg,
1116 _ ("Recursive upload failed: %s"),
1117 p->emsg);
1118 }
1120 pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL;
1121 pi.value.publish.specifics.error.message = p->emsg;
1122 p->client_info = GNUNET_FS_publish_make_status_ (&pi, pc, p, 0);
1123 }
1126 return;
1127 }
1128 /* handle completion */
1129 if (NULL != p->chk_uri)
1130 {
1132 "File upload complete, now publishing KSK blocks.\n");
1134
1135 if ((0 == p->bo.anonymity_level) &&
1136 (GNUNET_YES !=
1137 GNUNET_FS_uri_test_loc (p->chk_uri)))
1138 {
1139 /* zero anonymity, box CHK URI in LOC URI */
1141 }
1142 else
1143 {
1145 }
1146 return;
1147 }
1148 if ((GNUNET_YES != p->is_directory) && (p->data.file.do_index))
1149 {
1150 if (NULL == p->filename)
1151 {
1152 p->data.file.do_index = GNUNET_NO;
1154 _ (
1155 "Can not index file `%s': %s. Will try to insert instead.\n"),
1156 "<no-name>",
1157 _ ("needs to be an actual file"));
1160 return;
1161 }
1162 if (p->data.file.have_hash)
1163 {
1164 hash_for_index_cb (pc, &p->data.file.file_id);
1165 }
1166 else
1167 {
1168 p->start_time = GNUNET_TIME_absolute_get ();
1169 pc->fhc =
1172 }
1173 return;
1174 }
1176}
#define HASHING_BLOCKSIZE
Blocksize to use when hashing files for indexing (blocksize for IO, not for the DBlocks).
Definition: fs.h:48
static void create_loc_uri(struct GNUNET_FS_PublishContext *pc)
We're publishing without anonymity.
Definition: fs_publish.c:1017
static void publish_sblock(struct GNUNET_FS_PublishContext *pc)
We are almost done publishing the structure, add SBlocks (if needed).
Definition: fs_publish.c:286
static void hash_for_index_cb(void *cls, const struct GNUNET_HashCode *res)
Function called once the hash computation over an indexed file has completed.
Definition: fs_publish.c:806
#define EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME
int GNUNET_FS_uri_test_loc(const struct GNUNET_FS_Uri *uri)
Is this a location URI?
Definition: fs_uri.c:1401
struct GNUNET_CRYPTO_FileHashContext * GNUNET_CRYPTO_hash_file(enum GNUNET_SCHEDULER_Priority priority, const char *filename, size_t blocksize, GNUNET_CRYPTO_HashCompletedCallback callback, void *callback_cls)
Compute the hash of an entire file.
@ GNUNET_SCHEDULER_PRIORITY_IDLE
Run when otherwise idle.
char * GNUNET_FS_meta_data_get_by_type(const struct GNUNET_FS_MetaData *md, enum EXTRACTOR_MetaType type)
Get the first MD entry of the given type.
Definition: meta_data.c:438
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:111

References _, GNUNET_FS_PublishContext::all_done, create_loc_uri(), EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, GNUNET_FS_PublishContext::fhc, GNUNET_FS_PublishContext::fi_pos, GNUNET_asprintf(), GNUNET_CRYPTO_hash_file(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_FS_file_information_sync_(), GNUNET_FS_meta_data_get_by_type(), GNUNET_FS_publish_make_status_(), GNUNET_FS_publish_sync_(), GNUNET_FS_STATUS_PUBLISH_ERROR, GNUNET_FS_uri_test_loc(), GNUNET_log, GNUNET_NO, GNUNET_SCHEDULER_PRIORITY_IDLE, GNUNET_TIME_absolute_get(), GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, hash_for_index_cb(), HASHING_BLOCKSIZE, p, pc, GNUNET_FS_ProgressInfo::publish, publish_content(), publish_kblocks(), publish_sblock(), GNUNET_FS_ProgressInfo::status, GNUNET_FS_PublishContext::upload_task, and GNUNET_FS_ProgressInfo::value.

Referenced by block_proc(), deserialize_publish_file(), ds_put_cont(), encode_cont(), finish_reserve(), GNUNET_FS_publish_start(), and publish_kblocks_cont().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fip_signal_start()

static int fip_signal_start ( void *  cls,
struct GNUNET_FS_FileInformation fi,
uint64_t  length,
struct GNUNET_FS_MetaData meta,
struct GNUNET_FS_Uri **  uri,
struct GNUNET_FS_BlockOptions bo,
int *  do_index,
void **  client_info 
)
static

Signal the FS's progress function that we are starting an upload.

Parameters
clsclosure (of type struct GNUNET_FS_PublishContext *)
fithe entry in the publish-structure
lengthlength of the file or directory
metametadata for the file or directory (can be modified)
uripointer to the keywords that will be used for this entry (can be modified)
boblock options
do_indexshould we index?
client_infopointer to client context set upon creation (can be modified)
Returns
GNUNET_OK to continue (always)

Definition at line 1194 of file fs_publish.c.

1202{
1203 struct GNUNET_FS_PublishContext *pc = cls;
1204 struct GNUNET_FS_ProgressInfo pi;
1205 unsigned int kc;
1206 uint64_t left;
1207
1209 {
1211 return GNUNET_OK;
1212 }
1214 "Starting publish operation\n");
1215 if (*do_index)
1216 {
1217 /* space for on-demand blocks */
1218 pc->reserve_space +=
1219 ((length + DBLOCK_SIZE
1220 - 1) / DBLOCK_SIZE) * sizeof(struct OnDemandBlock);
1221 }
1222 else
1223 {
1224 /* space for DBlocks */
1225 pc->reserve_space += length;
1226 }
1227 /* entries for IBlocks and DBlocks, space for IBlocks */
1228 left = length;
1229 while (1)
1230 {
1231 left = (left + DBLOCK_SIZE - 1) / DBLOCK_SIZE;
1232 pc->reserve_entries += left;
1233 if (left <= 1)
1234 break;
1235 left = left * sizeof(struct ContentHashKey);
1236 pc->reserve_space += left;
1237 }
1239 /* entries and space for keywords */
1240 if (NULL != *uri)
1241 {
1243 pc->reserve_entries += kc;
1245 }
1247 *client_info = GNUNET_FS_publish_make_status_ (&pi, pc, fi, 0);
1249 if ((fi->is_directory) && (fi->dir != NULL))
1250 {
1251 /* We are a directory, and we are not top-level; process entries in directory */
1254 }
1255 return GNUNET_OK;
1256}
#define DBLOCK_SIZE
Size of the individual blocks used for file-sharing.
Definition: fs.h:41
static int fip_signal_start(void *cls, struct GNUNET_FS_FileInformation *fi, uint64_t length, struct GNUNET_FS_MetaData *meta, struct GNUNET_FS_Uri **uri, struct GNUNET_FS_BlockOptions *bo, int *do_index, void **client_info)
Signal the FS's progress function that we are starting an upload.
Definition: fs_publish.c:1194
void GNUNET_FS_file_information_inspect(struct GNUNET_FS_FileInformation *dir, GNUNET_FS_FileInformationProcessor proc, void *proc_cls)
Inspect a file or directory in a publish-structure.
unsigned int GNUNET_FS_uri_ksk_get_keyword_count(const struct GNUNET_FS_Uri *uri)
How many keywords are ANDed in this keyword URI?
Definition: fs_uri.c:711
@ GNUNET_FS_STATUS_PUBLISH_START
Notification that we have started to publish a file structure.
content hash key
Definition: fs.h:55
int skip_next_fi_callback
Flag set to GNUNET_YES if the next callback from GNUNET_FS_file_information_inspect should be skipped...
Definition: fs_api.h:1299
uint32_t reserve_entries
Overall number of entries to reserve for the publish operation.
Definition: fs_api.h:1270
uint64_t reserve_space
Storage space to reserve for the operation.
Definition: fs_api.h:1264

References DBLOCK_SIZE, GNUNET_FS_FileInformation::dir, fip_signal_start(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_FS_file_information_inspect(), GNUNET_FS_file_information_sync_(), GNUNET_FS_publish_make_status_(), GNUNET_FS_STATUS_PUBLISH_START, GNUNET_FS_uri_ksk_get_keyword_count(), GNUNET_log, GNUNET_MAX_MESSAGE_SIZE, GNUNET_NO, GNUNET_OK, GNUNET_YES, GNUNET_FS_FileInformation::is_directory, pc, GNUNET_FS_PublishContext::reserve_entries, GNUNET_FS_PublishContext::reserve_space, GNUNET_FS_PublishContext::skip_next_fi_callback, GNUNET_FS_ProgressInfo::status, and uri.

Referenced by fip_signal_start(), and GNUNET_FS_publish_start().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ suspend_operation()

static void suspend_operation ( struct GNUNET_FS_FileInformation fi,
struct GNUNET_FS_PublishContext pc 
)
static

Actually signal the FS's progress function that we are suspending an upload.

Parameters
fithe entry in the publish-structure
pcthe publish context of which a file is being suspended

Definition at line 1267 of file fs_publish.c.

1269{
1270 struct GNUNET_FS_ProgressInfo pi;
1271 uint64_t off;
1272
1273 if (NULL != pc->ksk_pc)
1274 {
1276 pc->ksk_pc = NULL;
1277 }
1278 if (NULL != pc->sks_pc)
1279 {
1281 pc->sks_pc = NULL;
1282 }
1284 "Suspending publish operation\n");
1286 fi->serialization = NULL;
1287 off = (NULL == fi->chk_uri) ? 0 : (GNUNET_YES == fi->is_directory) ?
1290 GNUNET_break (NULL == GNUNET_FS_publish_make_status_ (&pi, pc, fi, off));
1291 if (NULL != pc->qre)
1292 {
1294 pc->qre = NULL;
1295 }
1296 if (NULL != pc->dsh)
1297 {
1299 pc->dsh = NULL;
1300 }
1301 pc->rid = 0;
1302}
void GNUNET_DATASTORE_cancel(struct GNUNET_DATASTORE_QueueEntry *qe)
Cancel a datastore operation.
void GNUNET_FS_publish_ksk_cancel(struct GNUNET_FS_PublishKskContext *pkc)
Abort the KSK publishing operation.
void GNUNET_FS_publish_sks_cancel(struct GNUNET_FS_PublishSksContext *psc)
Abort the SKS publishing operation.
Definition: fs_namespace.c:495
@ GNUNET_FS_STATUS_PUBLISH_SUSPEND
Notification that we have suspended sharing a file structure.
char * serialization
Under what filename is this struct serialized (for operational persistence).
Definition: fs_api.h:287
size_t dir_size
Size of the directory itself (in bytes); 0 if the size has not yet been calculated.
Definition: fs_api.h:368
const struct GNUNET_FS_FileInformation * fi
Information about the file that is being published.

References GNUNET_FS_FileInformation::chk_uri, GNUNET_FS_FileInformation::data, GNUNET_FS_FileInformation::dir, GNUNET_FS_FileInformation::dir_size, GNUNET_FS_PublishContext::dsh, GNUNET_FS_ProgressInfo::fi, GNUNET_FS_FileInformation::file, GNUNET_FS_FileInformation::file_size, GNUNET_break, GNUNET_DATASTORE_cancel(), GNUNET_DATASTORE_disconnect(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_FS_publish_ksk_cancel(), GNUNET_FS_publish_make_status_(), GNUNET_FS_publish_sks_cancel(), GNUNET_FS_STATUS_PUBLISH_SUSPEND, GNUNET_log, GNUNET_NO, GNUNET_YES, GNUNET_FS_FileInformation::is_directory, GNUNET_FS_PublishContext::ksk_pc, pc, GNUNET_FS_PublishContext::qre, GNUNET_FS_PublishContext::rid, GNUNET_FS_FileInformation::serialization, GNUNET_FS_PublishContext::sks_pc, and GNUNET_FS_ProgressInfo::status.

Referenced by fip_signal_suspend(), and GNUNET_FS_publish_signal_suspend_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fip_signal_suspend()

static int fip_signal_suspend ( void *  cls,
struct GNUNET_FS_FileInformation fi,
uint64_t  length,
struct GNUNET_FS_MetaData meta,
struct GNUNET_FS_Uri **  uri,
struct GNUNET_FS_BlockOptions bo,
int *  do_index,
void **  client_info 
)
static

Signal the FS's progress function that we are suspending an upload.

Performs the recursion.

Parameters
clsclosure (of type struct GNUNET_FS_PublishContext *)
fithe entry in the publish-structure
lengthlength of the file or directory
metametadata for the file or directory (can be modified)
uripointer to the keywords that will be used for this entry (can be modified)
boblock options
do_indexshould we index?
client_infopointer to client context set upon creation (can be modified)
Returns
GNUNET_OK to continue (always)

Definition at line 1320 of file fs_publish.c.

1328{
1329 struct GNUNET_FS_PublishContext *pc = cls;
1330
1332 {
1334 return GNUNET_OK;
1335 }
1337 {
1338 /* process entries in directory */
1341 }
1343 *client_info = NULL;
1344 return GNUNET_OK;
1345}
static int fip_signal_suspend(void *cls, struct GNUNET_FS_FileInformation *fi, uint64_t length, struct GNUNET_FS_MetaData *meta, struct GNUNET_FS_Uri **uri, struct GNUNET_FS_BlockOptions *bo, int *do_index, void **client_info)
Signal the FS's progress function that we are suspending an upload.
Definition: fs_publish.c:1320
static void suspend_operation(struct GNUNET_FS_FileInformation *fi, struct GNUNET_FS_PublishContext *pc)
Actually signal the FS's progress function that we are suspending an upload.
Definition: fs_publish.c:1267
static struct GNUNET_FS_MetaData * meta
Meta-data provided via command-line option.
int GNUNET_FS_meta_data_test_for_directory(const struct GNUNET_FS_MetaData *md)
Does the meta-data claim that this is a directory? Checks if the mime-type is that of a GNUnet direct...
Definition: fs_directory.c:55

References GNUNET_FS_PublishContext::fi, fip_signal_suspend(), GNUNET_FS_file_information_inspect(), GNUNET_FS_meta_data_test_for_directory(), GNUNET_NO, GNUNET_OK, GNUNET_YES, meta, pc, GNUNET_FS_PublishContext::skip_next_fi_callback, and suspend_operation().

Referenced by fip_signal_suspend(), and GNUNET_FS_publish_signal_suspend_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_FS_publish_signal_suspend_()

void GNUNET_FS_publish_signal_suspend_ ( void *  cls)

Create SUSPEND event for the given publish operation and then clean up our state (without stop signal).

Parameters
clsthe struct GNUNET_FS_PublishContext to signal for

Definition at line 1355 of file fs_publish.c.

1356{
1357 struct GNUNET_FS_PublishContext *pc = cls;
1358
1359 if (NULL != pc->upload_task)
1360 {
1362 pc->upload_task = NULL;
1363 }
1368 pc->top = NULL;
1370}
void GNUNET_FS_end_top(struct GNUNET_FS_Handle *h, struct TopLevelActivity *top)
Destroy a top-level activity entry.
Definition: fs_api.c:402
static void publish_cleanup(struct GNUNET_FS_PublishContext *pc)
Cleanup the publish context, we're done with it.
Definition: fs_publish.c:79
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:979
struct TopLevelActivity * top
Our top-level activity entry (if we are top-level, otherwise NULL).
Definition: fs_api.h:1189

References GNUNET_FS_PublishContext::fi, fip_signal_suspend(), GNUNET_FS_end_top(), GNUNET_FS_file_information_inspect(), GNUNET_SCHEDULER_cancel(), GNUNET_YES, GNUNET_FS_PublishContext::h, pc, publish_cleanup(), GNUNET_FS_PublishContext::skip_next_fi_callback, suspend_operation(), GNUNET_FS_PublishContext::top, and GNUNET_FS_PublishContext::upload_task.

Referenced by deserialize_publish_file(), and GNUNET_FS_publish_start().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ finish_reserve()

static void finish_reserve ( void *  cls,
int  success,
struct GNUNET_TIME_Absolute  min_expiration,
const char *  msg 
)
static

We have gotten a reply for our space reservation request.

Either fail (insufficient space) or start publishing for good.

Parameters
clsthe struct GNUNET_FS_PublishContext *
successpositive reservation ID on success
min_expirationminimum expiration time required for content to be stored
msgerror message on error, otherwise NULL

Definition at line 1383 of file fs_publish.c.

1387{
1388 struct GNUNET_FS_PublishContext *pc = cls;
1389
1390 pc->qre = NULL;
1392 "Reservation complete (%d)!\n",
1393 success);
1394 if ((msg != NULL) || (success <= 0))
1395 {
1397 _ ("Datastore failure: %s"),
1398 msg);
1400 return;
1401 }
1402 pc->rid = success;
1403 GNUNET_assert (NULL == pc->upload_task);
1404 pc->upload_task =
1407}

References _, GNUNET_FS_FileInformation::emsg, GNUNET_FS_PublishContext::fi, GNUNET_asprintf(), GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_FS_publish_main_(), GNUNET_log, GNUNET_SCHEDULER_add_with_priority(), GNUNET_SCHEDULER_PRIORITY_BACKGROUND, msg, pc, GNUNET_FS_PublishContext::qre, GNUNET_FS_PublishContext::rid, signal_publish_error(), and GNUNET_FS_PublishContext::upload_task.

Referenced by GNUNET_FS_publish_start().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ compute_contents_size()

static uint64_t compute_contents_size ( struct GNUNET_FS_FileInformation fi)
static

Calculate the total size of all of the files in the directory structure.

Parameters
fifile structure to traverse

Definition at line 1416 of file fs_publish.c.

1417{
1418 struct GNUNET_FS_FileInformation *ent;
1419
1420 if (GNUNET_YES != fi->is_directory)
1421 return fi->data.file.file_size;
1422 fi->data.dir.contents_size = 0;
1423 for (ent = fi->data.dir.entries; NULL != ent; ent = ent->next)
1425 return fi->data.dir.contents_size;
1426}
static uint64_t compute_contents_size(struct GNUNET_FS_FileInformation *fi)
Calculate the total size of all of the files in the directory structure.
Definition: fs_publish.c:1416
uint64_t contents_size
Sum of all of the sizes of all of the files in the directory.
Definition: fs_api.h:384
struct GNUNET_FS_FileInformation * entries
Linked list of entries in the directory.
Definition: fs_api.h:362

References compute_contents_size(), GNUNET_FS_FileInformation::contents_size, GNUNET_FS_FileInformation::data, GNUNET_FS_FileInformation::dir, GNUNET_FS_FileInformation::entries, GNUNET_FS_FileInformation::file, GNUNET_FS_FileInformation::file_size, GNUNET_YES, GNUNET_FS_FileInformation::is_directory, and GNUNET_FS_FileInformation::next.

Referenced by compute_contents_size(), and GNUNET_FS_publish_start().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fip_signal_stop()

static int fip_signal_stop ( void *  cls,
struct GNUNET_FS_FileInformation fi,
uint64_t  length,
struct GNUNET_FS_MetaData meta,
struct GNUNET_FS_Uri **  uri,
struct GNUNET_FS_BlockOptions bo,
int *  do_index,
void **  client_info 
)
static

Signal the FS's progress function that we are stopping an upload.

Parameters
clsclosure (of type struct GNUNET_FS_PublishContext *)
fithe entry in the publish-structure
lengthlength of the file or directory
metametadata for the file or directory (can be modified)
uripointer to the keywords that will be used for this entry (can be modified)
boblock options (can be modified)
do_indexshould we index?
client_infopointer to client context set upon creation (can be modified)
Returns
GNUNET_OK to continue (always)

Definition at line 1524 of file fs_publish.c.

1531{
1532 struct GNUNET_FS_PublishContext *pc = cls;
1533 struct GNUNET_FS_ProgressInfo pi;
1534 uint64_t off;
1535
1537 {
1539 return GNUNET_OK;
1540 }
1542 {
1543 /* process entries in directory first */
1546 }
1547 if (NULL != fi->serialization)
1548 {
1550 fi->serialization);
1552 fi->serialization = NULL;
1553 }
1554 off = (fi->chk_uri == NULL) ? 0 : length;
1556 GNUNET_break (NULL == GNUNET_FS_publish_make_status_ (&pi, pc, fi, off));
1557 *client_info = NULL;
1558 return GNUNET_OK;
1559}
void GNUNET_FS_remove_sync_file_(struct GNUNET_FS_Handle *h, const char *ext, const char *ent)
Remove serialization/deserialization file from disk.
Definition: fs_api.c:728
#define GNUNET_FS_SYNC_PATH_FILE_INFO
Name of the directory with files that are being published.
Definition: fs_api.h:82
static int fip_signal_stop(void *cls, struct GNUNET_FS_FileInformation *fi, uint64_t length, struct GNUNET_FS_MetaData *meta, struct GNUNET_FS_Uri **uri, struct GNUNET_FS_BlockOptions *bo, int *do_index, void **client_info)
Signal the FS's progress function that we are stopping an upload.
Definition: fs_publish.c:1524
@ GNUNET_FS_STATUS_PUBLISH_STOPPED
Notification that we have stopped the process of uploading a file structure; no further events will b...

References GNUNET_FS_FileInformation::chk_uri, GNUNET_FS_ProgressInfo::fi, fip_signal_stop(), GNUNET_break, GNUNET_free, GNUNET_FS_file_information_inspect(), GNUNET_FS_meta_data_test_for_directory(), GNUNET_FS_publish_make_status_(), GNUNET_FS_remove_sync_file_(), GNUNET_FS_STATUS_PUBLISH_STOPPED, GNUNET_FS_SYNC_PATH_FILE_INFO, GNUNET_NO, GNUNET_OK, GNUNET_YES, GNUNET_FS_PublishContext::h, meta, pc, GNUNET_FS_FileInformation::serialization, GNUNET_FS_PublishContext::skip_next_fi_callback, and GNUNET_FS_ProgressInfo::status.

Referenced by fip_signal_stop(), and GNUNET_FS_publish_stop().

Here is the call graph for this function:
Here is the caller graph for this function: