[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r1317 - in GNUnet: . src/applications/fs/module
From: |
grothoff |
Subject: |
[GNUnet-SVN] r1317 - in GNUnet: . src/applications/fs/module |
Date: |
Fri, 8 Jul 2005 13:36:15 -0700 (PDT) |
Author: grothoff
Date: 2005-07-08 13:35:59 -0700 (Fri, 08 Jul 2005)
New Revision: 1317
Modified:
GNUnet/src/applications/fs/module/migration.c
GNUnet/src/applications/fs/module/ondemand.c
GNUnet/src/applications/fs/module/ondemand.h
GNUnet/todo
Log:
#762
Modified: GNUnet/src/applications/fs/module/migration.c
===================================================================
--- GNUnet/src/applications/fs/module/migration.c 2005-07-08 19:34:52 UTC
(rev 1316)
+++ GNUnet/src/applications/fs/module/migration.c 2005-07-08 20:35:59 UTC
(rev 1317)
@@ -54,6 +54,20 @@
* Traffic service.
*/
static Traffic_ServiceAPI * traffic;
+
+/**
+ * Lock used to access content.
+ */
+static Mutex lock;
+
+/**
+ * The content that we are currently trying
+ * to migrate (used to give us more than one
+ * chance should we fail for some reason the
+ * first time).
+ */
+static Datastore_Value * content;
+
/**
* Callback method for pushing content into the network.
@@ -76,49 +90,67 @@
unsigned int padding) {
unsigned int ret;
HashCode512 key;
- Datastore_Value * content;
GapWrapper * gw;
unsigned int size;
cron_t et;
cron_t now;
unsigned int anonymity;
- ret = 0;
- if (OK == datastore->getRandom(&receiver->hashPubKey,
- padding,
- &key,
- &content,
- 0)) {
+ MUTEX_LOCK(&lock);
+ if (content != NULL) {
size = sizeof(GapWrapper) + ntohl(content->size) - sizeof(Datastore_Value);
- et = ntohll(content->expirationTime);
- cronTime(&now);
- if (et > now) {
- et -= now;
- et = et % MAX_MIGRATION_EXP;
- et += now;
+ if (size > padding) {
+ FREE(content);
+ content = NULL;
}
- anonymity = ntohl(content->anonymityLevel);
- ret = SYSERR;
- if (anonymity == 0) {
- /* ret = OK; (if DHT succeeds) fixme for DHT */
- }
- if ( (ret != OK) &&
- (OK == checkCoverTraffic(traffic,
- anonymity)) ) {
- gw = MALLOC(size);
- gw->dc.size = htonl(size);
- gw->timeout = htonll(et);
- memcpy(&gw[1],
- &content[1],
- size - sizeof(GapWrapper));
- ret = gap->tryMigrate(&gw->dc,
- &key,
- position,
- padding);
- FREE(gw);
+ }
+ if (content == NULL) {
+ if (OK != datastore->getRandom(&receiver->hashPubKey,
+ padding,
+ &key,
+ &content,
+ 0)) {
+ MUTEX_UNLOCK(&lock);
+ return 0;
}
- FREE(content);
}
+ size = sizeof(GapWrapper) + ntohl(content->size) - sizeof(Datastore_Value);
+ if (size > padding) {
+ MUTEX_UNLOCK(&lock);
+ return 0;
+ }
+ et = ntohll(content->expirationTime);
+ cronTime(&now);
+ if (et > now) {
+ et -= now;
+ et = et % MAX_MIGRATION_EXP;
+ et += now;
+ }
+ anonymity = ntohl(content->anonymityLevel);
+ ret = 0;
+ if (anonymity == 0) {
+ /* ret > 0; (if DHT succeeds) fixme for DHT */
+ }
+ if ( (ret == 0) &&
+ (OK == checkCoverTraffic(traffic,
+ anonymity)) ) {
+ gw = MALLOC(size);
+ gw->dc.size = htonl(size);
+ gw->timeout = htonll(et);
+ memcpy(&gw[1],
+ &content[1],
+ size - sizeof(GapWrapper));
+ ret = gap->tryMigrate(&gw->dc,
+ &key,
+ position,
+ padding);
+ FREE(gw);
+ }
+ if (ret > 0) {
+ FREE(content);
+ content = NULL;
+ }
+ MUTEX_UNLOCK(&lock);
return ret;
}
@@ -127,6 +159,7 @@
GAP_ServiceAPI * g,
DHT_ServiceAPI * d,
Traffic_ServiceAPI * t) {
+ MUTEX_CREATE(&lock);
coreAPI = capi;
datastore = ds;
gap = g;
@@ -144,6 +177,9 @@
dht = NULL;
coreAPI = NULL;
traffic = NULL;
+ FREENONNULL(content);
+ content = NULL;
+ MUTEX_DESTROY(&lock);
}
/* end of migration.c */
Modified: GNUnet/src/applications/fs/module/ondemand.c
===================================================================
--- GNUnet/src/applications/fs/module/ondemand.c 2005-07-08 19:34:52 UTC
(rev 1316)
+++ GNUnet/src/applications/fs/module/ondemand.c 2005-07-08 20:35:59 UTC
(rev 1317)
@@ -19,7 +19,7 @@
*/
/**
- * @file applications/afs/module/fileindex.c
+ * @file applications/fs/module/ondemand.c
* @brief access to the list of indexed files
* @author Christian Grothoff
*/
@@ -214,11 +214,10 @@
fn);
fd = fileopen(fn,
#ifdef O_LARGEFILE
- O_CREAT|O_WRONLY|O_LARGEFILE,
-#else
- O_CREAT|O_WRONLY,
+ O_LARGEFILE |
#endif
- S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH); /* 644 */
+ O_CREAT|O_WRONLY,
+ S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH); /* 644 */
if(fd == -1) {
LOG_FILE_STRERROR(LOG_ERROR, "open", fn);
FREE(fn);
@@ -361,15 +360,16 @@
odb = (OnDemandBlock*) dbv;
fn = getOnDemandFile(&odb->fileId);
+ fileHandle = fileopen(fn,
#ifdef O_LARGEFILE
- fileHandle = fileopen(fn, O_RDONLY|O_LARGEFILE, 0);
-#else
- fileHandle = fileopen(fn, O_RDONLY, 0);
+ O_LARGEFILE |
#endif
+ O_RDONLY,
+ 0);
if (fileHandle == -1) {
char unavail_key[256];
EncName enc;
- cron_t *first_unavail;
+ cron_t * first_unavail;
struct stat linkStat;
LOG_FILE_STRERROR(LOG_ERROR, "open", fn);
Modified: GNUnet/src/applications/fs/module/ondemand.h
===================================================================
--- GNUnet/src/applications/fs/module/ondemand.h 2005-07-08 19:34:52 UTC
(rev 1316)
+++ GNUnet/src/applications/fs/module/ondemand.h 2005-07-08 20:35:59 UTC
(rev 1317)
@@ -1,5 +1,6 @@
/*
This file is part of GNUnet
+ (C) 2001, 2002, 2004, 2005 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
@@ -18,7 +19,7 @@
*/
/**
- * @file applications/afs/module/fileindex.h
+ * @file applications/fs/module/ondemand.h
* @brief On-demand encoding of indexed files
* @author Christian Grothoff
*/
@@ -37,7 +38,7 @@
* YES on success
*/
int ONDEMAND_initIndex(const HashCode512 * fileId,
- const char *fn);
+ const char *fn);
/**
* @return NO if already present, YES on success,
Modified: GNUnet/todo
===================================================================
--- GNUnet/todo 2005-07-08 19:34:52 UTC (rev 1316)
+++ GNUnet/todo 2005-07-08 20:35:59 UTC (rev 1317)
@@ -15,8 +15,6 @@
parsing, one of which is not thread-safe and only
used by src/conf. Any reasons why we could not
clean that up? [ Nils??? ]
-* cleanup API: FSUI_insertIntoNamespace or whatever,
- should return URI [ CG ]
0.7.0 [8'05?] (aka "compatibility? what's that?"):
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r1317 - in GNUnet: . src/applications/fs/module,
grothoff <=