[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r12511 - gnunet/src/dht
From: |
gnunet |
Subject: |
[GNUnet-SVN] r12511 - gnunet/src/dht |
Date: |
Tue, 10 Aug 2010 18:24:53 +0200 |
Author: nevans
Date: 2010-08-10 18:24:53 +0200 (Tue, 10 Aug 2010)
New Revision: 12511
Modified:
gnunet/src/dht/dht.h
gnunet/src/dht/dht_api.c
gnunet/src/dht/gnunet-dht-driver.c
gnunet/src/dht/gnunet-service-dht.c
gnunet/src/dht/test_dht_api.c
Log:
api change to allow client to set DHT malicious, still need to implement it on
the dht driver side
Modified: gnunet/src/dht/dht.h
===================================================================
--- gnunet/src/dht/dht.h 2010-08-10 15:23:21 UTC (rev 12510)
+++ gnunet/src/dht/dht.h 2010-08-10 16:24:53 UTC (rev 12511)
@@ -61,7 +61,24 @@
typedef void (*GNUNET_DHT_MessageReceivedHandler) (void *cls,
const struct
GNUNET_MessageHeader
*msg);
+struct GNUNET_DHT_ControlMessage
+{
+ /**
+ * Type: GNUNET_MESSAGE_TYPE_DHT_CONTROL
+ */
+ struct GNUNET_MessageHeader header;
+ /**
+ * Command code of the message.
+ */
+ uint16_t command;
+
+ /**
+ * Variable parameter for the command.
+ */
+ uint16_t variable;
+};
+
/**
* Message which indicates the DHT should cancel outstanding
* requests and discard any state.
Modified: gnunet/src/dht/dht_api.c
===================================================================
--- gnunet/src/dht/dht_api.c 2010-08-10 15:23:21 UTC (rev 12510)
+++ gnunet/src/dht/dht_api.c 2010-08-10 16:24:53 UTC (rev 12511)
@@ -825,9 +825,150 @@
}
/**
- * Perform an asynchronous FIND_PEER operation on the DHT.
+ * Send a message to the DHT telling it to start issuing random GET
+ * requests every 'frequency' milliseconds.
*
* @param handle handle to the DHT service
+ * @param frequency delay (in milliseconds) between sending malicious messages
+ * @param cont continuation to call once the message is sent
+ * @param cont_cls closure for continuation
+ *
+ * @return GNUNET_YES if the control message was sent, GNUNET_NO if not
+ */
+int GNUNET_DHT_set_malicious_getter (struct GNUNET_DHT_Handle *handle, int
frequency, GNUNET_SCHEDULER_Task cont, void *cont_cls)
+{
+ struct GNUNET_DHT_ControlMessage *msg;
+ struct PendingMessage *pending;
+
+ if ((handle->current != NULL) && (handle->retransmit_stage !=
DHT_RETRANSMITTING))
+ return GNUNET_NO;
+
+ msg = GNUNET_malloc(sizeof(struct GNUNET_DHT_ControlMessage));
+ msg->header.size = htons(sizeof(struct GNUNET_DHT_ControlMessage));
+ msg->header.type = htons(GNUNET_MESSAGE_TYPE_DHT_CONTROL);
+ msg->command = htons(GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_GET);
+ msg->variable = htons(frequency);
+
+ pending = GNUNET_malloc (sizeof (struct PendingMessage));
+ pending->msg = &msg->header;
+ pending->timeout = GNUNET_TIME_relative_get_forever();
+ pending->free_on_send = GNUNET_YES;
+ pending->cont = cont;
+ pending->cont_cls = cont_cls;
+ pending->unique_id = 0;
+
+ if (handle->current == NULL)
+ {
+ handle->current = pending;
+ process_pending_message (handle);
+ }
+ else
+ {
+ handle->retransmit_stage = DHT_RETRANSMITTING_MESSAGE_QUEUED;
+ handle->retransmission_buffer = pending;
+ }
+
+ return GNUNET_YES;
+}
+
+/**
+ * Send a message to the DHT telling it to start issuing random PUT
+ * requests every 'frequency' milliseconds.
+ *
+ * @param handle handle to the DHT service
+ * @param frequency delay (in milliseconds) between sending malicious messages
+ * @param cont continuation to call once the message is sent
+ * @param cont_cls closure for continuation
+ *
+ * @return GNUNET_YES if the control message was sent, GNUNET_NO if not
+ */
+int GNUNET_DHT_set_malicious_putter (struct GNUNET_DHT_Handle *handle, int
frequency, GNUNET_SCHEDULER_Task cont, void *cont_cls)
+{
+ struct GNUNET_DHT_ControlMessage *msg;
+ struct PendingMessage *pending;
+
+ if ((handle->current != NULL) && (handle->retransmit_stage !=
DHT_RETRANSMITTING))
+ return GNUNET_NO;
+
+ msg = GNUNET_malloc(sizeof(struct GNUNET_DHT_ControlMessage));
+ msg->header.size = htons(sizeof(struct GNUNET_DHT_ControlMessage));
+ msg->header.type = htons(GNUNET_MESSAGE_TYPE_DHT_CONTROL);
+ msg->command = htons(GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_PUT);
+ msg->variable = htons(frequency);
+
+ pending = GNUNET_malloc (sizeof (struct PendingMessage));
+ pending->msg = &msg->header;
+ pending->timeout = GNUNET_TIME_relative_get_forever();
+ pending->free_on_send = GNUNET_YES;
+ pending->cont = cont;
+ pending->cont_cls = cont_cls;
+ pending->unique_id = 0;
+
+ if (handle->current == NULL)
+ {
+ handle->current = pending;
+ process_pending_message (handle);
+ }
+ else
+ {
+ handle->retransmit_stage = DHT_RETRANSMITTING_MESSAGE_QUEUED;
+ handle->retransmission_buffer = pending;
+ }
+
+ return GNUNET_YES;
+}
+
+/**
+ * Send a message to the DHT telling it to start dropping
+ * all requests received.
+ *
+ * @param handle handle to the DHT service
+ * @param cont continuation to call once the message is sent
+ * @param cont_cls closure for continuation
+ *
+ * @return GNUNET_YES if the control message was sent, GNUNET_NO if not
+ */
+int GNUNET_DHT_set_malicious_dropper (struct GNUNET_DHT_Handle *handle,
GNUNET_SCHEDULER_Task cont, void *cont_cls)
+{
+ struct GNUNET_DHT_ControlMessage *msg;
+ struct PendingMessage *pending;
+
+ if ((handle->current != NULL) && (handle->retransmit_stage !=
DHT_RETRANSMITTING))
+ return GNUNET_NO;
+
+ msg = GNUNET_malloc(sizeof(struct GNUNET_DHT_ControlMessage));
+ msg->header.size = htons(sizeof(struct GNUNET_DHT_ControlMessage));
+ msg->header.type = htons(GNUNET_MESSAGE_TYPE_DHT_CONTROL);
+ msg->command = htons(GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_DROP);
+ msg->variable = htons(0);
+
+ pending = GNUNET_malloc (sizeof (struct PendingMessage));
+ pending->msg = &msg->header;
+ pending->timeout = GNUNET_TIME_relative_get_forever();
+ pending->free_on_send = GNUNET_YES;
+ pending->cont = cont;
+ pending->cont_cls = cont_cls;
+ pending->unique_id = 0;
+
+ if (handle->current == NULL)
+ {
+ handle->current = pending;
+ process_pending_message (handle);
+ }
+ else
+ {
+ handle->retransmit_stage = DHT_RETRANSMITTING_MESSAGE_QUEUED;
+ handle->retransmission_buffer = pending;
+ }
+
+ return GNUNET_YES;
+}
+
+
+/**
+ * Initiate a generic DHT route operation.
+ *
+ * @param handle handle to the DHT service
* @param key the key to look up
* @param desired_replication_level how many peers should ultimately receive
* this message (advisory only, target may be too high for the
Modified: gnunet/src/dht/gnunet-dht-driver.c
===================================================================
--- gnunet/src/dht/gnunet-dht-driver.c 2010-08-10 15:23:21 UTC (rev 12510)
+++ gnunet/src/dht/gnunet-dht-driver.c 2010-08-10 16:24:53 UTC (rev 12511)
@@ -583,7 +583,7 @@
int is_persistent)
{
struct StatisticsIteratorContext *stats_ctx;
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s:%s:%s -- %llu\n",
GNUNET_i2s(peer), subsystem, name, value);
+
if (GNUNET_CONTAINER_multihashmap_contains(stats_map, &peer->hashPubKey))
{
stats_ctx = GNUNET_CONTAINER_multihashmap_get(stats_map,
&peer->hashPubKey);
Modified: gnunet/src/dht/gnunet-service-dht.c
===================================================================
--- gnunet/src/dht/gnunet-service-dht.c 2010-08-10 15:23:21 UTC (rev 12510)
+++ gnunet/src/dht/gnunet-service-dht.c 2010-08-10 16:24:53 UTC (rev 12511)
@@ -2402,6 +2402,30 @@
}
/**
+ * Task to send a malicious put message across the network.
+ *
+ * @param cls closure for this task
+ * @param tc the context under which the task is running
+ */
+static void
+malicious_put_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ return;
+}
+
+/**
+ * Task to send a malicious put message across the network.
+ *
+ * @param cls closure for this task
+ * @param tc the context under which the task is running
+ */
+static void
+malicious_get_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ return;
+}
+
+/**
* Task to send a find peer message for our own peer identifier
* so that we can find the closest peers in the network to ourselves
* and attempt to connect to them.
@@ -2500,6 +2524,56 @@
}
/**
+ * Handler for any locally received DHT control messages,
+ * sets malicious flags mostly for now.
+ *
+ * @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_control_message (void *cls, struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
+{
+ const struct GNUNET_DHT_ControlMessage *dht_control_msg =
+ (const struct GNUNET_DHT_ControlMessage *) message;
+#if DEBUG_DHT
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "`%s:%s': Received `%s' request from client, command %d\n",
my_short_id, "DHT",
+ "CONTROL", ntohs(dht_control_msg->command));
+#endif
+
+ switch (ntohs(dht_control_msg->command))
+ {
+ case GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_GET:
+ if (ntohs(dht_control_msg->variable) > 0)
+ malicious_get_frequency = ntohs(dht_control_msg->variable);
+ if (malicious_getter != GNUNET_YES)
+ GNUNET_SCHEDULER_add_now(sched, &malicious_get_task, NULL);
+ malicious_getter = GNUNET_YES;
+ GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s:%s Initiating malicious GET
behavior, frequency %d\n", my_short_id, "DHT", malicious_get_frequency);
+ break;
+ case GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_PUT:
+ if (ntohs(dht_control_msg->variable) > 0)
+ malicious_put_frequency = ntohs(dht_control_msg->variable);
+ if (malicious_putter != GNUNET_YES)
+ GNUNET_SCHEDULER_add_now(sched, &malicious_put_task, NULL);
+ malicious_putter = GNUNET_YES;
+ GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s:%s Initiating malicious PUT
behavior, frequency %d\n", my_short_id, "DHT", malicious_put_frequency);
+ break;
+ case GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_DROP:
+ malicious_dropper = GNUNET_YES;
+ GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s:%s Initiating malicious DROP
behavior\n", my_short_id, "DHT");
+ break;
+ default:
+ GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s:%s Unknown control command type
`%d'!\n", ntohs(dht_control_msg->command));
+ }
+
+ GNUNET_SERVER_receive_done (client, GNUNET_OK);
+}
+
+/**
* Handler for any generic DHT stop messages, calls the appropriate handler
* depending on message type (if processed locally)
*
@@ -2759,6 +2833,7 @@
static struct GNUNET_SERVER_MessageHandler plugin_handlers[] = {
{&handle_dht_local_route_request, NULL, GNUNET_MESSAGE_TYPE_DHT_LOCAL_ROUTE,
0},
{&handle_dht_local_route_stop, NULL,
GNUNET_MESSAGE_TYPE_DHT_LOCAL_ROUTE_STOP, 0},
+ {&handle_dht_control_message, NULL, GNUNET_MESSAGE_TYPE_DHT_CONTROL, 0},
{NULL, NULL, 0, 0}
};
Modified: gnunet/src/dht/test_dht_api.c
===================================================================
--- gnunet/src/dht/test_dht_api.c 2010-08-10 15:23:21 UTC (rev 12510)
+++ gnunet/src/dht/test_dht_api.c 2010-08-10 16:24:53 UTC (rev 12511)
@@ -110,10 +110,10 @@
end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
/* do work here */
+ sleep(2);
GNUNET_SCHEDULER_cancel (sched, die_task);
GNUNET_DHT_disconnect (p1.dht_handle);
-
die_task = GNUNET_SCHEDULER_NO_TASK;
if (tc->reason == GNUNET_SCHEDULER_REASON_TIMEOUT)
@@ -166,6 +166,63 @@
* @param cls closure
* @param tc context information (why was this task triggered now)
*/
+void test_set_peer_malicious_drop (void *cls, const struct
GNUNET_SCHEDULER_TaskContext *tc)
+{
+ struct PeerContext *peer = cls;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called
test_set_peer_malicious_drop!\n");
+ if (tc->reason == GNUNET_SCHEDULER_REASON_TIMEOUT)
+ GNUNET_SCHEDULER_add_now (sched, &end_badly, NULL);
+
+ GNUNET_assert (peer->dht_handle != NULL);
+
+ GNUNET_DHT_set_malicious_dropper (peer->dht_handle, &end, &p1);
+}
+
+/**
+ * Signature of the main function of a task.
+ *
+ * @param cls closure
+ * @param tc context information (why was this task triggered now)
+ */
+void test_set_peer_malicious_put (void *cls, const struct
GNUNET_SCHEDULER_TaskContext *tc)
+{
+ struct PeerContext *peer = cls;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called
test_set_peer_malicious_put!\n");
+ if (tc->reason == GNUNET_SCHEDULER_REASON_TIMEOUT)
+ GNUNET_SCHEDULER_add_now (sched, &end_badly, NULL);
+
+ GNUNET_assert (peer->dht_handle != NULL);
+
+ GNUNET_DHT_set_malicious_putter (peer->dht_handle, 750,
&test_set_peer_malicious_drop, &p1);
+}
+
+/**
+ * Signature of the main function of a task.
+ *
+ * @param cls closure
+ * @param tc context information (why was this task triggered now)
+ */
+void test_set_peer_malicious_get (void *cls, const struct
GNUNET_SCHEDULER_TaskContext *tc)
+{
+ struct PeerContext *peer = cls;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called
test_set_peer_malicious_get!\n");
+ if (tc->reason == GNUNET_SCHEDULER_REASON_TIMEOUT)
+ GNUNET_SCHEDULER_add_now (sched, &end_badly, NULL);
+
+ GNUNET_assert (peer->dht_handle != NULL);
+
+ GNUNET_DHT_set_malicious_getter (peer->dht_handle, 1500,
&test_set_peer_malicious_put, &p1);
+}
+
+/**
+ * Signature of the main function of a task.
+ *
+ * @param cls closure
+ * @param tc context information (why was this task triggered now)
+ */
void
test_find_peer_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
@@ -177,7 +234,7 @@
GNUNET_assert (peer->dht_handle != NULL);
- GNUNET_DHT_find_peer_stop (peer->find_peer_handle, &end, &p1);
+ GNUNET_DHT_find_peer_stop (peer->find_peer_handle,
&test_set_peer_malicious_get, &p1);
//GNUNET_SCHEDULER_add_delayed(sched,
GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), &end, &p1);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r12511 - gnunet/src/dht,
gnunet <=