gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r34302 - in gnunet/src: dht include


From: gnunet
Subject: [GNUnet-SVN] r34302 - in gnunet/src: dht include
Date: Mon, 22 Sep 2014 17:12:15 +0200

Author: supriti
Date: 2014-09-22 17:12:15 +0200 (Mon, 22 Sep 2014)
New Revision: 34302

Modified:
   gnunet/src/dht/dht.h
   gnunet/src/dht/dht_api.c
   gnunet/src/dht/gnunet-service-xdht_clients.c
   gnunet/src/dht/gnunet-service-xdht_neighbours.c
   gnunet/src/dht/gnunet-service-xdht_neighbours.h
   gnunet/src/dht/gnunet_dht_profiler.c
   gnunet/src/include/gnunet_dht_service.h
   gnunet/src/include/gnunet_protocols.h
Log:
- Act malicious API complete
- Using multiple trails in PUT/GET


Modified: gnunet/src/dht/dht.h
===================================================================
--- gnunet/src/dht/dht.h        2014-09-22 13:19:57 UTC (rev 34301)
+++ gnunet/src/dht/dht.h        2014-09-22 15:12:15 UTC (rev 34302)
@@ -442,7 +442,20 @@
 };
 
 #if ENABLE_MALICIOUS
+
 /**
+ * Message to confirming receipt of ACT MALICIOUS, sent from DHT service to 
clients.
+ */
+struct GNUNET_DHT_ClientActMaliciousConfirmationMessage
+{
+  /**
+   * Type: #GNUNET_MESSAGE_TYPE_DHT_CLIENT_PUT_OK
+   */
+  struct GNUNET_MessageHeader header;
+};
+
+
+/**
  * Message to turn the service malicious
  */
 struct GNUNET_DHT_ActMaliciousMessage
@@ -453,7 +466,7 @@
   struct GNUNET_MessageHeader header;
 
   /**
-   * Type of malicious behaviour expected; 0 turning peer benign
+   * If set to 1, act maliciously
    */
   uint32_t action;
 };

Modified: gnunet/src/dht/dht_api.c
===================================================================
--- gnunet/src/dht/dht_api.c    2014-09-22 13:19:57 UTC (rev 34301)
+++ gnunet/src/dht/dht_api.c    2014-09-22 15:12:15 UTC (rev 34302)
@@ -93,7 +93,29 @@
 
 };
 
+#if ENABLE_MALICIOUS
+/**
+ * Handle to act malicious message
+ */
+struct GNUNET_DHT_ActMaliciousHandle
+{
+  /**
+   * Continuation to call when done.
+   */
+  GNUNET_DHT_ActMaliciousContinuation cont;
 
+  /**
+   * Main handle to this DHT api
+   */
+  struct GNUNET_DHT_Handle *dht_handle;
+
+  /**
+   * Closure for 'cont'.
+   */
+  void *cont_cls;
+};
+#endif
+
 /**
  * Handle to a PUT request.
  */
@@ -142,8 +164,6 @@
 
 };
 
-
-
 /**
  * Handle to a GET request
  */
@@ -342,6 +362,13 @@
    * Did we start our receive loop yet?
    */
   int in_receive;
+  
+#if ENABLE_MALICIOUS
+  /**
+   * Handle of act malicious request.
+   */
+  struct GNUNET_DHT_ActMaliciousHandle *mh;
+#endif
 };
 
 
@@ -857,7 +884,36 @@
 }
 
 
+#if ENABLE_MALICIOUS
 /**
+ * Process a act malicious confirmation from service.
+ * @param handle The DHT handle.
+ * @param msg confirmation message from the service.
+ * @return #GNUNET_OK if everything went fine,
+ *         #GNUNET_SYSERR if the message is malformed.
+ */
+static int
+process_act_malicious_confirmation_message (struct GNUNET_DHT_Handle *handle,
+           const struct GNUNET_DHT_ClientActMaliciousConfirmationMessage *msg)
+{
+   struct GNUNET_DHT_ActMaliciousHandle *mh;
+   GNUNET_DHT_PutContinuation cont;
+   void *cont_cls;
+   
+   mh = handle->mh;
+   if (NULL == mh)
+    return GNUNET_OK;
+  cont = mh->cont;
+  cont_cls = mh->cont_cls;
+  if (NULL != cont)
+    cont (cont_cls, GNUNET_OK);
+  
+  return GNUNET_OK;
+}
+#endif
+
+
+/**
  * Process a put confirmation message from the service.
  *
  * @param handle The DHT handle.
@@ -972,6 +1028,17 @@
     ret = process_put_confirmation_message (handle,
                                            (const struct 
GNUNET_DHT_ClientPutConfirmationMessage*) msg);
     break;
+#if ENABLE_MALICIOUS
+    case GNUNET_MESSAGE_TYPE_DHT_CLIENT_ACT_MALICIOUS_OK:
+       if(msize != sizeof (struct 
GNUNET_DHT_ClientActMaliciousConfirmationMessage))
+       {
+         GNUNET_break (0);
+         break;
+       }
+       ret = process_act_malicious_confirmation_message (handle,
+                                           (const struct 
GNUNET_DHT_ClientActMaliciousConfirmationMessage*) msg);
+      break;
+#endif
   default:
     GNUNET_break(0);
     LOG (GNUNET_ERROR_TYPE_WARNING,
@@ -1151,7 +1218,6 @@
   struct PendingMessage *pending;
   struct GNUNET_DHT_PutHandle *ph;
 
-
   msize = sizeof (struct GNUNET_DHT_ClientPutMessage) + size;
   if ((msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
       (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE))
@@ -1499,16 +1565,21 @@
 
 #if ENABLE_MALICIOUS
 /**
- * Turn the DHT service to act malicious depending on @a flag
+ * Turn the DHT service to act malicious.
  *
  * @param handle the DHT handle
  * @param action 1 to make the service malicious; 0 to make it benign
-          FIXME: perhaps make this an enum of known malicious behaviors?
+ * @param cont continuation to call when done (transmitting request to service)
+ * @param cont_cls closure for @a cont        
  */
-void
-GNUNET_DHT_malicious (struct GNUNET_DHT_Handle *handle, unsigned int action)
+struct GNUNET_DHT_ActMaliciousHandle *
+GNUNET_DHT_act_malicious (struct GNUNET_DHT_Handle *handle, 
+                          unsigned int action,
+                          GNUNET_DHT_PutContinuation cont,
+                          void *cont_cls)
 {
   struct GNUNET_DHT_ActMaliciousMessage *amm;
+  struct GNUNET_DHT_ActMaliciousHandle *mh;
   struct PendingMessage *pending;
   size_t msize;
   
@@ -1516,9 +1587,12 @@
   if (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
   {
     GNUNET_break(0);
-    return;
+    return NULL;
   }
-  
+  mh = GNUNET_new (struct GNUNET_DHT_ActMaliciousHandle);
+  mh->dht_handle = handle;
+  mh->cont = cont;
+  mh->cont_cls = cont_cls;
   pending = GNUNET_malloc (sizeof (struct PendingMessage) + msize);
   amm = (struct GNUNET_DHT_ActMaliciousMessage *)&pending[1];
   pending->msg = &amm->header;
@@ -1527,11 +1601,12 @@
   amm->header.size = htons (msize);
   amm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_ACT_MALICIOUS);
   amm->action = action;
-  
+  handle->mh = mh;
   GNUNET_CONTAINER_DLL_insert (handle->pending_head, handle->pending_tail,
                                pending);
   pending->in_pending_queue = GNUNET_YES;
   process_pending_messages (handle);
+  return mh;
 }
 #endif
 

Modified: gnunet/src/dht/gnunet-service-xdht_clients.c
===================================================================
--- gnunet/src/dht/gnunet-service-xdht_clients.c        2014-09-22 13:19:57 UTC 
(rev 34301)
+++ gnunet/src/dht/gnunet-service-xdht_clients.c        2014-09-22 15:12:15 UTC 
(rev 34302)
@@ -46,14 +46,7 @@
 #define DEBUG(...)                                           \
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
 
-#if ENABLE_MALICIOUS
 /**
- * Should this peer act malicious?
- */
-extern unsigned int malicious;
-#endif
-
-/**
  * Linked list of messages to send to clients.
  */
 struct PendingMessage
@@ -1298,7 +1291,7 @@
 
 #if ENABLE_MALICIOUS
 /**
- * Handler for act malicous message.
+ * Handler for act malicious message.
  *
  * @param cls closure for the service
  * @param client the client we received this message from
@@ -1310,11 +1303,24 @@
                           const struct GNUNET_MessageHeader *message)
 {
   const struct GNUNET_DHT_ActMaliciousMessage *msg;
-  unsigned int malicious;
+  struct PendingMessage *pm;
+  struct GNUNET_DHT_ClientActMaliciousConfirmationMessage *conf;
+  unsigned int malicious_action;
+
+  msg = (const struct GNUNET_DHT_ActMaliciousMessage *)message;
+  malicious_action = msg->action;
   
-  msg = (const struct GNUNET_DHT_ActMaliciousMessage *)message;
-  malicious = msg->action;
-  GDS_NEIGHBOURS_act_malicious(malicious);
+  if(GNUNET_OK == GDS_NEIGHBOURS_act_malicious (malicious_action))
+  {
+    pm = GNUNET_malloc (sizeof (struct PendingMessage) +
+                     sizeof (struct 
GNUNET_DHT_ClientActMaliciousConfirmationMessage));
+    conf = (struct GNUNET_DHT_ClientActMaliciousConfirmationMessage *) &pm[1];
+    conf->header.size = htons (sizeof (struct 
GNUNET_DHT_ClientActMaliciousConfirmationMessage));
+    conf->header.type = htons 
(GNUNET_MESSAGE_TYPE_DHT_CLIENT_ACT_MALICIOUS_OK);
+    pm->msg = &conf->header;
+    add_pending_message (find_active_client (client), pm);
+    GNUNET_SERVER_receive_done (client, GNUNET_OK);
+  }
 }
 #endif
 

Modified: gnunet/src/dht/gnunet-service-xdht_neighbours.c
===================================================================
--- gnunet/src/dht/gnunet-service-xdht_neighbours.c     2014-09-22 13:19:57 UTC 
(rev 34301)
+++ gnunet/src/dht/gnunet-service-xdht_neighbours.c     2014-09-22 15:12:15 UTC 
(rev 34302)
@@ -111,7 +111,7 @@
 /**
  * Maximum number of trails stored per finger.
  */
-#define MAXIMUM_TRAILS_PER_FINGER 2
+#define MAXIMUM_TRAILS_PER_FINGER 4
 
 /**
  * Finger map index for predecessor entry in finger table.
@@ -1066,10 +1066,11 @@
  * Set the ENABLE_MALICIOUS value to malicious.
  * @param malicious
  */
-void 
+int
 GDS_NEIGHBOURS_act_malicious (unsigned int malicious)
 {
   act_malicious = malicious;
+  return GNUNET_OK;
 }
 #endif
 
@@ -2149,9 +2150,8 @@
   return current_closest_peer;
 }
 
+
 /**
- * FIXME; Send put message across all the trail to reach to next hop to handle
- * malicious peers.
  * Construct a Put message and send it to target_peer.
  * @param key Key for the content
  * @param block_type Type of the block
@@ -2267,7 +2267,6 @@
   next_hop = successor.next_hop;
   intermediate_trail_id = successor.trail_id;
 
-  DEBUG("PUT_REQUEST_RECEVIED KEY = %s \n",GNUNET_h2s(key));
   if (0 == GNUNET_CRYPTO_cmp_peer_identity (&best_known_dest, &my_identity))
   {
     /* I am the destination. */
@@ -2279,10 +2278,10 @@
                              key, data, data_size);
     return;
   }
-  
+  DEBUG("\n PUT_REQUEST_RECEVIED for key = %s, act_malicious = 
%d",GNUNET_h2s(key),act_malicious);
   /* In case we are sending the request to  a finger, then send across all of 
its
    trail.*/
-#if 0
+#if ENABLE_MALICIOUS
   if (0 != GNUNET_CRYPTO_cmp_peer_identity (&successor.best_known_destination,
                                             &successor.next_hop))
   {
@@ -2294,26 +2293,40 @@
     {
       if (GNUNET_YES == next_hop_finger->trail_list[i].is_present)
       {
+        if(0 == next_hop_finger->trail_list[i].trail_length)
+        {
+          DEBUG("\n PUT_REQUEST = %s TRAIL LENGTH = 0 NOT SENDING ACROSS 
MULTIPLE TRAILS,next_hop = %s", GNUNET_h2s(key),
+                  GNUNET_i2s(&next_hop));
+           GDS_NEIGHBOURS_send_put (key, block_type, options, 
desired_replication_level,
+                                    best_known_dest, intermediate_trail_id, 
&next_hop,
+                                    0, 1, &my_identity, expiration_time,
+                                    data, data_size);
+           return;
+        } 
+        next_hop = next_hop_finger->trail_list[i].trail_head->peer;
+        DEBUG("\n PUT_REQUEST = %s SENDING ACROSS TRAIL_ID = %s, next_hop = 
%s",
+               
GNUNET_h2s(key),GNUNET_h2s(&next_hop_finger->trail_list[i].trail_id),
+               GNUNET_i2s(&next_hop));
         GDS_NEIGHBOURS_send_put (key, block_type, options, 
desired_replication_level,
                                  best_known_dest, 
                                  next_hop_finger->trail_list[i].trail_id, 
-                                 &next_hop, hop_count, put_path_length, 
put_path,
+                                 &next_hop, 0, 1, &my_identity,
                                  expiration_time,
                                  data, data_size);
        }
     }
+    return;
   }
-  else
 #endif
-    GDS_NEIGHBOURS_send_put (key, block_type, options, 
desired_replication_level,
-                             best_known_dest, intermediate_trail_id, &next_hop,
-                             0, 1, &my_identity, expiration_time,
-                             data, data_size);
+ DEBUG("\n PUT_REQUEST = %s NOT SENDING ACROSS MULTIPLE TRAILS  next_hop = %s",
+          GNUNET_h2s(key), GNUNET_i2s(&next_hop));
+ GDS_NEIGHBOURS_send_put (key, block_type, options, desired_replication_level,
+                          best_known_dest, intermediate_trail_id, &next_hop,
+                          0, 1, &my_identity, expiration_time,
+                          data, data_size);
 }
 
 /**
- * FIXME; Send get message across all the trail to reach to next hop to handle
- * malicious peers.
  * Construct a Get message and send it to target_peer.
  * @param key Key for the content
  * @param block_type Type of the block
@@ -2400,6 +2413,7 @@
   struct Closest_Peer successor;
   struct GNUNET_PeerIdentity best_known_dest;
   struct GNUNET_HashCode intermediate_trail_id;
+  struct GNUNET_PeerIdentity next_hop;
   uint64_t key_value;
   
   memcpy (&key_value, key, sizeof (uint64_t));
@@ -2410,8 +2424,7 @@
   
   best_known_dest = successor.best_known_destination;
   intermediate_trail_id = successor.trail_id;
-  
-  DEBUG("GET_REQUEST_RECEVIED KEY = %s \n",GNUNET_h2s(key));
+
   /* I am the destination. I have the data. */
   if (0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity,
                                             &best_known_dest))
@@ -2421,9 +2434,37 @@
     return;
   }
     
-  /* fixme; for multiple trails, we need to send back finger index and send 
trail
-   across all the fingers. but in current implementation we don't have this 
case.
-   compare finger and current_successor returns, */
+#if ENABLE_MALICIOUS
+  if (0 != GNUNET_CRYPTO_cmp_peer_identity (&successor.best_known_destination,
+                                            &successor.next_hop))
+  {
+    struct FingerInfo *next_hop_finger;
+    unsigned int i;
+    
+    next_hop_finger = &finger_table[successor.finger_table_index];
+    for (i = 0; i < next_hop_finger->trails_count; i++)
+    {
+      if (GNUNET_YES == next_hop_finger->trail_list[i].is_present)
+      {
+        if(0 == next_hop_finger->trail_list[i].trail_length)
+        {
+           GDS_NEIGHBOURS_send_get (key, block_type, options, 
+                                    desired_replication_level,
+                                    best_known_dest,intermediate_trail_id, 
+                                    &successor.next_hop,
+                                    0, 1, &my_identity);
+           return;
+        }
+        next_hop = next_hop_finger->trail_list[i].trail_head->peer;
+        GDS_NEIGHBOURS_send_get (key, block_type, options, 
desired_replication_level,
+                                 best_known_dest,
+                                 next_hop_finger->trail_list[i].trail_id, 
+                                 &next_hop, 0, 1, &my_identity);
+       }
+    }
+    return;
+  }
+#endif
   GDS_NEIGHBOURS_send_get (key, block_type, options, desired_replication_level,
                            best_known_dest,intermediate_trail_id, 
&successor.next_hop,
                            0, 1, &my_identity);
@@ -3479,9 +3520,7 @@
   struct GNUNET_PeerIdentity closest_peer;
   struct FingerInfo *successor;
   unsigned int finger_table_index;
-  struct GNUNET_PeerIdentity *updated_trail;
-  int updated_finger_trail_length;
-
+  
   /* Get the finger_table_index corresponding to finger_value we got from 
network.*/
   finger_table_index = get_finger_table_index (finger_value, is_predecessor);
 
@@ -3592,8 +3631,8 @@
         add_new_trail (existing_finger, finger_trail,
                        finger_trail_length, finger_trail_id);
     else
-        select_and_replace_trail (existing_finger, updated_trail,
-                                  updated_finger_trail_length, 
finger_trail_id);
+        select_and_replace_trail (existing_finger, finger_trail,
+                                  finger_trail_length, finger_trail_id);
   }
   update_current_search_finger_index (finger_table_index);
   return;
@@ -3631,14 +3670,6 @@
   size_t payload_size;
   uint64_t key_value;
 
-#if ENABLE_MALICIOUS
-  if(1 == act_malicious)
-  {
-    DEBUG("I am malicious,dropping put request. \n");
-    return GNUNET_OK;
-  }
-#endif
-  
   msize = ntohs (message->size);
   if (msize < sizeof (struct PeerPutMessage))
   {
@@ -3657,7 +3688,14 @@
     GNUNET_break_op (0);
     return GNUNET_OK;
   }
-  
+  DEBUG("\n PUT_REQUEST_RECEVIED for key = %s, my_id = 
%s",GNUNET_h2s(&put->key),GNUNET_i2s(&my_identity));
+#if ENABLE_MALICIOUS
+  if(1 == act_malicious)
+  {
+    DEBUG("\n I AM MALICIOUS PUT_REQUEST_RECEVIED for key = %s, my_id = 
%s",GNUNET_h2s(&put->key),GNUNET_i2s(&my_identity));
+    return GNUNET_OK;
+  }
+#endif
   GNUNET_STATISTICS_update (GDS_stats,
                             gettext_noop
                             ("# Bytes received from other peers"), (int64_t) 
msize,
@@ -3784,13 +3822,56 @@
   }
   else
   {
-    GDS_NEIGHBOURS_send_put (&put->key,
-                             ntohl (put->block_type),ntohl (put->options),
-                             ntohl (put->desired_replication_level),
-                             best_known_dest, intermediate_trail_id, next_hop,
-                             hop_count, putlen, pp,
-                             GNUNET_TIME_absolute_ntoh (put->expiration_time),
-                             payload, payload_size);
+#if ENABLE_MALICIOUS
+  if (0 != GNUNET_CRYPTO_cmp_peer_identity (&successor.best_known_destination,
+                                            &successor.next_hop))
+  {
+    struct FingerInfo *next_hop_finger;
+    unsigned int i;
+    
+    next_hop_finger = &finger_table[successor.finger_table_index];
+    for (i = 0; i < next_hop_finger->trails_count; i++)
+    {
+      if (GNUNET_YES == next_hop_finger->trail_list[i].is_present)
+      {
+        if(0 == next_hop_finger->trail_list[i].trail_length)
+        {
+          DEBUG("\n PUT_REQUEST_RECEVIED for key = %s, next_hop = %s,TRAIL 
LENGTH IS 0",GNUNET_h2s(&put->key),GNUNET_i2s(next_hop));
+          GDS_NEIGHBOURS_send_put (&put->key,
+                                  ntohl (put->block_type),ntohl (put->options),
+                                  ntohl (put->desired_replication_level),
+                                  best_known_dest, intermediate_trail_id, 
next_hop,
+                                  hop_count, putlen, pp,
+                                  GNUNET_TIME_absolute_ntoh 
(put->expiration_time),
+                                  payload, payload_size);
+          return GNUNET_OK;
+        }
+        next_hop = &next_hop_finger->trail_list[i].trail_head->peer;
+        DEBUG("\n PUT_REQUEST = %s SENDING ACROSS TRAIL_ID = %s, next_hop = 
%s",
+               
GNUNET_h2s(&put->key),GNUNET_h2s(&next_hop_finger->trail_list[i].trail_id),
+               GNUNET_i2s(next_hop));
+        GDS_NEIGHBOURS_send_put (&put->key,
+                                 ntohl (put->block_type),ntohl (put->options),
+                                 ntohl (put->desired_replication_level),
+                                 best_known_dest,
+                                 next_hop_finger->trail_list[i].trail_id, 
+                                 next_hop, hop_count, putlen, pp,
+                                 GNUNET_TIME_absolute_ntoh 
(put->expiration_time),
+                                 payload, payload_size);
+       }
+    }
+    return GNUNET_OK;
+  }
+#endif
+  DEBUG("\n PUT_REQUEST = %s NOT SENDING ACROSS MULTIPLE TRAILS  next_hop = 
%s",
+          GNUNET_h2s(&put->key), GNUNET_i2s(next_hop));
+  GDS_NEIGHBOURS_send_put (&put->key,
+                           ntohl (put->block_type),ntohl (put->options),
+                           ntohl (put->desired_replication_level),
+                           best_known_dest, intermediate_trail_id, next_hop,
+                           hop_count, putlen, pp,
+                           GNUNET_TIME_absolute_ntoh (put->expiration_time),
+                           payload, payload_size);
    }
   return GNUNET_OK;
 }
@@ -3824,14 +3905,6 @@
   uint64_t key_value;
   uint32_t hop_count;
   size_t msize;
-
-#if ENABLE_MALICIOUS
-  if(1 == act_malicious)
-  {
-    DEBUG("I am malicious,dropping get request. \n");
-    return GNUNET_OK;
-  }
-#endif
   
   msize = ntohs (message->size);
   if (msize < sizeof (struct PeerGetMessage))
@@ -3842,12 +3915,6 @@
 
   get = (const struct PeerGetMessage *)message;
   get_length = ntohl (get->get_path_length);
-  current_best_known_dest = get->best_known_destination;
-  received_intermediate_trail_id = get->intermediate_trail_id;
-  get_path = (const struct GNUNET_PeerIdentity *)&get[1];
-  hop_count = get->hop_count;
-  hop_count++;
-  
   if ((msize <
        sizeof (struct PeerGetMessage) +
        get_length * sizeof (struct GNUNET_PeerIdentity)) ||
@@ -3858,6 +3925,20 @@
     return GNUNET_YES;
   }
   
+#if ENABLE_MALICIOUS
+  if(1 == act_malicious)
+  {
+    DEBUG("I am malicious,dropping get request. \n");
+    return GNUNET_OK;
+  }
+#endif
+  current_best_known_dest = get->best_known_destination;
+  received_intermediate_trail_id = get->intermediate_trail_id;
+  get_path = (const struct GNUNET_PeerIdentity *)&get[1];
+  hop_count = get->hop_count;
+  hop_count++;
+  
+ 
   GNUNET_STATISTICS_update (GDS_stats,
                             gettext_noop
                             ("# Bytes received from other peers"), msize,
@@ -3906,7 +3987,6 @@
     }
   }
  
-   
   /* I am the final destination. */
   if (0 == GNUNET_CRYPTO_cmp_peer_identity(&my_identity, &best_known_dest))
   {
@@ -3924,6 +4004,38 @@
   }
   else
   {
+        
+#if ENABLE_MALICIOUS
+  if (0 != GNUNET_CRYPTO_cmp_peer_identity (&successor.best_known_destination,
+                                            &successor.next_hop))
+  {
+    struct FingerInfo *next_hop_finger;
+    unsigned int i;
+    
+    next_hop_finger = &finger_table[successor.finger_table_index];
+    for (i = 0; i < next_hop_finger->trails_count; i++)
+    {
+      if(0 == next_hop_finger->trail_list[i].trail_length)
+      {
+        GDS_NEIGHBOURS_send_get (&(get->key), get->block_type, get->options,
+                                get->desired_replication_level, 
best_known_dest,
+                                intermediate_trail_id, next_hop, hop_count,
+                                get_length, gp);
+        return GNUNET_OK;
+      }
+      if (GNUNET_YES == next_hop_finger->trail_list[i].is_present)
+      {
+        next_hop = &next_hop_finger->trail_list[i].trail_head->peer;
+        GDS_NEIGHBOURS_send_get (&(get->key), get->block_type, get->options,
+                                 get->desired_replication_level, 
best_known_dest,
+                                 next_hop_finger->trail_list[i].trail_id, 
+                                 next_hop, hop_count,
+                                 get_length, gp);
+       }
+    }
+    return GNUNET_OK;
+  }
+#endif
     GDS_NEIGHBOURS_send_get (&(get->key), get->block_type, get->options,
                              get->desired_replication_level, best_known_dest,
                              intermediate_trail_id, next_hop, hop_count,
@@ -4926,7 +5038,6 @@
   struct GNUNET_PeerIdentity *trail_to_new_successor;
 
   /* Probable successor is  a friend */
-  /* SUPUS: Here should I worry about friend,*/
   if (NULL != GNUNET_CONTAINER_multipeermap_get (friend_peermap,
                                                  &probable_successor))
   {
@@ -5053,7 +5164,7 @@
       char *my_id_str;
       uint64_t succ;
       char *key;
-    
+     
       my_id_str = GNUNET_strdup (GNUNET_i2s_full (&my_identity));
       memcpy(&succ, &current_successor->finger_identity, sizeof(uint64_t));
       GNUNET_asprintf (&key, "XDHT:%s:", my_id_str);

Modified: gnunet/src/dht/gnunet-service-xdht_neighbours.h
===================================================================
--- gnunet/src/dht/gnunet-service-xdht_neighbours.h     2014-09-22 13:19:57 UTC 
(rev 34301)
+++ gnunet/src/dht/gnunet-service-xdht_neighbours.h     2014-09-22 15:12:15 UTC 
(rev 34302)
@@ -37,7 +37,7 @@
  * Set the ENABLE_MALICIOUS value to malicious.
  * @param malicious
  */
-void 
+int
 GDS_NEIGHBOURS_act_malicious (unsigned int malicious);
 #endif
 

Modified: gnunet/src/dht/gnunet_dht_profiler.c
===================================================================
--- gnunet/src/dht/gnunet_dht_profiler.c        2014-09-22 13:19:57 UTC (rev 
34301)
+++ gnunet/src/dht/gnunet_dht_profiler.c        2014-09-22 15:12:15 UTC (rev 
34302)
@@ -38,22 +38,21 @@
 /**
  * Number of peers which should perform a PUT out of 100 peers
  */
-#define PUT_PROBABILITY 20
+#define PUT_PROBABILITY 50
 
 #if ENABLE_MALICIOUS
 /**
  * Number of peers which should act as malicious peers
  */
-#define MALICIOUS_PROBABILITY 50
+#define MALICIOUS_PROBABILITY 20
 
-#endif
 /**
- * Percentage of peers that should act maliciously.
- * These peers will never start PUT/GET request.
- * n_active and n_malicious should not intersect.
+ * Context for a peer which should act maliciously. 
  */
-#define MALICIOUS_PEERS 0
+struct MaliciousContext;
+#endif
 
+
 /**
  * Configuration
  */
@@ -70,16 +69,10 @@
 struct ActiveContext;
 
 /**
- * Context for a peer which should act maliciously. 
- */
-struct MaliciousContext;
-
-/**
  * Context to hold data of peer
  */
 struct Context
 {
-
   /**
    * The testbed peer this context belongs to
    */
@@ -119,6 +112,11 @@
    * Handler to the DHT service
    */
   struct GNUNET_DHT_Handle *dht;
+  
+  /**
+   * Handler to malicious api
+   */
+  struct GNUNET_DHT_ActMaliciousHandle *dht_malicious;
 };
 
 /**
@@ -126,6 +124,32 @@
  */
 struct Context **malicious_peer_contexts = NULL;
 
+/**
+ * Context for a peer which should act maliciously.
+ */
+struct Malicious_Context
+{
+  /**
+   * The linked peer context
+   */
+  struct Context *ctx;
+
+  /**
+   * Handler to the DHT service
+   */
+  struct GNUNET_DHT_Handle *dht;
+};
+
+/**
+ * Array of malicious peers.
+ */
+static struct MaliciousContext *a_mc;
+
+/**
+ * Number or malicious peers.
+ */
+static unsigned int n_malicious;
+
 #endif
 
 /**
@@ -182,28 +206,9 @@
    * The number of peers currently doing GET on our data
    */
   uint16_t nrefs;
-  
-  /**
-   * If set this peer will act maliciously.
-   */
-  unsigned int malicious;
 };
 
-#if ENABLE_MALICIOUS
-struct Malicious_Context
-{
-  /**
-   * The linked peer context
-   */
-  struct Context *ctx;
 
-  /**
-   * Handler to the DHT service
-   */
-  struct GNUNET_DHT_Handle *dht;
-};
-#endif
-
 /**
  * An array of contexts.  The size of this array should be equal to @a 
num_peers
  */
@@ -214,14 +219,7 @@
  */
 static struct ActiveContext *a_ac;
 
-#if ENABLE_MALICIOUS
 /**
- * Array of malicious peers.
- */
-static struct MaliciousContext *a_mc;
-#endif
-
-/**
  * The delay between rounds for collecting statistics
  */
 static struct GNUNET_TIME_Relative delay_stats;
@@ -246,14 +244,7 @@
  */
 static unsigned int num_peers;
 
-#if ENABLE_MALICIOUS
 /**
- * Number or malicious peers.
- */
-static unsigned int n_malicious;
-#endif
-
-/**
  * Number of active peers
  */
 static unsigned int n_active;
@@ -411,6 +402,11 @@
 static int in_shutdown = 0;
 
 /**
+ * Total number of times to check if circle is formed or not.
+ */
+static unsigned int tries;
+
+/**
  * Task that collects successor statistics from all the peers. 
  * @param cls
  * @param tc
@@ -419,6 +415,12 @@
 collect_stats (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
 
 /**
+ * Connect to DHT services of active peers
+ */
+static void
+start_profiling();
+
+/**
  * Shutdown task.  Cleanup all resources and operations.
  *
  * @param cls NULL
@@ -823,18 +825,12 @@
 dht_connect (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
   n_dht++;
+  DEBUG("\n Inside dht_connect , n_dht = %u",n_dht);
   return GNUNET_DHT_connect (cfg, 10);
 }
 
 
 /**
- * Connect to DHT services of active peers
- */
-static void
-start_profiling();
-
-
-/**
  * Adapter function called to destroy a connection to
  * a service.
  *
@@ -872,7 +868,6 @@
   }
 }
 
-
 /**
  * Connect to DHT services of active peers
  */
@@ -881,7 +876,7 @@
 {
   struct Context *ctx;
   unsigned int i;
-
+   
   DEBUG("GNUNET_TESTBED_service_connect \n");
   GNUNET_break (GNUNET_YES != in_shutdown);
   for(i = 0; i < n_active; i++)
@@ -900,18 +895,157 @@
   }
 }
 
+#if ENABLE_MALICIOUS
+/**
+ * Count of total number of malicious peers.
+ */
+static unsigned int count_malicious;
+
+/**
+ * Continuation of GNUNET_DHT_act_malicious
+ * @param cls Malicious context
+  * @param success #GNUNET_OK if the ACT_MALICIOUS was transmitted,
+ *                 #GNUNET_NO on timeout,
+ *                 #GNUNET_SYSERR on disconnect from service
+ *                 after the ACT_MALICIOUS message was transmitted
+ *                 (so we don't know if it was received or not)
+ */
+static void
+act_malicious_cont (void *cls, int success)
+{
+  struct MaliciousContext *mc = cls;
+  struct Context *ctx = mc->ctx;
+  
+  GNUNET_TESTBED_operation_done (ctx->op);
+  ctx->op = NULL;
+  return;
+}
+
+
+/**
+ * Call malicious API for all the malicious peers.
+ * @param cls the malicious context.
+ * @param op the operation that has been finished
+ * @param ca_result the service handle returned from 
GNUNET_TESTBED_ConnectAdapter()
+ * @param emsg error message in case the operation has failed; will be NULL if
+ *          operation has executed successfully.
+ */
+void 
+dht_set_malicious(void *cls,
+                  struct GNUNET_TESTBED_Operation *op,
+                  void *ca_result,
+                  const char *emsg)
+{
+  struct MaliciousContext *mc = cls;
+  struct Context *ctx = mc->ctx;
+
+  GNUNET_assert (NULL != ctx);
+  GNUNET_assert (NULL != ctx->op);
+  GNUNET_assert (ctx->op == op);
+  mc->dht = (struct GNUNET_DHT_Handle *) ca_result;
+  if (NULL != emsg)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Connection to DHT service failed: 
%s\n", emsg);
+    GNUNET_TESTBED_operation_done (ctx->op); /* Calls 
dht_disconnect_malicious() */
+    ctx->op = NULL;
+    return;
+  }
+  mc->dht_malicious = GNUNET_DHT_act_malicious(mc->dht, 1, act_malicious_cont, 
mc);
+}
+
+
+/**
+ * Adapter function called to destroy a connection to
+ * a service.
+ *
+ * @param cls the active context
+ * @param op_result service handle returned from the connect adapter
+ */
+static void
+dht_disconnect_malicious (void *cls, void *op_result)
+{
+  struct MaliciousContext *mc = cls;
+  count_malicious++;
+  GNUNET_assert (NULL != mc->dht);
+  GNUNET_assert (mc->dht == op_result);
+  GNUNET_DHT_disconnect (mc->dht);
+  mc->dht = NULL;
+  mc->ctx->op = NULL;
+  n_dht--;
+
+  if (0 != n_dht)
+    return;
+ 
+  if(n_malicious == count_malicious)
+  {
+    DEBUG("\n Call start_profiling()");
+    start_profiling();
+  }
+}
+
+
+/**
+ * Set the malicious variable in peer malicious context.
+ */
+static void
+set_malicious()
+{
+  unsigned int i;
+  DEBUG ("Setting %u peers malicious",n_malicious);
+  
+  for(i = 0; i < n_malicious; i++)
+  {
+    DEBUG("\n Inside loop , i = %u",i);
+    struct MaliciousContext *mc = &a_mc[i];
+    mc->ctx->op =
+        GNUNET_TESTBED_service_connect (mc->ctx,
+                                        mc->ctx->peer,
+                                        "dht",
+                                        &dht_set_malicious, mc,
+                                        &dht_connect,
+                                        &dht_disconnect_malicious,
+                                        mc);
+  }
+}
+
+#endif
+
+
+/**
+ * Start collecting relevant statistics. If ENABLE_MALICIOUS set, first
+ * set the malicious peers. If not, then start with PUT operation on active
+ * peers.
+ */
+static void
+start_func()
+{
+#if ENABLE_MALICIOUS
+  set_malicious();
+  return;
+#endif   
+  start_profiling();
+}
+
+
+/**
+ * Remove entry from successor peer hashmap.
+ * @param cls closure
+ * @param key current public key
+ * @param value value in the hash map
+ * @return #GNUNET_YES if we should continue to iterate,
+ *         #GNUNET_NO if not.
+ */
 static int 
 hashmap_iterate_remove(void *cls, 
                        const struct GNUNET_HashCode *key, 
                        void *value)
 {
-  GNUNET_assert(GNUNET_YES == 
GNUNET_CONTAINER_multihashmap_remove(successor_peer_hashmap, key, value));
+  GNUNET_assert (GNUNET_YES == 
+                GNUNET_CONTAINER_multihashmap_remove(successor_peer_hashmap, 
key, value));
   return GNUNET_YES;
 }
 
 
-static unsigned int tries;
-
 /**
  * Stats callback. Iterate over the hashmap and check if all th peers form
  * a virtual ring topology.
@@ -931,20 +1065,21 @@
   struct GNUNET_HashCode *key;
   int count;
   
-  
   /* Don't schedule the task till we are looking for circle here. */
   successor_stats_task = GNUNET_SCHEDULER_NO_TASK;
   GNUNET_TESTBED_operation_done (successor_stats_op);
   successor_stats_op = NULL;
   if (0 == max_searches)
   {
-    start_profiling();
+    start_func(); 
     return;
   }
+
+  GNUNET_assert (NULL != start_key);
   start_val =
           (struct GNUNET_HashCode *) 
GNUNET_CONTAINER_multihashmap_get(successor_peer_hashmap,
                                                 start_key);
-
+  
   val = start_val;
   for (count = 0; count < num_peers; count++)
   {
@@ -977,16 +1112,13 @@
   
   successor_peer_hashmap = GNUNET_CONTAINER_multihashmap_create (num_peers, 
                                                                  GNUNET_NO);
-  //TODO:Check if comparison is correct. 
   if ((start_val == val) && (count == num_peers))
   {
     DEBUG("CIRCLE COMPLETED after %u tries", tries);
-    //FIXME: FREE HASHMAP.
-    //FIXME: If circle is done, then check that finger table of all the peers
-    //are fill atleast O(log N) and then start with the experiments.
     if(GNUNET_SCHEDULER_NO_TASK == successor_stats_task)
-      start_profiling();
-    
+    {
+      start_func();
+    }
     return;
   }
   else
@@ -995,7 +1127,7 @@
     {
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                   "Maximum tries %u exceeded while checking successor TOTAL 
TRIES %u"
-                  " cirle formation.  Exiting\n",
+                  " circle formation.  Exiting\n",
                   max_searches,tries);
       if (GNUNET_SCHEDULER_NO_TASK != successor_stats_task)
       {
@@ -1003,7 +1135,7 @@
       }
       if(GNUNET_SCHEDULER_NO_TASK == successor_stats_task)
       {
-        start_profiling();
+        start_func();
       }
       
       return;
@@ -1039,7 +1171,7 @@
   static const char *key_string = "XDHT";
   if (0 == max_searches)
     return GNUNET_OK;
-  
+
   if (0 == strncmp (key_string, name, strlen (key_string)))
   {
     char *my_id_str;
@@ -1062,18 +1194,19 @@
    
     succ_key = GNUNET_new(struct GNUNET_HashCode);
     GNUNET_CRYPTO_hash (truncated_successor_str, 
sizeof(truncated_successor_str),succ_key);
-    
+
     if (0 == flag)
     {
+      GNUNET_assert(NULL != my_id_key);
       start_key = my_id_key;
+      GNUNET_assert(NULL != start_key);
       flag = 1;
     }
-    /* FIXME: GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE do not free the value
-     which is replaced, need to free it. */
     GNUNET_CONTAINER_multihashmap_put (successor_peer_hashmap,
                                        my_id_key, (void *)succ_key,
                                        
GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
   }
+
   return GNUNET_OK;
 }
 
@@ -1106,34 +1239,7 @@
 }
 
 
-#if ENABLE_MALICIOUS
-#if 0
 /**
- * Set the malicious variable in peer malicious context.
- */
-static void
-set_malicious()
-{
-  unsigned int i;
-  DEBUG ("Setting %u peers malicious");
-  for(i = 0; i < n_malicious; i++)
-  {
-    struct MaliciousContext *mc = &a_mc[i];
-    mc->ctx->op =
-        GNUNET_TESTBED_service_connect (ac->ctx,
-                                        ac->ctx->peer,
-                                        "dht",
-                                        &dht_set_malicious, mc,
-                                        &dht_connect,
-                                        &dht_finish,
-                                        mc);
-  }
-}
-#endif
-#endif
-
-
-/**
  * Callback called when DHT service on the peer is started
  *
  * @param cls the context
@@ -1156,14 +1262,11 @@
   DEBUG("Peers Started = %d; num_peers = %d \n", peers_started, num_peers);
   if (GNUNET_SCHEDULER_NO_TASK == successor_stats_task && peers_started == 
num_peers)
   {
-#if ENABLE_MALICIOUS
-    //set_malicious();
-#endif
-    
      DEBUG("successor_stats_task \n");
      struct Collect_Stat_Context *collect_stat_cls = GNUNET_new(struct 
Collect_Stat_Context);
      collect_stat_cls->service_connect_ctx = cls;
      collect_stat_cls->op = op;
+ 
      successor_stats_task = GNUNET_SCHEDULER_add_delayed (delay_stats,
                                                           &collect_stats,
                                                           collect_stat_cls);
@@ -1215,7 +1318,7 @@
   
 #if ENABLE_MALICIOUS
 
-  if(PUT_PROBABILITY + MALICIOUS_PEERS > 100)
+  if(PUT_PROBABILITY + MALICIOUS_PROBABILITY > 100)
   {
     DEBUG ("Reduce either number of malicious peer or active peers. ");
     GNUNET_SCHEDULER_shutdown ();
@@ -1224,23 +1327,21 @@
   }
   
   /* Select the peers which should act maliciously. */
-  n_malicious = num_peers * MALICIOUS_PEERS / 100;
+  n_malicious = num_peers * MALICIOUS_PROBABILITY / 100;
   
-  /* Select n_malicious peers and ensure that those are not active peers. 
-     keep all malicious peer at one place, and call act malicious for all
-     those peers. */
   a_mc = GNUNET_malloc (n_malicious * sizeof (struct MaliciousContext));
   malicious_peers = 0;
   
-  for (cnt = 0; cnt < num_peers && ac_cnt < n_active; cnt++)
+  for (cnt = 0; cnt < num_peers && malicious_peers < n_malicious; cnt++)
   {
     if (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100) >=
         MALICIOUS_PROBABILITY)
       continue;
-    a_ac[ac_cnt].malicious = 1;
-    a_mc[ac_cnt].ctx = &a_ctx[cnt];
+    a_ctx[cnt].mc = &a_mc[malicious_peers];
+    a_mc[malicious_peers].ctx = &a_ctx[cnt];
     malicious_peers++;
   } 
+  n_malicious = malicious_peers;
   INFO ("Malicious Peers: %u\n",malicious_peers);
   
 #endif
@@ -1250,7 +1351,7 @@
   for (cnt = 0; cnt < num_peers && ac_cnt < n_active; cnt++)
   {
     if ((GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100) >=
-        PUT_PROBABILITY) || (a_ac[ac_cnt].malicious == 1))
+        PUT_PROBABILITY) || (a_ctx[ac_cnt].mc != NULL))
       continue;
     
     a_ctx[cnt].ac = &a_ac[ac_cnt];

Modified: gnunet/src/include/gnunet_dht_service.h
===================================================================
--- gnunet/src/include/gnunet_dht_service.h     2014-09-22 13:19:57 UTC (rev 
34301)
+++ gnunet/src/include/gnunet_dht_service.h     2014-09-22 15:12:15 UTC (rev 
34302)
@@ -393,14 +393,31 @@
 
 #if ENABLE_MALICIOUS
 /**
- * Turn the DHT service to act malicious depending on @a flag
+ * Type of a Malicious continuation.  You must not call
+ * #GNUNET_DHT_disconnect in this continuation.
  *
+ * @param cls closure
+ * @param success #GNUNET_OK if the set malicious request was transmitted,
+ *                #GNUNET_NO on timeout,
+ *                #GNUNET_SYSERR on disconnect from service
+ *                after the PUT message was transmitted
+ *                (so we don't know if it was received or not)
+ */
+typedef void (*GNUNET_DHT_ActMaliciousContinuation)(void *cls,
+                                                int success);
+
+/**
+ * Turn the DHT service to act malicious
+ *
  * @param handle the DHT handle
  * @param action 1 to make the service malicious; 0 to make it benign
           FIXME: perhaps make this an enum of known malicious behaviors?
  */
-void
-GNUNET_DHT_malicious (struct GNUNET_DHT_Handle *handle, unsigned int action);
+struct GNUNET_DHT_ActMaliciousHandle *
+GNUNET_DHT_act_malicious (struct GNUNET_DHT_Handle *handle, 
+                      unsigned int action, 
+                      GNUNET_DHT_PutContinuation cont,
+                      void *cont_cls);
 #endif
 
 

Modified: gnunet/src/include/gnunet_protocols.h
===================================================================
--- gnunet/src/include/gnunet_protocols.h       2014-09-22 13:19:57 UTC (rev 
34301)
+++ gnunet/src/include/gnunet_protocols.h       2014-09-22 15:12:15 UTC (rev 
34302)
@@ -2593,22 +2593,28 @@
  */
 #define GNUNET_MESSAGE_TYPE_XDHT_P2P_GET 891
 
+/**
+ * Send back peer that considers you are its successor, a confirmation
+ * that you got the notify successor message. 
+ */
+#define GNUNET_MESSAGE_TYPE_XDHT_P2P_NOTIFY_SUCCESSOR_CONFIRMATION 892
+
 #if ENABLE_MALICIOUS
 /**
  * Turn X-VINE DHT service malicious
  */
-#define GNUNET_MESSAGE_TYPE_DHT_ACT_MALICIOUS 892
-#endif
+#define GNUNET_MESSAGE_TYPE_DHT_ACT_MALICIOUS 893
 
 /**
- * Send back peer that considers you are its successor, a confirmation
- * that you got the notify successor message. 
+ * Acknowledge receiving ACT MALICIOUS request
  */
-#define GNUNET_MESSAGE_TYPE_XDHT_P2P_NOTIFY_SUCCESSOR_CONFIRMATION 893
+#define GNUNET_MESSAGE_TYPE_DHT_CLIENT_ACT_MALICIOUS_OK  894
+
+#endif
 
/*******************************************************************************/
 
 /**
- * Next available: 903
+ * Next available: 904
  */
 
 /**




reply via email to

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