[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r453 - in GNUnet: . src/applications/fs/fsui src/applicatio
From: |
grothoff |
Subject: |
[GNUnet-SVN] r453 - in GNUnet: . src/applications/fs/fsui src/applications/fs/tools src/include |
Date: |
Sun, 20 Mar 2005 11:18:40 -0800 (PST) |
Author: grothoff
Date: 2005-03-20 11:18:39 -0800 (Sun, 20 Mar 2005)
New Revision: 453
Modified:
GNUnet/src/applications/fs/fsui/collection.c
GNUnet/src/applications/fs/fsui/fsui.c
GNUnet/src/applications/fs/fsui/fsui.h
GNUnet/src/applications/fs/tools/gnunet-pseudonym.c
GNUnet/src/include/gnunet_fsui_lib.h
GNUnet/todo
Log:
completing FSUI feature list
Modified: GNUnet/src/applications/fs/fsui/collection.c
===================================================================
--- GNUnet/src/applications/fs/fsui/collection.c 2005-03-20 12:42:26 UTC
(rev 452)
+++ GNUnet/src/applications/fs/fsui/collection.c 2005-03-20 19:18:39 UTC
(rev 453)
@@ -35,8 +35,7 @@
* namespace.
*
* TODO:
- * - collection of URIs + MetaData
- * - publishing of the data
+ * - actually have FSUI lib call into collection.c!
*/
#include "platform.h"
@@ -56,18 +55,56 @@
#define DEFAULT_ADVERTISEMENT_PRIORITY 128
+/**
+ * @brief information about a collection
+ */
typedef struct CollectionData {
DataContainer hdr;
+ /**
+ * Has this collection changed since the last publication? (NBO)
+ */
+ int changed;
+ /**
+ * What is the last ID for the publication?
+ */
+ HashCode512 lastId;
+ /**
+ * What is the next ID for the publication?
+ */
HashCode512 nextId;
+ /**
+ * What is the update interval? (NBO!)
+ */
+ cron_t updateInterval;
+ /**
+ * What is the update interval? (NBO!)
+ */
+ cron_t lastPublication;
+ /**
+ * Anonymity level for the collection. (NBO)
+ */
+ unsigned int anonymityLevel;
+ /**
+ * Name of the collection
+ */
char name[1];
+ /* the name is followed by a
+ serialized ECRS directory */
} CollectionData;
/**
* Start collection.
+ *
+ * @param updateInterval of ECRS_SBLOCK_UPDATE_NONE
+ * means to update _immediately_ on any change,
+ * wherease ECRS_SBLOCK_UPDATE_SPORADIC means
+ * to publish updates when the FSUI_Context
+ * is destroyed (i.e. on exit from the UI).
*/
int FSUI_startCollection(struct FSUI_Context * ctx,
unsigned int anonymityLevel,
+ cron_t updateInterval,
const char * name,
const struct ECRS_MetaData * meta) {
struct ECRS_URI * advertisement;
@@ -76,6 +113,9 @@
cron_t now;
unsigned int prio;
CollectionData * cd;
+ unsigned long long dirLen;
+ char * dirData;
+ struct ECRS_MetaData * dirMeta;
FSUI_stopCollection(ctx); /* cancel old collection */
GNUNET_ASSERT(name != NULL);
@@ -100,11 +140,26 @@
}
ECRS_freeUri(advertisement);
ECRS_freeUri(rootURI);
- cd = MALLOC(sizeof(CollectionData) + strlen(name));
+ dirMeta = ECRS_dupMetaData(meta);
+ GNUNET_ASSERT(OK == ECRS_createDirectory(&dirData,
+ &dirLen,
+ 0,
+ NULL,
+ dirMeta));
+ ECRS_freeMetaData(dirMeta);
+ cd = MALLOC(sizeof(CollectionData) + strlen(name) + dirLen);
ctx->collectionData = &cd->hdr;
cd->hdr.size = ntohl(sizeof(CollectionData) + strlen(name));
+ makeRandomId(&cd->lastId);
cd->nextId = nextId;
+ cd->updateInterval = htonll(updateInterval);
+ cd->anonymityLevel = htonl(anonymityLevel);
+ cd->changed = htonl(NO);
strcpy(cd->name, name);
+ memcpy(&cd->name[strlen(name)+1],
+ dirData,
+ dirLen);
+ FREE(dirData);
return OK;
}
@@ -139,8 +194,198 @@
return &cd->name[0];
}
+/**
+ * Upload an update of the current collection information to the
+ * network now. The function has no effect if the collection has not
+ * changed since the last publication. If we are currently not
+ * collecting, this function does nothing.
+ *
+ * Note that clients typically don't have to call this
+ * function explicitly. FSUI will call the function on
+ * exit (for sporadically updated collections), on any
+ * change to the collection (for immediately updated
+ * content) or when the publication time has arrived
+ * (for periodically updated collections).
+ *
+ * However, clients may want to call this function if
+ * explicit publication of an update at another
+ * time is desired.
+ */
+void FSUI_publishCollectionNow(struct FSUI_Context * ctx) {
+ CollectionData * cd;
+ cron_t now;
+ struct ECRS_URI * uri;
+ struct ECRS_URI * directoryURI;
+ struct ECRS_MetaData * metaData;
+ unsigned long long dirLen;
+ char * tmpName;
+ int fd;
+ if (ctx->collectionData == NULL)
+ return;
+ cd = (CollectionData*) ctx->collectionData;
+ if (ntohl(cd->changed) == NO)
+ return;
+ cronTime(&now);
+ if ( (ntohll(cd->updateInterval) != ECRS_SBLOCK_UPDATE_NONE) &&
+ (ntohll(cd->updateInterval) != ECRS_SBLOCK_UPDATE_SPORADIC) &&
+ (ntohll(cd->lastPublication) + ntohll(cd->updateInterval) < now) )
+ return;
+ if ( (ntohll(cd->updateInterval) != ECRS_SBLOCK_UPDATE_NONE) &&
+ (ntohll(cd->updateInterval) != ECRS_SBLOCK_UPDATE_SPORADIC) ) {
+ HashCode512 delta;
+ deltaId(&cd->nextId,
+ &cd->lastId,
+ &delta);
+ cd->lastId = cd->nextId;
+ addHashCodes(&cd->nextId,
+ &delta,
+ &cd->nextId);
+ } else {
+ cd->lastId = cd->nextId;
+ makeRandomId(&cd->nextId);
+ }
+ tmpName = STRDUP("/tmp/gnunet-collectionXXXXXX");
+ fd = mkstemp(tmpName);
+ if (fd == -1) {
+ LOG_STRERROR(LOG_ERROR, "mkstemp");
+ FREE(tmpName);
+ return;
+ }
+ dirLen = ntohl(cd->hdr.size) - sizeof(CollectionData) - strlen(cd->name);
+ if (-1 == write(fd, &cd->name[strlen(cd->name)+1], dirLen)) {
+ LOG_STRERROR(LOG_ERROR, "write");
+ FREE(tmpName);
+ return;
+ }
+ CLOSE(fd);
+ if (OK != ECRS_uploadFile(tmpName,
+ NO, /* indexing */
+ ntohl(cd->anonymityLevel),
+ getConfigurationInt("FS",
+ "ADVERTISEMENT-PRIORITY"),
+ now + COLLECTION_ADV_LIFETIME,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ &directoryURI)) {
+ UNLINK(tmpName);
+ FREE(tmpName);
+ return;
+ }
+ UNLINK(tmpName);
+ FREE(tmpName);
+ metaData = NULL;
+ GNUNET_ASSERT(OK == ECRS_listDirectory(&cd->name[strlen(cd->name)+1],
+ dirLen,
+ &metaData,
+ NULL,
+ NULL));
+ if (OK == ECRS_addToNamespace(cd->name,
+ ntohl(cd->anonymityLevel),
+ getConfigurationInt("FS",
+ "ADVERTISEMENT-PRIORITY"),
+ now + COLLECTION_ADV_LIFETIME,
+ now,
+ ntohll(cd->updateInterval),
+ &cd->lastId,
+ &cd->nextId,
+ directoryURI,
+ metaData,
+ &uri)) {
+ cd->lastPublication = htonll(now);
+ cd->changed = htonl(NO);
+ }
+ ECRS_freeUri(uri);
+ ECRS_freeMetaData(metaData);
+}
+struct CCcls {
+ unsigned int count;
+ ECRS_FileInfo * fis;
+};
+
+static int collectCallback(const ECRS_FileInfo * fi,
+ const HashCode512 * key,
+ struct CCcls * cls) {
+ GROW(cls->fis,
+ cls->count,
+ cls->count+1);
+ cls->fis[cls->count-1].uri = ECRS_dupUri(fi->uri);
+ cls->fis[cls->count-1].meta = ECRS_dupMetaData(fi->meta);
+ return OK;
+}
+
+/**
+ * If we are currently building a collection, publish
+ * the given file information in that collection.
+ * If we are currently not collecting, this function
+ * does nothing.
+ *
+ * Note that clients typically don't have to call this
+ * function explicitly -- by using the FSUI library it
+ * should be called automatically by FSUI code whenever
+ * needed. However, the function maybe useful if you're
+ * inserting files using libECRS directly or need other
+ * ways to explicitly extend a collection.
+ */
+void FSUI_publishToCollection(struct FSUI_Context * ctx,
+ const ECRS_FileInfo * fi) {
+ CollectionData * cd;
+ unsigned long long dirLen;
+ char * dirData;
+ struct ECRS_MetaData * metaData;
+ struct CCcls cls;
+ int i;
+
+ if (ctx->collectionData == NULL)
+ return;
+ if ((ECRS_isKeywordURI(fi->uri))) {
+ BREAK();
+ return;
+ }
+ cd = (CollectionData*) ctx->collectionData;
+ dirLen = ntohl(cd->hdr.size) - strlen(cd->name) - sizeof(CollectionData);
+ cls.count = 0;
+ cls.fis = NULL;
+ GNUNET_ASSERT(OK ==
+ ECRS_listDirectory(&cd->name[strlen(cd->name)+1],
+ dirLen,
+ &metaData,
+ (ECRS_SearchProgressCallback)
&collectCallback,
+ &cls));
+ collectCallback(fi,
+ NULL,
+ &cls);
+ dirData = NULL;
+ GNUNET_ASSERT(OK ==
+ ECRS_createDirectory(&dirData,
+ &dirLen,
+ cls.count,
+ cls.fis,
+ metaData));
+ ECRS_freeMetaData(metaData);
+ for (i=0;i<cls.count;i++) {
+ ECRS_freeUri(cls.fis[i].uri);
+ ECRS_freeMetaData(cls.fis[i].meta);
+ }
+ GROW(cls.fis,
+ cls.count,
+ 0);
+ REALLOC(cd,
+ sizeof(CollectionData) + strlen(cd->name) + dirLen);
+ memcpy(&cd->name[strlen(cd->name)+1],
+ dirData,
+ dirLen);
+ FREE(dirData);
+ cd->changed = htonl(YES);
+ if (ntohll(cd->updateInterval) == ECRS_SBLOCK_UPDATE_NONE)
+ FSUI_publishCollectionNow(ctx);
+}
+
+
+
/* end of collection.c */
Modified: GNUnet/src/applications/fs/fsui/fsui.c
===================================================================
--- GNUnet/src/applications/fs/fsui/fsui.c 2005-03-20 12:42:26 UTC (rev
452)
+++ GNUnet/src/applications/fs/fsui/fsui.c 2005-03-20 19:18:39 UTC (rev
453)
@@ -108,6 +108,7 @@
LOG(LOG_INFO,
"FSUI shutdown. This may take a while.\n");
+ FSUI_publishCollectionNow(ctx);
while (ctx->activeThreads != NULL) {
tpos = ctx->activeThreads;
ctx->activeThreads = tpos->next;
Modified: GNUnet/src/applications/fs/fsui/fsui.h
===================================================================
--- GNUnet/src/applications/fs/fsui/fsui.h 2005-03-20 12:42:26 UTC (rev
452)
+++ GNUnet/src/applications/fs/fsui/fsui.h 2005-03-20 19:18:39 UTC (rev
453)
@@ -271,4 +271,5 @@
void cleanupFSUIThreadList(FSUI_Context * ctx);
+
#endif
Modified: GNUnet/src/applications/fs/tools/gnunet-pseudonym.c
===================================================================
--- GNUnet/src/applications/fs/tools/gnunet-pseudonym.c 2005-03-20 12:42:26 UTC
(rev 452)
+++ GNUnet/src/applications/fs/tools/gnunet-pseudonym.c 2005-03-20 19:18:39 UTC
(rev 453)
@@ -379,6 +379,7 @@
pname);
if (OK == FSUI_startCollection(ctx,
0, /* FIXME: anonymity level! */
+ ECRS_SBLOCK_UPDATE_SPORADIC, /* FIXME:
allow other update policies */
pname,
meta)) {
printf(_("Started collection '%s'.\n"),
Modified: GNUnet/src/include/gnunet_fsui_lib.h
===================================================================
--- GNUnet/src/include/gnunet_fsui_lib.h 2005-03-20 12:42:26 UTC (rev
452)
+++ GNUnet/src/include/gnunet_fsui_lib.h 2005-03-20 19:18:39 UTC (rev
453)
@@ -533,6 +533,7 @@
*/
int FSUI_startCollection(struct FSUI_Context * ctx,
unsigned int anonymityLevel,
+ cron_t updateInterval,
const char * name,
const struct ECRS_MetaData * meta); /* collection.c */
@@ -550,6 +551,42 @@
*/
const char * FSUI_getCollection(struct FSUI_Context * ctx); /* collection.c */
+/**
+ * Upload an update of the current collection information to the
+ * network now. The function has no effect if the collection has not
+ * changed since the last publication. If we are currently not
+ * collecting, this function does nothing.
+ *
+ * Note that clients typically don't have to call this
+ * function explicitly. FSUI will call the function on
+ * exit (for sporadically updated collections), on any
+ * change to the collection (for immediately updated
+ * content) or when the publication time has arrived
+ * (for periodically updated collections).
+ *
+ * However, clients may want to call this function if
+ * explicit publication of an update at another
+ * time is desired.
+ */
+void FSUI_publishCollectionNow(struct FSUI_Context * ctx);
+
+/**
+ * If we are currently building a collection, publish
+ * the given file information in that collection.
+ * If we are currently not collecting, this function
+ * does nothing.
+ *
+ * Note that clients typically don't have to call this
+ * function explicitly -- by using the FSUI library it
+ * should be called automatically by FSUI code whenever
+ * needed. However, the function maybe useful if you're
+ * inserting files using libECRS directly or need other
+ * ways to explicitly extend a collection.
+ */
+void FSUI_publishToCollection(struct FSUI_Context * ctx,
+ const ECRS_FileInfo * fi);
+
+
/* ******************** Namespace API ***************** */
/**
Modified: GNUnet/todo
===================================================================
--- GNUnet/todo 2005-03-20 12:42:26 UTC (rev 452)
+++ GNUnet/todo 2005-03-20 19:18:39 UTC (rev 453)
@@ -13,7 +13,6 @@
* gap
* dht / gnunet-dht-join and gnunet-dht-query
- FSUI:
- * collections
* testing
- transport refactoring:
* HTTP: MTU change! => test with tbench!
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r453 - in GNUnet: . src/applications/fs/fsui src/applications/fs/tools src/include,
grothoff <=