- Act malicious API complete
[oweals/gnunet.git] / src / dht / gnunet-service-xdht_clients.c
index b9cfd6dda8abdd0b503376946241a7f685d153cf..3ddb62be12e976fa8bf909a16825bfc9fa2b4f17 100644 (file)
 
 #define LOG(kind,...) GNUNET_log_from (kind, "dht-clients",__VA_ARGS__)
 
-#if ENABLE_MALICIOUS
-/**
- * Should this peer act malicious?
- */
-extern unsigned int malicious;
-#endif
+#define DEBUG(...)                                           \
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
 
 /**
  * Linked list of messages to send to clients.
@@ -491,21 +487,24 @@ forward_reply (void *cls, const struct GNUNET_HashCode * key, void *value)
   int do_free;
   struct GNUNET_HashCode ch;
   unsigned int i;
-
   LOG_TRAFFIC (GNUNET_ERROR_TYPE_DEBUG,
-              "R5N CLIENT-RESULT %s\n",
+              "XVINE CLIENT-RESULT %s\n",
                GNUNET_h2s_full (key));
+#if 0
   if ((record->type != GNUNET_BLOCK_TYPE_ANY) && (record->type != frc->type))
   {
     LOG (GNUNET_ERROR_TYPE_DEBUG,
          "Record type missmatch, not passing request for key %s to local client\n",
          GNUNET_h2s (key));
+
     GNUNET_STATISTICS_update (GDS_stats,
                               gettext_noop
                               ("# Key match, type mismatches in REPLY to CLIENT"),
                               1, GNUNET_NO);
     return GNUNET_YES;          /* type mismatch */
   }
+#endif
   GNUNET_CRYPTO_hash (frc->data, frc->data_size, &ch);
   for (i = 0; i < record->seen_replies_count; i++)
     if (0 == memcmp (&record->seen_replies[i], &ch, sizeof (struct GNUNET_HashCode)))
@@ -642,6 +641,7 @@ GDS_CLIENTS_handle_reply (struct GNUNET_TIME_Absolute expiration,
                 _("Could not pass reply to client, message too big!\n"));
     return;
   }
+  DEBUG("reply FOR DATA_SIZE = %lu\n",msize);
   pm = GNUNET_malloc (msize + sizeof (struct PendingMessage));
   reply = (struct GNUNET_DHT_ClientResultMessage *) &pm[1];
   pm->msg = &reply->header;
@@ -666,7 +666,6 @@ GDS_CLIENTS_handle_reply (struct GNUNET_TIME_Absolute expiration,
   frc.type = type;
   GNUNET_CONTAINER_multihashmap_get_multiple (forward_map, key, &forward_reply,
                                               &frc);
-
   if (GNUNET_NO == frc.do_copy)
   {
     /* did not match any of the requests, free! */
@@ -850,9 +849,9 @@ transmit_request (struct ClientQueryRecord *cqr)
        GNUNET_h2s (&cqr->key),
        cqr->replication,
        cqr->seen_replies_count);
-  GDS_NEIGHBOURS_send_get (&cqr->key, cqr->type, cqr->msg_options, 
-                           cqr->replication, NULL, NULL , NULL,
-                           0, 0, NULL);
+  
+  GDS_NEIGHBOURS_handle_get (&cqr->key, cqr->type, cqr->msg_options, 
+                              cqr->replication);
   
   /* exponential back-off for retries.
    * max GNUNET_TIME_STD_EXPONENTIAL_BACKOFF_THRESHOLD (15 min) */
@@ -936,39 +935,19 @@ handle_dht_local_put (void *cls, struct GNUNET_SERVER_Client *client,
        "Handling local PUT of %u-bytes for query %s\n",
        size - sizeof (struct GNUNET_DHT_ClientPutMessage),
        GNUNET_h2s (&put_msg->key));
-  
+  DEBUG("PUT doing put i = %s\n",GNUNET_h2s(&(put_msg->key)));
   GDS_CLIENTS_handle_reply (GNUNET_TIME_absolute_ntoh (put_msg->expiration),
                             &put_msg->key, 0, NULL, 0, NULL,
                             ntohl (put_msg->type),
                             size - sizeof (struct GNUNET_DHT_ClientPutMessage),
                             &put_msg[1]);
-  /* FIXME: Should we store locally? */
-  GDS_DATACACHE_handle_put (GNUNET_TIME_absolute_ntoh (put_msg->expiration),
-                            &put_msg->key, 0, NULL, ntohl (put_msg->type),
-                            size - sizeof (struct GNUNET_DHT_ClientPutMessage),
-                            &put_msg[1]);
  
-  struct GNUNET_PeerIdentity my_identity =  GDS_NEIGHBOURS_get_my_id();
-  GDS_NEIGHBOURS_send_put (&put_msg->key, 
-                           ntohl (put_msg->type), ntohl (put_msg->options),
-                           ntohl (put_msg->desired_replication_level), NULL,
-                           NULL, NULL, 0, 0, NULL,
-                           GNUNET_TIME_absolute_ntoh (put_msg->expiration),
-                           &put_msg[1],
-                           size - sizeof (struct GNUNET_DHT_ClientPutMessage));
-  
-
-  GDS_CLIENTS_process_put (ntohl (put_msg->options),
-                           ntohl (put_msg->type),
-                           0,
-                           ntohl (put_msg->desired_replication_level),
-                           1,
-                           &my_identity,
-                           GNUNET_TIME_absolute_ntoh (put_msg->expiration),
-                           &put_msg->key,
-                           &put_msg[1],
-                           size - sizeof (struct GNUNET_DHT_ClientPutMessage));
-  
+  GDS_NEIGHBOURS_handle_put (&put_msg->key, 
+                              ntohl (put_msg->type), ntohl (put_msg->options),
+                              ntohl (put_msg->desired_replication_level),
+                              GNUNET_TIME_absolute_ntoh (put_msg->expiration),
+                              &put_msg[1],
+                              size - sizeof (struct GNUNET_DHT_ClientPutMessage));
   pm = GNUNET_malloc (sizeof (struct PendingMessage) +
                      sizeof (struct GNUNET_DHT_ClientPutConfirmationMessage));
   conf = (struct GNUNET_DHT_ClientPutConfirmationMessage *) &pm[1];
@@ -1034,6 +1013,7 @@ handle_dht_local_get (void *cls, struct GNUNET_SERVER_Client *client,
   cqr->replication = ntohl (get->desired_replication_level);
   cqr->msg_options = ntohl (get->options);
   cqr->type = ntohl (get->type);
+  
   // FIXME use cqr->key, set multihashmap create to GNUNET_YES
   GNUNET_CONTAINER_multihashmap_put (forward_map, &get->key, cqr,
                                      GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
@@ -1311,7 +1291,7 @@ handle_dht_local_monitor_stop (void *cls, struct GNUNET_SERVER_Client *client,
 
 #if ENABLE_MALICIOUS
 /**
- * Handler for monitor stop messages
+ * Handler for act malicious message.
  *
  * @param cls closure for the service
  * @param client the client we received this message from
@@ -1322,8 +1302,25 @@ static void
 handle_dht_act_malicious (void *cls, struct GNUNET_SERVER_Client *client,
                           const struct GNUNET_MessageHeader *message)
 {
-  /* FIXME: parse message and set malicious */
-  malicious = 1;
+  const struct GNUNET_DHT_ActMaliciousMessage *msg;
+  struct PendingMessage *pm;
+  struct GNUNET_DHT_ClientActMaliciousConfirmationMessage *conf;
+  unsigned int malicious_action;
+
+  msg = (const struct GNUNET_DHT_ActMaliciousMessage *)message;
+  malicious_action = msg->action;
+  
+  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