gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r3188 - in GNUnet: . src/applications/advertising


From: grothoff
Subject: [GNUnet-SVN] r3188 - in GNUnet: . src/applications/advertising
Date: Sun, 30 Jul 2006 20:20:46 -0700 (PDT)

Author: grothoff
Date: 2006-07-30 20:20:45 -0700 (Sun, 30 Jul 2006)
New Revision: 3188

Modified:
   GNUnet/src/applications/advertising/advertising.c
   GNUnet/src/applications/advertising/bootstrap.c
   GNUnet/src/applications/advertising/bootstrap.h
   GNUnet/todo
Log:
towards advertising'
'

Modified: GNUnet/src/applications/advertising/advertising.c
===================================================================
--- GNUnet/src/applications/advertising/advertising.c   2006-07-30 22:27:51 UTC 
(rev 3187)
+++ GNUnet/src/applications/advertising/advertising.c   2006-07-31 03:20:45 UTC 
(rev 3188)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2001, 2002, 2003, 2004, 2005 Christian Grothoff (and other 
contributing authors)
+     (C) 2001, 2002, 2003, 2004, 2005, 2006 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
@@ -125,12 +125,12 @@
  * @return SYSERR on error, OK on success
  */
 static int
-receivedhello(const P2P_MESSAGE_HEADER * message) {
+receivedhello(const MESSAGE_HEADER * message) {
   TSession * tsession;
   P2P_hello_MESSAGE * copy;
   PeerIdentity foreignId;
   P2P_hello_MESSAGE * msg;
-  P2P_MESSAGE_HEADER * ping;
+  MESSAGE_HEADER * ping;
   char * buffer;
   int heloEnd;
   int mtu;
@@ -150,7 +150,7 @@
                          P2P_hello_MESSAGE_size(msg)
                          - sizeof(Signature)
                          - sizeof(PublicKey)
-                         - sizeof(P2P_MESSAGE_HEADER),
+                         - sizeof(MESSAGE_HEADER),
                          &msg->signature,
                          &msg->publicKey)) {
     EncName enc;
@@ -442,7 +442,8 @@
   SendData sd;
   cron_t now;
 
-  if (getNetworkLoadUp() > 100)
+  if (os_network_monitor_get_load(coreAPI->load_monitor,
+                                 Upload) > 100)
     return; /* network load too high... */
   if (0 != weak_randomi(*prob))
     return; /* ignore */
@@ -490,9 +491,11 @@
 static void broadcasthello(void * unused) {
   unsigned int i;
 
-  if (getNetworkLoadUp() > 100)
+  if (os_network_monitor_get_load(coreAPI->load_monitor,
+                                 Upload) > 100)
     return; /* network load too high... */
-  if (getCPULoad() > 100)
+  if (os_cpu_get_load(coreAPI->ectx,
+                     coreAPI->cfg) > 100)
     return; /* CPU load too high... */
   i = transport->forEach(NULL,
                         NULL);
@@ -508,7 +511,8 @@
 
 static void forwardCallback(const PeerIdentity * peer,
                            FCC * fcc) {
-  if (getNetworkLoadUp() > 100)
+  if (os_network_monitor_get_load(coreAPI->monitor,
+                                 Upload) > 100)
     return; /* network load too high... */
   if (weak_randomi(fcc->prob) != 0)
     return; /* only forward with a certain chance */
@@ -538,7 +542,8 @@
   int count;
   FCC fcc;
 
-  if (getNetworkLoadUp() > 100)
+  if (os_network_monitor_get_load(coreAPI->load_monitor,
+                                 Upload) > 100)
     return; /* network load too high... */
   if (confirmed == NO)
     return;
@@ -597,9 +602,11 @@
 forwardhello(void * unused) {
   int count;
 
-  if (getCPULoad() > 100)
+  if (os_cpu_get_load(coreAPI->ectx,
+                     coreAPI->cfg) > 100)
     return; /* CPU load too high... */
-  if (getNetworkLoadUp() > 100)
+  if (os_network_monitor_get_load(coreAPI->load_monitor,
+                                 Upload) > 100)
     return; /* network load too high... */
 #if DEBUG_ADVERTISING
   LOG(LOG_CRON,
@@ -624,7 +631,7 @@
  */
 static int
 ehelloHandler(const PeerIdentity * sender,
-            const P2P_MESSAGE_HEADER * message) {
+             const MESSAGE_HEADER * message) {
   if (OK == receivedhello(message)) {
     /* if the hello was ok, update traffic preference
        for the peer (depending on how much we like
@@ -640,7 +647,7 @@
  */
 static int
 phelloHandler(const PeerIdentity * sender,
-            const P2P_MESSAGE_HEADER * message,
+             const MESSAGE_HEADER * message,
             TSession * session) {
   receivedhello(message);
   return OK;
@@ -657,36 +664,40 @@
     if (testConfigurationString("NETWORK",
                                "DISABLE-ADVERTISEMENTS",
                                "YES"))
-      delCronJob(&broadcasthello,
-                HELLO_BROADCAST_FREQUENCY,
-                NULL);
+      cron_del_job(coreAPI->cron,
+                  &broadcasthello,
+                  HELLO_BROADCAST_FREQUENCY,
+                  NULL);
     activeCronJobs -= ACJ_ANNOUNCE;
   } else {
     if (testConfigurationString("NETWORK",
                                "HELLOEXCHANGE",
                                "YES"))
-      addCronJob(&broadcasthello,
-                15 * cronSECONDS,
-                HELLO_BROADCAST_FREQUENCY,
-                NULL);
+      cron_add_job(coreAPI->cron,
+                  &broadcasthello,
+                  15 * cronSECONDS,
+                  HELLO_BROADCAST_FREQUENCY,
+                  NULL);
     activeCronJobs += ACJ_ANNOUNCE;
   }
   if (ACJ_FORWARD == (activeCronJobs & ACJ_FORWARD)) {
     if (! testConfigurationString("NETWORK",
                                  "HELLOEXCHANGE",
                                  "YES"))
-      delCronJob(&forwardhello,
-                HELLO_FORWARD_FREQUENCY,
-                NULL); /* seven minutes: exchange */
+      cron_del_job(coreAPI->cron,
+                  &forwardhello,
+                  HELLO_FORWARD_FREQUENCY,
+                  NULL); /* seven minutes: exchange */
     activeCronJobs -= ACJ_FORWARD;
   } else {
     if (! testConfigurationString("NETWORK",
                                  "DISABLE-ADVERTISEMENTS",
                                  "YES"))
-      addCronJob(&broadcasthello,
-                15 * cronSECONDS,
-                HELLO_BROADCAST_FREQUENCY,
-                NULL);
+      cron_add_job(coreAPI->cron,
+                  &broadcasthello,
+                  15 * cronSECONDS,
+                  HELLO_BROADCAST_FREQUENCY,
+                  NULL);
     activeCronJobs += ACJ_FORWARD;
   }
 }

Modified: GNUnet/src/applications/advertising/bootstrap.c
===================================================================
--- GNUnet/src/applications/advertising/bootstrap.c     2006-07-30 22:27:51 UTC 
(rev 3187)
+++ GNUnet/src/applications/advertising/bootstrap.c     2006-07-31 03:20:45 UTC 
(rev 3188)
@@ -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, 2006 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
@@ -29,6 +29,7 @@
 #include "gnunet_util.h"
 #include "gnunet_protocols.h"
 #include "gnunet_bootstrap_service.h"
+#include "gnunet_state_service.h"
 
 #define DEBUG_BOOTSTRAP NO
 
@@ -38,8 +39,10 @@
 
 static Bootstrap_ServiceAPI * bootstrap;
 
-static PTHREAD_T pt;
+static State_ServiceAPI * state;
 
+static struct PTHREAD * pt;
+
 static int abort_bootstrap = YES;
 
 typedef struct {
@@ -54,7 +57,7 @@
   P2P_hello_MESSAGE * msg;
 
   if (NULL == hcq) {
-    BREAK();
+    GE_BREAK(coreAPI->ectx, 0);
     return;
   }
   while ( (abort_bootstrap == NO) &&
@@ -85,19 +88,22 @@
       /* wait a bit */
       unsigned int load;
       int nload;
-      load = getCPULoad();
+      load = os_cpu_get_load(coreAPI->ectx,
+                            coreAPI->cfg);
       if (load == (unsigned int)-1)
        load = 50; 
-      nload = getNetworkLoadUp();
+      nload = os_network_monitor_get_load(coreAPI->load_monitor,
+                                         Upload);
       if (nload > load)
        load = nload;
-      nload = getNetworkLoadDown();
+      nload = os_network_monitor_get_load(coreAPI->load_monitor,
+                                         Download);
       if (nload > load)
        load = nload;
       if (load > 100)
        load = 100;
 
-      gnunet_util_sleep(50 + weak_randomi((load+1)*(load+1)));
+      PTHREAD_SLEEP(50 + weak_randomi((load+1)*(load+1)));
     }
   }
   for (i=0;i<hcq->helosCount;i++)
@@ -128,7 +134,7 @@
   cron_t now;
   char * data;
 
-  cronTime(&now);
+  now = get_time();
   if (coreAPI->forAllConnectedNodes(NULL, NULL) > 4) {
     /* still change delta and lastTest; even
        if the peer _briefly_ drops below 4
@@ -140,17 +146,19 @@
   }
   if (lastTest == 0) {
     /* first run in this process */
-    if (-1 != stateReadContent(BOOTSTRAP_INFO,
-                              (void**)&data)) {
-      /* but not first on this machine */
-      lastTest = cronTime(&now);
+    if (-1 != state->read(coreAPI->ectx,
+                         BOOTSTRAP_INFO,
+                         (void**)&data)) {
+      /* but not first on this machine */      
+      lastTest = now;
       delta = 2 * cronMINUTES; /* wait 2 minutes */
       FREE(data);
     } else {
       /* first on this machine, too! */
-      stateWriteContent(BOOTSTRAP_INFO,
-                       1,
-                       "X");
+      state->write(coreAPI->ectx,
+                  BOOTSTRAP_INFO,
+                  1,
+                  "X");
       delta = 60 * cronSECONDS;
     }
   }
@@ -174,7 +182,7 @@
   cls.helos = NULL;
   while (abort_bootstrap == NO) {
     while (abort_bootstrap == NO) {
-      gnunet_util_sleep(2 * cronSECONDS);
+      PTHREAD_SLEEP(2 * cronSECONDS);
       if (needBootstrap())
        break;
     }
@@ -202,13 +210,18 @@
  */
 void startBootstrap(CoreAPIForApplication * capi) {
   coreAPI = capi;
+  state = capi->requestService("state");
+  GE_ASSERT(capi->ectx,
+           state != NULL); 
   bootstrap = capi->requestService("bootstrap");
-  GNUNET_ASSERT(bootstrap != NULL);
+  GE_ASSERT(capi->ectx,
+           bootstrap != NULL);
   abort_bootstrap = NO;
-  GNUNET_ASSERT(0 == PTHREAD_CREATE(&pt,
-                                   &processThread,
-                                   NULL,
-                                   8 * 1024)); 
+  pt = PTHREAD_CREATE(&processThread,
+                     NULL,
+                     8 * 1024);
+  GE_ASSERT(capi->ectx,
+           pt != NULL);
 }
 
 /**
@@ -218,10 +231,13 @@
   void * unused;
 
   abort_bootstrap = YES;
-  PTHREAD_KILL(&pt, SIGALRM);
-  PTHREAD_JOIN(&pt, &unused);
+  PTHREAD_STOP_SLEEP(pt);
+  PTHREAD_JOIN(pt, &unused);
+  pt = NULL;
   coreAPI->releaseService(bootstrap);
   bootstrap = NULL;
+  coreAPI->releaseService(state);
+  state = NULL;
   coreAPI = NULL;
 }
 

Modified: GNUnet/src/applications/advertising/bootstrap.h
===================================================================
--- GNUnet/src/applications/advertising/bootstrap.h     2006-07-30 22:27:51 UTC 
(rev 3187)
+++ GNUnet/src/applications/advertising/bootstrap.h     2006-07-31 03:20:45 UTC 
(rev 3188)
@@ -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, 2006 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
@@ -39,7 +39,7 @@
 /**
  * Stop the bootstap service.
  */
-void stopBootstrap();
+void stopBootstrap(void);
 
 
 #endif

Modified: GNUnet/todo
===================================================================
--- GNUnet/todo 2006-07-30 22:27:51 UTC (rev 3187)
+++ GNUnet/todo 2006-07-31 03:20:45 UTC (rev 3188)
@@ -27,8 +27,8 @@
   * applications:
     + fragmentation, identity,  pingpong, session, transport,
       stats, topology_default, state, getoption compile
-    + for basics: advertising, bootstrap_http, traffic
-    + for fs: datastore, fs, gap, sqstore_sqlite
+    + for basics: advertising (1000), bootstrap_http (370), traffic (720)
+    + for fs: datastore (787), fs (18500), gap (2800), sqstore_sqlite (1375)
     + rest: sqstore_mysql, dht, chat, kvstore_sqlite, 
             sqstore_mysql, rpc, tbench, template, testbed, 
             topology_f2f, vpn, tracekit





reply via email to

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