- update default values, eliminate obsolete ones
[oweals/gnunet.git] / src / dht / gnunet-service-xdht_clients.c
index 17c95cc4c3c3b12454a8d80b02ae0601017012df..59fbd6f17b43f74d7ad31e7dd2762bd41b5b1e9d 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
+
 /**
  * Linked list of messages to send to clients.
  */
@@ -844,13 +851,10 @@ transmit_request (struct ClientQueryRecord *cqr)
        cqr->replication,
        cqr->seen_replies_count);
 
-  /* FIXME: Here I am passing NULL for parameters check if its correct or 
-   not. */
-#if 0
-  GDS_NEIGHBOURS_handle_get (cqr->type, cqr->msg_options, cqr->replication,
-                             0 /* hop count */ ,NULL, NULL, 0, 
-                             &cqr->key, NULL, NULL, 0);
-#endif
+  GDS_NEIGHBOURS_send_get (&cqr->key, cqr->type, cqr->msg_options, 
+                           cqr->replication, NULL, NULL , NULL,
+                           0, 0, NULL);
+  
   /* exponential back-off for retries.
    * max GNUNET_TIME_STD_EXPONENTIAL_BACKOFF_THRESHOLD (15 min) */
   cqr->retry_frequency = GNUNET_TIME_STD_BACKOFF (cqr->retry_frequency);
@@ -913,7 +917,7 @@ handle_dht_local_put (void *cls, struct GNUNET_SERVER_Client *client,
   struct PendingMessage *pm;
   struct GNUNET_DHT_ClientPutConfirmationMessage *conf;
   uint16_t size;
-  
+
   size = ntohs (message->size);
   if (size < sizeof (struct GNUNET_DHT_ClientPutMessage))
   {
@@ -926,7 +930,7 @@ handle_dht_local_put (void *cls, struct GNUNET_SERVER_Client *client,
                             ("# PUT requests received from clients"), 1,
                             GNUNET_NO);
   put_msg = (const struct GNUNET_DHT_ClientPutMessage *) message;
-  LOG_TRAFFIC (GNUNET_ERROR_TYPE_DEBUG, "R5N CLIENT-PUT %s\n",
+  LOG_TRAFFIC (GNUNET_ERROR_TYPE_DEBUG, "X-VINE DHT CLIENT-PUT %s\n",
                GNUNET_h2s_full (&put_msg->key));
   /* give to local clients */
   LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -944,24 +948,23 @@ handle_dht_local_put (void *cls, struct GNUNET_SERVER_Client *client,
                             &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));
   
-  /* FIXME: Is it correct to pass NULL for current destination and current
-   source. */
-  GDS_NEIGHBOURS_handle_put (ntohl (put_msg->type), ntohl (put_msg->options),
-                             ntohl (put_msg->desired_replication_level),
-                             GNUNET_TIME_absolute_ntoh (put_msg->expiration),
-                             0 /* hop count */ ,
-                             &put_msg->key, 0, NULL, &put_msg[1],
-                             size -
-                             sizeof (struct GNUNET_DHT_ClientPutMessage),
-                             NULL, NULL, 0, NULL);
-  
+
   GDS_CLIENTS_process_put (ntohl (put_msg->options),
                            ntohl (put_msg->type),
                            0,
                            ntohl (put_msg->desired_replication_level),
                            1,
-                           GDS_NEIGHBOURS_get_id(),
+                           &my_identity,
                            GNUNET_TIME_absolute_ntoh (put_msg->expiration),
                            &put_msg->key,
                            &put_msg[1],
@@ -1015,7 +1018,7 @@ handle_dht_local_get (void *cls, struct GNUNET_SERVER_Client *client,
        "Received GET request for %s from local client %p, xq: %.*s\n",
        GNUNET_h2s (&get->key), client, xquery_size, xquery);
 
-  LOG_TRAFFIC (GNUNET_ERROR_TYPE_DEBUG, "R5N CLIENT-GET %s\n",
+  LOG_TRAFFIC (GNUNET_ERROR_TYPE_DEBUG, "X-VINE CLIENT-GET %s\n",
                GNUNET_h2s_full (&get->key));
 
 
@@ -1035,23 +1038,20 @@ handle_dht_local_get (void *cls, struct GNUNET_SERVER_Client *client,
   // FIXME use cqr->key, set multihashmap create to GNUNET_YES
   GNUNET_CONTAINER_multihashmap_put (forward_map, &get->key, cqr,
                                      GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
+  
+  struct GNUNET_PeerIdentity my_identity;
+  my_identity = GDS_NEIGHBOURS_get_my_id();
   GDS_CLIENTS_process_get (ntohl (get->options),
                            ntohl (get->type),
                            0,
                            ntohl (get->desired_replication_level),
                            1,
-                           GDS_NEIGHBOURS_get_id(),
+                           &my_identity,
                            &get->key);
   /* start remote requests */
   if (GNUNET_SCHEDULER_NO_TASK != retry_task)
     GNUNET_SCHEDULER_cancel (retry_task);
   retry_task = GNUNET_SCHEDULER_add_now (&transmit_next_request_task, NULL);
-  /* perform local lookup 
-   * FIXME: Should we call it here or in neighbours file. And how to handle
-   * this case where we may get the data locally. You really need to rethink
-   * this design again. 
-  GDS_DATACACHE_handle_get (&get->key, cqr->type, cqr->xquery, xquery_size,
-                            NULL, 0); */
   GNUNET_SERVER_receive_done (client, GNUNET_OK);
 }
 
@@ -1310,6 +1310,25 @@ handle_dht_local_monitor_stop (void *cls, struct GNUNET_SERVER_Client *client,
 }
 
 
+#if ENABLE_MALICIOUS
+/**
+ * Handler for monitor stop messages
+ *
+ * @param cls closure for the service
+ * @param client the client we received this message from
+ * @param message the actual message received
+ *
+ */
+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;
+}
+#endif
+
+
 /**
  * Functions with this signature are called whenever a client
  * is disconnected on the network level.
@@ -1385,6 +1404,11 @@ GDS_CLIENTS_init (struct GNUNET_SERVER_Handle *server)
      sizeof (struct GNUNET_DHT_MonitorStartStopMessage)},
     {&handle_dht_local_get_result_seen, NULL,
      GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_RESULTS_KNOWN, 0},
+    #if ENABLE_MALICIOUS
+    {&handle_dht_act_malicious, NULL,
+     GNUNET_MESSAGE_TYPE_DHT_ACT_MALICIOUS,
+     sizeof (struct GNUNET_DHT_ActMaliciousMessage)},
+    #endif
     {NULL, NULL, 0, 0}
   };
   forward_map = GNUNET_CONTAINER_multihashmap_create (1024, GNUNET_NO);