[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r3228 - in GNUnet/src: applications/fs/fsui applications/fs
From: |
grothoff |
Subject: |
[GNUnet-SVN] r3228 - in GNUnet/src: applications/fs/fsui applications/fs/uritrack include |
Date: |
Sun, 13 Aug 2006 21:20:40 -0700 (PDT) |
Author: grothoff
Date: 2006-08-13 21:20:33 -0700 (Sun, 13 Aug 2006)
New Revision: 3228
Modified:
GNUnet/src/applications/fs/fsui/download.c
GNUnet/src/applications/fs/fsui/fsui.c
GNUnet/src/applications/fs/fsui/fsui.h
GNUnet/src/applications/fs/fsui/search.c
GNUnet/src/applications/fs/fsui/unindex.c
GNUnet/src/applications/fs/fsui/upload.c
GNUnet/src/applications/fs/uritrack/file_info.c
GNUnet/src/include/gnunet_fsui_lib.h
Log:
towards fixing fsui
Modified: GNUnet/src/applications/fs/fsui/download.c
===================================================================
--- GNUnet/src/applications/fs/fsui/download.c 2006-08-13 20:32:18 UTC (rev
3227)
+++ GNUnet/src/applications/fs/fsui/download.c 2006-08-14 04:20:33 UTC (rev
3228)
@@ -1,6 +1,6 @@
/*
This file is part of GNUnet.
- (C) 2001, 2002, 2003, 2004, 2005 Christian Grothoff (and other
contributing authors)
+ (C) 2001, 2002, 2003, 2004, 2005, 2006 Christian Grothoff (and other
contributing authors)
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
@@ -23,10 +23,14 @@
* @brief download functions
* @author Krista Bennett
* @author Christian Grothoff
+ *
+ * TODO:
+ * - does not signal all events properly!
*/
#include "platform.h"
#include "gnunet_ecrs_lib.h"
+#include "gnunet_uritrack_lib.h"
#include "gnunet_fsui_lib.h"
#include "fsui.h"
@@ -34,33 +38,32 @@
/**
* Start to download a file.
- *
- * @return OK on success, SYSERR if the target file is
- * already used for another download at the moment (or
- * if the disk does not have enough space).
*/
-static int startDownload(struct FSUI_Context * ctx,
- unsigned int anonymityLevel,
- const struct ECRS_URI * uri,
- const char * filename,
- int is_recursive,
- FSUI_DownloadList * parent);
+static FSUI_DownloadList *
+startDownload(struct FSUI_Context * ctx,
+ unsigned int anonymityLevel,
+ int is_recursive,
+ const struct ECRS_URI * uri,
+ const char * filename,
+ FSUI_DownloadList * parent);
static int triggerRecursiveDownload(const ECRS_FileInfo * fi,
const HashCode512 * key,
int isRoot,
void * prnt) {
FSUI_DownloadList * parent = prnt;
+ struct GE_Context * ectx;
int i;
FSUI_DownloadList * pos;
char * filename;
char * fullName;
char * dotdot;
+ ectx = parent->ctx->ectx;
if (isRoot == YES)
return OK; /* namespace ad, ignore */
- FSUI_trackURI(fi);
+ URITRACK_trackURI(ectx, parent->ctx->cfg, fi);
for (i=0;i<parent->completedDownloadsCount;i++)
if (ECRS_equalsUri(parent->completedDownloads[i],
fi->uri))
@@ -90,7 +93,7 @@
strcat(fullName, GNUNET_DIRECTORY_EXT);
while (NULL != (dotdot = strstr(fullName, "..")))
dotdot[0] = dotdot[1] = '_';
- mkdirp(fullName);
+ disk_directory_create(ectx, fullName);
strcat(fullName, DIR_SEPARATOR_STR);
while (NULL != (dotdot = strstr(filename, "..")))
dotdot[0] = dotdot[1] = '_';
@@ -102,11 +105,11 @@
fullName);
#endif
startDownload(parent->ctx,
- parent->anonymityLevel,
- fi->uri,
- fullName,
- YES,
- parent);
+ parent->anonymityLevel,
+ YES,
+ fi->uri,
+ fullName,
+ parent);
FREE(fullName);
return OK;
}
@@ -142,11 +145,10 @@
event.data.DownloadProgress.last_size = lastBlockSize;
event.data.DownloadProgress.filename = dl->filename;
event.data.DownloadProgress.uri = dl->uri;
- event.data.DownloadProgress.start_time = dl->startTime;
- event.data.DownloadProgress.is_recursive = dl->is_recursive;
- event.data.DownloadProgress.main_filename = root->filename;
- event.data.DownloadProgress.main_uri = root->uri;
- event.data.DownloadProgress.pos = dl;
+ event.data.DownloadProgress.dc.pos = dl;
+ event.data.DownloadProgress.dc.cctx = dl->cctx;
+ event.data.DownloadProgress.dc.ppos = dl->parent;
+ event.data.DownloadProgress.dc.pcctx = dl->parent != NULL ? dl->parent->cctx
: NULL;
dl->ctx->ecb(dl->ctx->ecbClosure,
&event);
if ( (lastBlockOffset == 0) &&
@@ -163,13 +165,14 @@
if ( (dl->is_recursive == YES) &&
(dl->is_directory == YES) ) {
md = NULL;
- MUTEX_LOCK(&dl->ctx->lock);
- ECRS_listDirectory(lastBlock,
+ MUTEX_LOCK(dl->ctx->lock);
+ ECRS_listDirectory(dl->ctx->ectx,
+ lastBlock,
lastBlockSize,
&md,
&triggerRecursiveDownload,
dl);
- MUTEX_UNLOCK(&dl->ctx->lock);
+ MUTEX_UNLOCK(dl->ctx->lock);
if (md != NULL)
ECRS_freeMetaData(md);
}
@@ -199,15 +202,20 @@
struct ECRS_MetaData * md;
FSUI_DownloadList * root;
unsigned long long totalBytes;
+ struct GE_Context * ectx;
+ ectx = dl->ctx->ectx;
#if DEBUG_DTM
- GE_LOG(ectx, GE_DEBUG | GE_REQUEST | GE_USER,
- "Download thread for `%s' started...\n",
- dl->filename);
+ GE_LOG(ectx,
+ GE_DEBUG | GE_REQUEST | GE_USER,
+ "Download thread for `%s' started...\n",
+ dl->filename);
#endif
GE_ASSERT(ectx, dl->ctx != NULL);
GE_ASSERT(ectx, dl->filename != NULL);
- ret = ECRS_downloadFile(dl->uri,
+ ret = ECRS_downloadFile(dl->ctx->ectx,
+ dl->ctx->cfg,
+ dl->uri,
dl->filename,
dl->anonymityLevel,
&downloadProgressCallback,
@@ -219,9 +227,10 @@
totalBytes = ECRS_fileSize(dl->uri);
} else {
#if DEBUG_DTM
- GE_LOG(ectx, GE_DEBUG | GE_REQUEST | GE_USER,
- "Download thread for `%s' failed (aborted or error)!\n",
- dl->filename);
+ GE_LOG(ectx,
+ GE_DEBUG | GE_REQUEST | GE_USER,
+ "Download thread for `%s' failed (aborted or error)!\n",
+ dl->filename);
#endif
if (dl->state == FSUI_DOWNLOAD_ACTIVE)
dl->state = FSUI_DOWNLOAD_ERROR;
@@ -251,12 +260,14 @@
fn[strlen(fn)-1] = '\0';
strcat(fn, GNUNET_DIRECTORY_EXT);
}
- fd = fileopen(fn,
- O_LARGEFILE | O_RDONLY);
+ fd = disk_file_open(ectx,
+ fn,
+ O_LARGEFILE | O_RDONLY);
if (fd == -1) {
- GE_LOG_STRERROR_FILE(ectx,LOG_ERROR,
- "OPEN",
- fn);
+ GE_LOG_STRERROR_FILE(ectx,
+ GE_ERROR | GE_BULK | GE_ADMIN | GE_USER,
+ "OPEN",
+ fn);
} else {
dirBlock = MMAP(NULL,
totalBytes,
@@ -265,21 +276,25 @@
fd,
0);
if (MAP_FAILED == dirBlock) {
- GE_LOG_STRERROR_FILE(ectx,LOG_ERROR, "MMAP", fn);
+ GE_LOG_STRERROR_FILE(ectx,
+ GE_ERROR | GE_BULK | GE_ADMIN | GE_USER,
+ "MMAP",
+ fn);
} else {
/* load directory, start downloads */
md = NULL;
- MUTEX_LOCK(&dl->ctx->lock);
- ECRS_listDirectory(dirBlock,
+ MUTEX_LOCK(dl->ctx->lock);
+ ECRS_listDirectory(dl->ctx->ectx,
+ dirBlock,
totalBytes,
&md,
&triggerRecursiveDownload,
dl);
- MUTEX_UNLOCK(&dl->ctx->lock);
+ MUTEX_UNLOCK(dl->ctx->lock);
ECRS_freeMetaData(md);
MUNMAP(dirBlock, totalBytes);
}
- closefile(fd);
+ CLOSE(fd);
}
FREE(fn);
}
@@ -303,7 +318,10 @@
printf("State: %u\n", dl->state);
GE_BREAK(ectx, 0);
}
- event.data.DownloadError.pos = dl;
+ event.data.DownloadError.dc.pos = dl;
+ event.data.DownloadError.dc.cctx = dl->cctx;
+ event.data.DownloadError.dc.ppos = dl->parent;
+ event.data.DownloadError.dc.pcctx = dl->parent != NULL ? dl->parent->cctx
: NULL;
dl->ctx->ecb(dl->ctx->ecbClosure,
&event);
} else {
@@ -312,19 +330,13 @@
(dl->ctx != NULL) &&
(dl != &dl->ctx->activeDownloads) ) {
event.type = FSUI_download_complete;
- event.data.DownloadProgress.total = dl->total;
- event.data.DownloadProgress.completed = dl->completed;
- event.data.DownloadProgress.last_offset = 0;
- event.data.DownloadProgress.eta = get_time();
- event.data.DownloadProgress.last_block = NULL;
- event.data.DownloadProgress.last_size = 0;
- event.data.DownloadProgress.filename = dl->filename;
- event.data.DownloadProgress.uri = dl->uri;
- event.data.DownloadProgress.start_time = dl->startTime;
- event.data.DownloadProgress.is_recursive = dl->is_recursive;
- event.data.DownloadProgress.main_filename = root->filename;
- event.data.DownloadProgress.main_uri = root->uri;
- event.data.DownloadProgress.pos = dl;
+ event.data.DownloadComplete.total = dl->total;
+ event.data.DownloadComplete.filename = dl->filename;
+ event.data.DownloadComplete.uri = dl->uri;
+ event.data.DownloadComplete.dc.pos = dl;
+ event.data.DownloadComplete.dc.cctx = dl->cctx;
+ event.data.DownloadComplete.dc.ppos = dl->parent;
+ event.data.DownloadComplete.dc.pcctx = dl->parent != NULL ?
dl->parent->cctx : NULL;
dl->ctx->ecb(dl->ctx->ecbClosure,
&event);
dl = dl->parent;
@@ -332,40 +344,38 @@
}
dl = cls;
#if DEBUG_DTM
- GE_LOG(ectx, GE_DEBUG | GE_REQUEST | GE_USER,
- "Download thread for `%s' terminated (%s)...\n",
- dl->filename,
- ret == OK ? "COMPLETED" : "ABORTED");
+ GE_LOG(ectx,
+ GE_DEBUG | GE_REQUEST | GE_USER,
+ "Download thread for `%s' terminated (%s)...\n",
+ dl->filename,
+ ret == OK ? "COMPLETED" : "ABORTED");
#endif
return NULL;
}
/**
* Start to download a file.
- *
- * @return OK on success, SYSERR if the target file is
- * already used for another download at the moment (or
- * if the disk does not have enough space).
*/
-static int startDownload(struct FSUI_Context * ctx,
- unsigned int anonymityLevel,
- const struct ECRS_URI * uri,
- const char * filename,
- int is_recursive,
- FSUI_DownloadList * parent) {
+static FSUI_DownloadList *
+startDownload(struct FSUI_Context * ctx,
+ unsigned int anonymityLevel,
+ int is_recursive,
+ const struct ECRS_URI * uri,
+ const char * filename,
+ FSUI_DownloadList * parent) {
FSUI_DownloadList * dl;
FSUI_DownloadList * root;
unsigned long long totalBytes;
- GE_ASSERT(ectx, ctx != NULL);
+ GE_ASSERT(NULL, ctx != NULL);
if (! (ECRS_isFileUri(uri) ||
ECRS_isLocationUri(uri)) ) {
- GE_BREAK(ectx, 0); /* wrong type of URI! */
- return SYSERR;
+ GE_BREAK(NULL, 0); /* wrong type of URI! */
+ return NULL;
}
dl = MALLOC(sizeof(FSUI_DownloadList));
memset(dl, 0, sizeof(FSUI_DownloadList));
- cronTime(&dl->startTime);
+ dl->startTime = get_time();
dl->state = FSUI_DOWNLOAD_PENDING;
dl->is_recursive = is_recursive;
dl->parent = parent;
@@ -385,7 +395,7 @@
root = root->parent;
root->total += totalBytes;
}
- return OK;
+ return dl;
}
/**
@@ -395,22 +405,22 @@
* already used for another download at the moment (or
* if the disk does not have enough space).
*/
-int FSUI_startDownload(struct FSUI_Context * ctx,
- unsigned int anonymityLevel,
- const struct ECRS_URI * uri,
- const char * filename) {
- int ret;
+struct FSUI_DownloadList *
+FSUI_startDownload(struct FSUI_Context * ctx,
+ unsigned int anonymityLevel,
+ int doRecursive,
+ const struct ECRS_URI * uri,
+ const char * filename) {
+ struct FSUI_DownloadList * ret;
- GE_ASSERT(ectx, filename != NULL);
- GE_ASSERT(ectx, ctx != NULL);
- MUTEX_LOCK(&ctx->lock);
- ret = startDownload(ctx,
- anonymityLevel,
+ MUTEX_LOCK(ctx->lock);
+ ret = startDownload(ctx,
+ anonymityLevel,
+ doRecursive,
uri,
filename,
- NO,
- &ctx->activeDownloads);
- MUTEX_UNLOCK(&ctx->lock);
+ NULL);
+ MUTEX_UNLOCK(ctx->lock);
return ret;
}
@@ -422,19 +432,22 @@
* @return YES if change done that may require re-trying
*/
int updateDownloadThread(FSUI_DownloadList * list) {
+ struct GE_Context * ectx;
FSUI_DownloadList * dpos;
void * unused;
int ret;
+ ectx = list->ctx->ectx;
if (list == NULL)
return NO;
#if DEBUG_DTM
- GE_LOG(ectx, GE_DEBUG | GE_REQUEST | GE_USER,
- "Download thread manager investigates pending downlod of file `%s'
(%u/%u downloads)\n",
- list->filename,
- list->ctx->activeDownloadThreads,
- list->ctx->threadPoolSize);
+ GE_LOG(ectx,
+ GE_DEBUG | GE_REQUEST | GE_USER,
+ "Download thread manager investigates pending downlod of file `%s'
(%u/%u downloads)\n",
+ list->filename,
+ list->ctx->activeDownloadThreads,
+ list->ctx->threadPoolSize);
#endif
ret = NO;
/* should this one be started? */
@@ -444,18 +457,21 @@
( (list->total > list->completed) ||
(list->total == 0) ) ) {
#if DEBUG_DTM
- GE_LOG(ectx, GE_DEBUG | GE_REQUEST | GE_USER,
- "Download thread manager starts downlod of file `%s'\n",
- list->filename);
+ GE_LOG(ectx,
+ GE_DEBUG | GE_REQUEST | GE_USER,
+ "Download thread manager starts downlod of file `%s'\n",
+ list->filename);
#endif
list->state = FSUI_DOWNLOAD_ACTIVE;
- if (0 == PTHREAD_CREATE(&list->handle,
- &downloadThread,
- list,
- 32 * 1024)) {
+ list->handle = PTHREAD_CREATE(&downloadThread,
+ list,
+ 32 * 1024);
+ if (list->handle != NULL) {
list->ctx->activeDownloadThreads++;
} else {
- LOG_STRERROR(LOG_WARNING, "pthread_create");
+ GE_LOG_STRERROR(ectx,
+ GE_ADMIN | GE_USER | GE_BULK | GE_ERROR,
+ "pthread_create");
list->state = FSUI_DOWNLOAD_ERROR_JOINED;
}
}
@@ -465,16 +481,16 @@
< list->ctx->activeDownloadThreads) &&
(list->state == FSUI_DOWNLOAD_ACTIVE) ) {
#if DEBUG_DTM
- GE_LOG(ectx, GE_DEBUG | GE_REQUEST | GE_USER,
- "Download thread manager aborts active download of file `%s' (%u/%u
downloads)\n",
- list->filename,
- list->ctx->activeDownloadThreads,
- list->ctx->threadPoolSize);
+ GE_LOG(ectx,
+ GE_DEBUG | GE_REQUEST | GE_USER,
+ "Download thread manager aborts active download of file `%s' (%u/%u
downloads)\n",
+ list->filename,
+ list->ctx->activeDownloadThreads,
+ list->ctx->threadPoolSize);
#endif
list->state = FSUI_DOWNLOAD_SUSPENDING;
- PTHREAD_KILL(&list->handle,
- SIGALRM); /* terminate sleep */
- PTHREAD_JOIN(&list->handle,
+ PTHREAD_STOP_SLEEP(list->handle);
+ PTHREAD_JOIN(list->handle,
&unused);
list->ctx->activeDownloadThreads--;
list->state = FSUI_DOWNLOAD_PENDING;
@@ -486,11 +502,12 @@
(list->state == FSUI_DOWNLOAD_ABORTED) ||
(list->state == FSUI_DOWNLOAD_ERROR) ) {
#if DEBUG_DTM
- GE_LOG(ectx, GE_DEBUG | GE_REQUEST | GE_USER,
- "Download thread manager collects inactive download of file `%s'\n",
- list->filename);
+ GE_LOG(ectx,
+ GE_DEBUG | GE_REQUEST | GE_USER,
+ "Download thread manager collects inactive download of file `%s'\n",
+ list->filename);
#endif
- PTHREAD_JOIN(&list->handle,
+ PTHREAD_JOIN(list->handle,
&unused);
list->ctx->activeDownloadThreads--;
list->state++; /* adds _JOINED */
@@ -515,7 +532,7 @@
FSUI_DownloadList * dpos;
int i;
- GE_ASSERT(ectx, list->state != FSUI_DOWNLOAD_ACTIVE);
+ GE_ASSERT(NULL, list->state != FSUI_DOWNLOAD_ACTIVE);
/* first, find our predecessor and
unlink us from the tree! */
@@ -528,7 +545,7 @@
while ( (dpos != NULL) &&
(dpos->next != list) )
dpos = dpos->next;
- GE_ASSERT(ectx, dpos != NULL);
+ GE_ASSERT(NULL, dpos != NULL);
dpos->next = list->next;
}
}
@@ -554,168 +571,44 @@
* @return SYSERR if no such download is pending
*/
int FSUI_stopDownload(struct FSUI_Context * ctx,
- const struct ECRS_URI * uri,
- const char * filename) {
- FSUI_DownloadList * dl;
+ struct FSUI_DownloadList * dl) {
FSUI_DownloadList * prev;
+ struct GE_Context * ectx;
unsigned int backup;
- GE_LOG(ectx, GE_DEBUG | GE_REQUEST | GE_USER,
- "FSUI_stopDownload called.\n");
- GE_ASSERT(ectx, filename != NULL);
- MUTEX_LOCK(&ctx->lock);
- dl = ctx->activeDownloads.child;
- prev = NULL;
- while (dl != NULL) {
- if ( (ECRS_equalsUri(uri,
- dl->uri)) &&
- ( (filename == NULL) ||
- (0 == strcmp(filename,
- dl->filename)) ) ) {
- backup = ctx->threadPoolSize;
- ctx->threadPoolSize = 0;
- updateDownloadThread(dl);
- freeDownloadList(dl);
- ctx->threadPoolSize = backup;
- MUTEX_UNLOCK(&ctx->lock);
- GE_LOG(ectx, GE_DEBUG | GE_REQUEST | GE_USER,
- "FSUI_stopDownload completed successfully.\n");
- return OK;
- }
- prev = dl;
- dl = dl->next;
+ ectx = ctx->ectx;
+ GE_LOG(ectx,
+ GE_DEBUG | GE_REQUEST | GE_USER,
+ "FSUI_stopDownload called.\n");
+ MUTEX_LOCK(ctx->lock);
+ prev = (dl->parent != NULL) ? dl->parent->child : ctx->activeDownloads.child;
+ while ( (prev != dl) &&
+ (prev != NULL) &&
+ (prev->next != dl) )
+ prev = prev->next;
+ if (prev == NULL) {
+ MUTEX_UNLOCK(ctx->lock);
+ GE_LOG(ectx,
+ GE_DEBUG | GE_REQUEST | GE_USER,
+ "FSUI_stopDownload failed to locate download.\n");
+ return SYSERR;
}
- MUTEX_UNLOCK(&ctx->lock);
- GE_LOG(ectx, GE_DEBUG | GE_REQUEST | GE_USER,
- "FSUI_stopDownload failed to locate download.\n");
- return SYSERR;
-}
-
-/**
- * List active downloads. Will NOT list completed
- * downloads, FSUI clients should listen closely
- * to the FSUI_ProgressCallback to not miss completion
- * events.
- */
-int FSUI_listDownloads(struct FSUI_Context * ctx,
- const FSUI_DownloadList * root,
- FSUI_DownloadIterator iter,
- void * closure) {
- FSUI_DownloadList * dl;
- int ret;
-
- ret = 0;
- MUTEX_LOCK(&ctx->lock);
- if (root == NULL)
- dl = ctx->activeDownloads.child;
- else
- dl = root->child;
- while (dl != NULL) {
- if (OK != iter(closure,
- dl,
- dl->filename,
- dl->uri,
- dl->total,
- dl->completed,
- dl->is_recursive,
- dl->anonymityLevel)) {
- MUTEX_UNLOCK(&ctx->lock);
- return SYSERR;
- }
- ret++;
- dl = dl->next;
+ if (prev == dl) { /* first */
+ if (dl->parent != NULL)
+ dl->parent->child = dl->next;
+ else
+ ctx->activeDownloads.child = dl->next;
+ } else {
+ prev->next = dl->next; /* unlink */
}
- MUTEX_UNLOCK(&ctx->lock);
- return ret;
+ backup = ctx->threadPoolSize;
+ ctx->threadPoolSize = 0;
+ updateDownloadThread(dl);
+ freeDownloadList(dl);
+ ctx->threadPoolSize = backup;
+ MUTEX_UNLOCK(ctx->lock);
+ return OK;
}
-/**
- * Clear all completed top-level downloads from the FSUI list.
- *
- * @param callback function to call on each completed download
- * that is being cleared.
- * @return SYSERR on error, otherwise number of downloads cleared
- */
-int FSUI_clearCompletedDownloads(struct FSUI_Context * ctx,
- FSUI_DownloadIterator iter,
- void * closure) {
- FSUI_DownloadList * dl;
- FSUI_DownloadList * tmp;
- int ret;
- int stop;
- ret = 0;
- MUTEX_LOCK(&ctx->lock);
- dl = ctx->activeDownloads.child;
- stop = NO;
- while ( (dl != NULL) &&
- (stop == NO) ) {
- if ( (dl->completed == dl->total) &&
- ( (dl->state == FSUI_DOWNLOAD_COMPLETED_JOINED) ||
- (dl->state == FSUI_DOWNLOAD_ABORTED_JOINED) ||
- (dl->state == FSUI_DOWNLOAD_ERROR_JOINED) ) ) {
- if (iter != NULL)
- if (OK != iter(closure,
- dl,
- dl->filename,
- dl->uri,
- dl->total,
- dl->completed,
- dl->is_recursive,
- dl->anonymityLevel))
- stop = YES;
- tmp = dl->next;
- freeDownloadList(dl);
- dl = tmp;
- ret++;
- } else {
- dl = dl->next;
- }
- }
- MUTEX_UNLOCK(&ctx->lock);
- if (stop == NO)
- return ret;
- else
- return SYSERR;
-}
-
-
-/**
- * Get parent of active download.
- * @return NULL if there is no parent
- */
-const FSUI_DownloadList *
-FSUI_getDownloadParent(const FSUI_DownloadList * child) {
- if (child->parent ==
- &child->ctx->activeDownloads)
- return NULL;
- else
- return child->parent;
-}
-
-/**
- * Start to download a file or directory recursively.
- *
- * @return OK on success (at least we started with it),
- * SYSERR if the file does not exist
- */
-int FSUI_startDownloadAll(struct FSUI_Context * ctx,
- unsigned int anonymityLevel,
- const struct ECRS_URI * uri,
- const char * dirname) {
- int ret;
-
- GE_ASSERT(ectx, dirname != NULL);
- GE_ASSERT(ectx, ctx != NULL);
- MUTEX_LOCK(&ctx->lock);
- ret = startDownload(ctx,
- anonymityLevel,
- uri,
- dirname,
- YES,
- &ctx->activeDownloads);
- MUTEX_UNLOCK(&ctx->lock);
- return ret;
-}
-
/* end of download.c */
Modified: GNUnet/src/applications/fs/fsui/fsui.c
===================================================================
--- GNUnet/src/applications/fs/fsui/fsui.c 2006-08-13 20:32:18 UTC (rev
3227)
+++ GNUnet/src/applications/fs/fsui/fsui.c 2006-08-14 04:20:33 UTC (rev
3228)
@@ -26,6 +26,7 @@
#include "platform.h"
#include "gnunet_fsui_lib.h"
+#include "gnunet_directories.h"
#include "fsui.h"
#define DEBUG_PERSISTENCE NO
@@ -43,7 +44,8 @@
else \
a = ntohll(bigl)
-static struct ECRS_URI * readURI(int fd) {
+static struct ECRS_URI * readURI(struct GE_Context * ectx,
+ int fd) {
char * buf;
unsigned int big;
struct ECRS_URI * ret;
@@ -58,7 +60,7 @@
FREE(buf);
return NULL;
}
- ret = ECRS_stringToUri(buf);
+ ret = ECRS_stringToUri(ectx, buf);
FREE(buf);
return ret;
ERR:
@@ -74,7 +76,8 @@
* @return NULL on error AND on read of empty
* list (these two cannot be distinguished)
*/
-static FSUI_DownloadList * readDownloadList(int fd,
+static FSUI_DownloadList * readDownloadList(struct GE_Context * ectx,
+ int fd,
FSUI_Context * ctx,
FSUI_DownloadList * parent) {
char zaro;
@@ -140,7 +143,7 @@
READLONG(ret->startTime);
ret->startTime = get_time() - ret->startTime;
ret->uri
- = readURI(fd);
+ = readURI(ectx, fd);
if (ret->completedDownloadsCount > 0)
ret->completedDownloads
= MALLOC(sizeof(struct ECRS_URI *) *
@@ -151,7 +154,7 @@
ok = ret->uri != NULL;
for (i=0;i<ret->completedDownloadsCount;i++) {
ret->completedDownloads[i]
- = readURI(fd);
+ = readURI(ectx, fd);
if (ret->completedDownloads[i] == NULL)
ok = NO;
}
@@ -160,19 +163,22 @@
goto ERR;
}
ret->parent = parent;
- ret->next = readDownloadList(fd,
+ ret->next = readDownloadList(ectx,
+ fd,
ctx,
parent);
- ret->child = readDownloadList(fd,
+ ret->child = readDownloadList(ectx,
+ fd,
ctx,
ret);
#if DEBUG_PERSISTENCE
- GE_LOG(ectx, GE_DEBUG | GE_REQUEST | GE_USER,
- "FSUI persistence: restoring download `%s': %s (%llu, %llu)\n",
- ret->filename,
- ret->finished == YES ? "finished" : "pending",
- ret->completed,
- ret->total);
+ GE_LOG(ectx,
+ GE_DEBUG | GE_REQUEST | GE_USER,
+ "FSUI persistence: restoring download `%s': %s (%llu, %llu)\n",
+ ret->filename,
+ ret->finished == YES ? "finished" : "pending",
+ ret->completed,
+ ret->total);
#endif
return ret;
ERR:
@@ -221,7 +227,8 @@
/**
* (recursively) write a download list.
*/
-static void writeDownloadList(int fd,
+static void writeDownloadList(struct GE_Context * ectx,
+ int fd,
const FSUI_DownloadList * list) {
static char zero = '\0';
static char nonzero = '+';
@@ -232,12 +239,13 @@
return;
}
#if DEBUG_PERSISTENCE
- GE_LOG(ectx, GE_DEBUG | GE_REQUEST | GE_USER,
- "Serializing download state of download `%s': %s (%llu, %llu)\n",
- list->filename,
- list->finished == YES ? "finished" : "pending",
- list->completed,
- list->total);
+ GE_LOG(ectx,
+ GE_DEBUG | GE_REQUEST | GE_USER,
+ "Serializing download state of download `%s': %s (%llu, %llu)\n",
+ list->filename,
+ list->finished == YES ? "finished" : "pending",
+ list->completed,
+ list->total);
#endif
WRITE(fd, &nonzero, sizeof(char));
@@ -257,9 +265,11 @@
for (i=0;i<list->completedDownloadsCount;i++)
writeURI(fd, list->completedDownloads[i]);
- writeDownloadList(fd,
+ writeDownloadList(ectx,
+ fd,
list->next);
- writeDownloadList(fd,
+ writeDownloadList(ectx,
+ fd,
list->child);
}
@@ -268,7 +278,8 @@
*
* @return OK on success, SYSERR on error
*/
-static int readFileInfo(int fd,
+static int readFileInfo(struct GE_Context * ectx,
+ int fd,
ECRS_FileInfo * fi) {
unsigned int size;
unsigned int big;
@@ -289,7 +300,8 @@
GE_BREAK(ectx, 0);
return SYSERR;
}
- fi->meta = ECRS_deserializeMetaData(buf,
+ fi->meta = ECRS_deserializeMetaData(ectx,
+ buf,
size);
if (fi->meta == NULL) {
FREE(buf);
@@ -299,7 +311,7 @@
FREE(buf);
fi->uri
- = readURI(fd);
+ = readURI(ectx, fd);
if (fi->uri == NULL) {
ECRS_freeMetaData(fi->meta);
fi->meta = NULL;
@@ -312,7 +324,8 @@
return SYSERR;
}
-static void writeFileInfo(int fd,
+static void writeFileInfo(struct GE_Context * ectx,
+ int fd,
const ECRS_FileInfo * fi) {
unsigned int size;
char * buf;
@@ -322,7 +335,8 @@
if (size > 1024 * 1024)
size = 1024 * 1024;
buf = MALLOC(size);
- ECRS_serializeMetaData(fi->meta,
+ ECRS_serializeMetaData(ectx,
+ fi->meta,
buf,
size,
ECRS_SERIALIZE_PART | ECRS_SERIALIZE_NO_COMPRESS);
@@ -338,7 +352,7 @@
FSUI_Context * ctx = c;
FSUI_DownloadList * dpos;
- MUTEX_LOCK(&ctx->lock);
+ MUTEX_LOCK(ctx->lock);
dpos = ctx->activeDownloads.child;
#if DEBUG_PERSISTENCE
if (dpos != NULL)
@@ -349,7 +363,7 @@
updateDownloadThread(dpos);
dpos = dpos->next;
}
- MUTEX_UNLOCK(&ctx->lock);
+ MUTEX_UNLOCK(ctx->lock);
}
/**
@@ -360,7 +374,10 @@
* @param name name of the context, must not be NULL
* @return NULL on error
*/
-struct FSUI_Context * FSUI_start(const char * name,
+struct FSUI_Context * FSUI_start(struct GE_Context * ectx,
+ struct GC_Configuration * cfg,
+ const char * name,
+ unsigned int threadPoolSize,
int doResume,
FSUI_EventCallback cb,
void * closure) {
@@ -378,11 +395,12 @@
= FSUI_DOWNLOAD_PENDING; /* !? */
ret->activeDownloads.ctx
= ret;
- gh = getFileName("GNUNET",
- "GNUNET_HOME",
- "You must specify a directory for "
- "user-data under '%s%s' at the beginning"
- " of the configuration file.\n");
+
+ GC_get_configuration_value_string(cfg,
+ "GNUNET",
+ "GNUNET_HOME",
+ GNUNET_HOME_DIRECTORY,
+ &gh);
fn = MALLOC(strlen(gh) + strlen(name) + 2 + 5);
strcpy(fn, gh);
FREE(gh);
@@ -390,18 +408,22 @@
strcat(fn, name);
ret->name = fn;
if (doResume) {
- ret->ipc = IPC_SEMAPHORE_CREATE(fn,
- 1);
+ ret->ipc = IPC_SEMAPHORE_CREATE(ectx,
+ fn,
+ 1);
GE_LOG(ectx, GE_INFO | GE_REQUEST | GE_USER,
"Getting IPC lock for FSUI (%s).\n",
fn);
- IPC_SEMAPHORE_DOWN(ret->ipc);
- GE_LOG(ectx, GE_INFO | GE_REQUEST | GE_USER,
- "Aquired IPC lock.\n");
+ IPC_SEMAPHORE_DOWN(ret->ipc, YES);
+ GE_LOG(ectx,
+ GE_INFO | GE_REQUEST | GE_USER,
+ "Aquired IPC lock.\n");
fd = -1;
strcat(fn, ".res");
if (0 == ACCESS(fn, R_OK))
- fd = fileopen(fn, O_RDONLY);
+ fd = disk_file_open(ectx,
+ fn,
+ O_RDONLY);
if (fd != -1) {
char magic[8];
unsigned int big;
@@ -474,7 +496,7 @@
list
= MALLOC(sizeof(FSUI_SearchList));
list->uri
- = ECRS_stringToUri(buf);
+ = ECRS_stringToUri(ectx, buf);
FREE(buf);
if (list->uri == NULL) {
FREE(list);
@@ -538,11 +560,13 @@
list->unmatchedResultsReceived
= NULL;
for (i=0;i<list->sizeResultsReceived;i++)
- readFileInfo(fd,
+ readFileInfo(ectx,
+ fd,
&list->resultsReceived[i]);
for (i=0;i<list->sizeUnmatchedResultsReceived;i++) {
rp = &list->unmatchedResultsReceived[i];
- readFileInfo(fd,
+ readFileInfo(ectx,
+ fd,
&rp->fi);
if (sizeof(unsigned int) !=
@@ -589,11 +613,13 @@
GE_LOG(ectx, GE_DEBUG | GE_REQUEST | GE_USER,
"FSUI persistence: restarting search\n");
#endif
- if (0 != PTHREAD_CREATE(&list->handle,
- &searchThread,
- list,
- 32 * 1024))
- DIE_STRERROR("pthread_create");
+ list->handle = PTHREAD_CREATE(&searchThread,
+ list,
+ 32 * 1024);
+ if (list->handle == NULL)
+ GE_DIE_STRERROR(ectx,
+ GE_FATAL | GE_ADMIN | GE_IMMEDIATE,
+ "pthread_create");
/* finally: prepend to list */
list->next
@@ -605,7 +631,8 @@
0,
sizeof(FSUI_DownloadList));
ret->activeDownloads.child
- = readDownloadList(fd,
+ = readDownloadList(ectx,
+ fd,
ret,
&ret->activeDownloads);
@@ -634,7 +661,8 @@
list->sizeResultsReceived,
0);
WARN:
- GE_LOG(ectx, GE_WARNING | GE_BULK | GE_USER,
+ GE_LOG(ectx,
+ GE_WARNING | GE_BULK | GE_USER,
_("FSUI state file `%s' had syntax error at offset %u.\n"),
fn,
lseek(fd, 0, SEEK_CUR));
@@ -643,25 +671,28 @@
UNLINK(fn);
} else {
if (errno != ENOENT)
- GE_LOG_STRERROR_FILE(ectx,LOG_ERROR,
- "open",
- fn);
+ GE_LOG_STRERROR_FILE(ectx,
+ GE_WARNING | GE_BULK | GE_USER,
+ "open",
+ fn);
}
} else {
ret->ipc = NULL;
}
- MUTEX_CREATE_RECURSIVE(&ret->lock);
+ ret->lock = MUTEX_CREATE(YES);
ret->ecb = cb;
ret->ecbClosure = closure;
- ret->threadPoolSize = getConfigurationInt("FS",
- "DOWNLOAD-POOL");
+ ret->threadPoolSize = threadPoolSize;
if (ret->threadPoolSize == 0)
ret->threadPoolSize = 32;
ret->activeDownloadThreads = 0;
- addCronJob(&updateDownloadThreads,
- 0,
- FSUI_UDT_FREQUENCY,
- ret);
+ ret->cron = cron_create(ectx);
+ cron_add_job(ret->cron,
+ &updateDownloadThreads,
+ 0,
+ FSUI_UDT_FREQUENCY,
+ ret);
+ cron_start(ret->cron);
return ret;
}
@@ -670,6 +701,7 @@
* later if possible).
*/
void FSUI_stop(struct FSUI_Context * ctx) {
+ struct GE_Context * ectx;
FSUI_ThreadList * tpos;
FSUI_SearchList * spos;
FSUI_DownloadList * dpos;
@@ -678,18 +710,17 @@
int fd;
int big;
- GE_LOG(ectx, GE_INFO | GE_REQUEST | GE_USER,
- "FSUI shutdown. This may take a while.\n");
- FSUI_publishCollectionNow(ctx);
+ ectx = ctx->ectx;
+ GE_LOG(ectx,
+ GE_INFO | GE_REQUEST | GE_USER,
+ "FSUI shutdown. This may take a while.\n");
- i = isCronRunning();
- if (i)
- suspendCron();
- delCronJob(&updateDownloadThreads,
- FSUI_UDT_FREQUENCY,
- ctx);
- if (i)
- resumeCron();
+ cron_stop(ctx->cron);
+ cron_del_job(ctx->cron,
+ &updateDownloadThreads,
+ FSUI_UDT_FREQUENCY,
+ ctx);
+ cron_destroy(ctx->cron);
/* first, stop all download threads
by reducing the thread pool size to 0 */
ctx->threadPoolSize = 0;
@@ -703,32 +734,31 @@
while (ctx->activeThreads != NULL) {
tpos = ctx->activeThreads;
ctx->activeThreads = tpos->next;
- PTHREAD_JOIN(&tpos->handle, &unused);
+ PTHREAD_JOIN(tpos->handle, &unused);
FREE(tpos);
}
/* next, serialize all of the FSUI state */
if (ctx->ipc != NULL) {
- fd = fileopen(ctx->name,
- O_CREAT|O_TRUNC|O_WRONLY,
- S_IRUSR|S_IWUSR);
- if (fd == -1) {
- GE_LOG_STRERROR_FILE(ectx,LOG_ERROR,
- "open",
- ctx->name);
- } else {
+ fd = disk_file_open(ectx,
+ ctx->name,
+ O_CREAT|O_TRUNC|O_WRONLY,
+ S_IRUSR|S_IWUSR);
+ if (fd != -1) {
WRITE(fd,
"FSUI00\n\0",
8); /* magic */
}
#if DEBUG_PERSISTENCE
- GE_LOG(ectx, GE_DEBUG | GE_REQUEST | GE_USER,
- "Serializing FSUI state...\n");
+ GE_LOG(ectx,
+ GE_DEBUG | GE_REQUEST | GE_USER,
+ "Serializing FSUI state...\n");
#endif
} else {
#if DEBUG_PERSISTENCE
- GE_LOG(ectx, GE_DEBUG | GE_REQUEST | GE_USER,
- "NOT serializing FSUI state...\n");
+ GE_LOG(ectx,
+ GE_DEBUG | GE_REQUEST | GE_USER,
+ "NOT serializing FSUI state...\n");
#endif
fd = -1;
}
@@ -747,7 +777,7 @@
ctx->activeSearches = spos->next;
spos->signalTerminate = YES;
- PTHREAD_JOIN(&spos->handle, &unused);
+ PTHREAD_JOIN(spos->handle, &unused);
if (fd != -1) {
/* serialize pending searches */
char * tmp;
@@ -776,13 +806,15 @@
&big,
sizeof(unsigned int));
for (i=0;i<spos->sizeResultsReceived;i++)
- writeFileInfo(fd,
+ writeFileInfo(ectx,
+ fd,
&spos->resultsReceived[i]);
for (i=0;i<spos->sizeUnmatchedResultsReceived;i++) {
ResultPending * rp;
rp = &spos->unmatchedResultsReceived[i];
- writeFileInfo(fd,
+ writeFileInfo(ectx,
+ fd,
&rp->fi);
big = htonl(rp->matchingKeyCount);
WRITE(fd,
@@ -827,7 +859,8 @@
WRITE(fd,
&big,
sizeof(unsigned int));
- writeDownloadList(fd,
+ writeDownloadList(ectx,
+ fd,
ctx->activeDownloads.child);
}
if (fd != -1) {
@@ -845,7 +878,7 @@
IPC_SEMAPHORE_UP(ctx->ipc);
IPC_SEMAPHORE_DESTROY(ctx->ipc);
}
- MUTEX_DESTROY(&ctx->lock);
+ MUTEX_DESTROY(ctx->lock);
FREE(ctx->name);
FREE(ctx);
GE_LOG(ectx, GE_INFO | GE_REQUEST | GE_USER,
@@ -866,11 +899,11 @@
void * unused;
prev = NULL;
- MUTEX_LOCK(&ctx->lock);
+ MUTEX_LOCK(ctx->lock);
pos = ctx->activeThreads;
while (pos != NULL) {
if (YES == pos->isDone) {
- PTHREAD_JOIN(&pos->handle,
+ PTHREAD_JOIN(pos->handle,
&unused);
tmp = pos->next;
FREE(pos);
@@ -884,7 +917,7 @@
pos = pos->next;
}
}
- MUTEX_UNLOCK(&ctx->lock);
+ MUTEX_UNLOCK(ctx->lock);
}
Modified: GNUnet/src/applications/fs/fsui/fsui.h
===================================================================
--- GNUnet/src/applications/fs/fsui/fsui.h 2006-08-13 20:32:18 UTC (rev
3227)
+++ GNUnet/src/applications/fs/fsui/fsui.h 2006-08-14 04:20:33 UTC (rev
3228)
@@ -27,6 +27,7 @@
#define FSUI_H
#include "gnunet_util.h"
+#include "gnunet_util_cron.h"
#include "gnunet_ecrs_lib.h"
#include "gnunet_blockstore.h"
@@ -225,6 +226,11 @@
struct FSUI_Context * ctx;
/**
+ * Client context for the downloadx
+ */
+ void * cctx;
+
+ /**
* State of the download.
*/
FSUI_DownloadState state;
@@ -307,10 +313,33 @@
} FSUI_DownloadList;
/**
+ * Context for the unindex thread.
+ */
+typedef struct FSUI_UnindexList {
+
+ struct FSUI_UnindexList * next;
+
+ struct PTHREAD * handle;
+
+ char * filename;
+
+ struct FSUI_Context * ctx;
+
+ cron_t start_time;
+
+} FSUI_UnindexList;
+
+
+
+/**
* @brief global state of the FSUI library
*/
typedef struct FSUI_Context {
+ struct GE_Context * ectx;
+
+ struct GC_Configuration * cfg;
+
/**
* IPC semaphore used to ensure mutual exclusion
* between different processes of the same name
@@ -328,6 +357,8 @@
*/
struct MUTEX * lock;
+ struct CronManager * cron;
+
/**
* Callback for notifying the client about events.
*/
@@ -355,6 +386,11 @@
FSUI_SearchList * activeSearches;
/**
+ * List of active unindex operations.
+ */
+ FSUI_UnindexList * unindexOperations;
+
+ /**
* Root of the tree of downloads. On shutdown,
* FSUI must abort each of these downloads.
*/
Modified: GNUnet/src/applications/fs/fsui/search.c
===================================================================
--- GNUnet/src/applications/fs/fsui/search.c 2006-08-13 20:32:18 UTC (rev
3227)
+++ GNUnet/src/applications/fs/fsui/search.c 2006-08-14 04:20:33 UTC (rev
3228)
@@ -27,8 +27,11 @@
*/
#include "platform.h"
+#include "gnunet_directories.h"
#include "gnunet_protocols.h"
#include "gnunet_fsui_lib.h"
+#include "gnunet_uritrack_lib.h"
+#include "gnunet_namespace_lib.h"
#include "fsui.h"
#define DEBUG_SEARCH NO
@@ -58,7 +61,9 @@
&event);
}
-static void setNamespaceRoot(const ECRS_FileInfo * fi) {
+static void setNamespaceRoot(struct GE_Context * ectx,
+ struct GC_Configuration * cfg,
+ const ECRS_FileInfo * fi) {
char * fn;
char * fnBase;
HashCode512 ns;
@@ -70,9 +75,11 @@
return;
}
name = ECRS_getNamespaceName(&ns);
- fn = getConfigurationString("GNUNET", "GNUNET_HOME");
- fnBase = expandFileName(fn);
- FREE(fn);
+ GC_get_configuration_value_string(cfg,
+ "GNUNET",
+ "GNUNET_HOME",
+ GNUNET_HOME_DIRECTORY,
+ &fnBase);
fn = MALLOC(strlen(fnBase) +
strlen(NS_ROOTS) +
strlen(name) +
@@ -80,17 +87,18 @@
strcpy(fn, fnBase);
strcat(fn, DIR_SEPARATOR_STR);
strcat(fn, NS_ROOTS);
- mkdirp(fn);
+ disk_directory_create(ectx, fn);
strcat(fn, DIR_SEPARATOR_STR);
strcat(fn, name);
FREE(name);
FREE(fnBase);
if (OK == ECRS_getSKSContentHash(fi->uri,
&ns)) {
- writeFile(fn,
- &ns,
- sizeof(HashCode512),
- "644");
+ disk_file_write(ectx,
+ fn,
+ &ns,
+ sizeof(HashCode512),
+ "644");
}
FREE(fn);
}
@@ -106,12 +114,21 @@
unsigned int i;
unsigned int j;
ResultPending * rp;
+ struct GE_Context * ectx;
- FSUI_trackURI(fi);
+ ectx = pos->ctx->ectx;
+
+ URITRACK_trackURI(ectx,
+ pos->ctx->cfg,
+ fi);
if (isRoot) {
- setNamespaceRoot(fi);
- FSUI_addNamespaceInfo(fi->uri,
- fi->meta);
+ setNamespaceRoot(ectx,
+ pos->ctx->cfg,
+ fi);
+ NS_addNamespaceInfo(ectx,
+ pos->ctx->cfg,
+ fi->uri,
+ fi->meta);
return OK;
}
for (i=0;i<pos->sizeResultsReceived;i++)
@@ -137,8 +154,9 @@
if (ECRS_equalsUri(fi->uri,
rp->fi.uri)) {
for (j=0;j<rp->matchingKeyCount;j++)
- if (equalsHashCode512(key,
- &rp->matchingKeys[j])) {
+ if (0 == memcmp(key,
+ &rp->matchingKeys[j],
+ sizeof(HashCode512))) {
#if DEBUG_SEARCH
GE_LOG(ectx, GE_DEBUG | GE_REQUEST | GE_USER,
"Received search result that I have seen before (missing
keyword to show client).\n");
@@ -209,8 +227,7 @@
static int testTerminate(FSUI_SearchList * pos) {
if (pos->signalTerminate == NO)
return OK;
- else
- return SYSERR;
+ return SYSERR;
}
/**
@@ -218,7 +235,9 @@
*/
void * searchThread(void * cls) {
FSUI_SearchList * pos = cls;
- ECRS_search(pos->uri,
+ ECRS_search(pos->ctx->ectx,
+ pos->ctx->cfg,
+ pos->uri,
pos->anonymityLevel,
get_time() + cronYEARS, /* timeout!?*/
&spcb,
@@ -231,24 +250,15 @@
/**
* Start a search.
*/
-int FSUI_startSearch(struct FSUI_Context * ctx,
- unsigned int anonymityLevel,
- const struct ECRS_URI * uri) {
+struct FSUI_SearchList *
+FSUI_startSearch(struct FSUI_Context * ctx,
+ unsigned int anonymityLevel,
+ const struct ECRS_URI * uri) {
FSUI_SearchList * pos;
+ struct GE_Context * ectx;
- MUTEX_LOCK(&ctx->lock);
- pos = ctx->activeSearches;
- while (pos != NULL) {
- if (ECRS_equalsUri(uri,
- pos->uri)) {
- GE_LOG(ectx, GE_ERROR | GE_BULK | GE_USER,
- _("This search is already pending!\n"));
- GE_BREAK(ectx, 0);
- MUTEX_UNLOCK(&ctx->lock);
- return SYSERR;
- }
- pos = pos->next;
- }
+ ectx = ctx->ectx;
+ MUTEX_LOCK(ctx->lock);
pos = MALLOC(sizeof(FSUI_SearchList));
pos->signalTerminate = NO;
pos->uri = ECRS_dupUri(uri);
@@ -259,106 +269,76 @@
pos->unmatchedResultsReceived = 0;
pos->anonymityLevel = anonymityLevel;
pos->ctx = ctx;
- if (0 != PTHREAD_CREATE(&pos->handle,
- &searchThread,
- pos,
- 32 * 1024)) {
- LOG_STRERROR(LOG_ERROR, "PTHREAD_CREATE");
+ pos->handle = PTHREAD_CREATE(&searchThread,
+ pos,
+ 32 * 1024);
+ if (pos->handle == NULL) {
+ GE_LOG_STRERROR(ectx,
+ GE_ERROR | GE_IMMEDIATE | GE_USER | GE_ADMIN,
+ "PTHREAD_CREATE");
ECRS_freeUri(pos->uri);
FREE(pos);
- MUTEX_UNLOCK(&ctx->lock);
- return SYSERR;
+ MUTEX_UNLOCK(ctx->lock);
+ return NULL;
}
pos->next = ctx->activeSearches;
ctx->activeSearches = pos;
- MUTEX_UNLOCK(&ctx->lock);
- return OK;
+ MUTEX_UNLOCK(ctx->lock);
+ return pos;
}
/**
* Stop a search.
*/
int FSUI_stopSearch(struct FSUI_Context * ctx,
- const struct ECRS_URI * uri) {
+ struct FSUI_SearchList * sl) {
FSUI_SearchList * pos;
FSUI_SearchList * prev;
void * unused;
int i;
+ MUTEX_LOCK(ctx->lock);
prev = NULL;
- MUTEX_LOCK(&ctx->lock);
pos = ctx->activeSearches;
- while (pos != NULL) {
- if (ECRS_equalsUri(uri,
- pos->uri)) {
- pos->signalTerminate = YES;
- /* send signal to terminate sleep! */
- PTHREAD_KILL(&pos->handle,
- SIGALRM);
- PTHREAD_JOIN(&pos->handle,
- &unused);
- ECRS_freeUri(pos->uri);
- for (i=0;i<pos->sizeResultsReceived;i++) {
- ECRS_freeUri(pos->resultsReceived[i].uri);
- ECRS_freeMetaData(pos->resultsReceived[i].meta);
- }
- GROW(pos->resultsReceived,
- pos->sizeResultsReceived,
- 0);
- for (i=0;i<pos->sizeResultsReceived;i++) {
- ECRS_freeUri(pos->unmatchedResultsReceived[i].fi.uri);
- ECRS_freeMetaData(pos->unmatchedResultsReceived[i].fi.meta);
- GROW(pos->unmatchedResultsReceived[i].matchingKeys,
- pos->unmatchedResultsReceived[i].matchingKeyCount,
- 0);
- }
- GROW(pos->unmatchedResultsReceived,
- pos->sizeUnmatchedResultsReceived,
- 0);
- if (prev == NULL)
- ctx->activeSearches = pos->next;
- else
- prev->next = pos->next;
- FREE(pos);
- MUTEX_UNLOCK(&ctx->lock);
- return OK;
- }
+ while ( (pos != sl) &&
+ (pos != NULL) ) {
prev = pos;
pos = pos->next;
}
- MUTEX_UNLOCK(&ctx->lock);
- return SYSERR;
-}
-
-/**
- * List active searches. Can also be used to obtain
- * search results that were already signaled earlier.
- */
-int FSUI_listSearches(struct FSUI_Context * ctx,
- FSUI_SearchIterator iter,
- void * closure) {
- int ret;
- FSUI_SearchList * pos;
-
- ret = 0;
- MUTEX_LOCK(&ctx->lock);
- pos = ctx->activeSearches;
- while (pos != NULL) {
- if (iter != NULL) {
- if (OK != iter(closure,
- pos->uri,
- pos->anonymityLevel,
- pos->sizeResultsReceived,
- pos->resultsReceived)) {
- MUTEX_UNLOCK(&ctx->lock);
- return SYSERR;
- }
- }
- ret++;
- pos = pos->next;
+ if (pos == NULL) {
+ MUTEX_UNLOCK(ctx->lock);
+ return SYSERR;
}
- MUTEX_UNLOCK(&ctx->lock);
- return ret;
+ if (prev == NULL)
+ ctx->activeSearches = pos->next;
+ else
+ prev->next = pos->next;
+ MUTEX_UNLOCK(ctx->lock);
+ pos->next = NULL;
+ pos->signalTerminate = YES;
+ /* send signal to terminate sleep! */
+ PTHREAD_STOP_SLEEP(pos->handle);
+ PTHREAD_JOIN(pos->handle,
+ &unused);
+ ECRS_freeUri(pos->uri);
+ for (i=0;i<pos->sizeResultsReceived;i++) {
+ ECRS_freeUri(pos->resultsReceived[i].uri);
+ ECRS_freeMetaData(pos->resultsReceived[i].meta);
+ }
+ GROW(pos->resultsReceived,
+ pos->sizeResultsReceived,
+ 0);
+ for (i=0;i<pos->sizeResultsReceived;i++) {
+ ECRS_freeUri(pos->unmatchedResultsReceived[i].fi.uri);
+ ECRS_freeMetaData(pos->unmatchedResultsReceived[i].fi.meta);
+ GROW(pos->unmatchedResultsReceived[i].matchingKeys,
+ pos->unmatchedResultsReceived[i].matchingKeyCount,
+ 0);
+ }
+ GROW(pos->unmatchedResultsReceived,
+ pos->sizeUnmatchedResultsReceived,
+ 0);
+ return OK;
}
/* end of search.c */
Modified: GNUnet/src/applications/fs/fsui/unindex.c
===================================================================
--- GNUnet/src/applications/fs/fsui/unindex.c 2006-08-13 20:32:18 UTC (rev
3227)
+++ GNUnet/src/applications/fs/fsui/unindex.c 2006-08-14 04:20:33 UTC (rev
3228)
@@ -30,15 +30,6 @@
#include "gnunet_fsui_lib.h"
#include "fsui.h"
-/**
- * Context for the unindex thread.
- */
-typedef struct {
- char * filename;
- FSUI_ThreadList * tl;
- FSUI_Context * ctx;
- cron_t start_time;
-} UnindexThreadClosure;
/**
* Transform an ECRS progress callback into an FSUI event.
@@ -46,14 +37,14 @@
static void progressCallback(unsigned long long totalBytes,
unsigned long long completedBytes,
cron_t eta,
- UnindexThreadClosure * utc) {
+ void * cls) {
+ FSUI_UnindexList * utc = cls;
FSUI_Event event;
event.type = FSUI_unindex_progress;
event.data.UnindexProgress.completed = completedBytes;
event.data.UnindexProgress.total = totalBytes;
event.data.UnindexProgress.filename = utc->filename;
- event.data.UnindexProgress.start_time = utc->start_time;
event.data.UnindexProgress.eta = eta;
utc->ctx->ecb(utc->ctx->ecbClosure,
&event);
@@ -62,35 +53,39 @@
/**
* Thread that does the unindex.
*/
-static void * unindexThread(UnindexThreadClosure * utc) {
+static void * unindexThread(void * cls) {
+ FSUI_UnindexList * utc = cls;
FSUI_Event event;
int ret;
- ret = ECRS_unindexFile(utc->filename,
- (ECRS_UploadProgressCallback) &progressCallback,
+ ret = ECRS_unindexFile(utc->ctx->ectx,
+ utc->ctx->cfg,
+ utc->filename,
+ &progressCallback,
utc,
NULL,
NULL);
if (ret == OK) {
event.type = FSUI_unindex_complete;
- if (OK != getFileSize(utc->filename,
- &event.data.UnindexComplete.total)) {
- GE_BREAK(ectx, 0);
+ if (OK != disk_file_size(utc->ctx->ectx,
+ utc->filename,
+ &event.data.UnindexComplete.total,
+ YES)) {
+ GE_BREAK(utc->ctx->ectx, 0);
event.data.UnindexComplete.total = 0;
}
event.data.UnindexComplete.filename = utc->filename;
- event.data.UnindexComplete.start_time = utc->start_time;
} else {
event.type = FSUI_unindex_error;
- event.data.message = _("Unindex failed.");
+ event.data.UnindexError.message = _("Unindex failed.");
}
utc->ctx->ecb(utc->ctx->ecbClosure,
&event);
FREE(utc->filename);
- utc->tl->isDone = YES;
FREE(utc);
- GE_LOG(ectx, GE_DEBUG | GE_REQUEST | GE_USER,
- "FSUI unindexThread exits.\n");
+ GE_LOG(utc->ctx->ectx,
+ GE_DEBUG | GE_REQUEST | GE_USER,
+ "FSUI unindexThread exits.\n");
return NULL;
}
@@ -104,38 +99,36 @@
* SYSERR if the file does not exist or gnunetd is not
* running
*/
-int FSUI_unindex(struct FSUI_Context * ctx,
- const char * filename) {
- FSUI_ThreadList * tl;
- UnindexThreadClosure * utc;
+struct FSUI_UnindexList *
+FSUI_unindex(struct FSUI_Context * ctx,
+ const char * filename) {
+ FSUI_UnindexList * utc;
- if (YES == isDirectory(filename)) {
- GE_BREAK(ectx, 0);
- return SYSERR;
+ if (YES == disk_directory_test(ctx->ectx,
+ filename)) {
+ GE_BREAK(ctx->ectx, 0);
+ return NULL;
}
- utc = MALLOC(sizeof(UnindexThreadClosure));
+ utc = MALLOC(sizeof(FSUI_UnindexList));
utc->ctx = ctx;
utc->filename = STRDUP(filename);
- cronTime(&utc->start_time);
- tl = MALLOC(sizeof(FSUI_ThreadList));
- utc->tl = tl;
- tl->isDone = NO;
- if (0 != PTHREAD_CREATE(&tl->handle,
- (PThreadMain) &unindexThread,
- utc,
- 32 * 1024)) {
- LOG_STRERROR(LOG_ERROR, "PTHREAD_CREATE");
- FREE(tl);
+ utc->start_time = get_time();
+ utc->handle = PTHREAD_CREATE(&unindexThread,
+ utc,
+ 32 * 1024);
+ if (utc->handle == NULL) {
+ GE_LOG_STRERROR(ctx->ectx,
+ GE_ERROR | GE_ADMIN | GE_USER | GE_IMMEDIATE,
+ "PTHREAD_CREATE");
FREE(utc->filename);
FREE(utc);
- return SYSERR;
+ return NULL;
}
- MUTEX_LOCK(&ctx->lock);
- tl->next = ctx->activeThreads;
- ctx->activeThreads = tl;
- MUTEX_UNLOCK(&ctx->lock);
- cleanupFSUIThreadList(ctx);
- return OK;
+ MUTEX_LOCK(ctx->lock);
+ utc->next = ctx->unindexOperations;
+ ctx->unindexOperations = utc;
+ MUTEX_UNLOCK(ctx->lock);
+ return utc;
}
/* end of unindex.c */
Modified: GNUnet/src/applications/fs/fsui/upload.c
===================================================================
--- GNUnet/src/applications/fs/fsui/upload.c 2006-08-13 20:32:18 UTC (rev
3227)
+++ GNUnet/src/applications/fs/fsui/upload.c 2006-08-14 04:20:33 UTC (rev
3228)
@@ -1,6 +1,6 @@
/*
This file is part of GNUnet.
- (C) 2001, 2002, 2003, 2004 Christian Grothoff (and other contributing
authors)
+ (C) 2001, 2002, 2003, 2004, 2006 Christian Grothoff (and other
contributing authors)
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
@@ -165,11 +165,17 @@
tempName = STRDUP("/tmp/gnunetdir.XXXXXX");
handle = mkstemp(tempName);
if (handle == -1) {
- GE_LOG_STRERROR_FILE(ectx,LOG_ERROR, tempName, "mkstemp");
+ GE_LOG_STRERROR_FILE(ectx,
+ GE_ERROR | GE_USER | GE_BULK,
+ tempName,
+ "mkstemp");
} else if (len != WRITE(handle,
data,
len)) {
- GE_LOG_STRERROR_FILE(ectx,LOG_ERROR, tempName, "write");
+ GE_LOG_STRERROR_FILE(ectx,
+ GE_ERROR | GE_USER | GE_BULK,
+ tempName,
+ "write");
} else {
closefile(handle);
utc->filename = tempName;
@@ -573,11 +579,13 @@
tl = MALLOC(sizeof(FSUI_ThreadList));
utc->tl = tl;
tl->isDone = NO;
- if (0 != PTHREAD_CREATE(&tl->handle,
- &uploadThread,
- utc,
- 128 * 1024)) {
- LOG_STRERROR(LOG_ERROR, "PTHREAD_CREATE");
+ tl->handle = PTHREAD_CREATE(&uploadThread,
+ utc,
+ 128 * 1024);
+ if (tl->handle == NULL) {
+ GE_LOG_STRERROR(ectx,
+ GE_ERROR | GE_USER | GE_BULK,
+ "PTHREAD_CREATE");
FREE(tl);
FREE(utc->main_filename);
ECRS_freeMetaData(utc->meta);
@@ -642,11 +650,13 @@
tl = MALLOC(sizeof(FSUI_ThreadList));
utc->tl = tl;
tl->isDone = NO;
- if (0 != PTHREAD_CREATE(&tl->handle,
- &uploadThread,
- utc,
- 128 * 1024)) {
- LOG_STRERROR(LOG_ERROR, "PTHREAD_CREATE");
+ tl->handle = PTHREAD_CREATE(&uploadThread,
+ utc,
+ 128 * 1024);
+ if (tl->handle == NULL) {
+ GE_LOG_STRERROR(ectx,
+ GE_ERROR | GE_USER | GE_BULK,
+ "PTHREAD_CREATE");
FREE(tl);
FREE(utc->main_filename);
ECRS_freeMetaData(utc->meta);
Modified: GNUnet/src/applications/fs/uritrack/file_info.c
===================================================================
--- GNUnet/src/applications/fs/uritrack/file_info.c 2006-08-13 20:32:18 UTC
(rev 3227)
+++ GNUnet/src/applications/fs/uritrack/file_info.c 2006-08-14 04:20:33 UTC
(rev 3228)
@@ -83,7 +83,7 @@
static char * getToggleName(struct GE_Context * ectx,
struct GC_Configuration * cfg) {
- char * new;
+ char * nw;
char * pfx;
GC_get_configuration_value_string(cfg,
@@ -91,12 +91,12 @@
"GNUNET_HOME",
GNUNET_HOME_DIRECTORY,
&pfx);
- new = MALLOC(strlen(pfx) + strlen(TRACK_OPTION) + 2);
- strcpy(new, pfx);
- strcat(new, "/");
- strcat(new, TRACK_OPTION);
+ nw = MALLOC(strlen(pfx) + strlen(TRACK_OPTION) + 2);
+ strcpy(nw, pfx);
+ strcat(nw, "/");
+ strcat(nw, TRACK_OPTION);
FREE(pfx);
- return new;
+ return nw;
}
/**
Modified: GNUnet/src/include/gnunet_fsui_lib.h
===================================================================
--- GNUnet/src/include/gnunet_fsui_lib.h 2006-08-13 20:32:18 UTC (rev
3227)
+++ GNUnet/src/include/gnunet_fsui_lib.h 2006-08-14 04:20:33 UTC (rev
3228)
@@ -272,10 +272,6 @@
} SearchResuming;
- /**
- * Download Progress information. Also used
- * for download_completed event.
- */
struct {
FSUI_DownloadContext dc;
@@ -329,6 +325,29 @@
FSUI_DownloadContext dc;
/**
+ * How large is the total download (as far
+ * as known so far).
+ */
+ unsigned long long total;
+
+ /**
+ * Information about the download.
+ */
+ char * filename;
+
+ /**
+ * Original URI.
+ */
+ struct ECRS_URI * uri;
+
+ } DownloadComplete;
+
+
+ struct {
+
+ FSUI_DownloadContext dc;
+
+ /**
* Error message.
*/
const char * message;
@@ -607,6 +626,7 @@
FSUI_start(struct GE_Context * ectx,
struct GC_Configuration * cfg,
const char * name,
+ unsigned int threadPoolSize,
int doResume,
FSUI_EventCallback cb,
void * closure); /* fsui.c */
@@ -623,8 +643,7 @@
/**
* Start a search.
*
- * @return SYSERR if such a search is already pending, OK on
- * success
+ * @return NULL on error
*/
struct FSUI_SearchList *
FSUI_startSearch(struct FSUI_Context * ctx,
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r3228 - in GNUnet/src: applications/fs/fsui applications/fs/uritrack include,
grothoff <=