[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r138 - in GNUnet: . contrib src/applications/fs/ecrs src/ap
From: |
grothoff |
Subject: |
[GNUnet-SVN] r138 - in GNUnet: . contrib src/applications/fs/ecrs src/applications/fs/fsui src/applications/gap src/include |
Date: |
Mon, 31 Jan 2005 19:31:18 -0800 (PST) |
Author: grothoff
Date: 2005-01-31 19:31:17 -0800 (Mon, 31 Jan 2005)
New Revision: 138
Modified:
GNUnet/contrib/gnunet.user
GNUnet/src/applications/fs/ecrs/uri.c
GNUnet/src/applications/fs/fsui/namespace_info.c
GNUnet/src/applications/gap/gap.c
GNUnet/src/include/gnunet_ecrs_lib.h
GNUnet/src/include/gnunet_fsui_lib.h
GNUnet/todo
Log:
work on namespaces in fsui
Modified: GNUnet/contrib/gnunet.user
===================================================================
--- GNUnet/contrib/gnunet.user 2005-02-01 01:07:27 UTC (rev 137)
+++ GNUnet/contrib/gnunet.user 2005-02-01 03:31:17 UTC (rev 138)
@@ -46,10 +46,17 @@
################################################
-# Options for anonymous filesharing (AFS).
+# Options for filesharing (FS).
################################################
-[AFS]
+[FS]
+# Default priority for locally inserted content
+INSERT-PRIORITY = 50
+
+# Default expiration time for locally inserted content, in days
+# Default is 36500 (100 years)
+INSERT-EXPIRATION = 36500
+
# How long should gnunet-search try to get an answer to a query before
# timing out (in seconds). Default is "3000", which should be enough
# for pretty much anything. Use 0 for no timeout.
@@ -75,16 +82,7 @@
# Disable symlinking.
DISABLE-SYMLINK = NO
-#################################################
-# Default options for the gnunet-insert tool
-#################################################
-[GNUNET-INSERT]
-# What is the initial priority of content that is locally inserted?
-# Default is 65535 which is "very high".
-CONTENT-PRIORITY = 65535
-
-
#################################################
# Default options for gnunet-gtk
#################################################
Modified: GNUnet/src/applications/fs/ecrs/uri.c
===================================================================
--- GNUnet/src/applications/fs/ecrs/uri.c 2005-02-01 01:07:27 UTC (rev
137)
+++ GNUnet/src/applications/fs/ecrs/uri.c 2005-02-01 03:31:17 UTC (rev
138)
@@ -404,6 +404,25 @@
}
/**
+ * Get the (globally unique) name for the given
+ * namespace.
+ * @return the name (hash) of the namespace, caller
+ * must free it.
+ */
+char * ECRS_getNamespaceName(const struct ECRS_URI * uri) {
+ char * ret;
+
+ if (! ECRS_isNamespaceURI(uri)) {
+ BREAK();
+ return NULL;
+ }
+ ret = MALLOC(sizeof(EncName));
+ hash2enc(&uri->data.sks.namespace,
+ (EncName*)ret);
+ return ret;
+}
+
+/**
* Is this a keyword URI?
*/
int ECRS_isKeywordURI(const struct ECRS_URI * uri) {
Modified: GNUnet/src/applications/fs/fsui/namespace_info.c
===================================================================
--- GNUnet/src/applications/fs/fsui/namespace_info.c 2005-02-01 01:07:27 UTC
(rev 137)
+++ GNUnet/src/applications/fs/fsui/namespace_info.c 2005-02-01 03:31:17 UTC
(rev 138)
@@ -30,8 +30,111 @@
#include "gnunet_fsui_lib.h"
#include "fsui.h"
-#define NS_HANDLE "namespaces"
+#define NS_DIR "data/namespaces/"
+static void writeNamespaceInfo(const char * namespaceName,
+ const struct ECRS_MetaData * meta,
+ int ranking) {
+ unsigned int size;
+ unsigned int tag;
+ char * buf;
+ char * fn;
+ char * fnBase;
+
+ fn = getConfigurationString(NULL, "GNUNET_HOME");
+ fnBase = expandFileName(fn);
+ FREE(fn);
+ fn = MALLOC(strlen(fnBase) +
+ strlen(NS_DIR) +
+ strlen(namespaceName) +
+ 6);
+ strcpy(fn, fnBase);
+ strcat(fn, DIR_SEPARATOR_STR);
+ strcat(fn, NS_DIR);
+ mkdirp(fn);
+ strcat(fn, DIR_SEPARATOR_STR);
+ strcat(fn, namespaceName);
+ FREE(fnBase);
+
+ size = ECRS_sizeofMetaData(meta);
+ tag = size + sizeof(int);
+ buf = MALLOC(tag);
+ ((int *) buf)[0] = htonl(ranking); /* ranking */
+ GNUNET_ASSERT(size == ECRS_serializeMetaData(meta,
+ &buf[sizeof(int)],
+ size,
+ NO));
+ writeFile(fn,
+ buf,
+ tag,
+ "660");
+ FREE(fn);
+ FREE(buf);
+}
+
+static int readNamespaceInfo(const char * namespaceName,
+ struct ECRS_MetaData ** meta,
+ int * ranking) {
+ unsigned int size;
+ unsigned int tag;
+ char * buf;
+ char * fn;
+ char * fnBase;
+
+ *meta = NULL;
+ fn = getConfigurationString(NULL, "GNUNET_HOME");
+ fnBase = expandFileName(fn);
+ FREE(fn);
+ fn = MALLOC(strlen(fnBase) +
+ strlen(NS_DIR) +
+ strlen(namespaceName) +
+ 6);
+ strcpy(fn, fnBase);
+ strcat(fn, DIR_SEPARATOR_STR);
+ strcat(fn, NS_DIR);
+ strcat(fn, DIR_SEPARATOR_STR);
+ strcat(fn, namespaceName);
+ FREE(fnBase);
+
+ tag = getFileSize(fn);
+ if (tag <= sizeof(int)) {
+ FREE(fn);
+ return SYSERR;
+ }
+ if (tag > 16 * 1024 * 1024) {
+ /* too big, must be invalid! remove! */
+ BREAK();
+ UNLINK(fn);
+ FREE(fn);
+ return SYSERR;
+ }
+ buf = MALLOC(tag);
+ if (size != readFile(fn,
+ tag,
+ buf)) {
+ FREE(buf);
+ FREE(fn);
+ return SYSERR;
+ }
+
+ size = tag - sizeof(int);
+ *ranking = ntohl(((int *) buf)[0]);
+ if(OK != ECRS_deserializeMetaData(meta,
+ &buf[sizeof(int)],
+ size)) {
+ /* invalid data! remove! */
+ BREAK();
+ UNLINK(fn);
+ FREE(buf);
+ FREE(fn);
+ return SYSERR;
+ }
+ FREE(fn);
+ FREE(buf);
+ return OK;
+}
+
+
/**
* Create a new namespace (and publish an advertismement).
* This function is synchronous, but may block the system
@@ -49,67 +152,153 @@
const struct ECRS_URI * advertisementURI,
const HashCode160 * rootEntry,
struct ECRS_URI ** root) {
- return SYSERR;
+ int ret;
+
+ ret = ECRS_createNamespace(namespaceName,
+ meta,
+ ctx->anonymityLevel,
+ getConfigurationInt("FS", "INSERT-PRIORITY"),
+ getConfigurationInt("FS", "INSERT-EXPIRATION") *
cronYEARS + cronTime(NULL),
+ advertisementURI,
+ rootEntry,
+ root);
+ /* store binding of namespaceName to 'meta' in state DB! */
+ if (ret == OK) {
+ writeNamespaceInfo(namespaceName,
+ meta,
+ 0);
+ }
+ return ret;
}
/**
- * Change the ranking of a namespace.
+ * Change the ranking of a (non-local) namespace.
+ *
+ * @param ns the name of the namespace, as obtained
+ * from ECRS_getNamespaceName
+ * @param delta by how much should the rating be
+ * changed?
+ * @return new rating of the namespace
*/
int FSUI_rankNamespace(struct FSUI_Context * ctx,
- const HashCode160 * ns,
+ const char * ns,
int delta) {
- int * eval;
- int value;
+ struct ECRS_MetaData * meta;
int ret;
- char * name;
- EncName ename;
+ int ranking;
- hash2enc(ns, &ename);
- name = MALLOC(256);
- SNPRINTF(name, 256, "%s-%s", NS_HANDLE, (char*) &ename);
- eval = NULL;
- ret = stateReadContent(name, (void**) &eval);
- if (ret == -1) {
- eval = MALLOC(sizeof(int));
- *eval = htonl(0);
+ ret = readNamespaceInfo(ns,
+ &meta,
+ &ranking);
+ if (ret == SYSERR) {
+ ranking = 0;
+ meta = ECRS_createMetaData();
}
- value = ntohl(*eval);
- value += delta;
- if (value == 0) {
- stateUnlinkFromDB(name);
- } else if (delta != 0) {
- *eval = ntohl(value);
- stateWriteContent(name, sizeof(int), eval);
- }
- FREE(eval);
- FREE(name);
- return value;
+ ranking += delta;
+ writeNamespaceInfo(ns,
+ meta,
+ ranking);
+ ECRS_freeMetaData(meta);
+ return ranking;
}
+typedef struct {
+ FSUI_NamespaceIterator iterator;
+ void * closure;
+ int ret;
+} LNClosure;
+
+static void listNamespaceHelper(const char * fn,
+ const char * dirName,
+ void * cls) {
+ LNClosure * c = cls;
+ int ret;
+ struct ECRS_MetaData * meta;
+ int rating;
+
+ if (c->ret == SYSERR)
+ return;
+ if (OK != readNamespaceInfo(fn,
+ &meta,
+ &rating))
+ return; /* ignore entry */
+ ret = c->iterator(c->closure,
+ fn,
+ meta,
+ rating);
+ ECRS_freeMetaData(meta);
+ if (ret == SYSERR)
+ c->ret = ret;
+ else
+ c->ret++;
+}
+
/**
- * List all available (local) namespaces.
+ * List all available (local or non-local) namespaces.
*
- * @param local only list local namespaces (if NO, all
- * known namespaces are listed)
+ * @param local only list local namespaces (if NO, only
+ * non-local known namespaces are listed)
*/
int FSUI_listNamespaces(struct FSUI_Context * ctx,
int local,
FSUI_NamespaceIterator iterator,
void * closure) {
int ret;
- int size;
- int pos;
- char * list;
- list = NULL;
- size = stateReadContent(NS_HANDLE,
- (void**)&list);
- if (size < 0)
- return SYSERR;
- ret = 0;
- while (pos < size) {
- /* FIXME */
- break;
+ if (local == YES) {
+ int ret;
+ char ** names;
+ int i;
+ int rating;
+ int aborted;
+ struct ECRS_MetaData * meta;
+
+ aborted = NO;
+ names = NULL;
+ ret = ECRS_listNamespaces(&names);
+ for (i=0;i<ret;i++) {
+ if (aborted == NO) {
+ if (OK != readNamespaceInfo(names[i],
+ &meta,
+ &rating)) {
+ rating = 0;
+ meta = ECRS_createMetaData();
+ }
+ if (SYSERR == iterator(closure,
+ names[i],
+ meta,
+ rating))
+ aborted = YES;
+ ECRS_freeMetaData(meta);
+ }
+ FREE(names[i]);
+ }
+ GROW(names, ret, 0);
+ if (aborted == YES)
+ ret = -1;
+ } else {
+ char * fn;
+ char * fnBase;
+ LNClosure cls;
+
+ cls.iterator = iterator;
+ cls.closure = closure;
+ cls.ret = 0;
+ fn = getConfigurationString(NULL, "GNUNET_HOME");
+ fnBase = expandFileName(fn);
+ FREE(fn);
+ fn = MALLOC(strlen(fnBase) +
+ strlen(NS_DIR) +
+ 4);
+ strcpy(fn, fnBase);
+ strcat(fn, DIR_SEPARATOR_STR);
+ strcat(fn, NS_DIR);
+
+ scanDirectory(fn,
+ &listNamespaceHelper,
+ &cls);
+ ret = cls.ret;
+ FREE(fn);
}
return ret;
}
@@ -122,93 +311,62 @@
* @param updateInterval the desired frequency for updates
* @param lastId the ID of the last value (maybe NULL)
* @param thisId the ID of the update
+ * @param nextId the ID of the next update (maybe NULL)
* @param dst to which URI should the namespace entry refer?
* @param md what meta-data should be associated with the
* entry?
* @param uri set to the resulting URI
*/
-int FSUI_addToNamespace(const char * name,
+int FSUI_addToNamespace(struct FSUI_Context * ctx,
+ const char * name,
cron_t updateInterval,
const HashCode160 * lastId,
const HashCode160 * thisId,
+ const HashCode160 * nextId,
const struct ECRS_URI * dst,
const struct ECRS_MetaData * md,
struct ECRS_URI ** uri) {
- return SYSERR;
+ int ret;
+ cron_t creationTime;
+ HashCode160 nid;
+ HashCode160 tid;
+
+
+ ret = ECRS_addToNamespace(name,
+ ctx->anonymityLevel,
+ getConfigurationInt("FS", "INSERT-PRIORITY"),
+ getConfigurationInt("FS", "INSERT-EXPIRATION") *
cronYEARS + cronTime(NULL),
+ creationTime,
+ updateInterval,
+ thisId,
+ nextId,
+ dst,
+ md,
+ uri);
+
+ return ret;
}
/**
* List all updateable content in a given namespace.
*/
-int FSUI_listNamespaceContent(const char * name,
+int FSUI_listNamespaceContent(struct FSUI_Context * ctx,
+ const char * name,
FSUI_UpdateIterator iterator,
void * closure) {
return SYSERR;
}
-
-
-
-/**
- * Get the nickname of the given namespace. If the
- * nickname is not unique within our database, append
- * the namespace identifier to make it unique.
- *
- * @return the nickname
- */
-char * ECRS_getUniqueNickname(const HashCode160 * ns) {
-#if 0
- NBlock * list;
- int ret;
- EncName enc;
- char * nick;
- int unique;
- int i;
-
- ret = listNamespaces(&list);
- if (ret > 0) {
- nick = NULL;
- for (i=0;i<ret;i++) {
- if (equalsHashCode160(&list[i].namespace,
- ns)) {
- nick = STRNDUP(list[i].nickname,
- MAX_NAME_LEN-8);
- break;
- }
- }
- if (nick == NULL) {
- hash2enc(ns, &enc);
- return STRDUP((char*) &enc);
- }
- unique = YES;
- for (i=0;i<ret;i++)
- if (0 == strncmp(nick,
- list[i].nickname,
- MAX_NAME_LEN-8))
- if (! equalsHashCode160(&list[i].namespace,
- ns))
- unique = NO;
- } else
- unique = NO;
-
- if (unique) {
- return nick;
- } else {
- char * ret;
- size_t n;
-
- hash2enc(ns, &enc);
- n = strlen(nick) + 40;
- ret = MALLOC(n);
- SNPRINTF(ret, n, "%s-%s", nick, &enc);
- FREE(nick);
- return ret;
- }
-#endif
- return STRDUP("NOT IMPLEMENTED");
+static int mergeMeta(EXTRACTOR_KeywordType type,
+ const char * data,
+ void * cls) {
+ struct ECRS_MetaData * meta = cls;
+ ECRS_addToMetaData(meta,
+ type,
+ data);
+ return OK;
}
-#if 0
/**
* Add a namespace to the set of known namespaces.
* For all namespace advertisements that we discover
@@ -216,42 +374,36 @@
*
* @param ns the namespace identifier
*/
-void addNamespace(const NBlock * ns) {
- NBlock * list;
- int ret;
- unsigned int i;
+void FSUI_addNamespaceInfo(const struct ECRS_URI * uri,
+ const struct ECRS_MetaData * meta) {
+ char * name;
+ int ranking;
+ struct ECRS_MetaData * old;
- if (ntohs(ns->major_formatVersion) != NBLOCK_MAJOR_VERSION) {
+ if (! ECRS_isNamespaceURI(uri)) {
BREAK();
return;
}
- list = NULL;
- ret = stateReadContent(NS_HANDLE,
- (void**)&list);
- if (ret > 0) {
- if ( (ret % sizeof(NBlock)) != 0) {
- FREE(list);
- LOG(LOG_WARNING,
- _("State DB file '%s' corrupt, deleting contents.\n"),
- NS_HANDLE);
- stateUnlinkFromDB(NS_HANDLE);
- } else {
- for (i=0;i<ret/sizeof(NBlock);i++) {
- if (0 == memcmp(ns,
- &list[i],
- sizeof(NBlock))) {
- FREE(list);
- return; /* seen before */
- }
- }
- FREE(list);
- }
+ name = ECRS_getNamespaceName(uri);
+ if (name == NULL)
+ return;
+ ranking = 0;
+ if (OK == readNamespaceInfo(name,
+ &old,
+ &ranking)) {
+ ECRS_getMetaData(meta,
+ &mergeMeta,
+ old);
+ writeNamespaceInfo(name,
+ old,
+ ranking);
+ ECRS_freeMetaData(old);
+ } else {
+ writeNamespaceInfo(name,
+ meta,
+ ranking);
}
- stateAppendContent(NS_HANDLE,
- sizeof(NBlock),
- ns);
+ FREE(name);
}
-#endif
-
/* end of namespace_info.c */
Modified: GNUnet/src/applications/gap/gap.c
===================================================================
--- GNUnet/src/applications/gap/gap.c 2005-02-01 01:07:27 UTC (rev 137)
+++ GNUnet/src/applications/gap/gap.c 2005-02-01 03:31:17 UTC (rev 138)
@@ -1,4 +1,4 @@
- /*
+/*
This file is part of GNUnet
GNUnet is free software; you can redistribute it and/or modify
Modified: GNUnet/src/include/gnunet_ecrs_lib.h
===================================================================
--- GNUnet/src/include/gnunet_ecrs_lib.h 2005-02-01 01:07:27 UTC (rev
137)
+++ GNUnet/src/include/gnunet_ecrs_lib.h 2005-02-01 03:31:17 UTC (rev
138)
@@ -202,6 +202,15 @@
int ECRS_isNamespaceURI(const struct ECRS_URI * uri);
/**
+ * Get the (globally unique) name for the given
+ * namespace.
+ *
+ * @return the name (hash) of the namespace, caller
+ * must free it.
+ */
+char * ECRS_getNamespaceName(const struct ECRS_URI * uri);
+
+/**
* Is this a keyword URI?
*/
int ECRS_isKeywordURI(const struct ECRS_URI * uri);
@@ -344,7 +353,7 @@
const HashCode160 * hc);
/**
- * Delete a local namespace. Only prevents future insertions
+ * Delete a local namespace. Only prevents future insertions
* into the namespace, does not delete any content from
* the network!
*
@@ -353,7 +362,9 @@
int ECRS_deleteNamespace(const char * namespaceName); /* namespace.c */
/**
- * Build a list of all available namespaces
+ * Build a list of all available local (!) namespaces
+ * The returned names are only the nicknames since
+ * we only iterate over the local namespaces.
*
* @param list where to store the names (is allocated, caller frees)
* @return SYSERR on error, otherwise the number of pseudonyms in list
@@ -363,7 +374,8 @@
/**
* Add an entry into a namespace.
*
- * @param name in which namespace to publish
+ * @param name in which namespace to publish, use just the
+ * nickname of the namespace
* @param dst to which URI should the namespace entry refer?
* @param md what meta-data should be associated with the
* entry?
Modified: GNUnet/src/include/gnunet_fsui_lib.h
===================================================================
--- GNUnet/src/include/gnunet_fsui_lib.h 2005-02-01 01:07:27 UTC (rev
137)
+++ GNUnet/src/include/gnunet_fsui_lib.h 2005-02-01 03:31:17 UTC (rev
138)
@@ -280,7 +280,6 @@
*/
typedef int (*FSUI_NamespaceIterator)(void * cls,
const char * namespaceName,
- const HashCode160 * ns,
const struct ECRS_MetaData * md,
int rating);
@@ -558,15 +557,25 @@
* Change the ranking of a namespace.
*/
int FSUI_rankNamespace(struct FSUI_Context * ctx,
- const HashCode160 * ns,
+ const char * ns,
int delta); /* namespace_info.c */
/**
- * List all available (local) namespaces.
+ * Add a namespace to the set of known namespaces.
+ * For all namespace advertisements that we discover
+ * FSUI should automatically call this function.
*
- * @param local only list local namespaces (if NO, all
- * known namespaces are listed)
+ * @param ns the namespace identifier
*/
+void FSUI_addNamespaceInfo(const struct ECRS_URI * uri,
+ const struct ECRS_MetaData * meta);
+
+/**
+ * List all available (local or non-local) namespaces.
+ *
+ * @param local only list local namespaces (if NO, only
+ * non-local known namespaces are listed)
+ */
int FSUI_listNamespaces(struct FSUI_Context * ctx,
int local,
FSUI_NamespaceIterator iterator,
@@ -579,16 +588,24 @@
* @param name in which namespace to publish
* @param updateInterval the desired frequency for updates
* @param lastId the ID of the last value (maybe NULL)
- * @param thisId the ID of the update
+ * set if this is an update to an existing entry
+ * @param thisId the ID of the update (maybe NULL if
+ * lastId determines the value or if no specific value
+ * is desired)
+ * @param nextId the ID of the next update (maybe NULL);
+ * set for sporadic updates if a specific next ID is
+ * desired
* @param dst to which URI should the namespace entry refer?
* @param md what meta-data should be associated with the
* entry?
* @param uri set to the resulting URI
*/
-int FSUI_addToNamespace(const char * name,
+int FSUI_addToNamespace(struct FSUI_Context * ctx,
+ const char * name,
cron_t updateInterval,
const HashCode160 * lastId,
const HashCode160 * thisId,
+ const HashCode160 * nextId,
const struct ECRS_URI * dst,
const struct ECRS_MetaData * md,
struct ECRS_URI ** uri); /* namespace_info.c */
@@ -596,7 +613,8 @@
/**
* List all updateable content in a given namespace.
*/
-int FSUI_listNamespaceContent(const char * name,
+int FSUI_listNamespaceContent(struct FSUI_Context * ctx,
+ const char * name,
FSUI_UpdateIterator iterator,
void * closure); /* namespace_info.c */
Modified: GNUnet/todo
===================================================================
--- GNUnet/todo 2005-02-01 01:07:27 UTC (rev 137)
+++ GNUnet/todo 2005-02-01 03:31:17 UTC (rev 138)
@@ -9,7 +9,6 @@
0.7.0pre0 [4'05] (aka "preview"):
- AFS:
a) complete libfsui:
- - namespace creation
- namespace updates
- collections
b) complete gnunet-afs-tools:
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r138 - in GNUnet: . contrib src/applications/fs/ecrs src/applications/fs/fsui src/applications/gap src/include,
grothoff <=