gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r36189 - in gnunet/src: core include transport util


From: gnunet
Subject: [GNUnet-SVN] r36189 - in gnunet/src: core include transport util
Date: Mon, 3 Aug 2015 13:34:36 +0200

Author: grothoff
Date: 2015-08-03 13:34:36 +0200 (Mon, 03 Aug 2015)
New Revision: 36189

Modified:
   gnunet/src/core/gnunet-service-core_neighbours.c
   gnunet/src/include/gnunet_container_lib.h
   gnunet/src/transport/transport_api.c
   gnunet/src/util/bandwidth.c
Log:
-improve indentation, reduce duplication of PIDs in core's neighbour map

Modified: gnunet/src/core/gnunet-service-core_neighbours.c
===================================================================
--- gnunet/src/core/gnunet-service-core_neighbours.c    2015-08-03 11:14:51 UTC 
(rev 36188)
+++ gnunet/src/core/gnunet-service-core_neighbours.c    2015-08-03 11:34:36 UTC 
(rev 36189)
@@ -141,7 +141,8 @@
 {
   if (NULL == neighbours)
     return NULL;
-  return GNUNET_CONTAINER_multipeermap_get (neighbours, peer);
+  return GNUNET_CONTAINER_multipeermap_get (neighbours,
+                                            peer);
 }
 
 
@@ -218,7 +219,9 @@
  * @return number of bytes transmitted
  */
 static size_t
-transmit_ready (void *cls, size_t size, void *buf)
+transmit_ready (void *cls,
+                size_t size,
+                void *buf)
 {
   struct Neighbour *n = cls;
   struct NeighbourMessageEntry *m;
@@ -249,13 +252,16 @@
   }
   cbuf = buf;
   GNUNET_assert (size >= m->size);
-  memcpy (cbuf, &m[1], m->size);
+  memcpy (cbuf,
+          &m[1],
+          m->size);
   ret = m->size;
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Copied message of type %u and size %u into transport buffer for 
`%4s'\n",
               (unsigned int)
               ntohs (((struct GNUNET_MessageHeader *) &m[1])->type),
-              (unsigned int) ret, GNUNET_i2s (&n->peer));
+              (unsigned int) ret,
+              GNUNET_i2s (&n->peer));
   GNUNET_free (m);
   n->has_excess_bandwidth = GNUNET_NO;
   process_queue (n);
@@ -336,7 +342,7 @@
     return;
   }
   n = find_neighbour (peer);
-  if (n != NULL)
+  if (NULL != n)
   {
     /* duplicate connect notification!? */
     GNUNET_break (0);
@@ -343,13 +349,14 @@
     return;
   }
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Received connection from `%4s'.\n",
+              "Received connection from `%s'.\n",
               GNUNET_i2s (peer));
   n = GNUNET_new (struct Neighbour);
   n->peer = *peer;
   GNUNET_assert (GNUNET_OK ==
                  GNUNET_CONTAINER_multipeermap_put (neighbours,
-                                                    &n->peer, n,
+                                                    &n->peer,
+                                                    n,
                                                     
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
   GNUNET_STATISTICS_set (GSC_stats,
                          gettext_noop ("# neighbour entries allocated"),
@@ -373,7 +380,7 @@
   struct Neighbour *n;
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Peer `%4s' disconnected from us; received notification from 
transport.\n",
+              "Peer `%s' disconnected from us; received notification from 
transport.\n",
               GNUNET_i2s (peer));
   n = find_neighbour (peer);
   if (NULL == n)
@@ -401,15 +408,18 @@
   uint16_t type;
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Received message of type %u from `%4s', demultiplexing.\n",
-              (unsigned int) ntohs (message->type), GNUNET_i2s (peer));
-  if (0 == memcmp (peer, &GSC_my_identity, sizeof (struct 
GNUNET_PeerIdentity)))
+              "Received message of type %u from `%s', demultiplexing.\n",
+              (unsigned int) ntohs (message->type),
+              GNUNET_i2s (peer));
+  if (0 == memcmp (peer,
+                   &GSC_my_identity,
+                   sizeof (struct GNUNET_PeerIdentity)))
   {
     GNUNET_break (0);
     return;
   }
   n = find_neighbour (peer);
-  if (n == NULL)
+  if (NULL == n)
   {
     /* received message from peer that is not connected!? */
     GNUNET_break (0);
@@ -556,9 +566,12 @@
 int
 GSC_NEIGHBOURS_init ()
 {
-  neighbours = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO);
+  neighbours = GNUNET_CONTAINER_multipeermap_create (128,
+                                                     GNUNET_YES);
   transport =
-      GNUNET_TRANSPORT_connect2 (GSC_cfg, &GSC_my_identity, NULL,
+      GNUNET_TRANSPORT_connect2 (GSC_cfg,
+                                 &GSC_my_identity,
+                                 NULL,
                                  &handle_transport_receive,
                                  &handle_transport_notify_connect,
                                  &handle_transport_notify_disconnect,
@@ -574,7 +587,7 @@
 
 
 /**
- * Wrapper around 'free_neighbour'.
+ * Wrapper around #free_neighbour().
  *
  * @param cls unused
  * @param key peer identity

Modified: gnunet/src/include/gnunet_container_lib.h
===================================================================
--- gnunet/src/include/gnunet_container_lib.h   2015-08-03 11:14:51 UTC (rev 
36188)
+++ gnunet/src/include/gnunet_container_lib.h   2015-08-03 11:34:36 UTC (rev 
36189)
@@ -986,7 +986,12 @@
                                      void *value);
 
 
+/**
+ * Hash map from peer identities to values.
+ */
 struct GNUNET_CONTAINER_MultiPeerMap;
+
+
 /**
  * @ingroup hashmap
  * Create a multi peer map (hash map for public keys of peers).

Modified: gnunet/src/transport/transport_api.c
===================================================================
--- gnunet/src/transport/transport_api.c        2015-08-03 11:14:51 UTC (rev 
36188)
+++ gnunet/src/transport/transport_api.c        2015-08-03 11:34:36 UTC (rev 
36189)
@@ -414,7 +414,7 @@
 
   /**
    * Hash map of the current connected neighbours of this peer.
-   * Maps peer identities to 'struct Neighbour' entries.
+   * Maps peer identities to `struct Neighbour` entries.
    */
   struct GNUNET_CONTAINER_MultiPeerMap *neighbours;
 
@@ -493,7 +493,8 @@
 neighbour_find (struct GNUNET_TRANSPORT_Handle *h,
                 const struct GNUNET_PeerIdentity *peer)
 {
-  return GNUNET_CONTAINER_multipeermap_get (h->neighbours, peer);
+  return GNUNET_CONTAINER_multipeermap_get (h->neighbours,
+                                            peer);
 }
 
 
@@ -561,7 +562,8 @@
   n->is_ready = GNUNET_YES;
   n->traffic_overhead = 0;
   GNUNET_BANDWIDTH_tracker_init2 (&n->out_tracker,
-                                  &outbound_bw_tracker_update, n,
+                                  &outbound_bw_tracker_update,
+                                  n,
                                   GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT,
                                   MAX_BANDWIDTH_CARRY_S,
                                   &notify_excess_cb,
@@ -568,7 +570,8 @@
                                   n);
   GNUNET_assert (GNUNET_OK ==
                  GNUNET_CONTAINER_multipeermap_put (h->neighbours,
-                                                    &n->id, n,
+                                                    &n->id,
+                                                    n,
                                                     
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
   return n;
 }
@@ -586,19 +589,22 @@
  */
 static int
 neighbour_delete (void *cls,
-                 const struct GNUNET_PeerIdentity *key, void *value)
+                 const struct GNUNET_PeerIdentity *key,
+                  void *value)
 {
   struct GNUNET_TRANSPORT_Handle *handle = cls;
   struct Neighbour *n = value;
 
+  GNUNET_BANDWIDTH_tracker_notification_stop (&n->out_tracker);
   if (NULL != handle->nd_cb)
-    handle->nd_cb (handle->cls, &n->id);
+    handle->nd_cb (handle->cls,
+                   &n->id);
   GNUNET_assert (NULL == n->th);
   GNUNET_assert (NULL == n->hn);
   GNUNET_assert (GNUNET_YES ==
-                 GNUNET_CONTAINER_multipeermap_remove (handle->neighbours, key,
+                 GNUNET_CONTAINER_multipeermap_remove (handle->neighbours,
+                                                       key,
                                                        n));
-  GNUNET_BANDWIDTH_tracker_notification_stop (&n->out_tracker);
   GNUNET_free (n);
   return GNUNET_YES;
 }
@@ -642,7 +648,9 @@
     disconnect_and_schedule_reconnect (h);
     return;
   }
-  GNUNET_CLIENT_receive (h->client, &demultiplexer, h,
+  GNUNET_CLIENT_receive (h->client,
+                         &demultiplexer,
+                         h,
                          GNUNET_TIME_UNIT_FOREVER_REL);
   size = ntohs (msg->size);
   switch (ntohs (msg->type))
@@ -649,7 +657,8 @@
   {
   case GNUNET_MESSAGE_TYPE_HELLO:
     if (GNUNET_OK !=
-        GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) msg, &me))
+        GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) msg,
+                             &me))
     {
       GNUNET_break (0);
       break;
@@ -697,7 +706,8 @@
       GNUNET_break (0);
       break;
     }
-    n = neighbour_add (h, &cim->id);
+    n = neighbour_add (h,
+                       &cim->id);
     LOG (GNUNET_ERROR_TYPE_DEBUG,
          "Receiving CONNECT message for `%4s' with quota %u\n",
          GNUNET_i2s (&cim->id),
@@ -704,8 +714,9 @@
          ntohl (cim->quota_out.value__));
     GNUNET_BANDWIDTH_tracker_update_quota (&n->out_tracker,
                                            cim->quota_out);
-    if (h->nc_cb != NULL)
-      h->nc_cb (h->cls, &n->id);
+    if (NULL != h->nc_cb)
+      h->nc_cb (h->cls,
+                &n->id);
     break;
   case GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT:
     if (size != sizeof (struct DisconnectInfoMessage))
@@ -724,7 +735,9 @@
       GNUNET_break (0);
       break;
     }
-    neighbour_delete (h, &dim->peer, n);
+    neighbour_delete (h,
+                      &dim->peer,
+                      n);
     break;
   case GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK:
     if (size != sizeof (struct SendOkMessage))
@@ -788,7 +801,9 @@
       break;
     }
     if (NULL != h->rec)
-      h->rec (h->cls, &im->peer, imm);
+      h->rec (h->cls,
+              &im->peer,
+              imm);
     break;
   case GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA:
     if (size != sizeof (struct QuotaSetMessage))
@@ -837,7 +852,9 @@
   GNUNET_assert (th == n->th);
   GNUNET_assert (NULL == n->hn);
   n->th = NULL;
-  th->notify (th->notify_cls, 0, NULL);
+  th->notify (th->notify_cls,
+              0,
+              NULL);
   GNUNET_free (th);
 }
 
@@ -851,7 +868,9 @@
  * @return number of bytes copied to @a buf
  */
 static size_t
-transport_notify_ready (void *cls, size_t size, void *buf)
+transport_notify_ready (void *cls,
+                        size_t size,
+                        void *buf)
 {
   struct GNUNET_TRANSPORT_Handle *h = cls;
   struct GNUNET_TRANSPORT_TransmitHandle *th;
@@ -874,7 +893,8 @@
   cbuf = buf;
   ret = 0;
   /* first send control messages */
-  while ((NULL != (th = h->control_head)) && (th->notify_size <= size))
+  while ( (NULL != (th = h->control_head)) &&
+          (th->notify_size <= size) )
   {
     GNUNET_CONTAINER_DLL_remove (h->control_head,
                                  h->control_tail,
@@ -1173,8 +1193,9 @@
   }
   /* Forget about all neighbours that we used to be connected to */
   GNUNET_CONTAINER_multipeermap_iterate (h->neighbours,
-                                         &neighbour_delete, h);
-  if (h->quota_task != NULL)
+                                         &neighbour_delete,
+                                         h);
+  if (NULL != h->quota_task)
   {
     GNUNET_SCHEDULER_cancel (h->quota_task);
     h->quota_task = NULL;
@@ -1181,15 +1202,22 @@
   }
   while ((NULL != (th = h->control_head)))
   {
-    GNUNET_CONTAINER_DLL_remove (h->control_head, h->control_tail, th);
-    th->notify (th->notify_cls, 0, NULL);
+    GNUNET_CONTAINER_DLL_remove (h->control_head,
+                                 h->control_tail,
+                                 th);
+    th->notify (th->notify_cls,
+                0,
+                NULL);
     GNUNET_free (th);
   }
   LOG (GNUNET_ERROR_TYPE_DEBUG,
        "Scheduling task to reconnect to transport service in %s.\n",
-       GNUNET_STRINGS_relative_time_to_string(h->reconnect_delay, GNUNET_YES));
+       GNUNET_STRINGS_relative_time_to_string (h->reconnect_delay,
+                                               GNUNET_YES));
   h->reconnect_task =
-      GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect, h);
+      GNUNET_SCHEDULER_add_delayed (h->reconnect_delay,
+                                    &reconnect,
+                                    h);
   h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay);
 }
 
@@ -1206,7 +1234,9 @@
 {
   LOG (GNUNET_ERROR_TYPE_DEBUG,
        "Canceling transmit of contral transmission requested\n");
-  GNUNET_CONTAINER_DLL_remove (th->control_head, th->control_tail, tth);
+  GNUNET_CONTAINER_DLL_remove (th->control_head,
+                               th->control_tail,
+                               tth);
   GNUNET_free (tth);
 }
 
@@ -1430,7 +1460,9 @@
  * @return number of bytes copied to @a buf
  */
 static size_t
-send_hello (void *cls, size_t size, void *buf)
+send_hello (void *cls,
+            size_t size,
+            void *buf)
 {
   struct GNUNET_TRANSPORT_OfferHelloHandle *ohh = cls;
   struct GNUNET_MessageHeader *msg = ohh->msg;
@@ -1446,9 +1478,12 @@
          "Timeout while trying to transmit `%s' request.\n",
          "HELLO");
     if (NULL != ohh->cont)
-      ohh->cont (ohh->cls, &tc);
+      ohh->cont (ohh->cls,
+                 &tc);
     GNUNET_free (msg);
-    GNUNET_CONTAINER_DLL_remove (ohh->th->oh_head, ohh->th->oh_tail, ohh);
+    GNUNET_CONTAINER_DLL_remove (ohh->th->oh_head,
+                                 ohh->th->oh_tail,
+                                 ohh);
     GNUNET_free (ohh);
     return 0;
   }
@@ -1457,12 +1492,17 @@
        "HELLO");
   ssize = ntohs (msg->size);
   GNUNET_assert (size >= ssize);
-  memcpy (buf, msg, ssize);
+  memcpy (buf,
+          msg,
+          ssize);
   GNUNET_free (msg);
   tc.reason = GNUNET_SCHEDULER_REASON_READ_READY;
   if (NULL != ohh->cont)
-    ohh->cont (ohh->cls, &tc);
-  GNUNET_CONTAINER_DLL_remove (ohh->th->oh_head, ohh->th->oh_tail, ohh);
+    ohh->cont (ohh->cls,
+               &tc);
+  GNUNET_CONTAINER_DLL_remove (ohh->th->oh_head,
+                               ohh->th->oh_tail,
+                               ohh);
   GNUNET_free (ohh);
   return ssize;
 }
@@ -1556,7 +1596,8 @@
 struct GNUNET_TRANSPORT_OfferHelloHandle *
 GNUNET_TRANSPORT_offer_hello (struct GNUNET_TRANSPORT_Handle *handle,
                               const struct GNUNET_MessageHeader *hello,
-                              GNUNET_SCHEDULER_TaskCallback cont, void *cls)
+                              GNUNET_SCHEDULER_TaskCallback cont,
+                              void *cls)
 {
   struct GNUNET_TRANSPORT_OfferHelloHandle *ohh;
   struct GNUNET_MessageHeader *msg;
@@ -1569,7 +1610,8 @@
   size = ntohs (hello->size);
   GNUNET_break (size >= sizeof (struct GNUNET_MessageHeader));
   if (GNUNET_OK !=
-      GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) hello, &peer))
+      GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) hello,
+                           &peer))
   {
     GNUNET_break (0);
     return NULL;
@@ -1604,7 +1646,9 @@
   struct GNUNET_TRANSPORT_Handle *th = ohh->th;
 
   cancel_control_transmit (ohh->th, ohh->tth);
-  GNUNET_CONTAINER_DLL_remove (th->oh_head, th->oh_tail, ohh);
+  GNUNET_CONTAINER_DLL_remove (th->oh_head,
+                               th->oh_tail,
+                               ohh);
   GNUNET_free (ohh->msg);
   GNUNET_free (ohh);
 }
@@ -1712,13 +1756,19 @@
  */
 struct GNUNET_TRANSPORT_Handle *
 GNUNET_TRANSPORT_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
-                          const struct GNUNET_PeerIdentity *self, void *cls,
+                          const struct GNUNET_PeerIdentity *self,
+                          void *cls,
                           GNUNET_TRANSPORT_ReceiveCallback rec,
                           GNUNET_TRANSPORT_NotifyConnect nc,
                           GNUNET_TRANSPORT_NotifyDisconnect nd)
 {
-  return GNUNET_TRANSPORT_connect2 (cfg, self, cls,
-                                    rec, nc, nd, NULL);
+  return GNUNET_TRANSPORT_connect2 (cfg,
+                                    self,
+                                    cls,
+                                    rec,
+                                    nc,
+                                    nd,
+                                    NULL);
 }
 
 
@@ -1738,7 +1788,8 @@
  */
 struct GNUNET_TRANSPORT_Handle *
 GNUNET_TRANSPORT_connect2 (const struct GNUNET_CONFIGURATION_Handle *cfg,
-                           const struct GNUNET_PeerIdentity *self, void *cls,
+                           const struct GNUNET_PeerIdentity *self,
+                           void *cls,
                            GNUNET_TRANSPORT_ReceiveCallback rec,
                            GNUNET_TRANSPORT_NotifyConnect nc,
                            GNUNET_TRANSPORT_NotifyDisconnect nd,
@@ -1761,7 +1812,8 @@
   ret->reconnect_delay = GNUNET_TIME_UNIT_ZERO;
   LOG (GNUNET_ERROR_TYPE_DEBUG,
        "Connecting to transport service.\n");
-  ret->client = GNUNET_CLIENT_connect ("transport", cfg);
+  ret->client = GNUNET_CLIENT_connect ("transport",
+                                       cfg);
   if (NULL == ret->client)
   {
     GNUNET_free (ret);
@@ -1772,8 +1824,10 @@
                                           GNUNET_YES);
   ret->ready_heap =
       GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
- schedule_control_transmit (ret, sizeof (struct StartMessage),
-                            &send_start, ret);
+  schedule_control_transmit (ret,
+                             sizeof (struct StartMessage),
+                             &send_start,
+                             ret);
   return ret;
 }
 
@@ -1869,7 +1923,8 @@
   th->notify_size = size;
   n->th = th;
   /* calculate when our transmission should be ready */
-  delay = GNUNET_BANDWIDTH_tracker_get_delay (&n->out_tracker, size + 
n->traffic_overhead);
+  delay = GNUNET_BANDWIDTH_tracker_get_delay (&n->out_tracker,
+                                              size + n->traffic_overhead);
   n->traffic_overhead = 0;
   if (delay.rel_value_us > timeout.rel_value_us)
     delay.rel_value_us = 0;        /* notify immediately (with failure) */
@@ -1876,8 +1931,11 @@
   LOG (GNUNET_ERROR_TYPE_DEBUG,
        "Bandwidth tracker allows next transmission to peer %s in %s\n",
        GNUNET_i2s (target),
-       GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES));
-  n->hn = GNUNET_CONTAINER_heap_insert (handle->ready_heap, n, 
delay.rel_value_us);
+       GNUNET_STRINGS_relative_time_to_string (delay,
+                                               GNUNET_YES));
+  n->hn = GNUNET_CONTAINER_heap_insert (handle->ready_heap,
+                                        n,
+                                        delay.rel_value_us);
   schedule_transmission (handle);
   return th;
 }

Modified: gnunet/src/util/bandwidth.c
===================================================================
--- gnunet/src/util/bandwidth.c 2015-08-03 11:14:51 UTC (rev 36188)
+++ gnunet/src/util/bandwidth.c 2015-08-03 11:34:36 UTC (rev 36189)
@@ -216,7 +216,7 @@
  * bytes).
  *
  * To stop notifications about updates and excess callbacks use
- * #GNUNET_BANDWIDTH_tracker_notification_stop
+ * #GNUNET_BANDWIDTH_tracker_notification_stop().
  *
  * @param av tracker to initialize
  * @param update_cb callback to notify a client about the tracker being updated




reply via email to

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