use constants instead of casting -1
authorChristian Grothoff <christian@grothoff.org>
Fri, 11 Jun 2010 21:57:37 +0000 (21:57 +0000)
committerChristian Grothoff <christian@grothoff.org>
Fri, 11 Jun 2010 21:57:37 +0000 (21:57 +0000)
src/core/gnunet-service-core.c
src/datastore/datastore.h
src/fs/fs_download.c
src/fs/gnunet-service-fs.c
src/fs/test_gnunet_service_fs_migration.c
src/fs/test_gnunet_service_fs_migration_data.conf
src/testing/testing_group.c
src/transport/gnunet-service-transport.c
src/util/time.c

index 2d06bd440b54889281571224d79895e18abae54e..97ed5736057dce1b33baabe3331a6abf1871fffa 100644 (file)
@@ -1029,7 +1029,7 @@ handle_client_request_info (void *cls,
       if (old_preference > n->current_preference) 
        {
          /* overflow; cap at maximum value */
-         n->current_preference = (unsigned long long) -1;
+         n->current_preference = ULLONG_MAX;
        }
       update_preference_sum (n->current_preference - old_preference);
 #if DEBUG_CORE_QUOTA
@@ -1545,7 +1545,7 @@ select_messages (struct Neighbour *n,
   while (GNUNET_YES == discard_low_prio)
     {
       min = NULL;
-      min_prio = -1;
+      min_prio = UINT_MAX;
       discard_low_prio = GNUNET_NO;
       /* calculate number of bytes available for transmission at time "t" */
       avail = GNUNET_BANDWIDTH_tracker_get_available (&n->available_send_window);
@@ -2014,7 +2014,7 @@ process_plaintext_neighbour_queue (struct Neighbour *n)
              (unsigned int) ntohl (n->bw_in.value__),
              GNUNET_i2s (&n->peer));
 #endif
-  ph->iv_seed = htonl (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, -1));
+  ph->iv_seed = htonl (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX));
   ph->sequence_number = htonl (++n->last_sequence_number_sent);
   ph->inbound_bw_limit = n->bw_in;
   ph->timestamp = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ());
@@ -2122,10 +2122,10 @@ create_neighbour (const struct GNUNET_PeerIdentity *pid)
   n->set_key_retry_frequency = INITIAL_SET_KEY_RETRY_FREQUENCY;
   n->bw_in = GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT;
   n->bw_out = GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT;
-  n->bw_out_internal_limit = GNUNET_BANDWIDTH_value_init ((uint32_t) - 1);
+  n->bw_out_internal_limit = GNUNET_BANDWIDTH_value_init (UINT32_MAX);
   n->bw_out_external_limit = GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT;
   n->ping_challenge = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
-                                                (uint32_t) - 1);
+                                                UINT32_MAX);
   neighbour_quota_update (n, NULL);
   consider_free_neighbour (n);
   return n;
@@ -2186,7 +2186,7 @@ handle_client_send (void *cls,
 #endif
   /* bound queue size */
   discard_expired_messages (n);
-  min_prio = (unsigned int) -1;
+  min_prio = UINT32_MAX;
   min_prio_entry = NULL;
   min_prio_prev = NULL;
   queue_size = 0;
@@ -3641,8 +3641,8 @@ neighbour_quota_update (void *cls,
   if (bandwidth_target_out_bps > need_per_second)
     distributable = bandwidth_target_out_bps - need_per_second;
   share = distributable * pref_rel;
-  if (share + need_per_peer > ( (uint32_t)-1))
-    q_in = GNUNET_BANDWIDTH_value_init ((uint32_t) -1);
+  if (share + need_per_peer > UINT32_MAX)
+    q_in = GNUNET_BANDWIDTH_value_init (UINT32_MAX);
   else
     q_in = GNUNET_BANDWIDTH_value_init (need_per_peer + (uint32_t) share);
   /* check if we want to disconnect for good due to inactivity */
index aa2646c0a7b04ad166be11dea91eda16552d3800..f827f87664f1634d9042f32fd3106c7fffd5d4d8 100644 (file)
@@ -27,7 +27,7 @@
 #ifndef DATASTORE_H
 #define DATASTORE_H
 
-#define DEBUG_DATASTORE GNUNET_NO
+#define DEBUG_DATASTORE GNUNET_YES
 
 #include "gnunet_util_lib.h"
 
index ff3eb09e1477455806186e848b014c25d0aff4dd..807ade93ca958cfdce66f8498e91936dc18c4fee 100644 (file)
@@ -1647,7 +1647,8 @@ GNUNET_FS_download_start_from_search (struct GNUNET_FS_Handle *h,
   struct GNUNET_FS_ProgressInfo pi;
   struct GNUNET_FS_DownloadContext *dc;
 
-  if (sr->download != NULL)
+  if ( (sr != NULL) &&
+       (sr->download != NULL) )
     {
       GNUNET_break (0);
       return NULL;
index c5a47973c2d6b3efe51a4cdfeb01a0926c551688..d7dc8600294edf62dc8e41809175fef5f7413bb2 100644 (file)
@@ -2150,7 +2150,7 @@ forward_request_task (void *cls,
   pr->irc = GNUNET_CORE_peer_change_preference (sched, cfg,
                                                &psc.target,
                                                GNUNET_CONSTANTS_SERVICE_TIMEOUT, 
-                                               GNUNET_BANDWIDTH_value_init ((uint32_t) -1 /* no limit */), 
+                                               GNUNET_BANDWIDTH_value_init (UINT32_MAX),
                                                DBLOCK_SIZE * 2, 
                                                (uint64_t) cp->inc_preference,
                                                &target_reservation_cb,
@@ -2348,7 +2348,8 @@ process_reply (void *cls,
       if (pr->cp != NULL)
        {
          GNUNET_PEER_change_rc (prq->sender->last_p2p_replies
-                                [prq->sender->last_p2p_replies_woff % P2P_SUCCESS_LIST_SIZE], -1);
+                                [prq->sender->last_p2p_replies_woff % P2P_SUCCESS_LIST_SIZE], 
+                                -1);
          GNUNET_PEER_change_rc (pr->cp->pid, 1);
          prq->sender->last_p2p_replies
            [(prq->sender->last_p2p_replies_woff++) % P2P_SUCCESS_LIST_SIZE]
@@ -2515,7 +2516,7 @@ process_reply (void *cls,
       reply->cont = &transmit_reply_continuation;
       reply->cont_cls = pr;
       reply->msize = msize;
-      reply->priority = (uint32_t) -1; /* send replies first! */
+      reply->priority = UINT32_MAX; /* send replies first! */
       pm = (struct PutMessage*) &reply[1];
       pm->header.type = htons (GNUNET_MESSAGE_TYPE_FS_PUT);
       pm->header.size = htons (msize);
index 9cf8c377394682517506a63d4d0bbce14e57f343..835650ef66808bbec837256cd44abbdf4440ea32 100644 (file)
@@ -244,6 +244,7 @@ main (int argc, char *argv[])
                    "WARNING",
 #endif
                    NULL);
+  system ("netstat -ntpl");
   GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
                       argvx, "test-gnunet-service-fs-migration",
                      "nohelp", options, &run, NULL);
index 82606092cbc97ebe0998cc1c4573a76003c04fd8..9a388e0e88327398ade796624cfa5993315aaae9 100644 (file)
@@ -12,12 +12,13 @@ HOSTNAME = localhost
 [transport]
 PORT = 43465
 PLUGINS = tcp
-#DEBUG = YES
+DEBUG = YES
 
 [arm]
 PORT = 43466
 HOSTNAME = localhost
 DEFAULTSERVICES = fs
+OPTIONS = -L DEBUG
 
 [datastore]
 #DEBUG = YES
index 7afbbd48be29360a8089d59cd2f08f8e96b5d529..4f369812de972afb525ff15c631b34818a7b12cb 100644 (file)
@@ -726,7 +726,7 @@ create_scale_free (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_Connectio
         {
           probability = pg->peers[i].num_connections / (double)previous_total_connections;
           random = ((double) GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK,
-                                                      (uint64_t)-1LL)) / ( (double) (uint64_t) -1LL);
+                                                      UINT64_MAX)) / ( (double) UINT64_MAX);
 #if VERBOSE_TESTING
           GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                       "Considering connecting peer %d to peer %d\n",
@@ -820,7 +820,7 @@ create_small_world_ring(struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_Conn
       for (j = 0; j < connsPerPeer / 2; j++)
         {
           random = ((double) GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK,
-                                                     (uint64_t)-1LL)) / ( (double) (uint64_t) -1LL);
+                                                     UINT64_MAX) / ( (double) UINT64_MAX));
           if (random < percentage)
             {
               /* Connect to uniformly selected random peer */
@@ -1035,7 +1035,7 @@ create_small_world (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_Connecti
                   probability = 1.0 / (distance * distance);
                   /* Choose a random value between 0 and 1 */
                  random = ((double) GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK,
-                                                             (uint64_t)-1LL)) / ( (double) (uint64_t) -1LL);
+                                                             UINT64_MAX)) / ( (double) UINT64_MAX);
                   /* If random < probability, then connect the two nodes */
                   if (random < probability)
                     smallWorldConnections += proc (pg, j, k);
@@ -1086,7 +1086,7 @@ create_erdos_renyi (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_Connecti
            inner_count++)
         {
           temp_rand = ((double) GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK,
-                                                        (uint64_t)-1LL)) / ( (double) (uint64_t) -1LL);
+                                                        UINT64_MAX)) / ( (double) UINT64_MAX);
 #if VERBOSE_TESTING
           GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                       _("rand is %f probability is %f\n"), temp_rand,
@@ -2077,7 +2077,7 @@ random_connect_iterator (void *cls,
   uint32_t second_pos;
   GNUNET_HashCode first_hash;
   random_number = ((double) GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK,
-                   (uint64_t)-1LL)) / ( (double) (uint64_t) -1LL);
+                                                    UINT64_MAX)) / ( (double) UINT64_MAX);
   if (random_number < random_ctx->percentage)
   {
     GNUNET_assert(GNUNET_OK == GNUNET_CONTAINER_multihashmap_put(random_ctx->first->connect_peers_working_set, key, value, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
index 1dcd988a9a67e5efd228a8cb8f2180780459b6b0..fd47130a170e4561fedf045faab707707fb7e098 100644 (file)
@@ -3132,7 +3132,7 @@ send_periodic_ping (void *cls,
   va = GNUNET_malloc (sizeof (struct ValidationEntry) + peer_address->addrlen);
   va->transport_name = GNUNET_strdup (tp->short_name);
   va->challenge = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
-                                            (unsigned int) -1);
+                                            UINT_MAX);
   va->send_time = GNUNET_TIME_absolute_get();
   va->session = peer_address->session;
   if (peer_address->addr != NULL)
@@ -3690,7 +3690,7 @@ run_validation (void *cls,
   chvc->ve_count++;
   va->transport_name = GNUNET_strdup (tname);
   va->challenge = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
-                                            (unsigned int) -1);
+                                            UINT_MAX);
   va->send_time = GNUNET_TIME_absolute_get();
   va->addr = (const void*) &va[1];
   memcpy (&va[1], addr, addrlen);
index 3d53e0af2f8a36809610eb484db09380af3c3f95..6a5a314da5263d5edc5d9361d6a55feebc450b38 100644 (file)
@@ -84,7 +84,7 @@ GNUNET_TIME_relative_get_unit ()
 struct GNUNET_TIME_Relative
 GNUNET_TIME_relative_get_forever ()
 {
-  static struct GNUNET_TIME_Relative forever = { (uint64_t) - 1LL };
+  static struct GNUNET_TIME_Relative forever = { UINT64_MAX };
   return forever;
 }
 
@@ -94,7 +94,7 @@ GNUNET_TIME_relative_get_forever ()
 struct GNUNET_TIME_Absolute
 GNUNET_TIME_absolute_get_forever ()
 {
-  static struct GNUNET_TIME_Absolute forever = { (uint64_t) - 1LL };
+  static struct GNUNET_TIME_Absolute forever = { UINT64_MAX };
   return forever;
 }
 
@@ -108,7 +108,7 @@ struct GNUNET_TIME_Absolute
 GNUNET_TIME_relative_to_absolute (struct GNUNET_TIME_Relative rel)
 {
   struct GNUNET_TIME_Absolute ret;
-  if (rel.value == (uint64_t) - 1LL)
+  if (rel.value == UINT64_MAX)
     return GNUNET_TIME_absolute_get_forever ();
   struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
   if (rel.value + now.value < rel.value)
@@ -196,7 +196,7 @@ struct GNUNET_TIME_Relative
 GNUNET_TIME_absolute_get_remaining (struct GNUNET_TIME_Absolute future)
 {
   struct GNUNET_TIME_Relative ret;
-  if (future.value == (uint64_t) - 1LL)
+  if (future.value == UINT64_MAX)
     return GNUNET_TIME_relative_get_forever ();
   struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
   if (now.value > future.value)
@@ -217,7 +217,7 @@ GNUNET_TIME_absolute_get_difference (struct GNUNET_TIME_Absolute start,
                                      struct GNUNET_TIME_Absolute end)
 {
   struct GNUNET_TIME_Relative ret;
-  if (end.value == (uint64_t) - 1LL)
+  if (end.value == UINT64_MAX)
     return GNUNET_TIME_relative_get_forever ();
   if (end.value < start.value)
     return GNUNET_TIME_relative_get_zero ();
@@ -238,7 +238,7 @@ GNUNET_TIME_absolute_get_duration (struct GNUNET_TIME_Absolute hence)
   struct GNUNET_TIME_Relative ret;
 
   now = GNUNET_TIME_absolute_get ();
-  GNUNET_assert (hence.value != (uint64_t) - 1LL);
+  GNUNET_assert (hence.value != UINT64_MAX);
   if (hence.value > now.value)
     return GNUNET_TIME_relative_get_zero ();
   ret.value = now.value - hence.value;
@@ -258,8 +258,8 @@ GNUNET_TIME_absolute_add (struct GNUNET_TIME_Absolute start,
 {
   struct GNUNET_TIME_Absolute ret;
 
-  if ((start.value == (uint64_t) - 1LL) ||
-      (duration.value == (uint64_t) - 1LL))
+  if ((start.value == UINT64_MAX) ||
+      (duration.value == UINT64_MAX))
     return GNUNET_TIME_absolute_get_forever ();
   if (start.value + duration.value < start.value)
     {
@@ -382,7 +382,7 @@ GNUNET_TIME_relative_add (struct GNUNET_TIME_Relative a1,
 {
   struct GNUNET_TIME_Relative ret;
 
-  if ((a1.value == (uint64_t) - 1LL) || (a2.value == (uint64_t) - 1LL))
+  if ((a1.value == UINT64_MAX) || (a2.value == UINT64_MAX))
     return GNUNET_TIME_relative_get_forever ();
   if (a1.value + a2.value < a1.value)
     {
@@ -409,7 +409,7 @@ GNUNET_TIME_relative_subtract (struct GNUNET_TIME_Relative a1,
 
   if (a2.value >= a1.value)
     return GNUNET_TIME_relative_get_zero ();
-  if (a1.value == (uint64_t) - 1LL
+  if (a1.value == UINT64_MAX
     return GNUNET_TIME_relative_get_forever ();
   ret.value = a1.value - a2.value;
   return ret;