gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r35118 - in gnunet/src: ats include util


From: gnunet
Subject: [GNUnet-SVN] r35118 - in gnunet/src: ats include util
Date: Fri, 6 Feb 2015 10:00:15 +0100

Author: grothoff
Date: 2015-02-06 10:00:14 +0100 (Fri, 06 Feb 2015)
New Revision: 35118

Modified:
   gnunet/src/ats/gnunet-service-ats_addresses.c
   gnunet/src/ats/gnunet-service-ats_performance.c
   gnunet/src/ats/gnunet-service-ats_reservations.c
   gnunet/src/ats/gnunet-service-ats_scheduling.c
   gnunet/src/ats/test_ats_api_performance_list_all_addresses.c
   gnunet/src/include/gnunet_ats_service.h
   gnunet/src/util/server_nc.c
Log:
-use only one nc per client

Modified: gnunet/src/ats/gnunet-service-ats_addresses.c
===================================================================
--- gnunet/src/ats/gnunet-service-ats_addresses.c       2015-02-06 08:35:41 UTC 
(rev 35117)
+++ gnunet/src/ats/gnunet-service-ats_addresses.c       2015-02-06 09:00:14 UTC 
(rev 35118)
@@ -215,12 +215,7 @@
  */
 struct GNUNET_CONTAINER_MultiPeerMap *GSA_addresses;
 
-/**
- * Context for sending messages to performance clients without PIC.
- */
-static struct GNUNET_SERVER_NotificationContext *nc;
 
-
 /**
  * Update statistic on number of addresses.
  */
@@ -698,7 +693,6 @@
 {
   GSA_addresses = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO);
   update_addresses_stat ();
-  nc = GNUNET_SERVER_notification_context_create (server, 32);
 }
 
 
@@ -749,8 +743,6 @@
   GAS_addresses_destroy_all ();
   GNUNET_CONTAINER_multipeermap_destroy (GSA_addresses);
   GSA_addresses = NULL;
-  GNUNET_SERVER_notification_context_destroy (nc);
-  nc = NULL;
 }
 
 
@@ -902,6 +894,7 @@
   char *addrp;
   size_t plugin_name_length;
   size_t msize;
+  struct GNUNET_SERVER_NotificationContext *nc;
 
   if (NULL != plugin_name)
     plugin_name_length = strlen (plugin_name) + 1;
@@ -937,6 +930,13 @@
     memcpy (addrp, plugin_addr, plugin_addr_len);
   if (NULL != plugin_name)
     strcpy (&addrp[plugin_addr_len], plugin_name);
+  nc = *GNUNET_SERVER_client_get_user_context (ai->client,
+                                               struct 
GNUNET_SERVER_NotificationContext *);
+  if (NULL == nc)
+  {
+    GNUNET_break (0);
+    return;
+  }
   GNUNET_SERVER_notification_context_unicast (nc,
                                               ai->client,
                                               &msg->header,
@@ -1021,8 +1021,6 @@
   const struct AddressListRequestMessage *alrm;
   struct GNUNET_PeerIdentity allzeros;
 
-  GNUNET_SERVER_notification_context_add (nc,
-                                          client);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Received ADDRESSLIST_REQUEST message\n");
   alrm = (const struct AddressListRequestMessage *) message;

Modified: gnunet/src/ats/gnunet-service-ats_performance.c
===================================================================
--- gnunet/src/ats/gnunet-service-ats_performance.c     2015-02-06 08:35:41 UTC 
(rev 35117)
+++ gnunet/src/ats/gnunet-service-ats_performance.c     2015-02-06 09:00:14 UTC 
(rev 35118)
@@ -33,7 +33,7 @@
 /**
  * Context for sending messages to performance clients without PIC.
  */
-static struct GNUNET_SERVER_NotificationContext *nc;
+static struct GNUNET_SERVER_NotificationContext *nc_no_pic;
 
 /**
  * Context for sending messages to performance clients with PIC.
@@ -79,6 +79,7 @@
       plugin_name_length;
   char buf[msize] GNUNET_ALIGN;
   struct GNUNET_ATS_Information *atsp;
+  struct GNUNET_SERVER_NotificationContext *nc;
   char *addrp;
 
   GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE);
@@ -109,6 +110,13 @@
   }
   else
   {
+    nc = *GNUNET_SERVER_client_get_user_context (client,
+                                                 struct 
GNUNET_SERVER_NotificationContext *);
+    if (NULL == nc)
+    {
+      GNUNET_break (0);
+      return;
+    }
     GNUNET_SERVER_notification_context_unicast (nc,
                                                 client,
                                                 &msg->header,
@@ -223,15 +231,19 @@
   {
     GNUNET_SERVER_notification_context_add (nc_pic,
                                             client);
-    GNUNET_SERVER_notification_context_add (nc,
-                                            client);
+    GNUNET_SERVER_client_set_user_context (client,
+                                           &nc_pic);
+    GAS_addresses_get_peer_info (NULL,
+                                 &peerinfo_it,
+                                 client);
   }
   else
-    GNUNET_SERVER_notification_context_add (nc,
+  {
+    GNUNET_SERVER_notification_context_add (nc_no_pic,
                                             client);
-  GAS_addresses_get_peer_info (NULL,
-                               &peerinfo_it,
-                               client);
+    GNUNET_SERVER_client_set_user_context (client,
+                                           &nc_no_pic);
+  }
 }
 
 
@@ -243,7 +255,7 @@
 void
 GAS_performance_init (struct GNUNET_SERVER_Handle *server)
 {
-  nc = GNUNET_SERVER_notification_context_create (server, 32);
+  nc_no_pic = GNUNET_SERVER_notification_context_create (server, 32);
   nc_pic = GNUNET_SERVER_notification_context_create (server, 32);
 }
 
@@ -254,8 +266,8 @@
 void
 GAS_performance_done ()
 {
-  GNUNET_SERVER_notification_context_destroy (nc);
-  nc = NULL;
+  GNUNET_SERVER_notification_context_destroy (nc_no_pic);
+  nc_no_pic = NULL;
   GNUNET_SERVER_notification_context_destroy (nc_pic);
   nc_pic = NULL;
 }

Modified: gnunet/src/ats/gnunet-service-ats_reservations.c
===================================================================
--- gnunet/src/ats/gnunet-service-ats_reservations.c    2015-02-06 08:35:41 UTC 
(rev 35117)
+++ gnunet/src/ats/gnunet-service-ats_reservations.c    2015-02-06 09:00:14 UTC 
(rev 35118)
@@ -39,12 +39,7 @@
  */
 static struct GNUNET_CONTAINER_MultiPeerMap *trackers;
 
-/**
- * Context for sending messages to performance clients without PIC.
- */
-static struct GNUNET_SERVER_NotificationContext *nc;
 
-
 /**
  * Reserve the given amount of incoming bandwidth (in bytes) from the
  * given peer.  If a reservation is not possible right now, return how
@@ -142,11 +137,17 @@
   struct ReservationResultMessage result;
   int32_t amount;
   struct GNUNET_TIME_Relative res_delay;
+  struct GNUNET_SERVER_NotificationContext *nc;
 
-  GNUNET_SERVER_notification_context_add (nc,
-                                          client);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Received RESERVATION_REQUEST message\n");
+  nc = *GNUNET_SERVER_client_get_user_context (client,
+                                               struct 
GNUNET_SERVER_NotificationContext *);
+  if (NULL == nc)
+  {
+    GNUNET_break (0);
+    return;
+  }
   amount = (int32_t) ntohl (msg->amount);
   res_delay = GAS_reservations_reserve (&msg->peer, amount);
   if (res_delay.rel_value_us > 0)
@@ -160,6 +161,7 @@
                             "# reservation requests processed",
                             1,
                             GNUNET_NO);
+
   GNUNET_SERVER_notification_context_unicast (nc,
                                               client,
                                               &result.header,
@@ -178,7 +180,6 @@
 GAS_reservations_init (struct GNUNET_SERVER_Handle *server)
 {
   trackers = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO);
-  nc = GNUNET_SERVER_notification_context_create (server, 128);
 }
 
 
@@ -211,9 +212,6 @@
                                          &free_tracker,
                                          NULL);
   GNUNET_CONTAINER_multipeermap_destroy (trackers);
-  GNUNET_SERVER_notification_context_destroy (nc);
-  nc = NULL;
-
 }
 
 /* end of gnunet-service-ats_reservations.c */

Modified: gnunet/src/ats/gnunet-service-ats_scheduling.c
===================================================================
--- gnunet/src/ats/gnunet-service-ats_scheduling.c      2015-02-06 08:35:41 UTC 
(rev 35117)
+++ gnunet/src/ats/gnunet-service-ats_scheduling.c      2015-02-06 09:00:14 UTC 
(rev 35118)
@@ -57,7 +57,10 @@
     return GNUNET_SYSERR;
   }
   my_client = client;
-  GNUNET_SERVER_notification_context_add (nc, client);
+  GNUNET_SERVER_notification_context_add (nc,
+                                          client);
+  GNUNET_SERVER_client_set_user_context (client,
+                                         &nc);
   return GNUNET_OK;
 }
 

Modified: gnunet/src/ats/test_ats_api_performance_list_all_addresses.c
===================================================================
--- gnunet/src/ats/test_ats_api_performance_list_all_addresses.c        
2015-02-06 08:35:41 UTC (rev 35117)
+++ gnunet/src/ats/test_ats_api_performance_list_all_addresses.c        
2015-02-06 09:00:14 UTC (rev 35118)
@@ -95,15 +95,16 @@
 
 static void
 ats_perf_cb (void *cls,
-            const struct GNUNET_HELLO_Address *address,
-            int address_active,
-            struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
-            struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
-            const struct GNUNET_ATS_Information *ats,
-            uint32_t ats_count)
+             const struct GNUNET_HELLO_Address *address,
+             int address_active,
+             struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
+             struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
+             const struct GNUNET_ATS_Information *ats,
+             uint32_t ats_count)
 {
   static int counter = 0;
 
+  fprintf (stderr, "HERE!\n");
   if (NULL == address)
   {
     phal = 0;
@@ -115,11 +116,11 @@
     else
     {
       GNUNET_break (0);
-      GNUNET_SCHEDULER_add_now (end_badly, NULL);
+      GNUNET_SCHEDULER_shutdown ();
     }
     return;
   }
-  counter ++;
+  counter++;
 }
 
 
@@ -129,23 +130,28 @@
         int is_persistent)
 {
 
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO, "ATS statistics: `%s' `%s' %llu\n",
-      subsystem,name, value);
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+              "ATS statistics: `%s' `%s' %llu\n",
+              subsystem,name, value);
   if (4 == value)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-        "All addresses added, connecting to performance\n");
+                "All addresses added, connecting to performance\n");
     if (NULL == (perf_ats = GNUNET_ATS_performance_init (cfg, NULL, NULL)))
     {
       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-          "Failed to connect to performance API\n");
+                  "Failed to connect to performance API\n");
       GNUNET_SCHEDULER_add_now (end_badly, NULL);
     }
-    phal = GNUNET_ATS_performance_list_addresses (perf_ats, NULL, GNUNET_YES, 
&ats_perf_cb, NULL);
+    phal = GNUNET_ATS_performance_list_addresses (perf_ats,
+                                                  NULL,
+                                                  GNUNET_YES,
+                                                  &ats_perf_cb, NULL);
   }
   return GNUNET_OK;
 }
 
+
 static void
 address_suggest_cb (void *cls,
                     const struct GNUNET_PeerIdentity *peer,
@@ -154,7 +160,8 @@
                     struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
                     struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
 {
-  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Did not expect suggestion 
callback!\n");
+  GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+              "Did not expect suggestion callback!\n");
   GNUNET_SCHEDULER_add_now (&end_badly, NULL);
 }
 
@@ -171,7 +178,8 @@
 static void
 end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
-  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Shutting down\n");
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+             "Shutting down\n");
   if (die_task != NULL )
   {
     GNUNET_SCHEDULER_cancel (die_task);
@@ -213,10 +221,10 @@
 }
 
 
-
 static void
-run (void *cls, const struct GNUNET_CONFIGURATION_Handle *mycfg,
-    struct GNUNET_TESTING_Peer *peer)
+run (void *cls,
+     const struct GNUNET_CONFIGURATION_Handle *mycfg,
+     struct GNUNET_TESTING_Peer *peer)
 {
   ret = 1;
   cfg = (struct GNUNET_CONFIGURATION_Handle *) mycfg;
@@ -271,11 +279,13 @@
   p1_ha[1].peer = p[1].id;
   p1_ha[1].transport_name = p1_addresses[1].plugin;
 
-  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Created peer 1: `%s'\n",
-      GNUNET_i2s (&p[1].id));
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+             "Created peer 1: `%s'\n",
+             GNUNET_i2s (&p[1].id));
 
   /* Add addresses */
-  sched_ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL );
+  sched_ats = GNUNET_ATS_scheduling_init (cfg,
+                                          &address_suggest_cb, NULL);
   if (sched_ats == NULL )
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not setup peer!\n");

Modified: gnunet/src/include/gnunet_ats_service.h
===================================================================
--- gnunet/src/include/gnunet_ats_service.h     2015-02-06 08:35:41 UTC (rev 
35117)
+++ gnunet/src/include/gnunet_ats_service.h     2015-02-06 09:00:14 UTC (rev 
35118)
@@ -638,7 +638,7 @@
  *
  * @param handle the performance handle to use
  * @param peer peer idm can be NULL for all peers
- * @param all GNUNET_YES to get information about all addresses or GNUNET_NO to
+ * @param all #GNUNET_YES to get information about all addresses or #GNUNET_NO 
to
  *        get only address currently used
  * @param infocb callback to call with the addresses,
  *        will callback with address == NULL when done
@@ -683,7 +683,7 @@
  */
 typedef void
 (*GNUNET_ATS_ReservationCallback) (void *cls,
-                                   const struct GNUNET_PeerIdentity * peer,
+                                   const struct GNUNET_PeerIdentity *peer,
                                    int32_t amount,
                                    struct GNUNET_TIME_Relative res_delay);
 
@@ -710,7 +710,7 @@
  */
 struct GNUNET_ATS_ReservationContext *
 GNUNET_ATS_reserve_bandwidth (struct GNUNET_ATS_PerformanceHandle *ph,
-                             const struct GNUNET_PeerIdentity *peer, 
+                             const struct GNUNET_PeerIdentity *peer,
                              int32_t amount,
                              GNUNET_ATS_ReservationCallback rcb,
                              void *rcb_cls);

Modified: gnunet/src/util/server_nc.c
===================================================================
--- gnunet/src/util/server_nc.c 2015-02-06 08:35:41 UTC (rev 35117)
+++ gnunet/src/util/server_nc.c 2015-02-06 09:00:14 UTC (rev 35118)
@@ -211,7 +211,9 @@
   ret = GNUNET_new (struct GNUNET_SERVER_NotificationContext);
   ret->server = server;
   ret->queue_length = queue_length;
-  GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, ret);
+  GNUNET_SERVER_disconnect_notify (server,
+                                   &handle_client_disconnect,
+                                   ret);
   return ret;
 }
 
@@ -234,7 +236,7 @@
                                 pos);
     if (NULL != pos->th)
     {
-      GNUNET_SERVER_notify_transmit_ready_cancel(pos->th);
+      GNUNET_SERVER_notify_transmit_ready_cancel (pos->th);
       pos->th = NULL;
     }
     GNUNET_SERVER_client_drop (pos->client);
@@ -307,7 +309,7 @@
   if (NULL == buf)
   {
     /* 'cl' should be freed via disconnect notification shortly */
-    LOG (GNUNET_ERROR_TYPE_DEBUG,
+    LOG (GNUNET_ERROR_TYPE_WARNING,
          "Failed to transmit message from NC queue to client\n");
     return 0;
   }




reply via email to

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