GNUnet  0.11.x
Data Structures | Macros | Functions
fs_test_lib.c File Reference

library routines for testing FS publishing and downloading; this code is limited to flat files and no keywords (those functions can be tested with single-peer setups; this is for testing routing). More...

#include "platform.h"
#include "fs_api.h"
#include "fs_test_lib.h"
Include dependency graph for fs_test_lib.c:

Go to the source code of this file.

Data Structures

struct  TestPublishOperation
 Handle for a publishing operation started for testing FS. More...
 
struct  TestDownloadOperation
 Handle for a download operation started for testing FS. More...
 

Macros

#define CONTENT_LIFETIME   GNUNET_TIME_UNIT_HOURS
 

Functions

static void report_uri (void *cls)
 Task scheduled to report on the completion of our publish operation. More...
 
static void publish_timeout (void *cls)
 Task scheduled to run when publish operation times out. More...
 
static void * publish_progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
 Progress callback for file-sharing events while publishing. More...
 
static size_t file_generator (void *cls, uint64_t offset, size_t max, void *buf, char **emsg)
 Generate test data for publishing test. More...
 
static void * publish_connect_adapter (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
 Connect adapter for publishing operation. More...
 
static void fs_disconnect_adapter (void *cls, void *op_result)
 Adapter function called to destroy connection to file-sharing service. More...
 
static void publish_fs_connect_complete_cb (void *cls, struct GNUNET_TESTBED_Operation *op, void *ca_result, const char *emsg)
 Callback to be called when testbed has connected to the fs service. More...
 
void GNUNET_FS_TEST_publish (struct GNUNET_TESTBED_Peer *peer, struct GNUNET_TIME_Relative timeout, uint32_t anonymity, int do_index, uint64_t size, uint32_t seed, unsigned int verbose, GNUNET_FS_TEST_UriContinuation cont, void *cont_cls)
 Publish a file at the given peer. More...
 
static void download_timeout (void *cls)
 Task scheduled to run when download operation times out. More...
 
static void report_success (void *cls)
 Task scheduled to report on the completion of our download operation. More...
 
static void * download_progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
 Progress callback for file-sharing events while downloading. More...
 
static void * download_connect_adapter (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
 Connect adapter for download operation. More...
 
static void download_fs_connect_complete_cb (void *cls, struct GNUNET_TESTBED_Operation *op, void *ca_result, const char *emsg)
 Callback to be called when testbed has connected to the fs service. More...
 
void GNUNET_FS_TEST_download (struct GNUNET_TESTBED_Peer *peer, struct GNUNET_TIME_Relative timeout, uint32_t anonymity, uint32_t seed, const struct GNUNET_FS_Uri *uri, unsigned int verbose, GNUNET_SCHEDULER_TaskCallback cont, void *cont_cls)
 Perform test download. More...
 

Detailed Description

library routines for testing FS publishing and downloading; this code is limited to flat files and no keywords (those functions can be tested with single-peer setups; this is for testing routing).

Author
Christian Grothoff

Definition in file fs_test_lib.c.

Macro Definition Documentation

◆ CONTENT_LIFETIME

#define CONTENT_LIFETIME   GNUNET_TIME_UNIT_HOURS

Definition at line 34 of file fs_test_lib.c.

Referenced by publish_fs_connect_complete_cb().

Function Documentation

◆ report_uri()

static void report_uri ( void *  cls)
static

Task scheduled to report on the completion of our publish operation.

Parameters
clsthe publish operation context
tcscheduler context (unused)

Definition at line 183 of file fs_test_lib.c.

References TestPublishOperation::do_index, TestPublishOperation::fs_op, GNUNET_DISK_directory_remove(), GNUNET_free, GNUNET_free_non_null, GNUNET_FS_publish_stop(), GNUNET_FS_uri_destroy(), GNUNET_TESTBED_operation_done(), GNUNET_YES, TestPublishOperation::publish_cont, TestPublishOperation::publish_cont_cls, TestPublishOperation::publish_context, TestPublishOperation::publish_tmp_file, and TestPublishOperation::publish_uri.

Referenced by publish_progress_cb().

184 {
185  struct TestPublishOperation *po = cls;
186 
190  po->publish_uri,
191  (GNUNET_YES == po->do_index)
192  ? po->publish_tmp_file
193  : NULL);
195  if ((GNUNET_YES != po->do_index) &&
196  (NULL != po->publish_tmp_file))
199  GNUNET_free (po);
200 }
char * publish_tmp_file
Name of the temporary file used, or NULL for none.
Definition: fs_test_lib.c:85
int do_index
Are we testing indexing? (YES: index, NO: insert, SYSERR: simulate)
Definition: fs_test_lib.c:105
void * publish_cont_cls
Closure for publish_cont.
Definition: fs_test_lib.c:60
void GNUNET_FS_publish_stop(struct GNUNET_FS_PublishContext *pc)
Stop an upload.
Definition: fs_publish.c:1570
struct GNUNET_FS_PublishContext * publish_context
Context for current publishing operation.
Definition: fs_test_lib.c:75
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
GNUNET_FS_TEST_UriContinuation publish_cont
Function to call when upload is done.
Definition: fs_test_lib.c:55
struct GNUNET_FS_Uri * publish_uri
Result URI.
Definition: fs_test_lib.c:80
struct GNUNET_TESTBED_Operation * fs_op
Handle for the operation to connect to the peer's 'fs' service.
Definition: fs_test_lib.c:45
int GNUNET_DISK_directory_remove(const char *filename)
Remove all files in a directory (rm -rf).
Definition: disk.c:1029
void GNUNET_TESTBED_operation_done(struct GNUNET_TESTBED_Operation *operation)
This function is used to signal that the event information (struct GNUNET_TESTBED_EventInformation) f...
Definition: testbed_api.c:2044
void GNUNET_FS_uri_destroy(struct GNUNET_FS_Uri *uri)
Free URI.
Definition: fs_uri.c:678
Handle for a publishing operation started for testing FS.
Definition: fs_test_lib.c:40
#define GNUNET_YES
Definition: gnunet_common.h:77
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ publish_timeout()

static void publish_timeout ( void *  cls)
static

Task scheduled to run when publish operation times out.

Parameters
clsthe publish operation context

Definition at line 209 of file fs_test_lib.c.

References TestPublishOperation::fs_op, GNUNET_DISK_directory_remove(), GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_free_non_null, GNUNET_FS_publish_stop(), GNUNET_log, GNUNET_TESTBED_operation_done(), TestPublishOperation::publish_cont, TestPublishOperation::publish_cont_cls, TestPublishOperation::publish_context, TestPublishOperation::publish_timeout_task, and TestPublishOperation::publish_tmp_file.

Referenced by GNUNET_FS_TEST_publish().

210 {
211  struct TestPublishOperation *po = cls;
212 
213  po->publish_timeout_task = NULL;
215  "Timeout while trying to publish data\n");
218  po->publish_cont (po->publish_cont_cls, NULL, NULL);
221  GNUNET_free (po);
222 }
char * publish_tmp_file
Name of the temporary file used, or NULL for none.
Definition: fs_test_lib.c:85
void * publish_cont_cls
Closure for publish_cont.
Definition: fs_test_lib.c:60
void GNUNET_FS_publish_stop(struct GNUNET_FS_PublishContext *pc)
Stop an upload.
Definition: fs_publish.c:1570
struct GNUNET_FS_PublishContext * publish_context
Context for current publishing operation.
Definition: fs_test_lib.c:75
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
GNUNET_FS_TEST_UriContinuation publish_cont
Function to call when upload is done.
Definition: fs_test_lib.c:55
struct GNUNET_TESTBED_Operation * fs_op
Handle for the operation to connect to the peer's 'fs' service.
Definition: fs_test_lib.c:45
int GNUNET_DISK_directory_remove(const char *filename)
Remove all files in a directory (rm -rf).
Definition: disk.c:1029
void GNUNET_TESTBED_operation_done(struct GNUNET_TESTBED_Operation *operation)
This function is used to signal that the event information (struct GNUNET_TESTBED_EventInformation) f...
Definition: testbed_api.c:2044
Handle for a publishing operation started for testing FS.
Definition: fs_test_lib.c:40
struct GNUNET_SCHEDULER_Task * publish_timeout_task
Task to abort publishing (timeout).
Definition: fs_test_lib.c:65
#define GNUNET_log(kind,...)
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ publish_progress_cb()

static void* publish_progress_cb ( void *  cls,
const struct GNUNET_FS_ProgressInfo info 
)
static

Progress callback for file-sharing events while publishing.

Parameters
clsthe publish operation context
infoinformation about the event

Definition at line 232 of file fs_test_lib.c.

References GNUNET_FS_ProgressInfo::download, GNUNET_ERROR_TYPE_INFO, GNUNET_FS_STATUS_DOWNLOAD_PROGRESS, GNUNET_FS_STATUS_PUBLISH_COMPLETED, GNUNET_FS_STATUS_PUBLISH_PROGRESS, GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY, GNUNET_FS_uri_dup(), GNUNET_log, GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_cancel(), GNUNET_FS_ProgressInfo::publish, TestPublishOperation::publish_timeout_task, TestPublishOperation::publish_uri, report_uri(), GNUNET_FS_ProgressInfo::status, GNUNET_FS_ProgressInfo::value, and TestPublishOperation::verbose.

Referenced by publish_connect_adapter().

233 {
234  struct TestPublishOperation *po = cls;
235 
236  switch (info->status)
237  {
240  po->publish_timeout_task = NULL;
241  po->publish_uri =
242  GNUNET_FS_uri_dup (info->value.publish.specifics.completed.chk_uri);
244  po);
245  break;
246 
248  if (po->verbose)
249  GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Publishing at %llu/%llu bytes\n",
250  (unsigned long long) info->value.publish.completed,
251  (unsigned long long) info->value.publish.size);
252  break;
253 
255  break;
256 
258  if (po->verbose)
259  GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Download at %llu/%llu bytes\n",
260  (unsigned long long) info->value.download.completed,
261  (unsigned long long) info->value.download.size);
262  break;
263 
264  default:
265  break;
266  }
267  return NULL;
268 }
static void report_uri(void *cls)
Task scheduled to report on the completion of our publish operation.
Definition: fs_test_lib.c:183
struct GNUNET_FS_ProgressInfo::@25::@27 download
Values for all "GNUNET_FS_STATUS_DOWNLOAD_*" events.
Notification that we are making progress sharing a file structure.
struct GNUNET_FS_Uri * GNUNET_FS_uri_dup(const struct GNUNET_FS_Uri *uri)
Duplicate URI.
Definition: fs_uri.c:998
struct GNUNET_FS_Uri * publish_uri
Result URI.
Definition: fs_test_lib.c:80
union GNUNET_FS_ProgressInfo::@25 value
Values that depend on the event type.
Notification that we are making progress sharing a directory.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1280
enum GNUNET_FS_Status status
Specific status code (determines the event type).
Handle for a publishing operation started for testing FS.
Definition: fs_test_lib.c:40
unsigned int verbose
Verbosity level of the current operation.
Definition: fs_test_lib.c:100
Notification about progress with this download.
Notification that we completed sharing a file structure.
struct GNUNET_SCHEDULER_Task * publish_timeout_task
Task to abort publishing (timeout).
Definition: fs_test_lib.c:65
struct GNUNET_FS_ProgressInfo::@25::@26 publish
Values for all "GNUNET_FS_STATUS_PUBLISH_*" events.
#define GNUNET_log(kind,...)
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:966
Here is the call graph for this function:
Here is the caller graph for this function:

◆ file_generator()

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

Generate test data for publishing test.

Parameters
clspointer to uint32_t with publishing seed
offsetoffset to generate data for
maxmaximum number of bytes to generate
bufwhere to write generated data
emsgwhere to store error message (unused)
Returns
number of bytes written to buf

Definition at line 282 of file fs_test_lib.c.

References buf, and TestPublishOperation::publish_seed.

Referenced by publish_fs_connect_complete_cb().

287 {
288  uint32_t *publish_seed = cls;
289  uint64_t pos;
290  uint8_t *cbuf = buf;
291  int mod;
292 
293  if (emsg != NULL)
294  *emsg = NULL;
295  if (buf == NULL)
296  return 0;
297  for (pos = 0; pos < 8; pos++)
298  cbuf[pos] = (uint8_t) (offset >> pos * 8);
299  for (pos = 8; pos < max; pos++)
300  {
301  mod = (255 - (offset / 1024 / 32));
302  if (mod == 0)
303  mod = 1;
304  cbuf[pos] = (uint8_t) ((offset * (*publish_seed)) % mod);
305  }
306  return max;
307 }
uint32_t publish_seed
Seed for file generation.
Definition: fs_test_lib.c:70
static char buf[2048]
Here is the caller graph for this function:

◆ publish_connect_adapter()

static void* publish_connect_adapter ( void *  cls,
const struct GNUNET_CONFIGURATION_Handle cfg 
)
static

Connect adapter for publishing operation.

Parameters
clsthe 'struct TestPublishOperation'
cfgconfiguration of the peer to connect to; will be available until GNUNET_TESTBED_operation_done() is called on the operation returned from GNUNET_TESTBED_service_connect()
Returns
service handle to return in 'op_result', NULL on error

Definition at line 320 of file fs_test_lib.c.

References GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END, GNUNET_FS_start(), and publish_progress_cb().

Referenced by GNUNET_FS_TEST_publish().

322 {
323  struct TestPublishOperation *po = cls;
324 
325  return GNUNET_FS_start (cfg,
326  "fs-test-publish",
327  &publish_progress_cb, po,
330 }
Last option in the VARARG list.
struct GNUNET_FS_Handle * GNUNET_FS_start(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *client_name, GNUNET_FS_ProgressCallback upcb, void *upcb_cls, enum GNUNET_FS_Flags flags,...)
Setup a connection to the file-sharing service.
Definition: fs_api.c:3141
No special flags set.
Handle for a publishing operation started for testing FS.
Definition: fs_test_lib.c:40
static void * publish_progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *info)
Progress callback for file-sharing events while publishing.
Definition: fs_test_lib.c:232
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fs_disconnect_adapter()

static void fs_disconnect_adapter ( void *  cls,
void *  op_result 
)
static

Adapter function called to destroy connection to file-sharing service.

Parameters
clsthe 'struct GNUNET_FS_Handle'
op_resultunused (different for publish/download!)

Definition at line 340 of file fs_test_lib.c.

References TestPublishOperation::fs, GNUNET_FS_stop(), and op_result().

Referenced by GNUNET_FS_TEST_download(), and GNUNET_FS_TEST_publish().

342 {
343  struct GNUNET_FS_Handle *fs = op_result;
344 
345  GNUNET_FS_stop (fs);
346 }
Master context for most FS operations.
Definition: fs_api.h:1068
static int op_result(struct GNUNET_OP_Handle *h, uint64_t op_id, int64_t result_code, const void *data, uint16_t data_size, void **ctx, uint8_t cancel)
Remove an operation, and call its result callback (unless it was cancelled).
Definition: op.c:245
void GNUNET_FS_stop(struct GNUNET_FS_Handle *h)
Close our connection with the file-sharing service.
Definition: fs_api.c:3216
static struct GNUNET_FS_Handle * fs
Handle to FS service.
Definition: gnunet-fs.c:36
Here is the call graph for this function:
Here is the caller graph for this function:

◆ publish_fs_connect_complete_cb()

static void publish_fs_connect_complete_cb ( void *  cls,
struct GNUNET_TESTBED_Operation op,
void *  ca_result,
const char *  emsg 
)
static

Callback to be called when testbed has connected to the fs service.

Parameters
clsthe 'struct TestPublishOperation'
opthe operation that has been finished
ca_resultthe 'struct GNUNET_FS_Handle ' (NULL on error)
emsgerror message in case the operation has failed; will be NULL if operation has executed successfully.

Definition at line 359 of file fs_test_lib.c.

References TestPublishOperation::anonymity, GNUNET_FS_BlockOptions::anonymity_level, bsize, buf, CONTENT_LIFETIME, GNUNET_FS_BlockOptions::content_priority, DBLOCK_SIZE, TestPublishOperation::do_index, GNUNET_FS_BlockOptions::expiration_time, fh, file_generator(), TestPublishOperation::fs, TestPublishOperation::fs_op, GNUNET_assert, GNUNET_DISK_file_close(), GNUNET_DISK_file_open(), GNUNET_DISK_file_write(), GNUNET_DISK_mktemp(), GNUNET_DISK_OPEN_CREATE, GNUNET_DISK_OPEN_WRITE, GNUNET_DISK_PERM_USER_READ, GNUNET_DISK_PERM_USER_WRITE, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_FS_file_information_create_from_file(), GNUNET_FS_file_information_create_from_reader(), GNUNET_FS_PUBLISH_OPTION_NONE, GNUNET_FS_publish_start(), GNUNET_log, GNUNET_MIN, GNUNET_OK, GNUNET_TESTBED_operation_done(), GNUNET_TIME_relative_to_absolute(), GNUNET_YES, TestPublishOperation::publish_cont, TestPublishOperation::publish_cont_cls, TestPublishOperation::publish_context, TestPublishOperation::publish_seed, TestPublishOperation::publish_tmp_file, GNUNET_FS_BlockOptions::replication_level, and TestPublishOperation::size.

Referenced by GNUNET_FS_TEST_publish().

363 {
364  struct TestPublishOperation *po = cls;
365  struct GNUNET_FS_FileInformation *fi;
366  struct GNUNET_DISK_FileHandle *fh;
367  char *em;
368  uint64_t off;
369  char buf[DBLOCK_SIZE];
370  size_t bsize;
371  struct GNUNET_FS_BlockOptions bo;
372 
373  if (NULL == ca_result)
374  {
376  "Failed to connect to FS for publishing: %s\n", emsg);
378  NULL, NULL);
380  GNUNET_free (po);
381  return;
382  }
383  po->fs = ca_result;
384 
387  bo.content_priority = 42;
388  bo.replication_level = 1;
389  if (GNUNET_YES == po->do_index)
390  {
391  po->publish_tmp_file = GNUNET_DISK_mktemp ("fs-test-publish-index");
392  GNUNET_assert (po->publish_tmp_file != NULL);
398  GNUNET_assert (NULL != fh);
399  off = 0;
400  while (off < po->size)
401  {
402  bsize = GNUNET_MIN (sizeof(buf), po->size - off);
403  emsg = NULL;
404  GNUNET_assert (bsize == file_generator (&po->publish_seed, off, bsize,
405  buf, &em));
406  GNUNET_assert (em == NULL);
407  GNUNET_assert (bsize == GNUNET_DISK_file_write (fh, buf, bsize));
408  off += bsize;
409  }
412  po->publish_tmp_file,
413  NULL, NULL, po->do_index,
414  &bo);
415  GNUNET_assert (NULL != fi);
416  }
417  else
418  {
420  po->size,
422  &po->publish_seed,
423  NULL, NULL,
424  po->do_index, &bo);
425  GNUNET_assert (NULL != fi);
426  }
427  po->publish_context =
428  GNUNET_FS_publish_start (po->fs, fi, NULL, NULL, NULL,
430 }
struct GNUNET_TIME_Absolute expiration_time
At what time should the block expire? Data blocks (DBLOCKS and IBLOCKS) may still be used even if the...
struct GNUNET_FS_Handle * fs
Handle to the file sharing context using this daemon.
Definition: fs_test_lib.c:50
char * publish_tmp_file
Name of the temporary file used, or NULL for none.
Definition: fs_test_lib.c:85
int do_index
Are we testing indexing? (YES: index, NO: insert, SYSERR: simulate)
Definition: fs_test_lib.c:105
Create file if it doesn&#39;t exist.
void * publish_cont_cls
Closure for publish_cont.
Definition: fs_test_lib.c:60
uint32_t publish_seed
Seed for file generation.
Definition: fs_test_lib.c:70
int GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1345
struct GNUNET_FS_PublishContext * GNUNET_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.
Definition: fs_publish.c:1442
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
Definition: time.c:246
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_FS_FileInformation * GNUNET_FS_file_information_create_from_file(struct GNUNET_FS_Handle *h, void *client_info, const char *filename, const struct GNUNET_FS_Uri *keywords, const struct GNUNET_CONTAINER_MetaData *meta, int do_index, const struct GNUNET_FS_BlockOptions *bo)
Create an entry for a file in a publish-structure.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
struct GNUNET_FS_PublishContext * publish_context
Context for current publishing operation.
Definition: fs_test_lib.c:75
Information for a file or directory that is about to be published.
Definition: fs_api.h:226
GNUNET_FS_TEST_UriContinuation publish_cont
Function to call when upload is done.
Definition: fs_test_lib.c:55
uint32_t anonymity_level
At which anonymity level should the block be shared? (0: no anonymity, 1: normal GAP, >1: with cover traffic).
struct GNUNET_TESTBED_Operation * fs_op
Handle for the operation to connect to the peer&#39;s &#39;fs&#39; service.
Definition: fs_test_lib.c:45
char * GNUNET_DISK_mktemp(const char *t)
Create an (empty) temporary file on disk.
Definition: disk.c:468
ssize_t GNUNET_DISK_file_write(const struct GNUNET_DISK_FileHandle *h, const void *buffer, size_t n)
Write a buffer to a file.
Definition: disk.c:820
#define GNUNET_MIN(a, b)
Definition: gnunet_common.h:80
static char buf[2048]
uint32_t anonymity
Anonymity level used.
Definition: fs_test_lib.c:95
static int fh
Handle to the unique file.
void GNUNET_TESTBED_operation_done(struct GNUNET_TESTBED_Operation *operation)
This function is used to signal that the event information (struct GNUNET_TESTBED_EventInformation) f...
Definition: testbed_api.c:2044
static unsigned int bsize
Handle for a publishing operation started for testing FS.
Definition: fs_test_lib.c:40
#define DBLOCK_SIZE
Size of the individual blocks used for file-sharing.
Definition: fs.h:40
static unsigned int size
Size of the "table".
Definition: peer.c:67
Open the file for writing.
Settings for publishing a block (which may of course also apply to an entire directory or file)...
uint32_t replication_level
How often should we try to migrate the block to other peers? Only used if "CONTENT_PUSHING" is set to...
uint64_t size
Size of the file.
Definition: fs_test_lib.c:90
#define GNUNET_log(kind,...)
uint32_t content_priority
How important is it for us to store the block? If we run out of space, the highest-priority, non-expired blocks will be kept.
struct GNUNET_FS_FileInformation * GNUNET_FS_file_information_create_from_reader(struct GNUNET_FS_Handle *h, void *client_info, uint64_t length, GNUNET_FS_DataReader reader, void *reader_cls, const struct GNUNET_FS_Uri *keywords, const struct GNUNET_CONTAINER_MetaData *meta, int do_index, const struct GNUNET_FS_BlockOptions *bo)
Create an entry for a file in a publish-structure.
#define GNUNET_YES
Definition: gnunet_common.h:77
#define CONTENT_LIFETIME
Definition: fs_test_lib.c:34
static size_t file_generator(void *cls, uint64_t offset, size_t max, void *buf, char **emsg)
Generate test data for publishing test.
Definition: fs_test_lib.c:282
No options (use defaults for everything).
struct GNUNET_DISK_FileHandle * GNUNET_DISK_file_open(const char *fn, enum GNUNET_DISK_OpenFlags flags, enum GNUNET_DISK_AccessPermissions perm)
Open a file.
Definition: disk.c:1268
Handle used to access files (and pipes).
static struct GNUNET_FS_BlockOptions bo
Options we set for published blocks.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_FS_TEST_publish()

void GNUNET_FS_TEST_publish ( struct GNUNET_TESTBED_Peer peer,
struct GNUNET_TIME_Relative  timeout,
uint32_t  anonymity,
int  do_index,
uint64_t  size,
uint32_t  seed,
unsigned int  verbose,
GNUNET_FS_TEST_UriContinuation  cont,
void *  cont_cls 
)

Publish a file at the given peer.

Publish a file at the given daemon.

Parameters
peerwhere to publish
timeoutif this operation cannot be completed within the given period, call the continuation with an error code
anonymityoption for publication
do_indexGNUNET_YES for index, GNUNET_NO for insertion, GNUNET_SYSERR for simulation
sizesize of the file to publish
seedseed to use for file generation
verbosehow verbose to be in reporting
contfunction to call when done
cont_clsclosure for cont

Definition at line 449 of file fs_test_lib.c.

References TestPublishOperation::anonymity, TestPublishOperation::do_index, fs_disconnect_adapter(), TestPublishOperation::fs_op, GNUNET_new, GNUNET_SCHEDULER_add_delayed(), GNUNET_TESTBED_service_connect(), publish_connect_adapter(), TestPublishOperation::publish_cont, TestPublishOperation::publish_cont_cls, publish_fs_connect_complete_cb(), TestPublishOperation::publish_seed, publish_timeout(), TestPublishOperation::publish_timeout_task, TestPublishOperation::size, and TestPublishOperation::verbose.

454 {
455  struct TestPublishOperation *po;
456 
457  po = GNUNET_new (struct TestPublishOperation);
458  po->publish_cont = cont;
459  po->publish_cont_cls = cont_cls;
460  po->publish_seed = seed;
461  po->anonymity = anonymity;
462  po->size = size;
463  po->verbose = verbose;
464  po->do_index = do_index;
466  peer,
467  "fs",
469  po,
472  po);
475 }
static void * publish_connect_adapter(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect adapter for publishing operation.
Definition: fs_test_lib.c:320
int do_index
Are we testing indexing? (YES: index, NO: insert, SYSERR: simulate)
Definition: fs_test_lib.c:105
void * publish_cont_cls
Closure for publish_cont.
Definition: fs_test_lib.c:60
uint32_t publish_seed
Seed for file generation.
Definition: fs_test_lib.c:70
#define GNUNET_new(type)
Allocate a struct or union of the given type.
GNUNET_FS_TEST_UriContinuation publish_cont
Function to call when upload is done.
Definition: fs_test_lib.c:55
static void publish_timeout(void *cls)
Task scheduled to run when publish operation times out.
Definition: fs_test_lib.c:209
struct GNUNET_TESTBED_Operation * fs_op
Handle for the operation to connect to the peer&#39;s &#39;fs&#39; service.
Definition: fs_test_lib.c:45
struct GNUNET_TESTBED_Operation * GNUNET_TESTBED_service_connect(void *op_cls, struct GNUNET_TESTBED_Peer *peer, const char *service_name, GNUNET_TESTBED_ServiceConnectCompletionCallback cb, void *cb_cls, GNUNET_TESTBED_ConnectAdapter ca, GNUNET_TESTBED_DisconnectAdapter da, void *cada_cls)
Connect to a service offered by the given peer.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1253
static int verbose
uint32_t anonymity
Anonymity level used.
Definition: fs_test_lib.c:95
Handle for a publishing operation started for testing FS.
Definition: fs_test_lib.c:40
unsigned int verbose
Verbosity level of the current operation.
Definition: fs_test_lib.c:100
static unsigned int size
Size of the "table".
Definition: peer.c:67
static void publish_fs_connect_complete_cb(void *cls, struct GNUNET_TESTBED_Operation *op, void *ca_result, const char *emsg)
Callback to be called when testbed has connected to the fs service.
Definition: fs_test_lib.c:359
static void fs_disconnect_adapter(void *cls, void *op_result)
Adapter function called to destroy connection to file-sharing service.
Definition: fs_test_lib.c:340
struct GNUNET_SCHEDULER_Task * publish_timeout_task
Task to abort publishing (timeout).
Definition: fs_test_lib.c:65
uint64_t size
Size of the file.
Definition: fs_test_lib.c:90
static unsigned int anonymity
Here is the call graph for this function:

◆ download_timeout()

static void download_timeout ( void *  cls)
static

Task scheduled to run when download operation times out.

Parameters
clsthe download operation context

Definition at line 487 of file fs_test_lib.c.

References TestDownloadOperation::download_cont, TestDownloadOperation::download_cont_cls, TestDownloadOperation::download_context, TestDownloadOperation::download_timeout_task, TestDownloadOperation::fs_op, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_FS_download_stop(), GNUNET_FS_uri_destroy(), GNUNET_log, GNUNET_SCHEDULER_add_now(), GNUNET_TESTBED_operation_done(), GNUNET_YES, and TestDownloadOperation::uri.

Referenced by GNUNET_FS_TEST_download().

488 {
489  struct TestDownloadOperation *dop = cls;
490 
492  "Timeout while trying to download file\n");
493  dop->download_timeout_task = NULL;
495  GNUNET_YES);
497  dop->download_cont_cls);
499  GNUNET_FS_uri_destroy (dop->uri);
500  GNUNET_free (dop);
501 }
GNUNET_SCHEDULER_TaskCallback download_cont
Function to call when download is done.
Definition: fs_test_lib.c:132
struct GNUNET_FS_Uri * uri
URI to download.
Definition: fs_test_lib.c:142
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1280
void GNUNET_FS_download_stop(struct GNUNET_FS_DownloadContext *dc, int do_delete)
Stop a download (aborts if download is incomplete).
Definition: fs_download.c:2333
void GNUNET_TESTBED_operation_done(struct GNUNET_TESTBED_Operation *operation)
This function is used to signal that the event information (struct GNUNET_TESTBED_EventInformation) f...
Definition: testbed_api.c:2044
void GNUNET_FS_uri_destroy(struct GNUNET_FS_Uri *uri)
Free URI.
Definition: fs_uri.c:678
struct GNUNET_TESTBED_Operation * fs_op
Handle for the operation to connect to the peer&#39;s &#39;fs&#39; service.
Definition: fs_test_lib.c:117
#define GNUNET_log(kind,...)
void * download_cont_cls
Closure for download_cont.
Definition: fs_test_lib.c:137
#define GNUNET_YES
Definition: gnunet_common.h:77
struct GNUNET_SCHEDULER_Task * download_timeout_task
Task to abort downloading (timeout).
Definition: fs_test_lib.c:147
Handle for a download operation started for testing FS.
Definition: fs_test_lib.c:112
struct GNUNET_FS_DownloadContext * download_context
Context for current download operation.
Definition: fs_test_lib.c:152
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ report_success()

static void report_success ( void *  cls)
static

Task scheduled to report on the completion of our download operation.

Parameters
clsthe download operation context

Definition at line 510 of file fs_test_lib.c.

References TestDownloadOperation::download_cont, TestDownloadOperation::download_cont_cls, TestDownloadOperation::download_context, TestDownloadOperation::fs_op, GNUNET_free, GNUNET_FS_download_stop(), GNUNET_FS_uri_destroy(), GNUNET_SCHEDULER_add_now(), GNUNET_TESTBED_operation_done(), GNUNET_YES, and TestDownloadOperation::uri.

Referenced by download_progress_cb().

511 {
512  struct TestDownloadOperation *dop = cls;
513 
515  GNUNET_YES);
517  dop->download_cont_cls);
519  GNUNET_FS_uri_destroy (dop->uri);
520  GNUNET_free (dop);
521 }
GNUNET_SCHEDULER_TaskCallback download_cont
Function to call when download is done.
Definition: fs_test_lib.c:132
struct GNUNET_FS_Uri * uri
URI to download.
Definition: fs_test_lib.c:142
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1280
void GNUNET_FS_download_stop(struct GNUNET_FS_DownloadContext *dc, int do_delete)
Stop a download (aborts if download is incomplete).
Definition: fs_download.c:2333
void GNUNET_TESTBED_operation_done(struct GNUNET_TESTBED_Operation *operation)
This function is used to signal that the event information (struct GNUNET_TESTBED_EventInformation) f...
Definition: testbed_api.c:2044
void GNUNET_FS_uri_destroy(struct GNUNET_FS_Uri *uri)
Free URI.
Definition: fs_uri.c:678
struct GNUNET_TESTBED_Operation * fs_op
Handle for the operation to connect to the peer&#39;s &#39;fs&#39; service.
Definition: fs_test_lib.c:117
void * download_cont_cls
Closure for download_cont.
Definition: fs_test_lib.c:137
#define GNUNET_YES
Definition: gnunet_common.h:77
Handle for a download operation started for testing FS.
Definition: fs_test_lib.c:112
struct GNUNET_FS_DownloadContext * download_context
Context for current download operation.
Definition: fs_test_lib.c:152
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ download_progress_cb()

static void* download_progress_cb ( void *  cls,
const struct GNUNET_FS_ProgressInfo info 
)
static

Progress callback for file-sharing events while downloading.

Parameters
clsthe download operation context
infoinformation about the event

Definition at line 531 of file fs_test_lib.c.

References GNUNET_FS_ProgressInfo::download, TestDownloadOperation::download_timeout_task, GNUNET_ERROR_TYPE_INFO, GNUNET_FS_STATUS_DOWNLOAD_ACTIVE, GNUNET_FS_STATUS_DOWNLOAD_COMPLETED, GNUNET_FS_STATUS_DOWNLOAD_INACTIVE, GNUNET_FS_STATUS_DOWNLOAD_PROGRESS, GNUNET_log, GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_cancel(), report_success(), GNUNET_FS_ProgressInfo::status, GNUNET_FS_ProgressInfo::value, and TestDownloadOperation::verbose.

Referenced by download_connect_adapter().

533 {
534  struct TestDownloadOperation *dop = cls;
535 
536  switch (info->status)
537  {
539  if (dop->verbose)
541  "Download at %llu/%llu bytes\n",
542  (unsigned long long) info->value.download.completed,
543  (unsigned long long) info->value.download.size);
544  break;
545 
548  dop->download_timeout_task = NULL;
550  break;
551 
554  break;
555 
556  /* FIXME: monitor data correctness during download progress */
557  /* FIXME: do performance reports given sufficient verbosity */
558  /* FIXME: advance timeout task to "immediate" on error */
559  default:
560  break;
561  }
562  return NULL;
563 }
struct GNUNET_FS_ProgressInfo::@25::@27 download
Values for all "GNUNET_FS_STATUS_DOWNLOAD_*" events.
Notification that this download completed.
union GNUNET_FS_ProgressInfo::@25 value
Values that depend on the event type.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1280
enum GNUNET_FS_Status status
Specific status code (determines the event type).
unsigned int verbose
Verbosity level of the current operation.
Definition: fs_test_lib.c:172
Notification that this download is no longer actively being pursued (back in the queue).
Notification about progress with this download.
Notification that this download is now actively being pursued (as opposed to waiting in the queue)...
#define GNUNET_log(kind,...)
struct GNUNET_SCHEDULER_Task * download_timeout_task
Task to abort downloading (timeout).
Definition: fs_test_lib.c:147
Handle for a download operation started for testing FS.
Definition: fs_test_lib.c:112
static void report_success(void *cls)
Task scheduled to report on the completion of our download operation.
Definition: fs_test_lib.c:510
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:966
Here is the call graph for this function:
Here is the caller graph for this function:

◆ download_connect_adapter()

static void* download_connect_adapter ( void *  cls,
const struct GNUNET_CONFIGURATION_Handle cfg 
)
static

Connect adapter for download operation.

Parameters
clsthe 'struct TestDownloadOperation'
cfgconfiguration of the peer to connect to; will be available until GNUNET_TESTBED_operation_done() is called on the operation returned from GNUNET_TESTBED_service_connect()
Returns
service handle to return in 'op_result', NULL on error

Definition at line 576 of file fs_test_lib.c.

References download_progress_cb(), GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END, and GNUNET_FS_start().

Referenced by GNUNET_FS_TEST_download().

578 {
579  struct TestPublishOperation *po = cls;
580 
581  return GNUNET_FS_start (cfg,
582  "fs-test-download",
586 }
Last option in the VARARG list.
struct GNUNET_FS_Handle * GNUNET_FS_start(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *client_name, GNUNET_FS_ProgressCallback upcb, void *upcb_cls, enum GNUNET_FS_Flags flags,...)
Setup a connection to the file-sharing service.
Definition: fs_api.c:3141
No special flags set.
Handle for a publishing operation started for testing FS.
Definition: fs_test_lib.c:40
static void * download_progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *info)
Progress callback for file-sharing events while downloading.
Definition: fs_test_lib.c:531
Here is the call graph for this function:
Here is the caller graph for this function:

◆ download_fs_connect_complete_cb()

static void download_fs_connect_complete_cb ( void *  cls,
struct GNUNET_TESTBED_Operation op,
void *  ca_result,
const char *  emsg 
)
static

Callback to be called when testbed has connected to the fs service.

Parameters
clsthe 'struct TestPublishOperation'
opthe operation that has been finished
ca_resultthe 'struct GNUNET_FS_Handle ' (NULL on error)
emsgerror message in case the operation has failed; will be NULL if operation has executed successfully.

Definition at line 599 of file fs_test_lib.c.

References TestDownloadOperation::anonymity, TestDownloadOperation::download_context, TestDownloadOperation::fs, GNUNET_assert, GNUNET_FS_DOWNLOAD_OPTION_NONE, GNUNET_FS_download_start(), TestDownloadOperation::size, and TestDownloadOperation::uri.

Referenced by GNUNET_FS_TEST_download().

603 {
604  struct TestDownloadOperation *dop = cls;
605 
606  dop->fs = ca_result;
607  GNUNET_assert (NULL != dop->fs);
608  dop->download_context =
609  GNUNET_FS_download_start (dop->fs, dop->uri, NULL, NULL, NULL, 0, dop->size,
611  NULL, NULL);
612 }
uint64_t size
Size of the file.
Definition: fs_test_lib.c:157
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
uint32_t anonymity
Anonymity level used.
Definition: fs_test_lib.c:162
struct GNUNET_FS_Uri * uri
URI to download.
Definition: fs_test_lib.c:142
struct GNUNET_FS_DownloadContext * GNUNET_FS_download_start(struct GNUNET_FS_Handle *h, const struct GNUNET_FS_Uri *uri, const struct GNUNET_CONTAINER_MetaData *meta, const char *filename, const char *tempname, uint64_t offset, uint64_t length, uint32_t anonymity, enum GNUNET_FS_DownloadOptions options, void *cctx, struct GNUNET_FS_DownloadContext *parent)
Download parts of a file.
Definition: fs_download.c:2145
No options (use defaults for everything).
struct GNUNET_FS_Handle * fs
Handle to the file sharing context using this daemon.
Definition: fs_test_lib.c:122
Handle for a download operation started for testing FS.
Definition: fs_test_lib.c:112
struct GNUNET_FS_DownloadContext * download_context
Context for current download operation.
Definition: fs_test_lib.c:152
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_FS_TEST_download()

void GNUNET_FS_TEST_download ( struct GNUNET_TESTBED_Peer peer,
struct GNUNET_TIME_Relative  timeout,
uint32_t  anonymity,
uint32_t  seed,
const struct GNUNET_FS_Uri uri,
unsigned int  verbose,
GNUNET_SCHEDULER_TaskCallback  cont,
void *  cont_cls 
)

Perform test download.

Parameters
peerwhich peer to download from
timeoutif this operation cannot be completed within the given period, call the continuation with an error code
anonymityoption for download
seedused for file validation
uriURI of file to download (CHK/LOC only)
verbosehow verbose to be in reporting
contfunction to call when done
cont_clsclosure for cont

Definition at line 629 of file fs_test_lib.c.

References TestPublishOperation::anonymity, TestDownloadOperation::anonymity, download_connect_adapter(), TestDownloadOperation::download_cont, TestDownloadOperation::download_cont_cls, download_fs_connect_complete_cb(), TestDownloadOperation::download_seed, download_timeout(), TestDownloadOperation::download_timeout_task, fs_disconnect_adapter(), TestDownloadOperation::fs_op, GNUNET_FS_uri_chk_get_file_size(), GNUNET_FS_uri_dup(), GNUNET_new, GNUNET_SCHEDULER_add_delayed(), GNUNET_TESTBED_service_connect(), TestDownloadOperation::size, TestDownloadOperation::uri, TestPublishOperation::verbose, and TestDownloadOperation::verbose.

634 {
635  struct TestDownloadOperation *dop;
636 
637  dop = GNUNET_new (struct TestDownloadOperation);
638  dop->uri = GNUNET_FS_uri_dup (uri);
640  dop->verbose = verbose;
641  dop->anonymity = anonymity;
642  dop->download_cont = cont;
643  dop->download_cont_cls = cont_cls;
644  dop->download_seed = seed;
645 
647  peer,
648  "fs",
650  dop,
653  dop);
654  dop->download_timeout_task =
656 }
uint64_t size
Size of the file.
Definition: fs_test_lib.c:157
uint32_t anonymity
Anonymity level used.
Definition: fs_test_lib.c:162
GNUNET_SCHEDULER_TaskCallback download_cont
Function to call when download is done.
Definition: fs_test_lib.c:132
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_FS_Uri * uri
URI to download.
Definition: fs_test_lib.c:142
struct GNUNET_FS_Uri * GNUNET_FS_uri_dup(const struct GNUNET_FS_Uri *uri)
Duplicate URI.
Definition: fs_uri.c:998
struct GNUNET_TESTBED_Operation * GNUNET_TESTBED_service_connect(void *op_cls, struct GNUNET_TESTBED_Peer *peer, const char *service_name, GNUNET_TESTBED_ServiceConnectCompletionCallback cb, void *cb_cls, GNUNET_TESTBED_ConnectAdapter ca, GNUNET_TESTBED_DisconnectAdapter da, void *cada_cls)
Connect to a service offered by the given peer.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1253
static int verbose
unsigned int verbose
Verbosity level of the current operation.
Definition: fs_test_lib.c:172
uint32_t download_seed
Seed for download verification.
Definition: fs_test_lib.c:167
struct GNUNET_TESTBED_Operation * fs_op
Handle for the operation to connect to the peer&#39;s &#39;fs&#39; service.
Definition: fs_test_lib.c:117
static void * download_connect_adapter(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect adapter for download operation.
Definition: fs_test_lib.c:576
static void fs_disconnect_adapter(void *cls, void *op_result)
Adapter function called to destroy connection to file-sharing service.
Definition: fs_test_lib.c:340
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:1371
void * download_cont_cls
Closure for download_cont.
Definition: fs_test_lib.c:137
static unsigned int anonymity
struct GNUNET_SCHEDULER_Task * download_timeout_task
Task to abort downloading (timeout).
Definition: fs_test_lib.c:147
Handle for a download operation started for testing FS.
Definition: fs_test_lib.c:112
static void download_timeout(void *cls)
Task scheduled to run when download operation times out.
Definition: fs_test_lib.c:487
static void download_fs_connect_complete_cb(void *cls, struct GNUNET_TESTBED_Operation *op, void *ca_result, const char *emsg)
Callback to be called when testbed has connected to the fs service.
Definition: fs_test_lib.c:599
Here is the call graph for this function: