Przeglądaj źródła

uncrustify as demanded.

ng0 4 lat temu
rodzic
commit
d41ed82a4e
100 zmienionych plików z 15617 dodań i 15718 usunięć
  1. 164 163
      src/abe/abe.c
  2. 33 32
      src/abe/test_cpabe.c
  3. 6 12
      src/arm/arm.h
  4. 342 344
      src/arm/arm_api.c
  5. 74 76
      src/arm/arm_monitor_api.c
  6. 430 410
      src/arm/gnunet-arm.c
  7. 461 463
      src/arm/gnunet-service-arm.c
  8. 39 36
      src/arm/mockup-service.c
  9. 121 120
      src/arm/test_arm_api.c
  10. 192 194
      src/arm/test_exponential_backoff.c
  11. 126 126
      src/arm/test_gnunet_service_arm.c
  12. 518 505
      src/ats-tests/ats-testing-experiment.c
  13. 461 466
      src/ats-tests/ats-testing-log.c
  14. 105 91
      src/ats-tests/ats-testing-preferences.c
  15. 185 174
      src/ats-tests/ats-testing-traffic.c
  16. 432 431
      src/ats-tests/ats-testing.c
  17. 58 70
      src/ats-tests/ats-testing.h
  18. 214 213
      src/ats-tests/gnunet-ats-sim.c
  19. 575 560
      src/ats-tests/gnunet-solver-eval.c
  20. 286 285
      src/ats-tests/perf_ats.c
  21. 19 21
      src/ats-tests/perf_ats.h
  22. 338 340
      src/ats-tests/perf_ats_logging.c
  23. 396 397
      src/ats-tool/gnunet-ats.c
  24. 17 41
      src/ats/ats.h
  25. 8 22
      src/ats/ats2.h
  26. 100 103
      src/ats/ats_api2_application.c
  27. 215 220
      src/ats/ats_api2_transport.c
  28. 109 112
      src/ats/ats_api_connectivity.c
  29. 346 348
      src/ats/ats_api_performance.c
  30. 16 16
      src/ats/ats_api_scanner.c
  31. 304 309
      src/ats/ats_api_scheduling.c
  32. 374 364
      src/ats/gnunet-ats-solver-eval.c
  33. 30 48
      src/ats/gnunet-ats-solver-eval.h
  34. 324 334
      src/ats/gnunet-service-ats-new.c
  35. 235 231
      src/ats/gnunet-service-ats.c
  36. 3 3
      src/ats/gnunet-service-ats.h
  37. 311 316
      src/ats/gnunet-service-ats_addresses.c
  38. 35 38
      src/ats/gnunet-service-ats_addresses.h
  39. 60 61
      src/ats/gnunet-service-ats_connectivity.c
  40. 11 11
      src/ats/gnunet-service-ats_connectivity.h
  41. 108 109
      src/ats/gnunet-service-ats_normalization.c
  42. 5 5
      src/ats/gnunet-service-ats_normalization.h
  43. 115 115
      src/ats/gnunet-service-ats_performance.c
  44. 15 15
      src/ats/gnunet-service-ats_performance.h
  45. 295 279
      src/ats/gnunet-service-ats_plugins.c
  46. 29 29
      src/ats/gnunet-service-ats_plugins.h
  47. 242 254
      src/ats/gnunet-service-ats_preferences.c
  48. 19 19
      src/ats/gnunet-service-ats_preferences.h
  49. 79 79
      src/ats/gnunet-service-ats_reservations.c
  50. 9 9
      src/ats/gnunet-service-ats_reservations.h
  51. 73 73
      src/ats/gnunet-service-ats_scheduling.c
  52. 11 11
      src/ats/gnunet-service-ats_scheduling.h
  53. 448 440
      src/ats/perf_ats_solver.c
  54. 57 57
      src/ats/plugin_ats2_common.c
  55. 340 348
      src/ats/plugin_ats2_simple.c
  56. 331 305
      src/ats/plugin_ats_mlp.c
  57. 353 361
      src/ats/plugin_ats_proportional.c
  58. 322 324
      src/ats/plugin_ats_ril.c
  59. 70 70
      src/ats/test_ats2_lib.c
  60. 6 6
      src/ats/test_ats2_lib.h
  61. 11 11
      src/ats/test_ats_api.c
  62. 463 448
      src/ats/test_ats_lib.c
  63. 25 55
      src/ats/test_ats_lib.h
  64. 9 9
      src/ats/test_ats_reservation_api.c
  65. 3 4
      src/auction/auction.h
  66. 146 146
      src/auction/gnunet-auction-create.c
  67. 17 16
      src/auction/gnunet-auction-info.c
  68. 17 16
      src/auction/gnunet-auction-join.c
  69. 36 36
      src/auction/gnunet-service-auction.c
  70. 5 5
      src/auction/test_auction_api.c
  71. 59 61
      src/block/bg_bf.c
  72. 126 128
      src/block/block.c
  73. 52 52
      src/block/plugin_block_template.c
  74. 61 61
      src/block/plugin_block_test.c
  75. 27 40
      src/cadet/cadet.h
  76. 319 323
      src/cadet/cadet_api.c
  77. 68 71
      src/cadet/cadet_api_get_channel.c
  78. 76 79
      src/cadet/cadet_api_get_path.c
  79. 8 8
      src/cadet/cadet_api_helper.c
  80. 62 64
      src/cadet/cadet_api_list_peers.c
  81. 66 68
      src/cadet/cadet_api_list_tunnels.c
  82. 18 40
      src/cadet/cadet_protocol.h
  83. 125 127
      src/cadet/cadet_test_lib.c
  84. 17 17
      src/cadet/cadet_test_lib.h
  85. 19 21
      src/cadet/desirability_table.c
  86. 322 323
      src/cadet/gnunet-cadet-profiler.c
  87. 361 351
      src/cadet/gnunet-cadet.c
  88. 364 365
      src/cadet/gnunet-service-cadet.c
  89. 18 24
      src/cadet/gnunet-service-cadet.h
  90. 334 337
      src/cadet/gnunet-service-cadet_channel.c
  91. 45 45
      src/cadet/gnunet-service-cadet_channel.h
  92. 334 334
      src/cadet/gnunet-service-cadet_connection.c
  93. 40 43
      src/cadet/gnunet-service-cadet_connection.h
  94. 375 381
      src/cadet/gnunet-service-cadet_core.c
  95. 4 4
      src/cadet/gnunet-service-cadet_core.h
  96. 153 155
      src/cadet/gnunet-service-cadet_dht.c
  97. 7 7
      src/cadet/gnunet-service-cadet_dht.h
  98. 48 48
      src/cadet/gnunet-service-cadet_hello.c
  99. 5 5
      src/cadet/gnunet-service-cadet_hello.h
  100. 372 376
      src/cadet/gnunet-service-cadet_paths.c

+ 164 - 163
src/abe/abe.c

@@ -11,13 +11,13 @@
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      Affero General Public License for more details.
-    
+
      You should have received a copy of the GNU Affero General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
 
-*/
+ */
 
 /**
  * @file abe/abe.c
@@ -33,55 +33,53 @@
 #include "gnunet_crypto_lib.h"
 #include "gnunet_abe_lib.h"
 
-struct GNUNET_ABE_AbeMasterKey
-{
+struct GNUNET_ABE_AbeMasterKey {
   gabe_pub_t* pub;
   gabe_msk_t* msk;
 };
 
-struct GNUNET_ABE_AbeKey
-{
+struct GNUNET_ABE_AbeKey {
   gabe_pub_t* pub;
   gabe_prv_t* prv;
 };
 
 static int
-init_aes( element_t k, int enc,
-          gcry_cipher_hd_t* handle,
-          struct GNUNET_CRYPTO_SymmetricSessionKey *key,
-          unsigned char* iv)
+init_aes(element_t k, int enc,
+         gcry_cipher_hd_t* handle,
+         struct GNUNET_CRYPTO_SymmetricSessionKey *key,
+         unsigned char* iv)
 {
   int rc;
   int key_len;
   unsigned char* key_buf;
 
   key_len = element_length_in_bytes(k) < 33 ? 3 : element_length_in_bytes(k);
-  key_buf = (unsigned char*) malloc(key_len);
+  key_buf = (unsigned char*)malloc(key_len);
   element_to_bytes(key_buf, k);
 
-  GNUNET_memcpy (key->aes_key, key_buf, GNUNET_CRYPTO_AES_KEY_LENGTH);
-  GNUNET_assert (0 ==
-                 gcry_cipher_open (handle, GCRY_CIPHER_AES256,
-                                   GCRY_CIPHER_MODE_CFB, 0));
-  rc = gcry_cipher_setkey (*handle,
-                           key->aes_key,
-                           sizeof (key->aes_key));
-  GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY));
-  memset (iv, 0, 16); //TODO make reasonable
-  rc = gcry_cipher_setiv (*handle,
-                          iv,
-                          16);
-  GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY));
+  GNUNET_memcpy(key->aes_key, key_buf, GNUNET_CRYPTO_AES_KEY_LENGTH);
+  GNUNET_assert(0 ==
+                gcry_cipher_open(handle, GCRY_CIPHER_AES256,
+                                 GCRY_CIPHER_MODE_CFB, 0));
+  rc = gcry_cipher_setkey(*handle,
+                          key->aes_key,
+                          sizeof(key->aes_key));
+  GNUNET_assert((0 == rc) || ((char)rc == GPG_ERR_WEAK_KEY));
+  memset(iv, 0, 16);  //TODO make reasonable
+  rc = gcry_cipher_setiv(*handle,
+                         iv,
+                         16);
+  GNUNET_assert((0 == rc) || ((char)rc == GPG_ERR_WEAK_KEY));
 
   free(key_buf);
   return rc;
 }
 
 static int
-aes_128_cbc_encrypt( char* pt,
-                     int size,
-                     element_t k,
-                     char **ct )
+aes_128_cbc_encrypt(char* pt,
+                    int size,
+                    element_t k,
+                    char **ct)
 {
   gcry_cipher_hd_t handle;
   struct GNUNET_CRYPTO_SymmetricSessionKey skey;
@@ -90,34 +88,35 @@ aes_128_cbc_encrypt( char* pt,
   int padding;
   int buf_size;
   uint8_t len[4];
+
   init_aes(k, 1, &handle, &skey, iv);
 
   /* TODO make less crufty */
 
   /* stuff in real length (big endian) before padding */
-  len[0] = (size & 0xff000000)>>24;
-  len[1] = (size & 0xff0000)>>16;
-  len[2] = (size & 0xff00)>>8;
-  len[3] = (size & 0xff)>>0;
-  padding = 16 - ((4+size) % 16);
+  len[0] = (size & 0xff000000) >> 24;
+  len[1] = (size & 0xff0000) >> 16;
+  len[2] = (size & 0xff00) >> 8;
+  len[3] = (size & 0xff) >> 0;
+  padding = 16 - ((4 + size) % 16);
   buf_size = 4 + size + padding;
-  buf = GNUNET_malloc (buf_size);
-  GNUNET_memcpy (buf, len, 4);
-  GNUNET_memcpy (buf+4, pt, size);
-  *ct = GNUNET_malloc (buf_size);
+  buf = GNUNET_malloc(buf_size);
+  GNUNET_memcpy(buf, len, 4);
+  GNUNET_memcpy(buf + 4, pt, size);
+  *ct = GNUNET_malloc(buf_size);
 
-  GNUNET_assert (0 == gcry_cipher_encrypt (handle, *ct, buf_size, buf, buf_size));
-  gcry_cipher_close (handle);
+  GNUNET_assert(0 == gcry_cipher_encrypt(handle, *ct, buf_size, buf, buf_size));
+  gcry_cipher_close(handle);
   //AES_cbc_encrypt(pt->data, ct->data, pt->len, &key, iv, AES_ENCRYPT);
-  GNUNET_free (buf);
+  GNUNET_free(buf);
   return buf_size;
 }
 
 static int
-aes_128_cbc_decrypt( char* ct,
-                     int size,
-                     element_t k,
-                     char **pt )
+aes_128_cbc_decrypt(char* ct,
+                    int size,
+                    element_t k,
+                    char **pt)
 {
   struct GNUNET_CRYPTO_SymmetricSessionKey skey;
   gcry_cipher_hd_t handle;
@@ -127,22 +126,22 @@ aes_128_cbc_decrypt( char* ct,
 
   init_aes(k, 1, &handle, &skey, iv);
 
-  tmp = GNUNET_malloc (size);
+  tmp = GNUNET_malloc(size);
 
   //AES_cbc_encrypt(ct->data, pt->data, ct->len, &key, iv, AES_DECRYPT);
-  GNUNET_assert (0 == gcry_cipher_decrypt (handle, tmp, size, ct, size));
-  gcry_cipher_close (handle);
+  GNUNET_assert(0 == gcry_cipher_decrypt(handle, tmp, size, ct, size));
+  gcry_cipher_close(handle);
   /* TODO make less crufty */
 
   /* get real length */
   len = 0;
   len = len
-    | ((tmp[0])<<24) | ((tmp[1])<<16)
-    | ((tmp[2])<<8)  | ((tmp[3])<<0);
+        | ((tmp[0]) << 24) | ((tmp[1]) << 16)
+        | ((tmp[2]) << 8) | ((tmp[3]) << 0);
   /* truncate any garbage from the padding */
-  *pt = GNUNET_malloc (len);
-  GNUNET_memcpy (*pt, tmp+4, len);
-  GNUNET_free (tmp);
+  *pt = GNUNET_malloc(len);
+  GNUNET_memcpy(*pt, tmp + 4, len);
+  GNUNET_free(tmp);
   return len;
 }
 
@@ -153,13 +152,14 @@ aes_128_cbc_decrypt( char* ct,
  * @return fresh private key; free using #GNUNET_ABE_cpabe_delete_master_key
  */
 struct GNUNET_ABE_AbeMasterKey*
-GNUNET_ABE_cpabe_create_master_key (void)
+GNUNET_ABE_cpabe_create_master_key(void)
 {
   struct GNUNET_ABE_AbeMasterKey* key;
-  key = GNUNET_new (struct GNUNET_ABE_AbeMasterKey);
+
+  key = GNUNET_new(struct GNUNET_ABE_AbeMasterKey);
   gabe_setup(&key->pub, &key->msk);
-  GNUNET_assert (NULL != key->pub);
-  GNUNET_assert (NULL != key->msk);
+  GNUNET_assert(NULL != key->pub);
+  GNUNET_assert(NULL != key->msk);
   return key;
 }
 
@@ -171,13 +171,13 @@ GNUNET_ABE_cpabe_create_master_key (void)
  * @return fresh private key; free using #GNUNET_free
  */
 void
-GNUNET_ABE_cpabe_delete_master_key (struct GNUNET_ABE_AbeMasterKey *key)
+GNUNET_ABE_cpabe_delete_master_key(struct GNUNET_ABE_AbeMasterKey *key)
 {
-  gabe_msk_free (key->msk);
-  gabe_pub_free (key->pub);
+  gabe_msk_free(key->msk);
+  gabe_pub_free(key->pub);
   //GNUNET_free (key->msk);
   //gabe_msk_free (key->msk); //For some reason free of pub implicit?
-  GNUNET_free (key);
+  GNUNET_free(key);
 }
 
 /**
@@ -189,19 +189,19 @@ GNUNET_ABE_cpabe_delete_master_key (struct GNUNET_ABE_AbeMasterKey *key)
  * @return fresh private key; free using #GNUNET_ABE_cpabe_delete_key
  */
 struct GNUNET_ABE_AbeKey*
-GNUNET_ABE_cpabe_create_key (struct GNUNET_ABE_AbeMasterKey *key,
-                             char **attrs)
+GNUNET_ABE_cpabe_create_key(struct GNUNET_ABE_AbeMasterKey *key,
+                            char **attrs)
 {
   struct GNUNET_ABE_AbeKey *prv_key;
   int size;
   char *tmp;
 
-  prv_key = GNUNET_new (struct GNUNET_ABE_AbeKey);
+  prv_key = GNUNET_new(struct GNUNET_ABE_AbeKey);
   prv_key->prv = gabe_keygen(key->pub, key->msk, attrs);
   size = gabe_pub_serialize(key->pub, &tmp);
   prv_key->pub = gabe_pub_unserialize(tmp, size);
-  GNUNET_free (tmp);
-  GNUNET_assert (NULL != prv_key->prv);
+  GNUNET_free(tmp);
+  GNUNET_assert(NULL != prv_key->prv);
   return prv_key;
 }
 
@@ -214,50 +214,50 @@ GNUNET_ABE_cpabe_create_key (struct GNUNET_ABE_AbeMasterKey *key,
  * @return fresh private key; free using #GNUNET_free
  */
 void
-GNUNET_ABE_cpabe_delete_key (struct GNUNET_ABE_AbeKey *key,
-                                int delete_pub)
+GNUNET_ABE_cpabe_delete_key(struct GNUNET_ABE_AbeKey *key,
+                            int delete_pub)
 {
   //Memory management in gabe is buggy
-  gabe_prv_free (key->prv);
+  gabe_prv_free(key->prv);
   if (GNUNET_YES == delete_pub)
-    gabe_pub_free (key->pub);
-  GNUNET_free (key);
+    gabe_pub_free(key->pub);
+  GNUNET_free(key);
 }
 
 static ssize_t
-write_cpabe (void **result,
-             uint32_t file_len,
-             char* cph_buf,
-             int cph_buf_len,
-             char* aes_buf,
-             int aes_buf_len)
+write_cpabe(void **result,
+            uint32_t file_len,
+            char* cph_buf,
+            int cph_buf_len,
+            char* aes_buf,
+            int aes_buf_len)
 {
   char *ptr;
   uint32_t *len;
 
-  *result = GNUNET_malloc (12 + cph_buf_len + aes_buf_len);
+  *result = GNUNET_malloc(12 + cph_buf_len + aes_buf_len);
   ptr = *result;
-  len = (uint32_t*) ptr;
-  *len = htonl (file_len);
+  len = (uint32_t*)ptr;
+  *len = htonl(file_len);
   ptr += 4;
-  len = (uint32_t*) ptr;
-  *len = htonl (aes_buf_len);
+  len = (uint32_t*)ptr;
+  *len = htonl(aes_buf_len);
   ptr += 4;
-  GNUNET_memcpy (ptr, aes_buf, aes_buf_len);
+  GNUNET_memcpy(ptr, aes_buf, aes_buf_len);
   ptr += aes_buf_len;
-  len = (uint32_t*) ptr;
-  *len = htonl (cph_buf_len);
+  len = (uint32_t*)ptr;
+  *len = htonl(cph_buf_len);
   ptr += 4;
-  GNUNET_memcpy (ptr, cph_buf, cph_buf_len);
+  GNUNET_memcpy(ptr, cph_buf, cph_buf_len);
   return 12 + cph_buf_len + aes_buf_len;
 }
 
 static ssize_t
-read_cpabe (const void *data,
-            char** cph_buf,
-            int *cph_buf_len,
-            char** aes_buf,
-            int *aes_buf_len)
+read_cpabe(const void *data,
+           char** cph_buf,
+           int *cph_buf_len,
+           char** aes_buf,
+           int *aes_buf_len)
 {
   int buf_len;
   char *ptr;
@@ -265,18 +265,18 @@ read_cpabe (const void *data,
 
   ptr = (char*)data;
   len = (uint32_t*)ptr;
-  buf_len = ntohl (*len);
+  buf_len = ntohl(*len);
   ptr += 4;
   len = (uint32_t*)ptr;
-  *aes_buf_len = ntohl (*len);
+  *aes_buf_len = ntohl(*len);
   ptr += 4;
-  *aes_buf = GNUNET_malloc (*aes_buf_len);
+  *aes_buf = GNUNET_malloc(*aes_buf_len);
   GNUNET_memcpy(*aes_buf, ptr, *aes_buf_len);
   ptr += *aes_buf_len;
   len = (uint32_t*)ptr;
-  *cph_buf_len = ntohl (*len);
+  *cph_buf_len = ntohl(*len);
   ptr += 4;
-  *cph_buf = GNUNET_malloc (*cph_buf_len);
+  *cph_buf = GNUNET_malloc(*cph_buf_len);
   GNUNET_memcpy(*cph_buf, ptr, *cph_buf_len);
 
   return buf_len;
@@ -294,11 +294,11 @@ read_cpabe (const void *data,
  * @return the size of the encrypted block, -1 for errors
  */
 ssize_t
-GNUNET_ABE_cpabe_encrypt (const void *block,
-                             size_t size,
-                             const char *policy,
-                             const struct GNUNET_ABE_AbeMasterKey *key,
-                             void **result)
+GNUNET_ABE_cpabe_encrypt(const void *block,
+                         size_t size,
+                         const char *policy,
+                         const struct GNUNET_ABE_AbeMasterKey *key,
+                         void **result)
 {
   gabe_cph_t* cph;
   char* plt;
@@ -309,15 +309,15 @@ GNUNET_ABE_cpabe_encrypt (const void *block,
   int aes_buf_len;
   ssize_t result_len;
 
-  if( !(cph = gabe_enc(key->pub, m, (char*)policy)) )
+  if (!(cph = gabe_enc(key->pub, m, (char*)policy)))
     return GNUNET_SYSERR;
   cph_buf_len = gabe_cph_serialize(cph,
-                                &cph_buf);
+                                   &cph_buf);
   gabe_cph_free(cph);
-  GNUNET_free (cph);
-  plt = GNUNET_memdup (block, size);
+  GNUNET_free(cph);
+  plt = GNUNET_memdup(block, size);
   aes_buf_len = aes_128_cbc_encrypt(plt, size, m, &aes_buf);
-  GNUNET_free (plt);
+  GNUNET_free(plt);
   element_clear(m);
   result_len = write_cpabe(result, size, cph_buf, cph_buf_len, aes_buf, aes_buf_len);
   GNUNET_free(cph_buf);
@@ -336,10 +336,10 @@ GNUNET_ABE_cpabe_encrypt (const void *block,
  * @return the size of the encrypted block, -1 for errors
  */
 ssize_t
-GNUNET_ABE_cpabe_decrypt (const void *block,
-                             size_t size,
-                             const struct GNUNET_ABE_AbeKey *key,
-                             void **result)
+GNUNET_ABE_cpabe_decrypt(const void *block,
+                         size_t size,
+                         const struct GNUNET_ABE_AbeKey *key,
+                         void **result)
 {
   char* aes_buf;
   char* cph_buf;
@@ -351,22 +351,23 @@ GNUNET_ABE_cpabe_decrypt (const void *block,
 
   read_cpabe(block, &cph_buf, &cph_buf_size, &aes_buf, &aes_buf_size);
   cph = gabe_cph_unserialize(key->pub, cph_buf, cph_buf_size);
-  if( !gabe_dec(key->pub, key->prv, cph, m) ) {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "%s\n", gabe_error());
-    GNUNET_free (aes_buf);
-    GNUNET_free (cph_buf);
-    gabe_cph_free(cph);
-    GNUNET_free (cph);
-    element_clear (m);
-    return GNUNET_SYSERR;
-  }
+  if (!gabe_dec(key->pub, key->prv, cph, m))
+    {
+      GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+                 "%s\n", gabe_error());
+      GNUNET_free(aes_buf);
+      GNUNET_free(cph_buf);
+      gabe_cph_free(cph);
+      GNUNET_free(cph);
+      element_clear(m);
+      return GNUNET_SYSERR;
+    }
   gabe_cph_free(cph);
-  GNUNET_free (cph);
+  GNUNET_free(cph);
   plt_len = aes_128_cbc_decrypt(aes_buf, aes_buf_size, m, (char**)result);
-  GNUNET_free (cph_buf);
-  GNUNET_free (aes_buf);
-  element_clear (m);
+  GNUNET_free(cph_buf);
+  GNUNET_free(aes_buf);
+  element_clear(m);
   //freeing is buggy in gabe
   //gabe_prv_free (prv);
   //gabe_pub_free (pub);
@@ -382,8 +383,8 @@ GNUNET_ABE_cpabe_decrypt (const void *block,
  * @return the size of the encrypted block, -1 for errors
  */
 ssize_t
-GNUNET_ABE_cpabe_serialize_key (const struct GNUNET_ABE_AbeKey *key,
-                                   void **result)
+GNUNET_ABE_cpabe_serialize_key(const struct GNUNET_ABE_AbeKey *key,
+                               void **result)
 {
   ssize_t len;
   char *pub;
@@ -391,14 +392,14 @@ GNUNET_ABE_cpabe_serialize_key (const struct GNUNET_ABE_AbeKey *key,
   int pub_len;
   int prv_len;
 
-  pub_len = gabe_pub_serialize (key->pub, &pub);
-  prv_len = gabe_prv_serialize (key->prv, &prv);
+  pub_len = gabe_pub_serialize(key->pub, &pub);
+  prv_len = gabe_prv_serialize(key->prv, &prv);
 
   len = pub_len + prv_len + 12;
-  write_cpabe (result, len, pub, pub_len, prv, prv_len);
+  write_cpabe(result, len, pub, pub_len, prv, prv_len);
 
-  GNUNET_free (pub);
-  GNUNET_free (prv);
+  GNUNET_free(pub);
+  GNUNET_free(prv);
 
   return len;
 }
@@ -412,8 +413,8 @@ GNUNET_ABE_cpabe_serialize_key (const struct GNUNET_ABE_AbeKey *key,
  * @return the ABE key. NULL of unsuccessful
  */
 struct GNUNET_ABE_AbeKey*
-GNUNET_ABE_cpabe_deserialize_key (const void *data,
-                                     size_t len)
+GNUNET_ABE_cpabe_deserialize_key(const void *data,
+                                 size_t len)
 {
   struct GNUNET_ABE_AbeKey *key;
   char *pub;
@@ -421,17 +422,17 @@ GNUNET_ABE_cpabe_deserialize_key (const void *data,
   int prv_len;
   int pub_len;
 
-  key = GNUNET_new (struct GNUNET_ABE_AbeKey);
-  read_cpabe (data,
-              &pub,
-              &pub_len,
-              &prv,
-              &prv_len);
-  key->pub = gabe_pub_unserialize (pub, pub_len);
-  key->prv = gabe_prv_unserialize (key->pub, prv, prv_len);
-
-  GNUNET_free (pub);
-  GNUNET_free (prv);
+  key = GNUNET_new(struct GNUNET_ABE_AbeKey);
+  read_cpabe(data,
+             &pub,
+             &pub_len,
+             &prv,
+             &prv_len);
+  key->pub = gabe_pub_unserialize(pub, pub_len);
+  key->prv = gabe_prv_unserialize(key->pub, prv, prv_len);
+
+  GNUNET_free(pub);
+  GNUNET_free(prv);
   return key;
 }
 
@@ -444,8 +445,8 @@ GNUNET_ABE_cpabe_deserialize_key (const void *data,
  * @return the size of the encrypted block, -1 for errors
  */
 ssize_t
-GNUNET_ABE_cpabe_serialize_master_key (const struct GNUNET_ABE_AbeMasterKey *key,
-                                          void **result)
+GNUNET_ABE_cpabe_serialize_master_key(const struct GNUNET_ABE_AbeMasterKey *key,
+                                      void **result)
 {
   ssize_t len;
   char *pub;
@@ -453,14 +454,14 @@ GNUNET_ABE_cpabe_serialize_master_key (const struct GNUNET_ABE_AbeMasterKey *key
   int pub_len;
   int msk_len;
 
-  pub_len = gabe_pub_serialize (key->pub, &pub);
-  msk_len = gabe_msk_serialize (key->msk, &msk);
+  pub_len = gabe_pub_serialize(key->pub, &pub);
+  msk_len = gabe_msk_serialize(key->msk, &msk);
 
   len = pub_len + msk_len + 12;
-  write_cpabe (result, len, pub, pub_len, msk, msk_len);
+  write_cpabe(result, len, pub, pub_len, msk, msk_len);
 
-  GNUNET_free (pub);
-  GNUNET_free (msk);
+  GNUNET_free(pub);
+  GNUNET_free(msk);
 
   return len;
 }
@@ -474,8 +475,8 @@ GNUNET_ABE_cpabe_serialize_master_key (const struct GNUNET_ABE_AbeMasterKey *key
  * @return the ABE key. NULL of unsuccessful
  */
 struct GNUNET_ABE_AbeMasterKey*
-GNUNET_ABE_cpabe_deserialize_master_key (const void *data,
-                                            size_t len)
+GNUNET_ABE_cpabe_deserialize_master_key(const void *data,
+                                        size_t len)
 {
   struct GNUNET_ABE_AbeMasterKey *key;
   char *msk;
@@ -483,17 +484,17 @@ GNUNET_ABE_cpabe_deserialize_master_key (const void *data,
   int msk_len;
   int pub_len;
 
-  key = GNUNET_new (struct GNUNET_ABE_AbeMasterKey);
-  read_cpabe (data,
-              &pub,
-              &pub_len,
-              &msk,
-              &msk_len);
-  key->pub = gabe_pub_unserialize (pub, pub_len);
-  key->msk = gabe_msk_unserialize (key->pub, msk, msk_len);
-
-  GNUNET_free (pub);
-  GNUNET_free (msk);
+  key = GNUNET_new(struct GNUNET_ABE_AbeMasterKey);
+  read_cpabe(data,
+             &pub,
+             &pub_len,
+             &msk,
+             &msk_len);
+  key->pub = gabe_pub_unserialize(pub, pub_len);
+  key->msk = gabe_msk_unserialize(key->pub, msk, msk_len);
+
+  GNUNET_free(pub);
+  GNUNET_free(msk);
 
   return key;
 }

+ 33 - 32
src/abe/test_cpabe.c

@@ -11,13 +11,13 @@
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      Affero General Public License for more details.
-    
+
      You should have received a copy of the GNU Affero General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
 
-*/
+ */
 /**
  * @author Martin Schanzenbach
  * @file util/test_crypto_abe.c
@@ -30,7 +30,7 @@
 #define TESTSTRING "Hello World!"
 
 static int
-testAbecipher ()
+testAbecipher()
 {
   struct GNUNET_ABE_AbeMasterKey *msk;
   struct GNUNET_ABE_AbeKey *key;
@@ -38,49 +38,50 @@ testAbecipher ()
   char **attrs;
   int size;
   char *res;
-  msk = GNUNET_ABE_cpabe_create_master_key ();
-  size = GNUNET_ABE_cpabe_encrypt (TESTSTRING, strlen (TESTSTRING) + 1,
-                                      "testattr", //Policy
-                                      msk,
-                                      (void*)&result);
-  GNUNET_assert (-1 != size);
-  attrs = GNUNET_malloc (2 * sizeof (char*));
+
+  msk = GNUNET_ABE_cpabe_create_master_key();
+  size = GNUNET_ABE_cpabe_encrypt(TESTSTRING, strlen(TESTSTRING) + 1,
+                                  "testattr",     //Policy
+                                  msk,
+                                  (void*)&result);
+  GNUNET_assert(-1 != size);
+  attrs = GNUNET_malloc(2 * sizeof(char*));
   attrs[0] = "testattr";
   attrs[1] = NULL;
-  key = GNUNET_ABE_cpabe_create_key (msk,
-                                        attrs);
+  key = GNUNET_ABE_cpabe_create_key(msk,
+                                    attrs);
 
-  size = GNUNET_ABE_cpabe_decrypt (result, size,
-                                      key,
-                                      (void*)&res);
-  if (strlen (TESTSTRING) + 1 != size)
-  {
-    printf ("abeciphertest failed: decryptBlock returned %d\n", size);
-    return 1;
-  }
-  if (0 != strcmp (res, TESTSTRING))
-  {
-    printf ("abeciphertest failed: %s != %s\n", res, TESTSTRING);
-    return 1;
-  }
+  size = GNUNET_ABE_cpabe_decrypt(result, size,
+                                  key,
+                                  (void*)&res);
+  if (strlen(TESTSTRING) + 1 != size)
+    {
+      printf("abeciphertest failed: decryptBlock returned %d\n", size);
+      return 1;
+    }
+  if (0 != strcmp(res, TESTSTRING))
+    {
+      printf("abeciphertest failed: %s != %s\n", res, TESTSTRING);
+      return 1;
+    }
   else
     return 0;
 }
 
 
 int
-main (int argc, char *argv[])
+main(int argc, char *argv[])
 {
   int failureCount = 0;
 
-  GNUNET_log_setup ("test-crypto-abe", "WARNING", NULL);
-  failureCount += testAbecipher ();
+  GNUNET_log_setup("test-crypto-abe", "WARNING", NULL);
+  failureCount += testAbecipher();
 
   if (failureCount != 0)
-  {
-    printf ("%d TESTS FAILED!\n", failureCount);
-    return -1;
-  }
+    {
+      printf("%d TESTS FAILED!\n", failureCount);
+      return -1;
+    }
   return 0;
 }
 

+ 6 - 12
src/arm/arm.h

@@ -11,12 +11,12 @@
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      Affero General Public License for more details.
-    
+
      You should have received a copy of the GNU Affero General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
-*/
+ */
 
 /**
  * @author Christian Grothoff
@@ -38,9 +38,7 @@ GNUNET_NETWORK_STRUCT_BEGIN
 /**
  * Status update from ARM to client.
  */
-struct GNUNET_ARM_StatusMessage
-{
-
+struct GNUNET_ARM_StatusMessage {
   /**
    * Reply to client, of type is #GNUNET_MESSAGE_TYPE_ARM_STATUS.
    */
@@ -54,8 +52,7 @@ struct GNUNET_ARM_StatusMessage
   /* followed by a 0-terminated service name */
 };
 
-struct GNUNET_ARM_Message
-{
+struct GNUNET_ARM_Message {
   /**
    * Reply to client, type is #GNUNET_MESSAGE_TYPE_ARM_RESULT or
    * #GNUNET_MESSAGE_TYPE_ARM_LIST_RESULT.
@@ -84,9 +81,7 @@ struct GNUNET_ARM_Message
 /**
  * Reply from ARM to client.
  */
-struct GNUNET_ARM_ResultMessage
-{
-
+struct GNUNET_ARM_ResultMessage {
   /**
    * Reply to client, of type is #GNUNET_MESSAGE_TYPE_ARM_RESULT, with an ID.
    */
@@ -104,8 +99,7 @@ struct GNUNET_ARM_ResultMessage
  * '\0' terminated strings. header->size contains the
  * total size (including all strings).
  */
-struct GNUNET_ARM_ListResultMessage
-{
+struct GNUNET_ARM_ListResultMessage {
   /**
    * Reply to client, of type is #GNUNET_MESSAGE_TYPE_ARM_LIST_RESULT,
    * with an ID.

Plik diff jest za duży
+ 342 - 344
src/arm/arm_api.c


+ 74 - 76
src/arm/arm_monitor_api.c

@@ -11,12 +11,12 @@
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      Affero General Public License for more details.
-    
+
      You should have received a copy of the GNU Affero General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
-*/
+ */
 
 /**
  * @file arm/arm_monitor_api.c
@@ -30,16 +30,14 @@
 #include "gnunet_protocols.h"
 #include "arm.h"
 
-#define INIT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
+#define INIT_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5)
 
-#define LOG(kind, ...) GNUNET_log_from (kind, "arm-monitor-api", __VA_ARGS__)
+#define LOG(kind, ...) GNUNET_log_from(kind, "arm-monitor-api", __VA_ARGS__)
 
 /**
  * Handle for interacting with ARM.
  */
-struct GNUNET_ARM_MonitorHandle
-{
-
+struct GNUNET_ARM_MonitorHandle {
   /**
    * Our control connection to the ARM service.
    */
@@ -79,7 +77,7 @@ struct GNUNET_ARM_MonitorHandle
  * @return #GNUNET_OK on success
  */
 static int
-reconnect_arm_monitor (struct GNUNET_ARM_MonitorHandle *h);
+reconnect_arm_monitor(struct GNUNET_ARM_MonitorHandle *h);
 
 
 /**
@@ -88,14 +86,14 @@ reconnect_arm_monitor (struct GNUNET_ARM_MonitorHandle *h);
  * @param cls the `struct GNUNET_ARM_MonitorHandle`
  */
 static void
-reconnect_arm_monitor_task (void *cls)
+reconnect_arm_monitor_task(void *cls)
 {
   struct GNUNET_ARM_MonitorHandle *h = cls;
 
   h->reconnect_task = NULL;
-  LOG (GNUNET_ERROR_TYPE_DEBUG,
-       "Connecting to ARM service for monitoring after delay\n");
-  GNUNET_break (GNUNET_OK == reconnect_arm_monitor (h));
+  LOG(GNUNET_ERROR_TYPE_DEBUG,
+      "Connecting to ARM service for monitoring after delay\n");
+  GNUNET_break(GNUNET_OK == reconnect_arm_monitor(h));
 }
 
 
@@ -106,18 +104,18 @@ reconnect_arm_monitor_task (void *cls)
  * @param h our handle
  */
 static void
-reconnect_arm_monitor_later (struct GNUNET_ARM_MonitorHandle *h)
+reconnect_arm_monitor_later(struct GNUNET_ARM_MonitorHandle *h)
 {
   if (NULL != h->mq)
-  {
-    GNUNET_MQ_destroy (h->mq);
-    h->mq = NULL;
-  }
-  GNUNET_assert (NULL == h->reconnect_task);
-  h->reconnect_task = GNUNET_SCHEDULER_add_delayed (h->retry_backoff,
-                                                    &reconnect_arm_monitor_task,
-                                                    h);
-  h->retry_backoff = GNUNET_TIME_STD_BACKOFF (h->retry_backoff);
+    {
+      GNUNET_MQ_destroy(h->mq);
+      h->mq = NULL;
+    }
+  GNUNET_assert(NULL == h->reconnect_task);
+  h->reconnect_task = GNUNET_SCHEDULER_add_delayed(h->retry_backoff,
+                                                   &reconnect_arm_monitor_task,
+                                                   h);
+  h->retry_backoff = GNUNET_TIME_STD_BACKOFF(h->retry_backoff);
 }
 
 
@@ -129,18 +127,18 @@ reconnect_arm_monitor_later (struct GNUNET_ARM_MonitorHandle *h)
  * @return #GNUNET_OK if the message is well-formed
  */
 static int
-check_monitor_notify (void *cls, const struct GNUNET_ARM_StatusMessage *msg)
+check_monitor_notify(void *cls, const struct GNUNET_ARM_StatusMessage *msg)
 {
   size_t sl =
-    ntohs (msg->header.size) - sizeof (struct GNUNET_ARM_StatusMessage);
-  const char *name = (const char *) &msg[1];
+    ntohs(msg->header.size) - sizeof(struct GNUNET_ARM_StatusMessage);
+  const char *name = (const char *)&msg[1];
 
-  (void) cls;
+  (void)cls;
   if ((0 == sl) || ('\0' != name[sl - 1]))
-  {
-    GNUNET_break (0);
-    return GNUNET_SYSERR;
-  }
+    {
+      GNUNET_break(0);
+      return GNUNET_SYSERR;
+    }
   return GNUNET_OK;
 }
 
@@ -152,18 +150,18 @@ check_monitor_notify (void *cls, const struct GNUNET_ARM_StatusMessage *msg)
  * @param res the message received from the arm service
  */
 static void
-handle_monitor_notify (void *cls, const struct GNUNET_ARM_StatusMessage *res)
+handle_monitor_notify(void *cls, const struct GNUNET_ARM_StatusMessage *res)
 {
   struct GNUNET_ARM_MonitorHandle *h = cls;
   enum GNUNET_ARM_ServiceStatus status;
 
-  status = (enum GNUNET_ARM_ServiceStatus) ntohl (res->status);
-  LOG (GNUNET_ERROR_TYPE_DEBUG,
-       "Received notification from ARM for service `%s' with status %d\n",
-       (const char *) &res[1],
-       (int) status);
+  status = (enum GNUNET_ARM_ServiceStatus)ntohl(res->status);
+  LOG(GNUNET_ERROR_TYPE_DEBUG,
+      "Received notification from ARM for service `%s' with status %d\n",
+      (const char *)&res[1],
+      (int)status);
   if (NULL != h->service_status)
-    h->service_status (h->service_status_cls, (const char *) &res[1], status);
+    h->service_status(h->service_status_cls, (const char *)&res[1], status);
 }
 
 
@@ -176,12 +174,12 @@ handle_monitor_notify (void *cls, const struct GNUNET_ARM_StatusMessage *res)
  * @param error error code
  */
 static void
-mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
+mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
 {
   struct GNUNET_ARM_MonitorHandle *h = cls;
 
-  (void) error;
-  reconnect_arm_monitor_later (h);
+  (void)error;
+  reconnect_arm_monitor_later(h);
 }
 
 
@@ -192,29 +190,29 @@ mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
  * @return #GNUNET_OK on success
  */
 static int
-reconnect_arm_monitor (struct GNUNET_ARM_MonitorHandle *h)
+reconnect_arm_monitor(struct GNUNET_ARM_MonitorHandle *h)
 {
   struct GNUNET_MQ_MessageHandler handlers[] =
-    {GNUNET_MQ_hd_var_size (monitor_notify,
-                            GNUNET_MESSAGE_TYPE_ARM_STATUS,
-                            struct GNUNET_ARM_StatusMessage,
-                            h),
-     GNUNET_MQ_handler_end ()};
+  { GNUNET_MQ_hd_var_size(monitor_notify,
+                          GNUNET_MESSAGE_TYPE_ARM_STATUS,
+                          struct GNUNET_ARM_StatusMessage,
+                          h),
+    GNUNET_MQ_handler_end() };
   struct GNUNET_MessageHeader *msg;
   struct GNUNET_MQ_Envelope *env;
 
-  GNUNET_assert (NULL == h->mq);
-  h->mq = GNUNET_CLIENT_connect (h->cfg, "arm", handlers, &mq_error_handler, h);
+  GNUNET_assert(NULL == h->mq);
+  h->mq = GNUNET_CLIENT_connect(h->cfg, "arm", handlers, &mq_error_handler, h);
   if (NULL == h->mq)
-  {
-    if (NULL != h->service_status)
-      h->service_status (h->service_status_cls,
-                         NULL,
-                         GNUNET_ARM_SERVICE_STOPPED);
-    return GNUNET_SYSERR;
-  }
-  env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_ARM_MONITOR);
-  GNUNET_MQ_send (h->mq, env);
+    {
+      if (NULL != h->service_status)
+        h->service_status(h->service_status_cls,
+                          NULL,
+                          GNUNET_ARM_SERVICE_STOPPED);
+      return GNUNET_SYSERR;
+    }
+  env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_ARM_MONITOR);
+  GNUNET_MQ_send(h->mq, env);
   return GNUNET_OK;
 }
 
@@ -231,21 +229,21 @@ reconnect_arm_monitor (struct GNUNET_ARM_MonitorHandle *h)
  * @return context to use for further ARM monitor operations, NULL on error.
  */
 struct GNUNET_ARM_MonitorHandle *
-GNUNET_ARM_monitor_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
-                          GNUNET_ARM_ServiceStatusCallback cont,
-                          void *cont_cls)
+GNUNET_ARM_monitor_start(const struct GNUNET_CONFIGURATION_Handle *cfg,
+                         GNUNET_ARM_ServiceStatusCallback cont,
+                         void *cont_cls)
 {
   struct GNUNET_ARM_MonitorHandle *h;
 
-  h = GNUNET_new (struct GNUNET_ARM_MonitorHandle);
+  h = GNUNET_new(struct GNUNET_ARM_MonitorHandle);
   h->cfg = cfg;
   h->service_status = cont;
   h->service_status_cls = cont_cls;
-  if (GNUNET_OK != reconnect_arm_monitor (h))
-  {
-    GNUNET_free (h);
-    return NULL;
-  }
+  if (GNUNET_OK != reconnect_arm_monitor(h))
+    {
+      GNUNET_free(h);
+      return NULL;
+    }
   return h;
 }
 
@@ -256,19 +254,19 @@ GNUNET_ARM_monitor_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
  * @param h the handle that was being used
  */
 void
-GNUNET_ARM_monitor_stop (struct GNUNET_ARM_MonitorHandle *h)
+GNUNET_ARM_monitor_stop(struct GNUNET_ARM_MonitorHandle *h)
 {
   if (NULL != h->mq)
-  {
-    GNUNET_MQ_destroy (h->mq);
-    h->mq = NULL;
-  }
+    {
+      GNUNET_MQ_destroy(h->mq);
+      h->mq = NULL;
+    }
   if (NULL != h->reconnect_task)
-  {
-    GNUNET_SCHEDULER_cancel (h->reconnect_task);
-    h->reconnect_task = NULL;
-  }
-  GNUNET_free (h);
+    {
+      GNUNET_SCHEDULER_cancel(h->reconnect_task);
+      h->reconnect_task = NULL;
+    }
+  GNUNET_free(h);
 }
 
 

+ 430 - 410
src/arm/gnunet-arm.c

@@ -16,7 +16,7 @@
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
-*/
+ */
 
 /**
  * @file arm/gnunet-arm.c
@@ -144,25 +144,25 @@ static struct GNUNET_ARM_Operation *op;
  * were specified when gnunet-arm was run.
  */
 static void
-delete_files ()
+delete_files()
 {
-  GNUNET_log (
+  GNUNET_log(
     GNUNET_ERROR_TYPE_DEBUG,
     "Will attempt to remove configuration file %s and service directory %s\n",
     config_file,
     dir);
-  if (0 != unlink (config_file))
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                _ ("Failed to remove configuration file %s\n"),
-                config_file);
-  }
-  if (GNUNET_OK != GNUNET_DISK_directory_remove (dir))
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                _ ("Failed to remove servicehome directory %s\n"),
-                dir);
-  }
+  if (0 != unlink(config_file))
+    {
+      GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
+                 _("Failed to remove configuration file %s\n"),
+                 config_file);
+    }
+  if (GNUNET_OK != GNUNET_DISK_directory_remove(dir))
+    {
+      GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
+                 _("Failed to remove servicehome directory %s\n"),
+                 dir);
+    }
 }
 
 
@@ -173,37 +173,37 @@ delete_files ()
  * @param cls closure, unused
  */
 static void
-shutdown_task (void *cls)
+shutdown_task(void *cls)
 {
-  (void) cls;
+  (void)cls;
   if (NULL != al_task)
-  {
-    GNUNET_SCHEDULER_cancel (al_task);
-    al_task = NULL;
-  }
+    {
+      GNUNET_SCHEDULER_cancel(al_task);
+      al_task = NULL;
+    }
   if (NULL != op)
-  {
-    GNUNET_ARM_operation_cancel (op);
-    op = NULL;
-  }
+    {
+      GNUNET_ARM_operation_cancel(op);
+      op = NULL;
+    }
   if (NULL != h)
-  {
-    GNUNET_ARM_disconnect (h);
-    h = NULL;
-  }
+    {
+      GNUNET_ARM_disconnect(h);
+      h = NULL;
+    }
   if (NULL != m)
-  {
-    GNUNET_ARM_monitor_stop (m);
-    m = NULL;
-  }
+    {
+      GNUNET_ARM_monitor_stop(m);
+      m = NULL;
+    }
   if (NULL != timeout_task)
-  {
-    GNUNET_SCHEDULER_cancel (timeout_task);
-    timeout_task = NULL;
-  }
+    {
+      GNUNET_SCHEDULER_cancel(timeout_task);
+      timeout_task = NULL;
+    }
   if ((GNUNET_YES == end) && (GNUNET_YES == delete))
-    delete_files ();
-  GNUNET_CONFIGURATION_destroy (cfg);
+    delete_files();
+  GNUNET_CONFIGURATION_destroy(cfg);
   cfg = NULL;
 }
 
@@ -215,16 +215,17 @@ shutdown_task (void *cls)
  * @return a string interpretation of the request status
  */
 static const char *
-req_string (enum GNUNET_ARM_RequestStatus rs)
+req_string(enum GNUNET_ARM_RequestStatus rs)
 {
   switch (rs)
-  {
-  case GNUNET_ARM_REQUEST_SENT_OK:
-    return _ ("Message was sent successfully");
-  case GNUNET_ARM_REQUEST_DISCONNECTED:
-    return _ ("We disconnected from ARM before we could send a request");
-  }
-  return _ ("Unknown request status");
+    {
+    case GNUNET_ARM_REQUEST_SENT_OK:
+      return _("Message was sent successfully");
+
+    case GNUNET_ARM_REQUEST_DISCONNECTED:
+      return _("We disconnected from ARM before we could send a request");
+    }
+  return _("Unknown request status");
 }
 
 
@@ -235,32 +236,41 @@ req_string (enum GNUNET_ARM_RequestStatus rs)
  * @return a string interpretation
  */
 static const char *
-ret_string (enum GNUNET_ARM_Result result)
+ret_string(enum GNUNET_ARM_Result result)
 {
   switch (result)
-  {
-  case GNUNET_ARM_RESULT_STOPPED:
-    return _ ("is stopped");
-  case GNUNET_ARM_RESULT_STARTING:
-    return _ ("is starting");
-  case GNUNET_ARM_RESULT_STOPPING:
-    return _ ("is stopping");
-  case GNUNET_ARM_RESULT_IS_STARTING_ALREADY:
-    return _ ("is starting already");
-  case GNUNET_ARM_RESULT_IS_STOPPING_ALREADY:
-    return _ ("is stopping already");
-  case GNUNET_ARM_RESULT_IS_STARTED_ALREADY:
-    return _ ("is started already");
-  case GNUNET_ARM_RESULT_IS_STOPPED_ALREADY:
-    return _ ("is stopped already");
-  case GNUNET_ARM_RESULT_IS_NOT_KNOWN:
-    return _ ("service is not known to ARM");
-  case GNUNET_ARM_RESULT_START_FAILED:
-    return _ ("service failed to start");
-  case GNUNET_ARM_RESULT_IN_SHUTDOWN:
-    return _ ("service cannot be manipulated because ARM is shutting down");
-  }
-  return _ ("Unknown result code.");
+    {
+    case GNUNET_ARM_RESULT_STOPPED:
+      return _("is stopped");
+
+    case GNUNET_ARM_RESULT_STARTING:
+      return _("is starting");
+
+    case GNUNET_ARM_RESULT_STOPPING:
+      return _("is stopping");
+
+    case GNUNET_ARM_RESULT_IS_STARTING_ALREADY:
+      return _("is starting already");
+
+    case GNUNET_ARM_RESULT_IS_STOPPING_ALREADY:
+      return _("is stopping already");
+
+    case GNUNET_ARM_RESULT_IS_STARTED_ALREADY:
+      return _("is started already");
+
+    case GNUNET_ARM_RESULT_IS_STOPPED_ALREADY:
+      return _("is stopped already");
+
+    case GNUNET_ARM_RESULT_IS_NOT_KNOWN:
+      return _("service is not known to ARM");
+
+    case GNUNET_ARM_RESULT_START_FAILED:
+      return _("service failed to start");
+
+    case GNUNET_ARM_RESULT_IN_SHUTDOWN:
+      return _("service cannot be manipulated because ARM is shutting down");
+    }
+  return _("Unknown result code.");
 }
 
 
@@ -270,7 +280,7 @@ ret_string (enum GNUNET_ARM_Result result)
  * @param cls closure
  */
 static void
-action_loop (void *cls);
+action_loop(void *cls);
 
 
 /**
@@ -283,18 +293,18 @@ action_loop (void *cls);
  *                  #GNUNET_SYSERR on error.
  */
 static void
-conn_status (void *cls, int connected)
+conn_status(void *cls, int connected)
 {
   static int once;
 
-  (void) cls;
+  (void)cls;
   if ((GNUNET_SYSERR == connected) && (0 == once))
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                _ ("Fatal error initializing ARM API.\n"));
-    GNUNET_SCHEDULER_shutdown ();
-    return;
-  }
+    {
+      GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
+                 _("Fatal error initializing ARM API.\n"));
+      GNUNET_SCHEDULER_shutdown();
+      return;
+    }
   once = 1;
 }
 
@@ -311,32 +321,32 @@ conn_status (void *cls, int connected)
  *               according to ARM
  */
 static void
-start_callback (void *cls,
-                enum GNUNET_ARM_RequestStatus rs,
-                enum GNUNET_ARM_Result result)
+start_callback(void *cls,
+               enum GNUNET_ARM_RequestStatus rs,
+               enum GNUNET_ARM_Result result)
 {
-  (void) cls;
+  (void)cls;
   op = NULL;
   if (GNUNET_ARM_REQUEST_SENT_OK != rs)
-  {
-    fprintf (stdout,
-             _ ("Failed to start the ARM service: %s\n"),
-             req_string (rs));
-    GNUNET_SCHEDULER_shutdown ();
-    return;
-  }
+    {
+      fprintf(stdout,
+              _("Failed to start the ARM service: %s\n"),
+              req_string(rs));
+      GNUNET_SCHEDULER_shutdown();
+      return;
+    }
   if ((GNUNET_ARM_RESULT_STARTING != result) &&
       (GNUNET_ARM_RESULT_IS_STARTED_ALREADY != result))
-  {
-    fprintf (stdout,
-             _ ("Failed to start the ARM service: %s\n"),
-             ret_string (result));
-    GNUNET_SCHEDULER_shutdown ();
-    return;
-  }
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM service [re]start successful\n");
+    {
+      fprintf(stdout,
+              _("Failed to start the ARM service: %s\n"),
+              ret_string(result));
+      GNUNET_SCHEDULER_shutdown();
+      return;
+    }
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "ARM service [re]start successful\n");
   start = 0;
-  al_task = GNUNET_SCHEDULER_add_now (&action_loop, NULL);
+  al_task = GNUNET_SCHEDULER_add_now(&action_loop, NULL);
 }
 
 
@@ -352,44 +362,44 @@ start_callback (void *cls,
  *               according to ARM
  */
 static void
-stop_callback (void *cls,
-               enum GNUNET_ARM_RequestStatus rs,
-               enum GNUNET_ARM_Result result)
+stop_callback(void *cls,
+              enum GNUNET_ARM_RequestStatus rs,
+              enum GNUNET_ARM_Result result)
 {
   char *msg;
 
-  (void) cls;
+  (void)cls;
   op = NULL;
   if (GNUNET_ARM_REQUEST_SENT_OK != rs)
-  {
-    GNUNET_asprintf (&msg,
-                     "%s",
-                     _ (
-                       "Failed to send a stop request to the ARM service: %s\n"));
-    fprintf (stdout, msg, req_string (rs));
-    GNUNET_free (msg);
-    GNUNET_SCHEDULER_shutdown ();
-    return;
-  }
+    {
+      GNUNET_asprintf(&msg,
+                      "%s",
+                      _(
+                        "Failed to send a stop request to the ARM service: %s\n"));
+      fprintf(stdout, msg, req_string(rs));
+      GNUNET_free(msg);
+      GNUNET_SCHEDULER_shutdown();
+      return;
+    }
   if ((GNUNET_ARM_RESULT_STOPPING != result) &&
       (GNUNET_ARM_RESULT_STOPPED != result) &&
       (GNUNET_ARM_RESULT_IS_STOPPED_ALREADY != result))
-  {
-    fprintf (stdout,
-             _ ("Failed to stop the ARM service: %s\n"),
-             ret_string (result));
-    GNUNET_SCHEDULER_shutdown ();
-    return;
-  }
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM service shutdown successful\n");
+    {
+      fprintf(stdout,
+              _("Failed to stop the ARM service: %s\n"),
+              ret_string(result));
+      GNUNET_SCHEDULER_shutdown();
+      return;
+    }
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "ARM service shutdown successful\n");
   end = 0;
   if (restart)
-  {
-    restart = 0;
-    start = 1;
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Initiating an ARM restart\n");
-  }
-  al_task = GNUNET_SCHEDULER_add_now (&action_loop, NULL);
+    {
+      restart = 0;
+      start = 1;
+      GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Initiating an ARM restart\n");
+    }
+  al_task = GNUNET_SCHEDULER_add_now(&action_loop, NULL);
 }
 
 
@@ -405,37 +415,37 @@ stop_callback (void *cls,
  *               according to ARM
  */
 static void
-init_callback (void *cls,
-               enum GNUNET_ARM_RequestStatus rs,
-               enum GNUNET_ARM_Result result)
+init_callback(void *cls,
+              enum GNUNET_ARM_RequestStatus rs,
+              enum GNUNET_ARM_Result result)
 {
-  (void) cls;
+  (void)cls;
   op = NULL;
   if (GNUNET_ARM_REQUEST_SENT_OK != rs)
-  {
-    fprintf (stdout,
-             _ ("Failed to send a request to start the `%s' service: %s\n"),
-             init,
-             req_string (rs));
-    GNUNET_SCHEDULER_shutdown ();
-    return;
-  }
+    {
+      fprintf(stdout,
+              _("Failed to send a request to start the `%s' service: %s\n"),
+              init,
+              req_string(rs));
+      GNUNET_SCHEDULER_shutdown();
+      return;
+    }
   if ((GNUNET_ARM_RESULT_STARTING != result) &&
       (GNUNET_ARM_RESULT_IS_STARTED_ALREADY != result))
-  {
-    fprintf (stdout,
-             _ ("Failed to start the `%s' service: %s\n"),
-             init,
-             ret_string (result));
-    GNUNET_SCHEDULER_shutdown ();
-    return;
-  }
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Service %s [re]started successfully\n",
-              init);
-  GNUNET_free (init);
+    {
+      fprintf(stdout,
+              _("Failed to start the `%s' service: %s\n"),
+              init,
+              ret_string(result));
+      GNUNET_SCHEDULER_shutdown();
+      return;
+    }
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+             "Service %s [re]started successfully\n",
+             init);
+  GNUNET_free(init);
   init = NULL;
-  al_task = GNUNET_SCHEDULER_add_now (&action_loop, NULL);
+  al_task = GNUNET_SCHEDULER_add_now(&action_loop, NULL);
 }
 
 
@@ -451,42 +461,42 @@ init_callback (void *cls,
  *               according to ARM
  */
 static void
-term_callback (void *cls,
-               enum GNUNET_ARM_RequestStatus rs,
-               enum GNUNET_ARM_Result result)
+term_callback(void *cls,
+              enum GNUNET_ARM_RequestStatus rs,
+              enum GNUNET_ARM_Result result)
 {
   char *msg;
 
-  (void) cls;
+  (void)cls;
   op = NULL;
   if (GNUNET_ARM_REQUEST_SENT_OK != rs)
-  {
-    GNUNET_asprintf (&msg,
-                     _ (
-                       "Failed to send a request to kill the `%s' service: %%s\n"),
-                     term);
-    fprintf (stdout, msg, req_string (rs));
-    GNUNET_free (msg);
-    GNUNET_SCHEDULER_shutdown ();
-    return;
-  }
+    {
+      GNUNET_asprintf(&msg,
+                      _(
+                        "Failed to send a request to kill the `%s' service: %%s\n"),
+                      term);
+      fprintf(stdout, msg, req_string(rs));
+      GNUNET_free(msg);
+      GNUNET_SCHEDULER_shutdown();
+      return;
+    }
   if ((GNUNET_ARM_RESULT_STOPPED != result) &&
       (GNUNET_ARM_RESULT_IS_STOPPED_ALREADY != result))
-  {
-    fprintf (stdout,
-             _ ("Failed to kill the `%s' service: %s\n"),
-             term,
-             ret_string (result));
-    GNUNET_SCHEDULER_shutdown ();
-    return;
-  }
+    {
+      fprintf(stdout,
+              _("Failed to kill the `%s' service: %s\n"),
+              term,
+              ret_string(result));
+      GNUNET_SCHEDULER_shutdown();
+      return;
+    }
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Service %s stopped successfully\n",
-              term);
-  GNUNET_free (term);
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+             "Service %s stopped successfully\n",
+             term);
+  GNUNET_free(term);
   term = NULL;
-  al_task = GNUNET_SCHEDULER_add_now (&action_loop, NULL);
+  al_task = GNUNET_SCHEDULER_add_now(&action_loop, NULL);
 }
 
 
@@ -501,39 +511,39 @@ term_callback (void *cls,
  * @param list list of services that are running
  */
 static void
-list_callback (void *cls,
-               enum GNUNET_ARM_RequestStatus rs,
-               unsigned int count,
-               const char *const *list)
+list_callback(void *cls,
+              enum GNUNET_ARM_RequestStatus rs,
+              unsigned int count,
+              const char *const *list)
 {
-  (void) cls;
+  (void)cls;
   op = NULL;
   if (GNUNET_ARM_REQUEST_SENT_OK != rs)
-  {
-    char *msg;
-
-    GNUNET_asprintf (&msg,
-                     "%s",
-                     _ ("Failed to request a list of services: %s\n"));
-    fprintf (stdout, msg, req_string (rs));
-    GNUNET_free (msg);
-    ret = 3;
-    GNUNET_SCHEDULER_shutdown ();
-  }
+    {
+      char *msg;
+
+      GNUNET_asprintf(&msg,
+                      "%s",
+                      _("Failed to request a list of services: %s\n"));
+      fprintf(stdout, msg, req_string(rs));
+      GNUNET_free(msg);
+      ret = 3;
+      GNUNET_SCHEDULER_shutdown();
+    }
   if (NULL == list)
-  {
-    fprintf (stderr,
-             "%s",
-             _ ("Error communicating with ARM. ARM not running?\n"));
-    GNUNET_SCHEDULER_shutdown ();
-    ret = 3;
-    return;
-  }
-  if (! quiet)
-    fprintf (stdout, "%s", _ ("Running services:\n"));
+    {
+      fprintf(stderr,
+              "%s",
+              _("Error communicating with ARM. ARM not running?\n"));
+      GNUNET_SCHEDULER_shutdown();
+      ret = 3;
+      return;
+    }
+  if (!quiet)
+    fprintf(stdout, "%s", _("Running services:\n"));
   for (unsigned int i = 0; i < count; i++)
-    fprintf (stdout, "%s\n", list[i]);
-  al_task = GNUNET_SCHEDULER_add_now (&action_loop, NULL);
+    fprintf(stdout, "%s\n", list[i]);
+  al_task = GNUNET_SCHEDULER_add_now(&action_loop, NULL);
 }
 
 
@@ -544,85 +554,91 @@ list_callback (void *cls,
  * @param cls closure, unused
  */
 static void
-action_loop (void *cls)
+action_loop(void *cls)
 {
-  (void) cls;
+  (void)cls;
   al_task = NULL;
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Running requested actions\n");
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Running requested actions\n");
   while (1)
-  {
-    switch (phase++)
     {
-    case 0:
-      if (NULL != term)
-      {
-        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Termination action\n");
-        op = GNUNET_ARM_request_service_stop (h, term, &term_callback, NULL);
-        return;
-      }
-      break;
-    case 1:
-      if (end || restart)
-      {
-        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "End action\n");
-        op = GNUNET_ARM_request_service_stop (h, "arm", &stop_callback, NULL);
-        return;
-      }
-      break;
-    case 2:
-      if (start)
-      {
-        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Start action\n");
-        op =
-          GNUNET_ARM_request_service_start (h,
-                                            "arm",
-                                            (no_stdout
-                                               ? 0
-                                               : GNUNET_OS_INHERIT_STD_OUT) |
-                                              (no_stderr
-                                                 ? 0
-                                                 : GNUNET_OS_INHERIT_STD_ERR),
-                                            &start_callback,
-                                            NULL);
-        return;
-      }
-      break;
-    case 3:
-      if (NULL != init)
-      {
-        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Initialization action\n");
-        op = GNUNET_ARM_request_service_start (h,
-                                               init,
-                                               GNUNET_OS_INHERIT_STD_NONE,
-                                               &init_callback,
-                                               NULL);
-        return;
-      }
-      break;
-    case 4:
-      if (list)
-      {
-        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                    "Going to list all running services controlled by ARM.\n");
-        op = GNUNET_ARM_request_service_list (h, &list_callback, &list);
-        return;
-      }
-      break;
-    case 5:
-      if (monitor)
-      {
-        if (! quiet)
-          fprintf (stderr, _ ("Now only monitoring, press CTRL-C to stop.\n"));
-        quiet =
-          0; /* does not make sense to stay quiet in monitor mode at this time */
-        return; /* done with tasks, just monitor */
-      }
-      break;
-    default: /* last phase */
-      GNUNET_SCHEDULER_shutdown ();
-      return;
+      switch (phase++)
+        {
+        case 0:
+          if (NULL != term)
+            {
+              GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Termination action\n");
+              op = GNUNET_ARM_request_service_stop(h, term, &term_callback, NULL);
+              return;
+            }
+          break;
+
+        case 1:
+          if (end || restart)
+            {
+              GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "End action\n");
+              op = GNUNET_ARM_request_service_stop(h, "arm", &stop_callback, NULL);
+              return;
+            }
+          break;
+
+        case 2:
+          if (start)
+            {
+              GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Start action\n");
+              op =
+                GNUNET_ARM_request_service_start(h,
+                                                 "arm",
+                                                 (no_stdout
+                                                  ? 0
+                                                  : GNUNET_OS_INHERIT_STD_OUT) |
+                                                 (no_stderr
+                                                  ? 0
+                                                  : GNUNET_OS_INHERIT_STD_ERR),
+                                                 &start_callback,
+                                                 NULL);
+              return;
+            }
+          break;
+
+        case 3:
+          if (NULL != init)
+            {
+              GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Initialization action\n");
+              op = GNUNET_ARM_request_service_start(h,
+                                                    init,
+                                                    GNUNET_OS_INHERIT_STD_NONE,
+                                                    &init_callback,
+                                                    NULL);
+              return;
+            }
+          break;
+
+        case 4:
+          if (list)
+            {
+              GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+                         "Going to list all running services controlled by ARM.\n");
+              op = GNUNET_ARM_request_service_list(h, &list_callback, &list);
+              return;
+            }
+          break;
+
+        case 5:
+          if (monitor)
+            {
+              if (!quiet)
+                fprintf(stderr, _("Now only monitoring, press CTRL-C to stop.\n"));
+              quiet =
+                0; /* does not make sense to stay quiet in monitor mode at this time */
+              return; /* done with tasks, just monitor */
+            }
+          break;
+
+        default: /* last phase */
+          GNUNET_SCHEDULER_shutdown();
+          return;
+        }
     }
-  }
 }
 
 
@@ -634,44 +650,48 @@ action_loop (void *cls)
  * @param status status of the service
  */
 static void
-srv_status (void *cls,
-            const char *service,
-            enum GNUNET_ARM_ServiceStatus status)
+srv_status(void *cls,
+           const char *service,
+           enum GNUNET_ARM_ServiceStatus status)
 {
   const char *msg;
 
-  (void) cls;
+  (void)cls;
   switch (status)
-  {
-  case GNUNET_ARM_SERVICE_MONITORING_STARTED:
-    return; /* this should be done silently */
-  case GNUNET_ARM_SERVICE_STOPPED:
-    msg = _ ("Stopped %s.\n");
-    break;
-  case GNUNET_ARM_SERVICE_STARTING:
-    msg = _ ("Starting %s...\n");
-    break;
-  case GNUNET_ARM_SERVICE_STOPPING:
-    msg = _ ("Stopping %s...\n");
-    break;
-  default:
-    msg = NULL;
-    break;
-  }
-  if (! quiet)
-  {
-    if (NULL != msg)
-      fprintf (stderr, msg, service);
-    else
-      fprintf (stderr,
-               _ ("Unknown status %u for service %s.\n"),
-               status,
-               service);
-  }
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Got service %s status %d\n",
-              service,
-              (int) status);
+    {
+    case GNUNET_ARM_SERVICE_MONITORING_STARTED:
+      return; /* this should be done silently */
+
+    case GNUNET_ARM_SERVICE_STOPPED:
+      msg = _("Stopped %s.\n");
+      break;
+
+    case GNUNET_ARM_SERVICE_STARTING:
+      msg = _("Starting %s...\n");
+      break;
+
+    case GNUNET_ARM_SERVICE_STOPPING:
+      msg = _("Stopping %s...\n");
+      break;
+
+    default:
+      msg = NULL;
+      break;
+    }
+  if (!quiet)
+    {
+      if (NULL != msg)
+        fprintf(stderr, msg, service);
+      else
+        fprintf(stderr,
+                _("Unknown status %u for service %s.\n"),
+                status,
+                service);
+    }
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+             "Got service %s status %d\n",
+             service,
+             (int)status);
 }
 
 
@@ -679,12 +699,12 @@ srv_status (void *cls,
  * Task run on timeout (if -T is given).
  */
 static void
-timeout_task_cb (void *cls)
+timeout_task_cb(void *cls)
 {
-  (void) cls;
+  (void)cls;
   timeout_task = NULL;
   ret = 2;
-  GNUNET_SCHEDULER_shutdown ();
+  GNUNET_SCHEDULER_shutdown();
 }
 
 
@@ -697,34 +717,34 @@ timeout_task_cb (void *cls)
  * @param c configuration
  */
 static void
-run (void *cls,
-     char *const *args,
-     const char *cfgfile,
-     const struct GNUNET_CONFIGURATION_Handle *c)
+run(void *cls,
+    char *const *args,
+    const char *cfgfile,
+    const struct GNUNET_CONFIGURATION_Handle *c)
 {
-  (void) cls;
-  (void) args;
-  (void) cfgfile;
-  cfg = GNUNET_CONFIGURATION_dup (c);
+  (void)cls;
+  (void)args;
+  (void)cfgfile;
+  cfg = GNUNET_CONFIGURATION_dup(c);
   if (GNUNET_OK !=
-      GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS", "GNUNET_HOME", &dir))
-  {
-    GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "PATHS", "GNUNET_HOME");
-    return;
-  }
-  (void) GNUNET_CONFIGURATION_get_value_filename (cfg,
-                                                  "arm",
-                                                  "CONFIG",
-                                                  &config_file);
-  if (NULL == (h = GNUNET_ARM_connect (cfg, &conn_status, NULL)))
+      GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", "GNUNET_HOME", &dir))
+    {
+      GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, "PATHS", "GNUNET_HOME");
+      return;
+    }
+  (void)GNUNET_CONFIGURATION_get_value_filename(cfg,
+                                                "arm",
+                                                "CONFIG",
+                                                &config_file);
+  if (NULL == (h = GNUNET_ARM_connect(cfg, &conn_status, NULL)))
     return;
   if (monitor)
-    m = GNUNET_ARM_monitor_start (cfg, &srv_status, NULL);
-  al_task = GNUNET_SCHEDULER_add_now (&action_loop, NULL);
-  GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
+    m = GNUNET_ARM_monitor_start(cfg, &srv_status, NULL);
+  al_task = GNUNET_SCHEDULER_add_now(&action_loop, NULL);
+  GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL);
   if (0 != timeout.rel_value_us)
     timeout_task =
-      GNUNET_SCHEDULER_add_delayed (timeout, &timeout_task_cb, NULL);
+      GNUNET_SCHEDULER_add_delayed(timeout, &timeout_task_cb, NULL);
 }
 
 
@@ -736,88 +756,88 @@ run (void *cls,
  * @return 0 ok, 1 on error, 2 on timeout
  */
 int
-main (int argc, char *const *argv)
+main(int argc, char *const *argv)
 {
   struct GNUNET_GETOPT_CommandLineOption options[] =
-    {GNUNET_GETOPT_option_flag ('e',
-                                "end",
-                                gettext_noop ("stop all GNUnet services"),
-                                &end),
-     GNUNET_GETOPT_option_string ('i',
-                                  "init",
-                                  "SERVICE",
-                                  gettext_noop ("start a particular service"),
-                                  &init),
-     GNUNET_GETOPT_option_string ('k',
-                                  "kill",
-                                  "SERVICE",
-                                  gettext_noop ("stop a particular service"),
-                                  &term),
-     GNUNET_GETOPT_option_flag ('s',
-                                "start",
-                                gettext_noop (
-                                  "start all GNUnet default services"),
-                                &start),
-     GNUNET_GETOPT_option_flag ('r',
-                                "restart",
-                                gettext_noop (
-                                  "stop and start all GNUnet default services"),
-                                &restart),
-     GNUNET_GETOPT_option_flag ('d',
-                                "delete",
-                                gettext_noop (
-                                  "delete config file and directory on exit"),
-                                &delete),
-     GNUNET_GETOPT_option_flag ('m',
-                                "monitor",
-                                gettext_noop ("monitor ARM activities"),
-                                &monitor),
-     GNUNET_GETOPT_option_flag ('q',
-                                "quiet",
-                                gettext_noop ("don't print status messages"),
-                                &quiet),
-     GNUNET_GETOPT_option_relative_time (
-       'T',
-       "timeout",
-       "DELAY",
-       gettext_noop (
-         "exit with error status if operation does not finish after DELAY"),
-       &timeout),
-     GNUNET_GETOPT_option_flag ('I',
-                                "info",
-                                gettext_noop (
-                                  "list currently running services"),
-                                &list),
-     GNUNET_GETOPT_option_flag (
-       'O',
-       "no-stdout",
-       gettext_noop ("don't let gnunet-service-arm inherit standard output"),
-       &no_stdout),
-     GNUNET_GETOPT_option_flag (
-       'E',
-       "no-stderr",
-       gettext_noop ("don't let gnunet-service-arm inherit standard error"),
-       &no_stderr),
-     GNUNET_GETOPT_OPTION_END};
+  { GNUNET_GETOPT_option_flag('e',
+                              "end",
+                              gettext_noop("stop all GNUnet services"),
+                              &end),
+    GNUNET_GETOPT_option_string('i',
+                                "init",
+                                "SERVICE",
+                                gettext_noop("start a particular service"),
+                                &init),
+    GNUNET_GETOPT_option_string('k',
+                                "kill",
+                                "SERVICE",
+                                gettext_noop("stop a particular service"),
+                                &term),
+    GNUNET_GETOPT_option_flag('s',
+                              "start",
+                              gettext_noop(
+                                "start all GNUnet default services"),
+                              &start),
+    GNUNET_GETOPT_option_flag('r',
+                              "restart",
+                              gettext_noop(
+                                "stop and start all GNUnet default services"),
+                              &restart),
+    GNUNET_GETOPT_option_flag('d',
+                              "delete",
+                              gettext_noop(
+                                "delete config file and directory on exit"),
+                              &delete),
+    GNUNET_GETOPT_option_flag('m',
+                              "monitor",
+                              gettext_noop("monitor ARM activities"),
+                              &monitor),
+    GNUNET_GETOPT_option_flag('q',
+                              "quiet",
+                              gettext_noop("don't print status messages"),
+                              &quiet),
+    GNUNET_GETOPT_option_relative_time(
+      'T',
+      "timeout",
+      "DELAY",
+      gettext_noop(
+        "exit with error status if operation does not finish after DELAY"),
+      &timeout),
+    GNUNET_GETOPT_option_flag('I',
+                              "info",
+                              gettext_noop(
+                                "list currently running services"),
+                              &list),
+    GNUNET_GETOPT_option_flag(
+      'O',
+      "no-stdout",
+      gettext_noop("don't let gnunet-service-arm inherit standard output"),
+      &no_stdout),
+    GNUNET_GETOPT_option_flag(
+      'E',
+      "no-stderr",
+      gettext_noop("don't let gnunet-service-arm inherit standard error"),
+      &no_stderr),
+    GNUNET_GETOPT_OPTION_END };
   int lret;
 
-  if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
+  if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv))
     return 2;
   if (GNUNET_OK ==
-      (lret = GNUNET_PROGRAM_run (
+      (lret = GNUNET_PROGRAM_run(
          argc,
          argv,
          "gnunet-arm",
-         gettext_noop (
+         gettext_noop(
            "Control services and the Automated Restart Manager (ARM)"),
          options,
          &run,
          NULL)))
-  {
-    GNUNET_free ((void *) argv);
-    return ret;
-  }
-  GNUNET_free ((void *) argv);
+    {
+      GNUNET_free((void *)argv);
+      return ret;
+    }
+  GNUNET_free((void *)argv);
   return lret;
 }
 

Plik diff jest za duży
+ 461 - 463
src/arm/gnunet-service-arm.c


+ 39 - 36
src/arm/mockup-service.c

@@ -11,12 +11,12 @@
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      Affero General Public License for more details.
-    
+
      You should have received a copy of the GNU Affero General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
-*/
+ */
 
 #include <stdlib.h>
 #include "platform.h"
@@ -33,15 +33,15 @@ static int special_ret = 0;
  * @param message the actual message
  */
 static void
-handle_stop (void *cls, const struct GNUNET_MessageHeader *message)
+handle_stop(void *cls, const struct GNUNET_MessageHeader *message)
 {
   struct GNUNET_SERVICE_Client *client = cls;
 
-  (void) message;
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-              _ ("Initiating shutdown as requested by client.\n"));
-  GNUNET_SERVICE_client_persist (client);
-  GNUNET_SCHEDULER_shutdown ();
+  (void)message;
+  GNUNET_log(GNUNET_ERROR_TYPE_INFO,
+             _("Initiating shutdown as requested by client.\n"));
+  GNUNET_SERVICE_client_persist(client);
+  GNUNET_SCHEDULER_shutdown();
   /* ARM won't exponentially increase restart delay if we
    * terminate normally. This changes the return code.
    */
@@ -58,12 +58,12 @@ handle_stop (void *cls, const struct GNUNET_MessageHeader *message)
  * @return @a c
  */
 static void *
-client_connect_cb (void *cls,
-                   struct GNUNET_SERVICE_Client *c,
-                   struct GNUNET_MQ_Handle *mq)
+client_connect_cb(void *cls,
+                  struct GNUNET_SERVICE_Client *c,
+                  struct GNUNET_MQ_Handle *mq)
 {
-  (void) cls;
-  (void) mq;
+  (void)cls;
+  (void)mq;
   return c;
 }
 
@@ -76,23 +76,23 @@ client_connect_cb (void *cls,
  * @param internal_cls should be equal to @a c
  */
 static void
-client_disconnect_cb (void *cls,
-                      struct GNUNET_SERVICE_Client *c,
-                      void *internal_cls)
+client_disconnect_cb(void *cls,
+                     struct GNUNET_SERVICE_Client *c,
+                     void *internal_cls)
 {
-  (void) cls;
-  GNUNET_assert (c == internal_cls);
+  (void)cls;
+  GNUNET_assert(c == internal_cls);
 }
 
 
 static void
-run (void *cls,
-     const struct GNUNET_CONFIGURATION_Handle *cfg,
-     struct GNUNET_SERVICE_Handle *service)
+run(void *cls,
+    const struct GNUNET_CONFIGURATION_Handle *cfg,
+    struct GNUNET_SERVICE_Handle *service)
 {
-  (void) cls;
-  (void) cfg;
-  (void) service;
+  (void)cls;
+  (void)cfg;
+  (void)service;
   /* nothing to do */
 }
 
@@ -100,20 +100,23 @@ run (void *cls,
 /**
  * Define "main" method using service macro.
  */
-GNUNET_SERVICE_MAIN ("do-nothing",
-                     GNUNET_SERVICE_OPTION_NONE,
-                     &run,
-                     &client_connect_cb,
-                     &client_disconnect_cb,
-                     NULL,
-                     GNUNET_MQ_hd_fixed_size (stop,
-                                              GNUNET_MESSAGE_TYPE_ARM_STOP,
-                                              struct GNUNET_MessageHeader,
-                                              NULL),
-                     GNUNET_MQ_handler_end ());
+GNUNET_SERVICE_MAIN("do-nothing",
+                    GNUNET_SERVICE_OPTION_NONE,
+                    &run,
+                    &client_connect_cb,
+                    &client_disconnect_cb,
+                    NULL,
+                    GNUNET_MQ_hd_fixed_size(stop,
+                                            GNUNET_MESSAGE_TYPE_ARM_STOP,
+                                            struct GNUNET_MessageHeader,
+                                            NULL),
+                    GNUNET_MQ_handler_end());
 
 
 /**
  * MINIMIZE heap size (way below 128k) since this process doesn't need much.
  */
-void __attribute__ ((destructor)) GNUNET_mockup_done () { _exit (special_ret); }
+void __attribute__ ((destructor)) GNUNET_mockup_done()
+{
+  _exit(special_ret);
+}

+ 121 - 120
src/arm/test_arm_api.c

@@ -11,12 +11,12 @@
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      Affero General Public License for more details.
-    
+
      You should have received a copy of the GNU Affero General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
-*/
+ */
 /**
  * @file arm/test_arm_api.c
  * @brief testcase for arm_api.c
@@ -26,9 +26,9 @@
 #include "gnunet_arm_service.h"
 #include "gnunet_resolver_service.h"
 
-#define LOG(...) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
+#define LOG(...) GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
 
-#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15)
+#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 15)
 
 static const struct GNUNET_CONFIGURATION_Handle *cfg;
 
@@ -42,139 +42,139 @@ static int phase = 0;
 
 
 static void
-arm_stop_cb (void *cls,
-	     enum GNUNET_ARM_RequestStatus status,
-	     enum GNUNET_ARM_Result result)
+arm_stop_cb(void *cls,
+            enum GNUNET_ARM_RequestStatus status,
+            enum GNUNET_ARM_Result result)
 {
   op = NULL;
   /* (6), a stop request should be sent to ARM successfully */
   /* ARM should report that it is stopping */
-  GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK);
-  GNUNET_break (result == GNUNET_ARM_RESULT_STOPPED);
-  GNUNET_break (phase == 6);
+  GNUNET_break(status == GNUNET_ARM_REQUEST_SENT_OK);
+  GNUNET_break(result == GNUNET_ARM_RESULT_STOPPED);
+  GNUNET_break(phase == 6);
   phase++;
-  LOG ("Sent 'STOP' request for arm to ARM %s\n",
-       (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully");
-  GNUNET_SCHEDULER_shutdown ();
+  LOG("Sent 'STOP' request for arm to ARM %s\n",
+      (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully");
+  GNUNET_SCHEDULER_shutdown();
 }
 
 
 static void
-resolver_stop_cb (void *cls,
-		  enum GNUNET_ARM_RequestStatus status,
-                  enum GNUNET_ARM_Result result)
+resolver_stop_cb(void *cls,
+                 enum GNUNET_ARM_RequestStatus status,
+                 enum GNUNET_ARM_Result result)
 {
   op = NULL;
   /* (5), a stop request should be sent to ARM successfully.
    * ARM should report that resolver is stopped.
    */
-  GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK);
-  GNUNET_break (result == GNUNET_ARM_RESULT_STOPPED);
-  GNUNET_break (phase == 5);
-  LOG ("Sent 'STOP' request for resolver to ARM %s\n",
-       (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully");
+  GNUNET_break(status == GNUNET_ARM_REQUEST_SENT_OK);
+  GNUNET_break(result == GNUNET_ARM_RESULT_STOPPED);
+  GNUNET_break(phase == 5);
+  LOG("Sent 'STOP' request for resolver to ARM %s\n",
+      (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully");
   phase++;
-  GNUNET_assert (NULL == op);
-  op = GNUNET_ARM_request_service_stop (arm,
-                                        "arm",
-                                        &arm_stop_cb,
-                                        NULL);
+  GNUNET_assert(NULL == op);
+  op = GNUNET_ARM_request_service_stop(arm,
+                                       "arm",
+                                       &arm_stop_cb,
+                                       NULL);
 }
 
 
 static void
-dns_notify (void *cls,
-            const struct sockaddr *addr,
-            socklen_t addrlen)
+dns_notify(void *cls,
+           const struct sockaddr *addr,
+           socklen_t addrlen)
 {
   if (addr == NULL)
     {
       /* (4), resolver should finish resolving localhost */
-      GNUNET_break (phase == 4);
+      GNUNET_break(phase == 4);
       phase++;
-      LOG ("Finished resolving localhost\n");
+      LOG("Finished resolving localhost\n");
       if (ok != 0)
         ok = 2;
-      GNUNET_assert (NULL == op);
-      op = GNUNET_ARM_request_service_stop (arm,
-                                            "resolver",
-                                            &resolver_stop_cb,
-                                            NULL);
+      GNUNET_assert(NULL == op);
+      op = GNUNET_ARM_request_service_stop(arm,
+                                           "resolver",
+                                           &resolver_stop_cb,
+                                           NULL);
       return;
     }
   /* (3), resolver should resolve localhost */
-  GNUNET_break (phase == 3);
-  LOG ("Resolved localhost\n");
+  GNUNET_break(phase == 3);
+  LOG("Resolved localhost\n");
   phase++;
-  GNUNET_break (addr != NULL);
+  GNUNET_break(addr != NULL);
   ok = 0;
 }
 
 
 static void
-resolver_start_cb (void *cls,
-		   enum GNUNET_ARM_RequestStatus status,
-		   enum GNUNET_ARM_Result result)
+resolver_start_cb(void *cls,
+                  enum GNUNET_ARM_RequestStatus status,
+                  enum GNUNET_ARM_Result result)
 {
   op = NULL;
   /* (2), the start request for resolver should be sent successfully
    * ARM should report that resolver service is starting.
    */
-  GNUNET_assert (status == GNUNET_ARM_REQUEST_SENT_OK);
-  GNUNET_break (phase == 2);
-  GNUNET_break (result == GNUNET_ARM_RESULT_STARTING);
-  LOG ("Sent 'START' request for resolver to ARM %s\n",
-       (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully");
+  GNUNET_assert(status == GNUNET_ARM_REQUEST_SENT_OK);
+  GNUNET_break(phase == 2);
+  GNUNET_break(result == GNUNET_ARM_RESULT_STARTING);
+  LOG("Sent 'START' request for resolver to ARM %s\n",
+      (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully");
   phase++;
-  GNUNET_RESOLVER_ip_get ("localhost",
-                          AF_INET,
-                          TIMEOUT,
-                          &dns_notify, NULL);
+  GNUNET_RESOLVER_ip_get("localhost",
+                         AF_INET,
+                         TIMEOUT,
+                         &dns_notify, NULL);
 }
 
 
 static void
-arm_conn (void *cls,
-	  int connected)
+arm_conn(void *cls,
+         int connected)
 {
   if (GNUNET_SYSERR == connected)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-		_("Fatal error initializing ARM API.\n"));
-    GNUNET_SCHEDULER_shutdown ();
-    GNUNET_assert (0);
-    return;
-  }
+    {
+      GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
+                 _("Fatal error initializing ARM API.\n"));
+      GNUNET_SCHEDULER_shutdown();
+      GNUNET_assert(0);
+      return;
+    }
   if (GNUNET_YES == connected)
-  {
-    /* (1), arm connection should be established */
-    LOG ("Connected to ARM\n");
-    GNUNET_break (phase == 1);
-    phase++;
-    GNUNET_assert (NULL == op);
-    op = GNUNET_ARM_request_service_start (arm,
-                                           "resolver",
-                                           GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
-                                           &resolver_start_cb,
-                                           NULL);
-  }
+    {
+      /* (1), arm connection should be established */
+      LOG("Connected to ARM\n");
+      GNUNET_break(phase == 1);
+      phase++;
+      GNUNET_assert(NULL == op);
+      op = GNUNET_ARM_request_service_start(arm,
+                                            "resolver",
+                                            GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
+                                            &resolver_start_cb,
+                                            NULL);
+    }
   else
-  {
-    /* (7), ARM should stop (we disconnect from it) */
-    LOG ("Disconnected from ARM\n");
-    GNUNET_break (phase == 7);
-    if (phase != 7)
-      ok = 3;
-    else if (ok == 1)
-      ok = 0;
-  }
+    {
+      /* (7), ARM should stop (we disconnect from it) */
+      LOG("Disconnected from ARM\n");
+      GNUNET_break(phase == 7);
+      if (phase != 7)
+        ok = 3;
+      else if (ok == 1)
+        ok = 0;
+    }
 }
 
 
 static void
-arm_start_cb (void *cls,
-	      enum GNUNET_ARM_RequestStatus status,
-	      enum GNUNET_ARM_Result result)
+arm_start_cb(void *cls,
+             enum GNUNET_ARM_RequestStatus status,
+             enum GNUNET_ARM_Result result)
 {
   op = NULL;
   /* (0) The request should be "sent" successfully
@@ -182,55 +182,55 @@ arm_start_cb (void *cls,
    * by itself).
    * ARM API should report that ARM service is starting.
    */
-  GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK);
-  GNUNET_break (phase == 0);
-  LOG ("Sent 'START' request for arm to ARM %s\n",
-       (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully");
-  GNUNET_break (result == GNUNET_ARM_RESULT_STARTING);
+  GNUNET_break(status == GNUNET_ARM_REQUEST_SENT_OK);
+  GNUNET_break(phase == 0);
+  LOG("Sent 'START' request for arm to ARM %s\n",
+      (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully");
+  GNUNET_break(result == GNUNET_ARM_RESULT_STARTING);
   phase++;
 }
 
 
 static void
-do_shutdown (void *cls)
+do_shutdown(void *cls)
 {
   if (NULL != op)
-  {
-    GNUNET_ARM_operation_cancel (op);
-    op = NULL;
-  }
+    {
+      GNUNET_ARM_operation_cancel(op);
+      op = NULL;
+    }
   if (NULL != arm)
-  {
-    GNUNET_ARM_disconnect (arm);
-    arm = NULL;
-  }
+    {
+      GNUNET_ARM_disconnect(arm);
+      arm = NULL;
+    }
 }
 
 
 static void
-task (void *cls,
-      char *const *args,
-      const char *cfgfile,
-      const struct GNUNET_CONFIGURATION_Handle *c)
+task(void *cls,
+     char *const *args,
+     const char *cfgfile,
+     const struct GNUNET_CONFIGURATION_Handle *c)
 {
   cfg = c;
-  arm = GNUNET_ARM_connect (cfg,
-                            &arm_conn,
-                            NULL);
+  arm = GNUNET_ARM_connect(cfg,
+                           &arm_conn,
+                           NULL);
   if (NULL == arm)
     return;
-  GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
-                                 NULL);
-  op = GNUNET_ARM_request_service_start (arm,
-                                         "arm",
-                                         GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
-                                         &arm_start_cb,
-                                         NULL);
+  GNUNET_SCHEDULER_add_shutdown(&do_shutdown,
+                                NULL);
+  op = GNUNET_ARM_request_service_start(arm,
+                                        "arm",
+                                        GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
+                                        &arm_start_cb,
+                                        NULL);
 }
 
 
 int
-main (int argc, char *argvx[])
+main(int argc, char *argvx[])
 {
   char *const argv[] = {
     "test-arm-api",
@@ -240,13 +240,14 @@ main (int argc, char *argvx[])
   struct GNUNET_GETOPT_CommandLineOption options[] = {
     GNUNET_GETOPT_OPTION_END
   };
-  GNUNET_log_setup ("test-arm-api",
-		    "WARNING",
-		    NULL);
-  GNUNET_assert (GNUNET_OK ==
-		 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
-				     argv, "test-arm-api", "nohelp", options,
-				     &task, NULL));
+
+  GNUNET_log_setup("test-arm-api",
+                   "WARNING",
+                   NULL);
+  GNUNET_assert(GNUNET_OK ==
+                GNUNET_PROGRAM_run((sizeof(argv) / sizeof(char *)) - 1,
+                                   argv, "test-arm-api", "nohelp", options,
+                                   &task, NULL));
   return ok;
 }
 

+ 192 - 194
src/arm/test_exponential_backoff.c

@@ -11,12 +11,12 @@
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      Affero General Public License for more details.
-    
+
      You should have received a copy of the GNU Affero General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
-*/
+ */
 /**
  * @file arm/test_exponential_backoff.c
  * @brief testcase for gnunet-service-arm.c
@@ -27,15 +27,15 @@
 #include "gnunet_util_lib.h"
 #include "gnunet_protocols.h"
 
-#define LOG(...) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
+#define LOG(...) GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
 
 #define LOG_BACKOFF GNUNET_NO
 
-#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
+#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10)
 
 #define SERVICE_TEST_TIMEOUT GNUNET_TIME_UNIT_FOREVER_REL
 
-#define FIVE_MILLISECONDS GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 5)
+#define FIVE_MILLISECONDS GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 5)
 
 #define SERVICE "do-nothing"
 
@@ -74,8 +74,7 @@ static char *killLogFileName;
 /**
  * Context for handling the shutdown of a service.
  */
-struct ShutdownContext
-{
+struct ShutdownContext {
   /**
    * Connection to the service that is being shutdown.
    */
@@ -85,12 +84,11 @@ struct ShutdownContext
    * Task set up to cancel the shutdown request on timeout.
    */
   struct GNUNET_SCHEDULER_Task *cancel_task;
-
 };
 
 
 static void
-kill_task (void *cbData);
+kill_task(void *cbData);
 
 
 /**
@@ -99,9 +97,9 @@ kill_task (void *cbData);
  * @param cls closure
  */
 static void
-service_shutdown_timeout (void *cls)
+service_shutdown_timeout(void *cls)
 {
-  GNUNET_assert (0);
+  GNUNET_assert(0);
 }
 
 
@@ -114,196 +112,196 @@ service_shutdown_timeout (void *cls)
  * @param error error code
  */
 static void
-mq_error_handler (void *cls,
-                  enum GNUNET_MQ_Error error)
+mq_error_handler(void *cls,
+                 enum GNUNET_MQ_Error error)
 {
   struct ShutdownContext *shutdown_ctx = cls;
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Service shutdown complete (MQ error).\n");
-  GNUNET_SCHEDULER_cancel (shutdown_ctx->cancel_task);
-  GNUNET_MQ_destroy (shutdown_ctx->mq);
-  GNUNET_free (shutdown_ctx);
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+             "Service shutdown complete (MQ error).\n");
+  GNUNET_SCHEDULER_cancel(shutdown_ctx->cancel_task);
+  GNUNET_MQ_destroy(shutdown_ctx->mq);
+  GNUNET_free(shutdown_ctx);
 }
 
 
 static void
-kill_task (void *cbData)
+kill_task(void *cbData)
 {
   struct ShutdownContext *shutdown_ctx
-    = GNUNET_new (struct ShutdownContext);
+    = GNUNET_new(struct ShutdownContext);
   struct GNUNET_MQ_Envelope *env;
   struct GNUNET_MessageHeader *msg;
   struct GNUNET_MQ_MessageHandler handlers[] = {
-    GNUNET_MQ_handler_end ()
+    GNUNET_MQ_handler_end()
   };
 
   kt = NULL;
   if (trialCount == 13)
-  {
-    LOG ("Saw enough kills, asking ARM to stop mock service for good\n");
-    GNUNET_ARM_request_service_stop (arm,
-                                     SERVICE,
-                                     NULL,
-                                     NULL);
-    ok = 0;
-    trialCount++;
-    GNUNET_free (shutdown_ctx);
-    return;
-  }
-  shutdown_ctx->mq = GNUNET_CLIENT_connect (cfg,
-                                            SERVICE,
-                                            handlers,
-                                            &mq_error_handler,
-                                            shutdown_ctx);
-  GNUNET_assert (NULL != shutdown_ctx->mq);
+    {
+      LOG("Saw enough kills, asking ARM to stop mock service for good\n");
+      GNUNET_ARM_request_service_stop(arm,
+                                      SERVICE,
+                                      NULL,
+                                      NULL);
+      ok = 0;
+      trialCount++;
+      GNUNET_free(shutdown_ctx);
+      return;
+    }
+  shutdown_ctx->mq = GNUNET_CLIENT_connect(cfg,
+                                           SERVICE,
+                                           handlers,
+                                           &mq_error_handler,
+                                           shutdown_ctx);
+  GNUNET_assert(NULL != shutdown_ctx->mq);
   trialCount++;
-  LOG ("Sending a shutdown request to the mock service\n");
-  env = GNUNET_MQ_msg (msg,
-                       GNUNET_MESSAGE_TYPE_ARM_STOP); /* FIXME: abuse of message type */
-  GNUNET_MQ_send (shutdown_ctx->mq,
-                  env);
+  LOG("Sending a shutdown request to the mock service\n");
+  env = GNUNET_MQ_msg(msg,
+                      GNUNET_MESSAGE_TYPE_ARM_STOP);  /* FIXME: abuse of message type */
+  GNUNET_MQ_send(shutdown_ctx->mq,
+                 env);
   shutdown_ctx->cancel_task
-    = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
-                                    &service_shutdown_timeout,
-                                    shutdown_ctx);
+    = GNUNET_SCHEDULER_add_delayed(TIMEOUT,
+                                   &service_shutdown_timeout,
+                                   shutdown_ctx);
 }
 
 
 static void
-trigger_disconnect (void *cls)
+trigger_disconnect(void *cls)
 {
-  GNUNET_ARM_disconnect (arm);
-  GNUNET_ARM_monitor_stop (mon);
+  GNUNET_ARM_disconnect(arm);
+  GNUNET_ARM_monitor_stop(mon);
   if (NULL != kt)
-  {
-    GNUNET_SCHEDULER_cancel (kt);
-    kt = NULL;
-  }
+    {
+      GNUNET_SCHEDULER_cancel(kt);
+      kt = NULL;
+    }
 }
 
 
 static void
-arm_stop_cb (void *cls,
-	     enum GNUNET_ARM_RequestStatus status,
-	     enum GNUNET_ARM_Result result)
+arm_stop_cb(void *cls,
+            enum GNUNET_ARM_RequestStatus status,
+            enum GNUNET_ARM_Result result)
 {
-  GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK);
-  GNUNET_break (result == GNUNET_ARM_RESULT_STOPPED);
-  LOG ("ARM service stopped\n");
-  GNUNET_SCHEDULER_shutdown ();
+  GNUNET_break(status == GNUNET_ARM_REQUEST_SENT_OK);
+  GNUNET_break(result == GNUNET_ARM_RESULT_STOPPED);
+  LOG("ARM service stopped\n");
+  GNUNET_SCHEDULER_shutdown();
 }
 
 
 static void
-srv_status (void *cls,
-            const char *service,
-            enum GNUNET_ARM_ServiceStatus status)
+srv_status(void *cls,
+           const char *service,
+           enum GNUNET_ARM_ServiceStatus status)
 {
   if (status == GNUNET_ARM_SERVICE_MONITORING_STARTED)
-  {
-    LOG ("ARM monitor started, starting mock service\n");
-    phase++;
-    GNUNET_ARM_request_service_start (arm,
-                                      SERVICE,
-                                      GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
-                                      NULL,
-                                      NULL);
-    return;
-  }
-  if (0 != strcasecmp (service, SERVICE))
+    {
+      LOG("ARM monitor started, starting mock service\n");
+      phase++;
+      GNUNET_ARM_request_service_start(arm,
+                                       SERVICE,
+                                       GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
+                                       NULL,
+                                       NULL);
+      return;
+    }
+  if (0 != strcasecmp(service, SERVICE))
     return; /* not what we care about */
   if (phase == 1)
-  {
-    GNUNET_break (status == GNUNET_ARM_SERVICE_STARTING);
-    GNUNET_break (phase == 1);
-    LOG ("do-nothing is starting\n");
-    phase++;
-    ok = 1;
-    GNUNET_assert (NULL == kt);
-    startedWaitingAt = GNUNET_TIME_absolute_get ();
-    kt = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
-                                       &kill_task,
-                                       NULL);
-  }
-  else if (phase == 2)
-  {
-    /* We passively monitor ARM for status updates. ARM should tell us
-     * when do-nothing dies (no need to run a service upness test ourselves).
-     */
-    if (status == GNUNET_ARM_SERVICE_STARTING)
     {
-      waitedFor = GNUNET_TIME_absolute_get_duration (startedWaitingAt);
-      LOG ("Waited for: %s\n",
-           GNUNET_STRINGS_relative_time_to_string (waitedFor,
-                                                   GNUNET_YES));
-
-      LOG ("do-nothing is starting, killing it...\n");
-      GNUNET_assert (NULL == kt);
-      kt = GNUNET_SCHEDULER_add_now (&kill_task, &ok);
+      GNUNET_break(status == GNUNET_ARM_SERVICE_STARTING);
+      GNUNET_break(phase == 1);
+      LOG("do-nothing is starting\n");
+      phase++;
+      ok = 1;
+      GNUNET_assert(NULL == kt);
+      startedWaitingAt = GNUNET_TIME_absolute_get();
+      kt = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS,
+                                        &kill_task,
+                                        NULL);
     }
-    else if ((status == GNUNET_ARM_SERVICE_STOPPED) && (trialCount == 14))
+  else if (phase == 2)
     {
-      phase++;
-      LOG ("do-nothing stopped working %u times, we are done here\n",
-           (unsigned int) trialCount);
-      GNUNET_ARM_request_service_stop (arm,
-                                       "arm",
-                                       &arm_stop_cb,
-                                       NULL);
+      /* We passively monitor ARM for status updates. ARM should tell us
+       * when do-nothing dies (no need to run a service upness test ourselves).
+       */
+      if (status == GNUNET_ARM_SERVICE_STARTING)
+        {
+          waitedFor = GNUNET_TIME_absolute_get_duration(startedWaitingAt);
+          LOG("Waited for: %s\n",
+              GNUNET_STRINGS_relative_time_to_string(waitedFor,
+                                                     GNUNET_YES));
+
+          LOG("do-nothing is starting, killing it...\n");
+          GNUNET_assert(NULL == kt);
+          kt = GNUNET_SCHEDULER_add_now(&kill_task, &ok);
+        }
+      else if ((status == GNUNET_ARM_SERVICE_STOPPED) && (trialCount == 14))
+        {
+          phase++;
+          LOG("do-nothing stopped working %u times, we are done here\n",
+              (unsigned int)trialCount);
+          GNUNET_ARM_request_service_stop(arm,
+                                          "arm",
+                                          &arm_stop_cb,
+                                          NULL);
+        }
     }
-  }
 }
 
 
 static void
-arm_start_cb (void *cls,
-              enum GNUNET_ARM_RequestStatus status,
-              enum GNUNET_ARM_Result result)
+arm_start_cb(void *cls,
+             enum GNUNET_ARM_RequestStatus status,
+             enum GNUNET_ARM_Result result)
 {
-  GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK);
-  GNUNET_break (result == GNUNET_ARM_RESULT_STARTING);
-  GNUNET_break (phase == 0);
-  LOG ("Sent 'START' request for arm to ARM %s\n",
-       (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully");
+  GNUNET_break(status == GNUNET_ARM_REQUEST_SENT_OK);
+  GNUNET_break(result == GNUNET_ARM_RESULT_STARTING);
+  GNUNET_break(phase == 0);
+  LOG("Sent 'START' request for arm to ARM %s\n",
+      (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully");
 }
 
 
 static void
-task (void *cls,
-      char *const *args,
-      const char *cfgfile,
-      const struct GNUNET_CONFIGURATION_Handle *c)
+task(void *cls,
+     char *const *args,
+     const char *cfgfile,
+     const struct GNUNET_CONFIGURATION_Handle *c)
 {
   cfg = c;
-  arm = GNUNET_ARM_connect (cfg, NULL, NULL);
+  arm = GNUNET_ARM_connect(cfg, NULL, NULL);
   if (NULL == arm)
-  {
-    GNUNET_break (0);
-    return;
-  }
-  mon = GNUNET_ARM_monitor_start (cfg,
-                                  &srv_status,
-                                  NULL);
-  if (NULL == mon)
-  {
-    GNUNET_break (0);
-    GNUNET_ARM_disconnect (arm);
-    arm = NULL;
-    return;
-  }
-  GNUNET_ARM_request_service_start (arm,
-                                    "arm",
-                                    GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
-                                    &arm_start_cb,
-                                    NULL);
-  GNUNET_SCHEDULER_add_shutdown (&trigger_disconnect,
+    {
+      GNUNET_break(0);
+      return;
+    }
+  mon = GNUNET_ARM_monitor_start(cfg,
+                                 &srv_status,
                                  NULL);
+  if (NULL == mon)
+    {
+      GNUNET_break(0);
+      GNUNET_ARM_disconnect(arm);
+      arm = NULL;
+      return;
+    }
+  GNUNET_ARM_request_service_start(arm,
+                                   "arm",
+                                   GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
+                                   &arm_start_cb,
+                                   NULL);
+  GNUNET_SCHEDULER_add_shutdown(&trigger_disconnect,
+                                NULL);
 }
 
 
 static int
-check ()
+check()
 {
   char *const argv[] = {
     "test-exponential-backoff",
@@ -315,14 +313,14 @@ check ()
   };
 
   /* Running ARM  and running the do_nothing task */
-  GNUNET_assert (GNUNET_OK ==
-		 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
-				     argv,
-                                     "test-exponential-backoff",
-				     "nohelp",
-                                     options,
-                                     &task,
-                                     NULL));
+  GNUNET_assert(GNUNET_OK ==
+                GNUNET_PROGRAM_run((sizeof(argv) / sizeof(char *)) - 1,
+                                   argv,
+                                   "test-exponential-backoff",
+                                   "nohelp",
+                                   options,
+                                   &task,
+                                   NULL));
   return ok;
 }
 
@@ -336,47 +334,47 @@ check ()
 
 
 static int
-init ()
+init()
 {
   struct GNUNET_CONFIGURATION_Handle *cfg;
   char pwd[PATH_MAX];
   char *binary;
 
-  cfg = GNUNET_CONFIGURATION_create ();
-  if (GNUNET_OK != GNUNET_CONFIGURATION_parse (cfg,
-                                               "test_arm_api_data.conf"))
-  {
-    GNUNET_CONFIGURATION_destroy (cfg);
-    return GNUNET_SYSERR;
-  }
-  if (NULL == getcwd (pwd, PATH_MAX))
-    return GNUNET_SYSERR;
-  GNUNET_assert (0 < GNUNET_asprintf (&binary,
-                                      "%s/%s",
-                                      pwd,
-                                      BINARY));
-  GNUNET_CONFIGURATION_set_value_string (cfg,
-                                         SERVICE,
-                                         "BINARY",
-                                         binary);
-  GNUNET_free (binary);
-  if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg,
-                                               CFGFILENAME))
-  {
-    GNUNET_CONFIGURATION_destroy (cfg);
+  cfg = GNUNET_CONFIGURATION_create();
+  if (GNUNET_OK != GNUNET_CONFIGURATION_parse(cfg,
+                                              "test_arm_api_data.conf"))
+    {
+      GNUNET_CONFIGURATION_destroy(cfg);
+      return GNUNET_SYSERR;
+    }
+  if (NULL == getcwd(pwd, PATH_MAX))
     return GNUNET_SYSERR;
-  }
-  GNUNET_CONFIGURATION_destroy (cfg);
+  GNUNET_assert(0 < GNUNET_asprintf(&binary,
+                                    "%s/%s",
+                                    pwd,
+                                    BINARY));
+  GNUNET_CONFIGURATION_set_value_string(cfg,
+                                        SERVICE,
+                                        "BINARY",
+                                        binary);
+  GNUNET_free(binary);
+  if (GNUNET_OK != GNUNET_CONFIGURATION_write(cfg,
+                                              CFGFILENAME))
+    {
+      GNUNET_CONFIGURATION_destroy(cfg);
+      return GNUNET_SYSERR;
+    }
+  GNUNET_CONFIGURATION_destroy(cfg);
 
 #if LOG_BACKOFF
-  killLogFileName = GNUNET_DISK_mktemp ("exponential-backoff-waiting.log");
-  if (NULL == (killLogFilePtr = fopen (killLogFileName,
-                                       "w")))
+  killLogFileName = GNUNET_DISK_mktemp("exponential-backoff-waiting.log");
+  if (NULL == (killLogFilePtr = fopen(killLogFileName,
+                                      "w")))
     {
-      GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
-                                "fopen",
-				killLogFileName);
-      GNUNET_free (killLogFileName);
+      GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING,
+                               "fopen",
+                               killLogFileName);
+      GNUNET_free(killLogFileName);
       return GNUNET_SYSERR;
     }
 #endif
@@ -385,29 +383,29 @@ init ()
 
 
 static void
-houseKeep ()
+houseKeep()
 {
 #if LOG_BACKOFF
-  GNUNET_assert (0 == fclose (killLogFilePtr));
-  GNUNET_free (killLogFileName);
+  GNUNET_assert(0 == fclose(killLogFilePtr));
+  GNUNET_free(killLogFileName);
 #endif
-  (void) unlink (CFGFILENAME);
+  (void)unlink(CFGFILENAME);
 }
 
 
 int
-main (int argc, char *argv[])
+main(int argc, char *argv[])
 {
   int ret;
 
-  GNUNET_log_setup ("test-exponential-backoff",
-		    "WARNING",
-		    NULL);
+  GNUNET_log_setup("test-exponential-backoff",
+                   "WARNING",
+                   NULL);
 
-  if (GNUNET_OK != init ())
+  if (GNUNET_OK != init())
     return 1;
-  ret = check ();
-  houseKeep ();
+  ret = check();
+  houseKeep();
   return ret;
 }
 

+ 126 - 126
src/arm/test_gnunet_service_arm.c

@@ -11,12 +11,12 @@
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      Affero General Public License for more details.
-    
+
      You should have received a copy of the GNU Affero General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
-*/
+ */
 /**
  * @file arm/test_gnunet_service_arm.c
  * @brief testcase for gnunet-service-arm.c; tests ARM by making it start the resolver
@@ -34,9 +34,9 @@
  * (by checking if running before starting, so really this time is always waited on
  * startup (annoying)).
  */
-#define START_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 50)
+#define START_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 50)
 
-#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
+#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10)
 
 
 static int ret = 1;
@@ -51,141 +51,141 @@ static const char hostname[] = "www.gnu.org"; /* any domain should do */
 
 
 static void
-trigger_disconnect (void *cls)
+trigger_disconnect(void *cls)
 {
-  GNUNET_ARM_disconnect (arm);
+  GNUNET_ARM_disconnect(arm);
   arm = NULL;
 }
 
 
 static void
-arm_stop_cb (void *cls,
-	     enum GNUNET_ARM_RequestStatus status,
-	     enum GNUNET_ARM_Result result)
+arm_stop_cb(void *cls,
+            enum GNUNET_ARM_RequestStatus status,
+            enum GNUNET_ARM_Result result)
 {
-  GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK);
-  GNUNET_break (result == GNUNET_ARM_RESULT_STOPPED);
+  GNUNET_break(status == GNUNET_ARM_REQUEST_SENT_OK);
+  GNUNET_break(result == GNUNET_ARM_RESULT_STOPPED);
   if (result != GNUNET_ARM_RESULT_STOPPED)
-  {
-    GNUNET_break (0);
-    ret = 4;
-  }
-  GNUNET_SCHEDULER_add_now (&trigger_disconnect, NULL);
+    {
+      GNUNET_break(0);
+      ret = 4;
+    }
+  GNUNET_SCHEDULER_add_now(&trigger_disconnect, NULL);
 }
 
 
 static void
-service_list (void *cls,
-	      enum GNUNET_ARM_RequestStatus rs,
-	      unsigned int count,
-              const char *const*list)
+service_list(void *cls,
+             enum GNUNET_ARM_RequestStatus rs,
+             unsigned int count,
+             const char *const*list)
 {
   unsigned int i;
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-	      "%u services are are currently running\n",
-	      count);
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+             "%u services are are currently running\n",
+             count);
   if (GNUNET_ARM_REQUEST_SENT_OK != rs)
     goto stop_arm;
-  for (i=0;i<count;i++)
-  {
-    if (0 == strcasecmp (list[i],
-                         "resolver (gnunet-service-resolver)"))
+  for (i = 0; i < count; i++)
     {
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                  "Got service list, now stopping arm\n");
-      ret = 0;
+      if (0 == strcasecmp(list[i],
+                          "resolver (gnunet-service-resolver)"))
+        {
+          GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+                     "Got service list, now stopping arm\n");
+          ret = 0;
+        }
     }
-  }
 
- stop_arm:
-  GNUNET_ARM_request_service_stop (arm,
-                                   "arm",
-                                   &arm_stop_cb,
-                                   NULL);
+stop_arm:
+  GNUNET_ARM_request_service_stop(arm,
+                                  "arm",
+                                  &arm_stop_cb,
+                                  NULL);
 }
 
 
 static void
-hostname_resolve_cb (void *cls,
-                     const struct sockaddr *addr,
-                     socklen_t addrlen)
+hostname_resolve_cb(void *cls,
+                    const struct sockaddr *addr,
+                    socklen_t addrlen)
 {
   if ((0 == ret) || (4 == ret) || (1 == resolved_ok))
     return;
   if (NULL == addr)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "Failed to resolve hostname!\n");
-    GNUNET_break (0);
-    ret = 3;
-    GNUNET_ARM_request_service_stop (arm,
-                                     "arm",
-                                     &arm_stop_cb,
-                                     NULL);
-    return;
-  }
+    {
+      GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
+                 "Failed to resolve hostname!\n");
+      GNUNET_break(0);
+      ret = 3;
+      GNUNET_ARM_request_service_stop(arm,
+                                      "arm",
+                                      &arm_stop_cb,
+                                      NULL);
+      return;
+    }
   if (0 == asked_for_a_list)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "Resolved hostname, now checking the service list\n");
-    GNUNET_ARM_request_service_list (arm,
-                                     &service_list,
-                                     NULL);
-    asked_for_a_list = 1;
-    resolved_ok = 1;
-  }
+    {
+      GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+                 "Resolved hostname, now checking the service list\n");
+      GNUNET_ARM_request_service_list(arm,
+                                      &service_list,
+                                      NULL);
+      asked_for_a_list = 1;
+      resolved_ok = 1;
+    }
 }
 
 
 static void
-arm_start_cb (void *cls,
-	      enum GNUNET_ARM_RequestStatus status,
-	      enum GNUNET_ARM_Result result)
+arm_start_cb(void *cls,
+             enum GNUNET_ARM_RequestStatus status,
+             enum GNUNET_ARM_Result result)
 {
-  GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK);
-  GNUNET_break (result == GNUNET_ARM_RESULT_STARTING);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Trying to resolve a hostname via the resolver service!\n");
+  GNUNET_break(status == GNUNET_ARM_REQUEST_SENT_OK);
+  GNUNET_break(result == GNUNET_ARM_RESULT_STARTING);
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+             "Trying to resolve a hostname via the resolver service!\n");
   /* connect to the resolver service */
   if (NULL ==
-      GNUNET_RESOLVER_ip_get (hostname,
-			      AF_UNSPEC,
-			      TIMEOUT,
-			      &hostname_resolve_cb,
-			      NULL))
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "Unable initiate connection to resolver service\n");
-    GNUNET_break (0);
-    ret = 2;
-    GNUNET_ARM_request_service_stop (arm,
-                                     "arm",
-                                     &arm_stop_cb,
-                                     NULL);
-  }
+      GNUNET_RESOLVER_ip_get(hostname,
+                             AF_UNSPEC,
+                             TIMEOUT,
+                             &hostname_resolve_cb,
+                             NULL))
+    {
+      GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
+                 "Unable initiate connection to resolver service\n");
+      GNUNET_break(0);
+      ret = 2;
+      GNUNET_ARM_request_service_stop(arm,
+                                      "arm",
+                                      &arm_stop_cb,
+                                      NULL);
+    }
 }
 
 
 static void
-run (void *cls,
-     char *const *args,
-     const char *cfgfile,
-     const struct GNUNET_CONFIGURATION_Handle *c)
+run(void *cls,
+    char *const *args,
+    const char *cfgfile,
+    const struct GNUNET_CONFIGURATION_Handle *c)
 {
-  arm = GNUNET_ARM_connect (c,
-                            NULL,
-                            NULL);
-  GNUNET_ARM_request_service_start (arm,
-                                    "arm",
-                                    GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
-                                    &arm_start_cb,
-                                    NULL);
+  arm = GNUNET_ARM_connect(c,
+                           NULL,
+                           NULL);
+  GNUNET_ARM_request_service_start(arm,
+                                   "arm",
+                                   GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
+                                   &arm_start_cb,
+                                   NULL);
 }
 
 
 int
-main (int argc, char *av[])
+main(int argc, char *av[])
 {
   static char *const argv[] = {
     "test-gnunet-service-arm",
@@ -203,27 +203,27 @@ main (int argc, char *av[])
     struct addrinfo *ai;
     int ret;
 
-    if (0 != (ret = getaddrinfo (hostname, NULL, NULL, &ai)))
-    {
-      fprintf (stderr,
-               "Failed to resolve `%s', testcase not run.\n",
-               hostname);
-      return 77;
-    }
-    freeaddrinfo (ai);
+    if (0 != (ret = getaddrinfo(hostname, NULL, NULL, &ai)))
+      {
+        fprintf(stderr,
+                "Failed to resolve `%s', testcase not run.\n",
+                hostname);
+        return 77;
+      }
+    freeaddrinfo(ai);
   }
 #elif HAVE_GETHOSTBYNAME2
   {
     struct hostent *host;
 
-    host = gethostbyname2 (hostname, AF_INET);
+    host = gethostbyname2(hostname, AF_INET);
     if (NULL == host)
-      host = gethostbyname2 (hostname, AF_INET6);
+      host = gethostbyname2(hostname, AF_INET6);
     if (NULL == host)
       {
-        fprintf (stderr,
-                 "Failed to resolve `%s', testcase not run.\n",
-                 hostname);
+        fprintf(stderr,
+                "Failed to resolve `%s', testcase not run.\n",
+                hostname);
         return 77;
       }
   }
@@ -231,34 +231,34 @@ main (int argc, char *av[])
   {
     struct hostent *host;
 
-    host = gethostbyname (hostname);
+    host = gethostbyname(hostname);
     if (NULL == host)
       {
-        fprintf (stderr,
-                 "Failed to resolve `%s', testcase not run.\n",
-                 hostname);
+        fprintf(stderr,
+                "Failed to resolve `%s', testcase not run.\n",
+                hostname);
         return 77;
       }
   }
 #else
-  fprintf (stderr,
-           "libc fails to have resolver function, testcase not run.\n");
+  fprintf(stderr,
+          "libc fails to have resolver function, testcase not run.\n");
   return 77;
 #endif
-  GNUNET_log_setup ("test-gnunet-service-arm",
-		    "WARNING",
-		    NULL);
-  GNUNET_break (GNUNET_OK ==
-		GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
-				    argv, "test-gnunet-service-arm",
-				    "nohelp", options,
-                                    &run, NULL));
+  GNUNET_log_setup("test-gnunet-service-arm",
+                   "WARNING",
+                   NULL);
+  GNUNET_break(GNUNET_OK ==
+               GNUNET_PROGRAM_run((sizeof(argv) / sizeof(char *)) - 1,
+                                  argv, "test-gnunet-service-arm",
+                                  "nohelp", options,
+                                  &run, NULL));
   if (0 != ret)
-  {
-    fprintf (stderr,
-             "Test failed with error code %d\n",
-             ret);
-  }
+    {
+      fprintf(stderr,
+              "Test failed with error code %d\n",
+              ret);
+    }
   return ret;
 }
 

+ 518 - 505
src/ats-tests/ats-testing-experiment.c

@@ -1,19 +1,19 @@
 /*
- This file is part of GNUnet.
- Copyright (C) 2010-2013 GNUnet e.V.
+   This file is part of GNUnet.
+   Copyright (C) 2010-2013 GNUnet e.V.
 
- GNUnet is free software: you can redistribute it and/or modify it
- under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License,
- or (at your option) any later version.
+   GNUnet is free software: you can redistribute it and/or modify it
+   under the terms of the GNU Affero General Public License as published
+   by the Free Software Foundation, either version 3 of the License,
+   or (at your option) any later version.
 
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- Affero General Public License for more details.
+   GNUnet is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Affero General Public License for more details.
 
- You should have received a copy of the GNU Affero General Public License
- along with this program.  If not, see <http://www.gnu.org/licenses/>.
+   You should have received a copy of the GNU Affero General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
  */
@@ -28,29 +28,35 @@
 #include "ats-testing.h"
 
 const char *
-print_op (enum OperationType op)
+print_op(enum OperationType op)
 {
-  switch (op) {
+  switch (op)
+    {
     case START_SEND:
       return "START_SEND";
+
     case STOP_SEND:
       return "STOP_SEND";
+
     case START_PREFERENCE:
       return "START_PREFERENCE";
+
     case STOP_PREFERENCE:
       return "STOP_PREFERENCE";
+
     default:
       break;
-  }
+    }
   return "";
 }
 
 
 static struct Experiment *
-create_experiment ()
+create_experiment()
 {
   struct Experiment *e;
-  e = GNUNET_new (struct Experiment);
+
+  e = GNUNET_new(struct Experiment);
   e->name = NULL;
   e->num_masters = 0;
   e->num_slaves = 0;
@@ -60,7 +66,7 @@ create_experiment ()
 }
 
 static void
-free_experiment (struct Experiment *e)
+free_experiment(struct Experiment *e)
 {
   struct Episode *cur;
   struct Episode *next;
@@ -69,28 +75,28 @@ free_experiment (struct Experiment *e)
 
   next = e->start;
   for (cur = next; NULL != cur; cur = next)
-  {
-    next = cur->next;
-
-    next_o = cur->head;
-    for (cur_o = next_o; NULL != cur_o; cur_o = next_o)
     {
-      next_o = cur_o->next;
-      GNUNET_free (cur_o);
+      next = cur->next;
+
+      next_o = cur->head;
+      for (cur_o = next_o; NULL != cur_o; cur_o = next_o)
+        {
+          next_o = cur_o->next;
+          GNUNET_free(cur_o);
+        }
+      GNUNET_free(cur);
     }
-    GNUNET_free (cur);
-  }
 
-  GNUNET_free_non_null (e->name);
-  GNUNET_free_non_null (e->cfg_file);
-  GNUNET_free (e);
+  GNUNET_free_non_null(e->name);
+  GNUNET_free_non_null(e->cfg_file);
+  GNUNET_free(e);
 }
 
 
 static int
-load_episode (struct Experiment *e,
-              struct Episode *cur,
-              struct GNUNET_CONFIGURATION_Handle *cfg)
+load_episode(struct Experiment *e,
+             struct Episode *cur,
+             struct GNUNET_CONFIGURATION_Handle *cfg)
 {
   struct GNUNET_ATS_TEST_Operation *o;
   char *sec_name;
@@ -100,272 +106,272 @@ load_episode (struct Experiment *e,
   char *pref;
   int op_counter = 0;
 
-  fprintf (stderr, "Parsing episode %u\n",cur->id);
-  GNUNET_asprintf (&sec_name, "episode-%u", cur->id);
+  fprintf(stderr, "Parsing episode %u\n", cur->id);
+  GNUNET_asprintf(&sec_name, "episode-%u", cur->id);
 
   while (1)
-  {
-    /* Load operation */
-    GNUNET_asprintf (&op_name, "op-%u-operation", op_counter);
-    if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg,
-        sec_name, op_name, &op))
     {
-      GNUNET_free (op_name);
-      break;
-    }
-    o = GNUNET_new (struct GNUNET_ATS_TEST_Operation);
-    /* operations = set_rate, start_send, stop_send, set_preference */
-    if (0 == strcmp (op, "start_send"))
-    {
-      o->type = START_SEND;
-    }
-    else if (0 == strcmp (op, "stop_send"))
-    {
-      o->type = STOP_SEND;
-    }
-    else if (0 == strcmp (op, "start_preference"))
-    {
-      o->type = START_PREFERENCE;
-    }
-    else if (0 == strcmp (op, "stop_preference"))
-    {
-      o->type = STOP_PREFERENCE;
-    }
-    else
-    {
-      fprintf (stderr, "Invalid operation %u `%s' in episode %u\n",
-          op_counter, op, cur->id);
-      GNUNET_free (op);
-      GNUNET_free (op_name);
-      GNUNET_free (o);
-      GNUNET_free (sec_name);
-      return GNUNET_SYSERR;
-    }
-    GNUNET_free (op_name);
-
-    /* Get source */
-    GNUNET_asprintf(&op_name, "op-%u-src", op_counter);
-    if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
-        sec_name, op_name, &o->src_id))
-    {
-      fprintf (stderr, "Missing src in operation %u `%s' in episode %u\n",
-          op_counter, op, cur->id);
-      GNUNET_free (op);
-      GNUNET_free (op_name);
-      GNUNET_free (o);
-      GNUNET_free (sec_name);
-      return GNUNET_SYSERR;
-    }
-    if (o->src_id > (e->num_masters - 1))
-    {
-      fprintf (stderr, "Invalid src %llu in operation %u `%s' in episode %u\n",
-          o->src_id, op_counter, op, cur->id);
-      GNUNET_free (op);
-      GNUNET_free (op_name);
-      GNUNET_free (o);
-      GNUNET_free (sec_name);
-      return GNUNET_SYSERR;
-    }
-    GNUNET_free (op_name);
-
-    /* Get destination */
-    GNUNET_asprintf(&op_name, "op-%u-dest", op_counter);
-    if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
-        sec_name, op_name, &o->dest_id))
-    {
-      fprintf (stderr, "Missing src in operation %u `%s' in episode %u\n",
-          op_counter, op, cur->id);
-      GNUNET_free (op);
-      GNUNET_free (op_name);
-      GNUNET_free (o);
-      GNUNET_free (sec_name);
-      return GNUNET_SYSERR;
-    }
-    if (o->dest_id > (e->num_slaves - 1))
-    {
-      fprintf (stderr, "Invalid destination %llu in operation %u `%s' in episode %u\n",
-          o->dest_id, op_counter, op, cur->id);
-      GNUNET_free (op);
-      GNUNET_free (op_name);
-      GNUNET_free (o);
-      GNUNET_free (sec_name);
-      return GNUNET_SYSERR;
-    }
-    GNUNET_free (op_name);
-
-    GNUNET_asprintf(&op_name, "op-%u-type", op_counter);
-    if ( (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_string(cfg,
-            sec_name, op_name, &type)) &&
-         (STOP_SEND != o->type) &&
-         (STOP_PREFERENCE != o->type) )
-    {
-      /* Load arguments for set_rate, start_send, set_preference */
-      if (0 == strcmp (type, "constant"))
-      {
-        o->gen_type = GNUNET_ATS_TEST_TG_CONSTANT;
-      }
-      else if (0 == strcmp (type, "linear"))
-      {
-        o->gen_type = GNUNET_ATS_TEST_TG_LINEAR;
-      }
-      else if (0 == strcmp (type, "sinus"))
-      {
-        o->gen_type = GNUNET_ATS_TEST_TG_SINUS;
-      }
-      else if (0 == strcmp (type, "random"))
-      {
-        o->gen_type = GNUNET_ATS_TEST_TG_RANDOM;
-      }
+      /* Load operation */
+      GNUNET_asprintf(&op_name, "op-%u-operation", op_counter);
+      if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg,
+                                                                 sec_name, op_name, &op))
+        {
+          GNUNET_free(op_name);
+          break;
+        }
+      o = GNUNET_new(struct GNUNET_ATS_TEST_Operation);
+      /* operations = set_rate, start_send, stop_send, set_preference */
+      if (0 == strcmp(op, "start_send"))
+        {
+          o->type = START_SEND;
+        }
+      else if (0 == strcmp(op, "stop_send"))
+        {
+          o->type = STOP_SEND;
+        }
+      else if (0 == strcmp(op, "start_preference"))
+        {
+          o->type = START_PREFERENCE;
+        }
+      else if (0 == strcmp(op, "stop_preference"))
+        {
+          o->type = STOP_PREFERENCE;
+        }
       else
-      {
-        fprintf (stderr, "Invalid type %u `%s' in episode %u\n",
-            op_counter, op, cur->id);
-        GNUNET_free (type);
-        GNUNET_free (op);
-        GNUNET_free (op_name);
-        GNUNET_free (sec_name);
-        GNUNET_free (o);
-        return GNUNET_SYSERR;
-      }
-      GNUNET_free (op_name);
-
-      /* Get base rate */
-      GNUNET_asprintf(&op_name, "op-%u-base-rate", op_counter);
-      if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
-          sec_name, op_name, &o->base_rate))
-      {
-        fprintf (stderr, "Missing base rate in operation %u `%s' in episode %u\n",
-            op_counter, op, cur->id);
-        GNUNET_free (type);
-        GNUNET_free (op);
-        GNUNET_free (op_name);
-        GNUNET_free (sec_name);
-        GNUNET_free (o);
-        return GNUNET_SYSERR;
-      }
-      GNUNET_free (op_name);
-
-      /* Get max rate */
-      GNUNET_asprintf(&op_name, "op-%u-max-rate", op_counter);
-      if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
-          sec_name, op_name, &o->max_rate))
-      {
-        if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) ||
-            (GNUNET_ATS_TEST_TG_RANDOM == o->gen_type) ||
-            (GNUNET_ATS_TEST_TG_SINUS == o->gen_type))
         {
-          fprintf (stderr, "Missing max rate in operation %u `%s' in episode %u\n",
-              op_counter, op, cur->id);
-          GNUNET_free (type);
-          GNUNET_free (op_name);
-          GNUNET_free (op);
-          GNUNET_free (o);
-          GNUNET_free (sec_name);
+          fprintf(stderr, "Invalid operation %u `%s' in episode %u\n",
+                  op_counter, op, cur->id);
+          GNUNET_free(op);
+          GNUNET_free(op_name);
+          GNUNET_free(o);
+          GNUNET_free(sec_name);
           return GNUNET_SYSERR;
         }
-      }
-      GNUNET_free (op_name);
-
-      /* Get period */
-      GNUNET_asprintf(&op_name, "op-%u-period", op_counter);
-      if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
-          sec_name, op_name, &o->period))
-      {
-        o->period = cur->duration;
-      }
-      GNUNET_free (op_name);
-
-      if (START_PREFERENCE == o->type)
-      {
-          /* Get frequency */
-          GNUNET_asprintf(&op_name, "op-%u-frequency", op_counter);
-          if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
-              sec_name, op_name, &o->frequency))
-          {
-              fprintf (stderr, "Missing frequency in operation %u `%s' in episode %u\n",
+      GNUNET_free(op_name);
+
+      /* Get source */
+      GNUNET_asprintf(&op_name, "op-%u-src", op_counter);
+      if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg,
+                                                                 sec_name, op_name, &o->src_id))
+        {
+          fprintf(stderr, "Missing src in operation %u `%s' in episode %u\n",
                   op_counter, op, cur->id);
-              GNUNET_free (type);
-              GNUNET_free (op_name);
-              GNUNET_free (op);
-              GNUNET_free (o);
-              GNUNET_free (sec_name);
-              return GNUNET_SYSERR;
-          }
-          GNUNET_free (op_name);
-
-          /* Get preference */
-          GNUNET_asprintf(&op_name, "op-%u-pref", op_counter);
-          if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
-              sec_name, op_name, &pref))
-          {
-              fprintf (stderr, "Missing preference in operation %u `%s' in episode %u\n",
+          GNUNET_free(op);
+          GNUNET_free(op_name);
+          GNUNET_free(o);
+          GNUNET_free(sec_name);
+          return GNUNET_SYSERR;
+        }
+      if (o->src_id > (e->num_masters - 1))
+        {
+          fprintf(stderr, "Invalid src %llu in operation %u `%s' in episode %u\n",
+                  o->src_id, op_counter, op, cur->id);
+          GNUNET_free(op);
+          GNUNET_free(op_name);
+          GNUNET_free(o);
+          GNUNET_free(sec_name);
+          return GNUNET_SYSERR;
+        }
+      GNUNET_free(op_name);
+
+      /* Get destination */
+      GNUNET_asprintf(&op_name, "op-%u-dest", op_counter);
+      if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg,
+                                                                 sec_name, op_name, &o->dest_id))
+        {
+          fprintf(stderr, "Missing src in operation %u `%s' in episode %u\n",
                   op_counter, op, cur->id);
-              GNUNET_free (type);
-              GNUNET_free (op_name);
-              GNUNET_free (op);
-              GNUNET_free_non_null (pref);
-              GNUNET_free (o);
-              GNUNET_free (sec_name);
-              return GNUNET_SYSERR;
-          }
+          GNUNET_free(op);
+          GNUNET_free(op_name);
+          GNUNET_free(o);
+          GNUNET_free(sec_name);
+          return GNUNET_SYSERR;
+        }
+      if (o->dest_id > (e->num_slaves - 1))
+        {
+          fprintf(stderr, "Invalid destination %llu in operation %u `%s' in episode %u\n",
+                  o->dest_id, op_counter, op, cur->id);
+          GNUNET_free(op);
+          GNUNET_free(op_name);
+          GNUNET_free(o);
+          GNUNET_free(sec_name);
+          return GNUNET_SYSERR;
+        }
+      GNUNET_free(op_name);
 
-          if (0 == strcmp(pref, "bandwidth"))
-            o->pref_type = GNUNET_ATS_PREFERENCE_BANDWIDTH;
-          else if (0 == strcmp(pref, "latency"))
-            o->pref_type = GNUNET_ATS_PREFERENCE_LATENCY;
+      GNUNET_asprintf(&op_name, "op-%u-type", op_counter);
+      if ((GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_string(cfg,
+                                                                  sec_name, op_name, &type)) &&
+          (STOP_SEND != o->type) &&
+          (STOP_PREFERENCE != o->type))
+        {
+          /* Load arguments for set_rate, start_send, set_preference */
+          if (0 == strcmp(type, "constant"))
+            {
+              o->gen_type = GNUNET_ATS_TEST_TG_CONSTANT;
+            }
+          else if (0 == strcmp(type, "linear"))
+            {
+              o->gen_type = GNUNET_ATS_TEST_TG_LINEAR;
+            }
+          else if (0 == strcmp(type, "sinus"))
+            {
+              o->gen_type = GNUNET_ATS_TEST_TG_SINUS;
+            }
+          else if (0 == strcmp(type, "random"))
+            {
+              o->gen_type = GNUNET_ATS_TEST_TG_RANDOM;
+            }
           else
-          {
-              fprintf (stderr, "Invalid preference in operation %u `%s' in episode %u\n",
-                  op_counter, op, cur->id);
-              GNUNET_free (type);
-              GNUNET_free (op_name);
-              GNUNET_free (op);
-              GNUNET_free_non_null (pref);
-              GNUNET_free (o);
-              GNUNET_free (sec_name);
+            {
+              fprintf(stderr, "Invalid type %u `%s' in episode %u\n",
+                      op_counter, op, cur->id);
+              GNUNET_free(type);
+              GNUNET_free(op);
+              GNUNET_free(op_name);
+              GNUNET_free(sec_name);
+              GNUNET_free(o);
               return GNUNET_SYSERR;
-          }
-          GNUNET_free (pref);
-          GNUNET_free (op_name);
-      }
-    }
+            }
+          GNUNET_free(op_name);
+
+          /* Get base rate */
+          GNUNET_asprintf(&op_name, "op-%u-base-rate", op_counter);
+          if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg,
+                                                                     sec_name, op_name, &o->base_rate))
+            {
+              fprintf(stderr, "Missing base rate in operation %u `%s' in episode %u\n",
+                      op_counter, op, cur->id);
+              GNUNET_free(type);
+              GNUNET_free(op);
+              GNUNET_free(op_name);
+              GNUNET_free(sec_name);
+              GNUNET_free(o);
+              return GNUNET_SYSERR;
+            }
+          GNUNET_free(op_name);
+
+          /* Get max rate */
+          GNUNET_asprintf(&op_name, "op-%u-max-rate", op_counter);
+          if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg,
+                                                                     sec_name, op_name, &o->max_rate))
+            {
+              if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) ||
+                  (GNUNET_ATS_TEST_TG_RANDOM == o->gen_type) ||
+                  (GNUNET_ATS_TEST_TG_SINUS == o->gen_type))
+                {
+                  fprintf(stderr, "Missing max rate in operation %u `%s' in episode %u\n",
+                          op_counter, op, cur->id);
+                  GNUNET_free(type);
+                  GNUNET_free(op_name);
+                  GNUNET_free(op);
+                  GNUNET_free(o);
+                  GNUNET_free(sec_name);
+                  return GNUNET_SYSERR;
+                }
+            }
+          GNUNET_free(op_name);
+
+          /* Get period */
+          GNUNET_asprintf(&op_name, "op-%u-period", op_counter);
+          if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg,
+                                                                   sec_name, op_name, &o->period))
+            {
+              o->period = cur->duration;
+            }
+          GNUNET_free(op_name);
+
+          if (START_PREFERENCE == o->type)
+            {
+              /* Get frequency */
+              GNUNET_asprintf(&op_name, "op-%u-frequency", op_counter);
+              if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg,
+                                                                       sec_name, op_name, &o->frequency))
+                {
+                  fprintf(stderr, "Missing frequency in operation %u `%s' in episode %u\n",
+                          op_counter, op, cur->id);
+                  GNUNET_free(type);
+                  GNUNET_free(op_name);
+                  GNUNET_free(op);
+                  GNUNET_free(o);
+                  GNUNET_free(sec_name);
+                  return GNUNET_SYSERR;
+                }
+              GNUNET_free(op_name);
+
+              /* Get preference */
+              GNUNET_asprintf(&op_name, "op-%u-pref", op_counter);
+              if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg,
+                                                                         sec_name, op_name, &pref))
+                {
+                  fprintf(stderr, "Missing preference in operation %u `%s' in episode %u\n",
+                          op_counter, op, cur->id);
+                  GNUNET_free(type);
+                  GNUNET_free(op_name);
+                  GNUNET_free(op);
+                  GNUNET_free_non_null(pref);
+                  GNUNET_free(o);
+                  GNUNET_free(sec_name);
+                  return GNUNET_SYSERR;
+                }
+
+              if (0 == strcmp(pref, "bandwidth"))
+                o->pref_type = GNUNET_ATS_PREFERENCE_BANDWIDTH;
+              else if (0 == strcmp(pref, "latency"))
+                o->pref_type = GNUNET_ATS_PREFERENCE_LATENCY;
+              else
+                {
+                  fprintf(stderr, "Invalid preference in operation %u `%s' in episode %u\n",
+                          op_counter, op, cur->id);
+                  GNUNET_free(type);
+                  GNUNET_free(op_name);
+                  GNUNET_free(op);
+                  GNUNET_free_non_null(pref);
+                  GNUNET_free(o);
+                  GNUNET_free(sec_name);
+                  return GNUNET_SYSERR;
+                }
+              GNUNET_free(pref);
+              GNUNET_free(op_name);
+            }
+        }
 
-    /* Safety checks */
-    if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) ||
-        (GNUNET_ATS_TEST_TG_SINUS == o->gen_type))
-    {
-      if ((o->max_rate - o->base_rate) > o->base_rate)
-      {
-        /* This will cause an underflow */
-        GNUNET_break (0);
-      }
-      fprintf (stderr, "Selected max rate and base rate cannot be used for desired traffic form!\n");
-    }
+      /* Safety checks */
+      if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) ||
+          (GNUNET_ATS_TEST_TG_SINUS == o->gen_type))
+        {
+          if ((o->max_rate - o->base_rate) > o->base_rate)
+            {
+              /* This will cause an underflow */
+              GNUNET_break(0);
+            }
+          fprintf(stderr, "Selected max rate and base rate cannot be used for desired traffic form!\n");
+        }
 
-    if ((START_SEND == o->type) || (START_PREFERENCE == o->type))
-      fprintf (stderr, "Found operation %u in episode %u: %s [%llu]->[%llu] == %s, %llu -> %llu in %s\n",
-        op_counter, cur->id, print_op (o->type), o->src_id,
-        o->dest_id, (NULL != type) ? type : "",
-        o->base_rate, o->max_rate,
-        GNUNET_STRINGS_relative_time_to_string (o->period, GNUNET_YES));
-    else
-      fprintf (stderr, "Found operation %u in episode %u: %s [%llu]->[%llu]\n",
-        op_counter, cur->id, print_op (o->type), o->src_id, o->dest_id);
+      if ((START_SEND == o->type) || (START_PREFERENCE == o->type))
+        fprintf(stderr, "Found operation %u in episode %u: %s [%llu]->[%llu] == %s, %llu -> %llu in %s\n",
+                op_counter, cur->id, print_op(o->type), o->src_id,
+                o->dest_id, (NULL != type) ? type : "",
+                o->base_rate, o->max_rate,
+                GNUNET_STRINGS_relative_time_to_string(o->period, GNUNET_YES));
+      else
+        fprintf(stderr, "Found operation %u in episode %u: %s [%llu]->[%llu]\n",
+                op_counter, cur->id, print_op(o->type), o->src_id, o->dest_id);
 
-    GNUNET_free_non_null (type);
-    GNUNET_free (op);
+      GNUNET_free_non_null(type);
+      GNUNET_free(op);
 
-    GNUNET_CONTAINER_DLL_insert (cur->head,cur->tail, o);
-    op_counter++;
-  }
-  GNUNET_free (sec_name);
+      GNUNET_CONTAINER_DLL_insert(cur->head, cur->tail, o);
+      op_counter++;
+    }
+  GNUNET_free(sec_name);
 
   return GNUNET_OK;
 }
 
 
 static int
-load_episodes (struct Experiment *e, struct GNUNET_CONFIGURATION_Handle *cfg)
+load_episodes(struct Experiment *e, struct GNUNET_CONFIGURATION_Handle *cfg)
 {
   int e_counter = 0;
   char *sec_name;
@@ -376,373 +382,380 @@ load_episodes (struct Experiment *e, struct GNUNET_CONFIGURATION_Handle *cfg)
   e_counter = 0;
   last = NULL;
   while (1)
-  {
-    GNUNET_asprintf(&sec_name, "episode-%u", e_counter);
-    if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg,
-        sec_name, "duration", &e_duration))
     {
-      GNUNET_free (sec_name);
-      break;
-    }
+      GNUNET_asprintf(&sec_name, "episode-%u", e_counter);
+      if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg,
+                                                               sec_name, "duration", &e_duration))
+        {
+          GNUNET_free(sec_name);
+          break;
+        }
 
-    cur = GNUNET_new (struct Episode);
-    cur->duration = e_duration;
-    cur->id = e_counter;
+      cur = GNUNET_new(struct Episode);
+      cur->duration = e_duration;
+      cur->id = e_counter;
 
-    if (GNUNET_OK != load_episode (e, cur, cfg))
-    {
-      GNUNET_free (sec_name);
-      GNUNET_free (cur);
-      return GNUNET_SYSERR;
-    }
+      if (GNUNET_OK != load_episode(e, cur, cfg))
+        {
+          GNUNET_free(sec_name);
+          GNUNET_free(cur);
+          return GNUNET_SYSERR;
+        }
 
-    fprintf (stderr, "Found episode %u with duration %s \n",
-        e_counter,
-        GNUNET_STRINGS_relative_time_to_string(cur->duration, GNUNET_YES));
-
-    /* Update experiment */
-    e->num_episodes ++;
-    e->total_duration = GNUNET_TIME_relative_add(e->total_duration, cur->duration);
-    /* Put in linked list */
-    if (NULL == last)
-      e->start = cur;
-    else
-    last->next = cur;
-
-    GNUNET_free (sec_name);
-    e_counter ++;
-    last = cur;
-  }
+      fprintf(stderr, "Found episode %u with duration %s \n",
+              e_counter,
+              GNUNET_STRINGS_relative_time_to_string(cur->duration, GNUNET_YES));
+
+      /* Update experiment */
+      e->num_episodes++;
+      e->total_duration = GNUNET_TIME_relative_add(e->total_duration, cur->duration);
+      /* Put in linked list */
+      if (NULL == last)
+        e->start = cur;
+      else
+        last->next = cur;
+
+      GNUNET_free(sec_name);
+      e_counter++;
+      last = cur;
+    }
   return e_counter;
 }
 
 
 static void
-timeout_experiment (void *cls)
+timeout_experiment(void *cls)
 {
   struct Experiment *e = cls;
+
   e->experiment_timeout_task = NULL;
-  fprintf (stderr, "Experiment timeout!\n");
+  fprintf(stderr, "Experiment timeout!\n");
 
   if (NULL != e->episode_timeout_task)
-  {
-    GNUNET_SCHEDULER_cancel (e->episode_timeout_task);
-    e->episode_timeout_task = NULL;
-  }
+    {
+      GNUNET_SCHEDULER_cancel(e->episode_timeout_task);
+      e->episode_timeout_task = NULL;
+    }
 
-  e->e_done_cb (e, GNUNET_TIME_absolute_get_duration(e->start_time),
-      GNUNET_SYSERR);
+  e->e_done_cb(e, GNUNET_TIME_absolute_get_duration(e->start_time),
+               GNUNET_SYSERR);
 }
 
 
 static void
-enforce_start_send (struct GNUNET_ATS_TEST_Operation *op)
+enforce_start_send(struct GNUNET_ATS_TEST_Operation *op)
 {
   struct BenchmarkPeer *peer;
   struct BenchmarkPartner *partner;
 
-  peer = GNUNET_ATS_TEST_get_peer (op->src_id);
+  peer = GNUNET_ATS_TEST_get_peer(op->src_id);
   if (NULL == peer)
-  {
-    GNUNET_break (0);
-    return;
-  }
+    {
+      GNUNET_break(0);
+      return;
+    }
 
-  partner = GNUNET_ATS_TEST_get_partner (op->src_id, op->dest_id);
+  partner = GNUNET_ATS_TEST_get_partner(op->src_id, op->dest_id);
   if (NULL == partner)
-  {
-    GNUNET_break (0);
-    return;
-  }
+    {
+      GNUNET_break(0);
+      return;
+    }
 
-  fprintf (stderr, "Found master %llu slave %llu\n",op->src_id, op->dest_id);
+  fprintf(stderr, "Found master %llu slave %llu\n", op->src_id, op->dest_id);
 
   if (NULL != partner->tg)
-  {
-    fprintf (stderr, "Stopping traffic between master %llu slave %llu\n",op->src_id, op->dest_id);
-    GNUNET_ATS_TEST_generate_traffic_stop(partner->tg);
-    partner->tg = NULL;
-  }
+    {
+      fprintf(stderr, "Stopping traffic between master %llu slave %llu\n", op->src_id, op->dest_id);
+      GNUNET_ATS_TEST_generate_traffic_stop(partner->tg);
+      partner->tg = NULL;
+    }
 
   partner->tg = GNUNET_ATS_TEST_generate_traffic_start(peer, partner,
-      op->gen_type, op->base_rate, op->max_rate, op->period,
-      GNUNET_TIME_UNIT_FOREVER_REL);
+                                                       op->gen_type, op->base_rate, op->max_rate, op->period,
+                                                       GNUNET_TIME_UNIT_FOREVER_REL);
 }
 
 static void
-enforce_stop_send (struct GNUNET_ATS_TEST_Operation *op)
+enforce_stop_send(struct GNUNET_ATS_TEST_Operation *op)
 {
   struct BenchmarkPartner *p;
-  p = GNUNET_ATS_TEST_get_partner (op->src_id, op->dest_id);
+
+  p = GNUNET_ATS_TEST_get_partner(op->src_id, op->dest_id);
   if (NULL == p)
-  {
-    GNUNET_break (0);
-    return;
-  }
+    {
+      GNUNET_break(0);
+      return;
+    }
 
-  fprintf (stderr, "Found master %llu slave %llu\n",op->src_id, op->dest_id);
+  fprintf(stderr, "Found master %llu slave %llu\n", op->src_id, op->dest_id);
 
   if (NULL != p->tg)
-  {
-    fprintf (stderr, "Stopping traffic between master %llu slave %llu\n",
-        op->src_id, op->dest_id);
-    GNUNET_ATS_TEST_generate_traffic_stop(p->tg);
-    p->tg = NULL;
-  }
+    {
+      fprintf(stderr, "Stopping traffic between master %llu slave %llu\n",
+              op->src_id, op->dest_id);
+      GNUNET_ATS_TEST_generate_traffic_stop(p->tg);
+      p->tg = NULL;
+    }
 }
 
 
 static void
-enforce_start_preference (struct GNUNET_ATS_TEST_Operation *op)
+enforce_start_preference(struct GNUNET_ATS_TEST_Operation *op)
 {
   struct BenchmarkPeer *peer;
   struct BenchmarkPartner *partner;
 
-  peer = GNUNET_ATS_TEST_get_peer (op->src_id);
+  peer = GNUNET_ATS_TEST_get_peer(op->src_id);
   if (NULL == peer)
-  {
-    GNUNET_break (0);
-    return;
-  }
+    {
+      GNUNET_break(0);
+      return;
+    }
 
-  partner = GNUNET_ATS_TEST_get_partner (op->src_id, op->dest_id);
+  partner = GNUNET_ATS_TEST_get_partner(op->src_id, op->dest_id);
   if (NULL == partner)
-  {
-    GNUNET_break (0);
-    return;
-  }
+    {
+      GNUNET_break(0);
+      return;
+    }
 
-  fprintf (stderr, "Found master %llu slave %llu\n",op->src_id, op->dest_id);
+  fprintf(stderr, "Found master %llu slave %llu\n", op->src_id, op->dest_id);
 
   if (NULL != partner->pg)
-  {
-    fprintf (stderr, "Stopping traffic between master %llu slave %llu\n",
-        op->src_id, op->dest_id);
-    GNUNET_ATS_TEST_generate_preferences_stop(partner->pg);
-    partner->pg = NULL;
-  }
+    {
+      fprintf(stderr, "Stopping traffic between master %llu slave %llu\n",
+              op->src_id, op->dest_id);
+      GNUNET_ATS_TEST_generate_preferences_stop(partner->pg);
+      partner->pg = NULL;
+    }
 
   partner->pg = GNUNET_ATS_TEST_generate_preferences_start(peer, partner,
-      op->gen_type, op->base_rate, op->max_rate, op->period, op->frequency,
-      op->pref_type);
+                                                           op->gen_type, op->base_rate, op->max_rate, op->period, op->frequency,
+                                                           op->pref_type);
 }
 
 static void
-enforce_stop_preference (struct GNUNET_ATS_TEST_Operation *op)
+enforce_stop_preference(struct GNUNET_ATS_TEST_Operation *op)
 {
   struct BenchmarkPartner *p;
-  p = GNUNET_ATS_TEST_get_partner (op->src_id, op->dest_id);
+
+  p = GNUNET_ATS_TEST_get_partner(op->src_id, op->dest_id);
   if (NULL == p)
-  {
-    GNUNET_break (0);
-    return;
-  }
+    {
+      GNUNET_break(0);
+      return;
+    }
 
-  fprintf (stderr, "Found master %llu slave %llu\n",op->src_id, op->dest_id);
+  fprintf(stderr, "Found master %llu slave %llu\n", op->src_id, op->dest_id);
 
   if (NULL != p->pg)
-  {
-    fprintf (stderr, "Stopping preference between master %llu slave %llu\n",
-        op->src_id, op->dest_id);
-    GNUNET_ATS_TEST_generate_preferences_stop (p->pg);
-    p->pg = NULL;
-  }
+    {
+      fprintf(stderr, "Stopping preference between master %llu slave %llu\n",
+              op->src_id, op->dest_id);
+      GNUNET_ATS_TEST_generate_preferences_stop(p->pg);
+      p->pg = NULL;
+    }
 }
 
-static void enforce_episode (struct Episode *ep)
+static void enforce_episode(struct Episode *ep)
 {
   struct GNUNET_ATS_TEST_Operation *cur;
+
   for (cur = ep->head; NULL != cur; cur = cur->next)
-  {
-
-    fprintf (stderr, "Enforcing operation: %s [%llu]->[%llu] == %llu\n",
-        print_op (cur->type), cur->src_id, cur->dest_id, cur->base_rate);
-    switch (cur->type) {
-      case START_SEND:
-        enforce_start_send (cur);
-        break;
-      case STOP_SEND:
-        enforce_stop_send (cur);
-        break;
-      case START_PREFERENCE:
-        enforce_start_preference (cur);
-        break;
-      case STOP_PREFERENCE:
-        enforce_stop_preference (cur);
-        break;
-      default:
-        break;
+    {
+      fprintf(stderr, "Enforcing operation: %s [%llu]->[%llu] == %llu\n",
+              print_op(cur->type), cur->src_id, cur->dest_id, cur->base_rate);
+      switch (cur->type)
+        {
+        case START_SEND:
+          enforce_start_send(cur);
+          break;
+
+        case STOP_SEND:
+          enforce_stop_send(cur);
+          break;
+
+        case START_PREFERENCE:
+          enforce_start_preference(cur);
+          break;
+
+        case STOP_PREFERENCE:
+          enforce_stop_preference(cur);
+          break;
+
+        default:
+          break;
+        }
     }
-  }
 }
 
 
 static void
-timeout_episode (void *cls)
+timeout_episode(void *cls)
 {
   struct Experiment *e = cls;
 
   e->episode_timeout_task = NULL;
   if (NULL != e->ep_done_cb)
-    e->ep_done_cb (e->cur);
+    e->ep_done_cb(e->cur);
 
   /* Scheduling next */
   e->cur = e->cur->next;
   if (NULL == e->cur)
-  {
-    /* done */
-    fprintf (stderr, "Last episode done!\n");
-    if (NULL != e->experiment_timeout_task)
     {
-      GNUNET_SCHEDULER_cancel (e->experiment_timeout_task);
-      e->experiment_timeout_task = NULL;
+      /* done */
+      fprintf(stderr, "Last episode done!\n");
+      if (NULL != e->experiment_timeout_task)
+        {
+          GNUNET_SCHEDULER_cancel(e->experiment_timeout_task);
+          e->experiment_timeout_task = NULL;
+        }
+      e->e_done_cb(e, GNUNET_TIME_absolute_get_duration(e->start_time), GNUNET_OK);
+      return;
     }
-    e->e_done_cb (e, GNUNET_TIME_absolute_get_duration(e->start_time), GNUNET_OK);
-    return;
-  }
 
-  fprintf (stderr, "Running episode %u with timeout %s\n",
-      e->cur->id,
-      GNUNET_STRINGS_relative_time_to_string(e->cur->duration, GNUNET_YES));
+  fprintf(stderr, "Running episode %u with timeout %s\n",
+          e->cur->id,
+          GNUNET_STRINGS_relative_time_to_string(e->cur->duration, GNUNET_YES));
   enforce_episode(e->cur);
 
-  e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed (e->cur->duration,
-      &timeout_episode, e);
+  e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed(e->cur->duration,
+                                                         &timeout_episode, e);
 }
 
 
 void
-GNUNET_ATS_TEST_experimentation_run (struct Experiment *e,
-    GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb,
-    GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb)
+GNUNET_ATS_TEST_experimentation_run(struct Experiment *e,
+                                    GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb,
+                                    GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb)
 {
-  fprintf (stderr, "Running experiment `%s'  with timeout %s\n", e->name,
-      GNUNET_STRINGS_relative_time_to_string(e->max_duration, GNUNET_YES));
+  fprintf(stderr, "Running experiment `%s'  with timeout %s\n", e->name,
+          GNUNET_STRINGS_relative_time_to_string(e->max_duration, GNUNET_YES));
   e->e_done_cb = e_done_cb;
   e->ep_done_cb = ep_done_cb;
   e->start_time = GNUNET_TIME_absolute_get();
 
   /* Start total time out */
-  e->experiment_timeout_task = GNUNET_SCHEDULER_add_delayed (e->max_duration,
-      &timeout_experiment, e);
+  e->experiment_timeout_task = GNUNET_SCHEDULER_add_delayed(e->max_duration,
+                                                            &timeout_experiment, e);
 
   /* Start */
   e->cur = e->start;
-  fprintf (stderr, "Running episode %u with timeout %s\n",
-      e->cur->id,
-      GNUNET_STRINGS_relative_time_to_string(e->cur->duration, GNUNET_YES));
+  fprintf(stderr, "Running episode %u with timeout %s\n",
+          e->cur->id,
+          GNUNET_STRINGS_relative_time_to_string(e->cur->duration, GNUNET_YES));
   enforce_episode(e->cur);
-  e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed (e->cur->duration,
-      &timeout_episode, e);
-
-
+  e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed(e->cur->duration,
+                                                         &timeout_episode, e);
 }
 
 
 struct Experiment *
-GNUNET_ATS_TEST_experimentation_load (const char *filename)
+GNUNET_ATS_TEST_experimentation_load(const char *filename)
 {
   struct Experiment *e;
   struct GNUNET_CONFIGURATION_Handle *cfg;
+
   e = NULL;
 
   cfg = GNUNET_CONFIGURATION_create();
-  if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, filename))
-  {
-    fprintf (stderr, "Failed to load `%s'\n", filename);
-    GNUNET_CONFIGURATION_destroy (cfg);
-    return NULL;
-  }
+  if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load(cfg, filename))
+    {
+      fprintf(stderr, "Failed to load `%s'\n", filename);
+      GNUNET_CONFIGURATION_destroy(cfg);
+      return NULL;
+    }
 
-  e = create_experiment ();
+  e = create_experiment();
 
   if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "experiment",
-      "name", &e->name))
-  {
-    fprintf (stderr, "Invalid %s", "name");
-    free_experiment (e);
-    return NULL;
-  }
+                                                             "name", &e->name))
+    {
+      fprintf(stderr, "Invalid %s", "name");
+      free_experiment(e);
+      return NULL;
+    }
   else
-    fprintf (stderr, "Experiment name: `%s'\n", e->name);
-
-  if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_filename (cfg, "experiment",
-      "cfg_file", &e->cfg_file))
-  {
-    fprintf (stderr, "Invalid %s", "cfg_file");
-    free_experiment (e);
-    return NULL;
-  }
+    fprintf(stderr, "Experiment name: `%s'\n", e->name);
+
+  if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_filename(cfg, "experiment",
+                                                               "cfg_file", &e->cfg_file))
+    {
+      fprintf(stderr, "Invalid %s", "cfg_file");
+      free_experiment(e);
+      return NULL;
+    }
   else
-    fprintf (stderr, "Experiment name: `%s'\n", e->cfg_file);
+    fprintf(stderr, "Experiment name: `%s'\n", e->cfg_file);
 
   if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, "experiment",
-      "masters", &e->num_masters))
-  {
-    fprintf (stderr, "Invalid %s", "masters");
-    free_experiment (e);
-    return NULL;
-  }
+                                                             "masters", &e->num_masters))
+    {
+      fprintf(stderr, "Invalid %s", "masters");
+      free_experiment(e);
+      return NULL;
+    }
   else
-    fprintf (stderr, "Experiment masters: `%llu'\n",
-        e->num_masters);
+    fprintf(stderr, "Experiment masters: `%llu'\n",
+            e->num_masters);
 
   if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, "experiment",
-      "slaves", &e->num_slaves))
-  {
-    fprintf (stderr, "Invalid %s", "slaves");
-    free_experiment (e);
-    return NULL;
-  }
+                                                             "slaves", &e->num_slaves))
+    {
+      fprintf(stderr, "Invalid %s", "slaves");
+      free_experiment(e);
+      return NULL;
+    }
   else
-    fprintf (stderr, "Experiment slaves: `%llu'\n",
-        e->num_slaves);
+    fprintf(stderr, "Experiment slaves: `%llu'\n",
+            e->num_slaves);
 
   if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, "experiment",
-      "log_freq", &e->log_freq))
-  {
-    fprintf (stderr, "Invalid %s", "log_freq");
-    free_experiment (e);
-    return NULL;
-  }
+                                                           "log_freq", &e->log_freq))
+    {
+      fprintf(stderr, "Invalid %s", "log_freq");
+      free_experiment(e);
+      return NULL;
+    }
   else
-    fprintf (stderr, "Experiment logging frequency: `%s'\n",
-        GNUNET_STRINGS_relative_time_to_string (e->log_freq, GNUNET_YES));
+    fprintf(stderr, "Experiment logging frequency: `%s'\n",
+            GNUNET_STRINGS_relative_time_to_string(e->log_freq, GNUNET_YES));
 
   if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, "experiment",
-      "max_duration", &e->max_duration))
-  {
-    fprintf (stderr, "Invalid %s", "max_duration");
-    free_experiment (e);
-    return NULL;
-  }
+                                                           "max_duration", &e->max_duration))
+    {
+      fprintf(stderr, "Invalid %s", "max_duration");
+      free_experiment(e);
+      return NULL;
+    }
   else
-    fprintf (stderr, "Experiment duration: `%s'\n",
-        GNUNET_STRINGS_relative_time_to_string (e->max_duration, GNUNET_YES));
+    fprintf(stderr, "Experiment duration: `%s'\n",
+            GNUNET_STRINGS_relative_time_to_string(e->max_duration, GNUNET_YES));
 
-  load_episodes (e, cfg);
-  fprintf (stderr, "Loaded %u episodes with total duration %s\n",
-      e->num_episodes,
-      GNUNET_STRINGS_relative_time_to_string (e->total_duration, GNUNET_YES));
+  load_episodes(e, cfg);
+  fprintf(stderr, "Loaded %u episodes with total duration %s\n",
+          e->num_episodes,
+          GNUNET_STRINGS_relative_time_to_string(e->total_duration, GNUNET_YES));
 
-  GNUNET_CONFIGURATION_destroy (cfg);
+  GNUNET_CONFIGURATION_destroy(cfg);
   return e;
 }
 
 void
-GNUNET_ATS_TEST_experimentation_stop (struct Experiment *e)
+GNUNET_ATS_TEST_experimentation_stop(struct Experiment *e)
 {
   if (NULL != e->experiment_timeout_task)
-  {
-    GNUNET_SCHEDULER_cancel (e->experiment_timeout_task);
-    e->experiment_timeout_task = NULL;
-  }
+    {
+      GNUNET_SCHEDULER_cancel(e->experiment_timeout_task);
+      e->experiment_timeout_task = NULL;
+    }
   if (NULL != e->episode_timeout_task)
-  {
-    GNUNET_SCHEDULER_cancel (e->episode_timeout_task);
-    e->episode_timeout_task = NULL;
-  }
-  free_experiment (e);
+    {
+      GNUNET_SCHEDULER_cancel(e->episode_timeout_task);
+      e->episode_timeout_task = NULL;
+    }
+  free_experiment(e);
 }
 
 /* end of file ats-testing-experiment.c*/

Plik diff jest za duży
+ 461 - 466
src/ats-tests/ats-testing-log.c


+ 105 - 91
src/ats-tests/ats-testing-preferences.c

@@ -1,19 +1,19 @@
 /*
- This file is part of GNUnet.
- Copyright (C) 2010-2013 GNUnet e.V.
+   This file is part of GNUnet.
+   Copyright (C) 2010-2013 GNUnet e.V.
 
- GNUnet is free software: you can redistribute it and/or modify it
- under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License,
- or (at your option) any later version.
+   GNUnet is free software: you can redistribute it and/or modify it
+   under the terms of the GNU Affero General Public License as published
+   by the Free Software Foundation, either version 3 of the License,
+   or (at your option) any later version.
 
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- Affero General Public License for more details.
+   GNUnet is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Affero General Public License for more details.
 
- You should have received a copy of the GNU Affero General Public License
- along with this program.  If not, see <http://www.gnu.org/licenses/>.
+   You should have received a copy of the GNU Affero General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
  */
@@ -33,76 +33,82 @@ static struct PreferenceGenerator *pg_tail;
 extern struct GNUNET_ATS_TEST_Topology *top;
 
 static double
-get_preference (struct PreferenceGenerator *pg)
+get_preference(struct PreferenceGenerator *pg)
 {
   struct GNUNET_TIME_Relative time_delta;
   double delta_value;
   double pref_value;
 
   /* Calculate the current preference value */
-  switch (pg->type) {
+  switch (pg->type)
+    {
     case GNUNET_ATS_TEST_TG_CONSTANT:
       pref_value = pg->base_value;
       break;
+
     case GNUNET_ATS_TEST_TG_LINEAR:
       time_delta = GNUNET_TIME_absolute_get_duration(pg->time_start);
       /* Calculate point of time in the current period */
       time_delta.rel_value_us = time_delta.rel_value_us %
-          pg->duration_period.rel_value_us;
-      delta_value = ((double) time_delta.rel_value_us  /
-          pg->duration_period.rel_value_us) * (pg->max_value - pg->base_value);
+                                pg->duration_period.rel_value_us;
+      delta_value = ((double)time_delta.rel_value_us /
+                     pg->duration_period.rel_value_us) * (pg->max_value - pg->base_value);
       if ((pg->max_value < pg->base_value) &&
           ((pg->max_value - pg->base_value) > pg->base_value))
-      {
-        /* This will cause an underflow */
-        GNUNET_break (0);
-      }
+        {
+          /* This will cause an underflow */
+          GNUNET_break(0);
+        }
       pref_value = pg->base_value + delta_value;
       break;
+
     case GNUNET_ATS_TEST_TG_RANDOM:
-      delta_value =  (double) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
-          10000 * (pg->max_value - pg->base_value)) / 10000;
+      delta_value = (double)GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK,
+                                                     10000 * (pg->max_value - pg->base_value)) / 10000;
       pref_value = pg->base_value + delta_value;
       break;
+
     case GNUNET_ATS_TEST_TG_SINUS:
       time_delta = GNUNET_TIME_absolute_get_duration(pg->time_start);
       /* Calculate point of time in the current period */
       time_delta.rel_value_us = time_delta.rel_value_us %
-          pg->duration_period.rel_value_us;
+                                pg->duration_period.rel_value_us;
       if ((pg->max_value - pg->base_value) > pg->base_value)
-      {
-        /* This will cause an underflow for second half of sinus period,
-         * will be detected in general when experiments are loaded */
-        GNUNET_break (0);
-      }
+        {
+          /* This will cause an underflow for second half of sinus period,
+           * will be detected in general when experiments are loaded */
+          GNUNET_break(0);
+        }
       delta_value = (pg->max_value - pg->base_value) *
-          sin ( (2 * M_PI) / ((double) pg->duration_period.rel_value_us) *
-              time_delta.rel_value_us);
+                    sin((2 * M_PI) / ((double)pg->duration_period.rel_value_us) *
+                        time_delta.rel_value_us);
       pref_value = pg->base_value + delta_value;
       break;
+
     default:
       pref_value = 0.0;
       break;
-  }
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Current preference value is %f\n",
-      pref_value);
+    }
+  GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Current preference value is %f\n",
+             pref_value);
   return pref_value;
 }
 
 
 static void
-set_pref_task (void *cls)
+set_pref_task(void *cls)
 {
   struct BenchmarkPartner *p = cls;
   double pref_value;
+
   p->pg->set_task = NULL;
 
-  pref_value = get_preference (p->pg);
+  pref_value = get_preference(p->pg);
 
   GNUNET_log(GNUNET_ERROR_TYPE_INFO,
-      "Setting preference for master [%u] and slave [%u] for %s to %f\n",
-      p->me->no, p->dest->no,
-      GNUNET_ATS_print_preference_type (p->pg->kind), pref_value);
+             "Setting preference for master [%u] and slave [%u] for %s to %f\n",
+             p->me->no, p->dest->no,
+             GNUNET_ATS_print_preference_type(p->pg->kind), pref_value);
 
   GNUNET_ATS_performance_change_preference(p->me->ats_perf_handle,
                                            &p->dest->id,
@@ -110,20 +116,22 @@ set_pref_task (void *cls)
                                            pref_value,
                                            GNUNET_ATS_PREFERENCE_END);
 
-  switch (p->pg->kind) {
+  switch (p->pg->kind)
+    {
     case GNUNET_ATS_PREFERENCE_BANDWIDTH:
       p->pref_bandwidth = pref_value;
       break;
+
     case GNUNET_ATS_PREFERENCE_LATENCY:
       p->pref_delay = pref_value;
       break;
+
     default:
       break;
-  }
-
-  p->pg->set_task = GNUNET_SCHEDULER_add_delayed (p->pg->frequency,
-      set_pref_task, p);
+    }
 
+  p->pg->set_task = GNUNET_SCHEDULER_add_delayed(p->pg->frequency,
+                                                 set_pref_task, p);
 }
 
 
@@ -142,25 +150,25 @@ set_pref_task (void *cls)
  * @return the preference generator
  */
 struct PreferenceGenerator *
-GNUNET_ATS_TEST_generate_preferences_start (struct BenchmarkPeer *src,
-                                            struct BenchmarkPartner *dest,
-                                            enum GeneratorType type,
-                                            unsigned int base_value,
-                                            unsigned int value_rate,
-                                            struct GNUNET_TIME_Relative period,
-                                            struct GNUNET_TIME_Relative frequency,
-                                            enum GNUNET_ATS_PreferenceKind kind)
+GNUNET_ATS_TEST_generate_preferences_start(struct BenchmarkPeer *src,
+                                           struct BenchmarkPartner *dest,
+                                           enum GeneratorType type,
+                                           unsigned int base_value,
+                                           unsigned int value_rate,
+                                           struct GNUNET_TIME_Relative period,
+                                           struct GNUNET_TIME_Relative frequency,
+                                           enum GNUNET_ATS_PreferenceKind kind)
 {
   struct PreferenceGenerator *pg;
 
   if (NULL != dest->pg)
-  {
-    GNUNET_break (0);
-    return NULL;
-  }
+    {
+      GNUNET_break(0);
+      return NULL;
+    }
 
-  pg = GNUNET_new (struct PreferenceGenerator);
-  GNUNET_CONTAINER_DLL_insert (pg_head, pg_tail, pg);
+  pg = GNUNET_new(struct PreferenceGenerator);
+  GNUNET_CONTAINER_DLL_insert(pg_head, pg_tail, pg);
   pg->type = type;
   pg->src = src;
   pg->dest = dest;
@@ -171,58 +179,63 @@ GNUNET_ATS_TEST_generate_preferences_start (struct BenchmarkPeer *src,
   pg->frequency = frequency;
   pg->time_start = GNUNET_TIME_absolute_get();
 
-  switch (type) {
+  switch (type)
+    {
     case GNUNET_ATS_TEST_TG_CONSTANT:
-      GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-                  "Setting up constant preference generator master[%u] `%s' and slave [%u] `%s' max %u Bips\n",
-                  dest->me->no, GNUNET_i2s (&dest->me->id),
-                  dest->dest->no, GNUNET_i2s (&dest->dest->id),
-                  base_value);
+      GNUNET_log(GNUNET_ERROR_TYPE_INFO,
+                 "Setting up constant preference generator master[%u] `%s' and slave [%u] `%s' max %u Bips\n",
+                 dest->me->no, GNUNET_i2s(&dest->me->id),
+                 dest->dest->no, GNUNET_i2s(&dest->dest->id),
+                 base_value);
       break;
+
     case GNUNET_ATS_TEST_TG_LINEAR:
-      GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-                  "Setting up linear preference generator master[%u] `%s' and slave [%u] `%s' min %u Bips max %u Bips\n",
-                  dest->me->no, GNUNET_i2s (&dest->me->id),
-                  dest->dest->no, GNUNET_i2s (&dest->dest->id),
-                  base_value, value_rate);
+      GNUNET_log(GNUNET_ERROR_TYPE_INFO,
+                 "Setting up linear preference generator master[%u] `%s' and slave [%u] `%s' min %u Bips max %u Bips\n",
+                 dest->me->no, GNUNET_i2s(&dest->me->id),
+                 dest->dest->no, GNUNET_i2s(&dest->dest->id),
+                 base_value, value_rate);
       break;
+
     case GNUNET_ATS_TEST_TG_SINUS:
-      GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-                  "Setting up sinus preference generator master[%u] `%s' and slave [%u] `%s' baserate %u Bips, amplitude %u Bps\n",
-                  dest->me->no, GNUNET_i2s (&dest->me->id),
-                  dest->dest->no, GNUNET_i2s (&dest->dest->id),
-                  base_value, value_rate);
+      GNUNET_log(GNUNET_ERROR_TYPE_INFO,
+                 "Setting up sinus preference generator master[%u] `%s' and slave [%u] `%s' baserate %u Bips, amplitude %u Bps\n",
+                 dest->me->no, GNUNET_i2s(&dest->me->id),
+                 dest->dest->no, GNUNET_i2s(&dest->dest->id),
+                 base_value, value_rate);
       break;
+
     case GNUNET_ATS_TEST_TG_RANDOM:
-      GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-                  "Setting up random preference generator master[%u] `%s' and slave [%u] `%s' min %u Bips max %u Bps\n",
-                  dest->me->no, GNUNET_i2s (&dest->me->id),
-                  dest->dest->no, GNUNET_i2s (&dest->dest->id),
-                  base_value, value_rate);
+      GNUNET_log(GNUNET_ERROR_TYPE_INFO,
+                 "Setting up random preference generator master[%u] `%s' and slave [%u] `%s' min %u Bips max %u Bps\n",
+                 dest->me->no, GNUNET_i2s(&dest->me->id),
+                 dest->dest->no, GNUNET_i2s(&dest->dest->id),
+                 base_value, value_rate);
       break;
+
     default:
       break;
-  }
+    }
 
   dest->pg = pg;
-  pg->set_task = GNUNET_SCHEDULER_add_now (&set_pref_task, dest);
+  pg->set_task = GNUNET_SCHEDULER_add_now(&set_pref_task, dest);
   return pg;
 }
 
 
 void
-GNUNET_ATS_TEST_generate_preferences_stop (struct PreferenceGenerator *pg)
+GNUNET_ATS_TEST_generate_preferences_stop(struct PreferenceGenerator *pg)
 {
-  GNUNET_CONTAINER_DLL_remove (pg_head, pg_tail, pg);
+  GNUNET_CONTAINER_DLL_remove(pg_head, pg_tail, pg);
   pg->dest->pg = NULL;
 
   if (NULL != pg->set_task)
-  {
-    GNUNET_SCHEDULER_cancel (pg->set_task);
-    pg->set_task = NULL;
-  }
+    {
+      GNUNET_SCHEDULER_cancel(pg->set_task);
+      pg->set_task = NULL;
+    }
 
-  GNUNET_free (pg);
+  GNUNET_free(pg);
 }
 
 
@@ -230,16 +243,17 @@ GNUNET_ATS_TEST_generate_preferences_stop (struct PreferenceGenerator *pg)
  * Stop all preferences generators
  */
 void
-GNUNET_ATS_TEST_generate_preferences_stop_all ()
+GNUNET_ATS_TEST_generate_preferences_stop_all()
 {
   struct PreferenceGenerator *cur;
   struct PreferenceGenerator *next;
+
   next = pg_head;
   for (cur = next; NULL != cur; cur = next)
-  {
+    {
       next = cur->next;
       GNUNET_ATS_TEST_generate_preferences_stop(cur);
-  }
+    }
 }
 
 /* end of file ats-testing-preferences.c */

+ 185 - 174
src/ats-tests/ats-testing-traffic.c

@@ -1,19 +1,19 @@
 /*
- This file is part of GNUnet.
- Copyright (C) 2010-2013, 2016 GNUnet e.V.
+   This file is part of GNUnet.
+   Copyright (C) 2010-2013, 2016 GNUnet e.V.
 
- GNUnet is free software: you can redistribute it and/or modify it
- under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License,
- or (at your option) any later version.
+   GNUnet is free software: you can redistribute it and/or modify it
+   under the terms of the GNU Affero General Public License as published
+   by the Free Software Foundation, either version 3 of the License,
+   or (at your option) any later version.
 
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- Affero General Public License for more details.
+   GNUnet is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Affero General Public License for more details.
 
- You should have received a copy of the GNU Affero General Public License
- along with this program.  If not, see <http://www.gnu.org/licenses/>.
+   You should have received a copy of the GNU Affero General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
  */
@@ -33,7 +33,7 @@ static struct TrafficGenerator *tg_tail;
 extern struct GNUNET_ATS_TEST_Topology *top;
 
 static struct GNUNET_TIME_Relative
-get_delay (struct TrafficGenerator *tg)
+get_delay(struct TrafficGenerator *tg)
 {
   struct GNUNET_TIME_Relative delay;
   struct GNUNET_TIME_Relative time_delta;
@@ -43,65 +43,70 @@ get_delay (struct TrafficGenerator *tg)
   delay.rel_value_us = 0;
 
   /* Calculate the current transmission rate based on the type of traffic */
-  switch (tg->type) {
+  switch (tg->type)
+    {
     case GNUNET_ATS_TEST_TG_CONSTANT:
       if (UINT32_MAX == tg->base_rate)
         return GNUNET_TIME_UNIT_ZERO;
       cur_rate = tg->base_rate;
       break;
+
     case GNUNET_ATS_TEST_TG_LINEAR:
       time_delta = GNUNET_TIME_absolute_get_duration(tg->time_start);
       /* Calculate point of time in the current period */
       time_delta.rel_value_us = time_delta.rel_value_us % tg->duration_period.rel_value_us;
-      delta_rate = ((double) time_delta.rel_value_us  / tg->duration_period.rel_value_us) *
-          (tg->max_rate - tg->base_rate);
+      delta_rate = ((double)time_delta.rel_value_us / tg->duration_period.rel_value_us) *
+                   (tg->max_rate - tg->base_rate);
       if ((tg->max_rate < tg->base_rate) && ((tg->max_rate - tg->base_rate) > tg->base_rate))
-      {
-        /* This will cause an underflow */
-        GNUNET_break (0);
-      }
+        {
+          /* This will cause an underflow */
+          GNUNET_break(0);
+        }
       cur_rate = tg->base_rate + delta_rate;
       break;
+
     case GNUNET_ATS_TEST_TG_RANDOM:
-      cur_rate = tg->base_rate + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
-          tg->max_rate - tg->base_rate);
+      cur_rate = tg->base_rate + GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK,
+                                                          tg->max_rate - tg->base_rate);
       break;
+
     case GNUNET_ATS_TEST_TG_SINUS:
       time_delta = GNUNET_TIME_absolute_get_duration(tg->time_start);
       /* Calculate point of time in the current period */
       time_delta.rel_value_us = time_delta.rel_value_us % tg->duration_period.rel_value_us;
       if ((tg->max_rate - tg->base_rate) > tg->base_rate)
-      {
-        /* This will cause an underflow for second half of sinus period,
-         * will be detected in general when experiments are loaded */
-        GNUNET_break (0);
-      }
+        {
+          /* This will cause an underflow for second half of sinus period,
+           * will be detected in general when experiments are loaded */
+          GNUNET_break(0);
+        }
       delta_rate = (tg->max_rate - tg->base_rate) *
-          sin ( (2 * M_PI) / ((double) tg->duration_period.rel_value_us) * time_delta.rel_value_us);
+                   sin((2 * M_PI) / ((double)tg->duration_period.rel_value_us) * time_delta.rel_value_us);
       cur_rate = tg->base_rate + delta_rate;
       break;
+
     default:
       return delay;
       break;
-  }
+    }
 
   if (cur_rate < 0)
-  {
-    cur_rate = 1;
-  }
+    {
+      cur_rate = 1;
+    }
   /* Calculate the delay for the next message based on the current delay  */
-  delay.rel_value_us =  GNUNET_TIME_UNIT_SECONDS.rel_value_us * TEST_MESSAGE_SIZE / cur_rate;
+  delay.rel_value_us = GNUNET_TIME_UNIT_SECONDS.rel_value_us * TEST_MESSAGE_SIZE / cur_rate;
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Current rate is %lld, calculated delay is %llu\n",
-              cur_rate,
-              (unsigned long long) delay.rel_value_us);
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+             "Current rate is %lld, calculated delay is %llu\n",
+             cur_rate,
+             (unsigned long long)delay.rel_value_us);
   return delay;
 }
 
 
 static void
-update_ping_data (void *cls)
+update_ping_data(void *cls)
 {
   struct BenchmarkPartner *p = cls;
   struct GNUNET_TIME_Relative delay;
@@ -112,23 +117,23 @@ update_ping_data (void *cls)
   p->me->total_bytes_sent += TEST_MESSAGE_SIZE;
 
   if (NULL == p->tg)
-  {
-    GNUNET_break (0);
-    return;
-  }
-  delay = get_delay (p->tg);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-	      "Delay for next transmission %s\n",
-	      GNUNET_STRINGS_relative_time_to_string (delay,
-						      GNUNET_YES));
+    {
+      GNUNET_break(0);
+      return;
+    }
+  delay = get_delay(p->tg);
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+             "Delay for next transmission %s\n",
+             GNUNET_STRINGS_relative_time_to_string(delay,
+                                                    GNUNET_YES));
   p->tg->next_ping_transmission
-    = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get(),
-				delay);
+    = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(),
+                               delay);
 }
 
 
 static void
-comm_schedule_send (void *cls)
+comm_schedule_send(void *cls)
 {
   struct BenchmarkPartner *p = cls;
   struct TestMessage *msg;
@@ -136,25 +141,25 @@ comm_schedule_send (void *cls)
 
   p->tg->send_task = NULL;
   p->last_message_sent = GNUNET_TIME_absolute_get();
-  env = GNUNET_MQ_msg (msg,
-		       TEST_MESSAGE_TYPE_PING);
-  memset (msg->padding,
-	  'a',
-	  sizeof (msg->padding));
-  GNUNET_MQ_notify_sent (env,
-			 &update_ping_data,
-			 p);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-	      "Master [%u]: Sending PING to [%u]\n",
-	      p->me->no,
-	      p->dest->no);
-  GNUNET_MQ_send (p->mq,
-		  env);
+  env = GNUNET_MQ_msg(msg,
+                      TEST_MESSAGE_TYPE_PING);
+  memset(msg->padding,
+         'a',
+         sizeof(msg->padding));
+  GNUNET_MQ_notify_sent(env,
+                        &update_ping_data,
+                        p);
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+             "Master [%u]: Sending PING to [%u]\n",
+             p->me->no,
+             p->dest->no);
+  GNUNET_MQ_send(p->mq,
+                 env);
 }
 
 
 static void
-update_pong_data (void *cls)
+update_pong_data(void *cls)
 {
   struct BenchmarkPartner *p = cls;
 
@@ -166,49 +171,50 @@ update_pong_data (void *cls)
 
 
 void
-GNUNET_ATS_TEST_traffic_handle_ping (struct BenchmarkPartner *p)
+GNUNET_ATS_TEST_traffic_handle_ping(struct BenchmarkPartner *p)
 {
   struct TestMessage *msg;
   struct GNUNET_MQ_Envelope *env;
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-	      "Slave [%u]: Received PING from [%u], sending PONG\n",
-	      p->me->no,
-	      p->dest->no);
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+             "Slave [%u]: Received PING from [%u], sending PONG\n",
+             p->me->no,
+             p->dest->no);
   p->messages_received++;
   p->bytes_received += TEST_MESSAGE_SIZE;
   p->me->total_messages_received++;
   p->me->total_bytes_received += TEST_MESSAGE_SIZE;
 
-  
-  env = GNUNET_MQ_msg (msg,
-		       TEST_MESSAGE_TYPE_PING);
-  memset (msg->padding,
-	  'a',
-	  sizeof (msg->padding));
-  GNUNET_MQ_notify_sent (env,
-			 &update_pong_data,
-			 p);
-  GNUNET_MQ_send (p->mq,
-		  env);
+
+  env = GNUNET_MQ_msg(msg,
+                      TEST_MESSAGE_TYPE_PING);
+  memset(msg->padding,
+         'a',
+         sizeof(msg->padding));
+  GNUNET_MQ_notify_sent(env,
+                        &update_pong_data,
+                        p);
+  GNUNET_MQ_send(p->mq,
+                 env);
 }
 
 
 void
-GNUNET_ATS_TEST_traffic_handle_pong (struct BenchmarkPartner *p)
+GNUNET_ATS_TEST_traffic_handle_pong(struct BenchmarkPartner *p)
 {
   struct GNUNET_TIME_Relative left;
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-	      "Master [%u]: Received PONG from [%u], next message\n",
-	      p->me->no,
-	      p->dest->no);
+
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+             "Master [%u]: Received PONG from [%u], next message\n",
+             p->me->no,
+             p->dest->no);
 
   p->messages_received++;
   p->bytes_received += TEST_MESSAGE_SIZE;
   p->me->total_messages_received++;
   p->me->total_bytes_received += TEST_MESSAGE_SIZE;
   p->total_app_rtt += GNUNET_TIME_absolute_get_difference(p->last_message_sent,
-      GNUNET_TIME_absolute_get()).rel_value_us;
+                                                          GNUNET_TIME_absolute_get()).rel_value_us;
 
   /* Schedule next send event */
   if (NULL == p->tg)
@@ -216,23 +222,23 @@ GNUNET_ATS_TEST_traffic_handle_pong (struct BenchmarkPartner *p)
 
   left = GNUNET_TIME_absolute_get_remaining(p->tg->next_ping_transmission);
   if (UINT32_MAX == p->tg->base_rate)
-  {
-    p->tg->send_task = GNUNET_SCHEDULER_add_now (&comm_schedule_send, p);
-  }
+    {
+      p->tg->send_task = GNUNET_SCHEDULER_add_now(&comm_schedule_send, p);
+    }
   else if (0 == left.rel_value_us)
-  {
-    p->tg->send_task = GNUNET_SCHEDULER_add_now (&comm_schedule_send, p);
-  }
+    {
+      p->tg->send_task = GNUNET_SCHEDULER_add_now(&comm_schedule_send, p);
+    }
   else
-  {
-    /* Enforce minimum transmission rate 1 msg / sec */
-    if (GNUNET_TIME_UNIT_SECONDS.rel_value_us == (left = GNUNET_TIME_relative_min (left, GNUNET_TIME_UNIT_SECONDS)).rel_value_us)
-      GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
-          "Enforcing minimum send rate between master [%u] and slave [%u]\n",
-          p->me->no, p->dest->no);
-    p->tg->send_task = GNUNET_SCHEDULER_add_delayed (left,
-        &comm_schedule_send, p);
-  }
+    {
+      /* Enforce minimum transmission rate 1 msg / sec */
+      if (GNUNET_TIME_UNIT_SECONDS.rel_value_us == (left = GNUNET_TIME_relative_min(left, GNUNET_TIME_UNIT_SECONDS)).rel_value_us)
+        GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
+                   "Enforcing minimum send rate between master [%u] and slave [%u]\n",
+                   p->me->no, p->dest->no);
+      p->tg->send_task = GNUNET_SCHEDULER_add_delayed(left,
+                                                      &comm_schedule_send, p);
+    }
 }
 
 
@@ -250,26 +256,26 @@ GNUNET_ATS_TEST_traffic_handle_pong (struct BenchmarkPartner *p)
  * @return the traffic generator
  */
 struct TrafficGenerator *
-GNUNET_ATS_TEST_generate_traffic_start (struct BenchmarkPeer *src,
-                                        struct BenchmarkPartner *dest,
-                                        enum GeneratorType type,
-                                        unsigned int base_rate,
-                                        unsigned int max_rate,
-                                        struct GNUNET_TIME_Relative period,
-                                        struct GNUNET_TIME_Relative duration)
+GNUNET_ATS_TEST_generate_traffic_start(struct BenchmarkPeer *src,
+                                       struct BenchmarkPartner *dest,
+                                       enum GeneratorType type,
+                                       unsigned int base_rate,
+                                       unsigned int max_rate,
+                                       struct GNUNET_TIME_Relative period,
+                                       struct GNUNET_TIME_Relative duration)
 {
   struct TrafficGenerator *tg;
 
   if (NULL != dest->tg)
-  {
-    GNUNET_break (0);
-    return NULL;
-  }
-
-  tg = GNUNET_new (struct TrafficGenerator);
-  GNUNET_CONTAINER_DLL_insert (tg_head,
-			       tg_tail,
-			       tg);
+    {
+      GNUNET_break(0);
+      return NULL;
+    }
+
+  tg = GNUNET_new(struct TrafficGenerator);
+  GNUNET_CONTAINER_DLL_insert(tg_head,
+                              tg_tail,
+                              tg);
   tg->type = type;
   tg->src = src;
   tg->dest = dest;
@@ -279,71 +285,76 @@ GNUNET_ATS_TEST_generate_traffic_start (struct BenchmarkPeer *src,
   tg->time_start = GNUNET_TIME_absolute_get();
   tg->next_ping_transmission = GNUNET_TIME_UNIT_FOREVER_ABS;
 
-  switch (type) {
-  case GNUNET_ATS_TEST_TG_CONSTANT:
-    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-		"Setting up constant traffic generator master[%u] `%s' and slave [%u] `%s' max %u Bips\n",
-		dest->me->no,
-		GNUNET_i2s (&dest->me->id),
-		dest->dest->no,
-		GNUNET_i2s (&dest->dest->id),
-		base_rate);
-    break;
-  case GNUNET_ATS_TEST_TG_LINEAR:
-    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-		"Setting up linear traffic generator master[%u] `%s' and slave [%u] `%s' min %u Bips max %u Bips\n",
-		dest->me->no,
-		GNUNET_i2s (&dest->me->id),
-		dest->dest->no,
-		GNUNET_i2s (&dest->dest->id),
-		base_rate,
-		max_rate);
-    break;
-  case GNUNET_ATS_TEST_TG_SINUS:
-    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-		"Setting up sinus traffic generator master[%u] `%s' and slave [%u] `%s' baserate %u Bips, amplitude %u Bps\n",
-		dest->me->no,
-		GNUNET_i2s (&dest->me->id),
-		dest->dest->no,
-		GNUNET_i2s (&dest->dest->id),
-		base_rate,
-		max_rate);
-    break;
-  case GNUNET_ATS_TEST_TG_RANDOM:
-    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-		"Setting up random traffic generator master[%u] `%s' and slave [%u] `%s' min %u Bips max %u Bps\n",
-		dest->me->no,
-		GNUNET_i2s (&dest->me->id),
-		dest->dest->no,
-		GNUNET_i2s (&dest->dest->id),
-		base_rate,
-		max_rate);
+  switch (type)
+    {
+    case GNUNET_ATS_TEST_TG_CONSTANT:
+      GNUNET_log(GNUNET_ERROR_TYPE_INFO,
+                 "Setting up constant traffic generator master[%u] `%s' and slave [%u] `%s' max %u Bips\n",
+                 dest->me->no,
+                 GNUNET_i2s(&dest->me->id),
+                 dest->dest->no,
+                 GNUNET_i2s(&dest->dest->id),
+                 base_rate);
+      break;
+
+    case GNUNET_ATS_TEST_TG_LINEAR:
+      GNUNET_log(GNUNET_ERROR_TYPE_INFO,
+                 "Setting up linear traffic generator master[%u] `%s' and slave [%u] `%s' min %u Bips max %u Bips\n",
+                 dest->me->no,
+                 GNUNET_i2s(&dest->me->id),
+                 dest->dest->no,
+                 GNUNET_i2s(&dest->dest->id),
+                 base_rate,
+                 max_rate);
+      break;
+
+    case GNUNET_ATS_TEST_TG_SINUS:
+      GNUNET_log(GNUNET_ERROR_TYPE_INFO,
+                 "Setting up sinus traffic generator master[%u] `%s' and slave [%u] `%s' baserate %u Bips, amplitude %u Bps\n",
+                 dest->me->no,
+                 GNUNET_i2s(&dest->me->id),
+                 dest->dest->no,
+                 GNUNET_i2s(&dest->dest->id),
+                 base_rate,
+                 max_rate);
       break;
+
+    case GNUNET_ATS_TEST_TG_RANDOM:
+      GNUNET_log(GNUNET_ERROR_TYPE_INFO,
+                 "Setting up random traffic generator master[%u] `%s' and slave [%u] `%s' min %u Bips max %u Bps\n",
+                 dest->me->no,
+                 GNUNET_i2s(&dest->me->id),
+                 dest->dest->no,
+                 GNUNET_i2s(&dest->dest->id),
+                 base_rate,
+                 max_rate);
+      break;
+
     default:
       break;
-  }
+    }
 
   dest->tg = tg;
   tg->send_task
-    = GNUNET_SCHEDULER_add_now (&comm_schedule_send,
-				dest);
+    = GNUNET_SCHEDULER_add_now(&comm_schedule_send,
+                               dest);
   return tg;
 }
 
 
 void
-GNUNET_ATS_TEST_generate_traffic_stop (struct TrafficGenerator *tg)
+GNUNET_ATS_TEST_generate_traffic_stop(struct TrafficGenerator *tg)
 {
-  GNUNET_CONTAINER_DLL_remove (tg_head,
-			       tg_tail,
-			       tg);
+  GNUNET_CONTAINER_DLL_remove(tg_head,
+                              tg_tail,
+                              tg);
   tg->dest->tg = NULL;
   if (NULL != tg->send_task)
-  {
-    GNUNET_SCHEDULER_cancel (tg->send_task);
-    tg->send_task = NULL;
-  }
-  GNUNET_free (tg);
+    {
+      GNUNET_SCHEDULER_cancel(tg->send_task);
+      tg->send_task = NULL;
+    }
+  GNUNET_free(tg);
 }
 
 
@@ -351,17 +362,17 @@ GNUNET_ATS_TEST_generate_traffic_stop (struct TrafficGenerator *tg)
  * Stop all traffic generators
  */
 void
-GNUNET_ATS_TEST_generate_traffic_stop_all ()
+GNUNET_ATS_TEST_generate_traffic_stop_all()
 {
   struct TrafficGenerator *cur;
   struct TrafficGenerator *next;
 
   next = tg_head;
   for (cur = next; NULL != cur; cur = next)
-  {
-    next = cur->next;
-    GNUNET_ATS_TEST_generate_traffic_stop(cur);
-  }
+    {
+      next = cur->next;
+      GNUNET_ATS_TEST_generate_traffic_stop(cur);
+    }
 }
 
 /* end of file ats-testing-traffic.c */

Plik diff jest za duży
+ 432 - 431
src/ats-tests/ats-testing.c


+ 58 - 70
src/ats-tests/ats-testing.h

@@ -1,19 +1,19 @@
 /*
- This file is part of GNUnet.
- Copyright (C) 2010-2013 GNUnet e.V.
+   This file is part of GNUnet.
+   Copyright (C) 2010-2013 GNUnet e.V.
 
- GNUnet is free software: you can redistribute it and/or modify it
- under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License,
- or (at your option) any later version.
+   GNUnet is free software: you can redistribute it and/or modify it
+   under the terms of the GNU Affero General Public License as published
+   by the Free Software Foundation, either version 3 of the License,
+   or (at your option) any later version.
 
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- Affero General Public License for more details.
+   GNUnet is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Affero General Public License for more details.
 
- You should have received a copy of the GNU Affero General Public License
- along with this program.  If not, see <http://www.gnu.org/licenses/>.
+   You should have received a copy of the GNU Affero General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
  */
@@ -48,11 +48,10 @@
 #define TEST_MESSAGE_SIZE 100
 
 
-struct TestMessage
-{
+struct TestMessage {
   struct GNUNET_MessageHeader header;
 
-  uint8_t padding[TEST_MESSAGE_SIZE - sizeof (struct GNUNET_MessageHeader)];
+  uint8_t padding[TEST_MESSAGE_SIZE - sizeof(struct GNUNET_MessageHeader)];
 };
 
 
@@ -66,8 +65,7 @@ struct TrafficGenerator;
 
 struct LoggingHandle;
 
-enum GeneratorType
-{
+enum GeneratorType {
   GNUNET_ATS_TEST_TG_LINEAR,
   GNUNET_ATS_TEST_TG_CONSTANT,
   GNUNET_ATS_TEST_TG_RANDOM,
@@ -108,8 +106,7 @@ typedef void (*GNUNET_ATS_TEST_LogRequest) (
 /**
  * Information we track for a peer in the testbed.
  */
-struct BenchmarkPeer
-{
+struct BenchmarkPeer {
   /**
    * Handle with testbed.
    */
@@ -227,8 +224,7 @@ struct BenchmarkPeer
   unsigned int total_bytes_received;
 };
 
-struct TrafficGenerator
-{
+struct TrafficGenerator {
   struct TrafficGenerator *prev;
   struct TrafficGenerator *next;
 
@@ -247,8 +243,7 @@ struct TrafficGenerator
 };
 
 
-struct PreferenceGenerator
-{
+struct PreferenceGenerator {
   struct PreferenceGenerator *prev;
   struct PreferenceGenerator *next;
 
@@ -272,8 +267,7 @@ struct PreferenceGenerator
 /**
  * Information about a benchmarking partner
  */
-struct BenchmarkPartner
-{
+struct BenchmarkPartner {
   /**
    * The peer itself this partner belongs to
    */
@@ -359,8 +353,7 @@ struct BenchmarkPartner
 /**
  * Overall state of the performance benchmark
  */
-struct BenchmarkState
-{
+struct BenchmarkState {
   /**
    * Are we connected to ATS service of all peers: GNUNET_YES/NO
    */
@@ -388,8 +381,7 @@ struct BenchmarkState
 };
 
 
-struct GNUNET_ATS_TEST_Topology
-{
+struct GNUNET_ATS_TEST_Topology {
   /**
    * Progress task
    */
@@ -467,8 +459,7 @@ struct GNUNET_ATS_TEST_Topology
   void *done_cb_cls;
 };
 
-enum OperationType
-{
+enum OperationType {
   START_SEND,
   STOP_SEND,
   START_PREFERENCE,
@@ -489,8 +480,7 @@ typedef void (*GNUNET_ATS_TESTING_ExperimentDoneCallback) (
 /**
  * An operation in an experiment
  */
-struct GNUNET_ATS_TEST_Operation
-{
+struct GNUNET_ATS_TEST_Operation {
   struct GNUNET_ATS_TEST_Operation *next;
   struct GNUNET_ATS_TEST_Operation *prev;
 
@@ -507,8 +497,7 @@ struct GNUNET_ATS_TEST_Operation
   enum GNUNET_ATS_PreferenceKind pref_type;
 };
 
-struct Episode
-{
+struct Episode {
   int id;
   struct Episode *next;
   struct GNUNET_TIME_Relative duration;
@@ -518,8 +507,7 @@ struct Episode
 };
 
 
-struct Experiment
-{
+struct Experiment {
   char *name;
   char *cfg_file;
   unsigned long long int num_masters;
@@ -550,7 +538,7 @@ extern struct GNUNET_CONFIGURATION_Handle *cfg;
  * @param e_done_cb the experiment is completed
  */
 void
-GNUNET_ATS_TEST_experimentation_run (
+GNUNET_ATS_TEST_experimentation_run(
   struct Experiment *e,
   GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb,
   GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb);
@@ -563,7 +551,7 @@ GNUNET_ATS_TEST_experimentation_run (
  * @return the Experiment or NULL on failure
  */
 struct Experiment *
-GNUNET_ATS_TEST_experimentation_load (const char *filename);
+GNUNET_ATS_TEST_experimentation_load(const char *filename);
 
 
 /**
@@ -572,15 +560,15 @@ GNUNET_ATS_TEST_experimentation_load (const char *filename);
  * @param e the experiment
  */
 void
-GNUNET_ATS_TEST_experimentation_stop (struct Experiment *e);
+GNUNET_ATS_TEST_experimentation_stop(struct Experiment *e);
 
 
 void
-GNUNET_ATS_TEST_traffic_handle_ping (struct BenchmarkPartner *p);
+GNUNET_ATS_TEST_traffic_handle_ping(struct BenchmarkPartner *p);
 
 
 void
-GNUNET_ATS_TEST_traffic_handle_pong (struct BenchmarkPartner *p);
+GNUNET_ATS_TEST_traffic_handle_pong(struct BenchmarkPartner *p);
 
 
 /**
@@ -597,24 +585,24 @@ GNUNET_ATS_TEST_traffic_handle_pong (struct BenchmarkPartner *p);
  * @return the traffic generator
  */
 struct TrafficGenerator *
-GNUNET_ATS_TEST_generate_traffic_start (struct BenchmarkPeer *src,
-                                        struct BenchmarkPartner *dest,
-                                        enum GeneratorType type,
-                                        unsigned int base_rate,
-                                        unsigned int max_rate,
-                                        struct GNUNET_TIME_Relative period,
-                                        struct GNUNET_TIME_Relative duration);
+GNUNET_ATS_TEST_generate_traffic_start(struct BenchmarkPeer *src,
+                                       struct BenchmarkPartner *dest,
+                                       enum GeneratorType type,
+                                       unsigned int base_rate,
+                                       unsigned int max_rate,
+                                       struct GNUNET_TIME_Relative period,
+                                       struct GNUNET_TIME_Relative duration);
 
 
 void
-GNUNET_ATS_TEST_generate_traffic_stop (struct TrafficGenerator *tg);
+GNUNET_ATS_TEST_generate_traffic_stop(struct TrafficGenerator *tg);
 
 
 /**
  * Stop all traffic generators
  */
 void
-GNUNET_ATS_TEST_generate_traffic_stop_all (void);
+GNUNET_ATS_TEST_generate_traffic_stop_all(void);
 
 
 /**
@@ -632,7 +620,7 @@ GNUNET_ATS_TEST_generate_traffic_stop_all (void);
  * @return the traffic generator
  */
 struct PreferenceGenerator *
-GNUNET_ATS_TEST_generate_preferences_start (
+GNUNET_ATS_TEST_generate_preferences_start(
   struct BenchmarkPeer *src,
   struct BenchmarkPartner *dest,
   enum GeneratorType type,
@@ -644,11 +632,11 @@ GNUNET_ATS_TEST_generate_preferences_start (
 
 
 void
-GNUNET_ATS_TEST_generate_preferences_stop (struct PreferenceGenerator *pg);
+GNUNET_ATS_TEST_generate_preferences_stop(struct PreferenceGenerator *pg);
 
 
 void
-GNUNET_ATS_TEST_generate_preferences_stop_all (void);
+GNUNET_ATS_TEST_generate_preferences_stop_all(void);
 
 
 /**
@@ -663,12 +651,12 @@ GNUNET_ATS_TEST_generate_preferences_stop_all (void);
  * @return the logging handle or NULL on error
  */
 struct LoggingHandle *
-GNUNET_ATS_TEST_logging_start (struct GNUNET_TIME_Relative log_frequency,
-                               const char *testname,
-                               struct BenchmarkPeer *masters,
-                               int num_masters,
-                               int num_slaves,
-                               int verbose);
+GNUNET_ATS_TEST_logging_start(struct GNUNET_TIME_Relative log_frequency,
+                              const char *testname,
+                              struct BenchmarkPeer *masters,
+                              int num_masters,
+                              int num_slaves,
+                              int verbose);
 
 
 /**
@@ -677,7 +665,7 @@ GNUNET_ATS_TEST_logging_start (struct GNUNET_TIME_Relative log_frequency,
  * @param l the logging handle
  */
 void
-GNUNET_ATS_TEST_logging_clean_up (struct LoggingHandle *l);
+GNUNET_ATS_TEST_logging_clean_up(struct LoggingHandle *l);
 
 
 /**
@@ -686,7 +674,7 @@ GNUNET_ATS_TEST_logging_clean_up (struct LoggingHandle *l);
  * @param l the logging handle
  */
 void
-GNUNET_ATS_TEST_logging_stop (struct LoggingHandle *l);
+GNUNET_ATS_TEST_logging_stop(struct LoggingHandle *l);
 
 
 /**
@@ -695,7 +683,7 @@ GNUNET_ATS_TEST_logging_stop (struct LoggingHandle *l);
  * @param l logging handle to use
  */
 void
-GNUNET_ATS_TEST_logging_now (struct LoggingHandle *l);
+GNUNET_ATS_TEST_logging_now(struct LoggingHandle *l);
 
 
 /**
@@ -706,20 +694,20 @@ GNUNET_ATS_TEST_logging_now (struct LoggingHandle *l);
  * @param plots create gnuplots: #GNUNET_YES or #GNUNET_NO
  */
 void
-GNUNET_ATS_TEST_logging_write_to_file (struct LoggingHandle *l,
-                                       const char *test_name,
-                                       int plots);
+GNUNET_ATS_TEST_logging_write_to_file(struct LoggingHandle *l,
+                                      const char *test_name,
+                                      int plots);
 
 
 /**
  * Topology related functions
  */
 struct BenchmarkPeer *
-GNUNET_ATS_TEST_get_peer (int src);
+GNUNET_ATS_TEST_get_peer(int src);
 
 
 struct BenchmarkPartner *
-GNUNET_ATS_TEST_get_partner (int src, int dest);
+GNUNET_ATS_TEST_get_partner(int src, int dest);
 
 
 /**
@@ -736,7 +724,7 @@ GNUNET_ATS_TEST_get_partner (int src, int dest);
  * @param log_request_cb callback to call when logging is required
  */
 void
-GNUNET_ATS_TEST_create_topology (
+GNUNET_ATS_TEST_create_topology(
   char *name,
   char *cfg_file,
   unsigned int num_slaves,
@@ -751,7 +739,7 @@ GNUNET_ATS_TEST_create_topology (
  * Shutdown topology
  */
 void
-GNUNET_ATS_TEST_shutdown_topology (void);
+GNUNET_ATS_TEST_shutdown_topology(void);
 
 
 /* end of file ats-testing.h */

+ 214 - 213
src/ats-tests/gnunet-ats-sim.c

@@ -1,19 +1,19 @@
 /*
- This file is part of GNUnet.
- Copyright (C) 2010-2013 GNUnet e.V.
+   This file is part of GNUnet.
+   Copyright (C) 2010-2013 GNUnet e.V.
 
- GNUnet is free software: you can redistribute it and/or modify it
- under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License,
- or (at your option) any later version.
+   GNUnet is free software: you can redistribute it and/or modify it
+   under the terms of the GNU Affero General Public License as published
+   by the Free Software Foundation, either version 3 of the License,
+   or (at your option) any later version.
 
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- Affero General Public License for more details.
+   GNUnet is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Affero General Public License for more details.
 
- You should have received a copy of the GNU Affero General Public License
- along with this program.  If not, see <http://www.gnu.org/licenses/>.
+   You should have received a copy of the GNU Affero General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
  */
@@ -32,7 +32,7 @@
 #include "gnunet_core_service.h"
 #include "ats-testing.h"
 
-#define TEST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
+#define TEST_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10)
 
 static struct BenchmarkPeer *masters_p;
 static struct BenchmarkPeer *slaves_p;
@@ -65,7 +65,7 @@ static struct LoggingHandle *l;
 
 
 static void
-evaluate (struct GNUNET_TIME_Relative duration_total)
+evaluate(struct GNUNET_TIME_Relative duration_total)
 {
   int c_m;
   int c_s;
@@ -84,312 +84,313 @@ evaluate (struct GNUNET_TIME_Relative duration_total)
   if (0 == duration)
     duration = 1;
   for (c_m = 0; c_m < e->num_masters; c_m++)
-  {
-    mp = &masters_p[c_m];
-    fprintf (stderr,
-             _("Master [%u]: sent: %u KiB in %u sec. = %u KiB/s, received: %u KiB in %u sec. = %u KiB/s\n"),
-             mp->no, mp->total_bytes_sent / 1024,
-             duration,
-             (mp->total_bytes_sent / 1024) / duration,
-             mp->total_bytes_received / 1024,
-             duration,
-             (mp->total_bytes_received / 1024) / duration);
-
-    for (c_s = 0; c_s < e->num_slaves; c_s++)
     {
-      p = &mp->partners[c_s];
-
-      b_sent_sec = 0;
-      b_recv_sec = 0;
-      kb_sent_percent = 0.0;
-      kb_recv_percent = 0.0;
-      rtt = 0;
-
-      if (duration > 0)
-      {
-          b_sent_sec = p->bytes_sent / duration;
-          b_recv_sec = p->bytes_received / duration;
-      }
-
-      if (mp->total_bytes_sent > 0)
-          kb_sent_percent = ((double) p->bytes_sent * 100) / mp->total_bytes_sent;
-      if (mp->total_bytes_received > 0)
-          kb_recv_percent = ((double) p->bytes_received * 100) / mp->total_bytes_received;
-      if (1000 * p->messages_sent > 0)
-          rtt = p->total_app_rtt / (1000 * p->messages_sent);
-      fprintf (stderr,
-          "%c Master [%u] -> Slave [%u]: sent %u Bips (%.2f %%), received %u Bips (%.2f %%)\n",
-          (mp->pref_partner == p->dest) ? '*' : ' ',
-          mp->no, p->dest->no,
-          b_sent_sec, kb_sent_percent,
+      mp = &masters_p[c_m];
+      fprintf(stderr,
+              _("Master [%u]: sent: %u KiB in %u sec. = %u KiB/s, received: %u KiB in %u sec. = %u KiB/s\n"),
+              mp->no, mp->total_bytes_sent / 1024,
+              duration,
+              (mp->total_bytes_sent / 1024) / duration,
+              mp->total_bytes_received / 1024,
+              duration,
+              (mp->total_bytes_received / 1024) / duration);
+
+      for (c_s = 0; c_s < e->num_slaves; c_s++)
+        {
+          p = &mp->partners[c_s];
+
+          b_sent_sec = 0;
+          b_recv_sec = 0;
+          kb_sent_percent = 0.0;
+          kb_recv_percent = 0.0;
+          rtt = 0;
+
+          if (duration > 0)
+            {
+              b_sent_sec = p->bytes_sent / duration;
+              b_recv_sec = p->bytes_received / duration;
+            }
+
+          if (mp->total_bytes_sent > 0)
+            kb_sent_percent = ((double)p->bytes_sent * 100) / mp->total_bytes_sent;
+          if (mp->total_bytes_received > 0)
+            kb_recv_percent = ((double)p->bytes_received * 100) / mp->total_bytes_received;
+          if (1000 * p->messages_sent > 0)
+            rtt = p->total_app_rtt / (1000 * p->messages_sent);
+          fprintf(stderr,
+                  "%c Master [%u] -> Slave [%u]: sent %u Bips (%.2f %%), received %u Bips (%.2f %%)\n",
+                  (mp->pref_partner == p->dest) ? '*' : ' ',
+                  mp->no, p->dest->no,
+                  b_sent_sec, kb_sent_percent,
                   b_recv_sec, kb_recv_percent);
-      fprintf (stderr,
-          "%c Master [%u] -> Slave [%u]: Average application layer RTT: %u ms\n",
-          (mp->pref_partner == p->dest) ? '*' : ' ',
-          mp->no, p->dest->no, rtt);
+          fprintf(stderr,
+                  "%c Master [%u] -> Slave [%u]: Average application layer RTT: %u ms\n",
+                  (mp->pref_partner == p->dest) ? '*' : ' ',
+                  mp->no, p->dest->no, rtt);
+        }
     }
-  }
 }
 
 
 static void
-do_shutdown (void *cls)
+do_shutdown(void *cls)
 {
-  fprintf (stderr, "Shutdown\n");
+  fprintf(stderr, "Shutdown\n");
   if (NULL != timeout_task)
-  {
-    GNUNET_SCHEDULER_cancel (timeout_task);
-    timeout_task = NULL;
-  }
+    {
+      GNUNET_SCHEDULER_cancel(timeout_task);
+      timeout_task = NULL;
+    }
   if (NULL != l)
-  {
-    GNUNET_ATS_TEST_logging_stop (l);
-    GNUNET_ATS_TEST_logging_clean_up (l);
-    l = NULL;
-  }
+    {
+      GNUNET_ATS_TEST_logging_stop(l);
+      GNUNET_ATS_TEST_logging_clean_up(l);
+      l = NULL;
+    }
 
   /* Stop traffic generation */
   GNUNET_ATS_TEST_generate_traffic_stop_all();
 
   /* Stop all preference generations */
-  GNUNET_ATS_TEST_generate_preferences_stop_all ();
+  GNUNET_ATS_TEST_generate_preferences_stop_all();
 
   if (NULL != e)
-  {
-    GNUNET_ATS_TEST_experimentation_stop (e);
-    e = NULL;
-  }
-  GNUNET_ATS_TEST_shutdown_topology ();
+    {
+      GNUNET_ATS_TEST_experimentation_stop(e);
+      e = NULL;
+    }
+  GNUNET_ATS_TEST_shutdown_topology();
 }
 
 
 static void
-do_timeout (void *cls)
+do_timeout(void *cls)
 {
   timeout_task = NULL;
-  GNUNET_SCHEDULER_shutdown ();
+  GNUNET_SCHEDULER_shutdown();
 }
 
 
 static void
-log_request__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_Properties *ats)
+log_request__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_Properties *ats)
 {
   if (NULL != l)
-  {
-    //GNUNET_break (0);
-    //GNUNET_ATS_TEST_logging_now (l);
-  }
+    {
+      //GNUNET_break (0);
+      //GNUNET_ATS_TEST_logging_now (l);
+    }
 }
 
 
 static void
-experiment_done_cb (struct Experiment *e,
-                    struct GNUNET_TIME_Relative duration,
-		    int success)
+experiment_done_cb(struct Experiment *e,
+                   struct GNUNET_TIME_Relative duration,
+                   int success)
 {
   if (GNUNET_OK == success)
-    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-                "Experiment done successful in %s\n",
-                GNUNET_STRINGS_relative_time_to_string (duration,
-                                                        GNUNET_YES));
+    GNUNET_log(GNUNET_ERROR_TYPE_INFO,
+               "Experiment done successful in %s\n",
+               GNUNET_STRINGS_relative_time_to_string(duration,
+                                                      GNUNET_YES));
   else
-    GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment failed \n");
+    GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Experiment failed \n");
 
   /* Stop logging */
-  GNUNET_ATS_TEST_logging_stop (l);
+  GNUNET_ATS_TEST_logging_stop(l);
 
   /* Stop traffic generation */
   GNUNET_ATS_TEST_generate_traffic_stop_all();
 
   /* Stop all preference generations */
-  GNUNET_ATS_TEST_generate_preferences_stop_all ();
+  GNUNET_ATS_TEST_generate_preferences_stop_all();
 
-  evaluate (duration);
+  evaluate(duration);
   if (opt_log)
     GNUNET_ATS_TEST_logging_write_to_file(l, opt_exp_file, opt_plot);
-  GNUNET_SCHEDULER_shutdown ();
+  GNUNET_SCHEDULER_shutdown();
 }
 
 
 static void
-episode_done_cb (struct Episode *ep)
+episode_done_cb(struct Episode *ep)
 {
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-	      "Episode %u done\n",
-	      ep->id);
+  GNUNET_log(GNUNET_ERROR_TYPE_INFO,
+             "Episode %u done\n",
+             ep->id);
 }
 
 
 static void
-topology_setup_done (void *cls,
-		     struct BenchmarkPeer *masters,
-		     struct BenchmarkPeer *slaves)
+topology_setup_done(void *cls,
+                    struct BenchmarkPeer *masters,
+                    struct BenchmarkPeer *slaves)
 {
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-	      "Topology setup complete!\n");
+  GNUNET_log(GNUNET_ERROR_TYPE_INFO,
+             "Topology setup complete!\n");
 
   masters_p = masters;
   slaves_p = slaves;
 
-  l = GNUNET_ATS_TEST_logging_start (e->log_freq,
-      e->name,
-      masters_p,
-      e->num_masters, e->num_slaves,
-      opt_verbose);
-  GNUNET_ATS_TEST_experimentation_run (e,
-				       &episode_done_cb,
-				       &experiment_done_cb);
+  l = GNUNET_ATS_TEST_logging_start(e->log_freq,
+                                    e->name,
+                                    masters_p,
+                                    e->num_masters, e->num_slaves,
+                                    opt_verbose);
+  GNUNET_ATS_TEST_experimentation_run(e,
+                                      &episode_done_cb,
+                                      &experiment_done_cb);
 /*
-  GNUNET_ATS_TEST_generate_preferences_start(&masters[0],&masters[0].partners[0],
+   GNUNET_ATS_TEST_generate_preferences_start(&masters[0],&masters[0].partners[0],
       GNUNET_ATS_TEST_TG_CONSTANT, 1, 1, GNUNET_TIME_UNIT_SECONDS,
       GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 250),
       GNUNET_ATS_PREFERENCE_BANDWIDTH);
-*/
+ */
 /*
-  GNUNET_ATS_TEST_generate_preferences_start(&masters[0],&masters[0].partners[0],
+   GNUNET_ATS_TEST_generate_preferences_start(&masters[0],&masters[0].partners[0],
       GNUNET_ATS_TEST_TG_LINEAR, 1, 50,
       GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2),
       GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 250),
       GNUNET_ATS_PREFERENCE_BANDWIDTH);
-*/
+ */
 /*
-  GNUNET_ATS_TEST_generate_preferences_start(&masters[0],&masters[0].partners[0],
+   GNUNET_ATS_TEST_generate_preferences_start(&masters[0],&masters[0].partners[0],
         GNUNET_ATS_TEST_TG_RANDOM, 1, 50,
         GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2),
         GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 250),
         GNUNET_ATS_PREFERENCE_BANDWIDTH);
-*/
-  /*
-  GNUNET_ATS_TEST_generate_preferences_start(&masters[0],&masters[0].partners[0],
-        GNUNET_ATS_TEST_TG_SINUS, 10, 5,
-        GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5),
-        GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 250),
-        GNUNET_ATS_PREFERENCE_BANDWIDTH);
-*/
+ */
+/*
+   GNUNET_ATS_TEST_generate_preferences_start(&masters[0],&masters[0].partners[0],
+      GNUNET_ATS_TEST_TG_SINUS, 10, 5,
+      GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5),
+      GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 250),
+      GNUNET_ATS_PREFERENCE_BANDWIDTH);
+ */
 #if 0
   int c_m;
   int c_s;
   for (c_m = 0; c_m < e->num_masters; c_m++)
-  {
+    {
       for (c_s = 0; c_s < e->num_slaves; c_s++)
-      {
-        /* Generate maximum traffic to all peers */
-        /* Example: Generate traffic with constant 10,000 Bytes/s */
-        GNUNET_ATS_TEST_generate_traffic_start (&masters[c_m],
-            &masters[c_m].partners[c_s],
-            GNUNET_ATS_TEST_TG_CONSTANT,
-            10000,
-            GNUNET_TIME_UNIT_FOREVER_REL);
-        /* Example: Generate traffic with an increasing rate from 1000 to 2000
-         * Bytes/s with in a minute */
-        GNUNET_ATS_TEST_generate_traffic_start (&masters[c_m],
-            &masters[c_m].partners[c_s],
-            GNUNET_ATS_TEST_TG_LINEAR,
-            1000,
-            2000,
-            GNUNET_TIME_UNIT_MINUTES,
-            GNUNET_TIME_UNIT_FOREVER_REL);
-        /* Example: Generate traffic with a random rate between 1000 to 2000
-         * Bytes/s */
-        GNUNET_ATS_TEST_generate_traffic_start (&masters[c_m],
-            &masters[c_m].partners[c_s],
-            GNUNET_ATS_TEST_TG_RANDOM,
-            1000,
-            2000,
-            GNUNET_TIME_UNIT_FOREVER_REL,
-            GNUNET_TIME_UNIT_FOREVER_REL);
-        /* Example: Generate traffic with a sinus form, a base rate of
-         * 1000 Bytes/s, an amplitude of (max-base), and a period of 1 minute */
-        GNUNET_ATS_TEST_generate_traffic_start (&masters[c_m],
-            &masters[c_m].partners[c_s],
-            GNUNET_ATS_TEST_TG_SINUS,
-            1000,
-            2000,
-            GNUNET_TIME_UNIT_MINUTES,
-            GNUNET_TIME_UNIT_FOREVER_REL);
-      }
-  }
+        {
+          /* Generate maximum traffic to all peers */
+          /* Example: Generate traffic with constant 10,000 Bytes/s */
+          GNUNET_ATS_TEST_generate_traffic_start(&masters[c_m],
+                                                 &masters[c_m].partners[c_s],
+                                                 GNUNET_ATS_TEST_TG_CONSTANT,
+                                                 10000,
+                                                 GNUNET_TIME_UNIT_FOREVER_REL);
+          /* Example: Generate traffic with an increasing rate from 1000 to 2000
+           * Bytes/s with in a minute */
+          GNUNET_ATS_TEST_generate_traffic_start(&masters[c_m],
+                                                 &masters[c_m].partners[c_s],
+                                                 GNUNET_ATS_TEST_TG_LINEAR,
+                                                 1000,
+                                                 2000,
+                                                 GNUNET_TIME_UNIT_MINUTES,
+                                                 GNUNET_TIME_UNIT_FOREVER_REL);
+          /* Example: Generate traffic with a random rate between 1000 to 2000
+           * Bytes/s */
+          GNUNET_ATS_TEST_generate_traffic_start(&masters[c_m],
+                                                 &masters[c_m].partners[c_s],
+                                                 GNUNET_ATS_TEST_TG_RANDOM,
+                                                 1000,
+                                                 2000,
+                                                 GNUNET_TIME_UNIT_FOREVER_REL,
+                                                 GNUNET_TIME_UNIT_FOREVER_REL);
+          /* Example: Generate traffic with a sinus form, a base rate of
+           * 1000 Bytes/s, an amplitude of (max-base), and a period of 1 minute */
+          GNUNET_ATS_TEST_generate_traffic_start(&masters[c_m],
+                                                 &masters[c_m].partners[c_s],
+                                                 GNUNET_ATS_TEST_TG_SINUS,
+                                                 1000,
+                                                 2000,
+                                                 GNUNET_TIME_UNIT_MINUTES,
+                                                 GNUNET_TIME_UNIT_FOREVER_REL);
+        }
+    }
 #endif
 
   timeout_task
-    = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_add (GNUNET_TIME_UNIT_MINUTES,
-                                                              e->max_duration),
-                                    &do_timeout,
-                                    NULL);
-  GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
+    = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_add(GNUNET_TIME_UNIT_MINUTES,
+                                                            e->max_duration),
+                                   &do_timeout,
+                                   NULL);
+  GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL);
 }
 
 
 static void
-parse_args (int argc, char *argv[])
+parse_args(int argc, char *argv[])
 {
   int c;
+
   opt_exp_file = NULL;
   opt_log = GNUNET_NO;
   opt_plot = GNUNET_NO;
 
   for (c = 0; c < argc; c++)
-  {
-    if ((c < (argc - 1)) && (0 == strcmp (argv[c], "-e")))
-    {
-      GNUNET_free_non_null (opt_exp_file);
-      opt_exp_file = GNUNET_strdup ( argv[c + 1]);
-    }
-    if (0 == strcmp (argv[c], "-l"))
-    {
-      opt_log = GNUNET_YES;
-    }
-    if (0 == strcmp (argv[c], "-p"))
     {
-      opt_plot = GNUNET_YES;
+      if ((c < (argc - 1)) && (0 == strcmp(argv[c], "-e")))
+        {
+          GNUNET_free_non_null(opt_exp_file);
+          opt_exp_file = GNUNET_strdup(argv[c + 1]);
+        }
+      if (0 == strcmp(argv[c], "-l"))
+        {
+          opt_log = GNUNET_YES;
+        }
+      if (0 == strcmp(argv[c], "-p"))
+        {
+          opt_plot = GNUNET_YES;
+        }
+      if (0 == strcmp(argv[c], "-v"))
+        {
+          opt_verbose = GNUNET_YES;
+        }
     }
-    if (0 == strcmp (argv[c], "-v"))
-    {
-      opt_verbose = GNUNET_YES;
-    }
-  }
 }
 
 
 int
-main (int argc, char *argv[])
+main(int argc, char *argv[])
 {
   GNUNET_log_setup("gnunet-ats-sim", "INFO", NULL);
 
-  parse_args (argc, argv);
-  if (NULL == opt_exp_file )
-  {
-    fprintf (stderr, "No experiment given...\n");
-    return 1;
-  }
+  parse_args(argc, argv);
+  if (NULL == opt_exp_file)
+    {
+      fprintf(stderr, "No experiment given...\n");
+      return 1;
+    }
 
-  fprintf (stderr, "Loading experiment `%s' \n", opt_exp_file );
-  e = GNUNET_ATS_TEST_experimentation_load (opt_exp_file);
+  fprintf(stderr, "Loading experiment `%s' \n", opt_exp_file);
+  e = GNUNET_ATS_TEST_experimentation_load(opt_exp_file);
   if (NULL == e)
-  {
-    fprintf (stderr, "Invalid experiment\n");
-    return 1;
-  }
+    {
+      fprintf(stderr, "Invalid experiment\n");
+      return 1;
+    }
   if (0 == e->num_episodes)
-  {
-    fprintf (stderr, "No episodes included\n");
-    return 1;
-  }
+    {
+      fprintf(stderr, "No episodes included\n");
+      return 1;
+    }
 
   /* Setup a topology with */
-  GNUNET_ATS_TEST_create_topology ("gnunet-ats-sim", e->cfg_file,
-      e->num_slaves,
-      e->num_masters,
-      GNUNET_NO,
-      &topology_setup_done,
-      NULL,
-      &log_request__cb);
-  GNUNET_free (opt_exp_file);
+  GNUNET_ATS_TEST_create_topology("gnunet-ats-sim", e->cfg_file,
+                                  e->num_slaves,
+                                  e->num_masters,
+                                  GNUNET_NO,
+                                  &topology_setup_done,
+                                  NULL,
+                                  &log_request__cb);
+  GNUNET_free(opt_exp_file);
   return 0;
 }
 /* end of file gnunet-ats-sim.c */

Plik diff jest za duży
+ 575 - 560
src/ats-tests/gnunet-solver-eval.c


+ 286 - 285
src/ats-tests/perf_ats.c

@@ -1,19 +1,19 @@
 /*
- This file is part of GNUnet.
- Copyright (C) 2010-2013, 2016 GNUnet e.V.
+   This file is part of GNUnet.
+   Copyright (C) 2010-2013, 2016 GNUnet e.V.
 
- GNUnet is free software: you can redistribute it and/or modify it
- under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License,
- or (at your option) any later version.
+   GNUnet is free software: you can redistribute it and/or modify it
+   under the terms of the GNU Affero General Public License as published
+   by the Free Software Foundation, either version 3 of the License,
+   or (at your option) any later version.
 
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- Affero General Public License for more details.
+   GNUnet is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Affero General Public License for more details.
 
- You should have received a copy of the GNU Affero General Public License
- along with this program.  If not, see <http://www.gnu.org/licenses/>.
+   You should have received a copy of the GNU Affero General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
  */
@@ -31,15 +31,15 @@
 #include "ats-testing.h"
 
 
-#define TEST_ATS_PREFRENCE_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
+#define TEST_ATS_PREFRENCE_FREQUENCY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1)
 #define TEST_ATS_PREFRENCE_START 1.0
 #define TEST_ATS_PREFRENCE_DELTA 1.0
 
-#define TEST_MESSAGE_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
+#define TEST_MESSAGE_FREQUENCY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1)
 
-#define TEST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120)
-#define BENCHMARK_DURATION GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
-#define LOGGING_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 500)
+#define TEST_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 120)
+#define BENCHMARK_DURATION GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10)
+#define LOGGING_FREQUENCY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 500)
 #define TESTNAME_PREFIX "perf_ats_"
 #define DEFAULT_SLAVES_NUM 2
 #define DEFAULT_MASTERS_NUM 1
@@ -123,7 +123,7 @@ static struct LoggingHandle *l;
 
 
 static void
-evaluate ()
+evaluate()
 {
   int c_m;
   int c_s;
@@ -139,48 +139,48 @@ evaluate ()
 
   duration = 1 + (perf_duration.rel_value_us / (1000 * 1000));
   for (c_m = 0; c_m < num_masters; c_m++)
-  {
-    mp = &mps[c_m];
-    fprintf (stderr,
-             "Master [%u]: sent: %u KiB in %u sec. = %u KiB/s, received: %u KiB in %u sec. = %u KiB/s\n",
-        mp->no, mp->total_bytes_sent / 1024, duration,
-        (mp->total_bytes_sent / 1024) / duration,
-        mp->total_bytes_received / 1024, duration,
-        (mp->total_bytes_received / 1024) / duration);
-
-    for (c_s = 0; c_s < num_slaves; c_s++)
     {
-      p = &mp->partners[c_s];
-      kb_sent_sec = 0;
-      kb_recv_sec = 0;
-      kb_sent_percent = 0.0;
-      kb_recv_percent = 0.0;
-      rtt = 0;
-
-      if (duration > 0)
-      {
-    	  kb_sent_sec = (p->bytes_sent / 1024) / duration;
-    	  kb_recv_sec = (p->bytes_received / 1024) / duration;
-      }
-
-      if (mp->total_bytes_sent > 0)
-    	  kb_sent_percent = ((double) p->bytes_sent * 100) / mp->total_bytes_sent;
-      if (mp->total_bytes_received > 0)
-    	  kb_recv_percent = ((double) p->bytes_received * 100) / mp->total_bytes_received;
-      if (1000 * p->messages_sent > 0)
-    	  rtt = p->total_app_rtt / (1000 * p->messages_sent);
-      fprintf (stderr,
-               "%c Master [%u] -> Slave [%u]: sent %u KiB/s (%.2f %%), received %u KiB/s (%.2f %%)\n",
-               (mp->pref_partner == p->dest) ? '*' : ' ',
-               mp->no, p->dest->no,
-               kb_sent_sec, kb_sent_percent,
-               kb_recv_sec, kb_recv_percent);
-      fprintf (stderr,
-               "%c Master [%u] -> Slave [%u]: Average application layer RTT: %u ms\n",
-               (mp->pref_partner == p->dest) ? '*' : ' ',
-               mp->no, p->dest->no, rtt);
+      mp = &mps[c_m];
+      fprintf(stderr,
+              "Master [%u]: sent: %u KiB in %u sec. = %u KiB/s, received: %u KiB in %u sec. = %u KiB/s\n",
+              mp->no, mp->total_bytes_sent / 1024, duration,
+              (mp->total_bytes_sent / 1024) / duration,
+              mp->total_bytes_received / 1024, duration,
+              (mp->total_bytes_received / 1024) / duration);
+
+      for (c_s = 0; c_s < num_slaves; c_s++)
+        {
+          p = &mp->partners[c_s];
+          kb_sent_sec = 0;
+          kb_recv_sec = 0;
+          kb_sent_percent = 0.0;
+          kb_recv_percent = 0.0;
+          rtt = 0;
+
+          if (duration > 0)
+            {
+              kb_sent_sec = (p->bytes_sent / 1024) / duration;
+              kb_recv_sec = (p->bytes_received / 1024) / duration;
+            }
+
+          if (mp->total_bytes_sent > 0)
+            kb_sent_percent = ((double)p->bytes_sent * 100) / mp->total_bytes_sent;
+          if (mp->total_bytes_received > 0)
+            kb_recv_percent = ((double)p->bytes_received * 100) / mp->total_bytes_received;
+          if (1000 * p->messages_sent > 0)
+            rtt = p->total_app_rtt / (1000 * p->messages_sent);
+          fprintf(stderr,
+                  "%c Master [%u] -> Slave [%u]: sent %u KiB/s (%.2f %%), received %u KiB/s (%.2f %%)\n",
+                  (mp->pref_partner == p->dest) ? '*' : ' ',
+                  mp->no, p->dest->no,
+                  kb_sent_sec, kb_sent_percent,
+                  kb_recv_sec, kb_recv_percent);
+          fprintf(stderr,
+                  "%c Master [%u] -> Slave [%u]: Average application layer RTT: %u ms\n",
+                  (mp->pref_partner == p->dest) ? '*' : ' ',
+                  mp->no, p->dest->no, rtt);
+        }
     }
-  }
 }
 
 
@@ -190,24 +190,24 @@ evaluate ()
  * @param cls NULL
  */
 static void
-do_shutdown (void *cls)
+do_shutdown(void *cls)
 {
   if (GNUNET_YES == logging)
     GNUNET_ATS_TEST_logging_clean_up(l);
   if (NULL != timeout_task)
-  {
-    GNUNET_SCHEDULER_cancel (timeout_task);
-    timeout_task = NULL;
-  }
+    {
+      GNUNET_SCHEDULER_cancel(timeout_task);
+      timeout_task = NULL;
+    }
   if (NULL != progress_task)
-  {
-    fprintf (stderr, "0\n");
-    GNUNET_SCHEDULER_cancel (progress_task);
-    progress_task = NULL;
-  }
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-              "Benchmarking done\n");
-  GNUNET_ATS_TEST_shutdown_topology ();
+    {
+      fprintf(stderr, "0\n");
+      GNUNET_SCHEDULER_cancel(progress_task);
+      progress_task = NULL;
+    }
+  GNUNET_log(GNUNET_ERROR_TYPE_INFO,
+             "Benchmarking done\n");
+  GNUNET_ATS_TEST_shutdown_topology();
 }
 
 
@@ -217,162 +217,163 @@ do_shutdown (void *cls)
  * @param cls NULL
  */
 static void
-do_timeout (void *cls)
+do_timeout(void *cls)
 {
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-              "Terminating with timeout\n");
+  GNUNET_log(GNUNET_ERROR_TYPE_INFO,
+             "Terminating with timeout\n");
   timeout_task = NULL;
-  evaluate ();
-  GNUNET_SCHEDULER_shutdown ();
+  evaluate();
+  GNUNET_SCHEDULER_shutdown();
 }
 
 
 static void
-print_progress (void *cls)
+print_progress(void *cls)
 {
   static int calls;
 
   progress_task = NULL;
-  fprintf (stderr,
-           "%llu..",
-           (long long unsigned) perf_duration.rel_value_us / (1000 * 1000) - calls);
+  fprintf(stderr,
+          "%llu..",
+          (long long unsigned)perf_duration.rel_value_us / (1000 * 1000) - calls);
   calls++;
 
-  progress_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
-                                                &print_progress,
-                                                NULL);
+  progress_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS,
+                                               &print_progress,
+                                               NULL);
 }
 
 
 static void
-ats_pref_task (void *cls)
+ats_pref_task(void *cls)
 {
   struct BenchmarkPeer *me = cls;
 
   me->ats_task = NULL;
 
   GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, " Master [%u] set preference for slave [%u] to %f\n",
-      me->no, me->pref_partner->no, me->pref_value);
-  GNUNET_ATS_performance_change_preference (me->ats_perf_handle,
-      &me->pref_partner->id,
-      pref_val, me->pref_value, GNUNET_ATS_PREFERENCE_END);
+             me->no, me->pref_partner->no, me->pref_value);
+  GNUNET_ATS_performance_change_preference(me->ats_perf_handle,
+                                           &me->pref_partner->id,
+                                           pref_val, me->pref_value, GNUNET_ATS_PREFERENCE_END);
   me->pref_value += TEST_ATS_PREFRENCE_DELTA;
-  me->ats_task = GNUNET_SCHEDULER_add_delayed (TEST_ATS_PREFRENCE_FREQUENCY,
-      &ats_pref_task, cls);
+  me->ats_task = GNUNET_SCHEDULER_add_delayed(TEST_ATS_PREFRENCE_FREQUENCY,
+                                              &ats_pref_task, cls);
 }
 
 
 static void
-start_benchmark (void *cls)
+start_benchmark(void *cls)
 {
   int c_m;
   int c_s;
 
-  progress_task = GNUNET_SCHEDULER_add_now (&print_progress,
-                                            NULL);
+  progress_task = GNUNET_SCHEDULER_add_now(&print_progress,
+                                           NULL);
 
   GNUNET_log(GNUNET_ERROR_TYPE_INFO,
              "Topology connected, start benchmarking...\n");
 
   /* Start sending test messages */
   for (c_m = 0; c_m < num_masters; c_m++)
-  {
-    for (c_s = 0; c_s < num_slaves; c_s++)
     {
-      GNUNET_ATS_TEST_generate_traffic_start (&mps[c_m],
-                                              &mps[c_m].partners[c_s],
-                                              GNUNET_ATS_TEST_TG_LINEAR,
-                                              UINT32_MAX,
-                                              UINT32_MAX,
-                                              GNUNET_TIME_UNIT_MINUTES,
-                                              GNUNET_TIME_UNIT_FOREVER_REL);
+      for (c_s = 0; c_s < num_slaves; c_s++)
+        {
+          GNUNET_ATS_TEST_generate_traffic_start(&mps[c_m],
+                                                 &mps[c_m].partners[c_s],
+                                                 GNUNET_ATS_TEST_TG_LINEAR,
+                                                 UINT32_MAX,
+                                                 UINT32_MAX,
+                                                 GNUNET_TIME_UNIT_MINUTES,
+                                                 GNUNET_TIME_UNIT_FOREVER_REL);
+        }
+      if (pref_val != GNUNET_ATS_PREFERENCE_END)
+        mps[c_m].ats_task = GNUNET_SCHEDULER_add_now(&ats_pref_task,
+                                                     &mps[c_m]);
     }
-    if (pref_val != GNUNET_ATS_PREFERENCE_END)
-      mps[c_m].ats_task = GNUNET_SCHEDULER_add_now (&ats_pref_task,
-                                                    &mps[c_m]);
-  }
 
   if (GNUNET_YES == logging)
-    l = GNUNET_ATS_TEST_logging_start (log_frequency,
-                                       testname, mps,
-                                       num_masters, num_slaves,
-                                       GNUNET_NO);
+    l = GNUNET_ATS_TEST_logging_start(log_frequency,
+                                      testname, mps,
+                                      num_masters, num_slaves,
+                                      GNUNET_NO);
 }
 
 
 static void
-do_benchmark (void *cls,
-              struct BenchmarkPeer *masters,
-              struct BenchmarkPeer *slaves)
+do_benchmark(void *cls,
+             struct BenchmarkPeer *masters,
+             struct BenchmarkPeer *slaves)
 {
   mps = masters;
   sps = slaves;
-  GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
-                                 NULL);
-  timeout_task = GNUNET_SCHEDULER_add_delayed (perf_duration,
-                                               &do_timeout,
-                                               NULL);
-  progress_task = GNUNET_SCHEDULER_add_now (&start_benchmark,
-                                            NULL);
+  GNUNET_SCHEDULER_add_shutdown(&do_shutdown,
+                                NULL);
+  timeout_task = GNUNET_SCHEDULER_add_delayed(perf_duration,
+                                              &do_timeout,
+                                              NULL);
+  progress_task = GNUNET_SCHEDULER_add_now(&start_benchmark,
+                                           NULL);
 }
 
 
 static struct BenchmarkPartner *
-find_partner (struct BenchmarkPeer *me,
-              const struct GNUNET_PeerIdentity *peer)
+find_partner(struct BenchmarkPeer *me,
+             const struct GNUNET_PeerIdentity *peer)
 {
   int c_m;
-  GNUNET_assert (NULL != me);
-  GNUNET_assert (NULL != peer);
+
+  GNUNET_assert(NULL != me);
+  GNUNET_assert(NULL != peer);
 
   for (c_m = 0; c_m < me->num_partners; c_m++)
-  {
-    /* Find a partner with other as destination */
-    if (0 == GNUNET_memcmp (peer, &me->partners[c_m].dest->id))
     {
-      return &me->partners[c_m];
+      /* Find a partner with other as destination */
+      if (0 == GNUNET_memcmp(peer, &me->partners[c_m].dest->id))
+        {
+          return &me->partners[c_m];
+        }
     }
-  }
   return NULL;
 }
 
 
 static void
-log_request_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_Properties *ats)
+log_request_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_Properties *ats)
 {
   struct BenchmarkPeer *me = cls;
   struct BenchmarkPartner *p;
   char *peer_id;
 
-  p = find_partner (me, &address->peer);
+  p = find_partner(me, &address->peer);
   if (NULL == p)
-  {
-    /* This is not one of my partners
-     * Will happen since the peers will connect to each other due to gossiping
-     */
-    return;
-  }
-  peer_id = GNUNET_strdup (GNUNET_i2s (&me->id));
-
-  if ((p->bandwidth_in != ntohl (bandwidth_in.value__)) ||
-      (p->bandwidth_out != ntohl (bandwidth_out.value__)))
-  p->bandwidth_in = ntohl (bandwidth_in.value__);
-  p->bandwidth_out = ntohl (bandwidth_out.value__);
-
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "%s [%u] received ATS information for peers `%s'\n",
-              (GNUNET_YES == p->me->master) ? "Master" : "Slave",
-              p->me->no,
-              GNUNET_i2s (&p->dest->id));
-
-  GNUNET_free (peer_id);
+    {
+      /* This is not one of my partners
+       * Will happen since the peers will connect to each other due to gossiping
+       */
+      return;
+    }
+  peer_id = GNUNET_strdup(GNUNET_i2s(&me->id));
+
+  if ((p->bandwidth_in != ntohl(bandwidth_in.value__)) ||
+      (p->bandwidth_out != ntohl(bandwidth_out.value__)))
+    p->bandwidth_in = ntohl(bandwidth_in.value__);
+  p->bandwidth_out = ntohl(bandwidth_out.value__);
+
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+             "%s [%u] received ATS information for peers `%s'\n",
+             (GNUNET_YES == p->me->master) ? "Master" : "Slave",
+             p->me->no,
+             GNUNET_i2s(&p->dest->id));
+
+  GNUNET_free(peer_id);
   if (NULL != l)
-    GNUNET_ATS_TEST_logging_now (l);
+    GNUNET_ATS_TEST_logging_now(l);
 }
 
 
@@ -380,7 +381,7 @@ log_request_cb (void *cls,
  * Start the performance test case
  */
 int
-main (int argc, char *argv[])
+main(int argc, char *argv[])
 {
   char *tmp;
   char *tmp_sep;
@@ -397,187 +398,187 @@ main (int argc, char *argv[])
    * perf_ats_<solver>_<transport>_<preference>[.exe]*/
 
   /* Find test prefix, store in temp */
-  tmp = strstr (argv[0], TESTNAME_PREFIX);
+  tmp = strstr(argv[0], TESTNAME_PREFIX);
   if (NULL == tmp)
-  {
-    fprintf (stderr, "Unable to parse test name `%s'\n", argv[0]);
-    return GNUNET_SYSERR;
-  }
+    {
+      fprintf(stderr, "Unable to parse test name `%s'\n", argv[0]);
+      return GNUNET_SYSERR;
+    }
 
   /* Set tmp to end of test name prefix */
-  tmp += strlen (TESTNAME_PREFIX);
+  tmp += strlen(TESTNAME_PREFIX);
 
   /* Determine solver name */
-  solver = GNUNET_strdup (tmp);
+  solver = GNUNET_strdup(tmp);
   /* Remove .exe prefix */
-  if (NULL != (dotexe = strstr (solver, ".exe")) && dotexe[4] == '\0')
+  if (NULL != (dotexe = strstr(solver, ".exe")) && dotexe[4] == '\0')
     dotexe[0] = '\0';
 
   /* Determine first '_' after solver */
-  tmp_sep = strchr (solver, '_');
+  tmp_sep = strchr(solver, '_');
   if (NULL == tmp_sep)
-  {
-    fprintf (stderr, "Unable to parse test name `%s'\n", argv[0]);
-    GNUNET_free(solver);
-    return GNUNET_SYSERR;
-  }
+    {
+      fprintf(stderr, "Unable to parse test name `%s'\n", argv[0]);
+      GNUNET_free(solver);
+      return GNUNET_SYSERR;
+    }
   tmp_sep[0] = '\0';
-  comm_name = GNUNET_strdup (&tmp_sep[1]);
-  tmp_sep = strchr (comm_name, '_');
+  comm_name = GNUNET_strdup(&tmp_sep[1]);
+  tmp_sep = strchr(comm_name, '_');
   if (NULL == tmp_sep)
-  {
-    fprintf (stderr, "Unable to parse test name `%s'\n", argv[0]);
-    GNUNET_free(solver);
-    return GNUNET_SYSERR;
-  }
+    {
+      fprintf(stderr, "Unable to parse test name `%s'\n", argv[0]);
+      GNUNET_free(solver);
+      return GNUNET_SYSERR;
+    }
   tmp_sep[0] = '\0';
-  for (c = 0; c <= strlen (comm_name); c++)
-    comm_name[c] = toupper (comm_name[c]);
-  if (0 == strcmp (comm_name, "CORE"))
+  for (c = 0; c <= strlen(comm_name); c++)
+    comm_name[c] = toupper(comm_name[c]);
+  if (0 == strcmp(comm_name, "CORE"))
     test_core = GNUNET_YES;
-  else if (0 == strcmp (comm_name, "TRANSPORT"))
+  else if (0 == strcmp(comm_name, "TRANSPORT"))
     test_core = GNUNET_NO;
   else
-  {
-    GNUNET_free (comm_name);
-    GNUNET_free (solver);
-    return GNUNET_SYSERR;
-  }
+    {
+      GNUNET_free(comm_name);
+      GNUNET_free(solver);
+      return GNUNET_SYSERR;
+    }
 
   pref_str = GNUNET_strdup(tmp_sep + 1);
 
-  GNUNET_asprintf (&conf_name, "%s%s_%s.conf", TESTNAME_PREFIX, solver,
-      pref_str);
-  GNUNET_asprintf (&test_name, "%s%s_%s", TESTNAME_PREFIX, solver, pref_str);
+  GNUNET_asprintf(&conf_name, "%s%s_%s.conf", TESTNAME_PREFIX, solver,
+                  pref_str);
+  GNUNET_asprintf(&test_name, "%s%s_%s", TESTNAME_PREFIX, solver, pref_str);
 
-  for (c = 0; c <= strlen (pref_str); c++)
-    pref_str[c] = toupper (pref_str[c]);
+  for (c = 0; c <= strlen(pref_str); c++)
+    pref_str[c] = toupper(pref_str[c]);
   pref_val = -1;
 
-  if (0 != strcmp (pref_str, "NONE"))
-  {
-    for (c = 0; c < GNUNET_ATS_PREFERENCE_END; c++)
+  if (0 != strcmp(pref_str, "NONE"))
     {
-      if (0 == strcmp (pref_str, prefs[c]))
-      {
-        pref_val = c;
-        break;
-      }
+      for (c = 0; c < GNUNET_ATS_PREFERENCE_END; c++)
+        {
+          if (0 == strcmp(pref_str, prefs[c]))
+            {
+              pref_val = c;
+              break;
+            }
+        }
     }
-  }
   else
-  {
-    /* abuse terminator to indicate no pref */
-    pref_val = GNUNET_ATS_PREFERENCE_END;
-  }
+    {
+      /* abuse terminator to indicate no pref */
+      pref_val = GNUNET_ATS_PREFERENCE_END;
+    }
   if (-1 == pref_val)
-  {
-    fprintf (stderr, "Unknown preference: `%s'\n", pref_str);
-    GNUNET_free(solver);
-    GNUNET_free(pref_str);
-    GNUNET_free (comm_name);
-    return -1;
-  }
+    {
+      fprintf(stderr, "Unknown preference: `%s'\n", pref_str);
+      GNUNET_free(solver);
+      GNUNET_free(pref_str);
+      GNUNET_free(comm_name);
+      return -1;
+    }
 
   for (c = 0; c < (argc - 1); c++)
-  {
-    if (0 == strcmp (argv[c], "-d"))
-      break;
-  }
+    {
+      if (0 == strcmp(argv[c], "-d"))
+        break;
+    }
   if (c < argc - 1)
-  {
-    if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_relative (argv[c + 1], &perf_duration))
-        fprintf (stderr, "Failed to parse duration `%s'\n", argv[c + 1]);
-  }
+    {
+      if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_relative(argv[c + 1], &perf_duration))
+        fprintf(stderr, "Failed to parse duration `%s'\n", argv[c + 1]);
+    }
   else
-  {
-    perf_duration = BENCHMARK_DURATION;
-  }
-  fprintf (stderr, "Running benchmark for %llu secs\n", (unsigned long long) (perf_duration.rel_value_us) / (1000 * 1000));
+    {
+      perf_duration = BENCHMARK_DURATION;
+    }
+  fprintf(stderr, "Running benchmark for %llu secs\n", (unsigned long long)(perf_duration.rel_value_us) / (1000 * 1000));
 
   for (c = 0; c < (argc - 1); c++)
-  {
-    if (0 == strcmp (argv[c], "-s"))
-      break;
-  }
+    {
+      if (0 == strcmp(argv[c], "-s"))
+        break;
+    }
   if (c < argc - 1)
-  {
-    if ((0L != (num_slaves = strtol (argv[c + 1], NULL, 10)))
-        && (num_slaves >= 1))
-      fprintf (stderr, "Starting %u slave peers\n", num_slaves);
-    else
-      num_slaves = DEFAULT_SLAVES_NUM;
-  }
+    {
+      if ((0L != (num_slaves = strtol(argv[c + 1], NULL, 10)))
+          && (num_slaves >= 1))
+        fprintf(stderr, "Starting %u slave peers\n", num_slaves);
+      else
+        num_slaves = DEFAULT_SLAVES_NUM;
+    }
   else
     num_slaves = DEFAULT_SLAVES_NUM;
 
   for (c = 0; c < (argc - 1); c++)
-  {
-    if (0 == strcmp (argv[c], "-m"))
-      break;
-  }
+    {
+      if (0 == strcmp(argv[c], "-m"))
+        break;
+    }
   if (c < argc - 1)
-  {
-    if ((0L != (num_masters = strtol (argv[c + 1], NULL, 10)))
-        && (num_masters >= 2))
-      fprintf (stderr, "Starting %u master peers\n", num_masters);
-    else
-      num_masters = DEFAULT_MASTERS_NUM;
-  }
+    {
+      if ((0L != (num_masters = strtol(argv[c + 1], NULL, 10)))
+          && (num_masters >= 2))
+        fprintf(stderr, "Starting %u master peers\n", num_masters);
+      else
+        num_masters = DEFAULT_MASTERS_NUM;
+    }
   else
     num_masters = DEFAULT_MASTERS_NUM;
 
   logging = GNUNET_NO;
   for (c = 0; c < argc; c++)
-  {
-    if (0 == strcmp (argv[c], "-l"))
-      logging = GNUNET_YES;
-  }
-
-  if (GNUNET_YES == logging)
-  {
-    for (c = 0; c < (argc - 1); c++)
     {
-      if (0 == strcmp (argv[c], "-f"))
-        break;
+      if (0 == strcmp(argv[c], "-l"))
+        logging = GNUNET_YES;
     }
-    if (c < argc - 1)
-    {
-      if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_relative (argv[c + 1], &log_frequency))
-          fprintf (stderr, "Failed to parse duration `%s'\n", argv[c + 1]);
-    }
-    else
+
+  if (GNUNET_YES == logging)
     {
-      log_frequency = LOGGING_FREQUENCY;
+      for (c = 0; c < (argc - 1); c++)
+        {
+          if (0 == strcmp(argv[c], "-f"))
+            break;
+        }
+      if (c < argc - 1)
+        {
+          if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_relative(argv[c + 1], &log_frequency))
+            fprintf(stderr, "Failed to parse duration `%s'\n", argv[c + 1]);
+        }
+      else
+        {
+          log_frequency = LOGGING_FREQUENCY;
+        }
+      fprintf(stderr, "Using log frequency %llu ms\n",
+              (unsigned long long)(log_frequency.rel_value_us) / (1000));
     }
-    fprintf (stderr, "Using log frequency %llu ms\n",
-        (unsigned long long) (log_frequency.rel_value_us) / (1000));
-  }
 
-  GNUNET_asprintf (&testname, "%s_%s_%s",solver, comm_name, pref_str);
+  GNUNET_asprintf(&testname, "%s_%s_%s", solver, comm_name, pref_str);
 
   if (num_slaves < num_masters)
-  {
-    fprintf (stderr,
-             "Number of master peers is lower than slaves! exit...\n");
-    GNUNET_free(test_name);
-    GNUNET_free(solver);
-    GNUNET_free(pref_str);
-    GNUNET_free (comm_name);
-    return GNUNET_SYSERR;
-  }
+    {
+      fprintf(stderr,
+              "Number of master peers is lower than slaves! exit...\n");
+      GNUNET_free(test_name);
+      GNUNET_free(solver);
+      GNUNET_free(pref_str);
+      GNUNET_free(comm_name);
+      return GNUNET_SYSERR;
+    }
 
   /**
    * Setup the topology
    */
-  GNUNET_ATS_TEST_create_topology ("perf-ats",
-                                   conf_name,
-                                   num_slaves,
-				   num_masters,
-                                   test_core,
-                                   &do_benchmark,
-                                   NULL,
-                                   &log_request_cb);
+  GNUNET_ATS_TEST_create_topology("perf-ats",
+                                  conf_name,
+                                  num_slaves,
+                                  num_masters,
+                                  test_core,
+                                  &do_benchmark,
+                                  NULL,
+                                  &log_request_cb);
 
   return result;
 }

+ 19 - 21
src/ats-tests/perf_ats.h

@@ -1,19 +1,19 @@
 /*
- This file is part of GNUnet.
- Copyright (C) 2010-2013 GNUnet e.V.
+   This file is part of GNUnet.
+   Copyright (C) 2010-2013 GNUnet e.V.
 
- GNUnet is free software: you can redistribute it and/or modify it
- under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License,
- or (at your option) any later version.
+   GNUnet is free software: you can redistribute it and/or modify it
+   under the terms of the GNU Affero General Public License as published
+   by the Free Software Foundation, either version 3 of the License,
+   or (at your option) any later version.
 
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- Affero General Public License for more details.
+   GNUnet is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Affero General Public License for more details.
 
- You should have received a copy of the GNU Affero General Public License
- along with this program.  If not, see <http://www.gnu.org/licenses/>.
+   You should have received a copy of the GNU Affero General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
  */
@@ -30,27 +30,26 @@
 #include "gnunet_core_service.h"
 #include "ats-testing.h"
 
-#define TEST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120)
-#define BENCHMARK_DURATION GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
-#define LOGGING_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 500)
+#define TEST_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 120)
+#define BENCHMARK_DURATION GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10)
+#define LOGGING_FREQUENCY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 500)
 #define TESTNAME_PREFIX "perf_ats_"
 #define DEFAULT_SLAVES_NUM 2
 #define DEFAULT_MASTERS_NUM 1
 
-#define TEST_ATS_PREFRENCE_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
+#define TEST_ATS_PREFRENCE_FREQUENCY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1)
 #define TEST_ATS_PREFRENCE_START 1.0
 #define TEST_ATS_PREFRENCE_DELTA 1.0
 
 #define TEST_MESSAGE_TYPE_PING 12345
 #define TEST_MESSAGE_TYPE_PONG 12346
 #define TEST_MESSAGE_SIZE 1000
-#define TEST_MESSAGE_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
+#define TEST_MESSAGE_FREQUENCY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1)
 
 /**
  * Information about a benchmarking partner
  */
-struct BenchmarkPartner
-{
+struct BenchmarkPartner {
   /**
    * The peer itself this partner belongs to
    */
@@ -128,8 +127,7 @@ struct BenchmarkPartner
 /**
  * Information we track for a peer in the testbed.
  */
-struct BenchmarkPeer
-{
+struct BenchmarkPeer {
   /**
    * Handle with testbed.
    */

+ 338 - 340
src/ats-tests/perf_ats_logging.c

@@ -1,19 +1,19 @@
 /*
- This file is part of GNUnet.
- Copyright (C) 2010-2013 GNUnet e.V.
+   This file is part of GNUnet.
+   Copyright (C) 2010-2013 GNUnet e.V.
 
- GNUnet is free software: you can redistribute it and/or modify it
- under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License,
- or (at your option) any later version.
+   GNUnet is free software: you can redistribute it and/or modify it
+   under the terms of the GNU Affero General Public License as published
+   by the Free Software Foundation, either version 3 of the License,
+   or (at your option) any later version.
 
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- Affero General Public License for more details.
+   GNUnet is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Affero General Public License for more details.
 
- You should have received a copy of the GNU Affero General Public License
- along with this program.  If not, see <http://www.gnu.org/licenses/>.
+   You should have received a copy of the GNU Affero General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
  */
@@ -28,25 +28,25 @@
 #include "perf_ats.h"
 
 #define THROUGHPUT_TEMPLATE "#!/usr/bin/gnuplot \n" \
-"set datafile separator ';' \n" \
-"set title \"Throughput between Master and Slaves\" \n" \
-"set xlabel \"Time in ms\" \n" \
-"set ylabel \"Bytes/s\" \n" \
-"set grid \n"
+  "set datafile separator ';' \n" \
+  "set title \"Throughput between Master and Slaves\" \n" \
+  "set xlabel \"Time in ms\" \n" \
+  "set ylabel \"Bytes/s\" \n" \
+  "set grid \n"
 
 #define RTT_TEMPLATE "#!/usr/bin/gnuplot \n" \
-"set datafile separator ';' \n" \
-"set title \"Application level roundtrip time between Master and Slaves\" \n" \
-"set xlabel \"Time in ms\" \n" \
-"set ylabel \"ms\" \n" \
-"set grid \n"
+  "set datafile separator ';' \n" \
+  "set title \"Application level roundtrip time between Master and Slaves\" \n" \
+  "set xlabel \"Time in ms\" \n" \
+  "set ylabel \"ms\" \n" \
+  "set grid \n"
 
 #define BW_TEMPLATE "#!/usr/bin/gnuplot \n" \
-"set datafile separator ';' \n" \
-"set title \"Bandwidth inbound and outbound between Master and Slaves\" \n" \
-"set xlabel \"Time in ms\" \n" \
-"set ylabel \"Bytes / s \" \n" \
-"set grid \n"
+  "set datafile separator ';' \n" \
+  "set title \"Bandwidth inbound and outbound between Master and Slaves\" \n" \
+  "set xlabel \"Time in ms\" \n" \
+  "set ylabel \"Bytes / s \" \n" \
+  "set grid \n"
 
 #define LOG_ITEMS_TIME 2
 #define LOG_ITEMS_PER_PEER 17
@@ -85,8 +85,7 @@ static struct GNUNET_TIME_Relative frequency;
 /**
  * A single logging time step for a partner
  */
-struct PartnerLoggingTimestep
-{
+struct PartnerLoggingTimestep {
   /**
    * Peer
    */
@@ -159,8 +158,7 @@ struct PartnerLoggingTimestep
 /**
  * A single logging time step for a peer
  */
-struct PeerLoggingTimestep
-{
+struct PeerLoggingTimestep {
   /**
    * Next in DLL
    */
@@ -215,8 +213,7 @@ struct PeerLoggingTimestep
 /**
  * Entry for a benchmark peer
  */
-struct LoggingPeer
-{
+struct LoggingPeer {
   /**
    * Peer
    */
@@ -245,7 +242,7 @@ static struct LoggingPeer *lp;
 
 
 static void
-write_throughput_gnuplot_script (char * fn, struct LoggingPeer *lp)
+write_throughput_gnuplot_script(char * fn, struct LoggingPeer *lp)
 {
   struct GNUNET_DISK_FileHandle *f;
   char * gfn;
@@ -253,57 +250,57 @@ write_throughput_gnuplot_script (char * fn, struct LoggingPeer *lp)
   int c_s;
   int peer_index;
 
-  GNUNET_asprintf (&gfn, "gnuplot_throughput_%s",fn);
-  f = GNUNET_DISK_file_open (gfn,
-      GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
-      GNUNET_DISK_PERM_USER_EXEC | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
+  GNUNET_asprintf(&gfn, "gnuplot_throughput_%s", fn);
+  f = GNUNET_DISK_file_open(gfn,
+                            GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
+                            GNUNET_DISK_PERM_USER_EXEC | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
   if (NULL == f)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot open gnuplot file `%s'\n", gfn);
-    GNUNET_free (gfn);
-    return;
-  }
+    {
+      GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot open gnuplot file `%s'\n", gfn);
+      GNUNET_free(gfn);
+      return;
+    }
 
   /* Write header */
 
   if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, THROUGHPUT_TEMPLATE, strlen(THROUGHPUT_TEMPLATE)))
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot write data to plot file `%s'\n", gfn);
+    GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot write data to plot file `%s'\n", gfn);
 
   /* Write master data */
   peer_index = LOG_ITEMS_TIME;
-  GNUNET_asprintf (&data, "plot '%s' using 2:%u with lines title 'Master %u send total', \\\n" \
-                           "'%s' using 2:%u with lines title 'Master %u receive total', \\\n",
-                           fn, peer_index + LOG_ITEM_THROUGHPUT_SENT, lp->peer->no,
-                           fn, peer_index + LOG_ITEM_THROUGHPUT_RECV, lp->peer->no);
+  GNUNET_asprintf(&data, "plot '%s' using 2:%u with lines title 'Master %u send total', \\\n" \
+                  "'%s' using 2:%u with lines title 'Master %u receive total', \\\n",
+                  fn, peer_index + LOG_ITEM_THROUGHPUT_SENT, lp->peer->no,
+                  fn, peer_index + LOG_ITEM_THROUGHPUT_RECV, lp->peer->no);
   if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, data, strlen(data)))
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot write data to plot file `%s'\n", gfn);
-  GNUNET_free (data);
+    GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot write data to plot file `%s'\n", gfn);
+  GNUNET_free(data);
 
-  peer_index = LOG_ITEMS_TIME + LOG_ITEMS_PER_PEER ;
+  peer_index = LOG_ITEMS_TIME + LOG_ITEMS_PER_PEER;
   for (c_s = 0; c_s < lp->peer->num_partners; c_s++)
-  {
-    GNUNET_asprintf (&data, "'%s' using 2:%u with lines title 'Master %u - Slave %u send', \\\n" \
-                            "'%s' using 2:%u with lines title 'Master %u - Slave %u receive'%s\n",
-                            fn, peer_index + LOG_ITEM_THROUGHPUT_SENT, lp->peer->no, lp->peer->partners[c_s].dest->no,
-                            fn, peer_index + LOG_ITEM_THROUGHPUT_RECV, lp->peer->no, lp->peer->partners[c_s].dest->no,
-                            (c_s < lp->peer->num_partners -1) ? ", \\" : "\n pause -1");
-    if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, data, strlen(data)))
-        GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot write data to plot file `%s'\n", gfn);
-    GNUNET_free (data);
-    peer_index += LOG_ITEMS_PER_PEER;
-  }
+    {
+      GNUNET_asprintf(&data, "'%s' using 2:%u with lines title 'Master %u - Slave %u send', \\\n" \
+                      "'%s' using 2:%u with lines title 'Master %u - Slave %u receive'%s\n",
+                      fn, peer_index + LOG_ITEM_THROUGHPUT_SENT, lp->peer->no, lp->peer->partners[c_s].dest->no,
+                      fn, peer_index + LOG_ITEM_THROUGHPUT_RECV, lp->peer->no, lp->peer->partners[c_s].dest->no,
+                      (c_s < lp->peer->num_partners - 1) ? ", \\" : "\n pause -1");
+      if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, data, strlen(data)))
+        GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot write data to plot file `%s'\n", gfn);
+      GNUNET_free(data);
+      peer_index += LOG_ITEMS_PER_PEER;
+    }
 
   if (GNUNET_SYSERR == GNUNET_DISK_file_close(f))
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot close gnuplot file `%s'\n", gfn);
+    GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot close gnuplot file `%s'\n", gfn);
   else
-    GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Data successfully written to plot file `%s'\n", gfn);
+    GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Data successfully written to plot file `%s'\n", gfn);
 
-  GNUNET_free (gfn);
+  GNUNET_free(gfn);
 }
 
 
 static void
-write_rtt_gnuplot_script (char * fn, struct LoggingPeer *lp)
+write_rtt_gnuplot_script(char * fn, struct LoggingPeer *lp)
 {
   struct GNUNET_DISK_FileHandle *f;
   char * gfn;
@@ -311,44 +308,44 @@ write_rtt_gnuplot_script (char * fn, struct LoggingPeer *lp)
   int c_s;
   int index;
 
-  GNUNET_asprintf (&gfn, "gnuplot_rtt_%s",fn);
-  f = GNUNET_DISK_file_open (gfn,
-      GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
-      GNUNET_DISK_PERM_USER_EXEC | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
+  GNUNET_asprintf(&gfn, "gnuplot_rtt_%s", fn);
+  f = GNUNET_DISK_file_open(gfn,
+                            GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
+                            GNUNET_DISK_PERM_USER_EXEC | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
   if (NULL == f)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot open gnuplot file `%s'\n", gfn);
-    GNUNET_free (gfn);
-    return;
-  }
+    {
+      GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot open gnuplot file `%s'\n", gfn);
+      GNUNET_free(gfn);
+      return;
+    }
 
   /* Write header */
 
   if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, RTT_TEMPLATE, strlen(RTT_TEMPLATE)))
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot write data to plot file `%s'\n", gfn);
+    GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot write data to plot file `%s'\n", gfn);
 
   index = LOG_ITEMS_TIME + LOG_ITEMS_PER_PEER;
   for (c_s = 0; c_s < lp->peer->num_partners; c_s++)
-  {
-    GNUNET_asprintf (&data, "%s'%s' using 2:%u with lines title 'Master %u - Slave %u '%s\n",
-        (0 == c_s) ? "plot " :"",
-        fn, index + LOG_ITEM_APP_RTT, lp->peer->no, lp->peer->partners[c_s].dest->no,
-        (c_s < lp->peer->num_partners -1) ? ", \\" : "\n pause -1");
-    if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, data, strlen(data)))
-        GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot write data to plot file `%s'\n", gfn);
-    GNUNET_free (data);
-    index += LOG_ITEMS_PER_PEER;
-  }
+    {
+      GNUNET_asprintf(&data, "%s'%s' using 2:%u with lines title 'Master %u - Slave %u '%s\n",
+                      (0 == c_s) ? "plot " : "",
+                      fn, index + LOG_ITEM_APP_RTT, lp->peer->no, lp->peer->partners[c_s].dest->no,
+                      (c_s < lp->peer->num_partners - 1) ? ", \\" : "\n pause -1");
+      if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, data, strlen(data)))
+        GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot write data to plot file `%s'\n", gfn);
+      GNUNET_free(data);
+      index += LOG_ITEMS_PER_PEER;
+    }
 
   if (GNUNET_SYSERR == GNUNET_DISK_file_close(f))
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot close gnuplot file `%s'\n", gfn);
+    GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot close gnuplot file `%s'\n", gfn);
   else
-    GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Data successfully written to plot file `%s'\n", gfn);
-  GNUNET_free (gfn);
+    GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Data successfully written to plot file `%s'\n", gfn);
+  GNUNET_free(gfn);
 }
 
 static void
-write_bw_gnuplot_script (char * fn, struct LoggingPeer *lp)
+write_bw_gnuplot_script(char * fn, struct LoggingPeer *lp)
 {
   struct GNUNET_DISK_FileHandle *f;
   char * gfn;
@@ -356,49 +353,49 @@ write_bw_gnuplot_script (char * fn, struct LoggingPeer *lp)
   int c_s;
   int index;
 
-  GNUNET_asprintf (&gfn, "gnuplot_bw_%s",fn);
-  f = GNUNET_DISK_file_open (gfn,
-      GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
-      GNUNET_DISK_PERM_USER_EXEC | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
+  GNUNET_asprintf(&gfn, "gnuplot_bw_%s", fn);
+  f = GNUNET_DISK_file_open(gfn,
+                            GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
+                            GNUNET_DISK_PERM_USER_EXEC | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
   if (NULL == f)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot open gnuplot file `%s'\n", gfn);
-    GNUNET_free (gfn);
-    return;
-  }
+    {
+      GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot open gnuplot file `%s'\n", gfn);
+      GNUNET_free(gfn);
+      return;
+    }
 
   /* Write header */
 
   if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, BW_TEMPLATE, strlen(BW_TEMPLATE)))
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot write data to plot file `%s'\n", gfn);
+    GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot write data to plot file `%s'\n", gfn);
 
   index = LOG_ITEMS_TIME + LOG_ITEMS_PER_PEER;
   for (c_s = 0; c_s < lp->peer->num_partners; c_s++)
-  {
-    GNUNET_asprintf (&data, "%s"\
-        "'%s' using 2:%u with lines title 'BW out master %u - Slave %u ', \\\n" \
-        "'%s' using 2:%u with lines title 'BW in master %u - Slave %u '"\
-        "%s\n",
-        (0 == c_s) ? "plot " :"",
-        fn, index + LOG_ITEM_ATS_BW_OUT, lp->peer->no, lp->peer->partners[c_s].dest->no,
-        fn, index + LOG_ITEM_ATS_BW_IN, lp->peer->no, lp->peer->partners[c_s].dest->no,
-        (c_s < lp->peer->num_partners -1) ? ", \\" : "\n pause -1");
-    if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, data, strlen(data)))
-        GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot write data to plot file `%s'\n", gfn);
-    GNUNET_free (data);
-    index += LOG_ITEMS_PER_PEER;
-  }
+    {
+      GNUNET_asprintf(&data, "%s" \
+                      "'%s' using 2:%u with lines title 'BW out master %u - Slave %u ', \\\n" \
+                      "'%s' using 2:%u with lines title 'BW in master %u - Slave %u '" \
+                      "%s\n",
+                      (0 == c_s) ? "plot " : "",
+                      fn, index + LOG_ITEM_ATS_BW_OUT, lp->peer->no, lp->peer->partners[c_s].dest->no,
+                      fn, index + LOG_ITEM_ATS_BW_IN, lp->peer->no, lp->peer->partners[c_s].dest->no,
+                      (c_s < lp->peer->num_partners - 1) ? ", \\" : "\n pause -1");
+      if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, data, strlen(data)))
+        GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot write data to plot file `%s'\n", gfn);
+      GNUNET_free(data);
+      index += LOG_ITEMS_PER_PEER;
+    }
 
   if (GNUNET_SYSERR == GNUNET_DISK_file_close(f))
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot close gnuplot file `%s'\n", gfn);
+    GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot close gnuplot file `%s'\n", gfn);
   else
-    GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Data successfully written to plot file `%s'\n", gfn);
-  GNUNET_free (gfn);
+    GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Data successfully written to plot file `%s'\n", gfn);
+  GNUNET_free(gfn);
 }
 
 
 static void
-write_to_file ()
+write_to_file()
 {
   struct GNUNET_DISK_FileHandle *f;
 
@@ -412,88 +409,88 @@ write_to_file ()
   int c_s;
 
   for (c_m = 0; c_m < num_peers; c_m++)
-  {
-    GNUNET_asprintf (&filename, "%llu_master_%u_%s_%s.data", GNUNET_TIME_absolute_get().abs_value_us,
-        lp[c_m].peer->no, GNUNET_i2s(&lp[c_m].peer->id), name);
-
-    f = GNUNET_DISK_file_open (filename,
-        GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
-        GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
-    if (NULL == f)
     {
-      GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot open log file `%s'\n", filename);
-      GNUNET_free (filename);
-      return;
+      GNUNET_asprintf(&filename, "%llu_master_%u_%s_%s.data", GNUNET_TIME_absolute_get().abs_value_us,
+                      lp[c_m].peer->no, GNUNET_i2s(&lp[c_m].peer->id), name);
+
+      f = GNUNET_DISK_file_open(filename,
+                                GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
+                                GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
+      if (NULL == f)
+        {
+          GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot open log file `%s'\n", filename);
+          GNUNET_free(filename);
+          return;
+        }
+
+      for (cur_lt = lp[c_m].head; NULL != cur_lt; cur_lt = cur_lt->next)
+        {
+          GNUNET_log(GNUNET_ERROR_TYPE_INFO,
+                     "Master [%u]: timestamp %llu %llu ; %u %u %u ; %u %u %u\n", lp[c_m].peer->no,
+                     cur_lt->timestamp, GNUNET_TIME_absolute_get_difference(lp[c_m].start, cur_lt->timestamp).rel_value_us / 1000,
+                     cur_lt->total_messages_sent, cur_lt->total_bytes_sent, cur_lt->total_throughput_send,
+                     cur_lt->total_messages_received, cur_lt->total_bytes_received, cur_lt->total_throughput_recv);
+
+          slave_string = GNUNET_strdup(";");
+          for (c_s = 0; c_s < lp[c_m].peer->num_partners; c_s++)
+            {
+              plt = &cur_lt->slaves_log[c_s];
+              /* Log partners */
+
+              /* Assembling slave string */
+              GNUNET_log(GNUNET_ERROR_TYPE_INFO,
+                         "\t Slave [%u]: %u %u %u ; %u %u %u rtt %u delay %u bw_in %u bw_out %u \n", plt->slave->no,
+                         plt->total_messages_sent, plt->total_bytes_sent, plt->throughput_sent,
+                         plt->total_messages_received, plt->total_bytes_received, plt->throughput_recv,
+                         plt->app_rtt, plt->ats_delay,
+                         plt->bandwidth_in, plt->bandwidth_out);
+
+              GNUNET_asprintf(&slave_string_tmp, "%s%u;%u;%u;%u;%u;%u;%.3f;%u;%u;%u;%u;%u;%u;%u;%u;%u;%u;", slave_string,
+                              plt->total_messages_sent, plt->total_bytes_sent, plt->throughput_sent,
+                              plt->total_messages_received, plt->total_bytes_received, plt->throughput_sent,
+                              (double)plt->app_rtt / 1000,
+                              plt->bandwidth_in, plt->bandwidth_out,
+                              plt->ats_cost_lan, plt->ats_cost_wan, plt->ats_cost_wlan,
+                              plt->ats_delay, plt->ats_distance, plt->ats_network_type,
+                              plt->ats_utilization_up, plt->ats_utilization_down);
+              GNUNET_free(slave_string);
+              slave_string = slave_string_tmp;
+            }
+          /* Assembling master string */
+
+
+
+          GNUNET_asprintf(&data, "%llu;%llu;%u;%u;%u;%u;%u;%u;;;;;;;;;;;%s\n",
+                          cur_lt->timestamp,
+                          GNUNET_TIME_absolute_get_difference(lp[c_m].start, cur_lt->timestamp).rel_value_us / 1000,
+                          cur_lt->total_messages_sent, cur_lt->total_bytes_sent, cur_lt->total_throughput_send,
+                          cur_lt->total_messages_received, cur_lt->total_bytes_received, cur_lt->total_throughput_recv,
+                          slave_string);
+          GNUNET_free(slave_string);
+
+          if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, data, strlen(data)))
+            GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot write data to log file `%s'\n", filename);
+          GNUNET_free(data);
+        }
+      if (GNUNET_SYSERR == GNUNET_DISK_file_close(f))
+        {
+          GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot close log file `%s'\n", filename);
+          GNUNET_free(filename);
+          return;
+        }
+
+      write_throughput_gnuplot_script(filename, lp);
+      write_rtt_gnuplot_script(filename, lp);
+      write_bw_gnuplot_script(filename, lp);
+
+      GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Data file successfully written to log file `%s'\n", filename);
+      GNUNET_free(filename);
     }
-
-    for (cur_lt = lp[c_m].head; NULL != cur_lt; cur_lt = cur_lt->next)
-    {
-       GNUNET_log(GNUNET_ERROR_TYPE_INFO,
-          "Master [%u]: timestamp %llu %llu ; %u %u %u ; %u %u %u\n", lp[c_m].peer->no,
-          cur_lt->timestamp, GNUNET_TIME_absolute_get_difference(lp[c_m].start,cur_lt->timestamp).rel_value_us / 1000,
-          cur_lt->total_messages_sent, cur_lt->total_bytes_sent, cur_lt->total_throughput_send,
-          cur_lt->total_messages_received, cur_lt->total_bytes_received, cur_lt->total_throughput_recv);
-
-      slave_string = GNUNET_strdup (";");
-      for (c_s = 0; c_s < lp[c_m].peer->num_partners; c_s++)
-      {
-        plt = &cur_lt->slaves_log[c_s];
-        /* Log partners */
-
-        /* Assembling slave string */
-        GNUNET_log(GNUNET_ERROR_TYPE_INFO,
-            "\t Slave [%u]: %u %u %u ; %u %u %u rtt %u delay %u bw_in %u bw_out %u \n", plt->slave->no,
-            plt->total_messages_sent, plt->total_bytes_sent, plt->throughput_sent,
-            plt->total_messages_received, plt->total_bytes_received, plt->throughput_recv,
-            plt->app_rtt, plt->ats_delay,
-            plt->bandwidth_in, plt->bandwidth_out);
-
-        GNUNET_asprintf(&slave_string_tmp, "%s%u;%u;%u;%u;%u;%u;%.3f;%u;%u;%u;%u;%u;%u;%u;%u;%u;%u;",slave_string,
-            plt->total_messages_sent, plt->total_bytes_sent,  plt->throughput_sent,
-            plt->total_messages_received, plt->total_bytes_received,  plt->throughput_sent,
-            (double) plt->app_rtt / 1000,
-            plt->bandwidth_in,plt->bandwidth_out,
-            plt->ats_cost_lan, plt->ats_cost_wan, plt->ats_cost_wlan,
-            plt->ats_delay, plt->ats_distance, plt->ats_network_type,
-            plt->ats_utilization_up, plt->ats_utilization_down);
-        GNUNET_free (slave_string);
-        slave_string = slave_string_tmp;
-      }
-      /* Assembling master string */
-
-
-
-      GNUNET_asprintf (&data, "%llu;%llu;%u;%u;%u;%u;%u;%u;;;;;;;;;;;%s\n",
-          cur_lt->timestamp,
-          GNUNET_TIME_absolute_get_difference(lp[c_m].start,cur_lt->timestamp).rel_value_us / 1000,
-          cur_lt->total_messages_sent, cur_lt->total_bytes_sent,  cur_lt->total_throughput_send,
-          cur_lt->total_messages_received, cur_lt->total_bytes_received, cur_lt->total_throughput_recv,
-          slave_string);
-      GNUNET_free (slave_string);
-
-      if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, data, strlen(data)))
-        GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot write data to log file `%s'\n", filename);
-      GNUNET_free (data);
-    }
-    if (GNUNET_SYSERR == GNUNET_DISK_file_close(f))
-    {
-      GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot close log file `%s'\n", filename);
-      GNUNET_free (filename);
-      return;
-    }
-
-    write_throughput_gnuplot_script (filename, lp);
-    write_rtt_gnuplot_script (filename, lp);
-    write_bw_gnuplot_script (filename, lp);
-
-    GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Data file successfully written to log file `%s'\n", filename);
-    GNUNET_free (filename);
-  }
 }
 
 
 void
-collect_log_now (void)
+collect_log_now(void)
 {
   struct LoggingPeer *bp;
   struct PeerLoggingTimestep *mlt;
@@ -511,143 +508,143 @@ collect_log_now (void)
     return;
 
   for (c_m = 0; c_m < num_peers; c_m++)
-  {
-    bp = &lp[c_m];
-    mlt = GNUNET_new (struct PeerLoggingTimestep);
-    GNUNET_CONTAINER_DLL_insert_tail(bp->head, bp->tail, mlt);
-    prev_log_mlt = mlt->prev;
-
-    /* Collect data */
-
-    /* Current master state */
-    mlt->timestamp = GNUNET_TIME_absolute_get();
-    mlt->total_bytes_sent = bp->peer->total_bytes_sent;
-    mlt->total_messages_sent = bp->peer->total_messages_sent;
-    mlt->total_bytes_received = bp->peer->total_bytes_received;
-    mlt->total_messages_received = bp->peer->total_messages_received;
-
-    /* Throughput */
-    if (NULL == prev_log_mlt)
-     {
-       /* Get difference to start */
-       delta = GNUNET_TIME_absolute_get_difference (lp[c_m].start, mlt->timestamp);
-     }
-     else
-     {
-       /* Get difference to last timestep */
-       delta = GNUNET_TIME_absolute_get_difference (mlt->prev->timestamp, mlt->timestamp);
-     }
-
-     /* Multiplication factor for throughput calculation */
-     mult = (1.0 * 1000 * 1000) / (delta.rel_value_us);
-
-     /* Total throughput */
-     if (NULL != prev_log_mlt)
-     {
-       if (mlt->total_bytes_sent - mlt->prev->total_bytes_sent > 0)
-         mlt->total_throughput_send = mult * (mlt->total_bytes_sent - mlt->prev->total_bytes_sent);
-       else
-         mlt->total_throughput_send = prev_log_mlt->total_throughput_send; /* no msgs send */
-
-       if (mlt->total_bytes_received - mlt->prev->total_bytes_received > 0)
-         mlt->total_throughput_recv = mult * (mlt->total_bytes_received - mlt->prev->total_bytes_received);
-       else
-         mlt->total_throughput_recv = prev_log_mlt->total_throughput_recv; /* no msgs received */
-     }
-     else
-     {
-       mlt->total_throughput_send = mult * mlt->total_bytes_sent;
-       mlt->total_throughput_send = mult * mlt->total_bytes_received;
-     }
-
-    mlt->slaves_log = GNUNET_malloc (bp->peer->num_partners *
-        sizeof (struct PartnerLoggingTimestep));
-
-    for (c_s = 0; c_s < bp->peer->num_partners; c_s++)
     {
-      p = &bp->peer->partners[c_s];
-      slt = &mlt->slaves_log[c_s];
-
-      slt->slave = p->dest;
-      /* Bytes sent from master to this slave */
-      slt->total_bytes_sent = p->bytes_sent;
-      /* Messages sent from master to this slave */
-      slt->total_messages_sent = p->messages_sent;
-      /* Bytes master received from this slave */
-      slt->total_bytes_received = p->bytes_received;
-      /* Messages master received from this slave */
-      slt->total_messages_received = p->messages_received;
-      slt->total_app_rtt = p->total_app_rtt;
-      /* ats performance information */
-      slt->ats_cost_lan = p->ats_cost_lan;
-      slt->ats_cost_wan = p->ats_cost_wan;
-      slt->ats_cost_wlan = p->ats_cost_wlan;
-      slt->ats_delay = p->ats_delay;
-      slt->ats_distance = p->ats_distance;
-      slt->ats_network_type = p->ats_network_type;
-      slt->ats_utilization_down = p->ats_utilization_down;
-      slt->ats_utilization_up = p->ats_utilization_up;
-      slt->bandwidth_in = p->bandwidth_in;
-      slt->bandwidth_out = p->bandwidth_out;
-
-      /* Total application level rtt  */
+      bp = &lp[c_m];
+      mlt = GNUNET_new(struct PeerLoggingTimestep);
+      GNUNET_CONTAINER_DLL_insert_tail(bp->head, bp->tail, mlt);
+      prev_log_mlt = mlt->prev;
+
+      /* Collect data */
+
+      /* Current master state */
+      mlt->timestamp = GNUNET_TIME_absolute_get();
+      mlt->total_bytes_sent = bp->peer->total_bytes_sent;
+      mlt->total_messages_sent = bp->peer->total_messages_sent;
+      mlt->total_bytes_received = bp->peer->total_bytes_received;
+      mlt->total_messages_received = bp->peer->total_messages_received;
+
+      /* Throughput */
       if (NULL == prev_log_mlt)
-      {
-        if (0 != slt->total_messages_sent)
-          app_rtt = slt->total_app_rtt / slt->total_messages_sent;
-        else
-          app_rtt = 0;
-      }
+        {
+          /* Get difference to start */
+          delta = GNUNET_TIME_absolute_get_difference(lp[c_m].start, mlt->timestamp);
+        }
       else
-      {
-        prev_log_slt =  &prev_log_mlt->slaves_log[c_s];
-        if ((slt->total_messages_sent - prev_log_slt->total_messages_sent) > 0)
-          app_rtt = (slt->total_app_rtt - prev_log_slt->total_app_rtt) /
-                  (slt->total_messages_sent - prev_log_slt->total_messages_sent);
-        else
-          app_rtt = prev_log_slt->app_rtt; /* No messages were */
-      }
-      slt->app_rtt = app_rtt;
-
-      /* Partner throughput */
+        {
+          /* Get difference to last timestep */
+          delta = GNUNET_TIME_absolute_get_difference(mlt->prev->timestamp, mlt->timestamp);
+        }
+
+      /* Multiplication factor for throughput calculation */
+      mult = (1.0 * 1000 * 1000) / (delta.rel_value_us);
+
+      /* Total throughput */
       if (NULL != prev_log_mlt)
-      {
-        prev_log_slt =  &prev_log_mlt->slaves_log[c_s];
-        if (slt->total_bytes_sent - prev_log_slt->total_bytes_sent > 0)
-          slt->throughput_sent = mult * (slt->total_bytes_sent - prev_log_slt->total_bytes_sent);
-        else
-          slt->throughput_sent = prev_log_slt->throughput_sent; /* no msgs send */
-
-        if (slt->total_bytes_received - prev_log_slt->total_bytes_received > 0)
-          slt->throughput_recv = mult * (slt->total_bytes_received - prev_log_slt->total_bytes_received);
-        else
-          slt->throughput_recv = prev_log_slt->throughput_recv; /* no msgs received */
-      }
+        {
+          if (mlt->total_bytes_sent - mlt->prev->total_bytes_sent > 0)
+            mlt->total_throughput_send = mult * (mlt->total_bytes_sent - mlt->prev->total_bytes_sent);
+          else
+            mlt->total_throughput_send = prev_log_mlt->total_throughput_send; /* no msgs send */
+
+          if (mlt->total_bytes_received - mlt->prev->total_bytes_received > 0)
+            mlt->total_throughput_recv = mult * (mlt->total_bytes_received - mlt->prev->total_bytes_received);
+          else
+            mlt->total_throughput_recv = prev_log_mlt->total_throughput_recv; /* no msgs received */
+        }
       else
-      {
-        slt->throughput_sent = mult * slt->total_bytes_sent;
-        slt->throughput_sent = mult * slt->total_bytes_received;
-      }
-
-      GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
-          "Master [%u]: slave [%u]\n",
-          bp->peer->no, p->dest->no);
+        {
+          mlt->total_throughput_send = mult * mlt->total_bytes_sent;
+          mlt->total_throughput_send = mult * mlt->total_bytes_received;
+        }
+
+      mlt->slaves_log = GNUNET_malloc(bp->peer->num_partners *
+                                      sizeof(struct PartnerLoggingTimestep));
+
+      for (c_s = 0; c_s < bp->peer->num_partners; c_s++)
+        {
+          p = &bp->peer->partners[c_s];
+          slt = &mlt->slaves_log[c_s];
+
+          slt->slave = p->dest;
+          /* Bytes sent from master to this slave */
+          slt->total_bytes_sent = p->bytes_sent;
+          /* Messages sent from master to this slave */
+          slt->total_messages_sent = p->messages_sent;
+          /* Bytes master received from this slave */
+          slt->total_bytes_received = p->bytes_received;
+          /* Messages master received from this slave */
+          slt->total_messages_received = p->messages_received;
+          slt->total_app_rtt = p->total_app_rtt;
+          /* ats performance information */
+          slt->ats_cost_lan = p->ats_cost_lan;
+          slt->ats_cost_wan = p->ats_cost_wan;
+          slt->ats_cost_wlan = p->ats_cost_wlan;
+          slt->ats_delay = p->ats_delay;
+          slt->ats_distance = p->ats_distance;
+          slt->ats_network_type = p->ats_network_type;
+          slt->ats_utilization_down = p->ats_utilization_down;
+          slt->ats_utilization_up = p->ats_utilization_up;
+          slt->bandwidth_in = p->bandwidth_in;
+          slt->bandwidth_out = p->bandwidth_out;
+
+          /* Total application level rtt  */
+          if (NULL == prev_log_mlt)
+            {
+              if (0 != slt->total_messages_sent)
+                app_rtt = slt->total_app_rtt / slt->total_messages_sent;
+              else
+                app_rtt = 0;
+            }
+          else
+            {
+              prev_log_slt = &prev_log_mlt->slaves_log[c_s];
+              if ((slt->total_messages_sent - prev_log_slt->total_messages_sent) > 0)
+                app_rtt = (slt->total_app_rtt - prev_log_slt->total_app_rtt) /
+                          (slt->total_messages_sent - prev_log_slt->total_messages_sent);
+              else
+                app_rtt = prev_log_slt->app_rtt; /* No messages were */
+            }
+          slt->app_rtt = app_rtt;
+
+          /* Partner throughput */
+          if (NULL != prev_log_mlt)
+            {
+              prev_log_slt = &prev_log_mlt->slaves_log[c_s];
+              if (slt->total_bytes_sent - prev_log_slt->total_bytes_sent > 0)
+                slt->throughput_sent = mult * (slt->total_bytes_sent - prev_log_slt->total_bytes_sent);
+              else
+                slt->throughput_sent = prev_log_slt->throughput_sent; /* no msgs send */
+
+              if (slt->total_bytes_received - prev_log_slt->total_bytes_received > 0)
+                slt->throughput_recv = mult * (slt->total_bytes_received - prev_log_slt->total_bytes_received);
+              else
+                slt->throughput_recv = prev_log_slt->throughput_recv; /* no msgs received */
+            }
+          else
+            {
+              slt->throughput_sent = mult * slt->total_bytes_sent;
+              slt->throughput_sent = mult * slt->total_bytes_received;
+            }
+
+          GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+                     "Master [%u]: slave [%u]\n",
+                     bp->peer->no, p->dest->no);
+        }
     }
-  }
 }
 
 static void
-collect_log_task (void *cls)
+collect_log_task(void *cls)
 {
   log_task = NULL;
-  collect_log_now ();
-  log_task = GNUNET_SCHEDULER_add_delayed (frequency,
-                                           &collect_log_task, NULL);
+  collect_log_now();
+  log_task = GNUNET_SCHEDULER_add_delayed(frequency,
+                                          &collect_log_task, NULL);
 }
 
 
 void
-perf_logging_stop ()
+perf_logging_stop()
 {
   int c_m;
   struct PeerLoggingTimestep *cur;
@@ -656,53 +653,54 @@ perf_logging_stop ()
     return;
 
   if (NULL != log_task)
-  {
-    GNUNET_SCHEDULER_cancel (log_task);
-    log_task = NULL;
-  }
-  collect_log_task (NULL);
+    {
+      GNUNET_SCHEDULER_cancel(log_task);
+      log_task = NULL;
+    }
+  collect_log_task(NULL);
 
   GNUNET_log(GNUNET_ERROR_TYPE_INFO,
-      _("Stop logging\n"));
+             _("Stop logging\n"));
 
-  write_to_file ();
+  write_to_file();
 
   for (c_m = 0; c_m < num_peers; c_m++)
-  {
-    while (NULL != (cur = lp[c_m].head))
     {
-      GNUNET_CONTAINER_DLL_remove (lp[c_m].head, lp[c_m].tail, cur);
-      GNUNET_free (cur->slaves_log);
-      GNUNET_free (cur);
+      while (NULL != (cur = lp[c_m].head))
+        {
+          GNUNET_CONTAINER_DLL_remove(lp[c_m].head, lp[c_m].tail, cur);
+          GNUNET_free(cur->slaves_log);
+          GNUNET_free(cur);
+        }
     }
-  }
 
-  GNUNET_free (lp);
+  GNUNET_free(lp);
 }
 
 
 void
-perf_logging_start (struct GNUNET_TIME_Relative log_frequency,
-    char * testname, struct BenchmarkPeer *masters, int num_masters)
+perf_logging_start(struct GNUNET_TIME_Relative log_frequency,
+                   char * testname, struct BenchmarkPeer *masters, int num_masters)
 {
   int c_m;
+
   GNUNET_log(GNUNET_ERROR_TYPE_INFO,
-      _("Start logging `%s'\n"), testname);
+             _("Start logging `%s'\n"), testname);
 
   num_peers = num_masters;
   name = testname;
   frequency = log_frequency;
 
-  lp = GNUNET_malloc (num_masters * sizeof (struct LoggingPeer));
+  lp = GNUNET_malloc(num_masters * sizeof(struct LoggingPeer));
 
-  for (c_m = 0; c_m < num_masters; c_m ++)
-  {
-    lp[c_m].peer = &masters[c_m];
-    lp[c_m].start = GNUNET_TIME_absolute_get();
-  }
+  for (c_m = 0; c_m < num_masters; c_m++)
+    {
+      lp[c_m].peer = &masters[c_m];
+      lp[c_m].start = GNUNET_TIME_absolute_get();
+    }
 
   /* Schedule logging task */
-  log_task = GNUNET_SCHEDULER_add_now (&collect_log_task, NULL);
+  log_task = GNUNET_SCHEDULER_add_now(&collect_log_task, NULL);
   running = GNUNET_YES;
 }
 /* end of file perf_ats_logging.c */

Plik diff jest za duży
+ 396 - 397
src/ats-tool/gnunet-ats.c


+ 17 - 41
src/ats/ats.h

@@ -11,12 +11,12 @@
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      Affero General Public License for more details.
-    
+
      You should have received a copy of the GNU Affero General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
-*/
+ */
 /**
  * @file ats/ats.h
  * @brief automatic transport selection messages
@@ -34,9 +34,7 @@
  * Flag used to indicate which type of client is connecting
  * to the ATS service.
  */
-enum StartFlag
-{
-
+enum StartFlag {
   /**
    * This is a scheduling client (aka transport service)
    */
@@ -67,8 +65,7 @@ GNUNET_NETWORK_STRUCT_BEGIN
  * First message any client sends to ATS, used to self-identify
  * (what type of client this is).
  */
-struct ClientStartMessage
-{
+struct ClientStartMessage {
   /**
    * Type is #GNUNET_MESSAGE_TYPE_ATS_START.
    */
@@ -85,8 +82,7 @@ struct ClientStartMessage
  * Connectivity client to ATS service: we would like to have
  * address suggestions for this peer.
  */
-struct RequestAddressMessage
-{
+struct RequestAddressMessage {
   /**
    * Type is #GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS or
    * #GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS_CANCEL to stop
@@ -109,8 +105,7 @@ struct RequestAddressMessage
 /**
  * Scheduling client to ATS service: here is another address you can use.
  */
-struct AddressAddMessage
-{
+struct AddressAddMessage {
   /**
    * Type is #GNUNET_MESSAGE_TYPE_ATS_ADDRESS_ADD.
    */
@@ -152,7 +147,6 @@ struct AddressAddMessage
    * - char address[address_length]
    * - char plugin_name[plugin_name_length] (including '\0'-termination).
    */
-
 };
 
 
@@ -160,8 +154,7 @@ struct AddressAddMessage
  * Message used to notify ATS that the performance
  * characteristics for an address have changed.
  */
-struct AddressUpdateMessage
-{
+struct AddressUpdateMessage {
   /**
    * Message of type #GNUNET_MESSAGE_TYPE_ATS_ADDRESS_UPDATE.
    */
@@ -183,7 +176,6 @@ struct AddressUpdateMessage
    * Performance properties of the address.
    */
   struct GNUNET_ATS_PropertiesNBO properties;
-
 };
 
 
@@ -192,8 +184,7 @@ struct AddressUpdateMessage
  * was destroyed and must thus henceforth no longer be considered
  * for scheduling.
  */
-struct AddressDestroyedMessage
-{
+struct AddressDestroyedMessage {
   /**
    * Type is #GNUNET_MESSAGE_TYPE_ATS_ADDRESS_DESTROYED.
    */
@@ -210,7 +201,6 @@ struct AddressDestroyedMessage
    * to find the session faster).
    */
   struct GNUNET_PeerIdentity peer;
-
 };
 
 
@@ -218,8 +208,7 @@ struct AddressDestroyedMessage
  * Message sent by ATS service to client to confirm that it is done
  * using the given session ID.
  */
-struct GNUNET_ATS_SessionReleaseMessage
-{
+struct GNUNET_ATS_SessionReleaseMessage {
   /**
    * Type is #GNUNET_MESSAGE_TYPE_ATS_SESSION_RELEASE.
    */
@@ -245,8 +234,7 @@ struct GNUNET_ATS_SessionReleaseMessage
  * identified by the given @e session_id for the given @e peer with
  * the given @e bandwidth_in and @e bandwidth_out limits from now on.
  */
-struct AddressSuggestionMessage
-{
+struct AddressSuggestionMessage {
   /**
    * A message of type #GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION.
    */
@@ -274,15 +262,13 @@ struct AddressSuggestionMessage
    * How much bandwidth we are allowed for receiving.
    */
   struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in;
-
 };
 
 
 /**
  *
  */
-struct PeerInformationMessage
-{
+struct PeerInformationMessage {
   /**
    * Type is #GNUNET_MESSAGE_TYPE_ATS_PEER_INFORMATION
    */
@@ -338,15 +324,13 @@ struct PeerInformationMessage
    * - char address[address_length]
    * - char plugin_name[plugin_name_length] (including '\0'-termination).
    */
-
 };
 
 
 /**
  * Client to service: please give us an overview of the addresses.
  */
-struct AddressListRequestMessage
-{
+struct AddressListRequestMessage {
   /**
    * Type is #GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_REQUEST
    */
@@ -367,15 +351,13 @@ struct AddressListRequestMessage
    * #GNUNET_NO to only return addresses that are in use.
    */
   int32_t all GNUNET_PACKED;
-
 };
 
 
 /**
  *
  */
-struct ReservationRequestMessage
-{
+struct ReservationRequestMessage {
   /**
    * Type is #GNUNET_MESSAGE_TYPE_ATS_RESERVATION_REQUEST
    */
@@ -396,8 +378,7 @@ struct ReservationRequestMessage
 /**
  *
  */
-struct ReservationResultMessage
-{
+struct ReservationResultMessage {
   /**
    * Type is #GNUNET_MESSAGE_TYPE_ATS_RESERVATION_RESULT
    */
@@ -424,9 +405,7 @@ struct ReservationResultMessage
  * Variable-size entry in a `struct ChangePreferenceMessage` or
  * `struct FeedbackPreferenceMessage`.
  */
-struct PreferenceInformation
-{
-
+struct PreferenceInformation {
   /**
    * An `enum GNUNET_ATS_PreferenceKind` in NBO.
    */
@@ -437,15 +416,13 @@ struct PreferenceInformation
    * preference_kind being expressed.
    */
   float preference_value GNUNET_PACKED;
-
 };
 
 
 /**
  * Client to ATS: I have a performance preference for a peer.
  */
-struct ChangePreferenceMessage
-{
+struct ChangePreferenceMessage {
   /**
    * Type is #GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_CHANGE.
    */
@@ -470,8 +447,7 @@ struct ChangePreferenceMessage
 /**
  * Message containing application feedback for a peer
  */
-struct FeedbackPreferenceMessage
-{
+struct FeedbackPreferenceMessage {
   /**
    * Type is #GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_FEEDBACK.
    */

+ 8 - 22
src/ats/ats2.h

@@ -16,7 +16,7 @@
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
-*/
+ */
 /**
  * @file ats/ats2.h
  * @brief automatic transport selection messages
@@ -36,9 +36,7 @@ GNUNET_NETWORK_STRUCT_BEGIN
 /**
  * ATS performance characteristics for an address.
  */
-struct PropertiesNBO
-{
-
+struct PropertiesNBO {
   /**
    * Delay.  Time between when the time packet is sent and the packet
    * arrives.  FOREVER if we did not (successfully) measure yet.
@@ -101,7 +99,6 @@ struct PropertiesNBO
    * A `enum GNUNET_TRANSPORT_CommunicatorCharacteristics` in NBO.
    */
   uint32_t cc;
-
 };
 
 
@@ -109,8 +106,7 @@ struct PropertiesNBO
  * Application client to ATS service: we would like to have
  * address suggestions for this peer.
  */
-struct ExpressPreferenceMessage
-{
+struct ExpressPreferenceMessage {
   /**
    * Type is #GNUNET_MESSAGE_TYPE_ATS_SUGGEST or
    * #GNUNET_MESSAGE_TYPE_ATS_SUGGEST_CANCEL to stop
@@ -133,15 +129,13 @@ struct ExpressPreferenceMessage
    * How much bandwidth in bytes/second does the application expect?
    */
   struct GNUNET_BANDWIDTH_Value32NBO bw;
-
 };
 
 
 /**
  * Transport client to ATS service: here is another session you can use.
  */
-struct SessionAddMessage
-{
+struct SessionAddMessage {
   /**
    * Type is #GNUNET_MESSAGE_TYPE_ATS_SESSION_ADD or
    * #GNUNET_MESSAGE_TYPE_ATS_SESSION_ADD_INBOUND_ONLY
@@ -167,7 +161,6 @@ struct SessionAddMessage
   /* followed by:
    * - char * address (including '\0'-termination).
    */
-
 };
 
 
@@ -175,8 +168,7 @@ struct SessionAddMessage
  * Message used to notify ATS that the performance
  * characteristics for an session have changed.
  */
-struct SessionUpdateMessage
-{
+struct SessionUpdateMessage {
   /**
    * Message of type #GNUNET_MESSAGE_TYPE_ATS_SESSION_UPDATE.
    */
@@ -198,7 +190,6 @@ struct SessionUpdateMessage
    * Performance properties of the session.
    */
   struct PropertiesNBO properties;
-
 };
 
 
@@ -207,8 +198,7 @@ struct SessionUpdateMessage
  * was destroyed and must thus henceforth no longer be considered
  * for scheduling.
  */
-struct SessionDelMessage
-{
+struct SessionDelMessage {
   /**
    * Type is #GNUNET_MESSAGE_TYPE_ATS_SESSION_DEL.
    */
@@ -225,7 +215,6 @@ struct SessionDelMessage
    * to find the session faster).
    */
   struct GNUNET_PeerIdentity peer;
-
 };
 
 
@@ -234,8 +223,7 @@ struct SessionDelMessage
  * identified by the given @e session_id for the given @e peer with
  * the given @e bandwidth_in and @e bandwidth_out limits from now on.
  */
-struct SessionAllocationMessage
-{
+struct SessionAllocationMessage {
   /**
    * A message of type #GNUNET_MESSAGE_TYPE_ATS_SESSION_ALLOCATION.
    */
@@ -263,7 +251,6 @@ struct SessionAllocationMessage
    * How much bandwidth we are allowed for receiving.
    */
   struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in;
-
 };
 
 
@@ -271,8 +258,7 @@ struct SessionAllocationMessage
  * ATS Service suggests to the transport service to try the address
  * for the given @e peer.
  */
-struct AddressSuggestionMessage
-{
+struct AddressSuggestionMessage {
   /**
    * A message of type #GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION.
    */

+ 100 - 103
src/ats/ats_api2_application.c

@@ -16,7 +16,7 @@
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
-*/
+ */
 /**
  * @file ats/ats_api2_application.c
  * @brief enable clients to ask ATS about establishing connections to peers
@@ -28,14 +28,13 @@
 #include "ats2.h"
 
 
-#define LOG(kind,...) GNUNET_log_from(kind, "ats-application-api", __VA_ARGS__)
+#define LOG(kind, ...) GNUNET_log_from(kind, "ats-application-api", __VA_ARGS__)
 
 
 /**
  * Handle for ATS address suggestion requests.
  */
-struct GNUNET_ATS_ApplicationSuggestHandle
-{
+struct GNUNET_ATS_ApplicationSuggestHandle {
   /**
    * ID of the peer for which address suggestion was requested.
    */
@@ -61,9 +60,7 @@ struct GNUNET_ATS_ApplicationSuggestHandle
 /**
  * Handle to the ATS subsystem for application management.
  */
-struct GNUNET_ATS_ApplicationHandle
-{
-
+struct GNUNET_ATS_ApplicationHandle {
   /**
    * Our configuration.
    */
@@ -99,7 +96,7 @@ struct GNUNET_ATS_ApplicationHandle
  * @param ch handle to use to re-connect.
  */
 static void
-reconnect (struct GNUNET_ATS_ApplicationHandle *ch);
+reconnect(struct GNUNET_ATS_ApplicationHandle *ch);
 
 
 /**
@@ -108,12 +105,12 @@ reconnect (struct GNUNET_ATS_ApplicationHandle *ch);
  * @param cls handle to use to re-connect.
  */
 static void
-reconnect_task (void *cls)
+reconnect_task(void *cls)
 {
   struct GNUNET_ATS_ApplicationHandle *ch = cls;
 
   ch->task = NULL;
-  reconnect (ch);
+  reconnect(ch);
 }
 
 
@@ -123,17 +120,17 @@ reconnect_task (void *cls)
  * @param ch our handle
  */
 static void
-force_reconnect (struct GNUNET_ATS_ApplicationHandle *ch)
+force_reconnect(struct GNUNET_ATS_ApplicationHandle *ch)
 {
   if (NULL != ch->mq)
-  {
-    GNUNET_MQ_destroy (ch->mq);
-    ch->mq = NULL;
-  }
-  ch->backoff = GNUNET_TIME_STD_BACKOFF (ch->backoff);
-  ch->task = GNUNET_SCHEDULER_add_delayed (ch->backoff,
-                                           &reconnect_task,
-                                           ch);
+    {
+      GNUNET_MQ_destroy(ch->mq);
+      ch->mq = NULL;
+    }
+  ch->backoff = GNUNET_TIME_STD_BACKOFF(ch->backoff);
+  ch->task = GNUNET_SCHEDULER_add_delayed(ch->backoff,
+                                          &reconnect_task,
+                                          ch);
 }
 
 
@@ -145,15 +142,15 @@ force_reconnect (struct GNUNET_ATS_ApplicationHandle *ch)
  * @param error details about the error
  */
 static void
-error_handler (void *cls,
-               enum GNUNET_MQ_Error error)
+error_handler(void *cls,
+              enum GNUNET_MQ_Error error)
 {
   struct GNUNET_ATS_ApplicationHandle *ch = cls;
 
-  LOG (GNUNET_ERROR_TYPE_DEBUG,
-       "ATS connection died (code %d), reconnecting\n",
-       (int) error);
-  force_reconnect (ch);
+  LOG(GNUNET_ERROR_TYPE_DEBUG,
+      "ATS connection died (code %d), reconnecting\n",
+      (int)error);
+  force_reconnect(ch);
 }
 
 
@@ -167,9 +164,9 @@ error_handler (void *cls,
  *         failure (message queue no longer exists)
  */
 static int
-transmit_suggestion (void *cls,
-                     const struct GNUNET_PeerIdentity *peer,
-                     void *value)
+transmit_suggestion(void *cls,
+                    const struct GNUNET_PeerIdentity *peer,
+                    void *value)
 {
   struct GNUNET_ATS_ApplicationHandle *ch = cls;
   struct GNUNET_ATS_ApplicationSuggestHandle *sh = value;
@@ -178,12 +175,12 @@ transmit_suggestion (void *cls,
 
   if (NULL == ch->mq)
     return GNUNET_SYSERR;
-  ev = GNUNET_MQ_msg (m,
-                      GNUNET_MESSAGE_TYPE_ATS_SUGGEST);
-  m->pk = htonl ((uint32_t) sh->pk);
+  ev = GNUNET_MQ_msg(m,
+                     GNUNET_MESSAGE_TYPE_ATS_SUGGEST);
+  m->pk = htonl((uint32_t)sh->pk);
   m->bw = sh->bw;
   m->peer = *peer;
-  GNUNET_MQ_send (ch->mq, ev);
+  GNUNET_MQ_send(ch->mq, ev);
   return GNUNET_OK;
 }
 
@@ -194,26 +191,26 @@ transmit_suggestion (void *cls,
  * @param ch handle to use to re-connect.
  */
 static void
-reconnect (struct GNUNET_ATS_ApplicationHandle *ch)
+reconnect(struct GNUNET_ATS_ApplicationHandle *ch)
 {
   static const struct GNUNET_MQ_MessageHandler handlers[] = {
     { NULL, 0, 0 }
   };
 
-  GNUNET_assert (NULL == ch->mq);
-  ch->mq = GNUNET_CLIENT_connect (ch->cfg,
-                                  "ats",
-                                  handlers,
-                                  &error_handler,
-                                  ch);
+  GNUNET_assert(NULL == ch->mq);
+  ch->mq = GNUNET_CLIENT_connect(ch->cfg,
+                                 "ats",
+                                 handlers,
+                                 &error_handler,
+                                 ch);
   if (NULL == ch->mq)
-  {
-    force_reconnect (ch);
-    return;
-  }
-  GNUNET_CONTAINER_multipeermap_iterate (ch->sug_requests,
-                                         &transmit_suggestion,
-                                         ch);
+    {
+      force_reconnect(ch);
+      return;
+    }
+  GNUNET_CONTAINER_multipeermap_iterate(ch->sug_requests,
+                                        &transmit_suggestion,
+                                        ch);
 }
 
 
@@ -224,15 +221,15 @@ reconnect (struct GNUNET_ATS_ApplicationHandle *ch)
  * @return ats application handle, NULL on error
  */
 struct GNUNET_ATS_ApplicationHandle *
-GNUNET_ATS_application_init (const struct GNUNET_CONFIGURATION_Handle *cfg)
+GNUNET_ATS_application_init(const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
   struct GNUNET_ATS_ApplicationHandle *ch;
 
-  ch = GNUNET_new (struct GNUNET_ATS_ApplicationHandle);
+  ch = GNUNET_new(struct GNUNET_ATS_ApplicationHandle);
   ch->cfg = cfg;
-  ch->sug_requests = GNUNET_CONTAINER_multipeermap_create (32,
-                                                           GNUNET_YES);
-  reconnect (ch);
+  ch->sug_requests = GNUNET_CONTAINER_multipeermap_create(32,
+                                                          GNUNET_YES);
+  reconnect(ch);
   return ch;
 }
 
@@ -247,13 +244,13 @@ GNUNET_ATS_application_init (const struct GNUNET_CONFIGURATION_Handle *cfg)
  * @return #GNUNET_OK (continue to iterate)
  */
 static int
-free_sug_handle (void *cls,
-                 const struct GNUNET_PeerIdentity *key,
-                 void *value)
+free_sug_handle(void *cls,
+                const struct GNUNET_PeerIdentity *key,
+                void *value)
 {
   struct GNUNET_ATS_ApplicationSuggestHandle *cur = value;
 
-  GNUNET_free (cur);
+  GNUNET_free(cur);
   return GNUNET_OK;
 }
 
@@ -264,23 +261,23 @@ free_sug_handle (void *cls,
  * @param ch handle to release
  */
 void
-GNUNET_ATS_application_done (struct GNUNET_ATS_ApplicationHandle *ch)
+GNUNET_ATS_application_done(struct GNUNET_ATS_ApplicationHandle *ch)
 {
   if (NULL != ch->mq)
-  {
-    GNUNET_MQ_destroy (ch->mq);
-    ch->mq = NULL;
-  }
+    {
+      GNUNET_MQ_destroy(ch->mq);
+      ch->mq = NULL;
+    }
   if (NULL != ch->task)
-  {
-    GNUNET_SCHEDULER_cancel (ch->task);
-    ch->task = NULL;
-  }
-  GNUNET_CONTAINER_multipeermap_iterate (ch->sug_requests,
-                                         &free_sug_handle,
-                                         NULL);
-  GNUNET_CONTAINER_multipeermap_destroy (ch->sug_requests);
-  GNUNET_free (ch);
+    {
+      GNUNET_SCHEDULER_cancel(ch->task);
+      ch->task = NULL;
+    }
+  GNUNET_CONTAINER_multipeermap_iterate(ch->sug_requests,
+                                        &free_sug_handle,
+                                        NULL);
+  GNUNET_CONTAINER_multipeermap_destroy(ch->sug_requests);
+  GNUNET_free(ch);
 }
 
 
@@ -298,31 +295,31 @@ GNUNET_ATS_application_done (struct GNUNET_ATS_ApplicationHandle *ch)
  * @return suggest handle, NULL if a request is already pending
  */
 struct GNUNET_ATS_ApplicationSuggestHandle *
-GNUNET_ATS_application_suggest (struct GNUNET_ATS_ApplicationHandle *ch,
-                                const struct GNUNET_PeerIdentity *peer,
-                                enum GNUNET_MQ_PreferenceKind pk,
-                                struct GNUNET_BANDWIDTH_Value32NBO bw)
+GNUNET_ATS_application_suggest(struct GNUNET_ATS_ApplicationHandle *ch,
+                               const struct GNUNET_PeerIdentity *peer,
+                               enum GNUNET_MQ_PreferenceKind pk,
+                               struct GNUNET_BANDWIDTH_Value32NBO bw)
 {
   struct GNUNET_ATS_ApplicationSuggestHandle *s;
 
-  s = GNUNET_new (struct GNUNET_ATS_ApplicationSuggestHandle);
+  s = GNUNET_new(struct GNUNET_ATS_ApplicationSuggestHandle);
   s->ch = ch;
   s->id = *peer;
   s->pk = pk;
   s->bw = bw;
-  (void) GNUNET_CONTAINER_multipeermap_put (ch->sug_requests,
-                                            &s->id,
-                                            s,
-                                            GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
-  LOG (GNUNET_ERROR_TYPE_DEBUG,
-       "Requesting ATS to suggest address for `%s'\n",
-       GNUNET_i2s (peer));
+  (void)GNUNET_CONTAINER_multipeermap_put(ch->sug_requests,
+                                          &s->id,
+                                          s,
+                                          GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
+  LOG(GNUNET_ERROR_TYPE_DEBUG,
+      "Requesting ATS to suggest address for `%s'\n",
+      GNUNET_i2s(peer));
   if (NULL == ch->mq)
     return s;
-  GNUNET_assert (GNUNET_OK ==
-                 transmit_suggestion (ch,
-                                      &s->id,
-                                      s));
+  GNUNET_assert(GNUNET_OK ==
+                transmit_suggestion(ch,
+                                    &s->id,
+                                    s));
   return s;
 }
 
@@ -333,32 +330,32 @@ GNUNET_ATS_application_suggest (struct GNUNET_ATS_ApplicationHandle *ch,
  * @param sh handle to stop
  */
 void
-GNUNET_ATS_application_suggest_cancel (struct GNUNET_ATS_ApplicationSuggestHandle *sh)
+GNUNET_ATS_application_suggest_cancel(struct GNUNET_ATS_ApplicationSuggestHandle *sh)
 {
   struct GNUNET_ATS_ApplicationHandle *ch = sh->ch;
   struct GNUNET_MQ_Envelope *ev;
   struct ExpressPreferenceMessage *m;
 
-  LOG (GNUNET_ERROR_TYPE_DEBUG,
-       "Telling ATS we no longer care for an address for `%s'\n",
-       GNUNET_i2s (&sh->id));
-  GNUNET_assert (GNUNET_OK ==
-                 GNUNET_CONTAINER_multipeermap_remove (ch->sug_requests,
-                                                       &sh->id,
-                                                       sh));
+  LOG(GNUNET_ERROR_TYPE_DEBUG,
+      "Telling ATS we no longer care for an address for `%s'\n",
+      GNUNET_i2s(&sh->id));
+  GNUNET_assert(GNUNET_OK ==
+                GNUNET_CONTAINER_multipeermap_remove(ch->sug_requests,
+                                                     &sh->id,
+                                                     sh));
   if (NULL == ch->mq)
-  {
-    GNUNET_free (sh);
-    return;
-  }
-  ev = GNUNET_MQ_msg (m,
-		      GNUNET_MESSAGE_TYPE_ATS_SUGGEST_CANCEL);
-  m->pk = htonl ((uint32_t) sh->pk);
+    {
+      GNUNET_free(sh);
+      return;
+    }
+  ev = GNUNET_MQ_msg(m,
+                     GNUNET_MESSAGE_TYPE_ATS_SUGGEST_CANCEL);
+  m->pk = htonl((uint32_t)sh->pk);
   m->bw = sh->bw;
   m->peer = sh->id;
-  GNUNET_MQ_send (ch->mq,
-                  ev);
-  GNUNET_free (sh);
+  GNUNET_MQ_send(ch->mq,
+                 ev);
+  GNUNET_free(sh);
 }
 
 

+ 215 - 220
src/ats/ats_api2_transport.c

@@ -16,7 +16,7 @@
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
-*/
+ */
 /**
  * @file ats/ats_api2_transport.c
  * @brief address suggestions and bandwidth allocation
@@ -27,7 +27,7 @@
 #include "gnunet_ats_transport_service.h"
 #include "ats2.h"
 
-#define LOG(kind,...) GNUNET_log_from(kind, "ats-transport-api", __VA_ARGS__)
+#define LOG(kind, ...) GNUNET_log_from(kind, "ats-transport-api", __VA_ARGS__)
 
 
 /**
@@ -35,9 +35,7 @@
  * doesn't matter if we have a session, any session that ATS is
  * allowed to suggest right now should be tracked.
  */
-struct GNUNET_ATS_SessionRecord
-{
-
+struct GNUNET_ATS_SessionRecord {
   /**
    * Transport handle this session record belongs to.
    */
@@ -75,16 +73,13 @@ struct GNUNET_ATS_SessionRecord
    * messages.
    */
   uint32_t slot;
-
 };
 
 
 /**
  * Handle to the ATS subsystem for bandwidth/transport transport information.
  */
-struct GNUNET_ATS_TransportHandle
-{
-
+struct GNUNET_ATS_TransportHandle {
   /**
    * Our configuration.
    */
@@ -129,7 +124,6 @@ struct GNUNET_ATS_TransportHandle
    * Reconnect backoff delay.
    */
   struct GNUNET_TIME_Relative backoff;
-
 };
 
 
@@ -141,18 +135,18 @@ struct GNUNET_ATS_TransportHandle
  * @param hbo value read
  */
 static void
-properties_hton (struct PropertiesNBO *nbo,
-                 const struct GNUNET_ATS_Properties *hbo)
+properties_hton(struct PropertiesNBO *nbo,
+                const struct GNUNET_ATS_Properties *hbo)
 {
-  nbo->delay = GNUNET_TIME_relative_hton (hbo->delay);
-  nbo->goodput_out = htonl (hbo->goodput_out);
-  nbo->goodput_in = htonl (hbo->goodput_in);
-  nbo->utilization_out = htonl (hbo->utilization_out);
-  nbo->utilization_in = htonl (hbo->utilization_in);
-  nbo->distance = htonl (hbo->distance);
-  nbo->mtu = htonl (hbo->mtu);
-  nbo->nt = htonl ((uint32_t) hbo->nt);
-  nbo->cc = htonl ((uint32_t) hbo->cc);
+  nbo->delay = GNUNET_TIME_relative_hton(hbo->delay);
+  nbo->goodput_out = htonl(hbo->goodput_out);
+  nbo->goodput_in = htonl(hbo->goodput_in);
+  nbo->utilization_out = htonl(hbo->utilization_out);
+  nbo->utilization_in = htonl(hbo->utilization_in);
+  nbo->distance = htonl(hbo->distance);
+  nbo->mtu = htonl(hbo->mtu);
+  nbo->nt = htonl((uint32_t)hbo->nt);
+  nbo->cc = htonl((uint32_t)hbo->cc);
 }
 
 
@@ -162,7 +156,7 @@ properties_hton (struct PropertiesNBO *nbo,
  * @param sh handle to use to re-connect.
  */
 static void
-reconnect (struct GNUNET_ATS_TransportHandle *ath);
+reconnect(struct GNUNET_ATS_TransportHandle *ath);
 
 
 /**
@@ -171,12 +165,12 @@ reconnect (struct GNUNET_ATS_TransportHandle *ath);
  * @param cls handle to use to re-connect.
  */
 static void
-reconnect_task (void *cls)
+reconnect_task(void *cls)
 {
   struct GNUNET_ATS_TransportHandle *ath = cls;
 
   ath->task = NULL;
-  reconnect (ath);
+  reconnect(ath);
 }
 
 
@@ -186,20 +180,20 @@ reconnect_task (void *cls)
  * @param ath our handle
  */
 static void
-force_reconnect (struct GNUNET_ATS_TransportHandle *ath)
+force_reconnect(struct GNUNET_ATS_TransportHandle *ath)
 {
   if (NULL != ath->mq)
-  {
-    GNUNET_MQ_destroy (ath->mq);
-    ath->mq = NULL;
-  }
+    {
+      GNUNET_MQ_destroy(ath->mq);
+      ath->mq = NULL;
+    }
   /* FIXME: do we tell transport service about disconnect events? CON:
      initially ATS will have a really screwed picture of the world and
      the rapid change would be bad.  PRO: if we don't, ATS and
      transport may disagree about the allocation for a while...
      For now: lazy: do nothing. */
-  ath->backoff = GNUNET_TIME_STD_BACKOFF (ath->backoff);
-  ath->task = GNUNET_SCHEDULER_add_delayed (ath->backoff,
+  ath->backoff = GNUNET_TIME_STD_BACKOFF(ath->backoff);
+  ath->task = GNUNET_SCHEDULER_add_delayed(ath->backoff,
                                            &reconnect_task,
                                            ath);
 }
@@ -212,11 +206,11 @@ force_reconnect (struct GNUNET_ATS_TransportHandle *ath)
  * @param m message received
  */
 static int
-check_ats_address_suggestion (void *cls,
-                              const struct AddressSuggestionMessage *m)
+check_ats_address_suggestion(void *cls,
+                             const struct AddressSuggestionMessage *m)
 {
-  (void) cls;
-  GNUNET_MQ_check_zero_termination (m);
+  (void)cls;
+  GNUNET_MQ_check_zero_termination(m);
   return GNUNET_SYSERR;
 }
 
@@ -228,13 +222,13 @@ check_ats_address_suggestion (void *cls,
  * @param m message received
  */
 static void
-handle_ats_address_suggestion (void *cls,
-			       const struct AddressSuggestionMessage *m)
+handle_ats_address_suggestion(void *cls,
+                              const struct AddressSuggestionMessage *m)
 {
   struct GNUNET_ATS_TransportHandle *ath = cls;
-  const char *address = (const char *) &m[1];
+  const char *address = (const char *)&m[1];
 
-  ath->suggest_cb (ath->suggest_cb_cls,
+  ath->suggest_cb(ath->suggest_cb_cls,
                   &m->peer,
                   address);
 }
@@ -243,8 +237,7 @@ handle_ats_address_suggestion (void *cls,
 /**
  * Closure for #match_session_cb.
  */
-struct FindContext
-{
+struct FindContext {
   /**
    * Key to look for.
    */
@@ -266,19 +259,19 @@ struct FindContext
  * @return #GNUNET_NO if match found, #GNUNET_YES to continue searching
  */
 static int
-match_session_cb (void *cls,
-                  const struct GNUNET_PeerIdentity *pid,
-                  void *value)
+match_session_cb(void *cls,
+                 const struct GNUNET_PeerIdentity *pid,
+                 void *value)
 {
   struct FindContext *fc = cls;
   struct GNUNET_ATS_SessionRecord *sr = value;
 
-  (void) pid;
+  (void)pid;
   if (fc->session_id == sr->slot)
-  {
-    fc->sr = sr;
-    return GNUNET_NO;
-  }
+    {
+      fc->sr = sr;
+      return GNUNET_NO;
+    }
   return GNUNET_YES;
 }
 
@@ -293,18 +286,19 @@ match_session_cb (void *cls,
  * @return NULL if no such record exists
  */
 static struct GNUNET_ATS_SessionRecord *
-find_session (struct GNUNET_ATS_TransportHandle *ath,
-              uint32_t session_id,
-              const struct GNUNET_PeerIdentity *pid)
+find_session(struct GNUNET_ATS_TransportHandle *ath,
+             uint32_t session_id,
+             const struct GNUNET_PeerIdentity *pid)
 {
   struct FindContext fc = {
     .session_id = session_id,
     .sr = NULL
   };
-  GNUNET_CONTAINER_multipeermap_get_multiple (ath->records,
-                                              pid,
-                                              &match_session_cb,
-                                              &fc);
+
+  GNUNET_CONTAINER_multipeermap_get_multiple(ath->records,
+                                             pid,
+                                             &match_session_cb,
+                                             &fc);
   return fc.sr;
 }
 
@@ -316,34 +310,34 @@ find_session (struct GNUNET_ATS_TransportHandle *ath,
  * @param m message received
  */
 static void
-handle_ats_session_allocation (void *cls,
-			       const struct SessionAllocationMessage *m)
+handle_ats_session_allocation(void *cls,
+                              const struct SessionAllocationMessage *m)
 {
   struct GNUNET_ATS_TransportHandle *ath = cls;
   struct GNUNET_ATS_SessionRecord *ar;
   uint32_t session_id;
 
-  session_id = ntohl (m->session_id);
-  ar = find_session (ath,
-                     session_id,
-                     &m->peer);
+  session_id = ntohl(m->session_id);
+  ar = find_session(ath,
+                    session_id,
+                    &m->peer);
   if (NULL == ar)
-  {
-    /* this can (rarely) happen if ATS changes an sessiones allocation
-       just when the transport service deleted it */
-    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-                "Allocation ignored, session unknown\n");
-    return;
-  }
+    {
+      /* this can (rarely) happen if ATS changes an sessiones allocation
+         just when the transport service deleted it */
+      GNUNET_log(GNUNET_ERROR_TYPE_INFO,
+                 "Allocation ignored, session unknown\n");
+      return;
+    }
   ath->backoff = GNUNET_TIME_UNIT_ZERO;
-  LOG (GNUNET_ERROR_TYPE_DEBUG,
-       "ATS allocates bandwidth for peer `%s' using address %s\n",
-       GNUNET_i2s (&ar->pid),
-       ar->address);
-  ath->alloc_cb (ath->alloc_cb_cls,
-                 ar->session,
-                 m->bandwidth_out,
-                 m->bandwidth_in);
+  LOG(GNUNET_ERROR_TYPE_DEBUG,
+      "ATS allocates bandwidth for peer `%s' using address %s\n",
+      GNUNET_i2s(&ar->pid),
+      ar->address);
+  ath->alloc_cb(ath->alloc_cb_cls,
+                ar->session,
+                m->bandwidth_out,
+                m->bandwidth_in);
 }
 
 
@@ -355,15 +349,15 @@ handle_ats_session_allocation (void *cls,
  * @param error details about the error
  */
 static void
-error_handler (void *cls,
-               enum GNUNET_MQ_Error error)
+error_handler(void *cls,
+              enum GNUNET_MQ_Error error)
 {
   struct GNUNET_ATS_TransportHandle *ath = cls;
 
-  LOG (GNUNET_ERROR_TYPE_DEBUG,
-       "ATS connection died (code %d), reconnecting\n",
-       (int) error);
-  force_reconnect (ath);
+  LOG(GNUNET_ERROR_TYPE_DEBUG,
+      "ATS connection died (code %d), reconnecting\n",
+      (int)error);
+  force_reconnect(ath);
 }
 
 
@@ -374,7 +368,7 @@ error_handler (void *cls,
  * @param ar the session to inform the ATS service about
  */
 static void
-send_add_session_message (const struct GNUNET_ATS_SessionRecord *ar)
+send_add_session_message(const struct GNUNET_ATS_SessionRecord *ar)
 {
   struct GNUNET_ATS_TransportHandle *ath = ar->ath;
   struct GNUNET_MQ_Envelope *ev;
@@ -383,26 +377,26 @@ send_add_session_message (const struct GNUNET_ATS_SessionRecord *ar)
 
   if (NULL == ath->mq)
     return; /* disconnected, skip for now */
-  alen = strlen (ar->address) + 1;
-  ev = GNUNET_MQ_msg_extra (m,
-                            alen,
-                            (NULL == ar->session)
-                            ? GNUNET_MESSAGE_TYPE_ATS_SESSION_ADD_INBOUND_ONLY
-                            : GNUNET_MESSAGE_TYPE_ATS_SESSION_ADD);
+  alen = strlen(ar->address) + 1;
+  ev = GNUNET_MQ_msg_extra(m,
+                           alen,
+                           (NULL == ar->session)
+                           ? GNUNET_MESSAGE_TYPE_ATS_SESSION_ADD_INBOUND_ONLY
+                           : GNUNET_MESSAGE_TYPE_ATS_SESSION_ADD);
   m->peer = ar->pid;
-  m->session_id = htonl (ar->slot);
-  properties_hton (&m->properties,
-                   &ar->properties);
-  GNUNET_memcpy (&m[1],
-                 ar->address,
-                 alen);
-
-  LOG (GNUNET_ERROR_TYPE_DEBUG,
-       "Adding address `%s' for peer `%s'\n",
-       ar->address,
-       GNUNET_i2s (&ar->pid));
-  GNUNET_MQ_send (ath->mq,
-                  ev);
+  m->session_id = htonl(ar->slot);
+  properties_hton(&m->properties,
+                  &ar->properties);
+  GNUNET_memcpy(&m[1],
+                ar->address,
+                alen);
+
+  LOG(GNUNET_ERROR_TYPE_DEBUG,
+      "Adding address `%s' for peer `%s'\n",
+      ar->address,
+      GNUNET_i2s(&ar->pid));
+  GNUNET_MQ_send(ath->mq,
+                 ev);
 }
 
 
@@ -415,15 +409,15 @@ send_add_session_message (const struct GNUNET_ATS_SessionRecord *ar)
  * @return #GNUNET_OK
  */
 static int
-send_add_session_cb (void *cls,
-                     const struct GNUNET_PeerIdentity *pid,
-                     void *value)
+send_add_session_cb(void *cls,
+                    const struct GNUNET_PeerIdentity *pid,
+                    void *value)
 {
   struct GNUNET_ATS_SessionRecord *ar = value;
 
-  (void) cls;
-  (void) pid;
-  send_add_session_message (ar);
+  (void)cls;
+  (void)pid;
+  send_add_session_message(ar);
   return GNUNET_OK;
 }
 
@@ -434,43 +428,43 @@ send_add_session_cb (void *cls,
  * @param ath handle to use to re-connect.
  */
 static void
-reconnect (struct GNUNET_ATS_TransportHandle *ath)
+reconnect(struct GNUNET_ATS_TransportHandle *ath)
 {
   struct GNUNET_MQ_MessageHandler handlers[] = {
-    GNUNET_MQ_hd_var_size (ats_address_suggestion,
-                           GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION,
-                           struct AddressSuggestionMessage,
-                           ath),
-    GNUNET_MQ_hd_fixed_size (ats_session_allocation,
-                             GNUNET_MESSAGE_TYPE_ATS_SESSION_ALLOCATION,
-                             struct SessionAllocationMessage,
-                             ath),
-    GNUNET_MQ_handler_end ()
+    GNUNET_MQ_hd_var_size(ats_address_suggestion,
+                          GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION,
+                          struct AddressSuggestionMessage,
+                          ath),
+    GNUNET_MQ_hd_fixed_size(ats_session_allocation,
+                            GNUNET_MESSAGE_TYPE_ATS_SESSION_ALLOCATION,
+                            struct SessionAllocationMessage,
+                            ath),
+    GNUNET_MQ_handler_end()
   };
   struct GNUNET_MQ_Envelope *ev;
   struct GNUNET_MessageHeader *init;
 
-  GNUNET_assert (NULL == ath->mq);
-  ath->mq = GNUNET_CLIENT_connect (ath->cfg,
+  GNUNET_assert(NULL == ath->mq);
+  ath->mq = GNUNET_CLIENT_connect(ath->cfg,
                                   "ats",
                                   handlers,
                                   &error_handler,
                                   ath);
   if (NULL == ath->mq)
-  {
-    GNUNET_break (0);
-    force_reconnect (ath);
-    return;
-  }
-  ev = GNUNET_MQ_msg (init,
-                      GNUNET_MESSAGE_TYPE_ATS_START);
-  GNUNET_MQ_send (ath->mq,
-                  ev);
+    {
+      GNUNET_break(0);
+      force_reconnect(ath);
+      return;
+    }
+  ev = GNUNET_MQ_msg(init,
+                     GNUNET_MESSAGE_TYPE_ATS_START);
+  GNUNET_MQ_send(ath->mq,
+                 ev);
   if (NULL == ath->mq)
     return;
-  GNUNET_CONTAINER_multipeermap_iterate (ath->records,
-                                         &send_add_session_cb,
-                                         ath);
+  GNUNET_CONTAINER_multipeermap_iterate(ath->records,
+                                        &send_add_session_cb,
+                                        ath);
 }
 
 
@@ -485,23 +479,23 @@ reconnect (struct GNUNET_ATS_TransportHandle *ath)
  * @return ats context
  */
 struct GNUNET_ATS_TransportHandle *
-GNUNET_ATS_transport_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
-                           GNUNET_ATS_AllocationCallback alloc_cb,
-                           void *alloc_cb_cls,
-                           GNUNET_ATS_SuggestionCallback suggest_cb,
-                           void *suggest_cb_cls)
+GNUNET_ATS_transport_init(const struct GNUNET_CONFIGURATION_Handle *cfg,
+                          GNUNET_ATS_AllocationCallback alloc_cb,
+                          void *alloc_cb_cls,
+                          GNUNET_ATS_SuggestionCallback suggest_cb,
+                          void *suggest_cb_cls)
 {
   struct GNUNET_ATS_TransportHandle *ath;
 
-  ath = GNUNET_new (struct GNUNET_ATS_TransportHandle);
+  ath = GNUNET_new(struct GNUNET_ATS_TransportHandle);
   ath->cfg = cfg;
   ath->suggest_cb = suggest_cb;
   ath->suggest_cb_cls = suggest_cb_cls;
   ath->alloc_cb = alloc_cb;
   ath->alloc_cb_cls = alloc_cb_cls;
-  ath->records = GNUNET_CONTAINER_multipeermap_create (128,
+  ath->records = GNUNET_CONTAINER_multipeermap_create(128,
                                                       GNUNET_YES);
-  reconnect (ath);
+  reconnect(ath);
   return ath;
 }
 
@@ -515,15 +509,15 @@ GNUNET_ATS_transport_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
  * @return #GNUNET_OK
  */
 static int
-free_record (void *cls,
-             const struct GNUNET_PeerIdentity *pid,
-             void *value)
+free_record(void *cls,
+            const struct GNUNET_PeerIdentity *pid,
+            void *value)
 {
   struct GNUNET_ATS_SessionRecord *ar = value;
 
-  (void) cls;
-  (void) pid;
-  GNUNET_free (ar);
+  (void)cls;
+  (void)pid;
+  GNUNET_free(ar);
   return GNUNET_OK;
 }
 
@@ -534,23 +528,23 @@ free_record (void *cls,
  * @param ath handle to release
  */
 void
-GNUNET_ATS_transport_done (struct GNUNET_ATS_TransportHandle *ath)
+GNUNET_ATS_transport_done(struct GNUNET_ATS_TransportHandle *ath)
 {
   if (NULL != ath->mq)
-  {
-    GNUNET_MQ_destroy (ath->mq);
-    ath->mq = NULL;
-  }
+    {
+      GNUNET_MQ_destroy(ath->mq);
+      ath->mq = NULL;
+    }
   if (NULL != ath->task)
-  {
-    GNUNET_SCHEDULER_cancel (ath->task);
-    ath->task = NULL;
-  }
-  GNUNET_CONTAINER_multipeermap_iterate (ath->records,
-                                         &free_record,
-                                         NULL);
-  GNUNET_CONTAINER_multipeermap_destroy (ath->records);
-  GNUNET_free (ath);
+    {
+      GNUNET_SCHEDULER_cancel(ath->task);
+      ath->task = NULL;
+    }
+  GNUNET_CONTAINER_multipeermap_iterate(ath->records,
+                                        &free_record,
+                                        NULL);
+  GNUNET_CONTAINER_multipeermap_destroy(ath->records);
+  GNUNET_free(ath);
 }
 
 
@@ -569,55 +563,56 @@ GNUNET_ATS_transport_done (struct GNUNET_ATS_TransportHandle *ath)
  *         on error (i.e. ATS knows this exact session already)
  */
 struct GNUNET_ATS_SessionRecord *
-GNUNET_ATS_session_add (struct GNUNET_ATS_TransportHandle *ath,
-                        const struct GNUNET_PeerIdentity *pid,
-                        const char *address,
-                        struct GNUNET_ATS_Session *session,
-                        const struct GNUNET_ATS_Properties *prop)
+GNUNET_ATS_session_add(struct GNUNET_ATS_TransportHandle *ath,
+                       const struct GNUNET_PeerIdentity *pid,
+                       const char *address,
+                       struct GNUNET_ATS_Session *session,
+                       const struct GNUNET_ATS_Properties *prop)
 {
   struct GNUNET_ATS_SessionRecord *ar;
   uint32_t s;
   size_t alen;
 
   if (NULL == address)
-  {
-    /* we need a valid address */
-    GNUNET_break (0);
-    return NULL;
-  }
-  alen = strlen (address) + 1;
-  if ( (alen + sizeof (struct SessionAddMessage) >= GNUNET_MAX_MESSAGE_SIZE) ||
-       (alen >= GNUNET_MAX_MESSAGE_SIZE) )
-  {
-    /* address too large for us, this should not happen */
-    GNUNET_break (0);
-    return NULL;
-  }
+    {
+      /* we need a valid address */
+      GNUNET_break(0);
+      return NULL;
+    }
+  alen = strlen(address) + 1;
+  if ((alen + sizeof(struct SessionAddMessage) >= GNUNET_MAX_MESSAGE_SIZE) ||
+      (alen >= GNUNET_MAX_MESSAGE_SIZE))
+    {
+      /* address too large for us, this should not happen */
+      GNUNET_break(0);
+      return NULL;
+    }
 
   /* Spin 's' until we find an unused session ID for this pid */
-  for (s = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
-                                     UINT32_MAX);
-       NULL != find_session (ath,
-                             s,
-                             pid);
-       s++) ;
-
-  alen = strlen (address) + 1;
-  ar = GNUNET_malloc (sizeof (struct GNUNET_ATS_SessionRecord) + alen);
+  for (s = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK,
+                                    UINT32_MAX);
+       NULL != find_session(ath,
+                            s,
+                            pid);
+       s++)
+    ;
+
+  alen = strlen(address) + 1;
+  ar = GNUNET_malloc(sizeof(struct GNUNET_ATS_SessionRecord) + alen);
   ar->ath = ath;
   ar->slot = s;
   ar->session = session;
-  ar->address = (const char *) &ar[1];
+  ar->address = (const char *)&ar[1];
   ar->pid = *pid;
   ar->properties = *prop;
-  memcpy (&ar[1],
-          address,
-          alen);
-  (void) GNUNET_CONTAINER_multipeermap_put (ath->records,
-                                            &ar->pid,
-                                            ar,
-                                            GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
-  send_add_session_message (ar);
+  memcpy(&ar[1],
+         address,
+         alen);
+  (void)GNUNET_CONTAINER_multipeermap_put(ath->records,
+                                          &ar->pid,
+                                          ar,
+                                          GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
+  send_add_session_message(ar);
   return ar;
 }
 
@@ -634,28 +629,28 @@ GNUNET_ATS_session_add (struct GNUNET_ATS_TransportHandle *ath,
  * @param prop performance data for the session
  */
 void
-GNUNET_ATS_session_update (struct GNUNET_ATS_SessionRecord *ar,
-                           const struct GNUNET_ATS_Properties *prop)
+GNUNET_ATS_session_update(struct GNUNET_ATS_SessionRecord *ar,
+                          const struct GNUNET_ATS_Properties *prop)
 {
   struct GNUNET_ATS_TransportHandle *ath = ar->ath;
   struct GNUNET_MQ_Envelope *ev;
   struct SessionUpdateMessage *m;
 
-  LOG (GNUNET_ERROR_TYPE_DEBUG,
-       "Updating address `%s' for peer `%s'\n",
-       ar->address,
-       GNUNET_i2s (&ar->pid));
+  LOG(GNUNET_ERROR_TYPE_DEBUG,
+      "Updating address `%s' for peer `%s'\n",
+      ar->address,
+      GNUNET_i2s(&ar->pid));
   ar->properties = *prop;
   if (NULL == ath->mq)
     return; /* disconnected, skip for now */
-  ev = GNUNET_MQ_msg (m,
-                      GNUNET_MESSAGE_TYPE_ATS_SESSION_UPDATE);
-  m->session_id = htonl (ar->slot);
+  ev = GNUNET_MQ_msg(m,
+                     GNUNET_MESSAGE_TYPE_ATS_SESSION_UPDATE);
+  m->session_id = htonl(ar->slot);
   m->peer = ar->pid;
-  properties_hton (&m->properties,
-                   &ar->properties);
-  GNUNET_MQ_send (ath->mq,
-                  ev);
+  properties_hton(&m->properties,
+                  &ar->properties);
+  GNUNET_MQ_send(ath->mq,
+                 ev);
 }
 
 
@@ -667,24 +662,24 @@ GNUNET_ATS_session_update (struct GNUNET_ATS_SessionRecord *ar,
  * @param ar session record to drop
  */
 void
-GNUNET_ATS_session_del (struct GNUNET_ATS_SessionRecord *ar)
+GNUNET_ATS_session_del(struct GNUNET_ATS_SessionRecord *ar)
 {
   struct GNUNET_ATS_TransportHandle *ath = ar->ath;
   struct GNUNET_MQ_Envelope *ev;
   struct SessionDelMessage *m;
 
-  LOG (GNUNET_ERROR_TYPE_DEBUG,
-       "Deleting address `%s' for peer `%s'\n",
-       ar->address,
-       GNUNET_i2s (&ar->pid));
+  LOG(GNUNET_ERROR_TYPE_DEBUG,
+      "Deleting address `%s' for peer `%s'\n",
+      ar->address,
+      GNUNET_i2s(&ar->pid));
   if (NULL == ath->mq)
     return;
-  ev = GNUNET_MQ_msg (m,
-                      GNUNET_MESSAGE_TYPE_ATS_SESSION_DEL);
-  m->session_id = htonl (ar->slot);
+  ev = GNUNET_MQ_msg(m,
+                     GNUNET_MESSAGE_TYPE_ATS_SESSION_DEL);
+  m->session_id = htonl(ar->slot);
   m->peer = ar->pid;
-  GNUNET_MQ_send (ath->mq,
-                  ev);
+  GNUNET_MQ_send(ath->mq,
+                 ev);
 }
 
 

+ 109 - 112
src/ats/ats_api_connectivity.c

@@ -11,12 +11,12 @@
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      Affero General Public License for more details.
-    
+
      You should have received a copy of the GNU Affero General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
-*/
+ */
 /**
  * @file ats/ats_api_connectivity.c
  * @brief enable clients to ask ATS about establishing connections to peers
@@ -28,14 +28,13 @@
 #include "ats.h"
 
 
-#define LOG(kind,...) GNUNET_log_from(kind, "ats-connectivity-api", __VA_ARGS__)
+#define LOG(kind, ...) GNUNET_log_from(kind, "ats-connectivity-api", __VA_ARGS__)
 
 
 /**
  * Handle for ATS address suggestion requests.
  */
-struct GNUNET_ATS_ConnectivitySuggestHandle
-{
+struct GNUNET_ATS_ConnectivitySuggestHandle {
   /**
    * ID of the peer for which address suggestion was requested.
    */
@@ -56,9 +55,7 @@ struct GNUNET_ATS_ConnectivitySuggestHandle
 /**
  * Handle to the ATS subsystem for connectivity management.
  */
-struct GNUNET_ATS_ConnectivityHandle
-{
-
+struct GNUNET_ATS_ConnectivityHandle {
   /**
    * Our configuration.
    */
@@ -94,7 +91,7 @@ struct GNUNET_ATS_ConnectivityHandle
  * @param ch handle to use to re-connect.
  */
 static void
-reconnect (struct GNUNET_ATS_ConnectivityHandle *ch);
+reconnect(struct GNUNET_ATS_ConnectivityHandle *ch);
 
 
 /**
@@ -103,12 +100,12 @@ reconnect (struct GNUNET_ATS_ConnectivityHandle *ch);
  * @param cls handle to use to re-connect.
  */
 static void
-reconnect_task (void *cls)
+reconnect_task(void *cls)
 {
   struct GNUNET_ATS_ConnectivityHandle *ch = cls;
 
   ch->task = NULL;
-  reconnect (ch);
+  reconnect(ch);
 }
 
 
@@ -118,17 +115,17 @@ reconnect_task (void *cls)
  * @param ch our handle
  */
 static void
-force_reconnect (struct GNUNET_ATS_ConnectivityHandle *ch)
+force_reconnect(struct GNUNET_ATS_ConnectivityHandle *ch)
 {
   if (NULL != ch->mq)
-  {
-    GNUNET_MQ_destroy (ch->mq);
-    ch->mq = NULL;
-  }
-  ch->backoff = GNUNET_TIME_STD_BACKOFF (ch->backoff);
-  ch->task = GNUNET_SCHEDULER_add_delayed (ch->backoff,
-                                           &reconnect_task,
-                                           ch);
+    {
+      GNUNET_MQ_destroy(ch->mq);
+      ch->mq = NULL;
+    }
+  ch->backoff = GNUNET_TIME_STD_BACKOFF(ch->backoff);
+  ch->task = GNUNET_SCHEDULER_add_delayed(ch->backoff,
+                                          &reconnect_task,
+                                          ch);
 }
 
 
@@ -140,15 +137,15 @@ force_reconnect (struct GNUNET_ATS_ConnectivityHandle *ch)
  * @param error details about the error
  */
 static void
-error_handler (void *cls,
-               enum GNUNET_MQ_Error error)
+error_handler(void *cls,
+              enum GNUNET_MQ_Error error)
 {
   struct GNUNET_ATS_ConnectivityHandle *ch = cls;
 
-  LOG (GNUNET_ERROR_TYPE_DEBUG,
-       "ATS connection died (code %d), reconnecting\n",
-       (int) error);
-  force_reconnect (ch);
+  LOG(GNUNET_ERROR_TYPE_DEBUG,
+      "ATS connection died (code %d), reconnecting\n",
+      (int)error);
+  force_reconnect(ch);
 }
 
 
@@ -162,9 +159,9 @@ error_handler (void *cls,
  *         failure (message queue no longer exists)
  */
 static int
-transmit_suggestion (void *cls,
-                     const struct GNUNET_PeerIdentity *peer,
-                     void *value)
+transmit_suggestion(void *cls,
+                    const struct GNUNET_PeerIdentity *peer,
+                    void *value)
 {
   struct GNUNET_ATS_ConnectivityHandle *ch = cls;
   struct GNUNET_ATS_ConnectivitySuggestHandle *sh = value;
@@ -173,10 +170,10 @@ transmit_suggestion (void *cls,
 
   if (NULL == ch->mq)
     return GNUNET_SYSERR;
-  ev = GNUNET_MQ_msg (m, GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS);
-  m->strength = htonl (sh->strength);
+  ev = GNUNET_MQ_msg(m, GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS);
+  m->strength = htonl(sh->strength);
   m->peer = *peer;
-  GNUNET_MQ_send (ch->mq, ev);
+  GNUNET_MQ_send(ch->mq, ev);
   return GNUNET_OK;
 }
 
@@ -187,33 +184,33 @@ transmit_suggestion (void *cls,
  * @param ch handle to use to re-connect.
  */
 static void
-reconnect (struct GNUNET_ATS_ConnectivityHandle *ch)
+reconnect(struct GNUNET_ATS_ConnectivityHandle *ch)
 {
   static const struct GNUNET_MQ_MessageHandler handlers[] =
-    { { NULL, 0, 0 } };
+  { { NULL, 0, 0 } };
   struct GNUNET_MQ_Envelope *ev;
   struct ClientStartMessage *init;
 
-  GNUNET_assert (NULL == ch->mq);
-  ch->mq = GNUNET_CLIENT_connect (ch->cfg,
-                                  "ats",
-                                  handlers,
-                                  &error_handler,
-                                  ch);
+  GNUNET_assert(NULL == ch->mq);
+  ch->mq = GNUNET_CLIENT_connect(ch->cfg,
+                                 "ats",
+                                 handlers,
+                                 &error_handler,
+                                 ch);
   if (NULL == ch->mq)
-  {
-    force_reconnect (ch);
-    return;
-  }
-  ev = GNUNET_MQ_msg (init,
-                      GNUNET_MESSAGE_TYPE_ATS_START);
-  init->start_flag = htonl (START_FLAG_CONNECTION_SUGGESTION);
-  GNUNET_MQ_send (ch->mq, ev);
+    {
+      force_reconnect(ch);
+      return;
+    }
+  ev = GNUNET_MQ_msg(init,
+                     GNUNET_MESSAGE_TYPE_ATS_START);
+  init->start_flag = htonl(START_FLAG_CONNECTION_SUGGESTION);
+  GNUNET_MQ_send(ch->mq, ev);
   if (NULL == ch->mq)
     return;
-  GNUNET_CONTAINER_multipeermap_iterate (ch->sug_requests,
-                                         &transmit_suggestion,
-                                         ch);
+  GNUNET_CONTAINER_multipeermap_iterate(ch->sug_requests,
+                                        &transmit_suggestion,
+                                        ch);
 }
 
 
@@ -224,15 +221,15 @@ reconnect (struct GNUNET_ATS_ConnectivityHandle *ch)
  * @return ats connectivity handle, NULL on error
  */
 struct GNUNET_ATS_ConnectivityHandle *
-GNUNET_ATS_connectivity_init (const struct GNUNET_CONFIGURATION_Handle *cfg)
+GNUNET_ATS_connectivity_init(const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
   struct GNUNET_ATS_ConnectivityHandle *ch;
 
-  ch = GNUNET_new (struct GNUNET_ATS_ConnectivityHandle);
+  ch = GNUNET_new(struct GNUNET_ATS_ConnectivityHandle);
   ch->cfg = cfg;
-  ch->sug_requests = GNUNET_CONTAINER_multipeermap_create (32,
-                                                           GNUNET_YES);
-  reconnect (ch);
+  ch->sug_requests = GNUNET_CONTAINER_multipeermap_create(32,
+                                                          GNUNET_YES);
+  reconnect(ch);
   return ch;
 }
 
@@ -247,13 +244,13 @@ GNUNET_ATS_connectivity_init (const struct GNUNET_CONFIGURATION_Handle *cfg)
  * @return #GNUNET_OK (continue to iterate)
  */
 static int
-free_sug_handle (void *cls,
-                 const struct GNUNET_PeerIdentity *key,
-                 void *value)
+free_sug_handle(void *cls,
+                const struct GNUNET_PeerIdentity *key,
+                void *value)
 {
   struct GNUNET_ATS_ConnectivitySuggestHandle *cur = value;
 
-  GNUNET_free (cur);
+  GNUNET_free(cur);
   return GNUNET_OK;
 }
 
@@ -264,23 +261,23 @@ free_sug_handle (void *cls,
  * @param ch handle to release
  */
 void
-GNUNET_ATS_connectivity_done (struct GNUNET_ATS_ConnectivityHandle *ch)
+GNUNET_ATS_connectivity_done(struct GNUNET_ATS_ConnectivityHandle *ch)
 {
   if (NULL != ch->mq)
-  {
-    GNUNET_MQ_destroy (ch->mq);
-    ch->mq = NULL;
-  }
+    {
+      GNUNET_MQ_destroy(ch->mq);
+      ch->mq = NULL;
+    }
   if (NULL != ch->task)
-  {
-    GNUNET_SCHEDULER_cancel (ch->task);
-    ch->task = NULL;
-  }
-  GNUNET_CONTAINER_multipeermap_iterate (ch->sug_requests,
-                                         &free_sug_handle,
-                                         NULL);
-  GNUNET_CONTAINER_multipeermap_destroy (ch->sug_requests);
-  GNUNET_free (ch);
+    {
+      GNUNET_SCHEDULER_cancel(ch->task);
+      ch->task = NULL;
+    }
+  GNUNET_CONTAINER_multipeermap_iterate(ch->sug_requests,
+                                        &free_sug_handle,
+                                        NULL);
+  GNUNET_CONTAINER_multipeermap_destroy(ch->sug_requests);
+  GNUNET_free(ch);
 }
 
 
@@ -296,36 +293,36 @@ GNUNET_ATS_connectivity_done (struct GNUNET_ATS_ConnectivityHandle *ch)
  * @return suggest handle, NULL if a request is already pending
  */
 struct GNUNET_ATS_ConnectivitySuggestHandle *
-GNUNET_ATS_connectivity_suggest (struct GNUNET_ATS_ConnectivityHandle *ch,
-                                 const struct GNUNET_PeerIdentity *peer,
-                                 uint32_t strength)
+GNUNET_ATS_connectivity_suggest(struct GNUNET_ATS_ConnectivityHandle *ch,
+                                const struct GNUNET_PeerIdentity *peer,
+                                uint32_t strength)
 {
   struct GNUNET_ATS_ConnectivitySuggestHandle *s;
 
-  s = GNUNET_new (struct GNUNET_ATS_ConnectivitySuggestHandle);
+  s = GNUNET_new(struct GNUNET_ATS_ConnectivitySuggestHandle);
   s->ch = ch;
   s->id = *peer;
   s->strength = strength;
   if (GNUNET_OK !=
-      GNUNET_CONTAINER_multipeermap_put (ch->sug_requests,
-                                         &s->id,
-                                         s,
-                                         GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
-  {
-    LOG (GNUNET_ERROR_TYPE_DEBUG,
-         "Not requesting ATS to suggest address for `%s', request already pending\n",
-         GNUNET_i2s (peer));
-    GNUNET_free (s);
-    return NULL;
-  }
-  LOG (GNUNET_ERROR_TYPE_DEBUG,
-       "Requesting ATS to suggest address for `%s'\n",
-       GNUNET_i2s (peer));
+      GNUNET_CONTAINER_multipeermap_put(ch->sug_requests,
+                                        &s->id,
+                                        s,
+                                        GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
+    {
+      LOG(GNUNET_ERROR_TYPE_DEBUG,
+          "Not requesting ATS to suggest address for `%s', request already pending\n",
+          GNUNET_i2s(peer));
+      GNUNET_free(s);
+      return NULL;
+    }
+  LOG(GNUNET_ERROR_TYPE_DEBUG,
+      "Requesting ATS to suggest address for `%s'\n",
+      GNUNET_i2s(peer));
   if (NULL == ch->mq)
     return s;
-  (void) transmit_suggestion (ch,
-                              &s->id,
-                              s);
+  (void)transmit_suggestion(ch,
+                            &s->id,
+                            s);
   return s;
 }
 
@@ -336,30 +333,30 @@ GNUNET_ATS_connectivity_suggest (struct GNUNET_ATS_ConnectivityHandle *ch,
  * @param sh handle to stop
  */
 void
-GNUNET_ATS_connectivity_suggest_cancel (struct GNUNET_ATS_ConnectivitySuggestHandle *sh)
+GNUNET_ATS_connectivity_suggest_cancel(struct GNUNET_ATS_ConnectivitySuggestHandle *sh)
 {
   struct GNUNET_ATS_ConnectivityHandle *ch = sh->ch;
   struct GNUNET_MQ_Envelope *ev;
   struct RequestAddressMessage *m;
 
-  LOG (GNUNET_ERROR_TYPE_DEBUG,
-       "Telling ATS we no longer care for an address for `%s'\n",
-       GNUNET_i2s (&sh->id));
-  GNUNET_assert (GNUNET_OK ==
-                 GNUNET_CONTAINER_multipeermap_remove (ch->sug_requests,
-                                                       &sh->id,
-                                                       sh));
+  LOG(GNUNET_ERROR_TYPE_DEBUG,
+      "Telling ATS we no longer care for an address for `%s'\n",
+      GNUNET_i2s(&sh->id));
+  GNUNET_assert(GNUNET_OK ==
+                GNUNET_CONTAINER_multipeermap_remove(ch->sug_requests,
+                                                     &sh->id,
+                                                     sh));
   if (NULL == ch->mq)
-  {
-    GNUNET_free (sh);
-    return;
-  }
-  ev = GNUNET_MQ_msg (m,
-		      GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS_CANCEL);
-  m->strength = htonl (0);
+    {
+      GNUNET_free(sh);
+      return;
+    }
+  ev = GNUNET_MQ_msg(m,
+                     GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS_CANCEL);
+  m->strength = htonl(0);
   m->peer = sh->id;
-  GNUNET_MQ_send (ch->mq, ev);
-  GNUNET_free (sh);
+  GNUNET_MQ_send(ch->mq, ev);
+  GNUNET_free(sh);
 }
 
 

Plik diff jest za duży
+ 346 - 348
src/ats/ats_api_performance.c


+ 16 - 16
src/ats/ats_api_scanner.c

@@ -11,12 +11,12 @@
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      Affero General Public License for more details.
-    
+
      You should have received a copy of the GNU Affero General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
-*/
+ */
 /**
  * @file ats/ats_api_scanner.c
  * @brief LAN interface scanning to determine IPs in LAN
@@ -33,14 +33,14 @@
  * @param hbo value read
  */
 void
-GNUNET_ATS_properties_hton (struct GNUNET_ATS_PropertiesNBO *nbo,
-                            const struct GNUNET_ATS_Properties *hbo)
+GNUNET_ATS_properties_hton(struct GNUNET_ATS_PropertiesNBO *nbo,
+                           const struct GNUNET_ATS_Properties *hbo)
 {
-  nbo->utilization_out = htonl (hbo->utilization_out);
-  nbo->utilization_in = htonl (hbo->utilization_in);
-  nbo->scope = htonl ((uint32_t) hbo->scope);
-  nbo->distance = htonl (hbo->distance);
-  nbo->delay = GNUNET_TIME_relative_hton (hbo->delay);
+  nbo->utilization_out = htonl(hbo->utilization_out);
+  nbo->utilization_in = htonl(hbo->utilization_in);
+  nbo->scope = htonl((uint32_t)hbo->scope);
+  nbo->distance = htonl(hbo->distance);
+  nbo->delay = GNUNET_TIME_relative_hton(hbo->delay);
 }
 
 
@@ -51,14 +51,14 @@ GNUNET_ATS_properties_hton (struct GNUNET_ATS_PropertiesNBO *nbo,
  * @param nbo value read
  */
 void
-GNUNET_ATS_properties_ntoh (struct GNUNET_ATS_Properties *hbo,
-                            const struct GNUNET_ATS_PropertiesNBO *nbo)
+GNUNET_ATS_properties_ntoh(struct GNUNET_ATS_Properties *hbo,
+                           const struct GNUNET_ATS_PropertiesNBO *nbo)
 {
-  hbo->utilization_out = ntohl (nbo->utilization_out);
-  hbo->utilization_in = ntohl (nbo->utilization_in);
-  hbo->scope = ntohl ((uint32_t) nbo->scope);
-  hbo->distance = ntohl (nbo->distance);
-  hbo->delay = GNUNET_TIME_relative_ntoh (nbo->delay);
+  hbo->utilization_out = ntohl(nbo->utilization_out);
+  hbo->utilization_in = ntohl(nbo->utilization_in);
+  hbo->scope = ntohl((uint32_t)nbo->scope);
+  hbo->distance = ntohl(nbo->distance);
+  hbo->delay = GNUNET_TIME_relative_ntoh(nbo->delay);
 }
 
 

+ 304 - 309
src/ats/ats_api_scheduling.c

@@ -11,12 +11,12 @@
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      Affero General Public License for more details.
-    
+
      You should have received a copy of the GNU Affero General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
-*/
+ */
 /**
  * @file ats/ats_api_scheduling.c
  * @brief automatic transport selection and outbound bandwidth determination
@@ -38,9 +38,9 @@
 /**
  * How frequently do we scan the interfaces for changes to the addresses?
  */
-#define INTERFACE_PROCESSING_INTERVAL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 2)
+#define INTERFACE_PROCESSING_INTERVAL GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 2)
 
-#define LOG(kind,...) GNUNET_log_from(kind, "ats-scheduling-api", __VA_ARGS__)
+#define LOG(kind, ...) GNUNET_log_from(kind, "ats-scheduling-api", __VA_ARGS__)
 
 /**
  * Session ID we use if there is no session / slot.
@@ -53,9 +53,7 @@
  * doesn't matter if we have a session, any address that ATS is
  * allowed to suggest right now should be tracked.
  */
-struct GNUNET_ATS_AddressRecord
-{
-
+struct GNUNET_ATS_AddressRecord {
   /**
    * Scheduling handle this address record belongs to.
    */
@@ -99,9 +97,7 @@ struct GNUNET_ATS_AddressRecord
 /**
  * Handle to the ATS subsystem for bandwidth/transport scheduling information.
  */
-struct GNUNET_ATS_SchedulingHandle
-{
-
+struct GNUNET_ATS_SchedulingHandle {
   /**
    * Our configuration.
    */
@@ -144,7 +140,6 @@ struct GNUNET_ATS_SchedulingHandle
    * Size of the @e session_array.
    */
   unsigned int session_array_size;
-
 };
 
 
@@ -154,7 +149,7 @@ struct GNUNET_ATS_SchedulingHandle
  * @param sh handle to use to re-connect.
  */
 static void
-reconnect (struct GNUNET_ATS_SchedulingHandle *sh);
+reconnect(struct GNUNET_ATS_SchedulingHandle *sh);
 
 
 /**
@@ -163,12 +158,12 @@ reconnect (struct GNUNET_ATS_SchedulingHandle *sh);
  * @param cls handle to use to re-connect.
  */
 static void
-reconnect_task (void *cls)
+reconnect_task(void *cls)
 {
   struct GNUNET_ATS_SchedulingHandle *sh = cls;
 
   sh->task = NULL;
-  reconnect (sh);
+  reconnect(sh);
 }
 
 
@@ -178,21 +173,21 @@ reconnect_task (void *cls)
  * @param sh our handle
  */
 static void
-force_reconnect (struct GNUNET_ATS_SchedulingHandle *sh)
+force_reconnect(struct GNUNET_ATS_SchedulingHandle *sh)
 {
   if (NULL != sh->mq)
-  {
-    GNUNET_MQ_destroy (sh->mq);
-    sh->mq = NULL;
-  }
-  sh->suggest_cb (sh->suggest_cb_cls,
-                  NULL, NULL, NULL,
-                  GNUNET_BANDWIDTH_ZERO,
-                  GNUNET_BANDWIDTH_ZERO);
-  sh->backoff = GNUNET_TIME_STD_BACKOFF (sh->backoff);
-  sh->task = GNUNET_SCHEDULER_add_delayed (sh->backoff,
-                                           &reconnect_task,
-                                           sh);
+    {
+      GNUNET_MQ_destroy(sh->mq);
+      sh->mq = NULL;
+    }
+  sh->suggest_cb(sh->suggest_cb_cls,
+                 NULL, NULL, NULL,
+                 GNUNET_BANDWIDTH_ZERO,
+                 GNUNET_BANDWIDTH_ZERO);
+  sh->backoff = GNUNET_TIME_STD_BACKOFF(sh->backoff);
+  sh->task = GNUNET_SCHEDULER_add_delayed(sh->backoff,
+                                          &reconnect_task,
+                                          sh);
 }
 
 
@@ -205,37 +200,37 @@ force_reconnect (struct GNUNET_ATS_SchedulingHandle *sh)
  * @return the session object (or NULL)
  */
 static struct GNUNET_ATS_AddressRecord *
-find_session (struct GNUNET_ATS_SchedulingHandle *sh,
-              uint32_t session_id,
-              const struct GNUNET_PeerIdentity *peer)
+find_session(struct GNUNET_ATS_SchedulingHandle *sh,
+             uint32_t session_id,
+             const struct GNUNET_PeerIdentity *peer)
 {
   struct GNUNET_ATS_AddressRecord *ar;
 
   if (session_id >= sh->session_array_size)
-  {
-    GNUNET_break (0);
-    return NULL;
-  }
+    {
+      GNUNET_break(0);
+      return NULL;
+    }
   if (0 == session_id)
     return NULL;
   ar = sh->session_array[session_id];
   if (NULL == ar)
-  {
-    GNUNET_break (0);
-    return NULL;
-  }
+    {
+      GNUNET_break(0);
+      return NULL;
+    }
   if (NULL == ar->address)
-  {
-    /* address was destroyed in the meantime, this can happen
-       as we communicate asynchronously with the ATS service. */
-    return NULL;
-  }
-  if (0 != GNUNET_memcmp (peer,
-                   &ar->address->peer))
-  {
-    GNUNET_break (0);
-    return NULL;
-  }
+    {
+      /* address was destroyed in the meantime, this can happen
+         as we communicate asynchronously with the ATS service. */
+      return NULL;
+    }
+  if (0 != GNUNET_memcmp(peer,
+                         &ar->address->peer))
+    {
+      GNUNET_break(0);
+      return NULL;
+    }
   return ar;
 }
 
@@ -247,27 +242,27 @@ find_session (struct GNUNET_ATS_SchedulingHandle *sh,
  * @return an unused slot, but never NOT_FOUND (0)
  */
 static uint32_t
-find_empty_session_slot (struct GNUNET_ATS_SchedulingHandle *sh)
+find_empty_session_slot(struct GNUNET_ATS_SchedulingHandle *sh)
 {
   static uint32_t off;
   uint32_t i;
 
-  GNUNET_assert (0 != sh->session_array_size);
+  GNUNET_assert(0 != sh->session_array_size);
   i = 0;
-  while ( ( (NOT_FOUND == off) ||
-            (NULL != sh->session_array[off % sh->session_array_size]) ) &&
-          (i < sh->session_array_size) )
-  {
-    off++;
-    i++;
-  }
-  if ( (NOT_FOUND != off % sh->session_array_size) &&
-       (NULL == sh->session_array[off % sh->session_array_size]) )
+  while (((NOT_FOUND == off) ||
+          (NULL != sh->session_array[off % sh->session_array_size])) &&
+         (i < sh->session_array_size))
+    {
+      off++;
+      i++;
+    }
+  if ((NOT_FOUND != off % sh->session_array_size) &&
+      (NULL == sh->session_array[off % sh->session_array_size]))
     return off;
   i = sh->session_array_size;
-  GNUNET_array_grow (sh->session_array,
-                     sh->session_array_size,
-                     sh->session_array_size * 2);
+  GNUNET_array_grow(sh->session_array,
+                    sh->session_array_size,
+                    sh->session_array_size * 2);
   return i;
 }
 
@@ -281,26 +276,26 @@ find_empty_session_slot (struct GNUNET_ATS_SchedulingHandle *sh)
  * @return the session id or NOT_FOUND for error
  */
 static uint32_t
-find_session_id (struct GNUNET_ATS_SchedulingHandle *sh,
-                 struct GNUNET_ATS_Session *session,
-                 const struct GNUNET_HELLO_Address *address)
+find_session_id(struct GNUNET_ATS_SchedulingHandle *sh,
+                struct GNUNET_ATS_Session *session,
+                const struct GNUNET_HELLO_Address *address)
 {
   uint32_t i;
 
   if (NULL == address)
-  {
-    GNUNET_break (0);
-    return NOT_FOUND;
-  }
+    {
+      GNUNET_break(0);
+      return NOT_FOUND;
+    }
   for (i = 1; i < sh->session_array_size; i++)
-    if ( (NULL != sh->session_array[i]) &&
-         (GNUNET_NO == sh->session_array[i]->in_destroy) &&
-         ( (session == sh->session_array[i]->session) ||
-           (NULL == sh->session_array[i]->session) ) &&
-         (0 == GNUNET_memcmp (&address->peer,
-                       &sh->session_array[i]->address->peer)) &&
-         (0 == GNUNET_HELLO_address_cmp (address,
-                                         sh->session_array[i]->address)) )
+    if ((NULL != sh->session_array[i]) &&
+        (GNUNET_NO == sh->session_array[i]->in_destroy) &&
+        ((session == sh->session_array[i]->session) ||
+         (NULL == sh->session_array[i]->session)) &&
+        (0 == GNUNET_memcmp(&address->peer,
+                            &sh->session_array[i]->address->peer)) &&
+        (0 == GNUNET_HELLO_address_cmp(address,
+                                       sh->session_array[i]->address)))
       return i;
   return NOT_FOUND;
 }
@@ -314,29 +309,29 @@ find_session_id (struct GNUNET_ATS_SchedulingHandle *sh,
  * @param session_id identifies session that is no longer valid
  */
 static void
-release_session (struct GNUNET_ATS_SchedulingHandle *sh,
-                 uint32_t session_id)
+release_session(struct GNUNET_ATS_SchedulingHandle *sh,
+                uint32_t session_id)
 {
   struct GNUNET_ATS_AddressRecord *ar;
 
   if (NOT_FOUND == session_id)
     return;
   if (session_id >= sh->session_array_size)
-  {
-    GNUNET_break (0);
-    force_reconnect (sh);
-    return;
-  }
+    {
+      GNUNET_break(0);
+      force_reconnect(sh);
+      return;
+    }
   /* this slot should have been removed from remove_session before */
   ar = sh->session_array[session_id];
   if (NULL != ar->session)
-  {
-    GNUNET_break (0);
-    force_reconnect (sh);
-    return;
-  }
-  GNUNET_HELLO_address_free (ar->address);
-  GNUNET_free (ar);
+    {
+      GNUNET_break(0);
+      force_reconnect(sh);
+      return;
+    }
+  GNUNET_HELLO_address_free(ar->address);
+  GNUNET_free(ar);
   sh->session_array[session_id] = NULL;
 }
 
@@ -349,15 +344,15 @@ release_session (struct GNUNET_ATS_SchedulingHandle *sh,
  * @param srm message received
  */
 static void
-handle_ats_session_release (void *cls,
-			    const struct GNUNET_ATS_SessionReleaseMessage *srm)
+handle_ats_session_release(void *cls,
+                           const struct GNUNET_ATS_SessionReleaseMessage *srm)
 {
   struct GNUNET_ATS_SchedulingHandle *sh = cls;
 
   /* Note: peer field in srm not necessary right now,
      but might be good to have in the future */
-  release_session (sh,
-                   ntohl (srm->session_id));
+  release_session(sh,
+                  ntohl(srm->session_id));
 }
 
 
@@ -369,71 +364,71 @@ handle_ats_session_release (void *cls,
  * @param m message received
  */
 static void
-handle_ats_address_suggestion (void *cls,
-			       const struct AddressSuggestionMessage *m)
+handle_ats_address_suggestion(void *cls,
+                              const struct AddressSuggestionMessage *m)
 {
   struct GNUNET_ATS_SchedulingHandle *sh = cls;
   struct GNUNET_ATS_AddressRecord *ar;
   uint32_t session_id;
 
-  session_id = ntohl (m->session_id);
+  session_id = ntohl(m->session_id);
   if (0 == session_id)
-  {
-    GNUNET_break (0);
-    force_reconnect (sh);
-    return;
-  }
-  ar = find_session (sh,
-                     session_id,
-                     &m->peer);
+    {
+      GNUNET_break(0);
+      force_reconnect(sh);
+      return;
+    }
+  ar = find_session(sh,
+                    session_id,
+                    &m->peer);
   if (NULL == ar)
-  {
-    GNUNET_break (0);
-    force_reconnect (sh);
-    return;
-  }
+    {
+      GNUNET_break(0);
+      force_reconnect(sh);
+      return;
+    }
   if (NULL == sh->suggest_cb)
     return;
   if (GNUNET_YES == ar->in_destroy)
-  {
-    /* ignore suggestion, as this address is dying, unless BW is 0,
-       in that case signal 'disconnect' via BW 0 */
-    if ( (0 == ntohl (m->bandwidth_out.value__)) &&
-         (0 == ntohl (m->bandwidth_in.value__)) )
     {
-      LOG (GNUNET_ERROR_TYPE_DEBUG,
-           "ATS suggests disconnect from peer `%s' with BW %u/%u\n",
-           GNUNET_i2s (&ar->address->peer),
-           (unsigned int) ntohl (m->bandwidth_out.value__),
-           (unsigned int) ntohl (m->bandwidth_in.value__));
-      sh->suggest_cb (sh->suggest_cb_cls,
-                      &m->peer,
-                      NULL,
-                      NULL,
-                      m->bandwidth_out,
-                      m->bandwidth_in);
+      /* ignore suggestion, as this address is dying, unless BW is 0,
+         in that case signal 'disconnect' via BW 0 */
+      if ((0 == ntohl(m->bandwidth_out.value__)) &&
+          (0 == ntohl(m->bandwidth_in.value__)))
+        {
+          LOG(GNUNET_ERROR_TYPE_DEBUG,
+              "ATS suggests disconnect from peer `%s' with BW %u/%u\n",
+              GNUNET_i2s(&ar->address->peer),
+              (unsigned int)ntohl(m->bandwidth_out.value__),
+              (unsigned int)ntohl(m->bandwidth_in.value__));
+          sh->suggest_cb(sh->suggest_cb_cls,
+                         &m->peer,
+                         NULL,
+                         NULL,
+                         m->bandwidth_out,
+                         m->bandwidth_in);
+        }
+      return;
+    }
+  if ((NULL == ar->session) &&
+      (GNUNET_HELLO_address_check_option(ar->address,
+                                         GNUNET_HELLO_ADDRESS_INFO_INBOUND)))
+    {
+      GNUNET_break(0);
+      return;
     }
-    return;
-  }
-  if ( (NULL == ar->session) &&
-       (GNUNET_HELLO_address_check_option (ar->address,
-                                           GNUNET_HELLO_ADDRESS_INFO_INBOUND)) )
-  {
-    GNUNET_break (0);
-    return;
-  }
   sh->backoff = GNUNET_TIME_UNIT_ZERO;
-  LOG (GNUNET_ERROR_TYPE_DEBUG,
-       "ATS suggests address slot %u for peer `%s' using plugin %s\n",
-       ar->slot,
-       GNUNET_i2s (&ar->address->peer),
-       ar->address->transport_name);
-  sh->suggest_cb (sh->suggest_cb_cls,
-                  &m->peer,
-                  ar->address,
-                  ar->session,
-                  m->bandwidth_out,
-                  m->bandwidth_in);
+  LOG(GNUNET_ERROR_TYPE_DEBUG,
+      "ATS suggests address slot %u for peer `%s' using plugin %s\n",
+      ar->slot,
+      GNUNET_i2s(&ar->address->peer),
+      ar->address->transport_name);
+  sh->suggest_cb(sh->suggest_cb_cls,
+                 &m->peer,
+                 ar->address,
+                 ar->session,
+                 m->bandwidth_out,
+                 m->bandwidth_in);
 }
 
 
@@ -445,15 +440,15 @@ handle_ats_address_suggestion (void *cls,
  * @param error details about the error
  */
 static void
-error_handler (void *cls,
-               enum GNUNET_MQ_Error error)
+error_handler(void *cls,
+              enum GNUNET_MQ_Error error)
 {
   struct GNUNET_ATS_SchedulingHandle *sh = cls;
 
-  LOG (GNUNET_ERROR_TYPE_DEBUG,
-       "ATS connection died (code %d), reconnecting\n",
-       (int) error);
-  force_reconnect (sh);
+  LOG(GNUNET_ERROR_TYPE_DEBUG,
+      "ATS connection died (code %d), reconnecting\n",
+      (int)error);
+  force_reconnect(sh);
 }
 
 
@@ -465,8 +460,8 @@ error_handler (void *cls,
  * @param ar the address to inform the ATS service about
  */
 static void
-send_add_address_message (struct GNUNET_ATS_SchedulingHandle *sh,
-                          const struct GNUNET_ATS_AddressRecord *ar)
+send_add_address_message(struct GNUNET_ATS_SchedulingHandle *sh,
+                         const struct GNUNET_ATS_AddressRecord *ar)
 {
   struct GNUNET_MQ_Envelope *ev;
   struct AddressAddMessage *m;
@@ -476,32 +471,32 @@ send_add_address_message (struct GNUNET_ATS_SchedulingHandle *sh,
 
   if (NULL == sh->mq)
     return; /* disconnected, skip for now */
-  GNUNET_break (GNUNET_NT_UNSPECIFIED != ar->properties.scope);
-  namelen = strlen (ar->address->transport_name) + 1;
+  GNUNET_break(GNUNET_NT_UNSPECIFIED != ar->properties.scope);
+  namelen = strlen(ar->address->transport_name) + 1;
   msize = ar->address->address_length + namelen;
-  ev = GNUNET_MQ_msg_extra (m, msize, GNUNET_MESSAGE_TYPE_ATS_ADDRESS_ADD);
+  ev = GNUNET_MQ_msg_extra(m, msize, GNUNET_MESSAGE_TYPE_ATS_ADDRESS_ADD);
   m->peer = ar->address->peer;
-  m->address_length = htons (ar->address->address_length);
-  m->address_local_info = htonl ((uint32_t) ar->address->local_info);
-  m->plugin_name_length = htons (namelen);
-  m->session_id = htonl (ar->slot);
+  m->address_length = htons(ar->address->address_length);
+  m->address_local_info = htonl((uint32_t)ar->address->local_info);
+  m->plugin_name_length = htons(namelen);
+  m->session_id = htonl(ar->slot);
   m->properties = ar->properties;
 
-  LOG (GNUNET_ERROR_TYPE_DEBUG,
-       "Adding address for peer `%s', plugin `%s', session %p slot %u\n",
-       GNUNET_i2s (&ar->address->peer),
-       ar->address->transport_name,
-       ar->session,
-       ar->slot);
-  pm = (char *) &m[1];
-  GNUNET_memcpy (pm,
-          ar->address->address,
-          ar->address->address_length);
+  LOG(GNUNET_ERROR_TYPE_DEBUG,
+      "Adding address for peer `%s', plugin `%s', session %p slot %u\n",
+      GNUNET_i2s(&ar->address->peer),
+      ar->address->transport_name,
+      ar->session,
+      ar->slot);
+  pm = (char *)&m[1];
+  GNUNET_memcpy(pm,
+                ar->address->address,
+                ar->address->address_length);
   if (NULL != ar->address->transport_name)
-    GNUNET_memcpy (&pm[ar->address->address_length],
-            ar->address->transport_name,
-            namelen);
-  GNUNET_MQ_send (sh->mq, ev);
+    GNUNET_memcpy(&pm[ar->address->address_length],
+                  ar->address->transport_name,
+                  namelen);
+  GNUNET_MQ_send(sh->mq, ev);
 }
 
 
@@ -511,51 +506,51 @@ send_add_address_message (struct GNUNET_ATS_SchedulingHandle *sh,
  * @param sh handle to use to re-connect.
  */
 static void
-reconnect (struct GNUNET_ATS_SchedulingHandle *sh)
+reconnect(struct GNUNET_ATS_SchedulingHandle *sh)
 {
   struct GNUNET_MQ_MessageHandler handlers[] = {
-    GNUNET_MQ_hd_fixed_size (ats_session_release,
-                             GNUNET_MESSAGE_TYPE_ATS_SESSION_RELEASE,
-                             struct GNUNET_ATS_SessionReleaseMessage,
-                             sh),
-    GNUNET_MQ_hd_fixed_size (ats_address_suggestion,
-                             GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION,
-                             struct AddressSuggestionMessage,
-                             sh),
-    GNUNET_MQ_handler_end ()
+    GNUNET_MQ_hd_fixed_size(ats_session_release,
+                            GNUNET_MESSAGE_TYPE_ATS_SESSION_RELEASE,
+                            struct GNUNET_ATS_SessionReleaseMessage,
+                            sh),
+    GNUNET_MQ_hd_fixed_size(ats_address_suggestion,
+                            GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION,
+                            struct AddressSuggestionMessage,
+                            sh),
+    GNUNET_MQ_handler_end()
   };
   struct GNUNET_MQ_Envelope *ev;
   struct ClientStartMessage *init;
   unsigned int i;
   struct GNUNET_ATS_AddressRecord *ar;
 
-  GNUNET_assert (NULL == sh->mq);
-  sh->mq = GNUNET_CLIENT_connect (sh->cfg,
-                                  "ats",
-                                  handlers,
-                                  &error_handler,
-                                  sh);
+  GNUNET_assert(NULL == sh->mq);
+  sh->mq = GNUNET_CLIENT_connect(sh->cfg,
+                                 "ats",
+                                 handlers,
+                                 &error_handler,
+                                 sh);
   if (NULL == sh->mq)
-  {
-    GNUNET_break (0);
-    force_reconnect (sh);
-    return;
-  }
-  ev = GNUNET_MQ_msg (init,
-                      GNUNET_MESSAGE_TYPE_ATS_START);
-  init->start_flag = htonl (START_FLAG_SCHEDULING);
-  GNUNET_MQ_send (sh->mq, ev);
+    {
+      GNUNET_break(0);
+      force_reconnect(sh);
+      return;
+    }
+  ev = GNUNET_MQ_msg(init,
+                     GNUNET_MESSAGE_TYPE_ATS_START);
+  init->start_flag = htonl(START_FLAG_SCHEDULING);
+  GNUNET_MQ_send(sh->mq, ev);
   if (NULL == sh->mq)
     return;
-  for (i=0;i<sh->session_array_size;i++)
-  {
-    ar = sh->session_array[i];
-    if (NULL == ar)
-      continue;
-    send_add_address_message (sh, ar);
-    if (NULL == sh->mq)
-      return;
-  }
+  for (i = 0; i < sh->session_array_size; i++)
+    {
+      ar = sh->session_array[i];
+      if (NULL == ar)
+        continue;
+      send_add_address_message(sh, ar);
+      if (NULL == sh->mq)
+        return;
+    }
 }
 
 
@@ -568,20 +563,20 @@ reconnect (struct GNUNET_ATS_SchedulingHandle *sh)
  * @return ats context
  */
 struct GNUNET_ATS_SchedulingHandle *
-GNUNET_ATS_scheduling_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
-                            GNUNET_ATS_AddressSuggestionCallback suggest_cb,
-                            void *suggest_cb_cls)
+GNUNET_ATS_scheduling_init(const struct GNUNET_CONFIGURATION_Handle *cfg,
+                           GNUNET_ATS_AddressSuggestionCallback suggest_cb,
+                           void *suggest_cb_cls)
 {
   struct GNUNET_ATS_SchedulingHandle *sh;
 
-  sh = GNUNET_new (struct GNUNET_ATS_SchedulingHandle);
+  sh = GNUNET_new(struct GNUNET_ATS_SchedulingHandle);
   sh->cfg = cfg;
   sh->suggest_cb = suggest_cb;
   sh->suggest_cb_cls = suggest_cb_cls;
-  GNUNET_array_grow (sh->session_array,
-                     sh->session_array_size,
-                     4);
-  reconnect (sh);
+  GNUNET_array_grow(sh->session_array,
+                    sh->session_array_size,
+                    4);
+  reconnect(sh);
   return sh;
 }
 
@@ -592,34 +587,34 @@ GNUNET_ATS_scheduling_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
  * @param sh handle to release
  */
 void
-GNUNET_ATS_scheduling_done (struct GNUNET_ATS_SchedulingHandle *sh)
+GNUNET_ATS_scheduling_done(struct GNUNET_ATS_SchedulingHandle *sh)
 {
   struct GNUNET_ATS_AddressRecord *ar;
   unsigned int i;
 
   if (NULL != sh->mq)
-  {
-    GNUNET_MQ_destroy (sh->mq);
-    sh->mq = NULL;
-  }
+    {
+      GNUNET_MQ_destroy(sh->mq);
+      sh->mq = NULL;
+    }
   if (NULL != sh->task)
-  {
-    GNUNET_SCHEDULER_cancel (sh->task);
-    sh->task = NULL;
-  }
-  for (i=0;i<sh->session_array_size;i++)
-  {
-    if (NULL != (ar = sh->session_array[i]))
     {
-      GNUNET_HELLO_address_free (ar->address);
-      GNUNET_free (ar);
-      sh->session_array[i] = NULL;
+      GNUNET_SCHEDULER_cancel(sh->task);
+      sh->task = NULL;
     }
-  }
-  GNUNET_array_grow (sh->session_array,
-                     sh->session_array_size,
-                     0);
-  GNUNET_free (sh);
+  for (i = 0; i < sh->session_array_size; i++)
+    {
+      if (NULL != (ar = sh->session_array[i]))
+        {
+          GNUNET_HELLO_address_free(ar->address);
+          GNUNET_free(ar);
+          sh->session_array[i] = NULL;
+        }
+    }
+  GNUNET_array_grow(sh->session_array,
+                    sh->session_array_size,
+                    0);
+  GNUNET_free(sh);
 }
 
 
@@ -636,10 +631,10 @@ GNUNET_ATS_scheduling_done (struct GNUNET_ATS_SchedulingHandle *sh)
  *         on error (i.e. ATS knows this exact address already)
  */
 struct GNUNET_ATS_AddressRecord *
-GNUNET_ATS_address_add (struct GNUNET_ATS_SchedulingHandle *sh,
-                        const struct GNUNET_HELLO_Address *address,
-                        struct GNUNET_ATS_Session *session,
-                        const struct GNUNET_ATS_Properties *prop)
+GNUNET_ATS_address_add(struct GNUNET_ATS_SchedulingHandle *sh,
+                       const struct GNUNET_HELLO_Address *address,
+                       struct GNUNET_ATS_Session *session,
+                       const struct GNUNET_ATS_Properties *prop)
 {
   struct GNUNET_ATS_AddressRecord *ar;
   size_t namelen;
@@ -647,42 +642,42 @@ GNUNET_ATS_address_add (struct GNUNET_ATS_SchedulingHandle *sh,
   uint32_t s;
 
   if (NULL == address)
-  {
-    /* we need a valid address */
-    GNUNET_break (0);
-    return NULL;
-  }
-  GNUNET_break (GNUNET_NT_UNSPECIFIED != prop->scope);
-  namelen = strlen (address->transport_name) + 1;
+    {
+      /* we need a valid address */
+      GNUNET_break(0);
+      return NULL;
+    }
+  GNUNET_break(GNUNET_NT_UNSPECIFIED != prop->scope);
+  namelen = strlen(address->transport_name) + 1;
   msize = address->address_length + namelen;
-  if ((msize + sizeof (struct AddressUpdateMessage) >= GNUNET_MAX_MESSAGE_SIZE) ||
+  if ((msize + sizeof(struct AddressUpdateMessage) >= GNUNET_MAX_MESSAGE_SIZE) ||
       (address->address_length >= GNUNET_MAX_MESSAGE_SIZE) ||
-      (namelen >= GNUNET_MAX_MESSAGE_SIZE) )
-  {
-    /* address too large for us, this should not happen */
-    GNUNET_break (0);
-    return NULL;
-  }
+      (namelen >= GNUNET_MAX_MESSAGE_SIZE))
+    {
+      /* address too large for us, this should not happen */
+      GNUNET_break(0);
+      return NULL;
+    }
 
   if (NOT_FOUND !=
-      find_session_id (sh,
-                       session,
-                       address))
-  {
-    /* Already existing, nothing todo, but this should not happen */
-    GNUNET_break (0);
-    return NULL;
-  }
-  s = find_empty_session_slot (sh);
-  ar = GNUNET_new (struct GNUNET_ATS_AddressRecord);
+      find_session_id(sh,
+                      session,
+                      address))
+    {
+      /* Already existing, nothing todo, but this should not happen */
+      GNUNET_break(0);
+      return NULL;
+    }
+  s = find_empty_session_slot(sh);
+  ar = GNUNET_new(struct GNUNET_ATS_AddressRecord);
   ar->sh = sh;
   ar->slot = s;
   ar->session = session;
-  ar->address = GNUNET_HELLO_address_copy (address);
-  GNUNET_ATS_properties_hton (&ar->properties,
-                              prop);
+  ar->address = GNUNET_HELLO_address_copy(address);
+  GNUNET_ATS_properties_hton(&ar->properties,
+                             prop);
   sh->session_array[s] = ar;
-  send_add_address_message (sh, ar);
+  send_add_address_message(sh, ar);
   return ar;
 }
 
@@ -694,10 +689,10 @@ GNUNET_ATS_address_add (struct GNUNET_ATS_SchedulingHandle *sh,
  * @param session session handle
  */
 void
-GNUNET_ATS_address_add_session (struct GNUNET_ATS_AddressRecord *ar,
-                                struct GNUNET_ATS_Session *session)
+GNUNET_ATS_address_add_session(struct GNUNET_ATS_AddressRecord *ar,
+                               struct GNUNET_ATS_Session *session)
 {
-  GNUNET_break (NULL == ar->session);
+  GNUNET_break(NULL == ar->session);
   ar->session = session;
 }
 
@@ -715,17 +710,17 @@ GNUNET_ATS_address_add_session (struct GNUNET_ATS_AddressRecord *ar,
  *                    use it still to establish a new session
  */
 int
-GNUNET_ATS_address_del_session (struct GNUNET_ATS_AddressRecord *ar,
-                                struct GNUNET_ATS_Session *session)
+GNUNET_ATS_address_del_session(struct GNUNET_ATS_AddressRecord *ar,
+                               struct GNUNET_ATS_Session *session)
 {
-  GNUNET_assert (session == ar->session);
+  GNUNET_assert(session == ar->session);
   ar->session = NULL;
-  if (GNUNET_HELLO_address_check_option (ar->address,
-                                         GNUNET_HELLO_ADDRESS_INFO_INBOUND))
-  {
-    GNUNET_ATS_address_destroy (ar);
-    return GNUNET_YES;
-  }
+  if (GNUNET_HELLO_address_check_option(ar->address,
+                                        GNUNET_HELLO_ADDRESS_INFO_INBOUND))
+    {
+      GNUNET_ATS_address_destroy(ar);
+      return GNUNET_YES;
+    }
   return GNUNET_NO;
 }
 
@@ -742,30 +737,30 @@ GNUNET_ATS_address_del_session (struct GNUNET_ATS_AddressRecord *ar,
  * @param prop performance data for the address
  */
 void
-GNUNET_ATS_address_update (struct GNUNET_ATS_AddressRecord *ar,
-                           const struct GNUNET_ATS_Properties *prop)
+GNUNET_ATS_address_update(struct GNUNET_ATS_AddressRecord *ar,
+                          const struct GNUNET_ATS_Properties *prop)
 {
   struct GNUNET_ATS_SchedulingHandle *sh = ar->sh;
   struct GNUNET_MQ_Envelope *ev;
   struct AddressUpdateMessage *m;
 
-  LOG (GNUNET_ERROR_TYPE_DEBUG,
-       "Updating address for peer `%s', plugin `%s', session %p slot %u\n",
-       GNUNET_i2s (&ar->address->peer),
-       ar->address->transport_name,
-       ar->session,
-       ar->slot);
-  GNUNET_break (GNUNET_NT_UNSPECIFIED != prop->scope);
-  GNUNET_ATS_properties_hton (&ar->properties,
-                              prop);
+  LOG(GNUNET_ERROR_TYPE_DEBUG,
+      "Updating address for peer `%s', plugin `%s', session %p slot %u\n",
+      GNUNET_i2s(&ar->address->peer),
+      ar->address->transport_name,
+      ar->session,
+      ar->slot);
+  GNUNET_break(GNUNET_NT_UNSPECIFIED != prop->scope);
+  GNUNET_ATS_properties_hton(&ar->properties,
+                             prop);
   if (NULL == sh->mq)
     return; /* disconnected, skip for now */
-  ev = GNUNET_MQ_msg (m, GNUNET_MESSAGE_TYPE_ATS_ADDRESS_UPDATE);
-  m->session_id = htonl (ar->slot);
+  ev = GNUNET_MQ_msg(m, GNUNET_MESSAGE_TYPE_ATS_ADDRESS_UPDATE);
+  m->session_id = htonl(ar->slot);
   m->peer = ar->address->peer;
   m->properties = ar->properties;
-  GNUNET_MQ_send (sh->mq,
-                  ev);
+  GNUNET_MQ_send(sh->mq,
+                 ev);
 }
 
 
@@ -775,27 +770,27 @@ GNUNET_ATS_address_update (struct GNUNET_ATS_AddressRecord *ar,
  * @param ar address to destroy
  */
 void
-GNUNET_ATS_address_destroy (struct GNUNET_ATS_AddressRecord *ar)
+GNUNET_ATS_address_destroy(struct GNUNET_ATS_AddressRecord *ar)
 {
   struct GNUNET_ATS_SchedulingHandle *sh = ar->sh;
   struct GNUNET_MQ_Envelope *ev;
   struct AddressDestroyedMessage *m;
 
-  LOG (GNUNET_ERROR_TYPE_DEBUG,
-       "Deleting address for peer `%s', plugin `%s', slot %u session %p\n",
-       GNUNET_i2s (&ar->address->peer),
-       ar->address->transport_name,
-       ar->slot,
-       ar->session);
-  GNUNET_break (NULL == ar->session);
+  LOG(GNUNET_ERROR_TYPE_DEBUG,
+      "Deleting address for peer `%s', plugin `%s', slot %u session %p\n",
+      GNUNET_i2s(&ar->address->peer),
+      ar->address->transport_name,
+      ar->slot,
+      ar->session);
+  GNUNET_break(NULL == ar->session);
   ar->session = NULL;
   ar->in_destroy = GNUNET_YES;
   if (NULL == sh->mq)
     return;
-  ev = GNUNET_MQ_msg (m, GNUNET_MESSAGE_TYPE_ATS_ADDRESS_DESTROYED);
-  m->session_id = htonl (ar->slot);
+  ev = GNUNET_MQ_msg(m, GNUNET_MESSAGE_TYPE_ATS_ADDRESS_DESTROYED);
+  m->session_id = htonl(ar->slot);
   m->peer = ar->address->peer;
-  GNUNET_MQ_send (sh->mq, ev);
+  GNUNET_MQ_send(sh->mq, ev);
 }
 
 

Plik diff jest za duży
+ 374 - 364
src/ats/gnunet-ats-solver-eval.c


+ 30 - 48
src/ats/gnunet-ats-solver-eval.h

@@ -1,19 +1,19 @@
 /*
- This file is part of GNUnet.
- Copyright (C) 2010-2013 GNUnet e.V.
+   This file is part of GNUnet.
+   Copyright (C) 2010-2013 GNUnet e.V.
 
- GNUnet is free software: you can redistribute it and/or modify it
- under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License,
- or (at your option) any later version.
+   GNUnet is free software: you can redistribute it and/or modify it
+   under the terms of the GNU Affero General Public License as published
+   by the Free Software Foundation, either version 3 of the License,
+   or (at your option) any later version.
 
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- Affero General Public License for more details.
+   GNUnet is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Affero General Public License for more details.
 
- You should have received a copy of the GNU Affero General Public License
- along with this program.  If not, see <http://www.gnu.org/licenses/>.
+   You should have received a copy of the GNU Affero General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
  */
@@ -34,8 +34,7 @@
 #include "gnunet-service-ats_normalization.h"
 #include "test_ats_api_common.h"
 
-enum GeneratorType
-{
+enum GeneratorType {
   GNUNET_ATS_TEST_TG_LINEAR,
   GNUNET_ATS_TEST_TG_CONSTANT,
   GNUNET_ATS_TEST_TG_RANDOM,
@@ -43,8 +42,7 @@ enum GeneratorType
 };
 
 
-enum OperationType
-{
+enum OperationType {
   SOLVER_OP_ADD_ADDRESS,
   SOLVER_OP_DEL_ADDRESS,
   SOLVER_OP_START_SET_PROPERTY,
@@ -55,8 +53,7 @@ enum OperationType
   SOLVER_OP_STOP_REQUEST,
 };
 
-struct SolverHandle
-{
+struct SolverHandle {
   /**
    * Solver plugin name
    */
@@ -78,15 +75,13 @@ struct SolverHandle
   struct GNUNET_CONTAINER_MultiPeerMap *addresses;
 };
 
-enum GNUNET_ATS_Solvers
-{
+enum GNUNET_ATS_Solvers {
   GNUNET_ATS_SOLVER_PROPORTIONAL,
   GNUNET_ATS_SOLVER_MLP,
   GNUNET_ATS_SOLVER_RIL,
 };
 
-struct LoggingFileHandle
-{
+struct LoggingFileHandle {
   /* DLL list for logging time steps */
   struct LoggingFileHandle *next;
   struct LoggingFileHandle *prev;
@@ -98,11 +93,9 @@ struct LoggingFileHandle
   long long unsigned int aid;
 
   struct GNUNET_DISK_FileHandle *f_hd;
-
 };
 
-struct LoggingTimeStep
-{
+struct LoggingTimeStep {
   struct LoggingTimeStep *prev;
   struct LoggingTimeStep *next;
 
@@ -113,8 +106,7 @@ struct LoggingTimeStep
   struct GNUNET_TIME_Relative delta;
 };
 
-struct LoggingPeer
-{
+struct LoggingPeer {
   struct LoggingPeer *prev;
   struct LoggingPeer *next;
 
@@ -128,8 +120,7 @@ struct LoggingPeer
   struct LoggingAddress *addr_tail;
 };
 
-struct LoggingAddress
-{
+struct LoggingAddress {
   struct LoggingAddress *next;
   struct LoggingAddress *prev;
 
@@ -144,8 +135,7 @@ struct LoggingAddress
 };
 
 
-struct TestPeer
-{
+struct TestPeer {
   struct TestPeer *prev;
   struct TestPeer *next;
 
@@ -165,8 +155,7 @@ struct TestPeer
 };
 
 
-struct TestAddress
-{
+struct TestAddress {
   struct TestAddress *next;
   struct TestAddress *prev;
 
@@ -183,16 +172,15 @@ struct Episode;
 struct Experiment;
 
 typedef void (*GNUNET_ATS_TESTING_EpisodeDoneCallback) (
-    struct Episode *e);
+  struct Episode *e);
 
 typedef void (*GNUNET_ATS_TESTING_ExperimentDoneCallback) (struct Experiment *e,
-    struct GNUNET_TIME_Relative duration,int success);
+                                                           struct GNUNET_TIME_Relative duration, int success);
 
 /**
  * An operation in an experiment
  */
-struct GNUNET_ATS_TEST_Operation
-{
+struct GNUNET_ATS_TEST_Operation {
   struct GNUNET_ATS_TEST_Operation *next;
   struct GNUNET_ATS_TEST_Operation *prev;
 
@@ -218,8 +206,7 @@ struct GNUNET_ATS_TEST_Operation
   // enum GNUNET_ATS_Property prop_type;
 };
 
-struct Episode
-{
+struct Episode {
   int id;
   struct Episode *next;
   struct GNUNET_TIME_Relative duration;
@@ -228,8 +215,7 @@ struct Episode
   struct GNUNET_ATS_TEST_Operation *tail;
 };
 
-struct LoggingHandle
-{
+struct LoggingHandle {
   struct GNUNET_SCHEDULER_Task * logging_task;
   struct GNUNET_TIME_Relative log_freq;
 
@@ -238,8 +224,7 @@ struct LoggingHandle
   struct LoggingTimeStep *tail;
 };
 
-struct Experiment
-{
+struct Experiment {
   char *name;
   char *log_prefix;
   char *cfg_file;
@@ -263,8 +248,7 @@ struct Experiment
   GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb;
 };
 
-struct PreferenceGenerator
-{
+struct PreferenceGenerator {
   struct PreferenceGenerator *prev;
   struct PreferenceGenerator *next;
 
@@ -302,12 +286,10 @@ struct PreferenceGenerator
   uint32_t last_assigned_bw_in;
   uint32_t last_assigned_bw_out;
   double last_delay_value;
-
 };
 
 
-struct PropertyGenerator
-{
+struct PropertyGenerator {
   struct PropertyGenerator *prev;
   struct PropertyGenerator *next;
 

+ 324 - 334
src/ats/gnunet-service-ats-new.c

@@ -16,7 +16,7 @@
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
-*/
+ */
 /**
  * @file ats/gnunet-service-ats-new.c
  * @brief ats service
@@ -59,8 +59,7 @@ struct Client;
 /**
  * Preferences expressed by a client are kept in a DLL per client.
  */
-struct ClientPreference
-{
+struct ClientPreference {
   /**
    * DLL pointer.
    */
@@ -91,9 +90,7 @@ struct ClientPreference
 /**
  * Information about ongoing sessions of the transport client.
  */
-struct GNUNET_ATS_Session
-{
-
+struct GNUNET_ATS_Session {
   /**
    * Session data exposed to the plugin.
    */
@@ -113,15 +110,13 @@ struct GNUNET_ATS_Session
    * Unique ID for the session when talking with the client.
    */
   uint32_t session_id;
-
 };
 
 
 /**
  * Information we track per client.
  */
-struct Client
-{
+struct Client {
   /**
    * Type of the client, initially #CT_NONE.
    */
@@ -141,9 +136,7 @@ struct Client
    * Details depending on @e type.
    */
   union {
-
     struct {
-
       /**
        * Head of DLL of preferences expressed by this client.
        */
@@ -153,20 +146,15 @@ struct Client
        * Tail of DLL of preferences expressed by this client.
        */
       struct ClientPreference *cp_tail;
-
     } application;
 
     struct {
-
       /**
        * Map from session IDs to `struct GNUNET_ATS_Session` objects.
        */
       struct GNUNET_CONTAINER_MultiHashMap32 *sessions;
-
     } transport;
-
   } details;
-
 };
 
 
@@ -200,32 +188,32 @@ static struct Client *transport_client;
  * @param address address the transport should try
  */
 static void
-suggest_cb (void *cls,
-	    const struct GNUNET_PeerIdentity *pid,
-	    const char *address)
+suggest_cb(void *cls,
+           const struct GNUNET_PeerIdentity *pid,
+           const char *address)
 {
   struct GNUNET_MQ_Envelope *env;
-  size_t slen = strlen (address) + 1;
+  size_t slen = strlen(address) + 1;
   struct AddressSuggestionMessage *as;
 
   if (NULL == transport_client)
-  {
-    // FIXME: stats!
-    return;
-  }
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Suggesting address `%s' of peer `%s'\n",
-              address,
-              GNUNET_i2s (pid));
-  env = GNUNET_MQ_msg_extra (as,
-			     slen,
-			     GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION);
+    {
+      // FIXME: stats!
+      return;
+    }
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+             "Suggesting address `%s' of peer `%s'\n",
+             address,
+             GNUNET_i2s(pid));
+  env = GNUNET_MQ_msg_extra(as,
+                            slen,
+                            GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION);
   as->peer = *pid;
-  memcpy (&as[1],
-	  address,
-	  slen);
-  GNUNET_MQ_send (transport_client->mq,
-		  env);
+  memcpy(&as[1],
+         address,
+         slen);
+  GNUNET_MQ_send(transport_client->mq,
+                 env);
 }
 
 
@@ -240,37 +228,37 @@ suggest_cb (void *cls,
  * @param bw_out suggested bandwidth for transmission
  */
 static void
-allocate_cb (void *cls,
-	     struct GNUNET_ATS_Session *session,
-	     const struct GNUNET_PeerIdentity *peer,
-	     struct GNUNET_BANDWIDTH_Value32NBO bw_in,
-	     struct GNUNET_BANDWIDTH_Value32NBO bw_out)
+allocate_cb(void *cls,
+            struct GNUNET_ATS_Session *session,
+            const struct GNUNET_PeerIdentity *peer,
+            struct GNUNET_BANDWIDTH_Value32NBO bw_in,
+            struct GNUNET_BANDWIDTH_Value32NBO bw_out)
 {
   struct GNUNET_MQ_Envelope *env;
   struct SessionAllocationMessage *sam;
 
-  (void) cls;
-  if ( (NULL == transport_client) ||
-       (session->client != transport_client) )
-  {
-    /* transport must have just died and solver is addressing the
-       losses of sessions (possibly of previous transport), ignore! */
-    return;
-  }
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Allocating %u/%u bytes for %p of peer `%s'\n",
-              ntohl (bw_in.value__),
-              ntohl (bw_out.value__),
-              session,
-              GNUNET_i2s (peer));
-  env = GNUNET_MQ_msg (sam,
-		       GNUNET_MESSAGE_TYPE_ATS_SESSION_ALLOCATION);
+  (void)cls;
+  if ((NULL == transport_client) ||
+      (session->client != transport_client))
+    {
+      /* transport must have just died and solver is addressing the
+         losses of sessions (possibly of previous transport), ignore! */
+      return;
+    }
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+             "Allocating %u/%u bytes for %p of peer `%s'\n",
+             ntohl(bw_in.value__),
+             ntohl(bw_out.value__),
+             session,
+             GNUNET_i2s(peer));
+  env = GNUNET_MQ_msg(sam,
+                      GNUNET_MESSAGE_TYPE_ATS_SESSION_ALLOCATION);
   sam->session_id = session->session_id;
   sam->peer = *peer;
   sam->bandwidth_in = bw_in;
   sam->bandwidth_out = bw_out;
-  GNUNET_MQ_send (transport_client->mq,
-		  env);
+  GNUNET_MQ_send(transport_client->mq,
+                 env);
 }
 
 
@@ -281,18 +269,18 @@ allocate_cb (void *cls,
  * @param prop[out] in HBO
  */
 static void
-prop_ntoh (const struct PropertiesNBO *properties,
-	   struct GNUNET_ATS_Properties *prop)
+prop_ntoh(const struct PropertiesNBO *properties,
+          struct GNUNET_ATS_Properties *prop)
 {
-  prop->delay = GNUNET_TIME_relative_ntoh (properties->delay);
-  prop->goodput_out = ntohl (properties->goodput_out);
-  prop->goodput_in = ntohl (properties->goodput_in);
-  prop->utilization_out = ntohl (properties->utilization_out);
-  prop->utilization_in = ntohl (properties->utilization_in);
-  prop->distance = ntohl (properties->distance);
-  prop->mtu = ntohl (properties->mtu);
-  prop->nt = (enum GNUNET_NetworkType) ntohl (properties->nt);
-  prop->cc = (enum GNUNET_TRANSPORT_CommunicatorCharacteristics) ntohl (properties->cc);
+  prop->delay = GNUNET_TIME_relative_ntoh(properties->delay);
+  prop->goodput_out = ntohl(properties->goodput_out);
+  prop->goodput_in = ntohl(properties->goodput_in);
+  prop->utilization_out = ntohl(properties->utilization_out);
+  prop->utilization_in = ntohl(properties->utilization_in);
+  prop->distance = ntohl(properties->distance);
+  prop->mtu = ntohl(properties->mtu);
+  prop->nt = (enum GNUNET_NetworkType)ntohl(properties->nt);
+  prop->cc = (enum GNUNET_TRANSPORT_CommunicatorCharacteristics)ntohl(properties->cc);
 }
 
 
@@ -303,8 +291,8 @@ prop_ntoh (const struct PropertiesNBO *properties,
  * @param msg the start message
  */
 static void
-handle_suggest (void *cls,
-                const struct ExpressPreferenceMessage *msg)
+handle_suggest(void *cls,
+               const struct ExpressPreferenceMessage *msg)
 {
   struct Client *c = cls;
   struct ClientPreference *cp;
@@ -312,27 +300,27 @@ handle_suggest (void *cls,
   if (CT_NONE == c->type)
     c->type = CT_APPLICATION;
   if (CT_APPLICATION != c->type)
-  {
-    GNUNET_break (0);
-    GNUNET_SERVICE_client_drop (c->client);
-    return;
-  }
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Client suggested we talk to %s with preference %d at rate %u\n",
-              GNUNET_i2s (&msg->peer),
-              (int) ntohl (msg->pk),
-              (int) ntohl (msg->bw.value__));
-  cp = GNUNET_new (struct ClientPreference);
+    {
+      GNUNET_break(0);
+      GNUNET_SERVICE_client_drop(c->client);
+      return;
+    }
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+             "Client suggested we talk to %s with preference %d at rate %u\n",
+             GNUNET_i2s(&msg->peer),
+             (int)ntohl(msg->pk),
+             (int)ntohl(msg->bw.value__));
+  cp = GNUNET_new(struct ClientPreference);
   cp->client = c;
   cp->pref.peer = msg->peer;
   cp->pref.bw = msg->bw;
-  cp->pref.pk = (enum GNUNET_MQ_PreferenceKind) ntohl (msg->pk);
-  cp->ph = plugin->preference_add (plugin->cls,
-				   &cp->pref);
-  GNUNET_CONTAINER_DLL_insert (c->details.application.cp_head,
-			       c->details.application.cp_tail,
-			       cp);
-  GNUNET_SERVICE_client_continue (c->client);
+  cp->pref.pk = (enum GNUNET_MQ_PreferenceKind)ntohl(msg->pk);
+  cp->ph = plugin->preference_add(plugin->cls,
+                                  &cp->pref);
+  GNUNET_CONTAINER_DLL_insert(c->details.application.cp_head,
+                              c->details.application.cp_tail,
+                              cp);
+  GNUNET_SERVICE_client_continue(c->client);
 }
 
 
@@ -343,8 +331,8 @@ handle_suggest (void *cls,
  * @param msg the start message
  */
 static void
-handle_suggest_cancel (void *cls,
-                       const struct ExpressPreferenceMessage *msg)
+handle_suggest_cancel(void *cls,
+                      const struct ExpressPreferenceMessage *msg)
 {
   struct Client *c = cls;
   struct ClientPreference *cp;
@@ -352,33 +340,33 @@ handle_suggest_cancel (void *cls,
   if (CT_NONE == c->type)
     c->type = CT_APPLICATION;
   if (CT_APPLICATION != c->type)
-  {
-    GNUNET_break (0);
-    GNUNET_SERVICE_client_drop (c->client);
-    return;
-  }
+    {
+      GNUNET_break(0);
+      GNUNET_SERVICE_client_drop(c->client);
+      return;
+    }
   for (cp = c->details.application.cp_head;
        NULL != cp;
        cp = cp->next)
-    if ( (cp->pref.pk == (enum GNUNET_MQ_PreferenceKind) ntohl (msg->pk)) &&
-	 (cp->pref.bw.value__ == msg->bw.value__) &&
-	 (0 == GNUNET_memcmp (&cp->pref.peer,
-		       &msg->peer)) )
+    if ((cp->pref.pk == (enum GNUNET_MQ_PreferenceKind)ntohl(msg->pk)) &&
+        (cp->pref.bw.value__ == msg->bw.value__) &&
+        (0 == GNUNET_memcmp(&cp->pref.peer,
+                            &msg->peer)))
       break;
   if (NULL == cp)
-  {
-    GNUNET_break (0);
-    GNUNET_SERVICE_client_drop (c->client);
-    return;
-  }
-  plugin->preference_del (plugin->cls,
-			  cp->ph,
-			  &cp->pref);
-  GNUNET_CONTAINER_DLL_remove (c->details.application.cp_head,
-			       c->details.application.cp_tail,
-			       cp);
-  GNUNET_free (cp);
-  GNUNET_SERVICE_client_continue (c->client);
+    {
+      GNUNET_break(0);
+      GNUNET_SERVICE_client_drop(c->client);
+      return;
+    }
+  plugin->preference_del(plugin->cls,
+                         cp->ph,
+                         &cp->pref);
+  GNUNET_CONTAINER_DLL_remove(c->details.application.cp_head,
+                              c->details.application.cp_tail,
+                              cp);
+  GNUNET_free(cp);
+  GNUNET_SERVICE_client_continue(c->client);
 }
 
 
@@ -389,27 +377,27 @@ handle_suggest_cancel (void *cls,
  * @param message the request message
  */
 static void
-handle_start (void *cls,
-	      const struct GNUNET_MessageHeader *hdr)
+handle_start(void *cls,
+             const struct GNUNET_MessageHeader *hdr)
 {
   struct Client *c = cls;
 
   if (CT_NONE != c->type)
-  {
-    GNUNET_break (0);
-    GNUNET_SERVICE_client_drop (c->client);
-    return;
-  }
+    {
+      GNUNET_break(0);
+      GNUNET_SERVICE_client_drop(c->client);
+      return;
+    }
   c->type = CT_TRANSPORT;
   c->details.transport.sessions
-    = GNUNET_CONTAINER_multihashmap32_create (128);
+    = GNUNET_CONTAINER_multihashmap32_create(128);
   if (NULL != transport_client)
-  {
-    GNUNET_SERVICE_client_drop (transport_client->client);
-    transport_client = NULL;
-  }
+    {
+      GNUNET_SERVICE_client_drop(transport_client->client);
+      transport_client = NULL;
+    }
   transport_client = c;
-  GNUNET_SERVICE_client_continue (c->client);
+  GNUNET_SERVICE_client_continue(c->client);
 }
 
 
@@ -422,17 +410,17 @@ handle_start (void *cls,
  * @return #GNUNET_OK if @a message is well-formed
  */
 static int
-check_session_add (void *cls,
-		   const struct SessionAddMessage *message)
+check_session_add(void *cls,
+                  const struct SessionAddMessage *message)
 {
   struct Client *c = cls;
 
-  GNUNET_MQ_check_zero_termination (message);
+  GNUNET_MQ_check_zero_termination(message);
   if (CT_TRANSPORT != c->type)
-  {
-    GNUNET_break (0);
-    return GNUNET_SYSERR;
-  }
+    {
+      GNUNET_break(0);
+      return GNUNET_SYSERR;
+    }
   return GNUNET_OK;
 }
 
@@ -444,45 +432,45 @@ check_session_add (void *cls,
  * @param message the request message
  */
 static void
-handle_session_add (void *cls,
-		    const struct SessionAddMessage *message)
+handle_session_add(void *cls,
+                   const struct SessionAddMessage *message)
 {
   struct Client *c = cls;
-  const char *address = (const char *) &message[1];
+  const char *address = (const char *)&message[1];
   struct GNUNET_ATS_Session *session;
   int inbound_only = (GNUNET_MESSAGE_TYPE_ATS_SESSION_ADD_INBOUND_ONLY ==
-		      ntohs (message->header.type));
+                      ntohs(message->header.type));
 
-  session = GNUNET_CONTAINER_multihashmap32_get (c->details.transport.sessions,
-						 message->session_id);
+  session = GNUNET_CONTAINER_multihashmap32_get(c->details.transport.sessions,
+                                                message->session_id);
   if (NULL != session)
-  {
-    GNUNET_break (0);
-    GNUNET_SERVICE_client_drop (c->client);
-    return;
-  }
-  session = GNUNET_new (struct GNUNET_ATS_Session);
+    {
+      GNUNET_break(0);
+      GNUNET_SERVICE_client_drop(c->client);
+      return;
+    }
+  session = GNUNET_new(struct GNUNET_ATS_Session);
   session->data.session = session;
   session->client = c;
   session->session_id = message->session_id;
   session->data.peer = message->peer;
-  prop_ntoh (&message->properties,
-	     &session->data.prop);
+  prop_ntoh(&message->properties,
+            &session->data.prop);
   session->data.inbound_only = inbound_only;
-  GNUNET_assert (GNUNET_YES ==
-		 GNUNET_CONTAINER_multihashmap32_put (c->details.transport.sessions,
-						      message->session_id,
-						      session,
-						      GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
-  session->sh = plugin->session_add (plugin->cls,
-				     &session->data,
-				     address);
-  GNUNET_assert (NULL != session->sh);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Transport has new session %p to %s\n",
-              session,
-              GNUNET_i2s (&message->peer));
-  GNUNET_SERVICE_client_continue (c->client);
+  GNUNET_assert(GNUNET_YES ==
+                GNUNET_CONTAINER_multihashmap32_put(c->details.transport.sessions,
+                                                    message->session_id,
+                                                    session,
+                                                    GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
+  session->sh = plugin->session_add(plugin->cls,
+                                    &session->data,
+                                    address);
+  GNUNET_assert(NULL != session->sh);
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+             "Transport has new session %p to %s\n",
+             session,
+             GNUNET_i2s(&message->peer));
+  GNUNET_SERVICE_client_continue(c->client);
 }
 
 
@@ -493,32 +481,32 @@ handle_session_add (void *cls,
  * @param msg the request message
  */
 static void
-handle_session_update (void *cls,
-		       const struct SessionUpdateMessage *msg)
+handle_session_update(void *cls,
+                      const struct SessionUpdateMessage *msg)
 {
   struct Client *c = cls;
   struct GNUNET_ATS_Session *session;
 
   if (CT_TRANSPORT != c->type)
-  {
-    GNUNET_break (0);
-    GNUNET_SERVICE_client_drop (c->client);
-    return;
-  }
-  session = GNUNET_CONTAINER_multihashmap32_get (c->details.transport.sessions,
-						 msg->session_id);
+    {
+      GNUNET_break(0);
+      GNUNET_SERVICE_client_drop(c->client);
+      return;
+    }
+  session = GNUNET_CONTAINER_multihashmap32_get(c->details.transport.sessions,
+                                                msg->session_id);
   if (NULL == session)
-  {
-    GNUNET_break (0);
-    GNUNET_SERVICE_client_drop (c->client);
-    return;
-  }
-  prop_ntoh (&msg->properties,
-	     &session->data.prop);
-  plugin->session_update (plugin->cls,
-			  session->sh,
-			  &session->data);
-  GNUNET_SERVICE_client_continue (c->client);
+    {
+      GNUNET_break(0);
+      GNUNET_SERVICE_client_drop(c->client);
+      return;
+    }
+  prop_ntoh(&msg->properties,
+            &session->data.prop);
+  plugin->session_update(plugin->cls,
+                         session->sh,
+                         &session->data);
+  GNUNET_SERVICE_client_continue(c->client);
 }
 
 
@@ -529,41 +517,41 @@ handle_session_update (void *cls,
  * @param message the request message
  */
 static void
-handle_session_del (void *cls,
-		    const struct SessionDelMessage *message)
+handle_session_del(void *cls,
+                   const struct SessionDelMessage *message)
 {
   struct Client *c = cls;
   struct GNUNET_ATS_Session *session;
 
   if (CT_TRANSPORT != c->type)
-  {
-    GNUNET_break (0);
-    GNUNET_SERVICE_client_drop (c->client);
-    return;
-  }
-  session = GNUNET_CONTAINER_multihashmap32_get (c->details.transport.sessions,
-						 message->session_id);
+    {
+      GNUNET_break(0);
+      GNUNET_SERVICE_client_drop(c->client);
+      return;
+    }
+  session = GNUNET_CONTAINER_multihashmap32_get(c->details.transport.sessions,
+                                                message->session_id);
   if (NULL == session)
-  {
-    GNUNET_break (0);
-    GNUNET_SERVICE_client_drop (c->client);
-    return;
-  }
-  GNUNET_assert (NULL != session->sh);
-  plugin->session_del (plugin->cls,
-		       session->sh,
-		       &session->data);
+    {
+      GNUNET_break(0);
+      GNUNET_SERVICE_client_drop(c->client);
+      return;
+    }
+  GNUNET_assert(NULL != session->sh);
+  plugin->session_del(plugin->cls,
+                      session->sh,
+                      &session->data);
   session->sh = NULL;
-  GNUNET_assert (GNUNET_YES ==
-		 GNUNET_CONTAINER_multihashmap32_remove (c->details.transport.sessions,
-							 session->session_id,
-							 session));
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Transport lost session %p to %s\n",
-              session,
-              GNUNET_i2s (&session->data.peer));
-  GNUNET_free (session);
-  GNUNET_SERVICE_client_continue (c->client);
+  GNUNET_assert(GNUNET_YES ==
+                GNUNET_CONTAINER_multihashmap32_remove(c->details.transport.sessions,
+                                                       session->session_id,
+                                                       session));
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+             "Transport lost session %p to %s\n",
+             session,
+             GNUNET_i2s(&session->data.peer));
+  GNUNET_free(session);
+  GNUNET_SERVICE_client_continue(c->client);
 }
 
 
@@ -577,11 +565,11 @@ handle_session_del (void *cls,
  * @return @a client
  */
 static void *
-client_connect_cb (void *cls,
-		   struct GNUNET_SERVICE_Client *client,
-		   struct GNUNET_MQ_Handle *mq)
+client_connect_cb(void *cls,
+                  struct GNUNET_SERVICE_Client *client,
+                  struct GNUNET_MQ_Handle *mq)
 {
-  struct Client *c = GNUNET_new (struct Client);
+  struct Client *c = GNUNET_new(struct Client);
 
   c->client = client;
   c->mq = mq;
@@ -598,21 +586,21 @@ client_connect_cb (void *cls,
  * @param value a `struct GNUNET_ATS_Session`
  */
 static int
-free_session (void *cls,
-	      uint32_t key,
-	      void *value)
+free_session(void *cls,
+             uint32_t key,
+             void *value)
 {
   struct Client *c = cls;
   struct GNUNET_ATS_Session *session = value;
 
-  (void) key;
-  GNUNET_assert (c == session->client);
-  GNUNET_assert (NULL != session->sh);
-  plugin->session_del (plugin->cls,
-		       session->sh,
-		       &session->data);
+  (void)key;
+  GNUNET_assert(c == session->client);
+  GNUNET_assert(NULL != session->sh);
+  plugin->session_del(plugin->cls,
+                      session->sh,
+                      &session->data);
   session->sh = NULL;
-  GNUNET_free (session);
+  GNUNET_free(session);
   return GNUNET_OK;
 }
 
@@ -626,42 +614,44 @@ free_session (void *cls,
  * @param app_ctx our `struct Client`
  */
 static void
-client_disconnect_cb (void *cls,
-		      struct GNUNET_SERVICE_Client *client,
-		      void *app_ctx)
+client_disconnect_cb(void *cls,
+                     struct GNUNET_SERVICE_Client *client,
+                     void *app_ctx)
 {
   struct Client *c = app_ctx;
 
-  (void) cls;
-  GNUNET_assert (c->client == client);
+  (void)cls;
+  GNUNET_assert(c->client == client);
   switch (c->type)
-  {
-  case CT_NONE:
-    break;
-  case CT_APPLICATION:
-    for (struct ClientPreference *cp = c->details.application.cp_head;
-	 NULL != cp;
-	 cp = c->details.application.cp_head)
     {
-      plugin->preference_del (plugin->cls,
-			      cp->ph,
-			      &cp->pref);
-      GNUNET_CONTAINER_DLL_remove (c->details.application.cp_head,
-				   c->details.application.cp_tail,
-				   cp);
-      GNUNET_free (cp);
+    case CT_NONE:
+      break;
+
+    case CT_APPLICATION:
+      for (struct ClientPreference *cp = c->details.application.cp_head;
+           NULL != cp;
+           cp = c->details.application.cp_head)
+        {
+          plugin->preference_del(plugin->cls,
+                                 cp->ph,
+                                 &cp->pref);
+          GNUNET_CONTAINER_DLL_remove(c->details.application.cp_head,
+                                      c->details.application.cp_tail,
+                                      cp);
+          GNUNET_free(cp);
+        }
+      break;
+
+    case CT_TRANSPORT:
+      if (transport_client == c)
+        transport_client = NULL;
+      GNUNET_CONTAINER_multihashmap32_iterate(c->details.transport.sessions,
+                                              &free_session,
+                                              c);
+      GNUNET_CONTAINER_multihashmap32_destroy(c->details.transport.sessions);
+      break;
     }
-    break;
-  case CT_TRANSPORT:
-    if (transport_client == c)
-      transport_client = NULL;
-    GNUNET_CONTAINER_multihashmap32_iterate (c->details.transport.sessions,
-					     &free_session,
-					     c);
-    GNUNET_CONTAINER_multihashmap32_destroy (c->details.transport.sessions);
-    break;
-  }
-  GNUNET_free (c);
+  GNUNET_free(c);
 }
 
 
@@ -671,26 +661,26 @@ client_disconnect_cb (void *cls,
  * @param cls unused
  */
 static void
-final_cleanup (void *cls)
+final_cleanup(void *cls)
 {
-  (void) cls;
+  (void)cls;
   if (NULL != stats)
-  {
-    GNUNET_STATISTICS_destroy (stats,
-			       GNUNET_NO);
-    stats = NULL;
-  }
+    {
+      GNUNET_STATISTICS_destroy(stats,
+                                GNUNET_NO);
+      stats = NULL;
+    }
   if (NULL != plugin)
-  {
-    GNUNET_PLUGIN_unload (plugin_name,
-			  plugin);
-    plugin = NULL;
-  }
+    {
+      GNUNET_PLUGIN_unload(plugin_name,
+                           plugin);
+      plugin = NULL;
+    }
   if (NULL != plugin_name)
-  {
-    GNUNET_free (plugin_name);
-    plugin_name = NULL;
-  }
+    {
+      GNUNET_free(plugin_name);
+      plugin_name = NULL;
+    }
 }
 
 
@@ -700,13 +690,13 @@ final_cleanup (void *cls)
  * @param cls unused
  */
 static void
-cleanup_task (void *cls)
+cleanup_task(void *cls)
 {
-  (void) cls;
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "ATS shutdown initiated\n");
-  GNUNET_SCHEDULER_add_now (&final_cleanup,
-                            NULL);
+  (void)cls;
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+             "ATS shutdown initiated\n");
+  GNUNET_SCHEDULER_add_now(&final_cleanup,
+                           NULL);
 }
 
 
@@ -718,45 +708,45 @@ cleanup_task (void *cls)
  * @param service the initialized service
  */
 static void
-run (void *cls,
-     const struct GNUNET_CONFIGURATION_Handle *cfg,
-     struct GNUNET_SERVICE_Handle *service)
+run(void *cls,
+    const struct GNUNET_CONFIGURATION_Handle *cfg,
+    struct GNUNET_SERVICE_Handle *service)
 {
   static struct GNUNET_ATS_PluginEnvironment env;
   char *solver;
 
-  stats = GNUNET_STATISTICS_create ("ats",
-				    cfg);
+  stats = GNUNET_STATISTICS_create("ats",
+                                   cfg);
   if (GNUNET_SYSERR ==
-      GNUNET_CONFIGURATION_get_value_string (cfg,
-                                             "ats",
-                                             "SOLVER",
-                                             &solver))
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                "No ATS solver configured, using 'simple' approach\n");
-    solver = GNUNET_strdup ("simple");
-  }
-  GNUNET_SCHEDULER_add_shutdown (&cleanup_task,
-				 NULL);
+      GNUNET_CONFIGURATION_get_value_string(cfg,
+                                            "ats",
+                                            "SOLVER",
+                                            &solver))
+    {
+      GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
+                 "No ATS solver configured, using 'simple' approach\n");
+      solver = GNUNET_strdup("simple");
+    }
+  GNUNET_SCHEDULER_add_shutdown(&cleanup_task,
+                                NULL);
   env.cls = NULL;
   env.cfg = cfg;
   env.stats = stats;
   env.suggest_cb = &suggest_cb;
   env.allocate_cb = &allocate_cb;
-  GNUNET_asprintf (&plugin_name,
-                   "libgnunet_plugin_ats2_%s",
-                   solver);
-  GNUNET_free (solver);
-  if (NULL == (plugin = GNUNET_PLUGIN_load (plugin_name,
-					    &env)))
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                _("Failed to initialize solver `%s'!\n"),
-                plugin_name);
-    GNUNET_SCHEDULER_shutdown ();
-    return;
-  }
+  GNUNET_asprintf(&plugin_name,
+                  "libgnunet_plugin_ats2_%s",
+                  solver);
+  GNUNET_free(solver);
+  if (NULL == (plugin = GNUNET_PLUGIN_load(plugin_name,
+                                           &env)))
+    {
+      GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
+                 _("Failed to initialize solver `%s'!\n"),
+                 plugin_name);
+      GNUNET_SCHEDULER_shutdown();
+      return;
+    }
 }
 
 
@@ -764,41 +754,41 @@ run (void *cls,
  * Define "main" method using service macro.
  */
 GNUNET_SERVICE_MAIN
-("ats",
- GNUNET_SERVICE_OPTION_NONE,
- &run,
- &client_connect_cb,
- &client_disconnect_cb,
- NULL,
- GNUNET_MQ_hd_fixed_size (suggest,
+  ("ats",
+  GNUNET_SERVICE_OPTION_NONE,
+  &run,
+  &client_connect_cb,
+  &client_disconnect_cb,
+  NULL,
+  GNUNET_MQ_hd_fixed_size(suggest,
                           GNUNET_MESSAGE_TYPE_ATS_SUGGEST,
                           struct ExpressPreferenceMessage,
                           NULL),
- GNUNET_MQ_hd_fixed_size (suggest_cancel,
+  GNUNET_MQ_hd_fixed_size(suggest_cancel,
                           GNUNET_MESSAGE_TYPE_ATS_SUGGEST_CANCEL,
                           struct ExpressPreferenceMessage,
                           NULL),
- GNUNET_MQ_hd_fixed_size (start,
-			  GNUNET_MESSAGE_TYPE_ATS_START,
-			  struct GNUNET_MessageHeader,
-			  NULL),
- GNUNET_MQ_hd_var_size (session_add,
-			GNUNET_MESSAGE_TYPE_ATS_SESSION_ADD,
-			struct SessionAddMessage,
-			NULL),
- GNUNET_MQ_hd_var_size (session_add,
-			GNUNET_MESSAGE_TYPE_ATS_SESSION_ADD_INBOUND_ONLY,
-			struct SessionAddMessage,
-			NULL),
- GNUNET_MQ_hd_fixed_size (session_update,
-			  GNUNET_MESSAGE_TYPE_ATS_SESSION_UPDATE,
-			  struct SessionUpdateMessage,
-			  NULL),
- GNUNET_MQ_hd_fixed_size (session_del,
-			  GNUNET_MESSAGE_TYPE_ATS_SESSION_DEL,
-			  struct SessionDelMessage,
-			  NULL),
- GNUNET_MQ_handler_end ());
+  GNUNET_MQ_hd_fixed_size(start,
+                          GNUNET_MESSAGE_TYPE_ATS_START,
+                          struct GNUNET_MessageHeader,
+                          NULL),
+  GNUNET_MQ_hd_var_size(session_add,
+                        GNUNET_MESSAGE_TYPE_ATS_SESSION_ADD,
+                        struct SessionAddMessage,
+                        NULL),
+  GNUNET_MQ_hd_var_size(session_add,
+                        GNUNET_MESSAGE_TYPE_ATS_SESSION_ADD_INBOUND_ONLY,
+                        struct SessionAddMessage,
+                        NULL),
+  GNUNET_MQ_hd_fixed_size(session_update,
+                          GNUNET_MESSAGE_TYPE_ATS_SESSION_UPDATE,
+                          struct SessionUpdateMessage,
+                          NULL),
+  GNUNET_MQ_hd_fixed_size(session_del,
+                          GNUNET_MESSAGE_TYPE_ATS_SESSION_DEL,
+                          struct SessionDelMessage,
+                          NULL),
+  GNUNET_MQ_handler_end());
 
 
 /* end of gnunet-service-ats.c */

+ 235 - 231
src/ats/gnunet-service-ats.c

@@ -11,12 +11,12 @@
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      Affero General Public License for more details.
-    
+
      You should have received a copy of the GNU Affero General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
-*/
+ */
 /**
  * @file ats/gnunet-service-ats.c
  * @brief ats service
@@ -50,43 +50,47 @@ struct GNUNET_STATISTICS_Handle *GSA_stats;
  * @param msg the start message
  */
 static void
-handle_ats_start (void *cls,
-                  const struct ClientStartMessage *msg)
+handle_ats_start(void *cls,
+                 const struct ClientStartMessage *msg)
 {
   struct GNUNET_SERVICE_Client *client = cls;
   enum StartFlag flag;
 
-  flag = ntohl (msg->start_flag);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Received ATS_START (%d) message\n",
-              (int) flag);
+  flag = ntohl(msg->start_flag);
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+             "Received ATS_START (%d) message\n",
+             (int)flag);
   switch (flag)
-  {
-  case START_FLAG_SCHEDULING:
-    if (GNUNET_OK !=
-	GAS_scheduling_add_client (client))
     {
-      GNUNET_SERVICE_client_drop (client);
+    case START_FLAG_SCHEDULING:
+      if (GNUNET_OK !=
+          GAS_scheduling_add_client(client))
+        {
+          GNUNET_SERVICE_client_drop(client);
+          return;
+        }
+      break;
+
+    case START_FLAG_PERFORMANCE_WITH_PIC:
+      GAS_performance_add_client(client,
+                                 flag);
+      break;
+
+    case START_FLAG_PERFORMANCE_NO_PIC:
+      GAS_performance_add_client(client,
+                                 flag);
+      break;
+
+    case START_FLAG_CONNECTION_SUGGESTION:
+      /* This client won't receive messages from us, no need to 'add' */
+      break;
+
+    default:
+      GNUNET_break(0);
+      GNUNET_SERVICE_client_drop(client);
       return;
     }
-    break;
-  case START_FLAG_PERFORMANCE_WITH_PIC:
-    GAS_performance_add_client (client,
-                                flag);
-    break;
-  case START_FLAG_PERFORMANCE_NO_PIC:
-    GAS_performance_add_client (client,
-                                flag);
-    break;
-  case START_FLAG_CONNECTION_SUGGESTION:
-    /* This client won't receive messages from us, no need to 'add' */
-    break;
-  default:
-    GNUNET_break (0);
-    GNUNET_SERVICE_client_drop (client);
-    return;
-  }
-  GNUNET_SERVICE_client_continue (client);
+  GNUNET_SERVICE_client_continue(client);
 }
 
 
@@ -98,14 +102,14 @@ handle_ats_start (void *cls,
  * @param message the request message
  */
 static void
-handle_reservation_request (void *cls,
-			    const struct ReservationRequestMessage *message)
+handle_reservation_request(void *cls,
+                           const struct ReservationRequestMessage *message)
 {
   struct GNUNET_SERVICE_Client *client = cls;
 
-  GAS_handle_reservation_request (client,
-				  message);
-  GNUNET_SERVICE_client_continue (client);
+  GAS_handle_reservation_request(client,
+                                 message);
+  GNUNET_SERVICE_client_continue(client);
 }
 
 
@@ -117,23 +121,23 @@ handle_reservation_request (void *cls,
  * @return #GNUNET_OK if @a message is well-formed
  */
 static int
-check_feedback (void *cls,
-		const struct FeedbackPreferenceMessage *message)
+check_feedback(void *cls,
+               const struct FeedbackPreferenceMessage *message)
 {
   uint16_t msize;
   uint32_t nump;
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Received PREFERENCE_FEEDBACK message\n");
-  msize = ntohs (message->header.size);
-  nump = ntohl (message->num_feedback);
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+             "Received PREFERENCE_FEEDBACK message\n");
+  msize = ntohs(message->header.size);
+  nump = ntohl(message->num_feedback);
   if (msize !=
-      sizeof (struct FeedbackPreferenceMessage) +
-      nump * sizeof (struct PreferenceInformation))
-  {
-    GNUNET_break (0);
-    return GNUNET_SYSERR;
-  }
+      sizeof(struct FeedbackPreferenceMessage) +
+      nump * sizeof(struct PreferenceInformation))
+    {
+      GNUNET_break(0);
+      return GNUNET_SYSERR;
+    }
   return GNUNET_OK;
 }
 
@@ -145,42 +149,42 @@ check_feedback (void *cls,
  * @param msg the request message
  */
 static void
-handle_feedback (void *cls,
-		 const struct FeedbackPreferenceMessage *msg)
+handle_feedback(void *cls,
+                const struct FeedbackPreferenceMessage *msg)
 {
   struct GNUNET_SERVICE_Client *client = cls;
   const struct PreferenceInformation *pi;
   uint32_t nump;
 
-  nump = ntohl (msg->num_feedback);
+  nump = ntohl(msg->num_feedback);
   if (GNUNET_NO ==
-      GNUNET_CONTAINER_multipeermap_contains (GSA_addresses,
-					      &msg->peer))
-  {
-    GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
-	       "Received PREFERENCE FEEDBACK for unknown peer `%s'\n",
-	       GNUNET_i2s (&msg->peer));
-    GNUNET_SERVICE_client_continue (client);
-    return;
-  }
+      GNUNET_CONTAINER_multipeermap_contains(GSA_addresses,
+                                             &msg->peer))
+    {
+      GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
+                 "Received PREFERENCE FEEDBACK for unknown peer `%s'\n",
+                 GNUNET_i2s(&msg->peer));
+      GNUNET_SERVICE_client_continue(client);
+      return;
+    }
 
-  GNUNET_STATISTICS_update (GSA_stats,
-                            "# preference feedbacks requests processed",
-                            1,
-                            GNUNET_NO);
-  pi = (const struct PreferenceInformation *) &msg[1];
+  GNUNET_STATISTICS_update(GSA_stats,
+                           "# preference feedbacks requests processed",
+                           1,
+                           GNUNET_NO);
+  pi = (const struct PreferenceInformation *)&msg[1];
   for (uint32_t i = 0; i < nump; i++)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-		"Received PREFERENCE FEEDBACK for peer `%s'\n",
-		GNUNET_i2s (&msg->peer));
-    GAS_plugin_notify_feedback (client,
-				&msg->peer,
-				GNUNET_TIME_relative_ntoh (msg->scope),
-				(enum GNUNET_ATS_PreferenceKind) ntohl (pi[i].preference_kind),
-				pi[i].preference_value);
-  }
-  GNUNET_SERVICE_client_continue (client);
+    {
+      GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+                 "Received PREFERENCE FEEDBACK for peer `%s'\n",
+                 GNUNET_i2s(&msg->peer));
+      GAS_plugin_notify_feedback(client,
+                                 &msg->peer,
+                                 GNUNET_TIME_relative_ntoh(msg->scope),
+                                 (enum GNUNET_ATS_PreferenceKind)ntohl(pi[i].preference_kind),
+                                 pi[i].preference_value);
+    }
+  GNUNET_SERVICE_client_continue(client);
 }
 
 
@@ -191,14 +195,14 @@ handle_feedback (void *cls,
  * @param message the request message
  */
 static void
-handle_request_address_list (void *cls,
-			     const struct AddressListRequestMessage *message)
+handle_request_address_list(void *cls,
+                            const struct AddressListRequestMessage *message)
 {
   struct GNUNET_SERVICE_Client *client = cls;
 
-  GAS_handle_request_address_list (client,
-				   message);
-  GNUNET_SERVICE_client_continue (client);
+  GAS_handle_request_address_list(client,
+                                  message);
+  GNUNET_SERVICE_client_continue(client);
 }
 
 
@@ -209,14 +213,14 @@ handle_request_address_list (void *cls,
  * @param message the request message
  */
 static void
-handle_request_address (void *cls,
-			const struct RequestAddressMessage * message)
+handle_request_address(void *cls,
+                       const struct RequestAddressMessage * message)
 {
   struct GNUNET_SERVICE_Client *client = cls;
 
-  GAS_handle_request_address (client,
-			      message);
-  GNUNET_SERVICE_client_continue (client);
+  GAS_handle_request_address(client,
+                             message);
+  GNUNET_SERVICE_client_continue(client);
 }
 
 
@@ -227,14 +231,14 @@ handle_request_address (void *cls,
  * @param message the request message
  */
 static void
-handle_request_address_cancel (void *cls,
-			       const struct RequestAddressMessage *message)
+handle_request_address_cancel(void *cls,
+                              const struct RequestAddressMessage *message)
 {
   struct GNUNET_SERVICE_Client *client = cls;
 
-  GAS_handle_request_address_cancel (client,
-				     message);
-  GNUNET_SERVICE_client_continue (client);
+  GAS_handle_request_address_cancel(client,
+                                    message);
+  GNUNET_SERVICE_client_continue(client);
 }
 
 
@@ -245,8 +249,8 @@ handle_request_address_cancel (void *cls,
  * @param m the request message
  */
 static int
-check_address_add (void *cls,
-		   const struct AddressAddMessage *m)
+check_address_add(void *cls,
+                  const struct AddressAddMessage *m)
 {
   const char *address;
   const char *plugin_name;
@@ -254,23 +258,23 @@ check_address_add (void *cls,
   uint16_t plugin_name_length;
   uint16_t size;
 
-  size = ntohs (m->header.size);
-  address_length = ntohs (m->address_length);
-  plugin_name_length = ntohs (m->plugin_name_length);
-  address = (const char *) &m[1];
+  size = ntohs(m->header.size);
+  address_length = ntohs(m->address_length);
+  plugin_name_length = ntohs(m->plugin_name_length);
+  address = (const char *)&m[1];
   if (plugin_name_length != 0)
     plugin_name = &address[address_length];
   else
     plugin_name = "";
 
-  if ( (address_length + plugin_name_length +
-	sizeof (struct AddressAddMessage) != size) ||
-       ( (plugin_name_length > 0) &&
-	 (plugin_name[plugin_name_length - 1] != '\0') ) )
-  {
-    GNUNET_break (0);
-    return GNUNET_SYSERR;
-  }
+  if ((address_length + plugin_name_length +
+       sizeof(struct AddressAddMessage) != size) ||
+      ((plugin_name_length > 0) &&
+       (plugin_name[plugin_name_length - 1] != '\0')))
+    {
+      GNUNET_break(0);
+      return GNUNET_SYSERR;
+    }
   return GNUNET_OK;
 }
 
@@ -282,13 +286,13 @@ check_address_add (void *cls,
  * @param message the request message
  */
 static void
-handle_address_add (void *cls,
-		    const struct AddressAddMessage *message)
+handle_address_add(void *cls,
+                   const struct AddressAddMessage *message)
 {
   struct GNUNET_SERVICE_Client *client = cls;
 
-  GAS_handle_address_add (message);
-  GNUNET_SERVICE_client_continue (client);
+  GAS_handle_address_add(message);
+  GNUNET_SERVICE_client_continue(client);
 }
 
 
@@ -299,13 +303,13 @@ handle_address_add (void *cls,
  * @param message the request message
  */
 static void
-handle_address_update (void *cls,
-		       const struct AddressUpdateMessage *message)
+handle_address_update(void *cls,
+                      const struct AddressUpdateMessage *message)
 {
   struct GNUNET_SERVICE_Client *client = cls;
 
-  GAS_handle_address_update (message);
-  GNUNET_SERVICE_client_continue (client);
+  GAS_handle_address_update(message);
+  GNUNET_SERVICE_client_continue(client);
 }
 
 
@@ -316,13 +320,13 @@ handle_address_update (void *cls,
  * @param message the request message
  */
 static void
-handle_address_destroyed (void *cls,
-			  const struct AddressDestroyedMessage *message)
+handle_address_destroyed(void *cls,
+                         const struct AddressDestroyedMessage *message)
 {
   struct GNUNET_SERVICE_Client *client = cls;
 
-  GAS_handle_address_destroyed (message);
-  GNUNET_SERVICE_client_continue (client);
+  GAS_handle_address_destroyed(message);
+  GNUNET_SERVICE_client_continue(client);
 }
 
 
@@ -334,22 +338,22 @@ handle_address_destroyed (void *cls,
  * @return #GNUNET_OK if @a message is well-formed
  */
 static int
-check_preference_change (void *cls,
-			 const struct ChangePreferenceMessage *message)
+check_preference_change(void *cls,
+                        const struct ChangePreferenceMessage *message)
 {
   uint16_t msize;
   uint32_t nump;
 
-  msize = ntohs (message->header.size);
-  nump = ntohl (message->num_preferences);
-  if ( (msize !=
-        sizeof (struct ChangePreferenceMessage) +
-        nump * sizeof (struct PreferenceInformation)) ||
-       (UINT16_MAX / sizeof (struct PreferenceInformation) < nump) )
-  {
-    GNUNET_break (0);
-    return GNUNET_SYSERR;
-  }
+  msize = ntohs(message->header.size);
+  nump = ntohl(message->num_preferences);
+  if ((msize !=
+       sizeof(struct ChangePreferenceMessage) +
+       nump * sizeof(struct PreferenceInformation)) ||
+      (UINT16_MAX / sizeof(struct PreferenceInformation) < nump))
+    {
+      GNUNET_break(0);
+      return GNUNET_SYSERR;
+    }
   return GNUNET_OK;
 }
 
@@ -361,14 +365,14 @@ check_preference_change (void *cls,
  * @param message the request message
  */
 static void
-handle_preference_change (void *cls,
-			  const struct ChangePreferenceMessage *message)
+handle_preference_change(void *cls,
+                         const struct ChangePreferenceMessage *message)
 {
   struct GNUNET_SERVICE_Client *client = cls;
 
-  GAS_handle_preference_change (client,
-				message);
-  GNUNET_SERVICE_client_continue (client);
+  GAS_handle_preference_change(client,
+                               message);
+  GNUNET_SERVICE_client_continue(client);
 }
 
 
@@ -382,9 +386,9 @@ handle_preference_change (void *cls,
  * @return @a client
  */
 static void *
-client_connect_cb (void *cls,
-		   struct GNUNET_SERVICE_Client *client,
-		   struct GNUNET_MQ_Handle *mq)
+client_connect_cb(void *cls,
+                  struct GNUNET_SERVICE_Client *client,
+                  struct GNUNET_MQ_Handle *mq)
 {
   return client;
 }
@@ -399,15 +403,15 @@ client_connect_cb (void *cls,
  * @param app_ctx
  */
 static void
-client_disconnect_cb (void *cls,
-		      struct GNUNET_SERVICE_Client *client,
-		      void *app_ctx)
+client_disconnect_cb(void *cls,
+                     struct GNUNET_SERVICE_Client *client,
+                     void *app_ctx)
 {
   if (NULL == client)
     return;
-  GAS_scheduling_remove_client (client);
-  GAS_connectivity_remove_client (client);
-  GAS_preference_client_disconnect (client);
+  GAS_scheduling_remove_client(client);
+  GAS_connectivity_remove_client(client);
+  GAS_preference_client_disconnect(client);
 }
 
 
@@ -417,22 +421,22 @@ client_disconnect_cb (void *cls,
  * @param cls unused
  */
 static void
-cleanup_task (void *cls)
+cleanup_task(void *cls)
 {
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "ATS shutdown initiated\n");
-  GAS_connectivity_done ();
-  GAS_addresses_done ();
-  GAS_plugin_done ();
-  GAS_normalization_stop ();
-  GAS_performance_done ();
-  GAS_preference_done ();
-  GAS_reservations_done ();
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+             "ATS shutdown initiated\n");
+  GAS_connectivity_done();
+  GAS_addresses_done();
+  GAS_plugin_done();
+  GAS_normalization_stop();
+  GAS_performance_done();
+  GAS_preference_done();
+  GAS_reservations_done();
   if (NULL != GSA_stats)
-  {
-    GNUNET_STATISTICS_destroy (GSA_stats, GNUNET_NO);
-    GSA_stats = NULL;
-  }
+    {
+      GNUNET_STATISTICS_destroy(GSA_stats, GNUNET_NO);
+      GSA_stats = NULL;
+    }
 }
 
 
@@ -444,37 +448,37 @@ cleanup_task (void *cls)
  * @param service the initialized service
  */
 static void
-run (void *cls,
-     const struct GNUNET_CONFIGURATION_Handle *cfg,
-     struct GNUNET_SERVICE_Handle *service)
+run(void *cls,
+    const struct GNUNET_CONFIGURATION_Handle *cfg,
+    struct GNUNET_SERVICE_Handle *service)
 {
-  GSA_stats = GNUNET_STATISTICS_create ("ats",
-					cfg);
-  GAS_reservations_init ();
-  GAS_connectivity_init ();
-  GAS_preference_init ();
-  GAS_normalization_start ();
-  GAS_addresses_init ();
+  GSA_stats = GNUNET_STATISTICS_create("ats",
+                                       cfg);
+  GAS_reservations_init();
+  GAS_connectivity_init();
+  GAS_preference_init();
+  GAS_normalization_start();
+  GAS_addresses_init();
   if (GNUNET_OK !=
-      GAS_plugin_init (cfg))
-  {
-    GNUNET_break (0);
-    GAS_addresses_done ();
-    GAS_normalization_stop ();
-    GAS_reservations_done ();
-    GAS_connectivity_done ();
-    GAS_preference_done ();
-    if (NULL != GSA_stats)
+      GAS_plugin_init(cfg))
     {
-      GNUNET_STATISTICS_destroy (GSA_stats,
-				 GNUNET_NO);
-      GSA_stats = NULL;
+      GNUNET_break(0);
+      GAS_addresses_done();
+      GAS_normalization_stop();
+      GAS_reservations_done();
+      GAS_connectivity_done();
+      GAS_preference_done();
+      if (NULL != GSA_stats)
+        {
+          GNUNET_STATISTICS_destroy(GSA_stats,
+                                    GNUNET_NO);
+          GSA_stats = NULL;
+        }
+      return;
     }
-    return;
-  }
-  GAS_performance_init ();
-  GNUNET_SCHEDULER_add_shutdown (&cleanup_task,
-				 NULL);
+  GAS_performance_init();
+  GNUNET_SCHEDULER_add_shutdown(&cleanup_task,
+                                NULL);
 }
 
 
@@ -482,53 +486,53 @@ run (void *cls,
  * Define "main" method using service macro.
  */
 GNUNET_SERVICE_MAIN
-("ats",
- GNUNET_SERVICE_OPTION_NONE,
- &run,
- &client_connect_cb,
- &client_disconnect_cb,
- NULL,
- GNUNET_MQ_hd_fixed_size (ats_start,
-			  GNUNET_MESSAGE_TYPE_ATS_START,
-			  struct ClientStartMessage,
-			  NULL),
- GNUNET_MQ_hd_fixed_size (request_address,
-			  GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS,
-			  struct RequestAddressMessage,
-			  NULL),
- GNUNET_MQ_hd_fixed_size (request_address_cancel, 
-			  GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS_CANCEL,
-			  struct RequestAddressMessage,
-			  NULL),
- GNUNET_MQ_hd_fixed_size (request_address_list, 
-			  GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_REQUEST,
-			  struct AddressListRequestMessage,
-			  NULL),
- GNUNET_MQ_hd_var_size (address_add, 
-			GNUNET_MESSAGE_TYPE_ATS_ADDRESS_ADD,
-			struct AddressAddMessage,
-			NULL),
- GNUNET_MQ_hd_fixed_size (address_update, 
-			  GNUNET_MESSAGE_TYPE_ATS_ADDRESS_UPDATE,
-			  struct AddressUpdateMessage,
-			  NULL),
- GNUNET_MQ_hd_fixed_size (address_destroyed, 
-			  GNUNET_MESSAGE_TYPE_ATS_ADDRESS_DESTROYED,
-			  struct AddressDestroyedMessage,
-			  NULL),
- GNUNET_MQ_hd_fixed_size (reservation_request, 
-			  GNUNET_MESSAGE_TYPE_ATS_RESERVATION_REQUEST,
-			  struct ReservationRequestMessage,
-			  NULL),
- GNUNET_MQ_hd_var_size (preference_change, 
-			GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_CHANGE,
-			struct ChangePreferenceMessage,
-			NULL),
- GNUNET_MQ_hd_var_size (feedback, 
-			GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_FEEDBACK,
-			struct FeedbackPreferenceMessage,
-			NULL),
- GNUNET_MQ_handler_end ());
+  ("ats",
+  GNUNET_SERVICE_OPTION_NONE,
+  &run,
+  &client_connect_cb,
+  &client_disconnect_cb,
+  NULL,
+  GNUNET_MQ_hd_fixed_size(ats_start,
+                          GNUNET_MESSAGE_TYPE_ATS_START,
+                          struct ClientStartMessage,
+                          NULL),
+  GNUNET_MQ_hd_fixed_size(request_address,
+                          GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS,
+                          struct RequestAddressMessage,
+                          NULL),
+  GNUNET_MQ_hd_fixed_size(request_address_cancel,
+                          GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS_CANCEL,
+                          struct RequestAddressMessage,
+                          NULL),
+  GNUNET_MQ_hd_fixed_size(request_address_list,
+                          GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_REQUEST,
+                          struct AddressListRequestMessage,
+                          NULL),
+  GNUNET_MQ_hd_var_size(address_add,
+                        GNUNET_MESSAGE_TYPE_ATS_ADDRESS_ADD,
+                        struct AddressAddMessage,
+                        NULL),
+  GNUNET_MQ_hd_fixed_size(address_update,
+                          GNUNET_MESSAGE_TYPE_ATS_ADDRESS_UPDATE,
+                          struct AddressUpdateMessage,
+                          NULL),
+  GNUNET_MQ_hd_fixed_size(address_destroyed,
+                          GNUNET_MESSAGE_TYPE_ATS_ADDRESS_DESTROYED,
+                          struct AddressDestroyedMessage,
+                          NULL),
+  GNUNET_MQ_hd_fixed_size(reservation_request,
+                          GNUNET_MESSAGE_TYPE_ATS_RESERVATION_REQUEST,
+                          struct ReservationRequestMessage,
+                          NULL),
+  GNUNET_MQ_hd_var_size(preference_change,
+                        GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_CHANGE,
+                        struct ChangePreferenceMessage,
+                        NULL),
+  GNUNET_MQ_hd_var_size(feedback,
+                        GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_FEEDBACK,
+                        struct FeedbackPreferenceMessage,
+                        NULL),
+  GNUNET_MQ_handler_end());
 
 
 /* end of gnunet-service-ats.c */

+ 3 - 3
src/ats/gnunet-service-ats.h

@@ -11,12 +11,12 @@
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      Affero General Public License for more details.
-    
+
      You should have received a copy of the GNU Affero General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
-*/
+ */
 
 /**
  * @file ats/gnunet-service-ats.h
@@ -31,7 +31,7 @@
 
 #define GAS_normalization_queue_length 3
 
-#define BANDWIDTH_ZERO GNUNET_BANDWIDTH_value_init (0)
+#define BANDWIDTH_ZERO GNUNET_BANDWIDTH_value_init(0)
 
 /**
  * Handle for statistics.

+ 311 - 316
src/ats/gnunet-service-ats_addresses.c

@@ -1,19 +1,19 @@
 /*
- This file is part of GNUnet.
- Copyright (C) 2011-2015 GNUnet e.V.
+   This file is part of GNUnet.
+   Copyright (C) 2011-2015 GNUnet e.V.
 
- GNUnet is free software: you can redistribute it and/or modify it
- under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License,
- or (at your option) any later version.
+   GNUnet is free software: you can redistribute it and/or modify it
+   under the terms of the GNU Affero General Public License as published
+   by the Free Software Foundation, either version 3 of the License,
+   or (at your option) any later version.
 
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- Affero General Public License for more details.
+   GNUnet is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Affero General Public License for more details.
 
- You should have received a copy of the GNU Affero General Public License
- along with this program.  If not, see <http://www.gnu.org/licenses/>.
+   You should have received a copy of the GNU Affero General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
  */
@@ -41,12 +41,12 @@ struct GNUNET_CONTAINER_MultiPeerMap *GSA_addresses;
  * Update statistic on number of addresses.
  */
 static void
-update_addresses_stat ()
+update_addresses_stat()
 {
-  GNUNET_STATISTICS_set (GSA_stats,
-                         "# addresses",
-                         GNUNET_CONTAINER_multipeermap_size (GSA_addresses),
-                         GNUNET_NO);
+  GNUNET_STATISTICS_set(GSA_stats,
+                        "# addresses",
+                        GNUNET_CONTAINER_multipeermap_size(GSA_addresses),
+                        GNUNET_NO);
 }
 
 
@@ -56,25 +56,25 @@ update_addresses_stat ()
  * @param addr address to destroy
  */
 static void
-free_address (struct ATS_Address *addr)
+free_address(struct ATS_Address *addr)
 {
-  GNUNET_assert (GNUNET_YES ==
-                 GNUNET_CONTAINER_multipeermap_remove (GSA_addresses,
-                                                       &addr->peer,
-                                                       addr));
-  update_addresses_stat ();
-  GAS_plugin_delete_address (addr);
-  GAS_performance_notify_all_clients (&addr->peer,
-                                      addr->plugin,
-                                      addr->addr,
-                                      addr->addr_len,
-                                      GNUNET_NO,
-                                      NULL,
-                                      addr->local_address_info,
-                                      GNUNET_BANDWIDTH_ZERO,
-                                      GNUNET_BANDWIDTH_ZERO);
-  GNUNET_free (addr->plugin);
-  GNUNET_free (addr);
+  GNUNET_assert(GNUNET_YES ==
+                GNUNET_CONTAINER_multipeermap_remove(GSA_addresses,
+                                                     &addr->peer,
+                                                     addr));
+  update_addresses_stat();
+  GAS_plugin_delete_address(addr);
+  GAS_performance_notify_all_clients(&addr->peer,
+                                     addr->plugin,
+                                     addr->addr,
+                                     addr->addr_len,
+                                     GNUNET_NO,
+                                     NULL,
+                                     addr->local_address_info,
+                                     GNUNET_BANDWIDTH_ZERO,
+                                     GNUNET_BANDWIDTH_ZERO);
+  GNUNET_free(addr->plugin);
+  GNUNET_free(addr);
 }
 
 
@@ -84,7 +84,7 @@ free_address (struct ATS_Address *addr)
  * @param norm normalization data to initialize
  */
 static void
-init_norm (struct GAS_NormalizationInfo *norm)
+init_norm(struct GAS_NormalizationInfo *norm)
 {
   unsigned int c;
 
@@ -105,29 +105,29 @@ init_norm (struct GAS_NormalizationInfo *norm)
  * @return the ATS_Address
  */
 static struct ATS_Address *
-create_address (const struct GNUNET_PeerIdentity *peer,
-                const char *plugin_name,
-                const void *plugin_addr,
-                size_t plugin_addr_len,
-                uint32_t local_address_info,
-                uint32_t session_id)
+create_address(const struct GNUNET_PeerIdentity *peer,
+               const char *plugin_name,
+               const void *plugin_addr,
+               size_t plugin_addr_len,
+               uint32_t local_address_info,
+               uint32_t session_id)
 {
   struct ATS_Address *aa;
 
-  aa = GNUNET_malloc (sizeof (struct ATS_Address) + plugin_addr_len);
+  aa = GNUNET_malloc(sizeof(struct ATS_Address) + plugin_addr_len);
   aa->peer = *peer;
   aa->addr_len = plugin_addr_len;
   aa->addr = &aa[1];
-  GNUNET_memcpy (&aa[1],
-          plugin_addr,
-          plugin_addr_len);
-  aa->plugin = GNUNET_strdup (plugin_name);
+  GNUNET_memcpy(&aa[1],
+                plugin_addr,
+                plugin_addr_len);
+  aa->plugin = GNUNET_strdup(plugin_name);
   aa->session_id = session_id;
   aa->local_address_info = local_address_info;
-  init_norm (&aa->norm_delay);
-  init_norm (&aa->norm_distance);
-  init_norm (&aa->norm_utilization_in);
-  init_norm (&aa->norm_utilization_out);
+  init_norm(&aa->norm_delay);
+  init_norm(&aa->norm_distance);
+  init_norm(&aa->norm_utilization_in);
+  init_norm(&aa->norm_utilization_out);
   return aa;
 }
 
@@ -135,8 +135,7 @@ create_address (const struct GNUNET_PeerIdentity *peer,
 /**
  * Closure for #find_address_cb()
  */
-struct FindAddressContext
-{
+struct FindAddressContext {
   /**
    * Session Id to look for.
    */
@@ -146,7 +145,6 @@ struct FindAddressContext
    * Where to store matching address result.
    */
   struct ATS_Address *exact_address;
-
 };
 
 
@@ -159,18 +157,18 @@ struct FindAddressContext
  * @return #GNUNET_YES to continue, #GNUNET_NO if address is found
  */
 static int
-find_address_cb (void *cls,
-                 const struct GNUNET_PeerIdentity *key,
-                 void *value)
+find_address_cb(void *cls,
+                const struct GNUNET_PeerIdentity *key,
+                void *value)
 {
   struct FindAddressContext *fac = cls;
   struct ATS_Address *aa = value;
 
   if (aa->session_id == fac->session_id)
-  {
-    fac->exact_address = aa;
-    return GNUNET_NO;
-  }
+    {
+      fac->exact_address = aa;
+      return GNUNET_NO;
+    }
   return GNUNET_YES;
 }
 
@@ -183,16 +181,16 @@ find_address_cb (void *cls,
  * @return an ATS_address or NULL
  */
 static struct ATS_Address *
-find_exact_address (const struct GNUNET_PeerIdentity *peer,
-                    uint32_t session_id)
+find_exact_address(const struct GNUNET_PeerIdentity *peer,
+                   uint32_t session_id)
 {
   struct FindAddressContext fac;
 
   fac.exact_address = NULL;
   fac.session_id = session_id;
-  GNUNET_CONTAINER_multipeermap_get_multiple (GSA_addresses,
-					      peer,
-					      &find_address_cb, &fac);
+  GNUNET_CONTAINER_multipeermap_get_multiple(GSA_addresses,
+                                             peer,
+                                             &find_address_cb, &fac);
   return fac.exact_address;
 }
 
@@ -209,58 +207,58 @@ find_exact_address (const struct GNUNET_PeerIdentity *peer,
  * @param prop performance information for this address
  */
 void
-GAS_addresses_add (const struct GNUNET_PeerIdentity *peer,
-                   const char *plugin_name,
-                   const void *plugin_addr,
-                   size_t plugin_addr_len,
-                   uint32_t local_address_info,
-                   uint32_t session_id,
-                   const struct GNUNET_ATS_Properties *prop)
+GAS_addresses_add(const struct GNUNET_PeerIdentity *peer,
+                  const char *plugin_name,
+                  const void *plugin_addr,
+                  size_t plugin_addr_len,
+                  uint32_t local_address_info,
+                  uint32_t session_id,
+                  const struct GNUNET_ATS_Properties *prop)
 {
   struct ATS_Address *new_address;
 
-  if (NULL != find_exact_address (peer,
-                                  session_id))
-  {
-    GNUNET_break (0);
-    return;
-  }
-  GNUNET_break (GNUNET_NT_UNSPECIFIED != prop->scope);
-  new_address = create_address (peer,
-                                plugin_name,
-                                plugin_addr,
-                                plugin_addr_len,
-                                local_address_info,
-                                session_id);
+  if (NULL != find_exact_address(peer,
+                                 session_id))
+    {
+      GNUNET_break(0);
+      return;
+    }
+  GNUNET_break(GNUNET_NT_UNSPECIFIED != prop->scope);
+  new_address = create_address(peer,
+                               plugin_name,
+                               plugin_addr,
+                               plugin_addr_len,
+                               local_address_info,
+                               session_id);
   /* Add a new address */
   new_address->properties = *prop;
   new_address->t_added = GNUNET_TIME_absolute_get();
   new_address->t_last_activity = GNUNET_TIME_absolute_get();
   GNUNET_assert(GNUNET_OK ==
-		GNUNET_CONTAINER_multipeermap_put (GSA_addresses,
-						   peer,
-						   new_address,
-						   GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
-  update_addresses_stat ();
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-	      "Adding new address for peer `%s' slot %u\n",
-	      GNUNET_i2s (peer),
-	      session_id);
+                GNUNET_CONTAINER_multipeermap_put(GSA_addresses,
+                                                  peer,
+                                                  new_address,
+                                                  GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
+  update_addresses_stat();
+  GNUNET_log(GNUNET_ERROR_TYPE_INFO,
+             "Adding new address for peer `%s' slot %u\n",
+             GNUNET_i2s(peer),
+             session_id);
   /* Tell solver about new address */
-  GAS_plugin_solver_lock ();
-  GAS_plugin_new_address (new_address);
-  GAS_normalization_update_property (new_address); // FIXME: needed?
-  GAS_plugin_solver_unlock ();
+  GAS_plugin_solver_lock();
+  GAS_plugin_new_address(new_address);
+  GAS_normalization_update_property(new_address);  // FIXME: needed?
+  GAS_plugin_solver_unlock();
   /* Notify performance clients about new address */
-  GAS_performance_notify_all_clients (&new_address->peer,
-				      new_address->plugin,
-				      new_address->addr,
-				      new_address->addr_len,
-				      new_address->active,
-				      &new_address->properties,
-                                      new_address->local_address_info,
-				      GNUNET_BANDWIDTH_value_init (new_address->assigned_bw_out),
-				      GNUNET_BANDWIDTH_value_init (new_address->assigned_bw_in));
+  GAS_performance_notify_all_clients(&new_address->peer,
+                                     new_address->plugin,
+                                     new_address->addr,
+                                     new_address->addr_len,
+                                     new_address->active,
+                                     &new_address->properties,
+                                     new_address->local_address_info,
+                                     GNUNET_BANDWIDTH_value_init(new_address->assigned_bw_out),
+                                     GNUNET_BANDWIDTH_value_init(new_address->assigned_bw_in));
 }
 
 
@@ -272,45 +270,45 @@ GAS_addresses_add (const struct GNUNET_PeerIdentity *peer,
  * @param prop performance information for this address
  */
 void
-GAS_addresses_update (const struct GNUNET_PeerIdentity *peer,
-                      uint32_t session_id,
-                      const struct GNUNET_ATS_Properties *prop)
+GAS_addresses_update(const struct GNUNET_PeerIdentity *peer,
+                     uint32_t session_id,
+                     const struct GNUNET_ATS_Properties *prop)
 {
   struct ATS_Address *aa;
 
   /* Get existing address */
-  aa = find_exact_address (peer,
-                           session_id);
+  aa = find_exact_address(peer,
+                          session_id);
   if (NULL == aa)
-  {
-    GNUNET_break (0);
-    return;
-  }
+    {
+      GNUNET_break(0);
+      return;
+    }
   if (NULL == aa->solver_information)
-  {
-    GNUNET_break (0);
-    return;
-  }
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Received ADDRESS_UPDATE for peer `%s' slot %u\n",
-              GNUNET_i2s (peer),
-              (unsigned int) session_id);
-  GNUNET_break (GNUNET_NT_UNSPECIFIED != prop->scope);
+    {
+      GNUNET_break(0);
+      return;
+    }
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+             "Received ADDRESS_UPDATE for peer `%s' slot %u\n",
+             GNUNET_i2s(peer),
+             (unsigned int)session_id);
+  GNUNET_break(GNUNET_NT_UNSPECIFIED != prop->scope);
   /* Update address */
   aa->t_last_activity = GNUNET_TIME_absolute_get();
   aa->properties = *prop;
   /* Notify performance clients about updated address */
-  GAS_performance_notify_all_clients (&aa->peer,
-                                      aa->plugin,
-                                      aa->addr,
-                                      aa->addr_len,
-                                      aa->active,
-                                      prop,
-                                      aa->local_address_info,
-                                      GNUNET_BANDWIDTH_value_init (aa->assigned_bw_out),
-                                      GNUNET_BANDWIDTH_value_init (aa->assigned_bw_in));
-
-  GAS_normalization_update_property (aa);
+  GAS_performance_notify_all_clients(&aa->peer,
+                                     aa->plugin,
+                                     aa->addr,
+                                     aa->addr_len,
+                                     aa->active,
+                                     prop,
+                                     aa->local_address_info,
+                                     GNUNET_BANDWIDTH_value_init(aa->assigned_bw_out),
+                                     GNUNET_BANDWIDTH_value_init(aa->assigned_bw_in));
+
+  GAS_normalization_update_property(aa);
 }
 
 
@@ -321,24 +319,24 @@ GAS_addresses_update (const struct GNUNET_PeerIdentity *peer,
  * @param session_id session id, can never be 0
  */
 void
-GAS_addresses_destroy (const struct GNUNET_PeerIdentity *peer,
-                       uint32_t session_id)
+GAS_addresses_destroy(const struct GNUNET_PeerIdentity *peer,
+                      uint32_t session_id)
 {
   struct ATS_Address *ea;
 
   /* Get existing address */
-  ea = find_exact_address (peer,
-                           session_id);
+  ea = find_exact_address(peer,
+                          session_id);
   if (NULL == ea)
-  {
-    GNUNET_break (0);
-    return;
-  }
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Received ADDRESS_DESTROYED for peer `%s' session %u\n",
-              GNUNET_i2s (peer),
-              session_id);
-  free_address (ea);
+    {
+      GNUNET_break(0);
+      return;
+    }
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+             "Received ADDRESS_DESTROYED for peer `%s' session %u\n",
+             GNUNET_i2s(peer),
+             session_id);
+  free_address(ea);
 }
 
 
@@ -349,12 +347,12 @@ GAS_addresses_destroy (const struct GNUNET_PeerIdentity *peer,
  * and receives updates when the solver changes the resource allocation.
  */
 void
-GAS_addresses_init ()
+GAS_addresses_init()
 {
   GSA_addresses
-    = GNUNET_CONTAINER_multipeermap_create (128,
-					    GNUNET_NO);
-  update_addresses_stat ();
+    = GNUNET_CONTAINER_multipeermap_create(128,
+                                           GNUNET_NO);
+  update_addresses_stat();
 }
 
 
@@ -367,13 +365,13 @@ GAS_addresses_init ()
  * @return #GNUNET_OK (continue to iterate)
  */
 static int
-destroy_all_address_it (void *cls,
-			const struct GNUNET_PeerIdentity *key,
-			void *value)
+destroy_all_address_it(void *cls,
+                       const struct GNUNET_PeerIdentity *key,
+                       void *value)
 {
   struct ATS_Address *aa = value;
 
-  free_address (aa);
+  free_address(aa);
   return GNUNET_OK;
 }
 
@@ -382,18 +380,18 @@ destroy_all_address_it (void *cls,
  * Remove all addresses
  */
 void
-GAS_addresses_destroy_all ()
+GAS_addresses_destroy_all()
 {
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-              "Destroying all addresses\n");
+  GNUNET_log(GNUNET_ERROR_TYPE_INFO,
+             "Destroying all addresses\n");
   if (0 ==
-      GNUNET_CONTAINER_multipeermap_size (GSA_addresses))
+      GNUNET_CONTAINER_multipeermap_size(GSA_addresses))
     return;
-  GAS_plugin_solver_lock ();
-  GNUNET_CONTAINER_multipeermap_iterate (GSA_addresses,
-                                         &destroy_all_address_it,
-                                         NULL);
-  GAS_plugin_solver_unlock ();
+  GAS_plugin_solver_lock();
+  GNUNET_CONTAINER_multipeermap_iterate(GSA_addresses,
+                                        &destroy_all_address_it,
+                                        NULL);
+  GAS_plugin_solver_unlock();
 }
 
 
@@ -401,14 +399,14 @@ GAS_addresses_destroy_all ()
  * Shutdown address subsystem.
  */
 void
-GAS_addresses_done ()
+GAS_addresses_done()
 {
   GNUNET_log(GNUNET_ERROR_TYPE_INFO,
              "Shutting down addresses\n");
-  GAS_plugin_solver_lock ();
-  GAS_addresses_destroy_all ();
-  GAS_plugin_solver_unlock ();
-  GNUNET_CONTAINER_multipeermap_destroy (GSA_addresses);
+  GAS_plugin_solver_lock();
+  GAS_addresses_destroy_all();
+  GAS_plugin_solver_unlock();
+  GNUNET_CONTAINER_multipeermap_destroy(GSA_addresses);
   GSA_addresses = NULL;
 }
 
@@ -416,8 +414,7 @@ GAS_addresses_done ()
 /**
  * Closure for #peerinfo_it().
  */
-struct PeerInfoIteratorContext
-{
+struct PeerInfoIteratorContext {
   /**
    * Function to call for each address.
    */
@@ -439,23 +436,23 @@ struct PeerInfoIteratorContext
  * @return #GNUNET_OK to continue
  */
 static int
-peerinfo_it (void *cls,
-	     const struct GNUNET_PeerIdentity *key,
-	     void *value)
+peerinfo_it(void *cls,
+            const struct GNUNET_PeerIdentity *key,
+            void *value)
 {
   struct PeerInfoIteratorContext *pi_ctx = cls;
   struct ATS_Address *addr = value;
 
-  pi_ctx->it (pi_ctx->it_cls,
-              &addr->peer,
-              addr->plugin,
-              addr->addr,
-              addr->addr_len,
-              addr->active,
-              &addr->properties,
-              addr->local_address_info,
-              GNUNET_BANDWIDTH_value_init (addr->assigned_bw_out),
-              GNUNET_BANDWIDTH_value_init (addr->assigned_bw_in));
+  pi_ctx->it(pi_ctx->it_cls,
+             &addr->peer,
+             addr->plugin,
+             addr->addr,
+             addr->addr_len,
+             addr->active,
+             &addr->properties,
+             addr->local_address_info,
+             GNUNET_BANDWIDTH_value_init(addr->assigned_bw_out),
+             GNUNET_BANDWIDTH_value_init(addr->assigned_bw_in));
   return GNUNET_OK;
 }
 
@@ -468,41 +465,41 @@ peerinfo_it (void *cls,
  * @param pi_it_cls the closure for @a pi_it
  */
 void
-GAS_addresses_get_peer_info (const struct GNUNET_PeerIdentity *peer,
-                             GNUNET_ATS_PeerInfo_Iterator pi_it,
-                             void *pi_it_cls)
+GAS_addresses_get_peer_info(const struct GNUNET_PeerIdentity *peer,
+                            GNUNET_ATS_PeerInfo_Iterator pi_it,
+                            void *pi_it_cls)
 {
   struct PeerInfoIteratorContext pi_ctx;
 
   if (NULL == pi_it)
-  {
-    /* does not make sense without callback */
-    GNUNET_break (0);
-    return;
-  }
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Returning information for %s from a total of %u known addresses\n",
-              (NULL == peer)
-              ? "all peers"
-              : GNUNET_i2s (peer),
-              (unsigned int) GNUNET_CONTAINER_multipeermap_size (GSA_addresses));
+    {
+      /* does not make sense without callback */
+      GNUNET_break(0);
+      return;
+    }
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+             "Returning information for %s from a total of %u known addresses\n",
+             (NULL == peer)
+             ? "all peers"
+             : GNUNET_i2s(peer),
+             (unsigned int)GNUNET_CONTAINER_multipeermap_size(GSA_addresses));
   pi_ctx.it = pi_it;
   pi_ctx.it_cls = pi_it_cls;
   if (NULL == peer)
-    GNUNET_CONTAINER_multipeermap_iterate (GSA_addresses,
-                                           &peerinfo_it,
-                                           &pi_ctx);
+    GNUNET_CONTAINER_multipeermap_iterate(GSA_addresses,
+                                          &peerinfo_it,
+                                          &pi_ctx);
   else
-    GNUNET_CONTAINER_multipeermap_get_multiple (GSA_addresses,
-                                                peer,
-                                                &peerinfo_it, &pi_ctx);
-  pi_it (pi_it_cls,
-         NULL, NULL, NULL, 0,
-         GNUNET_NO,
-         NULL,
-         GNUNET_HELLO_ADDRESS_INFO_NONE,
-         GNUNET_BANDWIDTH_ZERO,
-         GNUNET_BANDWIDTH_ZERO);
+    GNUNET_CONTAINER_multipeermap_get_multiple(GSA_addresses,
+                                               peer,
+                                               &peerinfo_it, &pi_ctx);
+  pi_it(pi_it_cls,
+        NULL, NULL, NULL, 0,
+        GNUNET_NO,
+        NULL,
+        GNUNET_HELLO_ADDRESS_INFO_NONE,
+        GNUNET_BANDWIDTH_ZERO,
+        GNUNET_BANDWIDTH_ZERO);
 }
 
 
@@ -510,8 +507,7 @@ GAS_addresses_get_peer_info (const struct GNUNET_PeerIdentity *peer,
  * Information we need for the callbacks to return a list of addresses
  * back to the client.
  */
-struct AddressIteration
-{
+struct AddressIteration {
   /**
    * Actual handle to the client.
    */
@@ -526,7 +522,6 @@ struct AddressIteration
    * Which ID should be included in the response?
    */
   uint32_t id;
-
 };
 
 
@@ -546,16 +541,16 @@ struct AddressIteration
  * @param bandwidth_in current inbound bandwidth assigned to address
  */
 static void
-transmit_req_addr (struct AddressIteration *ai,
-                   const struct GNUNET_PeerIdentity *id,
-                   const char *plugin_name,
-                   const void *plugin_addr,
-                   size_t plugin_addr_len,
-                   int active,
-                   const struct GNUNET_ATS_Properties *prop,
-                   enum GNUNET_HELLO_AddressInfo local_address_info,
-                   struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
-                   struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
+transmit_req_addr(struct AddressIteration *ai,
+                  const struct GNUNET_PeerIdentity *id,
+                  const char *plugin_name,
+                  const void *plugin_addr,
+                  size_t plugin_addr_len,
+                  int active,
+                  const struct GNUNET_ATS_Properties *prop,
+                  enum GNUNET_HELLO_AddressInfo local_address_info,
+                  struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
+                  struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
 
 {
   struct GNUNET_MQ_Envelope *env;
@@ -565,37 +560,37 @@ transmit_req_addr (struct AddressIteration *ai,
   size_t msize;
 
   if (NULL != plugin_name)
-    plugin_name_length = strlen (plugin_name) + 1;
+    plugin_name_length = strlen(plugin_name) + 1;
   else
     plugin_name_length = 0;
   msize = plugin_addr_len + plugin_name_length;
 
-  GNUNET_assert (sizeof (struct PeerInformationMessage) + msize
-		 < GNUNET_MAX_MESSAGE_SIZE);
-  env = GNUNET_MQ_msg_extra (msg,
-			     msize,
-			     GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_RESPONSE);
-  msg->id = htonl (ai->id);
+  GNUNET_assert(sizeof(struct PeerInformationMessage) + msize
+                < GNUNET_MAX_MESSAGE_SIZE);
+  env = GNUNET_MQ_msg_extra(msg,
+                            msize,
+                            GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_RESPONSE);
+  msg->id = htonl(ai->id);
   if (NULL != id)
     msg->peer = *id;
-  msg->address_length = htons (plugin_addr_len);
-  msg->address_active = ntohl (active);
-  msg->plugin_name_length = htons (plugin_name_length);
+  msg->address_length = htons(plugin_addr_len);
+  msg->address_active = ntohl(active);
+  msg->plugin_name_length = htons(plugin_name_length);
   msg->bandwidth_out = bandwidth_out;
   msg->bandwidth_in = bandwidth_in;
   if (NULL != prop)
-    GNUNET_ATS_properties_hton (&msg->properties,
-                                prop);
-  msg->address_local_info = htonl ((uint32_t) local_address_info);
-  addrp = (char *) &msg[1];
-  GNUNET_memcpy (addrp,
-		 plugin_addr,
-		 plugin_addr_len);
+    GNUNET_ATS_properties_hton(&msg->properties,
+                               prop);
+  msg->address_local_info = htonl((uint32_t)local_address_info);
+  addrp = (char *)&msg[1];
+  GNUNET_memcpy(addrp,
+                plugin_addr,
+                plugin_addr_len);
   if (NULL != plugin_name)
-    strcpy (&addrp[plugin_addr_len],
-	    plugin_name);
-  GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (ai->client),
-		  env);
+    strcpy(&addrp[plugin_addr_len],
+           plugin_name);
+  GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(ai->client),
+                 env);
 }
 
 
@@ -615,48 +610,48 @@ transmit_req_addr (struct AddressIteration *ai,
  * @param bandwidth_in current inbound bandwidth assigned to address
  */
 static void
-req_addr_peerinfo_it (void *cls,
-                      const struct GNUNET_PeerIdentity *id,
-                      const char *plugin_name,
-                      const void *plugin_addr,
-                      size_t plugin_addr_len,
-                      int active,
-                      const struct GNUNET_ATS_Properties *prop,
-                      enum GNUNET_HELLO_AddressInfo local_address_info,
-                      struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
-                      struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
+req_addr_peerinfo_it(void *cls,
+                     const struct GNUNET_PeerIdentity *id,
+                     const char *plugin_name,
+                     const void *plugin_addr,
+                     size_t plugin_addr_len,
+                     int active,
+                     const struct GNUNET_ATS_Properties *prop,
+                     enum GNUNET_HELLO_AddressInfo local_address_info,
+                     struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
+                     struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
 {
   struct AddressIteration *ai = cls;
 
-  if ( (NULL == id) &&
-       (NULL == plugin_name) &&
-       (NULL == plugin_addr) )
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "Address iteration done for one peer\n");
-    return;
-  }
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Callback for %s peer `%s' plugin `%s' BW out %u, BW in %u\n",
-              (active == GNUNET_YES) ? "ACTIVE" : "INACTIVE",
-              GNUNET_i2s (id),
-              plugin_name,
-              (unsigned int) ntohl (bandwidth_out.value__),
-              (unsigned int) ntohl (bandwidth_in.value__));
+  if ((NULL == id) &&
+      (NULL == plugin_name) &&
+      (NULL == plugin_addr))
+    {
+      GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+                 "Address iteration done for one peer\n");
+      return;
+    }
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+             "Callback for %s peer `%s' plugin `%s' BW out %u, BW in %u\n",
+             (active == GNUNET_YES) ? "ACTIVE" : "INACTIVE",
+             GNUNET_i2s(id),
+             plugin_name,
+             (unsigned int)ntohl(bandwidth_out.value__),
+             (unsigned int)ntohl(bandwidth_in.value__));
   /* Transmit result (either if address is active, or if
      client wanted all addresses) */
-  if ( (GNUNET_YES != ai->all) &&
-       (GNUNET_YES != active))
+  if ((GNUNET_YES != ai->all) &&
+      (GNUNET_YES != active))
     return;
-  transmit_req_addr (ai,
-                     id,
-                     plugin_name,
-                     plugin_addr, plugin_addr_len,
-                     active,
-                     prop,
-                     local_address_info,
-                     bandwidth_out,
-                     bandwidth_in);
+  transmit_req_addr(ai,
+                    id,
+                    plugin_name,
+                    plugin_addr, plugin_addr_len,
+                    active,
+                    prop,
+                    local_address_info,
+                    bandwidth_out,
+                    bandwidth_in);
 }
 
 
@@ -667,45 +662,45 @@ req_addr_peerinfo_it (void *cls,
  * @param alrm the request message
  */
 void
-GAS_handle_request_address_list (struct GNUNET_SERVICE_Client *client,
-                                 const struct AddressListRequestMessage *alrm)
+GAS_handle_request_address_list(struct GNUNET_SERVICE_Client *client,
+                                const struct AddressListRequestMessage *alrm)
 {
   struct AddressIteration ai;
   struct GNUNET_PeerIdentity allzeros;
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Received ADDRESSLIST_REQUEST message\n");
-  ai.all = ntohl (alrm->all);
-  ai.id = ntohl (alrm->id);
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+             "Received ADDRESSLIST_REQUEST message\n");
+  ai.all = ntohl(alrm->all);
+  ai.id = ntohl(alrm->id);
   ai.client = client;
 
-  memset (&allzeros,
-          '\0',
-          sizeof (struct GNUNET_PeerIdentity));
-  if (0 == GNUNET_is_zero (&alrm->peer))
-  {
-    /* Return addresses for all peers */
-    GAS_addresses_get_peer_info (NULL,
-                                 &req_addr_peerinfo_it,
-                                 &ai);
-  }
+  memset(&allzeros,
+         '\0',
+         sizeof(struct GNUNET_PeerIdentity));
+  if (0 == GNUNET_is_zero(&alrm->peer))
+    {
+      /* Return addresses for all peers */
+      GAS_addresses_get_peer_info(NULL,
+                                  &req_addr_peerinfo_it,
+                                  &ai);
+    }
   else
-  {
-    /* Return addresses for a specific peer */
-    GAS_addresses_get_peer_info (&alrm->peer,
-                                 &req_addr_peerinfo_it,
-                                 &ai);
-  }
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Finished handling `%s' message\n",
-              "ADDRESSLIST_REQUEST");
-  transmit_req_addr (&ai,
-                     NULL, NULL, NULL,
-                     0, GNUNET_NO,
-                     NULL,
-                     GNUNET_HELLO_ADDRESS_INFO_NONE,
-                     GNUNET_BANDWIDTH_ZERO,
-                     GNUNET_BANDWIDTH_ZERO);
+    {
+      /* Return addresses for a specific peer */
+      GAS_addresses_get_peer_info(&alrm->peer,
+                                  &req_addr_peerinfo_it,
+                                  &ai);
+    }
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+             "Finished handling `%s' message\n",
+             "ADDRESSLIST_REQUEST");
+  transmit_req_addr(&ai,
+                    NULL, NULL, NULL,
+                    0, GNUNET_NO,
+                    NULL,
+                    GNUNET_HELLO_ADDRESS_INFO_NONE,
+                    GNUNET_BANDWIDTH_ZERO,
+                    GNUNET_BANDWIDTH_ZERO);
 }
 
 

+ 35 - 38
src/ats/gnunet-service-ats_addresses.h

@@ -1,19 +1,19 @@
 /*
- This file is part of GNUnet.
- Copyright (C) 2011-2014 GNUnet e.V.
+   This file is part of GNUnet.
+   Copyright (C) 2011-2014 GNUnet e.V.
 
- GNUnet is free software: you can redistribute it and/or modify it
- under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License,
- or (at your option) any later version.
+   GNUnet is free software: you can redistribute it and/or modify it
+   under the terms of the GNU Affero General Public License as published
+   by the Free Software Foundation, either version 3 of the License,
+   or (at your option) any later version.
 
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- Affero General Public License for more details.
+   GNUnet is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Affero General Public License for more details.
 
- You should have received a copy of the GNU Affero General Public License
- along with this program.  If not, see <http://www.gnu.org/licenses/>.
+   You should have received a copy of the GNU Affero General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
  */
@@ -226,8 +226,7 @@
 /**
  * Information provided by ATS normalization
  */
-struct GAS_NormalizationInfo
-{
+struct GAS_NormalizationInfo {
   /**
    * Next index to use in averaging queue
    */
@@ -253,8 +252,7 @@ struct GAS_NormalizationInfo
 /**
  * Address with additional information
  */
-struct ATS_Address
-{
+struct ATS_Address {
   /**
    * Peer ID this address is for.
    */
@@ -350,11 +348,10 @@ struct ATS_Address
    */
   struct GAS_NormalizationInfo norm_utilization_in;
 
-    /**
+  /**
    * Normalized utilization outbound for this address.
    */
   struct GAS_NormalizationInfo norm_utilization_out;
-
 };
 
 
@@ -369,14 +366,14 @@ extern struct GNUNET_CONTAINER_MultiPeerMap *GSA_addresses;
  * known and current performance information.
  */
 void
-GAS_addresses_init (void);
+GAS_addresses_init(void);
 
 
 /**
  * Shutdown address subsystem.
  */
 void
-GAS_addresses_done (void);
+GAS_addresses_done(void);
 
 
 /**
@@ -391,13 +388,13 @@ GAS_addresses_done (void);
  * @param prop performance information for this address
  */
 void
-GAS_addresses_add (const struct GNUNET_PeerIdentity *peer,
-                   const char *plugin_name,
-                   const void *plugin_addr,
-                   size_t plugin_addr_len,
-                   uint32_t local_address_info,
-                   uint32_t session_id,
-                   const struct GNUNET_ATS_Properties *prop);
+GAS_addresses_add(const struct GNUNET_PeerIdentity *peer,
+                  const char *plugin_name,
+                  const void *plugin_addr,
+                  size_t plugin_addr_len,
+                  uint32_t local_address_info,
+                  uint32_t session_id,
+                  const struct GNUNET_ATS_Properties *prop);
 
 
 /**
@@ -408,9 +405,9 @@ GAS_addresses_add (const struct GNUNET_PeerIdentity *peer,
  * @param prop performance information for this address
  */
 void
-GAS_addresses_update (const struct GNUNET_PeerIdentity *peer,
-                      uint32_t session_id,
-                      const struct GNUNET_ATS_Properties *prop);
+GAS_addresses_update(const struct GNUNET_PeerIdentity *peer,
+                     uint32_t session_id,
+                     const struct GNUNET_ATS_Properties *prop);
 
 
 /**
@@ -420,15 +417,15 @@ GAS_addresses_update (const struct GNUNET_PeerIdentity *peer,
  * @param session_id session id, can never be 0
  */
 void
-GAS_addresses_destroy (const struct GNUNET_PeerIdentity *peer,
-                       uint32_t session_id);
+GAS_addresses_destroy(const struct GNUNET_PeerIdentity *peer,
+                      uint32_t session_id);
 
 
 /**
  * Remove all addresses.
  */
 void
-GAS_addresses_destroy_all (void);
+GAS_addresses_destroy_all(void);
 
 
 /**
@@ -466,9 +463,9 @@ typedef void
  * @param pi_it_cls the closure for @a pi_it
  */
 void
-GAS_addresses_get_peer_info (const struct GNUNET_PeerIdentity *peer,
-                             GNUNET_ATS_PeerInfo_Iterator pi_it,
-                             void *pi_it_cls);
+GAS_addresses_get_peer_info(const struct GNUNET_PeerIdentity *peer,
+                            GNUNET_ATS_PeerInfo_Iterator pi_it,
+                            void *pi_it_cls);
 
 
 /**
@@ -478,8 +475,8 @@ GAS_addresses_get_peer_info (const struct GNUNET_PeerIdentity *peer,
  * @param alrm the request message
  */
 void
-GAS_handle_request_address_list (struct GNUNET_SERVICE_Client *client,
-                                 const struct AddressListRequestMessage *alrm);
+GAS_handle_request_address_list(struct GNUNET_SERVICE_Client *client,
+                                const struct AddressListRequestMessage *alrm);
 
 
 #endif

+ 60 - 61
src/ats/gnunet-service-ats_connectivity.c

@@ -11,12 +11,12 @@
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      Affero General Public License for more details.
-    
+
      You should have received a copy of the GNU Affero General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
-*/
+ */
 
 /**
  * @file ats/gnunet-service-ats_connectivity.c
@@ -35,8 +35,7 @@
 /**
  * Active connection requests.
  */
-struct ConnectionRequest
-{
+struct ConnectionRequest {
   /**
    * Client that made the request.
    */
@@ -61,14 +60,14 @@ static struct GNUNET_CONTAINER_MultiPeerMap *connection_requests;
  * @return #GNUNET_YES if so, #GNUNET_NO if not
  */
 unsigned int
-GAS_connectivity_has_peer (void *cls,
-                           const struct GNUNET_PeerIdentity *peer)
+GAS_connectivity_has_peer(void *cls,
+                          const struct GNUNET_PeerIdentity *peer)
 {
   if (NULL == connection_requests)
     return 0;
   /* TODO: return sum of 'strength's of connectivity requests */
-  return GNUNET_CONTAINER_multipeermap_contains (connection_requests,
-                                                 peer);
+  return GNUNET_CONTAINER_multipeermap_contains(connection_requests,
+                                                peer);
 }
 
 
@@ -79,22 +78,22 @@ GAS_connectivity_has_peer (void *cls,
  * @param message the request message
  */
 void
-GAS_handle_request_address (struct GNUNET_SERVICE_Client *client,
-			    const struct RequestAddressMessage *msg)
+GAS_handle_request_address(struct GNUNET_SERVICE_Client *client,
+                           const struct RequestAddressMessage *msg)
 {
   struct ConnectionRequest *cr;
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Received `%s' message\n",
-              "GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS");
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+             "Received `%s' message\n",
+             "GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS");
   /* FIXME: should not ignore "msg->strength" */
-  cr = GNUNET_new (struct ConnectionRequest);
+  cr = GNUNET_new(struct ConnectionRequest);
   cr->client = client;
-  (void) GNUNET_CONTAINER_multipeermap_put (connection_requests,
-                                            &msg->peer,
-                                            cr,
-                                            GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
-  GAS_plugin_request_connect_start (&msg->peer);
+  (void)GNUNET_CONTAINER_multipeermap_put(connection_requests,
+                                          &msg->peer,
+                                          cr,
+                                          GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
+  GAS_plugin_request_connect_start(&msg->peer);
 }
 
 
@@ -108,25 +107,25 @@ GAS_handle_request_address (struct GNUNET_SERVICE_Client *client,
  * @return #GNUNET_OK (continue to iterate)
  */
 static int
-free_matching_requests (void *cls,
-                        const struct GNUNET_PeerIdentity *pid,
-                        void *value)
+free_matching_requests(void *cls,
+                       const struct GNUNET_PeerIdentity *pid,
+                       void *value)
 {
   struct GNUNET_SERVICE_Client *client = cls;
   struct ConnectionRequest *cr = value;
 
   if (cr->client == client)
-  {
-    GAS_plugin_request_connect_stop (pid);
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "Removed request pending for peer `%s\n",
-                GNUNET_i2s (pid));
-    GNUNET_assert (GNUNET_YES ==
-                   GNUNET_CONTAINER_multipeermap_remove (connection_requests,
+    {
+      GAS_plugin_request_connect_stop(pid);
+      GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+                 "Removed request pending for peer `%s\n",
+                 GNUNET_i2s(pid));
+      GNUNET_assert(GNUNET_YES ==
+                    GNUNET_CONTAINER_multipeermap_remove(connection_requests,
                                                          pid,
                                                          cr));
-    GNUNET_free (cr);
-  }
+      GNUNET_free(cr);
+    }
   return GNUNET_OK;
 }
 
@@ -139,17 +138,17 @@ free_matching_requests (void *cls,
  * @param msg the request message
  */
 void
-GAS_handle_request_address_cancel (struct GNUNET_SERVICE_Client *client,
-				   const struct RequestAddressMessage *msg)
+GAS_handle_request_address_cancel(struct GNUNET_SERVICE_Client *client,
+                                  const struct RequestAddressMessage *msg)
 {
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Received GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS_CANCEL message for peer %s\n",
-              GNUNET_i2s (&msg->peer));
-  GNUNET_break (0 == ntohl (msg->strength));
-  GNUNET_CONTAINER_multipeermap_get_multiple (connection_requests,
-                                              &msg->peer,
-                                              &free_matching_requests,
-                                              client);
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+             "Received GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS_CANCEL message for peer %s\n",
+             GNUNET_i2s(&msg->peer));
+  GNUNET_break(0 == ntohl(msg->strength));
+  GNUNET_CONTAINER_multipeermap_get_multiple(connection_requests,
+                                             &msg->peer,
+                                             &free_matching_requests,
+                                             client);
 }
 
 
@@ -160,11 +159,11 @@ GAS_handle_request_address_cancel (struct GNUNET_SERVICE_Client *client,
  * @param client handle of the (now dead) client
  */
 void
-GAS_connectivity_remove_client (struct GNUNET_SERVICE_Client *client)
+GAS_connectivity_remove_client(struct GNUNET_SERVICE_Client *client)
 {
-  GNUNET_CONTAINER_multipeermap_iterate (connection_requests,
-                                         &free_matching_requests,
-                                         client);
+  GNUNET_CONTAINER_multipeermap_iterate(connection_requests,
+                                        &free_matching_requests,
+                                        client);
 }
 
 
@@ -172,11 +171,11 @@ GAS_connectivity_remove_client (struct GNUNET_SERVICE_Client *client)
  * Shutdown connectivity subsystem.
  */
 void
-GAS_connectivity_init ()
+GAS_connectivity_init()
 {
   connection_requests
-    = GNUNET_CONTAINER_multipeermap_create (32,
-					    GNUNET_NO);
+    = GNUNET_CONTAINER_multipeermap_create(32,
+                                           GNUNET_NO);
 }
 
 
@@ -189,15 +188,15 @@ GAS_connectivity_init ()
  * @return #GNUNET_OK (continue to iterate)
  */
 static int
-free_request (void *cls,
-              const struct GNUNET_PeerIdentity *pid,
-              void *value)
+free_request(void *cls,
+             const struct GNUNET_PeerIdentity *pid,
+             void *value)
 {
   struct ConnectionRequest *cr = value;
 
-  free_matching_requests (cr->client,
-                          pid,
-                          cr);
+  free_matching_requests(cr->client,
+                         pid,
+                         cr);
   return GNUNET_OK;
 }
 
@@ -206,14 +205,14 @@ free_request (void *cls,
  * Shutdown connectivity subsystem.
  */
 void
-GAS_connectivity_done ()
+GAS_connectivity_done()
 {
-  GAS_plugin_solver_lock ();
-  GNUNET_CONTAINER_multipeermap_iterate (connection_requests,
-                                         &free_request,
-                                         NULL);
-  GAS_plugin_solver_unlock ();
-  GNUNET_CONTAINER_multipeermap_destroy (connection_requests);
+  GAS_plugin_solver_lock();
+  GNUNET_CONTAINER_multipeermap_iterate(connection_requests,
+                                        &free_request,
+                                        NULL);
+  GAS_plugin_solver_unlock();
+  GNUNET_CONTAINER_multipeermap_destroy(connection_requests);
   connection_requests = NULL;
 }
 

+ 11 - 11
src/ats/gnunet-service-ats_connectivity.h

@@ -11,12 +11,12 @@
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      Affero General Public License for more details.
-    
+
      You should have received a copy of the GNU Affero General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
-*/
+ */
 /**
  * @file ats/gnunet-service-ats_connectivity.h
  * @brief ats service, interaction with 'connecivity' API
@@ -38,8 +38,8 @@
  * @return #GNUNET_YES if so, #GNUNET_NO if not
  */
 unsigned int
-GAS_connectivity_has_peer (void *cls,
-                           const struct GNUNET_PeerIdentity *peer);
+GAS_connectivity_has_peer(void *cls,
+                          const struct GNUNET_PeerIdentity *peer);
 
 
 /**
@@ -49,8 +49,8 @@ GAS_connectivity_has_peer (void *cls,
  * @param msg the request message
  */
 void
-GAS_handle_request_address (struct GNUNET_SERVICE_Client *client,
-                            const struct RequestAddressMessage *msg);
+GAS_handle_request_address(struct GNUNET_SERVICE_Client *client,
+                           const struct RequestAddressMessage *msg);
 
 
 /**
@@ -60,8 +60,8 @@ GAS_handle_request_address (struct GNUNET_SERVICE_Client *client,
  * @param msg the request message
  */
 void
-GAS_handle_request_address_cancel (struct GNUNET_SERVICE_Client *client,
-                                   const struct RequestAddressMessage *msg);
+GAS_handle_request_address_cancel(struct GNUNET_SERVICE_Client *client,
+                                  const struct RequestAddressMessage *msg);
 
 
 /**
@@ -71,21 +71,21 @@ GAS_handle_request_address_cancel (struct GNUNET_SERVICE_Client *client,
  * @param client handle of the (now dead) client
  */
 void
-GAS_connectivity_remove_client (struct GNUNET_SERVICE_Client *client);
+GAS_connectivity_remove_client(struct GNUNET_SERVICE_Client *client);
 
 
 /**
  * Initialize connectivity subsystem.
  */
 void
-GAS_connectivity_init (void);
+GAS_connectivity_init(void);
 
 
 /**
  * Shutdown connectivity subsystem.
  */
 void
-GAS_connectivity_done (void);
+GAS_connectivity_done(void);
 
 
 #endif

+ 108 - 109
src/ats/gnunet-service-ats_normalization.c

@@ -1,19 +1,19 @@
 /*
- This file is part of GNUnet.
- Copyright (C) 2011-2015 GNUnet e.V.
+   This file is part of GNUnet.
+   Copyright (C) 2011-2015 GNUnet e.V.
 
- GNUnet is free software: you can redistribute it and/or modify it
- under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License,
- or (at your option) any later version.
+   GNUnet is free software: you can redistribute it and/or modify it
+   under the terms of the GNU Affero General Public License as published
+   by the Free Software Foundation, either version 3 of the License,
+   or (at your option) any later version.
 
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- Affero General Public License for more details.
+   GNUnet is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Affero General Public License for more details.
 
- You should have received a copy of the GNU Affero General Public License
- along with this program.  If not, see <http://www.gnu.org/licenses/>.
+   You should have received a copy of the GNU Affero General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
  */
@@ -31,14 +31,13 @@
 #include "gnunet-service-ats_normalization.h"
 #include "gnunet-service-ats_plugins.h"
 
-#define LOG(kind,...) GNUNET_log_from (kind, "ats-normalization",__VA_ARGS__)
+#define LOG(kind, ...) GNUNET_log_from(kind, "ats-normalization", __VA_ARGS__)
 
 
 /**
  * Range information for normalization of quality properties.
  */
-struct PropertyRange
-{
+struct PropertyRange {
   /**
    * Minimum value we see for this property across all addresses.
    */
@@ -65,8 +64,8 @@ static struct PropertyRange property_range;
  * @param ni normalization information to update
  */
 static void
-update_avg (uint64_t current_val,
-            struct GAS_NormalizationInfo *ni)
+update_avg(uint64_t current_val,
+           struct GAS_NormalizationInfo *ni)
 {
   double sum;
   uint32_t count;
@@ -78,13 +77,13 @@ update_avg (uint64_t current_val,
   count = 0;
   sum = 0.0;
   for (c1 = 0; c1 < GAS_normalization_queue_length; c1++)
-  {
-    if (UINT64_MAX != ni->atsi_abs[c1])
     {
-      count++;
-      sum += (double) ni->atsi_abs[c1];
+      if (UINT64_MAX != ni->atsi_abs[c1])
+        {
+          count++;
+          sum += (double)ni->atsi_abs[c1];
+        }
     }
-  }
   if (0 == count)
     ni->avg = current_val; /* must be UINT64_MAX */
   else
@@ -103,29 +102,29 @@ update_avg (uint64_t current_val,
  * @return #GNUNET_OK (continue to iterate)
  */
 static int
-find_min_max_it (void *cls,
-                 const struct GNUNET_PeerIdentity *h,
-                 void *k)
+find_min_max_it(void *cls,
+                const struct GNUNET_PeerIdentity *h,
+                void *k)
 {
   struct PropertyRange *pr = cls;
   const struct ATS_Address *a = k;
 
-  pr->max.utilization_out = GNUNET_MAX (pr->max.utilization_out,
-                                        a->properties.utilization_out);
-  pr->max.utilization_in = GNUNET_MAX (pr->max.utilization_in,
-                                       a->properties.utilization_in);
-  pr->max.distance = GNUNET_MAX (pr->max.distance,
-                                 a->properties.distance);
-  pr->max.delay = GNUNET_TIME_relative_max (pr->max.delay,
-                                            a->properties.delay);
-  pr->min.utilization_out = GNUNET_MIN (pr->min.utilization_out,
-                                        a->properties.utilization_out);
-  pr->min.utilization_in = GNUNET_MIN (pr->min.utilization_in,
-                                       a->properties.utilization_in);
-  pr->min.distance = GNUNET_MIN (pr->min.distance,
-                                 a->properties.distance);
-  pr->min.delay = GNUNET_TIME_relative_min (pr->min.delay,
-                                            a->properties.delay);
+  pr->max.utilization_out = GNUNET_MAX(pr->max.utilization_out,
+                                       a->properties.utilization_out);
+  pr->max.utilization_in = GNUNET_MAX(pr->max.utilization_in,
+                                      a->properties.utilization_in);
+  pr->max.distance = GNUNET_MAX(pr->max.distance,
+                                a->properties.distance);
+  pr->max.delay = GNUNET_TIME_relative_max(pr->max.delay,
+                                           a->properties.delay);
+  pr->min.utilization_out = GNUNET_MIN(pr->min.utilization_out,
+                                       a->properties.utilization_out);
+  pr->min.utilization_in = GNUNET_MIN(pr->min.utilization_in,
+                                      a->properties.utilization_in);
+  pr->min.distance = GNUNET_MIN(pr->min.distance,
+                                a->properties.distance);
+  pr->min.delay = GNUNET_TIME_relative_min(pr->min.delay,
+                                           a->properties.delay);
   return GNUNET_OK;
 }
 
@@ -139,13 +138,13 @@ find_min_max_it (void *cls,
  * @param ni normalization information to update
  */
 static void
-update_norm (uint64_t min,
-             uint64_t max,
-             struct GAS_NormalizationInfo *ni)
+update_norm(uint64_t min,
+            uint64_t max,
+            struct GAS_NormalizationInfo *ni)
 {
   /* max - 2 * min + avg_value / (max - min) */
   if (min < max)
-    ni->norm = DEFAULT_REL_QUALITY + (ni->avg - min) / (double) (max - min);
+    ni->norm = DEFAULT_REL_QUALITY + (ni->avg - min) / (double)(max - min);
   else
     ni->norm = DEFAULT_REL_QUALITY;
 }
@@ -163,24 +162,24 @@ update_norm (uint64_t min,
  * @return #GNUNET_OK (continue to iterate)
  */
 static int
-normalize_address (void *cls,
-		   const struct GNUNET_PeerIdentity *key,
-		   void *value)
+normalize_address(void *cls,
+                  const struct GNUNET_PeerIdentity *key,
+                  void *value)
 {
   struct ATS_Address *address = value;
 
-  update_norm (property_range.min.delay.rel_value_us,
-               property_range.max.delay.rel_value_us,
-               &address->norm_delay);
-  update_norm (property_range.min.distance,
-               property_range.max.distance,
-               &address->norm_distance);
-  update_norm (property_range.min.utilization_in,
-               property_range.max.utilization_in,
-               &address->norm_utilization_in);
-  update_norm (property_range.min.utilization_out,
-               property_range.max.utilization_out,
-               &address->norm_utilization_out);
+  update_norm(property_range.min.delay.rel_value_us,
+              property_range.max.delay.rel_value_us,
+              &address->norm_delay);
+  update_norm(property_range.min.distance,
+              property_range.max.distance,
+              &address->norm_distance);
+  update_norm(property_range.min.utilization_in,
+              property_range.max.utilization_in,
+              &address->norm_utilization_in);
+  update_norm(property_range.min.utilization_out,
+              property_range.max.utilization_out,
+              &address->norm_utilization_out);
   return GNUNET_OK;
 }
 
@@ -194,13 +193,13 @@ normalize_address (void *cls,
  * @return #GNUNET_OK (continue to iterate)
  */
 static int
-notify_change (void *cls,
-               const struct GNUNET_PeerIdentity *key,
-               void *value)
+notify_change(void *cls,
+              const struct GNUNET_PeerIdentity *key,
+              void *value)
 {
   struct ATS_Address *address = value;
 
-  GAS_plugin_notify_property_changed (address);
+  GAS_plugin_notify_property_changed(address);
   return GNUNET_OK;
 }
 
@@ -212,9 +211,9 @@ notify_change (void *cls,
  * @param pr range to initialize
  */
 static void
-init_range (struct PropertyRange *pr)
+init_range(struct PropertyRange *pr)
 {
-  memset (pr, 0, sizeof (struct PropertyRange));
+  memset(pr, 0, sizeof(struct PropertyRange));
   pr->min.utilization_out = UINT32_MAX;
   pr->min.utilization_in = UINT32_MAX;
   pr->min.distance = UINT32_MAX;
@@ -228,51 +227,51 @@ init_range (struct PropertyRange *pr)
  * @param address the address to update
  */
 void
-GAS_normalization_update_property (struct ATS_Address *address)
+GAS_normalization_update_property(struct ATS_Address *address)
 {
   const struct GNUNET_ATS_Properties *prop = &address->properties;
   struct PropertyRange range;
 
-  LOG (GNUNET_ERROR_TYPE_DEBUG,
-       "Updating properties for peer `%s'\n",
-       GNUNET_i2s (&address->peer));
-  GAS_plugin_solver_lock ();
-  update_avg (prop->delay.rel_value_us,
-              &address->norm_delay);
-  update_avg (prop->distance,
-              &address->norm_distance);
-  update_avg (prop->utilization_in,
-              &address->norm_utilization_in);
-  update_avg (prop->utilization_in,
-              &address->norm_utilization_out);
-
-  init_range (&range);
-  GNUNET_CONTAINER_multipeermap_iterate (GSA_addresses,
-                                         &find_min_max_it,
-                                         &range);
-  if (0 != GNUNET_memcmp (&range,
-                   &property_range))
-  {
-    /* limits changed, (re)normalize all addresses */
-    property_range = range;
-    GNUNET_CONTAINER_multipeermap_iterate (GSA_addresses,
-                                           &normalize_address,
-                                           NULL);
-    GNUNET_CONTAINER_multipeermap_iterate (GSA_addresses,
-                                           &notify_change,
-                                           NULL);
-  }
+  LOG(GNUNET_ERROR_TYPE_DEBUG,
+      "Updating properties for peer `%s'\n",
+      GNUNET_i2s(&address->peer));
+  GAS_plugin_solver_lock();
+  update_avg(prop->delay.rel_value_us,
+             &address->norm_delay);
+  update_avg(prop->distance,
+             &address->norm_distance);
+  update_avg(prop->utilization_in,
+             &address->norm_utilization_in);
+  update_avg(prop->utilization_in,
+             &address->norm_utilization_out);
+
+  init_range(&range);
+  GNUNET_CONTAINER_multipeermap_iterate(GSA_addresses,
+                                        &find_min_max_it,
+                                        &range);
+  if (0 != GNUNET_memcmp(&range,
+                         &property_range))
+    {
+      /* limits changed, (re)normalize all addresses */
+      property_range = range;
+      GNUNET_CONTAINER_multipeermap_iterate(GSA_addresses,
+                                            &normalize_address,
+                                            NULL);
+      GNUNET_CONTAINER_multipeermap_iterate(GSA_addresses,
+                                            &notify_change,
+                                            NULL);
+    }
   else
-  {
-    /* renormalize just this one address */
-    normalize_address (NULL,
-                       &address->peer,
-                       address);
-    notify_change (NULL,
-                   &address->peer,
-                   address);
-  }
-  GAS_plugin_solver_unlock ();
+    {
+      /* renormalize just this one address */
+      normalize_address(NULL,
+                        &address->peer,
+                        address);
+      notify_change(NULL,
+                    &address->peer,
+                    address);
+    }
+  GAS_plugin_solver_unlock();
 }
 
 
@@ -280,9 +279,9 @@ GAS_normalization_update_property (struct ATS_Address *address)
  * Start the normalization component
  */
 void
-GAS_normalization_start ()
+GAS_normalization_start()
 {
-  init_range (&property_range);
+  init_range(&property_range);
 }
 
 
@@ -290,7 +289,7 @@ GAS_normalization_start ()
  * Stop the normalization component and free all items
  */
 void
-GAS_normalization_stop ()
+GAS_normalization_stop()
 {
   /* nothing to do */
 }

+ 5 - 5
src/ats/gnunet-service-ats_normalization.h

@@ -11,12 +11,12 @@
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      Affero General Public License for more details.
-    
+
      You should have received a copy of the GNU Affero General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
-*/
+ */
 
 /**
  * @file ats/gnunet-service-ats_normalization.h
@@ -40,21 +40,21 @@
  * @param address the address to update
  */
 void
-GAS_normalization_update_property (struct ATS_Address *address);
+GAS_normalization_update_property(struct ATS_Address *address);
 
 
 /**
  * Start the normalization component
  */
 void
-GAS_normalization_start (void);
+GAS_normalization_start(void);
 
 
 /**
  * Stop the normalization component and free all items
  */
 void
-GAS_normalization_stop (void);
+GAS_normalization_stop(void);
 
 #endif
 /* end of gnunet-service-ats_normalization.h */

+ 115 - 115
src/ats/gnunet-service-ats_performance.c

@@ -11,12 +11,12 @@
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      Affero General Public License for more details.
-    
+
      You should have received a copy of the GNU Affero General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
-*/
+ */
 /**
  * @file ats/gnunet-service-ats_performance.c
  * @brief ats service, interaction with 'performance' API
@@ -63,64 +63,64 @@ static struct GNUNET_NotificationContext *nc_pic;
  * @param bandwidth_in assigned inbound bandwidth
  */
 static void
-notify_client (struct GNUNET_SERVICE_Client *client,
-               const struct GNUNET_PeerIdentity *peer,
-               const char *plugin_name,
-               const void *plugin_addr,
-               size_t plugin_addr_len,
-               int active,
-               const struct GNUNET_ATS_Properties *prop,
-               enum GNUNET_HELLO_AddressInfo local_address_info,
-               struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
-               struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
+notify_client(struct GNUNET_SERVICE_Client *client,
+              const struct GNUNET_PeerIdentity *peer,
+              const char *plugin_name,
+              const void *plugin_addr,
+              size_t plugin_addr_len,
+              int active,
+              const struct GNUNET_ATS_Properties *prop,
+              enum GNUNET_HELLO_AddressInfo local_address_info,
+              struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
+              struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
 {
   struct PeerInformationMessage *msg;
-  size_t plugin_name_length = strlen (plugin_name) + 1;
+  size_t plugin_name_length = strlen(plugin_name) + 1;
   size_t msize =
-    sizeof (struct PeerInformationMessage) +
+    sizeof(struct PeerInformationMessage) +
     plugin_addr_len +
     plugin_name_length;
   char buf[msize] GNUNET_ALIGN;
   char *addrp;
 
   if (NULL != prop)
-    GNUNET_break (GNUNET_NT_UNSPECIFIED != prop->scope);
-  GNUNET_assert (msize < GNUNET_MAX_MESSAGE_SIZE);
-  msg = (struct PeerInformationMessage *) buf;
-  msg->header.size = htons (msize);
-  msg->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_PEER_INFORMATION);
-  msg->id = htonl (0);
+    GNUNET_break(GNUNET_NT_UNSPECIFIED != prop->scope);
+  GNUNET_assert(msize < GNUNET_MAX_MESSAGE_SIZE);
+  msg = (struct PeerInformationMessage *)buf;
+  msg->header.size = htons(msize);
+  msg->header.type = htons(GNUNET_MESSAGE_TYPE_ATS_PEER_INFORMATION);
+  msg->id = htonl(0);
   msg->peer = *peer;
-  msg->address_length = htons (plugin_addr_len);
-  msg->address_active = ntohl ((uint32_t) active);
-  msg->plugin_name_length = htons (plugin_name_length);
+  msg->address_length = htons(plugin_addr_len);
+  msg->address_active = ntohl((uint32_t)active);
+  msg->plugin_name_length = htons(plugin_name_length);
   msg->bandwidth_out = bandwidth_out;
   msg->bandwidth_in = bandwidth_in;
   if (NULL != prop)
-    GNUNET_ATS_properties_hton (&msg->properties,
-                                prop);
+    GNUNET_ATS_properties_hton(&msg->properties,
+                               prop);
   else
-    memset (&msg->properties,
-            0,
-            sizeof (struct GNUNET_ATS_Properties));
-  msg->address_local_info = htonl (local_address_info);
-  addrp = (char *) &msg[1];
-  GNUNET_memcpy (addrp, plugin_addr, plugin_addr_len);
-  strcpy (&addrp[plugin_addr_len], plugin_name);
+    memset(&msg->properties,
+           0,
+           sizeof(struct GNUNET_ATS_Properties));
+  msg->address_local_info = htonl(local_address_info);
+  addrp = (char *)&msg[1];
+  GNUNET_memcpy(addrp, plugin_addr, plugin_addr_len);
+  strcpy(&addrp[plugin_addr_len], plugin_name);
   if (NULL == client)
-  {
-    GNUNET_notification_context_broadcast (nc_pic,
-					   &msg->header,
-					   GNUNET_YES);
-  }
+    {
+      GNUNET_notification_context_broadcast(nc_pic,
+                                            &msg->header,
+                                            GNUNET_YES);
+    }
   else
-  {
-    struct GNUNET_MQ_Envelope *env;
+    {
+      struct GNUNET_MQ_Envelope *env;
 
-    env = GNUNET_MQ_msg_copy (&msg->header);
-    GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
-		    env);
-  }
+      env = GNUNET_MQ_msg_copy(&msg->header);
+      GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client),
+                     env);
+    }
 }
 
 
@@ -142,32 +142,32 @@ notify_client (struct GNUNET_SERVICE_Client *client,
  * @param bandwidth_in assigned inbound bandwidth
  */
 void
-GAS_performance_notify_all_clients (const struct GNUNET_PeerIdentity *peer,
-                                    const char *plugin_name,
-                                    const void *plugin_addr,
-                                    size_t plugin_addr_len,
-                                    int active,
-                                    const struct GNUNET_ATS_Properties *prop,
-                                    enum GNUNET_HELLO_AddressInfo local_address_info,
-                                    struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
-                                    struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
+GAS_performance_notify_all_clients(const struct GNUNET_PeerIdentity *peer,
+                                   const char *plugin_name,
+                                   const void *plugin_addr,
+                                   size_t plugin_addr_len,
+                                   int active,
+                                   const struct GNUNET_ATS_Properties *prop,
+                                   enum GNUNET_HELLO_AddressInfo local_address_info,
+                                   struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
+                                   struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
 {
-  GNUNET_break ( (NULL == prop) ||
-                 (GNUNET_NT_UNSPECIFIED != prop->scope) );
-  notify_client (NULL,
-                 peer,
-                 plugin_name,
-                 plugin_addr,
-                 plugin_addr_len,
-                 active,
-                 prop,
-                 local_address_info,
-                 bandwidth_out,
-                 bandwidth_in);
-  GNUNET_STATISTICS_update (GSA_stats,
-                            "# performance updates given to clients",
-                            1,
-                            GNUNET_NO);
+  GNUNET_break((NULL == prop) ||
+               (GNUNET_NT_UNSPECIFIED != prop->scope));
+  notify_client(NULL,
+                peer,
+                plugin_name,
+                plugin_addr,
+                plugin_addr_len,
+                active,
+                prop,
+                local_address_info,
+                bandwidth_out,
+                bandwidth_in);
+  GNUNET_STATISTICS_update(GSA_stats,
+                           "# performance updates given to clients",
+                           1,
+                           GNUNET_NO);
 }
 
 
@@ -186,38 +186,38 @@ GAS_performance_notify_all_clients (const struct GNUNET_PeerIdentity *peer,
  * @param bandwidth_in current inbound bandwidth assigned to address
  */
 static void
-peerinfo_it (void *cls,
-             const struct GNUNET_PeerIdentity *id,
-             const char *plugin_name,
-             const void *plugin_addr,
-             size_t plugin_addr_len,
-             int active,
-             const struct GNUNET_ATS_Properties *prop,
-             enum GNUNET_HELLO_AddressInfo local_address_info,
-             struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
-             struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
+peerinfo_it(void *cls,
+            const struct GNUNET_PeerIdentity *id,
+            const char *plugin_name,
+            const void *plugin_addr,
+            size_t plugin_addr_len,
+            int active,
+            const struct GNUNET_ATS_Properties *prop,
+            enum GNUNET_HELLO_AddressInfo local_address_info,
+            struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
+            struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
 {
   struct GNUNET_SERVICE_Client *client = cls;
 
   if (NULL == id)
     return;
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Callback for peer `%s' plugin `%s' BW out %u, BW in %u \n",
-              GNUNET_i2s (id),
-              plugin_name,
-              (unsigned int) ntohl (bandwidth_out.value__),
-              (unsigned int) ntohl (bandwidth_in.value__));
-  GNUNET_break (GNUNET_NT_UNSPECIFIED != prop->scope);
-  notify_client (client,
-                 id,
-                 plugin_name,
-                 plugin_addr,
-                 plugin_addr_len,
-                 active,
-                 prop,
-                 local_address_info,
-                 bandwidth_out,
-                 bandwidth_in);
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+             "Callback for peer `%s' plugin `%s' BW out %u, BW in %u \n",
+             GNUNET_i2s(id),
+             plugin_name,
+             (unsigned int)ntohl(bandwidth_out.value__),
+             (unsigned int)ntohl(bandwidth_in.value__));
+  GNUNET_break(GNUNET_NT_UNSPECIFIED != prop->scope);
+  notify_client(client,
+                id,
+                plugin_name,
+                plugin_addr,
+                plugin_addr_len,
+                active,
+                prop,
+                local_address_info,
+                bandwidth_out,
+                bandwidth_in);
 }
 
 
@@ -228,25 +228,25 @@ peerinfo_it (void *cls,
  * @param flag flag specifying the type of the client
  */
 void
-GAS_performance_add_client (struct GNUNET_SERVICE_Client *client,
-                            enum StartFlag flag)
+GAS_performance_add_client(struct GNUNET_SERVICE_Client *client,
+                           enum StartFlag flag)
 {
   struct GNUNET_MQ_Handle *mq;
 
-  mq = GNUNET_SERVICE_client_get_mq (client);
+  mq = GNUNET_SERVICE_client_get_mq(client);
   if (START_FLAG_PERFORMANCE_WITH_PIC == flag)
-  {
-    GNUNET_notification_context_add (nc_pic,
-				     mq);
-    GAS_addresses_get_peer_info (NULL,
-                                 &peerinfo_it,
-                                 client);
-  }
+    {
+      GNUNET_notification_context_add(nc_pic,
+                                      mq);
+      GAS_addresses_get_peer_info(NULL,
+                                  &peerinfo_it,
+                                  client);
+    }
   else
-  {
-    GNUNET_notification_context_add (nc_no_pic,
-				     mq);
-  }
+    {
+      GNUNET_notification_context_add(nc_no_pic,
+                                      mq);
+    }
 }
 
 
@@ -256,10 +256,10 @@ GAS_performance_add_client (struct GNUNET_SERVICE_Client *client,
  * @param server handle to our server
  */
 void
-GAS_performance_init ()
+GAS_performance_init()
 {
-  nc_no_pic = GNUNET_notification_context_create (32);
-  nc_pic = GNUNET_notification_context_create (32);
+  nc_no_pic = GNUNET_notification_context_create(32);
+  nc_pic = GNUNET_notification_context_create(32);
 }
 
 
@@ -267,11 +267,11 @@ GAS_performance_init ()
  * Shutdown performance subsystem.
  */
 void
-GAS_performance_done ()
+GAS_performance_done()
 {
-  GNUNET_notification_context_destroy (nc_no_pic);
+  GNUNET_notification_context_destroy(nc_no_pic);
   nc_no_pic = NULL;
-  GNUNET_notification_context_destroy (nc_pic);
+  GNUNET_notification_context_destroy(nc_pic);
   nc_pic = NULL;
 }
 

+ 15 - 15
src/ats/gnunet-service-ats_performance.h

@@ -11,12 +11,12 @@
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      Affero General Public License for more details.
-    
+
      You should have received a copy of the GNU Affero General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
-*/
+ */
 
 /**
  * @file ats/gnunet-service-ats_performance.h
@@ -50,15 +50,15 @@
  * @param bandwidth_in assigned inbound bandwidth
  */
 void
-GAS_performance_notify_all_clients (const struct GNUNET_PeerIdentity *peer,
-                                    const char *plugin_name,
-                                    const void *plugin_addr,
-                                    size_t plugin_addr_len,
-                                    int active,
-                                    const struct GNUNET_ATS_Properties *prop,
-                                    enum GNUNET_HELLO_AddressInfo local_address_info,
-                                    struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
-                                    struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in);
+GAS_performance_notify_all_clients(const struct GNUNET_PeerIdentity *peer,
+                                   const char *plugin_name,
+                                   const void *plugin_addr,
+                                   size_t plugin_addr_len,
+                                   int active,
+                                   const struct GNUNET_ATS_Properties *prop,
+                                   enum GNUNET_HELLO_AddressInfo local_address_info,
+                                   struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
+                                   struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in);
 
 
 /**
@@ -68,8 +68,8 @@ GAS_performance_notify_all_clients (const struct GNUNET_PeerIdentity *peer,
  * @param flag flag specifying the type of the client
  */
 void
-GAS_performance_add_client (struct GNUNET_SERVICE_Client *client,
-                            enum StartFlag flag);
+GAS_performance_add_client(struct GNUNET_SERVICE_Client *client,
+                           enum StartFlag flag);
 
 
 /**
@@ -79,14 +79,14 @@ GAS_performance_add_client (struct GNUNET_SERVICE_Client *client,
  * @param addresses the address handle to use
  */
 void
-GAS_performance_init (void);
+GAS_performance_init(void);
 
 
 /**
  * Shutdown performance subsystem.
  */
 void
-GAS_performance_done (void);
+GAS_performance_done(void);
 
 
 #endif

+ 295 - 279
src/ats/gnunet-service-ats_plugins.c

@@ -1,19 +1,19 @@
 /*
- This file is part of GNUnet.
- Copyright (C) 2011-2014 GNUnet e.V.
+   This file is part of GNUnet.
+   Copyright (C) 2011-2014 GNUnet e.V.
 
- GNUnet is free software: you can redistribute it and/or modify it
- under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License,
- or (at your option) any later version.
+   GNUnet is free software: you can redistribute it and/or modify it
+   under the terms of the GNU Affero General Public License as published
+   by the Free Software Foundation, either version 3 of the License,
+   or (at your option) any later version.
 
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- Affero General Public License for more details.
+   GNUnet is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Affero General Public License for more details.
 
- You should have received a copy of the GNU Affero General Public License
- along with this program.  If not, see <http://www.gnu.org/licenses/>.
+   You should have received a copy of the GNU Affero General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
  */
@@ -59,14 +59,14 @@ static char *plugin;
  * @param pref_rel the new relative preference value
  */
 void
-GAS_plugin_notify_preference_changed (const struct GNUNET_PeerIdentity *peer,
-                                      enum GNUNET_ATS_PreferenceKind kind,
-                                      double pref_rel)
+GAS_plugin_notify_preference_changed(const struct GNUNET_PeerIdentity *peer,
+                                     enum GNUNET_ATS_PreferenceKind kind,
+                                     double pref_rel)
 {
-  sf->s_pref (sf->cls,
-              peer,
-              kind,
-              pref_rel);
+  sf->s_pref(sf->cls,
+             peer,
+             kind,
+             pref_rel);
 }
 
 
@@ -76,10 +76,10 @@ GAS_plugin_notify_preference_changed (const struct GNUNET_PeerIdentity *peer,
  * @param address the peer for which a property changed
  */
 void
-GAS_plugin_notify_property_changed (struct ATS_Address *address)
+GAS_plugin_notify_property_changed(struct ATS_Address *address)
 {
-  sf->s_address_update_property (sf->cls,
-                                 address);
+  sf->s_address_update_property(sf->cls,
+                                address);
 }
 
 
@@ -92,100 +92,116 @@ GAS_plugin_notify_property_changed (struct ATS_Address *address)
  * @param add additional information
  */
 static void
-solver_info_cb (void *cls,
-		enum GAS_Solver_Operation op,
-		enum GAS_Solver_Status status,
-		enum GAS_Solver_Additional_Information add)
+solver_info_cb(void *cls,
+               enum GAS_Solver_Operation op,
+               enum GAS_Solver_Status status,
+               enum GAS_Solver_Additional_Information add)
 {
   const char *add_info;
 
-  switch (add) {
+  switch (add)
+    {
     case GAS_INFO_NONE:
       add_info = "GAS_INFO_NONE";
       break;
+
     case GAS_INFO_FULL:
       add_info = "GAS_INFO_MLP_FULL";
       break;
+
     case GAS_INFO_UPDATED:
       add_info = "GAS_INFO_MLP_UPDATED";
       break;
+
     case GAS_INFO_PROP_ALL:
       add_info = "GAS_INFO_PROP_ALL";
       break;
+
     case GAS_INFO_PROP_SINGLE:
       add_info = "GAS_INFO_PROP_SINGLE";
       break;
+
     default:
       add_info = "INVALID";
       break;
-  }
+    }
   switch (op)
-  {
-  case GAS_OP_SOLVE_START:
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "Solver notifies `%s' with result `%s' `%s'\n",
-                "GAS_OP_SOLVE_START",
-                (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL",
-                add_info);
-    return;
-  case GAS_OP_SOLVE_STOP:
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "Solver notifies `%s' with result `%s'\n",
-                "GAS_OP_SOLVE_STOP",
-                (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL");
-    return;
-  case GAS_OP_SOLVE_SETUP_START:
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "Solver notifies `%s' with result `%s'\n",
-                "GAS_OP_SOLVE_SETUP_START",
-                (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL");
-    return;
-  case GAS_OP_SOLVE_SETUP_STOP:
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "Solver notifies `%s' with result `%s'\n",
-                "GAS_OP_SOLVE_SETUP_STOP",
-                (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL");
-    return;
-  case GAS_OP_SOLVE_MLP_LP_START:
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "Solver notifies `%s' with result `%s'\n",
-                "GAS_OP_SOLVE_LP_START",
-                (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL");
-    return;
-  case GAS_OP_SOLVE_MLP_LP_STOP:
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "Solver notifies `%s' with result `%s'\n",
-                "GAS_OP_SOLVE_LP_STOP",
-                (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL");
-    return;
-  case GAS_OP_SOLVE_MLP_MLP_START:
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "Solver notifies `%s' with result `%s'\n",
-                "GAS_OP_SOLVE_MLP_START",
-                (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL");
-    return;
-  case GAS_OP_SOLVE_MLP_MLP_STOP:
-    GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
-               "Solver notifies `%s' with result `%s'\n",
-               "GAS_OP_SOLVE_MLP_STOP",
-               (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL");
-    return;
-  case GAS_OP_SOLVE_UPDATE_NOTIFICATION_START:
-    GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
-               "Solver notifies `%s' with result `%s'\n",
-               "GAS_OP_SOLVE_UPDATE_NOTIFICATION_START",
-               (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL");
-    return;
-  case GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP:
-    GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
-               "Solver notifies `%s' with result `%s'\n",
-               "GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP",
-               (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL");
-    return;
-  default:
-    GNUNET_break (0);
-    break;
-  }
+    {
+    case GAS_OP_SOLVE_START:
+      GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+                 "Solver notifies `%s' with result `%s' `%s'\n",
+                 "GAS_OP_SOLVE_START",
+                 (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL",
+                 add_info);
+      return;
+
+    case GAS_OP_SOLVE_STOP:
+      GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+                 "Solver notifies `%s' with result `%s'\n",
+                 "GAS_OP_SOLVE_STOP",
+                 (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL");
+      return;
+
+    case GAS_OP_SOLVE_SETUP_START:
+      GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+                 "Solver notifies `%s' with result `%s'\n",
+                 "GAS_OP_SOLVE_SETUP_START",
+                 (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL");
+      return;
+
+    case GAS_OP_SOLVE_SETUP_STOP:
+      GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+                 "Solver notifies `%s' with result `%s'\n",
+                 "GAS_OP_SOLVE_SETUP_STOP",
+                 (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL");
+      return;
+
+    case GAS_OP_SOLVE_MLP_LP_START:
+      GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+                 "Solver notifies `%s' with result `%s'\n",
+                 "GAS_OP_SOLVE_LP_START",
+                 (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL");
+      return;
+
+    case GAS_OP_SOLVE_MLP_LP_STOP:
+      GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+                 "Solver notifies `%s' with result `%s'\n",
+                 "GAS_OP_SOLVE_LP_STOP",
+                 (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL");
+      return;
+
+    case GAS_OP_SOLVE_MLP_MLP_START:
+      GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+                 "Solver notifies `%s' with result `%s'\n",
+                 "GAS_OP_SOLVE_MLP_START",
+                 (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL");
+      return;
+
+    case GAS_OP_SOLVE_MLP_MLP_STOP:
+      GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+                 "Solver notifies `%s' with result `%s'\n",
+                 "GAS_OP_SOLVE_MLP_STOP",
+                 (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL");
+      return;
+
+    case GAS_OP_SOLVE_UPDATE_NOTIFICATION_START:
+      GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+                 "Solver notifies `%s' with result `%s'\n",
+                 "GAS_OP_SOLVE_UPDATE_NOTIFICATION_START",
+                 (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL");
+      return;
+
+    case GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP:
+      GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+                 "Solver notifies `%s' with result `%s'\n",
+                 "GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP",
+                 (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL");
+      return;
+
+    default:
+      GNUNET_break(0);
+      break;
+    }
 }
 
 
@@ -196,69 +212,69 @@ solver_info_cb (void *cls,
  * @param address the address with changes
  */
 static void
-bandwidth_changed_cb (void *cls,
-		      struct ATS_Address *address)
+bandwidth_changed_cb(void *cls,
+                     struct ATS_Address *address)
 {
   long long diff_out;
   long long diff_in;
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Bandwidth assignment changed for peer %s to %u/%u\n",
-              GNUNET_i2s (&address->peer),
-              (unsigned int) address->assigned_bw_in,
-              (unsigned int) address->assigned_bw_out);
-  GAS_reservations_set_bandwidth (&address->peer,
-                                  GNUNET_BANDWIDTH_value_init (address->assigned_bw_in));
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+             "Bandwidth assignment changed for peer %s to %u/%u\n",
+             GNUNET_i2s(&address->peer),
+             (unsigned int)address->assigned_bw_in,
+             (unsigned int)address->assigned_bw_out);
+  GAS_reservations_set_bandwidth(&address->peer,
+                                 GNUNET_BANDWIDTH_value_init(address->assigned_bw_in));
   /* Notify performance clients about changes to address */
-  GAS_performance_notify_all_clients (&address->peer,
-				      address->plugin,
-				      address->addr,
-				      address->addr_len,
-				      address->active,
-				      &address->properties,
-                                      address->local_address_info,
-				      GNUNET_BANDWIDTH_value_init (address->assigned_bw_out),
-				      GNUNET_BANDWIDTH_value_init (address->assigned_bw_in));
-
-  if ( (0 == address->assigned_bw_in) &&
-       (0 == address->assigned_bw_out) )
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-               "Telling transport to disconnect peer `%s'\n",
-                GNUNET_i2s (&address->peer));
-
-    /* Notify scheduling clients about suggestion */
-    GAS_scheduling_transmit_address_suggestion (&address->peer,
-                                                address->session_id,
-                                                GNUNET_BANDWIDTH_ZERO,
-                                                GNUNET_BANDWIDTH_ZERO);
-    return;
-  }
+  GAS_performance_notify_all_clients(&address->peer,
+                                     address->plugin,
+                                     address->addr,
+                                     address->addr_len,
+                                     address->active,
+                                     &address->properties,
+                                     address->local_address_info,
+                                     GNUNET_BANDWIDTH_value_init(address->assigned_bw_out),
+                                     GNUNET_BANDWIDTH_value_init(address->assigned_bw_in));
+
+  if ((0 == address->assigned_bw_in) &&
+      (0 == address->assigned_bw_out))
+    {
+      GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+                 "Telling transport to disconnect peer `%s'\n",
+                 GNUNET_i2s(&address->peer));
+
+      /* Notify scheduling clients about suggestion */
+      GAS_scheduling_transmit_address_suggestion(&address->peer,
+                                                 address->session_id,
+                                                 GNUNET_BANDWIDTH_ZERO,
+                                                 GNUNET_BANDWIDTH_ZERO);
+      return;
+    }
 
   /* Do bandwidth stability check */
-  diff_out = llabs ((long long) address->assigned_bw_out -
-                    (long long) address->last_notified_bw_out);
-  diff_in = llabs ((long long) address->assigned_bw_in -
-                   (long long) address->last_notified_bw_in);
-  if ( (diff_out < htonl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__)) &&
-       (diff_in < htonl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__)) )
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "Bandwidth change too small, not notifying client\n");
-    return;
-  }
-
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Sending bandwidth update for peer `%s': %u/%u\n",
-              GNUNET_i2s (&address->peer),
-              address->assigned_bw_out,
-              address->assigned_bw_out);
+  diff_out = llabs((long long)address->assigned_bw_out -
+                   (long long)address->last_notified_bw_out);
+  diff_in = llabs((long long)address->assigned_bw_in -
+                  (long long)address->last_notified_bw_in);
+  if ((diff_out < htonl(GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__)) &&
+      (diff_in < htonl(GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__)))
+    {
+      GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+                 "Bandwidth change too small, not notifying client\n");
+      return;
+    }
+
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+             "Sending bandwidth update for peer `%s': %u/%u\n",
+             GNUNET_i2s(&address->peer),
+             address->assigned_bw_out,
+             address->assigned_bw_out);
 
   /* *Notify scheduling clients about suggestion */
-  GAS_scheduling_transmit_address_suggestion (&address->peer,
-                                              address->session_id,
-                                              GNUNET_BANDWIDTH_value_init (address->assigned_bw_out),
-                                              GNUNET_BANDWIDTH_value_init (address->assigned_bw_in));
+  GAS_scheduling_transmit_address_suggestion(&address->peer,
+                                             address->session_id,
+                                             GNUNET_BANDWIDTH_value_init(address->assigned_bw_out),
+                                             GNUNET_BANDWIDTH_value_init(address->assigned_bw_in));
 
   address->last_notified_bw_out = address->assigned_bw_out;
   address->last_notified_bw_in = address->assigned_bw_in;
@@ -274,48 +290,48 @@ bandwidth_changed_cb (void *cls,
  * @return numeric quota value to use
  */
 static unsigned long long
-parse_quota (const char *quota_str,
-             const char *direction,
-             enum GNUNET_NetworkType network)
+parse_quota(const char *quota_str,
+            const char *direction,
+            enum GNUNET_NetworkType network)
 {
   int res;
   unsigned long long ret;
 
   res = GNUNET_NO;
-  if (0 == strcmp (quota_str, GNUNET_ATS_MaxBandwidthString))
-  {
-    ret = GNUNET_ATS_MaxBandwidth;
-    res = GNUNET_YES;
-  }
+  if (0 == strcmp(quota_str, GNUNET_ATS_MaxBandwidthString))
+    {
+      ret = GNUNET_ATS_MaxBandwidth;
+      res = GNUNET_YES;
+    }
   if ((GNUNET_NO == res) &&
       (GNUNET_OK ==
-       GNUNET_STRINGS_fancy_size_to_bytes (quota_str,
-                                           &ret)))
+       GNUNET_STRINGS_fancy_size_to_bytes(quota_str,
+                                          &ret)))
     res = GNUNET_YES;
   if ((GNUNET_NO == res) &&
       (1 ==
-       sscanf (quota_str,
-               "%llu",
-               &ret)))
+       sscanf(quota_str,
+              "%llu",
+              &ret)))
     res = GNUNET_YES;
   if (GNUNET_NO == res)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                _("Could not load %s quota for network `%s':  `%s', assigning default bandwidth %llu\n"),
-                direction,
-                GNUNET_NT_to_string (network),
-                quota_str,
-                (unsigned long long) GNUNET_ATS_DefaultBandwidth);
-    ret = GNUNET_ATS_DefaultBandwidth;
-  }
+    {
+      GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
+                 _("Could not load %s quota for network `%s':  `%s', assigning default bandwidth %llu\n"),
+                 direction,
+                 GNUNET_NT_to_string(network),
+                 quota_str,
+                 (unsigned long long)GNUNET_ATS_DefaultBandwidth);
+      ret = GNUNET_ATS_DefaultBandwidth;
+    }
   else
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-                _("%s quota configured for network `%s' is %llu\n"),
-                direction,
-                GNUNET_NT_to_string (network),
-                ret);
-  }
+    {
+      GNUNET_log(GNUNET_ERROR_TYPE_INFO,
+                 _("%s quota configured for network `%s' is %llu\n"),
+                 direction,
+                 GNUNET_NT_to_string(network),
+                 ret);
+    }
   return ret;
 }
 
@@ -330,39 +346,39 @@ parse_quota (const char *quota_str,
  * @return quota to apply
  */
 static unsigned long long
-load_quota (const struct GNUNET_CONFIGURATION_Handle *cfg,
-            enum GNUNET_NetworkType type,
-            const char *direction)
+load_quota(const struct GNUNET_CONFIGURATION_Handle *cfg,
+           enum GNUNET_NetworkType type,
+           const char *direction)
 {
   char *entry;
   char *quota_str;
   unsigned long long ret;
 
-  GNUNET_asprintf (&entry,
-                   "%s_QUOTA_%s",
-                   GNUNET_NT_to_string (type),
-                   direction);
+  GNUNET_asprintf(&entry,
+                  "%s_QUOTA_%s",
+                  GNUNET_NT_to_string(type),
+                  direction);
   if (GNUNET_OK ==
-      GNUNET_CONFIGURATION_get_value_string (cfg,
-                                             "ats",
-                                             entry,
-                                             &quota_str))
-  {
-    ret = parse_quota (quota_str,
-                       direction,
-                       type);
-    GNUNET_free (quota_str);
-  }
+      GNUNET_CONFIGURATION_get_value_string(cfg,
+                                            "ats",
+                                            entry,
+                                            &quota_str))
+    {
+      ret = parse_quota(quota_str,
+                        direction,
+                        type);
+      GNUNET_free(quota_str);
+    }
   else
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                _("No %s-quota configured for network `%s', assigning default bandwidth %llu\n"),
-                direction,
-                GNUNET_NT_to_string (type),
-                (unsigned long long) GNUNET_ATS_DefaultBandwidth);
-    ret = GNUNET_ATS_DefaultBandwidth;
-  }
-  GNUNET_free (entry);
+    {
+      GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
+                 _("No %s-quota configured for network `%s', assigning default bandwidth %llu\n"),
+                 direction,
+                 GNUNET_NT_to_string(type),
+                 (unsigned long long)GNUNET_ATS_DefaultBandwidth);
+      ret = GNUNET_ATS_DefaultBandwidth;
+    }
+  GNUNET_free(entry);
   return ret;
 }
 
@@ -377,27 +393,27 @@ load_quota (const struct GNUNET_CONFIGURATION_Handle *cfg,
  * @return number of networks loaded
  */
 static unsigned int
-load_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg,
-             unsigned long long *out_dest,
-             unsigned long long *in_dest,
-             int dest_length)
+load_quotas(const struct GNUNET_CONFIGURATION_Handle *cfg,
+            unsigned long long *out_dest,
+            unsigned long long *in_dest,
+            int dest_length)
 {
   unsigned int c;
 
   for (c = 0; (c < GNUNET_NT_COUNT) && (c < dest_length); c++)
-  {
-    in_dest[c] = load_quota (cfg,
-                             c,
-                             "out");
-    out_dest[c] = load_quota (cfg,
+    {
+      in_dest[c] = load_quota(cfg,
                               c,
-                              "in");
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "Loaded quota for network `%s' (in/out): %llu %llu\n",
-                GNUNET_NT_to_string (c),
-                in_dest[c],
-                out_dest[c]);
-  }
+                              "out");
+      out_dest[c] = load_quota(cfg,
+                               c,
+                               "in");
+      GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+                 "Loaded quota for network `%s' (in/out): %llu %llu\n",
+                 GNUNET_NT_to_string(c),
+                 in_dest[c],
+                 out_dest[c]);
+    }
   return c;
 }
 
@@ -410,21 +426,21 @@ load_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg,
  *         solver plugin)
  */
 int
-GAS_plugin_init (const struct GNUNET_CONFIGURATION_Handle *cfg)
+GAS_plugin_init(const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
   char *mode_str;
 
   /* Figure out configured solution method */
   if (GNUNET_SYSERR ==
-      GNUNET_CONFIGURATION_get_value_string (cfg,
-                                             "ats",
-                                             "MODE",
-                                             &mode_str))
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                "No resource assignment method configured, using proportional approach\n");
-    mode_str = GNUNET_strdup ("proportional");
-  }
+      GNUNET_CONFIGURATION_get_value_string(cfg,
+                                            "ats",
+                                            "MODE",
+                                            &mode_str))
+    {
+      GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
+                 "No resource assignment method configured, using proportional approach\n");
+      mode_str = GNUNET_strdup("proportional");
+    }
   env.cls = NULL;
   env.info_cb = &solver_info_cb;
   env.bandwidth_changed_cb = &bandwidth_changed_cb;
@@ -434,24 +450,24 @@ GAS_plugin_init (const struct GNUNET_CONFIGURATION_Handle *cfg)
   env.stats = GSA_stats;
   env.addresses = GSA_addresses;
   env.network_count = GNUNET_NT_COUNT;
-  load_quotas (cfg,
-               env.out_quota,
-               env.in_quota,
-               GNUNET_NT_COUNT);
-  GNUNET_asprintf (&plugin,
-                   "libgnunet_plugin_ats_%s",
-                   mode_str);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Initializing solver `%s'\n",
-              mode_str);
-  GNUNET_free (mode_str);
-  if (NULL == (sf = GNUNET_PLUGIN_load (plugin, &env)))
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                _("Failed to initialize solver `%s'!\n"),
-                plugin);
-    return GNUNET_SYSERR;
-  }
+  load_quotas(cfg,
+              env.out_quota,
+              env.in_quota,
+              GNUNET_NT_COUNT);
+  GNUNET_asprintf(&plugin,
+                  "libgnunet_plugin_ats_%s",
+                  mode_str);
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+             "Initializing solver `%s'\n",
+             mode_str);
+  GNUNET_free(mode_str);
+  if (NULL == (sf = GNUNET_PLUGIN_load(plugin, &env)))
+    {
+      GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
+                 _("Failed to initialize solver `%s'!\n"),
+                 plugin);
+      return GNUNET_SYSERR;
+    }
   return GNUNET_OK;
 }
 
@@ -460,12 +476,12 @@ GAS_plugin_init (const struct GNUNET_CONFIGURATION_Handle *cfg)
  * Shutdown address subsystem.
  */
 void
-GAS_plugin_done ()
+GAS_plugin_done()
 {
-  GNUNET_PLUGIN_unload (plugin,
-                        sf);
+  GNUNET_PLUGIN_unload(plugin,
+                       sf);
   sf = NULL;
-  GNUNET_free (plugin);
+  GNUNET_free(plugin);
   plugin = NULL;
 }
 
@@ -477,11 +493,11 @@ GAS_plugin_done ()
  * @param new_address the new address
  */
 void
-GAS_plugin_new_address (struct ATS_Address *new_address)
+GAS_plugin_new_address(struct ATS_Address *new_address)
 {
-  sf->s_add (sf->cls,
-             new_address,
-             new_address->properties.scope); /* FIXME: remove 3rd arg here! */
+  sf->s_add(sf->cls,
+            new_address,
+            new_address->properties.scope);  /* FIXME: remove 3rd arg here! */
 }
 
 
@@ -492,10 +508,10 @@ GAS_plugin_new_address (struct ATS_Address *new_address)
  * @param address address that was deleted
  */
 void
-GAS_plugin_delete_address (struct ATS_Address *address)
+GAS_plugin_delete_address(struct ATS_Address *address)
 {
-  sf->s_del (sf->cls,
-             address);
+  sf->s_del(sf->cls,
+            address);
 }
 
 
@@ -510,18 +526,18 @@ GAS_plugin_delete_address (struct ATS_Address *address)
  * @param score_abs degree of the appreciation
  */
 void
-GAS_plugin_notify_feedback (struct GNUNET_SERVICE_Client *application,
-                            const struct GNUNET_PeerIdentity *peer,
-                            const struct GNUNET_TIME_Relative scope,
-                            enum GNUNET_ATS_PreferenceKind kind,
-                            float score_abs)
+GAS_plugin_notify_feedback(struct GNUNET_SERVICE_Client *application,
+                           const struct GNUNET_PeerIdentity *peer,
+                           const struct GNUNET_TIME_Relative scope,
+                           enum GNUNET_ATS_PreferenceKind kind,
+                           float score_abs)
 {
-  sf->s_feedback (sf->cls,
-                  application,
-                  peer,
-                  scope,
-                  kind,
-                  score_abs);
+  sf->s_feedback(sf->cls,
+                 application,
+                 peer,
+                 scope,
+                 kind,
+                 score_abs);
 }
 
 
@@ -530,9 +546,9 @@ GAS_plugin_notify_feedback (struct GNUNET_SERVICE_Client *application,
  * happening in bulk right now.
  */
 void
-GAS_plugin_solver_lock ()
+GAS_plugin_solver_lock()
 {
-  sf->s_bulk_start (sf->cls);
+  sf->s_bulk_start(sf->cls);
 }
 
 
@@ -540,9 +556,9 @@ GAS_plugin_solver_lock ()
  * Resume instant solving, we are done with the bulk state updates.
  */
 void
-GAS_plugin_solver_unlock ()
+GAS_plugin_solver_unlock()
 {
-  sf->s_bulk_stop (sf->cls);
+  sf->s_bulk_stop(sf->cls);
 }
 
 
@@ -553,10 +569,10 @@ GAS_plugin_solver_unlock ()
  * @param pid identity of peer we now care about
  */
 void
-GAS_plugin_request_connect_start (const struct GNUNET_PeerIdentity *pid)
+GAS_plugin_request_connect_start(const struct GNUNET_PeerIdentity *pid)
 {
-  sf->s_get (sf->cls,
-             pid);
+  sf->s_get(sf->cls,
+            pid);
 }
 
 
@@ -567,10 +583,10 @@ GAS_plugin_request_connect_start (const struct GNUNET_PeerIdentity *pid)
  * @param pid identity of peer we care now less about
  */
 void
-GAS_plugin_request_connect_stop (const struct GNUNET_PeerIdentity *pid)
+GAS_plugin_request_connect_stop(const struct GNUNET_PeerIdentity *pid)
 {
-  sf->s_get_stop (sf->cls,
-                  pid);
+  sf->s_get_stop(sf->cls,
+                 pid);
 }
 
 

+ 29 - 29
src/ats/gnunet-service-ats_plugins.h

@@ -1,19 +1,19 @@
 /*
- This file is part of GNUnet.
- Copyright (C) 2011-2014 GNUnet e.V.
+   This file is part of GNUnet.
+   Copyright (C) 2011-2014 GNUnet e.V.
 
- GNUnet is free software: you can redistribute it and/or modify it
- under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License,
- or (at your option) any later version.
+   GNUnet is free software: you can redistribute it and/or modify it
+   under the terms of the GNU Affero General Public License as published
+   by the Free Software Foundation, either version 3 of the License,
+   or (at your option) any later version.
 
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- Affero General Public License for more details.
+   GNUnet is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Affero General Public License for more details.
 
- You should have received a copy of the GNU Affero General Public License
- along with this program.  If not, see <http://www.gnu.org/licenses/>.
+   You should have received a copy of the GNU Affero General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
  */
@@ -41,14 +41,14 @@
  *         solver plugin)
  */
 int
-GAS_plugin_init (const struct GNUNET_CONFIGURATION_Handle *cfg);
+GAS_plugin_init(const struct GNUNET_CONFIGURATION_Handle *cfg);
 
 
 /**
  * Shutdown address subsystem.
  */
 void
-GAS_plugin_done (void);
+GAS_plugin_done(void);
 
 
 /**
@@ -59,9 +59,9 @@ GAS_plugin_done (void);
  * @param pref_rel the new relative preference value
  */
 void
-GAS_plugin_notify_preference_changed (const struct GNUNET_PeerIdentity *peer,
-                                      enum GNUNET_ATS_PreferenceKind kind,
-                                      double pref_rel);
+GAS_plugin_notify_preference_changed(const struct GNUNET_PeerIdentity *peer,
+                                     enum GNUNET_ATS_PreferenceKind kind,
+                                     double pref_rel);
 
 
 /**
@@ -70,7 +70,7 @@ GAS_plugin_notify_preference_changed (const struct GNUNET_PeerIdentity *peer,
  * @param address the peer
  */
 void
-GAS_plugin_notify_property_changed (struct ATS_Address *address);
+GAS_plugin_notify_property_changed(struct ATS_Address *address);
 
 
 /**
@@ -81,7 +81,7 @@ GAS_plugin_notify_property_changed (struct ATS_Address *address);
  * @param addr_net network scope the address is in
  */
 void
-GAS_plugin_new_address (struct ATS_Address *new_address);
+GAS_plugin_new_address(struct ATS_Address *new_address);
 
 
 /**
@@ -91,7 +91,7 @@ GAS_plugin_new_address (struct ATS_Address *new_address);
  * @param address address that was deleted
  */
 void
-GAS_plugin_delete_address (struct ATS_Address *address);
+GAS_plugin_delete_address(struct ATS_Address *address);
 
 
 /**
@@ -105,11 +105,11 @@ GAS_plugin_delete_address (struct ATS_Address *address);
  * @param score_abs degree of the appreciation
  */
 void
-GAS_plugin_notify_feedback (struct GNUNET_SERVICE_Client *application,
-                            const struct GNUNET_PeerIdentity *peer,
-                            const struct GNUNET_TIME_Relative scope,
-                            enum GNUNET_ATS_PreferenceKind kind,
-                            float score_abs);
+GAS_plugin_notify_feedback(struct GNUNET_SERVICE_Client *application,
+                           const struct GNUNET_PeerIdentity *peer,
+                           const struct GNUNET_TIME_Relative scope,
+                           enum GNUNET_ATS_PreferenceKind kind,
+                           float score_abs);
 
 
 /**
@@ -117,14 +117,14 @@ GAS_plugin_notify_feedback (struct GNUNET_SERVICE_Client *application,
  * happening in bulk right now.
  */
 void
-GAS_plugin_solver_lock (void);
+GAS_plugin_solver_lock(void);
 
 
 /**
  * Resume instant solving, we are done with the bulk state updates.
  */
 void
-GAS_plugin_solver_unlock (void);
+GAS_plugin_solver_unlock(void);
 
 
 /**
@@ -134,7 +134,7 @@ GAS_plugin_solver_unlock (void);
  * @param pid identity of peer we now care about
  */
 void
-GAS_plugin_request_connect_start (const struct GNUNET_PeerIdentity *pid);
+GAS_plugin_request_connect_start(const struct GNUNET_PeerIdentity *pid);
 
 
 /**
@@ -144,7 +144,7 @@ GAS_plugin_request_connect_start (const struct GNUNET_PeerIdentity *pid);
  * @param pid identity of peer we care now less about
  */
 void
-GAS_plugin_request_connect_stop (const struct GNUNET_PeerIdentity *pid);
+GAS_plugin_request_connect_stop(const struct GNUNET_PeerIdentity *pid);
 
 
 #endif

+ 242 - 254
src/ats/gnunet-service-ats_preferences.c

@@ -11,12 +11,12 @@
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      Affero General Public License for more details.
-    
+
      You should have received a copy of the GNU Affero General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
-*/
+ */
 /**
  * @file ats/gnunet-service-ats_preferences.c
  * @brief manage preferences expressed by clients
@@ -32,12 +32,12 @@
 #include "gnunet-service-ats_reservations.h"
 #include "ats.h"
 
-#define LOG(kind,...) GNUNET_log_from (kind, "ats-preferences",__VA_ARGS__)
+#define LOG(kind, ...) GNUNET_log_from(kind, "ats-preferences", __VA_ARGS__)
 
 /**
  * How frequently do we age preference values?
  */
-#define PREF_AGING_INTERVAL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
+#define PREF_AGING_INTERVAL GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10)
 
 /**
  * By which factor do we age preferences expressed during
@@ -56,8 +56,7 @@
 /**
  * Relative preferences for a peer.
  */
-struct PeerRelative
-{
+struct PeerRelative {
   /**
    * Array of relative preference values, to be indexed by
    * an `enum GNUNET_ATS_PreferenceKind`.
@@ -83,8 +82,7 @@ static struct PeerRelative defvalues;
 /**
  * Preference information per peer and client.
  */
-struct PreferencePeer
-{
+struct PreferencePeer {
   /**
    * Next in DLL of preference entries for the same client.
    */
@@ -107,7 +105,6 @@ struct PreferencePeer
    * client scored other peers.
    */
   double f_rel[GNUNET_ATS_PREFERENCE_END];
-
 };
 
 
@@ -116,9 +113,7 @@ struct PreferencePeer
  * for peers.  This is the information we keep track of for each
  * such client.
  */
-struct PreferenceClient
-{
-
+struct PreferenceClient {
   /**
    * Next in client list
    */
@@ -145,7 +140,6 @@ struct PreferenceClient
    * peers as expressed by this client.
    */
   double f_abs_sum[GNUNET_ATS_PREFERENCE_END];
-
 };
 
 
@@ -175,8 +169,7 @@ static struct GNUNET_SCHEDULER_Task *aging_task;
 /**
  * Closure for #sum_relative_preferences().
  */
-struct SumContext
-{
+struct SumContext {
   /**
    * Where to accumulate the result.
    */
@@ -200,9 +193,9 @@ struct SumContext
  * @return #GNUNET_OK
  */
 static int
-sum_relative_preferences (void *cls,
-                          const struct GNUNET_PeerIdentity *peer,
-                          void *value)
+sum_relative_preferences(void *cls,
+                         const struct GNUNET_PeerIdentity *peer,
+                         void *value)
 {
   struct SumContext *sum_ctx = cls;
   struct PreferencePeer *p_cur = value;
@@ -221,8 +214,8 @@ sum_relative_preferences (void *cls,
  * @return the new relative preference
  */
 static void
-update_relative_values_for_peer (const struct GNUNET_PeerIdentity *id,
-				 enum GNUNET_ATS_PreferenceKind kind)
+update_relative_values_for_peer(const struct GNUNET_PeerIdentity *id,
+                                enum GNUNET_ATS_PreferenceKind kind)
 {
   struct PreferenceClient *c_cur;
   struct SumContext sum_ctx;
@@ -231,25 +224,25 @@ update_relative_values_for_peer (const struct GNUNET_PeerIdentity *id,
   sum_ctx.f_rel_total = 0.0;
   sum_ctx.kind = kind;
   for (c_cur = pc_head; NULL != c_cur; c_cur = c_cur->next)
-    GNUNET_CONTAINER_multipeermap_get_multiple (c_cur->peer2pref,
-                                                id,
-                                                &sum_relative_preferences,
-                                                &sum_ctx);
-  LOG (GNUNET_ERROR_TYPE_DEBUG,
-       "Total relative preference for peer `%s' for `%s' is %.3f\n",
-       GNUNET_i2s (id),
-       GNUNET_ATS_print_preference_type (kind),
-       sum_ctx.f_rel_total);
-  rp = GNUNET_CONTAINER_multipeermap_get (preference_peers,
-                                          id);
-  GNUNET_assert (NULL != rp);
+    GNUNET_CONTAINER_multipeermap_get_multiple(c_cur->peer2pref,
+                                               id,
+                                               &sum_relative_preferences,
+                                               &sum_ctx);
+  LOG(GNUNET_ERROR_TYPE_DEBUG,
+      "Total relative preference for peer `%s' for `%s' is %.3f\n",
+      GNUNET_i2s(id),
+      GNUNET_ATS_print_preference_type(kind),
+      sum_ctx.f_rel_total);
+  rp = GNUNET_CONTAINER_multipeermap_get(preference_peers,
+                                         id);
+  GNUNET_assert(NULL != rp);
   if (rp->f_rel[kind] != sum_ctx.f_rel_total)
-  {
-    rp->f_rel[kind] = sum_ctx.f_rel_total;
-    GAS_plugin_notify_preference_changed (id,
-                                          kind,
-                                          rp->f_rel[kind]);
-  }
+    {
+      rp->f_rel[kind] = sum_ctx.f_rel_total;
+      GAS_plugin_notify_preference_changed(id,
+                                           kind,
+                                           rp->f_rel[kind]);
+    }
 }
 
 
@@ -262,17 +255,17 @@ update_relative_values_for_peer (const struct GNUNET_PeerIdentity *id,
  * @return #GNUNET_OK to continue
  */
 static int
-free_peer (void *cls,
-           const struct GNUNET_PeerIdentity *key,
-           void *value)
+free_peer(void *cls,
+          const struct GNUNET_PeerIdentity *key,
+          void *value)
 {
   struct PeerRelative *rp = value;
 
-  GNUNET_assert (GNUNET_YES ==
-                 GNUNET_CONTAINER_multipeermap_remove (preference_peers,
-                                                       key,
-                                                       value));
-  GNUNET_free (rp);
+  GNUNET_assert(GNUNET_YES ==
+                GNUNET_CONTAINER_multipeermap_remove(preference_peers,
+                                                     key,
+                                                     value));
+  GNUNET_free(rp);
   return GNUNET_OK;
 }
 
@@ -286,30 +279,30 @@ free_peer (void *cls,
  * @return #GNUNET_OK (continue to iterate)
  */
 static int
-free_preference (void *cls,
-                 const struct GNUNET_PeerIdentity *key,
-                 void *value)
+free_preference(void *cls,
+                const struct GNUNET_PeerIdentity *key,
+                void *value)
 {
   struct PreferenceClient *pc = cls;
   struct PreferencePeer *p = value;
   struct PeerRelative *pr;
 
-  GNUNET_assert (GNUNET_OK ==
-                 GNUNET_CONTAINER_multipeermap_remove (pc->peer2pref,
-                                                       key,
-                                                       p));
-  GNUNET_free (p);
-  pr = GNUNET_CONTAINER_multipeermap_get (preference_peers,
-                                          key);
-  GNUNET_assert (NULL != pr);
-  GNUNET_assert (pr->num_clients > 0);
+  GNUNET_assert(GNUNET_OK ==
+                GNUNET_CONTAINER_multipeermap_remove(pc->peer2pref,
+                                                     key,
+                                                     p));
+  GNUNET_free(p);
+  pr = GNUNET_CONTAINER_multipeermap_get(preference_peers,
+                                         key);
+  GNUNET_assert(NULL != pr);
+  GNUNET_assert(pr->num_clients > 0);
   pr->num_clients--;
   if (0 == pr->num_clients)
-  {
-    free_peer (NULL,
-               key,
-               pr);
-  }
+    {
+      free_peer(NULL,
+                key,
+                pr);
+    }
   return GNUNET_OK;
 }
 
@@ -317,8 +310,7 @@ free_preference (void *cls,
 /**
  * Closure for #age_values().
  */
-struct AgeContext
-{
+struct AgeContext {
   /**
    * Counter of values remaining to update, incremented for each value
    * changed (to a new non-zero value).
@@ -329,7 +321,6 @@ struct AgeContext
    * Client we are currently aging values for.
    */
   struct PreferenceClient *cur_client;
-
 };
 
 
@@ -342,9 +333,9 @@ struct AgeContext
  * @return #GNUNET_OK (continue to iterate)
  */
 static int
-age_values (void *cls,
-            const struct GNUNET_PeerIdentity *peer,
-            void *value)
+age_values(void *cls,
+           const struct GNUNET_PeerIdentity *peer,
+           void *value)
 {
   struct AgeContext *ac = cls;
   struct PreferencePeer *p = value;
@@ -353,32 +344,32 @@ age_values (void *cls,
 
   dead = GNUNET_YES;
   for (i = 0; i < GNUNET_ATS_PREFERENCE_END; i++)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "Aging preference for peer `%s'\n",
-                GNUNET_i2s (peer));
-    if (p->f_abs[i] > DEFAULT_ABS_PREFERENCE)
-      p->f_abs[i] *= PREF_AGING_FACTOR;
-    if (p->f_abs[i] <= DEFAULT_ABS_PREFERENCE + PREF_EPSILON)
     {
-      p->f_abs[i] = DEFAULT_ABS_PREFERENCE;
-      p->f_rel[i] = DEFAULT_REL_PREFERENCE;
-      update_relative_values_for_peer (peer,
-                                       i);
+      GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+                 "Aging preference for peer `%s'\n",
+                 GNUNET_i2s(peer));
+      if (p->f_abs[i] > DEFAULT_ABS_PREFERENCE)
+        p->f_abs[i] *= PREF_AGING_FACTOR;
+      if (p->f_abs[i] <= DEFAULT_ABS_PREFERENCE + PREF_EPSILON)
+        {
+          p->f_abs[i] = DEFAULT_ABS_PREFERENCE;
+          p->f_rel[i] = DEFAULT_REL_PREFERENCE;
+          update_relative_values_for_peer(peer,
+                                          i);
+        }
+      else
+        {
+          ac->values_to_update++;
+          dead = GNUNET_NO;
+        }
     }
-    else
+  if (GNUNET_YES == dead)
     {
-      ac->values_to_update++;
-      dead = GNUNET_NO;
+      /* all preferences are zero, remove this entry */
+      free_preference(ac->cur_client,
+                      peer,
+                      p);
     }
-  }
-  if (GNUNET_YES == dead)
-  {
-    /* all preferences are zero, remove this entry */
-    free_preference (ac->cur_client,
-                     peer,
-                     p);
-  }
   return GNUNET_OK;
 }
 
@@ -389,41 +380,40 @@ age_values (void *cls,
  * @param cls unused
  */
 static void
-preference_aging (void *cls)
+preference_aging(void *cls)
 {
   struct AgeContext ac;
 
   aging_task = NULL;
-  GAS_plugin_solver_lock ();
+  GAS_plugin_solver_lock();
   ac.values_to_update = 0;
   for (ac.cur_client = pc_head; NULL != ac.cur_client; ac.cur_client = ac.cur_client->next)
-    GNUNET_CONTAINER_multipeermap_iterate (ac.cur_client->peer2pref,
-                                           &age_values,
-                                           &ac);
-  GAS_plugin_solver_unlock ();
+    GNUNET_CONTAINER_multipeermap_iterate(ac.cur_client->peer2pref,
+                                          &age_values,
+                                          &ac);
+  GAS_plugin_solver_unlock();
   if (ac.values_to_update > 0)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "Rescheduling aging task due to %u elements remaining to age\n",
-                ac.values_to_update);
-    if (NULL == aging_task)
-      aging_task = GNUNET_SCHEDULER_add_delayed (PREF_AGING_INTERVAL,
-                                                 &preference_aging,
-                                                 NULL);
-  }
+    {
+      GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+                 "Rescheduling aging task due to %u elements remaining to age\n",
+                 ac.values_to_update);
+      if (NULL == aging_task)
+        aging_task = GNUNET_SCHEDULER_add_delayed(PREF_AGING_INTERVAL,
+                                                  &preference_aging,
+                                                  NULL);
+    }
   else
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "No values to age left, not rescheduling aging task\n");
-  }
+    {
+      GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+                 "No values to age left, not rescheduling aging task\n");
+    }
 }
 
 
 /**
  * Closure for #update_rel_sum() and #update_abs_sum().
  */
-struct UpdateContext
-{
+struct UpdateContext {
   /**
    * Preference client with the sum of all absolute scores.
    */
@@ -433,7 +423,6 @@ struct UpdateContext
    * Which kind are we updating?
    */
   enum GNUNET_ATS_PreferenceKind kind;
-
 };
 
 
@@ -447,9 +436,9 @@ struct UpdateContext
  * @return #GNUNET_OK (continue to iterate)
  */
 static int
-update_abs_sum (void *cls,
-                const struct GNUNET_PeerIdentity *peer,
-                void *value)
+update_abs_sum(void *cls,
+               const struct GNUNET_PeerIdentity *peer,
+               void *value)
 {
   struct UpdateContext *uc = cls;
   struct PreferencePeer *p_cur = value;
@@ -469,19 +458,19 @@ update_abs_sum (void *cls,
  * @return #GNUNET_OK (continue to iterate)
  */
 static int
-update_rel_sum (void *cls,
-                const struct GNUNET_PeerIdentity *peer,
-                void *value)
+update_rel_sum(void *cls,
+               const struct GNUNET_PeerIdentity *peer,
+               void *value)
 {
   struct UpdateContext *uc = cls;
   struct PreferencePeer *p_cur = value;
 
   p_cur->f_rel[uc->kind] = p_cur->f_abs[uc->kind] / uc->pc->f_abs_sum[uc->kind];
-  LOG (GNUNET_ERROR_TYPE_DEBUG,
-       "Client has relative preference for %s for peer `%s' of %.3f\n",
-       GNUNET_ATS_print_preference_type (uc->kind),
-       GNUNET_i2s (peer),
-       p_cur->f_rel[uc->kind]);
+  LOG(GNUNET_ERROR_TYPE_DEBUG,
+      "Client has relative preference for %s for peer `%s' of %.3f\n",
+      GNUNET_ATS_print_preference_type(uc->kind),
+      GNUNET_i2s(peer),
+      p_cur->f_rel[uc->kind]);
   return GNUNET_OK;
 }
 
@@ -494,8 +483,8 @@ update_rel_sum (void *cls,
  * @return the result
  */
 static void
-recalculate_relative_preferences (struct PreferenceClient *c,
-                                  enum GNUNET_ATS_PreferenceKind kind)
+recalculate_relative_preferences(struct PreferenceClient *c,
+                                 enum GNUNET_ATS_PreferenceKind kind)
 {
   struct UpdateContext uc;
 
@@ -505,18 +494,18 @@ recalculate_relative_preferences (struct PreferenceClient *c,
   c->f_abs_sum[kind] = 0.0;
 
   /* For all peers: calculate sum of absolute preferences */
-  GNUNET_CONTAINER_multipeermap_iterate (c->peer2pref,
-                                         &update_abs_sum,
-                                         &uc);
-  LOG (GNUNET_ERROR_TYPE_DEBUG,
-       "Client has sum of total preferences for %s of %.3f\n",
-       GNUNET_ATS_print_preference_type (kind),
-       c->f_abs_sum[kind]);
+  GNUNET_CONTAINER_multipeermap_iterate(c->peer2pref,
+                                        &update_abs_sum,
+                                        &uc);
+  LOG(GNUNET_ERROR_TYPE_DEBUG,
+      "Client has sum of total preferences for %s of %.3f\n",
+      GNUNET_ATS_print_preference_type(kind),
+      c->f_abs_sum[kind]);
 
   /* For all peers: calculate relative preference */
-  GNUNET_CONTAINER_multipeermap_iterate (c->peer2pref,
-                                         &update_rel_sum,
-                                         &uc);
+  GNUNET_CONTAINER_multipeermap_iterate(c->peer2pref,
+                                        &update_rel_sum,
+                                        &uc);
 }
 
 
@@ -531,14 +520,14 @@ recalculate_relative_preferences (struct PreferenceClient *c,
  * @param value a `struct PeerRelative`, unused
  */
 static int
-update_iterator (void *cls,
-                 const struct GNUNET_PeerIdentity *key,
-                 void *value)
+update_iterator(void *cls,
+                const struct GNUNET_PeerIdentity *key,
+                void *value)
 {
   enum GNUNET_ATS_PreferenceKind *kind = cls;
 
-  update_relative_values_for_peer (key,
-                                   *kind);
+  update_relative_values_for_peer(key,
+                                  *kind);
   return GNUNET_OK;
 }
 
@@ -553,10 +542,10 @@ update_iterator (void *cls,
  * @param score_abs the normalized score
  */
 static void
-update_preference (struct GNUNET_SERVICE_Client *client,
-                   const struct GNUNET_PeerIdentity *peer,
-                   enum GNUNET_ATS_PreferenceKind kind,
-                   float score_abs)
+update_preference(struct GNUNET_SERVICE_Client *client,
+                  const struct GNUNET_PeerIdentity *peer,
+                  enum GNUNET_ATS_PreferenceKind kind,
+                  float score_abs)
 {
   struct PreferenceClient *c_cur;
   struct PreferencePeer *p_cur;
@@ -564,15 +553,15 @@ update_preference (struct GNUNET_SERVICE_Client *client,
   unsigned int i;
 
   if (kind >= GNUNET_ATS_PREFERENCE_END)
-  {
-    GNUNET_break(0);
-    return;
-  }
-  LOG (GNUNET_ERROR_TYPE_DEBUG,
-       "Client changes preference for peer `%s' for `%s' to %.2f\n",
-       GNUNET_i2s (peer),
-       GNUNET_ATS_print_preference_type (kind),
-       score_abs);
+    {
+      GNUNET_break(0);
+      return;
+    }
+  LOG(GNUNET_ERROR_TYPE_DEBUG,
+      "Client changes preference for peer `%s' for `%s' to %.2f\n",
+      GNUNET_i2s(peer),
+      GNUNET_ATS_print_preference_type(kind),
+      score_abs);
 
   /* Find preference client */
   for (c_cur = pc_head; NULL != c_cur; c_cur = c_cur->next)
@@ -580,66 +569,66 @@ update_preference (struct GNUNET_SERVICE_Client *client,
       break;
   /* Not found: create new preference client */
   if (NULL == c_cur)
-  {
-    c_cur = GNUNET_new (struct PreferenceClient);
-    c_cur->client = client;
-    c_cur->peer2pref = GNUNET_CONTAINER_multipeermap_create (16,
-                                                             GNUNET_NO);
-    for (i = 0; i < GNUNET_ATS_PREFERENCE_END; i++)
-      c_cur->f_abs_sum[i] = DEFAULT_ABS_PREFERENCE;
-    GNUNET_CONTAINER_DLL_insert (pc_head,
-                                 pc_tail,
-                                 c_cur);
-  }
+    {
+      c_cur = GNUNET_new(struct PreferenceClient);
+      c_cur->client = client;
+      c_cur->peer2pref = GNUNET_CONTAINER_multipeermap_create(16,
+                                                              GNUNET_NO);
+      for (i = 0; i < GNUNET_ATS_PREFERENCE_END; i++)
+        c_cur->f_abs_sum[i] = DEFAULT_ABS_PREFERENCE;
+      GNUNET_CONTAINER_DLL_insert(pc_head,
+                                  pc_tail,
+                                  c_cur);
+    }
 
   /* check global peer entry exists */
   if (NULL ==
-      (r_cur = GNUNET_CONTAINER_multipeermap_get (preference_peers,
-                                                  peer)))
-  {
-    /* Create struct for peer */
-    r_cur = GNUNET_new (struct PeerRelative);
-    for (i = 0; i < GNUNET_ATS_PREFERENCE_END; i++)
-      r_cur->f_rel[i] = DEFAULT_REL_PREFERENCE;
-    GNUNET_assert (GNUNET_OK ==
-                   GNUNET_CONTAINER_multipeermap_put (preference_peers,
+      (r_cur = GNUNET_CONTAINER_multipeermap_get(preference_peers,
+                                                 peer)))
+    {
+      /* Create struct for peer */
+      r_cur = GNUNET_new(struct PeerRelative);
+      for (i = 0; i < GNUNET_ATS_PREFERENCE_END; i++)
+        r_cur->f_rel[i] = DEFAULT_REL_PREFERENCE;
+      GNUNET_assert(GNUNET_OK ==
+                    GNUNET_CONTAINER_multipeermap_put(preference_peers,
                                                       peer,
                                                       r_cur,
                                                       GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
-  }
+    }
 
   /* Find entry for peer */
-  p_cur = GNUNET_CONTAINER_multipeermap_get (c_cur->peer2pref,
-                                             peer);
+  p_cur = GNUNET_CONTAINER_multipeermap_get(c_cur->peer2pref,
+                                            peer);
   if (NULL == p_cur)
-  {
-    /* Not found: create new peer entry */
-    p_cur = GNUNET_new (struct PreferencePeer);
-    for (i = 0; i < GNUNET_ATS_PREFERENCE_END; i++)
     {
-      /* Default value per peer absolute preference for a preference*/
-      p_cur->f_abs[i] = DEFAULT_ABS_PREFERENCE;
-      /* Default value per peer relative preference for a quality */
-      p_cur->f_rel[i] = DEFAULT_REL_PREFERENCE;
-    }
-    GNUNET_assert (GNUNET_YES ==
-                   GNUNET_CONTAINER_multipeermap_put (c_cur->peer2pref,
+      /* Not found: create new peer entry */
+      p_cur = GNUNET_new(struct PreferencePeer);
+      for (i = 0; i < GNUNET_ATS_PREFERENCE_END; i++)
+        {
+          /* Default value per peer absolute preference for a preference*/
+          p_cur->f_abs[i] = DEFAULT_ABS_PREFERENCE;
+          /* Default value per peer relative preference for a quality */
+          p_cur->f_rel[i] = DEFAULT_REL_PREFERENCE;
+        }
+      GNUNET_assert(GNUNET_YES ==
+                    GNUNET_CONTAINER_multipeermap_put(c_cur->peer2pref,
                                                       peer,
                                                       p_cur,
                                                       GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
-    r_cur->num_clients++;
-  }
+      r_cur->num_clients++;
+    }
 
   p_cur->f_abs[kind] += score_abs;
-  recalculate_relative_preferences (c_cur, kind);
-  GNUNET_CONTAINER_multipeermap_iterate (preference_peers,
-					 &update_iterator,
-					 &kind);
+  recalculate_relative_preferences(c_cur, kind);
+  GNUNET_CONTAINER_multipeermap_iterate(preference_peers,
+                                        &update_iterator,
+                                        &kind);
 
   if (NULL == aging_task)
-    aging_task = GNUNET_SCHEDULER_add_delayed (PREF_AGING_INTERVAL,
-                                               &preference_aging,
-                                               NULL);
+    aging_task = GNUNET_SCHEDULER_add_delayed(PREF_AGING_INTERVAL,
+                                              &preference_aging,
+                                              NULL);
 }
 
 
@@ -650,28 +639,28 @@ update_preference (struct GNUNET_SERVICE_Client *client,
  * @param msg the request message
  */
 void
-GAS_handle_preference_change (struct GNUNET_SERVICE_Client *client,
-			      const struct ChangePreferenceMessage *msg)
+GAS_handle_preference_change(struct GNUNET_SERVICE_Client *client,
+                             const struct ChangePreferenceMessage *msg)
 {
   const struct PreferenceInformation *pi;
   uint32_t nump;
 
-  nump = ntohl (msg->num_preferences);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Received PREFERENCE_CHANGE message for peer `%s'\n",
-              GNUNET_i2s (&msg->peer));
-  GNUNET_STATISTICS_update (GSA_stats,
-                            "# preference change requests processed",
-                            1,
-                            GNUNET_NO);
-  pi = (const struct PreferenceInformation *) &msg[1];
-  GAS_plugin_solver_lock ();
+  nump = ntohl(msg->num_preferences);
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+             "Received PREFERENCE_CHANGE message for peer `%s'\n",
+             GNUNET_i2s(&msg->peer));
+  GNUNET_STATISTICS_update(GSA_stats,
+                           "# preference change requests processed",
+                           1,
+                           GNUNET_NO);
+  pi = (const struct PreferenceInformation *)&msg[1];
+  GAS_plugin_solver_lock();
   for (uint32_t i = 0; i < nump; i++)
-    update_preference (client,
-                       &msg->peer,
-                       (enum GNUNET_ATS_PreferenceKind) ntohl (pi[i].preference_kind),
-                       pi[i].preference_value);
-  GAS_plugin_solver_unlock ();
+    update_preference(client,
+                      &msg->peer,
+                      (enum GNUNET_ATS_PreferenceKind)ntohl(pi[i].preference_kind),
+                      pi[i].preference_value);
+  GAS_plugin_solver_unlock();
 }
 
 
@@ -679,12 +668,12 @@ GAS_handle_preference_change (struct GNUNET_SERVICE_Client *client,
  * Initialize preferences subsystem.
  */
 void
-GAS_preference_init ()
+GAS_preference_init()
 {
   unsigned int i;
 
-  preference_peers = GNUNET_CONTAINER_multipeermap_create (16,
-                                                           GNUNET_NO);
+  preference_peers = GNUNET_CONTAINER_multipeermap_create(16,
+                                                          GNUNET_NO);
   for (i = 0; i < GNUNET_ATS_PREFERENCE_END; i++)
     defvalues.f_rel[i] = DEFAULT_REL_PREFERENCE;
 }
@@ -694,34 +683,33 @@ GAS_preference_init ()
  * Shutdown preferences subsystem.
  */
 void
-GAS_preference_done ()
+GAS_preference_done()
 {
   struct PreferenceClient *pc;
   struct PreferenceClient *next_pc;
 
   if (NULL != aging_task)
-  {
-    GNUNET_SCHEDULER_cancel (aging_task);
-    aging_task = NULL;
-  }
+    {
+      GNUNET_SCHEDULER_cancel(aging_task);
+      aging_task = NULL;
+    }
   next_pc = pc_head;
   while (NULL != (pc = next_pc))
-  {
-    next_pc = pc->next;
-    GNUNET_CONTAINER_DLL_remove (pc_head,
-                                 pc_tail,
-                                 pc);
-    GNUNET_CONTAINER_multipeermap_iterate (pc->peer2pref,
-                                           &free_preference,
-                                           pc);
-    GNUNET_CONTAINER_multipeermap_destroy (pc->peer2pref);
-    GNUNET_free (pc);
-  }
-  GNUNET_CONTAINER_multipeermap_iterate (preference_peers,
-					 &free_peer,
-                                         NULL);
-  GNUNET_CONTAINER_multipeermap_destroy (preference_peers);
-
+    {
+      next_pc = pc->next;
+      GNUNET_CONTAINER_DLL_remove(pc_head,
+                                  pc_tail,
+                                  pc);
+      GNUNET_CONTAINER_multipeermap_iterate(pc->peer2pref,
+                                            &free_preference,
+                                            pc);
+      GNUNET_CONTAINER_multipeermap_destroy(pc->peer2pref);
+      GNUNET_free(pc);
+    }
+  GNUNET_CONTAINER_multipeermap_iterate(preference_peers,
+                                        &free_peer,
+                                        NULL);
+  GNUNET_CONTAINER_multipeermap_destroy(preference_peers);
 }
 
 
@@ -735,17 +723,17 @@ GAS_preference_done ()
  * default preferences if peer does not exist
  */
 const double *
-GAS_preference_get_by_peer (void *cls,
-                            const struct GNUNET_PeerIdentity *id)
+GAS_preference_get_by_peer(void *cls,
+                           const struct GNUNET_PeerIdentity *id)
 {
   struct PeerRelative *rp;
 
   if (NULL ==
-      (rp = GNUNET_CONTAINER_multipeermap_get (preference_peers,
-                                               id)))
-  {
-    return defvalues.f_rel;
-  }
+      (rp = GNUNET_CONTAINER_multipeermap_get(preference_peers,
+                                              id)))
+    {
+      return defvalues.f_rel;
+    }
   return rp->f_rel;
 }
 
@@ -756,7 +744,7 @@ GAS_preference_get_by_peer (void *cls,
  * @param client the client
  */
 void
-GAS_preference_client_disconnect (struct GNUNET_SERVICE_Client *client)
+GAS_preference_client_disconnect(struct GNUNET_SERVICE_Client *client)
 {
   struct PreferenceClient *c_cur;
 
@@ -765,14 +753,14 @@ GAS_preference_client_disconnect (struct GNUNET_SERVICE_Client *client)
       break;
   if (NULL == c_cur)
     return;
-  GNUNET_CONTAINER_DLL_remove (pc_head,
-                               pc_tail,
-                               c_cur);
-  GNUNET_CONTAINER_multipeermap_iterate (c_cur->peer2pref,
-                                         &free_preference,
-                                         c_cur);
-  GNUNET_CONTAINER_multipeermap_destroy (c_cur->peer2pref);
-  GNUNET_free (c_cur);
+  GNUNET_CONTAINER_DLL_remove(pc_head,
+                              pc_tail,
+                              c_cur);
+  GNUNET_CONTAINER_multipeermap_iterate(c_cur->peer2pref,
+                                        &free_preference,
+                                        c_cur);
+  GNUNET_CONTAINER_multipeermap_destroy(c_cur->peer2pref);
+  GNUNET_free(c_cur);
 }
 
 

+ 19 - 19
src/ats/gnunet-service-ats_preferences.h

@@ -1,19 +1,19 @@
 /*
- This file is part of GNUnet.
- Copyright (C) 2011-2014 GNUnet e.V.
+   This file is part of GNUnet.
+   Copyright (C) 2011-2014 GNUnet e.V.
 
- GNUnet is free software: you can redistribute it and/or modify it
- under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License,
- or (at your option) any later version.
+   GNUnet is free software: you can redistribute it and/or modify it
+   under the terms of the GNU Affero General Public License as published
+   by the Free Software Foundation, either version 3 of the License,
+   or (at your option) any later version.
 
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- Affero General Public License for more details.
+   GNUnet is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Affero General Public License for more details.
 
- You should have received a copy of the GNU Affero General Public License
- along with this program.  If not, see <http://www.gnu.org/licenses/>.
+   You should have received a copy of the GNU Affero General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
  */
@@ -50,22 +50,22 @@
  * @param msg the request message
  */
 void
-GAS_handle_preference_change (struct GNUNET_SERVICE_Client *client,
-			      const struct ChangePreferenceMessage *msg);
+GAS_handle_preference_change(struct GNUNET_SERVICE_Client *client,
+                             const struct ChangePreferenceMessage *msg);
 
 
 /**
  * Initialize preferences subsystem.
  */
 void
-GAS_preference_init (void);
+GAS_preference_init(void);
 
 
 /**
  * Shutdown preferences subsystem.
  */
 void
-GAS_preference_done (void);
+GAS_preference_done(void);
 
 
 /**
@@ -77,8 +77,8 @@ GAS_preference_done (void);
  *  with `enum GNUNET_ATS_PreferenceKind`, never NULL
  */
 const double *
-GAS_preference_get_by_peer (void *cls,
-                            const struct GNUNET_PeerIdentity *id);
+GAS_preference_get_by_peer(void *cls,
+                           const struct GNUNET_PeerIdentity *id);
 
 
 /**
@@ -87,7 +87,7 @@ GAS_preference_get_by_peer (void *cls,
  * @param client the disconnecting client
  */
 void
-GAS_preference_client_disconnect (struct GNUNET_SERVICE_Client *client);
+GAS_preference_client_disconnect(struct GNUNET_SERVICE_Client *client);
 
 
 #endif

+ 79 - 79
src/ats/gnunet-service-ats_reservations.c

@@ -11,12 +11,12 @@
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      Affero General Public License for more details.
-    
+
      You should have received a copy of the GNU Affero General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
-*/
+ */
 /**
  * @file ats/gnunet-service-ats_reservations.c
  * @brief ats service, inbound bandwidth reservation management
@@ -53,38 +53,38 @@ static struct GNUNET_CONTAINER_MultiPeerMap *trackers;
  *         until the reservation might succeed
  */
 static struct GNUNET_TIME_Relative
-reservations_reserve (const struct GNUNET_PeerIdentity *peer,
-                      int32_t amount)
+reservations_reserve(const struct GNUNET_PeerIdentity *peer,
+                     int32_t amount)
 {
   struct GNUNET_BANDWIDTH_Tracker *tracker;
   struct GNUNET_TIME_Relative ret;
 
-  tracker = GNUNET_CONTAINER_multipeermap_get (trackers,
-                                               peer);
+  tracker = GNUNET_CONTAINER_multipeermap_get(trackers,
+                                              peer);
   if (NULL == tracker)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "Not connected, allowing reservation of %d bytes\n",
-                (int) amount);
-    return GNUNET_TIME_UNIT_ZERO;       /* not connected, satisfy now */
-  }
+    {
+      GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+                 "Not connected, allowing reservation of %d bytes\n",
+                 (int)amount);
+      return GNUNET_TIME_UNIT_ZERO;     /* not connected, satisfy now */
+    }
   if (amount >= 0)
-  {
-    ret = GNUNET_BANDWIDTH_tracker_get_delay (tracker, amount);
-    if (ret.rel_value_us > 0)
     {
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                  "Delay to satisfy reservation for %d bytes is %s\n",
-                  (int) amount,
-		  GNUNET_STRINGS_relative_time_to_string (ret,
-							  GNUNET_YES));
-      return ret;
+      ret = GNUNET_BANDWIDTH_tracker_get_delay(tracker, amount);
+      if (ret.rel_value_us > 0)
+        {
+          GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+                     "Delay to satisfy reservation for %d bytes is %s\n",
+                     (int)amount,
+                     GNUNET_STRINGS_relative_time_to_string(ret,
+                                                            GNUNET_YES));
+          return ret;
+        }
     }
-  }
-  (void) GNUNET_BANDWIDTH_tracker_consume (tracker, amount);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Reserved %d bytes\n",
-              (int) amount);
+  (void)GNUNET_BANDWIDTH_tracker_consume(tracker, amount);
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+             "Reserved %d bytes\n",
+             (int)amount);
   return GNUNET_TIME_UNIT_ZERO;
 }
 
@@ -98,40 +98,40 @@ reservations_reserve (const struct GNUNET_PeerIdentity *peer,
  *        this peer (estimate)
  */
 void
-GAS_reservations_set_bandwidth (const struct GNUNET_PeerIdentity *peer,
-                                struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
+GAS_reservations_set_bandwidth(const struct GNUNET_PeerIdentity *peer,
+                               struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
 {
   struct GNUNET_BANDWIDTH_Tracker *tracker;
 
-  tracker = GNUNET_CONTAINER_multipeermap_get (trackers, peer);
-  if (0 == ntohl (bandwidth_in.value__))
-  {
-    if (NULL == tracker)
-      return;
-    GNUNET_assert (GNUNET_YES ==
-                   GNUNET_CONTAINER_multipeermap_remove (trackers,
+  tracker = GNUNET_CONTAINER_multipeermap_get(trackers, peer);
+  if (0 == ntohl(bandwidth_in.value__))
+    {
+      if (NULL == tracker)
+        return;
+      GNUNET_assert(GNUNET_YES ==
+                    GNUNET_CONTAINER_multipeermap_remove(trackers,
                                                          peer,
                                                          tracker));
-    GNUNET_free (tracker);
-    return;
-  }
+      GNUNET_free(tracker);
+      return;
+    }
   if (NULL == tracker)
-  {
-    tracker = GNUNET_new (struct GNUNET_BANDWIDTH_Tracker);
-    GNUNET_BANDWIDTH_tracker_init (tracker,
-                                   NULL,
-                                   NULL,
-                                   bandwidth_in,
-                                   MAX_BANDWIDTH_CARRY_S);
-    GNUNET_assert (GNUNET_OK ==
-                   GNUNET_CONTAINER_multipeermap_put (trackers,
+    {
+      tracker = GNUNET_new(struct GNUNET_BANDWIDTH_Tracker);
+      GNUNET_BANDWIDTH_tracker_init(tracker,
+                                    NULL,
+                                    NULL,
+                                    bandwidth_in,
+                                    MAX_BANDWIDTH_CARRY_S);
+      GNUNET_assert(GNUNET_OK ==
+                    GNUNET_CONTAINER_multipeermap_put(trackers,
                                                       peer,
                                                       tracker,
                                                       GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
-    return;
-  }
-  GNUNET_BANDWIDTH_tracker_update_quota (tracker,
-                                         bandwidth_in);
+      return;
+    }
+  GNUNET_BANDWIDTH_tracker_update_quota(tracker,
+                                        bandwidth_in);
 }
 
 
@@ -142,31 +142,31 @@ GAS_reservations_set_bandwidth (const struct GNUNET_PeerIdentity *peer,
  * @param msg the request message
  */
 void
-GAS_handle_reservation_request (struct GNUNET_SERVICE_Client *client,
-                                const struct ReservationRequestMessage *msg)
+GAS_handle_reservation_request(struct GNUNET_SERVICE_Client *client,
+                               const struct ReservationRequestMessage *msg)
 {
   struct GNUNET_MQ_Envelope *env;
   struct ReservationResultMessage *result;
   int32_t amount;
   struct GNUNET_TIME_Relative res_delay;
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Received RESERVATION_REQUEST message\n");
-  amount = (int32_t) ntohl (msg->amount);
-  res_delay = reservations_reserve (&msg->peer, amount);
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+             "Received RESERVATION_REQUEST message\n");
+  amount = (int32_t)ntohl(msg->amount);
+  res_delay = reservations_reserve(&msg->peer, amount);
   if (res_delay.rel_value_us > 0)
     amount = 0;
-  env = GNUNET_MQ_msg (result,
-		       GNUNET_MESSAGE_TYPE_ATS_RESERVATION_RESULT);
-  result->amount = htonl (amount);
+  env = GNUNET_MQ_msg(result,
+                      GNUNET_MESSAGE_TYPE_ATS_RESERVATION_RESULT);
+  result->amount = htonl(amount);
   result->peer = msg->peer;
-  result->res_delay = GNUNET_TIME_relative_hton (res_delay);
-  GNUNET_STATISTICS_update (GSA_stats,
-                            "# reservation requests processed",
-                            1,
-                            GNUNET_NO);
-  GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
-		  env);
+  result->res_delay = GNUNET_TIME_relative_hton(res_delay);
+  GNUNET_STATISTICS_update(GSA_stats,
+                           "# reservation requests processed",
+                           1,
+                           GNUNET_NO);
+  GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client),
+                 env);
 }
 
 
@@ -174,10 +174,10 @@ GAS_handle_reservation_request (struct GNUNET_SERVICE_Client *client,
  * Initialize reservations subsystem.
  */
 void
-GAS_reservations_init ()
+GAS_reservations_init()
 {
-  trackers = GNUNET_CONTAINER_multipeermap_create (128,
-                                                   GNUNET_NO);
+  trackers = GNUNET_CONTAINER_multipeermap_create(128,
+                                                  GNUNET_NO);
 }
 
 
@@ -190,13 +190,13 @@ GAS_reservations_init ()
  * @return #GNUNET_OK (continue to iterate)
  */
 static int
-free_tracker (void *cls,
-	      const struct GNUNET_PeerIdentity *key,
-	      void *value)
+free_tracker(void *cls,
+             const struct GNUNET_PeerIdentity *key,
+             void *value)
 {
   struct GNUNET_BANDWIDTH_Tracker *tracker = value;
 
-  GNUNET_free (tracker);
+  GNUNET_free(tracker);
   return GNUNET_OK;
 }
 
@@ -205,12 +205,12 @@ free_tracker (void *cls,
  * Shutdown reservations subsystem.
  */
 void
-GAS_reservations_done ()
+GAS_reservations_done()
 {
-  GNUNET_CONTAINER_multipeermap_iterate (trackers,
-                                         &free_tracker,
-                                         NULL);
-  GNUNET_CONTAINER_multipeermap_destroy (trackers);
+  GNUNET_CONTAINER_multipeermap_iterate(trackers,
+                                        &free_tracker,
+                                        NULL);
+  GNUNET_CONTAINER_multipeermap_destroy(trackers);
 }
 
 /* end of gnunet-service-ats_reservations.c */

+ 9 - 9
src/ats/gnunet-service-ats_reservations.h

@@ -11,12 +11,12 @@
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      Affero General Public License for more details.
-    
+
      You should have received a copy of the GNU Affero General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
-*/
+ */
 
 /**
  * @file ats/gnunet-service-ats_reservations.h
@@ -39,9 +39,9 @@
  *        this peer (estimate)
  */
 void
-GAS_reservations_set_bandwidth (const struct GNUNET_PeerIdentity *peer,
-                                struct GNUNET_BANDWIDTH_Value32NBO
-                                bandwidth_in);
+GAS_reservations_set_bandwidth(const struct GNUNET_PeerIdentity *peer,
+                               struct GNUNET_BANDWIDTH_Value32NBO
+                               bandwidth_in);
 
 
 /**
@@ -51,8 +51,8 @@ GAS_reservations_set_bandwidth (const struct GNUNET_PeerIdentity *peer,
  * @param message the request message
  */
 void
-GAS_handle_reservation_request (struct GNUNET_SERVICE_Client *client,
-                                const struct ReservationRequestMessage *message);
+GAS_handle_reservation_request(struct GNUNET_SERVICE_Client *client,
+                               const struct ReservationRequestMessage *message);
 
 
 /**
@@ -61,13 +61,13 @@ GAS_handle_reservation_request (struct GNUNET_SERVICE_Client *client,
  * @param server handle to our server
  */
 void
-GAS_reservations_init (void);
+GAS_reservations_init(void);
 
 
 /**
  * Shutdown reservations subsystem.
  */
 void
-GAS_reservations_done (void);
+GAS_reservations_done(void);
 
 #endif

+ 73 - 73
src/ats/gnunet-service-ats_scheduling.c

@@ -11,12 +11,12 @@
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      Affero General Public License for more details.
-    
+
      You should have received a copy of the GNU Affero General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
-*/
+ */
 
 /**
  * @file ats/gnunet-service-ats_scheduling.c
@@ -42,14 +42,14 @@ static struct GNUNET_SERVICE_Client *my_client;
  * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
  */
 int
-GAS_scheduling_add_client (struct GNUNET_SERVICE_Client *client)
+GAS_scheduling_add_client(struct GNUNET_SERVICE_Client *client)
 {
   if (NULL != my_client)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "This ATS already has a scheduling client, refusing new scheduling client for now.\n");
-    return GNUNET_SYSERR;
-  }
+    {
+      GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+                 "This ATS already has a scheduling client, refusing new scheduling client for now.\n");
+      return GNUNET_SYSERR;
+    }
   my_client = client;
   return GNUNET_OK;
 }
@@ -62,11 +62,11 @@ GAS_scheduling_add_client (struct GNUNET_SERVICE_Client *client)
  * @param client handle of the (now dead) client
  */
 void
-GAS_scheduling_remove_client (struct GNUNET_SERVICE_Client *client)
+GAS_scheduling_remove_client(struct GNUNET_SERVICE_Client *client)
 {
   if (my_client != client)
     return;
-  GAS_addresses_destroy_all ();
+  GAS_addresses_destroy_all();
   my_client = NULL;
 }
 
@@ -81,33 +81,33 @@ GAS_scheduling_remove_client (struct GNUNET_SERVICE_Client *client)
  * @param bandwidth_in assigned inbound bandwidth
  */
 void
-GAS_scheduling_transmit_address_suggestion (const struct GNUNET_PeerIdentity *peer,
-                                            uint32_t session_id,
-                                            struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
-                                            struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
+GAS_scheduling_transmit_address_suggestion(const struct GNUNET_PeerIdentity *peer,
+                                           uint32_t session_id,
+                                           struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
+                                           struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
 {
   struct GNUNET_MQ_Envelope *env;
   struct AddressSuggestionMessage *msg;
 
   if (NULL == my_client)
     return;
-  GNUNET_STATISTICS_update (GSA_stats,
-                            "# address suggestions made",
-			    1,
-                            GNUNET_NO);
-  env = GNUNET_MQ_msg (msg,
-		       GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION);
+  GNUNET_STATISTICS_update(GSA_stats,
+                           "# address suggestions made",
+                           1,
+                           GNUNET_NO);
+  env = GNUNET_MQ_msg(msg,
+                      GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION);
   msg->peer = *peer;
-  msg->session_id = htonl (session_id);
+  msg->session_id = htonl(session_id);
   msg->bandwidth_out = bandwidth_out;
   msg->bandwidth_in = bandwidth_in;
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "ATS sends quota for peer `%s': (in/out) %u/%u\n",
-              GNUNET_i2s (peer),
-              (unsigned int) ntohl (bandwidth_in.value__),
-              (unsigned int) ntohl (bandwidth_out.value__));
-  GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (my_client),
-		  env);
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+             "ATS sends quota for peer `%s': (in/out) %u/%u\n",
+             GNUNET_i2s(peer),
+             (unsigned int)ntohl(bandwidth_in.value__),
+             (unsigned int)ntohl(bandwidth_out.value__));
+  GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(my_client),
+                 env);
 }
 
 
@@ -117,7 +117,7 @@ GAS_scheduling_transmit_address_suggestion (const struct GNUNET_PeerIdentity *pe
  * @param m the request message
  */
 void
-GAS_handle_address_add (const struct AddressAddMessage *m)
+GAS_handle_address_add(const struct AddressAddMessage *m)
 {
   const char *address;
   const char *plugin_name;
@@ -125,30 +125,30 @@ GAS_handle_address_add (const struct AddressAddMessage *m)
   uint16_t plugin_name_length;
   struct GNUNET_ATS_Properties prop;
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Received `%s' message\n",
-              "ADDRESS_ADD");
-  address_length = ntohs (m->address_length);
-  plugin_name_length = ntohs (m->plugin_name_length);
-  address = (const char *) &m[1];
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+             "Received `%s' message\n",
+             "ADDRESS_ADD");
+  address_length = ntohs(m->address_length);
+  plugin_name_length = ntohs(m->plugin_name_length);
+  address = (const char *)&m[1];
   if (plugin_name_length != 0)
     plugin_name = &address[address_length];
   else
     plugin_name = "";
-  GNUNET_STATISTICS_update (GSA_stats,
-                            "# addresses created",
-                            1,
-                            GNUNET_NO);
-  GNUNET_ATS_properties_ntoh (&prop,
-                              &m->properties);
-  GNUNET_break (GNUNET_NT_UNSPECIFIED != prop.scope);
-  GAS_addresses_add (&m->peer,
-                     plugin_name,
-                     address,
-                     address_length,
-                     ntohl (m->address_local_info),
-                     ntohl (m->session_id),
-                     &prop);
+  GNUNET_STATISTICS_update(GSA_stats,
+                           "# addresses created",
+                           1,
+                           GNUNET_NO);
+  GNUNET_ATS_properties_ntoh(&prop,
+                             &m->properties);
+  GNUNET_break(GNUNET_NT_UNSPECIFIED != prop.scope);
+  GAS_addresses_add(&m->peer,
+                    plugin_name,
+                    address,
+                    address_length,
+                    ntohl(m->address_local_info),
+                    ntohl(m->session_id),
+                    &prop);
 }
 
 
@@ -158,19 +158,19 @@ GAS_handle_address_add (const struct AddressAddMessage *m)
  * @param m the request message
  */
 void
-GAS_handle_address_update (const struct AddressUpdateMessage *m)
+GAS_handle_address_update(const struct AddressUpdateMessage *m)
 {
   struct GNUNET_ATS_Properties prop;
 
-  GNUNET_STATISTICS_update (GSA_stats,
-                            "# address updates received",
-                            1,
-                            GNUNET_NO);
-  GNUNET_ATS_properties_ntoh (&prop,
-                              &m->properties);
-  GAS_addresses_update (&m->peer,
-                        ntohl (m->session_id),
-                        &prop);
+  GNUNET_STATISTICS_update(GSA_stats,
+                           "# address updates received",
+                           1,
+                           GNUNET_NO);
+  GNUNET_ATS_properties_ntoh(&prop,
+                             &m->properties);
+  GAS_addresses_update(&m->peer,
+                       ntohl(m->session_id),
+                       &prop);
 }
 
 
@@ -180,26 +180,26 @@ GAS_handle_address_update (const struct AddressUpdateMessage *m)
  * @param m the request message
  */
 void
-GAS_handle_address_destroyed (const struct AddressDestroyedMessage *m)
+GAS_handle_address_destroyed(const struct AddressDestroyedMessage *m)
 {
   struct GNUNET_MQ_Envelope *env;
   struct GNUNET_ATS_SessionReleaseMessage *srm;
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Received `%s' message\n",
-              "ADDRESS_DESTROYED");
-  GNUNET_STATISTICS_update (GSA_stats,
-                            "# addresses destroyed",
-                            1,
-                            GNUNET_NO);
-  GAS_addresses_destroy (&m->peer,
-                         ntohl (m->session_id));
-  env = GNUNET_MQ_msg (srm,
-		       GNUNET_MESSAGE_TYPE_ATS_SESSION_RELEASE);
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+             "Received `%s' message\n",
+             "ADDRESS_DESTROYED");
+  GNUNET_STATISTICS_update(GSA_stats,
+                           "# addresses destroyed",
+                           1,
+                           GNUNET_NO);
+  GAS_addresses_destroy(&m->peer,
+                        ntohl(m->session_id));
+  env = GNUNET_MQ_msg(srm,
+                      GNUNET_MESSAGE_TYPE_ATS_SESSION_RELEASE);
   srm->session_id = m->session_id;
   srm->peer = m->peer;
-  GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (my_client),
-		  env);
+  GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(my_client),
+                 env);
 }
 
 

+ 11 - 11
src/ats/gnunet-service-ats_scheduling.h

@@ -11,12 +11,12 @@
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      Affero General Public License for more details.
-    
+
      You should have received a copy of the GNU Affero General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
-*/
+ */
 
 /**
  * @file ats/gnunet-service-ats_scheduling.h
@@ -37,7 +37,7 @@
  * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
  */
 int
-GAS_scheduling_add_client (struct GNUNET_SERVICE_Client *client);
+GAS_scheduling_add_client(struct GNUNET_SERVICE_Client *client);
 
 
 /**
@@ -47,7 +47,7 @@ GAS_scheduling_add_client (struct GNUNET_SERVICE_Client *client);
  * @param client handle of the (now dead) client
  */
 void
-GAS_scheduling_remove_client (struct GNUNET_SERVICE_Client *client);
+GAS_scheduling_remove_client(struct GNUNET_SERVICE_Client *client);
 
 
 /**
@@ -60,10 +60,10 @@ GAS_scheduling_remove_client (struct GNUNET_SERVICE_Client *client);
  * @param bandwidth_in assigned inbound bandwidth
  */
 void
-GAS_scheduling_transmit_address_suggestion (const struct GNUNET_PeerIdentity *peer,
-                                            uint32_t session_id,
-                                            struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
-                                            struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in);
+GAS_scheduling_transmit_address_suggestion(const struct GNUNET_PeerIdentity *peer,
+                                           uint32_t session_id,
+                                           struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
+                                           struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in);
 
 
 /**
@@ -73,7 +73,7 @@ GAS_scheduling_transmit_address_suggestion (const struct GNUNET_PeerIdentity *pe
  * @param m the request message
  */
 void
-GAS_handle_address_add (const struct AddressAddMessage *m);
+GAS_handle_address_add(const struct AddressAddMessage *m);
 
 
 /**
@@ -82,7 +82,7 @@ GAS_handle_address_add (const struct AddressAddMessage *m);
  * @param m the request message
  */
 void
-GAS_handle_address_update (const struct AddressUpdateMessage *m);
+GAS_handle_address_update(const struct AddressUpdateMessage *m);
 
 
 /**
@@ -91,7 +91,7 @@ GAS_handle_address_update (const struct AddressUpdateMessage *m);
  * @param m the request message
  */
 void
-GAS_handle_address_destroyed (const struct AddressDestroyedMessage *m);
+GAS_handle_address_destroyed(const struct AddressDestroyedMessage *m);
 
 
 #endif

Plik diff jest za duży
+ 448 - 440
src/ats/perf_ats_solver.c


+ 57 - 57
src/ats/plugin_ats2_common.c

@@ -1,19 +1,19 @@
 /*
- This file is part of GNUnet.
- Copyright (C) 2011-2015, 2018 GNUnet e.V.
+   This file is part of GNUnet.
+   Copyright (C) 2011-2015, 2018 GNUnet e.V.
 
- GNUnet is free software: you can redistribute it and/or modify it
- under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License,
- or (at your option) any later version.
+   GNUnet is free software: you can redistribute it and/or modify it
+   under the terms of the GNU Affero General Public License as published
+   by the Free Software Foundation, either version 3 of the License,
+   or (at your option) any later version.
 
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- Affero General Public License for more details.
+   GNUnet is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Affero General Public License for more details.
 
- You should have received a copy of the GNU Affero General Public License
- along with this program.  If not, see <http://www.gnu.org/licenses/>.
+   You should have received a copy of the GNU Affero General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
  */
@@ -40,59 +40,59 @@
  * @param quota[out] set to quota, #DEFAULT_BANDWIDTH if @a cfg does not say anything useful
  */
 static void
-get_quota (const struct GNUNET_CONFIGURATION_Handle *cfg,
-	   const char *nts,
-	   const char *direction,
-	   unsigned long long *quota)
+get_quota(const struct GNUNET_CONFIGURATION_Handle *cfg,
+          const char *nts,
+          const char *direction,
+          unsigned long long *quota)
 {
   char *quota_str;
   char *quota_s;
   int res;
 
-  GNUNET_asprintf (&quota_s,
-		   "%s_QUOTA_%s",
-		   nts,
-		   direction);
+  GNUNET_asprintf(&quota_s,
+                  "%s_QUOTA_%s",
+                  nts,
+                  direction);
   if (GNUNET_OK !=
-      GNUNET_CONFIGURATION_get_value_string (cfg,
-					     "ATS",
-					     quota_s,
-					     &quota_str))
-  {
-    GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING,
-			       "ATS",
-			       quota_s);
-    GNUNET_free (quota_s);
-    return;
-  }
-  GNUNET_free (quota_s);
+      GNUNET_CONFIGURATION_get_value_string(cfg,
+                                            "ATS",
+                                            quota_s,
+                                            &quota_str))
+    {
+      GNUNET_log_config_missing(GNUNET_ERROR_TYPE_WARNING,
+                                "ATS",
+                                quota_s);
+      GNUNET_free(quota_s);
+      return;
+    }
+  GNUNET_free(quota_s);
   res = GNUNET_NO;
-  if (0 == strcmp (quota_str,
-		   "unlimited"))
-  {
-    *quota = ULONG_MAX;
+  if (0 == strcmp(quota_str,
+                  "unlimited"))
+    {
+      *quota = ULONG_MAX;
+      res = GNUNET_YES;
+    }
+  if ((GNUNET_NO == res) &&
+      (GNUNET_OK ==
+       GNUNET_STRINGS_fancy_size_to_bytes(quota_str,
+                                          quota)))
     res = GNUNET_YES;
-  }
-  if ( (GNUNET_NO == res) &&
-       (GNUNET_OK ==
-	GNUNET_STRINGS_fancy_size_to_bytes (quota_str,
-					    quota)) )
-    res = GNUNET_YES;
-  if ( (GNUNET_NO == res) &&
-       (1 ==
-	sscanf (quota_str,
-		"%llu",
-		quota)) )
+  if ((GNUNET_NO == res) &&
+      (1 ==
+       sscanf(quota_str,
+              "%llu",
+              quota)))
     res = GNUNET_YES;
   if (GNUNET_NO == res)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                _("Could not load %s quota for network `%s': `%s', assigning default bandwidth %llu\n"),
-                direction,
-                nts,
-                quota_str,
-                (unsigned long long) DEFAULT_BANDWIDTH);
-    *quota = DEFAULT_BANDWIDTH;
-  }
-  GNUNET_free (quota_str);
+    {
+      GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
+                 _("Could not load %s quota for network `%s': `%s', assigning default bandwidth %llu\n"),
+                 direction,
+                 nts,
+                 quota_str,
+                 (unsigned long long)DEFAULT_BANDWIDTH);
+      *quota = DEFAULT_BANDWIDTH;
+    }
+  GNUNET_free(quota_str);
 }

Plik diff jest za duży
+ 340 - 348
src/ats/plugin_ats2_simple.c


Plik diff jest za duży
+ 331 - 305
src/ats/plugin_ats_mlp.c


Plik diff jest za duży
+ 353 - 361
src/ats/plugin_ats_proportional.c


Plik diff jest za duży
+ 322 - 324
src/ats/plugin_ats_ril.c


+ 70 - 70
src/ats/test_ats2_lib.c

@@ -14,7 +14,7 @@
 
      You should have received a copy of the GNU Affero General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
-*/
+ */
 /**
  * @file ats/test_ats2_lib.c
  * @brief test ATS library with a generic interpreter for running ATS tests
@@ -76,13 +76,13 @@ static struct GNUNET_ATS_SessionRecord *sr;
  * @return
  */
 static void
-allocation_cb (void *cls,
-               struct GNUNET_ATS_Session *session,
-               struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
-               struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
+allocation_cb(void *cls,
+              struct GNUNET_ATS_Session *session,
+              struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
+              struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
 {
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "allocation_cb() called\n");
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+             "allocation_cb() called\n");
 }
 
 
@@ -96,12 +96,12 @@ allocation_cb (void *cls,
  * @param address
  */
 static void
-suggestion_cb (void *cls,
-               const struct GNUNET_PeerIdentity *pid,
-               const char *address)
+suggestion_cb(void *cls,
+              const struct GNUNET_PeerIdentity *pid,
+              const char *address)
 {
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "suggestion_cb() called\n");
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+             "suggestion_cb() called\n");
   ret = 0;
 }
 
@@ -112,16 +112,16 @@ suggestion_cb (void *cls,
  * Initialises the application and transportation side of ATS.
  */
 static void
-init_both (const struct GNUNET_CONFIGURATION_Handle *cfg)
+init_both(const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
-  ah = GNUNET_ATS_application_init (cfg);
-  GNUNET_assert (NULL != ah);
-  th = GNUNET_ATS_transport_init (cfg,
-                                  &allocation_cb,
-                                  NULL,
-                                  &suggestion_cb,
-                                  NULL);
-  GNUNET_assert (NULL != ah);
+  ah = GNUNET_ATS_application_init(cfg);
+  GNUNET_assert(NULL != ah);
+  th = GNUNET_ATS_transport_init(cfg,
+                                 &allocation_cb,
+                                 NULL,
+                                 &suggestion_cb,
+                                 NULL);
+  GNUNET_assert(NULL != ah);
 }
 
 
@@ -129,11 +129,11 @@ init_both (const struct GNUNET_CONFIGURATION_Handle *cfg)
  * @brief Disconnect both 'sides' of ATS
  */
 static void
-finish_both (void)
+finish_both(void)
 {
-  GNUNET_ATS_application_done (ah);
+  GNUNET_ATS_application_done(ah);
   ah = NULL;
-  GNUNET_ATS_transport_done (th);
+  GNUNET_ATS_transport_done(th);
   th = NULL;
 }
 
@@ -142,7 +142,7 @@ finish_both (void)
  * @brief Provide information about the start of an imaginary connection
  */
 static void
-provide_info_start (void)
+provide_info_start(void)
 {
   struct GNUNET_ATS_Properties prop =
   {
@@ -157,12 +157,12 @@ provide_info_start (void)
     .cc = GNUNET_TRANSPORT_CC_UNKNOWN,
   };
 
-  sr = GNUNET_ATS_session_add (th,
-                               &other_peer,
-                               "test-address",
-                               NULL,
-                               &prop);
-  GNUNET_assert (NULL != sr);
+  sr = GNUNET_ATS_session_add(th,
+                              &other_peer,
+                              "test-address",
+                              NULL,
+                              &prop);
+  GNUNET_assert(NULL != sr);
 }
 
 
@@ -170,9 +170,9 @@ provide_info_start (void)
  * @brief Provide information about the end of an imaginary connection
  */
 static void
-provide_info_end (void)
+provide_info_end(void)
 {
-  GNUNET_ATS_session_del (sr);
+  GNUNET_ATS_session_del(sr);
 }
 
 
@@ -180,24 +180,24 @@ provide_info_end (void)
  * @brief Inform ATS about the need of a connection towards a peer
  */
 static void
-get_suggestion (void)
+get_suggestion(void)
 {
   struct GNUNET_ATS_ApplicationSuggestHandle *ash;
 
-  ash = GNUNET_ATS_application_suggest (ah,
-                                        &other_peer,
-                                        GNUNET_MQ_PREFERENCE_NONE,
-                                        GNUNET_BANDWIDTH_VALUE_MAX);
-  GNUNET_assert (NULL != ash);
+  ash = GNUNET_ATS_application_suggest(ah,
+                                       &other_peer,
+                                       GNUNET_MQ_PREFERENCE_NONE,
+                                       GNUNET_BANDWIDTH_VALUE_MAX);
+  GNUNET_assert(NULL != ash);
 }
 
 
 static void
-on_shutdown (void *cls)
+on_shutdown(void *cls)
 {
-  provide_info_end ();
-  finish_both ();
-  GNUNET_SCHEDULER_shutdown ();
+  provide_info_end();
+  finish_both();
+  GNUNET_SCHEDULER_shutdown();
 }
 
 
@@ -209,16 +209,16 @@ on_shutdown (void *cls)
  * @param peer handle to the peer
  */
 static void
-run (void *cls,
-     const struct GNUNET_CONFIGURATION_Handle *cfg,
-     struct GNUNET_TESTING_Peer *peer)
+run(void *cls,
+    const struct GNUNET_CONFIGURATION_Handle *cfg,
+    struct GNUNET_TESTING_Peer *peer)
 {
-  init_both (cfg);
-  provide_info_start ();
-  get_suggestion ();
-  (void) GNUNET_SCHEDULER_add_delayed (timeout,
-				       &on_shutdown,
-				       NULL);
+  init_both(cfg);
+  provide_info_start();
+  get_suggestion();
+  (void)GNUNET_SCHEDULER_add_delayed(timeout,
+                                     &on_shutdown,
+                                     NULL);
 }
 
 
@@ -231,27 +231,27 @@ run (void *cls,
  * @return
  */
 int
-main (int argc,
-      char *argv[])
+main(int argc,
+     char *argv[])
 {
   ret = 1;
-  memset (&other_peer, 0, sizeof (struct GNUNET_PeerIdentity));
-  timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
-					   2);
-  if (0 != GNUNET_TESTING_peer_run ("test-ats2-lib",
-                                    "test_ats2_lib.conf",
-                                    &run, NULL))
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "Running the testing peer failed.\n");
-    return 1;
-  }
+  memset(&other_peer, 0, sizeof(struct GNUNET_PeerIdentity));
+  timeout = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,
+                                          2);
+  if (0 != GNUNET_TESTING_peer_run("test-ats2-lib",
+                                   "test_ats2_lib.conf",
+                                   &run, NULL))
+    {
+      GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
+                 "Running the testing peer failed.\n");
+      return 1;
+    }
   if (0 != ret)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                "Global status indicates unsuccessful testrun - probably allocation_cb was not called.\n");
-    ret = 77; // SKIP test, test not yet right!
-  }
+    {
+      GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
+                 "Global status indicates unsuccessful testrun - probably allocation_cb was not called.\n");
+      ret = 77; // SKIP test, test not yet right!
+    }
   return ret;
 }
 

+ 6 - 6
src/ats/test_ats2_lib.h

@@ -11,10 +11,10 @@
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      Affero General Public License for more details.
-    
+
      You should have received a copy of the GNU Affero General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
-*/
+ */
 /**
  * @file ats/test_ats_lib.h
  * @brief test ATS library with a generic interpreter for running ATS tests
@@ -515,9 +515,9 @@
  * @return 0 on success
  */
 int
-TEST_ATS_run (int argc,
-              char *argv[],
-              struct Command *cmds,
-              struct GNUNET_TIME_Relative timeout);
+TEST_ATS_run(int argc,
+             char *argv[],
+             struct Command *cmds,
+             struct GNUNET_TIME_Relative timeout);
 
 #endif

+ 11 - 11
src/ats/test_ats_api.c

@@ -11,12 +11,12 @@
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      Affero General Public License for more details.
-    
+
      You should have received a copy of the GNU Affero General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
-*/
+ */
 /**
  * @file ats/test_ats_api.c
  * @brief test ATS
@@ -28,7 +28,7 @@
 /**
  * Global timeout for the testcase.
  */
-#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3)
+#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 3)
 
 /**
  * Definition of the test as a sequence of commands.
@@ -89,7 +89,7 @@ static struct Command test_commands[] = {
     .code = CMD_ADD_SESSION,
     .label = "add-session-0-0-1",
     .details.add_session = {
-      .add_label ="add-address-0-0",
+      .add_label = "add-address-0-0",
       .session = 1
     }
   },
@@ -104,7 +104,7 @@ static struct Command test_commands[] = {
     .code = CMD_CHANGE_PREFERENCE,
     .details.change_preference = {
       .pid = 0
-      /* FIXME: preference details */
+             /* FIXME: preference details */
     }
   },
   {
@@ -233,13 +233,13 @@ static struct Command test_commands[] = {
 
 
 int
-main (int argc,
-      char *argv[])
+main(int argc,
+     char *argv[])
 {
-  return TEST_ATS_run (argc,
-                       argv,
-                       test_commands,
-                       TIMEOUT);
+  return TEST_ATS_run(argc,
+                      argv,
+                      test_commands,
+                      TIMEOUT);
 }
 
 

Plik diff jest za duży
+ 463 - 448
src/ats/test_ats_lib.c


+ 25 - 55
src/ats/test_ats_lib.h

@@ -11,12 +11,12 @@
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      Affero General Public License for more details.
-    
+
      You should have received a copy of the GNU Affero General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
-*/
+ */
 /**
  * @file ats/test_ats_lib.h
  * @brief test ATS library with a generic interpreter for running ATS tests
@@ -33,8 +33,7 @@
 /**
  * Commands for the interpreter.
  */
-enum CommandCode
-{
+enum CommandCode {
   /**
    * End the test (passing).
    */
@@ -123,15 +122,13 @@ enum CommandCode
    * Wait for a bit.
    */
   CMD_SLEEP
-
 };
 
 
 /**
  * Details for the #CMD_ADD_ADDRESS command.
  */
-struct CommandAddAddress
-{
+struct CommandAddAddress {
   /**
    * Number of the peer (used to generate PID).
    */
@@ -172,8 +169,7 @@ struct CommandAddAddress
 /**
  * Details for the #CMD_DEL_ADDRESS command.
  */
-struct CommandDelAddress
-{
+struct CommandDelAddress {
   /**
    * Label of the corresponding #CMD_ADD_ADDRESS that
    * we are now to remove.
@@ -185,8 +181,7 @@ struct CommandDelAddress
 /**
  * Details for the #CMD_AWAIT_ADDRESS_SUGGESTION command.
  */
-struct CommandAwaitAddressSuggestion
-{
+struct CommandAwaitAddressSuggestion {
   /**
    * For which peer do we expect a suggestion?
    */
@@ -198,28 +193,24 @@ struct CommandAwaitAddressSuggestion
    * use NULL for "any" available address.
    */
   const char *add_label;
-
 };
 
 
 /**
  * Details for the #CMD_AWAIT_DISCONNECT_SUGGESTION command.
  */
-struct CommandAwaitDisconnectSuggestion
-{
+struct CommandAwaitDisconnectSuggestion {
   /**
    * For which peer do we expect the disconnect?
    */
   unsigned int pid;
-
 };
 
 
 /**
  * Details for the #CMD_REQUEST_CONNECTION_START command.
  */
-struct CommandRequestConnectionStart
-{
+struct CommandRequestConnectionStart {
   /**
    * Identity of the peer we would like to connect to.
    */
@@ -236,8 +227,7 @@ struct CommandRequestConnectionStart
 /**
  * Details for the #CMD_REQUEST_CONNECTION_STOP command.
  */
-struct CommandRequestConnectionStop
-{
+struct CommandRequestConnectionStop {
   /**
    * Label of the corresponding #CMD_REQUEST_CONNECTION_START that
    * we are now stopping.
@@ -249,8 +239,7 @@ struct CommandRequestConnectionStop
 /**
  * Details for the #CMD_AWAIT_ADDRESS_INFORMATION command.
  */
-struct CommandAwaitAddressInformation
-{
+struct CommandAwaitAddressInformation {
   /**
    * For which address do we expect information?
    * The address is identified by the respective
@@ -264,15 +253,13 @@ struct CommandAwaitAddressInformation
    * the properties from the @e add_label.
    */
   const char *update_label;
-
 };
 
 
 /**
  * Details for the #CMD_UPDATE_ADDRESS command.
  */
-struct CommandUpdateAddress
-{
+struct CommandUpdateAddress {
   /**
    * Label of the addresses's add operation.
    */
@@ -282,16 +269,14 @@ struct CommandUpdateAddress
    * Performance properties to supply.
    */
   struct GNUNET_ATS_Properties properties;
-
 };
 
 
 /**
  * Details for the #CMD_ADD_SESSION command.
  */
-struct CommandAddSession
-{
- /**
+struct CommandAddSession {
+  /**
    * Label of the addresses's add operation.
    */
   const char *add_label;
@@ -300,43 +285,37 @@ struct CommandAddSession
    * Session to supply.
    */
   unsigned int session;
-
 };
 
 
 /**
  * Details for the #CMD_DEL_SESSION command.
  */
-struct CommandDelSession
-{
- /**
+struct CommandDelSession {
+  /**
    * Label of the addresses's add operation.
    */
   const char *add_session_label;
-
 };
 
 
 /**
  * Details for the #CMD_CHANGE_PREFERENCE command.
  */
-struct CommandChangePreference
-{
+struct CommandChangePreference {
   /**
    * Identity of the peer we have a preference change towards.
    */
   unsigned int pid;
 
   /* FIXME: preference details! */
-
 };
 
 
 /**
  * Details for the #CMD_PROVIDE_FEEDBACK command.
  */
-struct CommandProvideFeedback
-{
+struct CommandProvideFeedback {
   /**
    * Identity of the peer we have a feedback for.
    */
@@ -354,8 +333,7 @@ struct CommandProvideFeedback
 /**
  * Details for the #CMD_LIST_ADDRESSES command.
  */
-struct CommandListAddresses
-{
+struct CommandListAddresses {
   /**
    * Identity of the peer we want a list for.
    */
@@ -403,15 +381,13 @@ struct CommandListAddresses
    * #GNUNET_ATS_performance_list_addresses().
    */
   struct GNUNET_ATS_AddressListHandle *alh;
-
 };
 
 
 /**
  * Details for the #CMD_RESERVE_BANDWIDTH command.
  */
-struct CommandReserveBandwidth
-{
+struct CommandReserveBandwidth {
   /**
    * For which peer do we reserve bandwidth?
    */
@@ -435,15 +411,13 @@ struct CommandReserveBandwidth
    * #GNUNET_ATS_reserve_bandwidth().
    */
   struct GNUNET_ATS_ReservationContext *rc;
-
 };
 
 
 /**
  * Details for the #CMD_SLEEP command.
  */
-struct CommandSleep
-{
+struct CommandSleep {
   /**
    * How long should we wait before running the next command?
    */
@@ -454,8 +428,7 @@ struct CommandSleep
 /**
  * A command for the test case interpreter.
  */
-struct Command
-{
+struct Command {
   /**
    * Command code to run.
    */
@@ -470,7 +443,6 @@ struct Command
    * Additional arguments to commands, if any.
    */
   union {
-
     struct CommandAddAddress add_address;
 
     struct CommandDelAddress del_address;
@@ -500,9 +472,7 @@ struct Command
     struct CommandReserveBandwidth reserve_bandwidth;
 
     struct CommandSleep sleep;
-
   } details;
-
 };
 
 
@@ -516,9 +486,9 @@ struct Command
  * @return 0 on success
  */
 int
-TEST_ATS_run (int argc,
-              char *argv[],
-              struct Command *cmds,
-              struct GNUNET_TIME_Relative timeout);
+TEST_ATS_run(int argc,
+             char *argv[],
+             struct Command *cmds,
+             struct GNUNET_TIME_Relative timeout);
 
 #endif

+ 9 - 9
src/ats/test_ats_reservation_api.c

@@ -11,12 +11,12 @@
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      Affero General Public License for more details.
-    
+
      You should have received a copy of the GNU Affero General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
-*/
+ */
 /**
  * @file ats/test_ats_reservation_api.c
  * @brief test ATS bandwidth reservation API
@@ -28,7 +28,7 @@
 /**
  * Global timeout for the testcase.
  */
-#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15)
+#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 15)
 
 /**
  * Definition of the test as a sequence of commands.
@@ -146,13 +146,13 @@ static struct Command test_commands[] = {
 
 
 int
-main (int argc,
-      char *argv[])
+main(int argc,
+     char *argv[])
 {
-  return TEST_ATS_run (argc,
-                       argv,
-                       test_commands,
-                       TIMEOUT);
+  return TEST_ATS_run(argc,
+                      argv,
+                      test_commands,
+                      TIMEOUT);
 }
 
 

+ 3 - 4
src/auction/auction.h

@@ -11,12 +11,12 @@
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      Affero General Public License for more details.
-    
+
      You should have received a copy of the GNU Affero General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
-*/
+ */
 
 /**
  * @author Markus Teich
@@ -34,8 +34,7 @@ GNUNET_NETWORK_STRUCT_BEGIN
 /**
  * Auction creation request sent from the client to the service
  */
-struct GNUNET_AUCTION_ClientCreateMessage
-{
+struct GNUNET_AUCTION_ClientCreateMessage {
   /**
    * Type: GNUNET_MESSAGE_TYPE_AUCTION_CLIENT_CREATE
    */

+ 146 - 146
src/auction/gnunet-auction-create.c

@@ -11,12 +11,12 @@
    WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Affero General Public License for more details.
-  
+
    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
-   */
+ */
 
 /**
  * @file auction/gnunet-auction-create.c
@@ -54,94 +54,94 @@ static int interactive; /** keep running in foreground */
  * @param cfg configuration
  */
 static void
-run (void *cls,
-	 char *const *args,
-	 const char *cfgfile,
-	 const struct GNUNET_CONFIGURATION_Handle *cfg)
+run(void *cls,
+    char *const *args,
+    const char *cfgfile,
+    const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
-	unsigned int i;
-	double cur, prev = DBL_MAX;
-	json_t *pmap;
-	json_t *parray;
-	json_t *pnode;
-	json_error_t jerr;
-
-	/* cmdline parsing */
-	if (GNUNET_TIME_UNIT_ZERO.rel_value_us == dstart.rel_value_us)
-	{
-		GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-		            "required argument --regtime missing or invalid (zero)\n");
-		goto fail;
-	}
-	if (GNUNET_TIME_UNIT_ZERO.rel_value_us == dround.rel_value_us)
-	{
-		GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-		            "required argument --roundtime missing or invalid (zero)\n");
-		goto fail;
-	}
-	if (!fndesc)
-	{
-		GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-		            "required argument --description missing\n");
-		goto fail;
-	}
-	if (!fnprices)
-	{
-		GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-		            "required argument --pricemap missing\n");
-		goto fail;
-	}
-
-	/* parse and check pricemap validity */
-	if (!(pmap = json_load_file (fnprices, JSON_DECODE_INT_AS_REAL, &jerr)))
-	{
-		GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-		            "parsing pricemap json at %d:%d: %s\n",
-		            jerr.line, jerr.column, jerr.text);
-		goto fail;
-	}
-	if (-1 == json_unpack_ex (pmap, &jerr, JSON_VALIDATE_ONLY,
-	                          "{s:s, s:[]}", "currency", "prices"))
-	{
-		GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-		            "validating pricemap: %s\n", jerr.text);
-		goto fail;
-	}
-	if (!(parray = json_object_get (pmap, "prices")) || !json_is_array (parray))
-	{
-		GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-		            "could not get `prices` array node from pricemap\n");
-		goto fail;
-	}
-	if (0 == json_array_size (parray))
-	{
-		GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "empty pricemap array\n");
-		goto fail;
-	}
-	json_array_foreach (parray, i, pnode)
-	{
-		if (-1 == json_unpack_ex (pnode, &jerr, 0, "F", &cur))
-		{
-			GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-			            "validating pricearray index %d: %s\n", i, jerr.text);
-			goto fail;
-		}
-		if (prev <= cur)
-		{
-			GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-			            "validating pricearray index %d: "
-			            "prices must be strictly monotonically decreasing\n",
-			            i);
-			goto fail;
-		}
-		prev = cur;
-	}
-
-	return;
+  unsigned int i;
+  double cur, prev = DBL_MAX;
+  json_t *pmap;
+  json_t *parray;
+  json_t *pnode;
+  json_error_t jerr;
+
+  /* cmdline parsing */
+  if (GNUNET_TIME_UNIT_ZERO.rel_value_us == dstart.rel_value_us)
+    {
+      GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
+                 "required argument --regtime missing or invalid (zero)\n");
+      goto fail;
+    }
+  if (GNUNET_TIME_UNIT_ZERO.rel_value_us == dround.rel_value_us)
+    {
+      GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
+                 "required argument --roundtime missing or invalid (zero)\n");
+      goto fail;
+    }
+  if (!fndesc)
+    {
+      GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
+                 "required argument --description missing\n");
+      goto fail;
+    }
+  if (!fnprices)
+    {
+      GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
+                 "required argument --pricemap missing\n");
+      goto fail;
+    }
+
+  /* parse and check pricemap validity */
+  if (!(pmap = json_load_file(fnprices, JSON_DECODE_INT_AS_REAL, &jerr)))
+    {
+      GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
+                 "parsing pricemap json at %d:%d: %s\n",
+                 jerr.line, jerr.column, jerr.text);
+      goto fail;
+    }
+  if (-1 == json_unpack_ex(pmap, &jerr, JSON_VALIDATE_ONLY,
+                           "{s:s, s:[]}", "currency", "prices"))
+    {
+      GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
+                 "validating pricemap: %s\n", jerr.text);
+      goto fail;
+    }
+  if (!(parray = json_object_get(pmap, "prices")) || !json_is_array(parray))
+    {
+      GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
+                 "could not get `prices` array node from pricemap\n");
+      goto fail;
+    }
+  if (0 == json_array_size(parray))
+    {
+      GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "empty pricemap array\n");
+      goto fail;
+    }
+  json_array_foreach(parray, i, pnode)
+  {
+    if (-1 == json_unpack_ex(pnode, &jerr, 0, "F", &cur))
+      {
+        GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
+                   "validating pricearray index %d: %s\n", i, jerr.text);
+        goto fail;
+      }
+    if (prev <= cur)
+      {
+        GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
+                   "validating pricearray index %d: "
+                   "prices must be strictly monotonically decreasing\n",
+                   i);
+        goto fail;
+      }
+    prev = cur;
+  }
+
+  return;
 
 fail:
-	ret = 1;
-	return;
+  ret = 1;
+  return;
 }
 
 
@@ -153,64 +153,64 @@ fail:
  * @return 0 ok, 1 on error
  */
 int
-main (int argc, char *const *argv)
+main(int argc, char *const *argv)
 {
-	struct GNUNET_GETOPT_CommandLineOption options[] = {
-
-                GNUNET_GETOPT_option_filename ('d',
-                                               "description",
-                                               "FILE",
-                                               gettext_noop ("description of the item to be sold"),
-                                               &fndesc),
-
-                GNUNET_GETOPT_option_filename ('p',
-                                               "pricemap",
-                                               "FILE",
-                                               gettext_noop ("mapping of possible prices"),
-                                               &fnprices),
-
-                GNUNET_GETOPT_option_relative_time ('r',
-                                                        "roundtime",
-                                                        "DURATION",
-                                                        gettext_noop ("max duration per round"),
-                                                        &dround),
-
-                GNUNET_GETOPT_option_relative_time ('s',
-                                                        "regtime",
-                                                        "DURATION",
-                                                        gettext_noop ("duration until auction starts"),
-                                                        &dstart),
-                GNUNET_GETOPT_option_uint ('m',
-                                               "m",
-                                               "NUMBER",
-                                               gettext_noop ("number of items to sell\n"
-                                                             "0 for first price auction\n"
-			                                     ">0 for vickrey/M+1st price auction"),
-                                               &m), 
-
-                GNUNET_GETOPT_option_flag ('u',
-                                              "public",
-                                              gettext_noop ("public auction outcome"),
-                                              &outcome),
-
-                GNUNET_GETOPT_option_flag ('i',
-                                              "interactive",
-                                              gettext_noop ("keep running in foreground until auction completes"),
-                                              &interactive),
-
-		GNUNET_GETOPT_OPTION_END
-	};
-	if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
-		return 2;
-
-	ret = (GNUNET_OK ==
-		   GNUNET_PROGRAM_run (argc, argv,
-							   "gnunet-auction-create",
-							   gettext_noop ("create a new auction and "
-							                 "start listening for bidders"),
-							   options,
-							   &run,
-							   NULL)) ? ret : 1;
-	GNUNET_free ((void*) argv);
-	return ret;
+  struct GNUNET_GETOPT_CommandLineOption options[] = {
+    GNUNET_GETOPT_option_filename('d',
+                                  "description",
+                                  "FILE",
+                                  gettext_noop("description of the item to be sold"),
+                                  &fndesc),
+
+    GNUNET_GETOPT_option_filename('p',
+                                  "pricemap",
+                                  "FILE",
+                                  gettext_noop("mapping of possible prices"),
+                                  &fnprices),
+
+    GNUNET_GETOPT_option_relative_time('r',
+                                       "roundtime",
+                                       "DURATION",
+                                       gettext_noop("max duration per round"),
+                                       &dround),
+
+    GNUNET_GETOPT_option_relative_time('s',
+                                       "regtime",
+                                       "DURATION",
+                                       gettext_noop("duration until auction starts"),
+                                       &dstart),
+    GNUNET_GETOPT_option_uint('m',
+                              "m",
+                              "NUMBER",
+                              gettext_noop("number of items to sell\n"
+                                           "0 for first price auction\n"
+                                           ">0 for vickrey/M+1st price auction"),
+                              &m),
+
+    GNUNET_GETOPT_option_flag('u',
+                              "public",
+                              gettext_noop("public auction outcome"),
+                              &outcome),
+
+    GNUNET_GETOPT_option_flag('i',
+                              "interactive",
+                              gettext_noop("keep running in foreground until auction completes"),
+                              &interactive),
+
+    GNUNET_GETOPT_OPTION_END
+  };
+
+  if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv))
+    return 2;
+
+  ret = (GNUNET_OK ==
+         GNUNET_PROGRAM_run(argc, argv,
+                            "gnunet-auction-create",
+                            gettext_noop("create a new auction and "
+                                         "start listening for bidders"),
+                            options,
+                            &run,
+                            NULL)) ? ret : 1;
+  GNUNET_free((void*)argv);
+  return ret;
 }

+ 17 - 16
src/auction/gnunet-auction-info.c

@@ -11,12 +11,12 @@
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      Affero General Public License for more details.
-    
+
      You should have received a copy of the GNU Affero General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
-*/
+ */
 
 /**
  * @file auction/gnunet-auction.c
@@ -42,10 +42,10 @@ static int ret;
  * @param cfg configuration
  */
 static void
-run (void *cls,
-     char *const *args,
-     const char *cfgfile,
-     const struct GNUNET_CONFIGURATION_Handle *cfg)
+run(void *cls,
+    char *const *args,
+    const char *cfgfile,
+    const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
   /* main code here */
 }
@@ -59,25 +59,26 @@ run (void *cls,
  * @return 0 ok, 1 on error
  */
 int
-main (int argc, char *const *argv)
+main(int argc, char *const *argv)
 {
   static const struct GNUNET_GETOPT_CommandLineOption options[] = {
     /* FIMXE: add options here */
     GNUNET_GETOPT_OPTION_END
   };
+
   if (GNUNET_OK !=
-      GNUNET_STRINGS_get_utf8_args (argc, argv,
-				    &argc, &argv))
+      GNUNET_STRINGS_get_utf8_args(argc, argv,
+                                   &argc, &argv))
     return 2;
 
   ret = (GNUNET_OK ==
-	 GNUNET_PROGRAM_run (argc, argv,
-			     "gnunet-auction",
-			     gettext_noop ("help text"),
-			     options,
-			     &run,
-			     NULL)) ? ret : 1;
-  GNUNET_free ((void*) argv);
+         GNUNET_PROGRAM_run(argc, argv,
+                            "gnunet-auction",
+                            gettext_noop("help text"),
+                            options,
+                            &run,
+                            NULL)) ? ret : 1;
+  GNUNET_free((void*)argv);
   return ret;
 }
 

+ 17 - 16
src/auction/gnunet-auction-join.c

@@ -11,12 +11,12 @@
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      Affero General Public License for more details.
-    
+
      You should have received a copy of the GNU Affero General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
-*/
+ */
 
 /**
  * @file auction/gnunet-auction.c
@@ -42,10 +42,10 @@ static int ret;
  * @param cfg configuration
  */
 static void
-run (void *cls,
-     char *const *args,
-     const char *cfgfile,
-     const struct GNUNET_CONFIGURATION_Handle *cfg)
+run(void *cls,
+    char *const *args,
+    const char *cfgfile,
+    const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
   /* main code here */
 }
@@ -59,25 +59,26 @@ run (void *cls,
  * @return 0 ok, 1 on error
  */
 int
-main (int argc, char *const *argv)
+main(int argc, char *const *argv)
 {
   static const struct GNUNET_GETOPT_CommandLineOption options[] = {
     /* FIMXE: add options here */
     GNUNET_GETOPT_OPTION_END
   };
+
   if (GNUNET_OK !=
-      GNUNET_STRINGS_get_utf8_args (argc, argv,
-				    &argc, &argv))
+      GNUNET_STRINGS_get_utf8_args(argc, argv,
+                                   &argc, &argv))
     return 2;
 
   ret = (GNUNET_OK ==
-	 GNUNET_PROGRAM_run (argc, argv,
-			     "gnunet-auction",
-			     gettext_noop ("help text"),
-			     options,
-			     &run,
-			     NULL)) ? ret : 1;
-  GNUNET_free ((void*) argv);
+         GNUNET_PROGRAM_run(argc, argv,
+                            "gnunet-auction",
+                            gettext_noop("help text"),
+                            options,
+                            &run,
+                            NULL)) ? ret : 1;
+  GNUNET_free((void*)argv);
   return ret;
 }
 

+ 36 - 36
src/auction/gnunet-service-auction.c

@@ -11,12 +11,12 @@
    WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Affero General Public License for more details.
-  
+
    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
-   */
+ */
 
 /**
  * @file auction/gnunet-service-auction.c
@@ -36,10 +36,10 @@
  * @return #GNUNET_OK (always)
  */
 static int
-check_create (void *cls, const struct GNUNET_AUCTION_ClientCreateMessage *msg)
+check_create(void *cls, const struct GNUNET_AUCTION_ClientCreateMessage *msg)
 {
-	/* always well-formed due to arbitrary length description */
-	return GNUNET_OK;
+  /* always well-formed due to arbitrary length description */
+  return GNUNET_OK;
 }
 
 
@@ -50,26 +50,26 @@ check_create (void *cls, const struct GNUNET_AUCTION_ClientCreateMessage *msg)
  * @param msg the actual message received
  */
 static void
-handle_create (void *cls, const struct GNUNET_AUCTION_ClientCreateMessage *msg)
+handle_create(void *cls, const struct GNUNET_AUCTION_ClientCreateMessage *msg)
 {
-	struct GNUNET_SERVICE_Client *client = cls;
+  struct GNUNET_SERVICE_Client *client = cls;
 //	struct GNUNET_MQ_Handle *mq;
 //	struct GNUNET_MQ_Envelope *env;
 //	struct GNUNET_AUCTION_blabla em;
-	uint16_t size;
+  uint16_t size;
 
-	GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-	            "Received CREATE message from client\n");
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+             "Received CREATE message from client\n");
 
-	size = ntohs (msg->header.size);
+  size = ntohs(msg->header.size);
 
-	/**TODO: create auction and return auction object */
+  /**TODO: create auction and return auction object */
 //	mq = GNUNET_SERVICE_client_get_mq (client);
 //	setup_info_message (&em);
 //	env = GNUNET_MQ_msg_copy (&em.header);
 //	GNUNET_MQ_send (mq, env);
 
-	GNUNET_SERVICE_client_continue (client);
+  GNUNET_SERVICE_client_continue(client);
 }
 
 
@@ -79,9 +79,9 @@ handle_create (void *cls, const struct GNUNET_AUCTION_ClientCreateMessage *msg)
  * @param cls unused
  */
 static void
-cleanup_task (void *cls)
+cleanup_task(void *cls)
 {
-	/* FIXME: do clean up here */
+  /* FIXME: do clean up here */
 }
 
 
@@ -94,11 +94,11 @@ cleanup_task (void *cls)
  * @return @a c
  */
 static void *
-client_connect_cb (void *cls,
-                   struct GNUNET_SERVICE_Client *c,
-                   struct GNUNET_MQ_Handle *mq)
+client_connect_cb(void *cls,
+                  struct GNUNET_SERVICE_Client *c,
+                  struct GNUNET_MQ_Handle *mq)
 {
-	return c;
+  return c;
 }
 
 
@@ -110,11 +110,11 @@ client_connect_cb (void *cls,
  * @param internal_cls should be equal to @a c
  */
 static void
-client_disconnect_cb (void *cls,
-                      struct GNUNET_SERVICE_Client *c,
-                      void *internal_cls)
+client_disconnect_cb(void *cls,
+                     struct GNUNET_SERVICE_Client *c,
+                     void *internal_cls)
 {
-	GNUNET_assert (c == internal_cls);
+  GNUNET_assert(c == internal_cls);
 }
 
 
@@ -126,12 +126,12 @@ client_disconnect_cb (void *cls,
  * @param service the initialized service
  */
 static void
-run (void *cls,
-     const struct GNUNET_CONFIGURATION_Handle *cfg,
-     struct GNUNET_SERVICE_Handle *service)
+run(void *cls,
+    const struct GNUNET_CONFIGURATION_Handle *cfg,
+    struct GNUNET_SERVICE_Handle *service)
 {
-	/* FIXME: do setup here */
-	GNUNET_SCHEDULER_add_shutdown (&cleanup_task, NULL);
+  /* FIXME: do setup here */
+  GNUNET_SCHEDULER_add_shutdown(&cleanup_task, NULL);
 }
 
 
@@ -139,17 +139,17 @@ run (void *cls,
  * Define "main" method using service macro.
  */
 GNUNET_SERVICE_MAIN
-("auction",
- GNUNET_SERVICE_OPTION_NONE,
- &run,
- &client_connect_cb,
- &client_disconnect_cb,
- NULL,
- GNUNET_MQ_hd_var_size (create,
+  ("auction",
+  GNUNET_SERVICE_OPTION_NONE,
+  &run,
+  &client_connect_cb,
+  &client_disconnect_cb,
+  NULL,
+  GNUNET_MQ_hd_var_size(create,
                         GNUNET_MESSAGE_TYPE_AUCTION_CLIENT_CREATE,
                         struct GNUNET_AUCTION_ClientCreateMessage,
                         NULL),
- GNUNET_MQ_handler_end ())
+  GNUNET_MQ_handler_end())
 
 
 /* end of gnunet-service-auction.c */

+ 5 - 5
src/auction/test_auction_api.c

@@ -11,12 +11,12 @@
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      Affero General Public License for more details.
-    
+
      You should have received a copy of the GNU Affero General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
-*/
+ */
 /**
  * @file auction/test_auction_api.c
  * @brief testcase for auction.c
@@ -24,17 +24,17 @@
 #include "platform.h"
 
 static int
-check ()
+check()
 {
   return 0;
 }
 
 int
-main (int argc, char *argv[])
+main(int argc, char *argv[])
 {
   int ret;
 
-  ret = check ();
+  ret = check();
 
   return ret;
 }

+ 59 - 61
src/block/bg_bf.c

@@ -11,12 +11,12 @@
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      Affero General Public License for more details.
-    
+
      You should have received a copy of the GNU Affero General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
-*/
+ */
 /**
  * @file block/bg_bf.c
  * @brief implementation of a block group using a Bloom filter
@@ -32,8 +32,7 @@
 /**
  * Internal data structure for a block group.
  */
-struct BfGroupInternals
-{
+struct BfGroupInternals {
   /**
    * A Bloom filter to weed out duplicate replies probabilistically.
    */
@@ -48,7 +47,6 @@ struct BfGroupInternals
    * Size of @a bf.
    */
   uint32_t bf_size;
-
 };
 
 
@@ -63,24 +61,24 @@ struct BfGroupInternals
  *         supported, #GNUNET_SYSERR on error
  */
 static int
-bf_group_serialize_cb (struct GNUNET_BLOCK_Group *bg,
-                       uint32_t *nonce,
-                       void **raw_data,
-                       size_t *raw_data_size)
+bf_group_serialize_cb(struct GNUNET_BLOCK_Group *bg,
+                      uint32_t *nonce,
+                      void **raw_data,
+                      size_t *raw_data_size)
 {
   struct BfGroupInternals *gi = bg->internal_cls;
   char *raw;
 
-  raw = GNUNET_malloc (gi->bf_size);
+  raw = GNUNET_malloc(gi->bf_size);
   if (GNUNET_OK !=
-      GNUNET_CONTAINER_bloomfilter_get_raw_data (gi->bf,
-                                                 raw,
-                                                 gi->bf_size))
-  {
-    GNUNET_free (raw);
-    GNUNET_break (0);
-    return GNUNET_SYSERR;
-  }
+      GNUNET_CONTAINER_bloomfilter_get_raw_data(gi->bf,
+                                                raw,
+                                                gi->bf_size))
+    {
+      GNUNET_free(raw);
+      GNUNET_break(0);
+      return GNUNET_SYSERR;
+    }
   *nonce = gi->bf_mutator;
   *raw_data = raw;
   *raw_data_size = gi->bf_size;
@@ -97,22 +95,22 @@ bf_group_serialize_cb (struct GNUNET_BLOCK_Group *bg,
  * @param seen_results_count number of entries in @a seen_results
  */
 static void
-bf_group_mark_seen_cb (struct GNUNET_BLOCK_Group *bg,
-                       const struct GNUNET_HashCode *seen_results,
-                       unsigned int seen_results_count)
+bf_group_mark_seen_cb(struct GNUNET_BLOCK_Group *bg,
+                      const struct GNUNET_HashCode *seen_results,
+                      unsigned int seen_results_count)
 {
   struct BfGroupInternals *gi = bg->internal_cls;
 
-  for (unsigned int i=0;i<seen_results_count;i++)
-  {
-    struct GNUNET_HashCode mhash;
+  for (unsigned int i = 0; i < seen_results_count; i++)
+    {
+      struct GNUNET_HashCode mhash;
 
-    GNUNET_BLOCK_mingle_hash (&seen_results[i],
-                              gi->bf_mutator,
-                              &mhash);
-    GNUNET_CONTAINER_bloomfilter_add (gi->bf,
-                                      &mhash);
-  }
+      GNUNET_BLOCK_mingle_hash(&seen_results[i],
+                               gi->bf_mutator,
+                               &mhash);
+      GNUNET_CONTAINER_bloomfilter_add(gi->bf,
+                                       &mhash);
+    }
 }
 
 
@@ -126,8 +124,8 @@ bf_group_mark_seen_cb (struct GNUNET_BLOCK_Group *bg,
  *         we failed.
  */
 static int
-bf_group_merge_cb (struct GNUNET_BLOCK_Group *bg1,
-                   const struct GNUNET_BLOCK_Group *bg2)
+bf_group_merge_cb(struct GNUNET_BLOCK_Group *bg1,
+                  const struct GNUNET_BLOCK_Group *bg2)
 {
   struct BfGroupInternals *gi1 = bg1->internal_cls;
   struct BfGroupInternals *gi2 = bg2->internal_cls;
@@ -136,8 +134,8 @@ bf_group_merge_cb (struct GNUNET_BLOCK_Group *bg1,
     return GNUNET_NO;
   if (gi1->bf_size != gi2->bf_size)
     return GNUNET_NO;
-  GNUNET_CONTAINER_bloomfilter_or2 (gi1->bf,
-                                    gi2->bf);
+  GNUNET_CONTAINER_bloomfilter_or2(gi1->bf,
+                                   gi2->bf);
   return GNUNET_OK;
 }
 
@@ -148,13 +146,13 @@ bf_group_merge_cb (struct GNUNET_BLOCK_Group *bg1,
  * @param bg group to destroy, NULL is allowed
  */
 static void
-bf_group_destroy_cb (struct GNUNET_BLOCK_Group *bg)
+bf_group_destroy_cb(struct GNUNET_BLOCK_Group *bg)
 {
   struct BfGroupInternals *gi = bg->internal_cls;
 
-  GNUNET_CONTAINER_bloomfilter_free (gi->bf);
-  GNUNET_free (gi);
-  GNUNET_free (bg);
+  GNUNET_CONTAINER_bloomfilter_free(gi->bf);
+  GNUNET_free(gi);
+  GNUNET_free(bg);
 }
 
 
@@ -172,24 +170,24 @@ bf_group_destroy_cb (struct GNUNET_BLOCK_Group *bg)
  *         by this @a type of block (this is not an error)
  */
 struct GNUNET_BLOCK_Group *
-GNUNET_BLOCK_GROUP_bf_create (void *cls,
-                              size_t bf_size,
-                              unsigned int bf_k,
-                              enum GNUNET_BLOCK_Type type,
-                              uint32_t nonce,
-                              const void *raw_data,
-                              size_t raw_data_size)
+GNUNET_BLOCK_GROUP_bf_create(void *cls,
+                             size_t bf_size,
+                             unsigned int bf_k,
+                             enum GNUNET_BLOCK_Type type,
+                             uint32_t nonce,
+                             const void *raw_data,
+                             size_t raw_data_size)
 {
   struct BfGroupInternals *gi;
   struct GNUNET_BLOCK_Group *bg;
 
-  gi = GNUNET_new (struct BfGroupInternals);
-  gi->bf = GNUNET_CONTAINER_bloomfilter_init ((bf_size != raw_data_size) ? NULL : raw_data,
-                                              bf_size,
-                                              bf_k);
+  gi = GNUNET_new(struct BfGroupInternals);
+  gi->bf = GNUNET_CONTAINER_bloomfilter_init((bf_size != raw_data_size) ? NULL : raw_data,
+                                             bf_size,
+                                             bf_k);
   gi->bf_mutator = nonce;
   gi->bf_size = bf_size;
-  bg = GNUNET_new (struct GNUNET_BLOCK_Group);
+  bg = GNUNET_new(struct GNUNET_BLOCK_Group);
   bg->type = type;
   bg->serialize_cb = &bf_group_serialize_cb;
   bg->mark_seen_cb = &bf_group_mark_seen_cb;
@@ -211,8 +209,8 @@ GNUNET_BLOCK_GROUP_bf_create (void *cls,
  *         #GNUNET_NO if @a hc was definitively not in @bg (but now is)
  */
 int
-GNUNET_BLOCK_GROUP_bf_test_and_set (struct GNUNET_BLOCK_Group *bg,
-                                    const struct GNUNET_HashCode *hc)
+GNUNET_BLOCK_GROUP_bf_test_and_set(struct GNUNET_BLOCK_Group *bg,
+                                   const struct GNUNET_HashCode *hc)
 {
   struct BfGroupInternals *gi;
   struct GNUNET_HashCode mhash;
@@ -220,15 +218,15 @@ GNUNET_BLOCK_GROUP_bf_test_and_set (struct GNUNET_BLOCK_Group *bg,
   if (NULL == bg)
     return GNUNET_NO;
   gi = bg->internal_cls;
-  GNUNET_BLOCK_mingle_hash (hc,
-                            gi->bf_mutator,
-                            &mhash);
+  GNUNET_BLOCK_mingle_hash(hc,
+                           gi->bf_mutator,
+                           &mhash);
   if (GNUNET_YES ==
-      GNUNET_CONTAINER_bloomfilter_test (gi->bf,
-                                         &mhash))
+      GNUNET_CONTAINER_bloomfilter_test(gi->bf,
+                                        &mhash))
     return GNUNET_YES;
-  GNUNET_CONTAINER_bloomfilter_add (gi->bf,
-                                    &mhash);
+  GNUNET_CONTAINER_bloomfilter_add(gi->bf,
+                                   &mhash);
   return GNUNET_NO;
 }
 
@@ -247,8 +245,8 @@ GNUNET_BLOCK_GROUP_bf_test_and_set (struct GNUNET_BLOCK_Group *bg,
  * @return must be a power of two and smaller or equal to 2^15.
  */
 size_t
-GNUNET_BLOCK_GROUP_compute_bloomfilter_size (unsigned int entry_count,
-                                             unsigned int k)
+GNUNET_BLOCK_GROUP_compute_bloomfilter_size(unsigned int entry_count,
+                                            unsigned int k)
 {
   size_t size;
   unsigned int ideal = (entry_count * k) / 4;

+ 126 - 128
src/block/block.c

@@ -11,12 +11,12 @@
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      Affero General Public License for more details.
-    
+
      You should have received a copy of the GNU Affero General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
-*/
+ */
 
 /**
  * @file block/block.c
@@ -34,8 +34,7 @@
 /**
  * Handle for a plugin.
  */
-struct Plugin
-{
+struct Plugin {
   /**
    * Name of the shared library.
    */
@@ -51,8 +50,7 @@ struct Plugin
 /**
  * Handle to an initialized block library.
  */
-struct GNUNET_BLOCK_Context
-{
+struct GNUNET_BLOCK_Context {
   /**
    * Array of our plugins.
    */
@@ -78,18 +76,18 @@ struct GNUNET_BLOCK_Context
  * @param hc where to store the result.
  */
 void
-GNUNET_BLOCK_mingle_hash (const struct GNUNET_HashCode *in,
-			  uint32_t mingle_number,
-                          struct GNUNET_HashCode *hc)
+GNUNET_BLOCK_mingle_hash(const struct GNUNET_HashCode *in,
+                         uint32_t mingle_number,
+                         struct GNUNET_HashCode *hc)
 {
   struct GNUNET_HashCode m;
 
-  GNUNET_CRYPTO_hash (&mingle_number,
-                      sizeof (uint32_t),
-                      &m);
-  GNUNET_CRYPTO_hash_xor (&m,
-                          in,
-                          hc);
+  GNUNET_CRYPTO_hash(&mingle_number,
+                     sizeof(uint32_t),
+                     &m);
+  GNUNET_CRYPTO_hash_xor(&m,
+                         in,
+                         hc);
 }
 
 
@@ -101,23 +99,23 @@ GNUNET_BLOCK_mingle_hash (const struct GNUNET_HashCode *in,
  * @param lib_ret the plugin API
  */
 static void
-add_plugin (void *cls,
-	    const char *library_name,
-	    void *lib_ret)
+add_plugin(void *cls,
+           const char *library_name,
+           void *lib_ret)
 {
   struct GNUNET_BLOCK_Context *ctx = cls;
   struct GNUNET_BLOCK_PluginFunctions *api = lib_ret;
   struct Plugin *plugin;
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-	      "Loading block plugin `%s'\n",
-              library_name);
-  plugin = GNUNET_new (struct Plugin);
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+             "Loading block plugin `%s'\n",
+             library_name);
+  plugin = GNUNET_new(struct Plugin);
   plugin->api = api;
-  plugin->library_name = GNUNET_strdup (library_name);
-  GNUNET_array_append (ctx->plugins,
-                       ctx->num_plugins,
-                       plugin);
+  plugin->library_name = GNUNET_strdup(library_name);
+  GNUNET_array_append(ctx->plugins,
+                      ctx->num_plugins,
+                      plugin);
 }
 
 
@@ -129,16 +127,16 @@ add_plugin (void *cls,
  * @return NULL on error
  */
 struct GNUNET_BLOCK_Context *
-GNUNET_BLOCK_context_create (const struct GNUNET_CONFIGURATION_Handle *cfg)
+GNUNET_BLOCK_context_create(const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
   struct GNUNET_BLOCK_Context *ctx;
 
-  ctx = GNUNET_new (struct GNUNET_BLOCK_Context);
+  ctx = GNUNET_new(struct GNUNET_BLOCK_Context);
   ctx->cfg = cfg;
-  GNUNET_PLUGIN_load_all ("libgnunet_plugin_block_",
-                          (void *) cfg,
-                          &add_plugin,
-                          ctx);
+  GNUNET_PLUGIN_load_all("libgnunet_plugin_block_",
+                         (void *)cfg,
+                         &add_plugin,
+                         ctx);
   return ctx;
 }
 
@@ -149,21 +147,21 @@ GNUNET_BLOCK_context_create (const struct GNUNET_CONFIGURATION_Handle *cfg)
  * @param ctx context to destroy
  */
 void
-GNUNET_BLOCK_context_destroy (struct GNUNET_BLOCK_Context *ctx)
+GNUNET_BLOCK_context_destroy(struct GNUNET_BLOCK_Context *ctx)
 {
   struct Plugin *plugin;
 
   for (unsigned int i = 0; i < ctx->num_plugins; i++)
-  {
-    plugin = ctx->plugins[i];
-    GNUNET_break (NULL ==
-                  GNUNET_PLUGIN_unload (plugin->library_name,
+    {
+      plugin = ctx->plugins[i];
+      GNUNET_break(NULL ==
+                   GNUNET_PLUGIN_unload(plugin->library_name,
                                         plugin->api));
-    GNUNET_free (plugin->library_name);
-    GNUNET_free (plugin);
-  }
-  GNUNET_free (ctx->plugins);
-  GNUNET_free (ctx);
+      GNUNET_free(plugin->library_name);
+      GNUNET_free(plugin);
+    }
+  GNUNET_free(ctx->plugins);
+  GNUNET_free(ctx);
 }
 
 
@@ -178,10 +176,10 @@ GNUNET_BLOCK_context_destroy (struct GNUNET_BLOCK_Context *ctx)
  *         supported, #GNUNET_SYSERR on error
  */
 int
-GNUNET_BLOCK_group_serialize (struct GNUNET_BLOCK_Group *bg,
-                              uint32_t *nonce,
-                              void **raw_data,
-                              size_t *raw_data_size)
+GNUNET_BLOCK_group_serialize(struct GNUNET_BLOCK_Group *bg,
+                             uint32_t *nonce,
+                             void **raw_data,
+                             size_t *raw_data_size)
 {
   *nonce = 0;
   *raw_data = NULL;
@@ -190,10 +188,10 @@ GNUNET_BLOCK_group_serialize (struct GNUNET_BLOCK_Group *bg,
     return GNUNET_NO;
   if (NULL == bg->serialize_cb)
     return GNUNET_NO;
-  return bg->serialize_cb (bg,
-                           nonce,
-                           raw_data,
-                           raw_data_size);
+  return bg->serialize_cb(bg,
+                          nonce,
+                          raw_data,
+                          raw_data_size);
 }
 
 
@@ -203,11 +201,11 @@ GNUNET_BLOCK_group_serialize (struct GNUNET_BLOCK_Group *bg,
  * @param bg group to destroy, NULL is allowed
  */
 void
-GNUNET_BLOCK_group_destroy (struct GNUNET_BLOCK_Group *bg)
+GNUNET_BLOCK_group_destroy(struct GNUNET_BLOCK_Group *bg)
 {
   if (NULL == bg)
     return;
-  bg->destroy_cb (bg);
+  bg->destroy_cb(bg);
 }
 
 
@@ -224,24 +222,24 @@ GNUNET_BLOCK_group_destroy (struct GNUNET_BLOCK_Group *bg)
  *         #GNUNET_SYSERR if merging is not supported
  */
 int
-GNUNET_BLOCK_group_merge (struct GNUNET_BLOCK_Group *bg1,
-                          struct GNUNET_BLOCK_Group *bg2)
+GNUNET_BLOCK_group_merge(struct GNUNET_BLOCK_Group *bg1,
+                         struct GNUNET_BLOCK_Group *bg2)
 {
   int ret;
 
   if (NULL == bg2)
     return GNUNET_OK;
   if (NULL == bg1)
-  {
-    bg2->destroy_cb (bg2);
-    return GNUNET_OK;
-  }
+    {
+      bg2->destroy_cb(bg2);
+      return GNUNET_OK;
+    }
   if (NULL == bg1->merge_cb)
     return GNUNET_SYSERR;
-  GNUNET_assert (bg1->merge_cb == bg1->merge_cb);
-  ret = bg1->merge_cb (bg1,
-                       bg2);
-  bg2->destroy_cb (bg2);
+  GNUNET_assert(bg1->merge_cb == bg1->merge_cb);
+  ret = bg1->merge_cb(bg1,
+                      bg2);
+  bg2->destroy_cb(bg2);
   return ret;
 }
 
@@ -254,23 +252,23 @@ GNUNET_BLOCK_group_merge (struct GNUNET_BLOCK_Group *bg1,
  * @return NULL if no matching plugin exists
  */
 static struct GNUNET_BLOCK_PluginFunctions *
-find_plugin (struct GNUNET_BLOCK_Context *ctx,
-	     enum GNUNET_BLOCK_Type type)
+find_plugin(struct GNUNET_BLOCK_Context *ctx,
+            enum GNUNET_BLOCK_Type type)
 {
   struct Plugin *plugin;
   unsigned int j;
 
   for (unsigned i = 0; i < ctx->num_plugins; i++)
-  {
-    plugin = ctx->plugins[i];
-    j = 0;
-    while (0 != (plugin->api->types[j]))
     {
-      if (type == plugin->api->types[j])
-        return plugin->api;
-      j++;
+      plugin = ctx->plugins[i];
+      j = 0;
+      while (0 != (plugin->api->types[j]))
+        {
+          if (type == plugin->api->types[j])
+            return plugin->api;
+          j++;
+        }
     }
-  }
   return NULL;
 }
 
@@ -287,32 +285,32 @@ find_plugin (struct GNUNET_BLOCK_Context *ctx,
  *         by this @a type of block (this is not an error)
  */
 struct GNUNET_BLOCK_Group *
-GNUNET_BLOCK_group_create (struct GNUNET_BLOCK_Context *ctx,
-                           enum GNUNET_BLOCK_Type type,
-                           uint32_t nonce,
-                           const void *raw_data,
-                           size_t raw_data_size,
-                           ...)
+GNUNET_BLOCK_group_create(struct GNUNET_BLOCK_Context *ctx,
+                          enum GNUNET_BLOCK_Type type,
+                          uint32_t nonce,
+                          const void *raw_data,
+                          size_t raw_data_size,
+                          ...)
 {
   struct GNUNET_BLOCK_PluginFunctions *plugin;
   struct GNUNET_BLOCK_Group *bg;
   va_list ap;
 
-  plugin = find_plugin (ctx,
-                        type);
+  plugin = find_plugin(ctx,
+                       type);
   if (NULL == plugin)
     return NULL;
   if (NULL == plugin->create_group)
     return NULL;
-  va_start (ap,
-            raw_data_size);
-  bg = plugin->create_group (plugin->cls,
-                             type,
-                             nonce,
-                             raw_data,
-                             raw_data_size,
-                             ap);
-  va_end (ap);
+  va_start(ap,
+           raw_data_size);
+  bg = plugin->create_group(plugin->cls,
+                            type,
+                            nonce,
+                            raw_data,
+                            raw_data_size,
+                            ap);
+  va_end(ap);
   return bg;
 }
 
@@ -336,31 +334,31 @@ GNUNET_BLOCK_group_create (struct GNUNET_BLOCK_Context *ctx,
  * @return characterization of result
  */
 enum GNUNET_BLOCK_EvaluationResult
-GNUNET_BLOCK_evaluate (struct GNUNET_BLOCK_Context *ctx,
-                       enum GNUNET_BLOCK_Type type,
-                       struct GNUNET_BLOCK_Group *group,
-                       enum GNUNET_BLOCK_EvaluationOptions eo,
-                       const struct GNUNET_HashCode *query,
-                       const void *xquery,
-                       size_t xquery_size,
-                       const void *reply_block,
-                       size_t reply_block_size)
+GNUNET_BLOCK_evaluate(struct GNUNET_BLOCK_Context *ctx,
+                      enum GNUNET_BLOCK_Type type,
+                      struct GNUNET_BLOCK_Group *group,
+                      enum GNUNET_BLOCK_EvaluationOptions eo,
+                      const struct GNUNET_HashCode *query,
+                      const void *xquery,
+                      size_t xquery_size,
+                      const void *reply_block,
+                      size_t reply_block_size)
 {
-  struct GNUNET_BLOCK_PluginFunctions *plugin = find_plugin (ctx,
-                                                             type);
+  struct GNUNET_BLOCK_PluginFunctions *plugin = find_plugin(ctx,
+                                                            type);
 
   if (NULL == plugin)
     return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
-  return plugin->evaluate (plugin->cls,
-                           ctx,
-                           type,
-                           group,
-                           eo,
-                           query,
-                           xquery,
-                           xquery_size,
-                           reply_block,
-                           reply_block_size);
+  return plugin->evaluate(plugin->cls,
+                          ctx,
+                          type,
+                          group,
+                          eo,
+                          query,
+                          xquery,
+                          xquery_size,
+                          reply_block,
+                          reply_block_size);
 }
 
 
@@ -376,22 +374,22 @@ GNUNET_BLOCK_evaluate (struct GNUNET_BLOCK_Context *ctx,
  *         (or if extracting a key from a block of this type does not work)
  */
 int
-GNUNET_BLOCK_get_key (struct GNUNET_BLOCK_Context *ctx,
-                      enum GNUNET_BLOCK_Type type,
-                      const void *block,
-                      size_t block_size,
-                      struct GNUNET_HashCode *key)
+GNUNET_BLOCK_get_key(struct GNUNET_BLOCK_Context *ctx,
+                     enum GNUNET_BLOCK_Type type,
+                     const void *block,
+                     size_t block_size,
+                     struct GNUNET_HashCode *key)
 {
-  struct GNUNET_BLOCK_PluginFunctions *plugin = find_plugin (ctx,
-                                                             type);
+  struct GNUNET_BLOCK_PluginFunctions *plugin = find_plugin(ctx,
+                                                            type);
 
   if (plugin == NULL)
     return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
-  return plugin->get_key (plugin->cls,
-                          type,
-                          block,
-                          block_size,
-                          key);
+  return plugin->get_key(plugin->cls,
+                         type,
+                         block,
+                         block_size,
+                         key);
 }
 
 
@@ -407,17 +405,17 @@ GNUNET_BLOCK_get_key (struct GNUNET_BLOCK_Context *ctx,
  * @return #GNUNET_SYSERR if not supported, #GNUNET_OK on success
  */
 int
-GNUNET_BLOCK_group_set_seen (struct GNUNET_BLOCK_Group *bg,
-                             const struct GNUNET_HashCode *seen_results,
-                             unsigned int seen_results_count)
+GNUNET_BLOCK_group_set_seen(struct GNUNET_BLOCK_Group *bg,
+                            const struct GNUNET_HashCode *seen_results,
+                            unsigned int seen_results_count)
 {
   if (NULL == bg)
     return GNUNET_OK;
   if (NULL == bg->mark_seen_cb)
     return GNUNET_SYSERR;
-  bg->mark_seen_cb (bg,
-                    seen_results,
-                    seen_results_count);
+  bg->mark_seen_cb(bg,
+                   seen_results,
+                   seen_results_count);
   return GNUNET_OK;
 }
 

+ 52 - 52
src/block/plugin_block_template.c

@@ -11,12 +11,12 @@
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      Affero General Public License for more details.
-    
+
      You should have received a copy of the GNU Affero General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
-*/
+ */
 
 /**
  * @file block/plugin_block_template.c
@@ -56,37 +56,37 @@
  *         by this @a type of block (this is not an error)
  */
 static struct GNUNET_BLOCK_Group *
-block_plugin_template_create_group (void *cls,
-                                    enum GNUNET_BLOCK_Type type,
-                                    uint32_t nonce,
-                                    const void *raw_data,
-                                    size_t raw_data_size,
-                                    va_list va)
+block_plugin_template_create_group(void *cls,
+                                   enum GNUNET_BLOCK_Type type,
+                                   uint32_t nonce,
+                                   const void *raw_data,
+                                   size_t raw_data_size,
+                                   va_list va)
 {
   unsigned int bf_size;
   const char *guard;
 
-  guard = va_arg (va, const char *);
-  if (0 == strcmp (guard,
-                   "seen-set-size"))
-    bf_size = GNUNET_BLOCK_GROUP_compute_bloomfilter_size (va_arg (va, unsigned int),
-                                                           BLOOMFILTER_K);
-  else if (0 == strcmp (guard,
-                        "filter-size"))
-    bf_size = va_arg (va, unsigned int);
+  guard = va_arg(va, const char *);
+  if (0 == strcmp(guard,
+                  "seen-set-size"))
+    bf_size = GNUNET_BLOCK_GROUP_compute_bloomfilter_size(va_arg(va, unsigned int),
+                                                          BLOOMFILTER_K);
+  else if (0 == strcmp(guard,
+                       "filter-size"))
+    bf_size = va_arg(va, unsigned int);
   else
-  {
-    GNUNET_break (0);
-    bf_size = TEMPLATE_BF_SIZE;
-  }
-  GNUNET_break (NULL == va_arg (va, const char *));
-  return GNUNET_BLOCK_GROUP_bf_create (cls,
-                                       bf_size,
-                                       BLOOMFILTER_K,
-                                       type,
-                                       nonce,
-                                       raw_data,
-                                       raw_data_size);
+    {
+      GNUNET_break(0);
+      bf_size = TEMPLATE_BF_SIZE;
+    }
+  GNUNET_break(NULL == va_arg(va, const char *));
+  return GNUNET_BLOCK_GROUP_bf_create(cls,
+                                      bf_size,
+                                      BLOOMFILTER_K,
+                                      type,
+                                      nonce,
+                                      raw_data,
+                                      raw_data_size);
 }
 
 
@@ -107,27 +107,27 @@ block_plugin_template_create_group (void *cls,
  * @return characterization of result
  */
 static enum GNUNET_BLOCK_EvaluationResult
-block_plugin_template_evaluate (void *cls,
-                                struct GNUNET_BLOCK_Context *ctx,
-                                enum GNUNET_BLOCK_Type type,
-                                struct GNUNET_BLOCK_Group *group,
-                                enum GNUNET_BLOCK_EvaluationOptions eo,
-                                const struct GNUNET_HashCode *query,
-                                const void *xquery,
-                                size_t xquery_size,
-                                const void *reply_block,
-                                size_t reply_block_size)
+block_plugin_template_evaluate(void *cls,
+                               struct GNUNET_BLOCK_Context *ctx,
+                               enum GNUNET_BLOCK_Type type,
+                               struct GNUNET_BLOCK_Group *group,
+                               enum GNUNET_BLOCK_EvaluationOptions eo,
+                               const struct GNUNET_HashCode *query,
+                               const void *xquery,
+                               size_t xquery_size,
+                               const void *reply_block,
+                               size_t reply_block_size)
 {
   struct GNUNET_HashCode chash;
 
   if (NULL == reply_block)
     return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
-  GNUNET_CRYPTO_hash (reply_block,
-                      reply_block_size,
-                      &chash);
+  GNUNET_CRYPTO_hash(reply_block,
+                     reply_block_size,
+                     &chash);
   if (GNUNET_YES ==
-      GNUNET_BLOCK_GROUP_bf_test_and_set (group,
-                                          &chash))
+      GNUNET_BLOCK_GROUP_bf_test_and_set(group,
+                                         &chash))
     return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE;
   return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
 }
@@ -145,11 +145,11 @@ block_plugin_template_evaluate (void *cls,
  *         (or if extracting a key from a block of this type does not work)
  */
 static int
-block_plugin_template_get_key (void *cls,
-                               enum GNUNET_BLOCK_Type type,
-                               const void *block,
-                               size_t block_size,
-			       struct GNUNET_HashCode *key)
+block_plugin_template_get_key(void *cls,
+                              enum GNUNET_BLOCK_Type type,
+                              const void *block,
+                              size_t block_size,
+                              struct GNUNET_HashCode *key)
 {
   return GNUNET_SYSERR;
 }
@@ -161,7 +161,7 @@ block_plugin_template_get_key (void *cls,
  * @param cls a `const struct GNUNET_CONFIGURATION_Handle`
  */
 void *
-libgnunet_plugin_block_template_init (void *cls)
+libgnunet_plugin_block_template_init(void *cls)
 {
   static enum GNUNET_BLOCK_Type types[] =
   {
@@ -170,7 +170,7 @@ libgnunet_plugin_block_template_init (void *cls)
   };
   struct GNUNET_BLOCK_PluginFunctions *api;
 
-  api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions);
+  api = GNUNET_new(struct GNUNET_BLOCK_PluginFunctions);
   api->evaluate = &block_plugin_template_evaluate;
   api->get_key = &block_plugin_template_get_key;
   api->create_group = &block_plugin_template_create_group;
@@ -183,11 +183,11 @@ libgnunet_plugin_block_template_init (void *cls)
  * Exit point from the plugin.
  */
 void *
-libgnunet_plugin_block_template_done (void *cls)
+libgnunet_plugin_block_template_done(void *cls)
 {
   struct GNUNET_BLOCK_PluginFunctions *api = cls;
 
-  GNUNET_free (api);
+  GNUNET_free(api);
   return NULL;
 }
 

+ 61 - 61
src/block/plugin_block_test.c

@@ -11,12 +11,12 @@
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      Affero General Public License for more details.
-    
+
      You should have received a copy of the GNU Affero General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
-*/
+ */
 
 /**
  * @file block/plugin_block_test.c
@@ -54,37 +54,37 @@
  *         by this @a type of block (this is not an error)
  */
 static struct GNUNET_BLOCK_Group *
-block_plugin_test_create_group (void *cls,
-                                enum GNUNET_BLOCK_Type type,
-                                uint32_t nonce,
-                                const void *raw_data,
-                                size_t raw_data_size,
-                                va_list va)
+block_plugin_test_create_group(void *cls,
+                               enum GNUNET_BLOCK_Type type,
+                               uint32_t nonce,
+                               const void *raw_data,
+                               size_t raw_data_size,
+                               va_list va)
 {
   unsigned int bf_size;
   const char *guard;
 
-  guard = va_arg (va, const char *);
-  if (0 == strcmp (guard,
-                   "seen-set-size"))
-    bf_size = GNUNET_BLOCK_GROUP_compute_bloomfilter_size (va_arg (va, unsigned int),
-                                                           BLOOMFILTER_K);
-  else if (0 == strcmp (guard,
-                        "filter-size"))
-    bf_size = va_arg (va, unsigned int);
+  guard = va_arg(va, const char *);
+  if (0 == strcmp(guard,
+                  "seen-set-size"))
+    bf_size = GNUNET_BLOCK_GROUP_compute_bloomfilter_size(va_arg(va, unsigned int),
+                                                          BLOOMFILTER_K);
+  else if (0 == strcmp(guard,
+                       "filter-size"))
+    bf_size = va_arg(va, unsigned int);
   else
-  {
-    GNUNET_break (0);
-    bf_size = TEST_BF_SIZE;
-  }
-  GNUNET_break (NULL == va_arg (va, const char *));
-  return GNUNET_BLOCK_GROUP_bf_create (cls,
-                                       bf_size,
-                                       BLOOMFILTER_K,
-                                       type,
-                                       nonce,
-                                       raw_data,
-                                       raw_data_size);
+    {
+      GNUNET_break(0);
+      bf_size = TEST_BF_SIZE;
+    }
+  GNUNET_break(NULL == va_arg(va, const char *));
+  return GNUNET_BLOCK_GROUP_bf_create(cls,
+                                      bf_size,
+                                      BLOOMFILTER_K,
+                                      type,
+                                      nonce,
+                                      raw_data,
+                                      raw_data_size);
 }
 
 
@@ -105,37 +105,37 @@ block_plugin_test_create_group (void *cls,
  * @return characterization of result
  */
 static enum GNUNET_BLOCK_EvaluationResult
-block_plugin_test_evaluate (void *cls,
-                            struct GNUNET_BLOCK_Context *ctx,
-                            enum GNUNET_BLOCK_Type type,
-                            struct GNUNET_BLOCK_Group *group,
-                            enum GNUNET_BLOCK_EvaluationOptions eo,
-                            const struct GNUNET_HashCode *query,
-                            const void *xquery,
-                            size_t xquery_size,
-                            const void *reply_block,
-                            size_t reply_block_size)
+block_plugin_test_evaluate(void *cls,
+                           struct GNUNET_BLOCK_Context *ctx,
+                           enum GNUNET_BLOCK_Type type,
+                           struct GNUNET_BLOCK_Group *group,
+                           enum GNUNET_BLOCK_EvaluationOptions eo,
+                           const struct GNUNET_HashCode *query,
+                           const void *xquery,
+                           size_t xquery_size,
+                           const void *reply_block,
+                           size_t reply_block_size)
 {
   struct GNUNET_HashCode chash;
 
-  if ( GNUNET_BLOCK_TYPE_TEST != type)
-  {
-    GNUNET_break (0);
-    return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
-  }
+  if (GNUNET_BLOCK_TYPE_TEST != type)
+    {
+      GNUNET_break(0);
+      return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
+    }
   if (0 != xquery_size)
-  {
-    GNUNET_break_op (0);
-    return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
-  }
+    {
+      GNUNET_break_op(0);
+      return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
+    }
   if (NULL == reply_block)
     return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
-  GNUNET_CRYPTO_hash (reply_block,
-                      reply_block_size,
-                      &chash);
+  GNUNET_CRYPTO_hash(reply_block,
+                     reply_block_size,
+                     &chash);
   if (GNUNET_YES ==
-      GNUNET_BLOCK_GROUP_bf_test_and_set (group,
-                                          &chash))
+      GNUNET_BLOCK_GROUP_bf_test_and_set(group,
+                                         &chash))
     return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE;
   return GNUNET_BLOCK_EVALUATION_OK_MORE;
 }
@@ -153,11 +153,11 @@ block_plugin_test_evaluate (void *cls,
  *         (or if extracting a key from a block of this type does not work)
  */
 static int
-block_plugin_test_get_key (void *cls,
-                           enum GNUNET_BLOCK_Type type,
-                           const void *block,
-                           size_t block_size,
-                           struct GNUNET_HashCode *key)
+block_plugin_test_get_key(void *cls,
+                          enum GNUNET_BLOCK_Type type,
+                          const void *block,
+                          size_t block_size,
+                          struct GNUNET_HashCode *key)
 {
   /* always fails since there is no fixed relationship between
    * keys and values for test values */
@@ -172,7 +172,7 @@ block_plugin_test_get_key (void *cls,
  * @return the exported block API
  */
 void *
-libgnunet_plugin_block_test_init (void *cls)
+libgnunet_plugin_block_test_init(void *cls)
 {
   static enum GNUNET_BLOCK_Type types[] =
   {
@@ -181,7 +181,7 @@ libgnunet_plugin_block_test_init (void *cls)
   };
   struct GNUNET_BLOCK_PluginFunctions *api;
 
-  api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions);
+  api = GNUNET_new(struct GNUNET_BLOCK_PluginFunctions);
   api->evaluate = &block_plugin_test_evaluate;
   api->get_key = &block_plugin_test_get_key;
   api->create_group = &block_plugin_test_create_group;
@@ -197,11 +197,11 @@ libgnunet_plugin_block_test_init (void *cls)
  * @return NULL
  */
 void *
-libgnunet_plugin_block_test_done (void *cls)
+libgnunet_plugin_block_test_done(void *cls)
 {
   struct GNUNET_BLOCK_PluginFunctions *api = cls;
 
-  GNUNET_free (api);
+  GNUNET_free(api);
   return NULL;
 }
 

+ 27 - 40
src/cadet/cadet.h

@@ -16,7 +16,7 @@
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
-*/
+ */
 
 /**
  * @author Bartlomiej Polot
@@ -35,18 +35,18 @@ extern "C" {
 
 #include <stdint.h>
 
-#if ! defined(GNUNET_CULL_LOGGING)
+#if !defined(GNUNET_CULL_LOGGING)
 #define CADET_TIMING_START                 \
   struct GNUNET_TIME_Absolute __timestamp; \
-  __timestamp = GNUNET_TIME_absolute_get ()
+  __timestamp = GNUNET_TIME_absolute_get()
 
 #define CADET_TIMING_END                                        \
   struct GNUNET_TIME_Relative __duration;                       \
-  __duration = GNUNET_TIME_absolute_get_duration (__timestamp); \
-  LOG (GNUNET_ERROR_TYPE_INFO,                                  \
-       " %s duration %s\n",                                     \
-       __FUNCTION__,                                            \
-       GNUNET_STRINGS_relative_time_to_string (__duration, GNUNET_YES));
+  __duration = GNUNET_TIME_absolute_get_duration(__timestamp); \
+  LOG(GNUNET_ERROR_TYPE_INFO,                                  \
+      " %s duration %s\n",                                     \
+      __FUNCTION__,                                            \
+      GNUNET_STRINGS_relative_time_to_string(__duration, GNUNET_YES));
 #else
 #define CADET_TIMING_START
 #define CADET_TIMING_END
@@ -99,8 +99,7 @@ GNUNET_NETWORK_STRUCT_BEGIN
 /**
  * Number uniquely identifying a channel of a client.
  */
-struct GNUNET_CADET_ClientChannelNumber
-{
+struct GNUNET_CADET_ClientChannelNumber {
   /**
    * Values for channel numbering.
    * Local channel numbers given by the service (incoming) are
@@ -115,8 +114,7 @@ struct GNUNET_CADET_ClientChannelNumber
 /**
  * Message for a client to create and destroy channels.
  */
-struct GNUNET_CADET_PortMessage
-{
+struct GNUNET_CADET_PortMessage {
   /**
    * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_OPEN
    * or #GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_CLOSE
@@ -135,8 +133,7 @@ struct GNUNET_CADET_PortMessage
 /**
  * Message for a client to create channels.
  */
-struct GNUNET_CADET_LocalChannelCreateMessage
-{
+struct GNUNET_CADET_LocalChannelCreateMessage {
   /**
    * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_CREATE
    *
@@ -169,8 +166,7 @@ struct GNUNET_CADET_LocalChannelCreateMessage
 /**
  * Message for or to a client to destroy tunnel.
  */
-struct GNUNET_CADET_LocalChannelDestroyMessage
-{
+struct GNUNET_CADET_LocalChannelDestroyMessage {
   /**
    * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY
    */
@@ -186,8 +182,7 @@ struct GNUNET_CADET_LocalChannelDestroyMessage
 /**
  * Message for cadet data traffic.
  */
-struct GNUNET_CADET_LocalData
-{
+struct GNUNET_CADET_LocalData {
   /**
    * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA
    */
@@ -214,8 +209,7 @@ struct GNUNET_CADET_LocalData
  * Message to allow the client send more data to the service
  * (always service -> client).
  */
-struct GNUNET_CADET_LocalAck
-{
+struct GNUNET_CADET_LocalAck {
   /**
    * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK
    */
@@ -233,8 +227,7 @@ struct GNUNET_CADET_LocalAck
  *
  * TODO: split into two messages!
  */
-struct GNUNET_CADET_LocalInfo
-{
+struct GNUNET_CADET_LocalInfo {
   /**
    * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNEL or
    * #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEER
@@ -256,8 +249,7 @@ struct GNUNET_CADET_LocalInfo
 /**
  * Message to inform the client about channels in the service.
  */
-struct GNUNET_CADET_RequestPathInfoMessage
-{
+struct GNUNET_CADET_RequestPathInfoMessage {
   /**
    * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_PATH
    */
@@ -278,8 +270,7 @@ struct GNUNET_CADET_RequestPathInfoMessage
 /**
  * Message to inform the client about channels in the service.
  */
-struct GNUNET_CADET_ChannelInfoMessage
-{
+struct GNUNET_CADET_ChannelInfoMessage {
   /**
    * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_CHANNEL.
    */
@@ -302,8 +293,7 @@ struct GNUNET_CADET_ChannelInfoMessage
 /**
  * Message to as the service about information on a channel.
  */
-struct GNUNET_CADET_RequestChannelInfoMessage
-{
+struct GNUNET_CADET_RequestChannelInfoMessage {
   /**
    * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_CHANNEL.
    */
@@ -319,8 +309,7 @@ struct GNUNET_CADET_RequestChannelInfoMessage
 /**
  * Message to inform the client about one of the paths known to the service.
  */
-struct GNUNET_CADET_LocalInfoPath
-{
+struct GNUNET_CADET_LocalInfoPath {
   /**
    * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PATH.
    */
@@ -336,8 +325,7 @@ struct GNUNET_CADET_LocalInfoPath
 /**
  * Message to inform the client about one of the peers in the service.
  */
-struct GNUNET_CADET_LocalInfoPeers
-{
+struct GNUNET_CADET_LocalInfoPeers {
   /**
    * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS
    */
@@ -370,8 +358,7 @@ struct GNUNET_CADET_LocalInfoPeers
  *
  * TODO: split into two messages!
  */
-struct GNUNET_CADET_LocalInfoTunnel
-{
+struct GNUNET_CADET_LocalInfoTunnel {
   /**
    * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNEL
    * or #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS
@@ -419,7 +406,7 @@ GNUNET_NETWORK_STRUCT_END
  * @return String representing FWD or BCK.
  */
 char *
-GC_f2s (int fwd);
+GC_f2s(int fwd);
 
 
 /**
@@ -431,7 +418,7 @@ GC_f2s (int fwd);
  * @return True if bigger (arg1) has a higher value than smaller (arg 2).
  */
 int
-GC_is_pid_bigger (uint32_t bigger, uint32_t smaller);
+GC_is_pid_bigger(uint32_t bigger, uint32_t smaller);
 
 
 /**
@@ -443,7 +430,7 @@ GC_is_pid_bigger (uint32_t bigger, uint32_t smaller);
  * @return Highest ACK value from the two.
  */
 uint32_t
-GC_max_pid (uint32_t a, uint32_t b);
+GC_max_pid(uint32_t a, uint32_t b);
 
 
 /**
@@ -455,7 +442,7 @@ GC_max_pid (uint32_t a, uint32_t b);
  * @return Lowest ACK value from the two.
  */
 uint32_t
-GC_min_pid (uint32_t a, uint32_t b);
+GC_min_pid(uint32_t a, uint32_t b);
 
 
 /**
@@ -468,7 +455,7 @@ GC_min_pid (uint32_t a, uint32_t b);
  * @return The size of the output.
  */
 size_t
-GC_bin2s (void *bin, unsigned int len, char **output);
+GC_bin2s(void *bin, unsigned int len, char **output);
 
 
 /**
@@ -482,7 +469,7 @@ GC_bin2s (void *bin, unsigned int len, char **output);
  * @return Human readable string description.
  */
 const char *
-GC_m2s (uint16_t m);
+GC_m2s(uint16_t m);
 
 #if 0 /* keep Emacsens' auto-indent happy */
 {

Plik diff jest za duży
+ 319 - 323
src/cadet/cadet_api.c


+ 68 - 71
src/cadet/cadet_api_get_channel.c

@@ -11,12 +11,12 @@
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      Affero General Public License for more details.
-    
+
      You should have received a copy of the GNU Affero General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
-*/
+ */
 /**
  * @file cadet/cadet_api_get_channel.c
  * @brief cadet api: client implementation of cadet service
@@ -34,9 +34,7 @@
 /**
  * Operation handle.
  */
-struct GNUNET_CADET_ChannelMonitor
-{
-
+struct GNUNET_CADET_ChannelMonitor {
   /**
    * Channel callback.
    */
@@ -56,7 +54,7 @@ struct GNUNET_CADET_ChannelMonitor
    * Message queue to talk to CADET service.
    */
   struct GNUNET_MQ_Handle *mq;
-  
+
   /**
    * Task to reconnect.
    */
@@ -71,7 +69,6 @@ struct GNUNET_CADET_ChannelMonitor
    * Peer we want information about.
    */
   struct GNUNET_PeerIdentity peer;
-
 };
 
 
@@ -84,11 +81,11 @@ struct GNUNET_CADET_ChannelMonitor
  *         #GNUNET_SYSERR otherwise
  */
 static int
-check_channel_info (void *cls,
-		    const struct GNUNET_CADET_ChannelInfoMessage *message)
+check_channel_info(void *cls,
+                   const struct GNUNET_CADET_ChannelInfoMessage *message)
 {
-  (void) cls;
-  
+  (void)cls;
+
   return GNUNET_OK;
 }
 
@@ -96,39 +93,39 @@ check_channel_info (void *cls,
 /**
  * Process a local peer info reply, pass info to the user.
  *
- * @param cls Closure 
+ * @param cls Closure
  * @param message Message itself.
  */
 static void
-handle_channel_info (void *cls,
-		     const struct GNUNET_CADET_ChannelInfoMessage *message)
+handle_channel_info(void *cls,
+                    const struct GNUNET_CADET_ChannelInfoMessage *message)
 {
   struct GNUNET_CADET_ChannelMonitor *cm = cls;
   struct GNUNET_CADET_ChannelInternals ci;
 
   ci.root = message->root;
   ci.dest = message->dest;
-  cm->channel_cb (cm->channel_cb_cls,
-		  &ci);
-  GNUNET_CADET_get_channel_cancel (cm);
+  cm->channel_cb(cm->channel_cb_cls,
+                 &ci);
+  GNUNET_CADET_get_channel_cancel(cm);
 }
 
 
 /**
  * Process a local peer info reply, pass info to the user.
  *
- * @param cls Closure 
+ * @param cls Closure
  * @param message Message itself.
  */
 static void
-handle_channel_info_end (void *cls,
-			 const struct GNUNET_MessageHeader *message)
+handle_channel_info_end(void *cls,
+                        const struct GNUNET_MessageHeader *message)
 {
   struct GNUNET_CADET_ChannelMonitor *cm = cls;
 
-  cm->channel_cb (cm->channel_cb_cls,
-		  NULL);
-  GNUNET_CADET_get_channel_cancel (cm);
+  cm->channel_cb(cm->channel_cb_cls,
+                 NULL);
+  GNUNET_CADET_get_channel_cancel(cm);
 }
 
 
@@ -138,7 +135,7 @@ handle_channel_info_end (void *cls,
  * @param cls a `struct GNUNET_CADET_ChannelMonitor` operation
  */
 static void
-reconnect (void *cls);
+reconnect(void *cls);
 
 
 /**
@@ -148,18 +145,18 @@ reconnect (void *cls);
  * @param error error code from MQ
  */
 static void
-error_handler (void *cls,
-	       enum GNUNET_MQ_Error error)
+error_handler(void *cls,
+              enum GNUNET_MQ_Error error)
 {
   struct GNUNET_CADET_ChannelMonitor *cm = cls;
 
-  GNUNET_MQ_destroy (cm->mq);
+  GNUNET_MQ_destroy(cm->mq);
   cm->mq = NULL;
-  cm->backoff = GNUNET_TIME_randomized_backoff (cm->backoff,
-						GNUNET_TIME_UNIT_MINUTES);
-  cm->reconnect_task = GNUNET_SCHEDULER_add_delayed (cm->backoff,
-						     &reconnect,
-						     cm);
+  cm->backoff = GNUNET_TIME_randomized_backoff(cm->backoff,
+                                               GNUNET_TIME_UNIT_MINUTES);
+  cm->reconnect_task = GNUNET_SCHEDULER_add_delayed(cm->backoff,
+                                                    &reconnect,
+                                                    cm);
 }
 
 
@@ -169,36 +166,36 @@ error_handler (void *cls,
  * @param cls a `struct GNUNET_CADET_ChannelMonitor` operation
  */
 static void
-reconnect (void *cls)
+reconnect(void *cls)
 {
   struct GNUNET_CADET_ChannelMonitor *cm = cls;
   struct GNUNET_MQ_MessageHandler handlers[] = {
-    GNUNET_MQ_hd_fixed_size (channel_info_end,
-			     GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_CHANNEL_END,
-			     struct GNUNET_MessageHeader,
-			     cm),
-    GNUNET_MQ_hd_var_size (channel_info,
-                           GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_CHANNEL,
-                           struct GNUNET_CADET_ChannelInfoMessage,
-                           cm),
-    GNUNET_MQ_handler_end ()
+    GNUNET_MQ_hd_fixed_size(channel_info_end,
+                            GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_CHANNEL_END,
+                            struct GNUNET_MessageHeader,
+                            cm),
+    GNUNET_MQ_hd_var_size(channel_info,
+                          GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_CHANNEL,
+                          struct GNUNET_CADET_ChannelInfoMessage,
+                          cm),
+    GNUNET_MQ_handler_end()
   };
   struct GNUNET_CADET_RequestChannelInfoMessage *msg;
   struct GNUNET_MQ_Envelope *env;
- 
+
   cm->reconnect_task = NULL;
-  cm->mq = GNUNET_CLIENT_connect (cm->cfg,
-				  "cadet",
-				  handlers,
-				  &error_handler,
-				  cm);
+  cm->mq = GNUNET_CLIENT_connect(cm->cfg,
+                                 "cadet",
+                                 handlers,
+                                 &error_handler,
+                                 cm);
   if (NULL == cm->mq)
-    return;	       		 
-  env = GNUNET_MQ_msg (msg,
-		       GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_CHANNEL);
+    return;
+  env = GNUNET_MQ_msg(msg,
+                      GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_CHANNEL);
   msg->target = cm->peer;
-  GNUNET_MQ_send (cm->mq,
-                  env);
+  GNUNET_MQ_send(cm->mq,
+                 env);
 }
 
 
@@ -212,29 +209,29 @@ reconnect (void *cls)
  * @return NULL on error
  */
 struct GNUNET_CADET_ChannelMonitor *
-GNUNET_CADET_get_channel (const struct GNUNET_CONFIGURATION_Handle *cfg,
-                          struct GNUNET_PeerIdentity *peer,
-                          GNUNET_CADET_ChannelCB callback,
-                          void *callback_cls)
+GNUNET_CADET_get_channel(const struct GNUNET_CONFIGURATION_Handle *cfg,
+                         struct GNUNET_PeerIdentity *peer,
+                         GNUNET_CADET_ChannelCB callback,
+                         void *callback_cls)
 {
   struct GNUNET_CADET_ChannelMonitor *cm;
 
   if (NULL == callback)
-  {
-    GNUNET_break (0);
-    return NULL;
-  }
-  cm = GNUNET_new (struct GNUNET_CADET_ChannelMonitor);
+    {
+      GNUNET_break(0);
+      return NULL;
+    }
+  cm = GNUNET_new(struct GNUNET_CADET_ChannelMonitor);
   cm->channel_cb = callback;
   cm->channel_cb_cls = callback_cls;
   cm->cfg = cfg;
   cm->peer = *peer;
-  reconnect (cm);
+  reconnect(cm);
   if (NULL == cm->mq)
-  {
-    GNUNET_free (cm);
-    return NULL;
-  }
+    {
+      GNUNET_free(cm);
+      return NULL;
+    }
   return cm;
 }
 
@@ -246,15 +243,15 @@ GNUNET_CADET_get_channel (const struct GNUNET_CONFIGURATION_Handle *cfg,
  * @return Closure that was given to #GNUNET_CADET_get_channel().
  */
 void *
-GNUNET_CADET_get_channel_cancel (struct GNUNET_CADET_ChannelMonitor *cm)
+GNUNET_CADET_get_channel_cancel(struct GNUNET_CADET_ChannelMonitor *cm)
 {
   void *ret = cm->channel_cb_cls;
 
   if (NULL != cm->mq)
-    GNUNET_MQ_destroy (cm->mq);
+    GNUNET_MQ_destroy(cm->mq);
   if (NULL != cm->reconnect_task)
-    GNUNET_SCHEDULER_cancel (cm->reconnect_task);
-  GNUNET_free (cm);
+    GNUNET_SCHEDULER_cancel(cm->reconnect_task);
+  GNUNET_free(cm);
   return ret;
 }
 

+ 76 - 79
src/cadet/cadet_api_get_path.c

@@ -16,7 +16,7 @@
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
-*/
+ */
 /**
  * @file cadet/cadet_api_get_path.c
  * @brief cadet api: client implementation of cadet service
@@ -34,9 +34,7 @@
 /**
  * Operation handle.
  */
-struct GNUNET_CADET_GetPath
-{
-
+struct GNUNET_CADET_GetPath {
   /**
    * Monitor callback
    */
@@ -71,7 +69,6 @@ struct GNUNET_CADET_GetPath
    * Peer we want information about.
    */
   struct GNUNET_PeerIdentity id;
-
 };
 
 
@@ -84,24 +81,24 @@ struct GNUNET_CADET_GetPath
  *         #GNUNET_SYSERR otherwise
  */
 static int
-check_get_path (void *cls,
-                const struct GNUNET_CADET_LocalInfoPath *message)
+check_get_path(void *cls,
+               const struct GNUNET_CADET_LocalInfoPath *message)
 {
-  size_t msize = sizeof (struct GNUNET_CADET_LocalInfoPath);
+  size_t msize = sizeof(struct GNUNET_CADET_LocalInfoPath);
   size_t esize;
 
-  (void) cls;
-  esize = ntohs (message->header.size);
+  (void)cls;
+  esize = ntohs(message->header.size);
   if (esize < msize)
-  {
-    GNUNET_break (0);
-    return GNUNET_SYSERR;
-  }
-  if (0 != ((esize - msize) % sizeof (struct GNUNET_PeerIdentity)))
-  {
-    GNUNET_break (0);
-    return GNUNET_SYSERR;
-  }
+    {
+      GNUNET_break(0);
+      return GNUNET_SYSERR;
+    }
+  if (0 != ((esize - msize) % sizeof(struct GNUNET_PeerIdentity)))
+    {
+      GNUNET_break(0);
+      return GNUNET_SYSERR;
+    }
   return GNUNET_OK;
 }
 
@@ -113,19 +110,19 @@ check_get_path (void *cls,
  * @param message Message itself.
  */
 static void
-handle_get_path (void *cls,
-                 const struct GNUNET_CADET_LocalInfoPath *message)
+handle_get_path(void *cls,
+                const struct GNUNET_CADET_LocalInfoPath *message)
 {
   struct GNUNET_CADET_GetPath *gp = cls;
   struct GNUNET_CADET_PeerPathDetail ppd;
 
   ppd.peer = gp->id;
-  ppd.path = (const struct GNUNET_PeerIdentity *) &message[1];
-  ppd.target_offset = ntohl (message->off);
-  ppd.path_length = (ntohs (message->header.size) - sizeof (*message))
-    / sizeof (struct GNUNET_PeerIdentity);
-  gp->path_cb (gp->path_cb_cls,
-	       &ppd);
+  ppd.path = (const struct GNUNET_PeerIdentity *)&message[1];
+  ppd.target_offset = ntohl(message->off);
+  ppd.path_length = (ntohs(message->header.size) - sizeof(*message))
+                    / sizeof(struct GNUNET_PeerIdentity);
+  gp->path_cb(gp->path_cb_cls,
+              &ppd);
 }
 
 
@@ -136,15 +133,15 @@ handle_get_path (void *cls,
  * @param message Message itself.
  */
 static void
-handle_get_path_end (void *cls,
-		     const struct GNUNET_MessageHeader *message)
+handle_get_path_end(void *cls,
+                    const struct GNUNET_MessageHeader *message)
 {
   struct GNUNET_CADET_GetPath *gp = cls;
 
-  (void) message;
-  gp->path_cb (gp->path_cb_cls,
-	       NULL);
-  GNUNET_CADET_get_path_cancel (gp);
+  (void)message;
+  gp->path_cb(gp->path_cb_cls,
+              NULL);
+  GNUNET_CADET_get_path_cancel(gp);
 }
 
 
@@ -154,7 +151,7 @@ handle_get_path_end (void *cls,
  * @param cls a `struct GNUNET_CADET_GetPath` operation
  */
 static void
-reconnect (void *cls);
+reconnect(void *cls);
 
 
 /**
@@ -164,18 +161,18 @@ reconnect (void *cls);
  * @param error error code from MQ
  */
 static void
-error_handler (void *cls,
-	       enum GNUNET_MQ_Error error)
+error_handler(void *cls,
+              enum GNUNET_MQ_Error error)
 {
   struct GNUNET_CADET_GetPath *gp = cls;
 
-  GNUNET_MQ_destroy (gp->mq);
+  GNUNET_MQ_destroy(gp->mq);
   gp->mq = NULL;
-  gp->backoff = GNUNET_TIME_randomized_backoff (gp->backoff,
-						GNUNET_TIME_UNIT_MINUTES);
-  gp->reconnect_task = GNUNET_SCHEDULER_add_delayed (gp->backoff,
-						     &reconnect,
-						     gp);
+  gp->backoff = GNUNET_TIME_randomized_backoff(gp->backoff,
+                                               GNUNET_TIME_UNIT_MINUTES);
+  gp->reconnect_task = GNUNET_SCHEDULER_add_delayed(gp->backoff,
+                                                    &reconnect,
+                                                    gp);
 }
 
 
@@ -185,36 +182,36 @@ error_handler (void *cls,
  * @param cls a `struct GNUNET_CADET_GetPath` operation
  */
 static void
-reconnect (void *cls)
+reconnect(void *cls)
 {
   struct GNUNET_CADET_GetPath *gp = cls;
   struct GNUNET_MQ_MessageHandler handlers[] = {
-    GNUNET_MQ_hd_var_size (get_path,
-                           GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PATH,
-                           struct GNUNET_CADET_LocalInfoPath,
-                           gp),
-    GNUNET_MQ_hd_fixed_size (get_path_end,
-			     GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PATH_END,
-			     struct GNUNET_MessageHeader,
-			     gp),
-    GNUNET_MQ_handler_end ()
+    GNUNET_MQ_hd_var_size(get_path,
+                          GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PATH,
+                          struct GNUNET_CADET_LocalInfoPath,
+                          gp),
+    GNUNET_MQ_hd_fixed_size(get_path_end,
+                            GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PATH_END,
+                            struct GNUNET_MessageHeader,
+                            gp),
+    GNUNET_MQ_handler_end()
   };
   struct GNUNET_CADET_RequestPathInfoMessage *msg;
   struct GNUNET_MQ_Envelope *env;
 
   gp->reconnect_task = NULL;
-  gp->mq = GNUNET_CLIENT_connect (gp->cfg,
-				  "cadet",
-				  handlers,
-				  &error_handler,
-				  gp);
+  gp->mq = GNUNET_CLIENT_connect(gp->cfg,
+                                 "cadet",
+                                 handlers,
+                                 &error_handler,
+                                 gp);
   if (NULL == gp->mq)
     return;
-  env = GNUNET_MQ_msg (msg,
-                       GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_PATH);
+  env = GNUNET_MQ_msg(msg,
+                      GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_PATH);
   msg->peer = gp->id;
-  GNUNET_MQ_send (gp->mq,
-                  env);
+  GNUNET_MQ_send(gp->mq,
+                 env);
 }
 
 
@@ -228,29 +225,29 @@ reconnect (void *cls)
  * @return NULL on error
  */
 struct GNUNET_CADET_GetPath *
-GNUNET_CADET_get_path (const struct GNUNET_CONFIGURATION_Handle *cfg,
-		       const struct GNUNET_PeerIdentity *id,
-                       GNUNET_CADET_PathCB callback,
-                       void *callback_cls)
+GNUNET_CADET_get_path(const struct GNUNET_CONFIGURATION_Handle *cfg,
+                      const struct GNUNET_PeerIdentity *id,
+                      GNUNET_CADET_PathCB callback,
+                      void *callback_cls)
 {
   struct GNUNET_CADET_GetPath *gp;
 
   if (NULL == callback)
-  {
-    GNUNET_break (0);
-    return NULL;
-  }
-  gp = GNUNET_new (struct GNUNET_CADET_GetPath);
+    {
+      GNUNET_break(0);
+      return NULL;
+    }
+  gp = GNUNET_new(struct GNUNET_CADET_GetPath);
   gp->path_cb = callback;
   gp->path_cb_cls = callback_cls;
   gp->cfg = cfg;
   gp->id = *id;
-  reconnect (gp);
+  reconnect(gp);
   if (NULL == gp->mq)
-  {
-    GNUNET_free (gp);
-    return NULL;
-  }
+    {
+      GNUNET_free(gp);
+      return NULL;
+    }
   return gp;
 }
 
@@ -262,15 +259,15 @@ GNUNET_CADET_get_path (const struct GNUNET_CONFIGURATION_Handle *cfg,
  * @return closure from #GNUNET_CADET_get_path().
  */
 void *
-GNUNET_CADET_get_path_cancel (struct GNUNET_CADET_GetPath *gp)
+GNUNET_CADET_get_path_cancel(struct GNUNET_CADET_GetPath *gp)
 {
   void *ret = gp->path_cb_cls;
 
   if (NULL != gp->mq)
-    GNUNET_MQ_destroy (gp->mq);
+    GNUNET_MQ_destroy(gp->mq);
   if (NULL != gp->reconnect_task)
-    GNUNET_SCHEDULER_cancel (gp->reconnect_task);
-  GNUNET_free (gp);
+    GNUNET_SCHEDULER_cancel(gp->reconnect_task);
+  GNUNET_free(gp);
   return ret;
 }
 

+ 8 - 8
src/cadet/cadet_api_helper.c

@@ -11,12 +11,12 @@
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      Affero General Public License for more details.
-    
+
      You should have received a copy of the GNU Affero General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
-*/
+ */
 /**
  * @file cadet/cadet_api_helper.c
  * @brief cadet api: client implementation of cadet service
@@ -41,15 +41,15 @@
  * @return A GNUNET_HashCode usable for the new CADET API.
  */
 const struct GNUNET_HashCode *
-GC_u2h (uint32_t port)
+GC_u2h(uint32_t port)
 {
   static struct GNUNET_HashCode hash;
 
-  GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-              "This is a transitional function, use proper crypto hashes as CADET ports\n");
-  GNUNET_CRYPTO_hash (&port,
-                      sizeof (port),
-                      &hash);
+  GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
+             "This is a transitional function, use proper crypto hashes as CADET ports\n");
+  GNUNET_CRYPTO_hash(&port,
+                     sizeof(port),
+                     &hash);
   return &hash;
 }
 

+ 62 - 64
src/cadet/cadet_api_list_peers.c

@@ -11,12 +11,12 @@
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      Affero General Public License for more details.
-    
+
      You should have received a copy of the GNU Affero General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
-*/
+ */
 /**
  * @file cadet/cadet_api_list_peers.c
  * @brief cadet api: client implementation of cadet service
@@ -34,9 +34,7 @@
 /**
  * Operation handle.
  */
-struct GNUNET_CADET_PeersLister
-{
-
+struct GNUNET_CADET_PeersLister {
   /**
    * Monitor callback
    */
@@ -66,7 +64,6 @@ struct GNUNET_CADET_PeersLister
    * Backoff for reconnect attempts.
    */
   struct GNUNET_TIME_Relative backoff;
-  
 };
 
 
@@ -77,18 +74,18 @@ struct GNUNET_CADET_PeersLister
  * @param info Message itself.
  */
 static void
-handle_get_peers (void *cls,
-                  const struct GNUNET_CADET_LocalInfoPeers *info)
+handle_get_peers(void *cls,
+                 const struct GNUNET_CADET_LocalInfoPeers *info)
 {
   struct GNUNET_CADET_PeersLister *pl = cls;
   struct GNUNET_CADET_PeerListEntry ple;
 
   ple.peer = info->destination;
-  ple.have_tunnel = (int) ntohs (info->tunnel);
-  ple.n_paths = (unsigned int) ntohs (info->paths);
-  ple.best_path_length = (unsigned int) ntohl (info->best_path_length);
-  pl->peers_cb (pl->peers_cb_cls,
-		&ple);
+  ple.have_tunnel = (int)ntohs(info->tunnel);
+  ple.n_paths = (unsigned int)ntohs(info->paths);
+  ple.best_path_length = (unsigned int)ntohl(info->best_path_length);
+  pl->peers_cb(pl->peers_cb_cls,
+               &ple);
 }
 
 
@@ -99,15 +96,16 @@ handle_get_peers (void *cls,
  * @param msg Message itself.
  */
 static void
-handle_get_peers_end (void *cls,
-		      const struct GNUNET_MessageHeader *msg)
+handle_get_peers_end(void *cls,
+                     const struct GNUNET_MessageHeader *msg)
 {
   struct GNUNET_CADET_PeersLister *pl = cls;
-  (void) msg;
 
-  pl->peers_cb (pl->peers_cb_cls,
-		NULL);
-  GNUNET_CADET_list_peers_cancel (pl);
+  (void)msg;
+
+  pl->peers_cb(pl->peers_cb_cls,
+               NULL);
+  GNUNET_CADET_list_peers_cancel(pl);
 }
 
 
@@ -117,7 +115,7 @@ handle_get_peers_end (void *cls,
  * @param cls a `struct GNUNET_CADET_PeersLister` operation
  */
 static void
-reconnect (void *cls);
+reconnect(void *cls);
 
 
 /**
@@ -127,18 +125,18 @@ reconnect (void *cls);
  * @param error error code from MQ
  */
 static void
-error_handler (void *cls,
-	       enum GNUNET_MQ_Error error)
+error_handler(void *cls,
+              enum GNUNET_MQ_Error error)
 {
   struct GNUNET_CADET_PeersLister *pl = cls;
 
-  GNUNET_MQ_destroy (pl->mq);
+  GNUNET_MQ_destroy(pl->mq);
   pl->mq = NULL;
-  pl->backoff = GNUNET_TIME_randomized_backoff (pl->backoff,
-						GNUNET_TIME_UNIT_MINUTES);
-  pl->reconnect_task = GNUNET_SCHEDULER_add_delayed (pl->backoff,
-						     &reconnect,
-						     pl);
+  pl->backoff = GNUNET_TIME_randomized_backoff(pl->backoff,
+                                               GNUNET_TIME_UNIT_MINUTES);
+  pl->reconnect_task = GNUNET_SCHEDULER_add_delayed(pl->backoff,
+                                                    &reconnect,
+                                                    pl);
 }
 
 
@@ -148,35 +146,35 @@ error_handler (void *cls,
  * @param cls a `struct GNUNET_CADET_PeersLister` operation
  */
 static void
-reconnect (void *cls)
+reconnect(void *cls)
 {
   struct GNUNET_CADET_PeersLister *pl = cls;
   struct GNUNET_MQ_MessageHandler handlers[] = {
-    GNUNET_MQ_hd_fixed_size (get_peers,
-			     GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS,
-			     struct GNUNET_CADET_LocalInfoPeers,
-			     pl),
-    GNUNET_MQ_hd_fixed_size (get_peers_end,
-			     GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS_END,
-			     struct GNUNET_MessageHeader,
-			     pl),
-    GNUNET_MQ_handler_end ()
+    GNUNET_MQ_hd_fixed_size(get_peers,
+                            GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS,
+                            struct GNUNET_CADET_LocalInfoPeers,
+                            pl),
+    GNUNET_MQ_hd_fixed_size(get_peers_end,
+                            GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS_END,
+                            struct GNUNET_MessageHeader,
+                            pl),
+    GNUNET_MQ_handler_end()
   };
   struct GNUNET_MessageHeader *msg;
   struct GNUNET_MQ_Envelope *env;
 
   pl->reconnect_task = NULL;
-  pl->mq = GNUNET_CLIENT_connect (pl->cfg,
-				  "cadet",
-				  handlers,
-				  &error_handler,
-				  pl);	
+  pl->mq = GNUNET_CLIENT_connect(pl->cfg,
+                                 "cadet",
+                                 handlers,
+                                 &error_handler,
+                                 pl);
   if (NULL == pl->mq)
     return;
-  env = GNUNET_MQ_msg (msg,
-		       GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_PEERS);
-  GNUNET_MQ_send (pl->mq,
-                  env);
+  env = GNUNET_MQ_msg(msg,
+                      GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_PEERS);
+  GNUNET_MQ_send(pl->mq,
+                 env);
 }
 
 
@@ -191,27 +189,27 @@ reconnect (void *cls)
  * @return NULL on error
  */
 struct GNUNET_CADET_PeersLister *
-GNUNET_CADET_list_peers (const struct GNUNET_CONFIGURATION_Handle *cfg,
-			 GNUNET_CADET_PeersCB callback,
-			 void *callback_cls)
+GNUNET_CADET_list_peers(const struct GNUNET_CONFIGURATION_Handle *cfg,
+                        GNUNET_CADET_PeersCB callback,
+                        void *callback_cls)
 {
   struct GNUNET_CADET_PeersLister *pl;
 
   if (NULL == callback)
-  {
-    GNUNET_break (0);
-    return NULL;
-  }
-  pl = GNUNET_new (struct GNUNET_CADET_PeersLister);
+    {
+      GNUNET_break(0);
+      return NULL;
+    }
+  pl = GNUNET_new(struct GNUNET_CADET_PeersLister);
   pl->peers_cb = callback;
   pl->peers_cb_cls = callback_cls;
   pl->cfg = cfg;
-  reconnect (pl);
+  reconnect(pl);
   if (NULL == pl->mq)
-  {
-    GNUNET_free (pl);
-    return NULL;
-  }
+    {
+      GNUNET_free(pl);
+      return NULL;
+    }
   return pl;
 }
 
@@ -223,15 +221,15 @@ GNUNET_CADET_list_peers (const struct GNUNET_CONFIGURATION_Handle *cfg,
  * @return Closure given to GNUNET_CADET_get_peers().
  */
 void *
-GNUNET_CADET_list_peers_cancel (struct GNUNET_CADET_PeersLister *pl)
+GNUNET_CADET_list_peers_cancel(struct GNUNET_CADET_PeersLister *pl)
 {
   void *ret = pl->peers_cb_cls;
 
   if (NULL != pl->mq)
-    GNUNET_MQ_destroy (pl->mq);
+    GNUNET_MQ_destroy(pl->mq);
   if (NULL != pl->reconnect_task)
-    GNUNET_SCHEDULER_cancel (pl->reconnect_task);
-  GNUNET_free (pl);
+    GNUNET_SCHEDULER_cancel(pl->reconnect_task);
+  GNUNET_free(pl);
   return ret;
 }
 

+ 66 - 68
src/cadet/cadet_api_list_tunnels.c

@@ -11,12 +11,12 @@
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      Affero General Public License for more details.
-    
+
      You should have received a copy of the GNU Affero General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
-*/
+ */
 /**
  * @file cadet/cadet_api_list_tunnels.c
  * @brief cadet api: client implementation of cadet service
@@ -34,9 +34,7 @@
 /**
  * Operation handle.
  */
-struct GNUNET_CADET_ListTunnels
-{
-
+struct GNUNET_CADET_ListTunnels {
   /**
    * Monitor callback
    */
@@ -46,7 +44,7 @@ struct GNUNET_CADET_ListTunnels
    * Info callback closure for @c tunnels_cb.
    */
   void *tunnels_cb_cls;
-  
+
   /**
    * Message queue to talk to CADET service.
    */
@@ -66,7 +64,6 @@ struct GNUNET_CADET_ListTunnels
    * Backoff for reconnect attempts.
    */
   struct GNUNET_TIME_Relative backoff;
-
 };
 
 
@@ -77,19 +74,19 @@ struct GNUNET_CADET_ListTunnels
  * @param info Message itself.
  */
 static void
-handle_get_tunnels (void *cls,
-		    const struct GNUNET_CADET_LocalInfoTunnel *info)
+handle_get_tunnels(void *cls,
+                   const struct GNUNET_CADET_LocalInfoTunnel *info)
 {
   struct GNUNET_CADET_ListTunnels *lt = cls;
   struct GNUNET_CADET_TunnelDetails td;
-  
+
   td.peer = info->destination;
-  td.channels = ntohl (info->channels);
-  td.connections = ntohl (info->connections);
-  td.estate = ntohs (info->estate);
-  td.cstate = ntohs (info->cstate);
-  lt->tunnels_cb (lt->tunnels_cb_cls,
-		  &td);
+  td.channels = ntohl(info->channels);
+  td.connections = ntohl(info->connections);
+  td.estate = ntohs(info->estate);
+  td.cstate = ntohs(info->cstate);
+  lt->tunnels_cb(lt->tunnels_cb_cls,
+                 &td);
 }
 
 
@@ -100,15 +97,16 @@ handle_get_tunnels (void *cls,
  * @param message Message itself.
  */
 static void
-handle_get_tunnels_end (void *cls,
-			const struct GNUNET_MessageHeader *msg)
+handle_get_tunnels_end(void *cls,
+                       const struct GNUNET_MessageHeader *msg)
 {
   struct GNUNET_CADET_ListTunnels *lt = cls;
-  (void) msg;
-  
-  lt->tunnels_cb (lt->tunnels_cb_cls,
-		  NULL);
-  GNUNET_CADET_list_tunnels_cancel (lt);
+
+  (void)msg;
+
+  lt->tunnels_cb(lt->tunnels_cb_cls,
+                 NULL);
+  GNUNET_CADET_list_tunnels_cancel(lt);
 }
 
 
@@ -118,7 +116,7 @@ handle_get_tunnels_end (void *cls,
  * @param cls a `struct GNUNET_CADET_ListTunnels` operation
  */
 static void
-reconnect (void *cls);
+reconnect(void *cls);
 
 
 /**
@@ -128,18 +126,18 @@ reconnect (void *cls);
  * @param error error code from MQ
  */
 static void
-error_handler (void *cls,
-	       enum GNUNET_MQ_Error error)
+error_handler(void *cls,
+              enum GNUNET_MQ_Error error)
 {
   struct GNUNET_CADET_ListTunnels *lt = cls;
 
-  GNUNET_MQ_destroy (lt->mq);
+  GNUNET_MQ_destroy(lt->mq);
   lt->mq = NULL;
-  lt->backoff = GNUNET_TIME_randomized_backoff (lt->backoff,
-						GNUNET_TIME_UNIT_MINUTES);
-  lt->reconnect_task = GNUNET_SCHEDULER_add_delayed (lt->backoff,
-						     &reconnect,
-						     lt);
+  lt->backoff = GNUNET_TIME_randomized_backoff(lt->backoff,
+                                               GNUNET_TIME_UNIT_MINUTES);
+  lt->reconnect_task = GNUNET_SCHEDULER_add_delayed(lt->backoff,
+                                                    &reconnect,
+                                                    lt);
 }
 
 
@@ -149,35 +147,35 @@ error_handler (void *cls,
  * @param cls a `struct GNUNET_CADET_ListTunnels` operation
  */
 static void
-reconnect (void *cls)
+reconnect(void *cls)
 {
   struct GNUNET_CADET_ListTunnels *lt = cls;
   struct GNUNET_MQ_MessageHandler handlers[] = {
-    GNUNET_MQ_hd_fixed_size (get_tunnels,
-			     GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS,
-			     struct GNUNET_CADET_LocalInfoTunnel,
-			     lt),
-    GNUNET_MQ_hd_fixed_size (get_tunnels_end,
-			     GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS_END,
-			     struct GNUNET_MessageHeader,
-			     lt),
-    GNUNET_MQ_handler_end ()
+    GNUNET_MQ_hd_fixed_size(get_tunnels,
+                            GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS,
+                            struct GNUNET_CADET_LocalInfoTunnel,
+                            lt),
+    GNUNET_MQ_hd_fixed_size(get_tunnels_end,
+                            GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS_END,
+                            struct GNUNET_MessageHeader,
+                            lt),
+    GNUNET_MQ_handler_end()
   };
   struct GNUNET_MessageHeader *msg;
   struct GNUNET_MQ_Envelope *env;
 
   lt->reconnect_task = NULL;
-  lt->mq = GNUNET_CLIENT_connect (lt->cfg,
-				  "cadet",
-				  handlers,
-				  &error_handler,
-				  lt);	
+  lt->mq = GNUNET_CLIENT_connect(lt->cfg,
+                                 "cadet",
+                                 handlers,
+                                 &error_handler,
+                                 lt);
   if (NULL == lt->mq)
     return;
-  env = GNUNET_MQ_msg (msg,
-		       GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_TUNNELS);
-  GNUNET_MQ_send (lt->mq,
-                  env);
+  env = GNUNET_MQ_msg(msg,
+                      GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_TUNNELS);
+  GNUNET_MQ_send(lt->mq,
+                 env);
 }
 
 
@@ -192,27 +190,27 @@ reconnect (void *cls)
  * @return NULL on error
  */
 struct GNUNET_CADET_ListTunnels *
-GNUNET_CADET_list_tunnels (const struct GNUNET_CONFIGURATION_Handle *cfg,
-			   GNUNET_CADET_TunnelsCB callback,
-			   void *callback_cls)
+GNUNET_CADET_list_tunnels(const struct GNUNET_CONFIGURATION_Handle *cfg,
+                          GNUNET_CADET_TunnelsCB callback,
+                          void *callback_cls)
 {
   struct GNUNET_CADET_ListTunnels *lt;
 
   if (NULL == callback)
-  {
-    GNUNET_break (0);
-    return NULL;
-  }
-  lt = GNUNET_new (struct GNUNET_CADET_ListTunnels);
+    {
+      GNUNET_break(0);
+      return NULL;
+    }
+  lt = GNUNET_new(struct GNUNET_CADET_ListTunnels);
   lt->tunnels_cb = callback;
   lt->tunnels_cb_cls = callback_cls;
   lt->cfg = cfg;
-  reconnect (lt);
+  reconnect(lt);
   if (NULL == lt->mq)
-  {
-    GNUNET_free (lt);
-    return NULL;
-  }
+    {
+      GNUNET_free(lt);
+      return NULL;
+    }
   return lt;
 }
 
@@ -224,15 +222,15 @@ GNUNET_CADET_list_tunnels (const struct GNUNET_CONFIGURATION_Handle *cfg,
  * @return Closure given to GNUNET_CADET_list_tunnels().
  */
 void *
-GNUNET_CADET_list_tunnels_cancel (struct GNUNET_CADET_ListTunnels *lt)
+GNUNET_CADET_list_tunnels_cancel(struct GNUNET_CADET_ListTunnels *lt)
 {
   void *ret = lt->tunnels_cb_cls;
 
   if (NULL != lt->mq)
-    GNUNET_MQ_destroy (lt->mq);
+    GNUNET_MQ_destroy(lt->mq);
   if (NULL != lt->reconnect_task)
-    GNUNET_SCHEDULER_cancel (lt->reconnect_task);
-  GNUNET_free (lt);
+    GNUNET_SCHEDULER_cancel(lt->reconnect_task);
+  GNUNET_free(lt);
   return ret;
 }
 

+ 18 - 40
src/cadet/cadet_protocol.h

@@ -11,12 +11,12 @@
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      Affero General Public License for more details.
-    
+
      You should have received a copy of the GNU Affero General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
-*/
+ */
 
 /**
  * @file cadet/cadet_protocol.h
@@ -46,7 +46,7 @@ struct GNUNET_CADET_TunnelMessage;
 extern "C"
 {
 #if 0
-  /* keep Emacsens' auto-indent happy */
+/* keep Emacsens' auto-indent happy */
 }
 #endif
 #endif
@@ -66,8 +66,7 @@ GNUNET_NETWORK_STRUCT_BEGIN
 /**
  * Message for cadet connection creation.
  */
-struct GNUNET_CADET_ConnectionCreateMessage
-{
+struct GNUNET_CADET_ConnectionCreateMessage {
   /**
    * Type: #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE
    *
@@ -100,8 +99,7 @@ struct GNUNET_CADET_ConnectionCreateMessage
 /**
  * Message for ack'ing a connection
  */
-struct GNUNET_CADET_ConnectionCreateAckMessage
-{
+struct GNUNET_CADET_ConnectionCreateAckMessage {
   /**
    * Type: #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE_ACK
    */
@@ -116,15 +114,13 @@ struct GNUNET_CADET_ConnectionCreateAckMessage
    * ID of the connection.
    */
   struct GNUNET_CADET_ConnectionTunnelIdentifier cid;
-
 };
 
 
 /**
  * Message for notifying a disconnection in a path
  */
-struct GNUNET_CADET_ConnectionBrokenMessage
-{
+struct GNUNET_CADET_ConnectionBrokenMessage {
   /**
    * Type: #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN.
    */
@@ -155,8 +151,7 @@ struct GNUNET_CADET_ConnectionBrokenMessage
 /**
  * Message to destroy a connection.
  */
-struct GNUNET_CADET_ConnectionDestroyMessage
-{
+struct GNUNET_CADET_ConnectionDestroyMessage {
   /**
    * Type: #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY
    */
@@ -185,8 +180,7 @@ struct GNUNET_CADET_ConnectionDestroyMessage
  * against the respective  #GNUNET_MESSAGE_TYPE_CADET_TUNNEL_ENCRYPTED
  * messages.
  */
-struct CadetEncryptedMessageIdentifier
-{
+struct CadetEncryptedMessageIdentifier {
   /**
    * This number is incremented by one per message. It may wrap around.
    * In network byte order.
@@ -199,7 +193,6 @@ struct CadetEncryptedMessageIdentifier
  * Flags to be used in GNUNET_CADET_KX.
  */
 enum GNUNET_CADET_KX_Flags {
-
   /**
    * Should the peer reply with its KX details?
    */
@@ -215,8 +208,7 @@ enum GNUNET_CADET_KX_Flags {
 /**
  * Message for a Key eXchange for a tunnel.
  */
-struct GNUNET_CADET_TunnelKeyExchangeMessage
-{
+struct GNUNET_CADET_TunnelKeyExchangeMessage {
   /**
    * Type: #GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX or
    * #GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX_AUTH as part
@@ -264,7 +256,6 @@ struct GNUNET_CADET_TunnelKeyExchangeMessage
    * using 'gcry_sexp_sprint'.
    */
   struct GNUNET_CRYPTO_EcdhePublicKey ratchet_key;
-
 };
 
 
@@ -272,9 +263,7 @@ struct GNUNET_CADET_TunnelKeyExchangeMessage
  * Message for a Key eXchange for a tunnel, with authentication.
  * Used as a response to the initial KX as well as for rekeying.
  */
-struct GNUNET_CADET_TunnelKeyExchangeAuthMessage
-{
-
+struct GNUNET_CADET_TunnelKeyExchangeAuthMessage {
   /**
    * Message header with key material.
    */
@@ -294,7 +283,6 @@ struct GNUNET_CADET_TunnelKeyExchangeAuthMessage
    * signature or payload data.
    */
   struct GNUNET_HashCode auth;
-
 };
 
 
@@ -302,9 +290,7 @@ struct GNUNET_CADET_TunnelKeyExchangeAuthMessage
  * Encrypted axolotl header with numbers that identify which
  * keys in which ratchet are to be used to decrypt the body.
  */
-struct GNUNET_CADET_AxHeader
-{
-
+struct GNUNET_CADET_AxHeader {
   /**
    * Number of messages sent with the current ratchet key.
    */
@@ -319,15 +305,13 @@ struct GNUNET_CADET_AxHeader
    * Current ratchet key.
    */
   struct GNUNET_CRYPTO_EcdhePublicKey DHRs;
-
 };
 
 
 /**
  * Axolotl-encrypted tunnel message with application payload.
  */
-struct GNUNET_CADET_TunnelEncryptedMessage
-{
+struct GNUNET_CADET_TunnelEncryptedMessage {
   /**
    * Type: #GNUNET_MESSAGE_TYPE_CADET_TUNNEL_ENCRYPTED
    */
@@ -370,8 +354,7 @@ struct GNUNET_CADET_TunnelEncryptedMessage
 /**
  * Message to create a Channel.
  */
-struct GNUNET_CADET_ChannelOpenMessage
-{
+struct GNUNET_CADET_ChannelOpenMessage {
   /**
    * Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN
    */
@@ -398,8 +381,7 @@ struct GNUNET_CADET_ChannelOpenMessage
  * Message to acknowledge opening a channel of type
  * #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN_ACK.
  */
-struct GNUNET_CADET_ChannelOpenAckMessage
-{
+struct GNUNET_CADET_ChannelOpenAckMessage {
   /**
    * Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN_ACK
    */
@@ -427,8 +409,7 @@ struct GNUNET_CADET_ChannelOpenAckMessage
  * Message to destroy a channel of type
  * #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY.
  */
-struct GNUNET_CADET_ChannelDestroyMessage
-{
+struct GNUNET_CADET_ChannelDestroyMessage {
   /**
    * Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY
    */
@@ -449,8 +430,7 @@ struct GNUNET_CADET_ChannelDestroyMessage
 /**
  * Number used to uniquely identify messages in a CADET Channel.
  */
-struct ChannelMessageIdentifier
-{
+struct ChannelMessageIdentifier {
   /**
    * Unique ID of the message, cycles around, in NBO.
    */
@@ -461,8 +441,7 @@ struct ChannelMessageIdentifier
 /**
  * Message for cadet data traffic.
  */
-struct GNUNET_CADET_ChannelAppDataMessage
-{
+struct GNUNET_CADET_ChannelAppDataMessage {
   /**
    * Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA.
    */
@@ -487,8 +466,7 @@ struct GNUNET_CADET_ChannelAppDataMessage
 /**
  * Message to acknowledge end-to-end data.
  */
-struct GNUNET_CADET_ChannelDataAckMessage
-{
+struct GNUNET_CADET_ChannelDataAckMessage {
   /**
    * Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA_ACK
    */

+ 125 - 127
src/cadet/cadet_test_lib.c

@@ -16,7 +16,7 @@
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
-*/
+ */
 /**
  * @file cadet/cadet_test_lib.c
  * @author Bartlomiej Polot
@@ -31,8 +31,7 @@
 /**
  * Test context for a CADET Test.
  */
-struct GNUNET_CADET_TEST_Context
-{
+struct GNUNET_CADET_TEST_Context {
   /**
    * Array of running peers.
    */
@@ -92,15 +91,13 @@ struct GNUNET_CADET_TEST_Context
    * Number of ports in #ports.
    */
   unsigned int port_count;
-
 };
 
 
 /**
  * Context for a cadet adapter callback.
  */
-struct GNUNET_CADET_TEST_AdapterContext
-{
+struct GNUNET_CADET_TEST_AdapterContext {
   /**
    * Peer number for the particular peer.
    */
@@ -129,33 +126,33 @@ struct GNUNET_CADET_TEST_AdapterContext
  * @return service handle to return in 'op_result', NULL on error
  */
 static void *
-cadet_connect_adapter (void *cls,
-                       const struct GNUNET_CONFIGURATION_Handle *cfg)
+cadet_connect_adapter(void *cls,
+                      const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
   struct GNUNET_CADET_TEST_AdapterContext *actx = cls;
   struct GNUNET_CADET_TEST_Context *ctx = actx->ctx;
   struct GNUNET_CADET_Handle *h;
 
-  h = GNUNET_CADET_connect (cfg);
+  h = GNUNET_CADET_connect(cfg);
   if (NULL == h)
-  {
-    GNUNET_break(0);
-    return NULL;
-  }
+    {
+      GNUNET_break(0);
+      return NULL;
+    }
   if (NULL == ctx->ports)
     return h;
-  actx->ports = GNUNET_new_array (ctx->port_count,
-                                  struct GNUNET_CADET_Port *);
+  actx->ports = GNUNET_new_array(ctx->port_count,
+                                 struct GNUNET_CADET_Port *);
   for (unsigned int i = 0; i < ctx->port_count; i++)
-  {
-    actx->ports[i] = GNUNET_CADET_open_port (h,
-                                             ctx->ports[i],
-                                             ctx->connects,
-                                             (void *) (long) actx->peer,
-                                             ctx->window_changes,
-                                             ctx->disconnects,
-                                             ctx->handlers);
-  }
+    {
+      actx->ports[i] = GNUNET_CADET_open_port(h,
+                                              ctx->ports[i],
+                                              ctx->connects,
+                                              (void *)(long)actx->peer,
+                                              ctx->window_changes,
+                                              ctx->disconnects,
+                                              ctx->handlers);
+    }
   return h;
 }
 
@@ -168,23 +165,23 @@ cadet_connect_adapter (void *cls,
  * @param op_result service handle returned from the connect adapter
  */
 static void
-cadet_disconnect_adapter (void *cls,
-                          void *op_result)
+cadet_disconnect_adapter(void *cls,
+                         void *op_result)
 {
   struct GNUNET_CADET_Handle *cadet = op_result;
   struct GNUNET_CADET_TEST_AdapterContext *actx = cls;
 
   if (NULL != actx->ports)
-  {
-    for (unsigned int i = 0; i < actx->ctx->port_count; i++)
     {
-      GNUNET_CADET_close_port (actx->ports[i]);
-      actx->ports[i] = NULL;
+      for (unsigned int i = 0; i < actx->ctx->port_count; i++)
+        {
+          GNUNET_CADET_close_port(actx->ports[i]);
+          actx->ports[i] = NULL;
+        }
+      GNUNET_free(actx->ports);
     }
-    GNUNET_free (actx->ports);
-  }
-  GNUNET_free (actx);
-  GNUNET_CADET_disconnect (cadet);
+  GNUNET_free(actx);
+  GNUNET_CADET_disconnect(cadet);
 }
 
 
@@ -199,7 +196,7 @@ cadet_disconnect_adapter (void *cls,
  *             NULL if operation has executed successfully.
  */
 static void
-cadet_connect_cb (void *cls,
+cadet_connect_cb(void *cls,
                  struct GNUNET_TESTBED_Operation *op,
                  void *ca_result,
                  const char *emsg)
@@ -207,47 +204,48 @@ cadet_connect_cb (void *cls,
   struct GNUNET_CADET_TEST_Context *ctx = cls;
 
   if (NULL != emsg)
-  {
-    fprintf (stderr,
-             "Failed to connect to CADET service: %s\n",
-             emsg);
-    GNUNET_SCHEDULER_shutdown ();
-    return;
-  }
-  for (unsigned int i = 0; i < ctx->num_peers; i++)
-    if (op == ctx->ops[i])
     {
-      ctx->cadets[i] = ca_result;
-      GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-                  "...cadet %u connected\n",
-                  i);
+      fprintf(stderr,
+              "Failed to connect to CADET service: %s\n",
+              emsg);
+      GNUNET_SCHEDULER_shutdown();
+      return;
     }
+  for (unsigned int i = 0; i < ctx->num_peers; i++)
+    if (op == ctx->ops[i])
+      {
+        ctx->cadets[i] = ca_result;
+        GNUNET_log(GNUNET_ERROR_TYPE_INFO,
+                   "...cadet %u connected\n",
+                   i);
+      }
   for (unsigned int i = 0; i < ctx->num_peers; i++)
     if (NULL == ctx->cadets[i])
-      return; /* still some CADET connections missing */
+      return;
+  /* still some CADET connections missing */
   /* all CADET connections ready! */
-  ctx->app_main (ctx->app_main_cls,
-                 ctx,
-                 ctx->num_peers,
-                 ctx->peers,
-                 ctx->cadets);
+  ctx->app_main(ctx->app_main_cls,
+                ctx,
+                ctx->num_peers,
+                ctx->peers,
+                ctx->cadets);
 }
 
 
 void
-GNUNET_CADET_TEST_cleanup (struct GNUNET_CADET_TEST_Context *ctx)
+GNUNET_CADET_TEST_cleanup(struct GNUNET_CADET_TEST_Context *ctx)
 {
   for (unsigned int i = 0; i < ctx->num_peers; i++)
-  {
-    GNUNET_assert (NULL != ctx->ops[i]);
-    GNUNET_TESTBED_operation_done (ctx->ops[i]);
-    ctx->ops[i] = NULL;
-  }
-  GNUNET_free (ctx->ops);
-  GNUNET_free (ctx->cadets);
-  GNUNET_free (ctx->handlers);
-  GNUNET_free (ctx);
-  GNUNET_SCHEDULER_shutdown ();
+    {
+      GNUNET_assert(NULL != ctx->ops[i]);
+      GNUNET_TESTBED_operation_done(ctx->ops[i]);
+      ctx->ops[i] = NULL;
+    }
+  GNUNET_free(ctx->ops);
+  GNUNET_free(ctx->cadets);
+  GNUNET_free(ctx->handlers);
+  GNUNET_free(ctx);
+  GNUNET_SCHEDULER_shutdown();
 }
 
 
@@ -265,7 +263,7 @@ GNUNET_CADET_TEST_cleanup (struct GNUNET_CADET_TEST_Context *ctx)
  *          failed
  */
 static void
-cadet_test_run (void *cls,
+cadet_test_run(void *cls,
                struct GNUNET_TESTBED_RunHandle *h,
                unsigned int num_peers,
                struct GNUNET_TESTBED_Peer **peers,
@@ -275,47 +273,47 @@ cadet_test_run (void *cls,
   struct GNUNET_CADET_TEST_Context *ctx = cls;
 
   if (0 != links_failed)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "Some links failed (%u), ending\n",
-                links_failed);
-    exit (77);
-  }
-  if  (num_peers != ctx->num_peers)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "Peers started %u/%u, ending\n",
-                num_peers,
-                ctx->num_peers);
-    exit (1);
-  }
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Testbed up, %u peers and %u links\n",
-              num_peers,
-              links_succeeded);
+    {
+      GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
+                 "Some links failed (%u), ending\n",
+                 links_failed);
+      exit(77);
+    }
+  if (num_peers != ctx->num_peers)
+    {
+      GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
+                 "Peers started %u/%u, ending\n",
+                 num_peers,
+                 ctx->num_peers);
+      exit(1);
+    }
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+             "Testbed up, %u peers and %u links\n",
+             num_peers,
+             links_succeeded);
   ctx->peers = peers;
   for (unsigned int i = 0; i < num_peers; i++)
-  {
-    struct GNUNET_CADET_TEST_AdapterContext *newctx;
-
-    newctx = GNUNET_new (struct GNUNET_CADET_TEST_AdapterContext);
-    newctx->peer = i;
-    newctx->ctx = ctx;
-    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-                "Connecting to cadet %u\n",
-                i);
-    ctx->ops[i] = GNUNET_TESTBED_service_connect (ctx,
-                                                  peers[i],
-                                                  "cadet",
-                                                  &cadet_connect_cb,
-                                                  ctx,
-                                                  &cadet_connect_adapter,
-                                                  &cadet_disconnect_adapter,
-                                                  newctx);
-    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-                "op handle %p\n",
-                ctx->ops[i]);
-  }
+    {
+      struct GNUNET_CADET_TEST_AdapterContext *newctx;
+
+      newctx = GNUNET_new(struct GNUNET_CADET_TEST_AdapterContext);
+      newctx->peer = i;
+      newctx->ctx = ctx;
+      GNUNET_log(GNUNET_ERROR_TYPE_INFO,
+                 "Connecting to cadet %u\n",
+                 i);
+      ctx->ops[i] = GNUNET_TESTBED_service_connect(ctx,
+                                                   peers[i],
+                                                   "cadet",
+                                                   &cadet_connect_cb,
+                                                   ctx,
+                                                   &cadet_connect_adapter,
+                                                   &cadet_disconnect_adapter,
+                                                   newctx);
+      GNUNET_log(GNUNET_ERROR_TYPE_INFO,
+                 "op handle %p\n",
+                 ctx->ops[i]);
+    }
 }
 
 
@@ -335,41 +333,41 @@ cadet_test_run (void *cls,
  * @param ports Ports the peers offer, NULL-terminated.
  */
 void
-GNUNET_CADET_TEST_ruN (const char *testname,
-                       const char *cfgfile,
-                       unsigned int num_peers,
-                       GNUNET_CADET_TEST_AppMain tmain,
-                       void *tmain_cls,
-                       GNUNET_CADET_ConnectEventHandler connects,
-                       GNUNET_CADET_WindowSizeEventHandler window_changes,
-                       GNUNET_CADET_DisconnectEventHandler disconnects,
-                       struct GNUNET_MQ_MessageHandler *handlers,
-                       const struct GNUNET_HashCode **ports)
+GNUNET_CADET_TEST_ruN(const char *testname,
+                      const char *cfgfile,
+                      unsigned int num_peers,
+                      GNUNET_CADET_TEST_AppMain tmain,
+                      void *tmain_cls,
+                      GNUNET_CADET_ConnectEventHandler connects,
+                      GNUNET_CADET_WindowSizeEventHandler window_changes,
+                      GNUNET_CADET_DisconnectEventHandler disconnects,
+                      struct GNUNET_MQ_MessageHandler *handlers,
+                      const struct GNUNET_HashCode **ports)
 {
   struct GNUNET_CADET_TEST_Context *ctx;
 
-  ctx = GNUNET_new (struct GNUNET_CADET_TEST_Context);
+  ctx = GNUNET_new(struct GNUNET_CADET_TEST_Context);
   ctx->num_peers = num_peers;
-  ctx->ops = GNUNET_new_array (num_peers,
-                               struct GNUNET_TESTBED_Operation *);
-  ctx->cadets = GNUNET_new_array (num_peers,
-                                  struct GNUNET_CADET_Handle *);
+  ctx->ops = GNUNET_new_array(num_peers,
+                              struct GNUNET_TESTBED_Operation *);
+  ctx->cadets = GNUNET_new_array(num_peers,
+                                 struct GNUNET_CADET_Handle *);
   ctx->app_main = tmain;
   ctx->app_main_cls = tmain_cls;
   ctx->connects = connects;
   ctx->window_changes = window_changes;
   ctx->disconnects = disconnects;
-  ctx->handlers = GNUNET_MQ_copy_handlers (handlers);
+  ctx->handlers = GNUNET_MQ_copy_handlers(handlers);
   ctx->ports = ports;
   ctx->port_count = 0;
   while (NULL != ctx->ports[ctx->port_count])
     ctx->port_count++;
-  GNUNET_TESTBED_test_run (testname,
-                           cfgfile,
-                           num_peers,
-                           0LL, NULL, NULL,
-                           &cadet_test_run,
-                           ctx);
+  GNUNET_TESTBED_test_run(testname,
+                          cfgfile,
+                          num_peers,
+                          0LL, NULL, NULL,
+                          &cadet_test_run,
+                          ctx);
 }
 
 /* end of cadet_test_lib.c */

+ 17 - 17
src/cadet/cadet_test_lib.h

@@ -11,12 +11,12 @@
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      Affero General Public License for more details.
-    
+
      You should have received a copy of the GNU Affero General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
-*/
+ */
 /**
  * @file cadet/cadet_test_lib.h
  * @author Bartlomiej Polot
@@ -52,10 +52,10 @@ struct GNUNET_CADET_TEST_Context;
  * @param cadets Handle to each of the CADETs of the peers.
  */
 typedef void (*GNUNET_CADET_TEST_AppMain) (void *cls,
-                                          struct GNUNET_CADET_TEST_Context *ctx,
-                                          unsigned int num_peers,
-                                          struct GNUNET_TESTBED_Peer **peers,
-                                          struct GNUNET_CADET_Handle **cadets);
+                                           struct GNUNET_CADET_TEST_Context *ctx,
+                                           unsigned int num_peers,
+                                           struct GNUNET_TESTBED_Peer **peers,
+                                           struct GNUNET_CADET_Handle **cadets);
 
 
 /**
@@ -74,16 +74,16 @@ typedef void (*GNUNET_CADET_TEST_AppMain) (void *cls,
  * @param ports Ports the peers offer, NULL-terminated.
  */
 void
-GNUNET_CADET_TEST_ruN (const char *testname,
-                       const char *cfgfile,
-                       unsigned int num_peers,
-                       GNUNET_CADET_TEST_AppMain tmain,
-                       void *tmain_cls,
-                       GNUNET_CADET_ConnectEventHandler connects,
-                       GNUNET_CADET_WindowSizeEventHandler window_changes,
-                       GNUNET_CADET_DisconnectEventHandler disconnects,
-                       struct GNUNET_MQ_MessageHandler *handlers,
-                       const struct GNUNET_HashCode **ports);
+GNUNET_CADET_TEST_ruN(const char *testname,
+                      const char *cfgfile,
+                      unsigned int num_peers,
+                      GNUNET_CADET_TEST_AppMain tmain,
+                      void *tmain_cls,
+                      GNUNET_CADET_ConnectEventHandler connects,
+                      GNUNET_CADET_WindowSizeEventHandler window_changes,
+                      GNUNET_CADET_DisconnectEventHandler disconnects,
+                      struct GNUNET_MQ_MessageHandler *handlers,
+                      const struct GNUNET_HashCode **ports);
 
 /**
  * Clean up the testbed.
@@ -91,7 +91,7 @@ GNUNET_CADET_TEST_ruN (const char *testname,
  * @param ctx handle for the testbed
  */
 void
-GNUNET_CADET_TEST_cleanup (struct GNUNET_CADET_TEST_Context *ctx);
+GNUNET_CADET_TEST_cleanup(struct GNUNET_CADET_TEST_Context *ctx);
 
 
 #if 0                           /* keep Emacsens' auto-indent happy */

+ 19 - 21
src/cadet/desirability_table.c

@@ -8,28 +8,26 @@
 #include <stdio.h>
 
 int
-main ()
+main()
 {
-  for (unsigned int num_alts=1; num_alts<10; num_alts++)
-    for (unsigned int off=0; off<10; off++)
-      for (double delta=-(int) off;delta<=5;delta += 0.25)
-      {
-        double weight_alts;
-
-        if (delta <= - 1.0)
-          weight_alts = - 1.0 * num_alts / delta; /* discount alternative paths */
-        else if (delta >= 1.0)
-          weight_alts = 1.0 * num_alts * delta; /* overcount alternative paths */
-        else
-          weight_alts = 1.0 * num_alts; /* count alternative paths normally */
-
-        fprintf (stderr,
-                 "Paths: %u  Offset: %u  Delta: %5.2f  SCORE: %f\n",
-                 num_alts,
-                 off,
-                 delta,
-                 ((off + 1.0) / (weight_alts * weight_alts)));
-      }
+  for (unsigned int num_alts = 1; num_alts < 10; num_alts++)
+    for (unsigned int off = 0; off < 10; off++)
+      for (double delta = -(int)off; delta <= 5; delta += 0.25)
+        {
+          double weight_alts;
 
+          if (delta <= -1.0)
+            weight_alts = -1.0 * num_alts / delta; /* discount alternative paths */
+          else if (delta >= 1.0)
+            weight_alts = 1.0 * num_alts * delta; /* overcount alternative paths */
+          else
+            weight_alts = 1.0 * num_alts; /* count alternative paths normally */
 
+          fprintf(stderr,
+                  "Paths: %u  Offset: %u  Delta: %5.2f  SCORE: %f\n",
+                  num_alts,
+                  off,
+                  delta,
+                  ((off + 1.0) / (weight_alts * weight_alts)));
+        }
 }

Plik diff jest za duży
+ 322 - 323
src/cadet/gnunet-cadet-profiler.c


+ 361 - 351
src/cadet/gnunet-cadet.c

@@ -16,7 +16,7 @@
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
-*/
+ */
 
 /**
  * @file cadet/gnunet-cadet.c
@@ -143,7 +143,7 @@ static unsigned int sent_pkt;
  * Wait for input on STDIO and send it out over the #ch.
  */
 static void
-listen_stdio (void);
+listen_stdio(void);
 
 
 /**
@@ -154,21 +154,25 @@ listen_stdio (void);
  * @return Human readable string.
  */
 static const char *
-enc_2s (uint16_t status)
+enc_2s(uint16_t status)
 {
   switch (status)
-  {
-  case 0:
-    return "NULL ";
-  case 1:
-    return "KSENT";
-  case 2:
-    return "KRECV";
-  case 3:
-    return "READY";
-  default:
-    return "";
-  }
+    {
+    case 0:
+      return "NULL ";
+
+    case 1:
+      return "KSENT";
+
+    case 2:
+      return "KRECV";
+
+    case 3:
+      return "READY";
+
+    default:
+      return "";
+    }
 }
 
 
@@ -180,23 +184,28 @@ enc_2s (uint16_t status)
  * @return Human readable string.
  */
 static const char *
-conn_2s (uint16_t status)
+conn_2s(uint16_t status)
 {
   switch (status)
-  {
-  case 0:
-    return "NEW  ";
-  case 1:
-    return "SRCH ";
-  case 2:
-    return "WAIT ";
-  case 3:
-    return "READY";
-  case 4:
-    return "SHUTD";
-  default:
-    return "";
-  }
+    {
+    case 0:
+      return "NEW  ";
+
+    case 1:
+      return "SRCH ";
+
+    case 2:
+      return "WAIT ";
+
+    case 3:
+      return "READY";
+
+    case 4:
+      return "SHUTD";
+
+    default:
+      return "";
+    }
 }
 
 
@@ -206,60 +215,60 @@ conn_2s (uint16_t status)
  * @param cls Closure (unused).
  */
 static void
-shutdown_task (void *cls)
+shutdown_task(void *cls)
 {
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown\n");
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Shutdown\n");
   if (NULL != lp)
-  {
-    GNUNET_CADET_close_port (lp);
-    lp = NULL;
-  }
+    {
+      GNUNET_CADET_close_port(lp);
+      lp = NULL;
+    }
   if (NULL != ch)
-  {
-    GNUNET_CADET_channel_destroy (ch);
-    ch = NULL;
-  }
+    {
+      GNUNET_CADET_channel_destroy(ch);
+      ch = NULL;
+    }
   if (NULL != gpo)
-  {
-    GNUNET_CADET_get_path_cancel (gpo);
-    gpo = NULL;
-  }
+    {
+      GNUNET_CADET_get_path_cancel(gpo);
+      gpo = NULL;
+    }
   if (NULL != plo)
-  {
-    GNUNET_CADET_list_peers_cancel (plo);
-    plo = NULL;
-  }
+    {
+      GNUNET_CADET_list_peers_cancel(plo);
+      plo = NULL;
+    }
   if (NULL != tio)
-  {
-    GNUNET_CADET_list_tunnels_cancel (tio);
-    tio = NULL;
-  }
+    {
+      GNUNET_CADET_list_tunnels_cancel(tio);
+      tio = NULL;
+    }
   if (NULL != mh)
-  {
-    GNUNET_CADET_disconnect (mh);
-    mh = NULL;
-  }
+    {
+      GNUNET_CADET_disconnect(mh);
+      mh = NULL;
+    }
   if (NULL != rd_task)
-  {
-    GNUNET_SCHEDULER_cancel (rd_task);
-    rd_task = NULL;
-  }
+    {
+      GNUNET_SCHEDULER_cancel(rd_task);
+      rd_task = NULL;
+    }
   if (NULL != echo_task)
-  {
-    GNUNET_SCHEDULER_cancel (echo_task);
-    echo_task = NULL;
-  }
+    {
+      GNUNET_SCHEDULER_cancel(echo_task);
+      echo_task = NULL;
+    }
   if (NULL != job)
-  {
-    GNUNET_SCHEDULER_cancel (job);
-    job = NULL;
-  }
+    {
+      GNUNET_SCHEDULER_cancel(job);
+      job = NULL;
+    }
 }
 
 void
-mq_cb (void *cls)
+mq_cb(void *cls)
 {
-  listen_stdio ();
+  listen_stdio();
 }
 
 
@@ -269,7 +278,7 @@ mq_cb (void *cls)
  * @param cls Closure (unused).
  */
 static void
-read_stdio (void *cls)
+read_stdio(void *cls)
 {
   struct GNUNET_MQ_Envelope *env;
   struct GNUNET_MessageHeader *msg;
@@ -277,41 +286,41 @@ read_stdio (void *cls)
   ssize_t data_size;
 
   rd_task = NULL;
-  data_size = read (0, buf, 60000);
+  data_size = read(0, buf, 60000);
   if (data_size < 1)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "read() returned  %s\n",
-                strerror (errno));
-    GNUNET_SCHEDULER_shutdown ();
-    return;
-  }
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Read %u bytes from stdio\n",
-              (unsigned int) data_size);
-  env = GNUNET_MQ_msg_extra (msg, data_size, GNUNET_MESSAGE_TYPE_CADET_CLI);
-  GNUNET_memcpy (&msg[1], buf, data_size);
-  GNUNET_MQ_send (GNUNET_CADET_get_mq (ch), env);
+    {
+      GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+                 "read() returned  %s\n",
+                 strerror(errno));
+      GNUNET_SCHEDULER_shutdown();
+      return;
+    }
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+             "Read %u bytes from stdio\n",
+             (unsigned int)data_size);
+  env = GNUNET_MQ_msg_extra(msg, data_size, GNUNET_MESSAGE_TYPE_CADET_CLI);
+  GNUNET_memcpy(&msg[1], buf, data_size);
+  GNUNET_MQ_send(GNUNET_CADET_get_mq(ch), env);
 
   sent_pkt++;
 
   if (GNUNET_NO == echo)
-  {
-    // Use MQ's notification if too much data of stdin is pooring in too fast.
-    if (STREAM_BUFFER_SIZE < sent_pkt)
     {
-      GNUNET_MQ_notify_sent (env, mq_cb, cls);
-      sent_pkt = 0;
+      // Use MQ's notification if too much data of stdin is pooring in too fast.
+      if (STREAM_BUFFER_SIZE < sent_pkt)
+        {
+          GNUNET_MQ_notify_sent(env, mq_cb, cls);
+          sent_pkt = 0;
+        }
+      else
+        {
+          listen_stdio();
+        }
     }
-    else
+  else
     {
-      listen_stdio ();
+      echo_time = GNUNET_TIME_absolute_get();
     }
-  }
-  else
-  {
-    echo_time = GNUNET_TIME_absolute_get ();
-  }
 }
 
 
@@ -319,20 +328,20 @@ read_stdio (void *cls)
  * Wait for input on STDIO and send it out over the #ch.
  */
 static void
-listen_stdio ()
+listen_stdio()
 {
   struct GNUNET_NETWORK_FDSet *rs;
 
   /* FIXME: why use 'rs' here, seems overly complicated... */
-  rs = GNUNET_NETWORK_fdset_create ();
-  GNUNET_NETWORK_fdset_set_native (rs, 0); /* STDIN */
-  rd_task = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
-                                         GNUNET_TIME_UNIT_FOREVER_REL,
-                                         rs,
-                                         NULL,
-                                         &read_stdio,
-                                         NULL);
-  GNUNET_NETWORK_fdset_destroy (rs);
+  rs = GNUNET_NETWORK_fdset_create();
+  GNUNET_NETWORK_fdset_set_native(rs, 0);  /* STDIN */
+  rd_task = GNUNET_SCHEDULER_add_select(GNUNET_SCHEDULER_PRIORITY_DEFAULT,
+                                        GNUNET_TIME_UNIT_FOREVER_REL,
+                                        rs,
+                                        NULL,
+                                        &read_stdio,
+                                        NULL);
+  GNUNET_NETWORK_fdset_destroy(rs);
 }
 
 
@@ -346,12 +355,12 @@ listen_stdio ()
  * @param channel connection to the other end (henceforth invalid)
  */
 static void
-channel_ended (void *cls, const struct GNUNET_CADET_Channel *channel)
+channel_ended(void *cls, const struct GNUNET_CADET_Channel *channel)
 {
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Channel ended!\n");
-  GNUNET_assert (channel == ch);
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Channel ended!\n");
+  GNUNET_assert(channel == ch);
   ch = NULL;
-  GNUNET_SCHEDULER_shutdown ();
+  GNUNET_SCHEDULER_shutdown();
 }
 
 
@@ -370,20 +379,20 @@ channel_ended (void *cls, const struct GNUNET_CADET_Channel *channel)
  * @return initial channel context for the channel, we use @a channel
  */
 static void *
-channel_incoming (void *cls,
-                  struct GNUNET_CADET_Channel *channel,
-                  const struct GNUNET_PeerIdentity *initiator)
+channel_incoming(void *cls,
+                 struct GNUNET_CADET_Channel *channel,
+                 const struct GNUNET_PeerIdentity *initiator)
 {
-  GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
-              "Incoming connection from %s\n",
-              GNUNET_i2s_full (initiator));
-  GNUNET_assert (NULL == ch);
-  GNUNET_assert (NULL != lp);
-  GNUNET_CADET_close_port (lp);
+  GNUNET_log(GNUNET_ERROR_TYPE_MESSAGE,
+             "Incoming connection from %s\n",
+             GNUNET_i2s_full(initiator));
+  GNUNET_assert(NULL == ch);
+  GNUNET_assert(NULL != lp);
+  GNUNET_CADET_close_port(lp);
   lp = NULL;
   ch = channel;
   if (GNUNET_NO == echo)
-    listen_stdio ();
+    listen_stdio();
   return channel;
 }
 
@@ -394,7 +403,7 @@ channel_incoming (void *cls,
  * @param cls Closure (NULL).
  */
 static void
-send_echo (void *cls)
+send_echo(void *cls)
 {
   struct GNUNET_MQ_Envelope *env;
   struct GNUNET_MessageHeader *msg;
@@ -402,8 +411,8 @@ send_echo (void *cls)
   echo_task = NULL;
   if (NULL == ch)
     return;
-  env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_CADET_CLI);
-  GNUNET_MQ_send (GNUNET_CADET_get_mq (ch), env);
+  env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_CADET_CLI);
+  GNUNET_MQ_send(GNUNET_CADET_get_mq(ch), env);
 }
 
 
@@ -416,7 +425,7 @@ send_echo (void *cls)
  *         #GNUNET_SYSERR to close it (signal serious error).
  */
 static int
-check_data (void *cls, const struct GNUNET_MessageHeader *message)
+check_data(void *cls, const struct GNUNET_MessageHeader *message)
 {
   return GNUNET_OK; /* all is well-formed */
 }
@@ -433,59 +442,59 @@ check_data (void *cls, const struct GNUNET_MessageHeader *message)
  * @param message The actual message.
  */
 static void
-handle_data (void *cls, const struct GNUNET_MessageHeader *message)
+handle_data(void *cls, const struct GNUNET_MessageHeader *message)
 {
-  size_t payload_size = ntohs (message->size) - sizeof (*message);
+  size_t payload_size = ntohs(message->size) - sizeof(*message);
   uint16_t len;
   ssize_t done;
   uint16_t off;
   const char *buf;
 
-  GNUNET_CADET_receive_done (ch);
+  GNUNET_CADET_receive_done(ch);
   if (GNUNET_YES == echo)
-  {
-    if (NULL != listen_port)
-    {
-      struct GNUNET_MQ_Envelope *env;
-      struct GNUNET_MessageHeader *msg;
-
-      env =
-        GNUNET_MQ_msg_extra (msg, payload_size, GNUNET_MESSAGE_TYPE_CADET_CLI);
-      GNUNET_memcpy (&msg[1], &message[1], payload_size);
-      GNUNET_MQ_send (GNUNET_CADET_get_mq (ch), env);
-      return;
-    }
-    else
     {
-      struct GNUNET_TIME_Relative latency;
-
-      latency = GNUNET_TIME_absolute_get_duration (echo_time);
-      echo_time = GNUNET_TIME_UNIT_FOREVER_ABS;
-      GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
-                  "time: %s\n",
-                  GNUNET_STRINGS_relative_time_to_string (latency, GNUNET_NO));
-      echo_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
-                                                &send_echo,
-                                                NULL);
+      if (NULL != listen_port)
+        {
+          struct GNUNET_MQ_Envelope *env;
+          struct GNUNET_MessageHeader *msg;
+
+          env =
+            GNUNET_MQ_msg_extra(msg, payload_size, GNUNET_MESSAGE_TYPE_CADET_CLI);
+          GNUNET_memcpy(&msg[1], &message[1], payload_size);
+          GNUNET_MQ_send(GNUNET_CADET_get_mq(ch), env);
+          return;
+        }
+      else
+        {
+          struct GNUNET_TIME_Relative latency;
+
+          latency = GNUNET_TIME_absolute_get_duration(echo_time);
+          echo_time = GNUNET_TIME_UNIT_FOREVER_ABS;
+          GNUNET_log(GNUNET_ERROR_TYPE_MESSAGE,
+                     "time: %s\n",
+                     GNUNET_STRINGS_relative_time_to_string(latency, GNUNET_NO));
+          echo_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS,
+                                                   &send_echo,
+                                                   NULL);
+        }
     }
-  }
 
-  len = ntohs (message->size) - sizeof (*message);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got %u bytes\n", len);
-  buf = (const char *) &message[1];
+  len = ntohs(message->size) - sizeof(*message);
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Got %u bytes\n", len);
+  buf = (const char *)&message[1];
   off = 0;
   while (off < len)
-  {
-    done = write (1, &buf[off], len - off);
-    if (done <= 0)
     {
-      if (-1 == done)
-        GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "write");
-      GNUNET_SCHEDULER_shutdown ();
-      return;
+      done = write(1, &buf[off], len - off);
+      if (done <= 0)
+        {
+          if (-1 == done)
+            GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "write");
+          GNUNET_SCHEDULER_shutdown();
+          return;
+        }
+      off += done;
     }
-    off += done;
-  }
 }
 
 
@@ -499,19 +508,19 @@ handle_data (void *cls, const struct GNUNET_MessageHeader *message)
  * @param ple information about peer, or NULL on "EOF".
  */
 static void
-peers_callback (void *cls, const struct GNUNET_CADET_PeerListEntry *ple)
+peers_callback(void *cls, const struct GNUNET_CADET_PeerListEntry *ple)
 {
   if (NULL == ple)
-  {
-    plo = NULL;
-    GNUNET_SCHEDULER_shutdown ();
-    return;
-  }
-  fprintf (stdout,
-           "%s tunnel: %c, paths: %u\n",
-           GNUNET_i2s_full (&ple->peer),
-           ple->have_tunnel ? 'Y' : 'N',
-           ple->n_paths);
+    {
+      plo = NULL;
+      GNUNET_SCHEDULER_shutdown();
+      return;
+    }
+  fprintf(stdout,
+          "%s tunnel: %c, paths: %u\n",
+          GNUNET_i2s_full(&ple->peer),
+          ple->have_tunnel ? 'Y' : 'N',
+          ple->n_paths);
 }
 
 
@@ -523,20 +532,20 @@ peers_callback (void *cls, const struct GNUNET_CADET_PeerListEntry *ple)
  * @param ppd path detail
  */
 static void
-path_callback (void *cls, const struct GNUNET_CADET_PeerPathDetail *ppd)
+path_callback(void *cls, const struct GNUNET_CADET_PeerPathDetail *ppd)
 {
   if (NULL == ppd)
-  {
-    gpo = NULL;
-    GNUNET_SCHEDULER_shutdown ();
-    return;
-  }
-  fprintf (stdout, "Path of length %u: ", ppd->path_length);
+    {
+      gpo = NULL;
+      GNUNET_SCHEDULER_shutdown();
+      return;
+    }
+  fprintf(stdout, "Path of length %u: ", ppd->path_length);
   for (unsigned int i = 0; i < ppd->path_length; i++)
-    fprintf (stdout,
-             (i == ppd->target_offset) ? "*%s* " : "%s ",
-             GNUNET_i2s (&ppd->path[i]));
-  fprintf (stdout, "\n");
+    fprintf(stdout,
+            (i == ppd->target_offset) ? "*%s* " : "%s ",
+            GNUNET_i2s(&ppd->path[i]));
+  fprintf(stdout, "\n");
 }
 
 
@@ -547,21 +556,21 @@ path_callback (void *cls, const struct GNUNET_CADET_PeerPathDetail *ppd)
  * @param td tunnel details
  */
 static void
-tunnels_callback (void *cls, const struct GNUNET_CADET_TunnelDetails *td)
+tunnels_callback(void *cls, const struct GNUNET_CADET_TunnelDetails *td)
 {
   if (NULL == td)
-  {
-    tio = NULL;
-    GNUNET_SCHEDULER_shutdown ();
-    return;
-  }
-  fprintf (stdout,
-           "%s [ENC: %s, CON: %s] CHs: %u, CONNs: %u\n",
-           GNUNET_i2s_full (&td->peer),
-           enc_2s (td->estate),
-           conn_2s (td->cstate),
-           td->channels,
-           td->connections);
+    {
+      tio = NULL;
+      GNUNET_SCHEDULER_shutdown();
+      return;
+    }
+  fprintf(stdout,
+          "%s [ENC: %s, CON: %s] CHs: %u, CONNs: %u\n",
+          GNUNET_i2s_full(&td->peer),
+          enc_2s(td->estate),
+          conn_2s(td->cstate),
+          td->channels,
+          td->connections);
 }
 
 
@@ -571,10 +580,10 @@ tunnels_callback (void *cls, const struct GNUNET_CADET_TunnelDetails *td)
  * @param cls Closure (unused).
  */
 static void
-get_peers (void *cls)
+get_peers(void *cls)
 {
   job = NULL;
-  plo = GNUNET_CADET_list_peers (my_cfg, &peers_callback, NULL);
+  plo = GNUNET_CADET_list_peers(my_cfg, &peers_callback, NULL);
 }
 
 
@@ -584,20 +593,20 @@ get_peers (void *cls)
  * @param cls Closure (unused).
  */
 static void
-show_peer (void *cls)
+show_peer(void *cls)
 {
   struct GNUNET_PeerIdentity pid;
 
   job = NULL;
-  if (GNUNET_OK != GNUNET_CRYPTO_eddsa_public_key_from_string (peer_id,
-                                                               strlen (peer_id),
-                                                               &pid.public_key))
-  {
-    fprintf (stderr, _ ("Invalid peer ID `%s'\n"), peer_id);
-    GNUNET_SCHEDULER_shutdown ();
-    return;
-  }
-  gpo = GNUNET_CADET_get_path (my_cfg, &pid, &path_callback, NULL);
+  if (GNUNET_OK != GNUNET_CRYPTO_eddsa_public_key_from_string(peer_id,
+                                                              strlen(peer_id),
+                                                              &pid.public_key))
+    {
+      fprintf(stderr, _("Invalid peer ID `%s'\n"), peer_id);
+      GNUNET_SCHEDULER_shutdown();
+      return;
+    }
+  gpo = GNUNET_CADET_get_path(my_cfg, &pid, &path_callback, NULL);
 }
 
 
@@ -607,10 +616,10 @@ show_peer (void *cls)
  * @param cls Closure (unused).
  */
 static void
-get_tunnels (void *cls)
+get_tunnels(void *cls)
 {
   job = NULL;
-  tio = GNUNET_CADET_list_tunnels (my_cfg, &tunnels_callback, NULL);
+  tio = GNUNET_CADET_list_tunnels(my_cfg, &tunnels_callback, NULL);
 }
 
 
@@ -620,10 +629,10 @@ get_tunnels (void *cls)
  * @param cls Closure (unused).
  */
 static void
-show_channel (void *cls)
+show_channel(void *cls)
 {
   job = NULL;
-  GNUNET_break (0);
+  GNUNET_break(0);
 }
 
 
@@ -633,10 +642,10 @@ show_channel (void *cls)
  * @param cls Closure (unused).
  */
 static void
-show_connection (void *cls)
+show_connection(void *cls)
 {
   job = NULL;
-  GNUNET_break (0);
+  GNUNET_break(0);
 }
 
 
@@ -649,17 +658,17 @@ show_connection (void *cls)
  * @param cfg configuration
  */
 static void
-run (void *cls,
-     char *const *args,
-     const char *cfgfile,
-     const struct GNUNET_CONFIGURATION_Handle *cfg)
+run(void *cls,
+    char *const *args,
+    const char *cfgfile,
+    const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
   struct GNUNET_MQ_MessageHandler handlers[] =
-    {GNUNET_MQ_hd_var_size (data,
-                            GNUNET_MESSAGE_TYPE_CADET_CLI,
-                            struct GNUNET_MessageHeader,
-                            NULL),
-     GNUNET_MQ_handler_end ()};
+  { GNUNET_MQ_hd_var_size(data,
+                          GNUNET_MESSAGE_TYPE_CADET_CLI,
+                          struct GNUNET_MessageHeader,
+                          NULL),
+    GNUNET_MQ_handler_end() };
 
   /* FIXME add option to monitor apps */
   my_cfg = cfg;
@@ -670,102 +679,102 @@ run (void *cls,
   if ((0 != (request_peers | request_tunnels) || NULL != conn_id ||
        NULL != channel_id) &&
       target_id != NULL)
-  {
-    fprintf (stderr,
-             _ ("Extra arguments are not applicable "
+    {
+      fprintf(stderr,
+              _("Extra arguments are not applicable "
                 "in combination with this option.\n"));
-    return;
-  }
+      return;
+    }
 
   if (NULL != peer_id)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show peer\n");
-    job = GNUNET_SCHEDULER_add_now (&show_peer, NULL);
-  }
+    {
+      GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Show peer\n");
+      job = GNUNET_SCHEDULER_add_now(&show_peer, NULL);
+    }
   else if (NULL != channel_id)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show channel\n");
-    job = GNUNET_SCHEDULER_add_now (&show_channel, NULL);
-  }
+    {
+      GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Show channel\n");
+      job = GNUNET_SCHEDULER_add_now(&show_channel, NULL);
+    }
   else if (NULL != conn_id)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show connection\n");
-    job = GNUNET_SCHEDULER_add_now (&show_connection, NULL);
-  }
+    {
+      GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Show connection\n");
+      job = GNUNET_SCHEDULER_add_now(&show_connection, NULL);
+    }
   else if (GNUNET_YES == request_peers)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show all peers\n");
-    job = GNUNET_SCHEDULER_add_now (&get_peers, NULL);
-  }
+    {
+      GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Show all peers\n");
+      job = GNUNET_SCHEDULER_add_now(&get_peers, NULL);
+    }
   else if (GNUNET_YES == request_tunnels)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show all tunnels\n");
-    job = GNUNET_SCHEDULER_add_now (&get_tunnels, NULL);
-  }
-
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting to CADET service\n");
-  mh = GNUNET_CADET_connect (cfg);
-  GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
-  if (NULL == mh)
-  {
-    GNUNET_SCHEDULER_shutdown ();
-    return;
-  }
-  if (NULL != listen_port)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Opening CADET listen port\n");
-    GNUNET_CRYPTO_hash (listen_port, strlen (listen_port), &porthash);
-    lp = GNUNET_CADET_open_port (mh,
-                                 &porthash,
-                                 &channel_incoming,
-                                 NULL,
-                                 NULL /* window changes */,
-                                 &channel_ended,
-                                 handlers);
-  }
-  if (NULL != target_id)
-  {
-    struct GNUNET_PeerIdentity pid;
+    {
+      GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Show all tunnels\n");
+      job = GNUNET_SCHEDULER_add_now(&get_tunnels, NULL);
+    }
 
-    if (GNUNET_OK !=
-        GNUNET_CRYPTO_eddsa_public_key_from_string (target_id,
-                                                    strlen (target_id),
-                                                    &pid.public_key))
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Connecting to CADET service\n");
+  mh = GNUNET_CADET_connect(cfg);
+  GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL);
+  if (NULL == mh)
     {
-      GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
-                  _ ("Invalid target `%s'\n"),
-                  target_id);
-      GNUNET_SCHEDULER_shutdown ();
+      GNUNET_SCHEDULER_shutdown();
       return;
     }
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "Connecting to `%s:%s'\n",
-                target_id,
-                target_port);
-    GNUNET_CRYPTO_hash (target_port, strlen (target_port), &porthash);
-    ch = GNUNET_CADET_channel_create (mh,
-                                      NULL,
-                                      &pid,
-                                      &porthash,
-                                      NULL /* window changes */,
-                                      &channel_ended,
-                                      handlers);
-    if (GNUNET_YES == echo)
+  if (NULL != listen_port)
     {
-      echo_task = GNUNET_SCHEDULER_add_now (&send_echo, NULL);
+      GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Opening CADET listen port\n");
+      GNUNET_CRYPTO_hash(listen_port, strlen(listen_port), &porthash);
+      lp = GNUNET_CADET_open_port(mh,
+                                  &porthash,
+                                  &channel_incoming,
+                                  NULL,
+                                  NULL /* window changes */,
+                                  &channel_ended,
+                                  handlers);
     }
-    else
+  if (NULL != target_id)
     {
-      listen_stdio ();
+      struct GNUNET_PeerIdentity pid;
+
+      if (GNUNET_OK !=
+          GNUNET_CRYPTO_eddsa_public_key_from_string(target_id,
+                                                     strlen(target_id),
+                                                     &pid.public_key))
+        {
+          GNUNET_log(GNUNET_ERROR_TYPE_MESSAGE,
+                     _("Invalid target `%s'\n"),
+                     target_id);
+          GNUNET_SCHEDULER_shutdown();
+          return;
+        }
+      GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+                 "Connecting to `%s:%s'\n",
+                 target_id,
+                 target_port);
+      GNUNET_CRYPTO_hash(target_port, strlen(target_port), &porthash);
+      ch = GNUNET_CADET_channel_create(mh,
+                                       NULL,
+                                       &pid,
+                                       &porthash,
+                                       NULL /* window changes */,
+                                       &channel_ended,
+                                       handlers);
+      if (GNUNET_YES == echo)
+        {
+          echo_task = GNUNET_SCHEDULER_add_now(&send_echo, NULL);
+        }
+      else
+        {
+          listen_stdio();
+        }
     }
-  }
 
   if ((NULL == lp) && (NULL == job) && (NULL == ch))
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, _ ("No action requested\n"));
-    GNUNET_SCHEDULER_shutdown ();
-    return;
-  }
+    {
+      GNUNET_log(GNUNET_ERROR_TYPE_MESSAGE, _("No action requested\n"));
+      GNUNET_SCHEDULER_shutdown();
+      return;
+    }
 }
 
 
@@ -777,60 +786,61 @@ run (void *cls,
  * @return 0 ok, 1 on error
  */
 int
-main (int argc, char *const *argv)
+main(int argc, char *const *argv)
 {
   int res;
   const char helpstr[] =
     "Create tunnels and retrieve info about CADET's status.";
   struct GNUNET_GETOPT_CommandLineOption options[] =
-    {/* I would use the terminology 'circuit' here...  --lynX */
-     GNUNET_GETOPT_option_string (
-       'C',
-       "connection",
-       "CONNECTION_ID",
-       gettext_noop ("Provide information about a particular connection"),
-       &conn_id),
-     GNUNET_GETOPT_option_flag ('e',
-                                "echo",
-                                gettext_noop ("Activate echo mode"),
-                                &echo),
-     GNUNET_GETOPT_option_string (
-       'o',
-       "open-port",
-       "SHARED_SECRET",
-       gettext_noop (
-         "Listen for connections using a shared secret among sender and recipient"),
-       &listen_port),
-     GNUNET_GETOPT_option_string ('p',
-                                  "peer",
-                                  "PEER_ID",
-                                  gettext_noop (
-                                    "Provide information about a patricular peer"),
-                                  &peer_id),
-     GNUNET_GETOPT_option_flag ('P',
-                                "peers",
-                                gettext_noop (
-                                  "Provide information about all peers"),
-                                &request_peers),
-     GNUNET_GETOPT_option_flag ('T',
-                                "tunnels",
-                                gettext_noop (
-                                  "Provide information about all tunnels"),
-                                &request_tunnels),
-     GNUNET_GETOPT_OPTION_END};
-
-  if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
+  {  /* I would use the terminology 'circuit' here...  --lynX */
+    GNUNET_GETOPT_option_string(
+      'C',
+      "connection",
+      "CONNECTION_ID",
+      gettext_noop("Provide information about a particular connection"),
+      &conn_id),
+    GNUNET_GETOPT_option_flag('e',
+                              "echo",
+                              gettext_noop("Activate echo mode"),
+                              &echo),
+    GNUNET_GETOPT_option_string(
+      'o',
+      "open-port",
+      "SHARED_SECRET",
+      gettext_noop(
+        "Listen for connections using a shared secret among sender and recipient"),
+      &listen_port),
+    GNUNET_GETOPT_option_string('p',
+                                "peer",
+                                "PEER_ID",
+                                gettext_noop(
+                                  "Provide information about a patricular peer"),
+                                &peer_id),
+    GNUNET_GETOPT_option_flag('P',
+                              "peers",
+                              gettext_noop(
+                                "Provide information about all peers"),
+                              &request_peers),
+    GNUNET_GETOPT_option_flag('T',
+                              "tunnels",
+                              gettext_noop(
+                                "Provide information about all tunnels"),
+                              &request_tunnels),
+    GNUNET_GETOPT_OPTION_END
+  };
+
+  if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv))
     return 2;
 
-  res = GNUNET_PROGRAM_run (argc,
-                            argv,
-                            "gnunet-cadet (OPTIONS | PEER_ID SHARED_SECRET)",
-                            gettext_noop (helpstr),
-                            options,
-                            &run,
-                            NULL);
+  res = GNUNET_PROGRAM_run(argc,
+                           argv,
+                           "gnunet-cadet (OPTIONS | PEER_ID SHARED_SECRET)",
+                           gettext_noop(helpstr),
+                           options,
+                           &run,
+                           NULL);
 
-  GNUNET_free ((void *) argv);
+  GNUNET_free((void *)argv);
 
   if (GNUNET_OK == res)
     return 0;

Plik diff jest za duży
+ 364 - 365
src/cadet/gnunet-service-cadet.c


+ 18 - 24
src/cadet/gnunet-service-cadet.h

@@ -12,12 +12,12 @@
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      Affero General Public License for more details.
-    
+
      You should have received a copy of the GNU Affero General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
-*/
+ */
 
 /**
  * @file cadet/gnunet-service-cadet.h
@@ -64,8 +64,7 @@ struct CadetPeerPath;
 /**
  * Entry in a peer path.
  */
-struct CadetPeerPathEntry
-{
+struct CadetPeerPathEntry {
   /**
    * DLL of paths where the same @e peer is at the same offset.
    */
@@ -99,14 +98,12 @@ struct CadetPeerPathEntry
    * against overflows.
    */
   int score;
-
 };
 
 /**
  * Entry in list of connections used by tunnel, with metadata.
  */
-struct CadetTConnection
-{
+struct CadetTConnection {
   /**
    * Next in DLL.
    */
@@ -147,9 +144,7 @@ struct CadetTConnection
 /**
  * Port opened by a client.
  */
-struct OpenPort
-{
-
+struct OpenPort {
   /**
    * Client that opened the port.
    */
@@ -164,7 +159,6 @@ struct OpenPort
    * Port hashed with our PID (matches incoming OPEN messages).
    */
   struct GNUNET_HashCode h_port;
-  
 };
 
 
@@ -272,8 +266,8 @@ extern unsigned long long drop_percent;
  * @param env envelope with the message
  */
 void
-GSC_send_to_client (struct CadetClient *c,
-                    struct GNUNET_MQ_Envelope *env);
+GSC_send_to_client(struct CadetClient *c,
+                   struct GNUNET_MQ_Envelope *env);
 
 
 /**
@@ -284,9 +278,9 @@ GSC_send_to_client (struct CadetClient *c,
  * @param ch the channel object
  */
 void
-GSC_handle_remote_channel_destroy (struct CadetClient *c,
-                                   struct GNUNET_CADET_ClientChannelNumber ccn,
-                                   struct CadetChannel *ch);
+GSC_handle_remote_channel_destroy(struct CadetClient *c,
+                                  struct GNUNET_CADET_ClientChannelNumber ccn,
+                                  struct CadetChannel *ch);
 
 /**
  * A client that created a loose channel that was not bound to a port
@@ -296,8 +290,8 @@ GSC_handle_remote_channel_destroy (struct CadetClient *c,
  * @param ch the channel that was lost
  */
 void
-GSC_drop_loose_channel (const struct GNUNET_HashCode *h_port,
-                        struct CadetChannel *ch);
+GSC_drop_loose_channel(const struct GNUNET_HashCode *h_port,
+                       struct CadetChannel *ch);
 
 
 /**
@@ -312,11 +306,11 @@ GSC_drop_loose_channel (const struct GNUNET_HashCode *h_port,
  * @return local channel number assigned to the new client
  */
 struct GNUNET_CADET_ClientChannelNumber
-GSC_bind (struct CadetClient *c,
-          struct CadetChannel *ch,
-          struct CadetPeer *dest,
-          const struct GNUNET_HashCode *port,
-          uint32_t options);
+GSC_bind(struct CadetClient *c,
+         struct CadetChannel *ch,
+         struct CadetPeer *dest,
+         const struct GNUNET_HashCode *port,
+         uint32_t options);
 
 
 /**
@@ -326,7 +320,7 @@ GSC_bind (struct CadetClient *c,
  * @return string for debugging
  */
 const char *
-GSC_2s (struct CadetClient *c);
+GSC_2s(struct CadetClient *c);
 
 
 #endif

Plik diff jest za duży
+ 334 - 337
src/cadet/gnunet-service-cadet_channel.c


+ 45 - 45
src/cadet/gnunet-service-cadet_channel.h

@@ -11,12 +11,12 @@
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      Affero General Public License for more details.
-    
+
      You should have received a copy of the GNU Affero General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
-*/
+ */
 
 /**
  * @file cadet/gnunet-service-cadet_channel.h
@@ -44,7 +44,7 @@ struct CadetChannel;
 
 
 /**
- * Hash the @a port and @a initiator and @a listener to 
+ * Hash the @a port and @a initiator and @a listener to
  * calculate the "challenge" @a h_port we send to the other
  * peer on #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN.
  *
@@ -53,9 +53,9 @@ struct CadetChannel;
  * @param listener peer that is listining on @a port
  */
 void
-GCCH_hash_port (struct GNUNET_HashCode *h_port,
-		const struct GNUNET_HashCode *port,
-		const struct GNUNET_PeerIdentity *listener);
+GCCH_hash_port(struct GNUNET_HashCode *h_port,
+               const struct GNUNET_HashCode *port,
+               const struct GNUNET_PeerIdentity *listener);
 
 
 /**
@@ -66,7 +66,7 @@ GCCH_hash_port (struct GNUNET_HashCode *h_port,
  * @return Static string with the channel IDs.
  */
 const char *
-GCCH_2s (const struct CadetChannel *ch);
+GCCH_2s(const struct CadetChannel *ch);
 
 
 /**
@@ -76,8 +76,8 @@ GCCH_2s (const struct CadetChannel *ch);
  * @param level Debug level to use.
  */
 void
-GCCH_debug (struct CadetChannel *ch,
-            enum GNUNET_ErrorType level);
+GCCH_debug(struct CadetChannel *ch,
+           enum GNUNET_ErrorType level);
 
 
 /**
@@ -88,7 +88,7 @@ GCCH_debug (struct CadetChannel *ch,
  * @return ID used to identify the channel with the remote peer.
  */
 struct GNUNET_CADET_ChannelTunnelNumber
-GCCH_get_id (const struct CadetChannel *ch);
+GCCH_get_id(const struct CadetChannel *ch);
 
 
 /**
@@ -102,11 +102,11 @@ GCCH_get_id (const struct CadetChannel *ch);
  * @return handle to the new channel
  */
 struct CadetChannel *
-GCCH_channel_local_new (struct CadetClient *owner,
-                        struct GNUNET_CADET_ClientChannelNumber owner_id,
-                        struct CadetPeer *destination,
-                        const struct GNUNET_HashCode *port,
-                        uint32_t options);
+GCCH_channel_local_new(struct CadetClient *owner,
+                       struct GNUNET_CADET_ClientChannelNumber owner_id,
+                       struct CadetPeer *destination,
+                       const struct GNUNET_HashCode *port,
+                       uint32_t options);
 
 
 /**
@@ -119,9 +119,9 @@ GCCH_channel_local_new (struct CadetClient *owner,
  * @param port port number @a c is listening on
  */
 void
-GCCH_bind (struct CadetChannel *ch,
-           struct CadetClient *c,
-	   const struct GNUNET_HashCode *port);
+GCCH_bind(struct CadetChannel *ch,
+          struct CadetClient *c,
+          const struct GNUNET_HashCode *port);
 
 
 /**
@@ -133,9 +133,9 @@ GCCH_bind (struct CadetChannel *ch,
  * @param ccn client number of the client @a c
  */
 void
-GCCH_channel_local_destroy (struct CadetChannel *ch,
-                            struct CadetClient *c,
-                            struct GNUNET_CADET_ClientChannelNumber ccn);
+GCCH_channel_local_destroy(struct CadetChannel *ch,
+                           struct CadetClient *c,
+                           struct GNUNET_CADET_ClientChannelNumber ccn);
 
 
 /**
@@ -149,7 +149,7 @@ GCCH_channel_local_destroy (struct CadetChannel *ch,
  * @param ch the channel for which the tunnel is now ready
  */
 void
-GCCH_tunnel_up (struct CadetChannel *ch);
+GCCH_tunnel_up(struct CadetChannel *ch);
 
 
 /**
@@ -163,10 +163,10 @@ GCCH_tunnel_up (struct CadetChannel *ch);
  * @return handle to the new channel
  */
 struct CadetChannel *
-GCCH_channel_incoming_new (struct CadetTunnel *t,
-                           struct GNUNET_CADET_ChannelTunnelNumber chid,
-                           const struct GNUNET_HashCode *h_port,
-                           uint32_t options);
+GCCH_channel_incoming_new(struct CadetTunnel *t,
+                          struct GNUNET_CADET_ChannelTunnelNumber chid,
+                          const struct GNUNET_HashCode *h_port,
+                          uint32_t options);
 
 
 /**
@@ -178,8 +178,8 @@ GCCH_channel_incoming_new (struct CadetTunnel *t,
  * @param cti identifier of the connection that delivered the message
  */
 void
-GCCH_handle_duplicate_open (struct CadetChannel *ch,
-                            const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti);
+GCCH_handle_duplicate_open(struct CadetChannel *ch,
+                           const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti);
 
 
 
@@ -191,9 +191,9 @@ GCCH_handle_duplicate_open (struct CadetChannel *ch,
  * @param msg message that was received
  */
 void
-GCCH_handle_channel_plaintext_data (struct CadetChannel *ch,
-                                    const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti,
-                                    const struct GNUNET_CADET_ChannelAppDataMessage *msg);
+GCCH_handle_channel_plaintext_data(struct CadetChannel *ch,
+                                   const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti,
+                                   const struct GNUNET_CADET_ChannelAppDataMessage *msg);
 
 
 /**
@@ -205,9 +205,9 @@ GCCH_handle_channel_plaintext_data (struct CadetChannel *ch,
  * @param ack details about what was received
  */
 void
-GCCH_handle_channel_plaintext_data_ack (struct CadetChannel *ch,
-                                        const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti,
-                                        const struct GNUNET_CADET_ChannelDataAckMessage *ack);
+GCCH_handle_channel_plaintext_data_ack(struct CadetChannel *ch,
+                                       const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti,
+                                       const struct GNUNET_CADET_ChannelDataAckMessage *ack);
 
 
 /**
@@ -220,9 +220,9 @@ GCCH_handle_channel_plaintext_data_ack (struct CadetChannel *ch,
  * @param port port number (needed to verify receiver knows the port)
  */
 void
-GCCH_handle_channel_open_ack (struct CadetChannel *ch,
-                              const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti,
-			      const struct GNUNET_HashCode *port);
+GCCH_handle_channel_open_ack(struct CadetChannel *ch,
+                             const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti,
+                             const struct GNUNET_HashCode *port);
 
 
 /**
@@ -242,8 +242,8 @@ GCCH_handle_channel_open_ack (struct CadetChannel *ch,
  *            NULL during shutdown
  */
 void
-GCCH_handle_remote_destroy (struct CadetChannel *ch,
-                            const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti);
+GCCH_handle_remote_destroy(struct CadetChannel *ch,
+                           const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti);
 
 
 /**
@@ -261,10 +261,10 @@ GCCH_handle_remote_destroy (struct CadetChannel *ch,
  *         #GNUNET_SYSERR in case of an error.
  */
 int
-GCCH_handle_local_data (struct CadetChannel *ch,
-                        struct GNUNET_CADET_ClientChannelNumber sender_ccn,
-                        const char *buf,
-                        size_t buf_len);
+GCCH_handle_local_data(struct CadetChannel *ch,
+                       struct GNUNET_CADET_ClientChannelNumber sender_ccn,
+                       const char *buf,
+                       size_t buf_len);
 
 
 /**
@@ -274,7 +274,7 @@ GCCH_handle_local_data (struct CadetChannel *ch,
  * @param client_ccn ccn of the client sending the ack
  */
 void
-GCCH_handle_local_ack (struct CadetChannel *ch,
-                       struct GNUNET_CADET_ClientChannelNumber client_ccn);
+GCCH_handle_local_ack(struct CadetChannel *ch,
+                      struct GNUNET_CADET_ClientChannelNumber client_ccn);
 
 #endif

Plik diff jest za duży
+ 334 - 334
src/cadet/gnunet-service-cadet_connection.c


+ 40 - 43
src/cadet/gnunet-service-cadet_connection.h

@@ -11,12 +11,12 @@
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      Affero General Public License for more details.
-    
+
      You should have received a copy of the GNU Affero General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
-*/
+ */
 
 /**
  * @file cadet/gnunet-service-cadet_connection.h
@@ -57,7 +57,7 @@ typedef void
  * @param cc connection to destroy
  */
 void
-GCC_destroy_without_core (struct CadetConnection *cc);
+GCC_destroy_without_core(struct CadetConnection *cc);
 
 
 /**
@@ -68,7 +68,7 @@ GCC_destroy_without_core (struct CadetConnection *cc);
  * @param cc connection to destroy
  */
 void
-GCC_destroy_without_tunnel (struct CadetConnection *cc);
+GCC_destroy_without_tunnel(struct CadetConnection *cc);
 
 
 /**
@@ -78,7 +78,7 @@ GCC_destroy_without_tunnel (struct CadetConnection *cc);
  * @return NULL if connection was not found
  */
 struct CadetConnection *
-GCC_lookup (const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid);
+GCC_lookup(const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid);
 
 
 /**
@@ -94,12 +94,12 @@ GCC_lookup (const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid);
  * @return handle to the connection
  */
 struct CadetConnection *
-GCC_create (struct CadetPeer *destination,
-            struct CadetPeerPath *path,
-            unsigned int off,
-            struct CadetTConnection *ct,
-            GCC_ReadyCallback ready_cb,
-            void *ready_cb_cls);
+GCC_create(struct CadetPeer *destination,
+           struct CadetPeerPath *path,
+           unsigned int off,
+           struct CadetTConnection *ct,
+           GCC_ReadyCallback ready_cb,
+           void *ready_cb_cls);
 
 
 /**
@@ -116,12 +116,12 @@ GCC_create (struct CadetPeer *destination,
  *         a connection that takes precedence on @a path
  */
 struct CadetConnection *
-GCC_create_inbound (struct CadetPeer *destination,
-                    struct CadetPeerPath *path,
-                    struct CadetTConnection *ct,
-                    const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid,
-                    GCC_ReadyCallback ready_cb,
-                    void *ready_cb_cls);
+GCC_create_inbound(struct CadetPeer *destination,
+                   struct CadetPeerPath *path,
+                   struct CadetTConnection *ct,
+                   const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid,
+                   GCC_ReadyCallback ready_cb,
+                   void *ready_cb_cls);
 
 
 /**
@@ -137,8 +137,8 @@ GCC_create_inbound (struct CadetPeer *destination,
  *            connection identifier of this connection...
  */
 void
-GCC_transmit (struct CadetConnection *cc,
-              struct GNUNET_MQ_Envelope *env);
+GCC_transmit(struct CadetConnection *cc,
+             struct GNUNET_MQ_Envelope *env);
 
 
 /**
@@ -147,7 +147,7 @@ GCC_transmit (struct CadetConnection *cc,
  * @param cc the connection that got the ACK.
  */
 void
-GCC_handle_connection_create_ack (struct CadetConnection *cc);
+GCC_handle_connection_create_ack(struct CadetConnection *cc);
 
 
 /**
@@ -158,7 +158,7 @@ GCC_handle_connection_create_ack (struct CadetConnection *cc);
  * @param cc connection that got the duplicate CREATE
  */
 void
-GCC_handle_duplicate_create (struct CadetConnection *cc);
+GCC_handle_duplicate_create(struct CadetConnection *cc);
 
 
 /**
@@ -168,8 +168,8 @@ GCC_handle_duplicate_create (struct CadetConnection *cc);
  * @param msg the key exchange message
  */
 void
-GCC_handle_kx (struct CadetConnection *cc,
-               const struct GNUNET_CADET_TunnelKeyExchangeMessage *msg);
+GCC_handle_kx(struct CadetConnection *cc,
+              const struct GNUNET_CADET_TunnelKeyExchangeMessage *msg);
 
 
 /**
@@ -179,16 +179,14 @@ GCC_handle_kx (struct CadetConnection *cc,
  * @param msg the key exchange message
  */
 void
-GCC_handle_kx_auth (struct CadetConnection *cc,
-                    const struct GNUNET_CADET_TunnelKeyExchangeAuthMessage *msg);
+GCC_handle_kx_auth(struct CadetConnection *cc,
+                   const struct GNUNET_CADET_TunnelKeyExchangeAuthMessage *msg);
 
 
 /**
  * Performance metrics for a connection.
  */
-struct CadetConnectionMetrics
-{
-
+struct CadetConnectionMetrics {
   /**
    * Our current best estimate of the latency, based on a weighted
    * average of at least @a latency_datapoints values.
@@ -221,7 +219,6 @@ struct CadetConnectionMetrics
    * connections.)
    */
   unsigned long long num_successes;
-
 };
 
 
@@ -232,7 +229,7 @@ struct CadetConnectionMetrics
  * @return the metrics
  */
 const struct CadetConnectionMetrics *
-GCC_get_metrics (struct CadetConnection *cc);
+GCC_get_metrics(struct CadetConnection *cc);
 
 
 /**
@@ -242,8 +239,8 @@ GCC_get_metrics (struct CadetConnection *cc);
  * @param msg the encrypted message to decrypt
  */
 void
-GCC_handle_encrypted (struct CadetConnection *cc,
-                      const struct GNUNET_CADET_TunnelEncryptedMessage *msg);
+GCC_handle_encrypted(struct CadetConnection *cc,
+                     const struct GNUNET_CADET_TunnelEncryptedMessage *msg);
 
 
 /**
@@ -253,7 +250,7 @@ GCC_handle_encrypted (struct CadetConnection *cc,
  * @param cid connection identifier where we expect an ACK
  */
 void
-GCC_ack_expected (const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid);
+GCC_ack_expected(const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid);
 
 
 /**
@@ -265,7 +262,7 @@ GCC_ack_expected (const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid);
  *            may have gotten back to us via a different connection).
  */
 void
-GCC_ack_observed (const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid);
+GCC_ack_observed(const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid);
 
 
 /**
@@ -277,8 +274,8 @@ GCC_ack_observed (const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid);
  * @param latency the observed latency
  */
 void
-GCC_latency_observed (const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti,
-                      struct GNUNET_TIME_Relative latency);
+GCC_latency_observed(const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti,
+                     struct GNUNET_TIME_Relative latency);
 
 
 /**
@@ -288,7 +285,7 @@ GCC_latency_observed (const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti,
  * @return corresponding entry in the tunnel's connection list
  */
 struct CadetTConnection *
-GCC_get_ct (struct CadetConnection *cc);
+GCC_get_ct(struct CadetConnection *cc);
 
 
 /**
@@ -299,8 +296,8 @@ GCC_get_ct (struct CadetConnection *cc);
  * @return path to @a cc
  */
 struct CadetPeerPath *
-GCC_get_path (struct CadetConnection *cc,
-              unsigned int *off);
+GCC_get_path(struct CadetConnection *cc,
+             unsigned int *off);
 
 
 /**
@@ -310,7 +307,7 @@ GCC_get_path (struct CadetConnection *cc,
  * @return unique number of the connection
  */
 const struct GNUNET_CADET_ConnectionTunnelIdentifier *
-GCC_get_id (struct CadetConnection *cc);
+GCC_get_id(struct CadetConnection *cc);
 
 
 /**
@@ -319,7 +316,7 @@ GCC_get_id (struct CadetConnection *cc);
  * @param cc Connection.
  */
 const char *
-GCC_2s (const struct CadetConnection *cc);
+GCC_2s(const struct CadetConnection *cc);
 
 
 /**
@@ -329,8 +326,8 @@ GCC_2s (const struct CadetConnection *cc);
  * @param level Debug level to use.
  */
 void
-GCC_debug (struct CadetConnection *cc,
-           enum GNUNET_ErrorType level);
+GCC_debug(struct CadetConnection *cc,
+          enum GNUNET_ErrorType level);
 
 
 #endif

Plik diff jest za duży
+ 375 - 381
src/cadet/gnunet-service-cadet_core.c


+ 4 - 4
src/cadet/gnunet-service-cadet_core.h

@@ -11,12 +11,12 @@
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      Affero General Public License for more details.
-    
+
      You should have received a copy of the GNU Affero General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
-*/
+ */
 
 /**
  * @file cadet/gnunet-service-cadet_core.h
@@ -47,14 +47,14 @@ extern "C"
  * @param c Configuration.
  */
 void
-GCO_init (const struct GNUNET_CONFIGURATION_Handle *c);
+GCO_init(const struct GNUNET_CONFIGURATION_Handle *c);
 
 
 /**
  * Shut down the CORE subsystem.
  */
 void
-GCO_shutdown (void);
+GCO_shutdown(void);
 
 
 #if 0                           /* keep Emacsens' auto-indent happy */

+ 153 - 155
src/cadet/gnunet-service-cadet_dht.c

@@ -11,12 +11,12 @@
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      Affero General Public License for more details.
-    
+
      You should have received a copy of the GNU Affero General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
-*/
+ */
 /**
  * @file cadet/gnunet-service-cadet_dht.c
  * @brief Information we track per peer.
@@ -40,29 +40,27 @@
  * notifications when our HELLO is ready, so this is just the maximum
  * we wait for the first notification.
  */
-#define STARTUP_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 500)
+#define STARTUP_DELAY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 500)
 
 /**
  * How long do we wait after we get an updated HELLO before publishing?
  * Allows for the HELLO to be updated again quickly, for example in
  * case multiple addresses changed and we got a partial update.
  */
-#define CHANGE_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 100)
+#define CHANGE_DELAY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 100)
 
 
-#define LOG(level, ...) GNUNET_log_from (level,"cadet-dht",__VA_ARGS__)
+#define LOG(level, ...) GNUNET_log_from(level, "cadet-dht", __VA_ARGS__)
 
 
 /**
  * Handle for DHT searches.
  */
-struct GCD_search_handle
-{
+struct GCD_search_handle {
   /**
    * DHT_GET handle.
    */
   struct GNUNET_DHT_GetHandle *dhtget;
-
 };
 
 
@@ -109,35 +107,35 @@ static struct GNUNET_TIME_Relative announce_delay;
  * @param data pointer to the result data
  */
 static void
-dht_get_id_handler (void *cls, struct GNUNET_TIME_Absolute exp,
-                    const struct GNUNET_HashCode *key,
-                    const struct GNUNET_PeerIdentity *get_path,
-                    unsigned int get_path_length,
-                    const struct GNUNET_PeerIdentity *put_path,
-                    unsigned int put_path_length,
-                    enum GNUNET_BLOCK_Type type,
-                    size_t size,
-                    const void *data)
+dht_get_id_handler(void *cls, struct GNUNET_TIME_Absolute exp,
+                   const struct GNUNET_HashCode *key,
+                   const struct GNUNET_PeerIdentity *get_path,
+                   unsigned int get_path_length,
+                   const struct GNUNET_PeerIdentity *put_path,
+                   unsigned int put_path_length,
+                   enum GNUNET_BLOCK_Type type,
+                   size_t size,
+                   const void *data)
 {
   const struct GNUNET_HELLO_Message *hello = data;
   struct CadetPeer *peer;
 
-  GCPP_try_path_from_dht (get_path,
-                          get_path_length,
-                          put_path,
-                          put_path_length);
-  if ( (size >= sizeof (struct GNUNET_HELLO_Message)) &&
-       (ntohs (hello->header.size) == size) &&
-       (size == GNUNET_HELLO_size (hello)) )
-  {
-    peer = GCP_get (&put_path[0],
-                    GNUNET_YES);
-    LOG (GNUNET_ERROR_TYPE_DEBUG,
-         "Got HELLO for %s\n",
-         GCP_2s (peer));
-    GCP_set_hello (peer,
-                   hello);
-  }
+  GCPP_try_path_from_dht(get_path,
+                         get_path_length,
+                         put_path,
+                         put_path_length);
+  if ((size >= sizeof(struct GNUNET_HELLO_Message)) &&
+      (ntohs(hello->header.size) == size) &&
+      (size == GNUNET_HELLO_size(hello)))
+    {
+      peer = GCP_get(&put_path[0],
+                     GNUNET_YES);
+      LOG(GNUNET_ERROR_TYPE_DEBUG,
+          "Got HELLO for %s\n",
+          GCP_2s(peer));
+      GCP_set_hello(peer,
+                    hello);
+    }
 }
 
 
@@ -147,7 +145,7 @@ dht_get_id_handler (void *cls, struct GNUNET_TIME_Absolute exp,
  * @param cls closure
  */
 static void
-announce_id (void *cls)
+announce_id(void *cls)
 {
   struct GNUNET_HashCode phash;
   const struct GNUNET_HELLO_Message *hello;
@@ -155,58 +153,58 @@ announce_id (void *cls)
   struct GNUNET_TIME_Absolute expiration;
   struct GNUNET_TIME_Relative next_put;
 
-  hello = GCH_get_mine ();
-  size = (NULL != hello) ? GNUNET_HELLO_size (hello) : 0;
+  hello = GCH_get_mine();
+  size = (NULL != hello) ? GNUNET_HELLO_size(hello) : 0;
   if (0 == size)
-  {
-    expiration = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (),
-                                           announce_delay);
-    announce_delay = GNUNET_TIME_STD_BACKOFF (announce_delay);
-  }
+    {
+      expiration = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(),
+                                            announce_delay);
+      announce_delay = GNUNET_TIME_STD_BACKOFF(announce_delay);
+    }
   else
-  {
-    expiration = GNUNET_HELLO_get_last_expiration (hello);
-    announce_delay = GNUNET_TIME_UNIT_SECONDS;
-  }
+    {
+      expiration = GNUNET_HELLO_get_last_expiration(hello);
+      announce_delay = GNUNET_TIME_UNIT_SECONDS;
+    }
 
   /* Call again in id_announce_time, unless HELLO expires first,
    * but wait at least 1s. */
   next_put
-    = GNUNET_TIME_absolute_get_remaining (expiration);
+    = GNUNET_TIME_absolute_get_remaining(expiration);
   next_put
-    = GNUNET_TIME_relative_min (next_put,
-                                id_announce_time);
+    = GNUNET_TIME_relative_min(next_put,
+                               id_announce_time);
   next_put
-    = GNUNET_TIME_relative_max (next_put,
-                                GNUNET_TIME_UNIT_SECONDS);
+    = GNUNET_TIME_relative_max(next_put,
+                               GNUNET_TIME_UNIT_SECONDS);
   announce_id_task
-    = GNUNET_SCHEDULER_add_delayed (next_put,
-                                    &announce_id,
-                                    cls);
-  GNUNET_STATISTICS_update (stats,
-                            "# DHT announce",
-                            1,
-                            GNUNET_NO);
-  memset (&phash,
-          0,
-          sizeof (phash));
-  GNUNET_memcpy (&phash,
-                 &my_full_id,
-                 sizeof (my_full_id));
-  LOG (GNUNET_ERROR_TYPE_DEBUG,
-       "Announcing my HELLO (%u bytes) in the DHT\n",
-       size);
-  GNUNET_DHT_put (dht_handle,   /* DHT handle */
-                  &phash,       /* Key to use */
-                  dht_replication_level,     /* Replication level */
-                  GNUNET_DHT_RO_RECORD_ROUTE
-                  | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,    /* DHT options */
-                  GNUNET_BLOCK_TYPE_DHT_HELLO,       /* Block type */
-                  size,  /* Size of the data */
-                  (const char *) hello, /* Data itself */
-                  expiration,  /* Data expiration */
-                  NULL,         /* Continuation */
-                  NULL);        /* Continuation closure */
+    = GNUNET_SCHEDULER_add_delayed(next_put,
+                                   &announce_id,
+                                   cls);
+  GNUNET_STATISTICS_update(stats,
+                           "# DHT announce",
+                           1,
+                           GNUNET_NO);
+  memset(&phash,
+         0,
+         sizeof(phash));
+  GNUNET_memcpy(&phash,
+                &my_full_id,
+                sizeof(my_full_id));
+  LOG(GNUNET_ERROR_TYPE_DEBUG,
+      "Announcing my HELLO (%u bytes) in the DHT\n",
+      size);
+  GNUNET_DHT_put(dht_handle,    /* DHT handle */
+                 &phash,        /* Key to use */
+                 dht_replication_level,      /* Replication level */
+                 GNUNET_DHT_RO_RECORD_ROUTE
+                 | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,     /* DHT options */
+                 GNUNET_BLOCK_TYPE_DHT_HELLO,        /* Block type */
+                 size,   /* Size of the data */
+                 (const char *)hello,   /* Data itself */
+                 expiration,   /* Data expiration */
+                 NULL,          /* Continuation */
+                 NULL);         /* Continuation closure */
 }
 
 
@@ -215,15 +213,15 @@ announce_id (void *cls)
  * changes. Re-triggers the DHT PUT immediately.
  */
 void
-GCD_hello_update ()
+GCD_hello_update()
 {
   if (NULL == announce_id_task)
     return; /* too early */
-  GNUNET_SCHEDULER_cancel (announce_id_task);
+  GNUNET_SCHEDULER_cancel(announce_id_task);
   announce_id_task
-    = GNUNET_SCHEDULER_add_delayed (CHANGE_DELAY,
-                                    &announce_id,
-                                    NULL);
+    = GNUNET_SCHEDULER_add_delayed(CHANGE_DELAY,
+                                   &announce_id,
+                                   NULL);
 }
 
 
@@ -233,42 +231,42 @@ GCD_hello_update ()
  * @param c Configuration.
  */
 void
-GCD_init (const struct GNUNET_CONFIGURATION_Handle *c)
+GCD_init(const struct GNUNET_CONFIGURATION_Handle *c)
 {
   if (GNUNET_OK !=
-      GNUNET_CONFIGURATION_get_value_number (c,
-                                             "CADET",
-                                             "DHT_REPLICATION_LEVEL",
-                                             &dht_replication_level))
-  {
-    GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_WARNING,
-                               "CADET",
-                               "DHT_REPLICATION_LEVEL",
-                               "USING DEFAULT");
-    dht_replication_level = 3;
-  }
+      GNUNET_CONFIGURATION_get_value_number(c,
+                                            "CADET",
+                                            "DHT_REPLICATION_LEVEL",
+                                            &dht_replication_level))
+    {
+      GNUNET_log_config_invalid(GNUNET_ERROR_TYPE_WARNING,
+                                "CADET",
+                                "DHT_REPLICATION_LEVEL",
+                                "USING DEFAULT");
+      dht_replication_level = 3;
+    }
 
   if (GNUNET_OK !=
-      GNUNET_CONFIGURATION_get_value_time (c,
-                                           "CADET",
-                                           "ID_ANNOUNCE_TIME",
-                                           &id_announce_time))
-  {
-    GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
-                               "CADET",
-                               "ID_ANNOUNCE_TIME",
-                               "MISSING");
-    GNUNET_SCHEDULER_shutdown ();
-    return;
-  }
-
-  dht_handle = GNUNET_DHT_connect (c,
-                                   64);
-  GNUNET_break (NULL != dht_handle);
+      GNUNET_CONFIGURATION_get_value_time(c,
+                                          "CADET",
+                                          "ID_ANNOUNCE_TIME",
+                                          &id_announce_time))
+    {
+      GNUNET_log_config_invalid(GNUNET_ERROR_TYPE_ERROR,
+                                "CADET",
+                                "ID_ANNOUNCE_TIME",
+                                "MISSING");
+      GNUNET_SCHEDULER_shutdown();
+      return;
+    }
+
+  dht_handle = GNUNET_DHT_connect(c,
+                                  64);
+  GNUNET_break(NULL != dht_handle);
   announce_delay = GNUNET_TIME_UNIT_SECONDS;
-  announce_id_task = GNUNET_SCHEDULER_add_delayed (STARTUP_DELAY,
-                                                   &announce_id,
-                                                   NULL);
+  announce_id_task = GNUNET_SCHEDULER_add_delayed(STARTUP_DELAY,
+                                                  &announce_id,
+                                                  NULL);
 }
 
 
@@ -276,18 +274,18 @@ GCD_init (const struct GNUNET_CONFIGURATION_Handle *c)
  * Shut down the DHT subsystem.
  */
 void
-GCD_shutdown (void)
+GCD_shutdown(void)
 {
   if (NULL != dht_handle)
-  {
-    GNUNET_DHT_disconnect (dht_handle);
-    dht_handle = NULL;
-  }
+    {
+      GNUNET_DHT_disconnect(dht_handle);
+      dht_handle = NULL;
+    }
   if (NULL != announce_id_task)
-  {
-    GNUNET_SCHEDULER_cancel (announce_id_task);
-    announce_id_task = NULL;
-  }
+    {
+      GNUNET_SCHEDULER_cancel(announce_id_task);
+      announce_id_task = NULL;
+    }
 }
 
 
@@ -298,37 +296,37 @@ GCD_shutdown (void)
  * @return handle to abort search
  */
 struct GCD_search_handle *
-GCD_search (const struct GNUNET_PeerIdentity *peer_id)
+GCD_search(const struct GNUNET_PeerIdentity *peer_id)
 {
   struct GNUNET_HashCode phash;
   struct GCD_search_handle *h;
 
-  GNUNET_STATISTICS_update (stats,
-                            "# DHT search",
-                            1,
-                            GNUNET_NO);
-  memset (&phash,
-          0,
-          sizeof (phash));
-  GNUNET_memcpy (&phash,
-                 peer_id,
-                 sizeof (*peer_id));
-
-  h = GNUNET_new (struct GCD_search_handle);
-  h->dhtget = GNUNET_DHT_get_start (dht_handle,    /* handle */
-                                    GNUNET_BLOCK_TYPE_DHT_HELLO, /* type */
-                                    &phash,     /* key to search */
-                                    dht_replication_level, /* replication level */
-                                    GNUNET_DHT_RO_RECORD_ROUTE |
-                                    GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
-                                    NULL,       /* xquery */
-                                    0,     /* xquery bits */
-                                    &dht_get_id_handler,
-				    h);
-  LOG (GNUNET_ERROR_TYPE_DEBUG,
-       "Starting DHT GET for peer %s (%p)\n",
-       GNUNET_i2s (peer_id),
-       h);
+  GNUNET_STATISTICS_update(stats,
+                           "# DHT search",
+                           1,
+                           GNUNET_NO);
+  memset(&phash,
+         0,
+         sizeof(phash));
+  GNUNET_memcpy(&phash,
+                peer_id,
+                sizeof(*peer_id));
+
+  h = GNUNET_new(struct GCD_search_handle);
+  h->dhtget = GNUNET_DHT_get_start(dht_handle,     /* handle */
+                                   GNUNET_BLOCK_TYPE_DHT_HELLO,  /* type */
+                                   &phash,      /* key to search */
+                                   dht_replication_level,  /* replication level */
+                                   GNUNET_DHT_RO_RECORD_ROUTE |
+                                   GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
+                                   NULL,        /* xquery */
+                                   0,      /* xquery bits */
+                                   &dht_get_id_handler,
+                                   h);
+  LOG(GNUNET_ERROR_TYPE_DEBUG,
+      "Starting DHT GET for peer %s (%p)\n",
+      GNUNET_i2s(peer_id),
+      h);
   return h;
 }
 
@@ -339,13 +337,13 @@ GCD_search (const struct GNUNET_PeerIdentity *peer_id)
  * @param h handle to search to stop
  */
 void
-GCD_search_stop (struct GCD_search_handle *h)
+GCD_search_stop(struct GCD_search_handle *h)
 {
-  LOG (GNUNET_ERROR_TYPE_DEBUG,
-       "Stopping DHT GET %p\n",
-       h);
-  GNUNET_DHT_get_stop (h->dhtget);
-  GNUNET_free (h);
+  LOG(GNUNET_ERROR_TYPE_DEBUG,
+      "Stopping DHT GET %p\n",
+      h);
+  GNUNET_DHT_get_stop(h->dhtget);
+  GNUNET_free(h);
 }
 
 /* end of gnunet-service-cadet_dht.c */

+ 7 - 7
src/cadet/gnunet-service-cadet_dht.h

@@ -11,12 +11,12 @@
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      Affero General Public License for more details.
-    
+
      You should have received a copy of the GNU Affero General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
-*/
+ */
 
 /**
  * @file cadet/gnunet-service-cadet_dht.h
@@ -52,14 +52,14 @@ struct GCD_search_handle;
  * @param c Configuration.
  */
 void
-GCD_init (const struct GNUNET_CONFIGURATION_Handle *c);
+GCD_init(const struct GNUNET_CONFIGURATION_Handle *c);
 
 
 /**
  * Shut down the DHT subsystem.
  */
 void
-GCD_shutdown (void);
+GCD_shutdown(void);
 
 
 /**
@@ -67,7 +67,7 @@ GCD_shutdown (void);
  * changes. Re-triggers the DHT PUT immediately.
  */
 void
-GCD_hello_update (void);
+GCD_hello_update(void);
 
 /**
  * Search DHT for paths to @a peeR_id
@@ -76,7 +76,7 @@ GCD_hello_update (void);
  * @return handle to abort search
  */
 struct GCD_search_handle *
-GCD_search (const struct GNUNET_PeerIdentity *peer_id);
+GCD_search(const struct GNUNET_PeerIdentity *peer_id);
 
 
 /**
@@ -85,7 +85,7 @@ GCD_search (const struct GNUNET_PeerIdentity *peer_id);
  * @param h handle to search to stop
  */
 void
-GCD_search_stop (struct GCD_search_handle *h);
+GCD_search_stop(struct GCD_search_handle *h);
 
 
 #if 0                           /* keep Emacsens' auto-indent happy */

+ 48 - 48
src/cadet/gnunet-service-cadet_hello.c

@@ -11,12 +11,12 @@
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      Affero General Public License for more details.
-    
+
      You should have received a copy of the GNU Affero General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
-*/
+ */
 /**
  * @file cadet/gnunet-service-cadet_hello.c
  * @brief spread knowledge about how to contact us (get HELLO from peerinfo),
@@ -35,7 +35,7 @@
 #include "gnunet-service-cadet_hello.h"
 #include "gnunet-service-cadet_peer.h"
 
-#define LOG(level, ...) GNUNET_log_from(level,"cadet-hll",__VA_ARGS__)
+#define LOG(level, ...) GNUNET_log_from(level, "cadet-hll", __VA_ARGS__)
 
 /**
  * Hello message of local peer.
@@ -62,34 +62,34 @@ static struct GNUNET_PEERINFO_NotifyContext *nc;
  * @param err_msg Error message.
  */
 static void
-got_hello (void *cls,
-           const struct GNUNET_PeerIdentity *id,
-           const struct GNUNET_HELLO_Message *hello,
-           const char *err_msg)
+got_hello(void *cls,
+          const struct GNUNET_PeerIdentity *id,
+          const struct GNUNET_HELLO_Message *hello,
+          const char *err_msg)
 {
   struct CadetPeer *peer;
 
-  if ( (NULL == id) ||
-       (NULL == hello) )
-    return;
-  if (0 == GNUNET_memcmp (id,
-                   &my_full_id))
-  {
-    GNUNET_free_non_null (mine);
-    mine = (struct GNUNET_HELLO_Message *) GNUNET_copy_message (&hello->header);
-    GCD_hello_update ();
+  if ((NULL == id) ||
+      (NULL == hello))
     return;
-  }
-
-  LOG (GNUNET_ERROR_TYPE_DEBUG,
-       "Hello for %s (%d bytes), expires on %s\n",
-       GNUNET_i2s (id),
-       GNUNET_HELLO_size (hello),
-       GNUNET_STRINGS_absolute_time_to_string (GNUNET_HELLO_get_last_expiration (hello)));
-  peer = GCP_get (id,
-                  GNUNET_YES);
-  GCP_set_hello (peer,
-                 hello);
+  if (0 == GNUNET_memcmp(id,
+                         &my_full_id))
+    {
+      GNUNET_free_non_null(mine);
+      mine = (struct GNUNET_HELLO_Message *)GNUNET_copy_message(&hello->header);
+      GCD_hello_update();
+      return;
+    }
+
+  LOG(GNUNET_ERROR_TYPE_DEBUG,
+      "Hello for %s (%d bytes), expires on %s\n",
+      GNUNET_i2s(id),
+      GNUNET_HELLO_size(hello),
+      GNUNET_STRINGS_absolute_time_to_string(GNUNET_HELLO_get_last_expiration(hello)));
+  peer = GCP_get(id,
+                 GNUNET_YES);
+  GCP_set_hello(peer,
+                hello);
 }
 
 
@@ -99,14 +99,14 @@ got_hello (void *cls,
  * @param c Configuration.
  */
 void
-GCH_init (const struct GNUNET_CONFIGURATION_Handle *c)
+GCH_init(const struct GNUNET_CONFIGURATION_Handle *c)
 {
-  GNUNET_assert (NULL == nc);
-  peerinfo = GNUNET_PEERINFO_connect (c);
-  nc = GNUNET_PEERINFO_notify (c,
-                               GNUNET_NO,
-                               &got_hello,
-                               NULL);
+  GNUNET_assert(NULL == nc);
+  peerinfo = GNUNET_PEERINFO_connect(c);
+  nc = GNUNET_PEERINFO_notify(c,
+                              GNUNET_NO,
+                              &got_hello,
+                              NULL);
 }
 
 
@@ -114,23 +114,23 @@ GCH_init (const struct GNUNET_CONFIGURATION_Handle *c)
  * Shut down the hello subsystem.
  */
 void
-GCH_shutdown ()
+GCH_shutdown()
 {
   if (NULL != nc)
-  {
-    GNUNET_PEERINFO_notify_cancel (nc);
-    nc = NULL;
-  }
+    {
+      GNUNET_PEERINFO_notify_cancel(nc);
+      nc = NULL;
+    }
   if (NULL != peerinfo)
-  {
-    GNUNET_PEERINFO_disconnect (peerinfo);
-    peerinfo = NULL;
-  }
+    {
+      GNUNET_PEERINFO_disconnect(peerinfo);
+      peerinfo = NULL;
+    }
   if (NULL != mine)
-  {
-    GNUNET_free (mine);
-    mine = NULL;
-  }
+    {
+      GNUNET_free(mine);
+      mine = NULL;
+    }
 }
 
 
@@ -140,7 +140,7 @@ GCH_shutdown ()
  * @return Own hello message.
  */
 const struct GNUNET_HELLO_Message *
-GCH_get_mine (void)
+GCH_get_mine(void)
 {
   return mine;
 }

+ 5 - 5
src/cadet/gnunet-service-cadet_hello.h

@@ -11,12 +11,12 @@
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      Affero General Public License for more details.
-    
+
      You should have received a copy of the GNU Affero General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
-*/
+ */
 
 /**
  * @file cadet/gnunet-service-cadet_hello.h
@@ -49,14 +49,14 @@ extern "C"
  * @param c Configuration.
  */
 void
-GCH_init (const struct GNUNET_CONFIGURATION_Handle *c);
+GCH_init(const struct GNUNET_CONFIGURATION_Handle *c);
 
 
 /**
  * Shut down the hello subsystem.
  */
 void
-GCH_shutdown (void);
+GCH_shutdown(void);
 
 
 /**
@@ -65,7 +65,7 @@ GCH_shutdown (void);
  * @return Own hello message.
  */
 const struct GNUNET_HELLO_Message *
-GCH_get_mine (void);
+GCH_get_mine(void);
 
 
 #if 0                           /* keep Emacsens' auto-indent happy */

+ 372 - 376
src/cadet/gnunet-service-cadet_paths.c

@@ -11,15 +11,15 @@
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      Affero General Public License for more details.
-    
+
      You should have received a copy of the GNU Affero General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
-*/
+ */
 /**
  * @file cadet/gnunet-service-cadet_paths.c
- * @brief Information we track per path.    
+ * @brief Information we track per path.
  * @author Bartlomiej Polot
  * @author Christian Grothoff
  */
@@ -30,15 +30,13 @@
 #include "gnunet-service-cadet_paths.h"
 
 
-#define LOG(level, ...) GNUNET_log_from(level,"cadet-pat",__VA_ARGS__)
+#define LOG(level, ...) GNUNET_log_from(level, "cadet-pat", __VA_ARGS__)
 
 
 /**
  * Information regarding a possible path to reach a peer.
  */
-struct CadetPeerPath
-{
-
+struct CadetPeerPath {
   /**
    * Array of all the peers on the path.  If @e hn is non-NULL, the
    * last one is our owner.
@@ -61,7 +59,6 @@ struct CadetPeerPath
    * Length of the @e entries array.
    */
   unsigned int entries_length;
-
 };
 
 
@@ -71,18 +68,18 @@ struct CadetPeerPath
  * @param path path to calculate the score for
  */
 static void
-recalculate_path_desirability (struct CadetPeerPath *path)
+recalculate_path_desirability(struct CadetPeerPath *path)
 {
   double result = 0.0;
 
-  for (unsigned int i=0;i<path->entries_length;i++)
-  {
-    struct CadetPeer *cp = path->entries[i]->peer;
+  for (unsigned int i = 0; i < path->entries_length; i++)
+    {
+      struct CadetPeer *cp = path->entries[i]->peer;
 
-    result += GCP_get_desirability_of_path (cp,
-                                            i);
-  }
-  path->desirability = (GNUNET_CONTAINER_HeapCostType) result;
+      result += GCP_get_desirability_of_path(cp,
+                                             i);
+    }
+  path->desirability = (GNUNET_CONTAINER_HeapCostType)result;
 }
 
 
@@ -100,7 +97,7 @@ recalculate_path_desirability (struct CadetPeerPath *path)
  * @return desirability of the path, larger is more desirable
  */
 GNUNET_CONTAINER_HeapCostType
-GCPP_get_desirability (const struct CadetPeerPath *path)
+GCPP_get_desirability(const struct CadetPeerPath *path)
 {
   return path->desirability;
 }
@@ -117,15 +114,15 @@ GCPP_get_desirability (const struct CadetPeerPath *path)
  *         otherwise connection from us to @a destination via @a path
  */
 struct CadetConnection *
-GCPP_get_connection (struct CadetPeerPath *path,
-                     struct CadetPeer *destination,
-                     unsigned int off)
+GCPP_get_connection(struct CadetPeerPath *path,
+                    struct CadetPeer *destination,
+                    unsigned int off)
 {
   struct CadetPeerPathEntry *entry;
 
-  GNUNET_assert (off < path->entries_length);
+  GNUNET_assert(off < path->entries_length);
   entry = path->entries[off];
-  GNUNET_assert (entry->peer == destination);
+  GNUNET_assert(entry->peer == destination);
   return entry->cc;
 }
 
@@ -139,21 +136,21 @@ GCPP_get_connection (struct CadetPeerPath *path,
  * @param cc the connection to remember
  */
 void
-GCPP_add_connection (struct CadetPeerPath *path,
-                     unsigned int off,
-                     struct CadetConnection *cc)
+GCPP_add_connection(struct CadetPeerPath *path,
+                    unsigned int off,
+                    struct CadetConnection *cc)
 {
   struct CadetPeerPathEntry *entry;
 
-  LOG (GNUNET_ERROR_TYPE_DEBUG,
-       "Adding %s to path %s at offset %u\n",
-       GCC_2s (cc),
-       GCPP_2s (path),
-       off);
-  GNUNET_assert (off < path->entries_length);
+  LOG(GNUNET_ERROR_TYPE_DEBUG,
+      "Adding %s to path %s at offset %u\n",
+      GCC_2s(cc),
+      GCPP_2s(path),
+      off);
+  GNUNET_assert(off < path->entries_length);
   entry = path->entries[off];
-  GNUNET_assert (NULL == entry->cc);
-  GNUNET_assert (NULL != cc);
+  GNUNET_assert(NULL == entry->cc);
+  GNUNET_assert(NULL != cc);
   entry->cc = cc;
 }
 
@@ -168,20 +165,20 @@ GCPP_add_connection (struct CadetPeerPath *path,
  * @param cc the connection to forget
  */
 void
-GCPP_del_connection (struct CadetPeerPath *path,
-                     unsigned int off,
-                     struct CadetConnection *cc)
+GCPP_del_connection(struct CadetPeerPath *path,
+                    unsigned int off,
+                    struct CadetConnection *cc)
 {
   struct CadetPeerPathEntry *entry;
 
-  LOG (GNUNET_ERROR_TYPE_DEBUG,
-       "Removing connection %s to path %s at offset %u\n",
-       GCC_2s (cc),
-       GCPP_2s (path),
-       off);
-  GNUNET_assert (off < path->entries_length);
+  LOG(GNUNET_ERROR_TYPE_DEBUG,
+      "Removing connection %s to path %s at offset %u\n",
+      GCC_2s(cc),
+      GCPP_2s(path),
+      off);
+  GNUNET_assert(off < path->entries_length);
   entry = path->entries[off];
-  GNUNET_assert (cc == entry->cc);
+  GNUNET_assert(cc == entry->cc);
   entry->cc = NULL;
 }
 
@@ -196,42 +193,42 @@ GCPP_del_connection (struct CadetPeerPath *path,
  * @param stop_at the path length at which to stop trying
  */
 static void
-attach_path (struct CadetPeerPath *path, unsigned int stop_at)
+attach_path(struct CadetPeerPath *path, unsigned int stop_at)
 {
-  GNUNET_assert (NULL == path->hn);
+  GNUNET_assert(NULL == path->hn);
 
   /* Try to attach this path to a peer, working backwards from the end. */
   while (path->entries_length > stop_at)
-  {
-    unsigned int end = path->entries_length - 1;
-    struct CadetPeerPathEntry *entry = path->entries[end];
-    int force = GNUNET_NO;
-
-    recalculate_path_desirability (path);
-    /* If the entry already has a connection using it, force attach. */
-    if (NULL != entry->cc)
-      force = GNUNET_YES;
-    path->hn = GCP_attach_path (entry->peer,
-                                path,
-                                end,
-                                force);
-    if (NULL != path->hn)
-      break;
-
-    /* Attach failed, trim this entry from the path. */
-    GNUNET_assert (NULL == entry->cc);
-    GCP_path_entry_remove (entry->peer,
-                           entry,
-                           end);
-    GNUNET_free (entry);
-    path->entries[end] = NULL;
-    path->entries_length--;
-  }
+    {
+      unsigned int end = path->entries_length - 1;
+      struct CadetPeerPathEntry *entry = path->entries[end];
+      int force = GNUNET_NO;
+
+      recalculate_path_desirability(path);
+      /* If the entry already has a connection using it, force attach. */
+      if (NULL != entry->cc)
+        force = GNUNET_YES;
+      path->hn = GCP_attach_path(entry->peer,
+                                 path,
+                                 end,
+                                 force);
+      if (NULL != path->hn)
+        break;
+
+      /* Attach failed, trim this entry from the path. */
+      GNUNET_assert(NULL == entry->cc);
+      GCP_path_entry_remove(entry->peer,
+                            entry,
+                            end);
+      GNUNET_free(entry);
+      path->entries[end] = NULL;
+      path->entries_length--;
+    }
 
   /* Shrink array to actual path length. */
-  GNUNET_array_grow (path->entries,
-                     path->entries_length,
-                     path->entries_length);
+  GNUNET_array_grow(path->entries,
+                    path->entries_length,
+                    path->entries_length);
 }
 
 
@@ -243,33 +240,33 @@ attach_path (struct CadetPeerPath *path, unsigned int stop_at)
  * @param path the path that is being released
  */
 void
-GCPP_release (struct CadetPeerPath *path)
+GCPP_release(struct CadetPeerPath *path)
 {
   struct CadetPeerPathEntry *entry;
 
-  LOG (GNUNET_ERROR_TYPE_DEBUG,
-       "Owner releases path %s\n",
-       GCPP_2s (path));
+  LOG(GNUNET_ERROR_TYPE_DEBUG,
+      "Owner releases path %s\n",
+      GCPP_2s(path));
   path->hn = NULL;
   entry = path->entries[path->entries_length - 1];
-  GNUNET_assert (path == entry->path);
-  GNUNET_assert (NULL == entry->cc);
+  GNUNET_assert(path == entry->path);
+  GNUNET_assert(NULL == entry->cc);
   /* cut 'off' end of path */
-  GCP_path_entry_remove (entry->peer,
-                         entry,
-                         path->entries_length - 1);
-  GNUNET_free (entry);
+  GCP_path_entry_remove(entry->peer,
+                        entry,
+                        path->entries_length - 1);
+  GNUNET_free(entry);
   path->entries[path->entries_length - 1] = NULL;
   path->entries_length--;
   /* see if new peer at the end likes this path any better */
-  attach_path (path, 0);
+  attach_path(path, 0);
   if (NULL == path->hn)
-  {
-    /* nobody wants us, discard the path */
-    GNUNET_assert (0 == path->entries_length);
-    GNUNET_assert (NULL == path->entries);
-    GNUNET_free (path);
-  }
+    {
+      /* nobody wants us, discard the path */
+      GNUNET_assert(0 == path->entries_length);
+      GNUNET_assert(NULL == path->entries);
+      GNUNET_free(path);
+    }
 }
 
 
@@ -282,40 +279,38 @@ GCPP_release (struct CadetPeerPath *path)
  * @param delta change in the score to apply
  */
 void
-GCPP_update_score (struct CadetPeerPath *path,
-                   unsigned int off,
-                   int delta)
+GCPP_update_score(struct CadetPeerPath *path,
+                  unsigned int off,
+                  int delta)
 {
   struct CadetPeerPathEntry *entry;
 
-  GNUNET_assert (off < path->entries_length);
+  GNUNET_assert(off < path->entries_length);
   entry = path->entries[off];
 
   /* Add delta, with checks for overflows */
   if (delta >= 0)
-  {
-    if (delta + entry->score < entry->score)
-      entry->score = INT_MAX;
-    else
-      entry->score += delta;
-  }
+    {
+      if (delta + entry->score < entry->score)
+        entry->score = INT_MAX;
+      else
+        entry->score += delta;
+    }
   else
-  {
-    if (delta + entry->score > entry->score)
-      entry->score = INT_MIN;
-    else
-      entry->score += delta;
-  }
-  recalculate_path_desirability (path);
+    {
+      if (delta + entry->score > entry->score)
+        entry->score = INT_MIN;
+      else
+        entry->score += delta;
+    }
+  recalculate_path_desirability(path);
 }
 
 
 /**
  * Closure for #find_peer_at() and #check_match().
  */
-struct CheckMatchContext
-{
-
+struct CheckMatchContext {
   /**
    * Set to a matching path, if any.
    */
@@ -330,7 +325,6 @@ struct CheckMatchContext
    * How long is the @e cpath array?
    */
   unsigned int cpath_length;
-
 };
 
 
@@ -345,38 +339,38 @@ struct CheckMatchContext
  * @return #GNUNET_YES (continue to iterate), or if found #GNUNET_NO
  */
 static int
-check_match (void *cls,
-             struct CadetPeerPath *path,
-             unsigned int off)
+check_match(void *cls,
+            struct CadetPeerPath *path,
+            unsigned int off)
 {
   struct CheckMatchContext *cm_ctx = cls;
 
-  GNUNET_assert (path->entries_length > off);
-  if ( (path->entries_length != off + 1) &&
-       (off + 1 != cm_ctx->cpath_length) )
-  {
-    LOG (GNUNET_ERROR_TYPE_DEBUG,
-         "check_match mismatch because path %s is too long (%u vs. %u vs. %u)\n",
-         GCPP_2s (path),
-         path->entries_length,
-         off + 1,
-         cm_ctx->cpath_length);
-    return GNUNET_YES; /* too long, goes somewhere else already, thus cannot be useful */
-  }
-  for (unsigned int i=0;i<off;i++)
-    if (cm_ctx->cpath[i] !=
-        GCPP_get_peer_at_offset (path,
-                                 i))
+  GNUNET_assert(path->entries_length > off);
+  if ((path->entries_length != off + 1) &&
+      (off + 1 != cm_ctx->cpath_length))
     {
-      LOG (GNUNET_ERROR_TYPE_DEBUG,
-           "check_match path %s mismatches at offset %u\n",
-           GCPP_2s (path),
-           i);
-      return GNUNET_YES; /* mismatch, ignore */
+      LOG(GNUNET_ERROR_TYPE_DEBUG,
+          "check_match mismatch because path %s is too long (%u vs. %u vs. %u)\n",
+          GCPP_2s(path),
+          path->entries_length,
+          off + 1,
+          cm_ctx->cpath_length);
+      return GNUNET_YES; /* too long, goes somewhere else already, thus cannot be useful */
     }
-  LOG (GNUNET_ERROR_TYPE_DEBUG,
-       "check_match found match with path %s\n",
-       GCPP_2s (path));
+  for (unsigned int i = 0; i < off; i++)
+    if (cm_ctx->cpath[i] !=
+        GCPP_get_peer_at_offset(path,
+                                i))
+      {
+        LOG(GNUNET_ERROR_TYPE_DEBUG,
+            "check_match path %s mismatches at offset %u\n",
+            GCPP_2s(path),
+            i);
+        return GNUNET_YES; /* mismatch, ignore */
+      }
+  LOG(GNUNET_ERROR_TYPE_DEBUG,
+      "check_match found match with path %s\n",
+      GCPP_2s(path));
   cm_ctx->match = path;
   return GNUNET_NO; /* match, we are done! */
 }
@@ -393,68 +387,70 @@ check_match (void *cls,
  *        paths already
  */
 static void
-extend_path (struct CadetPeerPath *path,
-             struct CadetPeer **peers,
-             unsigned int num_peers,
-             int force)
+extend_path(struct CadetPeerPath *path,
+            struct CadetPeer **peers,
+            unsigned int num_peers,
+            int force)
 {
   unsigned int old_len = path->entries_length;
   int i;
 
   /* Expand path */
-  GNUNET_array_grow (path->entries,
-                     path->entries_length,
-                     old_len + num_peers);
-  for (i=num_peers-1;i >= 0;i--)
-  {
-    struct CadetPeerPathEntry *entry = GNUNET_new (struct CadetPeerPathEntry);
-
-    path->entries[old_len + i] = entry;
-    entry->peer = peers[i];
-    entry->path = path;
-  }
-  for (i=num_peers-1;i >= 0;i--)
-  {
-    struct CadetPeerPathEntry *entry = path->entries[old_len + i];
-
-    GCP_path_entry_add (entry->peer,
-                        entry,
-                        old_len + i);
-  }
+  GNUNET_array_grow(path->entries,
+                    path->entries_length,
+                    old_len + num_peers);
+  for (i = num_peers - 1; i >= 0; i--)
+    {
+      struct CadetPeerPathEntry *entry = GNUNET_new(struct CadetPeerPathEntry);
+
+      path->entries[old_len + i] = entry;
+      entry->peer = peers[i];
+      entry->path = path;
+    }
+  for (i = num_peers - 1; i >= 0; i--)
+    {
+      struct CadetPeerPathEntry *entry = path->entries[old_len + i];
+
+      GCP_path_entry_add(entry->peer,
+                         entry,
+                         old_len + i);
+    }
 
   /* If we extend an existing path, detach it from the
      old owner and re-attach to the new one */
-  GCP_detach_path (path->entries[old_len-1]->peer,
-                   path,
-                   path->hn);
+  GCP_detach_path(path->entries[old_len - 1]->peer,
+                  path,
+                  path->hn);
   path->hn = NULL;
   path->entries_length = old_len + num_peers;
   if (GNUNET_YES == force)
-  {
-    int end = path->entries_length - 1;
-
-    path->hn = GCP_attach_path (path->entries[end]->peer,
-                                path,
-                                end,
-                                GNUNET_YES);
-  } else {
-    attach_path (path, old_len);
-  }
+    {
+      int end = path->entries_length - 1;
+
+      path->hn = GCP_attach_path(path->entries[end]->peer,
+                                 path,
+                                 end,
+                                 GNUNET_YES);
+    }
+  else
+    {
+      attach_path(path, old_len);
+    }
   if (NULL == path->hn)
-  {
-    /* none of the peers is interested in this path;
-       re-attach. */
-    GNUNET_assert (old_len == path->entries_length);
-    path->hn = GCP_attach_path (path->entries[old_len - 1]->peer,
-                                path,
-                                old_len - 1,
-                                GNUNET_YES);
-    GNUNET_assert (NULL != path->hn);
-    return;
-  }
-  LOG (GNUNET_ERROR_TYPE_DEBUG,
-       "Extended path %s\n",
-       GCPP_2s (path));
+    {
+      /* none of the peers is interested in this path;
+         re-attach. */
+      GNUNET_assert(old_len == path->entries_length);
+      path->hn = GCP_attach_path(path->entries[old_len - 1]->peer,
+                                 path,
+                                 old_len - 1,
+                                 GNUNET_YES);
+      GNUNET_assert(NULL != path->hn);
+      return;
+    }
+  LOG(GNUNET_ERROR_TYPE_DEBUG,
+      "Extended path %s\n",
+      GCPP_2s(path));
 }
 
 
@@ -471,10 +467,10 @@ extend_path (struct CadetPeerPath *path,
  * @return a path through the network
  */
 void
-GCPP_try_path_from_dht (const struct GNUNET_PeerIdentity *get_path,
-                        unsigned int get_path_length,
-                        const struct GNUNET_PeerIdentity *put_path,
-                        unsigned int put_path_length)
+GCPP_try_path_from_dht(const struct GNUNET_PeerIdentity *get_path,
+                       unsigned int get_path_length,
+                       const struct GNUNET_PeerIdentity *put_path,
+                       unsigned int put_path_length)
 {
   struct CadetPeer *cpath[get_path_length + put_path_length];
   struct CheckMatchContext cm_ctx;
@@ -484,42 +480,42 @@ GCPP_try_path_from_dht (const struct GNUNET_PeerIdentity *get_path,
 
   /* precompute 'cpath' so we can avoid doing the lookups lots of times */
   skip = 0;
-  memset (cpath,
-          0,
-          sizeof (cpath)); /* Just to trigger harder errors later. */
+  memset(cpath,
+         0,
+         sizeof(cpath));   /* Just to trigger harder errors later. */
   total_len = get_path_length + put_path_length;
-  for (unsigned int off=0;off<total_len;off++)
-  {
-    const struct GNUNET_PeerIdentity *pid;
-
-    pid = (off < get_path_length)
-      ? &get_path[get_path_length - off - 1]
-      : &put_path[get_path_length + put_path_length - off - 1];
-    /* Check that I am not in the path */
-    if (0 == GNUNET_memcmp (&my_full_id,
-                     pid))
+  for (unsigned int off = 0; off < total_len; off++)
     {
-      skip = off + 1;
-      continue;
+      const struct GNUNET_PeerIdentity *pid;
+
+      pid = (off < get_path_length)
+            ? &get_path[get_path_length - off - 1]
+            : &put_path[get_path_length + put_path_length - off - 1];
+      /* Check that I am not in the path */
+      if (0 == GNUNET_memcmp(&my_full_id,
+                             pid))
+        {
+          skip = off + 1;
+          continue;
+        }
+      cpath[off - skip] = GCP_get(pid,
+                                  GNUNET_YES);
+      /* Check that no peer is twice on the path */
+      for (unsigned int i = 0; i < off - skip; i++)
+        {
+          if (cpath[i] == cpath[off - skip])
+            {
+              skip = off - i;
+              break;
+            }
+        }
     }
-    cpath[off - skip] = GCP_get (pid,
-                                 GNUNET_YES);
-    /* Check that no peer is twice on the path */
-    for (unsigned int i=0;i<off - skip;i++)
+  if (skip >= total_len)
     {
-     if (cpath[i] == cpath[off - skip])
-      {
-        skip = off - i;
-        break;
-      }
+      LOG(GNUNET_ERROR_TYPE_DEBUG,
+          "Path discovered from DHT is one big cycle?\n");
+      return;
     }
-  }
-  if (skip >= total_len)
-  {
-    LOG (GNUNET_ERROR_TYPE_DEBUG,
-         "Path discovered from DHT is one big cycle?\n");
-    return;
-  }
   total_len -= skip;
 
   /* First figure out if this path is a subset of an existing path, an
@@ -527,73 +523,73 @@ GCPP_try_path_from_dht (const struct GNUNET_PeerIdentity *get_path,
   cm_ctx.cpath_length = total_len;
   cm_ctx.cpath = cpath;
   cm_ctx.match = NULL;
-  for (int i=total_len-1;i>=0;i--)
-  {
-    GCP_iterate_paths_at (cpath[i],
-                          (unsigned int) i,
-                          &check_match,
-                          &cm_ctx);
-    if (NULL != cm_ctx.match)
+  for (int i = total_len - 1; i >= 0; i--)
     {
-      if (i == total_len - 1)
-      {
-        /* Existing path includes this one, nothing to do! */
-        LOG (GNUNET_ERROR_TYPE_DEBUG,
-             "Path discovered from DHT is already known\n");
-        return;
-      }
-      if (cm_ctx.match->entries_length == i + 1)
-      {
-        /* Existing path ends in the middle of new path, extend it! */
-        LOG (GNUNET_ERROR_TYPE_DEBUG,
-             "Trying to extend existing path %s by additional links discovered from DHT\n",
-             GCPP_2s (cm_ctx.match));
-        extend_path (cm_ctx.match,
-                     &cpath[i + 1],
-                     total_len - i - 1,
-                     GNUNET_NO);
-        return;
-      }
+      GCP_iterate_paths_at(cpath[i],
+                           (unsigned int)i,
+                           &check_match,
+                           &cm_ctx);
+      if (NULL != cm_ctx.match)
+        {
+          if (i == total_len - 1)
+            {
+              /* Existing path includes this one, nothing to do! */
+              LOG(GNUNET_ERROR_TYPE_DEBUG,
+                  "Path discovered from DHT is already known\n");
+              return;
+            }
+          if (cm_ctx.match->entries_length == i + 1)
+            {
+              /* Existing path ends in the middle of new path, extend it! */
+              LOG(GNUNET_ERROR_TYPE_DEBUG,
+                  "Trying to extend existing path %s by additional links discovered from DHT\n",
+                  GCPP_2s(cm_ctx.match));
+              extend_path(cm_ctx.match,
+                          &cpath[i + 1],
+                          total_len - i - 1,
+                          GNUNET_NO);
+              return;
+            }
+        }
     }
-  }
 
   /* No match at all, create completely new path */
-  path = GNUNET_new (struct CadetPeerPath);
+  path = GNUNET_new(struct CadetPeerPath);
   path->entries_length = total_len;
-  path->entries = GNUNET_new_array (path->entries_length,
-                                    struct CadetPeerPathEntry *);
-  for (int i=path->entries_length-1;i>=0;i--)
-  {
-    struct CadetPeerPathEntry *entry = GNUNET_new (struct CadetPeerPathEntry);
-
-    path->entries[i] = entry;
-    entry->peer = cpath[i];
-    entry->path = path;
-  }
-  for (int i=path->entries_length-1;i>=0;i--)
-  {
-    struct CadetPeerPathEntry *entry = path->entries[i];
-
-    GCP_path_entry_add (entry->peer,
-                        entry,
-                        i);
-  }
+  path->entries = GNUNET_new_array(path->entries_length,
+                                   struct CadetPeerPathEntry *);
+  for (int i = path->entries_length - 1; i >= 0; i--)
+    {
+      struct CadetPeerPathEntry *entry = GNUNET_new(struct CadetPeerPathEntry);
+
+      path->entries[i] = entry;
+      entry->peer = cpath[i];
+      entry->path = path;
+    }
+  for (int i = path->entries_length - 1; i >= 0; i--)
+    {
+      struct CadetPeerPathEntry *entry = path->entries[i];
+
+      GCP_path_entry_add(entry->peer,
+                         entry,
+                         i);
+    }
 
   /* Finally, try to attach it */
-  attach_path (path, 0);
+  attach_path(path, 0);
   if (NULL == path->hn)
-  {
-    /* None of the peers on the path care about it. */
-    LOG (GNUNET_ERROR_TYPE_DEBUG,
-         "Path discovered from DHT is not interesting to us\n");
-    GNUNET_assert (0 == path->entries_length);
-    GNUNET_assert (NULL == path->entries);
-    GNUNET_free (path);
-    return;
-  }
-  LOG (GNUNET_ERROR_TYPE_DEBUG,
-       "Created new path %s based on information from DHT\n",
-       GCPP_2s (path));
+    {
+      /* None of the peers on the path care about it. */
+      LOG(GNUNET_ERROR_TYPE_DEBUG,
+          "Path discovered from DHT is not interesting to us\n");
+      GNUNET_assert(0 == path->entries_length);
+      GNUNET_assert(NULL == path->entries);
+      GNUNET_free(path);
+      return;
+    }
+  LOG(GNUNET_ERROR_TYPE_DEBUG,
+      "Created new path %s based on information from DHT\n",
+      GCPP_2s(path));
 }
 
 
@@ -605,8 +601,8 @@ GCPP_try_path_from_dht (const struct GNUNET_PeerIdentity *get_path,
  * @return corresponding path object
  */
 struct CadetPeerPath *
-GCPP_get_path_from_route (unsigned int path_length,
-                          const struct GNUNET_PeerIdentity *pids)
+GCPP_get_path_from_route(unsigned int path_length,
+                         const struct GNUNET_PeerIdentity *pids)
 {
   struct CheckMatchContext cm_ctx;
   struct CadetPeer *cpath[path_length];
@@ -614,79 +610,79 @@ GCPP_get_path_from_route (unsigned int path_length,
 
   /* precompute inverted 'cpath' so we can avoid doing the lookups and
      have the correct order */
-  for (unsigned int off=0;off<path_length;off++)
-    cpath[off] = GCP_get (&pids[path_length - 1 - off],
-                          GNUNET_YES);
+  for (unsigned int off = 0; off < path_length; off++)
+    cpath[off] = GCP_get(&pids[path_length - 1 - off],
+                         GNUNET_YES);
 
   /* First figure out if this path is a subset of an existing path, an
      extension of an existing path, or a new path. */
   cm_ctx.cpath = cpath;
   cm_ctx.cpath_length = path_length;
   cm_ctx.match = NULL;
-  for (int i=path_length-1;i>=0;i--)
-  {
-    GCP_iterate_paths_at (cpath[i],
-                          (unsigned int) i,
-                          &check_match,
-                          &cm_ctx);
-    if (NULL != cm_ctx.match)
+  for (int i = path_length - 1; i >= 0; i--)
     {
-      if (i == path_length - 1)
-      {
-        /* Existing path includes this one, return the match! */
-        LOG (GNUNET_ERROR_TYPE_DEBUG,
-             "Returning existing path %s as inverse for incoming connection\n",
-             GCPP_2s (cm_ctx.match));
-        return cm_ctx.match;
-      }
-      if (cm_ctx.match->entries_length == i + 1)
-      {
-        /* Existing path ends in the middle of new path, extend it! */
-        LOG (GNUNET_ERROR_TYPE_DEBUG,
-             "Extending existing path %s to create inverse for incoming connection\n",
-             GCPP_2s (cm_ctx.match));
-        extend_path (cm_ctx.match,
-                     &cpath[i + 1],
-                     path_length - i - 1,
-                     GNUNET_YES);
-        /* Check that extension was successful */
-        GNUNET_assert (cm_ctx.match->entries_length == path_length);
-        return cm_ctx.match;
-      }
-      /* Eh, we found a match but couldn't use it? Something is wrong. */
-      GNUNET_break (0);
+      GCP_iterate_paths_at(cpath[i],
+                           (unsigned int)i,
+                           &check_match,
+                           &cm_ctx);
+      if (NULL != cm_ctx.match)
+        {
+          if (i == path_length - 1)
+            {
+              /* Existing path includes this one, return the match! */
+              LOG(GNUNET_ERROR_TYPE_DEBUG,
+                  "Returning existing path %s as inverse for incoming connection\n",
+                  GCPP_2s(cm_ctx.match));
+              return cm_ctx.match;
+            }
+          if (cm_ctx.match->entries_length == i + 1)
+            {
+              /* Existing path ends in the middle of new path, extend it! */
+              LOG(GNUNET_ERROR_TYPE_DEBUG,
+                  "Extending existing path %s to create inverse for incoming connection\n",
+                  GCPP_2s(cm_ctx.match));
+              extend_path(cm_ctx.match,
+                          &cpath[i + 1],
+                          path_length - i - 1,
+                          GNUNET_YES);
+              /* Check that extension was successful */
+              GNUNET_assert(cm_ctx.match->entries_length == path_length);
+              return cm_ctx.match;
+            }
+          /* Eh, we found a match but couldn't use it? Something is wrong. */
+          GNUNET_break(0);
+        }
     }
-  }
 
   /* No match at all, create completely new path */
-  path = GNUNET_new (struct CadetPeerPath);
+  path = GNUNET_new(struct CadetPeerPath);
   path->entries_length = path_length;
-  path->entries = GNUNET_new_array (path->entries_length,
-                                    struct CadetPeerPathEntry *);
-  for (int i=path_length-1;i>=0;i--)
-  {
-    struct CadetPeerPathEntry *entry = GNUNET_new (struct CadetPeerPathEntry);
-
-    path->entries[i] = entry;
-    entry->peer = cpath[i];
-    entry->path = path;
-  }
-  for (int i=path_length-1;i>=0;i--)
-  {
-    struct CadetPeerPathEntry *entry = path->entries[i];
-
-    GCP_path_entry_add (entry->peer,
-                        entry,
-                        i);
-  }
-  recalculate_path_desirability (path);
-  LOG (GNUNET_ERROR_TYPE_DEBUG,
-       "Created new path %s to create inverse for incoming connection\n",
-       GCPP_2s (path));
-  path->hn = GCP_attach_path (cpath[path_length - 1],
-                              path,
-                              path_length - 1,
-                              GNUNET_YES);
+  path->entries = GNUNET_new_array(path->entries_length,
+                                   struct CadetPeerPathEntry *);
+  for (int i = path_length - 1; i >= 0; i--)
+    {
+      struct CadetPeerPathEntry *entry = GNUNET_new(struct CadetPeerPathEntry);
+
+      path->entries[i] = entry;
+      entry->peer = cpath[i];
+      entry->path = path;
+    }
+  for (int i = path_length - 1; i >= 0; i--)
+    {
+      struct CadetPeerPathEntry *entry = path->entries[i];
+
+      GCP_path_entry_add(entry->peer,
+                         entry,
+                         i);
+    }
+  recalculate_path_desirability(path);
+  LOG(GNUNET_ERROR_TYPE_DEBUG,
+      "Created new path %s to create inverse for incoming connection\n",
+      GCPP_2s(path));
+  path->hn = GCP_attach_path(cpath[path_length - 1],
+                             path,
+                             path_length - 1,
+                             GNUNET_YES);
   return path;
 }
 
@@ -699,7 +695,7 @@ GCPP_get_path_from_route (unsigned int path_length,
  * @return number of peers on the path
  */
 unsigned int
-GCPP_get_length (struct CadetPeerPath *path)
+GCPP_get_length(struct CadetPeerPath *path)
 {
   return path->entries_length;
 }
@@ -713,14 +709,14 @@ GCPP_get_length (struct CadetPeerPath *path)
  * @return offset of @a cp on @a path, or UINT_MAX if not found
  */
 unsigned int
-GCPP_find_peer (struct CadetPeerPath *path,
-                struct CadetPeer *cp)
+GCPP_find_peer(struct CadetPeerPath *path,
+               struct CadetPeer *cp)
 {
   for (unsigned int off = 0;
        off < path->entries_length;
        off++)
-    if (cp == GCPP_get_peer_at_offset (path,
-                                       off))
+    if (cp == GCPP_get_peer_at_offset(path,
+                                      off))
       return off;
   return UINT_MAX;
 }
@@ -734,10 +730,10 @@ GCPP_find_peer (struct CadetPeerPath *path,
  * @return the peer at offset @a off
  */
 struct CadetPeer *
-GCPP_get_peer_at_offset (struct CadetPeerPath *path,
-                         unsigned int off)
+GCPP_get_peer_at_offset(struct CadetPeerPath *path,
+                        unsigned int off)
 {
-  GNUNET_assert (off < path->entries_length);
+  GNUNET_assert(off < path->entries_length);
   return path->entries[off]->peer;
 }
 
@@ -749,7 +745,7 @@ GCPP_get_peer_at_offset (struct CadetPeerPath *path,
  * @return string, to be freed by caller (unlike other *_2s APIs!)
  */
 const char *
-GCPP_2s (struct CadetPeerPath *path)
+GCPP_2s(struct CadetPeerPath *path)
 {
   static char buf[2048];
   size_t off;
@@ -759,27 +755,27 @@ GCPP_2s (struct CadetPeerPath *path)
   for (unsigned int i = 0;
        i < path->entries_length;
        i++)
-  {
-    if ( (path->entries_length > max_plen) &&
-         (i == max_plen / 2) )
-      off += GNUNET_snprintf (&buf[off],
-                              sizeof (buf) - off,
-                              "...-");
-    if ( (path->entries_length > max_plen) &&
-         (i > max_plen / 2) &&
-         (i < path->entries_length - max_plen / 2) )
-      continue;
-    off += GNUNET_snprintf (&buf[off],
-                            sizeof (buf) - off,
-                            "%s%s",
-                            GNUNET_i2s (GCP_get_id (GCPP_get_peer_at_offset (path,
-                                                                             i))),
-                            (i == path->entries_length -1) ? "" : "-");
-  }
-  GNUNET_snprintf (&buf[off],
-                   sizeof (buf) - off,
-                   "(%p)",
-                   path);
+    {
+      if ((path->entries_length > max_plen) &&
+          (i == max_plen / 2))
+        off += GNUNET_snprintf(&buf[off],
+                               sizeof(buf) - off,
+                               "...-");
+      if ((path->entries_length > max_plen) &&
+          (i > max_plen / 2) &&
+          (i < path->entries_length - max_plen / 2))
+        continue;
+      off += GNUNET_snprintf(&buf[off],
+                             sizeof(buf) - off,
+                             "%s%s",
+                             GNUNET_i2s(GCP_get_id(GCPP_get_peer_at_offset(path,
+                                                                           i))),
+                             (i == path->entries_length - 1) ? "" : "-");
+    }
+  GNUNET_snprintf(&buf[off],
+                  sizeof(buf) - off,
+                  "(%p)",
+                  path);
   return buf;
 }
 

Niektóre pliki nie zostały wyświetlone z powodu dużej ilości zmienionych plików