gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r208 - in GNUnet/src: applications/fs/lib applications/fs/m


From: grothoff
Subject: [GNUnet-SVN] r208 - in GNUnet/src: applications/fs/lib applications/fs/module applications/gap include
Date: Mon, 7 Feb 2005 13:40:29 -0800 (PST)

Author: grothoff
Date: 2005-02-07 13:40:28 -0800 (Mon, 07 Feb 2005)
New Revision: 208

Modified:
   GNUnet/src/applications/fs/lib/fslib.c
   GNUnet/src/applications/fs/module/fs.c
   GNUnet/src/applications/fs/module/migration.c
   GNUnet/src/applications/fs/module/migration.h
   GNUnet/src/applications/fs/module/querymanager.c
   GNUnet/src/applications/fs/module/querymanager.h
   GNUnet/src/applications/gap/TODO
   GNUnet/src/applications/gap/gap.c
   GNUnet/src/include/fs.h
   GNUnet/src/include/gnunet_gap_service.h
Log:
gap updates

Modified: GNUnet/src/applications/fs/lib/fslib.c
===================================================================
--- GNUnet/src/applications/fs/lib/fslib.c      2005-02-07 21:36:40 UTC (rev 
207)
+++ GNUnet/src/applications/fs/lib/fslib.c      2005-02-07 21:40:28 UTC (rev 
208)
@@ -86,7 +86,8 @@
 
          value = MALLOC(sizeof(Datastore_Value) + size);
          value->size = htons(size + sizeof(Datastore_Value));
-         value->type = rep->type;
+         value->type = htonl(getTypeOfBlock(size,
+                                            &rep[1]));
          value->prio = htonl(0);
          value->anonymityLevel = htonl(0);
          value->expirationTime = htonll(0);

Modified: GNUnet/src/applications/fs/module/fs.c
===================================================================
--- GNUnet/src/applications/fs/module/fs.c      2005-02-07 21:36:40 UTC (rev 
207)
+++ GNUnet/src/applications/fs/module/fs.c      2005-02-07 21:40:28 UTC (rev 
208)
@@ -40,48 +40,6 @@
 #include "querymanager.h"
 #include "fs.h"
 
-/**
- * What is the maximum expiration time for migrated content? 
- *
- * This is a non-trivial issue.  If we have a ceiling for migration
- * time, it would violate anonymity if we send out content with an
- * expiration time above that ceiling (since it would expose the
- * content to originate from this peer).  But we want to store a
- * higher expiration time for our content in the DB.
- * 
- * A first idea would be to pick a random time smaller than the limit
- * for outgoing content; that does not _quite_ work since that could
- * also expose us as the originator: only for our own content the
- * expiration time would randomly go up and down.
- * 
- * The current best solution is to first bound the expiration time by
- * this ceiling (for inbound and outbound ETs, not for the database
- * entries locally) using modulo (to, in practice, get a constant
- * bound for the local content just like for the migrated content).
- * Then that number is randomized for _all_ outgoing content.  This
- * way, the time left changes for all entries, but statistically
- * always decreases on average as time progresses (also for all
- * entries).
- *
- * Now, for local content eventually modulo will rebound to the MAX
- * (whereas for migrated content it will hit 0 and disappear).  But
- * that is OK: the adversary cannot distinguish the modulo wraparound
- * from content migration (refresh with higher lifetime) which could
- * plausibly happen from the original node (and in fact would happen
- * around the same time!).  This design also achieves the design goal
- * that if the original node disappears, the migrated content will
- * eventually time-out (which is good since we don't want dangling
- * search results to stay around).
- *
- * However, this does NOT mean that migrated content cannot live
- * longer than 1 month -- remember, GNUnet peers discard expired
- * content _if they run out of space_.  So it is perfectly plausible
- * that content stays around longer.  Finally, clients (UI) may want
- * to filter / rank / display search results with their current
- * expiration to give the user some indication about availability.
- * 
- */
-#define MAX_MIGRATION_EXP (1L * cronMONTHS)
 
 typedef struct {
   struct DHT_GET_RECORD * rec;
@@ -165,7 +123,8 @@
 
   dv = MALLOC(size);
   dv->size = htonl(size);
-  dv->type = gw->type;
+  dv->type = htonl(getTypeOfBlock(size - sizeof(Datastore_Value),
+                                 &gw[1]));
   dv->prio = htonl(prio);
   dv->anonymityLevel = htonl(0);
   et = ntohll(gw->timeout);
@@ -222,7 +181,9 @@
     return SYSERR;
   }
   rs = (RequestSearch*) req;
-  trackQuery(&rs->query[0], sock);
+  trackQuery(&rs->query[0], 
+            ntohl(rs->type),
+            sock);
   keyCount = 1 + (ntohs(req->size) - sizeof(RequestSearch)) / 
sizeof(HashCode160);
   gap->get_start(ntohl(rs->type),
                 ntohl(rs->anonymityLevel),              
@@ -323,7 +284,6 @@
       sizeof(Datastore_Value);
     gw = MALLOC(size);
     gw->dc.size = htonl(size);
-    gw->type = htonl(type);
     et = ntohll(ri->expiration);
     /* expiration time normalization and randomization */
     cronTime(&now);
@@ -498,7 +458,7 @@
 static int csHandleRequestGetAvgPriority(ClientHandle sock,
                                         const CS_HEADER * req) {
   return coreAPI->sendValueToClient(sock, 
-                                   0); /* FIXME! */
+                                   gap->getAvgPriority());
 }
 
 /**
@@ -591,7 +551,6 @@
   
   gw = MALLOC(size);
   gw->dc.size = htonl(size);
-  gw->type = value->type;
   et = ntohll(value->expirationTime);
   /* expiration time normalization and randomization */
   cronTime(&now);
@@ -714,7 +673,6 @@
   
   gw = MALLOC(size);
   gw->dc.size = htonl(size);
-  gw->type = value->type;
   et = ntohll(value->expirationTime);
   /* expiration time normalization and randomization */
   cronTime(&now);
@@ -772,6 +730,31 @@
                              were found */
   return ret;
 }
+
+static int uniqueReplyIdentifier(const void * content,
+                                unsigned int size,
+                                unsigned int type,
+                                const HashCode160 * primaryKey) {
+  HashCode160 q;
+
+  unsigned int t;
+  if ( (OK == getQueryFor(size,
+                         content,
+                         &q)) &&
+       (equalsHashCode160(&q,
+                         primaryKey)) &&
+       ( (type == ANY_BLOCK) ||
+        (type == (t = getTypeOfBlock(size, content) ) ) ) ) {
+    switch(type) {
+    case D_BLOCK:
+      return YES;
+    default: 
+      return NO;
+    }
+  } else
+    return NO;
+}
+
   
 /**
  * Initialize the FS module. This method name must match
@@ -816,7 +799,7 @@
   dsGap.del = &gapDel;
   dsGap.iterate = &gapIterate;
   initQueryManager(capi);
-  gap->init(&dsGap);
+  gap->init(&dsGap, &uniqueReplyIdentifier);
   
   if (dht != NULL) {
     dsDht.closure = NULL;

Modified: GNUnet/src/applications/fs/module/migration.c
===================================================================
--- GNUnet/src/applications/fs/module/migration.c       2005-02-07 21:36:40 UTC 
(rev 207)
+++ GNUnet/src/applications/fs/module/migration.c       2005-02-07 21:40:28 UTC 
(rev 208)
@@ -75,6 +75,7 @@
   GapWrapper * gw;
   unsigned int size;
   cron_t et;
+  cron_t now;
  
   ret = 0;
   if (OK == datastore->getRandom(&receiver->hashPubKey,
@@ -85,19 +86,23 @@
     size = sizeof(GapWrapper) + ntohl(content->size) - sizeof(Datastore_Value);
     gw = MALLOC(size);
     gw->dc.size = htonl(size);
-    gw->type = content->type;
     et = ntohll(content->expirationTime);
-    /* FIXME: mingle et? */
+    cronTime(&now);
+    if (et > now) {
+      et -= now;
+      et = et % MAX_MIGRATION_EXP;
+      et += now;
+    }
     gw->timeout = htonll(et);
     memcpy(&gw[1],
           &content[1],
           size - sizeof(GapWrapper));
     /* FIXME: check anonymity level,
        if 0, consider using DHT migration instead;
-       if high, consider traffic volume before migrating */
+       if high, consider traffic volume before 
+       migrating */
     FREE(content);
     ret = gap->tryMigrate(&gw->dc,
-                         ntohl(gw->type),
                          &key,
                          position,
                          padding);  

Modified: GNUnet/src/applications/fs/module/migration.h
===================================================================
--- GNUnet/src/applications/fs/module/migration.h       2005-02-07 21:36:40 UTC 
(rev 207)
+++ GNUnet/src/applications/fs/module/migration.h       2005-02-07 21:40:28 UTC 
(rev 208)
@@ -33,7 +33,52 @@
 #include "gnunet_dht_service.h"
 #include "gnunet_gap_service.h"
 
+
+
 /**
+ * What is the maximum expiration time for migrated content? 
+ *
+ * This is a non-trivial issue.  If we have a ceiling for migration
+ * time, it would violate anonymity if we send out content with an
+ * expiration time above that ceiling (since it would expose the
+ * content to originate from this peer).  But we want to store a
+ * higher expiration time for our content in the DB.
+ * 
+ * A first idea would be to pick a random time smaller than the limit
+ * for outgoing content; that does not _quite_ work since that could
+ * also expose us as the originator: only for our own content the
+ * expiration time would randomly go up and down.
+ * 
+ * The current best solution is to first bound the expiration time by
+ * this ceiling (for inbound and outbound ETs, not for the database
+ * entries locally) using modulo (to, in practice, get a constant
+ * bound for the local content just like for the migrated content).
+ * Then that number is randomized for _all_ outgoing content.  This
+ * way, the time left changes for all entries, but statistically
+ * always decreases on average as time progresses (also for all
+ * entries).
+ *
+ * Now, for local content eventually modulo will rebound to the MAX
+ * (whereas for migrated content it will hit 0 and disappear).  But
+ * that is OK: the adversary cannot distinguish the modulo wraparound
+ * from content migration (refresh with higher lifetime) which could
+ * plausibly happen from the original node (and in fact would happen
+ * around the same time!).  This design also achieves the design goal
+ * that if the original node disappears, the migrated content will
+ * eventually time-out (which is good since we don't want dangling
+ * search results to stay around).
+ *
+ * However, this does NOT mean that migrated content cannot live
+ * longer than 1 month -- remember, GNUnet peers discard expired
+ * content _if they run out of space_.  So it is perfectly plausible
+ * that content stays around longer.  Finally, clients (UI) may want
+ * to filter / rank / display search results with their current
+ * expiration to give the user some indication about availability.
+ * 
+ */
+#define MAX_MIGRATION_EXP (1L * cronMONTHS)
+
+/**
  * Initialize the migration module.
  */
 void initMigration(CoreAPIForApplication * capi,

Modified: GNUnet/src/applications/fs/module/querymanager.c
===================================================================
--- GNUnet/src/applications/fs/module/querymanager.c    2005-02-07 21:36:40 UTC 
(rev 207)
+++ GNUnet/src/applications/fs/module/querymanager.c    2005-02-07 21:40:28 UTC 
(rev 208)
@@ -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, 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
@@ -32,6 +32,7 @@
 
 typedef struct {
   HashCode160 query;
+  unsigned int type;
   ClientHandle client;
 } TrackRecord;
 
@@ -77,6 +78,7 @@
  * @param client where did the query come from?
  */
 void trackQuery(const HashCode160 * query,
+               unsigned int type,
                const ClientHandle client) {
   int i;
 
@@ -95,6 +97,7 @@
         trackerSize * 2);
   trackers[trackerCount] = MALLOC(sizeof(TrackRecord));
   trackers[trackerCount]->query = *query;
+  trackers[trackerCount]->type = type;
   trackers[trackerCount]->client = client;
   trackerCount++;
   MUTEX_UNLOCK(&queryManagerLock);
@@ -134,24 +137,24 @@
   ReplyContent * rc;
 
   MUTEX_LOCK(&queryManagerLock);
-  for (i=trackerCount-1;i>=0;i--)
-    if (equalsHashCode160(&trackers[i]->query,
-                         key)) {
+  for (i=trackerCount-1;i>=0;i--) {
+    if ( (equalsHashCode160(&trackers[i]->query,
+                           key)) &&
+        ( (trackers[i]->type == ANY_BLOCK) ||
+          (trackers[i]->type == ntohl(value->type)) ) ) {
       rc = MALLOC(sizeof(ReplyContent) + 
                  ntohl(value->size) - sizeof(Datastore_Value));
       rc->header.size = htons(sizeof(ReplyContent) + 
                              ntohl(value->size) - sizeof(Datastore_Value));
       rc->header.type = htons(AFS_CS_PROTO_RESULT);
-      rc->type = value->type;
       memcpy(&rc[1],
             &value[1],
             ntohl(value->size) - sizeof(Datastore_Value));
       coreAPI->sendToClient(trackers[i]->client,
                            &rc->header);
-      MUTEX_UNLOCK(&queryManagerLock);
       FREE(rc);
-      return;
     }
+  }
   MUTEX_UNLOCK(&queryManagerLock);
 }
  

Modified: GNUnet/src/applications/fs/module/querymanager.h
===================================================================
--- GNUnet/src/applications/fs/module/querymanager.h    2005-02-07 21:36:40 UTC 
(rev 207)
+++ GNUnet/src/applications/fs/module/querymanager.h    2005-02-07 21:40:28 UTC 
(rev 208)
@@ -46,6 +46,7 @@
  * @param client where did the query come from?
  */
 void trackQuery(const HashCode160 * query,
+               unsigned int type,
                const ClientHandle client);
 
 /**

Modified: GNUnet/src/applications/gap/TODO
===================================================================
--- GNUnet/src/applications/gap/TODO    2005-02-07 21:36:40 UTC (rev 207)
+++ GNUnet/src/applications/gap/TODO    2005-02-07 21:40:28 UTC (rev 208)
@@ -4,6 +4,3 @@
   except that this way we cannot reward
   peers for answering local queries!
   [ disables economy! ]
-* anonymityLevel is not used in gap
-* routing policy is not used in gap
-* why is forwardQuery dead code???

Modified: GNUnet/src/applications/gap/gap.c
===================================================================
--- GNUnet/src/applications/gap/gap.c   2005-02-07 21:36:40 UTC (rev 207)
+++ GNUnet/src/applications/gap/gap.c   2005-02-07 21:40:28 UTC (rev 208)
@@ -216,19 +216,10 @@
 typedef struct {
   p2p_HEADER header;   
 
-  unsigned int type;
-
   HashCode160 primaryKey;
 
 } GAP_REPLY;
 
-typedef struct {
-  GAP_REPLY gap_reply;
-
-  char data[1];
-
-} GAP_REPLY_GENERIC;
-
 /**
  * In this struct, we store information about a 
  * query that is being send from the local node to
@@ -323,6 +314,8 @@
    */
   unsigned int seenIndex; 
 
+  int seenReplyWasUnique; /* YES/NO, only valid if seenIndex == 1 */
+
   /**
    * Hashcodes of the encrypted (!) replies that we have forwarded so far
    */
@@ -427,6 +420,12 @@
 static Blockstore * bs;
 
 /**
+ * Function that can be used to identify unique
+ * replies.
+ */
+static UniqueReplyIdentifier uri;
+
+/**
  * The routing table. This table has entries for all
  * queries that we have recently send out. It helps 
  * GNUnet to route the replies back to the respective
@@ -958,7 +957,7 @@
 }
 
 /**
- * Queue a CHK reply with cron to simulate
+ * Queue a reply with cron to simulate
  * another peer returning the response with
  * some latency (and then route as usual).
  * 
@@ -1035,6 +1034,7 @@
     GROW(ite->seen,
         ite->seenIndex,
         0);
+    ite->seenReplyWasUnique = NO;
     if (equalsHashCode160(query,
                          &ite->primaryKey)) {
       ite->ttl = now + ttl;
@@ -1074,6 +1074,7 @@
   GROW(ite->seen,
        ite->seenIndex,
        0); 
+  ite->seenReplyWasUnique = NO;
   return OK;
 }
 
@@ -1148,6 +1149,7 @@
     GROW(ite->seen,
         ite->seenIndex,
         0);
+    ite->seenReplyWasUnique = NO;
     if ( equalsHashCode160(query,
                           &ite->primaryKey) &&
         (YES == ite-> successful_local_lookup_in_delay_loop) ) {
@@ -1207,13 +1209,13 @@
        more agressively */
 
     /* pending == new! */
-    if ( equalsHashCode160(&ite->primaryKey,
-                          &ite->seen[0])) { /* CHK/unique match only */
+    if (ite->seenReplyWasUnique) {
       if (ite->ttl < (cron_t)(now + ttl)) { /* ttl of new is longer? */
        /* go again */
        GROW(ite->seen,
             ite->seenIndex,
             0);
+       ite->seenReplyWasUnique = NO;
        addToSlot(ITE_REPLACE, ite, query, ttl, priority, sender);
        if (YES == ite->successful_local_lookup_in_delay_loop) {
          *isRouted = NO; 
@@ -1273,16 +1275,14 @@
     }
   } 
   /* a different query that is expired a bit longer is using
-     the slot; but if it is a CHK query that has received
-     a response already, we can eagerly throw it out 
+     the slot; but if it is a query that has received
+     a unique response already, we can eagerly throw it out 
      anyway, since the request has been satisfied 
      completely */
   if ( (ite->ttl + TTL_DECREMENT < (cron_t)(now + ttl) ) &&
        (ite->ttl < now) && 
-       (ite->seenIndex == 1) &&
-       (equalsHashCode160(&ite->primaryKey,
-                         &ite->seen[0])) ) {
-    /* is CHK and we have seen the answer, get rid of it early */
+       (ite->seenReplyWasUnique) ) {
+    /* we have seen the unique answer, get rid of it early */
     addToSlot(ITE_REPLACE, ite, query, ttl, priority, sender);
     *isRouted = YES;
     *doForward = YES;
@@ -1369,6 +1369,7 @@
 
   /* check seen */
   ite = &ROUTING_indTable_[computeRoutingIndex(primaryKey)];
+
   hash(&value[1],
        ntohl(value->size) - sizeof(DataContainer),
        &hc);
@@ -1387,7 +1388,10 @@
          primaryKey,
          value,
          ite->priority);
-  if (equalsHashCode160(&hc, primaryKey)) /* CHK? */
+  if (uri(&value[1],
+         ntohl(value->size) - sizeof(DataContainer),
+         ite->type,
+         &ite->primaryKey))
     cls->doForward = NO; /* we have the one and only answer,
                            do not bother to forward... */
   return OK;
@@ -1411,42 +1415,46 @@
  */
 static int execQuery(const PeerIdentity * sender,
                     unsigned int prio,
+                    QUERY_POLICY policy,
                     int ttl,
                     const GAP_QUERY * query) {
   IndirectionTableEntry * ite;
-  DataContainer * result;
   int isRouted;
   struct qLRC cls;
 
   ite = &ROUTING_indTable_[computeRoutingIndex(&query->queries[0])];
   MUTEX_LOCK(&ite->lookup_exclusion); 
   if (sender != NULL) {
-    needsForwarding(&query->queries[0],
-                   ttl,
-                   prio,
-                   sender,
-                   &isRouted,
-                   &cls.doForward); 
+    if ((policy & QUERY_INDIRECT) > 0) {
+      needsForwarding(&query->queries[0],
+                     ttl,
+                     prio,
+                     sender,
+                     &isRouted,
+                     &cls.doForward); 
+    } else {
+      isRouted = NO;
+      cls.doForward = YES;
+    }
   } else {
     isRouted = YES;
     cls.doForward = YES;
   }
+  if ( (policy & QUERY_FORWARD) == 0)
+    cls.doForward = NO;
+
   cls.sender = sender;
-  if (isRouted != YES) {
-    MUTEX_UNLOCK(&ite->lookup_exclusion);
-    return SYSERR; /* if we can't route, 
-                     forwarding never makes
-                     any sense */
+  if ( (isRouted == YES) && /* if we can't route, lookup useless! */
+       ( (policy & QUERY_ANSWER) > 0) ) {
+    bs->get(bs->closure,
+           ntohl(query->type),
+           prio,
+           1 + ( ntohs(query->header.size) 
+                 - sizeof(GAP_QUERY)) / sizeof(HashCode160),
+           &query->queries[0],
+           (DataProcessor) &queryLocalResultCallback,
+           &cls);
   }
-  result = NULL;
-  bs->get(bs->closure,
-         ntohl(query->type),
-         prio,
-         1 + ( ntohs(query->header.size) 
-               - sizeof(GAP_QUERY)) / sizeof(HashCode160),
-         &query->queries[0],
-         (DataProcessor) &queryLocalResultCallback,
-         &cls);
   MUTEX_UNLOCK(&ite->lookup_exclusion);
   if (cls.doForward)
     forwardQuery(query,
@@ -1506,9 +1514,11 @@
   hash(&msg[1],
        size,
        &contentHC);
-  if (equalsHashCode160(&ite->primaryKey,
-                       &contentHC)) {
-    /* CHK, unique reply, stop forwarding! */  
+  if (uri(&msg[1],
+         size,
+         ite->type,
+         &ite->primaryKey)) {
+    /* unique reply, stop forwarding! */  
     dequeueQuery(&ite->primaryKey);
   }
   /* remove the sender from the waiting list
@@ -1565,6 +1575,15 @@
         ite->seenIndex,
         ite->seenIndex+1);
     ite->seen[ite->seenIndex-1] = contentHC;
+    if (ite->seenIndex == 1) {
+      ite->seenReplyWasUnique 
+       = uri(&msg[1],
+             size,
+             ite->type,
+             &ite->primaryKey);
+    } else {
+      ite->seenReplyWasUnique = NO;
+    }
   }
   MUTEX_UNLOCK(&ite->lookup_exclusion);
   return OK;
@@ -1578,12 +1597,14 @@
  * @param datastore the storage callbacks to use for storing data
  * @return SYSERR on error, OK on success
  */
-static int init(Blockstore * datastore) {
+static int init(Blockstore * datastore,
+               UniqueReplyIdentifier uid) {
   if (bs != NULL) {
     BREAK();
     return SYSERR;
   }
   bs = datastore;
+  uri = uid;
   return OK;
 }
 
@@ -1673,6 +1694,7 @@
     = *coreAPI->myIdentity;
   ret = execQuery(NULL,
                  prio,
+                 QUERY_ANSWER|QUERY_FORWARD|QUERY_INDIRECT,
                  timeout - cronTime(NULL),
                  msg);
   FREE(msg);
@@ -1703,7 +1725,6 @@
  */
 static unsigned int
 tryMigrate(const DataContainer * data,
-          unsigned int type,
           const HashCode160 * primaryKey,
           char * position,
           unsigned int padding) {
@@ -1720,8 +1741,6 @@
     = htons(GAP_p2p_PROTO_RESULT);
   reply->header.size
     = htons(size);
-  reply->type 
-    = htonl(type);
   reply->primaryKey 
     = *primaryKey;
   memcpy(&reply[1],
@@ -1759,6 +1778,16 @@
   }
   qmsg = MALLOC(ntohs(msg->size));
   memcpy(qmsg, msg, ntohs(msg->size));
+  if (equalsHashCode160(&qmsg->returnTo.hashPubKey,
+                       &coreAPI->myIdentity->hashPubKey)) {
+    /* A to B, B sends back to A without (!) source rewriting,
+       in this case, A must just drop; however, this
+       should never happen. */
+    BREAK();
+    FREE(qmsg);
+    return OK;
+  }
+      
 
   /* decrement ttl (always) */
   ttl = ntohl(qmsg->ttl);
@@ -1778,8 +1807,16 @@
     FREE(qmsg);
     return OK; /* straight drop. */
   }
+  preference = (double) prio;
+  if ((policy & QUERY_INDIRECT) > 0) {
+    qmsg->returnTo 
+      = *coreAPI->myIdentity;
+  } else {
+    /* otherwise we preserve the original sender
+       and kill the priority (since we cannot benefit) */
+    prio = 0;
+  }
 
-  preference = (double) prio;
   if (preference < QUERY_BANDWIDTH_VALUE)
     preference = QUERY_BANDWIDTH_VALUE;
   coreAPI->preferTrafficFrom(sender,
@@ -1793,13 +1830,36 @@
   ttl = ntohl(qmsg->ttl);
   if (ttl < 0)
     ttl = 0;
-  execQuery(sender,
+  execQuery(sender,        
            prio,
+           policy,
            ttl,
            qmsg);
   FREE(qmsg);
   return OK;
 }
+
+static unsigned int getAvgPriority() {
+  IndirectionTableEntry * ite;
+  unsigned long long tot;
+  int i;
+  unsigned int active;
+
+  tot = 0;
+  active = 0;
+  for (i=indirectionTableSize-1;i>=0;i--) {
+    ite = &ROUTING_indTable_[i];
+    if ( (ite->hostsWaiting > 0) &&
+        (ite->seenIndex == 0) ) {
+      tot += ite->priority;
+      active++;
+    }
+  }
+  if (active == 0)
+    return 0;
+  else
+    return (unsigned int) (tot / active);
+}
  
 
 GAP_ServiceAPI * 
@@ -1862,6 +1922,7 @@
   api.get_start = &get_start;
   api.get_stop = &get_stop;
   api.tryMigrate = &tryMigrate;
+  api.getAvgPriority = &getAvgPriority;
   return &api;
 }
 
@@ -1886,6 +1947,7 @@
     GROW(ROUTING_indTable_[i].seen, 
         ROUTING_indTable_[i].seenIndex, 
         0);
+    ROUTING_indTable_[i].seenReplyWasUnique = NO;
     GROW(ROUTING_indTable_[i].destination, 
         ROUTING_indTable_[i].hostsWaiting,
         0);
@@ -1915,6 +1977,7 @@
   lock = NULL;
   coreAPI = NULL;
   bs = NULL;
+  uri = NULL;
 }
 
 /* end of gap.c */

Modified: GNUnet/src/include/fs.h
===================================================================
--- GNUnet/src/include/fs.h     2005-02-07 21:36:40 UTC (rev 207)
+++ GNUnet/src/include/fs.h     2005-02-07 21:40:28 UTC (rev 208)
@@ -74,12 +74,6 @@
 typedef struct {
   CS_HEADER header;
 
-  /**
-   * The type of the reply (may not always match
-   * the query!)
-   */
-  unsigned int type;  
-
 } ReplyContent;
 
 
@@ -196,12 +190,11 @@
 
 /**
  * Encapsulation of the data in the format that is passed through gap.
- * We essentially add the type and timeout value since that part is
- * supposed to be communicated to other peers.
+ * We essentially add the timeout value since that part is supposed to
+ * be communicated to other peers.
  */
 typedef struct {
   DataContainer dc;
-  unsigned int type;
   unsigned long long timeout;
 } GapWrapper;
 

Modified: GNUnet/src/include/gnunet_gap_service.h
===================================================================
--- GNUnet/src/include/gnunet_gap_service.h     2005-02-07 21:36:40 UTC (rev 
207)
+++ GNUnet/src/include/gnunet_gap_service.h     2005-02-07 21:40:28 UTC (rev 
208)
@@ -35,6 +35,16 @@
 #include "gnunet_blockstore.h"
 
 /**
+ * Function that helps the routing code to find out if
+ * a given reply is the one and only reply for a given
+ * request.
+ */
+typedef int (*UniqueReplyIdentifier)(const void * content,
+                                    unsigned int size,
+                                    unsigned int query_type,
+                                    const HashCode160 * primaryKey);
+
+/**
  * Functions of the GAP Service API.
  */
 typedef struct {
@@ -45,7 +55,8 @@
    * @param datastore the storage callbacks to use for storing data
    * @return SYSERR on error, OK on success
    */
-  int (*init)(Blockstore * datastore);
+  int (*init)(Blockstore * datastore,
+             UniqueReplyIdentifier uri);
   
   /**
    * Perform a GET operation using 'key' as the key.  Note that no
@@ -86,10 +97,15 @@
    *   that buffer (must be a positive number).
    */
   unsigned int (*tryMigrate)(const DataContainer * data,
-                            unsigned int type,
                             const HashCode160 * primaryKey,
                             char * position,
                             unsigned int padding);
+
+  /**
+   * What is the average priority of requests that we
+   * are currently routing?
+   */
+  unsigned int (*getAvgPriority)();
     
 } GAP_ServiceAPI;
 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]