gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r3266 - in GNUnet: . src/applications/topology_f2f


From: grothoff
Subject: [GNUnet-SVN] r3266 - in GNUnet: . src/applications/topology_f2f
Date: Sun, 20 Aug 2006 12:40:49 -0700 (PDT)

Author: grothoff
Date: 2006-08-20 12:40:43 -0700 (Sun, 20 Aug 2006)
New Revision: 3266

Modified:
   GNUnet/src/applications/topology_f2f/topology.c
   GNUnet/todo
Log:
fixing f2f

Modified: GNUnet/src/applications/topology_f2f/topology.c
===================================================================
--- GNUnet/src/applications/topology_f2f/topology.c     2006-08-20 19:27:59 UTC 
(rev 3265)
+++ GNUnet/src/applications/topology_f2f/topology.c     2006-08-20 19:40:43 UTC 
(rev 3266)
@@ -32,6 +32,7 @@
 
 #include "platform.h"
 #include "gnunet_core.h"
+#include "gnunet_directories.h"
 #include "gnunet_protocols.h"
 #include "gnunet_topology_service.h"
 #include "gnunet_identity_service.h"
@@ -74,6 +75,8 @@
 
 static Pingpong_ServiceAPI * pingpong;
 
+static struct GE_Context * ectx;
+
 /**
  * How many peers are we connected to in relation
  * to our ideal number?  (ideal = 1.0, too few: < 1,
@@ -99,7 +102,9 @@
   int i;
 
   for (i=friendCount-1;i>=0;i--)
-    if (hostIdentityEquals(&friends[i], peer))
+    if (0 == memcmp(&friends[i], 
+                   peer,
+                   sizeof(PeerIdentity)))
       return OK;
   return SYSERR;
 }
@@ -117,7 +122,9 @@
                            const unsigned short proto, 
                            int confirmed,
                            IndexMatch * im) {
-  if (hostIdentityEquals(coreAPI->myIdentity, id))
+  if (0 == memcmp(coreAPI->myIdentity,
+                 id,
+                 sizeof(PeerIdentity)))
     return;
   if (coreAPI->computeIndex(id) != im->index)
     return;
@@ -140,7 +147,9 @@
                             const unsigned short proto,
                             int confirmed,
                             IndexMatch * im) {
-  if (hostIdentityEquals(coreAPI->myIdentity, id))
+  if (0 == memcmp(coreAPI->myIdentity, 
+                 id,
+                 sizeof(PeerIdentity)))
     return;
   if (coreAPI->computeIndex(id) != im->index)
     return;
@@ -182,8 +191,9 @@
   identity->forEachHost(now,
                        (HostIterator)&scanHelperSelect,
                        &indexMatch);
-  if (hostIdentityEquals(coreAPI->myIdentity,
-                        &indexMatch.match)) {
+  if (0 == memcmp(coreAPI->myIdentity,
+                 &indexMatch.match,
+                 sizeof(PeerIdentity))) {
     GE_BREAK(ectx, 0); /* should not happen, at least not often... */
     return;
   }
@@ -193,9 +203,10 @@
   }
   hash2enc(&indexMatch.match.hashPubKey,
           &enc);
-  GE_LOG(ectx, GE_DEBUG | GE_REQUEST | GE_USER,
-      "Topology: trying to connect to `%s'.\n",
-      &enc);
+  GE_LOG(ectx, 
+        GE_DEBUG | GE_REQUEST | GE_USER,
+        "Topology: trying to connect to `%s'.\n",
+        &enc);
   coreAPI->unicast(&indexMatch.match,
                   NULL,
                   0,
@@ -304,8 +315,11 @@
   return saturation;
 }
 
-static int rereadConfiguration() {
-  char * tmp;
+static int rereadConfiguration(void * ctx,
+                              struct GC_Configuration * cfg, 
+                              struct GE_Context * ectx,
+                              const char * section,
+                              const char * option) {
   char * fn;
   char * data;
   unsigned long long size;
@@ -313,34 +327,32 @@
   EncName enc;
   HashCode512 hc;
 
+  if (0 != strcmp(section, "F2F"))
+    return OK;
   GROW(friends,
        friendCount,
        0);
-  tmp = getConfigurationString("F2F",
-                              "FRIENDS");
-  if (tmp == NULL) {
-    GE_LOG(ectx, GE_ERROR | GE_BULK | GE_USER,
-       _("Need to have list of friends in configuration under `%s' in section 
`%s'.\n"),
-       "FRIENDS",
-       "F2F");
-    return SYSERR;
-  }
-  fn = expandFileName(tmp);
-  FREE(tmp);
-  if (0 == assertIsFile(fn)) {
+  fn = NULL;
+  GC_get_configuration_value_filename(cfg,
+                                     "F2F",
+                                     "FRIENDS",
+                                     VAR_DAEMON_DIRECTORY "/friends",
+                                     &fn);
+  if ( (0 == disk_file_test(ectx, fn)) ||
+       (OK != disk_file_size(ectx, fn, &size, YES)) ) {
+    GE_LOG(ectx,
+          GE_USER | GE_ADMIN | GE_ERROR | GE_IMMEDIATE,
+          "Could not read friends list `%s'\n",
+          fn);
     FREE(fn);
     return SYSERR;
   }
-  if (OK != getFileSize(fn,
-                       &size)) {
-    FREE(fn);
-    return SYSERR;
-  }
   data = MALLOC(size);
-  if (size != readFile(fn, size, data)) {
-    GE_LOG(ectx, GE_ERROR | GE_BULK | GE_USER,
-       _("Failed to read friends list from `%s'\n"),
-       fn);
+  if (size != disk_file_read(ectx, fn, size, data)) {
+    GE_LOG(ectx,
+          GE_ERROR | GE_BULK | GE_USER,
+          _("Failed to read friends list from `%s'\n"),
+          fn);
     FREE(fn);
     return SYSERR;
   }
@@ -354,8 +366,9 @@
           &data[pos],
           sizeof(EncName));
     if (! isspace(enc.encoding[sizeof(EncName)-1])) {
-      GE_LOG(ectx, GE_WARNING | GE_BULK | GE_USER,
-         _("Syntax error in topology specification, skipping bytes.\n"));
+      GE_LOG(ectx,
+            GE_WARNING | GE_BULK | GE_USER,
+            _("Syntax error in topology specification, skipping bytes.\n"));
       continue;
     }
     enc.encoding[sizeof(EncName)-1] = '\0';
@@ -366,9 +379,10 @@
           friendCount+1);
       friends[friendCount-1].hashPubKey = hc;
     } else {
-      GE_LOG(ectx, GE_WARNING | GE_BULK | GE_USER,
-         _("Syntax error in topology specification, skipping bytes `%s'.\n"),
-         &enc);
+      GE_LOG(ectx, 
+            GE_WARNING | GE_BULK | GE_USER,
+            _("Syntax error in topology specification, skipping bytes 
`%s'.\n"),
+            &enc);
     }
     pos = pos + sizeof(EncName);
     while ( (pos < size) &&
@@ -381,8 +395,9 @@
 Topology_ServiceAPI *
 provide_module_topology_f2f(CoreAPIForApplication * capi) {
   static Topology_ServiceAPI api;
-
+ 
   coreAPI = capi;
+  ectx = capi->ectx;
   identity = capi->requestService("identity");
   if (identity == NULL) {
     GE_BREAK(ectx, 0);
@@ -404,8 +419,9 @@
     transport = NULL;
     return NULL;
   }
-
-  if (SYSERR == rereadConfiguration()) {
+  if (0 != GC_attach_change_listener(coreAPI->cfg,
+                                    &rereadConfiguration,
+                                    NULL)) {
     capi->releaseService(identity);
     identity = NULL;
     capi->releaseService(transport);
@@ -414,12 +430,12 @@
     pingpong = NULL;
     return NULL;
   }
-  registerConfigurationUpdateCallback
-    ((NotifyConfigurationUpdateCallback)&rereadConfiguration);
-  addCronJob(&cronCheckLiveness,
-            LIVE_SCAN_FREQUENCY,
-            LIVE_SCAN_FREQUENCY,
-            NULL);
+  
+  cron_add_job(coreAPI->cron,
+              &cronCheckLiveness,
+              LIVE_SCAN_FREQUENCY,
+              LIVE_SCAN_FREQUENCY,
+              NULL);
   api.estimateNetworkSize = &estimateNetworkSize;
   api.getSaturation = &estimateSaturation;
   api.allowConnectionFrom = &allowConnection;
@@ -427,11 +443,13 @@
 }
 
 int release_module_topology_f2f() {
-  delCronJob(&cronCheckLiveness,
-            LIVE_SCAN_FREQUENCY,
-            NULL);
-  unregisterConfigurationUpdateCallback
-    ((NotifyConfigurationUpdateCallback)&rereadConfiguration);
+  cron_del_job(coreAPI->cron,
+              &cronCheckLiveness,
+              LIVE_SCAN_FREQUENCY,
+              NULL);
+  GC_detach_change_listener(coreAPI->cfg,
+                           &rereadConfiguration,
+                           NULL);
   coreAPI->releaseService(identity);
   identity = NULL;
   coreAPI->releaseService(transport);

Modified: GNUnet/todo
===================================================================
--- GNUnet/todo 2006-08-20 19:27:59 UTC (rev 3265)
+++ GNUnet/todo 2006-08-20 19:40:43 UTC (rev 3266)
@@ -29,10 +29,10 @@
       traffic, ecrs_core, template, tbench, tracekit, fs/fslib,
       fs/module, gap, fs/ecrs, fs/uritrack, fs/namespace,
       fs/fsui, fs/collection, fs/tools, bootstrap_http,
-      sqstore_mysql compile
+      sqstore_mysql, topology_f2f compile
     + fs/fsui, fs/collection, fs/uritrack, fs/namespace
       must still be revised to match new API!
-    + rest: sqstore_mysql, dht, rpc, topology_f2f, vpn
+    + rest: dht, rpc, vpn
     + low priority: chat, kvstore_sqlite, testbed
   * setup:
     + main binary compiles, plugins are missing





reply via email to

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